OSDN Git Service

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