Mercurial > hg > CbC > CbC_gcc
comparison gcc/stor-layout.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
29 #include "tm_p.h" | 29 #include "tm_p.h" |
30 #include "flags.h" | 30 #include "flags.h" |
31 #include "function.h" | 31 #include "function.h" |
32 #include "expr.h" | 32 #include "expr.h" |
33 #include "output.h" | 33 #include "output.h" |
34 #include "toplev.h" | 34 #include "diagnostic-core.h" |
35 #include "ggc.h" | 35 #include "ggc.h" |
36 #include "target.h" | 36 #include "target.h" |
37 #include "langhooks.h" | 37 #include "langhooks.h" |
38 #include "regs.h" | 38 #include "regs.h" |
39 #include "params.h" | 39 #include "params.h" |
47 tree sizetype_tab[(int) TYPE_KIND_LAST]; | 47 tree sizetype_tab[(int) TYPE_KIND_LAST]; |
48 | 48 |
49 /* If nonzero, this is an upper limit on alignment of structure fields. | 49 /* If nonzero, this is an upper limit on alignment of structure fields. |
50 The value is measured in bits. */ | 50 The value is measured in bits. */ |
51 unsigned int maximum_field_alignment = TARGET_DEFAULT_PACK_STRUCT * BITS_PER_UNIT; | 51 unsigned int maximum_field_alignment = TARGET_DEFAULT_PACK_STRUCT * BITS_PER_UNIT; |
52 /* ... and its original value in bytes, specified via -fpack-struct=<value>. */ | |
53 unsigned int initial_max_fld_align = TARGET_DEFAULT_PACK_STRUCT; | |
54 | 52 |
55 /* Nonzero if all REFERENCE_TYPEs are internal and hence should be allocated | 53 /* Nonzero if all REFERENCE_TYPEs are internal and hence should be allocated |
56 in the address spaces' address_mode, not pointer_mode. Set only by | 54 in the address spaces' address_mode, not pointer_mode. Set only by |
57 internal_reference_types called only by a front end. */ | 55 internal_reference_types called only by a front end. */ |
58 static int reference_types_internal = 0; | 56 static int reference_types_internal = 0; |
170 } | 168 } |
171 | 169 |
172 /* An array of functions used for self-referential size computation. */ | 170 /* An array of functions used for self-referential size computation. */ |
173 static GTY(()) VEC (tree, gc) *size_functions; | 171 static GTY(()) VEC (tree, gc) *size_functions; |
174 | 172 |
173 /* Look inside EXPR into simple arithmetic operations involving constants. | |
174 Return the outermost non-arithmetic or non-constant node. */ | |
175 | |
176 static tree | |
177 skip_simple_constant_arithmetic (tree expr) | |
178 { | |
179 while (true) | |
180 { | |
181 if (UNARY_CLASS_P (expr)) | |
182 expr = TREE_OPERAND (expr, 0); | |
183 else if (BINARY_CLASS_P (expr)) | |
184 { | |
185 if (TREE_CONSTANT (TREE_OPERAND (expr, 1))) | |
186 expr = TREE_OPERAND (expr, 0); | |
187 else if (TREE_CONSTANT (TREE_OPERAND (expr, 0))) | |
188 expr = TREE_OPERAND (expr, 1); | |
189 else | |
190 break; | |
191 } | |
192 else | |
193 break; | |
194 } | |
195 | |
196 return expr; | |
197 } | |
198 | |
175 /* Similar to copy_tree_r but do not copy component references involving | 199 /* Similar to copy_tree_r but do not copy component references involving |
176 PLACEHOLDER_EXPRs. These nodes are spotted in find_placeholder_in_expr | 200 PLACEHOLDER_EXPRs. These nodes are spotted in find_placeholder_in_expr |
177 and substituted in substitute_in_expr. */ | 201 and substituted in substitute_in_expr. */ |
178 | 202 |
179 static tree | 203 static tree |
231 static tree | 255 static tree |
232 self_referential_size (tree size) | 256 self_referential_size (tree size) |
233 { | 257 { |
234 static unsigned HOST_WIDE_INT fnno = 0; | 258 static unsigned HOST_WIDE_INT fnno = 0; |
235 VEC (tree, heap) *self_refs = NULL; | 259 VEC (tree, heap) *self_refs = NULL; |
236 tree param_type_list = NULL, param_decl_list = NULL, arg_list = NULL; | 260 tree param_type_list = NULL, param_decl_list = NULL; |
237 tree t, ref, return_type, fntype, fnname, fndecl; | 261 tree t, ref, return_type, fntype, fnname, fndecl; |
238 unsigned int i; | 262 unsigned int i; |
239 char buf[128]; | 263 char buf[128]; |
264 VEC(tree,gc) *args = NULL; | |
240 | 265 |
241 /* Do not factor out simple operations. */ | 266 /* Do not factor out simple operations. */ |
242 t = skip_simple_arithmetic (size); | 267 t = skip_simple_constant_arithmetic (size); |
243 if (TREE_CODE (t) == CALL_EXPR) | 268 if (TREE_CODE (t) == CALL_EXPR) |
244 return size; | 269 return size; |
245 | 270 |
246 /* Collect the list of self-references in the expression. */ | 271 /* Collect the list of self-references in the expression. */ |
247 find_placeholder_in_expr (size, &self_refs); | 272 find_placeholder_in_expr (size, &self_refs); |
253 return size; | 278 return size; |
254 size = t; | 279 size = t; |
255 | 280 |
256 /* Build the parameter and argument lists in parallel; also | 281 /* Build the parameter and argument lists in parallel; also |
257 substitute the former for the latter in the expression. */ | 282 substitute the former for the latter in the expression. */ |
258 for (i = 0; VEC_iterate (tree, self_refs, i, ref); i++) | 283 args = VEC_alloc (tree, gc, VEC_length (tree, self_refs)); |
284 FOR_EACH_VEC_ELT (tree, self_refs, i, ref) | |
259 { | 285 { |
260 tree subst, param_name, param_type, param_decl; | 286 tree subst, param_name, param_type, param_decl; |
261 | 287 |
262 if (DECL_P (ref)) | 288 if (DECL_P (ref)) |
263 { | 289 { |
288 | 314 |
289 size = substitute_in_expr (size, subst, param_decl); | 315 size = substitute_in_expr (size, subst, param_decl); |
290 | 316 |
291 param_type_list = tree_cons (NULL_TREE, param_type, param_type_list); | 317 param_type_list = tree_cons (NULL_TREE, param_type, param_type_list); |
292 param_decl_list = chainon (param_decl, param_decl_list); | 318 param_decl_list = chainon (param_decl, param_decl_list); |
293 arg_list = tree_cons (NULL_TREE, ref, arg_list); | 319 VEC_quick_push (tree, args, ref); |
294 } | 320 } |
295 | 321 |
296 VEC_free (tree, heap, self_refs); | 322 VEC_free (tree, heap, self_refs); |
297 | 323 |
298 /* Append 'void' to indicate that the number of parameters is fixed. */ | 324 /* Append 'void' to indicate that the number of parameters is fixed. */ |
299 param_type_list = tree_cons (NULL_TREE, void_type_node, param_type_list); | 325 param_type_list = tree_cons (NULL_TREE, void_type_node, param_type_list); |
300 | 326 |
301 /* The 3 lists have been created in reverse order. */ | 327 /* The 3 lists have been created in reverse order. */ |
302 param_type_list = nreverse (param_type_list); | 328 param_type_list = nreverse (param_type_list); |
303 param_decl_list = nreverse (param_decl_list); | 329 param_decl_list = nreverse (param_decl_list); |
304 arg_list = nreverse (arg_list); | |
305 | 330 |
306 /* Build the function type. */ | 331 /* Build the function type. */ |
307 return_type = TREE_TYPE (size); | 332 return_type = TREE_TYPE (size); |
308 fntype = build_function_type (return_type, param_type_list); | 333 fntype = build_function_type (return_type, param_type_list); |
309 | 334 |
310 /* Build the function declaration. */ | 335 /* Build the function declaration. */ |
311 sprintf (buf, "SZ"HOST_WIDE_INT_PRINT_UNSIGNED, fnno++); | 336 sprintf (buf, "SZ"HOST_WIDE_INT_PRINT_UNSIGNED, fnno++); |
312 fnname = get_file_function_name (buf); | 337 fnname = get_file_function_name (buf); |
313 fndecl = build_decl (input_location, FUNCTION_DECL, fnname, fntype); | 338 fndecl = build_decl (input_location, FUNCTION_DECL, fnname, fntype); |
314 for (t = param_decl_list; t; t = TREE_CHAIN (t)) | 339 for (t = param_decl_list; t; t = DECL_CHAIN (t)) |
315 DECL_CONTEXT (t) = fndecl; | 340 DECL_CONTEXT (t) = fndecl; |
316 DECL_ARGUMENTS (fndecl) = param_decl_list; | 341 DECL_ARGUMENTS (fndecl) = param_decl_list; |
317 DECL_RESULT (fndecl) | 342 DECL_RESULT (fndecl) |
318 = build_decl (input_location, RESULT_DECL, 0, return_type); | 343 = build_decl (input_location, RESULT_DECL, 0, return_type); |
319 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; | 344 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
340 | 365 |
341 /* Put it onto the list of size functions. */ | 366 /* Put it onto the list of size functions. */ |
342 VEC_safe_push (tree, gc, size_functions, fndecl); | 367 VEC_safe_push (tree, gc, size_functions, fndecl); |
343 | 368 |
344 /* Replace the original expression with a call to the size function. */ | 369 /* Replace the original expression with a call to the size function. */ |
345 return build_function_call_expr (input_location, fndecl, arg_list); | 370 return build_call_expr_loc_vec (input_location, fndecl, args); |
346 } | 371 } |
347 | 372 |
348 /* Take, queue and compile all the size functions. It is essential that | 373 /* Take, queue and compile all the size functions. It is essential that |
349 the size functions be gimplified at the very end of the compilation | 374 the size functions be gimplified at the very end of the compilation |
350 in order to guarantee transparent handling of self-referential sizes. | 375 in order to guarantee transparent handling of self-referential sizes. |
367 } | 392 } |
368 | 393 |
369 VEC_free (tree, gc, size_functions); | 394 VEC_free (tree, gc, size_functions); |
370 } | 395 } |
371 | 396 |
372 #ifndef MAX_FIXED_MODE_SIZE | |
373 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode) | |
374 #endif | |
375 | |
376 /* Return the machine mode to use for a nonscalar of SIZE bits. The | 397 /* Return the machine mode to use for a nonscalar of SIZE bits. The |
377 mode must be in class MCLASS, and have exactly that many value bits; | 398 mode must be in class MCLASS, and have exactly that many value bits; |
378 it may have padding as well. If LIMIT is nonzero, modes of wider | 399 it may have padding as well. If LIMIT is nonzero, modes of wider |
379 than MAX_FIXED_MODE_SIZE will not be used. */ | 400 than MAX_FIXED_MODE_SIZE will not be used. */ |
380 | 401 |
466 | 487 |
467 case MODE_CC: | 488 case MODE_CC: |
468 default: | 489 default: |
469 gcc_unreachable (); | 490 gcc_unreachable (); |
470 } | 491 } |
492 | |
493 return mode; | |
494 } | |
495 | |
496 /* Find a mode that is suitable for representing a vector with | |
497 NUNITS elements of mode INNERMODE. Returns BLKmode if there | |
498 is no suitable mode. */ | |
499 | |
500 enum machine_mode | |
501 mode_for_vector (enum machine_mode innermode, unsigned nunits) | |
502 { | |
503 enum machine_mode mode; | |
504 | |
505 /* First, look for a supported vector type. */ | |
506 if (SCALAR_FLOAT_MODE_P (innermode)) | |
507 mode = MIN_MODE_VECTOR_FLOAT; | |
508 else if (SCALAR_FRACT_MODE_P (innermode)) | |
509 mode = MIN_MODE_VECTOR_FRACT; | |
510 else if (SCALAR_UFRACT_MODE_P (innermode)) | |
511 mode = MIN_MODE_VECTOR_UFRACT; | |
512 else if (SCALAR_ACCUM_MODE_P (innermode)) | |
513 mode = MIN_MODE_VECTOR_ACCUM; | |
514 else if (SCALAR_UACCUM_MODE_P (innermode)) | |
515 mode = MIN_MODE_VECTOR_UACCUM; | |
516 else | |
517 mode = MIN_MODE_VECTOR_INT; | |
518 | |
519 /* Do not check vector_mode_supported_p here. We'll do that | |
520 later in vector_type_mode. */ | |
521 for (; mode != VOIDmode ; mode = GET_MODE_WIDER_MODE (mode)) | |
522 if (GET_MODE_NUNITS (mode) == nunits | |
523 && GET_MODE_INNER (mode) == innermode) | |
524 break; | |
525 | |
526 /* For integers, try mapping it to a same-sized scalar mode. */ | |
527 if (mode == VOIDmode | |
528 && GET_MODE_CLASS (innermode) == MODE_INT) | |
529 mode = mode_for_size (nunits * GET_MODE_BITSIZE (innermode), | |
530 MODE_INT, 0); | |
531 | |
532 if (mode == VOIDmode | |
533 || (GET_MODE_CLASS (mode) == MODE_INT | |
534 && !have_regs_of_mode[mode])) | |
535 return BLKmode; | |
471 | 536 |
472 return mode; | 537 return mode; |
473 } | 538 } |
474 | 539 |
475 /* Return the alignment of MODE. This will be bounded by 1 and | 540 /* Return the alignment of MODE. This will be bounded by 1 and |
591 #endif | 656 #endif |
592 } | 657 } |
593 } | 658 } |
594 | 659 |
595 /* See if we can use an ordinary integer mode for a bit-field. | 660 /* See if we can use an ordinary integer mode for a bit-field. |
596 Conditions are: a fixed size that is correct for another mode | 661 Conditions are: a fixed size that is correct for another mode, |
597 and occupying a complete byte or bytes on proper boundary. */ | 662 occupying a complete byte or bytes on proper boundary, |
663 and not volatile or not -fstrict-volatile-bitfields. */ | |
598 if (TYPE_SIZE (type) != 0 | 664 if (TYPE_SIZE (type) != 0 |
599 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | 665 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST |
600 && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT) | 666 && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT |
667 && !(TREE_THIS_VOLATILE (decl) | |
668 && flag_strict_volatile_bitfields > 0)) | |
601 { | 669 { |
602 enum machine_mode xmode | 670 enum machine_mode xmode |
603 = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1); | 671 = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1); |
604 unsigned int xalign = GET_MODE_ALIGNMENT (xmode); | 672 unsigned int xalign = GET_MODE_ALIGNMENT (xmode); |
605 | 673 |
675 && compare_tree_int (size, larger_than_size) > 0) | 743 && compare_tree_int (size, larger_than_size) > 0) |
676 { | 744 { |
677 int size_as_int = TREE_INT_CST_LOW (size); | 745 int size_as_int = TREE_INT_CST_LOW (size); |
678 | 746 |
679 if (compare_tree_int (size, size_as_int) == 0) | 747 if (compare_tree_int (size, size_as_int) == 0) |
680 warning (OPT_Wlarger_than_eq, "size of %q+D is %d bytes", decl, size_as_int); | 748 warning (OPT_Wlarger_than_, "size of %q+D is %d bytes", decl, size_as_int); |
681 else | 749 else |
682 warning (OPT_Wlarger_than_eq, "size of %q+D is larger than %wd bytes", | 750 warning (OPT_Wlarger_than_, "size of %q+D is larger than %wd bytes", |
683 decl, larger_than_size); | 751 decl, larger_than_size); |
684 } | 752 } |
685 } | 753 } |
686 | 754 |
687 /* If the RTL was already set, update its mode and mem attributes. */ | 755 /* If the RTL was already set, update its mode and mem attributes. */ |
745 #endif | 813 #endif |
746 | 814 |
747 rli->offset = size_zero_node; | 815 rli->offset = size_zero_node; |
748 rli->bitpos = bitsize_zero_node; | 816 rli->bitpos = bitsize_zero_node; |
749 rli->prev_field = 0; | 817 rli->prev_field = 0; |
750 rli->pending_statics = 0; | 818 rli->pending_statics = NULL; |
751 rli->packed_maybe_necessary = 0; | 819 rli->packed_maybe_necessary = 0; |
752 rli->remaining_in_alignment = 0; | 820 rli->remaining_in_alignment = 0; |
753 | 821 |
754 return rli; | 822 return rli; |
755 } | 823 } |
811 } | 879 } |
812 } | 880 } |
813 | 881 |
814 /* Print debugging information about the information in RLI. */ | 882 /* Print debugging information about the information in RLI. */ |
815 | 883 |
816 void | 884 DEBUG_FUNCTION void |
817 debug_rli (record_layout_info rli) | 885 debug_rli (record_layout_info rli) |
818 { | 886 { |
819 print_node_brief (stderr, "type", rli->t, 0); | 887 print_node_brief (stderr, "type", rli->t, 0); |
820 print_node_brief (stderr, "\noffset", rli->offset, 0); | 888 print_node_brief (stderr, "\noffset", rli->offset, 0); |
821 print_node_brief (stderr, " bitpos", rli->bitpos, 0); | 889 print_node_brief (stderr, " bitpos", rli->bitpos, 0); |
829 fprintf (stderr, "remaining in alignment = %u\n", rli->remaining_in_alignment); | 897 fprintf (stderr, "remaining in alignment = %u\n", rli->remaining_in_alignment); |
830 | 898 |
831 if (rli->packed_maybe_necessary) | 899 if (rli->packed_maybe_necessary) |
832 fprintf (stderr, "packed may be necessary\n"); | 900 fprintf (stderr, "packed may be necessary\n"); |
833 | 901 |
834 if (rli->pending_statics) | 902 if (!VEC_empty (tree, rli->pending_statics)) |
835 { | 903 { |
836 fprintf (stderr, "pending statics:\n"); | 904 fprintf (stderr, "pending statics:\n"); |
837 debug_tree (rli->pending_statics); | 905 debug_vec_tree (rli->pending_statics); |
838 } | 906 } |
839 } | 907 } |
840 | 908 |
841 /* Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and | 909 /* Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and |
842 BITPOS if necessary to keep BITPOS below OFFSET_ALIGN. */ | 910 BITPOS if necessary to keep BITPOS below OFFSET_ALIGN. */ |
994 /* We assume the union's size will be a multiple of a byte so we don't | 1062 /* We assume the union's size will be a multiple of a byte so we don't |
995 bother with BITPOS. */ | 1063 bother with BITPOS. */ |
996 if (TREE_CODE (rli->t) == UNION_TYPE) | 1064 if (TREE_CODE (rli->t) == UNION_TYPE) |
997 rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field)); | 1065 rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field)); |
998 else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE) | 1066 else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE) |
999 rli->offset = fold_build3_loc (input_location, COND_EXPR, sizetype, | 1067 rli->offset = fold_build3 (COND_EXPR, sizetype, DECL_QUALIFIER (field), |
1000 DECL_QUALIFIER (field), | |
1001 DECL_SIZE_UNIT (field), rli->offset); | 1068 DECL_SIZE_UNIT (field), rli->offset); |
1002 } | 1069 } |
1003 | 1070 |
1004 #if defined (PCC_BITFIELD_TYPE_MATTERS) || defined (BITFIELD_NBYTES_LIMITED) | 1071 #if defined (PCC_BITFIELD_TYPE_MATTERS) || defined (BITFIELD_NBYTES_LIMITED) |
1005 /* A bitfield of SIZE with a required access alignment of ALIGN is allocated | 1072 /* A bitfield of SIZE with a required access alignment of ALIGN is allocated |
1043 really like a structure field. If it is a FUNCTION_DECL, it's a | 1110 really like a structure field. If it is a FUNCTION_DECL, it's a |
1044 method. In both cases, all we do is lay out the decl, and we do | 1111 method. In both cases, all we do is lay out the decl, and we do |
1045 it *after* the record is laid out. */ | 1112 it *after* the record is laid out. */ |
1046 if (TREE_CODE (field) == VAR_DECL) | 1113 if (TREE_CODE (field) == VAR_DECL) |
1047 { | 1114 { |
1048 rli->pending_statics = tree_cons (NULL_TREE, field, | 1115 VEC_safe_push (tree, gc, rli->pending_statics, field); |
1049 rli->pending_statics); | |
1050 return; | 1116 return; |
1051 } | 1117 } |
1052 | 1118 |
1053 /* Enumerators and enum types which are local to this class need not | 1119 /* Enumerators and enum types which are local to this class need not |
1054 be laid out. Likewise for initialized constant fields. */ | 1120 be laid out. Likewise for initialized constant fields. */ |
1179 if (DECL_PACKED (field)) | 1245 if (DECL_PACKED (field)) |
1180 { | 1246 { |
1181 if (warn_packed_bitfield_compat == 1) | 1247 if (warn_packed_bitfield_compat == 1) |
1182 inform | 1248 inform |
1183 (input_location, | 1249 (input_location, |
1184 "Offset of packed bit-field %qD has changed in GCC 4.4", | 1250 "offset of packed bit-field %qD has changed in GCC 4.4", |
1185 field); | 1251 field); |
1186 } | 1252 } |
1187 else | 1253 else |
1188 rli->bitpos = round_up_loc (input_location, rli->bitpos, type_align); | 1254 rli->bitpos = round_up (rli->bitpos, type_align); |
1189 } | 1255 } |
1190 | 1256 |
1191 if (! DECL_PACKED (field)) | 1257 if (! DECL_PACKED (field)) |
1192 TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type); | 1258 TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type); |
1193 } | 1259 } |
1364 type_align = TYPE_ALIGN (TREE_TYPE (field)); | 1430 type_align = TYPE_ALIGN (TREE_TYPE (field)); |
1365 | 1431 |
1366 if (maximum_field_alignment != 0) | 1432 if (maximum_field_alignment != 0) |
1367 type_align = MIN (type_align, maximum_field_alignment); | 1433 type_align = MIN (type_align, maximum_field_alignment); |
1368 | 1434 |
1369 rli->bitpos = round_up_loc (input_location, rli->bitpos, type_align); | 1435 rli->bitpos = round_up (rli->bitpos, type_align); |
1370 | 1436 |
1371 /* If we really aligned, don't allow subsequent bitfields | 1437 /* If we really aligned, don't allow subsequent bitfields |
1372 to undo that. */ | 1438 to undo that. */ |
1373 rli->prev_field = NULL; | 1439 rli->prev_field = NULL; |
1374 } | 1440 } |
1430 { | 1496 { |
1431 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field)); | 1497 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field)); |
1432 | 1498 |
1433 /* If we ended a bitfield before the full length of the type then | 1499 /* If we ended a bitfield before the full length of the type then |
1434 pad the struct out to the full length of the last type. */ | 1500 pad the struct out to the full length of the last type. */ |
1435 if ((TREE_CHAIN (field) == NULL | 1501 if ((DECL_CHAIN (field) == NULL |
1436 || TREE_CODE (TREE_CHAIN (field)) != FIELD_DECL) | 1502 || TREE_CODE (DECL_CHAIN (field)) != FIELD_DECL) |
1437 && DECL_BIT_FIELD_TYPE (field) | 1503 && DECL_BIT_FIELD_TYPE (field) |
1438 && !integer_zerop (DECL_SIZE (field))) | 1504 && !integer_zerop (DECL_SIZE (field))) |
1439 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, | 1505 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, |
1440 bitsize_int (rli->remaining_in_alignment)); | 1506 bitsize_int (rli->remaining_in_alignment)); |
1441 | 1507 |
1478 if (! integer_zerop (rli->bitpos)) | 1544 if (! integer_zerop (rli->bitpos)) |
1479 unpadded_size_unit | 1545 unpadded_size_unit |
1480 = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node); | 1546 = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node); |
1481 | 1547 |
1482 /* Round the size up to be a multiple of the required alignment. */ | 1548 /* Round the size up to be a multiple of the required alignment. */ |
1483 TYPE_SIZE (rli->t) = round_up_loc (input_location, unpadded_size, | 1549 TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t)); |
1484 TYPE_ALIGN (rli->t)); | |
1485 TYPE_SIZE_UNIT (rli->t) | 1550 TYPE_SIZE_UNIT (rli->t) |
1486 = round_up_loc (input_location, unpadded_size_unit, TYPE_ALIGN_UNIT (rli->t)); | 1551 = round_up (unpadded_size_unit, TYPE_ALIGN_UNIT (rli->t)); |
1487 | 1552 |
1488 if (TREE_CONSTANT (unpadded_size) | 1553 if (TREE_CONSTANT (unpadded_size) |
1489 && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0 | 1554 && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0 |
1490 && input_location != BUILTINS_LOCATION) | 1555 && input_location != BUILTINS_LOCATION) |
1491 warning (OPT_Wpadded, "padding struct size to alignment boundary"); | 1556 warning (OPT_Wpadded, "padding struct size to alignment boundary"); |
1501 = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align); | 1566 = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align); |
1502 #else | 1567 #else |
1503 rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align); | 1568 rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align); |
1504 #endif | 1569 #endif |
1505 | 1570 |
1506 unpacked_size = round_up_loc (input_location, TYPE_SIZE (rli->t), rli->unpacked_align); | 1571 unpacked_size = round_up (TYPE_SIZE (rli->t), rli->unpacked_align); |
1507 if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t))) | 1572 if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t))) |
1508 { | 1573 { |
1509 if (TYPE_NAME (rli->t)) | 1574 if (TYPE_NAME (rli->t)) |
1510 { | 1575 { |
1511 tree name; | 1576 tree name; |
1552 return; | 1617 return; |
1553 | 1618 |
1554 /* A record which has any BLKmode members must itself be | 1619 /* A record which has any BLKmode members must itself be |
1555 BLKmode; it can't go in a register. Unless the member is | 1620 BLKmode; it can't go in a register. Unless the member is |
1556 BLKmode only because it isn't aligned. */ | 1621 BLKmode only because it isn't aligned. */ |
1557 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | 1622 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
1558 { | 1623 { |
1559 if (TREE_CODE (field) != FIELD_DECL) | 1624 if (TREE_CODE (field) != FIELD_DECL) |
1560 continue; | 1625 continue; |
1561 | 1626 |
1562 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK | 1627 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK |
1653 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type), | 1718 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type), |
1654 bitsize_unit_node)); | 1719 bitsize_unit_node)); |
1655 | 1720 |
1656 if (TYPE_SIZE (type) != 0) | 1721 if (TYPE_SIZE (type) != 0) |
1657 { | 1722 { |
1658 TYPE_SIZE (type) = round_up_loc (input_location, | 1723 TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type)); |
1659 TYPE_SIZE (type), TYPE_ALIGN (type)); | 1724 TYPE_SIZE_UNIT (type) |
1660 TYPE_SIZE_UNIT (type) = round_up_loc (input_location, TYPE_SIZE_UNIT (type), | 1725 = round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN_UNIT (type)); |
1661 TYPE_ALIGN_UNIT (type)); | |
1662 } | 1726 } |
1663 | 1727 |
1664 /* Evaluate nonconstant sizes only once, either now or as soon as safe. */ | 1728 /* Evaluate nonconstant sizes only once, either now or as soon as safe. */ |
1665 if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) | 1729 if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
1666 TYPE_SIZE (type) = variable_size (TYPE_SIZE (type)); | 1730 TYPE_SIZE (type) = variable_size (TYPE_SIZE (type)); |
1720 variant = TYPE_NEXT_VARIANT (variant)) | 1784 variant = TYPE_NEXT_VARIANT (variant)) |
1721 TYPE_PACKED (variant) = TYPE_PACKED (rli->t); | 1785 TYPE_PACKED (variant) = TYPE_PACKED (rli->t); |
1722 | 1786 |
1723 /* Lay out any static members. This is done now because their type | 1787 /* Lay out any static members. This is done now because their type |
1724 may use the record's type. */ | 1788 may use the record's type. */ |
1725 while (rli->pending_statics) | 1789 while (!VEC_empty (tree, rli->pending_statics)) |
1726 { | 1790 layout_decl (VEC_pop (tree, rli->pending_statics), 0); |
1727 layout_decl (TREE_VALUE (rli->pending_statics), 0); | |
1728 rli->pending_statics = TREE_CHAIN (rli->pending_statics); | |
1729 } | |
1730 | 1791 |
1731 /* Clean up. */ | 1792 /* Clean up. */ |
1732 if (free_p) | 1793 if (free_p) |
1733 free (rli); | 1794 { |
1795 VEC_free (tree, gc, rli->pending_statics); | |
1796 free (rli); | |
1797 } | |
1734 } | 1798 } |
1735 | 1799 |
1736 | 1800 |
1737 /* Finish processing a builtin RECORD_TYPE type TYPE. It's name is | 1801 /* Finish processing a builtin RECORD_TYPE type TYPE. It's name is |
1738 NAME, its fields are chained in reverse on FIELDS. | 1802 NAME, its fields are chained in reverse on FIELDS. |
1747 tree tail, next; | 1811 tree tail, next; |
1748 | 1812 |
1749 for (tail = NULL_TREE; fields; tail = fields, fields = next) | 1813 for (tail = NULL_TREE; fields; tail = fields, fields = next) |
1750 { | 1814 { |
1751 DECL_FIELD_CONTEXT (fields) = type; | 1815 DECL_FIELD_CONTEXT (fields) = type; |
1752 next = TREE_CHAIN (fields); | 1816 next = DECL_CHAIN (fields); |
1753 TREE_CHAIN (fields) = tail; | 1817 DECL_CHAIN (fields) = tail; |
1754 } | 1818 } |
1755 TYPE_FIELDS (type) = tail; | 1819 TYPE_FIELDS (type) = tail; |
1756 | 1820 |
1757 if (align_type) | 1821 if (align_type) |
1758 { | 1822 { |
1849 | 1913 |
1850 gcc_assert (!(nunits & (nunits - 1))); | 1914 gcc_assert (!(nunits & (nunits - 1))); |
1851 | 1915 |
1852 /* Find an appropriate mode for the vector type. */ | 1916 /* Find an appropriate mode for the vector type. */ |
1853 if (TYPE_MODE (type) == VOIDmode) | 1917 if (TYPE_MODE (type) == VOIDmode) |
1854 { | 1918 SET_TYPE_MODE (type, |
1855 enum machine_mode innermode = TYPE_MODE (innertype); | 1919 mode_for_vector (TYPE_MODE (innertype), nunits)); |
1856 enum machine_mode mode; | |
1857 | |
1858 /* First, look for a supported vector type. */ | |
1859 if (SCALAR_FLOAT_MODE_P (innermode)) | |
1860 mode = MIN_MODE_VECTOR_FLOAT; | |
1861 else if (SCALAR_FRACT_MODE_P (innermode)) | |
1862 mode = MIN_MODE_VECTOR_FRACT; | |
1863 else if (SCALAR_UFRACT_MODE_P (innermode)) | |
1864 mode = MIN_MODE_VECTOR_UFRACT; | |
1865 else if (SCALAR_ACCUM_MODE_P (innermode)) | |
1866 mode = MIN_MODE_VECTOR_ACCUM; | |
1867 else if (SCALAR_UACCUM_MODE_P (innermode)) | |
1868 mode = MIN_MODE_VECTOR_UACCUM; | |
1869 else | |
1870 mode = MIN_MODE_VECTOR_INT; | |
1871 | |
1872 /* Do not check vector_mode_supported_p here. We'll do that | |
1873 later in vector_type_mode. */ | |
1874 for (; mode != VOIDmode ; mode = GET_MODE_WIDER_MODE (mode)) | |
1875 if (GET_MODE_NUNITS (mode) == nunits | |
1876 && GET_MODE_INNER (mode) == innermode) | |
1877 break; | |
1878 | |
1879 /* For integers, try mapping it to a same-sized scalar mode. */ | |
1880 if (mode == VOIDmode | |
1881 && GET_MODE_CLASS (innermode) == MODE_INT) | |
1882 mode = mode_for_size (nunits * GET_MODE_BITSIZE (innermode), | |
1883 MODE_INT, 0); | |
1884 | |
1885 if (mode == VOIDmode || | |
1886 (GET_MODE_CLASS (mode) == MODE_INT | |
1887 && !have_regs_of_mode[mode])) | |
1888 SET_TYPE_MODE (type, BLKmode); | |
1889 else | |
1890 SET_TYPE_MODE (type, mode); | |
1891 } | |
1892 | 1920 |
1893 TYPE_SATURATING (type) = TYPE_SATURATING (TREE_TYPE (type)); | 1921 TYPE_SATURATING (type) = TYPE_SATURATING (TREE_TYPE (type)); |
1894 TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TREE_TYPE (type)); | 1922 TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TREE_TYPE (type)); |
1895 TYPE_SIZE_UNIT (type) = int_const_binop (MULT_EXPR, | 1923 TYPE_SIZE_UNIT (type) = int_const_binop (MULT_EXPR, |
1896 TYPE_SIZE_UNIT (innertype), | 1924 TYPE_SIZE_UNIT (innertype), |
1972 that (possible) negative values are handled appropriately. */ | 2000 that (possible) negative values are handled appropriately. */ |
1973 else | 2001 else |
1974 length | 2002 length |
1975 = size_binop (PLUS_EXPR, size_one_node, | 2003 = size_binop (PLUS_EXPR, size_one_node, |
1976 fold_convert (sizetype, | 2004 fold_convert (sizetype, |
1977 fold_build2_loc (input_location, | 2005 fold_build2 (MINUS_EXPR, |
1978 MINUS_EXPR, | 2006 TREE_TYPE (lb), |
1979 TREE_TYPE (lb), | 2007 ub, lb))); |
1980 ub, lb))); | |
1981 | 2008 |
1982 TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size, | 2009 TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size, |
1983 fold_convert (bitsizetype, | 2010 fold_convert (bitsizetype, |
1984 length)); | 2011 length)); |
1985 | 2012 |
1999 TYPE_ALIGN (type) | 2026 TYPE_ALIGN (type) |
2000 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT); | 2027 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT); |
2001 #else | 2028 #else |
2002 TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT); | 2029 TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT); |
2003 #endif | 2030 #endif |
2004 if (!TYPE_SIZE (element)) | |
2005 /* We don't know the size of the underlying element type, so | |
2006 our alignment calculations will be wrong, forcing us to | |
2007 fall back on structural equality. */ | |
2008 SET_TYPE_STRUCTURAL_EQUALITY (type); | |
2009 TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element); | 2031 TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element); |
2010 SET_TYPE_MODE (type, BLKmode); | 2032 SET_TYPE_MODE (type, BLKmode); |
2011 if (TYPE_SIZE (type) != 0 | 2033 if (TYPE_SIZE (type) != 0 |
2012 #ifdef MEMBER_TYPE_FORCES_BLK | 2034 #ifdef MEMBER_TYPE_FORCES_BLK |
2013 && ! MEMBER_TYPE_FORCES_BLK (type, VOIDmode) | 2035 && ! MEMBER_TYPE_FORCES_BLK (type, VOIDmode) |
2062 its size. We reverse them again later. */ | 2084 its size. We reverse them again later. */ |
2063 if (TREE_CODE (type) == QUAL_UNION_TYPE) | 2085 if (TREE_CODE (type) == QUAL_UNION_TYPE) |
2064 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type)); | 2086 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type)); |
2065 | 2087 |
2066 /* Place all the fields. */ | 2088 /* Place all the fields. */ |
2067 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | 2089 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
2068 place_field (rli, field); | 2090 place_field (rli, field); |
2069 | 2091 |
2070 if (TREE_CODE (type) == QUAL_UNION_TYPE) | 2092 if (TREE_CODE (type) == QUAL_UNION_TYPE) |
2071 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type)); | 2093 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type)); |
2072 | 2094 |