home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / GCC 1.37.1r15 / Sources / c-typeck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  112.3 KB  |  3,834 lines  |  [TEXT/MPS ]

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