OSDN Git Service

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