Pass pointer to RTX when calling alter_subreg().
[official-gcc.git] / gcc / stor-layout.c
bloba3d122f050042168c987402695db4f32c7d60dda
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, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "tm_p.h"
28 #include "flags.h"
29 #include "function.h"
30 #include "expr.h"
31 #include "toplev.h"
32 #include "ggc.h"
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 /* Nonzero if all REFERENCE_TYPEs are internal and hence should be
54 allocated in Pmode, not ptr_mode. Set only by internal_reference_types
55 called only by a front end. */
56 static int reference_types_internal = 0;
58 static void finalize_record_size PARAMS ((record_layout_info));
59 static void finalize_type_size PARAMS ((tree));
60 static void place_union_field PARAMS ((record_layout_info, tree));
61 extern void debug_rli PARAMS ((record_layout_info));
63 /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded. */
65 static tree pending_sizes;
67 /* Nonzero means cannot safely call expand_expr now,
68 so put variable sizes onto `pending_sizes' instead. */
70 int immediate_size_expand;
72 /* Show that REFERENCE_TYPES are internal and should be Pmode. Called only
73 by front end. */
75 void
76 internal_reference_types ()
78 reference_types_internal = 1;
81 /* Get a list of all the objects put on the pending sizes list. */
83 tree
84 get_pending_sizes ()
86 tree chain = pending_sizes;
87 tree t;
89 /* Put each SAVE_EXPR into the current function. */
90 for (t = chain; t; t = TREE_CHAIN (t))
91 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = current_function_decl;
93 pending_sizes = 0;
94 return chain;
97 /* Return non-zero if EXPR is present on the pending sizes list. */
99 int
100 is_pending_size (expr)
101 tree expr;
103 tree t;
105 for (t = pending_sizes; t; t = TREE_CHAIN (t))
106 if (TREE_VALUE (t) == expr)
107 return 1;
108 return 0;
111 /* Add EXPR to the pending sizes list. */
113 void
114 put_pending_size (expr)
115 tree expr;
117 /* Strip any simple arithmetic from EXPR to see if it has an underlying
118 SAVE_EXPR. */
119 while (TREE_CODE_CLASS (TREE_CODE (expr)) == '1'
120 || (TREE_CODE_CLASS (TREE_CODE (expr)) == '2'
121 && TREE_CONSTANT (TREE_OPERAND (expr, 1))))
122 expr = TREE_OPERAND (expr, 0);
124 if (TREE_CODE (expr) == SAVE_EXPR)
125 pending_sizes = tree_cons (NULL_TREE, expr, pending_sizes);
128 /* Put a chain of objects into the pending sizes list, which must be
129 empty. */
131 void
132 put_pending_sizes (chain)
133 tree chain;
135 if (pending_sizes)
136 abort ();
138 pending_sizes = chain;
141 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
142 to serve as the actual size-expression for a type or decl. */
144 tree
145 variable_size (size)
146 tree size;
148 /* If the language-processor is to take responsibility for variable-sized
149 items (e.g., languages which have elaboration procedures like Ada),
150 just return SIZE unchanged. Likewise for self-referential sizes and
151 constant sizes. */
152 if (TREE_CONSTANT (size)
153 || global_bindings_p () < 0 || contains_placeholder_p (size))
154 return size;
156 size = save_expr (size);
158 /* If an array with a variable number of elements is declared, and
159 the elements require destruction, we will emit a cleanup for the
160 array. That cleanup is run both on normal exit from the block
161 and in the exception-handler for the block. Normally, when code
162 is used in both ordinary code and in an exception handler it is
163 `unsaved', i.e., all SAVE_EXPRs are recalculated. However, we do
164 not wish to do that here; the array-size is the same in both
165 places. */
166 if (TREE_CODE (size) == SAVE_EXPR)
167 SAVE_EXPR_PERSISTENT_P (size) = 1;
169 if (global_bindings_p ())
171 if (TREE_CONSTANT (size))
172 error ("type size can't be explicitly evaluated");
173 else
174 error ("variable-size type declared outside of any function");
176 return size_one_node;
179 if (immediate_size_expand)
180 /* NULL_RTX is not defined; neither is the rtx type.
181 Also, we would like to pass const0_rtx here, but don't have it. */
182 expand_expr (size, expand_expr (integer_zero_node, NULL_RTX, VOIDmode, 0),
183 VOIDmode, 0);
184 else if (cfun != 0 && cfun->x_dont_save_pending_sizes_p)
185 /* The front-end doesn't want us to keep a list of the expressions
186 that determine sizes for variable size objects. */
188 else
189 put_pending_size (size);
191 return size;
194 #ifndef MAX_FIXED_MODE_SIZE
195 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
196 #endif
198 /* Return the machine mode to use for a nonscalar of SIZE bits.
199 The mode must be in class CLASS, and have exactly that many bits.
200 If LIMIT is nonzero, modes of wider than MAX_FIXED_MODE_SIZE will not
201 be used. */
203 enum machine_mode
204 mode_for_size (size, class, limit)
205 unsigned int size;
206 enum mode_class class;
207 int limit;
209 enum machine_mode mode;
211 if (limit && size > MAX_FIXED_MODE_SIZE)
212 return BLKmode;
214 /* Get the first mode which has this size, in the specified class. */
215 for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
216 mode = GET_MODE_WIDER_MODE (mode))
217 if (GET_MODE_BITSIZE (mode) == size)
218 return mode;
220 return BLKmode;
223 /* Similar, except passed a tree node. */
225 enum machine_mode
226 mode_for_size_tree (size, class, limit)
227 tree size;
228 enum mode_class class;
229 int limit;
231 if (TREE_CODE (size) != INTEGER_CST
232 /* What we really want to say here is that the size can fit in a
233 host integer, but we know there's no way we'd find a mode for
234 this many bits, so there's no point in doing the precise test. */
235 || compare_tree_int (size, 1000) > 0)
236 return BLKmode;
237 else
238 return mode_for_size (TREE_INT_CST_LOW (size), class, limit);
241 /* Similar, but never return BLKmode; return the narrowest mode that
242 contains at least the requested number of bits. */
244 enum machine_mode
245 smallest_mode_for_size (size, class)
246 unsigned int size;
247 enum mode_class class;
249 enum machine_mode mode;
251 /* Get the first mode which has at least this size, in the
252 specified class. */
253 for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
254 mode = GET_MODE_WIDER_MODE (mode))
255 if (GET_MODE_BITSIZE (mode) >= size)
256 return mode;
258 abort ();
261 /* Find an integer mode of the exact same size, or BLKmode on failure. */
263 enum machine_mode
264 int_mode_for_mode (mode)
265 enum machine_mode mode;
267 switch (GET_MODE_CLASS (mode))
269 case MODE_INT:
270 case MODE_PARTIAL_INT:
271 break;
273 case MODE_COMPLEX_INT:
274 case MODE_COMPLEX_FLOAT:
275 case MODE_FLOAT:
276 case MODE_VECTOR_INT:
277 case MODE_VECTOR_FLOAT:
278 mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
279 break;
281 case MODE_RANDOM:
282 if (mode == BLKmode)
283 break;
285 /* ... fall through ... */
287 case MODE_CC:
288 default:
289 abort ();
292 return mode;
295 /* Return the value of VALUE, rounded up to a multiple of DIVISOR.
296 This can only be applied to objects of a sizetype. */
298 tree
299 round_up (value, divisor)
300 tree value;
301 int divisor;
303 tree arg = size_int_type (divisor, TREE_TYPE (value));
305 return size_binop (MULT_EXPR, size_binop (CEIL_DIV_EXPR, value, arg), arg);
308 /* Likewise, but round down. */
310 tree
311 round_down (value, divisor)
312 tree value;
313 int divisor;
315 tree arg = size_int_type (divisor, TREE_TYPE (value));
317 return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg);
320 /* Set the size, mode and alignment of a ..._DECL node.
321 TYPE_DECL does need this for C++.
322 Note that LABEL_DECL and CONST_DECL nodes do not need this,
323 and FUNCTION_DECL nodes have them set up in a special (and simple) way.
324 Don't call layout_decl for them.
326 KNOWN_ALIGN is the amount of alignment we can assume this
327 decl has with no special effort. It is relevant only for FIELD_DECLs
328 and depends on the previous fields.
329 All that matters about KNOWN_ALIGN is which powers of 2 divide it.
330 If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
331 the record will be aligned to suit. */
333 void
334 layout_decl (decl, known_align)
335 tree decl;
336 unsigned int known_align;
338 tree type = TREE_TYPE (decl);
339 enum tree_code code = TREE_CODE (decl);
341 if (code == CONST_DECL)
342 return;
343 else if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
344 && code != TYPE_DECL && code != FIELD_DECL)
345 abort ();
347 if (type == error_mark_node)
348 type = void_type_node;
350 /* Usually the size and mode come from the data type without change,
351 however, the front-end may set the explicit width of the field, so its
352 size may not be the same as the size of its type. This happens with
353 bitfields, of course (an `int' bitfield may be only 2 bits, say), but it
354 also happens with other fields. For example, the C++ front-end creates
355 zero-sized fields corresponding to empty base classes, and depends on
356 layout_type setting DECL_FIELD_BITPOS correctly for the field. Set the
357 size in bytes from the size in bits. If we have already set the mode,
358 don't set it again since we can be called twice for FIELD_DECLs. */
360 TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
361 if (DECL_MODE (decl) == VOIDmode)
362 DECL_MODE (decl) = TYPE_MODE (type);
364 if (DECL_SIZE (decl) == 0)
366 DECL_SIZE (decl) = TYPE_SIZE (type);
367 DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
369 else
370 DECL_SIZE_UNIT (decl)
371 = convert (sizetype, size_binop (CEIL_DIV_EXPR, DECL_SIZE (decl),
372 bitsize_unit_node));
374 /* Force alignment required for the data type.
375 But if the decl itself wants greater alignment, don't override that.
376 Likewise, if the decl is packed, don't override it. */
377 if (! (code == FIELD_DECL && DECL_BIT_FIELD (decl))
378 && (DECL_ALIGN (decl) == 0
379 || (! (code == FIELD_DECL && DECL_PACKED (decl))
380 && TYPE_ALIGN (type) > DECL_ALIGN (decl))))
382 DECL_ALIGN (decl) = TYPE_ALIGN (type);
383 DECL_USER_ALIGN (decl) = 0;
386 /* For fields, set the bit field type and update the alignment. */
387 if (code == FIELD_DECL)
389 DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
390 if (maximum_field_alignment != 0)
391 DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
392 else if (DECL_PACKED (decl))
394 DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
395 DECL_USER_ALIGN (decl) = 0;
399 /* See if we can use an ordinary integer mode for a bit-field.
400 Conditions are: a fixed size that is correct for another mode
401 and occupying a complete byte or bytes on proper boundary. */
402 if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
403 && TYPE_SIZE (type) != 0
404 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
405 && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
407 enum machine_mode xmode
408 = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
410 if (xmode != BLKmode && known_align >= GET_MODE_ALIGNMENT (xmode))
412 DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
413 DECL_ALIGN (decl));
414 DECL_MODE (decl) = xmode;
415 DECL_BIT_FIELD (decl) = 0;
419 /* Turn off DECL_BIT_FIELD if we won't need it set. */
420 if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
421 && TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
422 && known_align >= TYPE_ALIGN (type)
423 && DECL_ALIGN (decl) >= TYPE_ALIGN (type)
424 && DECL_SIZE_UNIT (decl) != 0)
425 DECL_BIT_FIELD (decl) = 0;
427 /* Evaluate nonconstant size only once, either now or as soon as safe. */
428 if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
429 DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
430 if (DECL_SIZE_UNIT (decl) != 0
431 && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST)
432 DECL_SIZE_UNIT (decl) = variable_size (DECL_SIZE_UNIT (decl));
434 /* If requested, warn about definitions of large data objects. */
435 if (warn_larger_than
436 && (code == VAR_DECL || code == PARM_DECL)
437 && ! DECL_EXTERNAL (decl))
439 tree size = DECL_SIZE_UNIT (decl);
441 if (size != 0 && TREE_CODE (size) == INTEGER_CST
442 && compare_tree_int (size, larger_than_size) > 0)
444 unsigned int size_as_int = TREE_INT_CST_LOW (size);
446 if (compare_tree_int (size, size_as_int) == 0)
447 warning_with_decl (decl, "size of `%s' is %d bytes", size_as_int);
448 else
449 warning_with_decl (decl, "size of `%s' is larger than %d bytes",
450 larger_than_size);
455 /* Hook for a front-end function that can modify the record layout as needed
456 immediately before it is finalized. */
458 void (*lang_adjust_rli) PARAMS ((record_layout_info)) = 0;
460 void
461 set_lang_adjust_rli (f)
462 void (*f) PARAMS ((record_layout_info));
464 lang_adjust_rli = f;
467 /* Begin laying out type T, which may be a RECORD_TYPE, UNION_TYPE, or
468 QUAL_UNION_TYPE. Return a pointer to a struct record_layout_info which
469 is to be passed to all other layout functions for this record. It is the
470 responsibility of the caller to call `free' for the storage returned.
471 Note that garbage collection is not permitted until we finish laying
472 out the record. */
474 record_layout_info
475 start_record_layout (t)
476 tree t;
478 record_layout_info rli
479 = (record_layout_info) xmalloc (sizeof (struct record_layout_info_s));
481 rli->t = t;
483 /* If the type has a minimum specified alignment (via an attribute
484 declaration, for example) use it -- otherwise, start with a
485 one-byte alignment. */
486 rli->record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
487 rli->unpacked_align = rli->unpadded_align = rli->record_align;
488 rli->offset_align = MAX (rli->record_align, BIGGEST_ALIGNMENT);
490 #ifdef STRUCTURE_SIZE_BOUNDARY
491 /* Packed structures don't need to have minimum size. */
492 if (! TYPE_PACKED (t))
493 rli->record_align = MAX (rli->record_align, STRUCTURE_SIZE_BOUNDARY);
494 #endif
496 rli->offset = size_zero_node;
497 rli->bitpos = bitsize_zero_node;
498 rli->pending_statics = 0;
499 rli->packed_maybe_necessary = 0;
501 return rli;
504 /* These four routines perform computations that convert between
505 the offset/bitpos forms and byte and bit offsets. */
507 tree
508 bit_from_pos (offset, bitpos)
509 tree offset, bitpos;
511 return size_binop (PLUS_EXPR, bitpos,
512 size_binop (MULT_EXPR, convert (bitsizetype, offset),
513 bitsize_unit_node));
516 tree
517 byte_from_pos (offset, bitpos)
518 tree offset, bitpos;
520 return size_binop (PLUS_EXPR, offset,
521 convert (sizetype,
522 size_binop (TRUNC_DIV_EXPR, bitpos,
523 bitsize_unit_node)));
526 void
527 pos_from_byte (poffset, pbitpos, off_align, pos)
528 tree *poffset, *pbitpos;
529 unsigned int off_align;
530 tree pos;
532 *poffset
533 = size_binop (MULT_EXPR,
534 convert (sizetype,
535 size_binop (FLOOR_DIV_EXPR, pos,
536 bitsize_int (off_align
537 / BITS_PER_UNIT))),
538 size_int (off_align / BITS_PER_UNIT));
539 *pbitpos = size_binop (MULT_EXPR,
540 size_binop (FLOOR_MOD_EXPR, pos,
541 bitsize_int (off_align / BITS_PER_UNIT)),
542 bitsize_unit_node);
545 void
546 pos_from_bit (poffset, pbitpos, off_align, pos)
547 tree *poffset, *pbitpos;
548 unsigned int off_align;
549 tree pos;
551 *poffset = size_binop (MULT_EXPR,
552 convert (sizetype,
553 size_binop (FLOOR_DIV_EXPR, pos,
554 bitsize_int (off_align))),
555 size_int (off_align / BITS_PER_UNIT));
556 *pbitpos = size_binop (FLOOR_MOD_EXPR, pos, bitsize_int (off_align));
559 /* Given a pointer to bit and byte offsets and an offset alignment,
560 normalize the offsets so they are within the alignment. */
562 void
563 normalize_offset (poffset, pbitpos, off_align)
564 tree *poffset, *pbitpos;
565 unsigned int off_align;
567 /* If the bit position is now larger than it should be, adjust it
568 downwards. */
569 if (compare_tree_int (*pbitpos, off_align) >= 0)
571 tree extra_aligns = size_binop (FLOOR_DIV_EXPR, *pbitpos,
572 bitsize_int (off_align));
574 *poffset
575 = size_binop (PLUS_EXPR, *poffset,
576 size_binop (MULT_EXPR, convert (sizetype, extra_aligns),
577 size_int (off_align / BITS_PER_UNIT)));
579 *pbitpos
580 = size_binop (FLOOR_MOD_EXPR, *pbitpos, bitsize_int (off_align));
584 /* Print debugging information about the information in RLI. */
586 void
587 debug_rli (rli)
588 record_layout_info rli;
590 print_node_brief (stderr, "type", rli->t, 0);
591 print_node_brief (stderr, "\noffset", rli->offset, 0);
592 print_node_brief (stderr, " bitpos", rli->bitpos, 0);
594 fprintf (stderr, "\naligns: rec = %u, unpack = %u, unpad = %u, off = %u\n",
595 rli->record_align, rli->unpacked_align, rli->unpadded_align,
596 rli->offset_align);
597 if (rli->packed_maybe_necessary)
598 fprintf (stderr, "packed may be necessary\n");
600 if (rli->pending_statics)
602 fprintf (stderr, "pending statics:\n");
603 debug_tree (rli->pending_statics);
607 /* Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and
608 BITPOS if necessary to keep BITPOS below OFFSET_ALIGN. */
610 void
611 normalize_rli (rli)
612 record_layout_info rli;
614 normalize_offset (&rli->offset, &rli->bitpos, rli->offset_align);
617 /* Returns the size in bytes allocated so far. */
619 tree
620 rli_size_unit_so_far (rli)
621 record_layout_info rli;
623 return byte_from_pos (rli->offset, rli->bitpos);
626 /* Returns the size in bits allocated so far. */
628 tree
629 rli_size_so_far (rli)
630 record_layout_info rli;
632 return bit_from_pos (rli->offset, rli->bitpos);
635 /* Called from place_field to handle unions. */
637 static void
638 place_union_field (rli, field)
639 record_layout_info rli;
640 tree field;
642 unsigned int desired_align;
644 layout_decl (field, 0);
646 DECL_FIELD_OFFSET (field) = size_zero_node;
647 DECL_FIELD_BIT_OFFSET (field) = bitsize_zero_node;
648 SET_DECL_OFFSET_ALIGN (field, BIGGEST_ALIGNMENT);
650 desired_align = DECL_ALIGN (field);
652 #ifdef BIGGEST_FIELD_ALIGNMENT
653 /* Some targets (i.e. i386) limit union field alignment
654 to a lower boundary than alignment of variables unless
655 it was overridden by attribute aligned. */
656 if (! DECL_USER_ALIGN (field))
657 desired_align =
658 MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
659 #endif
661 TYPE_USER_ALIGN (rli->t) |= DECL_USER_ALIGN (field);
663 /* Union must be at least as aligned as any field requires. */
664 rli->record_align = MAX (rli->record_align, desired_align);
665 rli->unpadded_align = MAX (rli->unpadded_align, desired_align);
667 #ifdef PCC_BITFIELD_TYPE_MATTERS
668 /* On the m88000, a bit field of declare type `int' forces the
669 entire union to have `int' alignment. */
670 if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
672 rli->record_align = MAX (rli->record_align,
673 TYPE_ALIGN (TREE_TYPE (field)));
674 rli->unpadded_align = MAX (rli->unpadded_align,
675 TYPE_ALIGN (TREE_TYPE (field)));
677 #endif
679 /* We assume the union's size will be a multiple of a byte so we don't
680 bother with BITPOS. */
681 if (TREE_CODE (rli->t) == UNION_TYPE)
682 rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field));
683 else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE)
684 rli->offset = fold (build (COND_EXPR, sizetype,
685 DECL_QUALIFIER (field),
686 DECL_SIZE_UNIT (field), rli->offset));
689 /* RLI contains information about the layout of a RECORD_TYPE. FIELD
690 is a FIELD_DECL to be added after those fields already present in
691 T. (FIELD is not actually added to the TYPE_FIELDS list here;
692 callers that desire that behavior must manually perform that step.) */
694 void
695 place_field (rli, field)
696 record_layout_info rli;
697 tree field;
699 /* The alignment required for FIELD. */
700 unsigned int desired_align;
701 /* The alignment FIELD would have if we just dropped it into the
702 record as it presently stands. */
703 unsigned int known_align;
704 unsigned int actual_align;
705 unsigned int user_align;
706 /* The type of this field. */
707 tree type = TREE_TYPE (field);
709 if (TREE_CODE (field) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
710 return;
712 /* If FIELD is static, then treat it like a separate variable, not
713 really like a structure field. If it is a FUNCTION_DECL, it's a
714 method. In both cases, all we do is lay out the decl, and we do
715 it *after* the record is laid out. */
716 if (TREE_CODE (field) == VAR_DECL)
718 rli->pending_statics = tree_cons (NULL_TREE, field,
719 rli->pending_statics);
720 return;
723 /* Enumerators and enum types which are local to this class need not
724 be laid out. Likewise for initialized constant fields. */
725 else if (TREE_CODE (field) != FIELD_DECL)
726 return;
728 /* Unions are laid out very differently than records, so split
729 that code off to another function. */
730 else if (TREE_CODE (rli->t) != RECORD_TYPE)
732 place_union_field (rli, field);
733 return;
736 /* Work out the known alignment so far. Note that A & (-A) is the
737 value of the least-significant bit in A that is one. */
738 if (! integer_zerop (rli->bitpos))
739 known_align = (tree_low_cst (rli->bitpos, 1)
740 & - tree_low_cst (rli->bitpos, 1));
741 else if (integer_zerop (rli->offset))
742 known_align = BIGGEST_ALIGNMENT;
743 else if (host_integerp (rli->offset, 1))
744 known_align = (BITS_PER_UNIT
745 * (tree_low_cst (rli->offset, 1)
746 & - tree_low_cst (rli->offset, 1)));
747 else
748 known_align = rli->offset_align;
750 /* Lay out the field so we know what alignment it needs. For a
751 packed field, use the alignment as specified, disregarding what
752 the type would want. */
753 desired_align = DECL_ALIGN (field);
754 user_align = DECL_USER_ALIGN (field);
755 layout_decl (field, known_align);
756 if (! DECL_PACKED (field))
758 desired_align = DECL_ALIGN (field);
759 user_align = DECL_USER_ALIGN (field);
762 /* Some targets (i.e. i386, VMS) limit struct field alignment
763 to a lower boundary than alignment of variables unless
764 it was overridden by attribute aligned. */
765 #ifdef BIGGEST_FIELD_ALIGNMENT
766 if (! user_align)
767 desired_align
768 = MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
769 #endif
771 #ifdef ADJUST_FIELD_ALIGN
772 desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
773 #endif
775 /* Record must have at least as much alignment as any field.
776 Otherwise, the alignment of the field within the record is
777 meaningless. */
778 #ifdef PCC_BITFIELD_TYPE_MATTERS
779 if (PCC_BITFIELD_TYPE_MATTERS && type != error_mark_node
780 && DECL_BIT_FIELD_TYPE (field)
781 && ! integer_zerop (TYPE_SIZE (type)))
783 /* For these machines, a zero-length field does not
784 affect the alignment of the structure as a whole.
785 It does, however, affect the alignment of the next field
786 within the structure. */
787 if (! integer_zerop (DECL_SIZE (field)))
788 rli->record_align = MAX (rli->record_align, desired_align);
789 else if (! DECL_PACKED (field))
790 desired_align = TYPE_ALIGN (type);
792 /* A named bit field of declared type `int'
793 forces the entire structure to have `int' alignment. */
794 if (DECL_NAME (field) != 0)
796 unsigned int type_align = TYPE_ALIGN (type);
798 if (maximum_field_alignment != 0)
799 type_align = MIN (type_align, maximum_field_alignment);
800 else if (DECL_PACKED (field))
801 type_align = MIN (type_align, BITS_PER_UNIT);
803 rli->record_align = MAX (rli->record_align, type_align);
804 rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
805 if (warn_packed)
806 rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
809 else
810 #endif
812 rli->record_align = MAX (rli->record_align, desired_align);
813 rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
814 rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
817 if (warn_packed && DECL_PACKED (field))
819 if (known_align > TYPE_ALIGN (type))
821 if (TYPE_ALIGN (type) > desired_align)
823 if (STRICT_ALIGNMENT)
824 warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
825 else
826 warning_with_decl (field, "packed attribute is unnecessary for `%s'");
829 else
830 rli->packed_maybe_necessary = 1;
833 /* Does this field automatically have alignment it needs by virtue
834 of the fields that precede it and the record's own alignment? */
835 if (known_align < desired_align)
837 /* No, we need to skip space before this field.
838 Bump the cumulative size to multiple of field alignment. */
840 if (warn_padded)
841 warning_with_decl (field, "padding struct to align `%s'");
843 /* If the alignment is still within offset_align, just align
844 the bit position. */
845 if (desired_align < rli->offset_align)
846 rli->bitpos = round_up (rli->bitpos, desired_align);
847 else
849 /* First adjust OFFSET by the partial bits, then align. */
850 rli->offset
851 = size_binop (PLUS_EXPR, rli->offset,
852 convert (sizetype,
853 size_binop (CEIL_DIV_EXPR, rli->bitpos,
854 bitsize_unit_node)));
855 rli->bitpos = bitsize_zero_node;
857 rli->offset = round_up (rli->offset, desired_align / BITS_PER_UNIT);
860 if (! TREE_CONSTANT (rli->offset))
861 rli->offset_align = desired_align;
865 /* Handle compatibility with PCC. Note that if the record has any
866 variable-sized fields, we need not worry about compatibility. */
867 #ifdef PCC_BITFIELD_TYPE_MATTERS
868 if (PCC_BITFIELD_TYPE_MATTERS
869 && TREE_CODE (field) == FIELD_DECL
870 && type != error_mark_node
871 && DECL_BIT_FIELD (field)
872 && ! DECL_PACKED (field)
873 && maximum_field_alignment == 0
874 && ! integer_zerop (DECL_SIZE (field))
875 && host_integerp (DECL_SIZE (field), 1)
876 && host_integerp (rli->offset, 1)
877 && host_integerp (TYPE_SIZE (type), 1))
879 unsigned int type_align = TYPE_ALIGN (type);
880 tree dsize = DECL_SIZE (field);
881 HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
882 HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
883 HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
885 /* A bit field may not span more units of alignment of its type
886 than its type itself. Advance to next boundary if necessary. */
887 if ((((offset * BITS_PER_UNIT + bit_offset + field_size +
888 type_align - 1)
889 / type_align)
890 - (offset * BITS_PER_UNIT + bit_offset) / type_align)
891 > tree_low_cst (TYPE_SIZE (type), 1) / type_align)
892 rli->bitpos = round_up (rli->bitpos, type_align);
894 #endif
896 #ifdef BITFIELD_NBYTES_LIMITED
897 if (BITFIELD_NBYTES_LIMITED
898 && TREE_CODE (field) == FIELD_DECL
899 && type != error_mark_node
900 && DECL_BIT_FIELD_TYPE (field)
901 && ! DECL_PACKED (field)
902 && ! integer_zerop (DECL_SIZE (field))
903 && host_integerp (DECL_SIZE (field), 1)
904 && host_integerp (rli->offset, 1)
905 && host_integerp (TYPE_SIZE (type), 1))
907 unsigned int type_align = TYPE_ALIGN (type);
908 tree dsize = DECL_SIZE (field);
909 HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
910 HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
911 HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
913 if (maximum_field_alignment != 0)
914 type_align = MIN (type_align, maximum_field_alignment);
915 /* ??? This test is opposite the test in the containing if
916 statement, so this code is unreachable currently. */
917 else if (DECL_PACKED (field))
918 type_align = MIN (type_align, BITS_PER_UNIT);
920 /* A bit field may not span the unit of alignment of its type.
921 Advance to next boundary if necessary. */
922 /* ??? This code should match the code above for the
923 PCC_BITFIELD_TYPE_MATTERS case. */
924 if ((offset * BITS_PER_UNIT + bit_offset) / type_align
925 != ((offset * BITS_PER_UNIT + bit_offset + field_size - 1)
926 / type_align))
927 rli->bitpos = round_up (rli->bitpos, type_align);
929 #endif
931 /* Offset so far becomes the position of this field after normalizing. */
932 normalize_rli (rli);
933 DECL_FIELD_OFFSET (field) = rli->offset;
934 DECL_FIELD_BIT_OFFSET (field) = rli->bitpos;
935 SET_DECL_OFFSET_ALIGN (field, rli->offset_align);
937 TYPE_USER_ALIGN (rli->t) |= user_align;
939 /* If this field ended up more aligned than we thought it would be (we
940 approximate this by seeing if its position changed), lay out the field
941 again; perhaps we can use an integral mode for it now. */
942 if (! integer_zerop (DECL_FIELD_BIT_OFFSET (field)))
943 actual_align = (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
944 & - tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1));
945 else if (integer_zerop (DECL_FIELD_OFFSET (field)))
946 actual_align = BIGGEST_ALIGNMENT;
947 else if (host_integerp (DECL_FIELD_OFFSET (field), 1))
948 actual_align = (BITS_PER_UNIT
949 * (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
950 & - tree_low_cst (DECL_FIELD_OFFSET (field), 1)));
951 else
952 actual_align = DECL_OFFSET_ALIGN (field);
954 if (known_align != actual_align)
955 layout_decl (field, actual_align);
957 /* Now add size of this field to the size of the record. If the size is
958 not constant, treat the field as being a multiple of bytes and just
959 adjust the offset, resetting the bit position. Otherwise, apportion the
960 size amongst the bit position and offset. First handle the case of an
961 unspecified size, which can happen when we have an invalid nested struct
962 definition, such as struct j { struct j { int i; } }. The error message
963 is printed in finish_struct. */
964 if (DECL_SIZE (field) == 0)
965 /* Do nothing. */;
966 else if (TREE_CODE (DECL_SIZE_UNIT (field)) != INTEGER_CST
967 || TREE_CONSTANT_OVERFLOW (DECL_SIZE_UNIT (field)))
969 rli->offset
970 = size_binop (PLUS_EXPR, rli->offset,
971 convert (sizetype,
972 size_binop (CEIL_DIV_EXPR, rli->bitpos,
973 bitsize_unit_node)));
974 rli->offset
975 = size_binop (PLUS_EXPR, rli->offset, DECL_SIZE_UNIT (field));
976 rli->bitpos = bitsize_zero_node;
977 rli->offset_align = MIN (rli->offset_align, DECL_ALIGN (field));
979 else
981 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field));
982 normalize_rli (rli);
986 /* Assuming that all the fields have been laid out, this function uses
987 RLI to compute the final TYPE_SIZE, TYPE_ALIGN, etc. for the type
988 inidicated by RLI. */
990 static void
991 finalize_record_size (rli)
992 record_layout_info rli;
994 tree unpadded_size, unpadded_size_unit;
996 /* Now we want just byte and bit offsets, so set the offset alignment
997 to be a byte and then normalize. */
998 rli->offset_align = BITS_PER_UNIT;
999 normalize_rli (rli);
1001 /* Determine the desired alignment. */
1002 #ifdef ROUND_TYPE_ALIGN
1003 TYPE_ALIGN (rli->t) = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t),
1004 rli->record_align);
1005 #else
1006 TYPE_ALIGN (rli->t) = MAX (TYPE_ALIGN (rli->t), rli->record_align);
1007 #endif
1009 /* Compute the size so far. Be sure to allow for extra bits in the
1010 size in bytes. We have guaranteed above that it will be no more
1011 than a single byte. */
1012 unpadded_size = rli_size_so_far (rli);
1013 unpadded_size_unit = rli_size_unit_so_far (rli);
1014 if (! integer_zerop (rli->bitpos))
1015 unpadded_size_unit
1016 = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node);
1018 /* Record the un-rounded size in the binfo node. But first we check
1019 the size of TYPE_BINFO to make sure that BINFO_SIZE is available. */
1020 if (TYPE_BINFO (rli->t) && TREE_VEC_LENGTH (TYPE_BINFO (rli->t)) > 6)
1022 TYPE_BINFO_SIZE (rli->t) = unpadded_size;
1023 TYPE_BINFO_SIZE_UNIT (rli->t) = unpadded_size_unit;
1026 /* Round the size up to be a multiple of the required alignment */
1027 #ifdef ROUND_TYPE_SIZE
1028 TYPE_SIZE (rli->t) = ROUND_TYPE_SIZE (rli->t, unpadded_size,
1029 TYPE_ALIGN (rli->t));
1030 TYPE_SIZE_UNIT (rli->t)
1031 = ROUND_TYPE_SIZE_UNIT (rli->t, unpadded_size_unit,
1032 TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
1033 #else
1034 TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
1035 TYPE_SIZE_UNIT (rli->t) = round_up (unpadded_size_unit,
1036 TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
1037 #endif
1039 if (warn_padded && TREE_CONSTANT (unpadded_size)
1040 && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0)
1041 warning ("padding struct size to alignment boundary");
1043 if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
1044 && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
1045 && TREE_CONSTANT (unpadded_size))
1047 tree unpacked_size;
1049 #ifdef ROUND_TYPE_ALIGN
1050 rli->unpacked_align
1051 = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align);
1052 #else
1053 rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align);
1054 #endif
1056 #ifdef ROUND_TYPE_SIZE
1057 unpacked_size = ROUND_TYPE_SIZE (rli->t, TYPE_SIZE (rli->t),
1058 rli->unpacked_align);
1059 #else
1060 unpacked_size = round_up (TYPE_SIZE (rli->t), rli->unpacked_align);
1061 #endif
1063 if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t)))
1065 TYPE_PACKED (rli->t) = 0;
1067 if (TYPE_NAME (rli->t))
1069 const char *name;
1071 if (TREE_CODE (TYPE_NAME (rli->t)) == IDENTIFIER_NODE)
1072 name = IDENTIFIER_POINTER (TYPE_NAME (rli->t));
1073 else
1074 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (rli->t)));
1076 if (STRICT_ALIGNMENT)
1077 warning ("packed attribute causes inefficient alignment for `%s'", name);
1078 else
1079 warning ("packed attribute is unnecessary for `%s'", name);
1081 else
1083 if (STRICT_ALIGNMENT)
1084 warning ("packed attribute causes inefficient alignment");
1085 else
1086 warning ("packed attribute is unnecessary");
1092 /* Compute the TYPE_MODE for the TYPE (which is a RECORD_TYPE). */
1094 void
1095 compute_record_mode (type)
1096 tree type;
1098 tree field;
1099 enum machine_mode mode = VOIDmode;
1101 /* Most RECORD_TYPEs have BLKmode, so we start off assuming that.
1102 However, if possible, we use a mode that fits in a register
1103 instead, in order to allow for better optimization down the
1104 line. */
1105 TYPE_MODE (type) = BLKmode;
1107 if (! host_integerp (TYPE_SIZE (type), 1))
1108 return;
1110 /* A record which has any BLKmode members must itself be
1111 BLKmode; it can't go in a register. Unless the member is
1112 BLKmode only because it isn't aligned. */
1113 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1115 unsigned HOST_WIDE_INT bitpos;
1117 if (TREE_CODE (field) != FIELD_DECL)
1118 continue;
1120 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK
1121 || (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1122 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
1123 || ! host_integerp (bit_position (field), 1)
1124 || DECL_SIZE (field) == 0
1125 || ! host_integerp (DECL_SIZE (field), 1))
1126 return;
1128 bitpos = int_bit_position (field);
1130 /* Must be BLKmode if any field crosses a word boundary,
1131 since extract_bit_field can't handle that in registers. */
1132 if (bitpos / BITS_PER_WORD
1133 != ((tree_low_cst (DECL_SIZE (field), 1) + bitpos - 1)
1134 / BITS_PER_WORD)
1135 /* But there is no problem if the field is entire words. */
1136 && tree_low_cst (DECL_SIZE (field), 1) % BITS_PER_WORD != 0)
1137 return;
1139 /* If this field is the whole struct, remember its mode so
1140 that, say, we can put a double in a class into a DF
1141 register instead of forcing it to live in the stack. */
1142 if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
1143 mode = DECL_MODE (field);
1145 #ifdef MEMBER_TYPE_FORCES_BLK
1146 /* With some targets, eg. c4x, it is sub-optimal
1147 to access an aligned BLKmode structure as a scalar. */
1148 if (mode == VOIDmode && MEMBER_TYPE_FORCES_BLK (field))
1149 return;
1150 #endif /* MEMBER_TYPE_FORCES_BLK */
1153 /* If we only have one real field; use its mode. This only applies to
1154 RECORD_TYPE. This does not apply to unions. */
1155 if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode)
1156 TYPE_MODE (type) = mode;
1157 else
1158 TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1160 /* If structure's known alignment is less than what the scalar
1161 mode would need, and it matters, then stick with BLKmode. */
1162 if (TYPE_MODE (type) != BLKmode
1163 && STRICT_ALIGNMENT
1164 && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1165 || TYPE_ALIGN (type) >= GET_MODE_ALIGNMENT (TYPE_MODE (type))))
1167 /* If this is the only reason this type is BLKmode, then
1168 don't force containing types to be BLKmode. */
1169 TYPE_NO_FORCE_BLK (type) = 1;
1170 TYPE_MODE (type) = BLKmode;
1174 /* Compute TYPE_SIZE and TYPE_ALIGN for TYPE, once it has been laid
1175 out. */
1177 static void
1178 finalize_type_size (type)
1179 tree type;
1181 /* Normally, use the alignment corresponding to the mode chosen.
1182 However, where strict alignment is not required, avoid
1183 over-aligning structures, since most compilers do not do this
1184 alignment. */
1186 if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1187 && (STRICT_ALIGNMENT
1188 || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1189 && TREE_CODE (type) != QUAL_UNION_TYPE
1190 && TREE_CODE (type) != ARRAY_TYPE)))
1192 TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1193 TYPE_USER_ALIGN (type) = 0;
1196 /* Do machine-dependent extra alignment. */
1197 #ifdef ROUND_TYPE_ALIGN
1198 TYPE_ALIGN (type)
1199 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (type), BITS_PER_UNIT);
1200 #endif
1202 /* If we failed to find a simple way to calculate the unit size
1203 of the type, find it by division. */
1204 if (TYPE_SIZE_UNIT (type) == 0 && TYPE_SIZE (type) != 0)
1205 /* TYPE_SIZE (type) is computed in bitsizetype. After the division, the
1206 result will fit in sizetype. We will get more efficient code using
1207 sizetype, so we force a conversion. */
1208 TYPE_SIZE_UNIT (type)
1209 = convert (sizetype,
1210 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type),
1211 bitsize_unit_node));
1213 if (TYPE_SIZE (type) != 0)
1215 #ifdef ROUND_TYPE_SIZE
1216 TYPE_SIZE (type)
1217 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1218 TYPE_SIZE_UNIT (type)
1219 = ROUND_TYPE_SIZE_UNIT (type, TYPE_SIZE_UNIT (type),
1220 TYPE_ALIGN (type) / BITS_PER_UNIT);
1221 #else
1222 TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
1223 TYPE_SIZE_UNIT (type)
1224 = round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type) / BITS_PER_UNIT);
1225 #endif
1228 /* Evaluate nonconstant sizes only once, either now or as soon as safe. */
1229 if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1230 TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1231 if (TYPE_SIZE_UNIT (type) != 0
1232 && TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
1233 TYPE_SIZE_UNIT (type) = variable_size (TYPE_SIZE_UNIT (type));
1235 /* Also layout any other variants of the type. */
1236 if (TYPE_NEXT_VARIANT (type)
1237 || type != TYPE_MAIN_VARIANT (type))
1239 tree variant;
1240 /* Record layout info of this variant. */
1241 tree size = TYPE_SIZE (type);
1242 tree size_unit = TYPE_SIZE_UNIT (type);
1243 unsigned int align = TYPE_ALIGN (type);
1244 unsigned int user_align = TYPE_USER_ALIGN (type);
1245 enum machine_mode mode = TYPE_MODE (type);
1247 /* Copy it into all variants. */
1248 for (variant = TYPE_MAIN_VARIANT (type);
1249 variant != 0;
1250 variant = TYPE_NEXT_VARIANT (variant))
1252 TYPE_SIZE (variant) = size;
1253 TYPE_SIZE_UNIT (variant) = size_unit;
1254 TYPE_ALIGN (variant) = align;
1255 TYPE_USER_ALIGN (variant) = user_align;
1256 TYPE_MODE (variant) = mode;
1261 /* Do all of the work required to layout the type indicated by RLI,
1262 once the fields have been laid out. This function will call `free'
1263 for RLI. */
1265 void
1266 finish_record_layout (rli)
1267 record_layout_info rli;
1269 /* Compute the final size. */
1270 finalize_record_size (rli);
1272 /* Compute the TYPE_MODE for the record. */
1273 compute_record_mode (rli->t);
1275 /* Perform any last tweaks to the TYPE_SIZE, etc. */
1276 finalize_type_size (rli->t);
1278 /* Lay out any static members. This is done now because their type
1279 may use the record's type. */
1280 while (rli->pending_statics)
1282 layout_decl (TREE_VALUE (rli->pending_statics), 0);
1283 rli->pending_statics = TREE_CHAIN (rli->pending_statics);
1286 /* Clean up. */
1287 free (rli);
1290 /* Calculate the mode, size, and alignment for TYPE.
1291 For an array type, calculate the element separation as well.
1292 Record TYPE on the chain of permanent or temporary types
1293 so that dbxout will find out about it.
1295 TYPE_SIZE of a type is nonzero if the type has been laid out already.
1296 layout_type does nothing on such a type.
1298 If the type is incomplete, its TYPE_SIZE remains zero. */
1300 void
1301 layout_type (type)
1302 tree type;
1304 if (type == 0)
1305 abort ();
1307 /* Do nothing if type has been laid out before. */
1308 if (TYPE_SIZE (type))
1309 return;
1311 switch (TREE_CODE (type))
1313 case LANG_TYPE:
1314 /* This kind of type is the responsibility
1315 of the language-specific code. */
1316 abort ();
1318 case BOOLEAN_TYPE: /* Used for Java, Pascal, and Chill. */
1319 if (TYPE_PRECISION (type) == 0)
1320 TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
1322 /* ... fall through ... */
1324 case INTEGER_TYPE:
1325 case ENUMERAL_TYPE:
1326 case CHAR_TYPE:
1327 if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1328 && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
1329 TREE_UNSIGNED (type) = 1;
1331 TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
1332 MODE_INT);
1333 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1334 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1335 break;
1337 case REAL_TYPE:
1338 TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
1339 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1340 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1341 break;
1343 case COMPLEX_TYPE:
1344 TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
1345 TYPE_MODE (type)
1346 = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
1347 (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
1348 ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
1350 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1351 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1352 break;
1354 case VECTOR_TYPE:
1356 tree subtype;
1358 subtype = TREE_TYPE (type);
1359 TREE_UNSIGNED (type) = TREE_UNSIGNED (subtype);
1360 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1361 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1363 break;
1365 case VOID_TYPE:
1366 /* This is an incomplete type and so doesn't have a size. */
1367 TYPE_ALIGN (type) = 1;
1368 TYPE_USER_ALIGN (type) = 0;
1369 TYPE_MODE (type) = VOIDmode;
1370 break;
1372 case OFFSET_TYPE:
1373 TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
1374 TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
1375 /* A pointer might be MODE_PARTIAL_INT,
1376 but ptrdiff_t must be integral. */
1377 TYPE_MODE (type) = mode_for_size (POINTER_SIZE, MODE_INT, 0);
1378 break;
1380 case FUNCTION_TYPE:
1381 case METHOD_TYPE:
1382 TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
1383 TYPE_SIZE (type) = bitsize_int (2 * POINTER_SIZE);
1384 TYPE_SIZE_UNIT (type) = size_int ((2 * POINTER_SIZE) / BITS_PER_UNIT);
1385 break;
1387 case POINTER_TYPE:
1388 case REFERENCE_TYPE:
1390 int nbits = ((TREE_CODE (type) == REFERENCE_TYPE
1391 && reference_types_internal)
1392 ? GET_MODE_BITSIZE (Pmode) : POINTER_SIZE);
1394 TYPE_MODE (type) = nbits == POINTER_SIZE ? ptr_mode : Pmode;
1395 TYPE_SIZE (type) = bitsize_int (nbits);
1396 TYPE_SIZE_UNIT (type) = size_int (nbits / BITS_PER_UNIT);
1397 TREE_UNSIGNED (type) = 1;
1398 TYPE_PRECISION (type) = nbits;
1400 break;
1402 case ARRAY_TYPE:
1404 tree index = TYPE_DOMAIN (type);
1405 tree element = TREE_TYPE (type);
1407 build_pointer_type (element);
1409 /* We need to know both bounds in order to compute the size. */
1410 if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
1411 && TYPE_SIZE (element))
1413 tree ub = TYPE_MAX_VALUE (index);
1414 tree lb = TYPE_MIN_VALUE (index);
1415 tree length;
1416 tree element_size;
1418 /* The initial subtraction should happen in the original type so
1419 that (possible) negative values are handled appropriately. */
1420 length = size_binop (PLUS_EXPR, size_one_node,
1421 convert (sizetype,
1422 fold (build (MINUS_EXPR,
1423 TREE_TYPE (lb),
1424 ub, lb))));
1426 /* Special handling for arrays of bits (for Chill). */
1427 element_size = TYPE_SIZE (element);
1428 if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element)
1429 && (integer_zerop (TYPE_MAX_VALUE (element))
1430 || integer_onep (TYPE_MAX_VALUE (element)))
1431 && host_integerp (TYPE_MIN_VALUE (element), 1))
1433 HOST_WIDE_INT maxvalue
1434 = tree_low_cst (TYPE_MAX_VALUE (element), 1);
1435 HOST_WIDE_INT minvalue
1436 = tree_low_cst (TYPE_MIN_VALUE (element), 1);
1438 if (maxvalue - minvalue == 1
1439 && (maxvalue == 1 || maxvalue == 0))
1440 element_size = integer_one_node;
1443 TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
1444 convert (bitsizetype, length));
1446 /* If we know the size of the element, calculate the total
1447 size directly, rather than do some division thing below.
1448 This optimization helps Fortran assumed-size arrays
1449 (where the size of the array is determined at runtime)
1450 substantially.
1451 Note that we can't do this in the case where the size of
1452 the elements is one bit since TYPE_SIZE_UNIT cannot be
1453 set correctly in that case. */
1454 if (TYPE_SIZE_UNIT (element) != 0 && ! integer_onep (element_size))
1455 TYPE_SIZE_UNIT (type)
1456 = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length);
1459 /* Now round the alignment and size,
1460 using machine-dependent criteria if any. */
1462 #ifdef ROUND_TYPE_ALIGN
1463 TYPE_ALIGN (type)
1464 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
1465 #else
1466 TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
1467 #endif
1468 TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element);
1470 #ifdef ROUND_TYPE_SIZE
1471 if (TYPE_SIZE (type) != 0)
1473 tree tmp
1474 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1476 /* If the rounding changed the size of the type, remove any
1477 pre-calculated TYPE_SIZE_UNIT. */
1478 if (simple_cst_equal (TYPE_SIZE (type), tmp) != 1)
1479 TYPE_SIZE_UNIT (type) = NULL;
1481 TYPE_SIZE (type) = tmp;
1483 #endif
1485 TYPE_MODE (type) = BLKmode;
1486 if (TYPE_SIZE (type) != 0
1487 #ifdef MEMBER_TYPE_FORCES_BLK
1488 && ! MEMBER_TYPE_FORCES_BLK (type)
1489 #endif
1490 /* BLKmode elements force BLKmode aggregate;
1491 else extract/store fields may lose. */
1492 && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
1493 || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
1495 TYPE_MODE (type)
1496 = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1498 if (TYPE_MODE (type) != BLKmode
1499 && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
1500 && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type))
1501 && TYPE_MODE (type) != BLKmode)
1503 TYPE_NO_FORCE_BLK (type) = 1;
1504 TYPE_MODE (type) = BLKmode;
1507 break;
1510 case RECORD_TYPE:
1511 case UNION_TYPE:
1512 case QUAL_UNION_TYPE:
1514 tree field;
1515 record_layout_info rli;
1517 /* Initialize the layout information. */
1518 rli = start_record_layout (type);
1520 /* If this is a QUAL_UNION_TYPE, we want to process the fields
1521 in the reverse order in building the COND_EXPR that denotes
1522 its size. We reverse them again later. */
1523 if (TREE_CODE (type) == QUAL_UNION_TYPE)
1524 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1526 /* Place all the fields. */
1527 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1528 place_field (rli, field);
1530 if (TREE_CODE (type) == QUAL_UNION_TYPE)
1531 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1533 if (lang_adjust_rli)
1534 (*lang_adjust_rli) (rli);
1536 /* Finish laying out the record. */
1537 finish_record_layout (rli);
1539 break;
1541 case SET_TYPE: /* Used by Chill and Pascal. */
1542 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
1543 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
1544 abort();
1545 else
1547 #ifndef SET_WORD_SIZE
1548 #define SET_WORD_SIZE BITS_PER_WORD
1549 #endif
1550 unsigned int alignment
1551 = set_alignment ? set_alignment : SET_WORD_SIZE;
1552 int size_in_bits
1553 = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1554 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
1555 int rounded_size
1556 = ((size_in_bits + alignment - 1) / alignment) * alignment;
1558 if (rounded_size > (int) alignment)
1559 TYPE_MODE (type) = BLKmode;
1560 else
1561 TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
1563 TYPE_SIZE (type) = bitsize_int (rounded_size);
1564 TYPE_SIZE_UNIT (type) = size_int (rounded_size / BITS_PER_UNIT);
1565 TYPE_ALIGN (type) = alignment;
1566 TYPE_USER_ALIGN (type) = 0;
1567 TYPE_PRECISION (type) = size_in_bits;
1569 break;
1571 case FILE_TYPE:
1572 /* The size may vary in different languages, so the language front end
1573 should fill in the size. */
1574 TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
1575 TYPE_USER_ALIGN (type) = 0;
1576 TYPE_MODE (type) = BLKmode;
1577 break;
1579 default:
1580 abort ();
1583 /* Compute the final TYPE_SIZE, TYPE_ALIGN, etc. for TYPE. For
1584 records and unions, finish_record_layout already called this
1585 function. */
1586 if (TREE_CODE (type) != RECORD_TYPE
1587 && TREE_CODE (type) != UNION_TYPE
1588 && TREE_CODE (type) != QUAL_UNION_TYPE)
1589 finalize_type_size (type);
1591 /* If this type is created before sizetype has been permanently set,
1592 record it so set_sizetype can fix it up. */
1593 if (! sizetype_set)
1594 early_type_list = tree_cons (NULL_TREE, type, early_type_list);
1596 /* If an alias set has been set for this aggregate when it was incomplete,
1597 force it into alias set 0.
1598 This is too conservative, but we cannot call record_component_aliases
1599 here because some frontends still change the aggregates after
1600 layout_type. */
1601 if (AGGREGATE_TYPE_P (type) && TYPE_ALIAS_SET_KNOWN_P (type))
1602 TYPE_ALIAS_SET (type) = 0;
1605 /* Create and return a type for signed integers of PRECISION bits. */
1607 tree
1608 make_signed_type (precision)
1609 int precision;
1611 tree type = make_node (INTEGER_TYPE);
1613 TYPE_PRECISION (type) = precision;
1615 fixup_signed_type (type);
1616 return type;
1619 /* Create and return a type for unsigned integers of PRECISION bits. */
1621 tree
1622 make_unsigned_type (precision)
1623 int precision;
1625 tree type = make_node (INTEGER_TYPE);
1627 TYPE_PRECISION (type) = precision;
1629 fixup_unsigned_type (type);
1630 return type;
1633 /* Initialize sizetype and bitsizetype to a reasonable and temporary
1634 value to enable integer types to be created. */
1636 void
1637 initialize_sizetypes ()
1639 tree t = make_node (INTEGER_TYPE);
1641 /* Set this so we do something reasonable for the build_int_2 calls
1642 below. */
1643 integer_type_node = t;
1645 TYPE_MODE (t) = SImode;
1646 TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
1647 TYPE_USER_ALIGN (t) = 0;
1648 TYPE_SIZE (t) = build_int_2 (GET_MODE_BITSIZE (SImode), 0);
1649 TYPE_SIZE_UNIT (t) = build_int_2 (GET_MODE_SIZE (SImode), 0);
1650 TREE_UNSIGNED (t) = 1;
1651 TYPE_PRECISION (t) = GET_MODE_BITSIZE (SImode);
1652 TYPE_MIN_VALUE (t) = build_int_2 (0, 0);
1653 TYPE_IS_SIZETYPE (t) = 1;
1655 /* 1000 avoids problems with possible overflow and is certainly
1656 larger than any size value we'd want to be storing. */
1657 TYPE_MAX_VALUE (t) = build_int_2 (1000, 0);
1659 /* These two must be different nodes because of the caching done in
1660 size_int_wide. */
1661 sizetype = t;
1662 bitsizetype = copy_node (t);
1663 integer_type_node = 0;
1666 /* Set sizetype to TYPE, and initialize *sizetype accordingly.
1667 Also update the type of any standard type's sizes made so far. */
1669 void
1670 set_sizetype (type)
1671 tree type;
1673 int oprecision = TYPE_PRECISION (type);
1674 /* The *bitsizetype types use a precision that avoids overflows when
1675 calculating signed sizes / offsets in bits. However, when
1676 cross-compiling from a 32 bit to a 64 bit host, we are limited to 64 bit
1677 precision. */
1678 int precision = MIN (oprecision + BITS_PER_UNIT_LOG + 1,
1679 2 * HOST_BITS_PER_WIDE_INT);
1680 unsigned int i;
1681 tree t;
1683 if (sizetype_set)
1684 abort ();
1686 /* Make copies of nodes since we'll be setting TYPE_IS_SIZETYPE. */
1687 sizetype = copy_node (type);
1688 TYPE_DOMAIN (sizetype) = type;
1689 TYPE_IS_SIZETYPE (sizetype) = 1;
1690 bitsizetype = make_node (INTEGER_TYPE);
1691 TYPE_NAME (bitsizetype) = TYPE_NAME (type);
1692 TYPE_PRECISION (bitsizetype) = precision;
1693 TYPE_IS_SIZETYPE (bitsizetype) = 1;
1695 if (TREE_UNSIGNED (type))
1696 fixup_unsigned_type (bitsizetype);
1697 else
1698 fixup_signed_type (bitsizetype);
1700 layout_type (bitsizetype);
1702 if (TREE_UNSIGNED (type))
1704 usizetype = sizetype;
1705 ubitsizetype = bitsizetype;
1706 ssizetype = copy_node (make_signed_type (oprecision));
1707 sbitsizetype = copy_node (make_signed_type (precision));
1709 else
1711 ssizetype = sizetype;
1712 sbitsizetype = bitsizetype;
1713 usizetype = copy_node (make_unsigned_type (oprecision));
1714 ubitsizetype = copy_node (make_unsigned_type (precision));
1717 TYPE_NAME (bitsizetype) = get_identifier ("bit_size_type");
1719 /* Show is a sizetype, is a main type, and has no pointers to it. */
1720 for (i = 0; i < ARRAY_SIZE (sizetype_tab); i++)
1722 TYPE_IS_SIZETYPE (sizetype_tab[i]) = 1;
1723 TYPE_MAIN_VARIANT (sizetype_tab[i]) = sizetype_tab[i];
1724 TYPE_NEXT_VARIANT (sizetype_tab[i]) = 0;
1725 TYPE_POINTER_TO (sizetype_tab[i]) = 0;
1726 TYPE_REFERENCE_TO (sizetype_tab[i]) = 0;
1729 ggc_add_tree_root ((tree *) &sizetype_tab,
1730 sizeof sizetype_tab / sizeof (tree));
1732 /* Go down each of the types we already made and set the proper type
1733 for the sizes in them. */
1734 for (t = early_type_list; t != 0; t = TREE_CHAIN (t))
1736 if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE)
1737 abort ();
1739 TREE_TYPE (TYPE_SIZE (TREE_VALUE (t))) = bitsizetype;
1740 TREE_TYPE (TYPE_SIZE_UNIT (TREE_VALUE (t))) = sizetype;
1743 early_type_list = 0;
1744 sizetype_set = 1;
1747 /* Set the extreme values of TYPE based on its precision in bits,
1748 then lay it out. Used when make_signed_type won't do
1749 because the tree code is not INTEGER_TYPE.
1750 E.g. for Pascal, when the -fsigned-char option is given. */
1752 void
1753 fixup_signed_type (type)
1754 tree type;
1756 int precision = TYPE_PRECISION (type);
1758 /* We can not represent properly constants greater then
1759 2 * HOST_BITS_PER_WIDE_INT, still we need the types
1760 as they are used by i386 vector extensions and friends. */
1761 if (precision > HOST_BITS_PER_WIDE_INT * 2)
1762 precision = HOST_BITS_PER_WIDE_INT * 2;
1764 TYPE_MIN_VALUE (type)
1765 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1766 ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1767 (((HOST_WIDE_INT) (-1)
1768 << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1769 ? precision - HOST_BITS_PER_WIDE_INT - 1
1770 : 0))));
1771 TYPE_MAX_VALUE (type)
1772 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1773 ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1774 (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1775 ? (((HOST_WIDE_INT) 1
1776 << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1777 : 0));
1779 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1780 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1782 /* Lay out the type: set its alignment, size, etc. */
1783 layout_type (type);
1786 /* Set the extreme values of TYPE based on its precision in bits,
1787 then lay it out. This is used both in `make_unsigned_type'
1788 and for enumeral types. */
1790 void
1791 fixup_unsigned_type (type)
1792 tree type;
1794 int precision = TYPE_PRECISION (type);
1796 /* We can not represent properly constants greater then
1797 2 * HOST_BITS_PER_WIDE_INT, still we need the types
1798 as they are used by i386 vector extensions and friends. */
1799 if (precision > HOST_BITS_PER_WIDE_INT * 2)
1800 precision = HOST_BITS_PER_WIDE_INT * 2;
1802 TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1803 TYPE_MAX_VALUE (type)
1804 = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1805 ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1806 precision - HOST_BITS_PER_WIDE_INT > 0
1807 ? ((unsigned HOST_WIDE_INT) ~0
1808 >> (HOST_BITS_PER_WIDE_INT
1809 - (precision - HOST_BITS_PER_WIDE_INT)))
1810 : 0);
1811 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1812 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1814 /* Lay out the type: set its alignment, size, etc. */
1815 layout_type (type);
1818 /* Find the best machine mode to use when referencing a bit field of length
1819 BITSIZE bits starting at BITPOS.
1821 The underlying object is known to be aligned to a boundary of ALIGN bits.
1822 If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1823 larger than LARGEST_MODE (usually SImode).
1825 If no mode meets all these conditions, we return VOIDmode. Otherwise, if
1826 VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1827 mode meeting these conditions.
1829 Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1830 the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1831 all the conditions. */
1833 enum machine_mode
1834 get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1835 int bitsize, bitpos;
1836 unsigned int align;
1837 enum machine_mode largest_mode;
1838 int volatilep;
1840 enum machine_mode mode;
1841 unsigned int unit = 0;
1843 /* Find the narrowest integer mode that contains the bit field. */
1844 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1845 mode = GET_MODE_WIDER_MODE (mode))
1847 unit = GET_MODE_BITSIZE (mode);
1848 if ((bitpos % unit) + bitsize <= unit)
1849 break;
1852 if (mode == VOIDmode
1853 /* It is tempting to omit the following line
1854 if STRICT_ALIGNMENT is true.
1855 But that is incorrect, since if the bitfield uses part of 3 bytes
1856 and we use a 4-byte mode, we could get a spurious segv
1857 if the extra 4th byte is past the end of memory.
1858 (Though at least one Unix compiler ignores this problem:
1859 that on the Sequent 386 machine. */
1860 || MIN (unit, BIGGEST_ALIGNMENT) > align
1861 || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1862 return VOIDmode;
1864 if (SLOW_BYTE_ACCESS && ! volatilep)
1866 enum machine_mode wide_mode = VOIDmode, tmode;
1868 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1869 tmode = GET_MODE_WIDER_MODE (tmode))
1871 unit = GET_MODE_BITSIZE (tmode);
1872 if (bitpos / unit == (bitpos + bitsize - 1) / unit
1873 && unit <= BITS_PER_WORD
1874 && unit <= MIN (align, BIGGEST_ALIGNMENT)
1875 && (largest_mode == VOIDmode
1876 || unit <= GET_MODE_BITSIZE (largest_mode)))
1877 wide_mode = tmode;
1880 if (wide_mode != VOIDmode)
1881 return wide_mode;
1884 return mode;
1887 /* This function is run once to initialize stor-layout.c. */
1889 void
1890 init_stor_layout_once ()
1892 ggc_add_tree_root (&pending_sizes, 1);