home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / c-typeck.c < prev    next >
C/C++ Source or Header  |  1992-04-24  |  142KB  |  4,693 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file is part of the C front end.
  22.    It contains routines to build C expressions given their operands,
  23.    including computing the types of the result, C-specific error checks,
  24.    and some optimization.
  25.  
  26.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  27.    and to process initializations in declarations (since they work
  28.    like a strange sort of assignment).  */
  29.  
  30. #include "config.h"
  31. #include <stdio.h>
  32. #include "tree.h"
  33. #include "c-tree.h"
  34. #include "flags.h"
  35.  
  36. #define max(X, Y)  ((X) > (Y) ? (X) : (Y))
  37.  
  38. int mark_addressable ();
  39. static tree convert_for_assignment ();
  40. static void warn_for_assignment ();
  41. static int function_types_compatible_p ();
  42. static int self_promoting_args_p ();
  43. int comp_target_types ();
  44. static tree pointer_int_sum ();
  45. static tree pointer_diff ();
  46. static tree convert_sequence ();
  47. static tree unary_complex_lvalue ();
  48. static tree process_init_constructor ();
  49. static tree convert_arguments ();
  50. tree digest_init ();
  51. static void pedantic_lvalue_warning ();
  52. tree truthvalue_conversion ();
  53. void incomplete_type_error ();
  54. void readonly_warning ();
  55.  
  56. /* Do `exp = require_complete_type (exp);' to make sure exp
  57.    does not have an incomplete type.  (That includes void types.)  */
  58.  
  59. tree
  60. require_complete_type (value)
  61.      tree value;
  62. {
  63.   tree type = TREE_TYPE (value);
  64.  
  65.   /* First, detect a valid value with a complete type.  */
  66.   if (TYPE_SIZE (type) != 0
  67.       && type != void_type_node)
  68.     return value;
  69.  
  70.   incomplete_type_error (value, type);
  71.   return error_mark_node;
  72. }
  73.  
  74. /* Print an error message for invalid use of an incomplete type.
  75.    VALUE is the expression that was used (or 0 if that isn't known)
  76.    and TYPE is the type that was invalid.  */
  77.  
  78. void
  79. incomplete_type_error (value, type)
  80.      tree value;
  81.      tree type;
  82. {
  83.   char *errmsg;
  84.  
  85.   /* Avoid duplicate error message.  */
  86.   if (TREE_CODE (type) == ERROR_MARK)
  87.     return;
  88.  
  89.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  90.              || TREE_CODE (value) == PARM_DECL))
  91.     error ("`%s' has an incomplete type",
  92.        IDENTIFIER_POINTER (DECL_NAME (value)));
  93.   else
  94.     {
  95.     retry:
  96.       /* We must print an error message.  Be clever about what it says.  */
  97.  
  98.       switch (TREE_CODE (type))
  99.     {
  100.     case RECORD_TYPE:
  101.       errmsg = "invalid use of undefined type `struct %s'";
  102.       break;
  103.  
  104.     case UNION_TYPE:
  105.       errmsg = "invalid use of undefined type `union %s'";
  106.       break;
  107.  
  108.     case ENUMERAL_TYPE:
  109.       errmsg = "invalid use of undefined type `enum %s'";
  110.       break;
  111.  
  112.     case VOID_TYPE:
  113.       error ("invalid use of void expression");
  114.       return;
  115.  
  116.     case ARRAY_TYPE:
  117.       if (TYPE_DOMAIN (type))
  118.         {
  119.           type = TREE_TYPE (type);
  120.           goto retry;
  121.         }
  122.       error ("invalid use of array with unspecified bounds");
  123.       return;
  124.  
  125.     default:
  126.       abort ();
  127.     }
  128.  
  129.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  130.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  131.       else
  132.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  133.     error ("invalid use of incomplete typedef `%s'",
  134.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  135.     }
  136. }
  137.  
  138. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  139.    as well as those of TYPE.  */
  140.  
  141. static tree
  142. qualify_type (type, like)
  143.      tree type, like;
  144. {
  145.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  146.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  147.   return c_build_type_variant (type, constflag, volflag);
  148. }
  149.  
  150. /* Return the common type of two types.
  151.    We assume that comptypes has already been done and returned 1;
  152.    if that isn't so, this may crash.
  153.  
  154.    This is the type for the result of most arithmetic operations
  155.    if the operands have the given two types.
  156.  
  157.    We do not deal with enumeral types here because they have already been
  158.    converted to integer types.  */
  159.  
  160. tree
  161. common_type (t1, t2)
  162.      tree t1, t2;
  163. {
  164.   register enum tree_code code1;
  165.   register enum tree_code code2;
  166.  
  167.   /* Save time if the two types are the same.  */
  168.  
  169.   if (t1 == t2) return t1;
  170.  
  171.   /* If one type is nonsense, use the other.  */
  172.   if (t1 == error_mark_node)
  173.     return t2;
  174.   if (t2 == error_mark_node)
  175.     return t1;
  176.  
  177.   /* Treat an enum type as the unsigned integer type of the same width.  */
  178.  
  179.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  180.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  181.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  182.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  183.  
  184.   code1 = TREE_CODE (t1);
  185.   code2 = TREE_CODE (t2);
  186.  
  187.   switch (code1)
  188.     {
  189.     case INTEGER_TYPE:
  190.     case REAL_TYPE:
  191.       /* If only one is real, use it as the result.  */
  192.  
  193.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  194.     return t1;
  195.  
  196.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  197.     return t2;
  198.  
  199.       /* Both real or both integers; use the one with greater precision.  */
  200.  
  201.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  202.     return t1;
  203.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  204.     return t2;
  205.  
  206.       /* Same precision.  Prefer longs to ints even when same size.  */
  207.  
  208.       if (t1 == long_unsigned_type_node
  209.       || t2 == long_unsigned_type_node)
  210.     return long_unsigned_type_node;
  211.  
  212.       if (t1 == long_integer_type_node
  213.       || t2 == long_integer_type_node)
  214.     {
  215.       /* But preserve unsignedness from the other type,
  216.          since long cannot hold all the values of an unsigned int.  */
  217.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  218.         return long_unsigned_type_node;
  219.       return long_integer_type_node;
  220.     }
  221.  
  222.       /* Otherwise prefer the unsigned one.  */
  223.  
  224.       if (TREE_UNSIGNED (t1))
  225.     return t1;
  226.       else return t2;
  227.  
  228.     case POINTER_TYPE:
  229. #if 0
  230.       /* For two pointers, do this recursively on the target type,
  231.      and combine the qualifiers of the two types' targets.  */
  232.       {
  233.     tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  234.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  235.     int constp
  236.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  237.     int volatilep
  238.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  239.     return build_pointer_type (c_build_type_variant (target, constp, volatilep));
  240.       }
  241. #endif
  242.       return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  243.  
  244.     case ARRAY_TYPE:
  245.       {
  246.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  247.     /* Save space: see if the result is identical to one of the args.  */
  248.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  249.       return t1;
  250.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  251.       return t2;
  252.     /* Merge the element types, and have a size if either arg has one.  */
  253.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  254.       }
  255.  
  256.     case FUNCTION_TYPE:
  257.       /* Function types: prefer the one that specified arg types.
  258.      If both do, merge the arg types.  Also merge the return types.  */
  259.       {
  260.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  261.     tree p1 = TYPE_ARG_TYPES (t1);
  262.     tree p2 = TYPE_ARG_TYPES (t2);
  263.     int len;
  264.     tree newargs, n;
  265.     int i;
  266.  
  267.     /* Save space: see if the result is identical to one of the args.  */
  268.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  269.       return t1;
  270.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  271.       return t2;
  272.  
  273.     /* Simple way if one arg fails to specify argument types.  */
  274.     if (TYPE_ARG_TYPES (t1) == 0)
  275.       return build_function_type (valtype, TYPE_ARG_TYPES (t2));
  276.     if (TYPE_ARG_TYPES (t2) == 0)
  277.       return build_function_type (valtype, TYPE_ARG_TYPES (t1));
  278.  
  279.     /* If both args specify argument types, we must merge the two
  280.        lists, argument by argument.  */
  281.  
  282.     len = list_length (p1);
  283.     newargs = 0;
  284.  
  285.     for (i = 0; i < len; i++)
  286.       newargs = tree_cons (0, 0, newargs);
  287.  
  288.     n = newargs;
  289.  
  290.     for (; p1;
  291.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  292.       {
  293.       /* Given  wait (union {union wait *u; int *i} *)
  294.          and  wait (union wait *),
  295.          prefer  union wait *  as type of parm.  */
  296.         if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
  297.         && TREE_VALUE (p1) != TREE_VALUE (p2))
  298.           {
  299.         tree memb;
  300.         for (memb = TYPE_FIELDS (TREE_VALUE (p1));
  301.              memb; memb = TREE_CHAIN (memb))
  302.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
  303.             {
  304.               TREE_VALUE (n) = TREE_VALUE (p2);
  305.               goto parm_done;
  306.             }
  307.           }
  308.         if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
  309.         && TREE_VALUE (p2) != TREE_VALUE (p1))
  310.           {
  311.         tree memb;
  312.         for (memb = TYPE_FIELDS (TREE_VALUE (p2));
  313.              memb; memb = TREE_CHAIN (memb))
  314.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
  315.             {
  316.               TREE_VALUE (n) = TREE_VALUE (p1);
  317.               goto parm_done;
  318.             }
  319.           }
  320.         TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  321.       parm_done: ;
  322.       }
  323.  
  324.     return build_function_type (valtype, newargs);
  325.       }
  326.  
  327.     default:
  328.       return t1;
  329.     }
  330.  
  331. }
  332.  
  333. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  334.    or various other operations.  */
  335.  
  336. int
  337. comptypes (type1, type2)
  338.      tree type1, type2;
  339. {
  340.   register tree t1 = type1;
  341.   register tree t2 = type2;
  342.  
  343.   /* Suppress errors caused by previously reported errors.  */
  344.  
  345.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  346.     return 1;
  347.  
  348.   /* Treat an enum type as the unsigned integer type of the same width.  */
  349.  
  350.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  351.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  352.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  353.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  354.  
  355.   if (t1 == t2)
  356.     return 1;
  357.  
  358.   /* Different classes of types can't be compatible.  */
  359.  
  360.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  361.  
  362.   /* Qualifiers must match.  */
  363.  
  364.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  365.     return 0;
  366.   if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
  367.     return 0;
  368.  
  369.   /* If generating auxilliary info, allow for two different type nodes which
  370.      have essentially the same definition.  */
  371.  
  372.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  373.     return 1;
  374.  
  375.   switch (TREE_CODE (t1))
  376.     {
  377.     case POINTER_TYPE:
  378.       return (TREE_TYPE (t1) == TREE_TYPE (t2)
  379.           || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  380.  
  381.     case FUNCTION_TYPE:
  382.       return function_types_compatible_p (t1, t2);
  383.  
  384.     case ARRAY_TYPE:
  385.       /* Target types must match incl. qualifiers.  */
  386.       if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  387.         || comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  388.     return 0;
  389.       {
  390.     tree d1 = TYPE_DOMAIN (t1);
  391.     tree d2 = TYPE_DOMAIN (t2);
  392.  
  393.     /* Sizes must match unless one is missing or variable.  */
  394.     if (d1 == 0 || d2 == 0 || d1 == d2
  395.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  396.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  397.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  398.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  399.       return 1;
  400.  
  401.     return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  402.          == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  403.         && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  404.             == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  405.         && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  406.             == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  407.         && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  408.             == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  409.  
  410.     case RECORD_TYPE:
  411.     return maybe_objc_comptypes (t1, t2);
  412.       }
  413.     }
  414.   return 0;
  415. }
  416.  
  417. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  418.    ignoring their qualifiers.  */
  419.  
  420. int
  421. comp_target_types (ttl, ttr)
  422.      tree ttl, ttr;
  423. {
  424.   maybe_objc_comptypes (ttl, ttr);
  425.  
  426. #ifdef NeXT
  427.   if (!pedantic)
  428.     {
  429.       /* Ignore pointer qualifiers recursively.
  430.       This way char ** and const char ** are compatible.  */
  431.       if (TREE_CODE (ttl) == POINTER_TYPE
  432.       && TREE_CODE (ttr) == POINTER_TYPE)
  433.     return comp_target_types (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  434.                   TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  435.       else
  436.     return comptypes (ttl, ttr);
  437.     }
  438. #endif /* NeXT */
  439.   return comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  440.             TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  441. }
  442.  
  443. /* Subroutines of `comptypes'.  */
  444.  
  445. /* Return 1 if two function types F1 and F2 are compatible.
  446.    If either type specifies no argument types,
  447.    the other must specify a fixed number of self-promoting arg types.
  448.    Otherwise, the argument types must match.  */
  449.  
  450. static int
  451. function_types_compatible_p (f1, f2)
  452.      tree f1, f2;
  453. {
  454.   tree args1, args2;
  455.  
  456.   if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
  457.     || comptypes (TREE_TYPE (f1), TREE_TYPE (f2))))
  458.     return 0;
  459.  
  460.   args1 = TYPE_ARG_TYPES (f1);
  461.   args2 = TYPE_ARG_TYPES (f2);
  462.  
  463.   /* An unspecified parmlist matches any specified parmlist
  464.      whose argument types don't need default promotions.  */
  465.  
  466.   if (args1 == 0)
  467.     return self_promoting_args_p (args2);
  468.   if (args2 == 0)
  469.     return self_promoting_args_p (args1);
  470.  
  471.   while (1)
  472.     {
  473.       if (args1 == 0 && args2 == 0)
  474.     return 1;
  475.       /* If one parmlist is shorter than the other,
  476.      they fail to match.  */
  477.       if (args1 == 0 || args2 == 0)
  478.     return 0;
  479.       if (! comptypes (TREE_VALUE (args1), TREE_VALUE (args2)))
  480.     {
  481.       /* Allow  wait (union {union wait *u; int *i} *)
  482.          and  wait (union wait *)  to be compatible.  */
  483.       if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
  484.           && TYPE_NAME (TREE_VALUE (args1)) == 0
  485.           && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
  486.           && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
  487.                      TYPE_SIZE (TREE_VALUE (args2))))
  488.         {
  489.           tree memb;
  490.           for (memb = TYPE_FIELDS (TREE_VALUE (args1));
  491.            memb; memb = TREE_CHAIN (memb))
  492.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
  493.           break;
  494.           if (memb == 0)
  495.         return 0;
  496.         }
  497.       else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
  498.            && TYPE_NAME (TREE_VALUE (args2)) == 0
  499.            && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
  500.            && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
  501.                       TYPE_SIZE (TREE_VALUE (args1))))
  502.         {
  503.           tree memb;
  504.           for (memb = TYPE_FIELDS (TREE_VALUE (args2));
  505.            memb; memb = TREE_CHAIN (memb))
  506.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
  507.           break;
  508.           if (memb == 0)
  509.         return 0;
  510.         }
  511.       else
  512.         return 0;
  513.     }
  514.       args1 = TREE_CHAIN (args1);
  515.       args2 = TREE_CHAIN (args2);
  516.     }
  517. }
  518.  
  519. /* Return 1 if PARMS specifies a fixed number of parameters
  520.    and none of their types is affected by default promotions.  */
  521.  
  522. static int
  523. self_promoting_args_p (parms)
  524.      tree parms;
  525. {
  526.   register tree t;
  527.   for (t = parms; t; t = TREE_CHAIN (t))
  528.     {
  529.       register tree type = TREE_VALUE (t);
  530.  
  531.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  532.     return 0;
  533.  
  534.       if (type == float_type_node)
  535.     return 0;
  536.  
  537.       if (TREE_CODE (type) == INTEGER_TYPE
  538.       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  539.     return 0;
  540.     }
  541.   return 1;
  542. }
  543.  
  544. /* Return an unsigned type the same as TYPE in other respects.  */
  545.  
  546. tree
  547. unsigned_type (type)
  548.      tree type;
  549. {
  550.   if (type == signed_char_type_node || type == char_type_node)
  551.     return unsigned_char_type_node;
  552.   if (type == integer_type_node)
  553.     return unsigned_type_node;
  554.   if (type == short_integer_type_node)
  555.     return short_unsigned_type_node;
  556.   if (type == long_integer_type_node)
  557.     return long_unsigned_type_node;
  558.   if (type == long_long_integer_type_node)
  559.     return long_long_unsigned_type_node;
  560.   return type;
  561. }
  562.  
  563. /* Return a signed type the same as TYPE in other respects.  */
  564.  
  565. tree
  566. signed_type (type)
  567.      tree type;
  568. {
  569.   if (type == unsigned_char_type_node || type == char_type_node)
  570.     return signed_char_type_node;
  571.   if (type == unsigned_type_node)
  572.     return integer_type_node;
  573.   if (type == short_unsigned_type_node)
  574.     return short_integer_type_node;
  575.   if (type == long_unsigned_type_node)
  576.     return long_integer_type_node;
  577.   if (type == long_long_unsigned_type_node)
  578.     return long_long_integer_type_node;
  579.   return type;
  580. }
  581.  
  582. /* Return a type the same as TYPE except unsigned or
  583.    signed according to UNSIGNEDP.  */
  584.  
  585. tree
  586. signed_or_unsigned_type (unsignedp, type)
  587.      int unsignedp;
  588.      tree type;
  589. {
  590.   if (TREE_CODE (type) != INTEGER_TYPE)
  591.     return type;
  592.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  593.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  594.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  595.     return unsignedp ? unsigned_type_node : integer_type_node;
  596.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  597.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  598.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  599.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  600.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  601.     return (unsignedp ? long_long_unsigned_type_node
  602.         : long_long_integer_type_node);
  603.   return type;
  604. }
  605.  
  606. /* Compute the value of the `sizeof' operator.  */
  607.  
  608. tree
  609. c_sizeof (type)
  610.      tree type;
  611. {
  612.   enum tree_code code = TREE_CODE (type);
  613.  
  614.   if (code == FUNCTION_TYPE)
  615.     {
  616.       if (pedantic || warn_pointer_arith)
  617.     pedwarn ("sizeof applied to a function type");
  618.       return size_int (1);
  619.     }
  620.   if (code == VOID_TYPE)
  621.     {
  622.       if (pedantic || warn_pointer_arith)
  623.     pedwarn ("sizeof applied to a void type");
  624.       return size_int (1);
  625.     }
  626.   if (code == ERROR_MARK)
  627.     return size_int (1);
  628.   if (TYPE_SIZE (type) == 0)
  629.     {
  630.       warning ("sizeof applied to an incomplete type");
  631.       return size_int (0);
  632.     }
  633.  
  634.   /* Convert in case a char is more than one unit.  */
  635.   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  636.              size_int (TYPE_PRECISION (char_type_node)));
  637. }
  638.  
  639. tree
  640. c_sizeof_nowarn (type)
  641.      tree type;
  642. {
  643.   enum tree_code code = TREE_CODE (type);
  644.  
  645.   if (code == FUNCTION_TYPE
  646.       || code == VOID_TYPE
  647.       || code == ERROR_MARK)
  648.     return size_int (1);
  649.   if (TYPE_SIZE (type) == 0)
  650.     return size_int (0);
  651.  
  652.   /* Convert in case a char is more than one unit.  */
  653.   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  654.              size_int (TYPE_PRECISION (char_type_node)));
  655. }
  656.  
  657. /* Compute the size to increment a pointer by.  */
  658.  
  659. tree
  660. c_size_in_bytes (type)
  661.      tree type;
  662. {
  663.   enum tree_code code = TREE_CODE (type);
  664.  
  665.   if (code == FUNCTION_TYPE)
  666.     return size_int (1);
  667.   if (code == VOID_TYPE)
  668.     return size_int (1);
  669.   if (code == ERROR_MARK)
  670.     return size_int (1);
  671.   if (TYPE_SIZE (type) == 0)
  672.     {
  673.       error ("arithmetic on pointer to an incomplete type");
  674.       return size_int (1);
  675.     }
  676.  
  677.   /* Convert in case a char is more than one unit.  */
  678.   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  679.              size_int (BITS_PER_UNIT));
  680. }
  681.  
  682. /* Implement the __alignof keyword: Return the minimum required
  683.    alignment of TYPE, measured in bytes.  */
  684.  
  685. tree
  686. c_alignof (type)
  687.      tree type;
  688. {
  689.   enum tree_code code = TREE_CODE (type);
  690.  
  691.   if (code == FUNCTION_TYPE)
  692.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  693.  
  694.   if (code == VOID_TYPE || code == ERROR_MARK)
  695.     return size_int (1);
  696.  
  697.   return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  698. }
  699.  
  700. /* Implement the __alignof keyword: Return the minimum required
  701.    alignment of EXPR, measured in bytes.  For VAR_DECL's and
  702.    FIELD_DECL's return DECL_ALIGN (which can be set from an
  703.    "aligned" __attribute__ specification).  */
  704. tree
  705. c_alignof_expr (expr)
  706.      tree expr;
  707. {
  708.   if (TREE_CODE (expr) == VAR_DECL)
  709.     return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
  710.  
  711.   if (TREE_CODE (expr) == COMPONENT_REF
  712.       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
  713.     {
  714.       error ("`__alignof' applied to a bit-field");
  715.       return size_int (1);
  716.     }
  717.   else if (TREE_CODE (expr) == COMPONENT_REF
  718.       && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
  719.     return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
  720.  
  721.   if (TREE_CODE (expr) == INDIRECT_REF)
  722.     {
  723.       tree t = TREE_OPERAND (expr, 0);
  724.       tree best = t;
  725.       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  726.  
  727.       while (TREE_CODE (t) == NOP_EXPR
  728.           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  729.     {
  730.       int thisalign;
  731.  
  732.       t = TREE_OPERAND (t, 0);
  733.       thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  734.       if (thisalign > bestalign)
  735.         best = t, bestalign = thisalign;
  736.     }
  737.       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
  738.     }
  739.   else
  740.     return c_alignof (TREE_TYPE (expr));
  741. }
  742. /* Return either DECL or its known constant value (if it has one).  */
  743.  
  744. static tree
  745. decl_constant_value (decl)
  746.      tree decl;
  747. {
  748.   if (! TREE_PUBLIC (decl)
  749.       /* Don't change a variable array bound or initial value to a constant
  750.      in a place where a variable is invalid.  */
  751.       && current_function_decl != 0
  752.       && ! pedantic
  753.       && ! TREE_THIS_VOLATILE (decl)
  754.       && DECL_INITIAL (decl) != 0
  755.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  756.       /* This is invalid if initial value is not constant.
  757.      If it has either a function call, a memory reference,
  758.      or a variable, then re-evaluating it could give different results.  */
  759.       && TREE_CONSTANT (DECL_INITIAL (decl))
  760.       /* Check for cases where this is sub-optimal, even though valid.  */
  761.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  762.       && DECL_MODE (decl) != BLKmode)
  763.     return DECL_INITIAL (decl);
  764.   return decl;
  765. }
  766.  
  767. /* Perform default promotions for C data used in expressions.
  768.    Arrays and functions are converted to pointers;
  769.    enumeral types or short or char, to int.
  770.    In addition, manifest constants symbols are replaced by their values.  */
  771.  
  772. tree
  773. default_conversion (exp)
  774.      tree exp;
  775. {
  776.   register tree type = TREE_TYPE (exp);
  777.   register enum tree_code code = TREE_CODE (type);
  778.  
  779.   if (TREE_CODE (exp) == CONST_DECL)
  780.     exp = DECL_INITIAL (exp);
  781.   /* Replace a nonvolatile const static variable with its value.  */
  782.   else if (optimize
  783.        && TREE_CODE (exp) == VAR_DECL
  784.        && TREE_READONLY (exp))
  785.     exp = decl_constant_value (exp);
  786.  
  787.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  788.   if (TREE_CODE (exp) == NON_LVALUE_EXPR)
  789.     exp = TREE_OPERAND (exp, 0);
  790.  
  791.   /* Normally convert enums to int,
  792.      but convert wide enums to something wider.  */
  793.   if (code == ENUMERAL_TYPE)
  794.     {
  795.       type = type_for_size (max (TYPE_PRECISION (type),
  796.                  TYPE_PRECISION (integer_type_node)),
  797.                 (flag_traditional && TREE_UNSIGNED (type)));
  798.       return convert (type, exp);
  799.     }
  800.  
  801.   if (code == INTEGER_TYPE
  802.       && (TYPE_PRECISION (type)
  803.       < TYPE_PRECISION (integer_type_node)))
  804.     {
  805.       /* Traditionally, unsignedness is preserved in default promotions.  */
  806.       if (flag_traditional && TREE_UNSIGNED (type))
  807.     return convert (unsigned_type_node, exp);
  808.       return convert (integer_type_node, exp);
  809.     }
  810.   if (flag_traditional && type == float_type_node)
  811.     return convert (double_type_node, exp);
  812.   if (code == VOID_TYPE)
  813.     {
  814.       error ("void value not ignored as it ought to be");
  815.       return error_mark_node;
  816.     }
  817.   if (code == FUNCTION_TYPE)
  818.     {
  819.       return build_unary_op (ADDR_EXPR, exp, 0);
  820.     }
  821.   if (code == ARRAY_TYPE)
  822.     {
  823.       register tree adr;
  824.       tree restype = TREE_TYPE (type);
  825.       tree ptrtype;
  826.  
  827.       if (TREE_CODE (exp) == INDIRECT_REF)
  828.     return convert (TYPE_POINTER_TO (restype),
  829.             TREE_OPERAND (exp, 0));
  830.  
  831.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  832.     {
  833.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  834.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  835.             TREE_OPERAND (exp, 0), op1);
  836.     }
  837.  
  838.       if (!lvalue_p (exp)
  839.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  840.     {
  841.       error ("invalid use of non-lvalue array");
  842.       return error_mark_node;
  843.     }
  844.  
  845.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
  846.     restype = c_build_type_variant (restype, TYPE_READONLY (type),
  847.                     TYPE_VOLATILE (type));
  848.  
  849.       ptrtype = build_pointer_type (restype);
  850.  
  851.       if (TREE_CODE (exp) == VAR_DECL)
  852.     {
  853.       /* ??? This is not really quite correct
  854.          in that the type of the operand of ADDR_EXPR
  855.          is not the target type of the type of the ADDR_EXPR itself.
  856.          Question is, can this lossage be avoided?  */
  857.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  858.       if (mark_addressable (exp) == 0)
  859.         return error_mark_node;
  860.       TREE_CONSTANT (adr) = staticp (exp);
  861.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  862.       return adr;
  863.     }
  864.       /* This way is better for a COMPONENT_REF since it can
  865.      simplify the offset for a component.  */
  866.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  867.       return convert (ptrtype, adr);
  868.     }
  869.   return exp;
  870. }
  871.  
  872. /* Make an expression to refer to the COMPONENT field of
  873.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  874.  
  875. tree
  876. build_component_ref (datum, component)
  877.      tree datum, component;
  878. {
  879.   register tree type = TREE_TYPE (datum);
  880.   register enum tree_code code = TREE_CODE (type);
  881.   register tree field = NULL;
  882.   register tree ref;
  883.  
  884.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
  885.      unless we are not to support things not strictly ANSI.  */
  886.   switch (TREE_CODE (datum))
  887.     {
  888.     case COMPOUND_EXPR:
  889.       {
  890.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
  891.     pedantic_lvalue_warning (COMPOUND_EXPR);
  892.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  893.               TREE_OPERAND (datum, 0), value);
  894.       }
  895.     case COND_EXPR:
  896.       pedantic_lvalue_warning (COND_EXPR);
  897.       return build_conditional_expr
  898.     (TREE_OPERAND (datum, 0),
  899.      build_component_ref (TREE_OPERAND (datum, 1), component),
  900.      build_component_ref (TREE_OPERAND (datum, 2), component));
  901.     }
  902.  
  903.   /* See if there is a field or component with name COMPONENT.  */
  904.  
  905.   if (code == RECORD_TYPE || code == UNION_TYPE)
  906.     {
  907.       if (TYPE_SIZE (type) == 0)
  908.     {
  909.       incomplete_type_error (0, type);
  910.       return error_mark_node;
  911.     }
  912.  
  913.       /* Look up component name in the structure type definition.  */
  914.  
  915.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  916.     {
  917.       if (DECL_NAME (field) == component)
  918.         break;
  919.     }
  920.  
  921.       if (!field)
  922.     {
  923.       error (code == RECORD_TYPE
  924.          ? "structure has no member named `%s'"
  925.          : "union has no member named `%s'",
  926.          IDENTIFIER_POINTER (component));
  927.       return error_mark_node;
  928.     }
  929.       if (TREE_TYPE (field) == error_mark_node)
  930.     return error_mark_node;
  931.  
  932.       ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  933.  
  934.       if (TREE_READONLY (datum) || TREE_READONLY (field))
  935.     TREE_READONLY (ref) = 1;
  936.       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  937.     TREE_THIS_VOLATILE (ref) = 1;
  938.  
  939.       return ref;
  940.     }
  941.   else if (code != ERROR_MARK)
  942.     error ("request for member `%s' in something not a structure or union",
  943.         IDENTIFIER_POINTER (component));
  944.  
  945.   return error_mark_node;
  946. }
  947.  
  948. /* Given an expression PTR for a pointer, return an expression
  949.    for the value pointed to.
  950.    ERRORSTRING is the name of the operator to appear in error messages.  */
  951.  
  952. tree
  953. build_indirect_ref (ptr, errorstring)
  954.      tree ptr;
  955.      char *errorstring;
  956. {
  957.   register tree pointer = default_conversion (ptr);
  958.   register tree type = TREE_TYPE (pointer);
  959.  
  960.   if (TREE_CODE (type) == POINTER_TYPE)
  961.     if (TREE_CODE (pointer) == ADDR_EXPR
  962.     && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  963.         == TREE_TYPE (type)))
  964.       return TREE_OPERAND (pointer, 0);
  965.     else
  966.       {
  967.     tree t = TREE_TYPE (type);
  968.     register tree ref = build1 (INDIRECT_REF,
  969.                     TYPE_MAIN_VARIANT (t), pointer);
  970.  
  971.     if (TREE_CODE (t) == VOID_TYPE
  972.         || (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE))
  973.       {
  974.         error ("dereferencing pointer to incomplete type");
  975.         return error_mark_node;
  976.       }
  977.  
  978.     /* We *must* set TREE_READONLY when dereferencing a pointer to const,
  979.        so that we get the proper error message if the result is used
  980.        to assign to.  Also, &* is supposed to be a no-op.
  981.        And ANSI C seems to specify that the type of the result
  982.        should be the const type.  */
  983.     /* A de-reference of a pointer to const is not a const.  It is valid
  984.        to change it via some other pointer.  */
  985.     TREE_READONLY (ref) = TYPE_READONLY (t);
  986.     TREE_SIDE_EFFECTS (ref) = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
  987.     TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  988.     return ref;
  989.       }
  990.   else if (TREE_CODE (pointer) != ERROR_MARK)
  991.     error ("invalid type argument of `%s'", errorstring);
  992.   return error_mark_node;
  993. }
  994.  
  995. /* This handles expressions of the form "a[i]", which denotes
  996.    an array reference.
  997.  
  998.    This is logically equivalent in C to *(a+i), but we may do it differently.
  999.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1000.    This avoids forcing the array out of registers, and can work on
  1001.    arrays that are not lvalues (for example, members of structures returned
  1002.    by functions).  */
  1003.  
  1004. tree
  1005. build_array_ref (array, index)
  1006.      tree array, index;
  1007. {
  1008.   if (index == 0)
  1009.     {
  1010.       error ("subscript missing in array reference");
  1011.       return error_mark_node;
  1012.     }
  1013.  
  1014.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1015.       && TREE_CODE (array) != INDIRECT_REF)
  1016.     {
  1017.       tree rval, type;
  1018.  
  1019.       index = default_conversion (index);
  1020.       if (index != error_mark_node
  1021.       && TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  1022.     {
  1023.       error ("array subscript is not an integer");
  1024.       return error_mark_node;
  1025.     }
  1026.  
  1027.       /* An array that is indexed by a non-constant
  1028.      cannot be stored in a register; we must be able to do
  1029.      address arithmetic on its address.
  1030.      Likewise an array of elements of variable size.  */
  1031.       if (TREE_CODE (index) != INTEGER_CST
  1032.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  1033.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  1034.     {
  1035.       if (mark_addressable (array) == 0)
  1036.         return error_mark_node;
  1037.     }
  1038.  
  1039.       if (pedantic && !lvalue_p (array))
  1040.     pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1041.  
  1042.       if (pedantic)
  1043.     {
  1044.       tree foo = array;
  1045.       while (TREE_CODE (foo) == COMPONENT_REF)
  1046.         foo = TREE_OPERAND (foo, 0);
  1047.       if (TREE_CODE (foo) == VAR_DECL && TREE_REGDECL (foo))
  1048.         pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1049.     }
  1050.  
  1051.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  1052.       rval = build (ARRAY_REF, type, array, index);
  1053.       /* Array ref is const/volatile if the array elements are
  1054.          or if the array is.  */
  1055.       TREE_READONLY (rval)
  1056.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  1057.         | TREE_READONLY (array));
  1058.       TREE_SIDE_EFFECTS (rval)
  1059.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1060.         | TREE_SIDE_EFFECTS (array));
  1061.       TREE_THIS_VOLATILE (rval)
  1062.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1063.         /* This was added by rms on 16 Nov 91.
  1064.            It fixes  vol struct foo *a;  a->elts[1] 
  1065.            in an inline function.
  1066.            Hope it doesn't break something else.  */
  1067.         | TREE_THIS_VOLATILE (array));
  1068.       return require_complete_type (fold (rval));
  1069.     }
  1070.  
  1071.   {
  1072.     tree ar = default_conversion (array);
  1073.     tree ind = default_conversion (index);
  1074.  
  1075.     /* Put the integer in IND to simplify error checking.  */
  1076.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  1077.       {
  1078.     tree temp = ar;
  1079.     ar = ind;
  1080.     ind = temp;
  1081.       }
  1082.  
  1083.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  1084.       {
  1085.     error ("subscripted value is neither array nor pointer");
  1086.     return error_mark_node;
  1087.       }
  1088.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  1089.       {
  1090.     error ("array subscript is not an integer");
  1091.     return error_mark_node;
  1092.       }
  1093.  
  1094.     return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
  1095.                    "array indexing");
  1096.   }
  1097. }
  1098.  
  1099. /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against PARAMS.  */
  1100.  
  1101. #define ISDIGIT(c)    ((c) >= '0' && (c) <= '9')
  1102.  
  1103. #define T_I    &integer_type_node
  1104. #define T_L    &long_integer_type_node
  1105. #define T_S    &short_integer_type_node
  1106. #define T_UI    &unsigned_type_node
  1107. #define T_UL    &long_unsigned_type_node
  1108. #define T_US    &short_unsigned_type_node
  1109. #define T_F    &float_type_node
  1110. #define T_D    &double_type_node
  1111. #define T_LD    &long_double_type_node
  1112. #define T_C    &char_type_node
  1113. #define T_V    &void_type_node
  1114.  
  1115. typedef struct
  1116. {
  1117.   char *format_chars;
  1118.   int pointer_count;
  1119.   tree *nolen;
  1120.   tree *hlen;
  1121.   tree *llen;
  1122.   tree *bigllen;
  1123.   char *flag_chars;
  1124. } format_char_info;
  1125.  
  1126. static format_char_info print_table[]
  1127.   = {
  1128.       { "di",        0,    T_I,    T_I,    T_L,    NULL,    "-wp0 +" },
  1129.       { "oxX",        0,    T_UI,    T_UI,    T_UL,    NULL,    "-wp0#" },
  1130.       { "u",        0,    T_UI,    T_UI,    T_UL,    NULL,    "-wp0" },
  1131.       { "feEgG",    0,    T_D,    NULL,    NULL,    T_LD,    "-wp0 +#" },
  1132.       { "c",        0,    T_I,    NULL,    NULL,    NULL,    "-w" },
  1133.       { "s",        1,    T_C,    NULL,    NULL,    NULL,    "-wp" },
  1134.       { "p",        1,    T_V,    NULL,    NULL,    NULL,    "-" },
  1135.       { "n",        1,    T_I,    T_S,    T_L,    NULL,    "" },
  1136.       { NULL }
  1137.     };
  1138.  
  1139. static format_char_info scan_table[]
  1140.   = {
  1141.       { "di",        1,    T_I,    T_S,    T_L,    NULL,    "*" },
  1142.       { "ouxX",        1,    T_UI,    T_US,    T_UL,    NULL,    "*" },    
  1143.       { "efgEG",    1,    T_F,    NULL,    T_D,    T_LD,    "*" },
  1144.       { "s[c",        1,    T_C,    NULL,    NULL,    NULL,    "*" },
  1145.       { "p",        2,    T_V,    NULL,    NULL,    NULL,    "*" },
  1146.       { "n",        1,    T_I,    T_S,    T_L,    NULL,    "" },
  1147.       { NULL }
  1148.     };
  1149.  
  1150. typedef struct
  1151. {
  1152.   tree function_ident;        /* identifier such as "printf" */
  1153.   int is_scan;            /* TRUE if *scanf */
  1154.   int format_num;        /* number of format argument */
  1155.   int first_arg_num;        /* number of first arg (zero for varargs) */
  1156. } function_info;
  1157.  
  1158. static unsigned int function_info_entries = 0;
  1159. static function_info *function_info_table = NULL;
  1160.  
  1161. /* Record information for argument format checking.  FUNCTION_IDENT is
  1162.    the identifier node for the name of the function to check (its decl
  1163.    need not exist yet).  IS_SCAN is true for scanf-type format checking;
  1164.    false indicates printf-style format checking.  FORMAT_NUM is the number
  1165.    of the argument which is the format control string (starting from 1).
  1166.    FIRST_ARG_NUM is the number of the first actual argument to check
  1167.    against teh format string, or zero if no checking is not be done
  1168.    (e.g. for varargs such as vfprintf).  */
  1169.  
  1170. void
  1171. record_format_info (function_ident, is_scan, format_num, first_arg_num)
  1172.       tree function_ident;
  1173.       int is_scan;
  1174.       int format_num;
  1175.       int first_arg_num;
  1176. {
  1177.   function_info *info;
  1178.   
  1179.   function_info_entries++;
  1180.   if (function_info_table)
  1181.     function_info_table
  1182.       = (function_info *) xrealloc (function_info_table,
  1183.                     function_info_entries * sizeof (function_info));
  1184.   else
  1185.     function_info_table = (function_info *) xmalloc (sizeof (function_info));
  1186.   
  1187.   info = &function_info_table[function_info_entries - 1];
  1188.   
  1189.   info->function_ident = function_ident;
  1190.   info->is_scan = is_scan;
  1191.   info->format_num = format_num;
  1192.   info->first_arg_num = first_arg_num;
  1193. }
  1194.  
  1195. /* Initialize the table of functions to perform format checking on.
  1196.    The ANSI functions are always checked (whether <stdio.h> is
  1197.    included or not), since it is common to call printf without
  1198.    including <stdio.h>.  There shouldn't be a problem with this,
  1199.    since ANSI reserves these function names whether you include the
  1200.    header file or not.  In any case, the checking is harmless.  */
  1201.  
  1202. void
  1203. init_format_info_table ()
  1204. {
  1205.   record_format_info (get_identifier ("printf"), 0, 1, 2);
  1206.   record_format_info (get_identifier ("fprintf"), 0, 2, 3);
  1207.   record_format_info (get_identifier ("sprintf"), 0, 2, 3);
  1208.   record_format_info (get_identifier ("scanf"), 1, 1, 2);
  1209.   record_format_info (get_identifier ("fscanf"), 1, 2, 3);
  1210.   record_format_info (get_identifier ("sscanf"), 1, 2, 3);
  1211.   record_format_info (get_identifier ("vprintf"), 0, 1, 0);
  1212.   record_format_info (get_identifier ("vfprintf"), 0, 2, 0);
  1213.   record_format_info (get_identifier ("vsprintf"), 0, 2, 0);
  1214. }
  1215.  
  1216. static char    tfaff[] = "too few arguments for format";
  1217.  
  1218. /* Don't rely on existence of strchr.  */
  1219.  
  1220. static char *
  1221. my_strchr (string, c)
  1222.      char *string;
  1223.      int c;
  1224. {
  1225.   char *p;
  1226.   for (p = string; *p; p++)
  1227.     if (*p == c)
  1228.       return p;
  1229.  
  1230.   return 0;
  1231. }
  1232.  
  1233. /* Check the argument list of a call to printf, scanf, etc.
  1234.    INFO points to the element of function_info_table.
  1235.    PARAMS is the list of argument values.  */
  1236.  
  1237. static void
  1238. check_format (info, params)
  1239.      function_info *info;
  1240.      tree params;
  1241. {
  1242.   int i;
  1243.   int arg_num;
  1244.   int suppressed, wide, precise;
  1245.   int length_char;
  1246.   int format_char;
  1247.   int format_length;
  1248.   tree format_tree;
  1249.   tree cur_param;
  1250.   tree cur_type;
  1251.   tree wanted_type;
  1252.   char *format_chars;
  1253.   format_char_info *fci;
  1254.   static char message[132];
  1255.   char flag_chars[8];
  1256.  
  1257.   /* Skip to format argument.  If the argument isn't available, there's
  1258.      no work for us to do; prototype checking will catch the problem.  */
  1259.   for (arg_num = 1; ; ++arg_num)
  1260.     {
  1261.       if (params == 0)
  1262.     return;
  1263.       if (arg_num == info->format_num)
  1264.     break;
  1265.       params = TREE_CHAIN (params);
  1266.     }
  1267.   format_tree = TREE_VALUE (params);
  1268.   params = TREE_CHAIN (params);
  1269.   if (format_tree == 0)
  1270.     return;
  1271.   /* We can only check the format if it's a string constant.  */
  1272.   while (TREE_CODE (format_tree) == NOP_EXPR)
  1273.     format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
  1274.   if (format_tree == null_pointer_node)
  1275.     {
  1276.       warning ("null format string");
  1277.       return;
  1278.     }
  1279.   if (TREE_CODE (format_tree) != ADDR_EXPR)
  1280.     return;
  1281.   format_tree = TREE_OPERAND (format_tree, 0);
  1282.   if (TREE_CODE (format_tree) != STRING_CST)
  1283.     return;
  1284.   format_chars = TREE_STRING_POINTER (format_tree);
  1285.   format_length = TREE_STRING_LENGTH (format_tree);
  1286.   if (format_length <= 1)
  1287.     warning ("zero-length format string");
  1288.   if (format_chars[--format_length] != 0)
  1289.     {
  1290.       warning ("unterminated format string");
  1291.       return;
  1292.     }
  1293.   /* Skip to first argument to check.  */
  1294.   while (arg_num + 1 < info->first_arg_num)
  1295.     {
  1296.       if (params == 0)
  1297.     return;
  1298.       params = TREE_CHAIN (params);
  1299.       ++arg_num;
  1300.     }
  1301.   while (1)
  1302.     {
  1303.       if (*format_chars == 0)
  1304.     {
  1305.       if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
  1306.         warning ("embedded `\\0' in format");
  1307.       if (info->first_arg_num != 0 && params != 0)
  1308.         warning ("too many arguments for format");
  1309.       return;
  1310.     }
  1311.       if (*format_chars++ != '%')
  1312.     continue;
  1313.       if (*format_chars == 0)
  1314.     {
  1315.       warning ("spurious trailing `%%' in format");
  1316.       continue;
  1317.     }
  1318.       if (*format_chars == '%')
  1319.     {
  1320.       ++format_chars;
  1321.       continue;
  1322.     }
  1323.       flag_chars[0] = 0;
  1324.       suppressed = wide = precise = FALSE;
  1325.       if (info->is_scan)
  1326.     {
  1327.       suppressed = *format_chars == '*';
  1328.       if (suppressed)
  1329.         ++format_chars;
  1330.       while (ISDIGIT (*format_chars))
  1331.         ++format_chars;
  1332.     }
  1333.       else
  1334.     {
  1335.       while (*format_chars != 0 && my_strchr (" +#0-", *format_chars) != 0)
  1336.         {
  1337.           if (my_strchr (flag_chars, *format_chars) != 0)
  1338.         {
  1339.           sprintf (message, "repeated `%c' flag in format",
  1340.                *format_chars);
  1341.           warning (message);
  1342.         }
  1343.           i = strlen (flag_chars);
  1344.           flag_chars[i++] = *format_chars++;
  1345.           flag_chars[i] = 0;
  1346.         }
  1347.       /* "If the space and + flags both appear, 
  1348.          the space flag will be ignored."  */
  1349.       if (my_strchr (flag_chars, ' ') != 0
  1350.           && my_strchr (flag_chars, '+') != 0)
  1351.         warning ("use of both ` ' and `+' flags in format");
  1352.       /* "If the 0 and - flags both appear,
  1353.          the 0 flag will be ignored."  */
  1354.       if (my_strchr (flag_chars, '0') != 0
  1355.           && my_strchr (flag_chars, '-') != 0)
  1356.         warning ("use of both `0' and `-' flags in format");
  1357.       if (*format_chars == '*')
  1358.         {
  1359.           wide = TRUE;
  1360.           /* "...a field width...may be indicated by an asterisk.
  1361.          In this case, an int argument supplies the field width..."  */
  1362.           ++format_chars;
  1363.           if (params == 0)
  1364.         {
  1365.           warning (tfaff);
  1366.           return;
  1367.         }
  1368.           if (info->first_arg_num != 0)
  1369.         {
  1370.           cur_param = TREE_VALUE (params);
  1371.           params = TREE_CHAIN (params);
  1372.           ++arg_num;
  1373.           if (TREE_TYPE (cur_param) != integer_type_node)
  1374.             {
  1375.               sprintf (message,
  1376.                    "field width is not type int (arg %d)",
  1377.                    arg_num);
  1378.               warning (message);
  1379.             }
  1380.         }
  1381.         }
  1382.       else
  1383.         {
  1384.           while (ISDIGIT (*format_chars))
  1385.         {
  1386.           wide = TRUE;
  1387.           ++format_chars;
  1388.         }
  1389.         }
  1390.       if (*format_chars == '.')
  1391.         {
  1392.           precise = TRUE;
  1393.           /* "For d, i, o, u, x, and X conversions,
  1394.          if a precision is specified, the 0 flag will be ignored.
  1395.          For other conversions, the behavior is undefined."  */
  1396.           if (my_strchr (flag_chars, '0') != 0)
  1397.         warning ("precision and `0' flag both used in one %%-sequence");
  1398.           ++format_chars;
  1399.           if (*format_chars != '*' && !ISDIGIT (*format_chars))
  1400.         warning ("`.' not followed by `*' or digit in format");
  1401.           /* "...a...precision...may be indicated by an asterisk.
  1402.          In this case, an int argument supplies the...precision."  */
  1403.           if (*format_chars == '*')
  1404.         {
  1405.           if (info->first_arg_num != 0)
  1406.             {
  1407.               ++format_chars;
  1408.               if (params == 0)
  1409.                 {
  1410.               warning (tfaff);
  1411.               return;
  1412.             }
  1413.               cur_param = TREE_VALUE (params);
  1414.               params = TREE_CHAIN (params);
  1415.               ++arg_num;
  1416.               if (TREE_TYPE (cur_param) != integer_type_node)
  1417.                 {
  1418.                   sprintf (message,
  1419.                    "field width is not type int (arg %d)",
  1420.                    arg_num);
  1421.                   warning (message);
  1422.                 }
  1423.             }
  1424.         }
  1425.           else
  1426.         {
  1427.           while (ISDIGIT (*format_chars))
  1428.             ++format_chars;
  1429.         }
  1430.         }
  1431.     }
  1432.       if (*format_chars == 'h' || *format_chars == 'l' || *format_chars == 'L')
  1433.     length_char = *format_chars++;
  1434.       else
  1435.     length_char = 0;
  1436.       if (suppressed && length_char != 0)
  1437.     {
  1438.       sprintf (message,
  1439.            "use of `*' and `%c' together in format",
  1440.            length_char);
  1441.       warning (message);
  1442.     }
  1443.       format_char = *format_chars;
  1444.       if (format_char == 0)
  1445.     {
  1446.       warning ("conversion lacks type at end of format");
  1447.       continue;
  1448.     }
  1449.       format_chars++;
  1450.       fci = info->is_scan ? scan_table : print_table;
  1451.       while (1)
  1452.     {
  1453.       if (fci->format_chars == 0
  1454.           || my_strchr (fci->format_chars, format_char) != 0)
  1455.         break;
  1456.       ++fci;
  1457.     }
  1458.       if (fci->format_chars == 0)
  1459.     {
  1460.       if (format_char >= 040 && format_char <= 0177)
  1461.         sprintf (message,
  1462.              "unknown conversion type character `%c' in format",
  1463.              format_char);
  1464.       else
  1465.         sprintf (message,
  1466.              "unknown conversion type character 0x%x in format",
  1467.              format_char);
  1468.       warning (message);
  1469.       continue;
  1470.     }
  1471.       if (wide && my_strchr (fci->flag_chars, 'w') == 0)
  1472.     {
  1473.       sprintf (message, "width used with `%c' format",
  1474.            format_char);
  1475.       warning (message);
  1476.     }
  1477.       if (precise && my_strchr (fci->flag_chars, 'p') == 0)
  1478.     {
  1479.       sprintf (message, "precision used with `%c' format",
  1480.            format_char);
  1481.       warning (message);
  1482.     }
  1483.       if (suppressed)
  1484.     {
  1485.       if (my_strchr (fci->flag_chars, '*') == 0)
  1486.         {
  1487.           sprintf (message,
  1488.                "suppression of `%c' conversion in format",
  1489.                format_char);
  1490.           warning (message);
  1491.         }
  1492.       continue;
  1493.     }
  1494.       for (i = 0; flag_chars[i] != 0; ++i)
  1495.     {
  1496.       if (my_strchr (fci->flag_chars, flag_chars[i]) == 0)
  1497.         {
  1498.           sprintf (message, "flag `%c' used with type `%c'",
  1499.                flag_chars[i], format_char);
  1500.           warning (message);
  1501.         }
  1502.     }
  1503.       switch (length_char)
  1504.     {
  1505.     default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
  1506.     case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
  1507.     case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
  1508.     case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
  1509.     }
  1510.       if (wanted_type == 0)
  1511.     {
  1512.       sprintf (message,
  1513.            "use of `%c' length character with `%c' type character",
  1514.            length_char, format_char);
  1515.       warning (message);
  1516. #ifdef NeXT
  1517.       wanted_type = fci->nolen ? *(fci->nolen) : 0;
  1518. #endif /* NeXT */
  1519.     }
  1520.  
  1521.       /*
  1522.        ** XXX -- should kvetch about stuff such as
  1523.        **    {
  1524.        **        const int    i;
  1525.        **
  1526.        **        scanf ("%d", &i);
  1527.        **    }
  1528.        */
  1529.  
  1530.       /* Finally. . .check type of argument against desired type!  */
  1531.       if (info->first_arg_num == 0)
  1532.     continue;
  1533.       if (params == 0)
  1534.     {
  1535.       warning (tfaff);
  1536.       return;
  1537.     }
  1538.       cur_param = TREE_VALUE (params);
  1539.       params = TREE_CHAIN (params);
  1540.       ++arg_num;
  1541.       cur_type = TREE_TYPE (cur_param);
  1542.       for (i = 0; i < fci->pointer_count; ++i)
  1543.     {
  1544.       if (TREE_CODE (cur_type) == POINTER_TYPE)
  1545.         {
  1546.           cur_type = TREE_TYPE (cur_type);
  1547.           continue;
  1548.         }
  1549.       sprintf (message,
  1550.            "format argument is not a %s (arg %d)",
  1551.            ((fci->pointer_count == 1) ? "pointer" : "pointer to a pointer"),
  1552.            arg_num);
  1553.       warning (message);
  1554.       break;
  1555.     }
  1556.       if (i == fci->pointer_count)
  1557.     {
  1558.       register char *this;
  1559.       register char *that;
  1560.   
  1561.       this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
  1562.       that = 0;
  1563.       if (TYPE_NAME (cur_type) != 0)
  1564.         if (DECL_NAME (TYPE_NAME (cur_type)) != 0)
  1565.           that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
  1566.       if (that == 0)
  1567.         if (TREE_CODE (cur_type) == POINTER_TYPE)
  1568.           that = "pointer";
  1569.         else
  1570.           that = "different type";
  1571.       if (strcmp (this, that) != 0)
  1572.         {
  1573.           sprintf (message, "%s format, %s arg (arg %d)",
  1574.             this, that, arg_num);
  1575.           warning (message);
  1576.         }
  1577.     }
  1578.     }
  1579. }
  1580.  
  1581. /* Build a function call to function FUNCTION with parameters PARAMS.
  1582.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  1583.    TREE_VALUE of each node is a parameter-expression.
  1584.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  1585.  
  1586. tree
  1587. build_function_call (function, params)
  1588.      tree function, params;
  1589. {
  1590.   register tree fntype;
  1591.   register tree coerced_params;
  1592.   tree name = NULL_TREE;
  1593.  
  1594.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  1595.   if (TREE_CODE (function) == NON_LVALUE_EXPR)
  1596.     function = TREE_OPERAND (function, 0);
  1597.  
  1598.   /* Convert anything with function type to a pointer-to-function.  */
  1599.   if (TREE_CODE (function) == FUNCTION_DECL)
  1600.     {
  1601.       name = DECL_NAME (function);
  1602.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  1603.      (because calling an inline function does not mean the function
  1604.      needs to be separately compiled).  */
  1605.       function = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (function)),
  1606.              function);
  1607.     }
  1608.   else
  1609.     function = default_conversion (function);
  1610.  
  1611.   fntype = TREE_TYPE (function);
  1612.  
  1613.   if (TREE_CODE (fntype) == ERROR_MARK)
  1614.     return error_mark_node;
  1615.  
  1616.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  1617.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  1618.     {
  1619.       error ("called object is not a function");
  1620.       return error_mark_node;
  1621.     }
  1622.  
  1623.   /* fntype now gets the type of function pointed to.  */
  1624.   fntype = TREE_TYPE (fntype);
  1625.  
  1626.   /* Convert the parameters to the types declared in the
  1627.      function prototype, or apply default promotions.  */
  1628.  
  1629.   coerced_params
  1630.     = convert_arguments (TYPE_ARG_TYPES (fntype), params, name);
  1631.  
  1632.   /* Check for errors in format strings.  */
  1633.   if (warn_format && name != 0)
  1634.     {
  1635.       unsigned int i;
  1636.  
  1637.       /* See if this function is a format function.  */
  1638.       for (i = 0; i < function_info_entries; i++)
  1639.     if (function_info_table[i].function_ident == name)
  1640.       {
  1641.         register char *message;
  1642.  
  1643.         /* If so, check it.  */
  1644.         check_format (&function_info_table[i], coerced_params);
  1645.         break;
  1646.       }
  1647.     }
  1648.  
  1649.   /* Recognize certain built-in functions so we can make tree-codes
  1650.      other than CALL_EXPR.  We do this when it enables fold-const.c
  1651.      to do something useful.  */
  1652.  
  1653.   if (TREE_CODE (function) == ADDR_EXPR
  1654.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  1655.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  1656.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  1657.       {
  1658.       case BUILT_IN_ABS:
  1659.       case BUILT_IN_LABS:
  1660.       case BUILT_IN_FABS:
  1661.     if (coerced_params == 0)
  1662.       return integer_zero_node;
  1663.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  1664.       }
  1665.  
  1666.   {
  1667.     register tree result
  1668.       = build (CALL_EXPR, TREE_TYPE (fntype),
  1669.            function, coerced_params, NULL_TREE);
  1670.  
  1671.     TREE_SIDE_EFFECTS (result) = 1;
  1672.     if (TREE_TYPE (result) == void_type_node)
  1673.       return result;
  1674.     return require_complete_type (result);
  1675.   }
  1676. }
  1677.  
  1678. /* Convert the argument expressions in the list VALUES
  1679.    to the types in the list TYPELIST.  The result is a list of converted
  1680.    argument expressions.
  1681.  
  1682.    If TYPELIST is exhausted, or when an element has NULL as its type,
  1683.    perform the default conversions.
  1684.  
  1685.    PARMLIST is the chain of parm decls for the function being called.
  1686.    It may be 0, if that info is not available.
  1687.    It is used only for generating error messages.
  1688.  
  1689.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  1690.  
  1691.    This is also where warnings about wrong number of args are generated.
  1692.  
  1693.    Both VALUES and the returned value are chains of TREE_LIST nodes
  1694.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  1695.  
  1696. static tree
  1697. convert_arguments (typelist, values, name)
  1698.      tree typelist, values, name;
  1699. {
  1700.   register tree typetail, valtail;
  1701.   register tree result = NULL;
  1702.   int parmnum;
  1703.  
  1704.   /* Scan the given expressions and types, producing individual
  1705.      converted arguments and pushing them on RESULT in reverse order.  */
  1706.  
  1707.   for (valtail = values, typetail = typelist, parmnum = 0;
  1708.        valtail;
  1709.        valtail = TREE_CHAIN (valtail), parmnum++)
  1710.     {
  1711.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  1712.       register tree val = TREE_VALUE (valtail);
  1713.  
  1714.       if (type == void_type_node)
  1715.     {
  1716.       if (name)
  1717.         error ("too many arguments to function `%s'",
  1718.            IDENTIFIER_POINTER (name));
  1719.       else
  1720.         error ("too many arguments to function");
  1721.       break;
  1722.     }
  1723.  
  1724.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  1725.       if (TREE_CODE (val) == NON_LVALUE_EXPR)
  1726.     val = TREE_OPERAND (val, 0);
  1727.  
  1728.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  1729.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  1730.     val = default_conversion (val);
  1731.  
  1732.       val = require_complete_type (val);
  1733.  
  1734.       if (type != 0)
  1735.     {
  1736.       /* Formal parm type is specified by a function prototype.  */
  1737.       tree parmval;
  1738.  
  1739.       if (TYPE_SIZE (type) == 0)
  1740.         {
  1741.           error ("type of formal parameter %d is incomplete", parmnum + 1);
  1742.           parmval = val;
  1743.         }
  1744.       else
  1745.         {
  1746.           tree parmname;
  1747. #ifdef PROMOTE_PROTOTYPES
  1748.           /* Rather than truncating and then reextending,
  1749.          convert directly to int, if that's the type we will want.  */
  1750.           if (! flag_traditional
  1751.           && TREE_CODE (type) == INTEGER_TYPE
  1752.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1753.         type = integer_type_node;
  1754. #endif
  1755.  
  1756.           /* Nameless union automatically casts the types it contains.  */
  1757.           if (TREE_CODE (type) == UNION_TYPE && TYPE_NAME (type) == 0)
  1758.         {
  1759.           tree field;
  1760.           for (field = TYPE_FIELDS (type); field;
  1761.                field = TREE_CHAIN (field))
  1762.             if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
  1763.                    TYPE_MAIN_VARIANT (TREE_TYPE (val))))
  1764.               break;
  1765.  
  1766.           if (field)
  1767.             val = build1 (CONVERT_EXPR, type, val);
  1768.         }
  1769.  
  1770.           /* Optionally warn about conversions that can overflow.  */
  1771.           if (warn_conversion)
  1772.         {
  1773.           int formal_prec = TYPE_PRECISION (type);
  1774.           int actual_prec = TYPE_PRECISION (TREE_TYPE (val));
  1775.           int int_prec = TYPE_PRECISION (integer_type_node);
  1776.  
  1777.           if (TREE_CODE (type) != REAL_TYPE
  1778.               && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1779.             warning ("floating argument converted to integer");
  1780.           else if (TREE_CODE (type) == REAL_TYPE
  1781.               && TREE_CODE (TREE_TYPE (val)) != REAL_TYPE)
  1782.             warning ("integer argument converted to floating");
  1783.           /* Detect integer changing in width or signedness.  */
  1784.           else if ((TREE_CODE (type) == INTEGER_TYPE
  1785.                 || TREE_CODE (type) == ENUMERAL_TYPE)
  1786.                && (TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE
  1787.                    || TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE)
  1788.                && ((TREE_UNSIGNED (type)
  1789.                 != TREE_UNSIGNED (TREE_TYPE (val)))
  1790.                    || (max (formal_prec, int_prec)
  1791.                    != max (actual_prec, int_prec))))
  1792.             {
  1793.               if (max (formal_prec, int_prec)
  1794.               != max (actual_prec, int_prec))
  1795.             warning ("integer argument converted in width");
  1796.               else if (TREE_CODE (val) == INTEGER_CST
  1797.                    && int_fits_type_p (val, type))
  1798.             /* Change in signedness doesn't matter
  1799.                if a constant value is unaffected.  */
  1800.             ;
  1801.               else if (TREE_UNSIGNED (type))
  1802.             warning ("signed argument converted to unsigned");
  1803.               else
  1804.             warning ("unsigned argument converted to signed");
  1805.             }
  1806.         }
  1807.  
  1808.           parmval = convert_for_assignment (type, val, "argument passing",
  1809.                         name, parmnum + 1);
  1810.           
  1811. #ifdef PROMOTE_PROTOTYPES
  1812.           if (TREE_CODE (type) == INTEGER_TYPE
  1813.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1814.         parmval = default_conversion (parmval);
  1815. #endif
  1816.         }
  1817.       result = tree_cons (0, parmval, result);
  1818.     }
  1819.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  1820.                && (TYPE_PRECISION (TREE_TYPE (val))
  1821.                < TYPE_PRECISION (double_type_node)))
  1822.     /* Convert `float' to `double'.  */
  1823.     result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  1824.       else
  1825.     /* Convert `short' and `char' to full-size `int'.  */
  1826.     result = tree_cons (NULL_TREE, default_conversion (val), result);
  1827.  
  1828.       if (typetail)
  1829.     typetail = TREE_CHAIN (typetail);
  1830.     }
  1831.  
  1832.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  1833.     {
  1834.       if (name)
  1835.     error ("too few arguments to function `%s'",
  1836.            IDENTIFIER_POINTER (name));
  1837.       else
  1838.     error ("too few arguments to function");
  1839.     }
  1840.  
  1841.   return nreverse (result);
  1842. }
  1843.  
  1844. /* Build a binary-operation expression, after performing default conversions
  1845.    on the operands.  CODE is the kind of expression to build.  */
  1846.  
  1847. tree
  1848. build_binary_op (code, arg1, arg2)
  1849.      enum tree_code code;
  1850.      tree arg1, arg2;
  1851. {
  1852.   tree result
  1853.     = build_binary_op_nodefault (code, default_conversion (arg1),
  1854.                  default_conversion (arg2), code);
  1855.   return result;
  1856. }
  1857.  
  1858. /* This is the entry point used by the parser
  1859.    for binary operators in the input.
  1860.    In addition to constructing the expression,
  1861.    we check for operands that were written with other binary operators
  1862.    in a way that is likely to confuse the user.  */
  1863.    
  1864. tree
  1865. parser_build_binary_op (code, arg1, arg2)
  1866.      enum tree_code code;
  1867.      tree arg1, arg2;
  1868. {
  1869.   tree result
  1870.     = build_binary_op_nodefault (code, default_conversion (arg1),
  1871.                  default_conversion (arg2), code);
  1872.  
  1873.   char class;
  1874.   char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
  1875.   char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
  1876.   enum tree_code code1 = ERROR_MARK;
  1877.   enum tree_code code2 = ERROR_MARK;
  1878.  
  1879.   if (class1 == 'e' || class1 == '1'
  1880.       || class1 == '2' || class1 == '<')
  1881.     code1 = C_EXP_ORIGINAL_CODE (arg1);
  1882.   if (class2 == 'e' || class2 == '1'
  1883.       || class2 == '2' || class2 == '<')
  1884.     code2 = C_EXP_ORIGINAL_CODE (arg2);
  1885.  
  1886.   /* Check for cases such as x+y<<z which users are likely
  1887.      to misinterpret.  If parens are used, C_EXP_ORIGINAL_CODE
  1888.      is cleared to prevent these warnings.  */
  1889.   if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
  1890.     {
  1891.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1892.       || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1893.     warning ("suggest parentheses around + or - inside shift");
  1894.     }
  1895.  
  1896.   if (code == TRUTH_ORIF_EXPR)
  1897.     {
  1898.       if (code1 == TRUTH_ANDIF_EXPR
  1899.       || code2 == TRUTH_ANDIF_EXPR)
  1900.     warning ("suggest parentheses around && within ||");
  1901.     }
  1902.  
  1903.   if (code == BIT_IOR_EXPR)
  1904.     {
  1905.       if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
  1906.       || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1907.       || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
  1908.       || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1909.     warning ("suggest parentheses around arithmetic in operand of |");
  1910.     }
  1911.  
  1912.   if (code == BIT_XOR_EXPR)
  1913.     {
  1914.       if (code1 == BIT_AND_EXPR
  1915.       || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1916.       || code2 == BIT_AND_EXPR
  1917.       || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1918.     warning ("suggest parentheses around arithmetic in operand of ^");
  1919.     }
  1920.  
  1921.   if (code == BIT_AND_EXPR)
  1922.     {
  1923.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1924.       || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1925.     warning ("suggest parentheses around + or - in operand of &");
  1926.     }
  1927.  
  1928.   class = TREE_CODE_CLASS (TREE_CODE (result));
  1929.  
  1930.   /* Record the code that was specified in the source,
  1931.      for the sake of warnings about confusing nesting.  */
  1932.   if (class == 'e' || class == '1'
  1933.       || class == '2' || class == '<')
  1934.     C_SET_EXP_ORIGINAL_CODE (result, code);
  1935.   else
  1936.     {
  1937.       int flag = TREE_CONSTANT (result);
  1938.       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
  1939.       C_SET_EXP_ORIGINAL_CODE (result, code);
  1940.       TREE_CONSTANT (result) = flag;
  1941.     }
  1942.  
  1943.   return result;
  1944. }
  1945.  
  1946. /* Build a binary-operation expression without default conversions.
  1947.    CODE is the kind of expression to build.
  1948.    This function differs from `build' in several ways:
  1949.    the data type of the result is computed and recorded in it,
  1950.    warnings are generated if arg data types are invalid,
  1951.    special handling for addition and subtraction of pointers is known,
  1952.    and some optimization is done (operations on narrow ints
  1953.    are done in the narrower type when that gives the same result).
  1954.    Constant folding is also done before the result is returned.
  1955.  
  1956.    ERROR_CODE is the code that determines what to say in error messages.
  1957.    It is usually, but not always, the same as CODE.
  1958.  
  1959.    Note that the operands will never have enumeral types, or function
  1960.    or array types,
  1961.    because either they have just had the default conversions performed
  1962.    or they have both just been converted to some other type in which
  1963.    the arithmetic is to be done.  */
  1964.  
  1965. tree
  1966. build_binary_op_nodefault (code, op0, op1, error_code)
  1967.      enum tree_code code;
  1968.      tree op0, op1;
  1969.      enum tree_code error_code;
  1970. {
  1971.   tree type0 = TREE_TYPE (op0), type1 = TREE_TYPE (op1);
  1972.  
  1973.   /* The expression codes of the data types of the arguments tell us
  1974.      whether the arguments are integers, floating, pointers, etc.  */
  1975.   register enum tree_code code0 = TREE_CODE (type0);
  1976.   register enum tree_code code1 = TREE_CODE (type1);
  1977.  
  1978.   /* Expression code to give to the expression when it is built.
  1979.      Normally this is CODE, which is what the caller asked for,
  1980.      but in some special cases we change it.  */
  1981.   register enum tree_code resultcode = code;
  1982.  
  1983.   /* Data type in which the computation is to be performed.
  1984.      In the simplest cases this is the common type of the arguments.  */
  1985.   register tree result_type = NULL;
  1986.  
  1987.   /* Nonzero means operands have already been type-converted
  1988.      in whatever way is necessary.
  1989.      Zero means they need to be converted to RESULT_TYPE.  */
  1990.   int converted = 0;
  1991.  
  1992.   /* Nonzero means after finally constructing the expression
  1993.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  1994.   tree final_type = 0;
  1995.  
  1996.   /* Nonzero if this is an operation like MIN or MAX which can
  1997.      safely be computed in short if both args are promoted shorts.
  1998.      Also implies COMMON.
  1999.      -1 indicates a bitwise operation; this makes a difference
  2000.      in the exact conditions for when it is safe to do the operation
  2001.      in a narrower mode.  */
  2002.   int shorten = 0;
  2003.  
  2004.   /* Nonzero if this is a comparison operation;
  2005.      if both args are promoted shorts, compare the original shorts.
  2006.      Also implies COMMON.  */
  2007.   int short_compare = 0;
  2008.  
  2009.   /* Nonzero if this is a right-shift operation, which can be computed on the
  2010.      original short and then promoted if the operand is a promoted short.  */
  2011.   int short_shift = 0;
  2012.  
  2013.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  2014.   int common = 0;
  2015.  
  2016.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  2017.   if (TREE_CODE (op0) == NON_LVALUE_EXPR)
  2018.     op0 = TREE_OPERAND (op0, 0);
  2019.   if (TREE_CODE (op1) == NON_LVALUE_EXPR)
  2020.     op1 = TREE_OPERAND (op1, 0);
  2021.  
  2022.   /* If an error was already reported for one of the arguments,
  2023.      avoid reporting another error.  */
  2024.  
  2025.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  2026.     return error_mark_node;
  2027.  
  2028.   switch (code)
  2029.     {
  2030.     case PLUS_EXPR:
  2031.       /* Handle the pointer + int case.  */
  2032.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2033.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  2034.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  2035.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  2036.       else
  2037.     common = 1;
  2038.       break;
  2039.  
  2040.     case MINUS_EXPR:
  2041.       /* Subtraction of two similar pointers.
  2042.      We must subtract them as integers, then divide by object size.  */
  2043.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  2044.       && comp_target_types (type0, type1))
  2045.     return pointer_diff (op0, op1);
  2046.       /* Handle pointer minus int.  Just like pointer plus int.  */
  2047.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2048.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  2049.       else
  2050.     common = 1;
  2051.       break;
  2052.  
  2053.     case MULT_EXPR:
  2054.       common = 1;
  2055.       break;
  2056.  
  2057.     case TRUNC_DIV_EXPR:
  2058.     case CEIL_DIV_EXPR:
  2059.     case FLOOR_DIV_EXPR:
  2060.     case ROUND_DIV_EXPR:
  2061.     case EXACT_DIV_EXPR:
  2062.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2063.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2064.     {
  2065.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  2066.         resultcode = RDIV_EXPR;
  2067.       else
  2068.         shorten = 1;
  2069.       common = 1;
  2070.     }
  2071.       break;
  2072.  
  2073.     case BIT_AND_EXPR:
  2074.     case BIT_ANDTC_EXPR:
  2075.     case BIT_IOR_EXPR:
  2076.     case BIT_XOR_EXPR:
  2077.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2078.     shorten = -1;
  2079.       /* If one operand is a constant, and the other is a short type
  2080.      that has been converted to an int,
  2081.      really do the work in the short type and then convert the
  2082.      result to int.  If we are lucky, the constant will be 0 or 1
  2083.      in the short type, making the entire operation go away.  */
  2084.       if (TREE_CODE (op0) == INTEGER_CST
  2085.       && TREE_CODE (op1) == NOP_EXPR
  2086.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  2087.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  2088.     {
  2089.       final_type = result_type;
  2090.       op1 = TREE_OPERAND (op1, 0);
  2091.       result_type = TREE_TYPE (op1);
  2092.     }
  2093.       if (TREE_CODE (op1) == INTEGER_CST
  2094.       && TREE_CODE (op0) == NOP_EXPR
  2095.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  2096.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  2097.     {
  2098.       final_type = result_type;
  2099.       op0 = TREE_OPERAND (op0, 0);
  2100.       result_type = TREE_TYPE (op0);
  2101.     }
  2102.       break;
  2103.  
  2104.     case TRUNC_MOD_EXPR:
  2105.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2106.     shorten = 1;
  2107.       break;
  2108.  
  2109.     case TRUTH_ANDIF_EXPR:
  2110.     case TRUTH_ORIF_EXPR:
  2111.     case TRUTH_AND_EXPR:
  2112.     case TRUTH_OR_EXPR:
  2113.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  2114.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  2115.     {
  2116.       /* Result of these operations is always an int,
  2117.          but that does not mean the operands should be
  2118.          converted to ints!  */
  2119.       result_type = integer_type_node;
  2120.       op0 = truthvalue_conversion (op0);
  2121.       op1 = truthvalue_conversion (op1);
  2122.       converted = 1;
  2123.     }
  2124.       break;
  2125.  
  2126.       /* Shift operations: result has same type as first operand;
  2127.      always convert second operand to int.
  2128.      Also set SHORT_SHIFT if shifting rightward.  */
  2129.  
  2130.     case RSHIFT_EXPR:
  2131.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2132.     {
  2133.       result_type = type0;
  2134.       if (TREE_CODE (op1) == INTEGER_CST)
  2135.         {
  2136.           if (TREE_INT_CST_LOW (op1) > 0)
  2137.         short_shift = 1;
  2138.           else if (TREE_INT_CST_LOW (op1) < 0)
  2139.         warning ("shift count is negative");
  2140.           if (TREE_INT_CST_LOW (op1) >= TYPE_PRECISION (type0))
  2141.         warning ("shift count exceeds width of value shifted");
  2142.         }
  2143.       /* Convert the shift-count to an integer, regardless of
  2144.          size of value being shifted.  */
  2145.       if (TREE_TYPE (op1) != integer_type_node)
  2146.         op1 = convert (integer_type_node, op1);
  2147.       /* Avoid converting op1 to result_type later.  */
  2148.       converted = 1;
  2149.     }
  2150.       break;
  2151.  
  2152.     case LSHIFT_EXPR:
  2153.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2154.     {
  2155.       result_type = type0;
  2156.       if (TREE_CODE (op1) == INTEGER_CST
  2157.           && TREE_INT_CST_LOW (op1) < 0)
  2158.         warning ("shift count is negative");
  2159.       if (TREE_CODE (op1) == INTEGER_CST
  2160.           && TREE_INT_CST_LOW (op1) >= TYPE_PRECISION (type0))
  2161.         warning ("shift count exceeds width of value shifted");
  2162.       /* Convert the shift-count to an integer, regardless of
  2163.          size of value being shifted.  */
  2164.       if (TREE_TYPE (op1) != integer_type_node)
  2165.         op1 = convert (integer_type_node, op1);
  2166.       /* Avoid converting op1 to result_type later.  */
  2167.       converted = 1;
  2168.     }
  2169.       break;
  2170.  
  2171.     case RROTATE_EXPR:
  2172.     case LROTATE_EXPR:
  2173.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2174.     {
  2175.       result_type = type0;
  2176.       if (TREE_CODE (op1) == INTEGER_CST
  2177.           && TREE_INT_CST_LOW (op1) < 0)
  2178.         warning ("shift count is negative");
  2179.       if (TREE_CODE (op1) == INTEGER_CST
  2180.           && TREE_INT_CST_LOW (op1) >= TYPE_PRECISION (type0))
  2181.         warning ("shift count >= width of value shifted");
  2182.       /* Convert the shift-count to an integer, regardless of
  2183.          size of value being shifted.  */
  2184.       if (TREE_TYPE (op1) != integer_type_node)
  2185.         op1 = convert (integer_type_node, op1);
  2186.     }
  2187.       break;
  2188.  
  2189.     case EQ_EXPR:
  2190.     case NE_EXPR:
  2191.       /* Result of comparison is always int,
  2192.      but don't convert the args to int!  */
  2193.       result_type = integer_type_node;
  2194.       converted = 1;
  2195.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2196.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2197.     short_compare = 1;
  2198.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2199.     {
  2200.       register tree tt0 = TREE_TYPE (type0);
  2201.       register tree tt1 = TREE_TYPE (type1);
  2202.       /* Anything compares with void *.  void * compares with anything.
  2203.          Otherwise, the targets must be the same.  */
  2204.       if (comp_target_types (type0, type1))
  2205.         ;
  2206.       else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
  2207.         {
  2208.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  2209.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2210.         }
  2211.       else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
  2212.         {
  2213.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  2214.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2215.         }
  2216.       else
  2217.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2218.     }
  2219.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2220.            && integer_zerop (op1))
  2221.     op1 = null_pointer_node;
  2222.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2223.            && integer_zerop (op0))
  2224.     op0 = null_pointer_node;
  2225.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2226.     {
  2227.       if (! flag_traditional)
  2228.         pedwarn ("comparison between pointer and integer");
  2229.       op1 = convert (TREE_TYPE (op0), op1);
  2230.     }
  2231.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2232.     {
  2233.       if (! flag_traditional)
  2234.         pedwarn ("comparison between pointer and integer");
  2235.       op0 = convert (TREE_TYPE (op1), op0);
  2236.     }
  2237.       else
  2238.     /* If args are not valid, clear out RESULT_TYPE
  2239.        to cause an error message later.  */
  2240.     result_type = 0;
  2241.       break;
  2242.  
  2243.     case MAX_EXPR:
  2244.     case MIN_EXPR:
  2245.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2246.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2247.     shorten = 1;
  2248.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2249.     {
  2250.       if (! comp_target_types (type0, type1))
  2251.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2252.       else if (pedantic 
  2253.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2254.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2255.       result_type = common_type (type0, type1);
  2256.     }
  2257.       break;
  2258.  
  2259.     case LE_EXPR:
  2260.     case GE_EXPR:
  2261.     case LT_EXPR:
  2262.     case GT_EXPR:
  2263.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2264.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2265.         {
  2266.       tree op0_type = TREE_CODE (op0) == NOP_EXPR
  2267.               ? TREE_TYPE (TREE_OPERAND (op0, 0))
  2268.               : type0;
  2269.       tree op1_type = TREE_CODE (op1) == NOP_EXPR
  2270.               ? TREE_TYPE (TREE_OPERAND (op1, 0))
  2271.               : type1;
  2272.       int op0_unsigned = TREE_UNSIGNED (op0_type);
  2273.       int op1_unsigned = TREE_UNSIGNED (op1_type);
  2274.  
  2275.       short_compare = 1;
  2276.  
  2277.           /* Give warnings for ordered comparisons between signed and
  2278.          unsigned quantities.  Do not warn if the signed quantity
  2279.          is an unsuffixed integer literal (or some static constant
  2280.          expression involving such literals) and it is positive.
  2281.          Do not warn if the width of the unsigned quantity is less
  2282.          than that of the signed quantity, since in this case all
  2283.          values of the unsigned quantity fit in the signed quantity.  */
  2284. #ifndef NeXT
  2285.       if (extra_warnings && op0_unsigned != op1_unsigned
  2286.           && ((op0_unsigned
  2287.            && TYPE_PRECISION (op0_type) >= TYPE_PRECISION (op1_type)
  2288.            && (TREE_CODE (op1) != INTEGER_CST
  2289.                || (TREE_CODE (op1) == INTEGER_CST
  2290.                && INT_CST_LT (op1, integer_zero_node))))
  2291.           ||
  2292.           (op1_unsigned
  2293.            && TYPE_PRECISION (op1_type) >= TYPE_PRECISION (op0_type)
  2294.            && (TREE_CODE (op0) != INTEGER_CST
  2295.                || (TREE_CODE (op0) == INTEGER_CST
  2296.                && INT_CST_LT (op0, integer_zero_node)))) ))
  2297.         warning ("ordered comparison between signed and unsigned");
  2298. #endif /* NeXT */
  2299.         }
  2300.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2301.     {
  2302.       if (! comp_target_types (type0, type1))
  2303.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2304.       else if (pedantic 
  2305.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2306.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2307.       result_type = integer_type_node;
  2308.     }
  2309.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2310.            && integer_zerop (op1))
  2311.     {
  2312.       result_type = integer_type_node;
  2313.       op1 = null_pointer_node;
  2314.       if (! flag_traditional)
  2315.         pedwarn ("ordered comparison of pointer with integer zero");
  2316.     }
  2317.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2318.            && integer_zerop (op0))
  2319.     {
  2320.       result_type = integer_type_node;
  2321.       op0 = null_pointer_node;
  2322.       if (pedantic)
  2323.         pedwarn ("ordered comparison of pointer with integer zero");
  2324.     }
  2325.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2326.     {
  2327.       result_type = integer_type_node;
  2328.       if (! flag_traditional)
  2329.         pedwarn ("comparison between pointer and integer");
  2330.       op1 = convert (TREE_TYPE (op0), op1);
  2331.     }
  2332.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2333.     {
  2334.       result_type = integer_type_node;
  2335.       if (! flag_traditional)
  2336.         pedwarn ("comparison between pointer and integer");
  2337.       op0 = convert (TREE_TYPE (op1), op0);
  2338.     }
  2339.       converted = 1;
  2340.       break;
  2341.     }
  2342.  
  2343.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2344.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2345.     {
  2346.       if (shorten || common || short_compare)
  2347.     result_type = common_type (type0, type1);
  2348.  
  2349.       /* For certain operations (which identify themselves by shorten != 0)
  2350.      if both args were extended from the same smaller type,
  2351.      do the arithmetic in that type and then extend.
  2352.  
  2353.      shorten !=0 and !=1 indicates a bitwise operation.
  2354.      For them, this optimization is safe only if
  2355.      both args are zero-extended or both are sign-extended.
  2356.      Otherwise, we might change the result.
  2357.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  2358.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  2359.  
  2360.       if (shorten)
  2361.     {
  2362.       int unsigned0, unsigned1;
  2363.       tree arg0 = get_narrower (op0, &unsigned0);
  2364.       tree arg1 = get_narrower (op1, &unsigned1);
  2365.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  2366.       int uns = TREE_UNSIGNED (result_type);
  2367.       tree type;
  2368.  
  2369.       final_type = result_type;
  2370.  
  2371.       /* Handle the case that OP0 does not *contain* a conversion
  2372.          but it *requires* conversion to FINAL_TYPE.  */
  2373.  
  2374.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  2375.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  2376.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  2377.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  2378.  
  2379.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  2380.  
  2381.       /* For bitwise operations, signedness of nominal type
  2382.          does not matter.  Consider only how operands were extended.  */
  2383.       if (shorten == -1)
  2384.         uns = unsigned0;
  2385.  
  2386.       /* Note that in all three cases below we refrain from optimizing
  2387.          an unsigned operation on sign-extended args.
  2388.          That would not be valid.  */
  2389.  
  2390.       /* Both args variable: if both extended in same way
  2391.          from same width, do it in that width.
  2392.          Do it unsigned if args were zero-extended.  */
  2393.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  2394.            < TYPE_PRECISION (result_type))
  2395.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  2396.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  2397.           && unsigned0 == unsigned1
  2398.           && (unsigned0 || !uns))
  2399.         result_type
  2400.           = signed_or_unsigned_type (unsigned0,
  2401.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  2402.       else if (TREE_CODE (arg0) == INTEGER_CST
  2403.            && (unsigned1 || !uns)
  2404.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  2405.                < TYPE_PRECISION (result_type))
  2406.            && (type = signed_or_unsigned_type (unsigned1,
  2407.                                TREE_TYPE (arg1)),
  2408.                int_fits_type_p (arg0, type)))
  2409.         result_type = type;
  2410.       else if (TREE_CODE (arg1) == INTEGER_CST
  2411.            && (unsigned0 || !uns)
  2412.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  2413.                < TYPE_PRECISION (result_type))
  2414.            && (type = signed_or_unsigned_type (unsigned0,
  2415.                                TREE_TYPE (arg0)),
  2416.                int_fits_type_p (arg1, type)))
  2417.         result_type = type;
  2418.     }
  2419.  
  2420.       /* Shifts can be shortened if shifting right.  */
  2421.  
  2422.       if (short_shift)
  2423.     {
  2424.       int unsigned_arg;
  2425.       tree arg0 = get_narrower (op0, &unsigned_arg);
  2426.  
  2427.       final_type = result_type;
  2428.  
  2429.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  2430.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  2431.  
  2432.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  2433.           /* If arg is sign-extended and then unsigned-shifted,
  2434.          we can simulate this with a signed shift in arg's type
  2435.          only if the extended result is at least twice as wide
  2436.          as the arg.  Otherwise, the shift could use up all the
  2437.          ones made by sign-extension and bring in zeros.
  2438.          We can't optimize that case at all, but in most machines
  2439.          it never happens because available widths are 2**N.  */
  2440.           && (!TREE_UNSIGNED (final_type)
  2441.           || unsigned_arg
  2442.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  2443.         {
  2444.           /* Do an unsigned shift if the operand was zero-extended.  */
  2445.           result_type
  2446.         = signed_or_unsigned_type (unsigned_arg,
  2447.                        TREE_TYPE (arg0));
  2448.           /* Convert value-to-be-shifted to that type.  */
  2449.           if (TREE_TYPE (op0) != result_type)
  2450.         op0 = convert (result_type, op0);
  2451.           converted = 1;
  2452.         }
  2453.     }
  2454.  
  2455.       /* Comparison operations are shortened too but differently.
  2456.      They identify themselves by setting short_compare = 1.  */
  2457.  
  2458.       if (short_compare)
  2459.     {
  2460.       /* Don't write &op0, etc., because that would prevent op0
  2461.          from being kept in a register.
  2462.          Instead, make copies of the our local variables and
  2463.          pass the copies by reference, then copy them back afterward.  */
  2464.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  2465.       enum tree_code xresultcode = resultcode;
  2466.       tree val 
  2467.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  2468.       if (val != 0)
  2469.         return val;
  2470.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  2471.       resultcode = xresultcode;
  2472.     }
  2473.     }
  2474.  
  2475.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  2476.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  2477.      Then the expression will be built.
  2478.      It will be given type FINAL_TYPE if that is nonzero;
  2479.      otherwise, it will be given type RESULT_TYPE.  */
  2480.  
  2481.   if (!result_type)
  2482.     {
  2483.       binary_op_error (error_code);
  2484.       return error_mark_node;
  2485.     }
  2486.  
  2487.   if (! converted)
  2488.     {
  2489.       if (TREE_TYPE (op0) != result_type)
  2490.     op0 = convert (result_type, op0); 
  2491.       if (TREE_TYPE (op1) != result_type)
  2492.     op1 = convert (result_type, op1); 
  2493.     }
  2494.  
  2495.   {
  2496.     register tree result = build (resultcode, result_type, op0, op1);
  2497.     register tree folded;
  2498.  
  2499.     folded = fold (result);
  2500.     if (folded == result)
  2501.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2502.     if (final_type != 0)
  2503.       return convert (final_type, folded);
  2504.     return folded;
  2505.   }
  2506. }
  2507.  
  2508. /* Return a tree for the sum or difference (RESULTCODE says which)
  2509.    of pointer PTROP and integer INTOP.  */
  2510.  
  2511. static tree
  2512. pointer_int_sum (resultcode, ptrop, intop)
  2513.      enum tree_code resultcode;
  2514.      register tree ptrop, intop;
  2515. {
  2516.   tree size_exp;
  2517.  
  2518.   register tree result;
  2519.   register tree folded;
  2520.  
  2521.   /* The result is a pointer of the same type that is being added.  */
  2522.  
  2523.   register tree result_type = TREE_TYPE (ptrop);
  2524.  
  2525.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  2526.     {
  2527.       if (pedantic || warn_pointer_arith)
  2528.     pedwarn ("pointer of type `void *' used in arithmetic");
  2529.       size_exp = integer_one_node;
  2530.     }
  2531.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  2532.     {
  2533.       if (pedantic || warn_pointer_arith)
  2534.     pedwarn ("pointer to a function used in arithmetic");
  2535.       size_exp = integer_one_node;
  2536.     }
  2537.   else
  2538.     size_exp = c_size_in_bytes (TREE_TYPE (result_type));
  2539.  
  2540.   /* If what we are about to multiply by the size of the elements
  2541.      contains a constant term, apply distributive law
  2542.      and multiply that constant term separately.
  2543.      This helps produce common subexpressions.  */
  2544.  
  2545.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  2546.       && ! TREE_CONSTANT (intop)
  2547.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  2548.       && TREE_CONSTANT (size_exp))
  2549.     {
  2550.       enum tree_code subcode = resultcode;
  2551.       if (TREE_CODE (intop) == MINUS_EXPR)
  2552.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  2553.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1));
  2554.       intop = TREE_OPERAND (intop, 0);
  2555.     }
  2556.  
  2557.   /* Convert the integer argument to a type the same size as a pointer
  2558.      so the multiply won't overflow spuriously.  */
  2559.  
  2560.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  2561.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  2562.  
  2563.   /* Replace the integer argument
  2564.      with a suitable product by the object size.  */
  2565.  
  2566.   intop = build_binary_op (MULT_EXPR, intop, size_exp);
  2567.  
  2568.   /* Create the sum or difference.  */
  2569.  
  2570.   result = build (resultcode, result_type, ptrop, intop);
  2571.  
  2572.   folded = fold (result);
  2573.   if (folded == result)
  2574.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  2575.   return folded;
  2576. }
  2577.  
  2578. /* Return a tree for the difference of pointers OP0 and OP1.
  2579.    The resulting tree has type int.  */
  2580.  
  2581. static tree
  2582. pointer_diff (op0, op1)
  2583.      register tree op0, op1;
  2584. {
  2585.   register tree result, folded;
  2586.   tree restype = ptrdiff_type_node;
  2587.  
  2588.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  2589.  
  2590.   if (pedantic || warn_pointer_arith)
  2591.     {
  2592.       if (TREE_CODE (target_type) == VOID_TYPE)
  2593.     pedwarn ("pointer of type `void *' used in subtraction");
  2594.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  2595.     pedwarn ("pointer to a function used in subtraction");
  2596.     }
  2597.  
  2598.   /* First do the subtraction as integers;
  2599.      then drop through to build the divide operator.  */
  2600.  
  2601.   op0 = build_binary_op (MINUS_EXPR,
  2602.              convert (restype, op0), convert (restype, op1));
  2603.   op1 = c_size_in_bytes (target_type);
  2604.  
  2605.   /* Divide by the size, in easiest possible way.  */
  2606.  
  2607.   result = build (EXACT_DIV_EXPR, restype, op0, op1);
  2608.  
  2609.   folded = fold (result);
  2610.   if (folded == result)
  2611.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2612.   return folded;
  2613. }
  2614.  
  2615. /* Construct and perhaps optimize a tree representation
  2616.    for a unary operation.  CODE, a tree_code, specifies the operation
  2617.    and XARG is the operand.  NOCONVERT nonzero suppresses
  2618.    the default promotions (such as from short to int).  */
  2619.  
  2620. tree
  2621. build_unary_op (code, xarg, noconvert)
  2622.      enum tree_code code;
  2623.      tree xarg;
  2624.      int noconvert;
  2625. {
  2626.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  2627.   register tree arg = xarg;
  2628.   register tree argtype = 0;
  2629.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  2630.   char *errstring = NULL;
  2631.   tree val;
  2632.  
  2633.   if (typecode == ERROR_MARK)
  2634.     return error_mark_node;
  2635.   if (typecode == ENUMERAL_TYPE)
  2636.     typecode = INTEGER_TYPE;
  2637.  
  2638.   switch (code)
  2639.     {
  2640.     case CONVERT_EXPR:
  2641.       /* This is used for unary plus, because a CONVERT_EXPR
  2642.      is enough to prevent anybody from looking inside for
  2643.      associativity, but won't generate any code.  */
  2644.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2645.         errstring = "wrong type argument to unary plus";
  2646.       else if (!noconvert)
  2647.     arg = default_conversion (arg);
  2648.       break;
  2649.  
  2650.     case NEGATE_EXPR:
  2651.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2652.         errstring = "wrong type argument to unary minus";
  2653.       else if (!noconvert)
  2654.     arg = default_conversion (arg);
  2655.       break;
  2656.  
  2657.     case BIT_NOT_EXPR:
  2658.       if (typecode != INTEGER_TYPE)
  2659.         errstring = "wrong type argument to bit-complement";
  2660.       else if (!noconvert)
  2661.     arg = default_conversion (arg);
  2662.       break;
  2663.  
  2664.     case ABS_EXPR:
  2665.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  2666.         errstring = "wrong type argument to abs";
  2667.       else if (!noconvert)
  2668.     arg = default_conversion (arg);
  2669.       break;
  2670.  
  2671.     case TRUTH_NOT_EXPR:
  2672.       if (typecode != INTEGER_TYPE
  2673.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  2674.       /* These will convert to a pointer.  */
  2675.       && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
  2676.     {
  2677.       errstring = "wrong type argument to unary exclamation mark";
  2678.       break;
  2679.     }
  2680.       arg = truthvalue_conversion (arg);
  2681.       return invert_truthvalue (arg);
  2682.  
  2683.     case NOP_EXPR:
  2684.       break;
  2685.       
  2686.     case PREINCREMENT_EXPR:
  2687.     case POSTINCREMENT_EXPR:
  2688.     case PREDECREMENT_EXPR:
  2689.     case POSTDECREMENT_EXPR:
  2690.       /* Handle complex lvalues (when permitted)
  2691.      by reduction to simpler cases.  */
  2692.  
  2693.       val = unary_complex_lvalue (code, arg);
  2694.       if (val != 0)
  2695.     return val;
  2696.  
  2697.       /* Report invalid types.  */
  2698.  
  2699.       if (typecode != POINTER_TYPE
  2700.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2701.     {
  2702.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2703.         errstring ="wrong type argument to increment";
  2704.       else
  2705.         errstring ="wrong type argument to decrement";
  2706.       break;
  2707.     }
  2708.  
  2709.       {
  2710.     register tree inc;
  2711.     tree result_type = TREE_TYPE (arg);
  2712.  
  2713.     arg = get_unwidened (arg, 0);
  2714.     argtype = TREE_TYPE (arg);
  2715.  
  2716.     /* Compute the increment.  */
  2717.  
  2718.     if (typecode == POINTER_TYPE)
  2719.       {
  2720.         if (pedantic
  2721.         && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
  2722.             || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
  2723.           pedwarn ("wrong type argument to %s",
  2724.                ((code == PREINCREMENT_EXPR
  2725.              || code == POSTINCREMENT_EXPR)
  2726.             ? "increment" : "decrement"));
  2727.         inc = c_sizeof_nowarn (TREE_TYPE (result_type));
  2728.       }
  2729.     else
  2730.       inc = integer_one_node;
  2731.  
  2732.     inc = convert (argtype, inc);
  2733.  
  2734.     /* Handle incrementing a cast-expression.  */
  2735.  
  2736.     while (1)
  2737.       switch (TREE_CODE (arg))
  2738.         {
  2739.         case NOP_EXPR:
  2740.         case CONVERT_EXPR:
  2741.         case FLOAT_EXPR:
  2742.         case FIX_TRUNC_EXPR:
  2743.         case FIX_FLOOR_EXPR:
  2744.         case FIX_ROUND_EXPR:
  2745.         case FIX_CEIL_EXPR:
  2746.           /* If the real type has the same machine representation
  2747.          as the type it is cast to, we can make better output
  2748.          by adding directly to the inside of the cast.  */
  2749.           if ((TREE_CODE (TREE_TYPE (arg))
  2750.            == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
  2751.           && (TYPE_MODE (TREE_TYPE (arg))
  2752.               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
  2753.         arg = TREE_OPERAND (arg, 0);
  2754.           else
  2755.         {
  2756.           tree incremented, modify, value;
  2757.           pedantic_lvalue_warning (CONVERT_EXPR);
  2758.           arg = stabilize_reference (arg);
  2759.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2760.             value = arg;
  2761.           else
  2762.             value = save_expr (arg);
  2763.           incremented = build (((code == PREINCREMENT_EXPR
  2764.                      || code == POSTINCREMENT_EXPR)
  2765.                     ? PLUS_EXPR : MINUS_EXPR),
  2766.                        argtype, value, inc);
  2767.           TREE_SIDE_EFFECTS (incremented) = 1;
  2768.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2769.           value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2770.           TREE_USED (value) = 1;
  2771.           return value;
  2772.         }
  2773.           break;
  2774.  
  2775.         default:
  2776.           goto give_up;
  2777.         }
  2778.       give_up:
  2779.  
  2780.     /* Complain about anything else that is not a true lvalue.  */
  2781.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2782.                     || code == POSTINCREMENT_EXPR)
  2783.                    ? "increment" : "decrement")))
  2784.       return error_mark_node;
  2785.  
  2786.     /* Report a read-only lvalue.  */
  2787.     if (TYPE_READONLY (TREE_TYPE (arg)))
  2788.       readonly_warning (arg, 
  2789.                 ((code == PREINCREMENT_EXPR
  2790.                   || code == POSTINCREMENT_EXPR)
  2791.                  ? "increment" : "decrement"));
  2792.  
  2793.     val = build (code, TREE_TYPE (arg), arg, inc);
  2794.     TREE_SIDE_EFFECTS (val) = 1;
  2795.     val = convert (result_type, val);
  2796.     if (TREE_CODE (val) != code)
  2797.       TREE_NO_UNUSED_WARNING (val) = 1;
  2798.     return val;
  2799.       }
  2800.  
  2801.     case ADDR_EXPR:
  2802.       /* Note that this operation never does default_conversion
  2803.      regardless of NOCONVERT.  */
  2804.  
  2805.       /* Let &* cancel out to simplify resulting code.  */
  2806.       if (TREE_CODE (arg) == INDIRECT_REF)
  2807.     {
  2808.       /* Don't let this be an lvalue.  */
  2809.       if (lvalue_p (TREE_OPERAND (arg, 0)))
  2810.         return non_lvalue (TREE_OPERAND (arg, 0));
  2811.       return TREE_OPERAND (arg, 0);
  2812.     }
  2813.  
  2814.       /* For &x[y], return x+y */
  2815.       if (TREE_CODE (arg) == ARRAY_REF)
  2816.     {
  2817.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  2818.         return error_mark_node;
  2819.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2820.                   TREE_OPERAND (arg, 1));
  2821.     }
  2822.  
  2823.       /* Handle complex lvalues (when permitted)
  2824.      by reduction to simpler cases.  */
  2825.       val = unary_complex_lvalue (code, arg);
  2826.       if (val != 0)
  2827.     return val;
  2828.  
  2829.       /* Address of a cast is just a cast of the address
  2830.      of the operand of the cast.  */
  2831.       switch (TREE_CODE (arg))
  2832.     {
  2833.     case NOP_EXPR:
  2834.     case CONVERT_EXPR:
  2835.     case FLOAT_EXPR:
  2836.     case FIX_TRUNC_EXPR:
  2837.     case FIX_FLOOR_EXPR:
  2838.     case FIX_ROUND_EXPR:
  2839.     case FIX_CEIL_EXPR:
  2840.       if (pedantic)
  2841.         pedwarn ("ANSI C forbids the address of a cast expression");
  2842.       return convert (build_pointer_type (TREE_TYPE (arg)),
  2843.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  2844.                       0));
  2845.     }
  2846.  
  2847.       /* Allow the address of a constructor if all the elements
  2848.      are constant.  */
  2849.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  2850.     ;
  2851.       /* Anything not already handled and not a true memory reference
  2852.      is an error.  */
  2853.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  2854.     return error_mark_node;
  2855.  
  2856.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  2857.       argtype = TREE_TYPE (arg);
  2858. #ifdef NeXT
  2859.       /* If the lvalue is const or volatile,
  2860.      merge that into the type that the address will point to.  */
  2861.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  2862.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  2863.     {
  2864.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  2865.         argtype = c_build_type_variant (argtype,
  2866.                         TREE_READONLY (arg),
  2867.                         TREE_THIS_VOLATILE (arg));
  2868.     }
  2869. #else /* NeXT */
  2870.       if (TYPE_READONLY (TREE_TYPE (arg)) || TYPE_VOLATILE (TREE_TYPE (arg)))
  2871.     argtype = c_build_type_variant (argtype,
  2872.                     TYPE_READONLY (TREE_TYPE (arg)),
  2873.                     TYPE_VOLATILE (TREE_TYPE (arg)));
  2874. #endif /* NeXT */
  2875.  
  2876.       argtype = build_pointer_type (argtype);
  2877.  
  2878.       if (mark_addressable (arg) == 0)
  2879.     return error_mark_node;
  2880.  
  2881.       {
  2882.     tree addr;
  2883.  
  2884.     if (TREE_CODE (arg) == COMPONENT_REF)
  2885.       {
  2886.         tree field = TREE_OPERAND (arg, 1);
  2887.  
  2888.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  2889.  
  2890.         if (DECL_BIT_FIELD (field))
  2891.           {
  2892.         error ("attempt to take address of bit-field structure member `%s'",
  2893.                IDENTIFIER_POINTER (DECL_NAME (field)));
  2894.         return error_mark_node;
  2895.           }
  2896.  
  2897.         addr = convert (argtype, addr);
  2898.  
  2899.         if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  2900.           {
  2901.         tree offset
  2902.           = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  2903.                 size_int (BITS_PER_UNIT));
  2904.         int flag = TREE_CONSTANT (addr);
  2905.         addr = fold (build (PLUS_EXPR, argtype,
  2906.                     addr, convert (argtype, offset)));
  2907.         TREE_CONSTANT (addr) = flag;
  2908.           }
  2909.       }
  2910.     else
  2911.       addr = build1 (code, argtype, arg);
  2912.  
  2913.     /* Address of a static or external variable or
  2914.        function counts as a constant */
  2915.     TREE_CONSTANT (addr) = staticp (arg);
  2916.     return addr;
  2917.       }
  2918.     }
  2919.  
  2920.   if (!errstring)
  2921.     {
  2922.       if (argtype == 0)
  2923.     argtype = TREE_TYPE (arg);
  2924.       return fold (build1 (code, argtype, arg));
  2925.     }
  2926.  
  2927.   error (errstring);
  2928.   return error_mark_node;
  2929. }
  2930.  
  2931. #if 0
  2932. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  2933.    convert ARG with the same conversions in the same order
  2934.    and return the result.  */
  2935.  
  2936. static tree
  2937. convert_sequence (conversions, arg)
  2938.      tree conversions;
  2939.      tree arg;
  2940. {
  2941.   switch (TREE_CODE (conversions))
  2942.     {
  2943.     case NOP_EXPR:
  2944.     case CONVERT_EXPR:
  2945.     case FLOAT_EXPR:
  2946.     case FIX_TRUNC_EXPR:
  2947.     case FIX_FLOOR_EXPR:
  2948.     case FIX_ROUND_EXPR:
  2949.     case FIX_CEIL_EXPR:
  2950.       return convert (TREE_TYPE (conversions),
  2951.               convert_sequence (TREE_OPERAND (conversions, 0),
  2952.                     arg));
  2953.  
  2954.     default:
  2955.       return arg;
  2956.     }
  2957. }
  2958. #endif /* 0 */
  2959.  
  2960. /* Return nonzero if REF is an lvalue valid for this language.
  2961.    Lvalues can be assigned, unless their type has TYPE_READONLY.
  2962.    Lvalues can have their address taken, unless they have TREE_REGDECL.  */
  2963.  
  2964. int
  2965. lvalue_p (ref)
  2966.      tree ref;
  2967. {
  2968.   register enum tree_code code = TREE_CODE (ref);
  2969.  
  2970.   switch (code)
  2971.     {
  2972.     case COMPONENT_REF:
  2973.       return lvalue_p (TREE_OPERAND (ref, 0));
  2974.  
  2975.     case STRING_CST:
  2976.       return 1;
  2977.  
  2978.     case INDIRECT_REF:
  2979.     case ARRAY_REF:
  2980.     case VAR_DECL:
  2981.     case PARM_DECL:
  2982.     case RESULT_DECL:
  2983.     case ERROR_MARK:
  2984.       if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  2985.       && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  2986.     return 1;
  2987.       break;
  2988.     }
  2989.   return 0;
  2990. }
  2991.  
  2992. /* Return nonzero if REF is an lvalue valid for this language;
  2993.    otherwise, print an error message and return zero.  */
  2994.  
  2995. int
  2996. lvalue_or_else (ref, string)
  2997.      tree ref;
  2998.      char *string;
  2999. {
  3000.   int win = lvalue_p (ref);
  3001.   if (! win)
  3002.     error ("invalid lvalue in %s", string);
  3003.   return win;
  3004. }
  3005.  
  3006. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  3007.    for certain kinds of expressions which are not really lvalues
  3008.    but which we can accept as lvalues.
  3009.  
  3010.    If ARG is not a kind of expression we can handle, return zero.  */
  3011.    
  3012. static tree
  3013. unary_complex_lvalue (code, arg)
  3014.      enum tree_code code;
  3015.      tree arg;
  3016. {
  3017.   /* Handle (a, b) used as an "lvalue".  */
  3018.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  3019.     {
  3020.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  3021.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3022.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  3023.             TREE_OPERAND (arg, 0), real_result);
  3024.     }
  3025.  
  3026.   /* Handle (a ? b : c) used as an "lvalue".  */
  3027.   if (TREE_CODE (arg) == COND_EXPR)
  3028.     {
  3029.       pedantic_lvalue_warning (COND_EXPR);
  3030.       return (build_conditional_expr
  3031.           (TREE_OPERAND (arg, 0),
  3032.            build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  3033.            build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  3034.     }
  3035.  
  3036.   return 0;
  3037. }
  3038.  
  3039. /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
  3040.    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
  3041.  
  3042. static void
  3043. pedantic_lvalue_warning (code)
  3044.      enum tree_code code;
  3045. {
  3046.   if (pedantic)
  3047.     pedwarn ("ANSI C forbids use of %s expressions as lvalues",
  3048.          code == COND_EXPR ? "conditional"
  3049.          : code == COMPOUND_EXPR ? "compound" : "cast");
  3050. }
  3051.  
  3052. /* Warn about storing in something that is `const'.  */
  3053.  
  3054. void
  3055. readonly_warning (arg, string)
  3056.      tree arg;
  3057.      char *string;
  3058. {
  3059.   char buf[80];
  3060.   strcpy (buf, string);
  3061.  
  3062.   if (TREE_CODE (arg) == COMPONENT_REF)
  3063.     {
  3064.       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
  3065.     readonly_warning (TREE_OPERAND (arg, 0), string);
  3066.       else
  3067.     {
  3068.       strcat (buf, " of read-only member `%s'");
  3069.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  3070.     }
  3071.     }
  3072.   else if (TREE_CODE (arg) == VAR_DECL)
  3073.     {
  3074.       strcat (buf, " of read-only variable `%s'");
  3075.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  3076.     }
  3077.   else
  3078.     {
  3079.       pedwarn ("%s of read-only location", buf);
  3080.     }
  3081. }
  3082.  
  3083. /* Mark EXP saying that we need to be able to take the
  3084.    address of it; it should not be allocated in a register.
  3085.    Value is 1 if successful.  */
  3086.  
  3087. int
  3088. mark_addressable (exp)
  3089.      tree exp;
  3090. {
  3091.   register tree x = exp;
  3092.   while (1)
  3093.     switch (TREE_CODE (x))
  3094.       {
  3095.       case ADDR_EXPR:
  3096.       case COMPONENT_REF:
  3097.       case ARRAY_REF:
  3098.     x = TREE_OPERAND (x, 0);
  3099.     break;
  3100.  
  3101.       case VAR_DECL:
  3102.       case CONST_DECL:
  3103.       case PARM_DECL:
  3104.       case RESULT_DECL:
  3105.     if (TREE_REGDECL (x) && !TREE_ADDRESSABLE (x))
  3106.       {
  3107.         if (TREE_PUBLIC (x))
  3108.           {
  3109.         error ("address of global register variable `%s' requested",
  3110.                IDENTIFIER_POINTER (DECL_NAME (x)));
  3111.         return 0;
  3112.           }
  3113.         pedwarn ("address of register variable `%s' requested",
  3114.              IDENTIFIER_POINTER (DECL_NAME (x)));
  3115.       }
  3116.     put_var_into_stack (x);
  3117.  
  3118.     /* drops in */
  3119.       case FUNCTION_DECL:
  3120.     TREE_ADDRESSABLE (x) = 1;
  3121. #if 0  /* poplevel deals with this now.  */
  3122.     if (DECL_CONTEXT (x) == 0)
  3123.       TREE_ADDRESSABLE (DECL_NAME (x)) = 1;
  3124. #endif
  3125.  
  3126.       default:
  3127.     return 1;
  3128.     }
  3129. }
  3130.  
  3131. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  3132.  
  3133. tree
  3134. build_conditional_expr (ifexp, op1, op2)
  3135.      tree ifexp, op1, op2;
  3136. {
  3137.   register tree type1;
  3138.   register tree type2;
  3139.   register enum tree_code code1;
  3140.   register enum tree_code code2;
  3141.   register tree result_type = NULL;
  3142.  
  3143.   /* If second operand is omitted, it is the same as the first one;
  3144.      make sure it is calculated only once.  */
  3145.   if (op1 == 0)
  3146.     {
  3147.       if (pedantic)
  3148.     pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
  3149.       ifexp = op1 = save_expr (ifexp);
  3150.     }
  3151.  
  3152.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  3153.  
  3154.   if (TREE_CODE (ifexp) == ERROR_MARK
  3155.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  3156.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  3157.     return error_mark_node;
  3158.  
  3159. #if 0 /* Produces wrong result if within sizeof.  */
  3160.   /* Don't promote the operands separately if they promote
  3161.      the same way.  Return the unpromoted type and let the combined
  3162.      value get promoted if necessary.  */
  3163.  
  3164.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  3165.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  3166.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  3167.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  3168.     {
  3169.       if (TREE_CODE (ifexp) == INTEGER_CST)
  3170.     return (integer_zerop (ifexp) ? op2 : op1);
  3171.  
  3172.       return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
  3173.     }
  3174. #endif
  3175.  
  3176.   /* They don't match; promote them both and then try to reconcile them.  */
  3177.  
  3178.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  3179.     op1 = default_conversion (op1);
  3180.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  3181.     op2 = default_conversion (op2);
  3182.  
  3183.   type1 = TREE_TYPE (op1);
  3184.   code1 = TREE_CODE (type1);
  3185.   type2 = TREE_TYPE (op2);
  3186.   code2 = TREE_CODE (type2);
  3187.       
  3188.   /* Quickly detect the usual case where op1 and op2 have the same type
  3189.      after promotion.  */
  3190.   if (type1 == type2)
  3191.     result_type = type1;
  3192.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  3193.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  3194.     {
  3195.       result_type = common_type (type1, type2);
  3196.     }
  3197.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  3198.     {
  3199.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  3200.     pedwarn ("ANSI C forbids conditional expr with only one void side");
  3201.       result_type = void_type_node;
  3202.     }
  3203.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  3204.     {
  3205.       if (comp_target_types (type1, type2))
  3206.     result_type = common_type (type1, type2);
  3207.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node)
  3208.     result_type = qualify_type (type2, type1);
  3209.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node)
  3210.     result_type = qualify_type (type1, type2);
  3211.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  3212.     {
  3213.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  3214.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3215.       result_type = qualify_type (type1, type2);
  3216.     }
  3217.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  3218.     {
  3219.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  3220.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3221.       result_type = qualify_type (type2, type1);
  3222.     }
  3223.       else
  3224.     {
  3225.       pedwarn ("pointer type mismatch in conditional expression");
  3226.       result_type = build_pointer_type (void_type_node);
  3227.     }
  3228.     }
  3229.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  3230.     {
  3231.       if (! integer_zerop (op2))
  3232.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3233.       else
  3234.     {
  3235.       op2 = null_pointer_node;
  3236. #if 0  /* The spec seems to say this is permitted.  */
  3237.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  3238.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3239. #endif
  3240.     }
  3241.       result_type = type1;
  3242.     }
  3243.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3244.     {
  3245.       if (!integer_zerop (op1))
  3246.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3247.       else
  3248.     {
  3249.       op1 = null_pointer_node;
  3250. #if 0  /* The spec seems to say this is permitted.  */
  3251.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  3252.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3253. #endif
  3254.     }
  3255.       result_type = type2;
  3256.     }
  3257.  
  3258.   if (!result_type)
  3259.     {
  3260.       if (flag_cond_mismatch)
  3261.     result_type = void_type_node;
  3262.       else
  3263.     {
  3264.       error ("type mismatch in conditional expression");
  3265.       return error_mark_node;
  3266.     }
  3267.     }
  3268.  
  3269.   if (result_type != TREE_TYPE (op1))
  3270.     op1 = convert (result_type, op1);
  3271.   if (result_type != TREE_TYPE (op2))
  3272.     op2 = convert (result_type, op2);
  3273.     
  3274. #if 0
  3275.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  3276.     {
  3277.       result_type = TREE_TYPE (op1);
  3278.       if (TREE_CONSTANT (ifexp))
  3279.     return (integer_zerop (ifexp) ? op2 : op1);
  3280.  
  3281.       if (TYPE_MODE (result_type) == BLKmode)
  3282.     {
  3283.       register tree tempvar
  3284.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  3285.       register tree xop1 = build_modify_expr (tempvar, op1);
  3286.       register tree xop2 = build_modify_expr (tempvar, op2);
  3287.       register tree result = fold (build (COND_EXPR, result_type,
  3288.                           ifexp, xop1, xop2));
  3289.  
  3290.       layout_decl (tempvar, TYPE_ALIGN (result_type));
  3291.       /* No way to handle variable-sized objects here.
  3292.          I fear that the entire handling of BLKmode conditional exprs
  3293.          needs to be redone.  */
  3294.       if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
  3295.         abort ();
  3296.       DECL_RTL (tempvar)
  3297.         = assign_stack_local (DECL_MODE (tempvar),
  3298.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  3299.                    + BITS_PER_UNIT - 1)
  3300.                   / BITS_PER_UNIT,
  3301.                   0);
  3302.  
  3303.       TREE_SIDE_EFFECTS (result)
  3304.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  3305.           | TREE_SIDE_EFFECTS (op2);
  3306.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  3307.     }
  3308.     }
  3309. #endif /* 0 */
  3310.  
  3311.   if (TREE_CODE (ifexp) == INTEGER_CST)
  3312.     return (integer_zerop (ifexp) ? op2 : op1);
  3313.   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
  3314. }
  3315.  
  3316. /* Given a list of expressions, return a compound expression
  3317.    that performs them all and returns the value of the last of them.  */
  3318.  
  3319. tree
  3320. build_compound_expr (list)
  3321.      tree list;
  3322. {
  3323.   register tree rest;
  3324.  
  3325.   if (TREE_CHAIN (list) == 0)
  3326.     {
  3327. #if 0 /* If something inside inhibited lvalueness, we shoukd not override.  */
  3328.       /* Consider (x, y+0), which is not an lvalue since y+0 is not.  */
  3329.  
  3330.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3331.       if (TREE_CODE (list) == NON_LVALUE_EXPR)
  3332.     list = TREE_OPERAND (list, 0);
  3333. #endif
  3334.  
  3335.     return TREE_VALUE (list);
  3336.     }
  3337.  
  3338.   if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
  3339.     {
  3340.       /* Convert arrays to pointers when there really is a comma operator.  */
  3341.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
  3342.     TREE_VALUE (TREE_CHAIN (list))
  3343.       = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
  3344.     }
  3345.  
  3346.   rest = build_compound_expr (TREE_CHAIN (list));
  3347.  
  3348.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
  3349.     return rest;
  3350.  
  3351.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  3352. }
  3353.  
  3354. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  3355.  
  3356. tree
  3357. build_c_cast (type, expr)
  3358.      register tree type;
  3359.      tree expr;
  3360. {
  3361.   register tree value = expr;
  3362.   
  3363.   if (type == error_mark_node || expr == error_mark_node)
  3364.     return error_mark_node;
  3365.   type = TYPE_MAIN_VARIANT (type);
  3366.  
  3367. #if 0
  3368.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3369.   if (TREE_CODE (value) == NON_LVALUE_EXPR)
  3370.     value = TREE_OPERAND (value, 0);
  3371. #endif
  3372.  
  3373.   if (TREE_CODE (type) == ARRAY_TYPE)
  3374.     {
  3375.       error ("cast specifies array type");
  3376.       return error_mark_node;
  3377.     }
  3378.  
  3379.   if (TREE_CODE (type) == FUNCTION_TYPE)
  3380.     {
  3381.       error ("cast specifies function type");
  3382.       return error_mark_node;
  3383.     }
  3384.  
  3385.   if (type == TREE_TYPE (value))
  3386.     {
  3387.       if (pedantic)
  3388.     {
  3389.       if (TREE_CODE (type) == RECORD_TYPE
  3390.           || TREE_CODE (type) == UNION_TYPE)
  3391.         pedwarn ("ANSI C forbids casting nonscalar to the same type");
  3392.     }
  3393.     }
  3394.   else if (TREE_CODE (type) == UNION_TYPE)
  3395.     {
  3396.       tree field;
  3397.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  3398.     if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
  3399.                TYPE_MAIN_VARIANT (TREE_TYPE (value))))
  3400.       break;
  3401.  
  3402.       if (field)
  3403.     {
  3404.       tree nvalue = build1 (CONVERT_EXPR, type, value);
  3405.       TREE_CONSTANT (nvalue) = TREE_CONSTANT (value);
  3406.       if (pedantic)
  3407.         pedwarn ("ANSI C forbids casts to union type");
  3408.       return nvalue;
  3409.     }
  3410.       error ("cast to union type from type not present in union");
  3411.       return error_mark_node;
  3412.     }
  3413.   else
  3414.     {
  3415.       tree otype;
  3416.       /* Convert functions and arrays to pointers,
  3417.      but don't convert any other types.  */
  3418.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  3419.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
  3420.     value = default_conversion (value);
  3421.       otype = TREE_TYPE (value);
  3422.  
  3423.       /* Optionally warn about potentially worrysome casts.  */
  3424.  
  3425.       if (warn_cast_qual
  3426.       && TREE_CODE (type) == POINTER_TYPE
  3427.       && TREE_CODE (otype) == POINTER_TYPE)
  3428.     {
  3429.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  3430.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  3431.         pedwarn ("cast discards `volatile' from pointer target type");
  3432.       if (TYPE_READONLY (TREE_TYPE (otype))
  3433.           && ! TYPE_READONLY (TREE_TYPE (type)))
  3434.         pedwarn ("cast discards `const' from pointer target type");
  3435.     }
  3436.  
  3437.       /* Warn about possible alignment problems.  */
  3438. #ifdef STRICT_ALIGNMENT
  3439.       if (warn_cast_align
  3440.       && TREE_CODE (type) == POINTER_TYPE
  3441.       && TREE_CODE (otype) == POINTER_TYPE
  3442.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  3443.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  3444.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  3445.     warning ("cast increases required alignment of target type");
  3446. #endif
  3447.  
  3448.       if (TREE_CODE (type) == INTEGER_TYPE
  3449.       && TREE_CODE (otype) == POINTER_TYPE
  3450.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
  3451.     warning ("cast from pointer to integer of different size");
  3452.  
  3453.       if (TREE_CODE (type) == POINTER_TYPE
  3454.       && TREE_CODE (otype) == INTEGER_TYPE
  3455.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
  3456.     warning ("cast to pointer from integer of different size");
  3457.  
  3458.       value = convert (type, value);
  3459.     }
  3460.  
  3461.   if (value == expr && pedantic)
  3462.     {
  3463.       /* If pedantic, don't let a cast be an lvalue.  */
  3464.       return non_lvalue (value);
  3465.     }
  3466.   return value;
  3467. }
  3468.  
  3469. /* Build an assignment expression of lvalue LHS from value RHS.
  3470.    MODIFYCODE is the code for a binary operator that we use
  3471.    to combine the old value of LHS with RHS to get the new value.
  3472.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  3473.  
  3474. tree
  3475. build_modify_expr (lhs, modifycode, rhs)
  3476.      tree lhs, rhs;
  3477.      enum tree_code modifycode;
  3478. {
  3479.   register tree result;
  3480.   tree newrhs;
  3481.   tree lhstype = TREE_TYPE (lhs);
  3482.   tree olhstype = lhstype;
  3483.  
  3484.   /* Types that aren't fully specified cannot be used in assignments.  */
  3485.   lhs = require_complete_type (lhs);
  3486.  
  3487.   /* Avoid duplicate error messages from operands that had errors.  */
  3488.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  3489.     return error_mark_node;
  3490.  
  3491.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3492.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3493.     rhs = TREE_OPERAND (rhs, 0);
  3494.  
  3495.   newrhs = rhs;
  3496.  
  3497.   /* Handle control structure constructs used as "lvalues".  */
  3498.  
  3499.   switch (TREE_CODE (lhs))
  3500.     {
  3501.       /* Handle (a, b) used as an "lvalue".  */
  3502.     case COMPOUND_EXPR:
  3503.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3504.       return build (COMPOUND_EXPR, lhstype,
  3505.             TREE_OPERAND (lhs, 0),
  3506.             build_modify_expr (TREE_OPERAND (lhs, 1),
  3507.                        modifycode, rhs));
  3508.  
  3509.       /* Handle (a ? b : c) used as an "lvalue".  */
  3510.     case COND_EXPR:
  3511.       pedantic_lvalue_warning (COND_EXPR);
  3512.       rhs = save_expr (rhs);
  3513.       {
  3514.     /* Produce (a ? (b = rhs) : (c = rhs))
  3515.        except that the RHS goes through a save-expr
  3516.        so the code to compute it is only emitted once.  */
  3517.     tree cond
  3518.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  3519.                     build_modify_expr (TREE_OPERAND (lhs, 1),
  3520.                                modifycode, rhs),
  3521.                     build_modify_expr (TREE_OPERAND (lhs, 2),
  3522.                                modifycode, rhs));
  3523.     /* Make sure the code to compute the rhs comes out
  3524.        before the split.  */
  3525.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  3526.               /* But cast it to void to avoid an "unused" error.  */
  3527.               convert (void_type_node, rhs), cond);
  3528.       }
  3529.     }
  3530.  
  3531.   /* If a binary op has been requested, combine the old LHS value with the RHS
  3532.      producing the value we should actually store into the LHS.  */
  3533.  
  3534.   if (modifycode != NOP_EXPR)
  3535.     {
  3536.       lhs = stabilize_reference (lhs);
  3537.       newrhs = build_binary_op (modifycode, lhs, rhs);
  3538.     }
  3539.  
  3540.   /* Handle a cast used as an "lvalue".
  3541.      We have already performed any binary operator using the value as cast.
  3542.      Now convert the result to the true type of the lhs and store there;
  3543.      then cast the result back to the specified type to be the value
  3544.      of the assignment.  */
  3545.  
  3546.   switch (TREE_CODE (lhs))
  3547.     {
  3548.     case NOP_EXPR:
  3549.     case CONVERT_EXPR:
  3550.     case FLOAT_EXPR:
  3551.     case FIX_TRUNC_EXPR:
  3552.     case FIX_FLOOR_EXPR:
  3553.     case FIX_ROUND_EXPR:
  3554.     case FIX_CEIL_EXPR:
  3555.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  3556.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  3557.     newrhs = default_conversion (newrhs);
  3558.       {
  3559.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  3560.     tree result = build_modify_expr (inner_lhs, NOP_EXPR,
  3561.                      convert (TREE_TYPE (inner_lhs),
  3562.                           newrhs));
  3563.     pedantic_lvalue_warning (CONVERT_EXPR);
  3564.     return convert (TREE_TYPE (lhs), result);
  3565.       }
  3566.     }
  3567.  
  3568.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  3569.      Reject anything strange now.  */
  3570.  
  3571.   if (!lvalue_or_else (lhs, "assignment"))
  3572.     return error_mark_node;
  3573.  
  3574.   /* Warn about storing in something that is `const'.  */
  3575.  
  3576.   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  3577.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  3578.        || TREE_CODE (lhstype) == UNION_TYPE)
  3579.       && C_TYPE_FIELDS_READONLY (lhstype)))
  3580.     readonly_warning (lhs, "assignment");
  3581.  
  3582.   /* If storing into a structure or union member,
  3583.      it has probably been given type `int'.
  3584.      Compute the type that would go with
  3585.      the actual amount of storage the member occupies.  */
  3586.  
  3587.   if (TREE_CODE (lhs) == COMPONENT_REF
  3588.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  3589.       || TREE_CODE (lhstype) == REAL_TYPE
  3590.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  3591.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  3592.  
  3593.   /* If storing in a field that is in actuality a short or narrower than one,
  3594.      we must store in the field in its actual type.  */
  3595.  
  3596.   if (lhstype != TREE_TYPE (lhs))
  3597.     {
  3598.       lhs = copy_node (lhs);
  3599.       TREE_TYPE (lhs) = lhstype;
  3600.     }
  3601.  
  3602.   /* Convert new value to destination type.  */
  3603.  
  3604.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  3605.                    NULL_TREE, 0);
  3606.   if (TREE_CODE (newrhs) == ERROR_MARK)
  3607.     return error_mark_node;
  3608.  
  3609.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  3610.   TREE_SIDE_EFFECTS (result) = 1;
  3611.  
  3612.   /* If we got the LHS in a different type for storing in,
  3613.      convert the result back to the nominal type of LHS
  3614.      so that the value we return always has the same type
  3615.      as the LHS argument.  */
  3616.  
  3617.   if (olhstype == TREE_TYPE (result))
  3618.     return result;
  3619.   return convert_for_assignment (olhstype, result, "assignment", NULL_TREE, 0);
  3620. }
  3621.  
  3622. /* Convert value RHS to type TYPE as preparation for an assignment
  3623.    to an lvalue of type TYPE.
  3624.    The real work of conversion is done by `convert'.
  3625.    The purpose of this function is to generate error messages
  3626.    for assignments that are not allowed in C.
  3627.    ERRTYPE is a string to use in error messages:
  3628.    "assignment", "return", etc.
  3629.  
  3630.    FUNNAME is the name of the function being called,
  3631.    as an IDENTIFIER_NODE, or null.
  3632.    PARMNUM is the number of the argument, for printing in error messages.  */
  3633.  
  3634. static tree
  3635. convert_for_assignment (type, rhs, errtype, funname, parmnum)
  3636.      tree type, rhs;
  3637.      char *errtype;
  3638.      tree funname;
  3639.      int parmnum;
  3640. {
  3641.   register enum tree_code codel = TREE_CODE (type);
  3642.   register tree rhstype;
  3643.   register enum tree_code coder;
  3644.  
  3645.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3646.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3647.     rhs = TREE_OPERAND (rhs, 0);
  3648.  
  3649.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  3650.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  3651.     rhs = default_conversion (rhs);
  3652.  
  3653.   rhstype = TREE_TYPE (rhs);
  3654.   coder = TREE_CODE (rhstype);
  3655.  
  3656.   if (coder == ERROR_MARK)
  3657.     return error_mark_node;
  3658.  
  3659.   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  3660.     {
  3661.       /* Check for Objective-C protocols.  */
  3662.       maybe_objc_comptypes (type, rhstype);
  3663.  
  3664.       return rhs;
  3665.     }
  3666.  
  3667.   if (coder == VOID_TYPE)
  3668.     {
  3669.       error ("void value not ignored as it ought to be");
  3670.       return error_mark_node;
  3671.     }
  3672.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  3673.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE)
  3674.        &&
  3675.       (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  3676.     {
  3677.       return convert (type, rhs);
  3678.     }
  3679.   /* Conversions among pointers */
  3680.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  3681.     {
  3682.       register tree ttl = TREE_TYPE (type);
  3683.       register tree ttr = TREE_TYPE (rhstype);
  3684.       /* Any non-function converts to a [const][volatile] void *
  3685.      and vice versa; otherwise, targets must be the same.
  3686.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  3687.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  3688.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  3689.       || comp_target_types (type, rhstype)
  3690.       || (!pedantic      /* Unless pedantic, mix signed and unsigned.  */
  3691.           && TREE_CODE (ttl) == INTEGER_TYPE
  3692.           && TREE_CODE (ttr) == INTEGER_TYPE
  3693.           && TYPE_PRECISION (ttl) == TYPE_PRECISION (ttr)))
  3694.     {
  3695.       if (pedantic
  3696.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  3697.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  3698.           ||
  3699.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  3700.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  3701.         warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
  3702.                  "function pointer and `void *' incompatible in ANSI C; argument %d of `%s'",
  3703.                  errtype, funname, parmnum);
  3704.       /* Const and volatile mean something different for function types,
  3705.          so the usual warnings are not appropriate.  */
  3706.       else if (TREE_CODE (ttr) != FUNCTION_TYPE
  3707.            || TREE_CODE (ttl) != FUNCTION_TYPE)
  3708.         {
  3709.           if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  3710.         warn_for_assignment ("%s of pointer variable discards `const' from target type",
  3711.                      "pointer to const given for argument %d of `%s'",
  3712.                      errtype, funname, parmnum);
  3713.           if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  3714.         warn_for_assignment ("%s of pointer variable discards `volatile' from target type",
  3715.                      "pointer to volatile given for argument %d of `%s'",
  3716.                      errtype, funname, parmnum);
  3717.         }
  3718.       else
  3719.         {
  3720.           /* Because const and volatile on functions are restrictions
  3721.          that say the function will not do certain things,
  3722.          it is okay to use a const or volatile function
  3723.          where an ordinary one is wanted, but not vice-versa.  */
  3724.           if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
  3725.         warn_for_assignment ("%s of `const *' function pointer from non-const",
  3726.                      "pointer to non-const given for argument %d of `%s'",
  3727.                      errtype, funname, parmnum);
  3728.           if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
  3729.         warn_for_assignment ("%s of `volatile *' function pointer from non-volatile",
  3730.                      "pointer to non-volatile given for argument %d of `%s'",
  3731.                      errtype, funname, parmnum);
  3732.         }
  3733.     }
  3734.       else if (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  3735.            == unsigned_type (TYPE_MAIN_VARIANT (ttr)))
  3736.     warn_for_assignment ("pointer targets in %s differ in signedness",
  3737.                  "pointer targets differ in signedness; argument %d of `%s'",
  3738.                  errtype, funname, parmnum);
  3739.       else
  3740.     warn_for_assignment ("%s between incompatible pointer types",
  3741.                  "incompatible pointer type for argument %d of `%s'",
  3742.                  errtype, funname, parmnum);
  3743.       return convert (type, rhs);
  3744.     }
  3745.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  3746.     {
  3747.       if (! integer_zerop (rhs))
  3748.     {
  3749.       warn_for_assignment ("%s of pointer from integer lacks a cast",
  3750.                    "integer given for argument %d of `%s'",
  3751.                    errtype, funname, parmnum);
  3752.       return convert (type, rhs);
  3753.     }
  3754.       return null_pointer_node;
  3755.     }
  3756.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  3757.     {
  3758.       warn_for_assignment ("%s of integer from pointer lacks a cast",
  3759.                "pointer given for argument %d of `%s'",
  3760.                errtype, funname, parmnum);
  3761.       return convert (type, rhs);
  3762.     }
  3763.  
  3764.   if (funname)
  3765. #ifdef NeXT
  3766.     {
  3767.       tree selector = maybe_building_objc_message_expr ();
  3768.  
  3769.       if (selector && parmnum > 2)
  3770.     error ("incompatible type for argument %d of `%s'",
  3771.            parmnum - 2, IDENTIFIER_POINTER (selector));
  3772.       else
  3773.     error ("incompatible type for argument %d of `%s'",
  3774.            parmnum, IDENTIFIER_POINTER (funname));
  3775.     }
  3776. #else /* NeXT */
  3777.     error ("incompatible type for argument %d of `%s'",
  3778.        parmnum, IDENTIFIER_POINTER (funname));
  3779. #endif /* NeXT */
  3780.   else
  3781.     error ("incompatible types in %s", errtype);
  3782.  
  3783.   return error_mark_node;
  3784. }
  3785.  
  3786. /* Print a warning using either ANON_MSG or NAMED_MSG.
  3787.    ANON_MSG is used if DECL and FUNCTION are 0; it gets one parameter, OPNAME.
  3788.    NAMED_MSG is used if DECL is non-0;
  3789.    it gets two parameters, the name of DECL and that of FUNCTION.
  3790.    FUNCTION_MSG is used if DECL is 0 and FUNCTION is non-0;
  3791.    it gets one parameter, the name FUNCTION.  */
  3792.  
  3793. static void
  3794. warn_for_assignment (anon_msg, arg_msg, opname, function, argnum)
  3795.      char *anon_msg;
  3796.      char *arg_msg;
  3797.      char *opname;
  3798.      tree function;
  3799.      int argnum;
  3800. {
  3801.   if (function)
  3802.     {
  3803.       tree selector = maybe_building_objc_message_expr ();
  3804.       
  3805.       if (selector && argnum > 2)
  3806.     pedwarn (arg_msg, argnum - 2, IDENTIFIER_POINTER (selector));
  3807.       else
  3808.     pedwarn (arg_msg, argnum, IDENTIFIER_POINTER (function));
  3809.     }
  3810.   else
  3811.     pedwarn (anon_msg, opname);
  3812. }
  3813.  
  3814. /* Return nonzero if VALUE is a valid constant-valued expression
  3815.    for use in initializing a static variable; one that can be an
  3816.    element of a "constant" initializer.
  3817.  
  3818.    Return null_pointer_node if the value is absolute;
  3819.    if it is relocatable, return the variable that determines the relocation.
  3820.    We assume that VALUE has been folded as much as possible;
  3821.    therefore, we do not need to check for such things as
  3822.    arithmetic-combinations of integers.  */
  3823.  
  3824. static tree
  3825. initializer_constant_valid_p (value)
  3826.      tree value;
  3827. {
  3828.   switch (TREE_CODE (value))
  3829.     {
  3830.     case CONSTRUCTOR:
  3831.       return TREE_STATIC (value) ? null_pointer_node : 0;
  3832.  
  3833.     case INTEGER_CST:
  3834.     case REAL_CST:
  3835.     case STRING_CST:
  3836.       return null_pointer_node;
  3837.  
  3838.     case ADDR_EXPR:
  3839.       return TREE_OPERAND (value, 0);
  3840.  
  3841.     case NON_LVALUE_EXPR:
  3842.       return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3843.  
  3844.     case CONVERT_EXPR:
  3845.     case NOP_EXPR:
  3846.       /* Allow conversions between pointer types.  */
  3847.       if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
  3848.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  3849.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3850.       /* Allow conversions between real types.  */
  3851.       if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
  3852.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
  3853.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3854.       /* Allow length-preserving conversions between integer types.  */
  3855.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  3856.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
  3857.       && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (value)),
  3858.                  TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
  3859.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3860.       /* Allow conversions between integer types only if explicit value.  */
  3861.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  3862.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
  3863.     {
  3864.       tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3865.       if (inner == null_pointer_node)
  3866.         return null_pointer_node;
  3867.       return 0;
  3868.     }
  3869.       /* Allow (int) &foo.  */
  3870.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  3871.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
  3872.       && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (value)),
  3873.                  TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
  3874.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3875.       return 0;
  3876.  
  3877.     case PLUS_EXPR:
  3878.       {
  3879.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3880.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  3881.     /* If either term is absolute, use the other terms relocation.  */
  3882.     if (valid0 == null_pointer_node)
  3883.       return valid1;
  3884.     if (valid1 == null_pointer_node)
  3885.       return valid0;
  3886.     return 0;
  3887.       }
  3888.  
  3889.     case MINUS_EXPR:
  3890.       {
  3891.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  3892.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  3893.     /* Win if second argument is absolute.  */
  3894.     if (valid1 == null_pointer_node)
  3895.       return valid0;
  3896.     /* Win if both arguments have the same relocation.
  3897.        Then the value is absolute.  */
  3898.     if (valid0 == valid1)
  3899.       return null_pointer_node;
  3900.     return 0;
  3901.       }
  3902.     }
  3903.  
  3904.   return 0;
  3905. }
  3906.  
  3907. /* Perform appropriate conversions on the initial value of a variable,
  3908.    store it in the declaration DECL,
  3909.    and print any error messages that are appropriate.
  3910.    If the init is invalid, store an ERROR_MARK.  */
  3911.  
  3912. void
  3913. store_init_value (decl, init)
  3914.      tree decl, init;
  3915. {
  3916.   register tree value, type;
  3917.  
  3918.   /* If variable's type was invalidly declared, just ignore it.  */
  3919.  
  3920.   type = TREE_TYPE (decl);
  3921.   if (TREE_CODE (type) == ERROR_MARK)
  3922.     return;
  3923.  
  3924.   /* Digest the specified initializer into an expression.  */
  3925.  
  3926.   value = digest_init (type, init, 0, TREE_STATIC (decl),
  3927.                TREE_STATIC (decl) || pedantic);
  3928.  
  3929.   /* Store the expression if valid; else report error.  */
  3930.  
  3931. #if 0
  3932.   /* Note that this is the only place we can detect the error
  3933.      in a case such as   struct foo bar = (struct foo) { x, y };
  3934.      where there is one initial value which is a constuctor expression.  */
  3935.   if (value == error_mark_node)
  3936.     ;
  3937.   else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
  3938.     {
  3939.       error ("initializer for static variable is not constant");
  3940.       value = error_mark_node;
  3941.     }
  3942.   else if (TREE_STATIC (decl)
  3943.        && initializer_constant_valid_p (value) == 0)
  3944.     {
  3945.       error ("initializer for static variable uses complicated arithmetic");
  3946.       value = error_mark_node;
  3947.     }
  3948.   else
  3949.     {
  3950.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  3951.     {
  3952.       if (! TREE_CONSTANT (value))
  3953.         pedwarn ("aggregate initializer is not constant");
  3954.       else if (! TREE_STATIC (value))
  3955.         pedwarn ("aggregate initializer uses complicated arithmetic");
  3956.     }
  3957.     }
  3958. #endif
  3959.  
  3960.   DECL_INITIAL (decl) = value;
  3961. }
  3962.  
  3963. /* Digest the parser output INIT as an initializer for type TYPE.
  3964.    Return a C expression of type TYPE to represent the initial value.
  3965.  
  3966.    If TAIL is nonzero, it points to a variable holding a list of elements
  3967.    of which INIT is the first.  We update the list stored there by
  3968.    removing from the head all the elements that we use.
  3969.    Normally this is only one; we use more than one element only if
  3970.    TYPE is an aggregate and INIT is not a constructor.
  3971.  
  3972.    The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
  3973.    if non-constant initializers or elements are seen.  CONSTRUCTOR_CONSTANT
  3974.    applies only to elements of constructors.  */
  3975.  
  3976. tree
  3977. digest_init (type, init, tail, require_constant, constructor_constant)
  3978.      tree type, init, *tail;
  3979.      int require_constant, constructor_constant;
  3980. {
  3981.   enum tree_code code = TREE_CODE (type);
  3982.   tree element = 0;
  3983.   tree old_tail_contents;
  3984.   /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
  3985.      tree node which has no TREE_TYPE.  */
  3986.   int raw_constructor
  3987.     = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
  3988.  
  3989.   /* By default, assume we use one element from a list.
  3990.      We correct this later in the sole case where it is not true.  */
  3991.  
  3992.   if (tail)
  3993.     {
  3994.       old_tail_contents = *tail;
  3995.       *tail = TREE_CHAIN (*tail);
  3996.     }
  3997.  
  3998.   if (init == error_mark_node)
  3999.     return init;
  4000.  
  4001.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  4002.   if (TREE_CODE (init) == NON_LVALUE_EXPR)
  4003.     init = TREE_OPERAND (init, 0);
  4004.  
  4005.   if (init && raw_constructor
  4006.       && CONSTRUCTOR_ELTS (init) != 0
  4007.       && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
  4008.     {
  4009.       element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
  4010.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  4011.       if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
  4012.     element = TREE_OPERAND (element, 0);
  4013.     }
  4014.  
  4015.   /* Initialization of an array of chars from a string constant
  4016.      optionally enclosed in braces.  */
  4017.  
  4018.   if (code == ARRAY_TYPE)
  4019.     {
  4020.       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
  4021.       if ((typ1 == char_type_node
  4022.        || typ1 == signed_char_type_node
  4023.        || typ1 == unsigned_char_type_node
  4024.        || typ1 == unsigned_wchar_type_node
  4025.        || typ1 == signed_wchar_type_node)
  4026.       && ((init && TREE_CODE (init) == STRING_CST)
  4027.           || (element && TREE_CODE (element) == STRING_CST)))
  4028.     {
  4029.       tree string = element ? element : init;
  4030.  
  4031.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
  4032.            != char_type_node)
  4033.           && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
  4034.         {
  4035.           error ("char-array initialized from wide string");
  4036.           return error_mark_node;
  4037.         }
  4038.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
  4039.            == char_type_node)
  4040.           && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
  4041.         {
  4042.           error ("int-array initialized from non-wide string");
  4043.           return error_mark_node;
  4044.         }
  4045.  
  4046.       TREE_TYPE (string) = type;
  4047.       if (TYPE_DOMAIN (type) != 0
  4048.           && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4049.         {
  4050.           register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  4051.           size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  4052.           /* Subtract 1 because it's ok to ignore the terminating null char
  4053.          that is counted in the length of the constant.  */
  4054.           if (size < TREE_STRING_LENGTH (string) - 1)
  4055.         pedwarn ("initializer-string for array of chars is too long");
  4056.         }
  4057.       return string;
  4058.     }
  4059.     }
  4060.  
  4061.   /* Any type except an array can be initialized
  4062.      from an expression of the same type, optionally with braces.
  4063.      For an array, this is allowed only for a string constant.  */
  4064.  
  4065.   if (init && (TREE_TYPE (init) == type
  4066.            || (code == ARRAY_TYPE && TREE_TYPE (init)
  4067.            && comptypes (TREE_TYPE (init), type))
  4068.            || (code == POINTER_TYPE
  4069.            && TREE_TYPE (init) != 0
  4070.            && (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
  4071.                || TREE_CODE (TREE_TYPE (init)) == FUNCTION_TYPE)
  4072.            && comptypes (TREE_TYPE (TREE_TYPE (init)),
  4073.                  TREE_TYPE (type)))))
  4074.     {
  4075.       if (code == POINTER_TYPE
  4076.       && (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
  4077.           || TREE_CODE (TREE_TYPE (init)) == FUNCTION_TYPE))
  4078.     init = default_conversion (init);
  4079.       else if (code == ARRAY_TYPE && TREE_CODE (init) != STRING_CST)
  4080.     {
  4081.       error ("array initialized from non-constant array expression");
  4082.       return error_mark_node;
  4083.     }
  4084.  
  4085.       if (optimize && TREE_READONLY (init) && TREE_CODE (init) == VAR_DECL)
  4086.     init = decl_constant_value (init);
  4087.  
  4088.       if (require_constant && ! TREE_CONSTANT (init))
  4089.     {
  4090.       error ("initializer element is not constant");
  4091.       init = error_mark_node;
  4092.     }
  4093.       else if (require_constant && initializer_constant_valid_p (init) == 0)
  4094.     {
  4095.       error ("initializer element is not computable at load time");
  4096.       init = error_mark_node;
  4097.     }
  4098.  
  4099.       return init;
  4100.     }
  4101.  
  4102.   if (element && (TREE_TYPE (element) == type
  4103.           || (code == ARRAY_TYPE && TREE_TYPE (element)
  4104.               && comptypes (TREE_TYPE (element), type))))
  4105.     {
  4106.       if (code == ARRAY_TYPE)
  4107.     {
  4108.       error ("array initialized from non-constant array expression");
  4109.       return error_mark_node;
  4110.     }
  4111.       if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
  4112.     pedwarn ("single-expression nonscalar initializer has braces");
  4113.       if (optimize && TREE_READONLY (element) && TREE_CODE (element) == VAR_DECL)
  4114.     element = decl_constant_value (element);
  4115.  
  4116.       if (require_constant && ! TREE_CONSTANT (element))
  4117.     {
  4118.       error ("initializer element is not constant");
  4119.       init = error_mark_node;
  4120.     }
  4121.       else if (require_constant && initializer_constant_valid_p (element) == 0)
  4122.     {
  4123.       error ("initializer element is not computable at load time");
  4124.       init = error_mark_node;
  4125.     }
  4126.  
  4127.       return element;
  4128.     }
  4129.  
  4130.   /* Check for initializing a union by its first field.
  4131.      Such an initializer must use braces.  */
  4132.  
  4133.   if (code == UNION_TYPE)
  4134.     {
  4135.       tree result;
  4136.       tree field = TYPE_FIELDS (type);
  4137.  
  4138.       /* Find the first named field.  ANSI decided in September 1990
  4139.      that only named fields count here.  */
  4140.       while (field && DECL_NAME (field) == 0)
  4141.     field = TREE_CHAIN (field);
  4142.  
  4143.       if (field == 0)
  4144.     {
  4145.       error ("union with no named members cannot be initialized");
  4146.       return error_mark_node;
  4147.     }
  4148.  
  4149.       if (raw_constructor)
  4150.     return process_init_constructor (type, init, 0,
  4151.                      require_constant,
  4152.                      constructor_constant);
  4153.       else if (tail != 0)
  4154.     {
  4155.       *tail = old_tail_contents;
  4156.       return process_init_constructor (type, 0, tail,
  4157.                        require_constant,
  4158.                        constructor_constant);
  4159.     }
  4160.     }
  4161.  
  4162.   /* Handle scalar types, including conversions.  */
  4163.  
  4164.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  4165.       || code == ENUMERAL_TYPE)
  4166.     {
  4167.       if (raw_constructor)
  4168.     {
  4169.       if (element == 0)
  4170.         {
  4171.           error ("initializer for scalar variable requires one element");
  4172.           return error_mark_node;
  4173.         }
  4174.       init = element;
  4175.     }
  4176.  
  4177. #if 0  /* A non-raw constructor is an actual expression.  */
  4178.       if (TREE_CODE (init) == CONSTRUCTOR)
  4179.     {
  4180.       error ("initializer for scalar has extra braces");
  4181.       return error_mark_node;
  4182.     }
  4183. #endif
  4184.  
  4185.       init = convert_for_assignment (type, default_conversion (init),
  4186.                      "initialization", NULL_TREE, 0);
  4187.  
  4188.       if (require_constant && ! TREE_CONSTANT (init))
  4189.     {
  4190.       error ("initializer element is not constant");
  4191.       init = error_mark_node;
  4192.     }
  4193.       else if (require_constant && initializer_constant_valid_p (init) == 0)
  4194.     {
  4195.       error ("initializer element is not computable at load time");
  4196.       init = error_mark_node;
  4197.     }
  4198.  
  4199.       return init;
  4200.     }
  4201.  
  4202.   /* Come here only for records and arrays.  */
  4203.  
  4204.   if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4205.     {
  4206.       error ("variable-sized object may not be initialized");
  4207.       return error_mark_node;
  4208.     }
  4209.  
  4210.   if (code == ARRAY_TYPE || code == RECORD_TYPE)
  4211.     {
  4212.       if (raw_constructor)
  4213.     return process_init_constructor (type, init, 0, constructor_constant,
  4214.                      constructor_constant);
  4215.       else if (tail != 0)
  4216.     {
  4217.       *tail = old_tail_contents;
  4218.       return process_init_constructor (type, 0, tail, constructor_constant,
  4219.                        constructor_constant);
  4220.     }
  4221.       else if (flag_traditional)
  4222.     /* Traditionally one can say `char x[100] = 0;'.  */
  4223.     return process_init_constructor (type,
  4224.                      build_nt (CONSTRUCTOR, 0,
  4225.                            tree_cons (0, init, 0)),
  4226.                      0, constructor_constant,
  4227.                      constructor_constant);
  4228.     }
  4229.  
  4230.   error ("invalid initializer");
  4231.   return error_mark_node;
  4232. }
  4233.  
  4234. /* Process a constructor for a variable of type TYPE.
  4235.    The constructor elements may be specified either with INIT or with ELTS,
  4236.    only one of which should be non-null.
  4237.  
  4238.    If INIT is specified, it is a CONSTRUCTOR node which is specifically
  4239.    and solely for initializing this datum.
  4240.  
  4241.    If ELTS is specified, it is the address of a variable containing
  4242.    a list of expressions.  We take as many elements as we need
  4243.    from the head of the list and update the list.
  4244.  
  4245.    In the resulting constructor, TREE_CONSTANT is set if all elts are
  4246.    constant, and TREE_STATIC is set if, in addition, all elts are simple enough
  4247.    constants that the assembler and linker can compute them.
  4248.  
  4249.    The argument CONSTANT_VALUE says to print an error if either the
  4250.    value or any element is not a constant.
  4251.  
  4252.    The argument CONSTANT_ELEMENT says to print an error if an element
  4253.    of an aggregate is not constant.  It does not apply to a value
  4254.    which is not a constructor.  */
  4255.  
  4256. static tree
  4257. process_init_constructor (type, init, elts, constant_value, constant_element)
  4258.      tree type, init, *elts;
  4259.      int constant_value, constant_element;
  4260. {
  4261.   register tree tail;
  4262.   /* List of the elements of the result constructor,
  4263.      in reverse order.  */
  4264.   register tree members = NULL;
  4265.   int members_length = 0;
  4266.   tree result;
  4267.   int allconstant = 1;
  4268.   int allsimple = 1;
  4269.   int erroneous = 0;
  4270.  
  4271.   /* Make TAIL be the list of elements to use for the initialization,
  4272.      no matter how the data was given to us.  */
  4273.  
  4274.   if (elts)
  4275.     tail = *elts;
  4276.   else
  4277.     tail = CONSTRUCTOR_ELTS (init);
  4278.  
  4279.   /* Gobble as many elements as needed, and make a constructor or initial value
  4280.      for each element of this aggregate.  Chain them together in result.
  4281.      If there are too few, use 0 for each scalar ultimate component.  */
  4282.  
  4283.   if (TREE_CODE (type) == ARRAY_TYPE)
  4284.     {
  4285.       tree domain = TYPE_DOMAIN (type);
  4286.       register long len;
  4287.       register int i;
  4288.  
  4289.       if (domain)
  4290.     len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
  4291.            - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
  4292.            + 1);
  4293.       else
  4294.     len = -1;  /* Take as many as there are */
  4295.  
  4296.       /* Don't leave the loop based on i if the next item has an explicit
  4297.      index value that will override i. */
  4298.  
  4299.       for (i = 0; tail != 0; i++)
  4300.     {
  4301.       register tree next1;
  4302.  
  4303.       /* If this element specifies an index,
  4304.          move to that index before storing it in the new list.  */
  4305.       if (TREE_PURPOSE (tail) != 0)
  4306.         {
  4307.           int win = 0;
  4308.  
  4309.           if (TREE_CODE (TREE_PURPOSE (tail)) == IDENTIFIER_NODE)
  4310.         error ("field name used as index in array initializer");
  4311.           else if (TREE_CODE (TREE_PURPOSE (tail)) != INTEGER_CST)
  4312.         error ("non-constant array index in initializer");
  4313.           else if (tree_int_cst_lt (TREE_PURPOSE (tail),
  4314.                     TYPE_MIN_VALUE (domain))
  4315.                ||
  4316.                tree_int_cst_lt (TYPE_MAX_VALUE (domain),
  4317.                       TREE_PURPOSE (tail)))
  4318.         error ("array index out of range in initializer");
  4319.           else
  4320.         i = TREE_INT_CST_LOW (TREE_PURPOSE (tail)), win = 1;
  4321.  
  4322.           if (!win)
  4323.         TREE_VALUE (tail) = error_mark_node;
  4324.         }
  4325.  
  4326.       if (len >= 0 && i >= len)
  4327.         break;  /* Stop if we've indeed run out of elements. */
  4328.  
  4329.       /* Now digest the value specified.  */
  4330.       if (TREE_VALUE (tail) != 0)
  4331.         {
  4332.           tree tail1 = tail;
  4333.  
  4334.           next1 = digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  4335.                    TREE_VALUE (tail), &tail1,
  4336.                    /* Both of these are the same because
  4337.                       a value here is an elt overall.  */
  4338.                    constant_element, constant_element);
  4339.  
  4340.           if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
  4341.         abort ();
  4342.           if (tail == tail1 && len < 0)
  4343.         {
  4344.           error ("non-empty initializer for array of empty elements");
  4345.           /* Just ignore what we were supposed to use.  */
  4346.           tail1 = 0;
  4347.         }
  4348.           tail = tail1;
  4349.         }
  4350.       else
  4351.         {
  4352.           next1 = error_mark_node;
  4353.           tail = TREE_CHAIN (tail);
  4354.         }
  4355.  
  4356.       if (next1 == error_mark_node)
  4357.         erroneous = 1;
  4358.       else if (!TREE_CONSTANT (next1))
  4359.         allconstant = 0;
  4360.       else if (initializer_constant_valid_p (next1) == 0)
  4361.         allsimple = 0;
  4362.  
  4363.       /* Now store NEXT1 in the list, I elements from the *end*.
  4364.          Make the list longer if necessary.  */
  4365.       while (i >= members_length)
  4366.         {
  4367.           members = tree_cons (NULL_TREE, NULL_TREE, members);
  4368.           members_length++;
  4369.         }
  4370.       {
  4371.         tree temp;
  4372.         int j;
  4373.  
  4374.         temp = members;
  4375.         for (j = members_length - 1; j > i; j--)
  4376.           temp = TREE_CHAIN (temp);
  4377.         TREE_VALUE (temp) = next1;
  4378.       }
  4379.     }
  4380.     }
  4381.   if (TREE_CODE (type) == RECORD_TYPE)
  4382.     {
  4383.       register tree field;
  4384.       int i;
  4385.  
  4386.       /* Don't leave the loop based on field just yet; see if next item
  4387.      overrides the expected field first. */
  4388.  
  4389.       for (field = TYPE_FIELDS (type), i = 0; tail;
  4390.        field = TREE_CHAIN (field), i++)
  4391.     {
  4392.       register tree next1;
  4393.  
  4394.       /* If this element specifies a field, 
  4395.          move to that field before storing it in the new list.  */
  4396.       if (TREE_PURPOSE (tail) != 0)
  4397.         {
  4398.           int win = 0;
  4399.  
  4400.           if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
  4401.         error ("index value instead of field name in structure initializer");
  4402.           else
  4403.         {
  4404.           tree temp;
  4405.           int j;
  4406.           for (temp = TYPE_FIELDS (type), j = 0;
  4407.                temp;
  4408.                temp = TREE_CHAIN (temp), j++)
  4409.             if (DECL_NAME (temp) == TREE_PURPOSE (tail))
  4410.               break;
  4411.           if (temp)
  4412.             field = temp, i = j, win = 1;
  4413.           else
  4414.             error_with_decl ("no field `%s' in structure being initialized");
  4415.         }
  4416.           if (!win)
  4417.         TREE_VALUE (tail) = error_mark_node;
  4418.         }
  4419.  
  4420.       if (field == 0)
  4421.         break;  /* No more fields to init. */
  4422.  
  4423.       if (! DECL_NAME (field))
  4424.         {
  4425.           next1 = integer_zero_node;
  4426.         }
  4427.       else if (TREE_VALUE (tail) != 0)
  4428.         {
  4429.           tree tail1 = tail;
  4430.           next1 = digest_init (TREE_TYPE (field),
  4431.                    TREE_VALUE (tail), &tail1,
  4432.                    constant_element, constant_element);
  4433.           if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
  4434.         abort ();
  4435.           tail = tail1;
  4436.         }
  4437.       else
  4438.         {
  4439.           next1 = error_mark_node;
  4440.           tail = TREE_CHAIN (tail);
  4441.         }
  4442.  
  4443.       if (next1 == error_mark_node)
  4444.         erroneous = 1;
  4445.       else if (!TREE_CONSTANT (next1))
  4446.         allconstant = 0;
  4447.       else if (initializer_constant_valid_p (next1) == 0)
  4448.         allsimple = 0;
  4449.  
  4450.       /* Now store NEXT1 in the list, I elements from the *end*.
  4451.          Make the list longer if necessary.  */
  4452.       while (i >= members_length)
  4453.         {
  4454.           members = tree_cons (NULL_TREE, NULL_TREE, members);
  4455.           members_length++;
  4456.         }
  4457.       {
  4458.         tree temp;
  4459.         int j;
  4460.  
  4461.         temp = members;
  4462.         for (j = members_length - 1; j > i; j--)
  4463.           temp = TREE_CHAIN (temp);
  4464.         TREE_VALUE (temp) = next1;
  4465.         TREE_PURPOSE (temp) = field;
  4466.       }
  4467.     }
  4468.     }
  4469.   if (TREE_CODE (type) == UNION_TYPE)
  4470.     {
  4471.       register tree field = TYPE_FIELDS (type);
  4472.       register tree next1;
  4473.  
  4474.       /* Find the first named field.  ANSI decided in September 1990
  4475.      that only named fields count here.  */
  4476.       while (field && DECL_NAME (field) == 0)
  4477.     field = TREE_CHAIN (field);
  4478.  
  4479.       /* For a union, get the initializer for 1 fld.  */
  4480.  
  4481.       /* If this element specifies a field, initialize via that field.  */
  4482.       if (TREE_PURPOSE (tail) != 0)
  4483.     {
  4484.       int win = 0;
  4485.  
  4486.       if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
  4487.         error ("index value instead of field name in union initializer");
  4488.       else
  4489.         {
  4490.           tree temp;
  4491.           for (temp = TYPE_FIELDS (type);
  4492.            temp;
  4493.            temp = TREE_CHAIN (temp))
  4494.         if (DECL_NAME (temp) == TREE_PURPOSE (tail))
  4495.           break;
  4496.           if (temp)
  4497.         field = temp, win = 1;
  4498.           else
  4499.         error_with_decl ("no field `%s' in union being initialized");
  4500.         }
  4501.       if (!win)
  4502.         TREE_VALUE (tail) = error_mark_node;
  4503.     }
  4504.  
  4505.       if (TREE_VALUE (tail) != 0)
  4506.     {
  4507.       tree tail1 = tail;
  4508.       next1 = digest_init (TREE_TYPE (field),
  4509.                    TREE_VALUE (tail), &tail1,
  4510.                    constant_value, constant_element);
  4511.       if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
  4512.         abort ();
  4513.       tail = tail1;
  4514.     }
  4515.       else
  4516.     {
  4517.       next1 = error_mark_node;
  4518.       tail = TREE_CHAIN (tail);
  4519.     }
  4520.  
  4521.       if (next1 == error_mark_node)
  4522.     erroneous = 1;
  4523.       else if (!TREE_CONSTANT (next1))
  4524.     allconstant = 0;
  4525.       else if (initializer_constant_valid_p (next1) == 0)
  4526.     allsimple = 0;
  4527.       members = tree_cons (field, next1, members);
  4528.     }
  4529.  
  4530.   /* If arguments were specified as a list, just remove the ones we used.  */
  4531.   if (elts)
  4532.     *elts = tail;
  4533.   /* If arguments were specified as a constructor,
  4534.      complain unless we used all the elements of the constructor.  */
  4535.   else if (tail)
  4536.     {
  4537.       if (TREE_CODE (type) == UNION_TYPE)
  4538.     pedwarn ("excess elements in union initializer");
  4539.       else
  4540.     pedwarn ("excess elements in aggregate initializer");
  4541.     }
  4542.  
  4543.   if (erroneous)
  4544.     return error_mark_node;
  4545.  
  4546.   result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  4547.   if (allconstant) TREE_CONSTANT (result) = 1;
  4548.   if (allconstant && allsimple) TREE_STATIC (result) = 1;
  4549.   return result;
  4550. }
  4551.  
  4552. /* Expand an ASM statement with operands, handling output operands
  4553.    that are not variables or INDIRECT_REFS by transforming such
  4554.    cases into cases that expand_asm_operands can handle.
  4555.  
  4556.    Arguments are same as for expand_asm_operands.  */
  4557.  
  4558. void
  4559. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  4560.      tree string, outputs, inputs, clobbers;
  4561.      int vol;
  4562.      char *filename;
  4563.      int line;
  4564. {
  4565.   int noutputs = list_length (outputs);
  4566.   register int i;
  4567.   /* o[I] is the place that output number I should be written.  */
  4568.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  4569.   register tree tail;
  4570.  
  4571.   /* Record the contents of OUTPUTS before it is modifed.  */
  4572.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  4573.     o[i] = TREE_VALUE (tail);
  4574.  
  4575.   /* Perform default conversions on array and function inputs.  */
  4576.   /* Don't do this for other types--
  4577.      it would screw up operands expected to be in memory.  */
  4578.   for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
  4579.     if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
  4580.     || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
  4581.       TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
  4582.  
  4583.   /* Generate the ASM_OPERANDS insn;
  4584.      store into the TREE_VALUEs of OUTPUTS some trees for
  4585.      where the values were actually stored.  */
  4586.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  4587.  
  4588.   /* Copy all the intermediate outputs into the specified outputs.  */
  4589.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  4590.     {
  4591.       if (o[i] != TREE_VALUE (tail))
  4592.     {
  4593.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  4594.                0, VOIDmode, 0);
  4595.       free_temp_slots ();
  4596.     }
  4597.       /* Detect modification of read-only values.
  4598.      (Otherwise done by build_modify_expr.)  */
  4599.       else
  4600.     {
  4601.       tree type = TREE_TYPE (o[i]);
  4602.       if (TYPE_READONLY (type)
  4603.           || ((TREE_CODE (type) == RECORD_TYPE
  4604.            || TREE_CODE (type) == UNION_TYPE)
  4605.           && C_TYPE_FIELDS_READONLY (type)))
  4606.         readonly_warning (o[i], "modification by `asm'");
  4607.     }
  4608.     }
  4609.  
  4610.   /* Those MODIFY_EXPRs could do autoincrements.  */
  4611.   emit_queue ();
  4612. }
  4613.  
  4614. /* Expand a C `return' statement.
  4615.    RETVAL is the expression for what to return,
  4616.    or a null pointer for `return;' with no value.  */
  4617.  
  4618. void
  4619. c_expand_return (retval)
  4620.      tree retval;
  4621. {
  4622.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  4623.  
  4624.   if (TREE_THIS_VOLATILE (current_function_decl))
  4625.     warning ("function declared `volatile' has a `return' statement");
  4626.  
  4627.   if (!retval)
  4628.     {
  4629.       current_function_returns_null = 1;
  4630.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  4631.     warning ("`return' with no value, in function returning non-void");
  4632.       expand_null_return ();
  4633.     }
  4634.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  4635.     {
  4636.       current_function_returns_null = 1;
  4637.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  4638.     pedwarn ("`return' with a value, in function returning void");
  4639.       expand_return (retval);
  4640.     }
  4641.   else
  4642.     {
  4643.       tree t = convert_for_assignment (valtype, retval, "return",
  4644.                        NULL_TREE, 0);
  4645.       tree res = DECL_RESULT (current_function_decl);
  4646.       t = build (MODIFY_EXPR, TREE_TYPE (res),
  4647.          res, convert (TREE_TYPE (res), t));
  4648.       expand_return (t);
  4649.       current_function_returns_value = 1;
  4650.     }
  4651. }
  4652.  
  4653. /* Start a C switch statement, testing expression EXP.
  4654.    Return EXP if it is valid, an error node otherwise.  */
  4655.  
  4656. tree
  4657. c_expand_start_case (exp)
  4658.      tree exp;
  4659. {
  4660.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  4661.   tree type = TREE_TYPE (exp);
  4662.  
  4663.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  4664.     {
  4665.       error ("switch quantity not an integer");
  4666.       exp = error_mark_node;
  4667.     }
  4668.   else
  4669.     {
  4670.       tree index;
  4671.  
  4672.       if (warn_traditional
  4673.       && (TREE_TYPE (exp) == long_integer_type_node
  4674.           || TREE_TYPE (exp) == long_unsigned_type_node))
  4675.     pedwarn ("`long' switch expression not converted to `int' in ANSI C");
  4676.  
  4677.       exp = default_conversion (exp);
  4678.       type = TREE_TYPE (exp);
  4679.       index = get_unwidened (exp, 0);
  4680.       /* We can't strip a conversion from a signed type to an unsigned,
  4681.      because if we did, int_fits_type_p would do the wrong thing
  4682.      when checking case values for being in range,
  4683.      and it's too hard to do the right thing.  */
  4684.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  4685.       == TREE_UNSIGNED (TREE_TYPE (index)))
  4686.     exp = index;
  4687.     }
  4688.  
  4689.   expand_start_case (1, exp, type, "switch statement");
  4690.  
  4691.   return exp;
  4692. }
  4693.