home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / stor-layout.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  38KB  |  1,208 lines

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