* emit-rtl.c (adjust_address_1): Always copy address to avoid
[official-gcc.git] / gcc / stor-layout.c
blobf657463bfd010d36bdad14368cceb62a505c6fc6
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 #ifdef ADJUST_FIELD_ALIGN
662 desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
663 #endif
665 TYPE_USER_ALIGN (rli->t) |= DECL_USER_ALIGN (field);
667 /* Union must be at least as aligned as any field requires. */
668 rli->record_align = MAX (rli->record_align, desired_align);
669 rli->unpadded_align = MAX (rli->unpadded_align, desired_align);
671 #ifdef PCC_BITFIELD_TYPE_MATTERS
672 /* On the m88000, a bit field of declare type `int' forces the
673 entire union to have `int' alignment. */
674 if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
676 rli->record_align = MAX (rli->record_align,
677 TYPE_ALIGN (TREE_TYPE (field)));
678 rli->unpadded_align = MAX (rli->unpadded_align,
679 TYPE_ALIGN (TREE_TYPE (field)));
681 #endif
683 /* We assume the union's size will be a multiple of a byte so we don't
684 bother with BITPOS. */
685 if (TREE_CODE (rli->t) == UNION_TYPE)
686 rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field));
687 else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE)
688 rli->offset = fold (build (COND_EXPR, sizetype,
689 DECL_QUALIFIER (field),
690 DECL_SIZE_UNIT (field), rli->offset));
693 /* RLI contains information about the layout of a RECORD_TYPE. FIELD
694 is a FIELD_DECL to be added after those fields already present in
695 T. (FIELD is not actually added to the TYPE_FIELDS list here;
696 callers that desire that behavior must manually perform that step.) */
698 void
699 place_field (rli, field)
700 record_layout_info rli;
701 tree field;
703 /* The alignment required for FIELD. */
704 unsigned int desired_align;
705 /* The alignment FIELD would have if we just dropped it into the
706 record as it presently stands. */
707 unsigned int known_align;
708 unsigned int actual_align;
709 unsigned int user_align;
710 /* The type of this field. */
711 tree type = TREE_TYPE (field);
713 if (TREE_CODE (field) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
714 return;
716 /* If FIELD is static, then treat it like a separate variable, not
717 really like a structure field. If it is a FUNCTION_DECL, it's a
718 method. In both cases, all we do is lay out the decl, and we do
719 it *after* the record is laid out. */
720 if (TREE_CODE (field) == VAR_DECL)
722 rli->pending_statics = tree_cons (NULL_TREE, field,
723 rli->pending_statics);
724 return;
727 /* Enumerators and enum types which are local to this class need not
728 be laid out. Likewise for initialized constant fields. */
729 else if (TREE_CODE (field) != FIELD_DECL)
730 return;
732 /* Unions are laid out very differently than records, so split
733 that code off to another function. */
734 else if (TREE_CODE (rli->t) != RECORD_TYPE)
736 place_union_field (rli, field);
737 return;
740 /* Work out the known alignment so far. Note that A & (-A) is the
741 value of the least-significant bit in A that is one. */
742 if (! integer_zerop (rli->bitpos))
743 known_align = (tree_low_cst (rli->bitpos, 1)
744 & - tree_low_cst (rli->bitpos, 1));
745 else if (integer_zerop (rli->offset))
746 known_align = BIGGEST_ALIGNMENT;
747 else if (host_integerp (rli->offset, 1))
748 known_align = (BITS_PER_UNIT
749 * (tree_low_cst (rli->offset, 1)
750 & - tree_low_cst (rli->offset, 1)));
751 else
752 known_align = rli->offset_align;
754 /* Lay out the field so we know what alignment it needs. For a
755 packed field, use the alignment as specified, disregarding what
756 the type would want. */
757 desired_align = DECL_ALIGN (field);
758 user_align = DECL_USER_ALIGN (field);
759 layout_decl (field, known_align);
760 if (! DECL_PACKED (field))
762 desired_align = DECL_ALIGN (field);
763 user_align = DECL_USER_ALIGN (field);
766 /* Some targets (i.e. i386, VMS) limit struct field alignment
767 to a lower boundary than alignment of variables unless
768 it was overridden by attribute aligned. */
769 #ifdef BIGGEST_FIELD_ALIGNMENT
770 if (! user_align)
771 desired_align
772 = MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
773 #endif
775 #ifdef ADJUST_FIELD_ALIGN
776 desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
777 #endif
779 /* Record must have at least as much alignment as any field.
780 Otherwise, the alignment of the field within the record is
781 meaningless. */
782 #ifdef PCC_BITFIELD_TYPE_MATTERS
783 if (PCC_BITFIELD_TYPE_MATTERS && type != error_mark_node
784 && DECL_BIT_FIELD_TYPE (field)
785 && ! integer_zerop (TYPE_SIZE (type)))
787 /* For these machines, a zero-length field does not
788 affect the alignment of the structure as a whole.
789 It does, however, affect the alignment of the next field
790 within the structure. */
791 if (! integer_zerop (DECL_SIZE (field)))
792 rli->record_align = MAX (rli->record_align, desired_align);
793 else if (! DECL_PACKED (field))
794 desired_align = TYPE_ALIGN (type);
796 /* A named bit field of declared type `int'
797 forces the entire structure to have `int' alignment. */
798 if (DECL_NAME (field) != 0)
800 unsigned int type_align = TYPE_ALIGN (type);
802 if (maximum_field_alignment != 0)
803 type_align = MIN (type_align, maximum_field_alignment);
804 else if (DECL_PACKED (field))
805 type_align = MIN (type_align, BITS_PER_UNIT);
807 rli->record_align = MAX (rli->record_align, type_align);
808 rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
809 if (warn_packed)
810 rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
813 else
814 #endif
816 rli->record_align = MAX (rli->record_align, desired_align);
817 rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
818 rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
821 if (warn_packed && DECL_PACKED (field))
823 if (known_align > TYPE_ALIGN (type))
825 if (TYPE_ALIGN (type) > desired_align)
827 if (STRICT_ALIGNMENT)
828 warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
829 else
830 warning_with_decl (field, "packed attribute is unnecessary for `%s'");
833 else
834 rli->packed_maybe_necessary = 1;
837 /* Does this field automatically have alignment it needs by virtue
838 of the fields that precede it and the record's own alignment? */
839 if (known_align < desired_align)
841 /* No, we need to skip space before this field.
842 Bump the cumulative size to multiple of field alignment. */
844 if (warn_padded)
845 warning_with_decl (field, "padding struct to align `%s'");
847 /* If the alignment is still within offset_align, just align
848 the bit position. */
849 if (desired_align < rli->offset_align)
850 rli->bitpos = round_up (rli->bitpos, desired_align);
851 else
853 /* First adjust OFFSET by the partial bits, then align. */
854 rli->offset
855 = size_binop (PLUS_EXPR, rli->offset,
856 convert (sizetype,
857 size_binop (CEIL_DIV_EXPR, rli->bitpos,
858 bitsize_unit_node)));
859 rli->bitpos = bitsize_zero_node;
861 rli->offset = round_up (rli->offset, desired_align / BITS_PER_UNIT);
864 if (! TREE_CONSTANT (rli->offset))
865 rli->offset_align = desired_align;
869 /* Handle compatibility with PCC. Note that if the record has any
870 variable-sized fields, we need not worry about compatibility. */
871 #ifdef PCC_BITFIELD_TYPE_MATTERS
872 if (PCC_BITFIELD_TYPE_MATTERS
873 && TREE_CODE (field) == FIELD_DECL
874 && type != error_mark_node
875 && DECL_BIT_FIELD (field)
876 && ! DECL_PACKED (field)
877 && maximum_field_alignment == 0
878 && ! integer_zerop (DECL_SIZE (field))
879 && host_integerp (DECL_SIZE (field), 1)
880 && host_integerp (rli->offset, 1)
881 && host_integerp (TYPE_SIZE (type), 1))
883 unsigned int type_align = TYPE_ALIGN (type);
884 tree dsize = DECL_SIZE (field);
885 HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
886 HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
887 HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
889 /* A bit field may not span more units of alignment of its type
890 than its type itself. Advance to next boundary if necessary. */
891 if ((((offset * BITS_PER_UNIT + bit_offset + field_size +
892 type_align - 1)
893 / type_align)
894 - (offset * BITS_PER_UNIT + bit_offset) / type_align)
895 > tree_low_cst (TYPE_SIZE (type), 1) / type_align)
896 rli->bitpos = round_up (rli->bitpos, type_align);
898 #endif
900 #ifdef BITFIELD_NBYTES_LIMITED
901 if (BITFIELD_NBYTES_LIMITED
902 && TREE_CODE (field) == FIELD_DECL
903 && type != error_mark_node
904 && DECL_BIT_FIELD_TYPE (field)
905 && ! DECL_PACKED (field)
906 && ! integer_zerop (DECL_SIZE (field))
907 && host_integerp (DECL_SIZE (field), 1)
908 && host_integerp (rli->offset, 1)
909 && host_integerp (TYPE_SIZE (type), 1))
911 unsigned int type_align = TYPE_ALIGN (type);
912 tree dsize = DECL_SIZE (field);
913 HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
914 HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
915 HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
917 if (maximum_field_alignment != 0)
918 type_align = MIN (type_align, maximum_field_alignment);
919 /* ??? This test is opposite the test in the containing if
920 statement, so this code is unreachable currently. */
921 else if (DECL_PACKED (field))
922 type_align = MIN (type_align, BITS_PER_UNIT);
924 /* A bit field may not span the unit of alignment of its type.
925 Advance to next boundary if necessary. */
926 /* ??? This code should match the code above for the
927 PCC_BITFIELD_TYPE_MATTERS case. */
928 if ((offset * BITS_PER_UNIT + bit_offset) / type_align
929 != ((offset * BITS_PER_UNIT + bit_offset + field_size - 1)
930 / type_align))
931 rli->bitpos = round_up (rli->bitpos, type_align);
933 #endif
935 /* Offset so far becomes the position of this field after normalizing. */
936 normalize_rli (rli);
937 DECL_FIELD_OFFSET (field) = rli->offset;
938 DECL_FIELD_BIT_OFFSET (field) = rli->bitpos;
939 SET_DECL_OFFSET_ALIGN (field, rli->offset_align);
941 TYPE_USER_ALIGN (rli->t) |= user_align;
943 /* If this field ended up more aligned than we thought it would be (we
944 approximate this by seeing if its position changed), lay out the field
945 again; perhaps we can use an integral mode for it now. */
946 if (! integer_zerop (DECL_FIELD_BIT_OFFSET (field)))
947 actual_align = (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
948 & - tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1));
949 else if (integer_zerop (DECL_FIELD_OFFSET (field)))
950 actual_align = BIGGEST_ALIGNMENT;
951 else if (host_integerp (DECL_FIELD_OFFSET (field), 1))
952 actual_align = (BITS_PER_UNIT
953 * (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
954 & - tree_low_cst (DECL_FIELD_OFFSET (field), 1)));
955 else
956 actual_align = DECL_OFFSET_ALIGN (field);
958 if (known_align != actual_align)
959 layout_decl (field, actual_align);
961 /* Now add size of this field to the size of the record. If the size is
962 not constant, treat the field as being a multiple of bytes and just
963 adjust the offset, resetting the bit position. Otherwise, apportion the
964 size amongst the bit position and offset. First handle the case of an
965 unspecified size, which can happen when we have an invalid nested struct
966 definition, such as struct j { struct j { int i; } }. The error message
967 is printed in finish_struct. */
968 if (DECL_SIZE (field) == 0)
969 /* Do nothing. */;
970 else if (TREE_CODE (DECL_SIZE_UNIT (field)) != INTEGER_CST
971 || TREE_CONSTANT_OVERFLOW (DECL_SIZE_UNIT (field)))
973 rli->offset
974 = size_binop (PLUS_EXPR, rli->offset,
975 convert (sizetype,
976 size_binop (CEIL_DIV_EXPR, rli->bitpos,
977 bitsize_unit_node)));
978 rli->offset
979 = size_binop (PLUS_EXPR, rli->offset, DECL_SIZE_UNIT (field));
980 rli->bitpos = bitsize_zero_node;
981 rli->offset_align = MIN (rli->offset_align, DECL_ALIGN (field));
983 else
985 rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field));
986 normalize_rli (rli);
990 /* Assuming that all the fields have been laid out, this function uses
991 RLI to compute the final TYPE_SIZE, TYPE_ALIGN, etc. for the type
992 inidicated by RLI. */
994 static void
995 finalize_record_size (rli)
996 record_layout_info rli;
998 tree unpadded_size, unpadded_size_unit;
1000 /* Now we want just byte and bit offsets, so set the offset alignment
1001 to be a byte and then normalize. */
1002 rli->offset_align = BITS_PER_UNIT;
1003 normalize_rli (rli);
1005 /* Determine the desired alignment. */
1006 #ifdef ROUND_TYPE_ALIGN
1007 TYPE_ALIGN (rli->t) = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t),
1008 rli->record_align);
1009 #else
1010 TYPE_ALIGN (rli->t) = MAX (TYPE_ALIGN (rli->t), rli->record_align);
1011 #endif
1013 /* Compute the size so far. Be sure to allow for extra bits in the
1014 size in bytes. We have guaranteed above that it will be no more
1015 than a single byte. */
1016 unpadded_size = rli_size_so_far (rli);
1017 unpadded_size_unit = rli_size_unit_so_far (rli);
1018 if (! integer_zerop (rli->bitpos))
1019 unpadded_size_unit
1020 = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node);
1022 /* Record the un-rounded size in the binfo node. But first we check
1023 the size of TYPE_BINFO to make sure that BINFO_SIZE is available. */
1024 if (TYPE_BINFO (rli->t) && TREE_VEC_LENGTH (TYPE_BINFO (rli->t)) > 6)
1026 TYPE_BINFO_SIZE (rli->t) = unpadded_size;
1027 TYPE_BINFO_SIZE_UNIT (rli->t) = unpadded_size_unit;
1030 /* Round the size up to be a multiple of the required alignment */
1031 #ifdef ROUND_TYPE_SIZE
1032 TYPE_SIZE (rli->t) = ROUND_TYPE_SIZE (rli->t, unpadded_size,
1033 TYPE_ALIGN (rli->t));
1034 TYPE_SIZE_UNIT (rli->t)
1035 = ROUND_TYPE_SIZE_UNIT (rli->t, unpadded_size_unit,
1036 TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
1037 #else
1038 TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
1039 TYPE_SIZE_UNIT (rli->t) = round_up (unpadded_size_unit,
1040 TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
1041 #endif
1043 if (warn_padded && TREE_CONSTANT (unpadded_size)
1044 && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0)
1045 warning ("padding struct size to alignment boundary");
1047 if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
1048 && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
1049 && TREE_CONSTANT (unpadded_size))
1051 tree unpacked_size;
1053 #ifdef ROUND_TYPE_ALIGN
1054 rli->unpacked_align
1055 = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align);
1056 #else
1057 rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align);
1058 #endif
1060 #ifdef ROUND_TYPE_SIZE
1061 unpacked_size = ROUND_TYPE_SIZE (rli->t, TYPE_SIZE (rli->t),
1062 rli->unpacked_align);
1063 #else
1064 unpacked_size = round_up (TYPE_SIZE (rli->t), rli->unpacked_align);
1065 #endif
1067 if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t)))
1069 TYPE_PACKED (rli->t) = 0;
1071 if (TYPE_NAME (rli->t))
1073 const char *name;
1075 if (TREE_CODE (TYPE_NAME (rli->t)) == IDENTIFIER_NODE)
1076 name = IDENTIFIER_POINTER (TYPE_NAME (rli->t));
1077 else
1078 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (rli->t)));
1080 if (STRICT_ALIGNMENT)
1081 warning ("packed attribute causes inefficient alignment for `%s'", name);
1082 else
1083 warning ("packed attribute is unnecessary for `%s'", name);
1085 else
1087 if (STRICT_ALIGNMENT)
1088 warning ("packed attribute causes inefficient alignment");
1089 else
1090 warning ("packed attribute is unnecessary");
1096 /* Compute the TYPE_MODE for the TYPE (which is a RECORD_TYPE). */
1098 void
1099 compute_record_mode (type)
1100 tree type;
1102 tree field;
1103 enum machine_mode mode = VOIDmode;
1105 /* Most RECORD_TYPEs have BLKmode, so we start off assuming that.
1106 However, if possible, we use a mode that fits in a register
1107 instead, in order to allow for better optimization down the
1108 line. */
1109 TYPE_MODE (type) = BLKmode;
1111 if (! host_integerp (TYPE_SIZE (type), 1))
1112 return;
1114 /* A record which has any BLKmode members must itself be
1115 BLKmode; it can't go in a register. Unless the member is
1116 BLKmode only because it isn't aligned. */
1117 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1119 unsigned HOST_WIDE_INT bitpos;
1121 if (TREE_CODE (field) != FIELD_DECL)
1122 continue;
1124 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK
1125 || (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1126 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
1127 || ! host_integerp (bit_position (field), 1)
1128 || DECL_SIZE (field) == 0
1129 || ! host_integerp (DECL_SIZE (field), 1))
1130 return;
1132 bitpos = int_bit_position (field);
1134 /* Must be BLKmode if any field crosses a word boundary,
1135 since extract_bit_field can't handle that in registers. */
1136 if (bitpos / BITS_PER_WORD
1137 != ((tree_low_cst (DECL_SIZE (field), 1) + bitpos - 1)
1138 / BITS_PER_WORD)
1139 /* But there is no problem if the field is entire words. */
1140 && tree_low_cst (DECL_SIZE (field), 1) % BITS_PER_WORD != 0)
1141 return;
1143 /* If this field is the whole struct, remember its mode so
1144 that, say, we can put a double in a class into a DF
1145 register instead of forcing it to live in the stack. */
1146 if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
1147 mode = DECL_MODE (field);
1149 #ifdef MEMBER_TYPE_FORCES_BLK
1150 /* With some targets, eg. c4x, it is sub-optimal
1151 to access an aligned BLKmode structure as a scalar. */
1153 /* On ia64-*-hpux we need to ensure that we don't change the
1154 mode of a structure containing a single field or else we
1155 will pass it incorrectly. Since a structure with a single
1156 field causes mode to get set above we can't allow the
1157 check for mode == VOIDmode in this case. Perhaps
1158 MEMBER_TYPE_FORCES_BLK should be extended to include mode
1159 as an argument and the check could be put in there for c4x. */
1161 if ((mode == VOIDmode || FUNCTION_ARG_REG_LITTLE_ENDIAN)
1162 && MEMBER_TYPE_FORCES_BLK (field))
1163 return;
1164 #endif /* MEMBER_TYPE_FORCES_BLK */
1167 /* If we only have one real field; use its mode. This only applies to
1168 RECORD_TYPE. This does not apply to unions. */
1169 if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode)
1170 TYPE_MODE (type) = mode;
1171 else
1172 TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1174 /* If structure's known alignment is less than what the scalar
1175 mode would need, and it matters, then stick with BLKmode. */
1176 if (TYPE_MODE (type) != BLKmode
1177 && STRICT_ALIGNMENT
1178 && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1179 || TYPE_ALIGN (type) >= GET_MODE_ALIGNMENT (TYPE_MODE (type))))
1181 /* If this is the only reason this type is BLKmode, then
1182 don't force containing types to be BLKmode. */
1183 TYPE_NO_FORCE_BLK (type) = 1;
1184 TYPE_MODE (type) = BLKmode;
1188 /* Compute TYPE_SIZE and TYPE_ALIGN for TYPE, once it has been laid
1189 out. */
1191 static void
1192 finalize_type_size (type)
1193 tree type;
1195 /* Normally, use the alignment corresponding to the mode chosen.
1196 However, where strict alignment is not required, avoid
1197 over-aligning structures, since most compilers do not do this
1198 alignment. */
1200 if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1201 && (STRICT_ALIGNMENT
1202 || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1203 && TREE_CODE (type) != QUAL_UNION_TYPE
1204 && TREE_CODE (type) != ARRAY_TYPE)))
1206 TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1207 TYPE_USER_ALIGN (type) = 0;
1210 /* Do machine-dependent extra alignment. */
1211 #ifdef ROUND_TYPE_ALIGN
1212 TYPE_ALIGN (type)
1213 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (type), BITS_PER_UNIT);
1214 #endif
1216 /* If we failed to find a simple way to calculate the unit size
1217 of the type, find it by division. */
1218 if (TYPE_SIZE_UNIT (type) == 0 && TYPE_SIZE (type) != 0)
1219 /* TYPE_SIZE (type) is computed in bitsizetype. After the division, the
1220 result will fit in sizetype. We will get more efficient code using
1221 sizetype, so we force a conversion. */
1222 TYPE_SIZE_UNIT (type)
1223 = convert (sizetype,
1224 size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type),
1225 bitsize_unit_node));
1227 if (TYPE_SIZE (type) != 0)
1229 #ifdef ROUND_TYPE_SIZE
1230 TYPE_SIZE (type)
1231 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1232 TYPE_SIZE_UNIT (type)
1233 = ROUND_TYPE_SIZE_UNIT (type, TYPE_SIZE_UNIT (type),
1234 TYPE_ALIGN (type) / BITS_PER_UNIT);
1235 #else
1236 TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
1237 TYPE_SIZE_UNIT (type)
1238 = round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type) / BITS_PER_UNIT);
1239 #endif
1242 /* Evaluate nonconstant sizes only once, either now or as soon as safe. */
1243 if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1244 TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1245 if (TYPE_SIZE_UNIT (type) != 0
1246 && TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
1247 TYPE_SIZE_UNIT (type) = variable_size (TYPE_SIZE_UNIT (type));
1249 /* Also layout any other variants of the type. */
1250 if (TYPE_NEXT_VARIANT (type)
1251 || type != TYPE_MAIN_VARIANT (type))
1253 tree variant;
1254 /* Record layout info of this variant. */
1255 tree size = TYPE_SIZE (type);
1256 tree size_unit = TYPE_SIZE_UNIT (type);
1257 unsigned int align = TYPE_ALIGN (type);
1258 unsigned int user_align = TYPE_USER_ALIGN (type);
1259 enum machine_mode mode = TYPE_MODE (type);
1261 /* Copy it into all variants. */
1262 for (variant = TYPE_MAIN_VARIANT (type);
1263 variant != 0;
1264 variant = TYPE_NEXT_VARIANT (variant))
1266 TYPE_SIZE (variant) = size;
1267 TYPE_SIZE_UNIT (variant) = size_unit;
1268 TYPE_ALIGN (variant) = align;
1269 TYPE_USER_ALIGN (variant) = user_align;
1270 TYPE_MODE (variant) = mode;
1275 /* Do all of the work required to layout the type indicated by RLI,
1276 once the fields have been laid out. This function will call `free'
1277 for RLI. */
1279 void
1280 finish_record_layout (rli)
1281 record_layout_info rli;
1283 /* Compute the final size. */
1284 finalize_record_size (rli);
1286 /* Compute the TYPE_MODE for the record. */
1287 compute_record_mode (rli->t);
1289 /* Perform any last tweaks to the TYPE_SIZE, etc. */
1290 finalize_type_size (rli->t);
1292 /* Lay out any static members. This is done now because their type
1293 may use the record's type. */
1294 while (rli->pending_statics)
1296 layout_decl (TREE_VALUE (rli->pending_statics), 0);
1297 rli->pending_statics = TREE_CHAIN (rli->pending_statics);
1300 /* Clean up. */
1301 free (rli);
1304 /* Calculate the mode, size, and alignment for TYPE.
1305 For an array type, calculate the element separation as well.
1306 Record TYPE on the chain of permanent or temporary types
1307 so that dbxout will find out about it.
1309 TYPE_SIZE of a type is nonzero if the type has been laid out already.
1310 layout_type does nothing on such a type.
1312 If the type is incomplete, its TYPE_SIZE remains zero. */
1314 void
1315 layout_type (type)
1316 tree type;
1318 if (type == 0)
1319 abort ();
1321 /* Do nothing if type has been laid out before. */
1322 if (TYPE_SIZE (type))
1323 return;
1325 switch (TREE_CODE (type))
1327 case LANG_TYPE:
1328 /* This kind of type is the responsibility
1329 of the language-specific code. */
1330 abort ();
1332 case BOOLEAN_TYPE: /* Used for Java, Pascal, and Chill. */
1333 if (TYPE_PRECISION (type) == 0)
1334 TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
1336 /* ... fall through ... */
1338 case INTEGER_TYPE:
1339 case ENUMERAL_TYPE:
1340 case CHAR_TYPE:
1341 if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1342 && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
1343 TREE_UNSIGNED (type) = 1;
1345 TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
1346 MODE_INT);
1347 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1348 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1349 break;
1351 case REAL_TYPE:
1352 TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
1353 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1354 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1355 break;
1357 case COMPLEX_TYPE:
1358 TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
1359 TYPE_MODE (type)
1360 = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
1361 (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
1362 ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
1364 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1365 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1366 break;
1368 case VECTOR_TYPE:
1370 tree subtype;
1372 subtype = TREE_TYPE (type);
1373 TREE_UNSIGNED (type) = TREE_UNSIGNED (subtype);
1374 TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1375 TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1377 break;
1379 case VOID_TYPE:
1380 /* This is an incomplete type and so doesn't have a size. */
1381 TYPE_ALIGN (type) = 1;
1382 TYPE_USER_ALIGN (type) = 0;
1383 TYPE_MODE (type) = VOIDmode;
1384 break;
1386 case OFFSET_TYPE:
1387 TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
1388 TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
1389 /* A pointer might be MODE_PARTIAL_INT,
1390 but ptrdiff_t must be integral. */
1391 TYPE_MODE (type) = mode_for_size (POINTER_SIZE, MODE_INT, 0);
1392 break;
1394 case FUNCTION_TYPE:
1395 case METHOD_TYPE:
1396 TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
1397 TYPE_SIZE (type) = bitsize_int (2 * POINTER_SIZE);
1398 TYPE_SIZE_UNIT (type) = size_int ((2 * POINTER_SIZE) / BITS_PER_UNIT);
1399 break;
1401 case POINTER_TYPE:
1402 case REFERENCE_TYPE:
1404 int nbits = ((TREE_CODE (type) == REFERENCE_TYPE
1405 && reference_types_internal)
1406 ? GET_MODE_BITSIZE (Pmode) : POINTER_SIZE);
1408 TYPE_MODE (type) = nbits == POINTER_SIZE ? ptr_mode : Pmode;
1409 TYPE_SIZE (type) = bitsize_int (nbits);
1410 TYPE_SIZE_UNIT (type) = size_int (nbits / BITS_PER_UNIT);
1411 TREE_UNSIGNED (type) = 1;
1412 TYPE_PRECISION (type) = nbits;
1414 break;
1416 case ARRAY_TYPE:
1418 tree index = TYPE_DOMAIN (type);
1419 tree element = TREE_TYPE (type);
1421 build_pointer_type (element);
1423 /* We need to know both bounds in order to compute the size. */
1424 if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
1425 && TYPE_SIZE (element))
1427 tree ub = TYPE_MAX_VALUE (index);
1428 tree lb = TYPE_MIN_VALUE (index);
1429 tree length;
1430 tree element_size;
1432 /* The initial subtraction should happen in the original type so
1433 that (possible) negative values are handled appropriately. */
1434 length = size_binop (PLUS_EXPR, size_one_node,
1435 convert (sizetype,
1436 fold (build (MINUS_EXPR,
1437 TREE_TYPE (lb),
1438 ub, lb))));
1440 /* Special handling for arrays of bits (for Chill). */
1441 element_size = TYPE_SIZE (element);
1442 if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element)
1443 && (integer_zerop (TYPE_MAX_VALUE (element))
1444 || integer_onep (TYPE_MAX_VALUE (element)))
1445 && host_integerp (TYPE_MIN_VALUE (element), 1))
1447 HOST_WIDE_INT maxvalue
1448 = tree_low_cst (TYPE_MAX_VALUE (element), 1);
1449 HOST_WIDE_INT minvalue
1450 = tree_low_cst (TYPE_MIN_VALUE (element), 1);
1452 if (maxvalue - minvalue == 1
1453 && (maxvalue == 1 || maxvalue == 0))
1454 element_size = integer_one_node;
1457 TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
1458 convert (bitsizetype, length));
1460 /* If we know the size of the element, calculate the total
1461 size directly, rather than do some division thing below.
1462 This optimization helps Fortran assumed-size arrays
1463 (where the size of the array is determined at runtime)
1464 substantially.
1465 Note that we can't do this in the case where the size of
1466 the elements is one bit since TYPE_SIZE_UNIT cannot be
1467 set correctly in that case. */
1468 if (TYPE_SIZE_UNIT (element) != 0 && ! integer_onep (element_size))
1469 TYPE_SIZE_UNIT (type)
1470 = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length);
1473 /* Now round the alignment and size,
1474 using machine-dependent criteria if any. */
1476 #ifdef ROUND_TYPE_ALIGN
1477 TYPE_ALIGN (type)
1478 = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
1479 #else
1480 TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
1481 #endif
1482 TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element);
1484 #ifdef ROUND_TYPE_SIZE
1485 if (TYPE_SIZE (type) != 0)
1487 tree tmp
1488 = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1490 /* If the rounding changed the size of the type, remove any
1491 pre-calculated TYPE_SIZE_UNIT. */
1492 if (simple_cst_equal (TYPE_SIZE (type), tmp) != 1)
1493 TYPE_SIZE_UNIT (type) = NULL;
1495 TYPE_SIZE (type) = tmp;
1497 #endif
1499 TYPE_MODE (type) = BLKmode;
1500 if (TYPE_SIZE (type) != 0
1501 #ifdef MEMBER_TYPE_FORCES_BLK
1502 && ! MEMBER_TYPE_FORCES_BLK (type)
1503 #endif
1504 /* BLKmode elements force BLKmode aggregate;
1505 else extract/store fields may lose. */
1506 && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
1507 || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
1509 TYPE_MODE (type)
1510 = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1512 if (TYPE_MODE (type) != BLKmode
1513 && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
1514 && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type))
1515 && TYPE_MODE (type) != BLKmode)
1517 TYPE_NO_FORCE_BLK (type) = 1;
1518 TYPE_MODE (type) = BLKmode;
1521 break;
1524 case RECORD_TYPE:
1525 case UNION_TYPE:
1526 case QUAL_UNION_TYPE:
1528 tree field;
1529 record_layout_info rli;
1531 /* Initialize the layout information. */
1532 rli = start_record_layout (type);
1534 /* If this is a QUAL_UNION_TYPE, we want to process the fields
1535 in the reverse order in building the COND_EXPR that denotes
1536 its size. We reverse them again later. */
1537 if (TREE_CODE (type) == QUAL_UNION_TYPE)
1538 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1540 /* Place all the fields. */
1541 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1542 place_field (rli, field);
1544 if (TREE_CODE (type) == QUAL_UNION_TYPE)
1545 TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1547 if (lang_adjust_rli)
1548 (*lang_adjust_rli) (rli);
1550 /* Finish laying out the record. */
1551 finish_record_layout (rli);
1553 break;
1555 case SET_TYPE: /* Used by Chill and Pascal. */
1556 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
1557 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
1558 abort();
1559 else
1561 #ifndef SET_WORD_SIZE
1562 #define SET_WORD_SIZE BITS_PER_WORD
1563 #endif
1564 unsigned int alignment
1565 = set_alignment ? set_alignment : SET_WORD_SIZE;
1566 int size_in_bits
1567 = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1568 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
1569 int rounded_size
1570 = ((size_in_bits + alignment - 1) / alignment) * alignment;
1572 if (rounded_size > (int) alignment)
1573 TYPE_MODE (type) = BLKmode;
1574 else
1575 TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
1577 TYPE_SIZE (type) = bitsize_int (rounded_size);
1578 TYPE_SIZE_UNIT (type) = size_int (rounded_size / BITS_PER_UNIT);
1579 TYPE_ALIGN (type) = alignment;
1580 TYPE_USER_ALIGN (type) = 0;
1581 TYPE_PRECISION (type) = size_in_bits;
1583 break;
1585 case FILE_TYPE:
1586 /* The size may vary in different languages, so the language front end
1587 should fill in the size. */
1588 TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
1589 TYPE_USER_ALIGN (type) = 0;
1590 TYPE_MODE (type) = BLKmode;
1591 break;
1593 default:
1594 abort ();
1597 /* Compute the final TYPE_SIZE, TYPE_ALIGN, etc. for TYPE. For
1598 records and unions, finish_record_layout already called this
1599 function. */
1600 if (TREE_CODE (type) != RECORD_TYPE
1601 && TREE_CODE (type) != UNION_TYPE
1602 && TREE_CODE (type) != QUAL_UNION_TYPE)
1603 finalize_type_size (type);
1605 /* If this type is created before sizetype has been permanently set,
1606 record it so set_sizetype can fix it up. */
1607 if (! sizetype_set)
1608 early_type_list = tree_cons (NULL_TREE, type, early_type_list);
1610 /* If an alias set has been set for this aggregate when it was incomplete,
1611 force it into alias set 0.
1612 This is too conservative, but we cannot call record_component_aliases
1613 here because some frontends still change the aggregates after
1614 layout_type. */
1615 if (AGGREGATE_TYPE_P (type) && TYPE_ALIAS_SET_KNOWN_P (type))
1616 TYPE_ALIAS_SET (type) = 0;
1619 /* Create and return a type for signed integers of PRECISION bits. */
1621 tree
1622 make_signed_type (precision)
1623 int precision;
1625 tree type = make_node (INTEGER_TYPE);
1627 TYPE_PRECISION (type) = precision;
1629 fixup_signed_type (type);
1630 return type;
1633 /* Create and return a type for unsigned integers of PRECISION bits. */
1635 tree
1636 make_unsigned_type (precision)
1637 int precision;
1639 tree type = make_node (INTEGER_TYPE);
1641 TYPE_PRECISION (type) = precision;
1643 fixup_unsigned_type (type);
1644 return type;
1647 /* Initialize sizetype and bitsizetype to a reasonable and temporary
1648 value to enable integer types to be created. */
1650 void
1651 initialize_sizetypes ()
1653 tree t = make_node (INTEGER_TYPE);
1655 /* Set this so we do something reasonable for the build_int_2 calls
1656 below. */
1657 integer_type_node = t;
1659 TYPE_MODE (t) = SImode;
1660 TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
1661 TYPE_USER_ALIGN (t) = 0;
1662 TYPE_SIZE (t) = build_int_2 (GET_MODE_BITSIZE (SImode), 0);
1663 TYPE_SIZE_UNIT (t) = build_int_2 (GET_MODE_SIZE (SImode), 0);
1664 TREE_UNSIGNED (t) = 1;
1665 TYPE_PRECISION (t) = GET_MODE_BITSIZE (SImode);
1666 TYPE_MIN_VALUE (t) = build_int_2 (0, 0);
1667 TYPE_IS_SIZETYPE (t) = 1;
1669 /* 1000 avoids problems with possible overflow and is certainly
1670 larger than any size value we'd want to be storing. */
1671 TYPE_MAX_VALUE (t) = build_int_2 (1000, 0);
1673 /* These two must be different nodes because of the caching done in
1674 size_int_wide. */
1675 sizetype = t;
1676 bitsizetype = copy_node (t);
1677 integer_type_node = 0;
1680 /* Set sizetype to TYPE, and initialize *sizetype accordingly.
1681 Also update the type of any standard type's sizes made so far. */
1683 void
1684 set_sizetype (type)
1685 tree type;
1687 int oprecision = TYPE_PRECISION (type);
1688 /* The *bitsizetype types use a precision that avoids overflows when
1689 calculating signed sizes / offsets in bits. However, when
1690 cross-compiling from a 32 bit to a 64 bit host, we are limited to 64 bit
1691 precision. */
1692 int precision = MIN (oprecision + BITS_PER_UNIT_LOG + 1,
1693 2 * HOST_BITS_PER_WIDE_INT);
1694 unsigned int i;
1695 tree t;
1697 if (sizetype_set)
1698 abort ();
1700 /* Make copies of nodes since we'll be setting TYPE_IS_SIZETYPE. */
1701 sizetype = copy_node (type);
1702 TYPE_DOMAIN (sizetype) = type;
1703 TYPE_IS_SIZETYPE (sizetype) = 1;
1704 bitsizetype = make_node (INTEGER_TYPE);
1705 TYPE_NAME (bitsizetype) = TYPE_NAME (type);
1706 TYPE_PRECISION (bitsizetype) = precision;
1707 TYPE_IS_SIZETYPE (bitsizetype) = 1;
1709 if (TREE_UNSIGNED (type))
1710 fixup_unsigned_type (bitsizetype);
1711 else
1712 fixup_signed_type (bitsizetype);
1714 layout_type (bitsizetype);
1716 if (TREE_UNSIGNED (type))
1718 usizetype = sizetype;
1719 ubitsizetype = bitsizetype;
1720 ssizetype = copy_node (make_signed_type (oprecision));
1721 sbitsizetype = copy_node (make_signed_type (precision));
1723 else
1725 ssizetype = sizetype;
1726 sbitsizetype = bitsizetype;
1727 usizetype = copy_node (make_unsigned_type (oprecision));
1728 ubitsizetype = copy_node (make_unsigned_type (precision));
1731 TYPE_NAME (bitsizetype) = get_identifier ("bit_size_type");
1733 /* Show is a sizetype, is a main type, and has no pointers to it. */
1734 for (i = 0; i < ARRAY_SIZE (sizetype_tab); i++)
1736 TYPE_IS_SIZETYPE (sizetype_tab[i]) = 1;
1737 TYPE_MAIN_VARIANT (sizetype_tab[i]) = sizetype_tab[i];
1738 TYPE_NEXT_VARIANT (sizetype_tab[i]) = 0;
1739 TYPE_POINTER_TO (sizetype_tab[i]) = 0;
1740 TYPE_REFERENCE_TO (sizetype_tab[i]) = 0;
1743 ggc_add_tree_root ((tree *) &sizetype_tab,
1744 sizeof sizetype_tab / sizeof (tree));
1746 /* Go down each of the types we already made and set the proper type
1747 for the sizes in them. */
1748 for (t = early_type_list; t != 0; t = TREE_CHAIN (t))
1750 if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE)
1751 abort ();
1753 TREE_TYPE (TYPE_SIZE (TREE_VALUE (t))) = bitsizetype;
1754 TREE_TYPE (TYPE_SIZE_UNIT (TREE_VALUE (t))) = sizetype;
1757 early_type_list = 0;
1758 sizetype_set = 1;
1761 /* Set the extreme values of TYPE based on its precision in bits,
1762 then lay it out. Used when make_signed_type won't do
1763 because the tree code is not INTEGER_TYPE.
1764 E.g. for Pascal, when the -fsigned-char option is given. */
1766 void
1767 fixup_signed_type (type)
1768 tree type;
1770 int precision = TYPE_PRECISION (type);
1772 /* We can not represent properly constants greater then
1773 2 * HOST_BITS_PER_WIDE_INT, still we need the types
1774 as they are used by i386 vector extensions and friends. */
1775 if (precision > HOST_BITS_PER_WIDE_INT * 2)
1776 precision = HOST_BITS_PER_WIDE_INT * 2;
1778 TYPE_MIN_VALUE (type)
1779 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1780 ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1781 (((HOST_WIDE_INT) (-1)
1782 << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1783 ? precision - HOST_BITS_PER_WIDE_INT - 1
1784 : 0))));
1785 TYPE_MAX_VALUE (type)
1786 = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1787 ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1788 (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1789 ? (((HOST_WIDE_INT) 1
1790 << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1791 : 0));
1793 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1794 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1796 /* Lay out the type: set its alignment, size, etc. */
1797 layout_type (type);
1800 /* Set the extreme values of TYPE based on its precision in bits,
1801 then lay it out. This is used both in `make_unsigned_type'
1802 and for enumeral types. */
1804 void
1805 fixup_unsigned_type (type)
1806 tree type;
1808 int precision = TYPE_PRECISION (type);
1810 /* We can not represent properly constants greater then
1811 2 * HOST_BITS_PER_WIDE_INT, still we need the types
1812 as they are used by i386 vector extensions and friends. */
1813 if (precision > HOST_BITS_PER_WIDE_INT * 2)
1814 precision = HOST_BITS_PER_WIDE_INT * 2;
1816 TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1817 TYPE_MAX_VALUE (type)
1818 = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1819 ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1820 precision - HOST_BITS_PER_WIDE_INT > 0
1821 ? ((unsigned HOST_WIDE_INT) ~0
1822 >> (HOST_BITS_PER_WIDE_INT
1823 - (precision - HOST_BITS_PER_WIDE_INT)))
1824 : 0);
1825 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1826 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1828 /* Lay out the type: set its alignment, size, etc. */
1829 layout_type (type);
1832 /* Find the best machine mode to use when referencing a bit field of length
1833 BITSIZE bits starting at BITPOS.
1835 The underlying object is known to be aligned to a boundary of ALIGN bits.
1836 If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1837 larger than LARGEST_MODE (usually SImode).
1839 If no mode meets all these conditions, we return VOIDmode. Otherwise, if
1840 VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1841 mode meeting these conditions.
1843 Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1844 the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1845 all the conditions. */
1847 enum machine_mode
1848 get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1849 int bitsize, bitpos;
1850 unsigned int align;
1851 enum machine_mode largest_mode;
1852 int volatilep;
1854 enum machine_mode mode;
1855 unsigned int unit = 0;
1857 /* Find the narrowest integer mode that contains the bit field. */
1858 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1859 mode = GET_MODE_WIDER_MODE (mode))
1861 unit = GET_MODE_BITSIZE (mode);
1862 if ((bitpos % unit) + bitsize <= unit)
1863 break;
1866 if (mode == VOIDmode
1867 /* It is tempting to omit the following line
1868 if STRICT_ALIGNMENT is true.
1869 But that is incorrect, since if the bitfield uses part of 3 bytes
1870 and we use a 4-byte mode, we could get a spurious segv
1871 if the extra 4th byte is past the end of memory.
1872 (Though at least one Unix compiler ignores this problem:
1873 that on the Sequent 386 machine. */
1874 || MIN (unit, BIGGEST_ALIGNMENT) > align
1875 || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1876 return VOIDmode;
1878 if (SLOW_BYTE_ACCESS && ! volatilep)
1880 enum machine_mode wide_mode = VOIDmode, tmode;
1882 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1883 tmode = GET_MODE_WIDER_MODE (tmode))
1885 unit = GET_MODE_BITSIZE (tmode);
1886 if (bitpos / unit == (bitpos + bitsize - 1) / unit
1887 && unit <= BITS_PER_WORD
1888 && unit <= MIN (align, BIGGEST_ALIGNMENT)
1889 && (largest_mode == VOIDmode
1890 || unit <= GET_MODE_BITSIZE (largest_mode)))
1891 wide_mode = tmode;
1894 if (wide_mode != VOIDmode)
1895 return wide_mode;
1898 return mode;
1901 /* This function is run once to initialize stor-layout.c. */
1903 void
1904 init_stor_layout_once ()
1906 ggc_add_tree_root (&pending_sizes, 1);