OSDN Git Service

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