1 /* C-compiler utilities for types and variables storage layout
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1996, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
34 /* Set to one when set_sizetype has been called. */
35 static int sizetype_set;
37 /* List of types created before set_sizetype has been called. We do not
38 make this a GGC root since we want these nodes to be reclaimed. */
39 static tree early_type_list;
41 /* Data type for the expressions representing sizes of data types.
42 It is the first integer type laid out. */
43 tree sizetype_tab[(int) TYPE_KIND_LAST];
45 /* If nonzero, this is an upper limit on alignment of structure fields.
46 The value is measured in bits. */
47 unsigned int maximum_field_alignment;
49 /* If non-zero, the alignment of a bitstring or (power-)set value, in bits.
50 May be overridden by front-ends. */
51 unsigned int set_alignment = 0;
53 static tree layout_record PARAMS ((tree));
54 static void layout_union PARAMS ((tree));
56 /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded. */
58 static tree pending_sizes;
60 /* Nonzero means cannot safely call expand_expr now,
61 so put variable sizes onto `pending_sizes' instead. */
63 int immediate_size_expand;
68 tree chain = pending_sizes;
71 /* Put each SAVE_EXPR into the current function. */
72 for (t = chain; t; t = TREE_CHAIN (t))
73 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = current_function_decl;
80 put_pending_sizes (chain)
86 pending_sizes = chain;
89 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
90 to serve as the actual size-expression for a type or decl. */
96 /* If the language-processor is to take responsibility for variable-sized
97 items (e.g., languages which have elaboration procedures like Ada),
98 just return SIZE unchanged. Likewise for self-referential sizes. */
99 if (TREE_CONSTANT (size)
100 || global_bindings_p () < 0 || contains_placeholder_p (size))
103 size = save_expr (size);
105 /* If an array with a variable number of elements is declared, and
106 the elements require destruction, we will emit a cleanup for the
107 array. That cleanup is run both on normal exit from the block
108 and in the exception-handler for the block. Normally, when code
109 is used in both ordinary code and in an exception handler it is
110 `unsaved', i.e., all SAVE_EXPRs are recalculated. However, we do
111 not wish to do that here; the array-size is the same in both
113 if (TREE_CODE (size) == SAVE_EXPR)
114 SAVE_EXPR_PERSISTENT_P (size) = 1;
116 if (global_bindings_p ())
118 if (TREE_CONSTANT (size))
119 error ("type size can't be explicitly evaluated");
121 error ("variable-size type declared outside of any function");
123 return size_one_node;
126 if (immediate_size_expand)
127 /* NULL_RTX is not defined; neither is the rtx type.
128 Also, we would like to pass const0_rtx here, but don't have it. */
129 expand_expr (size, expand_expr (integer_zero_node, NULL_PTR, VOIDmode, 0),
132 && cfun->x_dont_save_pending_sizes_p)
133 /* The front-end doesn't want us to keep a list of the expressions
134 that determine sizes for variable size objects. */
137 pending_sizes = tree_cons (NULL_TREE, size, pending_sizes);
142 #ifndef MAX_FIXED_MODE_SIZE
143 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
146 /* Return the machine mode to use for a nonscalar of SIZE bits.
147 The mode must be in class CLASS, and have exactly that many bits.
148 If LIMIT is nonzero, modes of wider than MAX_FIXED_MODE_SIZE will not
152 mode_for_size (size, class, limit)
154 enum mode_class class;
157 register enum machine_mode mode;
159 if (limit && size > MAX_FIXED_MODE_SIZE)
162 /* Get the first mode which has this size, in the specified class. */
163 for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
164 mode = GET_MODE_WIDER_MODE (mode))
165 if (GET_MODE_BITSIZE (mode) == size)
171 /* Similar, except passed a tree node. */
174 mode_for_size_tree (size, class, limit)
176 enum mode_class class;
179 if (TREE_CODE (size) != INTEGER_CST
180 || TREE_INT_CST_HIGH (size) != 0
181 /* If the low-order part is so high as to appear negative, we can't
182 find a mode for that many bits. */
183 || TREE_INT_CST_LOW (size) < 0
184 /* What we really want to say here is that the size can fit in a
185 host integer, but we know there's no way we'd find a mode for
186 this many bits, so there's no point in doing the precise test. */
187 || TREE_INT_CST_LOW (size) > 1000)
190 return mode_for_size (TREE_INT_CST_LOW (size), class, limit);
193 /* Similar, but never return BLKmode; return the narrowest mode that
194 contains at least the requested number of bits. */
197 smallest_mode_for_size (size, class)
199 enum mode_class class;
201 register enum machine_mode mode;
203 /* Get the first mode which has at least this size, in the
205 for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
206 mode = GET_MODE_WIDER_MODE (mode))
207 if (GET_MODE_BITSIZE (mode) >= size)
213 /* Find an integer mode of the exact same size, or BLKmode on failure. */
216 int_mode_for_mode (mode)
217 enum machine_mode mode;
219 switch (GET_MODE_CLASS (mode))
222 case MODE_PARTIAL_INT:
225 case MODE_COMPLEX_INT:
226 case MODE_COMPLEX_FLOAT:
228 mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
235 /* ... fall through ... */
245 /* Return the value of VALUE, rounded up to a multiple of DIVISOR.
246 This can only be applied to objects of a sizetype. */
249 round_up (value, divisor)
253 tree arg = size_int_type (divisor, TREE_TYPE (value));
255 return size_binop (MULT_EXPR, size_binop (CEIL_DIV_EXPR, value, arg), arg);
258 /* Likewise, but round down. */
261 round_down (value, divisor)
265 tree arg = size_int_type (divisor, TREE_TYPE (value));
267 return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg);
270 /* Set the size, mode and alignment of a ..._DECL node.
271 TYPE_DECL does need this for C++.
272 Note that LABEL_DECL and CONST_DECL nodes do not need this,
273 and FUNCTION_DECL nodes have them set up in a special (and simple) way.
274 Don't call layout_decl for them.
276 KNOWN_ALIGN is the amount of alignment we can assume this
277 decl has with no special effort. It is relevant only for FIELD_DECLs
278 and depends on the previous fields.
279 All that matters about KNOWN_ALIGN is which powers of 2 divide it.
280 If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
281 the record will be aligned to suit. */
284 layout_decl (decl, known_align)
286 unsigned int known_align;
288 register tree type = TREE_TYPE (decl);
289 register enum tree_code code = TREE_CODE (decl);
291 if (code == CONST_DECL)
293 else if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
294 && code != TYPE_DECL && code != FIELD_DECL)
297 if (type == error_mark_node)
298 type = void_type_node;
300 /* Usually the size and mode come from the data type without change. */
301 DECL_MODE (decl) = TYPE_MODE (type);
302 TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
303 if (DECL_SIZE (decl) == 0)
305 DECL_SIZE (decl) = TYPE_SIZE (type);
306 DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
308 else if (code == FIELD_DECL)
310 HOST_WIDE_INT spec_size;
312 /* The front-end may set the explicit width of the field, so its
313 size may not be the same as the size of its type. This happens
314 with bitfields, of course (an `int' bitfield may be only 2 bits,
315 say), but it also happens with other fields. For example, the
316 C++ front-end creates zero-sized fields corresponding to empty
317 base classes, and depends on layout_type setting
318 DECL_FIELD_BITPOS correctly for the field. */
319 if (integer_zerop (DECL_SIZE (decl))
320 && DECL_NAME (decl) != NULL_TREE)
323 /* Size is specified in number of bits. */
324 spec_size = TREE_INT_CST_LOW (DECL_SIZE (decl));
325 if (spec_size % BITS_PER_UNIT == 0)
326 DECL_SIZE_UNIT (decl) = size_int (spec_size / BITS_PER_UNIT);
328 DECL_SIZE_UNIT (decl) = 0;
331 /* Force alignment required for the data type.
332 But if the decl itself wants greater alignment, don't override that.
333 Likewise, if the decl is packed, don't override it. */
334 if (!(code == FIELD_DECL && DECL_BIT_FIELD (decl))
335 && (DECL_ALIGN (decl) == 0
336 || (! DECL_PACKED (decl) && TYPE_ALIGN (type) > DECL_ALIGN (decl))))
337 DECL_ALIGN (decl) = TYPE_ALIGN (type);
339 /* See if we can use an ordinary integer mode for a bit-field.
340 Conditions are: a fixed size that is correct for another mode
341 and occupying a complete byte or bytes on proper boundary. */
342 if (code == FIELD_DECL)
344 DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
345 if (maximum_field_alignment != 0)
346 DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
347 else if (DECL_PACKED (decl))
348 DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
351 if (DECL_BIT_FIELD (decl)
352 && TYPE_SIZE (type) != 0
353 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
354 && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
356 register enum machine_mode xmode
357 = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
360 && known_align % GET_MODE_ALIGNMENT (xmode) == 0)
362 DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
364 DECL_MODE (decl) = xmode;
365 DECL_SIZE (decl) = bitsize_int (GET_MODE_BITSIZE (xmode));
366 DECL_SIZE_UNIT (decl) = size_int (GET_MODE_SIZE (xmode));
367 /* This no longer needs to be accessed as a bit field. */
368 DECL_BIT_FIELD (decl) = 0;
372 /* Turn off DECL_BIT_FIELD if we won't need it set. */
373 if (DECL_BIT_FIELD (decl) && TYPE_MODE (type) == BLKmode
374 && known_align % TYPE_ALIGN (type) == 0
375 && DECL_SIZE_UNIT (decl) != 0
376 && DECL_ALIGN (decl) >= TYPE_ALIGN (type))
377 DECL_BIT_FIELD (decl) = 0;
379 /* Evaluate nonconstant size only once, either now or as soon as safe. */
380 if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
381 DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
382 if (DECL_SIZE_UNIT (decl) != 0
383 && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST)
384 DECL_SIZE_UNIT (decl) = variable_size (DECL_SIZE_UNIT (decl));
386 /* If requested, warn about definitions of large data objects. */
388 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
389 && ! DECL_EXTERNAL (decl))
391 tree size = DECL_SIZE_UNIT (decl);
393 if (size != 0 && TREE_CODE (size) == INTEGER_CST
394 && (TREE_INT_CST_HIGH (size) != 0
395 || TREE_INT_CST_LOW (size) > larger_than_size))
397 int size_as_int = TREE_INT_CST_LOW (size);
399 if (size_as_int == TREE_INT_CST_LOW (size)
400 && TREE_INT_CST_HIGH (size) == 0)
401 warning_with_decl (decl, "size of `%s' is %d bytes", size_as_int);
403 warning_with_decl (decl, "size of `%s' is larger than %d bytes",
409 /* Lay out a RECORD_TYPE type (a C struct).
410 This means laying out the fields, determining their positions,
411 and computing the overall size and required alignment of the record.
412 Note that if you set the TYPE_ALIGN before calling this
413 then the struct is aligned to at least that boundary.
415 If the type has basetypes, you must call layout_basetypes
416 before calling this function.
418 The return value is a list of static members of the record.
419 They still need to be laid out. */
426 unsigned int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
427 unsigned int unpacked_align = record_align;
428 /* These must be laid out *after* the record is. */
429 tree pending_statics = NULL_TREE;
430 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
431 where CONST_SIZE is an integer
432 and VAR_SIZE is a tree expression.
433 If VAR_SIZE is null, the size is just CONST_SIZE.
434 Naturally we try to avoid using VAR_SIZE. */
435 HOST_WIDE_INT const_size = 0;
437 /* Once we start using VAR_SIZE, this is the maximum alignment
438 that we know VAR_SIZE has. */
439 unsigned int var_align = BITS_PER_UNIT;
440 int packed_maybe_necessary = 0;
442 #ifdef STRUCTURE_SIZE_BOUNDARY
443 /* Packed structures don't need to have minimum size. */
444 if (! TYPE_PACKED (rec))
445 record_align = MAX (record_align, STRUCTURE_SIZE_BOUNDARY);
448 for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
450 unsigned int known_align = var_size ? var_align : const_size;
451 unsigned int desired_align = 0;
452 tree type = TREE_TYPE (field);
454 /* If FIELD is static, then treat it like a separate variable,
455 not really like a structure field.
456 If it is a FUNCTION_DECL, it's a method.
457 In both cases, all we do is lay out the decl,
458 and we do it *after* the record is laid out. */
460 if (TREE_CODE (field) == VAR_DECL)
462 pending_statics = tree_cons (NULL_TREE, field, pending_statics);
466 /* Enumerators and enum types which are local to this class need not
467 be laid out. Likewise for initialized constant fields. */
468 if (TREE_CODE (field) != FIELD_DECL)
471 /* Lay out the field so we know what alignment it needs.
472 For a packed field, use the alignment as specified,
473 disregarding what the type would want. */
474 if (DECL_PACKED (field))
475 desired_align = DECL_ALIGN (field);
476 layout_decl (field, known_align);
477 if (! DECL_PACKED (field))
478 desired_align = DECL_ALIGN (field);
479 /* Some targets (i.e. VMS) limit struct field alignment
480 to a lower boundary than alignment of variables. */
481 #ifdef BIGGEST_FIELD_ALIGNMENT
482 desired_align = MIN (desired_align, BIGGEST_FIELD_ALIGNMENT);
484 #ifdef ADJUST_FIELD_ALIGN
485 desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
488 /* Record must have at least as much alignment as any field.
489 Otherwise, the alignment of the field within the record
492 #ifdef PCC_BITFIELD_TYPE_MATTERS
493 if (PCC_BITFIELD_TYPE_MATTERS && type != error_mark_node
494 && DECL_BIT_FIELD_TYPE (field)
495 && ! integer_zerop (TYPE_SIZE (type)))
497 /* For these machines, a zero-length field does not
498 affect the alignment of the structure as a whole.
499 It does, however, affect the alignment of the next field
500 within the structure. */
501 if (! integer_zerop (DECL_SIZE (field)))
502 record_align = MAX (record_align, desired_align);
503 else if (! DECL_PACKED (field))
504 desired_align = TYPE_ALIGN (type);
505 /* A named bit field of declared type `int'
506 forces the entire structure to have `int' alignment. */
507 if (DECL_NAME (field) != 0)
509 unsigned int type_align = TYPE_ALIGN (type);
511 if (maximum_field_alignment != 0)
512 type_align = MIN (type_align, maximum_field_alignment);
513 else if (DECL_PACKED (field))
514 type_align = MIN (type_align, BITS_PER_UNIT);
516 record_align = MAX (record_align, type_align);
518 unpacked_align = MAX (unpacked_align, TYPE_ALIGN (type));
524 record_align = MAX (record_align, desired_align);
526 unpacked_align = MAX (unpacked_align, TYPE_ALIGN (type));
529 if (warn_packed && DECL_PACKED (field))
531 if (const_size % TYPE_ALIGN (type) == 0
532 || (var_align % TYPE_ALIGN (type) == 0 && var_size != NULL_TREE))
534 if (TYPE_ALIGN (type) > desired_align)
536 if (STRICT_ALIGNMENT)
537 warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
539 warning_with_decl (field, "packed attribute is unnecessary for `%s'");
543 packed_maybe_necessary = 1;
546 /* Does this field automatically have alignment it needs
547 by virtue of the fields that precede it and the record's
550 if (const_size % desired_align != 0
551 || (var_align % desired_align != 0 && var_size != NULL_TREE))
553 /* No, we need to skip space before this field.
554 Bump the cumulative size to multiple of field alignment. */
557 warning_with_decl (field, "padding struct to align `%s'");
559 if (var_size == NULL_TREE || var_align % desired_align == 0)
561 = CEIL (const_size, desired_align) * desired_align;
565 var_size = size_binop (PLUS_EXPR, var_size,
566 bitsize_int (const_size));
568 var_size = round_up (var_size, desired_align);
569 var_align = MIN (var_align, desired_align);
573 #ifdef PCC_BITFIELD_TYPE_MATTERS
574 if (PCC_BITFIELD_TYPE_MATTERS
575 && TREE_CODE (field) == FIELD_DECL
576 && type != error_mark_node
577 && DECL_BIT_FIELD_TYPE (field)
578 && !DECL_PACKED (field)
579 && maximum_field_alignment == 0
580 && !integer_zerop (DECL_SIZE (field)))
582 unsigned int type_align = TYPE_ALIGN (type);
583 register tree dsize = DECL_SIZE (field);
584 int field_size = TREE_INT_CST_LOW (dsize);
586 /* A bit field may not span more units of alignment of its type
587 than its type itself. Advance to next boundary if necessary. */
588 if (((const_size + field_size + type_align - 1) / type_align
589 - const_size / type_align)
590 > TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (field))) / type_align)
591 const_size = CEIL (const_size, type_align) * type_align;
595 /* No existing machine description uses this parameter.
596 So I have made it in this aspect identical to PCC_BITFIELD_TYPE_MATTERS. */
597 #ifdef BITFIELD_NBYTES_LIMITED
598 if (BITFIELD_NBYTES_LIMITED
599 && TREE_CODE (field) == FIELD_DECL
600 && type != error_mark_node
601 && DECL_BIT_FIELD_TYPE (field)
602 && !DECL_PACKED (field)
603 && !integer_zerop (DECL_SIZE (field)))
605 unsigned int type_align = TYPE_ALIGN (type);
606 register tree dsize = DECL_SIZE (field);
607 int field_size = TREE_INT_CST_LOW (dsize);
609 if (maximum_field_alignment != 0)
610 type_align = MIN (type_align, maximum_field_alignment);
611 /* ??? This test is opposite the test in the containing if
612 statement, so this code is unreachable currently. */
613 else if (DECL_PACKED (field))
614 type_align = MIN (type_align, BITS_PER_UNIT);
616 /* A bit field may not span the unit of alignment of its type.
617 Advance to next boundary if necessary. */
618 /* ??? This code should match the code above for the
619 PCC_BITFIELD_TYPE_MATTERS case. */
620 if (const_size / type_align
621 != (const_size + field_size - 1) / type_align)
622 const_size = CEIL (const_size, type_align) * type_align;
626 /* Size so far becomes the position of this field. */
628 if (var_size && const_size)
629 DECL_FIELD_BITPOS (field)
630 = size_binop (PLUS_EXPR, var_size, bitsize_int (const_size));
632 DECL_FIELD_BITPOS (field) = var_size;
635 DECL_FIELD_BITPOS (field) = bitsize_int (const_size);
637 /* If this field ended up more aligned than we thought it
638 would be (we approximate this by seeing if its position
639 changed), lay out the field again; perhaps we can use an
640 integral mode for it now. */
641 if (known_align != const_size)
642 layout_decl (field, const_size);
645 /* Now add size of this field to the size of the record. */
648 register tree dsize = DECL_SIZE (field);
650 /* This can happen when we have an invalid nested struct definition,
651 such as struct j { struct j { int i; } }. The error message is
652 printed in finish_struct. */
655 else if (TREE_CODE (dsize) == INTEGER_CST
656 && ! TREE_CONSTANT_OVERFLOW (dsize)
657 && TREE_INT_CST_HIGH (dsize) == 0
658 && TREE_INT_CST_LOW (dsize) + const_size >= const_size)
659 /* Use const_size if there's no overflow. */
660 const_size += TREE_INT_CST_LOW (dsize);
663 if (var_size == NULL_TREE)
666 var_size = size_binop (PLUS_EXPR, var_size, dsize);
671 /* Work out the total size and alignment of the record
672 as one expression and store in the record type.
673 Round it up to a multiple of the record's alignment. */
675 if (var_size == NULL_TREE)
676 TYPE_SIZE (rec) = bitsize_int (const_size);
680 var_size = size_binop (PLUS_EXPR, var_size, bitsize_int (const_size));
682 TYPE_SIZE (rec) = var_size;
685 /* Determine the desired alignment. */
686 #ifdef ROUND_TYPE_ALIGN
687 TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), record_align);
689 TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), record_align);
692 /* Record the un-rounded size in the binfo node. But first we check
693 the size of TYPE_BINFO to make sure that BINFO_SIZE is available. */
694 if (TYPE_BINFO (rec) && TREE_VEC_LENGTH (TYPE_BINFO (rec)) > 6)
696 TYPE_BINFO_SIZE (rec) = TYPE_SIZE (rec);
697 TYPE_BINFO_SIZE_UNIT (rec)
699 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (rec),
700 bitsize_int (BITS_PER_UNIT)));
704 tree unpadded_size = TYPE_SIZE (rec);
706 #ifdef ROUND_TYPE_SIZE
707 TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
709 /* Round the size up to be a multiple of the required alignment */
710 TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
713 if (warn_padded && var_size == NULL_TREE
714 && simple_cst_equal (unpadded_size, TYPE_SIZE (rec)) == 0)
715 warning ("padding struct size to alignment boundary");
718 if (warn_packed && TYPE_PACKED (rec) && !packed_maybe_necessary
719 && var_size == NULL_TREE)
723 TYPE_PACKED (rec) = 0;
724 #ifdef ROUND_TYPE_ALIGN
726 = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), unpacked_align);
728 unpacked_align = MAX (TYPE_ALIGN (rec), unpacked_align);
730 #ifdef ROUND_TYPE_SIZE
731 unpacked_size = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), unpacked_align);
733 unpacked_size = round_up (TYPE_SIZE (rec), unpacked_align);
736 if (simple_cst_equal (unpacked_size, TYPE_SIZE (rec)))
742 if (TREE_CODE (TYPE_NAME (rec)) == IDENTIFIER_NODE)
743 name = IDENTIFIER_POINTER (TYPE_NAME (rec));
745 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (rec)));
746 if (STRICT_ALIGNMENT)
747 warning ("packed attribute causes inefficient alignment for `%s'", name);
749 warning ("packed attribute is unnecessary for `%s'", name);
753 if (STRICT_ALIGNMENT)
754 warning ("packed attribute causes inefficient alignment");
756 warning ("packed attribute is unnecessary");
759 TYPE_PACKED (rec) = 1;
762 return pending_statics;
765 /* Lay out a UNION_TYPE or QUAL_UNION_TYPE type.
766 Lay out all the fields, set their positions to zero,
767 and compute the size and alignment of the union (maximum of any field).
768 Note that if you set the TYPE_ALIGN before calling this
769 then the union align is aligned to at least that boundary. */
776 unsigned int union_align = BITS_PER_UNIT;
778 /* The size of the union, based on the fields scanned so far,
779 is max (CONST_SIZE, VAR_SIZE).
780 VAR_SIZE may be null; then CONST_SIZE by itself is the size. */
781 register HOST_WIDE_INT const_size = 0;
782 register tree var_size = 0;
784 #ifdef STRUCTURE_SIZE_BOUNDARY
785 /* Packed structures don't need to have minimum size. */
786 if (! TYPE_PACKED (rec))
787 union_align = STRUCTURE_SIZE_BOUNDARY;
790 /* If this is a QUAL_UNION_TYPE, we want to process the fields in
791 the reverse order in building the COND_EXPR that denotes its
792 size. We reverse them again later. */
793 if (TREE_CODE (rec) == QUAL_UNION_TYPE)
794 TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
796 for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
800 /* Enums which are local to this class need not be laid out. */
801 if (TREE_CODE (field) == CONST_DECL || TREE_CODE (field) == TYPE_DECL)
804 layout_decl (field, 0);
805 DECL_FIELD_BITPOS (field) = bitsize_int (0);
807 /* Union must be at least as aligned as any field requires. */
809 union_align = MAX (union_align, DECL_ALIGN (field));
811 #ifdef PCC_BITFIELD_TYPE_MATTERS
812 /* On the m88000, a bit field of declare type `int'
813 forces the entire union to have `int' alignment. */
814 if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
815 union_align = MAX (union_align, TYPE_ALIGN (TREE_TYPE (field)));
818 dsize = DECL_SIZE (field);
819 if (TREE_CODE (rec) == UNION_TYPE)
821 /* Set union_size to max (decl_size, union_size).
822 There are more and less general ways to do this.
823 Use only CONST_SIZE unless forced to use VAR_SIZE. */
825 if (TREE_CODE (dsize) == INTEGER_CST
826 && ! TREE_CONSTANT_OVERFLOW (dsize)
827 && TREE_INT_CST_HIGH (dsize) == 0)
829 = MAX (const_size, TREE_INT_CST_LOW (dsize));
830 else if (var_size == 0)
833 var_size = size_binop (MAX_EXPR, var_size, dsize);
835 else if (TREE_CODE (rec) == QUAL_UNION_TYPE)
836 var_size = fold (build (COND_EXPR, bitsizetype, DECL_QUALIFIER (field),
838 var_size ? var_size : bitsize_int (0)));
841 if (TREE_CODE (rec) == QUAL_UNION_TYPE)
842 TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
844 /* Determine the ultimate size of the union (in bytes). */
845 if (NULL == var_size)
847 = bitsize_int (CEIL (const_size, BITS_PER_UNIT) * BITS_PER_UNIT);
849 else if (const_size == 0)
850 TYPE_SIZE (rec) = var_size;
852 TYPE_SIZE (rec) = size_binop (MAX_EXPR, var_size,
853 round_up (bitsize_int (const_size),
856 /* Determine the desired alignment. */
857 #ifdef ROUND_TYPE_ALIGN
858 TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), union_align);
860 TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), union_align);
863 #ifdef ROUND_TYPE_SIZE
864 TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
866 /* Round the size up to be a multiple of the required alignment */
867 TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
871 /* Calculate the mode, size, and alignment for TYPE.
872 For an array type, calculate the element separation as well.
873 Record TYPE on the chain of permanent or temporary types
874 so that dbxout will find out about it.
876 TYPE_SIZE of a type is nonzero if the type has been laid out already.
877 layout_type does nothing on such a type.
879 If the type is incomplete, its TYPE_SIZE remains zero. */
886 tree pending_statics;
891 /* Do nothing if type has been laid out before. */
892 if (TYPE_SIZE (type))
895 /* Make sure all nodes we allocate are not momentary;
896 they must last past the current statement. */
897 old = suspend_momentary ();
899 /* Put all our nodes into the same obstack as the type. Also,
900 make expressions saveable (this is a no-op for permanent types). */
902 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
903 saveable_allocation ();
905 switch (TREE_CODE (type))
908 /* This kind of type is the responsibility
909 of the language-specific code. */
912 case BOOLEAN_TYPE: /* Used for Java, Pascal, and Chill. */
913 if (TYPE_PRECISION (type) == 0)
914 TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
916 /* ... fall through ... */
921 if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
922 && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
923 TREE_UNSIGNED (type) = 1;
925 TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
927 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
928 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
932 TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
933 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
934 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
938 TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
940 = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
941 (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
942 ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
944 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
945 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
949 TYPE_SIZE (type) = size_zero_node;
950 TYPE_SIZE_UNIT (type) = size_zero_node;
951 TYPE_ALIGN (type) = 1;
952 TYPE_MODE (type) = VOIDmode;
956 TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
957 TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
958 TYPE_MODE (type) = ptr_mode;
963 TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
964 TYPE_SIZE (type) = bitsize_int (2 * POINTER_SIZE);
965 TYPE_SIZE_UNIT (type) = size_int ((2 * POINTER_SIZE) / BITS_PER_UNIT);
970 TYPE_MODE (type) = ptr_mode;
971 TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
972 TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
973 TREE_UNSIGNED (type) = 1;
974 TYPE_PRECISION (type) = POINTER_SIZE;
979 register tree index = TYPE_DOMAIN (type);
980 register tree element = TREE_TYPE (type);
982 build_pointer_type (element);
984 /* We need to know both bounds in order to compute the size. */
985 if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
986 && TYPE_SIZE (element))
988 tree ub = TYPE_MAX_VALUE (index);
989 tree lb = TYPE_MIN_VALUE (index);
993 /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
994 test for negative below covers it. */
995 if (TREE_CODE (ub) == MAX_EXPR
996 && TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
997 && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
998 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
1000 ub = TREE_OPERAND (ub, 1);
1001 else if (TREE_CODE (ub) == MAX_EXPR
1002 && TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
1003 && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
1004 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
1007 ub = TREE_OPERAND (ub, 0);
1009 /* The initial subtraction should happen in the original type so
1010 that (possible) negative values are handled appropriately. */
1011 length = size_binop (PLUS_EXPR, size_one_node,
1013 fold (build (MINUS_EXPR,
1017 /* If neither bound is a constant and sizetype is signed, make
1018 sure the size is never negative. We should really do this
1019 if *either* bound is non-constant, but this is the best
1020 compromise between C and Ada. */
1021 if (! TREE_UNSIGNED (sizetype)
1022 && TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
1023 && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
1024 length = size_binop (MAX_EXPR, length, size_zero_node);
1026 /* Special handling for arrays of bits (for Chill). */
1027 element_size = TYPE_SIZE (element);
1028 if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element))
1030 HOST_WIDE_INT maxvalue
1031 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (element));
1032 HOST_WIDE_INT minvalue
1033 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (element));
1035 if (maxvalue - minvalue == 1
1036 && (maxvalue == 1 || maxvalue == 0))
1037 element_size = integer_one_node;
1040 TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
1041 convert (bitsizetype, length));
1043 /* If we know the size of the element, calculate the total
1044 size directly, rather than do some division thing below.
1045 This optimization helps Fortran assumed-size arrays
1046 (where the size of the array is determined at runtime)
1048 Note that we can't do this in the case where the size of
1049 the elements is one bit since TYPE_SIZE_UNIT cannot be
1050 set correctly in that case. */
1051 if (TYPE_SIZE_UNIT (element) != 0 && ! integer_onep (element_size))
1052 TYPE_SIZE_UNIT (type)
1053 = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length);
1056 /* Now round the alignment and size,
1057 using machine-dependent criteria if any. */
1059 #ifdef ROUND_TYPE_ALIGN
1061 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
1063 TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
1066 #ifdef ROUND_TYPE_SIZE
1067 if (TYPE_SIZE (type) != 0)
1070 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1072 /* If the rounding changed the size of the type, remove any
1073 pre-calculated TYPE_SIZE_UNIT. */
1074 if (simple_cst_equal (TYPE_SIZE (type), tmp) != 1)
1075 TYPE_SIZE_UNIT (type) = NULL;
1077 TYPE_SIZE (type) = tmp;
1081 TYPE_MODE (type) = BLKmode;
1082 if (TYPE_SIZE (type) != 0
1083 /* BLKmode elements force BLKmode aggregate;
1084 else extract/store fields may lose. */
1085 && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
1086 || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
1089 = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1091 if (TYPE_MODE (type) != BLKmode
1092 && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
1093 && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type))
1094 && TYPE_MODE (type) != BLKmode)
1096 TYPE_NO_FORCE_BLK (type) = 1;
1097 TYPE_MODE (type) = BLKmode;
1104 pending_statics = layout_record (type);
1105 TYPE_MODE (type) = BLKmode;
1106 if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
1109 enum machine_mode mode = VOIDmode;
1111 /* A record which has any BLKmode members must itself be BLKmode;
1112 it can't go in a register.
1113 Unless the member is BLKmode only because it isn't aligned. */
1114 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1118 if (TREE_CODE (field) != FIELD_DECL
1119 || TREE_CODE (TREE_TYPE (field)) == ERROR_MARK)
1122 if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1123 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
1126 if (TREE_CODE (DECL_FIELD_BITPOS (field)) != INTEGER_CST)
1129 bitpos = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
1131 /* Must be BLKmode if any field crosses a word boundary,
1132 since extract_bit_field can't handle that in registers. */
1133 if (bitpos / BITS_PER_WORD
1134 != ((TREE_INT_CST_LOW (DECL_SIZE (field)) + bitpos - 1)
1136 /* But there is no problem if the field is entire words. */
1137 && TREE_INT_CST_LOW (DECL_SIZE (field)) % BITS_PER_WORD != 0)
1140 /* If this field is the whole struct, remember its mode so
1141 that, say, we can put a double in a class into a DF
1142 register instead of forcing it to live in the stack. */
1143 if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
1144 mode = DECL_MODE (field);
1146 #ifdef STRUCT_FORCE_BLK
1147 /* With some targets, eg. c4x, it is sub-optimal
1148 to access an aligned BLKmode structure as a scalar. */
1149 if (mode == VOIDmode && STRUCT_FORCE_BLK (field))
1151 #endif /* STRUCT_FORCE_BLK */
1154 if (mode != VOIDmode)
1155 /* We only have one real field; use its mode. */
1156 TYPE_MODE (type) = mode;
1159 = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1161 /* If structure's known alignment is less than
1162 what the scalar mode would need, and it matters,
1163 then stick with BLKmode. */
1164 if (TYPE_MODE (type) != BLKmode
1166 && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1167 || (TYPE_ALIGN (type) >=
1168 GET_MODE_ALIGNMENT (TYPE_MODE (type)))))
1170 /* If this is the only reason this type is BLKmode,
1171 then don't force containing types to be BLKmode. */
1172 TYPE_NO_FORCE_BLK (type) = 1;
1173 TYPE_MODE (type) = BLKmode;
1179 /* Lay out any static members. This is done now
1180 because their type may use the record's type. */
1181 while (pending_statics)
1183 layout_decl (TREE_VALUE (pending_statics), 0);
1184 pending_statics = TREE_CHAIN (pending_statics);
1189 case QUAL_UNION_TYPE:
1190 layout_union (type);
1191 TYPE_MODE (type) = BLKmode;
1192 if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1193 /* If structure's known alignment is less than
1194 what the scalar mode would need, and it matters,
1195 then stick with BLKmode. */
1196 && (! STRICT_ALIGNMENT
1197 || TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1198 || ((int) TYPE_ALIGN (type)
1199 >= TREE_INT_CST_LOW (TYPE_SIZE (type)))))
1203 /* A union which has any BLKmode members must itself be BLKmode;
1204 it can't go in a register.
1205 Unless the member is BLKmode only because it isn't aligned. */
1206 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1208 if (TREE_CODE (field) != FIELD_DECL)
1211 if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1212 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
1217 = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1223 case SET_TYPE: /* Used by Chill and Pascal. */
1224 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
1225 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
1229 #ifndef SET_WORD_SIZE
1230 #define SET_WORD_SIZE BITS_PER_WORD
1232 unsigned int alignment
1233 = set_alignment ? set_alignment : SET_WORD_SIZE;
1235 = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1236 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
1238 = ((size_in_bits + alignment - 1) / alignment) * alignment;
1240 if (rounded_size > (int) alignment)
1241 TYPE_MODE (type) = BLKmode;
1243 TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
1245 TYPE_SIZE (type) = bitsize_int (rounded_size);
1246 TYPE_SIZE_UNIT (type) = size_int (rounded_size / BITS_PER_UNIT);
1247 TYPE_ALIGN (type) = alignment;
1248 TYPE_PRECISION (type) = size_in_bits;
1253 /* The size may vary in different languages, so the language front end
1254 should fill in the size. */
1255 TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
1256 TYPE_MODE (type) = BLKmode;
1263 /* Normally, use the alignment corresponding to the mode chosen.
1264 However, where strict alignment is not required, avoid
1265 over-aligning structures, since most compilers do not do this
1268 if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1269 && (STRICT_ALIGNMENT
1270 || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1271 && TREE_CODE (type) != QUAL_UNION_TYPE
1272 && TREE_CODE (type) != ARRAY_TYPE)))
1273 TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1275 /* Do machine-dependent extra alignment. */
1276 #ifdef ROUND_TYPE_ALIGN
1278 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (type), BITS_PER_UNIT);
1281 #ifdef ROUND_TYPE_SIZE
1282 if (TYPE_SIZE (type) != 0)
1284 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1287 /* Evaluate nonconstant size only once, either now or as soon as safe. */
1288 if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1289 TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1291 /* If we failed to find a simple way to calculate the unit size
1292 of the type above, find it by division. */
1293 if (TYPE_SIZE_UNIT (type) == 0 && TYPE_SIZE (type) != 0)
1294 /* TYPE_SIZE (type) is computed in bitsizetype. After the division, the
1295 result will fit in sizetype. We will get more efficient code using
1296 sizetype, so we force a conversion. */
1297 TYPE_SIZE_UNIT (type)
1298 = convert (sizetype,
1299 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type),
1300 bitsize_int (BITS_PER_UNIT)));
1302 /* Once again evaluate only once, either now or as soon as safe. */
1303 if (TYPE_SIZE_UNIT (type) != 0
1304 && TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
1305 TYPE_SIZE_UNIT (type) = variable_size (TYPE_SIZE_UNIT (type));
1307 /* Also layout any other variants of the type. */
1308 if (TYPE_NEXT_VARIANT (type)
1309 || type != TYPE_MAIN_VARIANT (type))
1312 /* Record layout info of this variant. */
1313 tree size = TYPE_SIZE (type);
1314 tree size_unit = TYPE_SIZE_UNIT (type);
1315 unsigned int align = TYPE_ALIGN (type);
1316 enum machine_mode mode = TYPE_MODE (type);
1318 /* Copy it into all variants. */
1319 for (variant = TYPE_MAIN_VARIANT (type);
1321 variant = TYPE_NEXT_VARIANT (variant))
1323 TYPE_SIZE (variant) = size;
1324 TYPE_SIZE_UNIT (variant) = size_unit;
1325 TYPE_ALIGN (variant) = align;
1326 TYPE_MODE (variant) = mode;
1331 resume_momentary (old);
1333 /* If this type is created before sizetype has been permanently set,
1334 record it so set_sizetype can fix it up. */
1337 TREE_CHAIN (type) = early_type_list;
1338 early_type_list = type;
1342 /* Create and return a type for signed integers of PRECISION bits. */
1345 make_signed_type (precision)
1348 register tree type = make_node (INTEGER_TYPE);
1350 TYPE_PRECISION (type) = precision;
1352 fixup_signed_type (type);
1356 /* Create and return a type for unsigned integers of PRECISION bits. */
1359 make_unsigned_type (precision)
1362 register tree type = make_node (INTEGER_TYPE);
1364 TYPE_PRECISION (type) = precision;
1366 fixup_unsigned_type (type);
1370 /* Initialize sizetype and bitsizetype to a reasonable and temporary
1371 value to enable integer types to be created. */
1374 initialize_sizetypes ()
1376 tree t = make_node (INTEGER_TYPE);
1378 /* Set this so we do something reasonable for the build_int_2 calls
1380 integer_type_node = t;
1382 TYPE_MODE (t) = SImode;
1383 TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
1384 TYPE_SIZE (t) = build_int_2 (GET_MODE_BITSIZE (SImode), 0);
1385 TYPE_SIZE_UNIT (t) = build_int_2 (GET_MODE_SIZE (SImode), 0);
1386 TREE_UNSIGNED (t) = 1;
1387 TYPE_PRECISION (t) = GET_MODE_BITSIZE (SImode);
1388 TYPE_MIN_VALUE (t) = build_int_2 (0, 0);
1390 /* 1000 avoids problems with possible overflow and is certainly
1391 larger than any size value we'd want to be storing. */
1392 TYPE_MAX_VALUE (t) = build_int_2 (1000, 0);
1394 /* These two must be different nodes because of the caching done in
1397 bitsizetype = copy_node (t);
1398 integer_type_node = 0;
1401 /* Set sizetype to TYPE, and initialize *sizetype accordingly.
1402 Also update the type of any standard type's sizes made so far. */
1408 int oprecision = TYPE_PRECISION (type);
1409 /* The *bitsizetype types use a precision that avoids overflows when
1410 calculating signed sizes / offsets in bits. However, when
1411 cross-compiling from a 32 bit to a 64 bit host, we are limited to 64 bit
1413 int precision = MIN (oprecision + BITS_PER_UNIT_LOG + 1,
1414 2 * HOST_BITS_PER_WIDE_INT);
1421 /* Make copies of nodes since we'll be setting TYPE_IS_SIZETYPE. */
1422 sizetype = copy_node (type);
1423 TYPE_DOMAIN (sizetype) = type;
1424 bitsizetype = make_node (INTEGER_TYPE);
1425 TYPE_NAME (bitsizetype) = TYPE_NAME (type);
1426 TYPE_PRECISION (bitsizetype) = precision;
1428 if (TREE_UNSIGNED (type))
1429 fixup_unsigned_type (bitsizetype);
1431 fixup_signed_type (bitsizetype);
1433 layout_type (bitsizetype);
1435 if (TREE_UNSIGNED (type))
1437 usizetype = sizetype;
1438 ubitsizetype = bitsizetype;
1439 ssizetype = copy_node (make_signed_type (oprecision));
1440 sbitsizetype = copy_node (make_signed_type (precision));
1444 ssizetype = sizetype;
1445 sbitsizetype = bitsizetype;
1446 usizetype = copy_node (make_unsigned_type (oprecision));
1447 ubitsizetype = copy_node (make_unsigned_type (precision));
1450 TYPE_NAME (bitsizetype) = get_identifier ("bit_size_type");
1452 /* Show is a sizetype, is a main type, and has no pointers to it. */
1453 for (i = 0; i < sizeof sizetype_tab / sizeof sizetype_tab[0]; i++)
1455 TYPE_IS_SIZETYPE (sizetype_tab[i]) = 1;
1456 TYPE_MAIN_VARIANT (sizetype_tab[i]) = sizetype_tab[i];
1457 TYPE_NEXT_VARIANT (sizetype_tab[i]) = 0;
1458 TYPE_POINTER_TO (sizetype_tab[i]) = 0;
1459 TYPE_REFERENCE_TO (sizetype_tab[i]) = 0;
1462 ggc_add_tree_root ((tree *) &sizetype_tab,
1463 sizeof sizetype_tab / sizeof (tree));
1465 /* Go down each of the types we already made and set the proper type
1466 for the sizes in them. */
1467 for (t = early_type_list; t != 0; t = next)
1469 next = TREE_CHAIN (t);
1472 if (TREE_CODE (t) != INTEGER_TYPE)
1475 TREE_TYPE (TYPE_SIZE (t)) = bitsizetype;
1476 TREE_TYPE (TYPE_SIZE_UNIT (t)) = sizetype;
1479 early_type_list = 0;
1483 /* Set the extreme values of TYPE based on its precision in bits,
1484 then lay it out. Used when make_signed_type won't do
1485 because the tree code is not INTEGER_TYPE.
1486 E.g. for Pascal, when the -fsigned-char option is given. */
1489 fixup_signed_type (type)
1492 register int precision = TYPE_PRECISION (type);
1494 TYPE_MIN_VALUE (type)
1495 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1496 ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1497 (((HOST_WIDE_INT) (-1)
1498 << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1499 ? precision - HOST_BITS_PER_WIDE_INT - 1
1501 TYPE_MAX_VALUE (type)
1502 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1503 ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1504 (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1505 ? (((HOST_WIDE_INT) 1
1506 << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1509 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1510 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1512 /* Lay out the type: set its alignment, size, etc. */
1516 /* Set the extreme values of TYPE based on its precision in bits,
1517 then lay it out. This is used both in `make_unsigned_type'
1518 and for enumeral types. */
1521 fixup_unsigned_type (type)
1524 register int precision = TYPE_PRECISION (type);
1526 TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1527 TYPE_MAX_VALUE (type)
1528 = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1529 ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1530 precision - HOST_BITS_PER_WIDE_INT > 0
1531 ? ((unsigned HOST_WIDE_INT) ~0
1532 >> (HOST_BITS_PER_WIDE_INT
1533 - (precision - HOST_BITS_PER_WIDE_INT)))
1535 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1536 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1538 /* Lay out the type: set its alignment, size, etc. */
1542 /* Find the best machine mode to use when referencing a bit field of length
1543 BITSIZE bits starting at BITPOS.
1545 The underlying object is known to be aligned to a boundary of ALIGN bits.
1546 If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1547 larger than LARGEST_MODE (usually SImode).
1549 If no mode meets all these conditions, we return VOIDmode. Otherwise, if
1550 VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1551 mode meeting these conditions.
1553 Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1554 the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1555 all the conditions. */
1558 get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1559 int bitsize, bitpos;
1561 enum machine_mode largest_mode;
1564 enum machine_mode mode;
1567 /* Find the narrowest integer mode that contains the bit field. */
1568 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1569 mode = GET_MODE_WIDER_MODE (mode))
1571 unit = GET_MODE_BITSIZE (mode);
1572 if ((bitpos % unit) + bitsize <= unit)
1576 if (mode == VOIDmode
1577 /* It is tempting to omit the following line
1578 if STRICT_ALIGNMENT is true.
1579 But that is incorrect, since if the bitfield uses part of 3 bytes
1580 and we use a 4-byte mode, we could get a spurious segv
1581 if the extra 4th byte is past the end of memory.
1582 (Though at least one Unix compiler ignores this problem:
1583 that on the Sequent 386 machine. */
1584 || MIN (unit, BIGGEST_ALIGNMENT) > (int) align
1585 || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1588 if (SLOW_BYTE_ACCESS && ! volatilep)
1590 enum machine_mode wide_mode = VOIDmode, tmode;
1592 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1593 tmode = GET_MODE_WIDER_MODE (tmode))
1595 unit = GET_MODE_BITSIZE (tmode);
1596 if (bitpos / unit == (bitpos + bitsize - 1) / unit
1597 && unit <= BITS_PER_WORD
1598 && unit <= (int) MIN (align, BIGGEST_ALIGNMENT)
1599 && (largest_mode == VOIDmode
1600 || unit <= GET_MODE_BITSIZE (largest_mode)))
1604 if (wide_mode != VOIDmode)
1611 /* Return the alignment of MODE. This will be bounded by 1 and
1612 BIGGEST_ALIGNMENT. */
1615 get_mode_alignment (mode)
1616 enum machine_mode mode;
1618 unsigned alignment = GET_MODE_UNIT_SIZE (mode);
1620 /* Extract the LSB of the size. */
1621 alignment = alignment & -alignment;
1623 alignment *= BITS_PER_UNIT;
1625 alignment = MIN (BIGGEST_ALIGNMENT, MAX (1, alignment));
1629 /* This function is run once to initialize stor-layout.c. */
1632 init_stor_layout_once ()
1634 ggc_add_tree_root (&pending_sizes, 1);