OSDN Git Service

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