home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 322 / compsrc4 / typechec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  100.4 KB  |  3,364 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file is part of the C front end.
  23.    It contains routines to build C expressions given their operands,
  24.    including computing the types of the result, C-specific error checks,
  25.    and some optimization.
  26.  
  27.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  28.    and to process initializations in declarations (since they work
  29.    like a strange sort of assignment).  */
  30.  
  31. #include "config.h"
  32. #include <stdio.h>
  33. #include "tree.h"
  34. #include "c-tree.h"
  35. #include "flags.h"
  36.  
  37.  
  38.  
  39. static void mark_addressable ();
  40. static tree convert_for_assignment ();
  41. static int compparms ();
  42. int comp_target_types ();
  43. static tree shorten_compare ();
  44. static void binary_op_error ();
  45. static tree pointer_int_sum ();
  46. static tree pointer_diff ();
  47. static tree convert_sequence ();
  48. static tree unary_complex_lvalue ();
  49. static tree process_init_constructor ();
  50. tree digest_init ();
  51. tree truthvalue_conversion ();
  52. void incomplete_type_error ();
  53. void readonly_warning ();
  54.  
  55. /* Return the _TYPE node describing the data type
  56.    of the data which NODE represents as a C expression.
  57.    Arrays and functions are converted to pointers
  58.    just as they are when they appear as C expressions.  */
  59.  
  60. tree
  61. datatype (node)
  62.      tree node;
  63. {
  64.   register tree type = TREE_TYPE (node);
  65.   if (TREE_CODE (type) == ARRAY_TYPE)
  66.     return TYPE_POINTER_TO (TREE_TYPE (type));
  67.   if (TREE_CODE (type) == FUNCTION_TYPE)
  68.     return build_pointer_type (type);
  69.   return type;
  70. }
  71.  
  72. /* Do `exp = require_complete_type (exp);' to make sure exp
  73.    does not have an incomplete type.  (That includes void types.)  */
  74.  
  75. tree
  76. require_complete_type (value)
  77.      tree value;
  78. {
  79.   tree type = TREE_TYPE (value);
  80.  
  81.   /* First, detect a valid value with a complete type.  */
  82.   if (TYPE_SIZE (type) != 0
  83.       && type != void_type_node)
  84.     return value;
  85.  
  86.   incomplete_type_error (value, type);
  87.   return error_mark_node;
  88. }
  89.  
  90. /* Print an error message for invalid use of an incomplete type.
  91.    VALUE is the expression that was used (or 0 if that isn't known)
  92.    and TYPE is the type that was invalid.  */
  93.  
  94. void
  95. incomplete_type_error (value, type)
  96.      tree value;
  97.      tree type;
  98. {
  99.   char *errmsg;
  100.  
  101.   /* Avoid duplicate error message.  */
  102.   if (TREE_CODE (type) == ERROR_MARK)
  103.     return;
  104.  
  105.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  106.              || TREE_CODE (value) == PARM_DECL))
  107.     error ("`%s' has an incomplete type",
  108.        IDENTIFIER_POINTER (DECL_NAME (value)));
  109.   else
  110.     {
  111.     retry:
  112.       /* We must print an error message.  Be clever about what it says.  */
  113.  
  114.       switch (TREE_CODE (type))
  115.     {
  116.     case RECORD_TYPE:
  117.       errmsg = "invalid use of undefined type `struct %s'";
  118.       break;
  119.  
  120.     case UNION_TYPE:
  121.       errmsg = "invalid use of undefined type `union %s'";
  122.       break;
  123.  
  124.     case ENUMERAL_TYPE:
  125.       errmsg = "invalid use of undefined type `enum %s'";
  126.       break;
  127.  
  128.     case VOID_TYPE:
  129.       error ("invalid use of void expression");
  130.       return;
  131.  
  132.     case ARRAY_TYPE:
  133.       if (TYPE_DOMAIN (type))
  134.         {
  135.           type = TREE_TYPE (type);
  136.           goto retry;
  137.         }
  138.       error ("invalid use of array with unspecified bounds");
  139.       return;
  140.  
  141.     default:
  142.       abort ();
  143.     }
  144.  
  145.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  146.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  147.       else
  148.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  149.     error ("invalid use of incomplete typedef `%s'",
  150.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  151.     }
  152. }
  153.  
  154. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  155.    as well as those of TYPE.  */
  156.  
  157. static tree
  158. qualify_type (type, like)
  159.      tree type, like;
  160. {
  161.   int constflag = TREE_READONLY (type) || TREE_READONLY (like);
  162.   int volflag = TREE_VOLATILE (type) || TREE_VOLATILE (like);
  163.   return build_type_variant (type, constflag, volflag);
  164. }
  165.  
  166. /* Return the common type of two types.
  167.    We assume that comptypes has already been done and returned 1;
  168.    if that isn't so, this may crash.
  169.  
  170.    This is the type for the result of most arithmetic operations
  171.    if the operands have the given two types.
  172.  
  173.    We do not deal with enumeral types here because they have already been
  174.    converted to integer types.  */
  175.  
  176. tree
  177. commontype (t1, t2)
  178.      tree t1, t2;
  179. {
  180.   register enum tree_code form1;
  181.   register enum tree_code form2;
  182.  
  183.   /* Save time if the two types are the same.  */
  184.  
  185.   if (t1 == t2) return t1;
  186.  
  187.   /* Treat an enum type as the unsigned integer type of the same width.  */
  188.  
  189.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  190.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  191.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  192.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  193.  
  194.   form1 = TREE_CODE (t1);
  195.   form2 = TREE_CODE (t2);
  196.  
  197.   switch (form1)
  198.     {
  199.     case INTEGER_TYPE:
  200.     case REAL_TYPE:
  201.       /* If only one is real, use it as the result.  */
  202.  
  203.       if (form1 == REAL_TYPE && form2 != REAL_TYPE)
  204.     return t1;
  205.  
  206.       if (form2 == REAL_TYPE && form1 != REAL_TYPE)
  207.     return t2;
  208.  
  209.       /* Both real or both integers; use the one with greater precision.  */
  210.  
  211.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  212.     return t1;
  213.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  214.     return t2;
  215.  
  216.       /* Same precision.  Prefer longs to ints even when same size.  */
  217.  
  218.       if (t1 == long_unsigned_type_node
  219.       || t2 == long_unsigned_type_node)
  220.     return long_unsigned_type_node;
  221.  
  222.       if (t1 == long_integer_type_node
  223.       || t2 == long_integer_type_node)
  224.     {
  225.       /* But preserve unsignedness from the other type,
  226.          since long cannot hold all the values of an unsigned int.  */
  227.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  228.         return long_unsigned_type_node;
  229.       return long_integer_type_node;
  230.     }
  231.  
  232.       /* Otherwise prefer the unsigned one.  */
  233.  
  234.       if (TREE_UNSIGNED (t1))
  235.     return t1;
  236.       else return t2;
  237.  
  238.     case POINTER_TYPE:
  239. #if 0
  240.       /* For two pointers, do this recursively on the target type,
  241.      and combine the qualifiers of the two types' targets.  */
  242.       {
  243.     tree target = commontype (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  244.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  245.     int constp
  246.       = TREE_READ_ONLY (TREE_TYPE (t1)) || TREE_READ_ONLY (TREE_TYPE (t2));
  247.     int volatilep
  248.       = TREE_VOLATILE (TREE_TYPE (t1)) || TREE_VOLATILE (TREE_TYPE (t2));
  249.     return build_pointer_type (build_type_variant (target, constp, volatilep));
  250.       }
  251. #endif
  252.       return build_pointer_type (commontype (TREE_TYPE (t1), TREE_TYPE (t2)));
  253.  
  254.     case ARRAY_TYPE:
  255.       {
  256.     tree elt = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  257.     /* Save space: see if the result is identical to one of the args.  */
  258.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  259.       return t1;
  260.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  261.       return t2;
  262.     /* Merge the element types, and have a size if either arg has one.  */
  263.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  264.       }
  265.  
  266.     case FUNCTION_TYPE:
  267.       /* Function types: prefer the one that specified arg types.
  268.      If both do, merge the arg types.  Also merge the return types.  */
  269.       {
  270.     tree valtype = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  271.     tree p1 = TYPE_ARG_TYPES (t1);
  272.     tree p2 = TYPE_ARG_TYPES (t2);
  273.     int len;
  274.     tree newargs, n;
  275.     int i;
  276.  
  277.     /* Save space: see if the result is identical to one of the args.  */
  278.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  279.       return t1;
  280.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  281.       return t2;
  282.  
  283.     /* Simple way if one arg fails to specify argument types.  */
  284.     if (TYPE_ARG_TYPES (t1) == 0)
  285.       return build_function_type (valtype, TYPE_ARG_TYPES (t2));
  286.     if (TYPE_ARG_TYPES (t2) == 0)
  287.       return build_function_type (valtype, TYPE_ARG_TYPES (t1));
  288.  
  289.     /* If both args specify argument types, we must merge the two
  290.        lists, argument by argument.  */
  291.  
  292.     len = list_length (p1);
  293.     newargs = 0;
  294.  
  295.     for (i = 0; i < len; i++)
  296.       newargs = tree_cons (0, 0, newargs);
  297.  
  298.     n = newargs;
  299.  
  300.     for (; p1;
  301.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  302.       TREE_VALUE (n) = commontype (TREE_VALUE (p1), TREE_VALUE (p2));
  303.  
  304.     return build_function_type (valtype, newargs);
  305.       }
  306.  
  307.     default:
  308.       return t1;
  309.     }
  310.  
  311. }
  312.  
  313. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  314.    or various other operations.  This is what ANSI C speaks of as
  315.    "being the same".  */
  316.  
  317. int
  318. comptypes (type1, type2)
  319.      tree type1, type2;
  320. {
  321.   register tree t1 = type1;
  322.   register tree t2 = type2;
  323.  
  324.   /* Suppress errors caused by previously reported errors */
  325.  
  326.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  327.     return 1;
  328.  
  329.   /* Treat an enum type as the unsigned integer type of the same width.  */
  330.  
  331.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  332.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  333.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  334.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  335.  
  336.   if (t1 == t2)
  337.     return 1;
  338.  
  339.   /* Different classes of types can't be compatible.  */
  340.  
  341.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  342.  
  343.   switch (TREE_CODE (t1))
  344.     {
  345.     case POINTER_TYPE:
  346.       return (TREE_TYPE (t1) == TREE_TYPE (t2)
  347.           || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  348.  
  349.     case FUNCTION_TYPE:
  350.       return ((TREE_TYPE (t1) == TREE_TYPE (t2)
  351.            || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
  352.           && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
  353.  
  354.     case ARRAY_TYPE:
  355.       /* Target types must match.  */
  356.       if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  357.         || comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  358.     return 0;
  359.       {
  360.     tree d1 = TYPE_DOMAIN (t1);
  361.     tree d2 = TYPE_DOMAIN (t2);
  362.  
  363.     /* Sizes must match unless one is missing or variable.  */
  364.     if (d1 == 0 || d2 == 0 || d1 == d2
  365.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  366.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  367.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  368.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  369.       return 1;
  370.  
  371.     return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  372.          == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  373.         && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  374.             == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  375.         && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  376.             == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  377.         && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  378.             == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  379.       }
  380.     }
  381.   return 0;
  382. }
  383.  
  384. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  385.    ignoring their qualifiers.  */
  386.  
  387. int
  388. comp_target_types (ttl, ttr)
  389.      tree ttl, ttr;
  390. {
  391.   return comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  392.             TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  393. }
  394.  
  395. /* Subroutines of `comptypes'.  */
  396.  
  397. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  398.    are equivalent in the sense that functions with those parameter types
  399.    can have equivalent types.
  400.    If either list is empty, we win.
  401.    Otherwise, the two lists must be equivalent, element by element.  */
  402.  
  403. static int
  404. compparms (parms1, parms2)
  405.      tree parms1, parms2;
  406. {
  407.   register tree t1 = parms1, t2 = parms2;
  408.  
  409.   /* An unspecified parmlist matches any specified parmlist
  410.      whose argument types don't need default promotions.  */
  411.  
  412.   if (t1 == 0)
  413.     return compparms1 (t2);
  414.   if (t2 == 0)
  415.     return compparms1 (t1);
  416.  
  417.   while (1)
  418.     {
  419.       if (t1 == 0 && t2 == 0)
  420.     return 1;
  421.       /* If one parmlist is shorter than the other,
  422.      they fail to match.  */
  423.       if (t1 == 0 || t2 == 0)
  424.     return 0;
  425.       if (! comptypes (TREE_VALUE (t1), TREE_VALUE (t2)))
  426.     return 0;
  427.       t1 = TREE_CHAIN (t1);
  428.       t2 = TREE_CHAIN (t2);
  429.     }
  430. }
  431.  
  432. /* Return 1 if PARMS specifies a fixed number of parameters
  433.    and none of their types is affected by default promotions.  */
  434.  
  435. int
  436. compparms1 (parms)
  437.      tree parms;
  438. {
  439.   register tree t;
  440.   for (t = parms; t; t = TREE_CHAIN (t))
  441.     {
  442.       register tree type = TREE_VALUE (t);
  443.  
  444.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  445.     return 0;
  446.  
  447.       if (type == float_type_node)
  448.     return 0;
  449.  
  450.       if (TREE_CODE (type) == INTEGER_TYPE
  451.       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  452.     return 0;
  453.     }
  454.   return 1;
  455. }
  456.  
  457. /* Return an unsigned type the same as TYPE in other respects.  */
  458.  
  459. tree
  460. unsigned_type (type)
  461.      tree type;
  462. {
  463.   if (type == signed_char_type_node || type == char_type_node)
  464.     return unsigned_char_type_node;
  465.   if (type == integer_type_node)
  466.     return unsigned_type_node;
  467.   if (type == short_integer_type_node)
  468.     return short_unsigned_type_node;
  469.   if (type == long_integer_type_node)
  470.     return long_unsigned_type_node;
  471.   return type;
  472. }
  473.  
  474. /* Return a signed type the same as TYPE in other respects.  */
  475.  
  476. tree
  477. signed_type (type)
  478.      tree type;
  479. {
  480.   if (type == unsigned_char_type_node || type == char_type_node)
  481.     return signed_char_type_node;
  482.   if (type == unsigned_type_node)
  483.     return integer_type_node;
  484.   if (type == short_unsigned_type_node)
  485.     return short_integer_type_node;
  486.   if (type == long_unsigned_type_node)
  487.     return long_integer_type_node;
  488.   return type;
  489. }
  490.  
  491. /* Return a type the same as TYPE except unsigned or
  492.    signed according to UNSIGNEDP.  */
  493.  
  494. tree
  495. signed_or_unsigned_type (unsignedp, type)
  496.      int unsignedp;
  497.      tree type;
  498. {
  499.   if (TREE_CODE (type) != INTEGER_TYPE)
  500.     return type;
  501.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  502.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  503.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  504.     return unsignedp ? unsigned_type_node : integer_type_node;
  505.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  506.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  507.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  508.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  509.   return type;
  510. }
  511.  
  512. /* Return an integer type with BITS bits of precision,
  513.    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
  514.  
  515. tree
  516. type_for_size (bits, unsignedp)
  517.      int bits;
  518.      int unsignedp;
  519. {
  520.   if (bits <= TYPE_PRECISION (signed_char_type_node))
  521.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  522.  
  523.   if (bits <= TYPE_PRECISION (short_integer_type_node))
  524.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  525.  
  526.   if (bits <= TYPE_PRECISION (integer_type_node))
  527.     return unsignedp ? unsigned_type_node : integer_type_node;
  528.  
  529.   if (bits <= TYPE_PRECISION (long_integer_type_node))
  530.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  531.  
  532.   return 0;
  533. }
  534.  
  535. tree
  536. get_floating_type (mode)
  537.      enum machine_mode mode;
  538. {
  539.   if (mode == SFmode)
  540.     return float_type_node;
  541.   if (mode == DFmode)
  542.     return double_type_node;
  543.   abort ();
  544. }
  545.  
  546. tree
  547. c_sizeof (type)
  548.      tree type;
  549. {
  550.   enum tree_code code = TREE_CODE (type);
  551.  
  552.   if (code == FUNCTION_TYPE)
  553.     {
  554.       if (pedantic)
  555.     warning ("sizeof applied to a function type");
  556.       return build_int (1);
  557.     }
  558.   if (code == VOID_TYPE)
  559.     {
  560.       if (pedantic)
  561.     warning ("sizeof applied to a void type");
  562.       return build_int (1);
  563.     }
  564.  
  565.   return size_in_bytes (type);
  566. }
  567.  
  568. tree
  569. c_sizeof_nowarn (type)
  570.      tree type;
  571. {
  572.   enum tree_code code = TREE_CODE (type);
  573.  
  574.   if (code == FUNCTION_TYPE
  575.       || code == VOID_TYPE)
  576.     return build_int (1);
  577.  
  578.   return size_in_bytes (type);
  579. }
  580.  
  581. /* Implement the __alignof keyword: Return the minimum required
  582.    alignment of TYPE, measured in bytes.  */
  583.  
  584. tree
  585. c_alignof (type)
  586.      tree type;
  587. {
  588.   enum tree_code code = TREE_CODE (type);
  589.  
  590.   if (pedantic)
  591.     warning ("ANSI C does not allow `__alignof'");
  592.  
  593.   if (code == FUNCTION_TYPE)
  594.     return build_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  595.  
  596.   if (code == VOID_TYPE)
  597.     return build_int (1);
  598.  
  599.   return build_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  600. }
  601.  
  602. /* Perform default promotions for C data used in expressions.
  603.    Arrays and functions are converted to pointers;
  604.    enumeral types or short or char, to int.
  605.    In addition, manifest constants symbols are replaced by their values.  */
  606.  
  607. tree
  608. default_conversion (exp)
  609.      tree exp;
  610. {
  611.   register tree dt = TREE_TYPE (exp);
  612.   register enum tree_code form = TREE_CODE (dt);
  613.  
  614.   if (TREE_CODE (exp) == CONST_DECL)
  615.     exp = DECL_INITIAL (exp);
  616.  
  617.   if (form == ENUMERAL_TYPE
  618.       || (form == INTEGER_TYPE
  619.       && (TYPE_PRECISION (dt)
  620.           < TYPE_PRECISION (integer_type_node))))
  621.     {
  622.       /* Traditionally, unsignedness is preserved in default promotions.  */
  623.       if (flag_traditional && TREE_UNSIGNED (dt))
  624.     return convert (unsigned_type_node, exp);
  625.       return convert (integer_type_node, exp);
  626.     }
  627.   if (flag_traditional && dt == float_type_node)
  628.     return convert (double_type_node, exp);
  629.   if (form == VOID_TYPE)
  630.     {
  631.       error ("void value not ignored as it ought to be");
  632.       return error_mark_node;
  633.     }
  634.   if (form == FUNCTION_TYPE)
  635.     {
  636.       return build_unary_op (ADDR_EXPR, exp, 0);
  637.     }
  638.   if (form == ARRAY_TYPE)
  639.     {
  640.       register tree adr;
  641.       if (TREE_CODE (exp) == INDIRECT_REF)
  642.     return convert (TYPE_POINTER_TO (TREE_TYPE (dt)),
  643.             TREE_OPERAND (exp, 0));
  644.  
  645.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  646.     {
  647.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  648.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  649.             TREE_OPERAND (exp, 0), op1);
  650.     }
  651.  
  652.       if (!lvalue_p (exp)
  653.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  654.     {
  655.       error ("invalid use of non-lvalue array");
  656.       return error_mark_node;
  657.     }
  658.  
  659. /* ??? This is not really quite correct
  660.    in that the type of the operand of ADDR_EXPR
  661.    is not the target type of the type of the ADDR_EXPR itself.
  662.    Question is, can this lossage be avoided?  */
  663.       adr = build (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (dt)), exp);
  664.       mark_addressable (exp);
  665.       TREE_LITERAL (adr) = staticp (exp);
  666.       TREE_VOLATILE (adr) = 0;   /* Default would be, same as EXP.  */
  667.       return adr;
  668.     }
  669.   return exp;
  670. }
  671.  
  672. /* Make an expression to refer to the COMPONENT field of
  673.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  674.  
  675. tree
  676. build_component_ref (datum, component)
  677.      tree datum, component;
  678. {
  679.   register tree basename = datum;
  680.   register tree basetype = TREE_TYPE (basename);
  681.   register enum tree_code form = TREE_CODE (basetype);
  682.   register tree field = NULL;
  683.   register tree ref;
  684.  
  685.   /* First, see if there is a field or component with name COMPONENT. */
  686.  
  687.   if (form == RECORD_TYPE || form == UNION_TYPE)
  688.     {
  689.       if (TYPE_SIZE (basetype) == 0)
  690.     {
  691.       incomplete_type_error (0, basetype);
  692.       return error_mark_node;
  693.     }
  694.  
  695.       /* Look up component name in the structure type definition.  */
  696.  
  697.       for (field = TYPE_FIELDS (basetype); field; field = TREE_CHAIN (field))
  698.     {
  699.       if (DECL_NAME (field) == component)
  700.         break;
  701.     }
  702.  
  703.       if (!field)
  704.     {
  705.       error (form == RECORD_TYPE
  706.          ? "structure has no member named `%s'"
  707.          : "union has no member named `%s'",
  708.          IDENTIFIER_POINTER (component));
  709.       return error_mark_node;
  710.     }
  711.  
  712.       ref = build (COMPONENT_REF, TREE_TYPE (field), basename, field);
  713.  
  714.       if (TREE_READONLY (basename) || TREE_READONLY (field))
  715.     TREE_READONLY (ref) = 1;
  716.       if (TREE_THIS_VOLATILE (basename) || TREE_VOLATILE (field))
  717.     TREE_THIS_VOLATILE (ref) = 1;
  718.  
  719.       return ref;
  720.     }
  721.   else if (form != ERROR_MARK)
  722.     error ("request for member `%s' in something not a structure or union",
  723.         IDENTIFIER_POINTER (component));
  724.  
  725.   return error_mark_node;
  726. }
  727.  
  728. /* Given an expression PTR for a pointer, return an expression
  729.    for the value pointed to.
  730.    ERRORSTRING is the name of the operator to appear in error messages.  */
  731.  
  732. tree
  733. build_indirect_ref (ptr, errorstring)
  734.      tree ptr;
  735.      char *errorstring;
  736. {
  737.   register tree pointer = default_conversion (ptr);
  738.   register tree dt = TREE_TYPE (pointer);
  739.  
  740.   if (TREE_CODE (dt) == POINTER_TYPE)
  741.     if (TREE_CODE (pointer) == ADDR_EXPR
  742.     && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  743.         == TREE_TYPE (dt)))
  744.       return TREE_OPERAND (pointer, 0);
  745.     else
  746.       {
  747.     tree t = TREE_TYPE (dt);
  748.     register tree ref = build (INDIRECT_REF,
  749.                    TYPE_MAIN_VARIANT (t), pointer);
  750.  
  751.     TREE_READONLY (ref) = TREE_READONLY (t);
  752.     TREE_VOLATILE (ref) = TREE_VOLATILE (t) || TREE_VOLATILE (pointer);
  753.     TREE_THIS_VOLATILE (ref) = TREE_VOLATILE (t);
  754.     return ref;
  755.       }
  756.   else if (TREE_CODE (pointer) != ERROR_MARK)
  757.     error ("invalid type argument of `%s'", errorstring);
  758.   return error_mark_node;
  759. }
  760.  
  761. /* This handles expressions of the form "a[i]", which denotes
  762.    an array reference.
  763.  
  764.    This is logically equivalent in C to *(a+i), but we may do it differently.
  765.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  766.    This avoids forcing the array out of registers, and can work on
  767.    arrays that are not lvalues (for example, members of structures returned
  768.    by functions).  */
  769.  
  770. tree
  771. build_array_ref (array, index)
  772.      tree array, index;
  773. {
  774.   if (index == 0)
  775.     {
  776.       error ("subscript missing in array reference");
  777.       return error_mark_node;
  778.     }
  779.  
  780.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  781.       && TREE_CODE (array) != INDIRECT_REF)
  782.     {
  783.       index = default_conversion (index);
  784.       if (index != error_mark_node
  785.       && TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  786.     {
  787.       error ("array subscript is not an integer");
  788.       return error_mark_node;
  789.     }
  790.  
  791.       /* An array that is indexed by a non-constant
  792.      cannot be stored in a register; we must be able to do
  793.      address arithmetic on its address.
  794.      Likewise an array of elements of variable size.  */
  795.       if (TREE_CODE (index) != INTEGER_CST
  796.       || TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)
  797.     mark_addressable (array);
  798.  
  799.       if (pedantic && !lvalue_p (array))
  800.     warning ("ANSI C forbids subscripting non-lvalue array");
  801.  
  802.       return require_complete_type (build (ARRAY_REF,
  803.                        TREE_TYPE (TREE_TYPE (array)),
  804.                        array, index));
  805.     }
  806.  
  807.   {
  808.     tree ar = default_conversion (array);
  809.     tree ind = default_conversion (index);
  810.  
  811.     if ((TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE
  812.      && TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  813.     || (TREE_CODE (TREE_TYPE (ind)) == POINTER_TYPE
  814.         && TREE_CODE (TREE_TYPE (ar)) != INTEGER_TYPE))
  815.       {
  816.     error ("array subscript is not an integer");
  817.     return error_mark_node;
  818.       }
  819.  
  820.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind),
  821.                    "array indexing");
  822.   }
  823. }
  824.  
  825. /* Build a function call to function FUNCTION with parameters PARAMS.
  826.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  827.    TREE_VALUE of each node is a parameter-expression.
  828.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  829.  
  830. tree
  831. build_function_call (function, params)
  832.      tree function, params;
  833. {
  834.   register tree fntype;
  835.   register tree value_type;
  836.   register tree coerced_params;
  837.   tree name = NULL_TREE;
  838.   tree actualparameterlist ();
  839.  
  840.   /* Convert anything with function type to a pointer-to-function.  */
  841.   if (TREE_CODE (function) == FUNCTION_DECL)
  842.     {
  843.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  844.      (because calling an inline function does not mean the function
  845.      needs to be separately compiled).  */
  846.       function = build (ADDR_EXPR, build_pointer_type (TREE_TYPE (function)),
  847.             function);
  848.     }
  849.   else
  850.     function = default_conversion (function);
  851.  
  852.   fntype = TREE_TYPE (function);
  853.  
  854.   if (TREE_CODE (fntype) == ERROR_MARK)
  855.     return error_mark_node;
  856.  
  857.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  858.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  859.     {
  860.       error ("called object is not a function");
  861.       return error_mark_node;
  862.     }
  863.  
  864.   /* fntype now gets the type of function pointed to.  */
  865.   fntype = TREE_TYPE (fntype);
  866.  
  867.   /* Convert the parameters to the types declared in the
  868.      function prototype, or apply default promotions.  */
  869.  
  870.   coerced_params = actualparameterlist (TYPE_ARG_TYPES (fntype), params, name);
  871.  
  872.   /* Recognize certain built-in functions so we can make tree-codes
  873.      other than CALL_EXPR.  We do this when it enables fold-const.c
  874.      to do something useful.  */
  875.  
  876.   if (TREE_CODE (function) == ADDR_EXPR
  877.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
  878.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  879.       {
  880.       case BUILT_IN_ABS:
  881.       case BUILT_IN_LABS:
  882.       case BUILT_IN_FABS:
  883.     if (coerced_params == 0)
  884.       return integer_zero_node;
  885.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  886.       }
  887.  
  888.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  889.   
  890.   {
  891.     register tree result = 
  892.       build (CALL_EXPR, value_type, function, coerced_params, NULL_TREE);
  893.  
  894.     TREE_VOLATILE (result) = 1;
  895.     if (value_type == void_type_node)
  896.       return result;
  897.     return require_complete_type (result);
  898.   }
  899. }
  900.  
  901. /* Convert the actual parameter expressions in the list VALUES
  902.    to the types in the list TYPELIST.
  903.    If parmdecls is exhausted, or when an element has NULL as its type,
  904.    perform the default conversions.
  905.  
  906.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  907.  
  908.    This is also where warnings about wrong number of args are generated.
  909.    
  910.    Return a list of expressions for the parameters as converted.
  911.  
  912.    Both VALUES and the returned value are chains of TREE_LIST nodes
  913.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  914.  
  915. tree
  916. actualparameterlist (typelist, values, name)
  917.      tree typelist, values, name;
  918. {
  919.   register tree typetail, valtail;
  920.   register tree result = NULL;
  921.  
  922.   for (valtail = values, typetail = typelist;
  923.        valtail;
  924.        valtail = TREE_CHAIN (valtail))
  925.     {
  926.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  927.       register tree val = TREE_VALUE (valtail);
  928.       register tree parm;
  929.  
  930.       if (type == void_type_node)
  931.     {
  932.       if (name)
  933.         error ("too many arguments to function `%s'",
  934.            IDENTIFIER_POINTER (name));
  935.       else
  936.         error ("too many arguments to function");
  937.       break;
  938.     }
  939.  
  940.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  941.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  942.     val = default_conversion (val);
  943.  
  944.       val = require_complete_type (val);
  945.  
  946.       if (type != 0)
  947.     /* Formal parm type is specified by a function prototype.  */
  948.     parm = build_tree_list (0, convert_for_assignment (type, val,
  949.                                "argument passing"));
  950.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  951.                && (TYPE_PRECISION (TREE_TYPE (val))
  952.                < TYPE_PRECISION (double_type_node)))
  953.     /* Convert `float' to `double'.  */
  954.     parm = build_tree_list (NULL_TREE,
  955.                 convert (double_type_node, val));
  956.       else
  957.     /* Convert `short' and `char' to full-size `int'.  */
  958.     parm = build_tree_list (NULL_TREE, default_conversion (val));
  959.  
  960.       result = chainon (result, parm);
  961.       if (typetail)
  962.     typetail = TREE_CHAIN (typetail);
  963.     }
  964.  
  965.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  966.     {
  967.       if (name)
  968.     error ("too few arguments to function `%s'",
  969.            IDENTIFIER_POINTER (name));
  970.       else
  971.     error ("too few arguments to function");
  972.     }
  973.  
  974.   return result;
  975. }
  976.  
  977. /* Build a binary-operation expression, after performing default
  978.    conversions on the operands.  CODE is the kind of expression to build.  */
  979.  
  980. tree
  981. build_binary_op (code, arg1, arg2)
  982.      enum tree_code code;
  983.      tree arg1, arg2;
  984. {
  985.   return build_binary_op_nodefault (code, default_conversion (arg1),
  986.                     default_conversion (arg2));
  987. }
  988.  
  989. /* Build a binary-operation expression without default conversions.
  990.    CODE is the kind of expression to build.
  991.    This function differs from `build' in several ways:
  992.    the data type of the result is computed and recorded in it,
  993.    warnings are generated if arg data types are invalid,
  994.    special handling for addition and subtraction of pointers is known,
  995.    and some optimization is done (operations on narrow ints
  996.    are done in the narrower type when that gives the same result).
  997.    Constant folding is also done before the result is returned.
  998.  
  999.    Note that the operands will never have enumeral types
  1000.    because either they have just had the default conversions performed
  1001.    or they have both just been converted to some other type in which
  1002.    the arithmetic is to be done.  */
  1003.  
  1004. tree
  1005. build_binary_op_nodefault (code, op0, op1)
  1006.      enum tree_code code;
  1007.      tree op0, op1;
  1008. {
  1009.   tree dt0 = datatype (op0), dt1 = datatype (op1);
  1010.  
  1011.   /* The expression codes of the data types of the arguments tell us
  1012.      whether the arguments are integers, floating, pointers, etc.  */
  1013.   register enum tree_code code0 = TREE_CODE (dt0);
  1014.   register enum tree_code code1 = TREE_CODE (dt1);
  1015.  
  1016.   /* Expression code to give to the expression when it is built.
  1017.      Normally this is CODE, which is what the caller asked for,
  1018.      but in some special cases we change it.  */
  1019.   register enum tree_code resultcode = code;
  1020.  
  1021.   /* Data type in which the computation is to be performed.
  1022.      In the simplest cases this is the common type of the arguments.  */
  1023.   register tree result_type = NULL;
  1024.  
  1025.   /* Nonzero means operands have already been type-converted
  1026.      in whatever way is necessary.
  1027.      Zero means they need to be converted to RESULT_TYPE.  */
  1028.   int converted = 0;
  1029.  
  1030.   /* Nonzero means after finally constructing the expression
  1031.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  1032.   tree final_type = 0;
  1033.  
  1034.   /* Nonzero if this is an operation like MIN or MAX which can
  1035.      safely be computed in short if both args are promoted shorts.
  1036.      Also implies COMMON.
  1037.      -1 indicates a bitwise operation; this makes a difference
  1038.      in the exact conditions for when it is safe to do the operation
  1039.      in a narrower mode.  */
  1040.   int shorten = 0;
  1041.  
  1042.   /* Nonzero if this is a comparison operation;
  1043.      if both args are promoted shorts, compare the original shorts.
  1044.      Also implies COMMON.  */
  1045.   int short_compare = 0;
  1046.  
  1047.   /* Nonzero if this is a right-shift operation, which can be computed on the
  1048.      original short and then promoted if the operand is a promoted short.  */
  1049.   int short_shift = 0;
  1050.  
  1051.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  1052.   int common = 0;
  1053.  
  1054.   /* If an error was already reported for one of the arguments,
  1055.      avoid reporting another error.  */
  1056.  
  1057.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  1058.     return error_mark_node;
  1059.  
  1060.   switch (code)
  1061.     {
  1062.     case PLUS_EXPR:
  1063.       /* Handle the pointer + int case.  */
  1064.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1065.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  1066.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  1067.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  1068.       else
  1069.     common = 1;
  1070.       break;
  1071.  
  1072.     case MINUS_EXPR:
  1073.       /* Subtraction of two similar pointers.
  1074.      We must subtract them as integers, then divide by object size.  */
  1075.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  1076.       && comp_target_types (dt0, dt1))
  1077.     return pointer_diff (op0, op1);
  1078.       /* Handle pointer minus int.  Just like pointer plus int.  */
  1079.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1080.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  1081.       else
  1082.     common = 1;
  1083.       break;
  1084.  
  1085.     case MULT_EXPR:
  1086.       common = 1;
  1087.       break;
  1088.  
  1089.     case TRUNC_DIV_EXPR:
  1090.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1091.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1092.     {
  1093.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  1094.         resultcode = RDIV_EXPR;
  1095.       else
  1096.         shorten = 1;
  1097.       common = 1;
  1098.     }
  1099.       break;
  1100.  
  1101.     case BIT_AND_EXPR:
  1102.     case BIT_ANDTC_EXPR:
  1103.     case BIT_IOR_EXPR:
  1104.     case BIT_XOR_EXPR:
  1105.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1106.     shorten = -1;
  1107.       /* If one operand is a constant, and the other is a short type
  1108.      that has been converted to an int,
  1109.      really do the work in the short type and then convert the
  1110.      result to int.  If we are lucky, the constant will be 0 or 1
  1111.      in the short type, making the entire operation go away.  */
  1112.       if (TREE_CODE (op0) == INTEGER_CST
  1113.       && TREE_CODE (op1) == NOP_EXPR
  1114.       && TYPE_PRECISION (dt1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  1115.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  1116.     {
  1117.       final_type = result_type;
  1118.       op1 = TREE_OPERAND (op1, 0);
  1119.       result_type = TREE_TYPE (op1);
  1120.     }
  1121.       if (TREE_CODE (op1) == INTEGER_CST
  1122.       && TREE_CODE (op0) == NOP_EXPR
  1123.       && TYPE_PRECISION (dt0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  1124.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  1125.     {
  1126.       final_type = result_type;
  1127.       op0 = TREE_OPERAND (op0, 0);
  1128.       result_type = TREE_TYPE (op0);
  1129.     }
  1130.       break;
  1131.  
  1132.     case TRUNC_MOD_EXPR:
  1133.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1134.     shorten = 1;
  1135.       break;
  1136.  
  1137.     case TRUTH_ANDIF_EXPR:
  1138.     case TRUTH_ORIF_EXPR:
  1139.     case TRUTH_AND_EXPR:
  1140.     case TRUTH_OR_EXPR:
  1141.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  1142.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  1143.     {
  1144.       /* Result of these operations is always an int,
  1145.          but that does not mean the operands should be
  1146.          converted to ints!  */
  1147.       result_type = integer_type_node;
  1148.       converted = 1;
  1149.     }
  1150.       break;
  1151.  
  1152.       /* Shift operations: result has same type as first operand.
  1153.      Also set SHORT_SHIFT if shifting rightward.  */
  1154.  
  1155.     case RSHIFT_EXPR:
  1156.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1157.     {
  1158.       result_type = dt0;
  1159.       if (TREE_CODE (op1) == INTEGER_CST
  1160.           && TREE_INT_CST_LOW (op1) > 0)
  1161.         short_shift = 1;
  1162.     }
  1163.       break;
  1164.  
  1165.     case LSHIFT_EXPR:
  1166.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1167.     {
  1168.       result_type = dt0;
  1169.       if (TREE_CODE (op1) == INTEGER_CST
  1170.           && TREE_INT_CST_LOW (op1) < 0)
  1171.         short_shift = 1;
  1172.     }
  1173.       break;
  1174.  
  1175.     case RROTATE_EXPR:
  1176.     case LROTATE_EXPR:
  1177.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1178.     result_type = dt0;
  1179.       break;
  1180.  
  1181.     case EQ_EXPR:
  1182.     case NE_EXPR:
  1183.       /* Result of comparison is always int,
  1184.      but don't convert the args to int!  */
  1185.       result_type = integer_type_node;
  1186.       converted = 1;
  1187.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1188.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1189.     short_compare = 1;
  1190.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1191.     {
  1192.       register tree tt0 = TREE_TYPE (dt0);
  1193.       register tree tt1 = TREE_TYPE (dt1);
  1194.       /* Anything compares with void *.  void * compares with anything.
  1195.          Otherwise, the targets must be the same.  */
  1196.       if (comp_target_types (dt0, dt1))
  1197.         ;
  1198.       else if (tt0 == void_type_node)
  1199.         {
  1200.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  1201.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1202.         }
  1203.       else if (tt1 == void_type_node)
  1204.         {
  1205.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  1206.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1207.         }
  1208.       else
  1209.         warning ("comparison of distinct pointer types lacks a cast");
  1210.     }
  1211.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1212.         && integer_zerop (op1))
  1213.     op1 = null_pointer_node;
  1214.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1215.         && integer_zerop (op0))
  1216.     op0 = null_pointer_node;
  1217.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1218.     {
  1219.       if (! flag_traditional)
  1220.         warning ("comparison between pointer and integer");
  1221.       op1 = convert (TREE_TYPE (op0), op1);
  1222.     }
  1223.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1224.     {
  1225.       if (! flag_traditional)
  1226.         warning ("comparison between pointer and integer");
  1227.       op0 = convert (TREE_TYPE (op1), op0);
  1228.     }
  1229.       else
  1230.     /* If args are not valid, clear out RESULT_TYPE
  1231.        to cause an error message later.  */
  1232.     result_type = 0;
  1233.       break;
  1234.  
  1235.     case MAX_EXPR:
  1236.     case MIN_EXPR:
  1237.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1238.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1239.     shorten = 1;
  1240.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1241.     {
  1242.       if (! comp_target_types (dt0, dt1))
  1243.         warning ("comparison of distinct pointer types lacks a cast");
  1244.       else if (pedantic 
  1245.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1246.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1247.       result_type = commontype (dt0, dt1);
  1248.     }
  1249.       break;
  1250.  
  1251.     case LE_EXPR:
  1252.     case GE_EXPR:
  1253.     case LT_EXPR:
  1254.     case GT_EXPR:
  1255.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1256.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1257.     short_compare = 1;
  1258.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1259.     {
  1260.       if (! comp_target_types (dt0, dt1))
  1261.         warning ("comparison of distinct pointer types lacks a cast");
  1262.       else if (pedantic 
  1263.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1264.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1265.       result_type = integer_type_node;
  1266.     }
  1267.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1268.         && integer_zerop (op1))
  1269.     {
  1270.       result_type = integer_type_node;
  1271.       op1 = null_pointer_node;
  1272.       if (! flag_traditional)
  1273.         warning ("ordered comparison of pointer with integer zero");
  1274.     }
  1275.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1276.         && integer_zerop (op0))
  1277.     {
  1278.       result_type = integer_type_node;
  1279.       op0 = null_pointer_node;
  1280.       if (pedantic)
  1281.         warning ("ordered comparison of pointer with integer zero");
  1282.     }
  1283.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1284.     {
  1285.       if (! flag_traditional)
  1286.         warning ("comparison between pointer and integer");
  1287.       op1 = convert (TREE_TYPE (op0), op1);
  1288.     }
  1289.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1290.     {
  1291.       if (! flag_traditional)
  1292.         warning ("comparison between pointer and integer");
  1293.       op0 = convert (TREE_TYPE (op1), op0);
  1294.     }
  1295.       converted = 1;
  1296.       break;
  1297.     }
  1298.  
  1299.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1300.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1301.     {
  1302.       if (shorten || common || short_compare)
  1303.     result_type = commontype (dt0, dt1);
  1304.  
  1305.       /* For certain operations (which identify themselves by shorten != 0)
  1306.      if both args were extended from the same smaller type,
  1307.      do the arithmetic in that type and then extend.
  1308.  
  1309.      shorten !=0 and !=1 indicates a bitwise operation.
  1310.      For them, this optimization is safe only if
  1311.      both args are zero-extended or both are sign-extended.
  1312.      Otherwise, we might change the result.
  1313.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  1314.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  1315.  
  1316.       if (shorten)
  1317.     {
  1318.       int unsigned0, unsigned1;
  1319.       tree arg0 = get_narrower (op0, &unsigned0);
  1320.       tree arg1 = get_narrower (op1, &unsigned1);
  1321.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  1322.       int uns = TREE_UNSIGNED (result_type);
  1323.       tree type;
  1324.  
  1325.       final_type = result_type;
  1326.  
  1327.       /* Handle the case that OP0 does not *contain* a conversion
  1328.          but it *requires* conversion to FINAL_TYPE.  */
  1329.  
  1330.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  1331.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1332.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  1333.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1334.  
  1335.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  1336.  
  1337.       /* For bitwise operations, signedness of nominal type
  1338.          does not matter.  Consider only how operands were extended.  */
  1339.       if (shorten == -1)
  1340.         uns = unsigned0;
  1341.  
  1342.       /* Note that in all three cases below we refrain from optimizing
  1343.          an unsigned operation on sign-extended args.
  1344.          That would not be valid.  */
  1345.  
  1346.       /* Both args variable: if both extended in same way
  1347.          from same width, do it in that width.
  1348.          Do it unsigned if args were zero-extended.  */
  1349.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  1350.            < TYPE_PRECISION (result_type))
  1351.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  1352.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  1353.           && unsigned0 == unsigned1
  1354.           && (unsigned0 || !uns))
  1355.         result_type
  1356.           = signed_or_unsigned_type (unsigned0,
  1357.                      commontype (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  1358.       else if (TREE_CODE (arg0) == INTEGER_CST
  1359.            && (unsigned1 || !uns)
  1360.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  1361.                < TYPE_PRECISION (result_type))
  1362.            && (type = signed_or_unsigned_type (unsigned1,
  1363.                                TREE_TYPE (arg1)),
  1364.                int_fits_type_p (arg0, type)))
  1365.         result_type = type;
  1366.       else if (TREE_CODE (arg1) == INTEGER_CST
  1367.            && (unsigned0 || !uns)
  1368.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  1369.                < TYPE_PRECISION (result_type))
  1370.            && (type = signed_or_unsigned_type (unsigned0,
  1371.                                TREE_TYPE (arg0)),
  1372.                int_fits_type_p (arg1, type)))
  1373.         result_type = type;
  1374.     }
  1375.  
  1376.       /* Shifts can be shortened if shifting right.  */
  1377.  
  1378.       if (short_shift)
  1379.     {
  1380.       int unsigned_arg;
  1381.       tree arg0 = get_narrower (op0, &unsigned_arg);
  1382.  
  1383.       final_type = result_type;
  1384.  
  1385.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  1386.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  1387.  
  1388.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  1389.           /* If arg is sign-extended and then unsigned-shifted,
  1390.          we can simulate this with a signed shift in arg's type
  1391.          only if the extended result is at least twice as wide
  1392.          as the arg.  Otherwise, the shift could use up all the
  1393.          ones made by sign-extension and bring in zeros.
  1394.          We can't optimize that case at all, but in most machines
  1395.          it never happens because available widths are 2**N.  */
  1396.           && (!TREE_UNSIGNED (final_type)
  1397.           || unsigned_arg
  1398.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  1399.         {
  1400.           /* Convert the shift-count to its nominal type.  */
  1401.           if (TREE_TYPE (op1) != result_type)
  1402.         op1 = convert (result_type, op1);
  1403.           /* Do an unsigned shift if the operand was zero-extended.  */
  1404.           result_type
  1405.         = signed_or_unsigned_type (unsigned_arg,
  1406.                        TREE_TYPE (arg0));
  1407.           /* Convert value-to-be-shifted to that type.  */
  1408.           if (TREE_TYPE (op0) != result_type)
  1409.         op0 = convert (result_type, op0);
  1410.           converted = 1;
  1411.         }
  1412.     }
  1413.  
  1414.       /* Comparison operations are shortened too but differently.
  1415.      They identify themselves by setting short_compare = 1.  */
  1416.  
  1417.       if (short_compare)
  1418.     {
  1419.       /* Don't write &op0, etc., because that would prevent op0
  1420.          from being kept in a register.
  1421.          Instead, make copies of the our local variables and
  1422.          pass the copies by reference, then copy them back afterward.  */
  1423.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  1424.       enum tree_code xresultcode = resultcode;
  1425.       tree val 
  1426.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  1427.       if (val != 0)
  1428.         return val;
  1429.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  1430.       resultcode = xresultcode;
  1431.     }
  1432.     }
  1433.  
  1434.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  1435.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  1436.      Then the expression will be built.
  1437.      It will be given type FINAL_TYPE if that is nonzero;
  1438.      otherwise, it will be given type RESULT_TYPE.  */
  1439.  
  1440.   if (!result_type)
  1441.     {
  1442.       binary_op_error (code);
  1443.       return error_mark_node;
  1444.     }
  1445.  
  1446.   if (! converted)
  1447.     {
  1448.       if (TREE_TYPE (op0) != result_type)
  1449.     op0 = convert (result_type, op0); 
  1450.       if (TREE_TYPE (op1) != result_type)
  1451.     op1 = convert (result_type, op1); 
  1452.     }
  1453.  
  1454.   {
  1455.     register tree result = build (resultcode, result_type, op0, op1);
  1456.     register tree folded;
  1457.  
  1458.     folded = fold (result);
  1459.     if (folded == result)
  1460.       TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1461.     if (final_type != 0)
  1462.       return convert (final_type, folded);
  1463.     return folded;
  1464.   }
  1465. }
  1466.  
  1467. /* Return a tree for the sum or difference (RESULTCODE says which)
  1468.    of pointer PTROP and integer INTOP.  */
  1469.  
  1470. static tree
  1471. pointer_int_sum (resultcode, ptrop, intop)
  1472.      enum tree_code resultcode;
  1473.      register tree ptrop, intop;
  1474. {
  1475.   tree size_exp;
  1476.  
  1477.   register tree result;
  1478.   register tree folded;
  1479.  
  1480.   /* The result is a pointer of the same type that is being added.  */
  1481.  
  1482.   register tree result_type = datatype (ptrop);
  1483.  
  1484.   if (TREE_TYPE (result_type) == void_type_node)
  1485.     {
  1486.       if (pedantic)
  1487.     warning ("pointer of type `void *' used in arithmetic");
  1488.       size_exp = integer_one_node;
  1489.     }
  1490.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  1491.     {
  1492.       if (pedantic)
  1493.     warning ("pointer to a function used in arithmetic");
  1494.       size_exp = integer_one_node;
  1495.     }
  1496.   else
  1497.     size_exp = size_in_bytes (TREE_TYPE (result_type));
  1498.  
  1499.   /* If what we are about to multiply by the size of the elements
  1500.      contains a constant term, apply distributive law
  1501.      and multiply that constant term separately.
  1502.      This helps produce common subexpressions.  */
  1503.  
  1504.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  1505.       && ! TREE_LITERAL (intop)
  1506.       && TREE_LITERAL (TREE_OPERAND (intop, 1))
  1507.       && TREE_LITERAL (size_exp))
  1508.     {
  1509.       enum tree_code subcode = resultcode;
  1510.       if (TREE_CODE (intop) == MINUS_EXPR)
  1511.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  1512.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1));
  1513.       intop = TREE_OPERAND (intop, 0);
  1514.     }
  1515.  
  1516.   /* Convert the integer argument to a type the same size as a pointer
  1517.      so the multiply won't overflow spuriously.  */
  1518.  
  1519.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  1520.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  1521.  
  1522.   /* Replace the integer argument
  1523.      with a suitable product by the object size.  */
  1524.  
  1525.   intop = build_binary_op (MULT_EXPR, intop, size_exp);
  1526.  
  1527.   /* Create the sum or difference.  */
  1528.  
  1529.   result = build (resultcode, result_type, ptrop, intop);
  1530.  
  1531.   folded = fold (result);
  1532.   if (folded == result)
  1533.     TREE_LITERAL (folded) = TREE_LITERAL (ptrop) & TREE_LITERAL (intop);
  1534.   return folded;
  1535. }
  1536.  
  1537. /* Return a tree for the difference of pointers OP0 and OP1.
  1538.    The resulting tree has type int.  */
  1539.  
  1540. static tree
  1541. pointer_diff (op0, op1)
  1542.      register tree op0, op1;
  1543. {
  1544.   tree dt0 = datatype (op0);
  1545.   enum tree_code resultcode;
  1546.   register tree result, folded;
  1547.   tree restype = type_for_size (POINTER_SIZE, 0);
  1548.  
  1549.   if (pedantic)
  1550.     {
  1551.       if (TREE_CODE (TREE_TYPE (dt0)) == VOID_TYPE)
  1552.     warning ("pointer of type `void *' used in subtraction");
  1553.       if (TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1554.     warning ("pointer to a function used in subtraction");
  1555.     }
  1556.  
  1557.   /* First do the subtraction as integers;
  1558.      then drop through to build the divide operator.  */
  1559.  
  1560.   op0 = build_binary_op (MINUS_EXPR,
  1561.              convert (restype, op0), convert (restype, op1));
  1562.   op1 = ((TREE_TYPE (dt0) == void_type_node
  1563.       || TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1564.      ? integer_one_node
  1565.      : size_in_bytes (TREE_TYPE (dt0)));
  1566.  
  1567.   /* By altering RESULTCODE, we direct this function to build
  1568.      the division operation.  If dividing by a power of 2,
  1569.      use floor-division (rounding down) since that is what
  1570.      a shift insn does.  Otherwise, since we can't use a shift anyway,
  1571.      use whichever kind of rounding this machine does most easily.  */
  1572.  
  1573.   if (TREE_CODE (op1) == INTEGER_CST
  1574.       && -1 == exact_log2 (TREE_INT_CST_LOW (op1)))
  1575.     resultcode = FLOOR_DIV_EXPR;
  1576.   else
  1577.     resultcode = EASY_DIV_EXPR;
  1578.  
  1579.   /* Create the sum or difference.  */
  1580.  
  1581.   result = build (resultcode, restype, op0, op1);
  1582.  
  1583.   folded = fold (result);
  1584.   if (folded == result)
  1585.     TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1586.   return folded;
  1587. }
  1588.  
  1589. /* Print an error message for invalid operands to arith operation CODE.  */
  1590.  
  1591. static void
  1592. binary_op_error (code)
  1593.      enum tree_code code;
  1594. {
  1595.   register char *opname;
  1596.   switch (code)
  1597.     {
  1598.     case PLUS_EXPR:
  1599.       opname = "+"; break;
  1600.     case MINUS_EXPR:
  1601.       opname = "-"; break;
  1602.     case MULT_EXPR:
  1603.       opname = "*"; break;
  1604.     case MAX_EXPR:
  1605.       opname = "max"; break;
  1606.     case MIN_EXPR:
  1607.       opname = "min"; break;
  1608.     case EQ_EXPR:
  1609.       opname = "=="; break;
  1610.     case NE_EXPR:
  1611.       opname = "!="; break;
  1612.     case LE_EXPR:
  1613.       opname = "<="; break;
  1614.     case GE_EXPR:
  1615.       opname = ">="; break;
  1616.     case LT_EXPR:
  1617.       opname = "<"; break;
  1618.     case GT_EXPR:
  1619.       opname = ">"; break;
  1620.     case LSHIFT_EXPR:
  1621.       opname = "<<"; break;
  1622.     case RSHIFT_EXPR:
  1623.       opname = ">>"; break;
  1624.     case TRUNC_MOD_EXPR:
  1625.       opname = "%"; break;
  1626.     case TRUNC_DIV_EXPR:
  1627.       opname = "/"; break;
  1628.     case BIT_AND_EXPR:
  1629.       opname = "&"; break;
  1630.     case BIT_IOR_EXPR:
  1631.       opname = "|"; break;
  1632.     case TRUTH_ANDIF_EXPR:
  1633.       opname = "&&"; break;
  1634.     case TRUTH_ORIF_EXPR:
  1635.       opname = "||"; break;
  1636.     case BIT_XOR_EXPR:
  1637.       opname = "^"; break;
  1638.     }
  1639.   error ("invalid operands to binary %s", opname);
  1640. }
  1641.  
  1642. /* Subroutine of build_binary_op_nodefault, used for comparison operations.
  1643.    See if the operands have both been converted from subword integer types
  1644.    and, if so, perhaps change them both back to their original type.
  1645.  
  1646.    The arguments of this function are all pointers to local variables
  1647.    of build_binary_op_nodefault: OP0_PTR is &OP0, OP1_PTR is &OP1,
  1648.    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
  1649.  
  1650.    If this function returns nonzero, it means that the comparison has
  1651.    a constant value.  What this function returns is an expression for
  1652.    that value.  */
  1653.  
  1654. static tree
  1655. shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
  1656.      tree *op0_ptr, *op1_ptr;
  1657.      tree *restype_ptr;
  1658.      enum tree_code *rescode_ptr;
  1659. {
  1660.   register tree type;
  1661.   tree op0 = *op0_ptr;
  1662.   tree op1 = *op1_ptr;
  1663.   int unsignedp0, unsignedp1;
  1664.   int real1, real2;
  1665.   tree primop0, primop1;
  1666.   enum tree_code code = *rescode_ptr;
  1667.  
  1668.   /* Throw away any conversions to wider types
  1669.      already present in the operands.  */
  1670.  
  1671.   primop0 = get_narrower (op0, &unsignedp0);
  1672.   primop1 = get_narrower (op1, &unsignedp1);
  1673.  
  1674.   /* Handle the case that OP0 does not *contain* a conversion
  1675.      but it *requires* conversion to FINAL_TYPE.  */
  1676.  
  1677.   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
  1678.     unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1679.   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
  1680.     unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1681.  
  1682.   /* If one of the operands must be floated, we cannot optimize.  */
  1683.   real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
  1684.   real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
  1685.  
  1686.   /* If first arg is constant, swap the args (changing operation
  1687.      so value is preserved), for canonicalization.  */
  1688.  
  1689.   if (TREE_LITERAL (primop0))
  1690.     {
  1691.       register tree tem = primop0;
  1692.       register int temi = unsignedp0;
  1693.       primop0 = primop1;
  1694.       primop1 = tem;
  1695.       tem = op0;
  1696.       op0 = op1;
  1697.       op1 = tem;
  1698.       *op0_ptr = op0;
  1699.       *op1_ptr = op1;
  1700.       unsignedp0 = unsignedp1;
  1701.       unsignedp1 = temi;
  1702.       temi = real1;
  1703.       real1 = real2;
  1704.       real2 = temi;
  1705.  
  1706.       switch (code)
  1707.     {
  1708.     case LT_EXPR:
  1709.       code = GT_EXPR;
  1710.       break;
  1711.     case GT_EXPR:
  1712.       code = LT_EXPR;
  1713.       break;
  1714.     case LE_EXPR:
  1715.       code = GE_EXPR;
  1716.       break;
  1717.     case GE_EXPR:
  1718.       code = LE_EXPR;
  1719.       break;
  1720.     }
  1721.       *rescode_ptr = code;
  1722.     }
  1723.  
  1724.   /* If comparing an integer against a constant more bits wide,
  1725.      maybe we can deduce a value of 1 or 0 independent of the data.
  1726.      Or else truncate the constant now
  1727.      rather than extend the variable at run time.
  1728.  
  1729.      This is only interesting if the constant is the wider arg.
  1730.      Also, it is not safe if the constant is unsigned and the
  1731.      variable arg is signed, since in this case the variable
  1732.      would be sign-extended and then regarded as unsigned.
  1733.      Our technique fails in this case because the lowest/highest
  1734.      possible unsigned results don't follow naturally from the
  1735.      lowest/highest possible values of the variable operand.
  1736.      For just EQ_EXPR and NE_EXPR there is another technique that
  1737.      could be used: see if the constant can be faithfully represented
  1738.      in the other operand's type, by truncating it and reextending it
  1739.      and see if that preserves the constant's value.  */
  1740.  
  1741.   if (!real1 && !real2
  1742.       && TREE_CODE (primop1) == INTEGER_CST
  1743.       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
  1744.     {
  1745.       int min_gt, max_gt, min_lt, max_lt;
  1746.       tree maxval, minval;
  1747.       /* 1 if comparison is nominally unsigned.  */
  1748.       int unsignedp = TREE_UNSIGNED (*restype_ptr);
  1749.       tree val;
  1750.  
  1751.       type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
  1752.  
  1753.       maxval = TYPE_MAX_VALUE (type);
  1754.       minval = TYPE_MIN_VALUE (type);
  1755.  
  1756.       if (unsignedp && !unsignedp0)
  1757.     *restype_ptr = signed_type (*restype_ptr);
  1758.  
  1759.       if (TREE_TYPE (primop1) != *restype_ptr)
  1760.     primop1 = convert (*restype_ptr, primop1);
  1761.       if (type != *restype_ptr)
  1762.     {
  1763.       minval = convert (*restype_ptr, minval);
  1764.       maxval = convert (*restype_ptr, maxval);
  1765.     }
  1766.  
  1767.       if (unsignedp && unsignedp0)
  1768.     {
  1769.       min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
  1770.       max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
  1771.       min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
  1772.       max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
  1773.     }
  1774.       else
  1775.     {
  1776.       min_gt = INT_CST_LT (primop1, minval);
  1777.       max_gt = INT_CST_LT (primop1, maxval);
  1778.       min_lt = INT_CST_LT (minval, primop1);
  1779.       max_lt = INT_CST_LT (maxval, primop1);
  1780.     }
  1781.  
  1782.       val = 0;
  1783.       switch (code)
  1784.     {
  1785.     case NE_EXPR:
  1786.       if (max_lt || min_gt)
  1787.         val = integer_one_node;
  1788.       break;
  1789.  
  1790.     case EQ_EXPR:
  1791.       if (max_lt || min_gt)
  1792.         val = integer_zero_node;
  1793.       break;
  1794.  
  1795.     case LT_EXPR:
  1796.       if (max_lt)
  1797.         val = integer_one_node;
  1798.       if (!min_lt)
  1799.         val = integer_zero_node;
  1800.       break;
  1801.  
  1802.     case GT_EXPR:
  1803.       if (min_gt)
  1804.         val = integer_one_node;
  1805.       if (!max_gt)
  1806.         val = integer_zero_node;
  1807.       break;
  1808.  
  1809.     case LE_EXPR:
  1810.       if (!max_gt)
  1811.         val = integer_one_node;
  1812.       if (min_gt)
  1813.         val = integer_zero_node;
  1814.       break;
  1815.  
  1816.     case GE_EXPR:
  1817.       if (!min_lt)
  1818.         val = integer_one_node;
  1819.       if (max_lt)
  1820.         val = integer_zero_node;
  1821.       break;
  1822.     }
  1823.  
  1824.       /* If primop0 was sign-extended and unsigned comparison specd,
  1825.      we did a signed comparison above using the signed type bounds.
  1826.      But the comparison we output must be unsigned.
  1827.  
  1828.      Also, for inequalities, VAL is no good; but if the signed
  1829.      comparison had *any* fixed result, it follows that the
  1830.      unsigned comparison just tests the sign in reverse
  1831.      (positive values are LE, negative ones GE).
  1832.      So we can generate an unsigned comparison
  1833.      against an extreme value of the signed type.  */
  1834.  
  1835.       if (unsignedp && !unsignedp0)
  1836.     {
  1837.       if (val != 0)
  1838.         switch (code)
  1839.           {
  1840.           case LT_EXPR:
  1841.           case GE_EXPR:
  1842.         primop1 = TYPE_MIN_VALUE (type);
  1843.         val = 0;
  1844.         break;
  1845.  
  1846.           case LE_EXPR:
  1847.           case GT_EXPR:
  1848.         primop1 = TYPE_MAX_VALUE (type);
  1849.         val = 0;
  1850.         break;
  1851.           }
  1852.       type = unsigned_type (type);
  1853.     }
  1854.  
  1855.       if (max_lt && !unsignedp0)
  1856.     {
  1857.       /* This is the case of (char)x >?< 0x80, which people used to use
  1858.          expecting old C compilers to change the 0x80 into -0x80.  */
  1859.       if (val == integer_zero_node)
  1860.         warning ("comparison is always 0 due to limited range of data type");
  1861.       if (val == integer_one_node)
  1862.         warning ("comparison is always 1 due to limited range of data type");
  1863.     }
  1864.  
  1865.       if (val != 0)
  1866.     {
  1867.       /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
  1868.       if (TREE_VOLATILE (primop0))
  1869.         return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
  1870.       return val;
  1871.     }
  1872.  
  1873.       /* Value is not predetermined, but do the comparison
  1874.      in the type of the operand that is not constant.
  1875.      TYPE is already properly set.  */
  1876.     }
  1877.   else if (real1 && real2
  1878.        && TYPE_PRECISION (TREE_TYPE (primop0)) == TYPE_PRECISION (TREE_TYPE (primop1)))
  1879.     type = TREE_TYPE (primop0);
  1880.  
  1881.   /* If args' natural types are both narrower than nominal type
  1882.      and both extend in the same manner, compare them
  1883.      in the type of the wider arg.
  1884.      Otherwise must actually extend both to the nominal
  1885.      common type lest different ways of extending
  1886.      alter the result.
  1887.      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
  1888.  
  1889.   else if (unsignedp0 == unsignedp1 && real1 == real2
  1890.        && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
  1891.        && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
  1892.     {
  1893.       type = commontype (TREE_TYPE (primop0), TREE_TYPE (primop1));
  1894.       type = signed_or_unsigned_type (unsignedp0
  1895.                       || TREE_UNSIGNED (*restype_ptr),
  1896.                       type);
  1897.       /* Make sure shorter operand is extended the right way
  1898.      to match the longer operand.  */
  1899.       primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
  1900.              primop0);
  1901.       primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
  1902.              primop1);
  1903.     }
  1904.   else
  1905.     {
  1906.       /* Here we must do the comparison on the nominal type
  1907.      using the args exactly as we received them.  */
  1908.       type = *restype_ptr;
  1909.       primop0 = op0;
  1910.       primop1 = op1;
  1911.     }
  1912.  
  1913.   *op0_ptr = convert (type, primop0);
  1914.   *op1_ptr = convert (type, primop1);
  1915.  
  1916.   *restype_ptr = integer_type_node;
  1917.  
  1918.   return 0;
  1919. }
  1920.  
  1921. /* Construct and perhaps optimize a tree representation
  1922.    for a unary operation.  CODE, a tree_code, specifies the operation
  1923.    and XARG is the operand.  NOCONVERT nonzero suppresses
  1924.    the default promotions (such as from short to int).  */
  1925.  
  1926. tree
  1927. build_unary_op (code, xarg, noconvert)
  1928.      enum tree_code code;
  1929.      tree xarg;
  1930.      int noconvert;
  1931. {
  1932.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  1933.   register tree arg = xarg;
  1934.   register tree argtype = 0;
  1935.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  1936.   char *errstring = NULL;
  1937.   tree val;
  1938.  
  1939.   if (typecode == ERROR_MARK)
  1940.     return error_mark_node;
  1941.   if (typecode == ENUMERAL_TYPE)
  1942.     typecode = INTEGER_TYPE;
  1943.  
  1944.   switch (code)
  1945.     {
  1946.     case CONVERT_EXPR:
  1947.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1948.         errstring = "wrong type argument to unary plus";
  1949.       /* This is used for unary plus, because a CONVERT_EXPR
  1950.      is enough to prevent anybody from looking inside for
  1951.      associativity, but won't generate any code.
  1952.      Any argument is ok.  */
  1953.       break;
  1954.  
  1955.     case NEGATE_EXPR:
  1956.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1957.         errstring = "wrong type argument to unary minus";
  1958.       else if (!noconvert)
  1959.     arg = default_conversion (arg);
  1960.       break;
  1961.  
  1962.     case BIT_NOT_EXPR:
  1963.       if (typecode != INTEGER_TYPE)
  1964.         errstring = "wrong type argument to bit-complement";
  1965.       else if (!noconvert)
  1966.     arg = default_conversion (arg);
  1967.       break;
  1968.  
  1969.     case ABS_EXPR:
  1970.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1971.         errstring = "wrong type argument to abs";
  1972.       else if (!noconvert)
  1973.     arg = default_conversion (arg);
  1974.       break;
  1975.  
  1976.     case TRUTH_NOT_EXPR:
  1977.       if (typecode != INTEGER_TYPE
  1978.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  1979.       /* This will convert to a pointer.  */
  1980.       && typecode != ARRAY_TYPE)
  1981.     {
  1982.       errstring = "wrong type argument to unary exclamation mark";
  1983.       break;
  1984.     }
  1985.       arg = truthvalue_conversion (arg);
  1986.       if (TREE_CODE (arg) == NE_EXPR)
  1987.     {
  1988.       TREE_SET_CODE (arg, EQ_EXPR);
  1989.       return arg;
  1990.     }
  1991.       if (TREE_CODE (arg) == EQ_EXPR)
  1992.     {
  1993.       TREE_SET_CODE (arg, NE_EXPR);
  1994.       return arg;
  1995.     }
  1996.       if (TREE_CODE (arg) == TRUTH_NOT_EXPR)
  1997.     {
  1998.       return TREE_OPERAND (arg, 0);
  1999.     }
  2000.       break;
  2001.  
  2002.     case NOP_EXPR:
  2003.       break;
  2004.       
  2005.     case PREINCREMENT_EXPR:
  2006.     case POSTINCREMENT_EXPR:
  2007.     case PREDECREMENT_EXPR:
  2008.     case POSTDECREMENT_EXPR:
  2009.       /* Handle complex lvalues (when permitted)
  2010.      by reduction to simpler cases.  */
  2011.  
  2012.       val = unary_complex_lvalue (code, arg);
  2013.       if (val != 0)
  2014.     return val;
  2015.  
  2016.       /* Report invalid types.  */
  2017.  
  2018.       if (typecode != POINTER_TYPE
  2019.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2020.     {
  2021.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2022.         errstring ="wrong type argument to increment";
  2023.       else
  2024.         errstring ="wrong type argument to decrement";
  2025.       break;
  2026.     }
  2027.  
  2028.       /* Report something read-only.  */
  2029.  
  2030.       if (TREE_READONLY (arg))
  2031.     readonly_warning (arg, 
  2032.               ((code == PREINCREMENT_EXPR
  2033.                 || code == POSTINCREMENT_EXPR)
  2034.                ? "increment" : "decrement"));
  2035.  
  2036.       {
  2037.     register tree inc;
  2038.     tree result_type = TREE_TYPE (arg);
  2039.  
  2040.     arg = get_unwidened (arg, 0);
  2041.     argtype = TREE_TYPE (arg);
  2042.  
  2043.     /* Compute the increment.  */
  2044.  
  2045.     if (typecode == POINTER_TYPE)
  2046.       {
  2047.         if (pedantic && (TREE_CODE (argtype) == FUNCTION_TYPE
  2048.                  || TREE_CODE (argtype) == VOID_TYPE))
  2049.           warning ("wrong type argument to %s",
  2050.                ((code == PREINCREMENT_EXPR
  2051.              || code == POSTINCREMENT_EXPR)
  2052.             ? "increment" : "decrement"));
  2053.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  2054.       }
  2055.     else
  2056.       inc = integer_one_node;
  2057.  
  2058.     inc = convert (argtype, inc);
  2059.  
  2060.     /* Handle incrementing a cast-expression.  */
  2061.  
  2062.     if (!pedantic)
  2063.       switch (TREE_CODE (arg))
  2064.         {
  2065.         case NOP_EXPR:
  2066.         case CONVERT_EXPR:
  2067.         case FLOAT_EXPR:
  2068.         case FIX_TRUNC_EXPR:
  2069.         case FIX_FLOOR_EXPR:
  2070.         case FIX_ROUND_EXPR:
  2071.         case FIX_CEIL_EXPR:
  2072.           {
  2073.         tree incremented, modify, value;
  2074.         arg = stabilize_reference (arg);
  2075.         if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2076.           value = arg;
  2077.         else
  2078.           value = save_expr (arg);
  2079.         incremented = build (((code == PREINCREMENT_EXPR
  2080.                        || code == POSTINCREMENT_EXPR)
  2081.                       ? PLUS_EXPR : MINUS_EXPR),
  2082.                      argtype, value, inc);
  2083.         TREE_VOLATILE (incremented) = 1;
  2084.         modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2085.         return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2086.           }
  2087.         }
  2088.  
  2089.     /* Complain about anything else that is not a true lvalue.  */
  2090.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2091.                     || code == POSTINCREMENT_EXPR)
  2092.                    ? "increment" : "decrement")))
  2093.       return error_mark_node;
  2094.  
  2095.     val = build (code, TREE_TYPE (arg), arg, inc);
  2096.     TREE_VOLATILE (val) = 1;
  2097.     return convert (result_type, val);
  2098.       }
  2099.  
  2100.     case ADDR_EXPR:
  2101.       /* Note that this operation never does default_conversion
  2102.      regardless of NOCONVERT.  */
  2103.  
  2104.       /* Let &* cancel out to simplify resulting code.  */
  2105.       if (TREE_CODE (arg) == INDIRECT_REF)
  2106.     return TREE_OPERAND (arg, 0);
  2107.  
  2108.       /* For &x[y], return x+y */
  2109.       if (TREE_CODE (arg) == ARRAY_REF)
  2110.     {
  2111.       mark_addressable (TREE_OPERAND (arg, 0));
  2112.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2113.                   TREE_OPERAND (arg, 1));
  2114.     }
  2115.  
  2116.       /* Handle complex lvalues (when permitted)
  2117.      by reduction to simpler cases.  */
  2118.       val = unary_complex_lvalue (code, arg);
  2119.       if (val != 0)
  2120.     return val;
  2121.  
  2122.       /* Address of a cast is just a cast of the address
  2123.      of the operand of the cast.  */
  2124.       switch (TREE_CODE (arg))
  2125.     {
  2126.     case NOP_EXPR:
  2127.     case CONVERT_EXPR:
  2128.     case FLOAT_EXPR:
  2129.     case FIX_TRUNC_EXPR:
  2130.     case FIX_FLOOR_EXPR:
  2131.     case FIX_ROUND_EXPR:
  2132.     case FIX_CEIL_EXPR:
  2133.       if (pedantic)
  2134.         warning ("ANSI C forbids the address of a cast expression");
  2135.       return convert (build_pointer_type (TREE_TYPE (arg)),
  2136.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  2137.                       0));
  2138.     }
  2139.  
  2140.       /* Allow the address of a constructor if all the elements
  2141.      are constant.  */
  2142.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_LITERAL (arg))
  2143.     ;
  2144.       /* Anything not already handled and not a true memory reference
  2145.      is an error.  */
  2146.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  2147.     return error_mark_node;
  2148.  
  2149.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  2150.       argtype = TREE_TYPE (arg);
  2151.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  2152.     argtype = build_type_variant (argtype,
  2153.                       TREE_READONLY (arg),
  2154.                       TREE_THIS_VOLATILE (arg));
  2155.  
  2156.       argtype = build_pointer_type (argtype);
  2157.  
  2158.       mark_addressable (arg);
  2159.  
  2160.       {
  2161.     tree addr;
  2162.  
  2163.     if (TREE_CODE (arg) == COMPONENT_REF)
  2164.       {
  2165.         tree field = TREE_OPERAND (arg, 1);
  2166.  
  2167.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  2168.  
  2169.         if (TREE_PACKED (field))
  2170.           {
  2171.         error ("attempt to take address of bit-field structure member `%s'",
  2172.                IDENTIFIER_POINTER (DECL_NAME (field)));
  2173.         return error_mark_node;
  2174.           }
  2175.  
  2176.         if (DECL_OFFSET (field) != 0)
  2177.           {
  2178.         tree offset = build_int_2 ((DECL_OFFSET (field)
  2179.                         / BITS_PER_UNIT),
  2180.                        0);
  2181.         TREE_TYPE (offset) = argtype;
  2182.         addr = fold (build (PLUS_EXPR, argtype, addr, offset));
  2183.           }
  2184.         else
  2185.           addr = convert (argtype, addr);
  2186.       }
  2187.     else
  2188.       addr = build (code, argtype, arg);
  2189.  
  2190.     /* Address of a static or external variable or
  2191.        function counts as a constant */
  2192.     TREE_LITERAL (addr) = staticp (arg);
  2193.     return addr;
  2194.       }
  2195.     }
  2196.  
  2197.   if (!errstring)
  2198.     {
  2199.       if (argtype == 0)
  2200.     argtype = TREE_TYPE (arg);
  2201.       return fold (build (code, argtype, arg));
  2202.     }
  2203.  
  2204.   error (errstring);
  2205.   return error_mark_node;
  2206. }
  2207.  
  2208. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  2209.    convert ARG with the same conversions in the same order
  2210.    and return the result.  */
  2211.  
  2212. static tree
  2213. convert_sequence (conversions, arg)
  2214.      tree conversions;
  2215.      tree arg;
  2216. {
  2217.   switch (TREE_CODE (conversions))
  2218.     {
  2219.     case NOP_EXPR:
  2220.     case CONVERT_EXPR:
  2221.     case FLOAT_EXPR:
  2222.     case FIX_TRUNC_EXPR:
  2223.     case FIX_FLOOR_EXPR:
  2224.     case FIX_ROUND_EXPR:
  2225.     case FIX_CEIL_EXPR:
  2226.       return convert (TREE_TYPE (conversions),
  2227.               convert_sequence (TREE_OPERAND (conversions, 0),
  2228.                     arg));
  2229.  
  2230.     default:
  2231.       return arg;
  2232.     }
  2233. }
  2234.  
  2235. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  2236.    for certain kinds of expressions which are not really lvalues
  2237.    but which we can accept as lvalues.
  2238.  
  2239.    If ARG is not a kind of expression we can handle, return zero.  */
  2240.    
  2241. static tree
  2242. unary_complex_lvalue (code, arg)
  2243.      enum tree_code code;
  2244.      tree arg;
  2245. {
  2246.   if (pedantic)
  2247.     return 0;
  2248.  
  2249.   /* Handle (a, b) used as an "lvalue".  */
  2250.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  2251.     {
  2252.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  2253.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  2254.             TREE_OPERAND (arg, 0), real_result);
  2255.     }
  2256.  
  2257.   /* Handle (a ? b : c) used as an "lvalue".  */
  2258.   if (TREE_CODE (arg) == COND_EXPR)
  2259.     return (build_conditional_expr
  2260.         (TREE_OPERAND (arg, 0),
  2261.          build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  2262.          build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  2263.  
  2264.   return 0;
  2265. }
  2266.  
  2267. /* Warn about storing in something that is `const'.  */
  2268.  
  2269. void
  2270. readonly_warning (arg, string)
  2271.      tree arg;
  2272.      char *string;
  2273. {
  2274.   char buf[80];
  2275.   strcpy (buf, string);
  2276.  
  2277.   if (TREE_CODE (arg) == COMPONENT_REF)
  2278.     {
  2279.       if (TREE_READONLY (TREE_OPERAND (arg, 0)))
  2280.     readonly_warning (TREE_OPERAND (arg, 0), string);
  2281.       else
  2282.     {
  2283.       strcat (buf, " of read-only member `%s'");
  2284.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  2285.     }
  2286.     }
  2287.   else if (TREE_CODE (arg) == VAR_DECL)
  2288.     {
  2289.       strcat (buf, " of read-only variable `%s'");
  2290.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  2291.     }
  2292.   else
  2293.     {
  2294.       warning ("%s of read-only location", buf);
  2295.     }
  2296. }
  2297.  
  2298. /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
  2299.    or validate its data type for an `if' or `while' statement or ?..: exp.
  2300.  
  2301.    This preparation consists of taking the ordinary
  2302.    representation of an expression expr and producing a valid tree
  2303.    boolean expression describing whether expr is nonzero.  We could
  2304.    simply always do build_binary_op (NE_EXPR, expr, integer_zero_node),
  2305.    but we optimize comparisons, &&, ||, and !  */
  2306.  
  2307. tree
  2308. truthvalue_conversion (expr)
  2309.      tree expr;
  2310. {
  2311.   register enum tree_code form = TREE_CODE (expr);
  2312.  
  2313.   if (form == EQ_EXPR && integer_zerop (TREE_OPERAND (expr, 1)))
  2314.     return build_unary_op (TRUTH_NOT_EXPR,
  2315.                truthvalue_conversion (TREE_OPERAND (expr, 0)), 0);
  2316.  
  2317.   /* A one-bit unsigned bit-field is already acceptable.  */
  2318.   if (form == COMPONENT_REF
  2319.       && 1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
  2320.       && 1 == DECL_SIZE_UNIT (TREE_OPERAND (expr, 1))
  2321.       && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
  2322.     return expr;
  2323.  
  2324.   if (form == TRUTH_ANDIF_EXPR || form == TRUTH_ORIF_EXPR
  2325.       || form == TRUTH_AND_EXPR || form == TRUTH_OR_EXPR
  2326.       || form == TRUTH_NOT_EXPR
  2327.       || form == EQ_EXPR || form == NE_EXPR
  2328.       || form == LE_EXPR || form == GE_EXPR
  2329.       || form == LT_EXPR || form == GT_EXPR
  2330.       || form == ERROR_MARK)
  2331.     return expr;
  2332.  
  2333.   /* Unary minus has no effect on whether its argument is nonzero.  */
  2334.   if (form == NEGATE_EXPR)
  2335.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2336.  
  2337.   /* Sign-extension and zero-extension has no effect.  */
  2338.   if (form == NOP_EXPR
  2339.       && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
  2340.       && (TYPE_PRECISION (TREE_TYPE (expr))
  2341.       > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))))
  2342.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2343.  
  2344.   return build_binary_op (NE_EXPR, expr, integer_zero_node);
  2345. }
  2346.  
  2347. /* Mark EXP saying that we need to be able to take the
  2348.    address of it; it should not be allocated in a register.  */
  2349.  
  2350. static void
  2351. mark_addressable (exp)
  2352.      tree exp;
  2353. {
  2354.   register tree x = exp;
  2355.   while (1)
  2356.     switch (TREE_CODE (x))
  2357.       {
  2358.       case ADDR_EXPR:
  2359.       case COMPONENT_REF:
  2360.       case ARRAY_REF:
  2361.     x = TREE_OPERAND (x, 0);
  2362.     break;
  2363.  
  2364.       case VAR_DECL:
  2365.       case CONST_DECL:
  2366.       case PARM_DECL:
  2367.       case RESULT_DECL:
  2368.     if (TREE_REGDECL (x) && !TREE_ADDRESSABLE (x))
  2369.       warning ("address requested for `%s', which is declared `register'",
  2370.            IDENTIFIER_POINTER (DECL_NAME (x)));
  2371.     put_var_into_stack (x);
  2372.  
  2373.     /* drops in */
  2374.       case FUNCTION_DECL:
  2375.     TREE_ADDRESSABLE (x) = 1;
  2376.     TREE_ADDRESSABLE (DECL_NAME (x)) = 1;
  2377.  
  2378.       default:
  2379.     return;
  2380.     }
  2381. }
  2382.  
  2383. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  2384.  
  2385. tree
  2386. build_conditional_expr (ifexp, op1, op2)
  2387.      tree ifexp, op1, op2;
  2388. {
  2389.   register tree type1;
  2390.   register tree type2;
  2391.   register enum tree_code code1;
  2392.   register enum tree_code code2;
  2393.   register tree result_type = NULL;
  2394.  
  2395.   /* If second operand is omitted, it is the same as the first one;
  2396.      make sure it is calculated only once.  */
  2397.   if (op1 == 0)
  2398.     {
  2399.       if (pedantic)
  2400.     warning ("ANSI C forbids omitting the middle term of a ?: expression");
  2401.       ifexp = op1 = save_expr (ifexp);
  2402.     }
  2403.  
  2404.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  2405.  
  2406.   if (TREE_CODE (ifexp) == ERROR_MARK
  2407.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  2408.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  2409.     return error_mark_node;
  2410.  
  2411.   /* Don't promote the operands separately if they promote
  2412.      the same way.  Return the unpromoted type and let the combined
  2413.      value get promoted if necessary.  */
  2414.  
  2415.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  2416.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  2417.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  2418.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  2419.     {
  2420.       if (TREE_LITERAL (ifexp))
  2421.     return (integer_zerop (ifexp) ? op2 : op1);
  2422.  
  2423.       return build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2);
  2424.     }
  2425.  
  2426.   /* They don't match; promote them both and then try to reconcile them.  */
  2427.  
  2428.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  2429.     op1 = default_conversion (op1);
  2430.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  2431.     op2 = default_conversion (op2);
  2432.  
  2433.   type1 = TREE_TYPE (op1);
  2434.   code1 = TREE_CODE (type1);
  2435.   type2 = TREE_TYPE (op2);
  2436.   code2 = TREE_CODE (type2);
  2437.       
  2438.   /* Quickly detect the usual case where op1 and op2 have the same type
  2439.      after promotion.  */
  2440.   if (type1 == type2)
  2441.     result_type = type1;
  2442.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  2443.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  2444.     {
  2445.       result_type = commontype (type1, type2);
  2446.     }
  2447.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  2448.     {
  2449.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  2450.     warning ("ANSI C forbids conditional expr with only one void side");
  2451.       result_type = void_type_node;
  2452.     }
  2453.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  2454.     {
  2455.       if (comp_target_types (type1, type2))
  2456.     result_type = commontype (type1, type2);
  2457.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  2458.     {
  2459.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2460.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2461.       result_type = qualify_type (type1, type2);
  2462.     }
  2463.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  2464.     {
  2465.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2466.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2467.       result_type = qualify_type (type2, type1);
  2468.     }
  2469.       else
  2470.     {
  2471.       warning ("pointer type mismatch in conditional expression");
  2472.       result_type = build_pointer_type (void_type_node);
  2473.     }
  2474.     }
  2475.   else if (code1 == POINTER_TYPE && TREE_CODE (op2) == INTEGER_CST)
  2476.     {
  2477.       if (!integer_zerop (op2))
  2478.     warning ("pointer/integer type mismatch in conditional expression");
  2479.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2480.     warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2481.       result_type = type1;
  2482.       op2 = null_pointer_node;
  2483.     }
  2484.   else if (code2 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST)
  2485.     {
  2486.       if (!integer_zerop (op1))
  2487.     warning ("pointer/integer type mismatch in conditional expression");
  2488.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2489.     warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2490.       result_type = type2;
  2491.       op1 = null_pointer_node;
  2492.     }
  2493.  
  2494.   if (!result_type)
  2495.     {
  2496.       if (flag_cond_mismatch)
  2497.     result_type = void_type_node;
  2498.       else
  2499.     {
  2500.       error ("type mismatch in conditional expression");
  2501.       return error_mark_node;
  2502.     }
  2503.     }
  2504.  
  2505.   if (result_type != TREE_TYPE (op1))
  2506.     op1 = convert (result_type, op1);
  2507.   if (result_type != TREE_TYPE (op2))
  2508.     op2 = convert (result_type, op2);
  2509.     
  2510. #if 0
  2511.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  2512.     {
  2513.       result_type = TREE_TYPE (op1);
  2514.       if (TREE_LITERAL (ifexp))
  2515.     return (integer_zerop (ifexp) ? op2 : op1);
  2516.  
  2517.       if (TYPE_MODE (result_type) == BLKmode)
  2518.     {
  2519.       register tree tempvar
  2520.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  2521.       register tree xop1 = build_modify_expr (tempvar, op1);
  2522.       register tree xop2 = build_modify_expr (tempvar, op2);
  2523.       register tree result = build (COND_EXPR, result_type,
  2524.                     ifexp, xop1, xop2);
  2525.  
  2526.       layout_decl (tempvar);
  2527.       /* No way to handle variable-sized objects here.
  2528.          I fear that the entire handling of BLKmode conditional exprs
  2529.          needs to be redone.  */
  2530.       if (! TREE_LITERAL (DECL_SIZE (tempvar)))
  2531.         abort ();
  2532.       DECL_RTL (tempvar)
  2533.         = assign_stack_local (DECL_MODE (tempvar),
  2534.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  2535.                    * DECL_SIZE_UNIT (tempvar)
  2536.                    + BITS_PER_UNIT - 1)
  2537.                   / BITS_PER_UNIT);
  2538.  
  2539.       TREE_VOLATILE (result)
  2540.         = TREE_VOLATILE (ifexp) | TREE_VOLATILE (op1)
  2541.           | TREE_VOLATILE (op2);
  2542.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  2543.     }
  2544.     }
  2545. #endif /* 0 */
  2546.  
  2547.   if (TREE_LITERAL (ifexp))
  2548.     return (integer_zerop (ifexp) ? op2 : op1);
  2549.  
  2550.   return build (COND_EXPR, result_type, ifexp, op1, op2);
  2551. }
  2552.  
  2553. /* Given a list of expressions, return a compound expression
  2554.    that performs them all and returns the value of the last of them.  */
  2555.  
  2556. tree
  2557. build_compound_expr (list)
  2558.      tree list;
  2559. {
  2560.   register tree rest;
  2561.  
  2562.   if (TREE_CHAIN (list) == 0)
  2563.     return TREE_VALUE (list);
  2564.  
  2565.   rest = build_compound_expr (TREE_CHAIN (list));
  2566.  
  2567.   if (! TREE_VOLATILE (TREE_VALUE (list)))
  2568.     return rest;
  2569.  
  2570.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  2571. }
  2572.  
  2573. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  2574.  
  2575. tree
  2576. build_c_cast (type, expr)
  2577.      register tree type;
  2578.      tree expr;
  2579. {
  2580.   register tree value;
  2581.   
  2582.   if (type == error_mark_node)
  2583.     return error_mark_node;
  2584.  
  2585.   if (type == TREE_TYPE (expr))
  2586.     {
  2587.       if (pedantic)
  2588.     {
  2589.       if (TREE_CODE (type) == RECORD_TYPE
  2590.           || TREE_CODE (type) == UNION_TYPE)
  2591.         warning ("ANSI C forbids casting nonscalar to the same type");
  2592.     }
  2593.       return expr;
  2594.     }
  2595.  
  2596.   value = convert (TYPE_MAIN_VARIANT (type), default_conversion (expr));
  2597.   /* As far as I know, it is not meaningful to cast something
  2598.      to a const or volatile type, because those are meaningful
  2599.      only for lvalues.
  2600.      But if it is meaningful, we must somehow return something
  2601.      whose TREE_READONLY or TREE_VOLATILE is set.
  2602.      That is not trivial because it is possible that VALUE == EXPR
  2603.      or is a shared constant.  */
  2604.   return value;
  2605. }
  2606.  
  2607. /* Build an assignment expression of lvalue LHS from value RHS.
  2608.    MODIFYCODE is the code for a binary operator that we use
  2609.    to combine the old value of LHS with RHS to get the new value.
  2610.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  2611.  
  2612. tree
  2613. build_modify_expr (lhs, modifycode, rhs)
  2614.      tree lhs, rhs;
  2615.      enum tree_code modifycode;
  2616. {
  2617.   register tree result;
  2618.   tree newrhs = rhs;
  2619.   tree lhstype = TREE_TYPE (lhs);
  2620.   tree olhstype = lhstype;
  2621.  
  2622.   /* Types that aren't fully specified cannot be used in assignments.  */
  2623.   lhs = require_complete_type (lhs);
  2624.  
  2625.   /* Avoid duplicate error messages from operands that had errors.  */
  2626.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  2627.     return error_mark_node;
  2628.  
  2629.   /* Handle control structure constructs used as "lvalues".  */
  2630.  
  2631.   if (!pedantic)
  2632.     switch (TREE_CODE (lhs))
  2633.       {
  2634.     /* Handle (a, b) used as an "lvalue".  */
  2635.       case COMPOUND_EXPR:
  2636.     return build (COMPOUND_EXPR, lhstype,
  2637.               TREE_OPERAND (lhs, 0),
  2638.               build_modify_expr (TREE_OPERAND (lhs, 1),
  2639.                      modifycode, rhs));
  2640.  
  2641.     /* Handle (a ? b : c) used as an "lvalue".  */
  2642.       case COND_EXPR:
  2643.     rhs = save_expr (rhs);
  2644.     return (build_conditional_expr
  2645.         (TREE_OPERAND (lhs, 0),
  2646.          build_modify_expr (TREE_OPERAND (lhs, 1), modifycode, rhs),
  2647.          build_modify_expr (TREE_OPERAND (lhs, 2), modifycode, rhs)));
  2648.       }
  2649.  
  2650.   /* If a binary op has been requested, combine the old LHS value with the RHS
  2651.      producing the value we should actually store into the LHS.  */
  2652.  
  2653.   if (modifycode != NOP_EXPR)
  2654.     {
  2655.       lhs = stabilize_reference (lhs);
  2656.       newrhs = build_binary_op (modifycode, lhs, rhs);
  2657.     }
  2658.  
  2659.   /* Handle a cast used as an "lvalue".
  2660.      We have already performed any binary operator using the value as cast.
  2661.      Now convert the result to the true type of the lhs and store there;
  2662.      then cast the result back to the specified type to be the value
  2663.      of the assignment.  */
  2664.  
  2665.   if (!pedantic)
  2666.     switch (TREE_CODE (lhs))
  2667.       {
  2668.       case NOP_EXPR:
  2669.       case CONVERT_EXPR:
  2670.       case FLOAT_EXPR:
  2671.       case FIX_TRUNC_EXPR:
  2672.       case FIX_FLOOR_EXPR:
  2673.       case FIX_ROUND_EXPR:
  2674.       case FIX_CEIL_EXPR:
  2675.     if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  2676.         || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  2677.       newrhs = default_conversion (newrhs);
  2678.     {
  2679.       tree inner_lhs = TREE_OPERAND (lhs, 0);
  2680.       tree result = build_modify_expr (inner_lhs, NOP_EXPR,
  2681.                        convert (TREE_TYPE (inner_lhs),
  2682.                             newrhs));
  2683.       return convert (TREE_TYPE (lhs), result);
  2684.     }
  2685.       }
  2686.  
  2687.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  2688.      Reject anything strange now.  */
  2689.  
  2690.   if (!lvalue_or_else (lhs, "assignment"))
  2691.     return error_mark_node;
  2692.  
  2693.   /* Warn about storing in something that is `const'.  */
  2694.  
  2695.   if (TREE_READONLY (lhs)
  2696.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  2697.        || TREE_CODE (lhstype) == UNION_TYPE)
  2698.       && C_TYPE_FIELDS_READONLY (lhstype)))
  2699.     readonly_warning (lhs, "assignment");
  2700.  
  2701.   /* If storing into a structure or union member,
  2702.      it has probably been given type `int'.
  2703.      Compute the type that would go with
  2704.      the actual amount of storage the member occupies.  */
  2705.  
  2706.   if (TREE_CODE (lhs) == COMPONENT_REF
  2707.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  2708.       || TREE_CODE (lhstype) == REAL_TYPE
  2709.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  2710.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  2711.  
  2712.   /* If storing in a field that is in actuality a short or narrower than one,
  2713.      we must store in the field in its actual type.  */
  2714.  
  2715.   if (lhstype != TREE_TYPE (lhs))
  2716.     {
  2717.       lhs = copy_node (lhs);
  2718.       TREE_TYPE (lhs) = lhstype;
  2719.     }
  2720.  
  2721.   /* Convert new value to destination type.  */
  2722.  
  2723.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment");
  2724.  
  2725.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  2726.   TREE_VOLATILE (result) = 1;
  2727.  
  2728.   /* If we got the LHS in a different type for storing in,
  2729.      convert the result back to the nominal type of LHS
  2730.      so that the value we return always has the same type
  2731.      as the LHS argument.  */
  2732.  
  2733.   if (olhstype == TREE_TYPE (result))
  2734.     return result;
  2735.   return convert_for_assignment (olhstype, result, "assignment");
  2736. }
  2737.  
  2738. /* Return 0 if EXP is not a valid lvalue in this language
  2739.    even though `lvalue_or_else' would accept it.  */
  2740.  
  2741. int
  2742. language_lvalue_valid (exp)
  2743.      tree exp;
  2744. {
  2745.   return 1;
  2746. }
  2747.  
  2748. /* Convert value RHS to type TYPE as preparation for an assignment
  2749.    to an lvalue of type TYPE.
  2750.    The real work of conversion is done by `convert'.
  2751.    The purpose of this function is to generate error messages
  2752.    for assignments that are not allowed in C.
  2753.    ERRTYPE is a string to use in error messages:
  2754.    "assignment", "return", etc.  */
  2755.  
  2756. static tree
  2757. convert_for_assignment (type, rhs, errtype)
  2758.      tree type, rhs;
  2759.      char *errtype;
  2760. {
  2761.   register enum tree_code codel = TREE_CODE (type);
  2762.   register tree rhstype = datatype (rhs);
  2763.   register enum tree_code coder = TREE_CODE (rhstype);
  2764.  
  2765.   if (coder == ERROR_MARK)
  2766.     return rhs;
  2767.  
  2768.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  2769.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  2770.     rhs = default_conversion (rhs);
  2771.  
  2772.   if (type == rhstype)
  2773.     return rhs;
  2774.  
  2775.   if (coder == VOID_TYPE)
  2776.     {
  2777.       error ("void value not ignored as it ought to be");
  2778.       return error_mark_node;
  2779.     }
  2780.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  2781.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE)
  2782.        &&
  2783.       (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  2784.     {
  2785.       return convert (type, rhs);
  2786.     }
  2787.   /* Conversions among pointers */
  2788.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  2789.     {
  2790.       register tree ttl = TREE_TYPE (type);
  2791.       register tree ttr = TREE_TYPE (rhstype);
  2792.       /* Any non-function converts to a [const][volatile] void *
  2793.      and vice versa; otherwise, targets must be the same.
  2794.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  2795.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  2796.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  2797.       || comp_target_types (type, rhstype))
  2798.     {
  2799.       if (pedantic
  2800.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  2801.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  2802.           ||
  2803.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  2804.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  2805.         warning ("%s between incompatible pointer types", errtype);
  2806.       else
  2807.         {
  2808.           if (! TREE_READONLY (ttl) && TREE_READONLY (ttr))
  2809.         warning ("%s of non-const * pointer from const *", errtype);
  2810.           if (! TREE_VOLATILE (ttl) && TREE_VOLATILE (ttr))
  2811.         warning ("%s of non-volatile * pointer from volatile *", errtype);
  2812.         }
  2813.     }
  2814.       else
  2815.     warning ("%s between incompatible pointer types", errtype);
  2816.       return convert (type, rhs);
  2817.     }
  2818.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  2819.     {
  2820.       if (! integer_zerop (rhs))
  2821.     {
  2822.       warning ("%s of pointer from integer lacks a cast", errtype);
  2823.       return convert (type, rhs);
  2824.     }
  2825.       return null_pointer_node;
  2826.     }
  2827.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  2828.     {
  2829.       warning ("%s of integer from pointer lacks a cast", errtype);
  2830.       return convert (type, rhs);
  2831.     }
  2832.  
  2833.   error ("incompatible types in %s", errtype);
  2834.   return error_mark_node;
  2835. }
  2836.  
  2837. /* Return nonzero if VALUE is a valid constant-valued expression
  2838.    for use in initializing a static variable; one that can be an
  2839.    element of a "constant" initializer.
  2840.  
  2841.    Return 1 if the value is absolute; return 2 if it is relocatable.
  2842.    We assume that VALUE has been folded as much as possible;
  2843.    therefore, we do not need to check for such things as
  2844.    arithmetic-combinations of integers.  */
  2845.  
  2846. static int
  2847. initializer_constant_valid_p (value)
  2848.      tree value;
  2849. {
  2850.   switch (TREE_CODE (value))
  2851.     {
  2852.     case CONSTRUCTOR:
  2853.       return TREE_STATIC (value);
  2854.  
  2855.     case INTEGER_CST:
  2856.     case REAL_CST:
  2857.     case STRING_CST:
  2858.       return 1;
  2859.  
  2860.     case ADDR_EXPR:
  2861.       return 2;
  2862.  
  2863.     case CONVERT_EXPR:
  2864.       /* Allow (int) &foo.  */
  2865.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  2866.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  2867.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2868.       return 0;
  2869.     
  2870.     case NOP_EXPR:
  2871.       return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2872.  
  2873.     case PLUS_EXPR:
  2874.       {
  2875.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2876.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  2877.     if (valid0 == 1 && valid1 == 2)
  2878.       return 2;
  2879.     if (valid0 == 2 && valid1 == 1)
  2880.       return 2;
  2881.     return 0;
  2882.       }
  2883.  
  2884.     case MINUS_EXPR:
  2885.       {
  2886.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2887.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  2888.     if (valid0 == 2 && valid1 == 1)
  2889.       return 2;
  2890.     return 0;
  2891.       }
  2892.     }
  2893.  
  2894.   return 0;
  2895. }
  2896.  
  2897. /* Perform appropriate conversions on the initial value of a variable,
  2898.    store it in the declaration DECL,
  2899.    and print any error messages that are appropriate.
  2900.    If the init is invalid, store an ERROR_MARK.  */
  2901.  
  2902. void
  2903. store_init_value (decl, init)
  2904.      tree decl, init;
  2905. {
  2906.   register tree value, type;
  2907.  
  2908.   /* If variable's type was invalidly declared, just ignore it.  */
  2909.  
  2910.   type = TREE_TYPE (decl);
  2911.   if (TREE_CODE (type) == ERROR_MARK)
  2912.     return;
  2913.  
  2914.   /* Digest the specified initializer into an expression.  */
  2915.  
  2916.   value = digest_init (type, init, 0);
  2917.  
  2918.   /* Store the expression if valid; else report error.  */
  2919.  
  2920.   if (value == error_mark_node)
  2921.     ;
  2922.   else if (TREE_STATIC (decl) && ! TREE_LITERAL (value))
  2923.     {
  2924.       error ("initializer for static variable is not constant");
  2925.       value = error_mark_node;
  2926.     }
  2927.   else if (TREE_STATIC (decl)
  2928.        && ! initializer_constant_valid_p (value))
  2929.     {
  2930.       error ("initializer for static variable uses complex arithmetic");
  2931.       value = error_mark_node;
  2932.     }
  2933.   else
  2934.     {
  2935.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  2936.     {
  2937.       if (! TREE_LITERAL (value))
  2938.         warning ("aggregate initializer is not constant");
  2939.       else if (! TREE_STATIC (value))
  2940.         warning ("aggregate initializer uses complex arithmetic");
  2941.     }
  2942.     }
  2943.   DECL_INITIAL (decl) = value;
  2944. }
  2945.  
  2946. /* Digest the parser output INIT as an initializer for type TYPE.
  2947.    Return a C expression of type TYPE to represent the initial value.
  2948.  
  2949.    If TAIL is nonzero, it points to a variable holding a list of elements
  2950.    of which INIT is the first.  We update the list stored there by
  2951.    removing from the head all the elements that we use.
  2952.    Normally this is only one; we use more than one element only if
  2953.    TYPE is an aggregate and INIT is not a constructor.  */
  2954.  
  2955. tree
  2956. digest_init (type, init, tail)
  2957.      tree type, init, *tail;
  2958. {
  2959.   enum tree_code code = TREE_CODE (type);
  2960.   tree element = 0;
  2961.   tree old_tail_contents;
  2962.   /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
  2963.      tree node which has no TREE_TYPE.  */
  2964.   int raw_constructor
  2965.     = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
  2966.  
  2967.   /* By default, assume we use one element from a list.
  2968.      We correct this later in the sole case where it is not true.  */
  2969.  
  2970.   if (tail)
  2971.     {
  2972.       old_tail_contents = *tail;
  2973.       *tail = TREE_CHAIN (*tail);
  2974.     }
  2975.  
  2976.   if (init == error_mark_node)
  2977.     return init;
  2978.  
  2979.   if (init && raw_constructor
  2980.       && CONSTRUCTOR_ELTS (init) != 0
  2981.       && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
  2982.     element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
  2983.  
  2984.   /* Any type can be initialized from an expression of the same type,
  2985.      optionally with braces.  */
  2986.  
  2987.   if (init && (TREE_TYPE (init) == type
  2988.            || (code == ARRAY_TYPE && TREE_TYPE (init)
  2989.            && comptypes (TREE_TYPE (init), type))))
  2990.     {
  2991.       if (pedantic && code == ARRAY_TYPE
  2992.       && TREE_CODE (init) != STRING_CST)
  2993.     warning ("ANSI C forbids initializing array from array expression");
  2994.       return init;
  2995.     }
  2996.  
  2997.   if (element && (TREE_TYPE (element) == type
  2998.           || (code == ARRAY_TYPE && TREE_TYPE (element)
  2999.               && comptypes (TREE_TYPE (element), type))))
  3000.     {
  3001.       if (pedantic && code == ARRAY_TYPE)
  3002.     warning ("ANSI C forbids initializing array from array expression");
  3003.       if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
  3004.     warning ("single-expression nonscalar initializer has braces");
  3005.       return element;
  3006.     }
  3007.  
  3008.   /* Check for initializing a union by its first field.
  3009.      Such an initializer must use braces.  */
  3010.  
  3011.   if (code == UNION_TYPE)
  3012.     {
  3013.       tree result;
  3014.  
  3015.       if (TYPE_FIELDS (type) == 0)
  3016.     {
  3017.       error ("union with no members cannot be initialized");
  3018.       return error_mark_node;
  3019.     }
  3020.       if (! raw_constructor)
  3021.     {
  3022.       error ("type mismatch in initialization");
  3023.       return error_mark_node;
  3024.     }
  3025.       if (element == 0)
  3026.     {
  3027.       error ("union initializer requires one element");
  3028.       return error_mark_node;
  3029.     }
  3030.       /* Take just the first element from within the constructor
  3031.      and it should match the type of the first element.  */
  3032.       element = digest_init (TREE_TYPE (TYPE_FIELDS (type)), element, 0);
  3033.       result = build (CONSTRUCTOR, type, 0, build_tree_list (0, element));
  3034.       TREE_LITERAL (result) = TREE_LITERAL (element);
  3035.       TREE_STATIC (result) = (initializer_constant_valid_p (element)
  3036.                   && TREE_LITERAL (element));
  3037.       return result;
  3038.     }
  3039.  
  3040.   /* Initialization of an array of chars from a string constant
  3041.      optionally enclosed in braces.  */
  3042.  
  3043.   if (code == ARRAY_TYPE
  3044.       && (TREE_TYPE (type) == char_type_node
  3045.       || TREE_TYPE (type) == signed_char_type_node
  3046.       || TREE_TYPE (type) == unsigned_char_type_node
  3047.       || TREE_TYPE (type) == unsigned_type_node
  3048.       || TREE_TYPE (type) == integer_type_node)
  3049.       && ((init && TREE_CODE (init) == STRING_CST)
  3050.       || (element && TREE_CODE (element) == STRING_CST)))
  3051.     {
  3052.       tree string = element ? element : init;
  3053.  
  3054.       if (TREE_TYPE (TREE_TYPE (string)) != char_type_node
  3055.       && TYPE_PRECISION (TREE_TYPE (type)) == BITS_PER_UNIT)
  3056.     {
  3057.       error ("char-array initialized from wide string");
  3058.       return error_mark_node;
  3059.     }
  3060.       if (TREE_TYPE (TREE_TYPE (string)) == char_type_node
  3061.       && TYPE_PRECISION (TREE_TYPE (type)) != BITS_PER_UNIT)
  3062.     {
  3063.       error ("int-array initialized from non-wide string");
  3064.       return error_mark_node;
  3065.     }
  3066.  
  3067.       if (pedantic && TREE_TYPE (type) != char_type_node)
  3068.     warning ("ANSI C forbids string initializer except for `char' elements");
  3069.       TREE_TYPE (string) = type;
  3070.       if (TYPE_DOMAIN (type) != 0
  3071.       && TREE_LITERAL (TYPE_SIZE (type)))
  3072.     {
  3073.       register int size
  3074.         = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
  3075.       size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  3076.       /* Subtract 1 because it's ok to ignore the terminating null char
  3077.          that is counted in the length of the constant.  */
  3078.       if (size < TREE_STRING_LENGTH (string) - 1)
  3079.         warning ("initializer-string for array of chars is too long");
  3080.     }
  3081.       return string;
  3082.     }
  3083.  
  3084.   /* Handle scalar types, including conversions.  */
  3085.  
  3086.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  3087.       || code == ENUMERAL_TYPE)
  3088.     {
  3089.       if (raw_constructor)
  3090.     {
  3091.       if (element == 0)
  3092.         {
  3093.           error ("initializer for scalar variable requires one element");
  3094.           return error_mark_node;
  3095.         }
  3096.       init = element;
  3097.     }
  3098.  
  3099.       return convert_for_assignment (type, default_conversion (init),
  3100.                      "initialization");
  3101.     }
  3102.  
  3103.   /* Come here only for records and arrays.  */
  3104.  
  3105.   if (TYPE_SIZE (type) && ! TREE_LITERAL (TYPE_SIZE (type)))
  3106.     {
  3107.       error ("variable-sized object may not be initialized");
  3108.       return error_mark_node;
  3109.     }
  3110.  
  3111.   if (code == ARRAY_TYPE || code == RECORD_TYPE)
  3112.     {
  3113.       tree result = 0;
  3114.       if (raw_constructor)
  3115.     return process_init_constructor (type, init, 0);
  3116.       else if (tail != 0)
  3117.     {
  3118.       *tail = old_tail_contents;
  3119.       return process_init_constructor (type, 0, tail);
  3120.     }
  3121.       else if (flag_traditional)
  3122.     /* Traditionally one can say `char x[100] = 0;'.  */
  3123.     return process_init_constructor (type,
  3124.                      build_nt (CONSTRUCTOR, 0,
  3125.                            tree_cons (0, init, 0)),
  3126.                      0);
  3127.     }
  3128.  
  3129.   error ("invalid initializer");
  3130.   return error_mark_node;
  3131. }
  3132.  
  3133. /* Process a constructor for a variable of type TYPE.
  3134.    The constructor elements may be specified either with INIT or with ELTS,
  3135.    only one of which should be non-null.
  3136.  
  3137.    If INIT is specified, it is a CONSTRUCTOR node which is specifically
  3138.    and solely for initializing this datum.
  3139.  
  3140.    If ELTS is specified, it is the address of a variable containing
  3141.    a list of expressions.  We take as many elements as we need
  3142.    from the head of the list and update the list.
  3143.  
  3144.    In the resulting constructor, TREE_LITERAL is set if all elts are
  3145.    constant, and TREE_STATIC is set if, in addition, all elts are simple enough
  3146.    constants that the assembler and linker can compute them.  */
  3147.  
  3148. static tree
  3149. process_init_constructor (type, init, elts)
  3150.      tree type, init, *elts;
  3151. {
  3152.   register tree tail;
  3153.   /* List of the elements of the result constructor,
  3154.      in reverse order.  */
  3155.   register tree members = NULL;
  3156.   tree result;
  3157.   int allconstant = 1;
  3158.   int allsimple = 1;
  3159.   int error = 0;
  3160.  
  3161.   /* Make TAIL be the list of elements to use for the initialization,
  3162.      no matter how the data was given to us.  */
  3163.  
  3164.   if (elts)
  3165.     tail = *elts;
  3166.   else
  3167.     tail = CONSTRUCTOR_ELTS (init);
  3168.  
  3169.   /* Gobble as many elements as needed, and make a constructor or initial value
  3170.      for each element of this aggregate.  Chain them together in result.
  3171.      If there are too few, use 0 for each scalar ultimate component.  */
  3172.  
  3173.   if (TREE_CODE (type) == ARRAY_TYPE)
  3174.     {
  3175.       tree domain = TYPE_DOMAIN (type);
  3176.       register long len;
  3177.       register int i;
  3178.  
  3179.       if (domain)
  3180.     len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
  3181.       - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
  3182.         + 1;
  3183.       else
  3184.     len = -1;  /* Take as many as there are */
  3185.  
  3186.       for (i = 0; (len < 0 || i < len) && tail != 0; i++)
  3187.     {
  3188.       register tree next1;
  3189.  
  3190.       if (TREE_VALUE (tail) != 0)
  3191.         {
  3192.           tree tail1 = tail;
  3193.           next1 = digest_init (TREE_TYPE (type),
  3194.                    TREE_VALUE (tail), &tail1);
  3195.           tail = tail1;
  3196.         }
  3197.       else
  3198.         {
  3199.           next1 = error_mark_node;
  3200.           tail = TREE_CHAIN (tail);
  3201.         }
  3202.  
  3203.       if (next1 == error_mark_node)
  3204.         error = 1;
  3205.       else if (!TREE_LITERAL (next1))
  3206.         allconstant = 0;
  3207.       else if (! initializer_constant_valid_p (next1))
  3208.         allsimple = 0;
  3209.       members = tree_cons (NULL_TREE, next1, members);
  3210.     }
  3211.     }
  3212.   if (TREE_CODE (type) == RECORD_TYPE)
  3213.     {
  3214.       register tree field;
  3215.  
  3216.       for (field = TYPE_FIELDS (type); field && tail;
  3217.        field = TREE_CHAIN (field))
  3218.     {
  3219.       register tree next1;
  3220.  
  3221.       if (TREE_VALUE (tail) != 0)
  3222.         {
  3223.           tree tail1 = tail;
  3224.           next1 = digest_init (TREE_TYPE (field),
  3225.                    TREE_VALUE (tail), &tail1);
  3226.           tail = tail1;
  3227.         }
  3228.       else
  3229.         {
  3230.           next1 = error_mark_node;
  3231.           tail = TREE_CHAIN (tail);
  3232.         }
  3233.  
  3234.       if (next1 == error_mark_node)
  3235.         error = 1;
  3236.       else if (!TREE_LITERAL (next1))
  3237.         allconstant = 0;
  3238.       else if (! initializer_constant_valid_p (next1))
  3239.         allsimple = 0;
  3240.       members = tree_cons (field, next1, members);
  3241.     }
  3242.     }
  3243.  
  3244.   /* If arguments were specified as a list, just remove the ones we used.  */
  3245.   if (elts)
  3246.     *elts = tail;
  3247.   /* If arguments were specified as a constructor,
  3248.      complain unless we used all the elements of the constructor.  */
  3249.   else if (tail)
  3250.     warning ("excess elements in aggregate initializer");
  3251.  
  3252.   if (error)
  3253.     return error_mark_node;
  3254.  
  3255.   result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  3256.   if (allconstant) TREE_LITERAL (result) = 1;
  3257.   if (allconstant && allsimple) TREE_STATIC (result) = 1;
  3258.   return result;
  3259. }
  3260.  
  3261. /* Expand an ASM statement with operands, handling output operands
  3262.    that are not variables or INDIRECT_REFS by transforming such
  3263.    cases into cases that expand_asm_operands can handle.
  3264.  
  3265.    Arguments are same as for expand_asm_operands.  */
  3266.  
  3267. void
  3268. c_expand_asm_operands (string, outputs, inputs, vol)
  3269.      tree string, outputs, inputs;
  3270.      int vol;
  3271. {
  3272.   int noutputs = list_length (outputs);
  3273.   register int i;
  3274.   /* o[I] is the place that output number I should be written.  */
  3275.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  3276.   register tree tail;
  3277.  
  3278.   /* Record the contents of OUTPUTS before it is modifed.  */
  3279.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3280.     o[i] = TREE_VALUE (tail);
  3281.  
  3282.   /* Generate the ASM_OPERANDS insn;
  3283.      store into the TREE_VALUEs of OUTPUTS some trees for
  3284.      where the values were actually stored.  */
  3285.   expand_asm_operands (string, outputs, inputs, vol);
  3286.  
  3287.   /* Copy all the intermediate outputs into the specified outputs.  */
  3288.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3289.     if (o[i] != TREE_VALUE (tail))
  3290.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  3291.            0, VOIDmode, 0);
  3292. }
  3293.  
  3294. /* Expand a C `return' statement.
  3295.    RETVAL is the expression for what to return,
  3296.    or a null pointer for `return;' with no value.  */
  3297.  
  3298. void
  3299. c_expand_return (retval)
  3300.      tree retval;
  3301. {
  3302.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  3303.  
  3304.   if (!retval)
  3305.     {
  3306.       current_function_returns_null = 1;
  3307.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  3308.     warning ("`return' with no value, in function returning non-void");
  3309.       expand_null_return ();
  3310.     }
  3311.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  3312.     {
  3313.       current_function_returns_null = 1;
  3314.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  3315.     warning ("`return' with a value, in function returning void");
  3316.       expand_return (retval);
  3317.     }
  3318.   else
  3319.     {
  3320.       tree t = convert_for_assignment (valtype, retval, "return");
  3321.       tree res = DECL_RESULT (current_function_decl);
  3322.       t = build (MODIFY_EXPR, TREE_TYPE (res),
  3323.          res, convert (TREE_TYPE (res), t));
  3324.       expand_return (t);
  3325.       current_function_returns_value = 1;
  3326.     }
  3327. }
  3328.  
  3329. /* Start a C switch statement, testing expression EXP.
  3330.    Return EXP if it is valid, an error node otherwise.  */
  3331.  
  3332. tree
  3333. c_expand_start_case (exp)
  3334.      tree exp;
  3335. {
  3336.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  3337.   tree type = TREE_TYPE (exp);
  3338.  
  3339.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  3340.     {
  3341.       error ("switch quantity not an integer");
  3342.       exp = error_mark_node;
  3343.     }
  3344.   else
  3345.     {
  3346.       tree index;
  3347.  
  3348.       exp = default_conversion (exp);
  3349.       type = TREE_TYPE (exp);
  3350.       index = get_unwidened (exp, 0);
  3351.       /* We can't strip a conversion from a signed type to an unsigned,
  3352.      because if we did, int_fits_type_p would do the wrong thing
  3353.      when checking case values for being in range,
  3354.      and it's too hard to do the right thing.  */
  3355.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  3356.       == TREE_UNSIGNED (TREE_TYPE (index)))
  3357.     exp = index;
  3358.     }
  3359.  
  3360.   expand_start_case (1, exp, type);
  3361.  
  3362.   return exp;
  3363. }
  3364.