OSDN Git Service

* config/linux.h (ASM_COMMENT_START): Remove from here,
[pf3gnuchains/gcc-fork.git] / gcc / stor-layout.c
1 /* C-compiler utilities for types and variables storage layout
2    Copyright (C) 1987, 88, 92-97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 #include "config.h"
23 #include "system.h"
24
25 #include "tree.h"
26 #include "flags.h"
27 #include "except.h"
28 #include "function.h"
29 #include "rtl.h"
30 #include "expr.h"
31 #include "toplev.h"
32
33 #define CEIL(x,y) (((x) + (y) - 1) / (y))
34
35 /* Data type for the expressions representing sizes of data types.
36    It is the first integer type laid out.  */
37
38 struct sizetype_tab sizetype_tab;
39
40 /* An integer constant with value 0 whose type is sizetype.  */
41
42 tree size_zero_node;
43
44 /* An integer constant with value 1 whose type is sizetype.  */
45
46 tree size_one_node;
47
48 /* If nonzero, this is an upper limit on alignment of structure fields.
49    The value is measured in bits.  */
50 int maximum_field_alignment;
51
52 /* If non-zero, the alignment of a bitstring or (power-)set value, in bits.
53    May be overridden by front-ends.  */
54 int set_alignment = 0;
55
56 static enum machine_mode smallest_mode_for_size  PROTO((unsigned int,
57                                                         enum mode_class));
58 static tree layout_record       PROTO((tree));
59 static void layout_union        PROTO((tree));
60 \f
61 /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded.  */
62
63 static tree pending_sizes;
64
65 /* Nonzero means cannot safely call expand_expr now,
66    so put variable sizes onto `pending_sizes' instead.  */
67
68 int immediate_size_expand;
69
70 tree
71 get_pending_sizes ()
72 {
73   tree chain = pending_sizes;
74   tree t;
75
76   /* Put each SAVE_EXPR into the current function.  */
77   for (t = chain; t; t = TREE_CHAIN (t))
78     SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = current_function_decl;
79   pending_sizes = 0;
80   return chain;
81 }
82
83 void
84 put_pending_sizes (chain)
85      tree chain;
86 {
87   if (pending_sizes)
88     abort ();
89
90   pending_sizes = chain;
91 }
92
93 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
94    to serve as the actual size-expression for a type or decl.  */
95
96 tree
97 variable_size (size)
98      tree size;
99 {
100   /* If the language-processor is to take responsibility for variable-sized
101      items (e.g., languages which have elaboration procedures like Ada),
102      just return SIZE unchanged.  Likewise for self-referential sizes.  */
103   if (TREE_CONSTANT (size)
104       || global_bindings_p () < 0 || contains_placeholder_p (size))
105     return size;
106
107   size = save_expr (size);
108
109   if (global_bindings_p ())
110     {
111       if (TREE_CONSTANT (size))
112         error ("type size can't be explicitly evaluated");
113       else
114         error ("variable-size type declared outside of any function");
115
116       return size_int (1);
117     }
118
119   if (immediate_size_expand)
120     /* NULL_RTX is not defined; neither is the rtx type. 
121        Also, we would like to pass const0_rtx here, but don't have it.  */
122     expand_expr (size, expand_expr (integer_zero_node, NULL_PTR, VOIDmode, 0),
123                  VOIDmode, 0);
124   else
125     pending_sizes = tree_cons (NULL_TREE, size, pending_sizes);
126
127   return size;
128 }
129 \f
130 #ifndef MAX_FIXED_MODE_SIZE
131 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
132 #endif
133
134 /* Return the machine mode to use for a nonscalar of SIZE bits.
135    The mode must be in class CLASS, and have exactly that many bits.
136    If LIMIT is nonzero, modes of wider than MAX_FIXED_MODE_SIZE will not
137    be used.  */
138
139 enum machine_mode
140 mode_for_size (size, class, limit)
141      unsigned int size;
142      enum mode_class class;
143      int limit;
144 {
145   register enum machine_mode mode;
146
147   if (limit && size > MAX_FIXED_MODE_SIZE)
148     return BLKmode;
149
150   /* Get the first mode which has this size, in the specified class.  */
151   for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
152        mode = GET_MODE_WIDER_MODE (mode))
153     if (GET_MODE_BITSIZE (mode) == size)
154       return mode;
155
156   return BLKmode;
157 }
158
159 /* Similar, but never return BLKmode; return the narrowest mode that
160    contains at least the requested number of bits.  */
161
162 static enum machine_mode
163 smallest_mode_for_size (size, class)
164      unsigned int size;
165      enum mode_class class;
166 {
167   register enum machine_mode mode;
168
169   /* Get the first mode which has at least this size, in the
170      specified class.  */
171   for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
172        mode = GET_MODE_WIDER_MODE (mode))
173     if (GET_MODE_BITSIZE (mode) >= size)
174       return mode;
175
176   abort ();
177 }
178
179 /* Return the value of VALUE, rounded up to a multiple of DIVISOR.  */
180
181 tree
182 round_up (value, divisor)
183      tree value;
184      int divisor;
185 {
186   return size_binop (MULT_EXPR,
187                      size_binop (CEIL_DIV_EXPR, value, size_int (divisor)),
188                      size_int (divisor));
189 }
190 \f
191 /* Set the size, mode and alignment of a ..._DECL node.
192    TYPE_DECL does need this for C++.
193    Note that LABEL_DECL and CONST_DECL nodes do not need this,
194    and FUNCTION_DECL nodes have them set up in a special (and simple) way.
195    Don't call layout_decl for them.
196
197    KNOWN_ALIGN is the amount of alignment we can assume this
198    decl has with no special effort.  It is relevant only for FIELD_DECLs
199    and depends on the previous fields.
200    All that matters about KNOWN_ALIGN is which powers of 2 divide it.
201    If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
202    the record will be aligned to suit.  */
203
204 void
205 layout_decl (decl, known_align)
206      tree decl;
207      unsigned known_align;
208 {
209   register tree type = TREE_TYPE (decl);
210   register enum tree_code code = TREE_CODE (decl);
211   int spec_size = DECL_FIELD_SIZE (decl);
212
213   if (code == CONST_DECL)
214     return;
215
216   if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
217       && code != FIELD_DECL && code != TYPE_DECL)
218     abort ();
219
220   if (type == error_mark_node)
221     {
222       type = void_type_node;
223       spec_size = 0;
224     }
225
226   /* Usually the size and mode come from the data type without change.  */
227
228   DECL_MODE (decl) = TYPE_MODE (type);
229   TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
230   if (DECL_SIZE (decl) == 0)
231     DECL_SIZE (decl) = TYPE_SIZE (type);
232
233   if (code == FIELD_DECL && DECL_BIT_FIELD (decl))
234     {
235       if (spec_size == 0 && DECL_NAME (decl) != 0)
236         abort ();
237
238       /* Size is specified number of bits.  */
239       DECL_SIZE (decl) = size_int (spec_size);
240     }
241   /* Force alignment required for the data type.
242      But if the decl itself wants greater alignment, don't override that.
243      Likewise, if the decl is packed, don't override it.  */
244   else if (DECL_ALIGN (decl) == 0
245            || (! DECL_PACKED (decl) &&  TYPE_ALIGN (type) > DECL_ALIGN (decl)))
246     DECL_ALIGN (decl) = TYPE_ALIGN (type);
247
248   /* See if we can use an ordinary integer mode for a bit-field.  */
249   /* Conditions are: a fixed size that is correct for another mode
250      and occupying a complete byte or bytes on proper boundary.  */
251   if (code == FIELD_DECL)
252     {
253       DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
254       if (maximum_field_alignment != 0)
255         DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
256       else if (DECL_PACKED (decl))
257         DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
258     }
259
260   if (DECL_BIT_FIELD (decl)
261       && TYPE_SIZE (type) != 0
262       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
263       && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
264     {
265       register enum machine_mode xmode
266         = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl)), MODE_INT, 1);
267
268       if (xmode != BLKmode
269           && known_align % GET_MODE_ALIGNMENT (xmode) == 0)
270         {
271           DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
272                                    DECL_ALIGN (decl));
273           DECL_MODE (decl) = xmode;
274           DECL_SIZE (decl) = size_int (GET_MODE_BITSIZE (xmode));
275           /* This no longer needs to be accessed as a bit field.  */
276           DECL_BIT_FIELD (decl) = 0;
277         }
278     }
279
280   /* Turn off DECL_BIT_FIELD if we won't need it set.  */
281   if (DECL_BIT_FIELD (decl) && TYPE_MODE (type) == BLKmode
282       && known_align % TYPE_ALIGN (type) == 0
283       && DECL_SIZE (decl) != 0
284       && (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST
285           || (TREE_INT_CST_LOW (DECL_SIZE (decl)) % BITS_PER_UNIT) == 0)
286       && DECL_ALIGN (decl) >= TYPE_ALIGN (type))
287     DECL_BIT_FIELD (decl) = 0;
288
289   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
290   if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
291     DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
292 }
293 \f
294 /* Lay out a RECORD_TYPE type (a C struct).
295    This means laying out the fields, determining their positions,
296    and computing the overall size and required alignment of the record.
297    Note that if you set the TYPE_ALIGN before calling this
298    then the struct is aligned to at least that boundary.
299
300    If the type has basetypes, you must call layout_basetypes
301    before calling this function.
302
303    The return value is a list of static members of the record.
304    They still need to be laid out.  */
305
306 static tree
307 layout_record (rec)
308      tree rec;
309 {
310   register tree field;
311   unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
312   /* These must be laid out *after* the record is.  */
313   tree pending_statics = NULL_TREE;
314   /* Record size so far is CONST_SIZE + VAR_SIZE bits,
315      where CONST_SIZE is an integer
316      and VAR_SIZE is a tree expression.
317      If VAR_SIZE is null, the size is just CONST_SIZE.
318      Naturally we try to avoid using VAR_SIZE.  */
319  register HOST_WIDE_INT const_size = 0;
320   register tree var_size = 0;
321   /* Once we start using VAR_SIZE, this is the maximum alignment
322      that we know VAR_SIZE has.  */
323   register int var_align = BITS_PER_UNIT;
324
325 #ifdef STRUCTURE_SIZE_BOUNDARY
326   /* Packed structures don't need to have minimum size.  */
327   if (! TYPE_PACKED (rec))
328     record_align = MAX (record_align, STRUCTURE_SIZE_BOUNDARY);
329 #endif
330
331   for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
332     {
333       register int known_align = var_size ? var_align : const_size;
334       register int desired_align = 0;
335
336       /* If FIELD is static, then treat it like a separate variable,
337          not really like a structure field.
338          If it is a FUNCTION_DECL, it's a method.
339          In both cases, all we do is lay out the decl,
340          and we do it *after* the record is laid out.  */
341
342       if (TREE_CODE (field) == VAR_DECL)
343         {
344           pending_statics = tree_cons (NULL_TREE, field, pending_statics);
345           continue;
346         }
347       /* Enumerators and enum types which are local to this class need not
348          be laid out.  Likewise for initialized constant fields.  */
349       if (TREE_CODE (field) != FIELD_DECL)
350         continue;
351
352       /* Lay out the field so we know what alignment it needs.
353          For a packed field, use the alignment as specified,
354          disregarding what the type would want.  */
355       if (DECL_PACKED (field))
356         desired_align = DECL_ALIGN (field);
357       layout_decl (field, known_align);
358       if (! DECL_PACKED (field))
359         desired_align = DECL_ALIGN (field);
360       /* Some targets (i.e. VMS) limit struct field alignment
361          to a lower boundary than alignment of variables.  */
362 #ifdef BIGGEST_FIELD_ALIGNMENT
363       desired_align = MIN (desired_align, BIGGEST_FIELD_ALIGNMENT);
364 #endif
365 #ifdef ADJUST_FIELD_ALIGN
366       desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
367 #endif
368
369       /* Record must have at least as much alignment as any field.
370          Otherwise, the alignment of the field within the record
371          is meaningless.  */
372
373 #ifndef PCC_BITFIELD_TYPE_MATTERS
374       record_align = MAX (record_align, desired_align);
375 #else
376       if (PCC_BITFIELD_TYPE_MATTERS && TREE_TYPE (field) != error_mark_node
377           && DECL_BIT_FIELD_TYPE (field)
378           && ! integer_zerop (TYPE_SIZE (TREE_TYPE (field))))
379         {
380           /* For these machines, a zero-length field does not
381              affect the alignment of the structure as a whole.
382              It does, however, affect the alignment of the next field
383              within the structure.  */
384           if (! integer_zerop (DECL_SIZE (field)))
385             record_align = MAX (record_align, desired_align);
386           else if (! DECL_PACKED (field))
387             desired_align = TYPE_ALIGN (TREE_TYPE (field));
388           /* A named bit field of declared type `int'
389              forces the entire structure to have `int' alignment.  */
390           if (DECL_NAME (field) != 0)
391             {
392               int type_align = TYPE_ALIGN (TREE_TYPE (field));
393               if (maximum_field_alignment != 0)
394                 type_align = MIN (type_align, maximum_field_alignment);
395               else if (DECL_PACKED (field))
396                 type_align = MIN (type_align, BITS_PER_UNIT);
397
398               record_align = MAX (record_align, type_align);
399             }
400         }
401       else
402         record_align = MAX (record_align, desired_align);
403 #endif
404
405       /* Does this field automatically have alignment it needs
406          by virtue of the fields that precede it and the record's
407          own alignment?  */
408
409       if (const_size % desired_align != 0
410           || (var_align % desired_align != 0
411               && var_size != 0))
412         {
413           /* No, we need to skip space before this field.
414              Bump the cumulative size to multiple of field alignment.  */
415
416           if (var_size == 0
417               || var_align % desired_align == 0)
418             const_size
419               = CEIL (const_size, desired_align) * desired_align;
420           else
421             {
422               if (const_size > 0)
423                 var_size = size_binop (PLUS_EXPR, var_size,
424                                        bitsize_int (const_size, 0L));
425               const_size = 0;
426               var_size = round_up (var_size, desired_align);
427               var_align = MIN (var_align, desired_align);
428             }
429         }
430
431 #ifdef PCC_BITFIELD_TYPE_MATTERS
432       if (PCC_BITFIELD_TYPE_MATTERS
433           && TREE_CODE (field) == FIELD_DECL
434           && TREE_TYPE (field) != error_mark_node
435           && DECL_BIT_FIELD_TYPE (field)
436           && !DECL_PACKED (field)
437           && maximum_field_alignment == 0
438           && !integer_zerop (DECL_SIZE (field)))
439         {
440           int type_align = TYPE_ALIGN (TREE_TYPE (field));
441           register tree dsize = DECL_SIZE (field);
442           int field_size = TREE_INT_CST_LOW (dsize);
443
444           /* A bit field may not span more units of alignment of its type
445              than its type itself.  Advance to next boundary if necessary.  */
446           if (((const_size + field_size + type_align - 1) / type_align
447                - const_size / type_align)
448               > TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (field))) / type_align)
449             const_size = CEIL (const_size, type_align) * type_align;
450         }
451 #endif
452
453 /* No existing machine description uses this parameter.
454    So I have made it in this aspect identical to PCC_BITFIELD_TYPE_MATTERS.  */
455 #ifdef BITFIELD_NBYTES_LIMITED
456       if (BITFIELD_NBYTES_LIMITED
457           && TREE_CODE (field) == FIELD_DECL
458           && TREE_TYPE (field) != error_mark_node
459           && DECL_BIT_FIELD_TYPE (field)
460           && !DECL_PACKED (field)
461           && !integer_zerop (DECL_SIZE (field)))
462         {
463           int type_align = TYPE_ALIGN (TREE_TYPE (field));
464           register tree dsize = DECL_SIZE (field);
465           int field_size = TREE_INT_CST_LOW (dsize);
466
467           if (maximum_field_alignment != 0)
468             type_align = MIN (type_align, maximum_field_alignment);
469           /* ??? This test is opposite the test in the containing if
470              statement, so this code is unreachable currently.  */
471           else if (DECL_PACKED (field))
472             type_align = MIN (type_align, BITS_PER_UNIT);
473
474           /* A bit field may not span the unit of alignment of its type.
475              Advance to next boundary if necessary.  */
476           /* ??? This code should match the code above for the
477              PCC_BITFIELD_TYPE_MATTERS case.  */
478           if (const_size / type_align
479               != (const_size + field_size - 1) / type_align)
480             const_size = CEIL (const_size, type_align) * type_align;
481         }
482 #endif
483
484       /* Size so far becomes the position of this field.  */
485
486       if (var_size && const_size)
487         DECL_FIELD_BITPOS (field)
488           = size_binop (PLUS_EXPR, var_size, bitsize_int (const_size, 0L));
489       else if (var_size)
490         DECL_FIELD_BITPOS (field) = var_size;
491       else
492         {
493           DECL_FIELD_BITPOS (field) = size_int (const_size);
494
495           /* If this field ended up more aligned than we thought it
496              would be (we approximate this by seeing if its position
497              changed), lay out the field again; perhaps we can use an
498              integral mode for it now.  */
499           if (known_align != const_size)
500             layout_decl (field, const_size);
501         }
502
503       /* Now add size of this field to the size of the record.  */
504
505       {
506         register tree dsize = DECL_SIZE (field);
507
508         /* This can happen when we have an invalid nested struct definition,
509            such as struct j { struct j { int i; } }.  The error message is
510            printed in finish_struct.  */
511         if (dsize == 0)
512           /* Do nothing.  */;
513         else if (TREE_CODE (dsize) == INTEGER_CST
514                  && ! TREE_CONSTANT_OVERFLOW (dsize)
515                  && TREE_INT_CST_HIGH (dsize) == 0
516                  && TREE_INT_CST_LOW (dsize) + const_size >= const_size)
517           /* Use const_size if there's no overflow.  */
518           const_size += TREE_INT_CST_LOW (dsize);
519         else
520           {
521             if (var_size == 0)
522               var_size = dsize;
523             else
524               var_size = size_binop (PLUS_EXPR, var_size, dsize);
525           }
526       }
527     }
528
529   /* Work out the total size and alignment of the record
530      as one expression and store in the record type.
531      Round it up to a multiple of the record's alignment.  */
532
533   if (var_size == 0)
534     {
535       TYPE_SIZE (rec) = size_int (const_size);
536     }
537   else
538     {
539       if (const_size)
540         var_size
541           = size_binop (PLUS_EXPR, var_size, bitsize_int (const_size, 0L));
542       TYPE_SIZE (rec) = var_size;
543     }
544
545   /* Determine the desired alignment.  */
546 #ifdef ROUND_TYPE_ALIGN
547   TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), record_align);
548 #else
549   TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), record_align);
550 #endif
551
552 #ifdef ROUND_TYPE_SIZE
553   TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
554 #else
555   /* Round the size up to be a multiple of the required alignment */
556   TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
557 #endif
558
559   return pending_statics;
560 }
561 \f
562 /* Lay out a UNION_TYPE or QUAL_UNION_TYPE type.
563    Lay out all the fields, set their positions to zero,
564    and compute the size and alignment of the union (maximum of any field).
565    Note that if you set the TYPE_ALIGN before calling this
566    then the union align is aligned to at least that boundary.  */
567
568 static void
569 layout_union (rec)
570      tree rec;
571 {
572   register tree field;
573   unsigned union_align = BITS_PER_UNIT;
574
575   /* The size of the union, based on the fields scanned so far,
576      is max (CONST_SIZE, VAR_SIZE).
577      VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
578   register int const_size = 0;
579   register tree var_size = 0;
580
581 #ifdef STRUCTURE_SIZE_BOUNDARY
582   /* Packed structures don't need to have minimum size.  */
583   if (! TYPE_PACKED (rec))
584     union_align = STRUCTURE_SIZE_BOUNDARY;
585 #endif
586
587   /* If this is a QUAL_UNION_TYPE, we want to process the fields in
588      the reverse order in building the COND_EXPR that denotes its
589      size.  We reverse them again later.  */
590   if (TREE_CODE (rec) == QUAL_UNION_TYPE)
591     TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
592
593   for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
594     {
595       /* Enums which are local to this class need not be laid out.  */
596       if (TREE_CODE (field) == CONST_DECL || TREE_CODE (field) == TYPE_DECL)
597         continue;
598
599       layout_decl (field, 0);
600       DECL_FIELD_BITPOS (field) = bitsize_int (0L, 0L);
601
602       /* Union must be at least as aligned as any field requires.  */
603
604       union_align = MAX (union_align, DECL_ALIGN (field));
605
606 #ifdef PCC_BITFIELD_TYPE_MATTERS
607       /* On the m88000, a bit field of declare type `int'
608          forces the entire union to have `int' alignment.  */
609       if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
610         union_align = MAX (union_align, TYPE_ALIGN (TREE_TYPE (field)));
611 #endif
612
613       if (TREE_CODE (rec) == UNION_TYPE)
614         {
615           /* Set union_size to max (decl_size, union_size).
616              There are more and less general ways to do this.
617              Use only CONST_SIZE unless forced to use VAR_SIZE.  */
618
619           if (TREE_CODE (DECL_SIZE (field)) == INTEGER_CST)
620             const_size
621               = MAX (const_size, TREE_INT_CST_LOW (DECL_SIZE (field)));
622           else if (var_size == 0)
623             var_size = DECL_SIZE (field);
624           else
625             var_size = size_binop (MAX_EXPR, var_size, DECL_SIZE (field));
626         }
627       else if (TREE_CODE (rec) == QUAL_UNION_TYPE)
628         var_size = fold (build (COND_EXPR, sizetype, DECL_QUALIFIER (field),
629                                 DECL_SIZE (field),
630                                 var_size ? var_size : bitsize_int (0L, 0L)));
631       }
632
633   if (TREE_CODE (rec) == QUAL_UNION_TYPE)
634     TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
635
636   /* Determine the ultimate size of the union (in bytes).  */
637   if (NULL == var_size)
638     TYPE_SIZE (rec) = bitsize_int (CEIL (const_size, BITS_PER_UNIT)
639                                    * BITS_PER_UNIT, 0L);
640   else if (const_size == 0)
641     TYPE_SIZE (rec) = var_size;
642   else
643     TYPE_SIZE (rec) = size_binop (MAX_EXPR, var_size,
644                                   round_up (bitsize_int (const_size, 0L),
645                                             BITS_PER_UNIT));
646
647   /* Determine the desired alignment.  */
648 #ifdef ROUND_TYPE_ALIGN
649   TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), union_align);
650 #else
651   TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), union_align);
652 #endif
653
654 #ifdef ROUND_TYPE_SIZE
655   TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
656 #else
657   /* Round the size up to be a multiple of the required alignment */
658   TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
659 #endif
660 }
661 \f
662 /* Calculate the mode, size, and alignment for TYPE.
663    For an array type, calculate the element separation as well.
664    Record TYPE on the chain of permanent or temporary types
665    so that dbxout will find out about it.
666
667    TYPE_SIZE of a type is nonzero if the type has been laid out already.
668    layout_type does nothing on such a type.
669
670    If the type is incomplete, its TYPE_SIZE remains zero.  */
671
672 void
673 layout_type (type)
674      tree type;
675 {
676   int old;
677   tree pending_statics;
678
679   if (type == 0)
680     abort ();
681
682   /* Do nothing if type has been laid out before.  */
683   if (TYPE_SIZE (type))
684     return;
685
686   /* Make sure all nodes we allocate are not momentary;
687      they must last past the current statement.  */
688   old = suspend_momentary ();
689
690   /* Put all our nodes into the same obstack as the type.  Also,
691      make expressions saveable (this is a no-op for permanent types).  */
692
693   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
694   saveable_allocation ();
695
696   switch (TREE_CODE (type))
697     {
698     case LANG_TYPE:
699       /* This kind of type is the responsibility
700          of the language-specific code.  */
701       abort ();
702
703     case BOOLEAN_TYPE:  /* Used for Java, Pascal, and Chill. */
704       if (TYPE_PRECISION (type) == 0)
705         TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
706       /* ... fall through ... */
707
708     case INTEGER_TYPE:
709     case ENUMERAL_TYPE:
710     case CHAR_TYPE:
711       if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
712           && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
713         TREE_UNSIGNED (type) = 1;
714
715       TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
716                                                  MODE_INT);
717       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)), 0L);
718       break;
719
720     case REAL_TYPE:
721       TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
722       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)), 0L);
723       break;
724
725     case COMPLEX_TYPE:
726       TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
727       TYPE_MODE (type)
728         = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
729                          (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
730                           ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
731                          0);
732       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)), 0L);
733       break;
734
735     case VOID_TYPE:
736       TYPE_SIZE (type) = size_zero_node;
737       TYPE_ALIGN (type) = 1;
738       TYPE_MODE (type) = VOIDmode;
739       break;
740
741     case OFFSET_TYPE:
742       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE, 0L);
743       TYPE_MODE (type) = ptr_mode;
744       break;
745
746     case FUNCTION_TYPE:
747     case METHOD_TYPE:
748       TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
749       TYPE_SIZE (type) = size_int (2 * POINTER_SIZE);
750       break;
751
752     case POINTER_TYPE:
753     case REFERENCE_TYPE:
754       TYPE_MODE (type) = ptr_mode;
755       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE, 0L);
756       TREE_UNSIGNED (type) = 1;
757       TYPE_PRECISION (type) = POINTER_SIZE;
758       break;
759
760     case ARRAY_TYPE:
761       {
762         register tree index = TYPE_DOMAIN (type);
763         register tree element = TREE_TYPE (type);
764
765         build_pointer_type (element);
766
767         /* We need to know both bounds in order to compute the size.  */
768         if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
769             && TYPE_SIZE (element))
770           {
771             tree ub = TYPE_MAX_VALUE (index);
772             tree lb = TYPE_MIN_VALUE (index);
773             tree length;
774
775             /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
776                test for negative below covers it.  */
777             if (TREE_CODE (ub) == MAX_EXPR
778                 && TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
779                 && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
780                 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
781                                     lb, 0))
782               ub = TREE_OPERAND (ub, 1);
783             else if (TREE_CODE (ub) == MAX_EXPR
784                      && TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
785                      && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
786                      && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
787                                                        0),
788                                          lb, 0))
789               ub = TREE_OPERAND (ub, 0);
790
791             /* The initial subtraction should happen in the original type so
792                that (possible) negative values are handled appropriately.  */
793             length = size_binop (PLUS_EXPR, size_one_node,
794                                  fold (build (MINUS_EXPR, TREE_TYPE (lb),
795                                               ub, lb)));
796
797             /* If neither bound is a constant and sizetype is signed, make
798                sure the size is never negative.  We should really do this
799                if *either* bound is non-constant, but this is the best
800                compromise between C and Ada.  */
801             if (! TREE_UNSIGNED (sizetype)
802                 && TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
803                 && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
804               length = size_binop (MAX_EXPR, length, size_zero_node);
805
806             TYPE_SIZE (type) = size_binop (MULT_EXPR, TYPE_SIZE (element),
807                                            length);
808           }
809
810         /* Now round the alignment and size,
811            using machine-dependent criteria if any.  */
812
813 #ifdef ROUND_TYPE_ALIGN
814         TYPE_ALIGN (type)
815           = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
816 #else
817         TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
818 #endif
819
820 #ifdef ROUND_TYPE_SIZE
821         if (TYPE_SIZE (type) != 0)
822           TYPE_SIZE (type)
823             = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
824 #endif
825
826         TYPE_MODE (type) = BLKmode;
827         if (TYPE_SIZE (type) != 0
828             && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
829             /* BLKmode elements force BLKmode aggregate;
830                else extract/store fields may lose.  */
831             && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
832                 || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
833           {
834             TYPE_MODE (type)
835               = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
836                                MODE_INT, 1);
837
838             if (STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
839                 && TYPE_ALIGN (type) < TREE_INT_CST_LOW (TYPE_SIZE (type))
840                 && TYPE_MODE (type) != BLKmode)
841               {
842                 TYPE_NO_FORCE_BLK (type) = 1;
843                 TYPE_MODE (type) = BLKmode;
844               }
845           }
846         break;
847       }
848
849     case RECORD_TYPE:
850       pending_statics = layout_record (type);
851       TYPE_MODE (type) = BLKmode;
852       if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
853         {
854           tree field;
855           enum machine_mode mode = VOIDmode;
856
857           /* A record which has any BLKmode members must itself be BLKmode;
858              it can't go in a register.
859              Unless the member is BLKmode only because it isn't aligned.  */
860           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
861             {
862               int bitpos;
863
864               if (TREE_CODE (field) != FIELD_DECL)
865                 continue;
866
867               if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
868                   && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
869                 goto record_lose;
870
871               if (TREE_CODE (DECL_FIELD_BITPOS (field)) != INTEGER_CST)
872                 goto record_lose;
873
874               bitpos = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
875
876               /* Must be BLKmode if any field crosses a word boundary,
877                  since extract_bit_field can't handle that in registers.  */
878               if (bitpos / BITS_PER_WORD
879                   != ((TREE_INT_CST_LOW (DECL_SIZE (field)) + bitpos - 1)
880                       / BITS_PER_WORD)
881                   /* But there is no problem if the field is entire words.  */
882                   && TREE_INT_CST_LOW (DECL_SIZE (field)) % BITS_PER_WORD != 0)
883                 goto record_lose;
884
885               /* If this field is the whole struct, remember its mode so
886                  that, say, we can put a double in a class into a DF
887                  register instead of forcing it to live in the stack.  */
888               if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
889                 mode = DECL_MODE (field);
890             }
891
892           if (mode != VOIDmode)
893             /* We only have one real field; use its mode.  */
894             TYPE_MODE (type) = mode;
895           else
896             TYPE_MODE (type)
897               = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
898                                MODE_INT, 1);
899
900           /* If structure's known alignment is less than
901              what the scalar mode would need, and it matters,
902              then stick with BLKmode.  */
903           if (STRICT_ALIGNMENT
904               && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
905                     || (TYPE_ALIGN (type)
906                         >= TREE_INT_CST_LOW (TYPE_SIZE (type)))))
907             {
908               if (TYPE_MODE (type) != BLKmode)
909                 /* If this is the only reason this type is BLKmode,
910                    then don't force containing types to be BLKmode.  */
911                 TYPE_NO_FORCE_BLK (type) = 1;
912               TYPE_MODE (type) = BLKmode;
913             }
914
915         record_lose: ;
916         }
917
918       /* Lay out any static members.  This is done now
919          because their type may use the record's type.  */
920       while (pending_statics)
921         {
922           layout_decl (TREE_VALUE (pending_statics), 0);
923           pending_statics = TREE_CHAIN (pending_statics);
924         }
925       break;
926
927     case UNION_TYPE:
928     case QUAL_UNION_TYPE:
929       layout_union (type);
930       TYPE_MODE (type) = BLKmode;
931       if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
932           /* If structure's known alignment is less than
933              what the scalar mode would need, and it matters,
934              then stick with BLKmode.  */
935           && (! STRICT_ALIGNMENT
936               || TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
937               || TYPE_ALIGN (type) >= TREE_INT_CST_LOW (TYPE_SIZE (type))))
938         {
939           tree field;
940           /* A union which has any BLKmode members must itself be BLKmode;
941              it can't go in a register.
942              Unless the member is BLKmode only because it isn't aligned.  */
943           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
944             {
945               if (TREE_CODE (field) != FIELD_DECL)
946                 continue;
947
948               if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
949                   && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
950                 goto union_lose;
951             }
952
953           TYPE_MODE (type)
954             = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
955                              MODE_INT, 1);
956
957         union_lose: ;
958         }
959       break;
960
961     case SET_TYPE:  /* Used by Chill and Pascal. */
962       if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
963           || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
964         abort();
965       else
966         {
967 #ifndef SET_WORD_SIZE
968 #define SET_WORD_SIZE BITS_PER_WORD
969 #endif
970           int alignment = set_alignment ? set_alignment : SET_WORD_SIZE;
971           int size_in_bits
972             = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
973                - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
974           int rounded_size
975             = ((size_in_bits + alignment - 1) / alignment) * alignment;
976           if (rounded_size > alignment)
977             TYPE_MODE (type) = BLKmode;
978           else
979             TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
980           TYPE_SIZE (type) = bitsize_int (rounded_size, 0L);
981           TYPE_ALIGN (type) = alignment;
982           TYPE_PRECISION (type) = size_in_bits;
983         }
984       break;
985
986     case FILE_TYPE:
987       /* The size may vary in different languages, so the language front end
988          should fill in the size.  */
989       TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
990       TYPE_MODE  (type) = BLKmode;
991       break;
992
993     default:
994       abort ();
995     } /* end switch */
996
997   /* Normally, use the alignment corresponding to the mode chosen.
998      However, where strict alignment is not required, avoid
999      over-aligning structures, since most compilers do not do this
1000      alignment.  */
1001
1002   if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1003       && (STRICT_ALIGNMENT
1004           || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1005               && TREE_CODE (type) != QUAL_UNION_TYPE
1006               && TREE_CODE (type) != ARRAY_TYPE)))
1007     TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1008
1009   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
1010   if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1011     TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1012
1013   /* Also layout any other variants of the type.  */
1014   if (TYPE_NEXT_VARIANT (type)
1015       || type != TYPE_MAIN_VARIANT (type))
1016     {
1017       tree variant;
1018       /* Record layout info of this variant.  */
1019       tree size = TYPE_SIZE (type);
1020       int align = TYPE_ALIGN (type);
1021       enum machine_mode mode = TYPE_MODE (type);
1022
1023       /* Copy it into all variants.  */
1024       for (variant = TYPE_MAIN_VARIANT (type);
1025            variant;
1026            variant = TYPE_NEXT_VARIANT (variant))
1027         {
1028           TYPE_SIZE (variant) = size;
1029           TYPE_ALIGN (variant) = align;
1030           TYPE_MODE (variant) = mode;
1031         }
1032     }
1033         
1034   pop_obstacks ();
1035   resume_momentary (old);
1036 }
1037 \f
1038 /* Create and return a type for signed integers of PRECISION bits.  */
1039
1040 tree
1041 make_signed_type (precision)
1042      int precision;
1043 {
1044   register tree type = make_node (INTEGER_TYPE);
1045
1046   TYPE_PRECISION (type) = precision;
1047
1048   /* Create the extreme values based on the number of bits.  */
1049
1050   TYPE_MIN_VALUE (type)
1051     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1052                     ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1053                    (((HOST_WIDE_INT) (-1)
1054                      << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1055                          ? precision - HOST_BITS_PER_WIDE_INT - 1
1056                          : 0))));
1057   TYPE_MAX_VALUE (type)
1058     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1059                     ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1060                    (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1061                     ? (((HOST_WIDE_INT) 1
1062                         << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1063                     : 0));
1064
1065   /* Give this type's extreme values this type as their type.  */
1066
1067   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1068   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1069
1070   /* The first type made with this or `make_unsigned_type'
1071      is the type for size values.  */
1072
1073   if (sizetype == 0)
1074     set_sizetype (type);
1075
1076   /* Lay out the type: set its alignment, size, etc.  */
1077
1078   layout_type (type);
1079
1080   return type;
1081 }
1082
1083 /* Create and return a type for unsigned integers of PRECISION bits.  */
1084
1085 tree
1086 make_unsigned_type (precision)
1087      int precision;
1088 {
1089   register tree type = make_node (INTEGER_TYPE);
1090
1091   TYPE_PRECISION (type) = precision;
1092
1093   /* The first type made with this or `make_signed_type'
1094      is the type for size values.  */
1095
1096   if (sizetype == 0)
1097     {
1098       TREE_UNSIGNED (type) = 1;
1099       set_sizetype (type);
1100     }
1101
1102   fixup_unsigned_type (type);
1103   return type;
1104 }
1105
1106 /* Set sizetype to TYPE, and initialize *sizetype accordingly.
1107    Also update the type of any standard type's sizes made so far.  */
1108
1109 void
1110 set_sizetype (type)
1111      tree type;
1112 {
1113   int oprecision = TYPE_PRECISION (type), precision;
1114
1115   sizetype = type;
1116
1117   /* The *bitsizetype types use a precision that avoids overflows when
1118      calculating signed sizes / offsets in bits.
1119
1120      We are allocating bitsizetype once and change it in place when
1121      we decide later that we want to change it.  This way, we avoid the
1122      hassle of changing all the TYPE_SIZE (TREE_TYPE (sometype))
1123      individually in each front end.  */
1124   if (! bitsizetype)
1125     bitsizetype = make_node (INTEGER_TYPE);
1126
1127   precision = oprecision + BITS_PER_UNIT_LOG + 1;
1128   /* However, when cross-compiling from a 32 bit to a 64 bit host,
1129      we are limited to 64 bit precision.  */
1130   if (precision > 2 * HOST_BITS_PER_WIDE_INT)
1131     precision = 2 * HOST_BITS_PER_WIDE_INT;
1132   TYPE_PRECISION (bitsizetype) = precision;
1133   if (TREE_UNSIGNED (type))
1134     fixup_unsigned_type (bitsizetype);
1135   else
1136     fixup_signed_type (bitsizetype);
1137   layout_type (bitsizetype);
1138
1139   if (TREE_UNSIGNED (type))
1140     {
1141       usizetype = sizetype;
1142       ubitsizetype = bitsizetype;
1143       ssizetype = make_signed_type (oprecision);
1144       sbitsizetype = make_signed_type (precision);
1145     }
1146   else
1147     {
1148       ssizetype = sizetype;
1149       sbitsizetype = bitsizetype;
1150       usizetype = make_unsigned_type (oprecision);
1151       ubitsizetype = make_unsigned_type (precision);
1152     }
1153 }
1154
1155 /* Set the extreme values of TYPE based on its precision in bits,
1156    then lay it out.  Used when make_signed_type won't do
1157    because the tree code is not INTEGER_TYPE.
1158    E.g. for Pascal, when the -fsigned-char option is given.  */
1159
1160 void
1161 fixup_signed_type (type)
1162      tree type;
1163 {
1164   register int precision = TYPE_PRECISION (type);
1165
1166   TYPE_MIN_VALUE (type)
1167     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1168                     ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1169                    (((HOST_WIDE_INT) (-1)
1170                      << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1171                          ? precision - HOST_BITS_PER_WIDE_INT - 1
1172                          : 0))));
1173   TYPE_MAX_VALUE (type)
1174     = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1175                     ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1176                    (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1177                     ? (((HOST_WIDE_INT) 1
1178                         << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1179                     : 0));
1180
1181   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1182   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1183
1184   /* Lay out the type: set its alignment, size, etc.  */
1185
1186   layout_type (type);
1187 }
1188
1189 /* Set the extreme values of TYPE based on its precision in bits,
1190    then lay it out.  This is used both in `make_unsigned_type'
1191    and for enumeral types.  */
1192
1193 void
1194 fixup_unsigned_type (type)
1195      tree type;
1196 {
1197   register int precision = TYPE_PRECISION (type);
1198
1199   TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1200   TYPE_MAX_VALUE (type)
1201     = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1202                    ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1203                    precision - HOST_BITS_PER_WIDE_INT > 0
1204                    ? ((unsigned HOST_WIDE_INT) ~0
1205                       >> (HOST_BITS_PER_WIDE_INT
1206                           - (precision - HOST_BITS_PER_WIDE_INT)))
1207                    : 0);
1208   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1209   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1210
1211   /* Lay out the type: set its alignment, size, etc.  */
1212
1213   layout_type (type);
1214 }
1215 \f
1216 /* Find the best machine mode to use when referencing a bit field of length
1217    BITSIZE bits starting at BITPOS.
1218
1219    The underlying object is known to be aligned to a boundary of ALIGN bits.
1220    If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1221    larger than LARGEST_MODE (usually SImode).
1222
1223    If no mode meets all these conditions, we return VOIDmode.  Otherwise, if
1224    VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1225    mode meeting these conditions.
1226
1227    Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1228    the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1229    all the conditions.  */
1230
1231 enum machine_mode
1232 get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1233      int bitsize, bitpos;
1234      int align;
1235      enum machine_mode largest_mode;
1236      int volatilep;
1237 {
1238   enum machine_mode mode;
1239   int unit = 0;
1240
1241   /* Find the narrowest integer mode that contains the bit field.  */
1242   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1243        mode = GET_MODE_WIDER_MODE (mode))
1244     {
1245       unit = GET_MODE_BITSIZE (mode);
1246       if ((bitpos % unit) + bitsize <= unit)
1247         break;
1248     }
1249
1250   if (mode == MAX_MACHINE_MODE
1251       /* It is tempting to omit the following line
1252          if STRICT_ALIGNMENT is true.
1253          But that is incorrect, since if the bitfield uses part of 3 bytes
1254          and we use a 4-byte mode, we could get a spurious segv
1255          if the extra 4th byte is past the end of memory.
1256          (Though at least one Unix compiler ignores this problem:
1257          that on the Sequent 386 machine.  */
1258       || MIN (unit, BIGGEST_ALIGNMENT) > align
1259       || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1260     return VOIDmode;
1261
1262   if (SLOW_BYTE_ACCESS && ! volatilep)
1263     {
1264       enum machine_mode wide_mode = VOIDmode, tmode;
1265
1266       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1267            tmode = GET_MODE_WIDER_MODE (tmode))
1268         {
1269           unit = GET_MODE_BITSIZE (tmode);
1270           if (bitpos / unit == (bitpos + bitsize - 1) / unit
1271               && unit <= BITS_PER_WORD
1272               && unit <= MIN (align, BIGGEST_ALIGNMENT)
1273               && (largest_mode == VOIDmode
1274                   || unit <= GET_MODE_BITSIZE (largest_mode)))
1275             wide_mode = tmode;
1276         }
1277
1278       if (wide_mode != VOIDmode)
1279         return wide_mode;
1280     }
1281
1282   return mode;
1283 }
1284 \f
1285 /* Save all variables describing the current status into the structure *P.
1286    This is used before starting a nested function.  */
1287
1288 void
1289 save_storage_status (p)
1290      struct function *p;
1291 {
1292 #if 0  /* Need not save, since always 0 and non0 (resp.) within a function.  */
1293   p->pending_sizes = pending_sizes;
1294   p->immediate_size_expand = immediate_size_expand;
1295 #endif /* 0 */
1296 }
1297
1298 /* Restore all variables describing the current status from the structure *P.
1299    This is used after a nested function.  */
1300
1301 void
1302 restore_storage_status (p)
1303      struct function *p;
1304 {
1305 #if 0
1306   pending_sizes = p->pending_sizes;
1307   immediate_size_expand = p->immediate_size_expand;
1308 #endif /* 0 */
1309 }