home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / src / gcc-257 / cp-typec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-25  |  209.3 KB  |  6,801 lines

  1. /* Build expressions with type checking for C++ compiler.
  2.    Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  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 2, 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 and C++ specific error
  25.    checks, 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. extern void error ();
  32. extern void warning ();
  33.  
  34. #include "config.h"
  35. #include <stdio.h>
  36. #include "tree.h"
  37. #include "rtl.h"
  38. #include "cp-tree.h"
  39. #include "flags.h"
  40.  
  41. int mark_addressable ();
  42. static tree convert_for_assignment ();
  43. /* static */ tree convert_for_initialization ();
  44. int compparms ();
  45. static int self_promoting_args_p ();
  46. int comp_target_types ();
  47. extern tree shorten_compare ();
  48. void warn_for_assignment ();
  49. extern void binary_op_error ();
  50. static tree pointer_int_sum ();
  51. static tree pointer_diff ();
  52. static tree convert_sequence ();
  53. /* static */ tree unary_complex_lvalue ();
  54. static void pedantic_lvalue_warning ();
  55. tree truthvalue_conversion ();
  56.  
  57. extern rtx original_result_rtx;
  58.  
  59. /* Return the target type of TYPE, which meas return T for:
  60.    T*, T&, T[], T (...), and otherwise, just T.  */
  61.  
  62. tree
  63. target_type (type)
  64.      tree type;
  65. {
  66.   if (TREE_CODE (type) == REFERENCE_TYPE)
  67.     type = TREE_TYPE (type);
  68.   while (TREE_CODE (type) == POINTER_TYPE
  69.      || TREE_CODE (type) == ARRAY_TYPE
  70.      || TREE_CODE (type) == FUNCTION_TYPE
  71.      || TREE_CODE (type) == METHOD_TYPE
  72.      || TREE_CODE (type) == OFFSET_TYPE)
  73.     type = TREE_TYPE (type);
  74.   return type;
  75. }
  76.  
  77. /* Do `exp = require_complete_type (exp);' to make sure exp
  78.    does not have an incomplete type.  (That includes void types.)  */
  79.  
  80. tree
  81. require_complete_type (value)
  82.      tree value;
  83. {
  84.   tree type = TREE_TYPE (value);
  85.  
  86.   /* First, detect a valid value with a complete type.  */
  87.   if (TYPE_SIZE (type) != 0
  88.       && type != void_type_node)
  89.     return value;
  90.  
  91.   /* If we see X::Y, we build an OFFSET_TYPE which has
  92.      not been laid out.  Try to avoid an error by interpreting
  93.      it as this->X::Y, if reasonable.  */
  94.   if (TREE_CODE (value) == OFFSET_REF
  95.       && C_C_D != 0
  96.       && TREE_OPERAND (value, 0) == C_C_D)
  97.     {
  98.       tree base, member = TREE_OPERAND (value, 1);
  99.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  100.       my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
  101.       base = convert_pointer_to (basetype, current_class_decl);
  102.       value = build (COMPONENT_REF, TREE_TYPE (member),
  103.              build_indirect_ref (base, NULL_PTR), member);
  104.       return require_complete_type (value);
  105.     }
  106.  
  107.   incomplete_type_error (value, type);
  108.   return error_mark_node;
  109. }
  110.  
  111. /* Return truthvalue of whether type of EXP is instantiated.  */
  112. int
  113. type_unknown_p (exp)
  114.      tree exp;
  115. {
  116.   return (TREE_CODE (exp) == TREE_LIST
  117.       || TREE_TYPE (exp) == unknown_type_node
  118.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  119.           && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
  120. }
  121.  
  122. /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
  123.    does not have an uninstantiated type.
  124.    TYPE is type to instantiate with, if uninstantiated.  */
  125. tree
  126. require_instantiated_type (type, exp, errval)
  127.      tree type, exp, errval;
  128. {
  129.   if (TREE_TYPE (exp) == NULL_TREE)
  130.     {
  131.       error ("argument list may not have an initializer list");
  132.       return errval;
  133.     }
  134.  
  135.   if (TREE_TYPE (exp) == unknown_type_node
  136.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  137.       && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
  138.     {
  139.       exp = instantiate_type (type, exp, 1);
  140.       if (TREE_TYPE (exp) == error_mark_node)
  141.     return errval;
  142.     }
  143.   return exp;
  144. }
  145.  
  146. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  147.    as well as those of TYPE.  */
  148.  
  149. static tree
  150. qualify_type (type, like)
  151.      tree type, like;
  152. {
  153.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  154.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  155.   /* @@ Must do member pointers here.  */
  156.   return build_type_variant (type, constflag, volflag);
  157. }
  158.  
  159. /* Return the common type of two parameter lists.
  160.    We assume that comptypes has already been done and returned 1;
  161.    if that isn't so, this may crash.
  162.  
  163.    As an optimization, free the space we allocate if the parameter
  164.    lists are already common.  */
  165.  
  166. tree
  167. commonparms (p1, p2)
  168.      tree p1, p2;
  169. {
  170.   tree oldargs = p1, newargs, n;
  171.   int i, len;
  172.   int any_change = 0;
  173.   char *first_obj = (char *) oballoc (0);
  174.  
  175.   len = list_length (p1);
  176.   newargs = tree_last (p1);
  177.  
  178.   if (newargs == void_list_node)
  179.     i = 1;
  180.   else
  181.     {
  182.       i = 0;
  183.       newargs = 0;
  184.     }
  185.  
  186.   for (; i < len; i++)
  187.     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
  188.  
  189.   n = newargs;
  190.  
  191.   for (i = 0; p1;
  192.        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
  193.     {
  194.       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
  195.     {
  196.       /* We used to give a warning here that advised about a default
  197.          argument being given in the prototype but not in the function's
  198.          declaration.  It's best not to bother.  */
  199.       TREE_PURPOSE (n) = TREE_PURPOSE (p1);
  200.       any_change = 1;
  201.     }
  202.       else if (! TREE_PURPOSE (p1))
  203.     {
  204.       if (TREE_PURPOSE (p2))
  205.         {
  206.           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  207.           any_change = 1;
  208.         }
  209.     }
  210.       else
  211.     {
  212.       int cmp = simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2));
  213.       if (cmp < 0)
  214.         my_friendly_abort (111);
  215.       if (cmp == 0)
  216.         {
  217.           error ("redeclaration of default argument %d", i+1);
  218.           any_change = 1;
  219.         }
  220.       TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  221.     }
  222.       if (TREE_VALUE (p1) != TREE_VALUE (p2))
  223.     {
  224.       any_change = 1;
  225.       TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  226.     }
  227.       else
  228.     TREE_VALUE (n) = TREE_VALUE (p1);
  229.     }
  230.   if (! any_change)
  231.     {
  232.       obfree (first_obj);
  233.       return oldargs;
  234.     }
  235.  
  236.   return newargs;
  237. }
  238.  
  239. /* Return the common type of two types.
  240.    We assume that comptypes has already been done and returned 1;
  241.    if that isn't so, this may crash.
  242.  
  243.    This is the type for the result of most arithmetic operations
  244.    if the operands have the given two types.
  245.  
  246.    We do not deal with enumeral types here because they have already been
  247.    converted to integer types.  */
  248.  
  249. tree
  250. common_type (t1, t2)
  251.      tree t1, t2;
  252. {
  253.   register enum tree_code code1;
  254.   register enum tree_code code2;
  255.  
  256.   /* Save time if the two types are the same.  */
  257.  
  258.   if (t1 == t2) return t1;
  259.  
  260.   /* If one type is nonsense, use the other.  */
  261.   if (t1 == error_mark_node)
  262.     return t2;
  263.   if (t2 == error_mark_node)
  264.     return t1;
  265.  
  266.   /* Treat an enum type as the unsigned integer type of the same width.  */
  267.  
  268.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  269.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  270.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  271.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  272.  
  273.   code1 = TREE_CODE (t1);
  274.   code2 = TREE_CODE (t2);
  275.  
  276.   switch (code1)
  277.     {
  278.     case INTEGER_TYPE:
  279.     case REAL_TYPE:
  280.       /* If only one is real, use it as the result.  */
  281.  
  282.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  283.     return t1;
  284.  
  285.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  286.     return t2;
  287.  
  288.       /* Both real or both integers; use the one with greater precision.  */
  289.  
  290.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  291.     return t1;
  292.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  293.     return t2;
  294.  
  295.       /* Same precision.  Prefer longs to ints even when same size.  */
  296.  
  297.       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
  298.       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
  299.     return long_unsigned_type_node;
  300.  
  301.       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
  302.       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
  303.     {
  304.       /* But preserve unsignedness from the other type,
  305.          since long cannot hold all the values of an unsigned int.  */
  306.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  307.         return long_unsigned_type_node;
  308.       return long_integer_type_node;
  309.     }
  310.  
  311.       /* Otherwise prefer the unsigned one.  */
  312.  
  313.       if (TREE_UNSIGNED (t1))
  314.     return t1;
  315.       else return t2;
  316.  
  317.     case POINTER_TYPE:
  318.     case REFERENCE_TYPE:
  319.       /* For two pointers, do this recursively on the target type,
  320.      and combine the qualifiers of the two types' targets.  */
  321.       /* This code was turned off; I don't know why.
  322.       But ANSI C++ specifies doing this with the qualifiers.
  323.       So I turned it on again.  */
  324.       {
  325.     tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  326.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  327.     int constp
  328.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  329.     int volatilep
  330.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  331.     target = build_type_variant (target, constp, volatilep);
  332.     if (code1 == POINTER_TYPE)
  333.       return build_pointer_type (target);
  334.     else
  335.       return build_reference_type (target);
  336.       }
  337. #if 0
  338.     case POINTER_TYPE:
  339.       return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  340.  
  341.     case REFERENCE_TYPE:
  342.       return build_reference_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  343. #endif
  344.  
  345.     case ARRAY_TYPE:
  346.       {
  347.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  348.     /* Save space: see if the result is identical to one of the args.  */
  349.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  350.       return t1;
  351.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  352.       return t2;
  353.     /* Merge the element types, and have a size if either arg has one.  */
  354.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  355.       }
  356.  
  357.     case FUNCTION_TYPE:
  358.       /* Function types: prefer the one that specified arg types.
  359.      If both do, merge the arg types.  Also merge the return types.  */
  360.       {
  361.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  362.     tree p1 = TYPE_ARG_TYPES (t1);
  363.     tree p2 = TYPE_ARG_TYPES (t2);
  364.     tree rval, raises;
  365.  
  366.     /* Save space: see if the result is identical to one of the args.  */
  367.     if (valtype == TREE_TYPE (t1) && ! p2)
  368.       return t1;
  369.     if (valtype == TREE_TYPE (t2) && ! p1)
  370.       return t2;
  371.  
  372.     /* Simple way if one arg fails to specify argument types.  */
  373.     if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
  374.       {
  375.         rval = build_function_type (valtype, p2);
  376.         if (raises = TYPE_RAISES_EXCEPTIONS (t2))
  377.           rval = build_exception_variant (NULL_TREE, rval, raises);
  378.         return rval;
  379.       }
  380.     raises = TYPE_RAISES_EXCEPTIONS (t1);
  381.     if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
  382.       {
  383.         rval = build_function_type (valtype, p1);
  384.         if (raises)
  385.           rval = build_exception_variant (NULL_TREE, rval, raises);
  386.         return rval;
  387.       }
  388.  
  389.     rval = build_function_type (valtype, commonparms (p1, p2));
  390.     return build_exception_variant (NULL_TREE, rval, raises);
  391.       }
  392.  
  393.     case RECORD_TYPE:
  394.     case UNION_TYPE:
  395.       my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1
  396.               && TYPE_MAIN_VARIANT (t2) == t2, 306);
  397.  
  398.       if (binfo_or_else (t1, t2))
  399.     return t1;
  400.       compiler_error ("common_type called with uncommon aggregate types");
  401.       return t1;
  402.  
  403.     case METHOD_TYPE:
  404.       if (TYPE_METHOD_BASETYPE (t1) == TYPE_METHOD_BASETYPE (t2)
  405.       && TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
  406.     {
  407.       /* Get this value the long way, since TYPE_METHOD_BASETYPE
  408.          is just the main variant of this.  */
  409.       tree basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
  410.       tree raises, t3;
  411.  
  412.       raises = TYPE_RAISES_EXCEPTIONS (t1);
  413.  
  414.       /* If this was a member function type, get back to the
  415.          original type of type member function (i.e., without
  416.          the class instance variable up front.  */
  417.       t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1)));
  418.       t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2)));
  419.       t3 = common_type (t1, t2);
  420.       t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3));
  421.       return build_exception_variant (basetype, t3, raises);
  422.     }
  423.       compiler_error ("common_type called with uncommon method types");
  424.       return t1;
  425.  
  426.     case OFFSET_TYPE:
  427.       if (TYPE_OFFSET_BASETYPE (t1) == TYPE_OFFSET_BASETYPE (t2)
  428.       && TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
  429.     {
  430.       tree basetype = TYPE_OFFSET_BASETYPE (t1);
  431.       return build_offset_type (basetype,
  432.                     common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  433.     }
  434.       compiler_error ("common_type called with uncommon member types");
  435.       return t1;
  436.  
  437.     default:
  438.       return t1;
  439.     }
  440. }
  441.  
  442. /* Return 1 if TYPE1 and TYPE2 raise the same exceptions.  */
  443. int
  444. compexcepttypes (t1, t2, strict)
  445.      tree t1, t2;
  446.      int strict;
  447. {
  448.   return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
  449. }
  450.  
  451. static int
  452. comp_array_types (cmp, t1, t2, strict)
  453.      register int (*cmp)();
  454.      tree t1, t2;
  455.      int strict;
  456. {
  457.   tree d1 = TYPE_DOMAIN (t1);
  458.   tree d2 = TYPE_DOMAIN (t2);
  459.  
  460.   /* Target types must match incl. qualifiers.  */
  461.   if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  462.     || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
  463.     return 0;
  464.  
  465.   /* Sizes must match unless one is missing or variable.  */
  466.   if (d1 == 0 || d2 == 0 || d1 == d2
  467.       || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  468.       || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  469.       || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  470.       || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  471.     return 1;
  472.  
  473.   return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  474.        == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  475.       && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  476.           == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  477.       && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  478.           == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  479.       && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  480.           == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  481. }
  482.  
  483. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  484.    or various other operations.  This is what ANSI C++ speaks of as
  485.    "being the same".
  486.  
  487.    For C++: argument STRICT says we should be strict about this
  488.    comparison:
  489.  
  490.     2 : strict, except that if one type is a reference and
  491.         the other is not, compare the target type of the
  492.         reference to the type that's not a reference (ARM, p308).
  493.     1 : strict (compared according to ANSI C)
  494.     0 : <= (compared according to C++)
  495.     -1: <= or >= (relaxed)
  496.  
  497.    Otherwise, pointers involving base classes and derived classes
  498.    can be mixed as legal: i.e. a pointer to a base class may be assigned
  499.    to a pointer to one of its derived classes, as per C++. A pointer to
  500.    a derived class may be passed as a parameter to a function expecting a
  501.    pointer to a base classes. These allowances do not commute. In this
  502.    case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
  503.    be the derived class.  */
  504. int
  505. comptypes (type1, type2, strict)
  506.      tree type1, type2;
  507.      int strict;
  508. {
  509.   register tree t1 = type1;
  510.   register tree t2 = type2;
  511.  
  512.   /* Suppress errors caused by previously reported errors */
  513.  
  514.   if (t1 == t2)
  515.     return 1;
  516.  
  517.   /* This should never happen.  */
  518.   my_friendly_assert (t1 != error_mark_node, 307);
  519.  
  520.   if (t2 == error_mark_node)
  521.     return 0;
  522.  
  523.   if (strict < 0)
  524.     {
  525.       /* Treat an enum type as the unsigned integer type of the same width.  */
  526.  
  527.       if (TREE_CODE (t1) == ENUMERAL_TYPE)
  528.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  529.       if (TREE_CODE (t2) == ENUMERAL_TYPE)
  530.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  531.     }
  532.  
  533.   if (t1 == t2)
  534.     return 1;
  535.  
  536.   /* Different classes of types can't be compatible.  */
  537.  
  538.   if (TREE_CODE (t1) != TREE_CODE (t2))
  539.     {
  540.       if (strict == 2
  541.       && ((TREE_CODE (t1) == REFERENCE_TYPE)
  542.           ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
  543.     {
  544.       if (TREE_CODE (t1) == REFERENCE_TYPE)
  545.         return comptypes (TREE_TYPE (t1), t2, 1);
  546.       return comptypes (t1, TREE_TYPE (t2), 1);
  547.     }
  548.  
  549.       return 0;
  550.     }
  551.   if (strict > 1)
  552.     strict = 1;
  553.  
  554.   /* Qualifiers must match.  */
  555.  
  556.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  557.     return 0;
  558.   if (TREE_THIS_VOLATILE (t1) != TREE_THIS_VOLATILE (t2))
  559.     return 0;
  560.  
  561.   /* Allow for two different type nodes which have essentially the same
  562.      definition.  Note that we already checked for equality of the type
  563.      type qualifiers (just above).  */
  564.  
  565.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  566.     return 1;
  567.  
  568.   switch (TREE_CODE (t1))
  569.     {
  570.     case RECORD_TYPE:
  571.     case UNION_TYPE:
  572.       if (t1 == t2)
  573.     return 1;
  574.       if (strict <= 0)
  575.     goto look_hard;
  576.       return 0;
  577.  
  578.     case OFFSET_TYPE:
  579.       return (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1)),
  580.              TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2)), strict)
  581.           && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
  582.  
  583.     case METHOD_TYPE:
  584.       if (! compexcepttypes (t1, t2, strict))
  585.     return 0;
  586.  
  587.       /* This case is anti-symmetrical!
  588.      One can pass a base member (or member function)
  589.      to something expecting a derived member (or member function),
  590.      but not vice-versa!  */
  591.  
  592.       return (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2)),
  593.              TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1)), strict)
  594.           && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
  595.           && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1)),
  596.                 TREE_CHAIN (TYPE_ARG_TYPES(t2)), strict));
  597.     case POINTER_TYPE:
  598.     case REFERENCE_TYPE:
  599.       t1 = TREE_TYPE (t1);
  600.       t2 = TREE_TYPE (t2);
  601.       if (t1 == t2)
  602.     return 1;
  603.       if (strict <= 0)
  604.     {
  605.       if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
  606.         {
  607.           int rval;
  608.         look_hard:
  609.           rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2);
  610.  
  611.           if (rval)
  612.         return 1;
  613.           if (strict < 0)
  614.         return UNIQUELY_DERIVED_FROM_P (t2, t1);
  615.         }
  616.       return 0;
  617.     }
  618.       else
  619.     return comptypes (t1, t2, strict);
  620.  
  621.     case FUNCTION_TYPE:
  622.       if (! compexcepttypes (t1, t2, strict))
  623.     return 0;
  624.  
  625.       return ((TREE_TYPE (t1) == TREE_TYPE (t2)
  626.            || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
  627.           && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
  628.  
  629.     case ARRAY_TYPE:
  630.       /* Target types must match incl. qualifiers.  */
  631.       return comp_array_types (comptypes, t1, t2, strict);
  632.  
  633.     }
  634.   return 0;
  635. }
  636.  
  637. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  638.    ignoring their qualifiers.
  639.  
  640.    NPTRS is the number of pointers we can strip off and keep cool.
  641.    This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
  642.    but to not permit B** to convert to A**.  */
  643.  
  644. int
  645. comp_target_types (ttl, ttr, nptrs)
  646.      tree ttl, ttr;
  647.      int nptrs;
  648. {
  649.   ttl = TYPE_MAIN_VARIANT (ttl);
  650.   ttr = TYPE_MAIN_VARIANT (ttr);
  651.   if (ttl == ttr)
  652.     return 1;
  653.  
  654.   if (TREE_CODE (ttr) != TREE_CODE (ttl))
  655.     return 0;
  656.  
  657.   if (TREE_CODE (ttr) == POINTER_TYPE)
  658.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs - 1);
  659.  
  660.   if (TREE_CODE (ttr) == REFERENCE_TYPE)
  661.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  662.   if (TREE_CODE (ttr) == ARRAY_TYPE)
  663.     return comp_array_types (comp_target_types, ttl, ttr, 0);
  664.   else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
  665.     if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  666.       switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 0))
  667.     {
  668.     case 0:
  669.       return 0;
  670.     case 1:
  671.       return 1;
  672.     case 2:
  673.       warning ("contravariance violation for method types ignored");
  674.       return 1;
  675.     default:
  676.       my_friendly_abort (112);
  677.     }
  678.     else
  679.       return 0;
  680.  
  681.   /* for C++ */
  682.   else if (TREE_CODE (ttr) == OFFSET_TYPE)
  683.     {
  684.       /* Contravariance: we can assign a pointer to base member to a pointer
  685.      to derived member.  Note difference from simple pointer case, where
  686.      we can pass a pointer to derived to a pointer to base.  */
  687.       if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0))
  688.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  689.       else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0)
  690.            && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  691.     {
  692.       warning ("contravariance violation for member types ignored");
  693.       return 1;
  694.     }
  695.     }
  696.   else if (IS_AGGR_TYPE (ttl))
  697.     {
  698.       if (nptrs < 0)
  699.     return 0;
  700.       return comptypes (TYPE_POINTER_TO (ttl), TYPE_POINTER_TO (ttr), 0);
  701.     }
  702.  
  703.   return 0;
  704. }
  705.  
  706. /* If two types share a common base type, return that basetype.
  707.    If there is not a unique most-derived base type, this function
  708.    returns ERROR_MARK_NODE.  */
  709. tree
  710. common_base_type (tt1, tt2)
  711.      tree tt1, tt2;
  712. {
  713.   tree best = NULL_TREE, tmp;
  714.   int i;
  715.  
  716.   /* If one is a baseclass of another, that's good enough.  */
  717.   if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
  718.     return tt1;
  719.   if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
  720.     return tt2;
  721.  
  722.   /* If they share a virtual baseclass, that's good enough.  */
  723.   for (tmp = CLASSTYPE_VBASECLASSES (tt1); tmp; tmp = TREE_CHAIN (tmp))
  724.     {
  725.       if (binfo_member (BINFO_TYPE (tmp), CLASSTYPE_VBASECLASSES (tt2)))
  726.     return BINFO_TYPE (tmp);
  727.     }
  728.  
  729.   /* Otherwise, try to find a unique baseclass of TT1
  730.      that is shared by TT2, and follow that down.  */
  731.   for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--)
  732.     {
  733.       tree basetype = TYPE_BINFO_BASETYPE (tt1, i);
  734.       tree trial = common_base_type (basetype, tt2);
  735.       if (trial)
  736.     {
  737.       if (trial == error_mark_node)
  738.         return trial;
  739.       if (best == NULL_TREE)
  740.         best = trial;
  741.       else if (best != trial)
  742.         return error_mark_node;
  743.     }
  744.     }
  745.  
  746.   /* Same for TT2.  */
  747.   for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--)
  748.     {
  749.       tree basetype = TYPE_BINFO_BASETYPE (tt2, i);
  750.       tree trial = common_base_type (tt1, basetype);
  751.       if (trial)
  752.     {
  753.       if (trial == error_mark_node)
  754.         return trial;
  755.       if (best == NULL_TREE)
  756.         best = trial;
  757.       else if (best != trial)
  758.         return error_mark_node;
  759.     }
  760.     }
  761.   return best;
  762. }
  763.  
  764. /* Subroutines of `comptypes'.  */
  765.  
  766. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  767.    are equivalent in the sense that functions with those parameter types
  768.    can have equivalent types.
  769.    If either list is empty, we win.
  770.    Otherwise, the two lists must be equivalent, element by element.
  771.  
  772.    C++: See comment above about TYPE1, TYPE2, STRICT.
  773.    If STRICT == 3, it means checking is strict, but do not compare
  774.    default parameter values.  */
  775. int
  776. compparms (parms1, parms2, strict)
  777.      tree parms1, parms2;
  778.      int strict;
  779. {
  780.   register tree t1 = parms1, t2 = parms2;
  781.  
  782.   /* An unspecified parmlist matches any specified parmlist
  783.      whose argument types don't need default promotions.  */
  784.  
  785.   if (t1 == 0)
  786.     return self_promoting_args_p (t2);
  787.   if (t2 == 0)
  788.     return self_promoting_args_p (t1);
  789.  
  790.   while (1)
  791.     {
  792.       if (t1 == 0 && t2 == 0)
  793.     return 1;
  794.       /* If one parmlist is shorter than the other,
  795.      they fail to match, unless STRICT is <= 0.  */
  796.       if (t1 == 0 || t2 == 0)
  797.     {
  798.       if (strict > 0)
  799.         return 0;
  800.       if (strict < 0)
  801.         return 1;
  802.       if (strict == 0)
  803.         return t1 && TREE_PURPOSE (t1);
  804.     }
  805.       if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict))
  806.     {
  807.       if (strict > 0)
  808.         return 0;
  809.       if (strict == 0)
  810.         return t2 == void_list_node && TREE_PURPOSE (t1);
  811.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  812.     }
  813.       if (strict != 3 && TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  814.     {
  815.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  816.       if (cmp < 0)
  817.         my_friendly_abort (113);
  818.       if (cmp == 0)
  819.         return 0;
  820.     }
  821.  
  822.       t1 = TREE_CHAIN (t1);
  823.       t2 = TREE_CHAIN (t2);
  824.     }
  825. }
  826.  
  827. /* This really wants return whether or not parameter type lists
  828.    would make their owning functions assignment compatible or not.  */
  829. int
  830. comp_target_parms (parms1, parms2, strict)
  831.      tree parms1, parms2;
  832.      int strict;
  833. {
  834.   register tree t1 = parms1, t2 = parms2;
  835.   int warn_contravariance = 0;
  836.  
  837.   /* An unspecified parmlist matches any specified parmlist
  838.      whose argument types don't need default promotions.
  839.      @@@ see 13.3.3 for a counterexample...  */
  840.  
  841.   if (t1 == 0 && t2 != 0)
  842.     {
  843.       cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
  844.           parms2);
  845.       return self_promoting_args_p (t2);
  846.     }
  847.   if (t2 == 0)
  848.     return self_promoting_args_p (t1);
  849.  
  850.   for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  851.     {
  852.       tree p1, p2;
  853.  
  854.       /* If one parmlist is shorter than the other,
  855.      they fail to match, unless STRICT is <= 0.  */
  856.       if (t1 == 0 || t2 == 0)
  857.     {
  858.       if (strict > 0)
  859.         return 0;
  860.       if (strict < 0)
  861.         return 1 + warn_contravariance;
  862.       return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
  863.     }
  864.       p1 = TREE_VALUE (t1);
  865.       p2 = TREE_VALUE (t2);
  866.       if (p1 == p2)
  867.     continue;
  868.       if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
  869.       || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE))
  870.     {
  871.       if (strict <= 0
  872.           && (TYPE_MAIN_VARIANT (TREE_TYPE (p1))
  873.           == TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
  874.         continue;
  875.  
  876.       /* The following is wrong for contravariance,
  877.          but many programs depend on it.  */
  878.       if (TREE_TYPE (p1) == void_type_node)
  879.         continue;
  880.       if (TREE_TYPE (p2) == void_type_node)
  881.         {
  882.           warn_contravariance = 1;
  883.           continue;
  884.         }
  885.       if (IS_AGGR_TYPE (TREE_TYPE (p1)))
  886.         {
  887.           if (comptypes (p2, p1, 0) == 0)
  888.         {
  889.           if (comptypes (p1, p2, 0) != 0)
  890.             warn_contravariance = 1;
  891.           else
  892.             return 0;
  893.         }
  894.           continue;
  895.         }
  896.     }
  897.       /* Note backwards order due to contravariance.  */
  898.       if (comp_target_types (p2, p1, 1) == 0)
  899.     {
  900.       if (comp_target_types (p1, p2, 1))
  901.         {
  902.           warn_contravariance = 1;
  903.           continue;
  904.         }
  905.       if (strict != 0)
  906.         return 0;
  907. #if 0
  908.       /* What good do these cases do?  */
  909.       if (strict == 0)
  910.         return p2 == void_type_node && TREE_PURPOSE (t1);
  911.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  912. #endif
  913.     }
  914.       /* Target types are compatible--just make sure that if
  915.      we use parameter lists, that they are ok as well.  */
  916.       if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE)
  917.     switch (comp_target_parms (TYPE_ARG_TYPES (p1),
  918.                    TYPE_ARG_TYPES (p2),
  919.                    strict))
  920.       {
  921.       case 0:
  922.         return 0;
  923.       case 1:
  924.         break;
  925.       case 2:
  926.         warn_contravariance = 1;
  927.       }
  928.  
  929.       if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  930.     {
  931.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  932.       if (cmp < 0)
  933.         my_friendly_abort (114);
  934.       if (cmp == 0)
  935.         return 0;
  936.     }
  937.     }
  938.   return 1 + warn_contravariance;
  939. }
  940.  
  941. /* Return 1 if PARMS specifies a fixed number of parameters
  942.    and none of their types is affected by default promotions.  */
  943.  
  944. static int
  945. self_promoting_args_p (parms)
  946.      tree parms;
  947. {
  948.   register tree t;
  949.   for (t = parms; t; t = TREE_CHAIN (t))
  950.     {
  951.       register tree type = TREE_VALUE (t);
  952.  
  953.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  954.     return 0;
  955.  
  956.       if (TYPE_MAIN_VARIANT (type) == float_type_node)
  957.     return 0;
  958.  
  959.       if (type == 0)
  960.     return 0;
  961.  
  962.       if (C_PROMOTING_INTEGER_TYPE_P (type))
  963.     return 0;
  964.     }
  965.   return 1;
  966. }
  967.  
  968. /* Return an unsigned type the same as TYPE in other respects.
  969.  
  970.    C++: must make these work for type variants as well.  */
  971.  
  972. tree
  973. unsigned_type (type)
  974.      tree type;
  975. {
  976.   tree type1 = TYPE_MAIN_VARIANT (type);
  977.   if (type1 == signed_char_type_node || type1 == char_type_node)
  978.     return unsigned_char_type_node;
  979.   if (type1 == integer_type_node)
  980.     return unsigned_type_node;
  981.   if (type1 == short_integer_type_node)
  982.     return short_unsigned_type_node;
  983.   if (type1 == long_integer_type_node)
  984.     return long_unsigned_type_node;
  985.   if (type1 == long_long_integer_type_node)
  986.     return long_long_unsigned_type_node;
  987.   return type;
  988. }
  989.  
  990. /* Return a signed type the same as TYPE in other respects.  */
  991.  
  992. tree
  993. signed_type (type)
  994.      tree type;
  995. {
  996.   tree type1 = TYPE_MAIN_VARIANT (type);
  997.   if (type1 == unsigned_char_type_node || type1 == char_type_node)
  998.     return signed_char_type_node;
  999.   if (type1 == unsigned_type_node)
  1000.     return integer_type_node;
  1001.   if (type1 == short_unsigned_type_node)
  1002.     return short_integer_type_node;
  1003.   if (type1 == long_unsigned_type_node)
  1004.     return long_integer_type_node;
  1005.   if (type1 == long_long_unsigned_type_node)
  1006.     return long_long_integer_type_node;
  1007.   return type;
  1008. }
  1009.  
  1010. /* Return a type the same as TYPE except unsigned or
  1011.    signed according to UNSIGNEDP.  */
  1012.  
  1013. tree
  1014. signed_or_unsigned_type (unsignedp, type)
  1015.      int unsignedp;
  1016.      tree type;
  1017. {
  1018.   if (TREE_CODE (type) != INTEGER_TYPE)
  1019.     return type;
  1020.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  1021.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  1022.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  1023.     return unsignedp ? unsigned_type_node : integer_type_node;
  1024.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  1025.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  1026.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  1027.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  1028.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  1029.     return (unsignedp ? long_long_unsigned_type_node
  1030.         : long_long_integer_type_node);
  1031.   return type;
  1032. }
  1033.  
  1034. tree
  1035. c_sizeof (type)
  1036.      tree type;
  1037. {
  1038.   enum tree_code code = TREE_CODE (type);
  1039.   tree t;
  1040.  
  1041.   if (code == FUNCTION_TYPE)
  1042.     {
  1043.       if (pedantic || warn_pointer_arith)
  1044.     pedwarn ("ANSI C++ forbids taking the sizeof a function type");
  1045.       return size_int (1);
  1046.     }
  1047.   if (code == METHOD_TYPE)
  1048.     {
  1049.       if (pedantic || warn_pointer_arith)
  1050.     pedwarn ("ANSI C++ forbids taking the sizeof a method type");
  1051.       return size_int (1);
  1052.     }
  1053.   if (code == VOID_TYPE)
  1054.     {
  1055.       if (pedantic || warn_pointer_arith)
  1056.     pedwarn ("ANSI C++ forbids taking the sizeof a void type");
  1057.       return size_int (1);
  1058.     }
  1059.   if (code == ERROR_MARK)
  1060.     return size_int (1);
  1061.  
  1062.   /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
  1063.      referenced object.'' */
  1064.   if (code == REFERENCE_TYPE)
  1065.     type = TREE_TYPE (type);
  1066.  
  1067.   /* We couldn't find anything in the ARM or the draft standard that says,
  1068.      one way or the other, if doing sizeof on something that doesn't have
  1069.      an object associated with it is correct or incorrect.  For example, if
  1070.      you declare `struct S { char str[16]; };', and in your program do
  1071.      a `sizeof (S::str)', should we flag that as an error or should we give
  1072.      the size of it?  Since it seems like a reasonable thing to do, we'll go
  1073.      with giving the value.  */
  1074.   if (code == OFFSET_TYPE)
  1075.     type = TREE_TYPE (type);
  1076.  
  1077.   if (TYPE_SIZE (type) == 0)
  1078.     {
  1079.       error ("sizeof applied to an incomplete type");
  1080.       return size_int (0);
  1081.     }
  1082.  
  1083.   /* Convert in case a char is more than one unit.  */
  1084.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1085.           size_int (TYPE_PRECISION (char_type_node)));
  1086.   /* size_binop does not put the constant in range, so do it now.  */
  1087.   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
  1088.     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
  1089.   return t;
  1090. }
  1091.  
  1092. tree
  1093. c_sizeof_nowarn (type)
  1094.      tree type;
  1095. {
  1096.   enum tree_code code = TREE_CODE (type);
  1097.   tree t;
  1098.  
  1099.   if (code == FUNCTION_TYPE
  1100.       || code == METHOD_TYPE
  1101.       || code == VOID_TYPE
  1102.       || code == ERROR_MARK)
  1103.     return size_int (1);
  1104.   if (code == REFERENCE_TYPE)
  1105.     type = TREE_TYPE (type);
  1106.  
  1107.   if (TYPE_SIZE (type) == 0)
  1108.     {
  1109.       /* ??? Tiemann, why have any diagnostic here?
  1110.      There is none in the corresponding function for C.  */
  1111.       warning ("sizeof applied to an incomplete type");
  1112.       return size_int (0);
  1113.     }
  1114.  
  1115.   /* Convert in case a char is more than one unit.  */
  1116.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1117.              size_int (TYPE_PRECISION (char_type_node)));
  1118.   force_fit_type (t, 0);
  1119.   return t;
  1120. }
  1121.  
  1122. /* Implement the __alignof keyword: Return the minimum required
  1123.    alignment of TYPE, measured in bytes.  */
  1124.  
  1125. tree
  1126. c_alignof (type)
  1127.      tree type;
  1128. {
  1129.   enum tree_code code = TREE_CODE (type);
  1130.   tree t;
  1131.  
  1132.   if (code == FUNCTION_TYPE || code == METHOD_TYPE)
  1133.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  1134.  
  1135.   if (code == VOID_TYPE || code == ERROR_MARK)
  1136.     return size_int (1);
  1137.  
  1138.   /* C++: this is really correct!  */
  1139.   if (code == REFERENCE_TYPE)
  1140.     type = TREE_TYPE (type);
  1141.  
  1142.   t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  1143.   force_fit_type (t, 0);
  1144.   return t;
  1145. }
  1146.  
  1147. /* Perform default promotions for C data used in expressions.
  1148.    Arrays and functions are converted to pointers;
  1149.    enumeral types or short or char, to int.
  1150.    In addition, manifest constants symbols are replaced by their values.
  1151.  
  1152.    C++: this will automatically bash references to their target type.  */
  1153.  
  1154. tree
  1155. default_conversion (exp)
  1156.      tree exp;
  1157. {
  1158.   register tree type = TREE_TYPE (exp);
  1159.   register enum tree_code code = TREE_CODE (type);
  1160.  
  1161.   if (code == OFFSET_TYPE /* || TREE_CODE (exp) == OFFSET_REF */ )
  1162.     {
  1163.       if (TREE_CODE (exp) == OFFSET_REF)
  1164.     return default_conversion (resolve_offset_ref (exp));
  1165.  
  1166.       type = TREE_TYPE (type);
  1167.       code = TREE_CODE (type);
  1168.     }
  1169.  
  1170.   if (code == REFERENCE_TYPE)
  1171.     {
  1172.       exp = convert_from_reference (exp);
  1173.       type = TREE_TYPE (exp);
  1174.       code = TREE_CODE (type);
  1175.     }
  1176.  
  1177.   /* Constants can be used directly unless they're not loadable.  */
  1178.   if (TREE_CODE (exp) == CONST_DECL)
  1179.     exp = DECL_INITIAL (exp);
  1180.   /* Replace a nonvolatile const static variable with its value.  */
  1181.   else if (TREE_READONLY_DECL_P (exp) && DECL_MODE (exp) != BLKmode)
  1182.     {
  1183.       exp = decl_constant_value (exp);
  1184.       type = TREE_TYPE (exp);
  1185.     }
  1186.  
  1187.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  1188.      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  1189.  
  1190.   /* Normally convert enums to int,
  1191.      but convert wide enums to something wider.  */
  1192.   if (code == ENUMERAL_TYPE)
  1193.     {
  1194.       type = type_for_size (MAX (TYPE_PRECISION (type),
  1195.                  TYPE_PRECISION (integer_type_node)),
  1196.                 ((flag_traditional
  1197.                   || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
  1198.                  && TREE_UNSIGNED (type)));
  1199.       return convert (type, exp);
  1200.     }
  1201.  
  1202.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  1203.     {
  1204.       /* Traditionally, unsignedness is preserved in default promotions.
  1205.          Otherwise, retain unsignedness if really not getting bigger.  */
  1206.       if (TREE_UNSIGNED (type)
  1207.       && (flag_traditional
  1208.           || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
  1209.     return convert (unsigned_type_node, exp);
  1210.       return convert (integer_type_node, exp);
  1211.     }
  1212.   if (flag_traditional
  1213.       && TYPE_MAIN_VARIANT (type) == float_type_node)
  1214.     return convert (double_type_node, exp);
  1215.   if (code == VOID_TYPE)
  1216.     {
  1217.       error ("void value not ignored as it ought to be");
  1218.       return error_mark_node;
  1219.     }
  1220.   if (code == FUNCTION_TYPE)
  1221.     {
  1222.       return build_unary_op (ADDR_EXPR, exp, 0);
  1223.     }
  1224.   if (code == METHOD_TYPE)
  1225.     {
  1226.       if (TREE_CODE (exp) == OFFSET_REF)
  1227.     {
  1228.       my_friendly_assert (TREE_CODE (TREE_OPERAND (exp, 1)) == FUNCTION_DECL,
  1229.                   308);
  1230.       return build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0);
  1231.     }
  1232.       return build_unary_op (ADDR_EXPR, exp, 0);
  1233.     }
  1234.   if (code == ARRAY_TYPE)
  1235.     {
  1236.       register tree adr;
  1237.       tree restype = TREE_TYPE (type);
  1238.       tree ptrtype;
  1239.  
  1240.       if (TREE_CODE (exp) == INDIRECT_REF)
  1241.     {
  1242.       /* Stripping away the INDIRECT_REF is not the right
  1243.          thing to do for references...  */
  1244.       tree inner = TREE_OPERAND (exp, 0);
  1245.       if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
  1246.         {
  1247.           inner = build1 (CONVERT_EXPR,
  1248.                   build_pointer_type (TREE_TYPE (TREE_TYPE (inner))),
  1249.                   inner);
  1250.           TREE_REFERENCE_EXPR (inner) = 1;
  1251.         }
  1252.       return convert (TYPE_POINTER_TO (TREE_TYPE (type)), inner);
  1253.     }
  1254.  
  1255.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  1256.     {
  1257.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  1258.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  1259.             TREE_OPERAND (exp, 0), op1);
  1260.     }
  1261.  
  1262.       if (!lvalue_p (exp)
  1263.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  1264.     {
  1265.       error ("invalid use of non-lvalue array");
  1266.       return error_mark_node;
  1267.     }
  1268.  
  1269.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
  1270.     restype = build_type_variant (restype, TYPE_READONLY (type),
  1271.                       TYPE_VOLATILE (type));
  1272.  
  1273.       ptrtype = build_pointer_type (restype);
  1274.  
  1275.       if (TREE_CODE (exp) == VAR_DECL)
  1276.     {
  1277.       /* ??? This is not really quite correct
  1278.          in that the type of the operand of ADDR_EXPR
  1279.          is not the target type of the type of the ADDR_EXPR itself.
  1280.          Question is, can this lossage be avoided?  */
  1281.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  1282.       if (mark_addressable (exp) == 0)
  1283.         return error_mark_node;
  1284.       TREE_CONSTANT (adr) = staticp (exp);
  1285.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  1286.       return adr;
  1287.     }
  1288.       /* This way is better for a COMPONENT_REF since it can
  1289.      simplify the offset for a component.  */
  1290.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  1291.       return convert (ptrtype, adr);
  1292.     }
  1293.   return exp;
  1294. }
  1295.  
  1296. tree
  1297. build_object_ref (datum, basetype, field)
  1298.      tree datum, basetype, field;
  1299. {
  1300.   if (is_aggr_typedef (basetype, 1) && datum != error_mark_node)
  1301.     {
  1302.       tree real_basetype = IDENTIFIER_TYPE_VALUE (basetype);
  1303.       if (binfo_or_else (real_basetype, TREE_TYPE (datum)))
  1304.     return build_component_ref (build_scoped_ref (datum, basetype),
  1305.                     field, NULL_TREE, 1);
  1306.     }
  1307.   return error_mark_node;
  1308. }
  1309.  
  1310. /* Like `build_component_ref, but uses an already found field.
  1311.    Must compute visibility for C_C_D.  Otherwise, ok.  */
  1312. tree
  1313. build_component_ref_1 (datum, field, protect)
  1314.      tree datum, field;
  1315.      int protect;
  1316. {
  1317.   register tree basetype = TREE_TYPE (datum);
  1318.   register enum tree_code code = TREE_CODE (basetype);
  1319.   register tree ref;
  1320.  
  1321.   if (code == REFERENCE_TYPE)
  1322.     {
  1323.       datum = convert_from_reference (datum);
  1324.       basetype = TREE_TYPE (datum);
  1325.       code = TREE_CODE (basetype);
  1326.     }
  1327.  
  1328.   if (! IS_AGGR_TYPE_CODE (code))
  1329.     {
  1330.       if (code != ERROR_MARK)
  1331.     cp_error ("request for member `%D' in something not a class, structure or union", field);
  1332.       return error_mark_node;
  1333.     }
  1334.  
  1335.   if (TYPE_SIZE (basetype) == 0)
  1336.     {
  1337.       incomplete_type_error (0, basetype);
  1338.       return error_mark_node;
  1339.     }
  1340.  
  1341.   /* Look up component name in the structure type definition.  */
  1342.  
  1343.   if (field == error_mark_node)
  1344.     my_friendly_abort (115);
  1345.  
  1346.   if (TREE_STATIC (field))
  1347.     return field;
  1348.  
  1349.   if (datum == C_C_D && ! DECL_PUBLIC (field))
  1350.     {
  1351.       enum visibility_type visibility
  1352.     = compute_visibility (TYPE_BINFO (current_class_type), field);
  1353.  
  1354.     if (visibility == visibility_private)
  1355.       {
  1356.     cp_error ("field `%D' is private", field);
  1357.     return error_mark_node;
  1358.       }
  1359.     else if (visibility == visibility_protected)
  1360.       {
  1361.     cp_error ("field `%D' is protected", field);
  1362.     return error_mark_node;
  1363.       }
  1364.     }
  1365.  
  1366.   ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  1367.  
  1368.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1369.     TREE_READONLY (ref) = 1;
  1370.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1371.     TREE_THIS_VOLATILE (ref) = 1;
  1372.   if (DECL_MUTABLE_P (field))
  1373.     TREE_READONLY (ref) = 0;
  1374.  
  1375.   return ref;
  1376. }
  1377.  
  1378. tree
  1379. build_component_ref (datum, component, basetype_path, protect)
  1380.      tree datum, component, basetype_path;
  1381.      int protect;
  1382. {
  1383.   register tree basetype = TREE_TYPE (datum);
  1384.   register enum tree_code code = TREE_CODE (basetype);
  1385.   register tree field = NULL;
  1386.   register tree ref;
  1387.  
  1388.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
  1389.      unless we are not to support things not strictly ANSI.  */
  1390.   switch (TREE_CODE (datum))
  1391.     {
  1392.     case COMPOUND_EXPR:
  1393.       {
  1394.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
  1395.                       basetype_path, protect);
  1396.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  1397.               TREE_OPERAND (datum, 0), value);
  1398.       }
  1399.     case COND_EXPR:
  1400.       return build_conditional_expr
  1401.     (TREE_OPERAND (datum, 0),
  1402.      build_component_ref (TREE_OPERAND (datum, 1), component,
  1403.                   basetype_path, protect),
  1404.      build_component_ref (TREE_OPERAND (datum, 2), component,
  1405.                   basetype_path, protect));
  1406.     }
  1407.  
  1408.   if (code == REFERENCE_TYPE)
  1409.     {
  1410. #if 0
  1411.       /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
  1412.      @@ Maybe that is not right.  */
  1413.       if (TREE_REFERENCE_EXPR (datum))
  1414.     datum = build1 (INDIRECT_REF, TREE_TYPE (basetype), datum);
  1415.       else
  1416. #endif
  1417.     datum = convert_from_reference (datum);
  1418.       basetype = TREE_TYPE (datum);
  1419.       code = TREE_CODE (basetype);
  1420.     }
  1421.  
  1422.   /* First, see if there is a field or component with name COMPONENT. */
  1423.   if (TREE_CODE (component) == TREE_LIST)
  1424.     {
  1425.       my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE
  1426.         && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309);
  1427.       return build (COMPONENT_REF, TREE_TYPE (component), datum, component);
  1428.     }
  1429.   if (TREE_CODE (component) == TYPE_EXPR)
  1430.     return build_component_type_expr (datum, component, NULL_TREE, protect);
  1431.  
  1432.   if (! IS_AGGR_TYPE_CODE (code))
  1433.     {
  1434.       if (code != ERROR_MARK)
  1435.     error ("request for member `%s' in something not a class, structure or union",
  1436.            IDENTIFIER_POINTER (component));
  1437.       return error_mark_node;
  1438.     }
  1439.  
  1440.   if (TYPE_SIZE (basetype) == 0)
  1441.     {
  1442.       incomplete_type_error (0, basetype);
  1443.       return error_mark_node;
  1444.     }
  1445.  
  1446.   if (TREE_CODE (component) == BIT_NOT_EXPR)
  1447.     {
  1448.       if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
  1449.     {
  1450.       cp_error ("destructor specifier `%T::~%T' must have matching names",
  1451.             basetype, TREE_OPERAND (component, 0));
  1452.       return error_mark_node;
  1453.     }
  1454.       if (! TYPE_HAS_DESTRUCTOR (basetype))
  1455.     {
  1456.       cp_error ("type `%T' has no destructor", basetype);
  1457.       return error_mark_node;
  1458.     }
  1459.       return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0);
  1460.     }
  1461.  
  1462.   /* Look up component name in the structure type definition.  */
  1463.   if (CLASSTYPE_VFIELD (basetype)
  1464.       && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
  1465.     /* Special-case this because if we use normal lookups in an ambiguous
  1466.        hierarchy, the compiler will abort (because vptr lookups are
  1467.        not supposed to be ambiguous.  */
  1468.     field = CLASSTYPE_VFIELD (basetype);
  1469.   else
  1470.     {
  1471.       if (basetype_path == NULL_TREE)
  1472.     basetype_path = TYPE_BINFO (basetype);
  1473.       field = lookup_field (basetype_path, component,
  1474.                 protect && ! VFIELD_NAME_P (component), 0);
  1475.       if (field == error_mark_node)
  1476.     return error_mark_node;
  1477.  
  1478.       if (field == NULL_TREE)
  1479.     {
  1480.       /* Not found as a data field, look for it as a method.  If found,
  1481.          then if this is the only possible one, return it, else
  1482.          report ambiguity error.  */
  1483.       tree fndecls = lookup_fnfields (basetype_path, component, 1);
  1484.       if (fndecls == error_mark_node)
  1485.         return error_mark_node;
  1486.       if (fndecls)
  1487.         {
  1488.           if (TREE_CHAIN (fndecls) == NULL_TREE
  1489.           && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE)
  1490.         {
  1491.           enum visibility_type visibility;
  1492.           tree fndecl;
  1493.  
  1494.           /* Unique, so use this one now.  */
  1495.           basetype = TREE_PURPOSE (fndecls);
  1496.           fndecl = TREE_VALUE (fndecls);
  1497.           visibility = compute_visibility (TREE_PURPOSE (fndecls), fndecl);
  1498.           if (visibility == visibility_public)
  1499.             {
  1500.               if (DECL_VINDEX (fndecl)
  1501.               && ! resolves_to_fixed_type_p (datum, 0))
  1502.             {
  1503.               tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1504.               addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr);
  1505.               datum = build_indirect_ref (addr, NULL_PTR);
  1506.               my_friendly_assert (datum != error_mark_node, 310);
  1507.               fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl));
  1508.             }
  1509.               return fndecl;
  1510.             }
  1511.           if (visibility == visibility_protected)
  1512.             cp_error ("member function `%D' is protected", fndecl);
  1513.           else
  1514.             cp_error ("member function `%D' is private", fndecl);
  1515.           return error_mark_node;
  1516.         }
  1517.           else
  1518.         return build (COMPONENT_REF, unknown_type_node, datum, fndecls);
  1519.         }
  1520.  
  1521.       if (component == ansi_opname[(int) TYPE_EXPR])
  1522.         cp_error ("`%#T' has no such type conversion operator", basetype);
  1523.       else
  1524.         cp_error ("`%#T' has no member named `%D'", basetype, component);
  1525.       return error_mark_node;
  1526.     }
  1527.       else if (TREE_TYPE (field) == error_mark_node)
  1528.     return error_mark_node;
  1529.  
  1530.       if (TREE_CODE (field) != FIELD_DECL)
  1531.     {
  1532.       if (TREE_CODE (field) == TYPE_DECL)
  1533.         {
  1534.           error ("invalid use of type decl `%s' as expression",
  1535.              IDENTIFIER_POINTER (DECL_NAME (field)));
  1536.           return error_mark_node;
  1537.         }
  1538.        if (DECL_RTL (field) != 0)
  1539.         assemble_external (field);
  1540.       TREE_USED (field) = 1;
  1541.       return field;
  1542.     }
  1543.     }
  1544.  
  1545.   if (DECL_FIELD_CONTEXT (field) != basetype
  1546.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  1547.     {
  1548.       tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1549.       if (integer_zerop (addr))
  1550.     {
  1551.       error ("invalid reference to NULL ptr, use ptr-to-member instead");
  1552.       return error_mark_node;
  1553.     }
  1554.       addr = convert_pointer_to (DECL_FIELD_CONTEXT (field), addr);
  1555.       datum = build_indirect_ref (addr, NULL_PTR);
  1556.       my_friendly_assert (datum != error_mark_node, 311);
  1557.     }
  1558.   ref = build (COMPONENT_REF, TREE_TYPE (field), break_out_cleanups (datum), field);
  1559.  
  1560.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1561.     TREE_READONLY (ref) = 1;
  1562.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1563.     TREE_THIS_VOLATILE (ref) = 1;
  1564.   if (DECL_MUTABLE_P (field))
  1565.     TREE_READONLY (ref) = 0;
  1566.  
  1567.   return ref;
  1568. }
  1569.  
  1570. /* Given an expression PTR for a pointer, return an expression
  1571.    for the value pointed to.
  1572.    ERRORSTRING is the name of the operator to appear in error messages.
  1573.  
  1574.    This function may need to overload OPERATOR_FNNAME.
  1575.    Must also handle REFERENCE_TYPEs for C++.  */
  1576.  
  1577. tree
  1578. build_x_indirect_ref (ptr, errorstring)
  1579.      tree ptr;
  1580.      char *errorstring;
  1581. {
  1582.   tree rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE);
  1583.  
  1584.   if (rval) return rval;
  1585.   return build_indirect_ref (ptr, errorstring);
  1586. }
  1587.  
  1588. tree
  1589. build_indirect_ref (ptr, errorstring)
  1590.      tree ptr;
  1591.      char *errorstring;
  1592. {
  1593.   register tree pointer = default_conversion (ptr);
  1594.   register tree type = TREE_TYPE (pointer);
  1595.  
  1596.   if (ptr == current_class_decl)
  1597.     return C_C_D;
  1598.  
  1599.   if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
  1600.     {
  1601.       if (TREE_CODE (pointer) == ADDR_EXPR
  1602.       && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  1603.           == TREE_TYPE (type)))
  1604.     return TREE_OPERAND (pointer, 0);
  1605.       else
  1606.     {
  1607.       tree t = TREE_TYPE (type);
  1608.       register tree ref = build1 (INDIRECT_REF,
  1609.                       TYPE_MAIN_VARIANT (t), pointer);
  1610.  
  1611.       TREE_READONLY (ref) = TYPE_READONLY (t);
  1612.       TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  1613.       TREE_SIDE_EFFECTS (ref)
  1614.         = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
  1615.       return ref;
  1616.     }
  1617.     }
  1618.   /* `pointer' won't be an error_mark_node if we were given a
  1619.      pointer to member, so it's cool to check for this here.  */
  1620.   else if (TYPE_PTRMEMFUNC_P (type))
  1621.     error ("use of `%s' on pointer to member", errorstring);
  1622.   else if (pointer != error_mark_node)
  1623.     {
  1624.       if (errorstring)
  1625.     error ("invalid type argument of `%s'", errorstring);
  1626.       else
  1627.     error ("invalid type argument");
  1628.     }
  1629.   return error_mark_node;
  1630. }
  1631.  
  1632. /* This handles expressions of the form "a[i]", which denotes
  1633.    an array reference.
  1634.  
  1635.    This is logically equivalent in C to *(a+i), but we may do it differently.
  1636.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1637.    This avoids forcing the array out of registers, and can work on
  1638.    arrays that are not lvalues (for example, members of structures returned
  1639.    by functions).
  1640.  
  1641.    If INDEX is of some user-defined type, it must be converted to
  1642.    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
  1643.    will inherit the type of the array, which will be some pointer type.  */
  1644.  
  1645. tree
  1646. build_x_array_ref (array, index)
  1647.      tree array, index;
  1648. {
  1649.   tree rval;
  1650.  
  1651.   rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, index, NULL_TREE);
  1652.   if (rval)
  1653.     return rval;
  1654.   return build_array_ref (array, index);
  1655. }
  1656.  
  1657. tree
  1658. build_array_ref (array, idx)
  1659.      tree array, idx;
  1660. {
  1661.   tree itype;
  1662.  
  1663.   if (idx == 0)
  1664.     {
  1665.       error ("subscript missing in array reference");
  1666.       return error_mark_node;
  1667.     }
  1668.  
  1669.   if (TREE_TYPE (array) == error_mark_node
  1670.       || TREE_TYPE (idx) == error_mark_node)
  1671.     return error_mark_node;
  1672.  
  1673.   itype = TREE_TYPE (idx);
  1674.   /* We must check here for the reference, so we can do the possible
  1675.      conversions immediately afterwards.  */
  1676.   if (TREE_CODE (itype) == REFERENCE_TYPE)
  1677.     {
  1678.       idx = convert_from_reference (idx);
  1679.       itype = TREE_TYPE (idx);
  1680.     }
  1681.  
  1682.   if (IS_AGGR_TYPE (itype))
  1683.     {
  1684.       if (TYPE_HAS_INT_CONVERSION (itype))
  1685.     idx = build_type_conversion (CONVERT_EXPR,
  1686.                      integer_type_node, idx, 1);
  1687.       else
  1688.     {
  1689.       error_with_aggr_type (itype,
  1690.                 "type `%s' requires integer conversion for array indexing");
  1691.       return error_mark_node;
  1692.     }
  1693.     }
  1694.  
  1695.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1696.       && TREE_CODE (array) != INDIRECT_REF)
  1697.     {
  1698.       tree rval, type;
  1699.  
  1700.       /* Subscripting with type char is likely to lose
  1701.      on a machine where chars are signed.
  1702.      So warn on any machine, but optionally.
  1703.      Don't warn for unsigned char since that type is safe.
  1704.      Don't warn for signed char because anyone who uses that
  1705.      must have done so deliberately.  */
  1706.       if (warn_char_subscripts
  1707.       && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
  1708.     warning ("array subscript has type `char'");
  1709.  
  1710.       /* Apply default promotions *after* noticing character types.  */
  1711.       idx = default_conversion (idx);
  1712.  
  1713.       if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
  1714.     {
  1715.       error ("array subscript is not an integer");
  1716.       return error_mark_node;
  1717.     }
  1718.  
  1719.       /* An array that is indexed by a non-constant
  1720.      cannot be stored in a register; we must be able to do
  1721.      address arithmetic on its address.
  1722.      Likewise an array of elements of variable size.  */
  1723.       if (TREE_CODE (idx) != INTEGER_CST
  1724.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  1725.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  1726.     {
  1727.       if (mark_addressable (array) == 0)
  1728.         return error_mark_node;
  1729.     }
  1730.       /* An array that is indexed by a constant value which is not within
  1731.      the array bounds cannot be stored in a register either; because we
  1732.      would get a crash in store_bit_field/extract_bit_field when trying
  1733.      to access a non-existent part of the register.  */
  1734.       if (TREE_CODE (idx) == INTEGER_CST
  1735.       && TYPE_VALUES (TREE_TYPE (array))
  1736.       && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
  1737.     {
  1738.       if (mark_addressable (array) == 0)
  1739.         return error_mark_node;
  1740.     }
  1741.  
  1742.       /* Note in C++ we don't bother warning about subscripting a
  1743.      `register' array, since it's legal in C++ to take the address
  1744.      of something with that storage specification.  */
  1745.       if (pedantic && !lvalue_p (array))
  1746.     pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
  1747.  
  1748.       if (pedantic)
  1749.     {
  1750.       tree foo = array;
  1751.       while (TREE_CODE (foo) == COMPONENT_REF)
  1752.         foo = TREE_OPERAND (foo, 0);
  1753.       if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
  1754.         pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
  1755.     }
  1756.  
  1757.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  1758.       rval = build (ARRAY_REF, type, array, idx);
  1759.       /* Array ref is const/volatile if the array elements are
  1760.      or if the array is..  */
  1761.       TREE_READONLY (rval)
  1762.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  1763.         | TREE_READONLY (array));
  1764.       TREE_SIDE_EFFECTS (rval)
  1765.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1766.         | TREE_SIDE_EFFECTS (array));
  1767.       TREE_THIS_VOLATILE (rval)
  1768.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1769.         /* This was added by rms on 16 Nov 91.
  1770.            It fixes  vol struct foo *a;  a->elts[1] 
  1771.            in an inline function.
  1772.            Hope it doesn't break something else.  */
  1773.         | TREE_THIS_VOLATILE (array));
  1774.       return require_complete_type (fold (rval));
  1775.     }
  1776.  
  1777.   {
  1778.     tree ar = default_conversion (array);
  1779.     tree ind = default_conversion (idx);
  1780.  
  1781.     /* Put the integer in IND to simplify error checking.  */
  1782.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  1783.       {
  1784.     tree temp = ar;
  1785.     ar = ind;
  1786.     ind = temp;
  1787.       }
  1788.  
  1789.     if (ar == error_mark_node)
  1790.       return ar;
  1791.  
  1792.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  1793.       {
  1794.     error ("subscripted value is neither array nor pointer");
  1795.     return error_mark_node;
  1796.       }
  1797.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  1798.       {
  1799.     error ("array subscript is not an integer");
  1800.     return error_mark_node;
  1801.       }
  1802.  
  1803.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
  1804.                    "array indexing");
  1805.   }
  1806. }
  1807.  
  1808. /* Build a function call to function FUNCTION with parameters PARAMS.
  1809.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  1810.    TREE_VALUE of each node is a parameter-expression.
  1811.    FUNCTION's data type may be a function type or a pointer-to-function.
  1812.  
  1813.    For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
  1814.    is the list of possible methods that FUNCTION could conceivably
  1815.    be.  If the list of methods comes from a class, then it will be
  1816.    a list of lists (where each element is associated with the class
  1817.    that produced it), otherwise it will be a simple list (for
  1818.    functions overloaded in global scope).
  1819.  
  1820.    In the first case, TREE_VALUE (function) is the head of one of those
  1821.    lists, and TREE_PURPOSE is the name of the function.
  1822.  
  1823.    In the second case, TREE_PURPOSE (function) is the function's
  1824.    name directly.
  1825.  
  1826.    DECL is the class instance variable, usually CURRENT_CLASS_DECL.  */
  1827.  
  1828. /*
  1829.  * [eichin:19911015.1726EST] actually return a possibly incomplete
  1830.  * type
  1831.  */
  1832. tree
  1833. build_x_function_call (function, params, decl)
  1834.      tree function, params, decl;
  1835. {
  1836.   tree type;
  1837.   int is_method;
  1838.  
  1839.   if (function == error_mark_node)
  1840.     return error_mark_node;
  1841.  
  1842.   type = TREE_TYPE (function);
  1843.   is_method = ((TREE_CODE (function) == TREE_LIST
  1844.         && current_class_type != NULL_TREE
  1845.         && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function)
  1846.            || TREE_CODE (function) == IDENTIFIER_NODE
  1847.            || TREE_CODE (type) == METHOD_TYPE
  1848.            || TYPE_PTRMEMFUNC_P (type));
  1849.  
  1850.   /* Handle methods, friends, and overloaded functions, respectively.  */
  1851.   if (is_method)
  1852.     {
  1853.       if (TREE_CODE (function) == FUNCTION_DECL)
  1854.     {
  1855.       if (DECL_NAME (function))
  1856.         function = DECL_NAME (function);
  1857.       else
  1858.         function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function));
  1859.     }
  1860.       else if (TREE_CODE (function) == TREE_LIST)
  1861.     {
  1862. #if 0
  1863.       if (TREE_CODE (TREE_VALUE (function)) == TREE_LIST)
  1864.         function = TREE_PURPOSE (TREE_VALUE (function));
  1865.       else
  1866.         function = TREE_PURPOSE (function);
  1867. #else
  1868.       my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312);
  1869.       function = TREE_PURPOSE (function);
  1870. #endif
  1871.     }
  1872.       else if (TREE_CODE (function) != IDENTIFIER_NODE)
  1873.     {
  1874.       if (TREE_CODE (function) == OFFSET_REF)
  1875.         {
  1876.           if (TREE_OPERAND (function, 0))
  1877.         decl = TREE_OPERAND (function, 0);
  1878.         }
  1879.       /* Call via a pointer to member function.  */
  1880.       if (decl == NULL_TREE)
  1881.         {
  1882.           error ("pointer to member function called, but not in class scope");
  1883.           return error_mark_node;
  1884.         }
  1885.       /* What other type of POINTER_TYPE could this be? */
  1886.       if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE
  1887.           && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function))
  1888.           && TREE_CODE (function) != OFFSET_REF)
  1889.         function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function);
  1890.       goto do_x_function;
  1891.     }
  1892.  
  1893.       /* this is an abbreviated method call.
  1894.          must go through here in case it is a virtual function.
  1895.      @@ Perhaps this could be optimized.  */
  1896.  
  1897.       if (decl == NULL_TREE)
  1898.     {
  1899.       if (current_class_type == NULL_TREE)
  1900.         {
  1901.           error ("object missing in call to method `%s'",
  1902.              IDENTIFIER_POINTER (function));
  1903.           return error_mark_node;
  1904.         }
  1905.       /* Yow: call from a static member function.  */
  1906.       decl = build1 (NOP_EXPR,
  1907.              TYPE_POINTER_TO (current_class_type),
  1908.              error_mark_node);
  1909.     }
  1910.  
  1911.       return build_method_call (decl, function, params,
  1912.                 NULL_TREE, LOOKUP_NORMAL);
  1913.     }
  1914.   else if (TREE_CODE (function) == COMPONENT_REF
  1915.        && type == unknown_type_node)
  1916.     {
  1917.       /* Should we undo what was done in build_component_ref? */
  1918.       if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
  1919.     /* Get the name that build_component_ref hid. */
  1920.     function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
  1921.       else
  1922.     function = TREE_PURPOSE (TREE_OPERAND (function, 1));
  1923.       return build_method_call (decl, function, params,
  1924.                 NULL_TREE, LOOKUP_NORMAL);
  1925.     }
  1926.   else if (TREE_CODE (function) == TREE_LIST)
  1927.     {
  1928.       if (TREE_CHAIN (function) != NULL_TREE)
  1929.         {
  1930.           if (TREE_CODE (TREE_VALUE (function)) == TEMPLATE_DECL)
  1931.             return build_overload_call_maybe (TREE_PURPOSE (function),
  1932.                           params, 1, (struct candidate *)0);
  1933.           else
  1934.             return build_overload_call (TREE_PURPOSE (function), params, 1,
  1935.                     (struct candidate *)0);
  1936.         }
  1937.       else if (TREE_VALUE (function) == NULL_TREE)
  1938.     {
  1939.       error ("function `%s' declared overloaded, but no definitions appear with which to resolve it",
  1940.          IDENTIFIER_POINTER (TREE_PURPOSE (function)));
  1941.       return error_mark_node;
  1942.     }
  1943.       else if (TREE_CODE (TREE_VALUE (function)) == TEMPLATE_DECL)
  1944.     return build_overload_call_maybe (TREE_PURPOSE (function),
  1945.                       params, 1, (struct candidate *)0);
  1946.       else
  1947.     function = TREE_VALUE (function);
  1948.     }
  1949.  
  1950.  do_x_function:
  1951.   if (TREE_CODE (function) == OFFSET_REF)
  1952.     {
  1953.       /* If the component is a data element (or a virtual function), we play
  1954.      games here to make things work.  */
  1955.       tree decl_addr;
  1956.  
  1957.       if (TREE_OPERAND (function, 0))
  1958.     decl = TREE_OPERAND (function, 0);
  1959.       else
  1960.     decl = C_C_D;
  1961.  
  1962.       decl_addr = build_unary_op (ADDR_EXPR, decl, 0);
  1963.       function = get_member_function_from_ptrfunc (&decl_addr, decl,
  1964.                            TREE_OPERAND (function, 1));
  1965.       params = tree_cons (NULL_TREE, decl_addr, params);
  1966.       return build_function_call (function, params);
  1967.     }
  1968.  
  1969.   type = TREE_TYPE (function);
  1970.   if (type != error_mark_node)
  1971.     {
  1972.       if (TREE_CODE (type) == REFERENCE_TYPE)
  1973.     type = TREE_TYPE (type);
  1974.  
  1975.       if (TYPE_LANG_SPECIFIC (type) && TYPE_OVERLOADS_CALL_EXPR (type))
  1976.     return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE);
  1977.     }
  1978.  
  1979.   if (is_method)
  1980.     {
  1981.       tree fntype = TREE_TYPE (function);
  1982.       tree ctypeptr;
  1983.  
  1984.       /* Explicitly named method?  */
  1985.       if (TREE_CODE (function) == FUNCTION_DECL)
  1986.     ctypeptr = TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function));
  1987.       /* Expression with ptr-to-method type?  It could either be a plain
  1988.      usage, or it might be a case where the ptr-to-method is being
  1989.      passed in as an argument.  */
  1990.       else if (TYPE_PTRMEMFUNC_P (fntype))
  1991.     {
  1992.       tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype)));
  1993.       ctypeptr = TYPE_POINTER_TO (rec);
  1994.     }
  1995.       /* Unexpected node type?  */
  1996.       else
  1997.     my_friendly_abort (116);
  1998.       if (decl == NULL_TREE)
  1999.     {
  2000.       if (current_function_decl
  2001.           && DECL_STATIC_FUNCTION_P (current_function_decl))
  2002.         error ("invalid call to member function needing `this' in static member function scope");
  2003.       else
  2004.         error ("pointer to member function called, but not in class scope");
  2005.       return error_mark_node;
  2006.     }
  2007.       if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
  2008.       && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
  2009.     {
  2010.       decl = build_unary_op (ADDR_EXPR, decl, 0);
  2011.       decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl);
  2012.     }
  2013.       else
  2014.     decl = build_c_cast (ctypeptr, decl);
  2015.       params = tree_cons (NULL_TREE, decl, params);
  2016.     }
  2017.  
  2018.   return build_function_call (function, params);
  2019. }
  2020.  
  2021. /* Resolve a pointer to member function.  INSTANCE is the object
  2022.    instance to use, if the member points to a virtual member.  */
  2023.  
  2024. tree
  2025. get_member_function_from_ptrfunc (instance_ptrptr, instance, function)
  2026.      tree *instance_ptrptr;
  2027.      tree instance;
  2028.      tree function;
  2029. {
  2030.   if (TREE_CODE (function) == OFFSET_REF)
  2031.     {
  2032.       function = TREE_OPERAND (function, 1);
  2033.     }
  2034.  
  2035.   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
  2036.     {
  2037.       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
  2038.       tree index = save_expr (convert (integer_type_node,
  2039.                        build_component_ref (function,
  2040.                                 index_identifier,
  2041.                                 0, 0)));
  2042.       tree e1 = build (GT_EXPR, integer_type_node, index, integer_zero_node);
  2043.       tree delta = build_component_ref (function, delta_identifier, 0, 0);
  2044.       tree delta2 = DELTA2_FROM_PTRMEMFUNC (function);
  2045.       tree e2;
  2046.       tree e3;
  2047.       tree aref, vtbl;
  2048.  
  2049.       vtbl = build1 (ADDR_EXPR, ptr_type_node, instance);
  2050.       vtbl = build (PLUS_EXPR,
  2051.             build_pointer_type (build_pointer_type (vtable_entry_type)),
  2052.             vtbl, convert (sizetype, delta2));
  2053.       vtbl = build_indirect_ref (vtbl, NULL_PTR);
  2054.       aref = build_array_ref (vtbl, size_binop (MINUS_EXPR,
  2055.                         index,
  2056.                         integer_one_node));
  2057.       aref = save_expr (aref);
  2058.  
  2059.       /* Save the intermediate result in a SAVE_EXPR so we don't have to
  2060.      compute each component of the virtual function pointer twice.  */ 
  2061.      if (/* !building_cleanup && */ TREE_CODE (aref) == INDIRECT_REF)
  2062.     TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
  2063.       
  2064.       delta = build (PLUS_EXPR, integer_type_node,
  2065.              build_conditional_expr (e1, build_component_ref (aref, delta_identifier, 0, 0), integer_zero_node),
  2066.              delta);
  2067.  
  2068.       *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (*instance_ptrptr),
  2069.                 *instance_ptrptr,
  2070.                 convert (integer_type_node, delta));
  2071.       e2 = build_component_ref (aref, pfn_identifier, 0, 0);
  2072.  
  2073.       e3 = PFN_FROM_PTRMEMFUNC (function);
  2074.       TREE_TYPE (e2) = TREE_TYPE (e3);
  2075.       function = build_conditional_expr (e1, e2, e3);
  2076.     }
  2077.   return function;
  2078. }
  2079.  
  2080. tree
  2081. build_function_call_real (function, params, require_complete)
  2082.      tree function, params;
  2083.      int require_complete;
  2084. {
  2085.   register tree fntype, fndecl;
  2086.   register tree value_type;
  2087.   register tree coerced_params;
  2088.   int is_method;
  2089.  
  2090.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2091.      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
  2092.   if (TREE_CODE (function) == NOP_EXPR
  2093.       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
  2094.     function = TREE_OPERAND (function, 0);
  2095.  
  2096.   if (TREE_CODE (function) == FUNCTION_DECL)
  2097.     {
  2098.       GNU_xref_call (current_function_decl,
  2099.              IDENTIFIER_POINTER (DECL_NAME (function)
  2100.                      ? DECL_NAME (function)
  2101.                      : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function))));
  2102.       assemble_external (function);
  2103.       fndecl = function;
  2104.  
  2105.       /* Convert anything with function type to a pointer-to-function.  */
  2106.       if (pedantic
  2107.       && DECL_NAME (function)
  2108.       && IDENTIFIER_LENGTH (DECL_NAME (function)) == 4
  2109.       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (function)), "main")
  2110.       && DECL_CONTEXT (function) == NULL_TREE)
  2111.     {
  2112.       pedwarn ("ANSI C++ forbids calling `main' from within program");
  2113.     }
  2114.  
  2115.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  2116.      (because calling an inline function does not mean the function
  2117.      needs to be separately compiled).  */
  2118.  
  2119.       if (! DECL_INLINE (function))
  2120.     {
  2121.       assemble_external (function);
  2122.       TREE_USED (function) = 1;
  2123.     }
  2124.  
  2125.       fntype = build_type_variant (TREE_TYPE (function),
  2126.                    TREE_READONLY (function),
  2127.                    TREE_THIS_VOLATILE (function));
  2128.       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
  2129.     }
  2130.   else
  2131.     {
  2132.       fndecl = NULL_TREE;
  2133.  
  2134.       /* Convert anything with function type to a pointer-to-function.  */
  2135.       if (function == error_mark_node)
  2136.     return error_mark_node;
  2137.       function = default_conversion (function);
  2138.     }
  2139.  
  2140.   fntype = TREE_TYPE (function);
  2141.  
  2142.   if (TYPE_PTRMEMFUNC_P (fntype))
  2143.     {
  2144.       tree instance_ptr = build_unary_op (ADDR_EXPR, C_C_D, 0);
  2145.       fntype = TYPE_PTRMEMFUNC_FN_TYPE (fntype);
  2146.       function = get_member_function_from_ptrfunc (&instance_ptr, C_C_D, function);
  2147.     }
  2148.  
  2149.   is_method = (TREE_CODE (fntype) == POINTER_TYPE
  2150.            && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
  2151.  
  2152.   if (!((TREE_CODE (fntype) == POINTER_TYPE
  2153.      && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
  2154.     || is_method))
  2155.     {
  2156.       error ("called object is not a function");
  2157.       return error_mark_node;
  2158.     }
  2159.  
  2160.   /* fntype now gets the type of function pointed to.  */
  2161.   fntype = TREE_TYPE (fntype);
  2162.  
  2163.   /* Convert the parameters to the types declared in the
  2164.      function prototype, or apply default promotions.  */
  2165.  
  2166.   coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
  2167.                       params, fndecl, LOOKUP_NORMAL);
  2168.  
  2169.   /* Recognize certain built-in functions so we can make tree-codes
  2170.      other than CALL_EXPR.  We do this when it enables fold-const.c
  2171.      to do something useful.  */
  2172.  
  2173.   if (TREE_CODE (function) == ADDR_EXPR
  2174.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  2175.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  2176.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  2177.       {
  2178.       case BUILT_IN_ABS:
  2179.       case BUILT_IN_LABS:
  2180.       case BUILT_IN_FABS:
  2181.     if (coerced_params == 0)
  2182.       return integer_zero_node;
  2183.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  2184.       }
  2185.  
  2186.   /* C++ */
  2187.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  2188.   {
  2189.     register tree result = 
  2190.       build (CALL_EXPR, value_type,
  2191.          function, coerced_params, NULL_TREE);
  2192.  
  2193.     TREE_SIDE_EFFECTS (result) = 1;
  2194.     TREE_RAISES (result) |= !! TYPE_RAISES_EXCEPTIONS (fntype);
  2195.     if (! require_complete)
  2196.       return result;
  2197.     if (value_type == void_type_node)
  2198.       return result;
  2199.     return require_complete_type (result);
  2200.   }
  2201. }
  2202.  
  2203. tree
  2204. build_function_call (function, params)
  2205.      tree function, params;
  2206. {
  2207.   return build_function_call_real (function, params, 1);
  2208. }
  2209.      
  2210. tree
  2211. build_function_call_maybe (function, params)
  2212.      tree function, params;
  2213. {
  2214.   return build_function_call_real (function, params, 0);
  2215. }
  2216.  
  2217.  
  2218. /* Convert the actual parameter expressions in the list VALUES
  2219.    to the types in the list TYPELIST.
  2220.    If parmdecls is exhausted, or when an element has NULL as its type,
  2221.    perform the default conversions.
  2222.  
  2223.    RETURN_LOC is the location of the return value, if known, NULL_TREE
  2224.    otherwise.  This is useful in the case where we can avoid creating
  2225.    a temporary variable in the case where we can initialize the return
  2226.    value directly.  If we are not eliding constructors, then we set this
  2227.    to NULL_TREE to avoid this avoidance.
  2228.  
  2229.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  2230.  
  2231.    This is also where warnings about wrong number of args are generated.
  2232.    
  2233.    Return a list of expressions for the parameters as converted.
  2234.  
  2235.    Both VALUES and the returned value are chains of TREE_LIST nodes
  2236.    with the elements of the list in the TREE_VALUE slots of those nodes.
  2237.  
  2238.    In C++, unspecified trailing parameters can be filled in with their
  2239.    default arguments, if such were specified.  Do so here.  */
  2240.  
  2241. tree
  2242. convert_arguments (return_loc, typelist, values, fndecl, flags)
  2243.      tree return_loc, typelist, values, fndecl;
  2244.      int flags;
  2245. {
  2246.   extern tree gc_protect_fndecl;
  2247.   register tree typetail, valtail;
  2248.   register tree result = NULL_TREE;
  2249.   char *called_thing;
  2250.   int maybe_raises = 0;
  2251.   int i = 0;
  2252.  
  2253.   if (! flag_elide_constructors)
  2254.     return_loc = 0;
  2255.  
  2256.   if (fndecl)
  2257.     {
  2258.       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
  2259.     {
  2260.       if (DECL_NAME (fndecl) == NULL_TREE
  2261.           || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
  2262.         called_thing = "constructor";
  2263.       else
  2264.         called_thing = "member function";
  2265.       i -= 1;
  2266.     }
  2267.       else
  2268.     {
  2269.       called_thing = "function";
  2270.     }
  2271.     }
  2272.  
  2273.   for (valtail = values, typetail = typelist;
  2274.        valtail;
  2275.        valtail = TREE_CHAIN (valtail), i++)
  2276.     {
  2277.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  2278.       register tree val = TREE_VALUE (valtail);
  2279.  
  2280.       if (type == void_type_node)
  2281.     {
  2282.       if (fndecl)
  2283.         {
  2284.           char *buf = (char *)alloca (40 + strlen (called_thing));
  2285.           sprintf (buf, "too many arguments to %s `%%s'", called_thing);
  2286.           error_with_decl (fndecl, buf);
  2287.           error ("at this point in file");
  2288.         }
  2289.       else
  2290.         error ("too many arguments to function");
  2291.       /* In case anybody wants to know if this argument
  2292.          list is valid.  */
  2293.       if (result)
  2294.         TREE_TYPE (tree_last (result)) = error_mark_node;
  2295.       break;
  2296.     }
  2297.  
  2298.       /* The tree type of the parameter being passed may not yet be
  2299.      known.  In this case, its type is TYPE_UNKNOWN, and will
  2300.      be instantiated by the type given by TYPE.  If TYPE
  2301.      is also NULL, the tree type of VAL is ERROR_MARK_NODE.  */
  2302.       if (type && type_unknown_p (val))
  2303.     val = require_instantiated_type (type, val, integer_zero_node);
  2304.       else if (type_unknown_p (val))
  2305.     {
  2306.       /* Strip the `&' from an overloaded FUNCTION_DECL.  */
  2307.       if (TREE_CODE (val) == ADDR_EXPR)
  2308.         val = TREE_OPERAND (val, 0);
  2309.       if (TREE_CODE (val) == TREE_LIST
  2310.           && TREE_CHAIN (val) == NULL_TREE
  2311.           && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE
  2312.           && (TREE_TYPE (val) == unknown_type_node
  2313.           || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE))
  2314.         /* Instantiates automatically.  */
  2315.         val = TREE_VALUE (val);
  2316.       else
  2317.         {
  2318.           error ("insufficient type information in parameter list");
  2319.           val = integer_zero_node;
  2320.         }
  2321.     }
  2322.       else if (TREE_CODE (val) == OFFSET_REF)
  2323.     val = resolve_offset_ref (val);
  2324.  
  2325.       {
  2326. #if 0
  2327.     /* This code forces the assumption that if we have a ptr-to-func
  2328.        type in an arglist, that every routine that wants to check
  2329.        its validity has done so, and thus we need not do any
  2330.        more conversion.  I don't remember why this is necessary.  */
  2331.     else if (TREE_CODE (ttype) == FUNCTION_TYPE
  2332.          && (type == NULL
  2333.              || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
  2334.              || TREE_CODE (TREE_TYPE (type)) == VOID_TYPE))
  2335.       {
  2336.         type = build_pointer_type (ttype);
  2337.       }
  2338. #endif
  2339.       }
  2340.  
  2341.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2342.      Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
  2343.       if (TREE_CODE (val) == NOP_EXPR
  2344.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
  2345.     val = TREE_OPERAND (val, 0);
  2346.  
  2347.       if ((type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
  2348.       && (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  2349.           || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
  2350.           || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE))
  2351.     val = default_conversion (val);
  2352.  
  2353.       val = require_complete_type (val);
  2354.  
  2355.       if (val == error_mark_node)
  2356.     continue;
  2357.  
  2358.       maybe_raises |= TREE_RAISES (val);
  2359.  
  2360.       if (type != 0)
  2361.     {
  2362.       /* Formal parm type is specified by a function prototype.  */
  2363.       tree parmval;
  2364.  
  2365.       if (TYPE_SIZE (type) == 0)
  2366.         {
  2367.           error ("parameter type of called function is incomplete");
  2368.           parmval = val;
  2369.         }
  2370.       else
  2371.         {
  2372. #ifdef PROMOTE_PROTOTYPES
  2373.           /* Rather than truncating and then reextending,
  2374.          convert directly to int, if that's the type we will want.  */
  2375.           if (! flag_traditional
  2376.           && (TREE_CODE (type) == INTEGER_TYPE
  2377.               || TREE_CODE (type) == ENUMERAL_TYPE)
  2378.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2379.         type = integer_type_node;
  2380. #endif
  2381.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2382.                             "argument passing", fndecl, i);
  2383. #ifdef PROMOTE_PROTOTYPES
  2384.           if ((TREE_CODE (type) == INTEGER_TYPE
  2385.            || TREE_CODE (type) == ENUMERAL_TYPE)
  2386.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2387.         parmval = default_conversion (parmval);
  2388. #endif
  2389.         }
  2390.       result = tree_cons (NULL_TREE, parmval, result);
  2391.     }
  2392.       else
  2393.     {
  2394.       if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
  2395.         val = convert_from_reference (val);
  2396.  
  2397.       if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  2398.           && (TYPE_PRECISION (TREE_TYPE (val))
  2399.           < TYPE_PRECISION (double_type_node)))
  2400.         /* Convert `float' to `double'.  */
  2401.         result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  2402.       else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
  2403.            && (TYPE_GETS_INIT_REF (TREE_TYPE (val))
  2404.                || TYPE_GETS_ASSIGN_REF (TREE_TYPE (val))))
  2405.         {
  2406.           warning ("cannot pass objects of type `%s' through `...'",
  2407.                TYPE_NAME_STRING (TREE_TYPE (val)));
  2408.           result = tree_cons (NULL_TREE, val, result);
  2409.         }
  2410.       else
  2411.         /* Convert `short' and `char' to full-size `int'.  */
  2412.         result = tree_cons (NULL_TREE, default_conversion (val), result);
  2413.     }
  2414.  
  2415.       if (flag_gc
  2416.       /* There are certain functions for which we don't need
  2417.          to protect our arguments.  GC_PROTECT_FNDECL is one.  */
  2418.       && fndecl != gc_protect_fndecl
  2419.       && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result)))
  2420.       && ! value_safe_from_gc (NULL_TREE, TREE_VALUE (result)))
  2421.     /* This will build a temporary variable whose cleanup is
  2422.        to clear the obstack entry.  */
  2423.     TREE_VALUE (result) = protect_value_from_gc (NULL_TREE,
  2424.                              TREE_VALUE (result));
  2425.  
  2426.       if (typetail)
  2427.     typetail = TREE_CHAIN (typetail);
  2428.     }
  2429.  
  2430.   if (typetail != 0 && typetail != void_list_node)
  2431.     {
  2432.       /* See if there are default arguments that can be used */
  2433.       if (TREE_PURPOSE (typetail))
  2434.     {
  2435.       while (typetail != void_list_node)
  2436.         {
  2437.           tree type = TREE_VALUE (typetail);
  2438.           tree val = TREE_PURPOSE (typetail);
  2439.           tree parmval;
  2440.  
  2441.           if (val == NULL_TREE)
  2442.         parmval = error_mark_node;
  2443.           else if (TREE_CODE (val) == CONSTRUCTOR)
  2444.         {
  2445.           parmval = digest_init (type, val, (tree *)0);
  2446.           parmval = convert_for_initialization (return_loc, type, parmval, flags,
  2447.                             "default constructor", fndecl, i);
  2448.         }
  2449.           else
  2450.         {
  2451.           /* This could get clobbered by the following call.  */
  2452.           if (TREE_HAS_CONSTRUCTOR (val))
  2453.             val = copy_node (val);
  2454.  
  2455.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2456.                             "default argument", fndecl, i);
  2457. #ifdef PROMOTE_PROTOTYPES
  2458.           if ((TREE_CODE (type) == INTEGER_TYPE
  2459.                || TREE_CODE (type) == ENUMERAL_TYPE)
  2460.               && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2461.             parmval = default_conversion (parmval);
  2462. #endif
  2463.         }
  2464.           maybe_raises |= TREE_RAISES (parmval);
  2465.  
  2466.           if (flag_gc
  2467.           && type_needs_gc_entry (TREE_TYPE (parmval))
  2468.           && ! value_safe_from_gc (NULL_TREE, parmval))
  2469.         parmval = protect_value_from_gc (NULL_TREE, parmval);
  2470.  
  2471.           result = tree_cons (0, parmval, result);
  2472.           typetail = TREE_CHAIN (typetail);
  2473.           /* ends with `...'.  */
  2474.           if (typetail == NULL_TREE)
  2475.         break;
  2476.         }
  2477.     }
  2478.       else
  2479.     {
  2480.       if (fndecl)
  2481.         {
  2482.           char *buf = (char *)alloca (32 + strlen (called_thing));
  2483.           sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
  2484.           cp_error_at (buf, fndecl);
  2485.           error ("at this point in file");
  2486.         }
  2487.       else
  2488.         error ("too few arguments to function");
  2489.       return error_mark_list;
  2490.     }
  2491.     }
  2492.   if (result)
  2493.     TREE_RAISES (result) = maybe_raises;
  2494.  
  2495.   return nreverse (result);
  2496. }
  2497.  
  2498. /* Build a binary-operation expression, after performing default
  2499.    conversions on the operands.  CODE is the kind of expression to build.  */
  2500.  
  2501. tree
  2502. build_x_binary_op (code, arg1, arg2)
  2503.      enum tree_code code;
  2504.      tree arg1, arg2;
  2505. {
  2506.   tree rval;
  2507.  
  2508.   /* If there's any way we can call this function, do so.  */
  2509.   if (rval = build_opfncall (code, 0, arg1, arg2, NULL_TREE))
  2510.     {
  2511.       /* If it's accessible, we win.  */
  2512.       if (rval = build_opfncall (code, LOOKUP_PROTECT, arg1, arg2, NULL_TREE))
  2513.     return rval;
  2514.       /* Else, report an error.  */
  2515.       build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
  2516.       return error_mark_node;
  2517.     }
  2518.   if (code == MEMBER_REF)
  2519.     return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR),
  2520.                   arg2);
  2521.   return build_binary_op (code, arg1, arg2, 1);
  2522. }
  2523.  
  2524. tree
  2525. build_binary_op (code, arg1, arg2, convert_p)
  2526.      enum tree_code code;
  2527.      tree arg1, arg2;
  2528.      int convert_p;
  2529. {
  2530.   tree type1, type2;
  2531.   tree args[2];
  2532.  
  2533.   args[0] = arg1;
  2534.   args[1] = arg2;
  2535.  
  2536.   if (convert_p)
  2537.     {
  2538.       args[0] = default_conversion (args[0]);
  2539.       args[1] = default_conversion (args[1]);
  2540.  
  2541.       if (type_unknown_p (args[0]))
  2542.     {
  2543.       args[0] = instantiate_type (TREE_TYPE (args[1]), args[0], 1);
  2544.       args[0] = default_conversion (args[0]);
  2545.     }
  2546.       else if (type_unknown_p (args[1]))
  2547.     {
  2548.       args[1] = require_instantiated_type (TREE_TYPE (args[0]),
  2549.                            args[1],
  2550.                            error_mark_node);
  2551.       args[1] = default_conversion (args[1]);
  2552.     }
  2553.  
  2554.       type1 = TREE_TYPE (args[0]);
  2555.       type2 = TREE_TYPE (args[1]);
  2556.  
  2557.       if (IS_AGGR_TYPE_2 (type1, type2) && ! TYPE_PTRMEMFUNC_P (type1))
  2558.     {
  2559.       /* Try to convert this to something reasonable.  */
  2560.       if (! build_default_binary_type_conversion(code, &args[0], &args[1]))
  2561.         return error_mark_node;
  2562.     }
  2563.       else if ((IS_AGGR_TYPE (type1) && ! TYPE_PTRMEMFUNC_P (type1))
  2564.            || (IS_AGGR_TYPE (type2) && ! TYPE_PTRMEMFUNC_P (type2)))
  2565.     {
  2566.       int convert_index = IS_AGGR_TYPE (type2);
  2567.       /* Avoid being tripped up by things like (ARG1 != 0).  */
  2568.       tree types[2], try;
  2569.       
  2570.       types[0] = type1; types[1] = type2;
  2571.       try = build_type_conversion (code, types[convert_index ^ 1],
  2572.                        args[convert_index], 1);
  2573.       
  2574.       if (try == 0
  2575.           && args[1] == integer_zero_node
  2576.           && (code == NE_EXPR || code == EQ_EXPR))
  2577.         try = build_type_conversion (code, ptr_type_node,
  2578.                      args[convert_index], 1);
  2579.       if (try == 0)
  2580.         {
  2581.           cp_error ("no member function `%T::operator %s(%#T)'",
  2582.               types[convert_index],
  2583.               opname_tab[(int) code]
  2584.               ? opname_tab[(int) code] : "<unknown>",
  2585.               types[convert_index ^ 1]);
  2586.           return error_mark_node;
  2587.         }
  2588.       if (try == error_mark_node)
  2589.         error ("ambiguous pointer conversion");
  2590.       args[convert_index] = try;
  2591.     }
  2592.     }
  2593.   return build_binary_op_nodefault (code, args[0], args[1], code);
  2594. }
  2595.  
  2596. /* Build a binary-operation expression without default conversions.
  2597.    CODE is the kind of expression to build.
  2598.    This function differs from `build' in several ways:
  2599.    the data type of the result is computed and recorded in it,
  2600.    warnings are generated if arg data types are invalid,
  2601.    special handling for addition and subtraction of pointers is known,
  2602.    and some optimization is done (operations on narrow ints
  2603.    are done in the narrower type when that gives the same result).
  2604.    Constant folding is also done before the result is returned.
  2605.  
  2606.    ERROR_CODE is the code that determines what to say in error messages.
  2607.    It is usually, but not always, the same as CODE.
  2608.  
  2609.    Note that the operands will never have enumeral types
  2610.    because either they have just had the default conversions performed
  2611.    or they have both just been converted to some other type in which
  2612.    the arithmetic is to be done.
  2613.  
  2614.    C++: must do special pointer arithmetic when implementing
  2615.    multiple inheritance, and deal with pointer to member functions.  */
  2616.  
  2617. tree
  2618. build_binary_op_nodefault (code, op0, op1, error_code)
  2619.      enum tree_code code;
  2620.      tree op0, op1;
  2621.      enum tree_code error_code;
  2622. {
  2623.   tree type0 = TREE_TYPE (op0), type1 = TREE_TYPE (op1);
  2624.  
  2625.   /* The expression codes of the data types of the arguments tell us
  2626.      whether the arguments are integers, floating, pointers, etc.  */
  2627.   register enum tree_code code0 = TREE_CODE (type0);
  2628.   register enum tree_code code1 = TREE_CODE (type1);
  2629.  
  2630.   /* Expression code to give to the expression when it is built.
  2631.      Normally this is CODE, which is what the caller asked for,
  2632.      but in some special cases we change it.  */
  2633.   register enum tree_code resultcode = code;
  2634.  
  2635.   /* Data type in which the computation is to be performed.
  2636.      In the simplest cases this is the common type of the arguments.  */
  2637.   register tree result_type = NULL;
  2638.  
  2639.   /* Nonzero means operands have already been type-converted
  2640.      in whatever way is necessary.
  2641.      Zero means they need to be converted to RESULT_TYPE.  */
  2642.   int converted = 0;
  2643.  
  2644.   /* Nonzero means after finally constructing the expression
  2645.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  2646.   tree final_type = 0;
  2647.  
  2648.   /* Nonzero if this is an operation like MIN or MAX which can
  2649.      safely be computed in short if both args are promoted shorts.
  2650.      Also implies COMMON.
  2651.      -1 indicates a bitwise operation; this makes a difference
  2652.      in the exact conditions for when it is safe to do the operation
  2653.      in a narrower mode.  */
  2654.   int shorten = 0;
  2655.  
  2656.   /* Nonzero if this is a comparison operation;
  2657.      if both args are promoted shorts, compare the original shorts.
  2658.      Also implies COMMON.  */
  2659.   int short_compare = 0;
  2660.  
  2661.   /* Nonzero if this is a right-shift operation, which can be computed on the
  2662.      original short and then promoted if the operand is a promoted short.  */
  2663.   int short_shift = 0;
  2664.  
  2665.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  2666.   int common = 0;
  2667.  
  2668.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  2669.   STRIP_TYPE_NOPS (op0);
  2670.   STRIP_TYPE_NOPS (op1);
  2671.  
  2672.   /* If an error was already reported for one of the arguments,
  2673.      avoid reporting another error.  */
  2674.  
  2675.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  2676.     return error_mark_node;
  2677.  
  2678.   switch (code)
  2679.     {
  2680.     case PLUS_EXPR:
  2681.       /* Handle the pointer + int case.  */
  2682.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2683.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  2684.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  2685.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  2686.       else
  2687.     common = 1;
  2688.       break;
  2689.  
  2690.     case MINUS_EXPR:
  2691.       /* Subtraction of two similar pointers.
  2692.      We must subtract them as integers, then divide by object size.  */
  2693.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  2694.       && comp_target_types (type0, type1, 1))
  2695.     return pointer_diff (op0, op1);
  2696.       /* Handle pointer minus int.  Just like pointer plus int.  */
  2697.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2698.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  2699.       else
  2700.     common = 1;
  2701.       break;
  2702.  
  2703.     case MULT_EXPR:
  2704.       common = 1;
  2705.       break;
  2706.  
  2707.     case TRUNC_DIV_EXPR:
  2708.     case CEIL_DIV_EXPR:
  2709.     case FLOOR_DIV_EXPR:
  2710.     case ROUND_DIV_EXPR:
  2711.     case EXACT_DIV_EXPR:
  2712.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2713.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2714.     {
  2715.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  2716.         resultcode = RDIV_EXPR;
  2717.       else
  2718.         shorten = 1;
  2719.       common = 1;
  2720.     }
  2721.       break;
  2722.  
  2723.     case BIT_AND_EXPR:
  2724.     case BIT_ANDTC_EXPR:
  2725.     case BIT_IOR_EXPR:
  2726.     case BIT_XOR_EXPR:
  2727.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2728.     shorten = -1;
  2729.       /* If one operand is a constant, and the other is a short type
  2730.      that has been converted to an int,
  2731.      really do the work in the short type and then convert the
  2732.      result to int.  If we are lucky, the constant will be 0 or 1
  2733.      in the short type, making the entire operation go away.  */
  2734.       if (TREE_CODE (op0) == INTEGER_CST
  2735.       && TREE_CODE (op1) == NOP_EXPR
  2736.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  2737.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  2738.     {
  2739.       final_type = result_type;
  2740.       op1 = TREE_OPERAND (op1, 0);
  2741.       result_type = TREE_TYPE (op1);
  2742.     }
  2743.       if (TREE_CODE (op1) == INTEGER_CST
  2744.       && TREE_CODE (op0) == NOP_EXPR
  2745.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  2746.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  2747.     {
  2748.       final_type = result_type;
  2749.       op0 = TREE_OPERAND (op0, 0);
  2750.       result_type = TREE_TYPE (op0);
  2751.     }
  2752.       break;
  2753.  
  2754.     case TRUNC_MOD_EXPR:
  2755.     case FLOOR_MOD_EXPR:
  2756.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2757.     shorten = 1;
  2758.       break;
  2759.  
  2760.     case TRUTH_ANDIF_EXPR:
  2761.     case TRUTH_ORIF_EXPR:
  2762.     case TRUTH_AND_EXPR:
  2763.     case TRUTH_OR_EXPR:
  2764.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  2765.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  2766.     {
  2767.       /* Result of these operations is always an int,
  2768.          but that does not mean the operands should be
  2769.          converted to ints!  */
  2770.       result_type = integer_type_node;
  2771.       op0 = truthvalue_conversion (op0);
  2772.       op1 = truthvalue_conversion (op1);
  2773.       converted = 1;
  2774.     }
  2775.       break;
  2776.  
  2777.       /* Shift operations: result has same type as first operand;
  2778.      always convert second operand to int.
  2779.      Also set SHORT_SHIFT if shifting rightward.  */
  2780.  
  2781.     case RSHIFT_EXPR:
  2782.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2783.     {
  2784.       result_type = type0;
  2785.       if (TREE_CODE (op1) == INTEGER_CST)
  2786.         {
  2787.           if (tree_int_cst_lt (op1, integer_zero_node))
  2788.         warning ("right shift count is negative");
  2789.           else
  2790.         {
  2791.           if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
  2792.             short_shift = 1;
  2793.           if (TREE_INT_CST_HIGH (op1) != 0
  2794.               || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2795.               >= TYPE_PRECISION (type0)))
  2796.             warning ("right shift count >= width of type");
  2797.         }
  2798.         }
  2799.       /* Convert the shift-count to an integer, regardless of
  2800.          size of value being shifted.  */
  2801.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2802.         op1 = convert (integer_type_node, op1);
  2803.       /* Avoid converting op1 to result_type later.  */
  2804.       converted = 1;
  2805.     }
  2806.       break;
  2807.  
  2808.     case LSHIFT_EXPR:
  2809.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2810.     {
  2811.       result_type = type0;
  2812.       if (TREE_CODE (op1) == INTEGER_CST)
  2813.         {
  2814.           if (tree_int_cst_lt (op1, integer_zero_node))
  2815.         warning ("left shift count is negative");
  2816.           else if (TREE_INT_CST_HIGH (op1) != 0
  2817.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2818.                >= TYPE_PRECISION (type0)))
  2819.         warning ("left shift count >= width of type");
  2820.         }
  2821.       /* Convert the shift-count to an integer, regardless of
  2822.          size of value being shifted.  */
  2823.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2824.         op1 = convert (integer_type_node, op1);
  2825.       /* Avoid converting op1 to result_type later.  */
  2826.       converted = 1;
  2827.     }
  2828.       break;
  2829.  
  2830.     case RROTATE_EXPR:
  2831.     case LROTATE_EXPR:
  2832.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2833.     {
  2834.       result_type = type0;
  2835.       if (TREE_CODE (op1) == INTEGER_CST)
  2836.         {
  2837.           if (tree_int_cst_lt (op1, integer_zero_node))
  2838.         warning ("%s rotate count is negative",
  2839.              (code == LROTATE_EXPR) ? "left" : "right");
  2840.           else if (TREE_INT_CST_HIGH (op1) != 0
  2841.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2842.                >= TYPE_PRECISION (type0)))
  2843.         warning ("%s rotate count >= width of type",
  2844.              (code == LROTATE_EXPR) ? "left" : "right");
  2845.         }
  2846.       /* Convert the shift-count to an integer, regardless of
  2847.          size of value being shifted.  */
  2848.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2849.         op1 = convert (integer_type_node, op1);
  2850.     }
  2851.       break;
  2852.  
  2853.     case EQ_EXPR:
  2854.     case NE_EXPR:
  2855.       /* Result of comparison is always int,
  2856.      but don't convert the args to int!  */
  2857.       result_type = integer_type_node;
  2858.       converted = 1;
  2859.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2860.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2861.     short_compare = 1;
  2862.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2863.     {
  2864.       register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0));
  2865.       register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
  2866.       /* Anything compares with void *.  void * compares with anything.
  2867.          Otherwise, the targets must be the same.  */
  2868.       if (tt0 != tt1 && TREE_CODE (tt0) == RECORD_TYPE
  2869.           && TREE_CODE (tt1) == RECORD_TYPE)
  2870.         {
  2871.           tree base = common_base_type (tt0, tt1);
  2872.           if (base == NULL_TREE)
  2873.         warning ("comparison of distinct object pointer types");
  2874.           else if (base == error_mark_node)
  2875.         {
  2876.           message_2_types (error, "comparison of pointer types `%s*' and `%s*' requires conversion to ambiguous supertype", tt0, tt1);
  2877.           return error_mark_node;
  2878.         }
  2879.           else
  2880.         {
  2881.           if (integer_zerop (op0))
  2882.             op0 = null_pointer_node;
  2883.           else
  2884.             op0 = convert_pointer_to (base, op0);
  2885.           if (integer_zerop (op1))
  2886.             op1 = null_pointer_node;
  2887.           else
  2888.             op1 = convert_pointer_to (base, op1);
  2889.         }
  2890.         }
  2891.       else if (comp_target_types (type0, type1, 1))
  2892.         ;
  2893.       else if (tt0 == void_type_node)
  2894.         {
  2895.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  2896.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  2897.         }
  2898.       else if (tt1 == void_type_node)
  2899.         {
  2900.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  2901.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  2902.         }
  2903.       else
  2904.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2905.     }
  2906.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2907.            && integer_zerop (op1))
  2908.     op1 = null_pointer_node;
  2909.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2910.            && integer_zerop (op0))
  2911.     op0 = null_pointer_node;
  2912.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2913.     {
  2914.       error ("ANSI C++ forbids comparison between pointer and integer");
  2915.       op1 = convert (TREE_TYPE (op0), op1);
  2916.     }
  2917.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2918.     {
  2919.       error ("ANSI C++ forbids comparison between pointer and integer");
  2920.       op0 = convert (TREE_TYPE (op1), op0);
  2921.     }
  2922.       else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST
  2923.            && integer_zerop (op1))
  2924.     {
  2925.       op0 = build_component_ref (op0, index_identifier, 0, 0);
  2926.       op1 = integer_zero_node;
  2927.     }
  2928.       else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
  2929.            && integer_zerop (op0))
  2930.     {
  2931.       op0 = build_component_ref (op1, index_identifier, 0, 0);
  2932.       op1 = integer_zero_node;
  2933.     }
  2934.       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
  2935.            && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
  2936.            == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
  2937.     {
  2938.       /* The code we generate for the test is:
  2939.  
  2940.       (op0.index == op1.index
  2941.        && ((op1.index != -1 && op0.delta2 == op1.delta2)
  2942.            || op0.pfn == op1.pfn)) */
  2943.  
  2944.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  2945.       tree index1 = save_expr (build_component_ref (op1, index_identifier, 0, 0));
  2946.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  2947.       tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
  2948.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  2949.       tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
  2950.       tree e1, e2, e3;
  2951.       tree integer_neg_one_node
  2952.         = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  2953.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  2954.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  2955.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  2956.       e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
  2957.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  2958.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  2959.       if (code == EQ_EXPR)
  2960.         return e2;
  2961.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  2962.     }
  2963.       else if (TYPE_PTRMEMFUNC_P (type0)
  2964.            && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
  2965.     {
  2966.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  2967.       tree index1;
  2968.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  2969.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  2970.       tree delta21 = integer_zero_node;
  2971.       tree e1, e2, e3;
  2972.       tree integer_neg_one_node
  2973.         = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  2974.       if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
  2975.           && DECL_VINDEX (TREE_OPERAND (op1, 0)))
  2976.         {
  2977.           /* Map everything down one to make room for the null pointer to member.  */
  2978.           index1 = size_binop (PLUS_EXPR,
  2979.                    DECL_VINDEX (TREE_OPERAND (op1, 0)),
  2980.                    integer_one_node);
  2981.           op1 = integer_zero_node;
  2982.           delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1)));
  2983.           delta21 = DECL_FIELD_BITPOS (delta21);
  2984.           delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT));
  2985.         }
  2986.       else
  2987.         index1 = integer_neg_one_node;
  2988.       op1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1);
  2989.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  2990.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  2991.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  2992.       e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
  2993.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  2994.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  2995.       if (code == EQ_EXPR)
  2996.         return e2;
  2997.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  2998.     }
  2999.       else if (TYPE_PTRMEMFUNC_P (type1)
  3000.            && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
  3001.     {
  3002.       return build_binary_op (code, op1, op0, 1);
  3003.     }
  3004.       else
  3005.     /* If args are not valid, clear out RESULT_TYPE
  3006.        to cause an error message later.  */
  3007.     result_type = 0;
  3008.       break;
  3009.  
  3010.     case MAX_EXPR:
  3011.     case MIN_EXPR:
  3012.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3013.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3014.     shorten = 1;
  3015.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3016.     {
  3017.       if (! comp_target_types (type0, type1, 1))
  3018.         pedwarn ("comparison of distinct pointer types lacks a cast");
  3019.       else if (pedantic
  3020.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  3021.         pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
  3022.       result_type = common_type (type0, type1);
  3023.     }
  3024.       break;
  3025.  
  3026.     case LE_EXPR:
  3027.     case GE_EXPR:
  3028.     case LT_EXPR:
  3029.     case GT_EXPR:
  3030.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3031.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3032.     short_compare = 1;
  3033.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3034.     {
  3035.       if (! comp_target_types (type0, type1, 1))
  3036.         pedwarn ("comparison of distinct pointer types lacks a cast");
  3037.       else if (pedantic 
  3038.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  3039.         pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
  3040.       result_type = integer_type_node;
  3041.     }
  3042.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  3043.            && integer_zerop (op1))
  3044.     {
  3045.       result_type = integer_type_node;
  3046.       op1 = null_pointer_node;
  3047.       if (! flag_traditional)
  3048.         warning ("ordered comparison of pointer with integer zero");
  3049.     }
  3050.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  3051.            && integer_zerop (op0))
  3052.     {
  3053.       result_type = integer_type_node;
  3054.       op0 = null_pointer_node;
  3055.       if (pedantic)
  3056.         pedwarn ("ANSI C++ forbids ordered comparison of pointer with integer zero");
  3057.     }
  3058.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3059.     {
  3060.       result_type = integer_type_node;
  3061.       if (pedantic)
  3062.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3063.       else if (! flag_traditional)
  3064.         warning ("comparison between pointer and integer");
  3065.       op1 = convert (TREE_TYPE (op0), op1);
  3066.     }
  3067.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  3068.     {
  3069.       result_type = integer_type_node;
  3070.       if (pedantic)
  3071.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3072.       else if (! flag_traditional)
  3073.         warning ("comparison between pointer and integer");
  3074.       op0 = convert (TREE_TYPE (op1), op0);
  3075.     }
  3076.       converted = 1;
  3077.       break;
  3078.     }
  3079.  
  3080.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3081.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3082.     {
  3083.       if (shorten || common || short_compare)
  3084.     result_type = common_type (type0, type1);
  3085.  
  3086.       /* For certain operations (which identify themselves by shorten != 0)
  3087.      if both args were extended from the same smaller type,
  3088.      do the arithmetic in that type and then extend.
  3089.  
  3090.      shorten !=0 and !=1 indicates a bitwise operation.
  3091.      For them, this optimization is safe only if
  3092.      both args are zero-extended or both are sign-extended.
  3093.      Otherwise, we might change the result.
  3094.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  3095.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  3096.  
  3097.       if (shorten)
  3098.     {
  3099.       int unsigned0, unsigned1;
  3100.       tree arg0 = get_narrower (op0, &unsigned0);
  3101.       tree arg1 = get_narrower (op1, &unsigned1);
  3102.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  3103.       int uns = TREE_UNSIGNED (result_type);
  3104.       tree type;
  3105.  
  3106.       final_type = result_type;
  3107.  
  3108.       /* Handle the case that OP0 does not *contain* a conversion
  3109.          but it *requires* conversion to FINAL_TYPE.  */
  3110.  
  3111.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  3112.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  3113.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  3114.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  3115.  
  3116.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  3117.  
  3118.       /* For bitwise operations, signedness of nominal type
  3119.          does not matter.  Consider only how operands were extended.  */
  3120.       if (shorten == -1)
  3121.         uns = unsigned0;
  3122.  
  3123.       /* Note that in all three cases below we refrain from optimizing
  3124.          an unsigned operation on sign-extended args.
  3125.          That would not be valid.  */
  3126.  
  3127.       /* Both args variable: if both extended in same way
  3128.          from same width, do it in that width.
  3129.          Do it unsigned if args were zero-extended.  */
  3130.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  3131.            < TYPE_PRECISION (result_type))
  3132.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  3133.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  3134.           && unsigned0 == unsigned1
  3135.           && (unsigned0 || !uns))
  3136.         result_type
  3137.           = signed_or_unsigned_type (unsigned0,
  3138.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  3139.       else if (TREE_CODE (arg0) == INTEGER_CST
  3140.            && (unsigned1 || !uns)
  3141.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  3142.                < TYPE_PRECISION (result_type))
  3143.            && (type = signed_or_unsigned_type (unsigned1,
  3144.                                TREE_TYPE (arg1)),
  3145.                int_fits_type_p (arg0, type)))
  3146.         result_type = type;
  3147.       else if (TREE_CODE (arg1) == INTEGER_CST
  3148.            && (unsigned0 || !uns)
  3149.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  3150.                < TYPE_PRECISION (result_type))
  3151.            && (type = signed_or_unsigned_type (unsigned0,
  3152.                                TREE_TYPE (arg0)),
  3153.                int_fits_type_p (arg1, type)))
  3154.         result_type = type;
  3155.     }
  3156.  
  3157.       /* Shifts can be shortened if shifting right.  */
  3158.  
  3159.       if (short_shift)
  3160.     {
  3161.       int unsigned_arg;
  3162.       tree arg0 = get_narrower (op0, &unsigned_arg);
  3163.  
  3164.       final_type = result_type;
  3165.  
  3166.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  3167.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  3168.  
  3169.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  3170.           /* If arg is sign-extended and then unsigned-shifted,
  3171.          we can simulate this with a signed shift in arg's type
  3172.          only if the extended result is at least twice as wide
  3173.          as the arg.  Otherwise, the shift could use up all the
  3174.          ones made by sign-extension and bring in zeros.
  3175.          We can't optimize that case at all, but in most machines
  3176.          it never happens because available widths are 2**N.  */
  3177.           && (!TREE_UNSIGNED (final_type)
  3178.           || unsigned_arg
  3179.           || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0))
  3180.               <= TYPE_PRECISION (result_type))))
  3181.         {
  3182.           /* Do an unsigned shift if the operand was zero-extended.  */
  3183.           result_type
  3184.         = signed_or_unsigned_type (unsigned_arg,
  3185.                        TREE_TYPE (arg0));
  3186.           /* Convert value-to-be-shifted to that type.  */
  3187.           if (TREE_TYPE (op0) != result_type)
  3188.         op0 = convert (result_type, op0);
  3189.           converted = 1;
  3190.         }
  3191.     }
  3192.  
  3193.       /* Comparison operations are shortened too but differently.
  3194.      They identify themselves by setting short_compare = 1.  */
  3195.  
  3196.       if (short_compare)
  3197.     {
  3198.       /* Don't write &op0, etc., because that would prevent op0
  3199.          from being kept in a register.
  3200.          Instead, make copies of the our local variables and
  3201.          pass the copies by reference, then copy them back afterward.  */
  3202.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  3203.       enum tree_code xresultcode = resultcode;
  3204.       tree val 
  3205.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  3206.       if (val != 0)
  3207.         return val;
  3208.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  3209.       resultcode = xresultcode;
  3210.     }
  3211.  
  3212.       if (short_compare && extra_warnings)
  3213.     {
  3214.       int unsignedp0, unsignedp1;
  3215.       tree primop0 = get_narrower (op0, &unsignedp0);
  3216.       tree primop1 = get_narrower (op1, &unsignedp1);
  3217.  
  3218.       /* Warn if signed and unsigned are being compared in a size larger
  3219.          than their original size, as this will always fail.  */
  3220.  
  3221.       if (unsignedp0 != unsignedp1
  3222.           && (TYPE_PRECISION (TREE_TYPE (primop0))
  3223.           < TYPE_PRECISION (result_type))
  3224.           && (TYPE_PRECISION (TREE_TYPE (primop1))
  3225.           < TYPE_PRECISION (result_type)))
  3226.         warning ("comparison between promoted unsigned and signed");
  3227.  
  3228.       /* Warn if two unsigned values are being compared in a size
  3229.          larger than their original size, and one (and only one) is the
  3230.          result of a `~' operator.  This comparison will always fail.
  3231.  
  3232.          Also warn if one operand is a constant, and the constant does not
  3233.          have all bits set that are set in the ~ operand when it is
  3234.          extended.  */
  3235.  
  3236.       else if (TREE_CODE (primop0) == BIT_NOT_EXPR
  3237.            ^ TREE_CODE (primop1) == BIT_NOT_EXPR)
  3238.         {
  3239.           if (TREE_CODE (primop0) == BIT_NOT_EXPR)
  3240.         primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
  3241.           if (TREE_CODE (primop1) == BIT_NOT_EXPR)
  3242.         primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
  3243.           
  3244.           if (TREE_CODE (primop0) == INTEGER_CST
  3245.           || TREE_CODE (primop1) == INTEGER_CST)
  3246.         {
  3247.           tree primop;
  3248.           HOST_WIDE_INT constant, mask;
  3249.           int unsignedp;
  3250.           unsigned bits;
  3251.  
  3252.           if (TREE_CODE (primop0) == INTEGER_CST)
  3253.             {
  3254.               primop = primop1;
  3255.               unsignedp = unsignedp1;
  3256.               constant = TREE_INT_CST_LOW (primop0);
  3257.             }
  3258.           else
  3259.             {
  3260.               primop = primop0;
  3261.               unsignedp = unsignedp0;
  3262.               constant = TREE_INT_CST_LOW (primop1);
  3263.             }
  3264.  
  3265.           bits = TYPE_PRECISION (TREE_TYPE (primop));
  3266.           if (bits < TYPE_PRECISION (result_type)
  3267.               && bits < HOST_BITS_PER_LONG && unsignedp)
  3268.             {
  3269.               mask = (~ (HOST_WIDE_INT) 0) << bits;
  3270.               if ((mask & constant) != mask)
  3271.             warning ("comparison of promoted ~unsigned with constant");
  3272.             }
  3273.         }
  3274.           else if (unsignedp0 && unsignedp1
  3275.                && (TYPE_PRECISION (TREE_TYPE (primop0))
  3276.                < TYPE_PRECISION (result_type))
  3277.                && (TYPE_PRECISION (TREE_TYPE (primop1))
  3278.                < TYPE_PRECISION (result_type)))
  3279.         warning ("comparison of promoted ~unsigned with unsigned");
  3280.         }
  3281.     }
  3282.     }
  3283.  
  3284.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  3285.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  3286.      Then the expression will be built.
  3287.      It will be given type FINAL_TYPE if that is nonzero;
  3288.      otherwise, it will be given type RESULT_TYPE.  */
  3289.  
  3290.   if (!result_type)
  3291.     {
  3292.       binary_op_error (error_code);
  3293.       return error_mark_node;
  3294.     }
  3295.  
  3296.   if (! converted)
  3297.     {
  3298.       if (TREE_TYPE (op0) != result_type)
  3299.     op0 = convert (result_type, op0); 
  3300.       if (TREE_TYPE (op1) != result_type)
  3301.     op1 = convert (result_type, op1); 
  3302.     }
  3303.  
  3304.   {
  3305.     register tree result = build (resultcode, result_type, op0, op1);
  3306.     register tree folded;
  3307.  
  3308.     folded = fold (result);
  3309.     if (folded == result)
  3310.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3311.     if (final_type != 0)
  3312.       return convert (final_type, folded);
  3313.     return folded;
  3314.   }
  3315. }
  3316.  
  3317. /* Return a tree for the sum or difference (RESULTCODE says which)
  3318.    of pointer PTROP and integer INTOP.  */
  3319.  
  3320. static tree
  3321. pointer_int_sum (resultcode, ptrop, intop)
  3322.      enum tree_code resultcode;
  3323.      register tree ptrop, intop;
  3324. {
  3325.   tree size_exp;
  3326.  
  3327.   register tree result;
  3328.   register tree folded = fold (intop);
  3329.  
  3330.   /* The result is a pointer of the same type that is being added.  */
  3331.  
  3332.   register tree result_type = TREE_TYPE (ptrop);
  3333.  
  3334.   /* Needed to make OOPS V2R3 work.  */
  3335.   intop = folded;
  3336.   if (TREE_CODE (intop) == INTEGER_CST
  3337.       && TREE_INT_CST_LOW (intop) == 0
  3338.       && TREE_INT_CST_HIGH (intop) == 0)
  3339.     return ptrop;
  3340.  
  3341.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  3342.     {
  3343.       if (pedantic || warn_pointer_arith)
  3344.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
  3345.       size_exp = integer_one_node;
  3346.     }
  3347.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  3348.     {
  3349.       if (pedantic || warn_pointer_arith)
  3350.     pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
  3351.       size_exp = integer_one_node;
  3352.     }
  3353.   else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
  3354.     {
  3355.       if (pedantic || warn_pointer_arith)
  3356.     pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
  3357.       size_exp = integer_one_node;
  3358.     }
  3359.   else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
  3360.     {
  3361.       if (pedantic)
  3362.     pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
  3363.       size_exp = integer_one_node;
  3364.     }
  3365.   else
  3366.     size_exp = size_in_bytes (TREE_TYPE (result_type));
  3367.  
  3368.   /* If what we are about to multiply by the size of the elements
  3369.      contains a constant term, apply distributive law
  3370.      and multiply that constant term separately.
  3371.      This helps produce common subexpressions.  */
  3372.  
  3373.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  3374.       && ! TREE_CONSTANT (intop)
  3375.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  3376.       && TREE_CONSTANT (size_exp))
  3377.     {
  3378.       enum tree_code subcode = resultcode;
  3379.       if (TREE_CODE (intop) == MINUS_EXPR)
  3380.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  3381.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
  3382.       intop = TREE_OPERAND (intop, 0);
  3383.     }
  3384.  
  3385.   /* Convert the integer argument to a type the same size as a pointer
  3386.      so the multiply won't overflow spuriously.  */
  3387.  
  3388.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  3389.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  3390.  
  3391.   /* Replace the integer argument
  3392.      with a suitable product by the object size.  */
  3393.  
  3394.   intop = build_binary_op (MULT_EXPR, intop, size_exp, 1);
  3395.  
  3396.   /* Create the sum or difference.  */
  3397.  
  3398.   result = build (resultcode, result_type, ptrop, intop);
  3399.  
  3400.   folded = fold (result);
  3401.   if (folded == result)
  3402.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  3403.   return folded;
  3404. }
  3405.  
  3406. /* Return a tree for the difference of pointers OP0 and OP1.
  3407.    The resulting tree has type int.  */
  3408.  
  3409. static tree
  3410. pointer_diff (op0, op1)
  3411.      register tree op0, op1;
  3412. {
  3413.   register tree result, folded;
  3414.   tree restype = ptrdiff_type_node;
  3415.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  3416.  
  3417.   if (pedantic)
  3418.     {
  3419.       if (TREE_CODE (target_type) == VOID_TYPE)
  3420.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
  3421.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  3422.     pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
  3423.       if (TREE_CODE (target_type) == METHOD_TYPE)
  3424.     pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
  3425.       if (TREE_CODE (target_type) == OFFSET_TYPE)
  3426.     pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
  3427.     }
  3428.  
  3429.   /* First do the subtraction as integers;
  3430.      then drop through to build the divide operator.  */
  3431.  
  3432.   op0 = build_binary_op (MINUS_EXPR,
  3433.              convert (restype, op0), convert (restype, op1), 1);
  3434.  
  3435.   /* This generates an error if op1 is a pointer to an incomplete type.  */
  3436.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
  3437.     error ("arithmetic on pointer to an incomplete type");
  3438.  
  3439.   op1 = ((TREE_CODE (target_type) == VOID_TYPE
  3440.       || TREE_CODE (target_type) == FUNCTION_TYPE
  3441.       || TREE_CODE (target_type) == METHOD_TYPE
  3442.       || TREE_CODE (target_type) == OFFSET_TYPE)
  3443.      ? integer_one_node
  3444.      : size_in_bytes (target_type));
  3445.  
  3446.   /* Do the division.  */
  3447.  
  3448.   result = build (EXACT_DIV_EXPR, restype, op0, op1);
  3449.  
  3450.   folded = fold (result);
  3451.   if (folded == result)
  3452.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3453.   return folded;
  3454. }
  3455.  
  3456. /* Handle the case of taking the address of a COMPONENT_REF.
  3457.    Called by `build_unary_op' and `build_up_reference'.
  3458.  
  3459.    ARG is the COMPONENT_REF whose address we want.
  3460.    ARGTYPE is the pointer type that this address should have.
  3461.    MSG is an error message to print if this COMPONENT_REF is not
  3462.    addressable (such as a bitfield).  */
  3463.  
  3464. tree
  3465. build_component_addr (arg, argtype, msg)
  3466.      tree arg, argtype;
  3467.      char *msg;
  3468. {
  3469.   tree field = TREE_OPERAND (arg, 1);
  3470.   tree basetype = decl_type_context (field);
  3471.   tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  3472.  
  3473.   if (DECL_BIT_FIELD (field))
  3474.     {
  3475.       error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
  3476.       return error_mark_node;
  3477.     }
  3478.  
  3479.   if (flag_gc)
  3480.     cp_warning ("address of `%T::%D' taken", basetype, field);
  3481.  
  3482.   if (TREE_CODE (field) == FIELD_DECL
  3483.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  3484.     /* Can't convert directly to ARGTYPE, since that
  3485.        may have the same pointer type as one of our
  3486.        baseclasses.  */
  3487.     rval = build1 (NOP_EXPR, argtype,
  3488.            convert_pointer_to (basetype, rval));
  3489.   else
  3490.     /* This conversion is harmless.  */
  3491.     rval = convert (argtype, rval);
  3492.  
  3493.   if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  3494.     {
  3495.       tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  3496.                 size_int (BITS_PER_UNIT));
  3497.       int flag = TREE_CONSTANT (rval);
  3498.       rval = fold (build (PLUS_EXPR, argtype,
  3499.               rval, convert (argtype, offset)));
  3500.       TREE_CONSTANT (rval) = flag;
  3501.     }
  3502.   return rval;
  3503. }
  3504.    
  3505. /* Construct and perhaps optimize a tree representation
  3506.    for a unary operation.  CODE, a tree_code, specifies the operation
  3507.    and XARG is the operand.  */
  3508.  
  3509. tree
  3510. build_x_unary_op (code, xarg)
  3511.      enum tree_code code;
  3512.      tree xarg;
  3513. {
  3514.   tree rval;
  3515.  
  3516.   /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
  3517.      error message. */
  3518.   if (code != ADDR_EXPR || TREE_CODE (TREE_TYPE (xarg)) != RECORD_TYPE
  3519.       || TYPE_SIZE (TREE_TYPE (xarg)))
  3520.     {
  3521.       /* See comments in `build_x_unary_op'.  */
  3522.       if (rval = build_opfncall (code, 0, xarg, NULL_TREE, NULL_TREE))
  3523.     {
  3524.       if (rval = build_opfncall (code, LOOKUP_PROTECT, xarg, NULL_TREE, NULL_TREE))
  3525.         return rval;
  3526.       build_opfncall (code, LOOKUP_NORMAL, xarg, NULL_TREE, NULL_TREE);
  3527.       return error_mark_node;
  3528.     }
  3529.     }
  3530.   return build_unary_op (code, xarg, 0);
  3531. }
  3532.  
  3533. /* C++: Must handle pointers to members.
  3534.  
  3535.    Perhaps type instantiation should be extended to handle conversion
  3536.    from aggregates to types we don't yet know we want?  (Or are those
  3537.    cases typically errors which should be reported?)
  3538.  
  3539.    NOCONVERT nonzero suppresses the default promotions
  3540.    (such as from short to int).  */
  3541. tree
  3542. build_unary_op (code, xarg, noconvert)
  3543.      enum tree_code code;
  3544.      tree xarg;
  3545.      int noconvert;
  3546. {
  3547.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  3548.   register tree arg = xarg;
  3549.   register tree argtype = 0;
  3550.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  3551.   char *errstring = NULL;
  3552.   tree val;
  3553.   int isaggrtype;
  3554.  
  3555.   if (typecode == ERROR_MARK)
  3556.     return error_mark_node;
  3557.  
  3558.   if (typecode == REFERENCE_TYPE && code != ADDR_EXPR && ! noconvert)
  3559.     {
  3560.       arg = convert_from_reference (arg);
  3561.       typecode = TREE_CODE (TREE_TYPE (arg));
  3562.     }
  3563.  
  3564.   if (typecode == ENUMERAL_TYPE)
  3565.     typecode = INTEGER_TYPE;
  3566.  
  3567.   isaggrtype = IS_AGGR_TYPE_CODE (typecode);
  3568.  
  3569.   switch (code)
  3570.     {
  3571.     case CONVERT_EXPR:
  3572.       /* This is used for unary plus, because a CONVERT_EXPR
  3573.      is enough to prevent anybody from looking inside for
  3574.      associativity, but won't generate any code.  */
  3575.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3576.         errstring = "wrong type argument to unary plus";
  3577.       else if (!noconvert)
  3578.     arg = default_conversion (arg);
  3579.       break;
  3580.  
  3581.     case NEGATE_EXPR:
  3582.       if (isaggrtype)
  3583.     {
  3584.       if (!noconvert)
  3585.         arg = default_conversion (arg);
  3586.       else
  3587.         {
  3588.           cp_error ("type conversion for type `%T' not allowed",
  3589.               TREE_TYPE (arg));
  3590.           return error_mark_node;
  3591.         }
  3592.       typecode = TREE_CODE (TREE_TYPE (arg));
  3593.       noconvert = 1;
  3594.     }
  3595.  
  3596.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3597.         errstring = "wrong type argument to unary minus";
  3598.       else if (!noconvert)
  3599.     arg = default_conversion (arg);
  3600.       break;
  3601.  
  3602.     case BIT_NOT_EXPR:
  3603.       if (isaggrtype)
  3604.     {
  3605.       if (!noconvert)
  3606.         arg = default_conversion (arg);
  3607.       else
  3608.         {
  3609.           cp_error ("type conversion for type `%T' not allowed",
  3610.               TREE_TYPE (arg));
  3611.           return error_mark_node;
  3612.         }
  3613.       typecode = TREE_CODE (TREE_TYPE (arg));
  3614.       noconvert = 1;
  3615.     }
  3616.  
  3617.       if (typecode != INTEGER_TYPE)
  3618.         errstring = "wrong type argument to bit-complement";
  3619.       else if (!noconvert)
  3620.     arg = default_conversion (arg);
  3621.       break;
  3622.  
  3623.     case ABS_EXPR:
  3624.       if (isaggrtype)
  3625.     {
  3626.       if (!noconvert)
  3627.         arg = default_conversion (arg);
  3628.       else
  3629.         {
  3630.           cp_error ("type conversion for type `%T' not allowed",
  3631.               TREE_TYPE (arg));
  3632.           return error_mark_node;
  3633.         }
  3634.       typecode = TREE_CODE (TREE_TYPE (arg));
  3635.       noconvert = 1;
  3636.     }
  3637.  
  3638.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  3639.         errstring = "wrong type argument to abs";
  3640.       else if (!noconvert)
  3641.     arg = default_conversion (arg);
  3642.       break;
  3643.  
  3644.     case TRUTH_NOT_EXPR:
  3645.       if (isaggrtype)
  3646.     {
  3647.       arg = truthvalue_conversion (arg);
  3648.       typecode = TREE_CODE (TREE_TYPE (arg));
  3649.     }
  3650.  
  3651.       if (typecode != INTEGER_TYPE
  3652.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  3653.       /* These will convert to a pointer.  */
  3654.       && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
  3655.     {
  3656.       errstring = "wrong type argument to unary exclamation mark";
  3657.       break;
  3658.     }
  3659.       arg = truthvalue_conversion (arg);
  3660.       val = invert_truthvalue (arg);
  3661.       if (val) return val;
  3662.       break;
  3663.  
  3664.     case NOP_EXPR:
  3665.       break;
  3666.       
  3667.     case PREINCREMENT_EXPR:
  3668.     case POSTINCREMENT_EXPR:
  3669.     case PREDECREMENT_EXPR:
  3670.     case POSTDECREMENT_EXPR:
  3671.       /* Handle complex lvalues (when permitted)
  3672.      by reduction to simpler cases.  */
  3673.  
  3674.       val = unary_complex_lvalue (code, arg);
  3675.       if (val != 0)
  3676.     return val;
  3677.  
  3678.       /* Report invalid types.  */
  3679.  
  3680.       if (isaggrtype)
  3681.     {
  3682.       arg = default_conversion (arg);
  3683.       typecode = TREE_CODE (TREE_TYPE (arg));
  3684.     }
  3685.  
  3686.       if (typecode != POINTER_TYPE
  3687.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  3688.     {
  3689.       if (code == PREINCREMENT_EXPR)
  3690.         errstring ="no pre-increment operator for type";
  3691.       else if (code == POSTINCREMENT_EXPR)
  3692.         errstring ="no post-increment operator for type";
  3693.       else if (code == PREDECREMENT_EXPR)
  3694.         errstring ="no pre-decrement operator for type";
  3695.       else
  3696.         errstring ="no post-decrement operator for type";
  3697.       break;
  3698.     }
  3699.  
  3700.       /* Report something read-only.  */
  3701.  
  3702.       if (TYPE_READONLY (TREE_TYPE (arg))
  3703.       || TREE_READONLY (arg))
  3704.     readonly_error (arg, ((code == PREINCREMENT_EXPR
  3705.                    || code == POSTINCREMENT_EXPR)
  3706.                   ? "increment" : "decrement"),
  3707.             0);
  3708.  
  3709.       {
  3710.     register tree inc;
  3711.     tree result_type = TREE_TYPE (arg);
  3712.  
  3713.     arg = get_unwidened (arg, 0);
  3714.     argtype = TREE_TYPE (arg);
  3715.  
  3716.     /* ARM $5.2.5 last annotation says this should be forbidden.  */
  3717.     if (TREE_CODE (argtype) == ENUMERAL_TYPE)
  3718.       pedwarn ("ANSI C++ forbids %sing an enum",
  3719.            (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  3720.            ? "increment" : "decrement");
  3721.         
  3722.     /* Compute the increment.  */
  3723.  
  3724.     if (typecode == POINTER_TYPE)
  3725.       {
  3726.         enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
  3727.         if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
  3728.         || tmp == VOID_TYPE || tmp == OFFSET_TYPE)
  3729.           cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
  3730.                 ((code == PREINCREMENT_EXPR
  3731.                   || code == POSTINCREMENT_EXPR)
  3732.                  ? "increment" : "decrement"), argtype);
  3733.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  3734.       }
  3735.     else
  3736.       inc = integer_one_node;
  3737.  
  3738.     inc = convert (argtype, inc);
  3739.  
  3740.     /* Handle incrementing a cast-expression.  */
  3741.  
  3742.     switch (TREE_CODE (arg))
  3743.       {
  3744.       case NOP_EXPR:
  3745.       case CONVERT_EXPR:
  3746.       case FLOAT_EXPR:
  3747.       case FIX_TRUNC_EXPR:
  3748.       case FIX_FLOOR_EXPR:
  3749.       case FIX_ROUND_EXPR:
  3750.       case FIX_CEIL_EXPR:
  3751.         {
  3752.           tree incremented, modify, value;
  3753.           pedantic_lvalue_warning (CONVERT_EXPR);
  3754.           arg = stabilize_reference (arg);
  3755.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  3756.         value = arg;
  3757.           else
  3758.         value = save_expr (arg);
  3759.           incremented = build (((code == PREINCREMENT_EXPR
  3760.                      || code == POSTINCREMENT_EXPR)
  3761.                     ? PLUS_EXPR : MINUS_EXPR),
  3762.                    argtype, value, inc);
  3763.           TREE_SIDE_EFFECTS (incremented) = 1;
  3764.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  3765.           return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  3766.         }
  3767.       }
  3768.  
  3769.     if (TREE_CODE (arg) == OFFSET_REF)
  3770.       arg = resolve_offset_ref (arg);
  3771.  
  3772.     /* Complain about anything else that is not a true lvalue.  */
  3773.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  3774.                     || code == POSTINCREMENT_EXPR)
  3775.                    ? "increment" : "decrement")))
  3776.       return error_mark_node;
  3777.  
  3778.     val = build (code, TREE_TYPE (arg), arg, inc);
  3779.     TREE_SIDE_EFFECTS (val) = 1;
  3780.     return convert (result_type, val);
  3781.       }
  3782.  
  3783.     case ADDR_EXPR:
  3784.       /* Note that this operation never does default_conversion
  3785.      regardless of NOCONVERT.  */
  3786.  
  3787.       if (TREE_REFERENCE_EXPR (arg))
  3788.     {
  3789.       error ("references are not lvalues");
  3790.       return error_mark_node;
  3791.     }
  3792.       else if (typecode == REFERENCE_TYPE)
  3793.     {
  3794.       arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  3795.       TREE_REFERENCE_EXPR (arg) = 1;
  3796.       return arg;
  3797.     }
  3798.       else if (TREE_CODE (arg) == FUNCTION_DECL
  3799.            && DECL_NAME (arg)
  3800.            && DECL_CONTEXT (arg) == NULL_TREE
  3801.            && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4
  3802.            && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm'
  3803.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main"))
  3804.     {
  3805.       /* ARM $3.4 */
  3806.       error ("attempt to take address of function `main'");
  3807.       return error_mark_node;
  3808.     }
  3809.  
  3810.       /* Let &* cancel out to simplify resulting code.  */
  3811.       if (TREE_CODE (arg) == INDIRECT_REF)
  3812.     {
  3813.       /* We don't need to have `current_class_decl' wrapped in a
  3814.          NON_LVALUE_EXPR node.  */
  3815.       if (arg == C_C_D)
  3816.         return current_class_decl;
  3817.  
  3818.       /* Keep `default_conversion' from converting if
  3819.          ARG is of REFERENCE_TYPE.  */
  3820.       arg = TREE_OPERAND (arg, 0);
  3821.       if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
  3822.         {
  3823.           if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg)
  3824.           && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg)))
  3825.         arg = DECL_INITIAL (arg);
  3826.           arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  3827.           TREE_REFERENCE_EXPR (arg) = 1;
  3828.           TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
  3829.         }
  3830.       else if (lvalue_p (arg))
  3831.         /* Don't let this be an lvalue.  */
  3832.         return non_lvalue (arg);
  3833.       return arg;
  3834.     }
  3835.  
  3836.       /* For &x[y], return x+y */
  3837.       if (TREE_CODE (arg) == ARRAY_REF)
  3838.     {
  3839.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  3840.         return error_mark_node;
  3841.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  3842.                   TREE_OPERAND (arg, 1), 1);
  3843.     }
  3844.  
  3845.       /* For &(++foo), we are really taking the address of the variable
  3846.      being acted upon by the increment/decrement operator.  ARM $5.3.1
  3847.      However, according to ARM $5.2.5, we don't allow postfix ++ and
  3848.      --, since the prefix operators return lvalues, but the postfix
  3849.      operators do not.  */
  3850.       if (TREE_CODE (arg) == PREINCREMENT_EXPR
  3851.       || TREE_CODE (arg) == PREDECREMENT_EXPR)
  3852.     arg = TREE_OPERAND (arg, 0);
  3853.  
  3854.       /* Uninstantiated types are all functions.  Taking the
  3855.      address of a function is a no-op, so just return the
  3856.      argument.  */
  3857.  
  3858.       if (TREE_CODE (arg) == IDENTIFIER_NODE
  3859.       && IDENTIFIER_OPNAME_P (arg))
  3860.     {
  3861.       my_friendly_abort (117);
  3862.       /* We don't know the type yet, so just work around the problem.
  3863.          We know that this will resolve to an lvalue.  */
  3864.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  3865.     }
  3866.  
  3867.       if (TREE_CODE (arg) == TREE_LIST)
  3868.     {
  3869.       /* Look at methods with only this name.  */
  3870.       if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL)
  3871.         {
  3872.           tree targ = TREE_VALUE (arg);
  3873.  
  3874.           /* If this function is unique, or it is a unique
  3875.          constructor, we can take its address easily.  */
  3876.           if (DECL_CHAIN (targ) == NULL_TREE
  3877.           || (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (targ))
  3878.               && DECL_CHAIN (DECL_CHAIN (targ)) == NULL_TREE))
  3879.         {
  3880.           if (DECL_CHAIN (targ))
  3881.             targ = DECL_CHAIN (targ);
  3882.           if (DECL_CLASS_CONTEXT (targ))
  3883.             targ = build (OFFSET_REF, TREE_TYPE (targ), C_C_D, targ);
  3884.  
  3885.           val = unary_complex_lvalue (ADDR_EXPR, targ);
  3886.           if (val)
  3887.             return val;
  3888.         }
  3889.  
  3890.           /* This possible setting of TREE_CONSTANT is what makes it possible
  3891.          with an initializer list to emit the entire thing in the data
  3892.          section, rather than a run-time initialization.  */
  3893.           arg = build1 (ADDR_EXPR, unknown_type_node, arg);
  3894.           if (staticp (targ))
  3895.         TREE_CONSTANT (arg) = 1;
  3896.           return arg;
  3897.         }
  3898.       if (TREE_CHAIN (arg) == NULL_TREE
  3899.           && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE)
  3900.         {
  3901.           /* Unique overloaded member function.  */
  3902.           return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)), 0);
  3903.         }
  3904.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  3905.     }
  3906.  
  3907.       /* Handle complex lvalues (when permitted)
  3908.      by reduction to simpler cases.  */
  3909.       val = unary_complex_lvalue (code, arg);
  3910.       if (val != 0)
  3911.     return val;
  3912.  
  3913. #if 0 /* Turned off because inconsistent;
  3914.      float f; *&(int)f = 3.4 stores in int format
  3915.      whereas (int)f = 3.4 stores in float format.  */
  3916.       /* Address of a cast is just a cast of the address
  3917.      of the operand of the cast.  */
  3918.       switch (TREE_CODE (arg))
  3919.     {
  3920.     case NOP_EXPR:
  3921.     case CONVERT_EXPR:
  3922.     case FLOAT_EXPR:
  3923.     case FIX_TRUNC_EXPR:
  3924.     case FIX_FLOOR_EXPR:
  3925.     case FIX_ROUND_EXPR:
  3926.     case FIX_CEIL_EXPR:
  3927.       if (pedantic)
  3928.         pedwarn ("ANSI C++ forbids taking the address of a cast expression");
  3929.       return convert (build_pointer_type (TREE_TYPE (arg)),
  3930.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0));
  3931.     }
  3932. #endif
  3933.  
  3934.       /* Allow the address of a constructor if all the elements
  3935.      are constant.  */
  3936.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  3937.     ;
  3938.       /* Anything not already handled and not a true memory reference
  3939.      is an error.  */
  3940.       else if (typecode != FUNCTION_TYPE
  3941.            && typecode != METHOD_TYPE
  3942.            && !lvalue_or_else (arg, "unary `&'"))
  3943.     return error_mark_node;
  3944.  
  3945.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  3946.       argtype = TREE_TYPE (arg);
  3947.       /* If the lvalue is const or volatile,
  3948.      merge that into the type that the address will point to.  */
  3949.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  3950.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  3951.     {
  3952.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  3953.         argtype = build_type_variant (argtype,
  3954.                       TREE_READONLY (arg),
  3955.                       TREE_THIS_VOLATILE (arg));
  3956.     }
  3957.  
  3958.       argtype = build_pointer_type (argtype);
  3959.  
  3960.       if (mark_addressable (arg) == 0)
  3961.     return error_mark_node;
  3962.  
  3963.       {
  3964.     tree addr;
  3965.  
  3966.     if (TREE_CODE (arg) == COMPONENT_REF)
  3967.       addr = build_component_addr (arg, argtype,
  3968.                        "attempt to take address of bit-field structure member `%s'");
  3969.     else
  3970.       addr = build1 (code, argtype, arg);
  3971.  
  3972.     /* Address of a static or external variable or
  3973.        function counts as a constant */
  3974.     if (staticp (arg))
  3975.       TREE_CONSTANT (addr) = 1;
  3976.     return addr;
  3977.       }
  3978.     }
  3979.  
  3980.   if (!errstring)
  3981.     {
  3982.       if (argtype == 0)
  3983.     argtype = TREE_TYPE (arg);
  3984.       return fold (build1 (code, argtype, arg));
  3985.     }
  3986.  
  3987.   error (errstring);
  3988.   return error_mark_node;
  3989. }
  3990.  
  3991. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  3992.    convert ARG with the same conversions in the same order
  3993.    and return the result.  */
  3994.  
  3995. static tree
  3996. convert_sequence (conversions, arg)
  3997.      tree conversions;
  3998.      tree arg;
  3999. {
  4000.   switch (TREE_CODE (conversions))
  4001.     {
  4002.     case NOP_EXPR:
  4003.     case CONVERT_EXPR:
  4004.     case FLOAT_EXPR:
  4005.     case FIX_TRUNC_EXPR:
  4006.     case FIX_FLOOR_EXPR:
  4007.     case FIX_ROUND_EXPR:
  4008.     case FIX_CEIL_EXPR:
  4009.       return convert (TREE_TYPE (conversions),
  4010.               convert_sequence (TREE_OPERAND (conversions, 0),
  4011.                     arg));
  4012.  
  4013.     default:
  4014.       return arg;
  4015.     }
  4016. }
  4017.  
  4018. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  4019.    for certain kinds of expressions which are not really lvalues
  4020.    but which we can accept as lvalues.
  4021.  
  4022.    If ARG is not a kind of expression we can handle, return zero.  */
  4023.    
  4024. tree
  4025. unary_complex_lvalue (code, arg)
  4026.      enum tree_code code;
  4027.      tree arg;
  4028. {
  4029.   /* Handle (a, b) used as an "lvalue".  */
  4030.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  4031.     {
  4032.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  4033.       pedantic_lvalue_warning (COMPOUND_EXPR);
  4034.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  4035.             TREE_OPERAND (arg, 0), real_result);
  4036.     }
  4037.  
  4038.   /* Handle (a ? b : c) used as an "lvalue".  */
  4039.   if (TREE_CODE (arg) == COND_EXPR)
  4040.     {
  4041.       pedantic_lvalue_warning (COND_EXPR);
  4042.       return (build_conditional_expr
  4043.           (TREE_OPERAND (arg, 0),
  4044.            build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  4045.            build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  4046.     }
  4047.  
  4048.   if (code != ADDR_EXPR)
  4049.     return 0;
  4050.  
  4051.   /* Handle (a = b) used as an "lvalue" for `&'.  */
  4052.   if (TREE_CODE (arg) == MODIFY_EXPR
  4053.       || TREE_CODE (arg) == INIT_EXPR)
  4054.     {
  4055.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4056.       return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
  4057.     }
  4058.  
  4059.   if (TREE_CODE (arg) == WITH_CLEANUP_EXPR)
  4060.     {
  4061.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4062.       real_result = build (WITH_CLEANUP_EXPR, TREE_TYPE (real_result),
  4063.                real_result, 0, TREE_OPERAND (arg, 2));
  4064.       return real_result;
  4065.     }
  4066.  
  4067.   if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
  4068.       || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
  4069.       || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
  4070.     {
  4071.       /* The representation of something of type OFFSET_TYPE
  4072.      is really the representation of a pointer to it.
  4073.      Here give the representation its true type.  */
  4074.       tree t;
  4075.       tree offset;
  4076.  
  4077.       my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
  4078.  
  4079.       if (TREE_CODE (arg) != OFFSET_REF)
  4080.     return 0;
  4081.  
  4082.       t = TREE_OPERAND (arg, 1);
  4083.  
  4084.       if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */
  4085.     return build_unary_op (ADDR_EXPR, t, 0);
  4086.       if (TREE_CODE (t) == VAR_DECL)
  4087.     return build_unary_op (ADDR_EXPR, t, 0);
  4088.       else
  4089.     {
  4090.       /* Can't build a pointer to member if the member must
  4091.          go through virtual base classes.  */
  4092.       if (virtual_member (DECL_FIELD_CONTEXT (t),
  4093.                   CLASSTYPE_VBASECLASSES (TREE_TYPE (TREE_OPERAND (arg, 0)))))
  4094.         {
  4095.           sorry ("pointer to member via virtual baseclass");
  4096.           return error_mark_node;
  4097.         }
  4098.  
  4099.       if (TREE_OPERAND (arg, 0)
  4100.           && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
  4101.           || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node))
  4102.         {
  4103.           /* Don't know if this should return address to just
  4104.          _DECL, or actual address resolved in this expression.  */
  4105.           sorry ("address of bound pointer-to-member expression");
  4106.           return error_mark_node;
  4107.         }
  4108.  
  4109.       return convert (build_pointer_type (TREE_TYPE (arg)),
  4110.               size_binop (EASY_DIV_EXPR, 
  4111.                       DECL_FIELD_BITPOS (t),
  4112.                       size_int (BITS_PER_UNIT)));
  4113.     }
  4114.     }
  4115.  
  4116.   if (TREE_CODE (arg) == OFFSET_REF)
  4117.     {
  4118.       tree left = TREE_OPERAND (arg, 0), left_addr;
  4119.       tree right_addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 1), 0);
  4120.  
  4121.       if (left == 0)
  4122.     if (current_class_decl)
  4123.       left_addr = current_class_decl;
  4124.     else
  4125.       {
  4126.         error ("no `this' for pointer to member");
  4127.         return error_mark_node;
  4128.       }
  4129.       else
  4130.     left_addr = build_unary_op (ADDR_EXPR, left, 0);
  4131.  
  4132.       return build (PLUS_EXPR, build_pointer_type (TREE_TYPE (arg)),
  4133.             build1 (NOP_EXPR, integer_type_node, left_addr),
  4134.             build1 (NOP_EXPR, integer_type_node, right_addr));
  4135.     }
  4136.  
  4137.   /* We permit compiler to make function calls returning
  4138.      objects of aggregate type look like lvalues.  */
  4139.   {
  4140.     tree targ = arg;
  4141.  
  4142.     if (TREE_CODE (targ) == SAVE_EXPR)
  4143.       targ = TREE_OPERAND (targ, 0);
  4144.  
  4145.     if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ)))
  4146.       {
  4147.     if (TREE_CODE (arg) == SAVE_EXPR)
  4148.       targ = arg;
  4149.     else
  4150.       targ = build_cplus_new (TREE_TYPE (arg), arg, 1);
  4151.     return build1 (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (arg)), targ);
  4152.       }
  4153.  
  4154.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF)
  4155.       return build (SAVE_EXPR, TYPE_POINTER_TO (TREE_TYPE (arg)),
  4156.              TREE_OPERAND (targ, 0), current_function_decl, NULL);
  4157.  
  4158.     /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
  4159.        we do, here's how to handle it.  */
  4160.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == WITH_CLEANUP_EXPR)
  4161.       {
  4162. #if 0
  4163.     /* Not really a bug, but something to turn on when testing.  */
  4164.     compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
  4165. #endif
  4166.     return unary_complex_lvalue (ADDR_EXPR, targ);
  4167.       }
  4168.   }
  4169.  
  4170.   /* Don't let anything else be handled specially.  */
  4171.   return 0;
  4172. }
  4173.  
  4174. /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
  4175.    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
  4176.  
  4177. static void
  4178. pedantic_lvalue_warning (code)
  4179.      enum tree_code code;
  4180. {
  4181.   if (pedantic)
  4182.     pedwarn ("ANSI C++ forbids use of %s expressions as lvalues",
  4183.          code == COND_EXPR ? "conditional"
  4184.          : code == COMPOUND_EXPR ? "compound" : "cast");
  4185. }
  4186.  
  4187. /* Mark EXP saying that we need to be able to take the
  4188.    address of it; it should not be allocated in a register.
  4189.    Value is 1 if successful.
  4190.  
  4191.    C++: we do not allow `current_class_decl' to be addressable.  */
  4192.  
  4193. int
  4194. mark_addressable (exp)
  4195.      tree exp;
  4196. {
  4197.   register tree x = exp;
  4198.  
  4199.   if (TREE_ADDRESSABLE (x) == 1)
  4200.     return 1;
  4201.  
  4202.   while (1)
  4203.     switch (TREE_CODE (x))
  4204.       {
  4205.       case ADDR_EXPR:
  4206.       case COMPONENT_REF:
  4207.       case ARRAY_REF:
  4208.     x = TREE_OPERAND (x, 0);
  4209.     break;
  4210.  
  4211.       case PARM_DECL:
  4212.     if (x == current_class_decl)
  4213.       {
  4214.         error ("address of `this' not available");
  4215.         TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
  4216.         put_var_into_stack (x);
  4217.         return 1;
  4218.       }
  4219.       case VAR_DECL:
  4220.     if (TREE_STATIC (x)
  4221.         && TREE_READONLY (x)
  4222.         && DECL_RTL (x) != 0
  4223.         && ! decl_in_memory_p (x))
  4224.       {
  4225.         /* We thought this would make a good constant variable,
  4226.            but we were wrong.  */
  4227.         push_obstacks_nochange ();
  4228.         end_temporary_allocation ();
  4229.  
  4230.         TREE_ASM_WRITTEN (x) = 0;
  4231.         DECL_RTL (x) = 0;
  4232.         rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0);
  4233.         TREE_ADDRESSABLE (x) = 1;
  4234.  
  4235.         pop_obstacks ();
  4236.  
  4237.         return 1;
  4238.       }
  4239.     /* Caller should not be trying to mark initialized
  4240.        constant fields addressable.  */
  4241.     my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0
  4242.                 || DECL_IN_AGGR_P (x) == 0
  4243.                 || TREE_STATIC (x)
  4244.                 || DECL_EXTERNAL (x), 314);
  4245.  
  4246.       case CONST_DECL:
  4247.       case RESULT_DECL:
  4248.     /* For C++, we don't warn about taking the address of a register
  4249.        variable for CONST_DECLs; ARM p97 explicitly says it's okay.  */
  4250.     put_var_into_stack (x);
  4251.     TREE_ADDRESSABLE (x) = 1;
  4252.     return 1;
  4253.  
  4254.       case FUNCTION_DECL:
  4255.     /* We have to test both conditions here.  The first may
  4256.        be non-zero in the case of processing a default function.
  4257.        The second may be non-zero in the case of a template function.  */
  4258.     x = DECL_MAIN_VARIANT (x);
  4259.     if ((DECL_INLINE (x) || DECL_PENDING_INLINE_INFO (x))
  4260.         && (DECL_CONTEXT (x) == NULL_TREE
  4261.         || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't'
  4262.         || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x))))
  4263.       {
  4264.         mark_inline_for_output (x);
  4265.         if (x == current_function_decl)
  4266.           DECL_EXTERNAL (x) = 0;
  4267.       }
  4268.     TREE_ADDRESSABLE (x) = 1;
  4269.     TREE_USED (x) = 1;
  4270.     TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
  4271.     return 1;
  4272.  
  4273.       default:
  4274.     return 1;
  4275.     }
  4276. }
  4277.  
  4278. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  4279.  
  4280. tree
  4281. build_x_conditional_expr (ifexp, op1, op2)
  4282.      tree ifexp, op1, op2;
  4283. {
  4284.   tree rval;
  4285.  
  4286.   /* See comments in `build_x_binary_op'.  */
  4287.   if (op1 != 0 && (rval = build_opfncall (COND_EXPR, 0, ifexp, op1, op2)))
  4288.     {
  4289.       if (rval = build_opfncall (COND_EXPR, LOOKUP_PROTECT, ifexp, op1, op2))
  4290.     return rval;
  4291.       build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2);
  4292.       return error_mark_node;
  4293.     }
  4294.   return build_conditional_expr (ifexp, op1, op2);
  4295. }
  4296.  
  4297. tree
  4298. build_conditional_expr (ifexp, op1, op2)
  4299.      tree ifexp, op1, op2;
  4300. {
  4301.   register tree type1;
  4302.   register tree type2;
  4303.   register enum tree_code code1;
  4304.   register enum tree_code code2;
  4305.   register tree result_type = NULL_TREE;
  4306.  
  4307.   /* If second operand is omitted, it is the same as the first one;
  4308.      make sure it is calculated only once.  */
  4309.   if (op1 == 0)
  4310.     {
  4311.       if (pedantic)
  4312.     pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
  4313.       ifexp = op1 = save_expr (ifexp);
  4314.     }
  4315.  
  4316.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  4317.  
  4318.   if (TREE_CODE (ifexp) == ERROR_MARK)
  4319.     return error_mark_node;
  4320.  
  4321.   op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
  4322.   if (op1 == error_mark_node)
  4323.     return error_mark_node;
  4324.   op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
  4325.   if (op2 == error_mark_node)
  4326.     return error_mark_node;
  4327.  
  4328.   /* C++: REFERENCE_TYPES must be dereferenced.  */
  4329.   type1 = TREE_TYPE (op1);
  4330.   code1 = TREE_CODE (type1);
  4331.   type2 = TREE_TYPE (op2);
  4332.   code2 = TREE_CODE (type2);
  4333.  
  4334.   if (code1 == REFERENCE_TYPE)
  4335.     {
  4336.       op1 = convert_from_reference (op1);
  4337.       type1 = TREE_TYPE (op1);
  4338.       code1 = TREE_CODE (type1);
  4339.     }
  4340.   if (code2 == REFERENCE_TYPE)
  4341.     {
  4342.       op2 = convert_from_reference (op2);
  4343.       type2 = TREE_TYPE (op2);
  4344.       code2 = TREE_CODE (type2);
  4345.     }
  4346.  
  4347. #if 1 /* Produces wrong result if within sizeof.  Sorry.  */
  4348.   /* Don't promote the operands separately if they promote
  4349.      the same way.  Return the unpromoted type and let the combined
  4350.      value get promoted if necessary.  */
  4351.  
  4352.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)
  4353.       && code2 != ARRAY_TYPE
  4354. #if 0
  4355.       /* For C++, let the enumeral type come through.  */
  4356.       && code2 != ENUMERAL_TYPE
  4357. #endif
  4358.       && code2 != FUNCTION_TYPE
  4359.       && code2 != METHOD_TYPE)
  4360.     {
  4361.       tree result;
  4362.  
  4363.       if (TREE_CONSTANT (ifexp)
  4364.       && (TREE_CODE (ifexp) == INTEGER_CST
  4365.           || TREE_CODE (ifexp) == ADDR_EXPR))
  4366.     return (integer_zerop (ifexp) ? op2 : op1);
  4367.  
  4368.       if (TREE_CODE (op1) == CONST_DECL)
  4369.     op1 = DECL_INITIAL (op1);
  4370.       else if (TREE_READONLY_DECL_P (op1))
  4371.     op1 = decl_constant_value (op1);
  4372.       if (TREE_CODE (op2) == CONST_DECL)
  4373.     op2 = DECL_INITIAL (op2);
  4374.       else if (TREE_READONLY_DECL_P (op2))
  4375.     op2 = decl_constant_value (op2);
  4376.       if (type1 != type2)
  4377.     type1 = build_type_variant
  4378.             (type1,
  4379.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4380.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4381.       /* ??? This is a kludge to deal with the fact that
  4382.      we don't sort out integers and enums properly, yet.  */
  4383.       result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
  4384.       if (TREE_TYPE (result) != type1)
  4385.     result = build1 (NOP_EXPR, type1, result);
  4386.       return result;
  4387.     }
  4388. #endif
  4389.  
  4390.   /* They don't match; promote them both and then try to reconcile them.
  4391.      But don't permit mismatching enum types.  */
  4392.   if (code1 == ENUMERAL_TYPE)
  4393.     {
  4394.       if (code2 == ENUMERAL_TYPE)
  4395.     {
  4396.       message_2_types (error, "enumeral mismatch in conditional expression: `%s' vs `%s'", type1, type2);
  4397.       return error_mark_node;
  4398.     }
  4399.       else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2))
  4400.     warning ("enumeral and non-enumeral type in conditional expression");
  4401.     }
  4402.   else if (extra_warnings
  4403.        && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1))
  4404.     warning ("enumeral and non-enumeral type in conditional expression");
  4405.  
  4406.   if (code1 != VOID_TYPE)
  4407.     {
  4408.       op1 = default_conversion (op1);
  4409.       type1 = TREE_TYPE (op1);
  4410.       code1 = TREE_CODE (type1);
  4411.     }
  4412.   if (code2 != VOID_TYPE)
  4413.     {
  4414.       op2 = default_conversion (op2);
  4415.       type2 = TREE_TYPE (op2);
  4416.       code2 = TREE_CODE (type2);
  4417.     }
  4418.  
  4419.   /* Quickly detect the usual case where op1 and op2 have the same type
  4420.      after promotion.  */
  4421.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
  4422.     {
  4423.       if (type1 == type2)
  4424.     result_type = type1;
  4425.       else
  4426.     result_type = build_type_variant
  4427.             (type1,
  4428.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4429.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4430.     }
  4431.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  4432.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  4433.     {
  4434.       result_type = common_type (type1, type2);
  4435.     }
  4436.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  4437.     {
  4438.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  4439.     pedwarn ("ANSI C++ forbids conditional expr with only one void side");
  4440.       result_type = void_type_node;
  4441.     }
  4442.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  4443.     {
  4444.       if (comp_target_types (type1, type2, 1))
  4445.     result_type = common_type (type1, type2);
  4446.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node)
  4447.     result_type = qualify_type (type2, type1);
  4448.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node)
  4449.     result_type = qualify_type (type1, type2);
  4450.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  4451.     {
  4452.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4453.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4454.       result_type = qualify_type (type1, type2);
  4455.     }
  4456.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  4457.     {
  4458.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4459.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4460.       result_type = qualify_type (type2, type1);
  4461.     }
  4462.       /* C++ */
  4463.       else if (comptypes (type2, type1, 0))
  4464.     result_type = type2;
  4465.       else if (IS_AGGR_TYPE (TREE_TYPE (type1))
  4466.            && IS_AGGR_TYPE (TREE_TYPE (type2))
  4467.            && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2))))
  4468.     {
  4469.       if (result_type == error_mark_node)
  4470.         {
  4471.           message_2_types (error, "common base type of types `%s' and `%s' is ambiguous",
  4472.                    TREE_TYPE (type1), TREE_TYPE (type2));
  4473.           result_type = ptr_type_node;
  4474.         }
  4475.       else result_type = TYPE_POINTER_TO (result_type);
  4476.     }
  4477.       else
  4478.     {
  4479.       pedwarn ("pointer type mismatch in conditional expression");
  4480.       result_type = ptr_type_node;
  4481.     }
  4482.     }
  4483.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  4484.     {
  4485.       if (!integer_zerop (op2))
  4486.     warning ("pointer/integer type mismatch in conditional expression");
  4487.       else
  4488.     {
  4489.       op2 = null_pointer_node;
  4490.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4491.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4492.     }
  4493.       result_type = type1;
  4494.     }
  4495.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  4496.     {
  4497.       if (!integer_zerop (op1))
  4498.     warning ("pointer/integer type mismatch in conditional expression");
  4499.       else
  4500.     {
  4501.       op1 = null_pointer_node;
  4502.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4503.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4504.     }
  4505.       result_type = type2;
  4506.       op1 = null_pointer_node;
  4507.     }
  4508.  
  4509.   if (!result_type)
  4510.     {
  4511.       /* The match does not look good.  If either is
  4512.      an aggregate value, try converting to a scalar type.  */
  4513.       if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
  4514.     {
  4515.       message_2_types (error, "aggregate mismatch in conditional expression: `%s' vs `%s'", type1, type2);
  4516.       return error_mark_node;
  4517.     }
  4518.       if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
  4519.     {
  4520.       tree tmp = build_type_conversion (CONVERT_EXPR, type2, op1, 0);
  4521.       if (tmp == NULL_TREE)
  4522.         {
  4523.           cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1);
  4524.           return error_mark_node;
  4525.         }
  4526.       if (tmp == error_mark_node)
  4527.         error ("ambiguous pointer conversion");
  4528.       result_type = type2;
  4529.       op1 = tmp;
  4530.     }
  4531.       else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
  4532.     {
  4533.       tree tmp = build_type_conversion (CONVERT_EXPR, type1, op2, 0);
  4534.       if (tmp == NULL_TREE)
  4535.         {
  4536.           cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2);
  4537.           return error_mark_node;
  4538.         }
  4539.       if (tmp == error_mark_node)
  4540.         error ("ambiguous pointer conversion");
  4541.       result_type = type1;
  4542.       op2 = tmp;
  4543.     }
  4544.       else if (flag_cond_mismatch)
  4545.     result_type = void_type_node;
  4546.       else
  4547.     {
  4548.       error ("type mismatch in conditional expression");
  4549.       return error_mark_node;
  4550.     }
  4551.     }
  4552.  
  4553.   if (result_type != TREE_TYPE (op1))
  4554.     op1 = convert_and_check (result_type, op1);
  4555.   if (result_type != TREE_TYPE (op2))
  4556.     op2 = convert_and_check (result_type, op2);
  4557.  
  4558. #if 0
  4559.   /* XXX delete me, I've been here for years.  */
  4560.   if (IS_AGGR_TYPE_CODE (code1))
  4561.     {
  4562.       result_type = TREE_TYPE (op1);
  4563.       if (TREE_CONSTANT (ifexp))
  4564.     return (integer_zerop (ifexp) ? op2 : op1);
  4565.  
  4566.       if (TYPE_MODE (result_type) == BLKmode)
  4567.     {
  4568.       register tree tempvar
  4569.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  4570.       register tree xop1 = build_modify_expr (tempvar, NOP_EXPR, op1);
  4571.       register tree xop2 = build_modify_expr (tempvar, NOP_EXPR, op2);
  4572.       register tree result = fold (build (COND_EXPR, result_type,
  4573.                           ifexp, xop1, xop2));
  4574.  
  4575.       layout_decl (tempvar, 0);
  4576.       /* No way to handle variable-sized objects here.
  4577.          I fear that the entire handling of BLKmode conditional exprs
  4578.          needs to be redone.  */
  4579.       my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar)), 315);
  4580.       DECL_RTL (tempvar)
  4581.         = assign_stack_local (DECL_MODE (tempvar),
  4582.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  4583.                    + BITS_PER_UNIT - 1)
  4584.                   / BITS_PER_UNIT,
  4585.                   0);
  4586.  
  4587.       TREE_SIDE_EFFECTS (result)
  4588.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  4589.           | TREE_SIDE_EFFECTS (op2);
  4590.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  4591.     }
  4592.     }
  4593. #endif /* 0 */
  4594.  
  4595.   if (TREE_CONSTANT (ifexp))
  4596.     return integer_zerop (ifexp) ? op2 : op1;
  4597.  
  4598.   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
  4599. }
  4600.  
  4601. /* Handle overloading of the ',' operator when needed.  Otherwise,
  4602.    this function just builds an expression list.  */
  4603. tree
  4604. build_x_compound_expr (list)
  4605.      tree list;
  4606. {
  4607.   tree rest = TREE_CHAIN (list);
  4608.   tree result;
  4609.  
  4610.   if (rest == NULL_TREE)
  4611.     return build_compound_expr (list);
  4612.  
  4613.   result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL,
  4614.                TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
  4615.   if (result)
  4616.     return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest)));
  4617.   else
  4618.     return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list),
  4619.                        build_tree_list (NULL_TREE, build_x_compound_expr (rest))));
  4620. }
  4621.  
  4622. /* Given a list of expressions, return a compound expression
  4623.    that performs them all and returns the value of the last of them.  */
  4624.  
  4625. tree
  4626. build_compound_expr (list)
  4627.      tree list;
  4628. {
  4629.   register tree rest;
  4630.  
  4631.   if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
  4632.     TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
  4633.  
  4634.   if (TREE_CHAIN (list) == 0)
  4635.     {
  4636.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  4637.      Strip such NOP_EXPRs, since LIST is used in non-lvalue context.  */
  4638.       if (TREE_CODE (list) == NOP_EXPR
  4639.       && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
  4640.     list = TREE_OPERAND (list, 0);
  4641.  
  4642.       /* Convert arrays to pointers.  */
  4643.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
  4644.     return default_conversion (TREE_VALUE (list));
  4645.       else
  4646.     return TREE_VALUE (list);
  4647.     }
  4648.  
  4649.   rest = build_compound_expr (TREE_CHAIN (list));
  4650.  
  4651.   /* When pedantic, a compound expression can be neither an lvalue
  4652.      nor an integer constant expression.  */
  4653.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
  4654.     return rest;
  4655.  
  4656.   return build (COMPOUND_EXPR, TREE_TYPE (rest),
  4657.         break_out_cleanups (TREE_VALUE (list)), rest);
  4658. }
  4659.  
  4660. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  4661.  
  4662. tree
  4663. build_c_cast (type, expr)
  4664.      register tree type;
  4665.      tree expr;
  4666. {
  4667.   register tree value = expr;
  4668.  
  4669.   if (type == error_mark_node || expr == error_mark_node)
  4670.     return error_mark_node;
  4671.  
  4672.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  4673.      Strip such NOP_EXPRs, since VALUE is being used in non-lvalue context.  */
  4674.   if (TREE_CODE (value) == NOP_EXPR
  4675.       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  4676.     value = TREE_OPERAND (value, 0);
  4677.  
  4678.   if (TREE_TYPE (expr)
  4679.       && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
  4680.       && TREE_CODE (type) != OFFSET_TYPE)
  4681.     value = resolve_offset_ref (value);
  4682.  
  4683.   if (TREE_CODE (type) == ARRAY_TYPE)
  4684.     {
  4685.       /* Allow casting from T1* to T2[] because Cfront allows it.
  4686.      NIHCL uses it. It is not valid ANSI C however, and hence, not
  4687.      valid ANSI C++.  */
  4688.       if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
  4689.     {
  4690.       if (pedantic)
  4691.         pedwarn ("ANSI C++ forbids casting to an array type");
  4692.       type = build_pointer_type (TREE_TYPE (type));
  4693.     }
  4694.       else
  4695.     {
  4696.       error ("ANSI C++ forbids casting to an array type");
  4697.       return error_mark_node;
  4698.     }
  4699.     }
  4700.  
  4701.   /* When converting into a reference type, just convert into a pointer to
  4702.      the new type and deference it.  While this is not exactly what ARM 5.4
  4703.      calls for [why not? -jason], it is pretty close for now.
  4704.      (int &)ri ---> *(int*)&ri  */
  4705.   if (TREE_CODE (type) == REFERENCE_TYPE)
  4706.     {
  4707.       value = build_unary_op (ADDR_EXPR, value, 0);
  4708.       if (value != error_mark_node)
  4709.     value = convert (build_pointer_type (TREE_TYPE (type)), value);
  4710.       if (value != error_mark_node)
  4711.     value = build_indirect_ref (value, "reference conversion");
  4712.       return value;
  4713.     }
  4714.  
  4715.   if (TREE_TYPE (value)
  4716.       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
  4717.     {
  4718.       /* For C++, we must copy the constness of TYPE into VALUE.  */
  4719.       if (TREE_READONLY (value) != TYPE_READONLY (type))
  4720.     {
  4721.       value = copy_node (value);
  4722.       TREE_READONLY (value) = TYPE_READONLY (type);
  4723.     }
  4724.       else if (pedantic)
  4725.     {
  4726.       if (TREE_CODE (type) == RECORD_TYPE
  4727.           || TREE_CODE (type) == UNION_TYPE)
  4728.         pedwarn ("ANSI C++ forbids casting nonscalar to the same type");
  4729.     }
  4730.       return value;
  4731.     }
  4732.  
  4733.   /* If there's only one function in the overloaded space,
  4734.      just take it.  */
  4735.   if (TREE_CODE (value) == TREE_LIST
  4736.       && TREE_CHAIN (value) == NULL_TREE)
  4737.     value = TREE_VALUE (value);
  4738.  
  4739.   /* Make up for the fact that we do not always perform
  4740.      `default_conversion' anymore.  */
  4741.   if (TREE_READONLY_DECL_P (value))
  4742.     value = decl_constant_value (value);
  4743.  
  4744.   if (TREE_TYPE (value) == NULL_TREE
  4745.       || type_unknown_p (value))
  4746.     {
  4747.       value = instantiate_type (type, value, 1);
  4748.       /* Did we lose?  */
  4749.       if (value == error_mark_node)
  4750.     return error_mark_node;
  4751.     }
  4752.   else
  4753.     {
  4754.       tree otype, ovalue;
  4755.  
  4756.       /* Convert functions and arrays to pointers and
  4757.      convert references to their expanded types,
  4758.      but don't convert any other types.  */
  4759.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  4760.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  4761.       || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
  4762.     value = default_conversion (value);
  4763.       otype = TREE_TYPE (value);
  4764.  
  4765.       /* Optionally warn about potentially worrisome casts.  */
  4766.  
  4767.       if (warn_cast_qual
  4768.       && TREE_CODE (type) == POINTER_TYPE
  4769.       && TREE_CODE (otype) == POINTER_TYPE)
  4770.     {
  4771.       /* For C++ we make these regular warnings, rather than
  4772.          softening them into pedwarns.  */
  4773.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  4774.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  4775.         warning ("cast discards `volatile' from pointer target type");
  4776.       if (TYPE_READONLY (TREE_TYPE (otype))
  4777.           && ! TYPE_READONLY (TREE_TYPE (type)))
  4778.         warning ("cast discards `const' from pointer target type");
  4779.     }
  4780.  
  4781.       /* Warn about possible alignment problems.  */
  4782.       if (STRICT_ALIGNMENT && warn_cast_align
  4783.       && TREE_CODE (type) == POINTER_TYPE
  4784.       && TREE_CODE (otype) == POINTER_TYPE
  4785.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  4786.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  4787.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  4788.     warning ("cast increases required alignment of target type");
  4789.  
  4790. #if 0
  4791.       if (TREE_CODE (type) == INTEGER_TYPE
  4792.       && TREE_CODE (otype) == POINTER_TYPE
  4793.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
  4794.     warning ("cast from pointer to integer of different size");
  4795.  
  4796.       if (TREE_CODE (type) == POINTER_TYPE
  4797.       && TREE_CODE (otype) == INTEGER_TYPE
  4798.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  4799.       /* Don't warn about converting 0 to pointer,
  4800.          provided the 0 was explicit--not cast or made by folding.  */
  4801.       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
  4802.     warning ("cast to pointer from integer of different size");
  4803. #endif
  4804.  
  4805.       ovalue = value;
  4806.       value = convert_force (type, value);
  4807.  
  4808.       /* Ignore any integer overflow caused by the cast.  */
  4809.       if (TREE_CODE (value) == INTEGER_CST)
  4810.     {
  4811.       TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  4812.       TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  4813.     }
  4814.     }
  4815.   if (value == expr)
  4816.     /* Always produce some operator for an explicit cast,
  4817.        so we can tell (for -pedantic) that the cast is no lvalue.  */
  4818.     {
  4819.       tree nvalue = build1 (NOP_EXPR, type, value);
  4820.       TREE_CONSTANT (nvalue) = TREE_CONSTANT (value);
  4821.       return nvalue;
  4822.     }
  4823.  
  4824.   return value;
  4825. }
  4826.  
  4827. /* Build an assignment expression of lvalue LHS from value RHS.
  4828.  
  4829.    In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
  4830.    that reference becomes deferenced down to it base type. */
  4831.  
  4832. /* Return a reference to the BASE_INDEX part of EXPR.  TYPE is
  4833.    the type to which BASE_INDEX applies.  */
  4834. static tree
  4835. get_base_ref (type, base_index, expr)
  4836.      tree type;
  4837.      int base_index;
  4838.      tree expr;
  4839. {
  4840.   tree binfos = TYPE_BINFO_BASETYPES (type);
  4841.   tree base_binfo = TREE_VEC_ELT (binfos, base_index);
  4842.   tree ref;
  4843.  
  4844.   if (TREE_CODE (expr) == ARRAY_REF
  4845.       || ! BINFO_OFFSET_ZEROP (base_binfo)
  4846.       || TREE_VIA_VIRTUAL (base_binfo)
  4847.       || TYPE_MODE (type) != TYPE_MODE (BINFO_TYPE (base_binfo)))
  4848.     {
  4849.       tree addr = build_unary_op (ADDR_EXPR, expr, 0);
  4850.       ref = build_indirect_ref (convert_pointer_to (base_binfo, addr),
  4851.                 NULL_PTR);
  4852.     }
  4853.   else
  4854.     {
  4855.       ref = copy_node (expr);
  4856.       TREE_TYPE (ref) = BINFO_TYPE (base_binfo);
  4857.     }
  4858.   return ref;
  4859. }
  4860.  
  4861. /* Build an assignment expression of lvalue LHS from value RHS.
  4862.    MODIFYCODE is the code for a binary operator that we use
  4863.    to combine the old value of LHS with RHS to get the new value.
  4864.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
  4865.  
  4866.    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
  4867.  
  4868.    `build_modify_expr_1' implements recursive part of memberwise
  4869.    assignment operation.  */
  4870. static tree
  4871. build_modify_expr_1 (lhs, modifycode, rhs, basetype_path)
  4872.      tree lhs, rhs;
  4873.      enum tree_code modifycode;
  4874.      tree basetype_path;
  4875. {
  4876.   register tree result;
  4877.   tree newrhs = rhs;
  4878.   tree lhstype = TREE_TYPE (lhs);
  4879.   tree olhstype = lhstype;
  4880.  
  4881.   /* Avoid duplicate error messages from operands that had errors.  */
  4882.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  4883.     return error_mark_node;
  4884.  
  4885.   /* If a binary op has been requested, combine the old LHS value with the RHS
  4886.      producing the value we should actually store into the LHS.  */
  4887.  
  4888.   if (modifycode == INIT_EXPR)
  4889.     ;
  4890.   else if (modifycode == NOP_EXPR)
  4891.     {
  4892.       /* must deal with overloading of `operator=' here.  */
  4893.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  4894.     lhstype = TREE_TYPE (lhstype);
  4895.       else
  4896.     lhstype = olhstype;
  4897.     }
  4898.   else
  4899.     {
  4900.       lhs = stabilize_reference (lhs);
  4901.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  4902.       modifycode = NOP_EXPR;
  4903.     }
  4904.  
  4905.   /* If storing into a structure or union member,
  4906.      it has probably been given type `int'.
  4907.      Compute the type that would go with
  4908.      the actual amount of storage the member occupies.  */
  4909.  
  4910.   if (TREE_CODE (lhs) == COMPONENT_REF
  4911.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  4912.       || TREE_CODE (lhstype) == REAL_TYPE
  4913.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  4914.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  4915.  
  4916.   /* C++: The semantics of C++ differ from those of C when an
  4917.      assignment of an aggregate is desired.  Assignment in C++ is
  4918.      now defined as memberwise assignment of non-static members
  4919.      and base class objects.  This rule applies recursively
  4920.      until a member of a built-in type is found.
  4921.  
  4922.      Also, we cannot do a bit-wise copy of aggregates which
  4923.      contain virtual function table pointers.  Those
  4924.      pointer values must be preserved through the copy.
  4925.      However, this is handled in expand_expr, and not here.
  4926.      This is because much better code can be generated at
  4927.      that stage than this one.  */
  4928.   if (TREE_CODE (lhstype) == RECORD_TYPE
  4929.       && TYPE_LANG_SPECIFIC (lhstype)
  4930.       && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
  4931.     {
  4932.       register tree elt;
  4933.       int i;
  4934.  
  4935.       /* Perform operation on object.  */
  4936.       if (modifycode == INIT_EXPR && TYPE_HAS_INIT_REF (lhstype))
  4937.     {
  4938.       result = build_method_call (lhs, constructor_name_full (lhstype),
  4939.                       build_tree_list (NULL_TREE, rhs),
  4940.                       basetype_path, LOOKUP_NORMAL);
  4941.       return build_indirect_ref (result, NULL_PTR);
  4942.     }
  4943.       else if (modifycode == NOP_EXPR)
  4944.     {
  4945.       /* `operator=' is not an inheritable operator; see 13.4.3.  */
  4946.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype))
  4947.         {
  4948.           result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  4949.                        lhs, rhs, make_node (NOP_EXPR));
  4950.           if (result == NULL_TREE)
  4951.         return error_mark_node;
  4952.           return result;
  4953.         }
  4954.     }
  4955.  
  4956.       if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype)
  4957.       || (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  4958.       || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype)))
  4959.     {
  4960.       tree binfos = BINFO_BASETYPES (TYPE_BINFO (lhstype));
  4961.       result = NULL_TREE;
  4962.  
  4963.       if (binfos != NULL_TREE)
  4964.         /* Perform operation on each member, depth-first, left-right.  */
  4965.         for (i = 0; i <= TREE_VEC_LENGTH (binfos)-1; i++)
  4966.           {
  4967.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  4968.         tree base_lhs, base_rhs;
  4969.         tree new_result;
  4970.  
  4971.         /* Assignments from virtual baseclasses handled elsewhere.  */
  4972.         if (TREE_VIA_VIRTUAL (base_binfo))
  4973.           continue;
  4974.  
  4975.         base_lhs = get_base_ref (lhstype, i, lhs);
  4976.         base_rhs = get_base_ref (lhstype, i, newrhs);
  4977.  
  4978.         BINFO_INHERITANCE_CHAIN (base_binfo) = basetype_path;
  4979.         new_result
  4980.           = build_modify_expr_1 (base_lhs, modifycode, base_rhs,
  4981.                      base_binfo);
  4982.  
  4983.         /* We either get back a compound stmt, or a simple one.  */
  4984.         if (new_result && TREE_CODE (new_result) == TREE_LIST)
  4985.           new_result = build_compound_expr (new_result);
  4986.         result = tree_cons (NULL_TREE, new_result, result);
  4987.           }
  4988.  
  4989.       for (elt = TYPE_FIELDS (lhstype); elt; elt = TREE_CHAIN (elt))
  4990.         {
  4991.           tree vbases = NULL_TREE;
  4992.           tree elt_lhs, elt_rhs;
  4993.  
  4994.           if (TREE_CODE (elt) != FIELD_DECL)
  4995.         continue;
  4996.           if (DECL_NAME (elt)
  4997.           && (VFIELD_NAME_P (DECL_NAME (elt))
  4998.               || VBASE_NAME_P (DECL_NAME (elt))))
  4999.         continue;
  5000.  
  5001.           if (TREE_READONLY (elt)
  5002.           || TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5003.         {
  5004.           cp_error ("cannot generate default `%T::operator ='",
  5005.                 lhstype);
  5006.           if (TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5007.             cp_error_at ("because member `%#D' is a reference", elt);
  5008.           else
  5009.             cp_error_at ("because member `%#D' is const", elt);
  5010.  
  5011.           return error_mark_node;
  5012.         }
  5013.  
  5014.           if (IS_AGGR_TYPE (TREE_TYPE (elt))
  5015.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5016.         vbases = CLASSTYPE_VBASECLASSES (TREE_TYPE (elt));
  5017.  
  5018.           elt_lhs = build (COMPONENT_REF, TREE_TYPE (elt), lhs, elt);
  5019.           elt_rhs = build (COMPONENT_REF, TREE_TYPE (elt), newrhs, elt);
  5020.           /* It is not always safe to go through `build_modify_expr_1'
  5021.          when performing element-wise copying.  This is because
  5022.          an element may be of ARRAY_TYPE, which will not
  5023.          be properly copied as a naked element.  */
  5024.           if (TREE_CODE (TREE_TYPE (elt)) == RECORD_TYPE
  5025.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5026.         basetype_path = TYPE_BINFO (TREE_TYPE (elt));
  5027.  
  5028.           while (vbases)
  5029.         {
  5030.           tree elt_lhs_addr = build_unary_op (ADDR_EXPR, elt_lhs, 0);
  5031.           tree elt_rhs_addr = build_unary_op (ADDR_EXPR, elt_rhs, 0);
  5032.  
  5033.           elt_lhs_addr = convert_pointer_to (vbases, elt_lhs_addr);
  5034.           elt_rhs_addr = convert_pointer_to (vbases, elt_rhs_addr);
  5035.           result
  5036.             = tree_cons (NULL_TREE,
  5037.                  build_modify_expr_1
  5038.                  (build_indirect_ref (elt_lhs_addr, NULL_PTR),
  5039.                   modifycode,
  5040.                   build_indirect_ref (elt_rhs_addr, NULL_PTR),
  5041.                   basetype_path),
  5042.                  result);
  5043.           if (TREE_VALUE (result) == error_mark_node)
  5044.             return error_mark_node;
  5045.           vbases = TREE_CHAIN (vbases);
  5046.         }
  5047.           elt_lhs = build_modify_expr_1 (elt_lhs, modifycode, elt_rhs,
  5048.                          basetype_path);
  5049.           result = tree_cons (NULL_TREE, elt_lhs, result);
  5050.         }
  5051.  
  5052.       if (result)
  5053.         return build_compound_expr (result);
  5054.       /* No fields to move.  */
  5055.       return integer_zero_node;
  5056.     }
  5057.       else
  5058.     {
  5059.       result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5060.               void_type_node, lhs, rhs);
  5061.       TREE_SIDE_EFFECTS (result) = 1;
  5062.       return result;
  5063.     }
  5064.     }
  5065.  
  5066.   result = build_modify_expr (lhs, modifycode, newrhs);
  5067.   /* ARRAY_TYPEs cannot be converted to anything meaningful,
  5068.      and leaving it there screws up `build_compound_expr' when
  5069.      it tries to defaultly convert everything.  */
  5070.   if (TREE_CODE (TREE_TYPE (result)) == ARRAY_TYPE)
  5071.     TREE_TYPE (result) = void_type_node;
  5072.   return result;
  5073. }
  5074.  
  5075. /* Taken from expr.c:
  5076.    Subroutine of expand_expr:
  5077.    record the non-copied parts (LIST) of an expr (LHS), and return a list
  5078.    which specifies the initial values of these parts.  */
  5079.  
  5080. static tree
  5081. init_noncopied_parts (lhs, list)
  5082.      tree lhs;
  5083.      tree list;
  5084. {
  5085.   tree tail;
  5086.   tree parts = 0;
  5087.  
  5088.   for (tail = list; tail; tail = TREE_CHAIN (tail))
  5089.     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
  5090.       parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail)));
  5091.     else
  5092.       {
  5093.     tree part = TREE_VALUE (tail);
  5094.     tree part_type = TREE_TYPE (part);
  5095.     tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part);
  5096.     parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts);
  5097.       }
  5098.   return parts;
  5099. }
  5100.  
  5101. tree
  5102. build_modify_expr (lhs, modifycode, rhs)
  5103.      tree lhs;
  5104.      enum tree_code modifycode;
  5105.      tree rhs;
  5106. {
  5107.   register tree result;
  5108.   tree newrhs = rhs;
  5109.   tree lhstype = TREE_TYPE (lhs);
  5110.   tree olhstype = lhstype;
  5111.  
  5112.   /* Types that aren't fully specified cannot be used in assignments.  */
  5113.   lhs = require_complete_type (lhs);
  5114.  
  5115.   /* Avoid duplicate error messages from operands that had errors.  */
  5116.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  5117.     return error_mark_node;
  5118.  
  5119.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  5120.      Strip such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  5121.   if (TREE_CODE (rhs) == NOP_EXPR
  5122.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  5123.     rhs = TREE_OPERAND (rhs, 0);
  5124.  
  5125.   /* Decide early if we are going to protect RHS from GC
  5126.      before assigning it to LHS.  */
  5127.   if (type_needs_gc_entry (TREE_TYPE (rhs))
  5128.       && ! value_safe_from_gc (lhs, rhs))
  5129.     rhs = protect_value_from_gc (lhs, rhs);
  5130.  
  5131.   newrhs = rhs;
  5132.  
  5133.   /* Handle control structure constructs used as "lvalues".  */
  5134.  
  5135.   switch (TREE_CODE (lhs))
  5136.     {
  5137.       /* Handle --foo = 5; as these are valid constructs in C++ */
  5138.     case PREDECREMENT_EXPR:
  5139.     case PREINCREMENT_EXPR:
  5140.       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
  5141.     lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
  5142.              stabilize_reference (TREE_OPERAND (lhs, 0)));
  5143.       return build (COMPOUND_EXPR, lhstype,
  5144.             lhs,
  5145.             build_modify_expr (TREE_OPERAND (lhs, 0),
  5146.                        modifycode, rhs));
  5147.  
  5148.       /* Handle (a, b) used as an "lvalue".  */
  5149.     case COMPOUND_EXPR:
  5150.       pedantic_lvalue_warning (COMPOUND_EXPR);
  5151.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
  5152.                   modifycode, rhs);
  5153.       if (TREE_CODE (newrhs) == ERROR_MARK)
  5154.     return error_mark_node;
  5155.       return build (COMPOUND_EXPR, lhstype,
  5156.             TREE_OPERAND (lhs, 0), newrhs);
  5157.  
  5158.       /* Handle (a ? b : c) used as an "lvalue".  */
  5159.     case COND_EXPR:
  5160.       pedantic_lvalue_warning (COND_EXPR);
  5161.       rhs = save_expr (rhs);
  5162.       {
  5163.     /* Produce (a ? (b = rhs) : (c = rhs))
  5164.        except that the RHS goes through a save-expr
  5165.        so the code to compute it is only emitted once.  */
  5166.     tree cond
  5167.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  5168.                     build_modify_expr (TREE_OPERAND (lhs, 1),
  5169.                                modifycode, rhs),
  5170.                     build_modify_expr (TREE_OPERAND (lhs, 2),
  5171.                                modifycode, rhs));
  5172.     if (TREE_CODE (cond) == ERROR_MARK)
  5173.       return cond;
  5174.     /* Make sure the code to compute the rhs comes out
  5175.        before the split.  */
  5176.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  5177.               /* Case to void to suppress warning
  5178.              from warn_if_unused_value.  */
  5179.               convert (void_type_node, rhs), cond);
  5180.       }
  5181.     }
  5182.  
  5183.   /* If a binary op has been requested, combine the old LHS value with the RHS
  5184.      producing the value we should actually store into the LHS.  */
  5185.  
  5186.   if (modifycode == INIT_EXPR)
  5187.     ;
  5188.   else if (modifycode == NOP_EXPR)
  5189.     {
  5190.       /* must deal with overloading of `operator=' here.  */
  5191.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5192.     lhstype = TREE_TYPE (lhstype);
  5193. #if 1
  5194.       /* `operator=' is not an inheritable operator.  */
  5195.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype))
  5196.     {
  5197.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5198.                    lhs, rhs, make_node (NOP_EXPR));
  5199.       if (result == NULL_TREE)
  5200.         return error_mark_node;
  5201.       return result;
  5202.     }
  5203. #else
  5204.       /* Treat `operator=' as an inheritable operator.  */
  5205.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_GETS_ASSIGNMENT (lhstype))
  5206.     {
  5207.       tree orig_lhstype = lhstype;
  5208.       while (! TYPE_HAS_ASSIGNMENT (lhstype))
  5209.         {
  5210.           int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (lhstype);
  5211.           tree basetype = NULL_TREE;
  5212.           for (i = 0; i < n_baseclasses; i++)
  5213.         if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype, i)))
  5214.           {
  5215.             if (basetype != NULL_TREE)
  5216.               {
  5217.             message_2_types (error, "base classes `%s' and `%s' both have operator ='",
  5218.                      basetype,
  5219.                      TYPE_BINFO_BASETYPE (lhstype, i));
  5220.             return error_mark_node;
  5221.               }
  5222.             basetype = TYPE_BINFO_BASETYPE (lhstype, i);
  5223.           }
  5224.           lhstype = basetype;
  5225.         }
  5226.       if (orig_lhstype != lhstype)
  5227.         {
  5228.           lhs = build_indirect_ref (convert_pointer_to (lhstype,
  5229.                                 build_unary_op (ADDR_EXPR, lhs, 0)), NULL_PTR);
  5230.           if (lhs == error_mark_node)
  5231.         {
  5232.           cp_error ("conversion to private basetype `%T'", lhstype);
  5233.           return error_mark_node;
  5234.         }
  5235.         }
  5236.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5237.                    lhs, rhs, make_node (NOP_EXPR));
  5238.       if (result == NULL_TREE)
  5239.         return error_mark_node;
  5240.       return result;
  5241.     }
  5242. #endif
  5243.       lhstype = olhstype;
  5244.     }
  5245.   else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
  5246.     {
  5247.       /* This case must convert to some sort of lvalue that
  5248.      can participate in an op= operation.  */
  5249.       tree lhs_tmp = lhs;
  5250.       tree rhs_tmp = rhs;
  5251.       if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp))
  5252.     {
  5253.       lhs = stabilize_reference (lhs_tmp);
  5254.       /* Forget is was ever anything else.  */
  5255.       olhstype = lhstype = TREE_TYPE (lhs);
  5256.       newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1);
  5257.     }
  5258.       else
  5259.     return error_mark_node;
  5260.     }
  5261.   else
  5262.     {
  5263.       lhs = stabilize_reference (lhs);
  5264.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  5265.     }
  5266.  
  5267.   /* Handle a cast used as an "lvalue".
  5268.      We have already performed any binary operator using the value as cast.
  5269.      Now convert the result to the cast type of the lhs,
  5270.      and then true type of the lhs and store it there;
  5271.      then convert result back to the cast type to be the value
  5272.      of the assignment.  */
  5273.  
  5274.   switch (TREE_CODE (lhs))
  5275.     {
  5276.     case NOP_EXPR:
  5277.     case CONVERT_EXPR:
  5278.     case FLOAT_EXPR:
  5279.     case FIX_TRUNC_EXPR:
  5280.     case FIX_FLOOR_EXPR:
  5281.     case FIX_ROUND_EXPR:
  5282.     case FIX_CEIL_EXPR:
  5283.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  5284.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
  5285.       || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
  5286.       || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
  5287.     newrhs = default_conversion (newrhs);
  5288.       {
  5289.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  5290.     tree result;
  5291.     result = build_modify_expr (inner_lhs, NOP_EXPR,
  5292.                     convert (TREE_TYPE (inner_lhs),
  5293.                          convert (lhstype, newrhs)));
  5294.     if (TREE_CODE (result) == ERROR_MARK)
  5295.       return result;
  5296.     return convert (TREE_TYPE (lhs), result);
  5297.       }
  5298.     }
  5299.  
  5300.   if (TREE_CODE (lhs) == OFFSET_REF)
  5301.     {
  5302.       if (TREE_OPERAND (lhs, 0) == NULL_TREE)
  5303.     {
  5304.       /* Static class member?  */
  5305.       tree member = TREE_OPERAND (lhs, 1);
  5306.       if (TREE_CODE (member) == VAR_DECL)
  5307.         lhs = member;
  5308.       else
  5309.         {
  5310.           compiler_error ("invalid static class member");
  5311.           return error_mark_node;
  5312.         }
  5313.     }
  5314.       else
  5315.     lhs = resolve_offset_ref (lhs);
  5316.     }
  5317.  
  5318.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  5319.      Reject anything strange now.  */
  5320.  
  5321.   if (!lvalue_or_else (lhs, "assignment"))
  5322.     return error_mark_node;
  5323.  
  5324.   GNU_xref_assign (lhs);
  5325.  
  5326.   /* Warn about storing in something that is `const'.  */
  5327.   /* For C++, don't warn if this is initialization.  */
  5328.   if (modifycode != INIT_EXPR
  5329.       && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  5330.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  5331.            || TREE_CODE (lhstype) == UNION_TYPE)
  5332.           && C_TYPE_FIELDS_READONLY (lhstype))
  5333.       || (TREE_CODE (lhstype) == REFERENCE_TYPE
  5334.           && TYPE_READONLY (TREE_TYPE (lhstype)))))
  5335.     readonly_error (lhs, "assignment", 0);
  5336.  
  5337.   /* If storing into a structure or union member,
  5338.      it has probably been given type `int'.
  5339.      Compute the type that would go with
  5340.      the actual amount of storage the member occupies.  */
  5341.  
  5342.   if (TREE_CODE (lhs) == COMPONENT_REF
  5343.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  5344.       || TREE_CODE (lhstype) == REAL_TYPE
  5345.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  5346.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  5347.  
  5348.   /* check to see if there is an assignment to `this' */
  5349.   if (lhs == current_class_decl)
  5350.     {
  5351.       if (flag_this_is_variable > 0
  5352.       && DECL_NAME (current_function_decl) != NULL_TREE
  5353.       && current_class_name != DECL_NAME (current_function_decl))
  5354.     warning ("assignment to `this' not in constructor or destructor");
  5355.       current_function_just_assigned_this = 1;
  5356.     }
  5357.  
  5358.   /* The TREE_TYPE of RHS may be TYPE_UNKNOWN.  This can happen
  5359.      when the type of RHS is not yet known, i.e. its type
  5360.      is inherited from LHS.  */
  5361.   rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
  5362.   if (rhs == error_mark_node)
  5363.     return error_mark_node;
  5364.   newrhs = rhs;
  5365.  
  5366.   if (modifycode != INIT_EXPR)
  5367.     {
  5368.       /* Make modifycode now either a NOP_EXPR or an INIT_EXPR.  */
  5369.       modifycode = NOP_EXPR;
  5370.       /* Reference-bashing */
  5371.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5372.     {
  5373.       tree tmp = convert_from_reference (lhs);
  5374.       lhstype = TREE_TYPE (tmp);
  5375.       if (TYPE_SIZE (lhstype) == 0)
  5376.         {
  5377.           incomplete_type_error (lhs, lhstype);
  5378.           return error_mark_node;
  5379.         }
  5380.       lhs = tmp;
  5381.       olhstype = lhstype;
  5382.     }
  5383.       if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE)
  5384.     {
  5385.       tree tmp = convert_from_reference (newrhs);
  5386.       if (TYPE_SIZE (TREE_TYPE (tmp)) == 0)
  5387.         {
  5388.           incomplete_type_error (newrhs, TREE_TYPE (tmp));
  5389.           return error_mark_node;
  5390.         }
  5391.       newrhs = tmp;
  5392.     }
  5393.     }
  5394.  
  5395.   if (TREE_SIDE_EFFECTS (lhs))
  5396.     lhs = stabilize_reference (lhs);
  5397.   if (TREE_SIDE_EFFECTS (newrhs))
  5398.     newrhs = stabilize_reference (newrhs);
  5399.  
  5400.   /* C++: The semantics of C++ differ from those of C when an
  5401.      assignment of an aggregate is desired.  Assignment in C++ is
  5402.      now defined as memberwise assignment of non-static members
  5403.      and base class objects.  This rule applies recursively
  5404.      until a member of a built-in type is found.
  5405.  
  5406.      Also, we cannot do a bit-wise copy of aggregates which
  5407.      contain virtual function table pointers.  Those
  5408.      pointer values must be preserved through the copy.
  5409.      However, this is handled in expand_expr, and not here.
  5410.      This is because much better code can be generated at
  5411.      that stage than this one.  */
  5412.   if (TREE_CODE (lhstype) == RECORD_TYPE
  5413.       && (TYPE_USES_VIRTUAL_BASECLASSES (lhstype)
  5414.       || (modifycode != INIT_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  5415.       || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype)))
  5416.       && (TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))
  5417.       || (TREE_CODE (TREE_TYPE (newrhs)) == RECORD_TYPE
  5418.           && UNIQUELY_DERIVED_FROM_P (lhstype, TREE_TYPE (newrhs)))))
  5419.     {
  5420.       tree vbases = CLASSTYPE_VBASECLASSES (lhstype);
  5421.       tree lhs_addr = build_unary_op (ADDR_EXPR, lhs, 0);
  5422.       tree rhs_addr;
  5423.  
  5424.       /* Memberwise assignment would cause NEWRHS to be
  5425.      evaluated for every member that gets assigned.
  5426.      By wrapping side-effecting exprs in a SAVE_EXPR,
  5427.      NEWRHS will only be evaluated once.  */
  5428.       if (IS_AGGR_TYPE (TREE_TYPE (newrhs))
  5429.       && TREE_SIDE_EFFECTS (newrhs)
  5430.       /* This are things we don't have to save.  */
  5431.       && TREE_CODE (newrhs) != TARGET_EXPR
  5432.       && TREE_CODE (newrhs) != WITH_CLEANUP_EXPR)
  5433.     /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
  5434.        If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
  5435.        will result in expand_expr expanding the call without knowing
  5436.        that it should run the cleanup.  */
  5437.     newrhs = save_expr (break_out_cleanups (newrhs));
  5438.  
  5439.       rhs_addr = build_unary_op (ADDR_EXPR, newrhs, 0);
  5440.       result = tree_cons (NULL_TREE,
  5441.               convert (build_reference_type (lhstype), lhs),
  5442.               NULL_TREE);
  5443.  
  5444.       if (! comptypes (TREE_TYPE (lhs_addr), TREE_TYPE (rhs_addr), 1))
  5445.     rhs_addr = convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr)), rhs_addr);
  5446.       {
  5447.     tree noncopied_parts = NULL_TREE;
  5448.  
  5449.     if (TYPE_NONCOPIED_PARTS (lhstype) != 0)
  5450.       noncopied_parts = init_noncopied_parts (lhs,
  5451.                           TYPE_NONCOPIED_PARTS (lhstype));
  5452.     while (noncopied_parts != 0)
  5453.       {
  5454.         result = tree_cons (NULL_TREE,
  5455.                 build_modify_expr (convert (ptr_type_node, TREE_VALUE (noncopied_parts)),
  5456.                            NOP_EXPR,
  5457.                            TREE_PURPOSE (noncopied_parts)),
  5458.                 result);
  5459.         noncopied_parts = TREE_CHAIN (noncopied_parts);
  5460.       }
  5461.       }
  5462.       /* Once we have our hands on an address, we must change NEWRHS
  5463.      to work from there.  Otherwise we can get multiple evaluations
  5464.      of NEWRHS.  */
  5465.       if (TREE_CODE (newrhs) != SAVE_EXPR)
  5466.     newrhs = build_indirect_ref (rhs_addr, NULL_PTR);
  5467.  
  5468.       while (vbases)
  5469.     {
  5470.       tree elt_lhs = convert_pointer_to (vbases, lhs_addr);
  5471.       tree elt_rhs = convert_pointer_to (vbases, rhs_addr);
  5472.       result
  5473.         = tree_cons (NULL_TREE,
  5474.              build_modify_expr_1 (build_indirect_ref (elt_lhs, NULL_PTR),
  5475.                           modifycode,
  5476.                           build_indirect_ref (elt_rhs, NULL_PTR),
  5477.                           TYPE_BINFO (lhstype)),
  5478.              result);
  5479.       if (TREE_VALUE (result) == error_mark_node)
  5480.         return error_mark_node;
  5481.       vbases = TREE_CHAIN (vbases);
  5482.     }
  5483.       result = tree_cons (NULL_TREE,
  5484.               build_modify_expr_1 (lhs,
  5485.                            modifycode,
  5486.                            newrhs,
  5487.                            TYPE_BINFO (lhstype)),
  5488.               result);
  5489.       return build_compound_expr (result);
  5490.     }
  5491.  
  5492.   /* It is now illegal to assign unions which contain members that
  5493.      have non-default assignment operators.  */
  5494.   if (! flag_traditional && TREE_CODE (lhstype) == UNION_TYPE)
  5495.     {
  5496.       if (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype))
  5497.     {
  5498.       error ("invalid initialization of union containing members with X(X&) constructor");
  5499.       return error_mark_node;
  5500.     }
  5501.       else if (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  5502.     {
  5503.       error ("invalid assignment of union containing members with non-default operator=");
  5504.       return error_mark_node;
  5505.     }
  5506.     }
  5507.  
  5508.   /* If storing in a field that is in actuality a short or narrower than one,
  5509.      we must store in the field in its actual type.  */
  5510.  
  5511.   if (lhstype != TREE_TYPE (lhs))
  5512.     {
  5513.       lhs = copy_node (lhs);
  5514.       TREE_TYPE (lhs) = lhstype;
  5515.     }
  5516.  
  5517.   /* Convert new value to destination type.  */
  5518.  
  5519.   if (TREE_CODE (lhstype) == ARRAY_TYPE)
  5520.     {
  5521.       /* Have to wrap this in RTL_EXPR for two cases:
  5522.      in base or member initialization and if we
  5523.      are a branch of a ?: operator.  Since we
  5524.      can't easily know the latter, just do it always.  */
  5525.  
  5526.       result = make_node (RTL_EXPR);
  5527.  
  5528.       TREE_TYPE (result) = void_type_node;
  5529.       do_pending_stack_adjust ();
  5530.       start_sequence_for_rtl_expr (result);
  5531.  
  5532.       /* As a matter of principle, `start_sequence' should do this.  */
  5533.       emit_note (0, -1);
  5534.  
  5535.       expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs,
  5536.                1 + (modifycode != INIT_EXPR));
  5537.  
  5538.       do_pending_stack_adjust ();
  5539.  
  5540.       TREE_SIDE_EFFECTS (result) = 1;
  5541.       RTL_EXPR_SEQUENCE (result) = get_insns ();
  5542.       RTL_EXPR_RTL (result) = const0_rtx;
  5543.       end_sequence ();
  5544.       return result;
  5545.     }
  5546.  
  5547.   if (modifycode == INIT_EXPR)
  5548.     {
  5549.       newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
  5550.                        "assignment", NULL_TREE, 0);
  5551.       if (lhs == DECL_RESULT (current_function_decl))
  5552.     {
  5553.       if (DECL_INITIAL (lhs))
  5554.         warning ("return value from function receives multiple initializations");
  5555.       DECL_INITIAL (lhs) = newrhs;
  5556.     }
  5557.     }
  5558.   else
  5559.     {
  5560.       if (IS_AGGR_TYPE (lhstype))
  5561.     {
  5562. #if 1
  5563.       if (TYPE_GETS_ASSIGNMENT (lhstype)
  5564.           && ! TYPE_HAS_ASSIGNMENT (lhstype))
  5565.         {
  5566.           cp_error ("assignment not defined for type `%T'", lhstype);
  5567.           return error_mark_node;
  5568.         }
  5569. #endif
  5570.       if (result = build_opfncall (MODIFY_EXPR,
  5571.                        LOOKUP_NORMAL, lhs, newrhs,
  5572.                        make_node (NOP_EXPR)))
  5573.         return result;
  5574.     }
  5575.       newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  5576.                        NULL_TREE, 0);
  5577.       if (flag_elide_constructors == 0
  5578.       && TREE_CODE (newrhs) == CALL_EXPR
  5579.       && TREE_ADDRESSABLE (lhstype))
  5580.     {
  5581.       /* Can't initialized directly from a CALL_EXPR, since
  5582.          we don't know about what doesn't alias what.  */
  5583.  
  5584.       tree temp = get_temp_name (lhstype, 0);
  5585.       newrhs = build (COMPOUND_EXPR, lhstype,
  5586.               build_modify_expr (temp, INIT_EXPR, newrhs),
  5587.               temp);
  5588.     }
  5589.     }
  5590.  
  5591.   if (TREE_CODE (newrhs) == ERROR_MARK)
  5592.     return error_mark_node;
  5593.  
  5594.   if (TREE_CODE (newrhs) == COND_EXPR)
  5595.     {
  5596.       tree lhs1;
  5597.       tree cond = TREE_OPERAND (newrhs, 0);
  5598.  
  5599.       if (TREE_SIDE_EFFECTS (lhs))
  5600.     cond = build_compound_expr (tree_cons
  5601.                     (NULL_TREE, lhs,
  5602.                      build_tree_list (NULL_TREE, cond)));
  5603.  
  5604.       /* Cannot have two identical lhs on this one tree (result) as preexpand
  5605.      calls will rip them out and fill in RTL for them, but when the
  5606.      rtl is generated, the calls will only be in the first side of the
  5607.      condition, not on both, or before the conditional jump! (mrs) */
  5608.       lhs1 = break_out_calls (lhs);
  5609.  
  5610.       if (lhs == lhs1)
  5611.     /* If there's no change, the COND_EXPR behaves like any other rhs.  */
  5612.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5613.             lhstype, lhs, newrhs);
  5614.       else
  5615.     {
  5616.       tree result_type = TREE_TYPE (newrhs);
  5617.       /* We have to convert each arm to the proper type because the
  5618.          types may have been munged by constant folding.  */
  5619.       result
  5620.         = build (COND_EXPR, result_type, cond,
  5621.              build_modify_expr (lhs, modifycode,
  5622.                     convert (result_type,
  5623.                          TREE_OPERAND (newrhs, 1))),
  5624.              build_modify_expr (lhs1, modifycode,
  5625.                     convert (result_type,
  5626.                          TREE_OPERAND (newrhs, 2))));
  5627.     }
  5628.     }
  5629.   else if (modifycode != INIT_EXPR && TREE_CODE (newrhs) == WITH_CLEANUP_EXPR)
  5630.     {
  5631.       tree cleanup = TREE_OPERAND (newrhs, 2);
  5632.       tree slot;
  5633.  
  5634.       /* Finish up by running cleanups and having the "value" of the lhs.  */
  5635.       tree exprlist = tree_cons (NULL_TREE, cleanup,
  5636.                  build_tree_list (NULL_TREE, lhs));
  5637.       newrhs = TREE_OPERAND (newrhs, 0);
  5638.       if (TREE_CODE (newrhs) == TARGET_EXPR)
  5639.       slot = TREE_OPERAND (newrhs, 0);
  5640.       else if (TREE_CODE (newrhs) == ADDR_EXPR)
  5641.     {
  5642.       /* Bad but legal.  */
  5643.       slot = newrhs;
  5644.       warning ("address taken of temporary object");
  5645.     }
  5646.       else
  5647.     my_friendly_abort (118);
  5648.  
  5649.       /* Copy the value computed in SLOT into LHS.  */
  5650.       exprlist = tree_cons (NULL_TREE,
  5651.                 build_modify_expr (lhs, modifycode, slot),
  5652.                 exprlist);
  5653.       /* Evaluate the expression that needs CLEANUP.  This will
  5654.      compute the value into SLOT.  */
  5655.       exprlist = tree_cons (NULL_TREE, newrhs, exprlist);
  5656.       result = convert (lhstype, build_compound_expr (exprlist));
  5657.     }
  5658.   else
  5659.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5660.             lhstype, lhs, newrhs);
  5661.   TREE_SIDE_EFFECTS (result) = 1;
  5662.  
  5663.   /* If we got the LHS in a different type for storing in,
  5664.      convert the result back to the nominal type of LHS
  5665.      so that the value we return always has the same type
  5666.      as the LHS argument.  */
  5667.  
  5668.   if (olhstype == TREE_TYPE (result))
  5669.     return result;
  5670.   return convert_for_assignment (olhstype, result, "assignment",
  5671.                  NULL_TREE, 0);
  5672. }
  5673.  
  5674.  
  5675. /* Return 0 if EXP is not a valid lvalue in this language
  5676.    even though `lvalue_or_else' would accept it.  */
  5677.  
  5678. int
  5679. language_lvalue_valid (exp)
  5680.      tree exp;
  5681. {
  5682.   return 1;
  5683. }
  5684.  
  5685. /* Build a constructor for a pointer to member function.  It can be
  5686.    used to initialize global variables, local variable, or used
  5687.    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
  5688.    want to be.  */
  5689.  
  5690. tree
  5691. build_ptrmemfunc (type, pfn)
  5692.      tree type, pfn;
  5693. {
  5694.   tree index;
  5695.   tree delta = integer_zero_node;
  5696.   tree delta2 = integer_zero_node;
  5697.   tree vfield_offset;
  5698.   tree npfn;
  5699.   tree u;
  5700.  
  5701.   /* Handle null pointer to member function conversions. */
  5702.   if (integer_zerop (pfn))
  5703.     {
  5704.       pfn = build_c_cast (type, integer_zero_node);
  5705.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
  5706.       return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, integer_zero_node,
  5707.                           tree_cons (NULL_TREE, integer_zero_node,
  5708.                                  tree_cons (NULL_TREE, u, NULL_TREE))));
  5709.     }
  5710.  
  5711.   /* Allow pointer to member conversions here. */
  5712.   if (type != TREE_TYPE (pfn))
  5713.     {
  5714.       tree binfo
  5715.     = get_binfo (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
  5716.              TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
  5717.              1);
  5718.       if (binfo == error_mark_node)
  5719.     {
  5720.       error ("   in pointer to member function conversion");
  5721.       return NULL_TREE;
  5722.     }
  5723.       if (binfo == 0)
  5724.     {
  5725.       error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
  5726.                    TYPE_METHOD_BASETYPE (TREE_TYPE (type)));
  5727.       error ("   in pointer to member function conversion");
  5728.       return NULL_TREE;
  5729.     }
  5730.       if (TREE_VIA_VIRTUAL (binfo))
  5731.     {
  5732.       sorry ("pointer to member conversion from virtual base class");
  5733.     }
  5734.       delta = BINFO_OFFSET (binfo);
  5735.       delta2 = size_binop (PLUS_EXPR, delta2, delta);
  5736.     }
  5737.   
  5738.  
  5739.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
  5740.     warning ("assuming pointer to member function is non-virtual");
  5741.  
  5742.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
  5743.       && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
  5744.     {
  5745.       /* Find the offset to the vfield pointer in the object. */
  5746.       vfield_offset = TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn)));
  5747.       vfield_offset = CLASSTYPE_VFIELD (vfield_offset);
  5748.       vfield_offset = DECL_FIELD_BITPOS (vfield_offset);
  5749.       vfield_offset = size_binop (FLOOR_DIV_EXPR, vfield_offset, size_int (BITS_PER_UNIT));
  5750.       delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
  5751.  
  5752.       /* Map everything down one to make room for the null pointer to member.  */
  5753.       index = size_binop (PLUS_EXPR,
  5754.               DECL_VINDEX (TREE_OPERAND (pfn, 0)),
  5755.               integer_one_node);
  5756.       u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
  5757.  
  5758.       return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  5759.                           tree_cons (NULL_TREE, index,
  5760.                                  tree_cons (NULL_TREE, u, NULL_TREE))));
  5761.     }
  5762.   else
  5763.     index = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  5764.  
  5765.   npfn = build1 (NOP_EXPR, type, pfn);
  5766.   TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
  5767.  
  5768.   u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
  5769.  
  5770.   return build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  5771.                           tree_cons (NULL_TREE, index,
  5772.                              tree_cons (NULL_TREE, u, NULL_TREE))));
  5773. }
  5774.  
  5775. /* Convert value RHS to type TYPE as preparation for an assignment
  5776.    to an lvalue of type TYPE.
  5777.    The real work of conversion is done by `convert'.
  5778.    The purpose of this function is to generate error messages
  5779.    for assignments that are not allowed in C.
  5780.    ERRTYPE is a string to use in error messages:
  5781.    "assignment", "return", etc.
  5782.  
  5783.    C++: attempts to allow `convert' to find conversions involving
  5784.    implicit type conversion between aggregate and scalar types
  5785.    as per 8.5.6 of C++ manual.  Does not randomly dereference
  5786.    pointers to aggregates!  */
  5787.  
  5788. static tree
  5789. convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
  5790.      tree type, rhs;
  5791.      char *errtype;
  5792.      tree fndecl;
  5793.      int parmnum;
  5794. {
  5795.   register enum tree_code codel = TREE_CODE (type);
  5796.   register tree rhstype;
  5797.   register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
  5798.  
  5799.   if (coder == UNKNOWN_TYPE)
  5800.     rhs = instantiate_type (type, rhs, 1);
  5801.  
  5802.   if (coder == ERROR_MARK)
  5803.     return error_mark_node;
  5804.  
  5805.   if (codel == OFFSET_TYPE)
  5806.     {
  5807.       type = TREE_TYPE (type);
  5808.       codel = TREE_CODE (type);
  5809.     }
  5810.  
  5811.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  5812.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  5813.     rhs = TREE_OPERAND (rhs, 0);
  5814.  
  5815.   if (rhs == error_mark_node)
  5816.     return error_mark_node;
  5817.  
  5818.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  5819.     {
  5820.       rhs = resolve_offset_ref (rhs);
  5821.       if (rhs == error_mark_node)
  5822.     return error_mark_node;
  5823.       rhstype = TREE_TYPE (rhs);
  5824.       coder = TREE_CODE (rhstype);
  5825.     }
  5826.  
  5827.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  5828.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  5829.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  5830.     rhs = default_conversion (rhs);
  5831.   else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  5832.     rhs = convert_from_reference (rhs);
  5833.  
  5834.   rhstype = TREE_TYPE (rhs);
  5835.   coder = TREE_CODE (rhstype);
  5836.  
  5837.   /* This should no longer change types on us.  */
  5838.   if (TREE_CODE (rhs) == CONST_DECL)
  5839.     rhs = DECL_INITIAL (rhs);
  5840.   else if (TREE_READONLY_DECL_P (rhs))
  5841.     rhs = decl_constant_value (rhs);
  5842.  
  5843.   if (type == rhstype)
  5844.     {
  5845.       overflow_warning (rhs);
  5846.       return rhs;
  5847.     }
  5848.  
  5849.   if (coder == VOID_TYPE)
  5850.     {
  5851.       error ("void value not ignored as it ought to be");
  5852.       return error_mark_node;
  5853.     }
  5854.   /* Arithmetic types all interconvert.  */
  5855.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE)
  5856.        && (coder == INTEGER_TYPE || coder == REAL_TYPE))
  5857.     {
  5858.       /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE.  */
  5859.       if (coder == REAL_TYPE && codel == INTEGER_TYPE)
  5860.     warn_for_assignment ("float or double assigned to integer data type",
  5861.                  "float or double used for argument %d of `%s'",
  5862.                  errtype, fndecl, parmnum, 0);
  5863.       /* And we should warn if assigning a negative value to
  5864.      an unsigned variable.  */
  5865.       else if (TREE_UNSIGNED (type))
  5866.     {
  5867.       if (TREE_CODE (rhs) == INTEGER_CST
  5868.           && TREE_NEGATED_INT (rhs))
  5869.         warn_for_assignment ("negative value assigned to unsigned quantity",
  5870.                  "negative value passed as argument %d of `%s'",
  5871.                  errtype, fndecl, parmnum, 0);
  5872.       overflow_warning (rhs);
  5873.       if (TREE_CONSTANT (rhs))
  5874.         rhs = fold (rhs);
  5875.     }
  5876.  
  5877.       return convert_and_check (type, rhs);
  5878.     }
  5879.   /* Conversions involving enums.  */
  5880.   else if ((codel == ENUMERAL_TYPE
  5881.         && (coder == ENUMERAL_TYPE || coder == INTEGER_TYPE || coder == REAL_TYPE))
  5882.        || (coder == ENUMERAL_TYPE
  5883.            && (codel == ENUMERAL_TYPE || codel == INTEGER_TYPE || codel == REAL_TYPE)))
  5884.     {
  5885.       extern int warn_enum_clash;
  5886.  
  5887.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  5888.     return convert (type, rhs);
  5889.       if (warn_enum_clash)
  5890.     {
  5891.       if (codel == ENUMERAL_TYPE && coder == ENUMERAL_TYPE)
  5892.         message_2_types (warning, "conversion between incompatible enumeral types `%s' and `%s'",
  5893.                  type, rhstype);
  5894.       else if (coder == REAL_TYPE)
  5895.         warn_for_assignment ("float or double assigned to enumeral data type",
  5896.                  "float or double passed as enumeral data type for argument %d of `%s'",
  5897.                  errtype, fndecl, parmnum, pedantic);
  5898.       else if (codel == REAL_TYPE)
  5899.         warn_for_assignment ("enumeral value assigned to real data type",
  5900.                  "enumeral value passed as real data type for argument %d of `%s'",
  5901.                  errtype, fndecl, parmnum, pedantic);
  5902.       else if (coder == INTEGER_TYPE)
  5903.         warn_for_assignment ("assignment of integer to enumeral data type",
  5904.                  "passing integer as enumeral data type for argument %d of `%s'",
  5905.                  errtype, fndecl, parmnum, pedantic);
  5906.     }
  5907.       return convert (type, rhs);
  5908.     }
  5909.   /* Conversions among pointers */
  5910.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  5911.     {
  5912.       register tree ttl = TREE_TYPE (type);
  5913.       register tree ttr = TREE_TYPE (rhstype);
  5914.  
  5915.       /* If both pointers are of aggregate type, then we
  5916.      can give better error messages, and save some work
  5917.      as well.  */
  5918.       if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
  5919.     {
  5920.       tree binfo;
  5921.  
  5922.       if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)
  5923.           || type == class_star_type_node
  5924.           || rhstype == class_star_type_node)
  5925.         binfo = TYPE_BINFO (ttl);
  5926.       else
  5927.         binfo = get_binfo (ttl, ttr, 1);
  5928.  
  5929.       if (binfo == error_mark_node)
  5930.         return error_mark_node;
  5931.       if (binfo == 0)
  5932.         return error_not_base_type (ttl, ttr);
  5933.  
  5934.       if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  5935.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  5936.                  "pointer to const given for argument %d of `%s'",
  5937.                  errtype, fndecl, parmnum, 0);
  5938.       if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  5939.         warn_for_assignment ("%s of non-`volatile *' pointer from `volatile *'",
  5940.                  "pointer to volatile given for argument %d of `%s'",
  5941.                  errtype, fndecl, parmnum, 0);
  5942.     }
  5943.  
  5944.       /* Any non-function converts to a [const][volatile] void *
  5945.      and vice versa; otherwise, targets must be the same.
  5946.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  5947.       else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  5948.            || TYPE_MAIN_VARIANT (ttr) == void_type_node
  5949.            || comp_target_types (type, rhstype, 1)
  5950.            || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  5951.            == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
  5952.     {
  5953.       /* ARM $4.8, commentary on p39.  */
  5954.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  5955.           && TREE_CODE (ttr) == OFFSET_TYPE)
  5956.         {
  5957.           error ("no standard conversion from pointer to member to `void *'");
  5958.           return error_mark_node;
  5959.         }
  5960.  
  5961.       if (TYPE_MAIN_VARIANT (ttl) != void_type_node
  5962.           && TYPE_MAIN_VARIANT (ttr) == void_type_node
  5963.           && rhs != null_pointer_node)
  5964.         pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
  5965.              errtype);
  5966.       else if (pedantic
  5967.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  5968.            && (TREE_CODE (ttr) == FUNCTION_TYPE
  5969.                || TREE_CODE (ttr) == METHOD_TYPE))
  5970.           ||
  5971.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  5972.            && (TREE_CODE (ttl) == FUNCTION_TYPE
  5973.                || TREE_CODE (ttl) == METHOD_TYPE))))
  5974.         warn_for_assignment ("%s between function pointer and `void *'",
  5975.                  "function pointer and `void *' incompatible; argument %d of `%s'",
  5976.                  errtype, fndecl, parmnum, flag_pedantic_errors);
  5977.       /* Const and volatile mean something different for function types,
  5978.          so the usual warnings are not appropriate.  */
  5979.       else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
  5980.            || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
  5981.         {
  5982.           if (TREE_CODE (ttl) == OFFSET_TYPE
  5983.           && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
  5984.                    CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
  5985.         {
  5986.           sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
  5987.           return error_mark_node;
  5988.         }
  5989.           if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  5990.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  5991.                      "pointer to const given for argument %d of `%s'",
  5992.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  5993.           if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  5994.         warn_for_assignment ("%s of non-`volatile *' pointer from `volatile *'",
  5995.                      "pointer to volatile given for argument %d of `%s'",
  5996.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  5997.         }
  5998.     }
  5999.       else if (TREE_CODE (ttr) == OFFSET_TYPE
  6000.            && TREE_CODE (ttl) != OFFSET_TYPE)
  6001.     {
  6002.       /* Normally, pointers to different type codes (other
  6003.          than void) are not compatible, but we perform
  6004.          some type instantiation if that resolves the
  6005.          ambiguity of (X Y::*) and (X *).  */
  6006.  
  6007.       if (current_class_decl)
  6008.         {
  6009.           if (TREE_CODE (rhs) == INTEGER_CST)
  6010.         {
  6011.           rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)),
  6012.                    current_class_decl, rhs);
  6013.           return convert_for_assignment (type, rhs,
  6014.                          errtype, fndecl, parmnum);
  6015.         }
  6016.         }
  6017.       if (TREE_CODE (ttl) == METHOD_TYPE)
  6018.         error ("%s between pointer-to-method and pointer-to-member types",
  6019.            errtype);
  6020.       else
  6021.         error ("%s between pointer and pointer-to-member types", errtype);
  6022.       return error_mark_node;
  6023.     }
  6024.       else
  6025.     {
  6026.       int const_parity = TYPE_READONLY (type) ^ TYPE_READONLY (rhstype);
  6027.       int volatile_parity = TYPE_VOLATILE (type) ^ TYPE_VOLATILE (rhstype);
  6028.       int unsigned_parity;
  6029.       int nptrs = 0;
  6030.  
  6031.       while (TREE_CODE (ttl) == POINTER_TYPE
  6032.          && TREE_CODE (ttr) == POINTER_TYPE)
  6033.         {
  6034.           nptrs -= 1;
  6035.           const_parity |= TYPE_READONLY (ttl) ^ TYPE_READONLY (ttr);
  6036.           volatile_parity |= TYPE_VOLATILE (ttl) ^ TYPE_VOLATILE (ttr);
  6037.           ttl = TREE_TYPE (ttl);
  6038.           ttr = TREE_TYPE (ttr);
  6039.         }
  6040.       unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);
  6041.       if (unsigned_parity)
  6042.         if (TREE_UNSIGNED (ttl))
  6043.           ttr = unsigned_type (ttr);
  6044.         else
  6045.           ttl = unsigned_type (ttl);
  6046.  
  6047.       if (comp_target_types (ttl, ttr, nptrs))
  6048.         {
  6049.           if (const_parity)
  6050.         warn_for_assignment ("%s of non-`const *' pointer from `const *'",
  6051.                      "pointer to const given for argument %d of `%s'",
  6052.                      errtype, fndecl, parmnum, 0);
  6053.           if (volatile_parity)
  6054.         warn_for_assignment ("%s of non-`volatile *' pointer from volatile *",
  6055.                      "pointer to volatile given for argument %d of `%s'",
  6056.                      errtype, fndecl, parmnum, 0);
  6057.           if (unsigned_parity > 0)
  6058.         warn_for_assignment ("%s of unsigned pointer from signed pointer",
  6059.                      "passing signed pointer to unsigned pointer argument %d of `%s'",
  6060.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6061.           else if (unsigned_parity < 0)
  6062.         warn_for_assignment ("%s of signed pointer from unsigned pointer",
  6063.                      "passing unsigned pointer to signed pointer argument %d of `%s'",
  6064.                      errtype, fndecl, parmnum, flag_pedantic_errors);
  6065.  
  6066.           /* C++ is not so friendly about converting function and
  6067.          member function pointers as C.  Emit warnings here.  */
  6068.           if (TREE_CODE (ttl) == FUNCTION_TYPE
  6069.           || TREE_CODE (ttl) == METHOD_TYPE)
  6070.         if (! comptypes (ttl, ttr, 0))
  6071.           {
  6072.             char *tmpbuf, *lhsbuf;
  6073.             char *rhsbuf;
  6074.             tree null_name = get_identifier ("");
  6075.             tree lhs = build_decl (FUNCTION_DECL, null_name, ttl);
  6076.             tree rhs = build_decl (FUNCTION_DECL, null_name, ttr);
  6077.             tmpbuf = fndecl_as_string (0, lhs, 1);
  6078.             lhsbuf = (char *) alloca (strlen (tmpbuf)+1);
  6079.             strcpy (lhsbuf, tmpbuf);
  6080.             rhsbuf = fndecl_as_string (0, rhs, 1);
  6081.             warning ("conflicting function types in %s:", errtype);
  6082.             warning ("\t`%s' != `%s'", lhsbuf, rhsbuf);
  6083.           }
  6084.         }
  6085.       else if (TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6086.         {
  6087.           /* When does this happen?  */
  6088.           my_friendly_abort (119);
  6089.           /* Conversion of a pointer-to-member type to void *.  */
  6090.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6091.           TREE_TYPE (rhs) = type;
  6092.           return rhs;
  6093.         }
  6094.       else if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6095.         {
  6096.           /* When does this happen?  */
  6097.           my_friendly_abort (120);
  6098.           /* Conversion of a pointer-to-member type to void *.  */
  6099.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6100.           TREE_TYPE (rhs) = type;
  6101.           return rhs;
  6102.         }
  6103.       else
  6104.         {
  6105.           if (fndecl)
  6106.         error ("incompatible pointer types for argument %d of `%s'",
  6107.                parmnum + 1, lang_printable_name (fndecl));
  6108.           else
  6109.         error ("%s between incompatible pointer types", errtype);
  6110.           return error_mark_node;
  6111.         }
  6112.     }
  6113.       return convert (type, rhs);
  6114.     }
  6115.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  6116.     {
  6117.       /* An explicit constant 0 can convert to a pointer,
  6118.          but not a 0 that results from casting or folding.  */
  6119.       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
  6120.     {
  6121.       warn_for_assignment ("%s of pointer from integer lacks a cast",
  6122.                    "passing integer to pointer argument %d of `%s' lacks a cast",
  6123.                    errtype, fndecl, parmnum, flag_pedantic_errors);
  6124.       return convert (type, rhs);
  6125.     }
  6126.       return null_pointer_node;
  6127.     }
  6128.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  6129.     {
  6130.       warn_for_assignment ("%s of integer from pointer lacks a cast",
  6131.                "passing pointer to integer argument %d of `%s' lacks a cast",
  6132.                errtype, fndecl, parmnum, flag_pedantic_errors);
  6133.       return convert (type, rhs);
  6134.     }
  6135.  
  6136.   /* C++ */
  6137.   else if (((coder == POINTER_TYPE && TREE_CODE (rhs) == ADDR_EXPR
  6138.          && TREE_CODE (rhstype) == POINTER_TYPE
  6139.          && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE)
  6140.         || integer_zerop (rhs))
  6141.        && TYPE_PTRMEMFUNC_P (type))
  6142.     {
  6143.       /* compatible pointer to member functions. */
  6144.       rhs = build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), rhs);
  6145.       if (rhs == 0)
  6146.     return error_mark_node;
  6147.       return digest_init (type, rhs, (tree *)0);
  6148.     }
  6149.   else if (codel == ERROR_MARK || coder == ERROR_MARK)
  6150.     return error_mark_node;
  6151.  
  6152.   /* This should no longer happen.  References are initialized via
  6153.      `convert_for_initialization'.  They should otherwise be
  6154.      bashed before coming here.  */
  6155.   else if (codel == REFERENCE_TYPE)
  6156.     /* Force an abort.  */
  6157.     my_friendly_assert (codel != REFERENCE_TYPE, 317);
  6158.   else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))
  6159.     return build1 (NOP_EXPR, type, rhs);
  6160.   else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs)))
  6161.     return convert (type, rhs);
  6162.  
  6163.   error ("incompatible types in %s", errtype);
  6164.   return error_mark_node;
  6165. }
  6166.  
  6167. /* Print a warning using either ANON_MSG or NAMED_MSG.
  6168.    ANON_MSG is used if DECL and FUNCTION are 0; it gets one parameter, OPNAME.
  6169.    NAMED_MSG is used if DECL is non-0;
  6170.    it gets two parameters, the name of DECL and that of FUNCTION.
  6171.    FUNCTION_MSG is used if DECL is 0 and FUNCTION is non-0;
  6172.    it gets one parameter, the name FUNCTION.
  6173.  
  6174.    If SEVERE is non-0, the report an error instead of a warning.
  6175.  
  6176.    If FNDECL is nonzero, the message concerns an argument in a call
  6177.    to that function.  ARGNUM is the number of the argument, origin 0.  */
  6178.  
  6179. void
  6180. warn_for_assignment (anon_msg, arg_msg, opname, fndecl, argnum, severe)
  6181.      char *anon_msg;
  6182.      char *arg_msg;
  6183.      char *opname;
  6184.      tree fndecl;
  6185.      int argnum;
  6186.      int severe;
  6187. {
  6188.   if (fndecl)
  6189.     {
  6190.       if (argnum < 0)
  6191.     {
  6192.       char *buf = (char *)alloca (strlen (arg_msg) + 1);
  6193.       char *p;
  6194.       strcpy (buf, arg_msg);
  6195.       for (p = buf; *p; p++)
  6196.         if (p[0] == '%' && p[1] == 'd')
  6197.           {
  6198.         p[1] = 's';
  6199.         if (severe)
  6200.           error (buf, "`this'", lang_printable_name (fndecl));
  6201.         else
  6202.           warning (buf, "`this'", lang_printable_name (fndecl));
  6203.         break;
  6204.           }
  6205.     }
  6206.       else if (severe)
  6207.     error (arg_msg, argnum + 1, lang_printable_name (fndecl));
  6208.       else
  6209.     warning (arg_msg, argnum + 1, lang_printable_name (fndecl));
  6210.     }
  6211.   else if (severe)
  6212.     error (anon_msg, opname);
  6213.   else
  6214.     warning (anon_msg, opname);
  6215. }
  6216.  
  6217. /* Convert RHS to be of type TYPE.  If EXP is non-zero,
  6218.    it is the target of the initialization.
  6219.    ERRTYPE is a string to use in error messages.
  6220.  
  6221.    Two major differences between the behavior of
  6222.    `convert_for_assignment' and `convert_for_initialization'
  6223.    are that references are bashed in the former, while
  6224.    copied in the latter, and aggregates are assigned in
  6225.    the former (operator=) while initialized in the
  6226.    latter (X(X&)).
  6227.  
  6228.    If using constructor make sure no conversion operator exists, if one does
  6229.    exist, an ambiguity exists.  */
  6230. tree
  6231. convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
  6232.      tree exp, type, rhs;
  6233.      int flags;
  6234.      char *errtype;
  6235.      tree fndecl;
  6236.      int parmnum;
  6237. {
  6238.   register enum tree_code codel = TREE_CODE (type);
  6239.   register tree rhstype;
  6240.   register enum tree_code coder;
  6241.  
  6242.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  6243.      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
  6244.   if (TREE_CODE (rhs) == NOP_EXPR
  6245.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)))
  6246.     rhs = TREE_OPERAND (rhs, 0);
  6247.  
  6248.   if (rhs == error_mark_node
  6249.       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
  6250.     return error_mark_node;
  6251.  
  6252.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6253.     {
  6254.       rhs = resolve_offset_ref (rhs);
  6255.       if (rhs == error_mark_node)
  6256.     return error_mark_node;
  6257.       rhstype = TREE_TYPE (rhs);
  6258.       coder = TREE_CODE (rhstype);
  6259.     }
  6260.  
  6261.   if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  6262.        && TREE_CODE (type) != ARRAY_TYPE && TREE_CODE (type) != REFERENCE_TYPE)
  6263.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  6264.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6265.     rhs = default_conversion (rhs);
  6266.  
  6267.   rhstype = TREE_TYPE (rhs);
  6268.   coder = TREE_CODE (rhstype);
  6269.  
  6270.   if (coder == UNKNOWN_TYPE)
  6271.     {
  6272.       rhs = instantiate_type (type, rhs, 1);
  6273.       rhstype = TREE_TYPE (rhs);
  6274.       coder = TREE_CODE (rhstype);
  6275.     }
  6276.  
  6277.   if (coder == ERROR_MARK)
  6278.     return error_mark_node;
  6279.  
  6280. #if 0
  6281.   /* This is *not* the quick way out!  It is the way to disaster.  */
  6282.   if (type == rhstype)
  6283.     goto converted;
  6284. #endif
  6285.  
  6286.   /* We accept references to incomplete types, so we can
  6287.      return here before checking if RHS is of complete type.  */
  6288.      
  6289.   if (codel == REFERENCE_TYPE)
  6290.     return convert_to_reference ((exp ? exp : error_mark_node),
  6291.                   type, rhs, fndecl, parmnum, errtype,
  6292.                  0, flags);
  6293.  
  6294.   rhs = require_complete_type (rhs);
  6295.   if (rhs == error_mark_node)
  6296.     return error_mark_node;
  6297.  
  6298.   if (exp != 0) exp = require_complete_type (exp);
  6299.   if (exp == error_mark_node)
  6300.     return error_mark_node;
  6301.  
  6302.   if (TREE_CODE (rhstype) == REFERENCE_TYPE)
  6303.     rhstype = TREE_TYPE (rhstype);
  6304.  
  6305.   if (IS_AGGR_TYPE (type) && TYPE_NEEDS_CONSTRUCTOR (type))
  6306.     {
  6307.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  6308.     {
  6309.       /* This is sufficient to perform initialization.  No need, apparently,
  6310.          to go through X(X&) to do first-cut initialization.  Return through
  6311.          a TARGET_EXPR so that we get cleanups if it is used.  */
  6312.       if (TREE_CODE (rhs) == CALL_EXPR)
  6313.         {
  6314.           rhs = build_cplus_new (type, rhs, 0);
  6315.           return rhs;
  6316.         }
  6317.       /* Handle the case of default parameter initialization and
  6318.          initialization of static variables.  */
  6319.       else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs))
  6320.         {
  6321.           my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318);
  6322.           if (exp)
  6323.         {
  6324.           my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316);
  6325.           TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1))
  6326.             = build_unary_op (ADDR_EXPR, exp, 0);
  6327.         }
  6328.           else
  6329.         rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0), 0);
  6330.           return rhs;
  6331.         }
  6332.     }
  6333.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)
  6334.       || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype)))
  6335.     {
  6336.       if (TYPE_HAS_INIT_REF (type))
  6337.         {
  6338.           tree init = build_method_call (exp, constructor_name_full (type),
  6339.                          build_tree_list (NULL_TREE, rhs),
  6340.                          NULL_TREE, LOOKUP_NORMAL);
  6341.  
  6342.           if (init == error_mark_node)
  6343.         return error_mark_node;
  6344.  
  6345.           if (exp == 0)
  6346.         {
  6347.           exp = build_cplus_new (type, init, 0);
  6348.           return exp;
  6349.         }
  6350.  
  6351.           return build (COMPOUND_EXPR, type, init, exp);
  6352.         }
  6353.  
  6354. #if 0
  6355.       /* ??? The following warnings are turned off because
  6356.          this is another place where the default X(X&) constructor
  6357.          is implemented.  */
  6358.       if (TYPE_HAS_ASSIGNMENT (type))
  6359.         warning ("bitwise copy: `%s' defines operator=()",
  6360.              TYPE_NAME_STRING (type));
  6361.       else if (TYPE_GETS_ASSIGNMENT (type))
  6362.         warning ("bitwise copy: `%s' has a member with operator=()",
  6363.              TYPE_NAME_STRING (type));
  6364. #endif
  6365.  
  6366.       if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  6367.         rhs = convert_from_reference (rhs);
  6368.       if (type != rhstype)
  6369.         return build1 (NOP_EXPR, type, rhs);
  6370.       return rhs;
  6371.     }
  6372.  
  6373.       return convert (type, rhs);
  6374.     }
  6375. #if 0
  6376.   /* ??? The following warnings are turned off because
  6377.      this is another place where the default X(X&) constructor
  6378.      is implemented.  */
  6379.   if (TYPE_LANG_SPECIFIC (type))
  6380.     {
  6381.       if (TYPE_HAS_ASSIGNMENT (type))
  6382.     warning ("bitwise copy: `%s' defines operator=()",
  6383.          TYPE_NAME_STRING (type));
  6384.       else if (TYPE_GETS_ASSIGNMENT (type))
  6385.     warning ("bitwise copy: `%s' has a member with operator=()",
  6386.          TYPE_NAME_STRING (type));
  6387.     }
  6388. #endif
  6389.  
  6390.   if (type == TREE_TYPE (rhs))
  6391.     {
  6392.       if (TREE_READONLY_DECL_P (rhs))
  6393.     rhs = decl_constant_value (rhs);
  6394.       return rhs;
  6395.     }
  6396.  
  6397.   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
  6398. }
  6399.  
  6400. /* Expand an ASM statement with operands, handling output operands
  6401.    that are not variables or INDIRECT_REFS by transforming such
  6402.    cases into cases that expand_asm_operands can handle.
  6403.  
  6404.    Arguments are same as for expand_asm_operands.
  6405.  
  6406.    We don't do default conversions on all inputs, because it can screw
  6407.    up operands that are expected to be in memory.  */
  6408.  
  6409. void
  6410. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  6411.      tree string, outputs, inputs, clobbers;
  6412.      int vol;
  6413.      char *filename;
  6414.      int line;
  6415. {
  6416.   int noutputs = list_length (outputs);
  6417.   register int i;
  6418.   /* o[I] is the place that output number I should be written.  */
  6419.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  6420.   register tree tail;
  6421.  
  6422.   /* Record the contents of OUTPUTS before it is modified.  */
  6423.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6424.     o[i] = TREE_VALUE (tail);
  6425.  
  6426.   /* Generate the ASM_OPERANDS insn;
  6427.      store into the TREE_VALUEs of OUTPUTS some trees for
  6428.      where the values were actually stored.  */
  6429.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  6430.  
  6431.   /* Copy all the intermediate outputs into the specified outputs.  */
  6432.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6433.     {
  6434.       if (o[i] != TREE_VALUE (tail))
  6435.     {
  6436.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  6437.                const0_rtx, VOIDmode, 0);
  6438.       free_temp_slots ();
  6439.     }
  6440.       /* Detect modification of read-only values.
  6441.      (Otherwise done by build_modify_expr.)  */
  6442.       else
  6443.     {
  6444.       tree type = TREE_TYPE (o[i]);
  6445.       if (TYPE_READONLY (type)
  6446.           || ((TREE_CODE (type) == RECORD_TYPE
  6447.            || TREE_CODE (type) == UNION_TYPE)
  6448.           && C_TYPE_FIELDS_READONLY (type)))
  6449.         readonly_error (o[i], "modification by `asm'", 1);
  6450.     }
  6451.     }
  6452.  
  6453.   /* Those MODIFY_EXPRs could do autoincrements.  */
  6454.   emit_queue ();
  6455. }
  6456.  
  6457. /* Expand a C `return' statement.
  6458.    RETVAL is the expression for what to return,
  6459.    or a null pointer for `return;' with no value.
  6460.  
  6461.    C++: upon seeing a `return', we must call destructors on all
  6462.    variables in scope which had constructors called on them.
  6463.    This means that if in a destructor, the base class destructors
  6464.    must be called before returning.
  6465.  
  6466.    The RETURN statement in C++ has initialization semantics.  */
  6467.  
  6468. void
  6469. c_expand_return (retval)
  6470.      tree retval;
  6471. {
  6472.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  6473.   extern tree dtor_label, ctor_label;
  6474.   tree result = DECL_RESULT (current_function_decl);
  6475.   tree valtype = TREE_TYPE (result);
  6476.   register int use_temp = 0;
  6477.   int returns_value = 1;
  6478.  
  6479.   if (TREE_THIS_VOLATILE (current_function_decl))
  6480.     warning ("function declared `volatile' has a `return' statement");
  6481.  
  6482.   if (retval == error_mark_node)
  6483.     {
  6484.       current_function_returns_null = 1;
  6485.       return;
  6486.     }
  6487.  
  6488.   if (retval == NULL_TREE)
  6489.     {
  6490.       /* A non-named return value does not count.  */
  6491.  
  6492.       /* Can't just return from a destructor.  */
  6493.       if (dtor_label)
  6494.     {
  6495.       expand_goto (dtor_label);
  6496.       return;
  6497.     }
  6498.  
  6499.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  6500.     retval = current_class_decl;
  6501.       else if (DECL_NAME (result) != NULL_TREE
  6502.            && TREE_CODE (valtype) != VOID_TYPE)
  6503.     retval = result;
  6504.       else
  6505.     {
  6506.       current_function_returns_null = 1;
  6507.  
  6508.       if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
  6509.         {
  6510.           if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE)
  6511.         {
  6512.           pedwarn ("`return' with no value, in function returning non-void");
  6513.           /* Clear this, so finish_function won't say that we
  6514.              reach the end of a non-void function (which we don't,
  6515.              we gave a return!).  */
  6516.           current_function_returns_null = 0;
  6517.         }
  6518.         }
  6519.  
  6520.       expand_null_return ();
  6521.       return;
  6522.     }
  6523.     }
  6524.   else if (DECL_CONSTRUCTOR_P (current_function_decl)
  6525.        && retval != current_class_decl)
  6526.     {
  6527.       error ("return from a constructor: use `this = ...' instead");
  6528.       retval = current_class_decl;
  6529.     }
  6530.  
  6531.   if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE)
  6532.     {
  6533.       current_function_returns_null = 1;
  6534.       /* We do this here so we'll avoid a warning about how the function
  6535.      "may or may not return a value" in finish_function.  */
  6536.       returns_value = 0;
  6537.  
  6538.       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  6539.     pedwarn ("`return' with a value, in function returning void");
  6540.       expand_return (retval);
  6541.     }
  6542.   /* Add some useful error checking for C++.  */
  6543.   else if (TREE_CODE (valtype) == REFERENCE_TYPE)
  6544.     {
  6545.       tree whats_returned;
  6546.       tree tmp_result = result;
  6547.  
  6548.       /* Don't initialize directly into a non-BLKmode retval, since that
  6549.      could lose when being inlined by another caller.  (GCC can't
  6550.      read the function return register in an inline function when
  6551.      the return value is being ignored).  */
  6552.       if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode)
  6553.     tmp_result = 0;
  6554.  
  6555.       /* convert to reference now, so we can give error if we
  6556.      return an reference to a non-lvalue.  */
  6557.       retval = convert_for_initialization (tmp_result, valtype, retval,
  6558.                        LOOKUP_NORMAL, "return",
  6559.                        NULL_TREE, 0);
  6560.  
  6561.       /* Sort through common things to see what it is
  6562.      we are returning.  */
  6563.       whats_returned = retval;
  6564.       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
  6565.     {
  6566.       whats_returned = TREE_OPERAND (whats_returned, 1);
  6567.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  6568.         whats_returned = TREE_OPERAND (whats_returned, 0);
  6569.     }
  6570.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  6571.     {
  6572.       whats_returned = TREE_OPERAND (whats_returned, 0);
  6573.       while (TREE_CODE (whats_returned) == NEW_EXPR
  6574.          || TREE_CODE (whats_returned) == TARGET_EXPR
  6575.          || TREE_CODE (whats_returned) == WITH_CLEANUP_EXPR)
  6576.         /* Get the target.  */
  6577.         whats_returned = TREE_OPERAND (whats_returned, 0);
  6578.     }
  6579.  
  6580.       if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
  6581.     {
  6582.       if (TEMP_NAME_P (DECL_NAME (whats_returned)))
  6583.         warning ("reference to non-lvalue returned");
  6584.       else if (! TREE_STATIC (whats_returned)
  6585.            && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned)))
  6586.         cp_warning_at ("reference to local variable `%D' returned", whats_returned);
  6587.     }
  6588.     }
  6589.   else if (TREE_CODE (retval) == ADDR_EXPR)
  6590.     {
  6591.       tree whats_returned = TREE_OPERAND (retval, 0);
  6592.  
  6593.       if (TREE_CODE (whats_returned) == TREE_LIST)
  6594.     whats_returned = TREE_VALUE (whats_returned);
  6595.  
  6596.       if (DECL_NAME (whats_returned)
  6597.       && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
  6598.       && !TREE_STATIC (whats_returned))
  6599.     cp_warning_at ("address of local variable `%D' returned", whats_returned);
  6600.     }
  6601.   
  6602.   /* Now deal with possible C++ hair:
  6603.      (1) Compute the return value.
  6604.      (2) If there are aggregate values with destructors which
  6605.      must be cleaned up, clean them (taking care
  6606.      not to clobber the return value).
  6607.      (3) If an X(X&) constructor is defined, the return
  6608.      value must be returned via that.  */
  6609.  
  6610.   if (retval == result
  6611.       /* Watch out for constructors, which "return" aggregates
  6612.      via initialization, but which otherwise "return" a pointer.  */
  6613.       || DECL_CONSTRUCTOR_P (current_function_decl))
  6614.     {
  6615.       /* This is just an error--it's already been reported.  */
  6616.       if (TYPE_SIZE (valtype) == NULL_TREE)
  6617.     return;
  6618.  
  6619.       if (TYPE_MODE (valtype) != BLKmode
  6620.       && any_pending_cleanups (1))
  6621.     {
  6622.       retval = get_temp_regvar (valtype, retval);
  6623.       use_temp = obey_regdecls;
  6624.     }
  6625.     }
  6626.   else if (IS_AGGR_TYPE (valtype) && TYPE_NEEDS_CONSTRUCTOR (valtype))
  6627.     {
  6628.       /* Throw away the cleanup that `build_functional_cast' gave us.  */
  6629.       if (TREE_CODE (retval) == WITH_CLEANUP_EXPR
  6630.       && TREE_CODE (TREE_OPERAND (retval, 0)) == TARGET_EXPR)
  6631.     retval = TREE_OPERAND (retval, 0);
  6632.       expand_aggr_init (result, retval, 0);
  6633.       DECL_INITIAL (result) = NULL_TREE;
  6634.       retval = 0;
  6635.     }
  6636.   else
  6637.     {
  6638.       if (TYPE_MODE (valtype) == VOIDmode)
  6639.     {
  6640.       if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode
  6641.           && warn_return_type)
  6642.         warning ("return of void value in function returning non-void");
  6643.       expand_expr_stmt (retval);
  6644.       retval = 0;
  6645.       result = 0;
  6646.     }
  6647.       else if (TYPE_MODE (valtype) != BLKmode
  6648.            && any_pending_cleanups (1))
  6649.     {
  6650.       retval = get_temp_regvar (valtype, retval);
  6651.       use_temp = obey_regdecls;
  6652.       result = 0;
  6653.     }
  6654.       else
  6655.     {
  6656.       retval = convert_for_initialization (result, valtype, retval,
  6657.                            LOOKUP_NORMAL,
  6658.                            "return", NULL_TREE, 0);
  6659.       DECL_INITIAL (result) = NULL_TREE;
  6660.     }
  6661.       if (retval == error_mark_node)
  6662.     return;
  6663.     }
  6664.  
  6665.   emit_queue ();
  6666.  
  6667.   if (retval != NULL_TREE
  6668.       && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
  6669.       && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
  6670.     current_function_return_value = retval;
  6671.  
  6672.   if (result)
  6673.     {
  6674.       /* Everything's great--RETVAL is in RESULT.  */
  6675.       if (original_result_rtx)
  6676.     store_expr (result, original_result_rtx, 0);
  6677.       else if (retval && retval != result)
  6678.     {
  6679.       /* Clear this out so the later call to decl_function_context
  6680.          won't end up bombing on us.  */
  6681.       if (DECL_CONTEXT (result) == error_mark_node)
  6682.         DECL_CONTEXT (result) = NULL_TREE;
  6683.       /* Here is where we finally get RETVAL into RESULT.
  6684.          `expand_return' does the magic of protecting
  6685.          RESULT from cleanups.  */
  6686.       retval = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  6687.       TREE_SIDE_EFFECTS (retval) = 1;
  6688.       expand_return (retval);
  6689.     }
  6690.       else
  6691.     expand_return (result);
  6692.  
  6693.       use_variable (DECL_RTL (result));
  6694.       if (ctor_label  && TREE_CODE (ctor_label) != ERROR_MARK)
  6695.     expand_goto (ctor_label);
  6696.       else
  6697.     expand_null_return ();
  6698.     }
  6699.   else
  6700.     {
  6701.       /* We may still need to put RETVAL into RESULT.  */
  6702.       result = DECL_RESULT (current_function_decl);
  6703.       if (original_result_rtx)
  6704.     {
  6705.       /* Here we have a named return value that went
  6706.          into memory.  We can compute RETVAL into that.  */
  6707.       if (retval)
  6708.         expand_assignment (result, retval, 0, 0);
  6709.       else
  6710.         store_expr (result, original_result_rtx, 0);
  6711.       result = make_tree (TREE_TYPE (result), original_result_rtx);
  6712.     }
  6713.       else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
  6714.     {
  6715.       /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do.  */
  6716.       expand_goto (ctor_label);
  6717.     }
  6718.       else if (retval)
  6719.     {
  6720.       /* Here is where we finally get RETVAL into RESULT.
  6721.          `expand_return' does the magic of protecting
  6722.          RESULT from cleanups.  */
  6723.       result = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  6724.       TREE_SIDE_EFFECTS (result) = 1;
  6725.       expand_return (result);
  6726.     }
  6727.       else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode)
  6728.     expand_return (result);
  6729.     }
  6730.  
  6731.   current_function_returns_value = returns_value;
  6732.   if (original_result_rtx)
  6733.     use_variable (original_result_rtx);
  6734.   if (use_temp)
  6735.     use_variable (DECL_RTL (DECL_RESULT (current_function_decl)));
  6736.  
  6737.   /* One way to clear out cleanups that EXPR might
  6738.      generate.  Note that this code will really be
  6739.      dead code, but that is ok--cleanups that were
  6740.      needed were handled by the magic of `return'.  */
  6741.   expand_cleanups_to (NULL_TREE);
  6742. }
  6743.  
  6744. /* Start a C switch statement, testing expression EXP.
  6745.    Return EXP if it is valid, an error node otherwise.  */
  6746.  
  6747. tree
  6748. c_expand_start_case (exp)
  6749.      tree exp;
  6750. {
  6751.   tree type = TREE_TYPE (exp);
  6752.   register enum tree_code code = TREE_CODE (type);
  6753.  
  6754.   if (IS_AGGR_TYPE_CODE (code))
  6755.     exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
  6756.   else
  6757.     exp = default_conversion (exp);
  6758.   if (exp == NULL_TREE)
  6759.     {
  6760.       error ("switch quantity not an integer");
  6761.       exp = error_mark_node;
  6762.     }
  6763.   type = TREE_TYPE (exp);
  6764.   code = TREE_CODE (type);
  6765.  
  6766.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  6767.     {
  6768.       error ("switch quantity not an integer");
  6769.       exp = error_mark_node;
  6770.     }
  6771.   else
  6772.     {
  6773.       tree index;
  6774.  
  6775.       exp = default_conversion (exp);
  6776.       type = TREE_TYPE (exp);
  6777.       index = get_unwidened (exp, 0);
  6778.       /* We can't strip a conversion from a signed type to an unsigned,
  6779.      because if we did, int_fits_type_p would do the wrong thing
  6780.      when checking case values for being in range,
  6781.      and it's too hard to do the right thing.  */
  6782.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  6783.       == TREE_UNSIGNED (TREE_TYPE (index)))
  6784.     exp = index;
  6785.     }
  6786.  
  6787.   expand_start_case (1, exp, type, "switch statement");
  6788.  
  6789.   return exp;
  6790. }
  6791.  
  6792. /* C++ does not yet support type checking of format strings.  */
  6793.  
  6794. void
  6795. record_format_info (function_ident, is_scan, format_num, first_arg_num)
  6796.       tree function_ident;
  6797.       int is_scan;
  6798.       int format_num;
  6799.       int first_arg_num;
  6800. {}
  6801.