OSDN Git Service

eadb9732a8ff3a19d027847a189716340d0cc0a2
[pf3gnuchains/gcc-fork.git] / gcc / stor-layout.c
1 /* C-compiler utilities for types and variables storage layout
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1996, 1998,
3    1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
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"
33
34 /* Set to one when set_sizetype has been called.  */
35 static int sizetype_set;
36
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;
40
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];
44
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;
48
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;
52
53 static void finalize_record_size        PARAMS ((record_layout_info));
54 static void finalize_type_size          PARAMS ((tree));
55 static void place_union_field           PARAMS ((record_layout_info, tree));
56 extern void debug_rli                   PARAMS ((record_layout_info));
57 \f
58 /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded.  */
59
60 static tree pending_sizes;
61
62 /* Nonzero means cannot safely call expand_expr now,
63    so put variable sizes onto `pending_sizes' instead.  */
64
65 int immediate_size_expand;
66
67 /* Get a list of all the objects put on the pending sizes list.  */
68
69 tree
70 get_pending_sizes ()
71 {
72   tree chain = pending_sizes;
73   tree t;
74
75   /* Put each SAVE_EXPR into the current function.  */
76   for (t = chain; t; t = TREE_CHAIN (t))
77     SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = current_function_decl;
78
79   pending_sizes = 0;
80   return chain;
81 }
82
83 /* Put a chain of objects into the pending sizes list, which must be
84    empty.  */
85
86 void
87 put_pending_sizes (chain)
88      tree chain;
89 {
90   if (pending_sizes)
91     abort ();
92
93   pending_sizes = chain;
94 }
95
96 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
97    to serve as the actual size-expression for a type or decl.  */
98
99 tree
100 variable_size (size)
101      tree size;
102 {
103   /* If the language-processor is to take responsibility for variable-sized
104      items (e.g., languages which have elaboration procedures like Ada),
105      just return SIZE unchanged.  Likewise for self-referential sizes.  */
106   if (TREE_CONSTANT (size)
107       || global_bindings_p () < 0 || contains_placeholder_p (size))
108     return size;
109
110   size = save_expr (size);
111
112   /* If an array with a variable number of elements is declared, and
113      the elements require destruction, we will emit a cleanup for the
114      array.  That cleanup is run both on normal exit from the block
115      and in the exception-handler for the block.  Normally, when code
116      is used in both ordinary code and in an exception handler it is
117      `unsaved', i.e., all SAVE_EXPRs are recalculated.  However, we do
118      not wish to do that here; the array-size is the same in both
119      places.  */
120   if (TREE_CODE (size) == SAVE_EXPR)
121     SAVE_EXPR_PERSISTENT_P (size) = 1;
122
123   if (global_bindings_p ())
124     {
125       if (TREE_CONSTANT (size))
126         error ("type size can't be explicitly evaluated");
127       else
128         error ("variable-size type declared outside of any function");
129
130       return size_one_node;
131     }
132
133   if (immediate_size_expand)
134     /* NULL_RTX is not defined; neither is the rtx type. 
135        Also, we would like to pass const0_rtx here, but don't have it.  */
136     expand_expr (size, expand_expr (integer_zero_node, NULL_PTR, VOIDmode, 0),
137                  VOIDmode, 0);
138   else if (cfun != 0 && cfun->x_dont_save_pending_sizes_p)
139     /* The front-end doesn't want us to keep a list of the expressions
140        that determine sizes for variable size objects.  */
141     ;
142   else
143     pending_sizes = tree_cons (NULL_TREE, size, pending_sizes);
144
145   return size;
146 }
147 \f
148 #ifndef MAX_FIXED_MODE_SIZE
149 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
150 #endif
151
152 /* Return the machine mode to use for a nonscalar of SIZE bits.
153    The mode must be in class CLASS, and have exactly that many bits.
154    If LIMIT is nonzero, modes of wider than MAX_FIXED_MODE_SIZE will not
155    be used.  */
156
157 enum machine_mode
158 mode_for_size (size, class, limit)
159      unsigned int size;
160      enum mode_class class;
161      int limit;
162 {
163   register enum machine_mode mode;
164
165   if (limit && size > MAX_FIXED_MODE_SIZE)
166     return BLKmode;
167
168   /* Get the first mode which has this size, in the specified class.  */
169   for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
170        mode = GET_MODE_WIDER_MODE (mode))
171     if (GET_MODE_BITSIZE (mode) == size)
172       return mode;
173
174   return BLKmode;
175 }
176
177 /* Similar, except passed a tree node.  */
178
179 enum machine_mode
180 mode_for_size_tree (size, class, limit)
181      tree size;
182      enum mode_class class;
183      int limit;
184 {
185   if (TREE_CODE (size) != INTEGER_CST
186       /* What we really want to say here is that the size can fit in a
187          host integer, but we know there's no way we'd find a mode for
188          this many bits, so there's no point in doing the precise test.  */
189       || compare_tree_int (size, 1000) > 0)
190     return BLKmode;
191   else
192     return mode_for_size (TREE_INT_CST_LOW (size), class, limit);
193 }
194
195 /* Similar, but never return BLKmode; return the narrowest mode that
196    contains at least the requested number of bits.  */
197
198 enum machine_mode
199 smallest_mode_for_size (size, class)
200      unsigned int size;
201      enum mode_class class;
202 {
203   register enum machine_mode mode;
204
205   /* Get the first mode which has at least this size, in the
206      specified class.  */
207   for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
208        mode = GET_MODE_WIDER_MODE (mode))
209     if (GET_MODE_BITSIZE (mode) >= size)
210       return mode;
211
212   abort ();
213 }
214
215 /* Find an integer mode of the exact same size, or BLKmode on failure.  */
216
217 enum machine_mode
218 int_mode_for_mode (mode)
219      enum machine_mode mode;
220 {
221   switch (GET_MODE_CLASS (mode))
222     {
223     case MODE_INT:
224     case MODE_PARTIAL_INT:
225       break;
226
227     case MODE_COMPLEX_INT:
228     case MODE_COMPLEX_FLOAT:
229     case MODE_FLOAT:
230       mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
231       break;
232
233     case MODE_RANDOM:
234       if (mode == BLKmode)
235         break;
236
237       /* ... fall through ... */
238
239     case MODE_CC:
240     default:
241       abort ();
242     }
243
244   return mode;
245 }
246
247 /* Return the value of VALUE, rounded up to a multiple of DIVISOR.
248    This can only be applied to objects of a sizetype.  */
249
250 tree
251 round_up (value, divisor)
252      tree value;
253      int divisor;
254 {
255   tree arg = size_int_type (divisor, TREE_TYPE (value));
256
257   return size_binop (MULT_EXPR, size_binop (CEIL_DIV_EXPR, value, arg), arg);
258 }
259
260 /* Likewise, but round down.  */
261
262 tree
263 round_down (value, divisor)
264      tree value;
265      int divisor;
266 {
267   tree arg = size_int_type (divisor, TREE_TYPE (value));
268
269   return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg);
270 }
271 \f
272 /* Set the size, mode and alignment of a ..._DECL node.
273    TYPE_DECL does need this for C++.
274    Note that LABEL_DECL and CONST_DECL nodes do not need this,
275    and FUNCTION_DECL nodes have them set up in a special (and simple) way.
276    Don't call layout_decl for them.
277
278    KNOWN_ALIGN is the amount of alignment we can assume this
279    decl has with no special effort.  It is relevant only for FIELD_DECLs
280    and depends on the previous fields.
281    All that matters about KNOWN_ALIGN is which powers of 2 divide it.
282    If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
283    the record will be aligned to suit.  */
284
285 void
286 layout_decl (decl, known_align)
287      tree decl;
288      unsigned int known_align;
289 {
290   register tree type = TREE_TYPE (decl);
291   register enum tree_code code = TREE_CODE (decl);
292
293   if (code == CONST_DECL)
294     return;
295   else if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
296            && code != TYPE_DECL && code != FIELD_DECL)
297     abort ();
298
299   if (type == error_mark_node)
300     type = void_type_node;
301
302   /* Usually the size and mode come from the data type without change,
303      however, the front-end may set the explicit width of the field, so its
304      size may not be the same as the size of its type.  This happens with
305      bitfields, of course (an `int' bitfield may be only 2 bits, say), but it
306      also happens with other fields.  For example, the C++ front-end creates
307      zero-sized fields corresponding to empty base classes, and depends on
308      layout_type setting DECL_FIELD_BITPOS correctly for the field.  Set the
309      size in bytes from the size in bits.  If we have already set the mode,
310      don't set it again since we can be called twice for FIELD_DECLs.  */
311
312   TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
313   if (DECL_MODE (decl) == VOIDmode)
314     DECL_MODE (decl) = TYPE_MODE (type);
315
316   if (DECL_SIZE (decl) == 0)
317     {
318       DECL_SIZE (decl) = TYPE_SIZE (type);
319       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
320     }
321   else
322     DECL_SIZE_UNIT (decl)
323       = convert (sizetype, size_binop (CEIL_DIV_EXPR, DECL_SIZE (decl),
324                                        bitsize_unit_node));
325
326   /* Force alignment required for the data type.
327      But if the decl itself wants greater alignment, don't override that.
328      Likewise, if the decl is packed, don't override it.  */
329   if (! (code == FIELD_DECL && DECL_BIT_FIELD (decl))
330       && (DECL_ALIGN (decl) == 0
331           || (! (code == FIELD_DECL && DECL_PACKED (decl))
332               && TYPE_ALIGN (type) > DECL_ALIGN (decl))))
333     DECL_ALIGN (decl) = TYPE_ALIGN (type);
334
335   /* For fields, set the bit field type and update the alignment.  */
336   if (code == FIELD_DECL)
337     {
338       DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
339       if (maximum_field_alignment != 0)
340         DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
341       else if (DECL_PACKED (decl))
342         DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
343     }
344
345   /* See if we can use an ordinary integer mode for a bit-field. 
346      Conditions are: a fixed size that is correct for another mode
347      and occupying a complete byte or bytes on proper boundary.  */
348   if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
349       && TYPE_SIZE (type) != 0
350       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
351       && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
352     {
353       register enum machine_mode xmode
354         = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
355
356       if (xmode != BLKmode && known_align >= GET_MODE_ALIGNMENT (xmode))
357         {
358           DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
359                                    DECL_ALIGN (decl));
360           DECL_MODE (decl) = xmode;
361           DECL_BIT_FIELD (decl) = 0;
362         }
363     }
364
365   /* Turn off DECL_BIT_FIELD if we won't need it set.  */
366   if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
367       && TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
368       && known_align >= TYPE_ALIGN (type)
369       && DECL_ALIGN (decl) >= TYPE_ALIGN (type)
370       && DECL_SIZE_UNIT (decl) != 0)
371     DECL_BIT_FIELD (decl) = 0;
372
373   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
374   if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
375     DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
376   if (DECL_SIZE_UNIT (decl) != 0
377       && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST)
378     DECL_SIZE_UNIT (decl) = variable_size (DECL_SIZE_UNIT (decl));
379
380   /* If requested, warn about definitions of large data objects.  */
381   if (warn_larger_than
382       && (code == VAR_DECL || code == PARM_DECL)
383       && ! DECL_EXTERNAL (decl))
384     {
385       tree size = DECL_SIZE_UNIT (decl);
386
387       if (size != 0 && TREE_CODE (size) == INTEGER_CST
388           && compare_tree_int (size, larger_than_size) > 0)
389         {
390           unsigned int size_as_int = TREE_INT_CST_LOW (size);
391
392           if (compare_tree_int (size, size_as_int) == 0)
393             warning_with_decl (decl, "size of `%s' is %d bytes", size_as_int);
394           else
395             warning_with_decl (decl, "size of `%s' is larger than %d bytes",
396                                larger_than_size);
397         }
398     }
399 }
400 \f
401 /* Begin laying out type T, which may be a RECORD_TYPE, UNION_TYPE, or
402    QUAL_UNION_TYPE.  Return a pointer to a struct record_layout_info which
403    is to be passed to all other layout functions for this record.  It is the
404    responsibility of the caller to call `free' for the storage returned. 
405    Note that garbage collection is not permitted until we finish laying
406    out the record.  */
407
408 record_layout_info
409 start_record_layout (t)
410      tree t;
411 {
412   record_layout_info rli 
413     = (record_layout_info) xmalloc (sizeof (struct record_layout_info));
414
415   rli->t = t;
416
417   /* If the type has a minimum specified alignment (via an attribute
418      declaration, for example) use it -- otherwise, start with a
419      one-byte alignment.  */
420   rli->record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
421   rli->unpacked_align = rli->record_align;
422   rli->offset_align = MAX (rli->record_align, BIGGEST_ALIGNMENT);
423
424 #ifdef STRUCTURE_SIZE_BOUNDARY
425   /* Packed structures don't need to have minimum size.  */
426   if (! TYPE_PACKED (t))
427     rli->record_align = MAX (rli->record_align, STRUCTURE_SIZE_BOUNDARY);
428 #endif
429
430   rli->offset = size_zero_node;
431   rli->bitpos = bitsize_zero_node;
432   rli->pending_statics = 0;
433   rli->packed_maybe_necessary = 0;
434
435   return rli;
436 }
437
438 /* These four routines perform computations that convert between
439    the offset/bitpos forms and byte and bit offsets.  */
440
441 tree
442 bit_from_pos (offset, bitpos)
443      tree offset, bitpos;
444 {
445   return size_binop (PLUS_EXPR, bitpos,
446                      size_binop (MULT_EXPR, convert (bitsizetype, offset),
447                                  bitsize_unit_node));
448 }
449
450 tree
451 byte_from_pos (offset, bitpos)
452      tree offset, bitpos;
453 {
454   return size_binop (PLUS_EXPR, offset,
455                      convert (sizetype,
456                               size_binop (TRUNC_DIV_EXPR, bitpos,
457                                           bitsize_unit_node)));
458 }
459
460 void
461 pos_from_byte (poffset, pbitpos, off_align, pos)
462      tree *poffset, *pbitpos;
463      unsigned int off_align;
464      tree pos;
465 {
466   *poffset
467     = size_binop (MULT_EXPR,
468                   convert (sizetype,
469                            size_binop (FLOOR_DIV_EXPR, pos,
470                                        bitsize_int (off_align
471                                                     / BITS_PER_UNIT))),
472                   size_int (off_align / BITS_PER_UNIT));
473   *pbitpos = size_binop (MULT_EXPR,
474                          size_binop (FLOOR_MOD_EXPR, pos,
475                                      bitsize_int (off_align / BITS_PER_UNIT)),
476                          bitsize_unit_node);
477 }
478
479 void
480 pos_from_bit (poffset, pbitpos, off_align, pos)
481      tree *poffset, *pbitpos;
482      unsigned int off_align;
483      tree pos;
484 {
485   *poffset = size_binop (MULT_EXPR,
486                          convert (sizetype,
487                                   size_binop (FLOOR_DIV_EXPR, pos,
488                                               bitsize_int (off_align))),
489                          size_int (off_align / BITS_PER_UNIT));
490   *pbitpos = size_binop (FLOOR_MOD_EXPR, pos, bitsize_int (off_align));
491 }
492
493 /* Given a pointer to bit and byte offsets and an offset alignment,
494    normalize the offsets so they are within the alignment.  */
495
496 void
497 normalize_offset (poffset, pbitpos, off_align)
498      tree *poffset, *pbitpos;
499      unsigned int off_align;
500 {
501   /* If the bit position is now larger than it should be, adjust it
502      downwards.  */
503   if (compare_tree_int (*pbitpos, off_align) >= 0)
504     {
505       tree extra_aligns = size_binop (FLOOR_DIV_EXPR, *pbitpos,
506                                       bitsize_int (off_align));
507
508       *poffset
509         = size_binop (PLUS_EXPR, *poffset,
510                       size_binop (MULT_EXPR, convert (sizetype, extra_aligns),
511                                   size_int (off_align / BITS_PER_UNIT)));
512                                 
513       *pbitpos
514         = size_binop (FLOOR_MOD_EXPR, *pbitpos, bitsize_int (off_align));
515     }
516 }
517
518 /* Print debugging information about the information in RLI.  */
519
520 void
521 debug_rli (rli)
522      record_layout_info rli;
523 {
524   print_node_brief (stderr, "type", rli->t, 0);
525   print_node_brief (stderr, "\noffset", rli->offset, 0);
526   print_node_brief (stderr, " bitpos", rli->bitpos, 0);
527
528   fprintf (stderr, "\nrec_align = %u, unpack_align = %u, off_align = %u\n",
529            rli->record_align, rli->unpacked_align, rli->offset_align);
530   if (rli->packed_maybe_necessary)
531     fprintf (stderr, "packed may be necessary\n");
532
533   if (rli->pending_statics)
534     {
535       fprintf (stderr, "pending statics:\n");
536       debug_tree (rli->pending_statics);
537     }
538 }
539
540 /* Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and
541    BITPOS if necessary to keep BITPOS below OFFSET_ALIGN.  */
542
543 void
544 normalize_rli (rli)
545      record_layout_info rli;
546 {
547   normalize_offset (&rli->offset, &rli->bitpos, rli->offset_align);
548 }
549
550 /* Returns the size in bytes allocated so far.  */
551
552 tree
553 rli_size_unit_so_far (rli)
554      record_layout_info rli;
555 {
556   return byte_from_pos (rli->offset, rli->bitpos);
557 }
558
559 /* Returns the size in bits allocated so far.  */
560
561 tree
562 rli_size_so_far (rli)
563      record_layout_info rli;
564 {
565   return bit_from_pos (rli->offset, rli->bitpos);
566 }
567
568 /* Called from place_field to handle unions.  */
569
570 static void
571 place_union_field (rli, field)
572      record_layout_info rli;
573      tree field;
574 {
575   layout_decl (field, 0);
576   
577   DECL_FIELD_OFFSET (field) = size_zero_node;
578   DECL_FIELD_BIT_OFFSET (field) = bitsize_zero_node;
579   DECL_OFFSET_ALIGN (field) = BIGGEST_ALIGNMENT;
580
581   /* Union must be at least as aligned as any field requires.  */
582   rli->record_align = MAX (rli->record_align, DECL_ALIGN (field));
583
584 #ifdef PCC_BITFIELD_TYPE_MATTERS
585   /* On the m88000, a bit field of declare type `int' forces the
586      entire union to have `int' alignment.  */
587   if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
588     rli->record_align = MAX (rli->record_align, 
589                              TYPE_ALIGN (TREE_TYPE (field)));
590 #endif
591
592   /* We assume the union's size will be a multiple of a byte so we don't
593      bother with BITPOS.  */
594   if (TREE_CODE (rli->t) == UNION_TYPE)
595     rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field));
596   else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE)
597     rli->offset = fold (build (COND_EXPR, sizetype, 
598                                DECL_QUALIFIER (field),
599                                DECL_SIZE_UNIT (field), rli->offset));
600 }
601
602 /* RLI contains information about the layout of a RECORD_TYPE.  FIELD
603    is a FIELD_DECL to be added after those fields already present in
604    T.  (FIELD is not actually added to the TYPE_FIELDS list here;
605    callers that desire that behavior must manually perform that step.)  */
606
607 void
608 place_field (rli, field)
609      record_layout_info rli;
610      tree field;
611 {
612   /* The alignment required for FIELD.  */
613   unsigned int desired_align;
614   /* The alignment FIELD would have if we just dropped it into the
615      record as it presently stands.  */
616   unsigned int known_align;
617   unsigned int actual_align;
618   /* The type of this field.  */
619   tree type = TREE_TYPE (field);
620  
621   /* If FIELD is static, then treat it like a separate variable, not
622      really like a structure field.  If it is a FUNCTION_DECL, it's a
623      method.  In both cases, all we do is lay out the decl, and we do
624      it *after* the record is laid out.  */
625   if (TREE_CODE (field) == VAR_DECL)
626     {
627       rli->pending_statics = tree_cons (NULL_TREE, field,
628                                         rli->pending_statics);
629       return;
630     }
631
632   /* Enumerators and enum types which are local to this class need not
633      be laid out.  Likewise for initialized constant fields.  */
634   else if (TREE_CODE (field) != FIELD_DECL)
635     return;
636
637   /* Unions are laid out very differently than records, so split
638      that code off to another function.  */
639   else if (TREE_CODE (rli->t) != RECORD_TYPE)
640     {
641       place_union_field (rli, field);
642       return;
643     }
644
645   /* Work out the known alignment so far.  Note that A & (-A) is the
646      value of the least-significant bit in A that is one.  */
647   if (! integer_zerop (rli->bitpos))
648     known_align = (tree_low_cst (rli->bitpos, 1)
649                    & - tree_low_cst (rli->bitpos, 1));
650   else if (integer_zerop (rli->offset))
651     known_align = BIGGEST_ALIGNMENT;
652   else if (host_integerp (rli->offset, 1))
653     known_align = (BITS_PER_UNIT
654                    * (tree_low_cst (rli->offset, 1)
655                       & - tree_low_cst (rli->offset, 1)));
656   else
657     known_align = rli->offset_align;
658
659   /* Lay out the field so we know what alignment it needs.  For a
660      packed field, use the alignment as specified, disregarding what
661      the type would want.  */
662   desired_align = DECL_ALIGN (field);
663   layout_decl (field, known_align);
664   if (! DECL_PACKED (field))
665     desired_align = DECL_ALIGN (field);
666
667   /* Some targets (i.e. VMS) limit struct field alignment
668      to a lower boundary than alignment of variables.  */
669 #ifdef BIGGEST_FIELD_ALIGNMENT
670   desired_align = MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
671 #endif
672 #ifdef ADJUST_FIELD_ALIGN
673   desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
674 #endif
675
676   /* Record must have at least as much alignment as any field.
677      Otherwise, the alignment of the field within the record is
678      meaningless.  */
679 #ifdef PCC_BITFIELD_TYPE_MATTERS
680   if (PCC_BITFIELD_TYPE_MATTERS && type != error_mark_node
681       && DECL_BIT_FIELD_TYPE (field)
682       && ! integer_zerop (TYPE_SIZE (type)))
683     {
684       /* For these machines, a zero-length field does not
685          affect the alignment of the structure as a whole.
686          It does, however, affect the alignment of the next field
687          within the structure.  */
688       if (! integer_zerop (DECL_SIZE (field)))
689         rli->record_align = MAX (rli->record_align, desired_align);
690       else if (! DECL_PACKED (field))
691         desired_align = TYPE_ALIGN (type);
692
693       /* A named bit field of declared type `int'
694          forces the entire structure to have `int' alignment.  */
695       if (DECL_NAME (field) != 0)
696         {
697           unsigned int type_align = TYPE_ALIGN (type);
698
699           if (maximum_field_alignment != 0)
700             type_align = MIN (type_align, maximum_field_alignment);
701           else if (DECL_PACKED (field))
702             type_align = MIN (type_align, BITS_PER_UNIT);
703
704           rli->record_align = MAX (rli->record_align, type_align);
705           if (warn_packed)
706             rli->unpacked_align = MAX (rli->unpacked_align, 
707                                        TYPE_ALIGN (type));
708         }
709     }
710   else
711 #endif
712     {
713       rli->record_align = MAX (rli->record_align, desired_align);
714       rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
715     }
716
717   if (warn_packed && DECL_PACKED (field))
718     {
719       if (known_align > TYPE_ALIGN (type))
720         {
721           if (TYPE_ALIGN (type) > desired_align)
722             {
723               if (STRICT_ALIGNMENT)
724                 warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
725               else
726                 warning_with_decl (field, "packed attribute is unnecessary for `%s'");
727             }
728         }
729       else
730         rli->packed_maybe_necessary = 1;
731     }
732
733   /* Does this field automatically have alignment it needs by virtue
734      of the fields that precede it and the record's own alignment?  */
735   if (known_align < desired_align)
736     {
737       /* No, we need to skip space before this field.
738          Bump the cumulative size to multiple of field alignment.  */
739
740       if (warn_padded)
741         warning_with_decl (field, "padding struct to align `%s'");
742
743       /* If the alignment is still within offset_align, just align
744          the bit position.  */
745       if (desired_align < rli->offset_align)
746         rli->bitpos = round_up (rli->bitpos, desired_align);
747       else
748         {
749           /* First adjust OFFSET by the partial bits, then align.  */
750           rli->offset
751             = size_binop (PLUS_EXPR, rli->offset,
752                           convert (sizetype,
753                                    size_binop (CEIL_DIV_EXPR, rli->bitpos,
754                                                bitsize_unit_node)));
755           rli->bitpos = bitsize_zero_node;
756
757           rli->offset = round_up (rli->offset, desired_align / BITS_PER_UNIT);
758         }
759
760       if (! TREE_CONSTANT (rli->offset))
761         rli->offset_align = desired_align;
762
763     }
764
765   /* Handle compatibility with PCC.  Note that if the record has any
766      variable-sized fields, we need not worry about compatibility.  */
767 #ifdef PCC_BITFIELD_TYPE_MATTERS
768   if (PCC_BITFIELD_TYPE_MATTERS
769       && TREE_CODE (field) == FIELD_DECL
770       && type != error_mark_node
771       && DECL_BIT_FIELD (field)
772       && ! DECL_PACKED (field)
773       && maximum_field_alignment == 0
774       && ! integer_zerop (DECL_SIZE (field))
775       && host_integerp (DECL_SIZE (field), 1)
776       && host_integerp (rli->offset, 1)
777       && host_integerp (TYPE_SIZE (type), 1))
778     {
779       unsigned int type_align = TYPE_ALIGN (type);
780       tree dsize = DECL_SIZE (field);
781       HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
782       HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
783       HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
784
785       /* A bit field may not span more units of alignment of its type
786          than its type itself.  Advance to next boundary if necessary.  */
787       if ((((offset * BITS_PER_UNIT + bit_offset + field_size +
788              type_align - 1)
789             / type_align)
790            - (offset * BITS_PER_UNIT + bit_offset) / type_align)
791           > tree_low_cst (TYPE_SIZE (type), 1) / type_align)
792         rli->bitpos = round_up (rli->bitpos, type_align);
793     }
794 #endif
795
796 #ifdef BITFIELD_NBYTES_LIMITED
797   if (BITFIELD_NBYTES_LIMITED
798       && TREE_CODE (field) == FIELD_DECL
799       && type != error_mark_node
800       && DECL_BIT_FIELD_TYPE (field)
801       && ! DECL_PACKED (field)
802       && ! integer_zerop (DECL_SIZE (field))
803       && host_integerp (DECL_SIZE (field), 1)
804       && host_integerp (rli->size, 1)
805       && host_integerp (TYPE_SIZE (type), 1))
806     {
807       unsigned int type_align = TYPE_ALIGN (type);
808       tree dsize = DECL_SIZE (field);
809       HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
810       HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
811       HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
812
813       if (maximum_field_alignment != 0)
814         type_align = MIN (type_align, maximum_field_alignment);
815       /* ??? This test is opposite the test in the containing if
816          statement, so this code is unreachable currently.  */
817       else if (DECL_PACKED (field))
818         type_align = MIN (type_align, BITS_PER_UNIT);
819
820       /* A bit field may not span the unit of alignment of its type.
821          Advance to next boundary if necessary.  */
822       /* ??? This code should match the code above for the
823          PCC_BITFIELD_TYPE_MATTERS case.  */
824       if ((offset * BITS_PER_UNIT + bit_offset) / type_align
825           != ((offset * BITS_PER_UNIT + bit_offset + field_size - 1)
826               / type_align))
827         rli->bitpos = round_up (rli->bitpos, type_align);
828     }
829 #endif
830
831   /* Offset so far becomes the position of this field after normalizing.  */
832   normalize_rli (rli);
833   DECL_FIELD_OFFSET (field) = rli->offset;
834   DECL_FIELD_BIT_OFFSET (field) = rli->bitpos;
835   DECL_OFFSET_ALIGN (field) = rli->offset_align;
836
837   /* If this field ended up more aligned than we thought it would be (we
838      approximate this by seeing if its position changed), lay out the field
839      again; perhaps we can use an integral mode for it now.  */
840   if (! integer_zerop (DECL_FIELD_BIT_OFFSET (field)))
841     actual_align = (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
842                     & - tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1));
843   else if (integer_zerop (DECL_FIELD_OFFSET (field)))
844     actual_align = BIGGEST_ALIGNMENT;
845   else if (host_integerp (DECL_FIELD_OFFSET (field), 1))
846     actual_align = (BITS_PER_UNIT
847                    * (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
848                       & - tree_low_cst (DECL_FIELD_OFFSET (field), 1)));
849   else
850     actual_align = DECL_OFFSET_ALIGN (field);
851
852   if (known_align != actual_align)
853     layout_decl (field, actual_align);
854
855   /* Now add size of this field to the size of the record.  If the size is
856      not constant, treat the field as being a multiple of bytes and just
857      adjust the offset, resetting the bit position.  Otherwise, apportion the
858      size amongst the bit position and offset.  First handle the case of an
859      unspecified size, which can happen when we have an invalid nested struct
860      definition, such as struct j { struct j { int i; } }.  The error message
861      is printed in finish_struct.  */
862   if (DECL_SIZE (field) == 0)
863     /* Do nothing.  */;
864   else if (! TREE_CONSTANT (DECL_SIZE_UNIT (field)))
865     {
866       rli->offset
867         = size_binop (PLUS_EXPR, rli->offset,
868                       convert (sizetype,
869                                size_binop (CEIL_DIV_EXPR, rli->bitpos,
870                                            bitsize_unit_node)));
871       rli->offset
872         = size_binop (PLUS_EXPR, rli->offset, DECL_SIZE_UNIT (field));
873       rli->bitpos = bitsize_zero_node;
874       rli->offset_align = MIN (rli->offset_align, DECL_ALIGN (field));
875     }
876   else
877     {
878       rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field));
879       normalize_rli (rli);
880     }
881 }
882
883 /* Assuming that all the fields have been laid out, this function uses
884    RLI to compute the final TYPE_SIZE, TYPE_ALIGN, etc. for the type
885    inidicated by RLI.  */
886
887 static void
888 finalize_record_size (rli)
889      record_layout_info rli;
890 {
891   tree unpadded_size, unpadded_size_unit;
892
893   /* Now we want just byte and bit offsets, so set the offset alignment
894      to be a byte and then normalize.  */
895   rli->offset_align = BITS_PER_UNIT;
896   normalize_rli (rli);
897
898   /* Determine the desired alignment.  */
899 #ifdef ROUND_TYPE_ALIGN
900   TYPE_ALIGN (rli->t) = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t),
901                                           rli->record_align);
902 #else
903   TYPE_ALIGN (rli->t) = MAX (TYPE_ALIGN (rli->t), rli->record_align);
904 #endif
905
906   /* Compute the size so far.  Be sure to allow for extra bits in the
907      size in bytes.  We have guaranteed above that it will be no more
908      than a single byte.  */
909   unpadded_size = rli_size_so_far (rli);
910   unpadded_size_unit = rli_size_unit_so_far (rli);
911   if (! integer_zerop (rli->bitpos))
912     unpadded_size_unit
913       = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node);
914
915   /* Record the un-rounded size in the binfo node.  But first we check
916      the size of TYPE_BINFO to make sure that BINFO_SIZE is available.  */
917   if (TYPE_BINFO (rli->t) && TREE_VEC_LENGTH (TYPE_BINFO (rli->t)) > 6)
918     {
919       TYPE_BINFO_SIZE (rli->t) = unpadded_size;
920       TYPE_BINFO_SIZE_UNIT (rli->t) = unpadded_size_unit;
921     }
922
923     /* Round the size up to be a multiple of the required alignment */
924 #ifdef ROUND_TYPE_SIZE
925   TYPE_SIZE (rli->t) = ROUND_TYPE_SIZE (rli->t, unpadded_size,
926                                         TYPE_ALIGN (rli->t));
927   TYPE_SIZE_UNIT (rli->t)
928     = ROUND_TYPE_SIZE_UNIT (rli->t, unpaded_size_unit,
929                             TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
930 #else
931   TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
932   TYPE_SIZE_UNIT (rli->t) = round_up (unpadded_size_unit,
933                                       TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
934 #endif
935
936   if (warn_padded && TREE_CONSTANT (unpadded_size)
937       && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0)
938     warning ("padding struct size to alignment boundary");
939   
940   if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
941       && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
942       && TREE_CONSTANT (unpadded_size))
943     {
944       tree unpacked_size;
945
946 #ifdef ROUND_TYPE_ALIGN
947       rli->unpacked_align
948         = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align);
949 #else
950       rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align);
951 #endif
952
953 #ifdef ROUND_TYPE_SIZE
954       unpacked_size = ROUND_TYPE_SIZE (rli->t, TYPE_SIZE (rli->t),
955                                        rli->unpacked_align);
956 #else
957       unpacked_size = round_up (TYPE_SIZE (rli->t), rli->unpacked_align);
958 #endif
959
960       if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t)))
961         {
962           TYPE_PACKED (rli->t) = 0;
963
964           if (TYPE_NAME (rli->t))
965             {
966               char *name;
967
968               if (TREE_CODE (TYPE_NAME (rli->t)) == IDENTIFIER_NODE)
969                 name = IDENTIFIER_POINTER (TYPE_NAME (rli->t));
970               else
971                 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (rli->t)));
972
973               if (STRICT_ALIGNMENT)
974                 warning ("packed attribute causes inefficient alignment for `%s'", name);
975               else
976                 warning ("packed attribute is unnecessary for `%s'", name);
977             }
978           else
979             {
980               if (STRICT_ALIGNMENT)
981                 warning ("packed attribute causes inefficient alignment");
982               else
983                 warning ("packed attribute is unnecessary");
984             }
985         }
986     }
987 }
988
989 /* Compute the TYPE_MODE for the TYPE (which is a RECORD_TYPE).  */
990
991 void
992 compute_record_mode (type)
993      tree type;
994 {
995   tree field;
996   enum machine_mode mode = VOIDmode;
997
998   /* Most RECORD_TYPEs have BLKmode, so we start off assuming that.
999      However, if possible, we use a mode that fits in a register
1000      instead, in order to allow for better optimization down the
1001      line.  */
1002   TYPE_MODE (type) = BLKmode;
1003
1004   if (! host_integerp (TYPE_SIZE (type), 1))
1005     return;
1006
1007   /* A record which has any BLKmode members must itself be
1008      BLKmode; it can't go in a register.  Unless the member is
1009      BLKmode only because it isn't aligned.  */
1010   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1011     {
1012       unsigned HOST_WIDE_INT bitpos;
1013
1014       if (TREE_CODE (field) != FIELD_DECL)
1015         continue;
1016
1017       if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK
1018           || (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1019               && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
1020           || ! host_integerp (bit_position (field), 1)
1021           || ! host_integerp (DECL_SIZE (field), 1))
1022         return;
1023
1024       bitpos = int_bit_position (field);
1025           
1026       /* Must be BLKmode if any field crosses a word boundary,
1027          since extract_bit_field can't handle that in registers.  */
1028       if (bitpos / BITS_PER_WORD
1029           != ((TREE_INT_CST_LOW (DECL_SIZE (field)) + bitpos - 1)
1030               / BITS_PER_WORD)
1031           /* But there is no problem if the field is entire words.  */
1032           && tree_low_cst (DECL_SIZE (field), 1) % BITS_PER_WORD != 0)
1033         return;
1034
1035       /* If this field is the whole struct, remember its mode so
1036          that, say, we can put a double in a class into a DF
1037          register instead of forcing it to live in the stack.  */
1038       if (field == TYPE_FIELDS (type) && TREE_CHAIN (field) == 0)
1039         mode = DECL_MODE (field);
1040
1041 #ifdef STRUCT_FORCE_BLK
1042       /* With some targets, eg. c4x, it is sub-optimal
1043          to access an aligned BLKmode structure as a scalar.  */
1044       if (mode == VOIDmode && STRUCT_FORCE_BLK (field))
1045         return;
1046 #endif /* STRUCT_FORCE_BLK  */
1047     }
1048
1049   if (mode != VOIDmode)
1050     /* We only have one real field; use its mode.  */
1051     TYPE_MODE (type) = mode;
1052   else
1053     TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1054
1055   /* If structure's known alignment is less than what the scalar
1056      mode would need, and it matters, then stick with BLKmode.  */
1057   if (TYPE_MODE (type) != BLKmode
1058       && STRICT_ALIGNMENT
1059       && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1060             || TYPE_ALIGN (type) >= GET_MODE_ALIGNMENT (TYPE_MODE (type))))
1061     {
1062       /* If this is the only reason this type is BLKmode, then
1063          don't force containing types to be BLKmode.  */
1064       TYPE_NO_FORCE_BLK (type) = 1;
1065       TYPE_MODE (type) = BLKmode;
1066     }
1067 }
1068
1069 /* Compute TYPE_SIZE and TYPE_ALIGN for TYPE, once it has been laid
1070    out.  */
1071
1072 static void
1073 finalize_type_size (type)
1074      tree type;
1075 {
1076   /* Normally, use the alignment corresponding to the mode chosen.
1077      However, where strict alignment is not required, avoid
1078      over-aligning structures, since most compilers do not do this
1079      alignment.  */
1080
1081   if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1082       && (STRICT_ALIGNMENT
1083           || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1084               && TREE_CODE (type) != QUAL_UNION_TYPE
1085               && TREE_CODE (type) != ARRAY_TYPE)))
1086     TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1087
1088   /* Do machine-dependent extra alignment.  */
1089 #ifdef ROUND_TYPE_ALIGN
1090   TYPE_ALIGN (type)
1091     = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (type), BITS_PER_UNIT);
1092 #endif
1093
1094   /* If we failed to find a simple way to calculate the unit size
1095      of the type, find it by division.  */
1096   if (TYPE_SIZE_UNIT (type) == 0 && TYPE_SIZE (type) != 0)
1097     /* TYPE_SIZE (type) is computed in bitsizetype.  After the division, the
1098        result will fit in sizetype.  We will get more efficient code using
1099        sizetype, so we force a conversion.  */
1100     TYPE_SIZE_UNIT (type)
1101       = convert (sizetype,
1102                  size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type),
1103                              bitsize_unit_node));
1104
1105   if (TYPE_SIZE (type) != 0)
1106     {
1107 #ifdef ROUND_TYPE_SIZE
1108       TYPE_SIZE (type)
1109         = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1110       TYPE_SIZE_UNIT (type)
1111         = ROUND_TYPE_SIZE_UNIT (type, TYPE_SIZE_UNIT (type),
1112                                 TYPE_ALIGN (type) / BITS_PER_UNIT);
1113 #else
1114       TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
1115       TYPE_SIZE_UNIT (type)
1116         = round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type) / BITS_PER_UNIT);
1117 #endif
1118     }
1119
1120   /* Evaluate nonconstant sizes only once, either now or as soon as safe.  */
1121   if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1122     TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1123   if (TYPE_SIZE_UNIT (type) != 0
1124       && TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
1125     TYPE_SIZE_UNIT (type) = variable_size (TYPE_SIZE_UNIT (type));
1126
1127   /* Also layout any other variants of the type.  */
1128   if (TYPE_NEXT_VARIANT (type)
1129       || type != TYPE_MAIN_VARIANT (type))
1130     {
1131       tree variant;
1132       /* Record layout info of this variant.  */
1133       tree size = TYPE_SIZE (type);
1134       tree size_unit = TYPE_SIZE_UNIT (type);
1135       unsigned int align = TYPE_ALIGN (type);
1136       enum machine_mode mode = TYPE_MODE (type);
1137
1138       /* Copy it into all variants.  */
1139       for (variant = TYPE_MAIN_VARIANT (type);
1140            variant != 0;
1141            variant = TYPE_NEXT_VARIANT (variant))
1142         {
1143           TYPE_SIZE (variant) = size;
1144           TYPE_SIZE_UNIT (variant) = size_unit;
1145           TYPE_ALIGN (variant) = align;
1146           TYPE_MODE (variant) = mode;
1147         }
1148     }
1149 }
1150
1151 /* Do all of the work required to layout the type indicated by RLI,
1152    once the fields have been laid out.  This function will call `free'
1153    for RLI.  */
1154
1155 void
1156 finish_record_layout (rli)
1157      record_layout_info rli;
1158 {
1159   /* Compute the final size.  */
1160   finalize_record_size (rli);
1161
1162   /* Compute the TYPE_MODE for the record.  */
1163   compute_record_mode (rli->t);
1164
1165   /* Lay out any static members.  This is done now because their type
1166      may use the record's type.  */
1167   while (rli->pending_statics)
1168     {
1169       layout_decl (TREE_VALUE (rli->pending_statics), 0);
1170       rli->pending_statics = TREE_CHAIN (rli->pending_statics);
1171     }
1172
1173   /* Perform any last tweaks to the TYPE_SIZE, etc.  */
1174   finalize_type_size (rli->t);
1175
1176   /* Clean up.  */
1177   free (rli);
1178 }
1179 \f
1180 /* Calculate the mode, size, and alignment for TYPE.
1181    For an array type, calculate the element separation as well.
1182    Record TYPE on the chain of permanent or temporary types
1183    so that dbxout will find out about it.
1184
1185    TYPE_SIZE of a type is nonzero if the type has been laid out already.
1186    layout_type does nothing on such a type.
1187
1188    If the type is incomplete, its TYPE_SIZE remains zero.  */
1189
1190 void
1191 layout_type (type)
1192      tree type;
1193 {
1194   int old;
1195
1196   if (type == 0)
1197     abort ();
1198
1199   /* Do nothing if type has been laid out before.  */
1200   if (TYPE_SIZE (type))
1201     return;
1202
1203   /* Make sure all nodes we allocate are not momentary; they must last
1204      past the current statement.  */
1205   old = suspend_momentary ();
1206
1207   /* Put all our nodes into the same obstack as the type.  Also,
1208      make expressions saveable (this is a no-op for permanent types).  */
1209
1210   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
1211   saveable_allocation ();
1212
1213   switch (TREE_CODE (type))
1214     {
1215     case LANG_TYPE:
1216       /* This kind of type is the responsibility
1217          of the language-specific code.  */
1218       abort ();
1219
1220     case BOOLEAN_TYPE:  /* Used for Java, Pascal, and Chill. */
1221       if (TYPE_PRECISION (type) == 0)
1222         TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
1223
1224       /* ... fall through ... */
1225
1226     case INTEGER_TYPE:
1227     case ENUMERAL_TYPE:
1228     case CHAR_TYPE:
1229       if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1230           && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
1231         TREE_UNSIGNED (type) = 1;
1232
1233       TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
1234                                                  MODE_INT);
1235       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1236       TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1237       break;
1238
1239     case REAL_TYPE:
1240       TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
1241       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1242       TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1243       break;
1244
1245     case COMPLEX_TYPE:
1246       TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
1247       TYPE_MODE (type)
1248         = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
1249                          (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
1250                           ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
1251                          0);
1252       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
1253       TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
1254       break;
1255
1256     case VOID_TYPE:
1257       /* This is an incomplete type and so doesn't have a size.  */
1258       TYPE_ALIGN (type) = 1;
1259       TYPE_MODE (type) = VOIDmode;
1260       break;
1261
1262     case OFFSET_TYPE:
1263       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
1264       TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
1265       TYPE_MODE (type) = ptr_mode;
1266       break;
1267
1268     case FUNCTION_TYPE:
1269     case METHOD_TYPE:
1270       TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
1271       TYPE_SIZE (type) = bitsize_int (2 * POINTER_SIZE);
1272       TYPE_SIZE_UNIT (type) = size_int ((2 * POINTER_SIZE) / BITS_PER_UNIT);
1273       break;
1274
1275     case POINTER_TYPE:
1276     case REFERENCE_TYPE:
1277       TYPE_MODE (type) = ptr_mode;
1278       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
1279       TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
1280       TREE_UNSIGNED (type) = 1;
1281       TYPE_PRECISION (type) = POINTER_SIZE;
1282       break;
1283
1284     case ARRAY_TYPE:
1285       {
1286         register tree index = TYPE_DOMAIN (type);
1287         register tree element = TREE_TYPE (type);
1288
1289         build_pointer_type (element);
1290
1291         /* We need to know both bounds in order to compute the size.  */
1292         if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
1293             && TYPE_SIZE (element))
1294           {
1295             tree ub = TYPE_MAX_VALUE (index);
1296             tree lb = TYPE_MIN_VALUE (index);
1297             tree length;
1298             tree element_size;
1299
1300             /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
1301                test for negative below covers it.  */
1302             if (TREE_CODE (ub) == MAX_EXPR
1303                 && TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
1304                 && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
1305                 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
1306                                     lb, 0))
1307               ub = TREE_OPERAND (ub, 1);
1308             else if (TREE_CODE (ub) == MAX_EXPR
1309                      && TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
1310                      && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
1311                      && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
1312                                                        0),
1313                                          lb, 0))
1314               ub = TREE_OPERAND (ub, 0);
1315
1316             /* The initial subtraction should happen in the original type so
1317                that (possible) negative values are handled appropriately.  */
1318             length = size_binop (PLUS_EXPR, size_one_node,
1319                                  convert (sizetype,
1320                                           fold (build (MINUS_EXPR,
1321                                                        TREE_TYPE (lb),
1322                                                        ub, lb))));
1323
1324             /* If neither bound is a constant and sizetype is signed, make
1325                sure the size is never negative.  We should really do this
1326                if *either* bound is non-constant, but this is the best
1327                compromise between C and Ada.  */
1328             if (! TREE_UNSIGNED (sizetype)
1329                 && TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
1330                 && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
1331               length = size_binop (MAX_EXPR, length, size_zero_node);
1332
1333             /* Special handling for arrays of bits (for Chill).  */
1334             element_size = TYPE_SIZE (element);
1335             if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element))
1336               {
1337                 HOST_WIDE_INT maxvalue
1338                   = TREE_INT_CST_LOW (TYPE_MAX_VALUE (element));
1339                 HOST_WIDE_INT minvalue
1340                   = TREE_INT_CST_LOW (TYPE_MIN_VALUE (element));
1341
1342                 if (maxvalue - minvalue == 1
1343                     && (maxvalue == 1 || maxvalue == 0))
1344                   element_size = integer_one_node;
1345               }
1346
1347             TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
1348                                            convert (bitsizetype, length));
1349
1350             /* If we know the size of the element, calculate the total
1351                size directly, rather than do some division thing below.
1352                This optimization helps Fortran assumed-size arrays
1353                (where the size of the array is determined at runtime)
1354                substantially.
1355                Note that we can't do this in the case where the size of
1356                the elements is one bit since TYPE_SIZE_UNIT cannot be
1357                set correctly in that case.  */
1358             if (TYPE_SIZE_UNIT (element) != 0 && ! integer_onep (element_size))
1359               TYPE_SIZE_UNIT (type)
1360                 = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length);
1361           }
1362
1363         /* Now round the alignment and size,
1364            using machine-dependent criteria if any.  */
1365
1366 #ifdef ROUND_TYPE_ALIGN
1367         TYPE_ALIGN (type)
1368           = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
1369 #else
1370         TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
1371 #endif
1372
1373 #ifdef ROUND_TYPE_SIZE
1374         if (TYPE_SIZE (type) != 0)
1375           {
1376             tree tmp
1377               = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
1378
1379             /* If the rounding changed the size of the type, remove any
1380                pre-calculated TYPE_SIZE_UNIT.  */
1381             if (simple_cst_equal (TYPE_SIZE (type), tmp) != 1)
1382               TYPE_SIZE_UNIT (type) = NULL;
1383
1384             TYPE_SIZE (type) = tmp;
1385           }
1386 #endif
1387
1388         TYPE_MODE (type) = BLKmode;
1389         if (TYPE_SIZE (type) != 0
1390             /* BLKmode elements force BLKmode aggregate;
1391                else extract/store fields may lose.  */
1392             && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
1393                 || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
1394           {
1395             TYPE_MODE (type)
1396               = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
1397
1398             if (TYPE_MODE (type) != BLKmode
1399                 && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
1400                 && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type))
1401                 && TYPE_MODE (type) != BLKmode)
1402               {
1403                 TYPE_NO_FORCE_BLK (type) = 1;
1404                 TYPE_MODE (type) = BLKmode;
1405               }
1406           }
1407         break;
1408       }
1409
1410     case RECORD_TYPE:
1411     case UNION_TYPE:
1412     case QUAL_UNION_TYPE:
1413       {
1414         tree field;
1415         record_layout_info rli;
1416
1417         /* Initialize the layout information.  */
1418         rli = start_record_layout (type);
1419
1420         /* If this is a QUAL_UNION_TYPE, we want to process the fields
1421            in the reverse order in building the COND_EXPR that denotes
1422            its size.  We reverse them again later.  */
1423         if (TREE_CODE (type) == QUAL_UNION_TYPE)
1424           TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1425
1426         /* Place all the fields.  */
1427         for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1428           place_field (rli, field);
1429
1430         if (TREE_CODE (type) == QUAL_UNION_TYPE)
1431           TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
1432
1433         /* Finish laying out the record.  */
1434         finish_record_layout (rli);
1435       }
1436       break;
1437
1438     case SET_TYPE:  /* Used by Chill and Pascal. */
1439       if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
1440           || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
1441         abort();
1442       else
1443         {
1444 #ifndef SET_WORD_SIZE
1445 #define SET_WORD_SIZE BITS_PER_WORD
1446 #endif
1447           unsigned int alignment
1448             = set_alignment ? set_alignment : SET_WORD_SIZE;
1449           int size_in_bits
1450             = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1451                - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
1452           int rounded_size
1453             = ((size_in_bits + alignment - 1) / alignment) * alignment;
1454
1455           if (rounded_size > (int) alignment)
1456             TYPE_MODE (type) = BLKmode;
1457           else
1458             TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
1459
1460           TYPE_SIZE (type) = bitsize_int (rounded_size);
1461           TYPE_SIZE_UNIT (type) = size_int (rounded_size / BITS_PER_UNIT);
1462           TYPE_ALIGN (type) = alignment;
1463           TYPE_PRECISION (type) = size_in_bits;
1464         }
1465       break;
1466
1467     case FILE_TYPE:
1468       /* The size may vary in different languages, so the language front end
1469          should fill in the size.  */
1470       TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
1471       TYPE_MODE  (type) = BLKmode;
1472       break;
1473
1474     default:
1475       abort ();
1476     }
1477
1478   /* Compute the final TYPE_SIZE, TYPE_ALIGN, etc. for TYPE.  For
1479      records and unions, finish_record_layout already called this
1480      function.  */
1481   if (TREE_CODE (type) != RECORD_TYPE 
1482       && TREE_CODE (type) != UNION_TYPE
1483       && TREE_CODE (type) != QUAL_UNION_TYPE)
1484     finalize_type_size (type);
1485
1486   pop_obstacks ();
1487   resume_momentary (old);
1488
1489   /* If this type is created before sizetype has been permanently set,
1490      record it so set_sizetype can fix it up.  */
1491   if (! sizetype_set)
1492     early_type_list = tree_cons (NULL_TREE, type, early_type_list);
1493 }
1494 \f
1495 /* Create and return a type for signed integers of PRECISION bits.  */
1496
1497 tree
1498 make_signed_type (precision)
1499      int precision;
1500 {
1501   register tree type = make_node (INTEGER_TYPE);
1502
1503   TYPE_PRECISION (type) = precision;
1504
1505   fixup_signed_type (type);
1506   return type;
1507 }
1508
1509 /* Create and return a type for unsigned integers of PRECISION bits.  */
1510
1511 tree
1512 make_unsigned_type (precision)
1513      int precision;
1514 {
1515   register tree type = make_node (INTEGER_TYPE);
1516
1517   TYPE_PRECISION (type) = precision;
1518
1519   fixup_unsigned_type (type);
1520   return type;
1521 }
1522 \f
1523 /* Initialize sizetype and bitsizetype to a reasonable and temporary
1524    value to enable integer types to be created.  */
1525
1526 void
1527 initialize_sizetypes ()
1528 {
1529   tree t = make_node (INTEGER_TYPE);
1530
1531   /* Set this so we do something reasonable for the build_int_2 calls
1532      below.  */
1533   integer_type_node = t;
1534
1535   TYPE_MODE (t) = SImode;
1536   TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
1537   TYPE_SIZE (t) = build_int_2 (GET_MODE_BITSIZE (SImode), 0);
1538   TYPE_SIZE_UNIT (t) = build_int_2 (GET_MODE_SIZE (SImode), 0);
1539   TREE_UNSIGNED (t) = 1;
1540   TYPE_PRECISION (t) = GET_MODE_BITSIZE (SImode);
1541   TYPE_MIN_VALUE (t) = build_int_2 (0, 0);
1542   TYPE_IS_SIZETYPE (t) = 1;
1543
1544   /* 1000 avoids problems with possible overflow and is certainly
1545      larger than any size value we'd want to be storing.  */
1546   TYPE_MAX_VALUE (t) = build_int_2 (1000, 0);
1547
1548   /* These two must be different nodes because of the caching done in
1549      size_int_wide.  */
1550   sizetype = t;
1551   bitsizetype = copy_node (t);
1552   integer_type_node = 0;
1553 }
1554
1555 /* Set sizetype to TYPE, and initialize *sizetype accordingly.
1556    Also update the type of any standard type's sizes made so far.  */
1557
1558 void
1559 set_sizetype (type)
1560      tree type;
1561 {
1562   int oprecision = TYPE_PRECISION (type);
1563   /* The *bitsizetype types use a precision that avoids overflows when
1564      calculating signed sizes / offsets in bits.  However, when
1565      cross-compiling from a 32 bit to a 64 bit host, we are limited to 64 bit
1566      precision.  */
1567   int precision = MIN (oprecision + BITS_PER_UNIT_LOG + 1,
1568                        2 * HOST_BITS_PER_WIDE_INT);
1569   unsigned int i;
1570   tree t;
1571
1572   if (sizetype_set)
1573     abort ();
1574
1575   /* Make copies of nodes since we'll be setting TYPE_IS_SIZETYPE.  */
1576   sizetype = copy_node (type);
1577   TYPE_DOMAIN (sizetype) = type;
1578   TYPE_IS_SIZETYPE (sizetype) = 1;
1579   bitsizetype = make_node (INTEGER_TYPE);
1580   TYPE_NAME (bitsizetype) = TYPE_NAME (type);
1581   TYPE_PRECISION (bitsizetype) = precision;
1582   TYPE_IS_SIZETYPE (bitsizetype) = 1;
1583
1584   if (TREE_UNSIGNED (type))
1585     fixup_unsigned_type (bitsizetype);
1586   else
1587     fixup_signed_type (bitsizetype);
1588
1589   layout_type (bitsizetype);
1590
1591   if (TREE_UNSIGNED (type))
1592     {
1593       usizetype = sizetype;
1594       ubitsizetype = bitsizetype;
1595       ssizetype = copy_node (make_signed_type (oprecision));
1596       sbitsizetype = copy_node (make_signed_type (precision));
1597     }
1598   else
1599     {
1600       ssizetype = sizetype;
1601       sbitsizetype = bitsizetype;
1602       usizetype = copy_node (make_unsigned_type (oprecision));
1603       ubitsizetype = copy_node (make_unsigned_type (precision));
1604     }
1605
1606   TYPE_NAME (bitsizetype) = get_identifier ("bit_size_type");
1607
1608   /* Show is a sizetype, is a main type, and has no pointers to it.  */
1609   for (i = 0; i < sizeof sizetype_tab / sizeof sizetype_tab[0]; i++)
1610     {
1611       TYPE_IS_SIZETYPE (sizetype_tab[i]) = 1;
1612       TYPE_MAIN_VARIANT (sizetype_tab[i]) = sizetype_tab[i];
1613       TYPE_NEXT_VARIANT (sizetype_tab[i]) = 0;
1614       TYPE_POINTER_TO (sizetype_tab[i]) = 0;
1615       TYPE_REFERENCE_TO (sizetype_tab[i]) = 0;
1616     }
1617
1618   ggc_add_tree_root ((tree *) &sizetype_tab,
1619                      sizeof sizetype_tab / sizeof (tree));
1620
1621   /* Go down each of the types we already made and set the proper type
1622      for the sizes in them.  */
1623   for (t = early_type_list; t != 0; t = TREE_CHAIN (t))
1624     {
1625       if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE)
1626         abort ();
1627
1628       TREE_TYPE (TYPE_SIZE (TREE_VALUE (t))) = bitsizetype;
1629       TREE_TYPE (TYPE_SIZE_UNIT (TREE_VALUE (t))) = sizetype;
1630     }
1631
1632   early_type_list = 0;
1633   sizetype_set = 1;
1634 }
1635 \f
1636 /* Set the extreme values of TYPE based on its precision in bits,
1637    then lay it out.  Used when make_signed_type won't do
1638    because the tree code is not INTEGER_TYPE.
1639    E.g. for Pascal, when the -fsigned-char option is given.  */
1640
1641 void
1642 fixup_signed_type (type)
1643      tree type;
1644 {
1645   register int precision = TYPE_PRECISION (type);
1646
1647   TYPE_MIN_VALUE (type)
1648     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1649                     ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1650                    (((HOST_WIDE_INT) (-1)
1651                      << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1652                          ? precision - HOST_BITS_PER_WIDE_INT - 1
1653                          : 0))));
1654   TYPE_MAX_VALUE (type)
1655     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1656                     ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1657                    (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1658                     ? (((HOST_WIDE_INT) 1
1659                         << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1660                     : 0));
1661
1662   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1663   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1664
1665   /* Lay out the type: set its alignment, size, etc.  */
1666   layout_type (type);
1667 }
1668
1669 /* Set the extreme values of TYPE based on its precision in bits,
1670    then lay it out.  This is used both in `make_unsigned_type'
1671    and for enumeral types.  */
1672
1673 void
1674 fixup_unsigned_type (type)
1675      tree type;
1676 {
1677   register int precision = TYPE_PRECISION (type);
1678
1679   TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1680   TYPE_MAX_VALUE (type)
1681     = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1682                    ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1683                    precision - HOST_BITS_PER_WIDE_INT > 0
1684                    ? ((unsigned HOST_WIDE_INT) ~0
1685                       >> (HOST_BITS_PER_WIDE_INT
1686                           - (precision - HOST_BITS_PER_WIDE_INT)))
1687                    : 0);
1688   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1689   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1690
1691   /* Lay out the type: set its alignment, size, etc.  */
1692   layout_type (type);
1693 }
1694 \f
1695 /* Find the best machine mode to use when referencing a bit field of length
1696    BITSIZE bits starting at BITPOS.
1697
1698    The underlying object is known to be aligned to a boundary of ALIGN bits.
1699    If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1700    larger than LARGEST_MODE (usually SImode).
1701
1702    If no mode meets all these conditions, we return VOIDmode.  Otherwise, if
1703    VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1704    mode meeting these conditions.
1705
1706    Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1707    the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1708    all the conditions.  */
1709
1710 enum machine_mode
1711 get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1712      int bitsize, bitpos;
1713      unsigned int align;
1714      enum machine_mode largest_mode;
1715      int volatilep;
1716 {
1717   enum machine_mode mode;
1718   unsigned int unit = 0;
1719
1720   /* Find the narrowest integer mode that contains the bit field.  */
1721   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1722        mode = GET_MODE_WIDER_MODE (mode))
1723     {
1724       unit = GET_MODE_BITSIZE (mode);
1725       if ((bitpos % unit) + bitsize <= unit)
1726         break;
1727     }
1728
1729   if (mode == VOIDmode
1730       /* It is tempting to omit the following line
1731          if STRICT_ALIGNMENT is true.
1732          But that is incorrect, since if the bitfield uses part of 3 bytes
1733          and we use a 4-byte mode, we could get a spurious segv
1734          if the extra 4th byte is past the end of memory.
1735          (Though at least one Unix compiler ignores this problem:
1736          that on the Sequent 386 machine.  */
1737       || MIN (unit, BIGGEST_ALIGNMENT) > align
1738       || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1739     return VOIDmode;
1740
1741   if (SLOW_BYTE_ACCESS && ! volatilep)
1742     {
1743       enum machine_mode wide_mode = VOIDmode, tmode;
1744
1745       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1746            tmode = GET_MODE_WIDER_MODE (tmode))
1747         {
1748           unit = GET_MODE_BITSIZE (tmode);
1749           if (bitpos / unit == (bitpos + bitsize - 1) / unit
1750               && unit <= BITS_PER_WORD
1751               && unit <= MIN (align, BIGGEST_ALIGNMENT)
1752               && (largest_mode == VOIDmode
1753                   || unit <= GET_MODE_BITSIZE (largest_mode)))
1754             wide_mode = tmode;
1755         }
1756
1757       if (wide_mode != VOIDmode)
1758         return wide_mode;
1759     }
1760
1761   return mode;
1762 }
1763
1764 /* Return the alignment of MODE. This will be bounded by 1 and
1765    BIGGEST_ALIGNMENT.  */
1766
1767 unsigned int
1768 get_mode_alignment (mode)
1769      enum machine_mode mode;
1770 {
1771   unsigned int alignment = GET_MODE_UNIT_SIZE (mode) * BITS_PER_UNIT;
1772   
1773   /* Extract the LSB of the size.  */
1774   alignment = alignment & -alignment;
1775
1776   alignment = MIN (BIGGEST_ALIGNMENT, MAX (1, alignment));
1777   return alignment;
1778 }
1779
1780 /* This function is run once to initialize stor-layout.c.  */
1781
1782 void
1783 init_stor_layout_once ()
1784 {
1785   ggc_add_tree_root (&pending_sizes, 1);
1786 }