LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-tree.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 9.6 % 2380 228
Test Date: 2026-07-11 15:47:05 Functions: 14.7 % 156 23
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
       2              : 
       3              : // This file is part of GCC.
       4              : 
       5              : // GCC is free software; you can redistribute it and/or modify it under
       6              : // the terms of the GNU General Public License as published by the Free
       7              : // Software Foundation; either version 3, or (at your option) any later
       8              : // version.
       9              : 
      10              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13              : // for more details.
      14              : 
      15              : // You should have received a copy of the GNU General Public License
      16              : // along with GCC; see the file COPYING3.  If not see
      17              : // <http://www.gnu.org/licenses/>.
      18              : 
      19              : #include "rust-tree.h"
      20              : #include "fold-const.h"
      21              : #include "stringpool.h"
      22              : #include "attribs.h"
      23              : #include "escaped_string.h"
      24              : #include "libiberty.h"
      25              : #include "stor-layout.h"
      26              : #include "hash-map.h"
      27              : #include "diagnostic.h"
      28              : #include "timevar.h"
      29              : #include "convert.h"
      30              : #include "gimple-expr.h"
      31              : #include "gimplify.h"
      32              : #include "function.h"
      33              : #include "gcc-rich-location.h"
      34              : #include "target.h"
      35              : #include "file-prefix-map.h"
      36              : #include "cgraph.h"
      37              : #include "output.h"
      38              : #include "memmodel.h"
      39              : #include "tm_p.h"
      40              : 
      41              : // forked from gcc/c-family/c-common.cc c_global_trees
      42              : tree c_global_trees[CTI_MAX];
      43              : // forked from gcc/cp/decl.cc cp_global_trees
      44              : tree cp_global_trees[CPTI_MAX];
      45              : 
      46              : struct saved_scope *scope_chain;
      47              : 
      48              : namespace Rust {
      49              : 
      50              : void
      51         1303 : mark_exp_read (tree exp)
      52              : {
      53         1303 :   char tmp_name[32];
      54         1303 :   ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", 1);
      55              : 
      56         1303 :   if (exp == NULL)
      57            0 :     return;
      58              : 
      59         1303 :   switch (TREE_CODE (exp))
      60              :     {
      61         1286 :     case VAR_DECL:
      62         1286 :       gcc_fallthrough ();
      63         1286 :     case PARM_DECL:
      64         1286 :       DECL_READ_P (exp) = 1;
      65         1286 :       break;
      66           16 :     case ARRAY_REF:
      67           16 :     case COMPONENT_REF:
      68           16 :     case MODIFY_EXPR:
      69           16 :     case REALPART_EXPR:
      70           16 :     case IMAGPART_EXPR:
      71           16 :     CASE_CONVERT:
      72           16 :     case ADDR_EXPR:
      73           16 :     case INDIRECT_REF:
      74           16 :     case FLOAT_EXPR:
      75           16 :     case VIEW_CONVERT_EXPR:
      76           16 :       mark_exp_read (TREE_OPERAND (exp, 0));
      77           16 :       break;
      78            0 :     case COMPOUND_EXPR:
      79            0 :       mark_exp_read (TREE_OPERAND (exp, 1));
      80            0 :       break;
      81            0 :     case COND_EXPR:
      82            0 :       if (TREE_OPERAND (exp, 1))
      83            0 :         mark_exp_read (TREE_OPERAND (exp, 1));
      84            0 :       if (TREE_OPERAND (exp, 2))
      85            0 :         mark_exp_read (TREE_OPERAND (exp, 2));
      86              :       break;
      87              :     default:
      88              :       break;
      89              :     }
      90              : }
      91              : 
      92              : tree
      93            0 : convert_from_reference (tree val)
      94              : {
      95            0 :   if (TREE_TYPE (val) && TYPE_REF_P (TREE_TYPE (val)))
      96              :     {
      97            0 :       tree t = TREE_TYPE (TREE_TYPE (val));
      98            0 :       tree ref = build1 (INDIRECT_REF, t, val);
      99              : 
     100            0 :       mark_exp_read (val);
     101              : 
     102            0 :       TREE_SIDE_EFFECTS (ref)
     103            0 :         = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (val));
     104            0 :       val = ref;
     105              :     }
     106              : 
     107            0 :   return val;
     108              : }
     109              : 
     110              : tree
     111         1287 : mark_use (tree expr, bool rvalue_p, bool read_p,
     112              :           location_t loc /* = UNKNOWN_LOCATION */,
     113              :           bool reject_builtin /* = true */)
     114              : {
     115              : #define RECUR(t) mark_use ((t), rvalue_p, read_p, loc, reject_builtin)
     116              : 
     117         1287 :   if (expr == NULL_TREE || error_operand_p (expr))
     118              :     return expr;
     119              : 
     120         1287 :   if (reject_builtin)
     121            0 :     return error_mark_node;
     122              : 
     123         1287 :   if (read_p)
     124         1287 :     mark_exp_read (expr);
     125              : 
     126         1287 :   bool recurse_op[3] = {false, false, false};
     127         1287 :   switch (TREE_CODE (expr))
     128              :     {
     129           15 :     case COMPONENT_REF:
     130           15 :       recurse_op[0] = true;
     131           15 :       break;
     132            0 :     case COMPOUND_EXPR:
     133            0 :       recurse_op[1] = true;
     134            0 :       break;
     135            0 :     case COND_EXPR:
     136            0 :       recurse_op[2] = true;
     137            0 :       if (TREE_OPERAND (expr, 1))
     138            0 :         recurse_op[1] = true;
     139              :       break;
     140            0 :     case INDIRECT_REF:
     141            0 :       if (REFERENCE_REF_P (expr))
     142              :         {
     143              :           /* Try to look through the reference.  */
     144            0 :           tree ref = TREE_OPERAND (expr, 0);
     145            0 :           tree r = mark_rvalue_use (ref, loc, reject_builtin);
     146            0 :           if (r != ref)
     147            0 :             expr = convert_from_reference (r);
     148              :         }
     149              :       break;
     150              : 
     151            0 :     case VIEW_CONVERT_EXPR:
     152            0 :       if (location_wrapper_p (expr))
     153              :         {
     154            0 :           loc = EXPR_LOCATION (expr);
     155            0 :           tree op = TREE_OPERAND (expr, 0);
     156            0 :           tree nop = RECUR (op);
     157            0 :           if (nop == error_mark_node)
     158              :             return error_mark_node;
     159            0 :           else if (op == nop)
     160              :             /* No change.  */;
     161            0 :           else if (DECL_P (nop) || CONSTANT_CLASS_P (nop))
     162              :             {
     163              :               /* Reuse the location wrapper.  */
     164            0 :               TREE_OPERAND (expr, 0) = nop;
     165              :               /* If we're replacing a DECL with a constant, we also need to
     166              :                  change the TREE_CODE of the location wrapper.  */
     167            0 :               if (rvalue_p)
     168            0 :                 TREE_SET_CODE (expr, NON_LVALUE_EXPR);
     169              :             }
     170              :           else
     171              :             {
     172              :               /* Drop the location wrapper.  */
     173            0 :               expr = nop;
     174            0 :               protected_set_expr_location (expr, loc);
     175              :             }
     176            0 :           return expr;
     177              :         }
     178            0 :       gcc_fallthrough ();
     179            0 :     CASE_CONVERT:
     180            0 :       recurse_op[0] = true;
     181            0 :       break;
     182              : 
     183              :     default:
     184              :       break;
     185              :     }
     186              : 
     187         5148 :   for (int i = 0; i < 3; ++i)
     188         3861 :     if (recurse_op[i])
     189              :       {
     190           15 :         tree op = TREE_OPERAND (expr, i);
     191           15 :         op = RECUR (op);
     192           15 :         if (op == error_mark_node)
     193              :           return error_mark_node;
     194           15 :         TREE_OPERAND (expr, i) = op;
     195              :       }
     196              : 
     197              :   return expr;
     198              : #undef RECUR
     199              : }
     200              : 
     201              : tree
     202            0 : mark_rvalue_use (tree e, location_t loc /* = UNKNOWN_LOCATION */,
     203              :                  bool reject_builtin /* = true */)
     204              : {
     205            0 :   return mark_use (e, true, true, loc, reject_builtin);
     206              : }
     207              : 
     208              : tree
     209            0 : mark_lvalue_use (tree expr)
     210              : {
     211            0 :   return mark_use (expr, false, true, input_location, false);
     212              : }
     213              : 
     214              : tree
     215            0 : mark_lvalue_use_nonread (tree expr)
     216              : {
     217            0 :   return mark_use (expr, false, false, input_location, false);
     218              : }
     219              : 
     220              : tree
     221        10161 : mark_discarded_use (tree expr)
     222              : {
     223        10161 :   if (expr == NULL_TREE)
     224              :     return expr;
     225              : 
     226        10161 :   STRIP_ANY_LOCATION_WRAPPER (expr);
     227              : 
     228        10161 :   switch (TREE_CODE (expr))
     229              :     {
     230            0 :     case COND_EXPR:
     231            0 :       TREE_OPERAND (expr, 2) = mark_discarded_use (TREE_OPERAND (expr, 2));
     232            2 :       gcc_fallthrough ();
     233            2 :     case COMPOUND_EXPR:
     234            2 :       TREE_OPERAND (expr, 1) = mark_discarded_use (TREE_OPERAND (expr, 1));
     235            2 :       return expr;
     236              : 
     237              :     case COMPONENT_REF:
     238              :     case ARRAY_REF:
     239              :     case INDIRECT_REF:
     240              :     case MEMBER_REF:
     241              :       break;
     242        10143 :     default:
     243        10143 :       if (DECL_P (expr))
     244              :         break;
     245              :       else
     246              :         return expr;
     247              :     }
     248              : 
     249         1272 :   return mark_use (expr, true, true, input_location, false);
     250              : }
     251              : 
     252              : tree
     253        10694 : convert_to_void (tree expr, impl_conv_void implicit)
     254              : {
     255        10694 :   location_t loc = expr_loc_or_input_loc (expr);
     256        10694 :   if (expr == error_mark_node || TREE_TYPE (expr) == error_mark_node)
     257              :     return error_mark_node;
     258              : 
     259        10159 :   expr = mark_discarded_use (expr);
     260        10159 :   if (implicit == ICV_CAST)
     261              :     /* An explicit cast to void avoids all -Wunused-but-set* warnings.  */
     262            0 :     mark_exp_read (expr);
     263              : 
     264        10159 :   if (!TREE_TYPE (expr))
     265              :     return expr;
     266              : 
     267        10159 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
     268              :     return expr;
     269         7839 :   switch (TREE_CODE (expr))
     270              :     {
     271            0 :     case COND_EXPR:
     272            0 :       {
     273              :         /* The two parts of a cond expr might be separate lvalues.  */
     274            0 :         tree op1 = TREE_OPERAND (expr, 1);
     275            0 :         tree op2 = TREE_OPERAND (expr, 2);
     276            0 :         bool side_effects
     277            0 :           = ((op1 && TREE_SIDE_EFFECTS (op1)) || TREE_SIDE_EFFECTS (op2));
     278            0 :         tree new_op1, new_op2;
     279            0 :         new_op1 = NULL_TREE;
     280            0 :         if (implicit != ICV_CAST && !side_effects)
     281              :           {
     282            0 :             if (op1)
     283            0 :               new_op1 = convert_to_void (op1, ICV_SECOND_OF_COND);
     284            0 :             new_op2 = convert_to_void (op2, ICV_THIRD_OF_COND);
     285              :           }
     286              :         else
     287              :           {
     288            0 :             if (op1)
     289            0 :               new_op1 = convert_to_void (op1, ICV_CAST);
     290            0 :             new_op2 = convert_to_void (op2, ICV_CAST);
     291              :           }
     292              : 
     293            0 :         expr = build3_loc (loc, COND_EXPR, TREE_TYPE (new_op2),
     294            0 :                            TREE_OPERAND (expr, 0), new_op1, new_op2);
     295            0 :         break;
     296              :       }
     297              : 
     298            2 :     case COMPOUND_EXPR:
     299            2 :       {
     300              :         /* The second part of a compound expr contains the value.  */
     301            2 :         tree op1 = TREE_OPERAND (expr, 1);
     302            2 :         tree new_op1;
     303            2 :         if (implicit != ICV_CAST
     304            2 :             && !warning_suppressed_p (expr /* What warning? */))
     305            2 :           new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA);
     306              :         else
     307            0 :           new_op1 = convert_to_void (op1, ICV_CAST);
     308              : 
     309            2 :         if (new_op1 != op1)
     310              :           {
     311            2 :             tree t = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (new_op1),
     312            2 :                                  TREE_OPERAND (expr, 0), new_op1);
     313            2 :             expr = t;
     314              :           }
     315              : 
     316              :         break;
     317              :       }
     318              : 
     319              :     case NON_LVALUE_EXPR:
     320              :     case NOP_EXPR:
     321              :       /* These have already decayed to rvalue.  */
     322              :       break;
     323              : 
     324         2220 :     case CALL_EXPR:
     325         2220 :       maybe_warn_nodiscard (expr, implicit);
     326         2220 :       break;
     327              : 
     328            0 :     case INDIRECT_REF:
     329            0 :       {
     330            0 :         tree type = TREE_TYPE (expr);
     331            0 :         int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
     332            0 :         int is_volatile = TYPE_VOLATILE (type);
     333            0 :         int is_complete = COMPLETE_TYPE_P (type);
     334              : 
     335              :         /* Can't load the value if we don't know the type.  */
     336            0 :         if (is_volatile && !is_complete)
     337              :           {
     338            0 :             switch (implicit)
     339              :               {
     340            0 :               case ICV_CAST:
     341            0 :                 warning_at (loc, 0,
     342              :                             "conversion to void will not access "
     343              :                             "object of incomplete type %qT",
     344              :                             type);
     345            0 :                 break;
     346            0 :               case ICV_SECOND_OF_COND:
     347            0 :                 warning_at (loc, 0,
     348              :                             "indirection will not access object of "
     349              :                             "incomplete type %qT in second operand "
     350              :                             "of conditional expression",
     351              :                             type);
     352            0 :                 break;
     353            0 :               case ICV_THIRD_OF_COND:
     354            0 :                 warning_at (loc, 0,
     355              :                             "indirection will not access object of "
     356              :                             "incomplete type %qT in third operand "
     357              :                             "of conditional expression",
     358              :                             type);
     359            0 :                 break;
     360            0 :               case ICV_RIGHT_OF_COMMA:
     361            0 :                 warning_at (loc, 0,
     362              :                             "indirection will not access object of "
     363              :                             "incomplete type %qT in right operand of "
     364              :                             "comma operator",
     365              :                             type);
     366            0 :                 break;
     367            0 :               case ICV_LEFT_OF_COMMA:
     368            0 :                 warning_at (loc, 0,
     369              :                             "indirection will not access object of "
     370              :                             "incomplete type %qT in left operand of "
     371              :                             "comma operator",
     372              :                             type);
     373            0 :                 break;
     374            0 :               case ICV_STATEMENT:
     375            0 :                 warning_at (loc, 0,
     376              :                             "indirection will not access object of "
     377              :                             "incomplete type %qT in statement",
     378              :                             type);
     379            0 :                 break;
     380            0 :               case ICV_THIRD_IN_FOR:
     381            0 :                 warning_at (loc, 0,
     382              :                             "indirection will not access object of "
     383              :                             "incomplete type %qT in for increment "
     384              :                             "expression",
     385              :                             type);
     386            0 :                 break;
     387            0 :               default:
     388            0 :                 rust_unreachable ();
     389              :               }
     390              :           }
     391              :         /* Don't load the value if this is an implicit dereference, or if
     392              :            the type needs to be handled by ctors/dtors.  */
     393            0 :         else if (is_volatile && is_reference)
     394              :           {
     395            0 :             switch (implicit)
     396              :               {
     397            0 :               case ICV_CAST:
     398            0 :                 warning_at (loc, 0,
     399              :                             "conversion to void will not access "
     400              :                             "object of type %qT",
     401              :                             type);
     402            0 :                 break;
     403            0 :               case ICV_SECOND_OF_COND:
     404            0 :                 warning_at (loc, 0,
     405              :                             "implicit dereference will not access "
     406              :                             "object of type %qT in second operand of "
     407              :                             "conditional expression",
     408              :                             type);
     409            0 :                 break;
     410            0 :               case ICV_THIRD_OF_COND:
     411            0 :                 warning_at (loc, 0,
     412              :                             "implicit dereference will not access "
     413              :                             "object of type %qT in third operand of "
     414              :                             "conditional expression",
     415              :                             type);
     416            0 :                 break;
     417            0 :               case ICV_RIGHT_OF_COMMA:
     418            0 :                 warning_at (loc, 0,
     419              :                             "implicit dereference will not access "
     420              :                             "object of type %qT in right operand of "
     421              :                             "comma operator",
     422              :                             type);
     423            0 :                 break;
     424            0 :               case ICV_LEFT_OF_COMMA:
     425            0 :                 warning_at (loc, 0,
     426              :                             "implicit dereference will not access "
     427              :                             "object of type %qT in left operand of comma "
     428              :                             "operator",
     429              :                             type);
     430            0 :                 break;
     431            0 :               case ICV_STATEMENT:
     432            0 :                 warning_at (loc, 0,
     433              :                             "implicit dereference will not access "
     434              :                             "object of type %qT in statement",
     435              :                             type);
     436            0 :                 break;
     437            0 :               case ICV_THIRD_IN_FOR:
     438            0 :                 warning_at (loc, 0,
     439              :                             "implicit dereference will not access "
     440              :                             "object of type %qT in for increment expression",
     441              :                             type);
     442            0 :                 break;
     443            0 :               default:
     444            0 :                 rust_unreachable ();
     445              :               }
     446              :           }
     447            0 :         else if (is_volatile && TREE_ADDRESSABLE (type))
     448              :           {
     449            0 :             switch (implicit)
     450              :               {
     451            0 :               case ICV_CAST:
     452            0 :                 warning_at (loc, 0,
     453              :                             "conversion to void will not access "
     454              :                             "object of non-trivially-copyable type %qT",
     455              :                             type);
     456            0 :                 break;
     457            0 :               case ICV_SECOND_OF_COND:
     458            0 :                 warning_at (loc, 0,
     459              :                             "indirection will not access object of "
     460              :                             "non-trivially-copyable type %qT in second "
     461              :                             "operand of conditional expression",
     462              :                             type);
     463            0 :                 break;
     464            0 :               case ICV_THIRD_OF_COND:
     465            0 :                 warning_at (loc, 0,
     466              :                             "indirection will not access object of "
     467              :                             "non-trivially-copyable type %qT in third "
     468              :                             "operand of conditional expression",
     469              :                             type);
     470            0 :                 break;
     471            0 :               case ICV_RIGHT_OF_COMMA:
     472            0 :                 warning_at (loc, 0,
     473              :                             "indirection will not access object of "
     474              :                             "non-trivially-copyable type %qT in right "
     475              :                             "operand of comma operator",
     476              :                             type);
     477            0 :                 break;
     478            0 :               case ICV_LEFT_OF_COMMA:
     479            0 :                 warning_at (loc, 0,
     480              :                             "indirection will not access object of "
     481              :                             "non-trivially-copyable type %qT in left "
     482              :                             "operand of comma operator",
     483              :                             type);
     484            0 :                 break;
     485            0 :               case ICV_STATEMENT:
     486            0 :                 warning_at (loc, 0,
     487              :                             "indirection will not access object of "
     488              :                             "non-trivially-copyable type %qT in statement",
     489              :                             type);
     490            0 :                 break;
     491            0 :               case ICV_THIRD_IN_FOR:
     492            0 :                 warning_at (loc, 0,
     493              :                             "indirection will not access object of "
     494              :                             "non-trivially-copyable type %qT in for "
     495              :                             "increment expression",
     496              :                             type);
     497            0 :                 break;
     498            0 :               default:
     499            0 :                 rust_unreachable ();
     500              :               }
     501              :           }
     502            0 :         if (is_reference || !is_volatile || !is_complete
     503            0 :             || TREE_ADDRESSABLE (type))
     504              :           {
     505              :             /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
     506              :                operation is stripped off. Note that we don't warn about
     507              :                - an expression with TREE_NO_WARNING set. (For an example of
     508              :                  such expressions, see build_over_call in call.cc.)
     509              :                - automatic dereferencing of references, since the user cannot
     510              :                  control it. (See also warn_if_unused_value() in c-common.cc.)
     511              :              */
     512            0 :             if (warn_unused_value && implicit != ICV_CAST
     513            0 :                 && !warning_suppressed_p (expr, OPT_Wunused_value)
     514            0 :                 && !is_reference)
     515            0 :               warning_at (loc, OPT_Wunused_value, "value computed is not used");
     516            0 :             expr = TREE_OPERAND (expr, 0);
     517            0 :             if (TREE_CODE (expr) == CALL_EXPR)
     518            0 :               maybe_warn_nodiscard (expr, implicit);
     519              :           }
     520              : 
     521              :         break;
     522              :       }
     523              : 
     524         1247 :     case VAR_DECL:
     525         1247 :       {
     526              :         /* External variables might be incomplete.  */
     527         1247 :         tree type = TREE_TYPE (expr);
     528         1247 :         int is_complete = COMPLETE_TYPE_P (type);
     529              : 
     530         1247 :         if (TYPE_VOLATILE (type) && !is_complete)
     531            0 :           switch (implicit)
     532              :             {
     533            0 :             case ICV_CAST:
     534            0 :               warning_at (loc, 0,
     535              :                           "conversion to void will not access "
     536              :                           "object %qE of incomplete type %qT",
     537              :                           expr, type);
     538            0 :               break;
     539            0 :             case ICV_SECOND_OF_COND:
     540            0 :               warning_at (loc, 0,
     541              :                           "variable %qE of incomplete type %qT will "
     542              :                           "not be accessed in second operand of "
     543              :                           "conditional expression",
     544              :                           expr, type);
     545            0 :               break;
     546            0 :             case ICV_THIRD_OF_COND:
     547            0 :               warning_at (loc, 0,
     548              :                           "variable %qE of incomplete type %qT will "
     549              :                           "not be accessed in third operand of "
     550              :                           "conditional expression",
     551              :                           expr, type);
     552            0 :               break;
     553            0 :             case ICV_RIGHT_OF_COMMA:
     554            0 :               warning_at (loc, 0,
     555              :                           "variable %qE of incomplete type %qT will "
     556              :                           "not be accessed in right operand of comma operator",
     557              :                           expr, type);
     558            0 :               break;
     559            0 :             case ICV_LEFT_OF_COMMA:
     560            0 :               warning_at (loc, 0,
     561              :                           "variable %qE of incomplete type %qT will "
     562              :                           "not be accessed in left operand of comma operator",
     563              :                           expr, type);
     564            0 :               break;
     565            0 :             case ICV_STATEMENT:
     566            0 :               warning_at (loc, 0,
     567              :                           "variable %qE of incomplete type %qT will "
     568              :                           "not be accessed in statement",
     569              :                           expr, type);
     570            0 :               break;
     571            0 :             case ICV_THIRD_IN_FOR:
     572            0 :               warning_at (loc, 0,
     573              :                           "variable %qE of incomplete type %qT will "
     574              :                           "not be accessed in for increment expression",
     575              :                           expr, type);
     576            0 :               break;
     577            0 :             default:
     578            0 :               rust_unreachable ();
     579              :             }
     580              : 
     581              :         break;
     582              :       }
     583              : 
     584         7839 :     default:;
     585              :     }
     586              : 
     587         7839 :   if (!TREE_SIDE_EFFECTS (expr))
     588         5618 :     expr = void_node;
     589              : 
     590              :   return expr;
     591              : }
     592              : 
     593              : void
     594         2220 : maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
     595              : {
     596         2220 :   tree call = expr;
     597         2220 :   if (TREE_CODE (expr) == TARGET_EXPR)
     598            0 :     call = TARGET_EXPR_INITIAL (expr);
     599              : 
     600         2220 :   location_t loc = expr_loc_or_input_loc (call);
     601         2220 :   tree callee = CALL_EXPR_FN (call);
     602         2220 :   if (!callee)
     603              :     return;
     604              : 
     605         2220 :   tree type = TREE_TYPE (callee);
     606         2220 :   if (INDIRECT_TYPE_P (type))
     607         2220 :     type = TREE_TYPE (type);
     608              : 
     609         2220 :   tree rettype = TREE_TYPE (type);
     610         2220 :   tree fn = get_fndecl_from_callee (callee);
     611         2220 :   tree attr;
     612         2220 :   if (implicit != ICV_CAST && fn
     613         2220 :       && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))))
     614              :     {
     615           14 :       escaped_string msg;
     616           14 :       tree args = TREE_VALUE (attr);
     617           14 :       if (args)
     618            7 :         msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
     619           14 :       const char *format
     620           14 :         = (msg ? G_ ("ignoring return value of %qD, that must be used: %qs")
     621            7 :                : G_ ("ignoring return value of %qD, that must be used"));
     622           14 :       const char *raw_msg = msg ? (const char *) msg : "";
     623           14 :       auto_diagnostic_group d;
     624           14 :       if (warning_at (loc, OPT_Wunused_result, format, fn, raw_msg))
     625           14 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
     626           14 :     }
     627         2206 :   else if (implicit != ICV_CAST
     628         2206 :            && (attr
     629         2206 :                = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))))
     630              :     {
     631            0 :       escaped_string msg;
     632            0 :       tree args = TREE_VALUE (attr);
     633            0 :       if (args)
     634            0 :         msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
     635            0 :       const char *format
     636            0 :         = (msg ? G_ (
     637              :              "ignoring returned value of type %qT, that must be used: %qs")
     638            0 :                : G_ ("ignoring returned value of type %qT, that must be used"));
     639            0 :       const char *raw_msg = msg ? (const char *) msg : "";
     640            0 :       auto_diagnostic_group d;
     641            0 :       if (warning_at (loc, OPT_Wunused_result, format, rettype, raw_msg))
     642              :         {
     643            0 :           if (fn)
     644            0 :             inform (DECL_SOURCE_LOCATION (fn), "in call to %qD, declared here",
     645              :                     fn);
     646            0 :           inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
     647              :                   "%qT declared here", rettype);
     648              :         }
     649            0 :     }
     650              : }
     651              : 
     652              : location_t
     653        12914 : expr_loc_or_loc (const_tree t, location_t or_loc)
     654              : {
     655        12914 :   location_t loc = EXPR_LOCATION (t);
     656         6782 :   if (loc == UNKNOWN_LOCATION)
     657         6132 :     loc = or_loc;
     658        12914 :   return loc;
     659              : }
     660              : 
     661              : location_t
     662        12914 : expr_loc_or_input_loc (const_tree t)
     663              : {
     664        12914 :   return expr_loc_or_loc (t, input_location);
     665              : }
     666              : 
     667              : // FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
     668              : // if we can.
     669              : tree
     670         2220 : get_fndecl_from_callee (tree fn)
     671              : {
     672         2220 :   if (fn == NULL_TREE)
     673              :     return fn;
     674         2220 :   if (TREE_CODE (fn) == FUNCTION_DECL)
     675              :     return fn;
     676         2220 :   tree type = TREE_TYPE (fn);
     677         2220 :   if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
     678              :     return NULL_TREE;
     679              : 
     680         2220 :   STRIP_NOPS (fn);
     681         2220 :   if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
     682         2082 :     fn = TREE_OPERAND (fn, 0);
     683         2220 :   if (TREE_CODE (fn) == FUNCTION_DECL)
     684              :     return fn;
     685              :   return NULL_TREE;
     686              : }
     687              : 
     688              : tree
     689          231 : pointer_offset_expression (tree base_tree, tree index_tree, location_t location)
     690              : {
     691          231 :   tree base_type_tree = TREE_TYPE (base_tree);
     692          231 :   tree element_type_tree
     693          231 :     = TREE_TYPE (base_type_tree) ? TREE_TYPE (base_type_tree) : error_mark_node;
     694          231 :   if (base_tree == error_mark_node || TREE_TYPE (base_tree) == error_mark_node
     695          462 :       || index_tree == error_mark_node || element_type_tree == error_mark_node)
     696              :     {
     697            1 :       error_at (location, "unknown element size type for %qT", base_type_tree);
     698            1 :       return error_mark_node;
     699              :     }
     700              : 
     701          230 :   tree element_size = TYPE_SIZE_UNIT (element_type_tree);
     702          230 :   index_tree = fold_convert_loc (location, sizetype, index_tree);
     703          230 :   tree offset
     704          230 :     = fold_build2_loc (location, MULT_EXPR, sizetype, index_tree, element_size);
     705              : 
     706          230 :   return fold_build2_loc (location, POINTER_PLUS_EXPR, TREE_TYPE (base_tree),
     707          230 :                           base_tree, offset);
     708              : }
     709              : 
     710              : // forked from gcc/cp/tree.cc cp_walk_subtrees
     711              : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
     712              :    traversal.  Called from walk_tree.  */
     713              : 
     714              : tree
     715            5 : rs_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, void *data,
     716              :                   hash_set<tree> *pset)
     717              : {
     718            5 :   enum tree_code code = TREE_CODE (*tp);
     719            5 :   tree result;
     720              : 
     721              : #define WALK_SUBTREE(NODE)                                                     \
     722              :   do                                                                           \
     723              :     {                                                                          \
     724              :       result = rs_walk_tree (&(NODE), func, data, pset);                       \
     725              :       if (result)                                                              \
     726              :         goto out;                                                              \
     727              :     }                                                                          \
     728              :   while (0)
     729              : 
     730            5 :   if (TYPE_P (*tp))
     731              :     {
     732              :       /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
     733              :          the argument, so don't look through typedefs, but do walk into
     734              :          template arguments for alias templates (and non-typedefed classes).
     735              : 
     736              :          If *WALK_SUBTREES_P > 1, we're interested in type identity or
     737              :          equivalence, so look through typedefs, ignoring template arguments for
     738              :          alias templates, and walk into template args of classes.
     739              : 
     740              :          See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
     741              :          when that's the behavior the walk_tree_fn wants.  */
     742            0 :       if (*walk_subtrees_p == 1 && typedef_variant_p (*tp))
     743              :         {
     744            0 :           *walk_subtrees_p = 0;
     745            0 :           return NULL_TREE;
     746              :         }
     747              :     }
     748              : 
     749              :   /* Not one of the easy cases.  We must explicitly go through the
     750              :      children.  */
     751            5 :   result = NULL_TREE;
     752            5 :   switch (code)
     753              :     {
     754            0 :     case TREE_LIST:
     755            0 :       WALK_SUBTREE (TREE_PURPOSE (*tp));
     756              :       break;
     757              : 
     758            0 :     case RECORD_TYPE:
     759            0 :       if (TYPE_PTRMEMFUNC_P (*tp))
     760            0 :         WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp));
     761              :       break;
     762              : 
     763            0 :     case CONSTRUCTOR:
     764            0 :       if (COMPOUND_LITERAL_P (*tp))
     765            0 :         WALK_SUBTREE (TREE_TYPE (*tp));
     766              :       break;
     767              : 
     768            0 :     case DECL_EXPR:
     769              :       /* User variables should be mentioned in BIND_EXPR_VARS
     770              :          and their initializers and sizes walked when walking
     771              :          the containing BIND_EXPR.  Compiler temporaries are
     772              :          handled here.  And also normal variables in templates,
     773              :          since do_poplevel doesn't build a BIND_EXPR then.  */
     774            0 :       if (VAR_P (TREE_OPERAND (*tp, 0))
     775            0 :           && (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0))
     776            0 :               && !TREE_STATIC (TREE_OPERAND (*tp, 0))))
     777              :         {
     778            0 :           tree decl = TREE_OPERAND (*tp, 0);
     779            0 :           WALK_SUBTREE (DECL_INITIAL (decl));
     780            0 :           WALK_SUBTREE (DECL_SIZE (decl));
     781            0 :           WALK_SUBTREE (DECL_SIZE_UNIT (decl));
     782              :         }
     783              :       break;
     784              : 
     785              :     default:
     786              :       return NULL_TREE;
     787              :     }
     788              : 
     789              :   /* We didn't find what we were looking for.  */
     790              : out:
     791              :   return result;
     792              : 
     793              : #undef WALK_SUBTREE
     794              : }
     795              : 
     796              : // forked from gcc/cp/tree.cc cp_expr_location
     797              : 
     798              : /* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
     799              :    locations.  */
     800              : 
     801              : location_t
     802           11 : rs_expr_location (const_tree t_)
     803              : {
     804           11 :   tree t = const_cast<tree> (t_);
     805           11 :   if (t == NULL_TREE)
     806              :     return UNKNOWN_LOCATION;
     807              : 
     808           11 :   return EXPR_LOCATION (t);
     809              : }
     810              : 
     811              : // forked from gcc/cp/class.cc is_really_empty_class
     812              : 
     813              : /* Returns true if TYPE contains no actual data, just various
     814              :    possible combinations of empty classes.  If IGNORE_VPTR is true,
     815              :    a vptr doesn't prevent the class from being considered empty.  Typically
     816              :    we want to ignore the vptr on assignment, and not on initialization.  */
     817              : 
     818              : bool
     819         1323 : is_really_empty_class (tree type, bool ignore_vptr)
     820              : {
     821         1323 :   if (CLASS_TYPE_P (type))
     822              :     {
     823            0 :       tree field;
     824            0 :       tree binfo;
     825            0 :       tree base_binfo;
     826            0 :       int i;
     827              : 
     828              :       /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
     829              :          out, but we'd like to be able to check this before then.  */
     830            0 :       if (COMPLETE_TYPE_P (type) && is_empty_class (type))
     831              :         return true;
     832              : 
     833            0 :       if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
     834              :         return false;
     835              : 
     836            0 :       for (binfo = TYPE_BINFO (type), i = 0;
     837            0 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
     838            0 :         if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
     839              :           return false;
     840            0 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     841            0 :         if (TREE_CODE (field) == FIELD_DECL
     842            0 :             && !DECL_ARTIFICIAL (field)
     843              :             /* An unnamed bit-field is not a data member.  */
     844            0 :             && !DECL_UNNAMED_BIT_FIELD (field)
     845            0 :             && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
     846              :           return false;
     847              :       return true;
     848              :     }
     849         1323 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     850            8 :     return (integer_zerop (array_type_nelts_top (type))
     851            8 :             || is_really_empty_class (TREE_TYPE (type), ignore_vptr));
     852              :   return false;
     853              : }
     854              : 
     855              : // forked from gcc/cp/class.cc is_empty_class
     856              : 
     857              : /* Returns 1 if TYPE contains only padding bytes.  */
     858              : 
     859              : int
     860            1 : is_empty_class (tree type)
     861              : {
     862            1 :   if (type == error_mark_node)
     863              :     return 0;
     864              : 
     865            1 :   if (!CLASS_TYPE_P (type))
     866              :     return 0;
     867              : 
     868            0 :   return CLASSTYPE_EMPTY_P (type);
     869              : }
     870              : 
     871              : // forked from gcc/cp/tree.cc builtin_valid_in_constant_expr_p
     872              : 
     873              : /* Test whether DECL is a builtin that may appear in a
     874              :    constant-expression. */
     875              : 
     876              : bool
     877            0 : builtin_valid_in_constant_expr_p (const_tree decl)
     878              : {
     879            0 :   STRIP_ANY_LOCATION_WRAPPER (decl);
     880            0 :   if (TREE_CODE (decl) != FUNCTION_DECL)
     881              :     /* Not a function.  */
     882              :     return false;
     883            0 :   if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
     884              :     {
     885            0 :       if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
     886            0 :         switch (DECL_FE_FUNCTION_CODE (decl))
     887              :           {
     888              :           case RS_BUILT_IN_IS_CONSTANT_EVALUATED:
     889              :           case RS_BUILT_IN_SOURCE_LOCATION:
     890              :           case RS_BUILT_IN_IS_CORRESPONDING_MEMBER:
     891              :           case RS_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
     892              :             return true;
     893              :           default:
     894              :             break;
     895              :           }
     896              :       /* Not a built-in.  */
     897              :       return false;
     898              :     }
     899            0 :   switch (DECL_FUNCTION_CODE (decl))
     900              :     {
     901              :       /* These always have constant results like the corresponding
     902              :          macros/symbol.  */
     903              :     case BUILT_IN_FILE:
     904              :     case BUILT_IN_FUNCTION:
     905              :     case BUILT_IN_LINE:
     906              : 
     907              :       /* The following built-ins are valid in constant expressions
     908              :          when their arguments are.  */
     909              :     case BUILT_IN_ADD_OVERFLOW_P:
     910              :     case BUILT_IN_SUB_OVERFLOW_P:
     911              :     case BUILT_IN_MUL_OVERFLOW_P:
     912              : 
     913              :       /* These have constant results even if their operands are
     914              :          non-constant.  */
     915              :     case BUILT_IN_CONSTANT_P:
     916              :     case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
     917              :       return true;
     918              :     default:
     919              :       return false;
     920              :     }
     921              : }
     922              : 
     923              : // forked from gcc/cp/decl2.cc decl_maybe_constant_var_p
     924              : 
     925              : /* Returns true if DECL could be a symbolic constant variable, depending on
     926              :    its initializer.  */
     927              : 
     928              : bool
     929            0 : decl_maybe_constant_var_p (tree decl)
     930              : {
     931            0 :   tree type = TREE_TYPE (decl);
     932            0 :   if (!VAR_P (decl))
     933              :     return false;
     934            0 :   if (DECL_DECLARED_CONSTEXPR_P (decl))
     935              :     return true;
     936            0 :   if (DECL_HAS_VALUE_EXPR_P (decl))
     937              :     /* A proxy isn't constant.  */
     938              :     return false;
     939            0 :   if (TYPE_REF_P (type))
     940              :     /* References can be constant.  */;
     941            0 :   else if (RS_TYPE_CONST_NON_VOLATILE_P (type)
     942            0 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     943              :     /* And const integers.  */;
     944              :   else
     945              :     return false;
     946              : 
     947            0 :   if (DECL_INITIAL (decl) && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
     948              :     /* We know the initializer, and it isn't constant.  */
     949              :     return false;
     950              :   else
     951              :     return true;
     952              : }
     953              : 
     954              : // forked from gcc/cp/typeck.cc cp_type_quals
     955              : 
     956              : /* Returns the type qualifiers for this type, including the qualifiers on the
     957              :    elements for an array type.  */
     958              : 
     959              : int
     960           30 : rs_type_quals (const_tree type)
     961              : {
     962           30 :   int quals;
     963              :   /* This CONST_CAST is okay because strip_array_types returns its
     964              :      argument unmodified and we assign it to a const_tree.  */
     965           30 :   type = strip_array_types (const_cast<tree> (type));
     966           30 :   if (type == error_mark_node
     967              :       /* Quals on a FUNCTION_TYPE are memfn quals.  */
     968           30 :       || TREE_CODE (type) == FUNCTION_TYPE)
     969              :     return TYPE_UNQUALIFIED;
     970           30 :   quals = TYPE_QUALS (type);
     971              :   /* METHOD and REFERENCE_TYPEs should never have quals.  */
     972              :   // gcc_assert (
     973              :   //   (TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
     974              :   //   || ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) ==
     975              :   //   TYPE_UNQUALIFIED));
     976           30 :   return quals;
     977              : }
     978              : 
     979              : // forked from gcc/cp/decl.cc cp_global_trees
     980              : 
     981              : /* The following symbols are subsumed in the cp_global_trees array, and
     982              :    listed here individually for documentation purposes.
     983              : 
     984              :    C++ extensions
     985              :         tree wchar_decl_node;
     986              : 
     987              :         tree vtable_entry_type;
     988              :         tree delta_type_node;
     989              :         tree __t_desc_type_node;
     990              : 
     991              :         tree class_type_node;
     992              :         tree unknown_type_node;
     993              : 
     994              :    Array type `vtable_entry_type[]'
     995              : 
     996              :         tree vtbl_type_node;
     997              :         tree vtbl_ptr_type_node;
     998              : 
     999              :    Namespaces,
    1000              : 
    1001              :         tree std_node;
    1002              :         tree abi_node;
    1003              : 
    1004              :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
    1005              :    one that the user will declare, but sufficient to be called
    1006              :    by routines that want to abort the program.
    1007              : 
    1008              :         tree abort_fndecl;
    1009              : 
    1010              :    Used by RTTI
    1011              :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
    1012              :         tree tinfo_var_id;  */
    1013              : 
    1014              : /* The following symbols are subsumed in the c_global_trees array, and
    1015              :    listed here individually for documentation purposes.
    1016              : 
    1017              :    INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
    1018              : 
    1019              :         tree short_integer_type_node;
    1020              :         tree long_integer_type_node;
    1021              :         tree long_long_integer_type_node;
    1022              : 
    1023              :         tree short_unsigned_type_node;
    1024              :         tree long_unsigned_type_node;
    1025              :         tree long_long_unsigned_type_node;
    1026              : 
    1027              :         tree truthvalue_type_node;
    1028              :         tree truthvalue_false_node;
    1029              :         tree truthvalue_true_node;
    1030              : 
    1031              :         tree ptrdiff_type_node;
    1032              : 
    1033              :         tree unsigned_char_type_node;
    1034              :         tree signed_char_type_node;
    1035              :         tree wchar_type_node;
    1036              : 
    1037              :         tree char8_type_node;
    1038              :         tree char16_type_node;
    1039              :         tree char32_type_node;
    1040              : 
    1041              :         tree float_type_node;
    1042              :         tree double_type_node;
    1043              :         tree long_double_type_node;
    1044              : 
    1045              :         tree complex_integer_type_node;
    1046              :         tree complex_float_type_node;
    1047              :         tree complex_double_type_node;
    1048              :         tree complex_long_double_type_node;
    1049              : 
    1050              :         tree dfloat32_type_node;
    1051              :         tree dfloat64_type_node;
    1052              :         tree_dfloat128_type_node;
    1053              : 
    1054              :         tree intQI_type_node;
    1055              :         tree intHI_type_node;
    1056              :         tree intSI_type_node;
    1057              :         tree intDI_type_node;
    1058              :         tree intTI_type_node;
    1059              : 
    1060              :         tree unsigned_intQI_type_node;
    1061              :         tree unsigned_intHI_type_node;
    1062              :         tree unsigned_intSI_type_node;
    1063              :         tree unsigned_intDI_type_node;
    1064              :         tree unsigned_intTI_type_node;
    1065              : 
    1066              :         tree widest_integer_literal_type_node;
    1067              :         tree widest_unsigned_literal_type_node;
    1068              : 
    1069              :    Nodes for types `void *' and `const void *'.
    1070              : 
    1071              :         tree ptr_type_node, const_ptr_type_node;
    1072              : 
    1073              :    Nodes for types `char *' and `const char *'.
    1074              : 
    1075              :         tree string_type_node, const_string_type_node;
    1076              : 
    1077              :    Type `char[SOMENUMBER]'.
    1078              :    Used when an array of char is needed and the size is irrelevant.
    1079              : 
    1080              :         tree char_array_type_node;
    1081              : 
    1082              :    Type `wchar_t[SOMENUMBER]' or something like it.
    1083              :    Used when a wide string literal is created.
    1084              : 
    1085              :         tree wchar_array_type_node;
    1086              : 
    1087              :    Type `char8_t[SOMENUMBER]' or something like it.
    1088              :    Used when a UTF-8 string literal is created.
    1089              : 
    1090              :         tree char8_array_type_node;
    1091              : 
    1092              :    Type `char16_t[SOMENUMBER]' or something like it.
    1093              :    Used when a UTF-16 string literal is created.
    1094              : 
    1095              :         tree char16_array_type_node;
    1096              : 
    1097              :    Type `char32_t[SOMENUMBER]' or something like it.
    1098              :    Used when a UTF-32 string literal is created.
    1099              : 
    1100              :         tree char32_array_type_node;
    1101              : 
    1102              :    Type `int ()' -- used for implicit declaration of functions.
    1103              : 
    1104              :         tree default_function_type;
    1105              : 
    1106              :    A VOID_TYPE node, packaged in a TREE_LIST.
    1107              : 
    1108              :         tree void_list_node;
    1109              : 
    1110              :   The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
    1111              :   and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
    1112              :   VAR_DECLS, but C++ does.)
    1113              : 
    1114              :         tree function_name_decl_node;
    1115              :         tree pretty_function_name_decl_node;
    1116              :         tree c99_function_name_decl_node;
    1117              : 
    1118              :   Stack of nested function name VAR_DECLs.
    1119              : 
    1120              :         tree saved_function_name_decls;
    1121              : 
    1122              : */
    1123              : 
    1124              : // forked from gcc/cp/module.cc fixed_trees
    1125              : 
    1126              : static GTY (()) vec<tree, va_gc> *fixed_trees;
    1127              : 
    1128              : // forked from gcc/cp/module.cc maybe_add_global
    1129              : 
    1130              : /* VAL is a global tree, add it to the global vec if it is
    1131              :    interesting.  Add some of its targets, if they too are
    1132              :    interesting.  We do not add identifiers, as they can be re-found
    1133              :    via the identifier hash table.  There is a cost to the number of
    1134              :    global trees.  */
    1135              : 
    1136              : static int
    1137            0 : maybe_add_global (tree val, unsigned &crc)
    1138              : {
    1139            0 :   int v = 0;
    1140              : 
    1141            0 :   if (val && !(TREE_CODE (val) == IDENTIFIER_NODE || TREE_VISITED (val)))
    1142              :     {
    1143            0 :       TREE_VISITED (val) = true;
    1144            0 :       crc = crc32_unsigned (crc, fixed_trees->length ());
    1145            0 :       vec_safe_push (fixed_trees, val);
    1146            0 :       v++;
    1147              : 
    1148            0 :       if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPED))
    1149            0 :         v += maybe_add_global (TREE_TYPE (val), crc);
    1150            0 :       if (CODE_CONTAINS_STRUCT (TREE_CODE (val), TS_TYPE_COMMON))
    1151            0 :         v += maybe_add_global (TYPE_NAME (val), crc);
    1152              :     }
    1153              : 
    1154            0 :   return v;
    1155              : }
    1156              : 
    1157              : // forked from gcc/cp/module.cc global_tree_arys
    1158              : 
    1159              : /* Global trees.  */
    1160              : static const std::pair<tree *, unsigned> global_tree_arys[] = {
    1161              :   std::pair<tree *, unsigned> (cp_global_trees, CPTI_MODULE_HWM),
    1162              :   std::pair<tree *, unsigned> (c_global_trees, CTI_MODULE_HWM),
    1163              : };
    1164              : 
    1165              : // forked from gcc/cp/module.cc init_modules
    1166              : 
    1167              : void
    1168            0 : init_modules ()
    1169              : {
    1170            0 :   unsigned crc = 0;
    1171            0 :   vec_alloc (fixed_trees, 200);
    1172              : 
    1173            0 :   const tree *ptr = global_tree_arys[0].first;
    1174            0 :   unsigned limit = global_tree_arys[0].second;
    1175            0 :   for (unsigned ix = 0; ix != limit; ix++, ptr++)
    1176              :     {
    1177            0 :       maybe_add_global (*ptr, crc);
    1178              :     }
    1179              : 
    1180              :   ptr = global_tree_arys[1].first;
    1181            0 :   limit = global_tree_arys[1].second;
    1182            0 :   for (unsigned ix = 0; ix != limit; ix++, ptr++)
    1183              :     {
    1184            0 :       maybe_add_global (*ptr, crc);
    1185              :     }
    1186            0 : }
    1187              : 
    1188              : // forked from gcc/cp/constexpr.cc var_in_constexpr_fn
    1189              : 
    1190              : /* True if T was declared in a function declared to be constexpr, and
    1191              :    therefore potentially constant in C++14.  */
    1192              : 
    1193              : bool
    1194            0 : var_in_constexpr_fn (tree t)
    1195              : {
    1196            0 :   tree ctx = DECL_CONTEXT (t);
    1197            0 :   return (ctx && TREE_CODE (ctx) == FUNCTION_DECL
    1198            0 :           && DECL_DECLARED_CONSTEXPR_P (ctx));
    1199              : }
    1200              : 
    1201              : // forked from gcc/cp/name-lookup.cc member_vec_linear_search
    1202              : 
    1203              : /* Linear search of (unordered) MEMBER_VEC for NAME.  */
    1204              : 
    1205              : static tree
    1206            0 : member_vec_linear_search (vec<tree, va_gc> *member_vec, tree name)
    1207              : {
    1208            0 :   for (int ix = member_vec->length (); ix--;)
    1209            0 :     if (tree binding = (*member_vec)[ix])
    1210            0 :       if (OVL_NAME (binding) == name)
    1211              :         return binding;
    1212              : 
    1213              :   return NULL_TREE;
    1214              : }
    1215              : 
    1216              : // forked from gcc/cp/name-lookup.cc member_vec_binary_search
    1217              : 
    1218              : /* Binary search of (ordered) MEMBER_VEC for NAME.  */
    1219              : 
    1220              : static tree
    1221            0 : member_vec_binary_search (vec<tree, va_gc> *member_vec, tree name)
    1222              : {
    1223            0 :   for (unsigned lo = 0, hi = member_vec->length (); lo < hi;)
    1224              :     {
    1225            0 :       unsigned mid = (lo + hi) / 2;
    1226            0 :       tree binding = (*member_vec)[mid];
    1227            0 :       tree binding_name = OVL_NAME (binding);
    1228              : 
    1229            0 :       if (binding_name > name)
    1230              :         hi = mid;
    1231            0 :       else if (binding_name < name)
    1232            0 :         lo = mid + 1;
    1233              :       else
    1234              :         return binding;
    1235              :     }
    1236              : 
    1237              :   return NULL_TREE;
    1238              : }
    1239              : 
    1240              : // forked from gcc/cp/tree.cc is_overloaded_fn
    1241              : 
    1242              : /* Returns nonzero if X is an expression for a (possibly overloaded)
    1243              :    function.  If "f" is a function or function template, "f", "c->f",
    1244              :    "c.f", "C::f", and "f<int>" will all be considered possibly
    1245              :    overloaded functions.  Returns 2 if the function is actually
    1246              :    overloaded, i.e., if it is impossible to know the type of the
    1247              :    function without performing overload resolution.  */
    1248              : 
    1249              : int
    1250            5 : is_overloaded_fn (tree x)
    1251              : {
    1252            5 :   STRIP_ANY_LOCATION_WRAPPER (x);
    1253              : 
    1254            5 :   if (TREE_CODE (x) == COMPONENT_REF)
    1255            5 :     x = TREE_OPERAND (x, 1);
    1256              : 
    1257            5 :   return OVL_P (x);
    1258              : }
    1259              : 
    1260              : // forked from gcc/cp/tree.cc ovl_make
    1261              : 
    1262              : /* Make a raw overload node containing FN.  */
    1263              : 
    1264              : tree
    1265            0 : ovl_make (tree fn, tree next)
    1266              : {
    1267            0 :   tree result = make_node (OVERLOAD);
    1268              : 
    1269            0 :   if (TREE_CODE (fn) == OVERLOAD)
    1270            0 :     OVL_NESTED_P (result) = true;
    1271              : 
    1272            0 :   TREE_TYPE (result) = (next ? unknown_type_node : TREE_TYPE (fn));
    1273            0 :   if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
    1274            0 :     OVL_DEDUP_P (result) = true;
    1275            0 :   OVL_FUNCTION (result) = fn;
    1276            0 :   OVL_CHAIN (result) = next;
    1277            0 :   return result;
    1278              : }
    1279              : 
    1280              : // forked from gcc/cp/name-lookup.cc lookup_add
    1281              : 
    1282              : /* Add a set of new FNS into a lookup.  */
    1283              : 
    1284              : tree
    1285            0 : lookup_add (tree fns, tree lookup)
    1286              : {
    1287            0 :   if (fns == error_mark_node || lookup == error_mark_node)
    1288            0 :     return error_mark_node;
    1289              : 
    1290            0 :   lookup = fns;
    1291              : 
    1292              :   return lookup;
    1293              : }
    1294              : 
    1295              : // forked from gcc/cp/typeck.cc type_memfn_quals
    1296              : 
    1297              : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
    1298              :    METHOD_TYPE.  */
    1299              : 
    1300              : int
    1301            0 : type_memfn_quals (const_tree type)
    1302              : {
    1303            0 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    1304            0 :     return TYPE_QUALS (type);
    1305            0 :   else if (TREE_CODE (type) == METHOD_TYPE)
    1306            0 :     return rs_type_quals (class_of_this_parm (type));
    1307              :   else
    1308            0 :     rust_unreachable ();
    1309              : }
    1310              : 
    1311              : // forked from gcc/cp/pt.cc find_parameter_pack_data
    1312              : 
    1313              : /* Structure used to track the progress of find_parameter_packs_r.  */
    1314              : struct find_parameter_pack_data
    1315              : {
    1316              :   /* TREE_LIST that will contain all of the parameter packs found by
    1317              :      the traversal.  */
    1318              :   tree *parameter_packs;
    1319              : 
    1320              :   /* Set of AST nodes that have been visited by the traversal.  */
    1321              :   hash_set<tree> *visited;
    1322              : 
    1323              :   /* True iff we're making a type pack expansion.  */
    1324              :   bool type_pack_expansion_p;
    1325              : 
    1326              :   /* True iff we found a subtree that has the extra args mechanism.  */
    1327              :   bool found_extra_args_tree_p = false;
    1328              : };
    1329              : 
    1330              : // forked from gcc/cp/lex.cc conv_type_hasher
    1331              : 
    1332              : /* Hasher for the conversion operator name hash table.  */
    1333              : struct rust_conv_type_hasher : ggc_ptr_hash<tree_node>
    1334              : {
    1335              :   /* Hash NODE, an identifier node in the table.  TYPE_UID is
    1336              :      suitable, as we're not concerned about matching canonicalness
    1337              :      here.  */
    1338            0 :   static hashval_t hash (tree node)
    1339              :   {
    1340            0 :     return (hashval_t) TYPE_UID (TREE_TYPE (node));
    1341              :   }
    1342              : 
    1343              :   /* Compare NODE, an identifier node in the table, against TYPE, an
    1344              :      incoming TYPE being looked up.  */
    1345            0 :   static bool equal (tree node, tree type) { return TREE_TYPE (node) == type; }
    1346              : };
    1347              : 
    1348              : static GTY (()) hash_table<rust_conv_type_hasher> *conv_type_names;
    1349              : 
    1350              : // forked from gcc/cp/lex.cc make_conv_op_name
    1351              : 
    1352              : /* Return an identifier for a conversion operator to TYPE.  We can get
    1353              :    from the returned identifier to the type.  We store TYPE, which is
    1354              :    not necessarily the canonical type,  which allows us to report the
    1355              :    form the user used in error messages.  All these identifiers are
    1356              :    not in the identifier hash table, and have the same string name.
    1357              :    These IDENTIFIERS are not in the identifier hash table, and all
    1358              :    have the same IDENTIFIER_STRING.  */
    1359              : 
    1360              : tree
    1361            0 : make_conv_op_name (tree type)
    1362              : {
    1363            0 :   if (type == error_mark_node)
    1364              :     return error_mark_node;
    1365              : 
    1366            0 :   if (conv_type_names == NULL)
    1367            0 :     conv_type_names = hash_table<rust_conv_type_hasher>::create_ggc (31);
    1368              : 
    1369            0 :   tree *slot
    1370            0 :     = conv_type_names->find_slot_with_hash (type, (hashval_t) TYPE_UID (type),
    1371              :                                             INSERT);
    1372            0 :   tree identifier = *slot;
    1373            0 :   if (!identifier)
    1374              :     {
    1375              :       /* Create a raw IDENTIFIER outside of the identifier hash
    1376              :          table.  */
    1377            0 :       identifier = copy_node (conv_op_identifier);
    1378              : 
    1379              :       /* Just in case something managed to bind.  */
    1380            0 :       IDENTIFIER_BINDING (identifier) = NULL;
    1381              : 
    1382              :       /* Hang TYPE off the identifier so it can be found easily later
    1383              :          when performing conversions.  */
    1384            0 :       TREE_TYPE (identifier) = type;
    1385              : 
    1386            0 :       *slot = identifier;
    1387              :     }
    1388              : 
    1389              :   return identifier;
    1390              : }
    1391              : 
    1392              : // forked from gcc/cp/pt.cc builtin_pack_fn_p
    1393              : 
    1394              : /* True iff FN is a function representing a built-in variadic parameter
    1395              :    pack.  */
    1396              : 
    1397              : bool
    1398            0 : builtin_pack_fn_p (tree fn)
    1399              : {
    1400            0 :   if (!fn || TREE_CODE (fn) != FUNCTION_DECL
    1401            0 :       || !DECL_IS_UNDECLARED_BUILTIN (fn))
    1402              :     return false;
    1403              : 
    1404            0 :   if (id_equal (DECL_NAME (fn), "__integer_pack"))
    1405              :     return true;
    1406              : 
    1407              :   return false;
    1408              : }
    1409              : 
    1410              : // forked from gcc/cp/pt.cc builtin_pack_call_p
    1411              : 
    1412              : /* True iff CALL is a call to a function representing a built-in variadic
    1413              :    parameter pack.  */
    1414              : 
    1415              : static bool
    1416            0 : builtin_pack_call_p (tree call)
    1417              : {
    1418            0 :   if (TREE_CODE (call) != CALL_EXPR)
    1419              :     return false;
    1420            0 :   return builtin_pack_fn_p (CALL_EXPR_FN (call));
    1421              : }
    1422              : 
    1423              : //// forked from gcc/cp/pt.cc has_extra_args_mechanism_p
    1424              : //
    1425              : ///* Return true if the tree T has the extra args mechanism for
    1426              : //   avoiding partial instantiation.  */
    1427              : //
    1428              : // static bool
    1429              : // has_extra_args_mechanism_p (const_tree t)
    1430              : //{
    1431              : //  return false;
    1432              : //}
    1433              : 
    1434              : // forked from gcc/cp/pt.cc find_parameter_packs_r
    1435              : 
    1436              : /* Identifies all of the argument packs that occur in a template
    1437              :    argument and appends them to the TREE_LIST inside DATA, which is a
    1438              :    find_parameter_pack_data structure. This is a subroutine of
    1439              :    make_pack_expansion and uses_parameter_packs.  */
    1440              : static tree
    1441            0 : find_parameter_packs_r (tree *tp, int *walk_subtrees, void *data)
    1442              : {
    1443            0 :   tree t = *tp;
    1444            0 :   struct find_parameter_pack_data *ppd
    1445              :     = (struct find_parameter_pack_data *) data;
    1446            0 :   bool parameter_pack_p = false;
    1447              : 
    1448              : #define WALK_SUBTREE(NODE)                                                     \
    1449              :   rs_walk_tree (&(NODE), &find_parameter_packs_r, ppd, ppd->visited)
    1450              : 
    1451              :   /* Don't look through typedefs; we are interested in whether a
    1452              :      parameter pack is actually written in the expression/type we're
    1453              :      looking at, not the target type.  */
    1454            0 :   if (TYPE_P (t) && typedef_variant_p (t))
    1455              :     {
    1456            0 :       *walk_subtrees = 0;
    1457            0 :       return NULL_TREE;
    1458              :     }
    1459              : 
    1460              :   /* Identify whether this is a parameter pack or not.  */
    1461            0 :   switch (TREE_CODE (t))
    1462              :     {
    1463              :     case FIELD_DECL:
    1464              :     case PARM_DECL:
    1465              :       break;
    1466              : 
    1467              :     case VAR_DECL:
    1468              :       break;
    1469              : 
    1470            0 :     case CALL_EXPR:
    1471            0 :       if (builtin_pack_call_p (t))
    1472              :         parameter_pack_p = true;
    1473              :       break;
    1474              : 
    1475              :     case BASES:
    1476              :       parameter_pack_p = true;
    1477              :       break;
    1478              :     default:
    1479              :       /* Not a parameter pack.  */
    1480              :       break;
    1481              :     }
    1482              : 
    1483              :   if (parameter_pack_p)
    1484              :     {
    1485              :       /* Add this parameter pack to the list.  */
    1486            0 :       *ppd->parameter_packs = tree_cons (NULL_TREE, t, *ppd->parameter_packs);
    1487              :     }
    1488              : 
    1489            0 :   if (TYPE_P (t))
    1490            0 :     rs_walk_tree (&TYPE_CONTEXT (t), &find_parameter_packs_r, ppd,
    1491              :                   ppd->visited);
    1492              : 
    1493              :   /* This switch statement will return immediately if we don't find a
    1494              :      parameter pack.  ??? Should some of these be in cp_walk_subtrees?  */
    1495            0 :   switch (TREE_CODE (t))
    1496              :     {
    1497            0 :     case DECL_EXPR:
    1498            0 :       {
    1499            0 :         tree decl = DECL_EXPR_DECL (t);
    1500            0 :         if (is_typedef_decl (decl))
    1501              :           /* Since we stop at typedefs above, we need to look through them at
    1502              :              the point of the DECL_EXPR.  */
    1503            0 :           rs_walk_tree (&DECL_ORIGINAL_TYPE (decl), &find_parameter_packs_r,
    1504              :                         ppd, ppd->visited);
    1505              :         return NULL_TREE;
    1506              :       }
    1507              : 
    1508            0 :     case INTEGER_TYPE:
    1509            0 :       rs_walk_tree (&TYPE_MAX_VALUE (t), &find_parameter_packs_r, ppd,
    1510              :                     ppd->visited);
    1511            0 :       *walk_subtrees = 0;
    1512            0 :       return NULL_TREE;
    1513              : 
    1514            0 :     case IDENTIFIER_NODE:
    1515            0 :       rs_walk_tree (&TREE_TYPE (t), &find_parameter_packs_r, ppd, ppd->visited);
    1516            0 :       *walk_subtrees = 0;
    1517            0 :       return NULL_TREE;
    1518              : 
    1519            0 :     case DECLTYPE_TYPE:
    1520            0 :       {
    1521              :         /* When traversing a DECLTYPE_TYPE_EXPR, we need to set
    1522              :            type_pack_expansion_p to false so that any placeholders
    1523              :            within the expression don't get marked as parameter packs.  */
    1524            0 :         bool type_pack_expansion_p = ppd->type_pack_expansion_p;
    1525            0 :         ppd->type_pack_expansion_p = false;
    1526            0 :         rs_walk_tree (&DECLTYPE_TYPE_EXPR (t), &find_parameter_packs_r, ppd,
    1527              :                       ppd->visited);
    1528            0 :         ppd->type_pack_expansion_p = type_pack_expansion_p;
    1529            0 :         *walk_subtrees = 0;
    1530            0 :         return NULL_TREE;
    1531              :       }
    1532              : 
    1533            0 :     case IF_STMT:
    1534            0 :       rs_walk_tree (&IF_COND (t), &find_parameter_packs_r, ppd, ppd->visited);
    1535            0 :       rs_walk_tree (&THEN_CLAUSE (t), &find_parameter_packs_r, ppd,
    1536              :                     ppd->visited);
    1537            0 :       rs_walk_tree (&ELSE_CLAUSE (t), &find_parameter_packs_r, ppd,
    1538              :                     ppd->visited);
    1539              :       /* Don't walk into IF_STMT_EXTRA_ARGS.  */
    1540            0 :       *walk_subtrees = 0;
    1541            0 :       return NULL_TREE;
    1542              : 
    1543            0 :     case FUNCTION_TYPE:
    1544            0 :     case METHOD_TYPE:
    1545            0 :       WALK_SUBTREE (TYPE_RAISES_EXCEPTIONS (t));
    1546            0 :       break;
    1547              : 
    1548              :     default:
    1549              :       return NULL_TREE;
    1550              :     }
    1551              : 
    1552              : #undef WALK_SUBTREE
    1553              : 
    1554            0 :   return NULL_TREE;
    1555              : }
    1556              : 
    1557              : // forked from gcc/cp/typeck.cc type_memfn_rqual
    1558              : 
    1559              : /* Returns the function-ref-qualifier for TYPE */
    1560              : 
    1561              : rs_ref_qualifier
    1562            0 : type_memfn_rqual (const_tree type)
    1563              : {
    1564            0 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
    1565              : 
    1566            0 :   if (!FUNCTION_REF_QUALIFIED (type))
    1567              :     return REF_QUAL_NONE;
    1568            0 :   else if (FUNCTION_RVALUE_QUALIFIED (type))
    1569              :     return REF_QUAL_RVALUE;
    1570              :   else
    1571            0 :     return REF_QUAL_LVALUE;
    1572              : }
    1573              : 
    1574              : // forked from gcc/cp/lex.cc maybe_add_lang_type_raw
    1575              : 
    1576              : /* Add a raw lang_type to T, a type, should it need one.  */
    1577              : 
    1578              : bool
    1579            0 : maybe_add_lang_type_raw (tree t)
    1580              : {
    1581            0 :   if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
    1582              :     return false;
    1583              : 
    1584            0 :   auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc (
    1585              :     sizeof (struct lang_type)));
    1586            0 :   TYPE_LANG_SPECIFIC (t) = lt;
    1587              : 
    1588            0 :   if (GATHER_STATISTICS)
    1589              :     {
    1590              :       tree_node_counts[(int) lang_type] += 1;
    1591              :       tree_node_sizes[(int) lang_type] += sizeof (struct lang_type);
    1592              :     }
    1593              : 
    1594            0 :   return true;
    1595              : }
    1596              : 
    1597              : // forked from gcc/c-family/c-lex.cc get_fileinfo
    1598              : 
    1599              : static splay_tree file_info_tree;
    1600              : 
    1601              : struct c_fileinfo *
    1602            0 : get_fileinfo (const char *name)
    1603              : {
    1604            0 :   splay_tree_node n;
    1605            0 :   struct c_fileinfo *fi;
    1606              : 
    1607            0 :   if (!file_info_tree)
    1608            0 :     file_info_tree = splay_tree_new (splay_tree_compare_strings, 0,
    1609              :                                      splay_tree_delete_pointers);
    1610              : 
    1611            0 :   n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
    1612            0 :   if (n)
    1613            0 :     return (struct c_fileinfo *) n->value;
    1614              : 
    1615            0 :   fi = XNEW (struct c_fileinfo);
    1616            0 :   fi->time = 0;
    1617            0 :   fi->interface_only = 0;
    1618            0 :   fi->interface_unknown = 1;
    1619            0 :   splay_tree_insert (file_info_tree, (splay_tree_key) name,
    1620              :                      (splay_tree_value) fi);
    1621            0 :   return fi;
    1622              : }
    1623              : 
    1624              : // forked from gcc/cp/lex.cc cxx_make_type
    1625              : 
    1626              : tree
    1627            0 : cxx_make_type (enum tree_code code MEM_STAT_DECL)
    1628              : {
    1629            0 :   tree t = make_node (code PASS_MEM_STAT);
    1630              : 
    1631            0 :   if (maybe_add_lang_type_raw (t))
    1632              :     {
    1633              :       /* Set up some flags that give proper default behavior.  */
    1634            0 :       struct c_fileinfo *finfo = get_fileinfo (LOCATION_FILE (input_location));
    1635            0 :       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
    1636            0 :       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
    1637              :     }
    1638              : 
    1639            0 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    1640            0 :     TYPE_CXX_ODR_P (t) = 1;
    1641              : 
    1642            0 :   return t;
    1643              : }
    1644              : 
    1645              : // forked from gcc/cp/tree.cc build_min_array_type
    1646              : 
    1647              : /* Build an ARRAY_TYPE without laying it out.  */
    1648              : 
    1649              : static tree
    1650            0 : build_min_array_type (tree elt_type, tree index_type)
    1651              : {
    1652            0 :   tree t = cxx_make_type (ARRAY_TYPE);
    1653            0 :   TREE_TYPE (t) = elt_type;
    1654            0 :   TYPE_DOMAIN (t) = index_type;
    1655            0 :   return t;
    1656              : }
    1657              : 
    1658              : // forked from gcc/cp/name-lookup.cc resort_data
    1659              : 
    1660              : } // namespace Rust
    1661              : 
    1662              : static struct
    1663              : {
    1664              :   gt_pointer_operator new_value;
    1665              :   void *cookie;
    1666              : } resort_data;
    1667              : 
    1668              : // forked from gcc/cp/name-lookup.cc resort_member_name_cmp
    1669              : 
    1670              : /* This routine compares two fields like member_name_cmp but using the
    1671              :    pointer operator in resort_field_decl_data.  We don't have to deal
    1672              :    with duplicates here.  */
    1673              : 
    1674              : static int
    1675            0 : resort_member_name_cmp (const void *a_p, const void *b_p)
    1676              : {
    1677            0 :   tree a = *(const tree *) a_p;
    1678            0 :   tree b = *(const tree *) b_p;
    1679            0 :   tree name_a = OVL_NAME (a);
    1680            0 :   tree name_b = OVL_NAME (b);
    1681              : 
    1682            0 :   resort_data.new_value (&name_a, &name_a, resort_data.cookie);
    1683            0 :   resort_data.new_value (&name_b, &name_b, resort_data.cookie);
    1684              : 
    1685            0 :   gcc_checking_assert (name_a != name_b);
    1686              : 
    1687            0 :   return name_a < name_b ? -1 : +1;
    1688              : }
    1689              : 
    1690              : // forked from gcc/cp/name-lookup.cc resort_type_member_vec
    1691              : 
    1692              : /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered.  */
    1693              : 
    1694              : void
    1695            0 : resort_type_member_vec (void *obj, void * /*orig_obj*/,
    1696              :                         gt_pointer_operator new_value, void *cookie)
    1697              : {
    1698            0 :   if (vec<tree, va_gc> *member_vec = (vec<tree, va_gc> *) obj)
    1699              :     {
    1700            0 :       resort_data.new_value = new_value;
    1701            0 :       resort_data.cookie = cookie;
    1702            0 :       member_vec->qsort (resort_member_name_cmp);
    1703              :     }
    1704            0 : }
    1705              : 
    1706              : namespace Rust {
    1707              : 
    1708              : // forked from gcc/cp/name-lookup.cc fields_linear_search
    1709              : 
    1710              : /* Linear search of (partially ordered) fields of KLASS for NAME.  */
    1711              : 
    1712              : static tree
    1713            0 : fields_linear_search (tree klass, tree name, bool want_type)
    1714              : {
    1715            0 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1716              :     {
    1717            0 :       tree decl = fields;
    1718              : 
    1719            0 :       if (DECL_NAME (decl) != name)
    1720            0 :         continue;
    1721              : 
    1722            0 :       if (DECL_DECLARES_FUNCTION_P (decl))
    1723              :         /* Functions are found separately.  */
    1724            0 :         continue;
    1725              : 
    1726            0 :       if (!want_type || DECL_DECLARES_TYPE_P (decl))
    1727              :         return decl;
    1728              :     }
    1729              : 
    1730              :   return NULL_TREE;
    1731              : }
    1732              : 
    1733              : // forked from gcc/cp/except.cc canonnothrow_spec_pical_eh_spec
    1734              : 
    1735              : /* Return true iff SPEC is throw() or noexcept(true).  */
    1736              : 
    1737              : bool
    1738            0 : nothrow_spec_p (const_tree spec)
    1739              : {
    1740            0 :   if (spec == empty_except_spec || spec == noexcept_true_spec)
    1741              :     return true;
    1742              : 
    1743            0 :   gcc_assert (!spec || TREE_VALUE (spec) || spec == noexcept_false_spec
    1744              :               || TREE_PURPOSE (spec) == error_mark_node);
    1745              : 
    1746              :   return false;
    1747              : }
    1748              : 
    1749              : // forked from gcc/cp/tree.cc may_get_fns
    1750              : 
    1751              : /* Get the overload set FROM refers to.  Returns NULL if it's not an
    1752              :    overload set.  */
    1753              : 
    1754              : tree
    1755            0 : maybe_get_fns (tree from)
    1756              : {
    1757            0 :   STRIP_ANY_LOCATION_WRAPPER (from);
    1758              : 
    1759              :   /* A baselink is also considered an overloaded function.  */
    1760            0 :   if (TREE_CODE (from) == COMPONENT_REF)
    1761            0 :     from = TREE_OPERAND (from, 1);
    1762              : 
    1763            0 :   if (OVL_P (from))
    1764            0 :     return from;
    1765              : 
    1766              :   return NULL;
    1767              : }
    1768              : 
    1769              : // forked from gcc/cp/tree.cc get_fns
    1770              : 
    1771              : /* FROM refers to an overload set.  Return that set (or die).  */
    1772              : 
    1773              : tree
    1774            0 : get_fns (tree from)
    1775              : {
    1776            0 :   tree res = maybe_get_fns (from);
    1777              : 
    1778            0 :   gcc_assert (res);
    1779            0 :   return res;
    1780              : }
    1781              : 
    1782              : // forked from gcc/cp/tree.cc get_first_fn
    1783              : 
    1784              : /* Return the first function of the overload set FROM refers to.  */
    1785              : 
    1786              : tree
    1787            0 : get_first_fn (tree from)
    1788              : {
    1789            0 :   return OVL_FIRST (get_fns (from));
    1790              : }
    1791              : 
    1792              : // forked from gcc/cp/tree.cc dependent_name
    1793              : 
    1794              : /* X is the CALL_EXPR_FN of a CALL_EXPR.  If X represents a dependent name
    1795              :    (14.6.2), return the IDENTIFIER_NODE for that name.  Otherwise, return
    1796              :    NULL_TREE.  */
    1797              : 
    1798              : tree
    1799            0 : dependent_name (tree x)
    1800              : {
    1801              :   /* FIXME a dependent name must be unqualified, but this function doesn't
    1802              :      distinguish between qualified and unqualified identifiers.  */
    1803            0 :   if (identifier_p (x))
    1804              :     return x;
    1805              : 
    1806            0 :   if (OVL_P (x))
    1807            0 :     return OVL_NAME (x);
    1808              :   return NULL_TREE;
    1809              : }
    1810              : 
    1811              : // forked from gcc/cp/tree.cc called_fns_equal
    1812              : 
    1813              : /* Subroutine of rs_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
    1814              :    CALL_EXPRS.  Return whether they are equivalent.  */
    1815              : 
    1816              : static bool
    1817            0 : called_fns_equal (tree t1, tree t2)
    1818              : {
    1819              :   /* Core 1321: dependent names are equivalent even if the overload sets
    1820              :      are different.  But do compare explicit template arguments.  */
    1821            0 :   tree name1 = dependent_name (t1);
    1822            0 :   tree name2 = dependent_name (t2);
    1823            0 :   if (name1 || name2)
    1824              :     {
    1825            0 :       tree targs1 = NULL_TREE, targs2 = NULL_TREE;
    1826              : 
    1827            0 :       if (name1 != name2)
    1828              :         return false;
    1829              : 
    1830              :       /* FIXME dependent_name currently returns an unqualified name regardless
    1831              :          of whether the function was named with a qualified- or unqualified-id.
    1832              :          Until that's fixed, check that we aren't looking at overload sets from
    1833              :          different scopes.  */
    1834            0 :       if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
    1835            0 :           && (DECL_CONTEXT (get_first_fn (t1))
    1836            0 :               != DECL_CONTEXT (get_first_fn (t2))))
    1837              :         return false;
    1838              : 
    1839            0 :       return rs_tree_equal (targs1, targs2);
    1840              :     }
    1841              :   else
    1842            0 :     return rs_tree_equal (t1, t2);
    1843              : }
    1844              : 
    1845              : // forked from gcc/cp/tree.cc canonical_eh_spec
    1846              : 
    1847              : /* Return the canonical version of exception-specification RAISES for a C++17
    1848              :    function type, for use in type comparison and building TYPE_CANONICAL.  */
    1849              : 
    1850              : tree
    1851            0 : canonical_eh_spec (tree raises)
    1852              : {
    1853            0 :   if (raises == NULL_TREE)
    1854              :     return raises;
    1855            0 :   else if (nothrow_spec_p (raises))
    1856              :     /* throw() -> noexcept.  */
    1857            0 :     return noexcept_true_spec;
    1858              :   else
    1859              :     /* For C++17 type matching, anything else -> nothing.  */
    1860              :     return NULL_TREE;
    1861              : }
    1862              : 
    1863              : /* Like cp_tree_operand_length, but takes a tree_code CODE.  */
    1864              : 
    1865              : int
    1866            0 : rs_tree_code_length (enum tree_code code)
    1867              : {
    1868            0 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    1869              : 
    1870            0 :   switch (code)
    1871              :     {
    1872              :     case PREINCREMENT_EXPR:
    1873              :     case PREDECREMENT_EXPR:
    1874              :     case POSTINCREMENT_EXPR:
    1875              :     case POSTDECREMENT_EXPR:
    1876              :       return 1;
    1877              : 
    1878            0 :     case ARRAY_REF:
    1879            0 :       return 2;
    1880              : 
    1881            0 :     default:
    1882            0 :       return TREE_CODE_LENGTH (code);
    1883              :     }
    1884              : }
    1885              : 
    1886              : // forked from gcc/cp/tree.cc rs_tree_operand_length
    1887              : 
    1888              : /* Return the number of operands in T that we care about for things like
    1889              :    mangling.  */
    1890              : 
    1891              : int
    1892            0 : rs_tree_operand_length (const_tree t)
    1893              : {
    1894            0 :   enum tree_code code = TREE_CODE (t);
    1895              : 
    1896            0 :   if (TREE_CODE_CLASS (code) == tcc_vl_exp)
    1897            0 :     return VL_EXP_OPERAND_LENGTH (t);
    1898              : 
    1899            0 :   return rs_tree_code_length (code);
    1900              : }
    1901              : 
    1902              : // forked from gcc/cp/tree.cc cp_tree_equal
    1903              : 
    1904              : /* Return truthvalue of whether T1 is the same tree structure as T2.
    1905              :    Return 1 if they are the same. Return 0 if they are different.  */
    1906              : 
    1907              : bool
    1908            0 : rs_tree_equal (tree t1, tree t2)
    1909              : {
    1910            0 :   enum tree_code code1, code2;
    1911              : 
    1912            0 :   if (t1 == t2)
    1913              :     return true;
    1914            0 :   if (!t1 || !t2)
    1915              :     return false;
    1916              : 
    1917            0 :   code1 = TREE_CODE (t1);
    1918            0 :   code2 = TREE_CODE (t2);
    1919              : 
    1920            0 :   if (code1 != code2)
    1921              :     return false;
    1922              : 
    1923            0 :   if (CONSTANT_CLASS_P (t1) && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1924              :     return false;
    1925              : 
    1926            0 :   switch (code1)
    1927              :     {
    1928            0 :     case VOID_CST:
    1929              :       /* There's only a single VOID_CST node, so we should never reach
    1930              :          here.  */
    1931            0 :       rust_unreachable ();
    1932              : 
    1933            0 :     case INTEGER_CST:
    1934            0 :       return tree_int_cst_equal (t1, t2);
    1935              : 
    1936            0 :     case REAL_CST:
    1937            0 :       return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
    1938              : 
    1939            0 :     case STRING_CST:
    1940            0 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
    1941            0 :              && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
    1942            0 :                          TREE_STRING_LENGTH (t1));
    1943              : 
    1944            0 :     case FIXED_CST:
    1945            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
    1946              : 
    1947            0 :     case COMPLEX_CST:
    1948            0 :       return rs_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
    1949            0 :              && rs_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
    1950              : 
    1951            0 :     case VECTOR_CST:
    1952            0 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
    1953              : 
    1954            0 :     case CONSTRUCTOR:
    1955              :       /* We need to do this when determining whether or not two
    1956              :          non-type pointer to member function template arguments
    1957              :          are the same.  */
    1958            0 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    1959            0 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
    1960              :         return false;
    1961              :       {
    1962              :         tree field, value;
    1963              :         unsigned int i;
    1964            0 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
    1965              :           {
    1966            0 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
    1967            0 :             if (!rs_tree_equal (field, elt2->index)
    1968            0 :                 || !rs_tree_equal (value, elt2->value))
    1969            0 :               return false;
    1970              :           }
    1971              :       }
    1972              :       return true;
    1973              : 
    1974            0 :     case TREE_LIST:
    1975            0 :       if (!rs_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
    1976              :         return false;
    1977            0 :       if (!rs_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
    1978              :         return false;
    1979            0 :       return rs_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
    1980              : 
    1981            0 :     case SAVE_EXPR:
    1982            0 :       return rs_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
    1983              : 
    1984            0 :     case CALL_EXPR:
    1985            0 :       {
    1986            0 :         if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
    1987              :           return false;
    1988              : 
    1989            0 :         if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
    1990              :           return false;
    1991              : 
    1992            0 :         call_expr_arg_iterator iter1, iter2;
    1993            0 :         init_call_expr_arg_iterator (t1, &iter1);
    1994            0 :         init_call_expr_arg_iterator (t2, &iter2);
    1995            0 :         if (iter1.n != iter2.n)
    1996              :           return false;
    1997              : 
    1998            0 :         while (more_call_expr_args_p (&iter1))
    1999              :           {
    2000            0 :             tree arg1 = next_call_expr_arg (&iter1);
    2001            0 :             tree arg2 = next_call_expr_arg (&iter2);
    2002              : 
    2003            0 :             gcc_checking_assert (arg1 && arg2);
    2004            0 :             if (!rs_tree_equal (arg1, arg2))
    2005              :               return false;
    2006              :           }
    2007              : 
    2008              :         return true;
    2009              :       }
    2010              : 
    2011            0 :     case TARGET_EXPR:
    2012            0 :       {
    2013            0 :         tree o1 = TREE_OPERAND (t1, 0);
    2014            0 :         tree o2 = TREE_OPERAND (t2, 0);
    2015              : 
    2016              :         /* Special case: if either target is an unallocated VAR_DECL,
    2017              :            it means that it's going to be unified with whatever the
    2018              :            TARGET_EXPR is really supposed to initialize, so treat it
    2019              :            as being equivalent to anything.  */
    2020            0 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE && !DECL_RTL_SET_P (o1))
    2021              :           /*Nop*/;
    2022            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
    2023            0 :                  && !DECL_RTL_SET_P (o2))
    2024              :           /*Nop*/;
    2025            0 :         else if (!rs_tree_equal (o1, o2))
    2026              :           return false;
    2027              : 
    2028            0 :         return rs_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
    2029              :       }
    2030              : 
    2031            0 :     case PARM_DECL:
    2032              :       /* For comparing uses of parameters in late-specified return types
    2033              :          with an out-of-class definition of the function, but can also come
    2034              :          up for expressions that involve 'this' in a member function
    2035              :          template.  */
    2036              : 
    2037            0 :       if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2038              :         {
    2039            0 :           if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
    2040              :             return false;
    2041            0 :           if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
    2042              :             return false;
    2043            0 :           if (DECL_ARTIFICIAL (t1)
    2044            0 :               || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
    2045            0 :                   && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
    2046              :             return true;
    2047              :         }
    2048              :       return false;
    2049              : 
    2050              :     case VAR_DECL:
    2051              :     case CONST_DECL:
    2052              :     case FIELD_DECL:
    2053              :     case FUNCTION_DECL:
    2054              :     case IDENTIFIER_NODE:
    2055              :     case SSA_NAME:
    2056              :       return false;
    2057              : 
    2058              :     case TREE_VEC:
    2059              :       return true;
    2060              : 
    2061            0 :     case NON_LVALUE_EXPR:
    2062            0 :     case VIEW_CONVERT_EXPR:
    2063              :       /* Used for location wrappers with possibly NULL types.  */
    2064            0 :       if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
    2065              :         {
    2066            0 :           if (TREE_TYPE (t1) || TREE_TYPE (t2))
    2067              :             return false;
    2068              :           break;
    2069              :         }
    2070              : 
    2071              :     default:
    2072              :       break;
    2073              :     }
    2074              : 
    2075            0 :   switch (TREE_CODE_CLASS (code1))
    2076              :     {
    2077            0 :     case tcc_unary:
    2078            0 :     case tcc_binary:
    2079            0 :     case tcc_comparison:
    2080            0 :     case tcc_expression:
    2081            0 :     case tcc_vl_exp:
    2082            0 :     case tcc_reference:
    2083            0 :     case tcc_statement:
    2084            0 :       {
    2085            0 :         int n = rs_tree_operand_length (t1);
    2086            0 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
    2087            0 :             && n != TREE_OPERAND_LENGTH (t2))
    2088              :           return false;
    2089              : 
    2090            0 :         for (int i = 0; i < n; ++i)
    2091            0 :           if (!rs_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
    2092              :             return false;
    2093              : 
    2094              :         return true;
    2095              :       }
    2096              : 
    2097            0 :     case tcc_type:
    2098            0 :       return same_type_p (t1, t2);
    2099              : 
    2100            0 :     default:
    2101            0 :       rust_unreachable ();
    2102              :     }
    2103              : 
    2104              :   /* We can get here with --disable-checking.  */
    2105              :   return false;
    2106              : }
    2107              : 
    2108              : // forked from gcc/cp/class.cc publicly_uniquely_derived_p
    2109              : 
    2110              : /* TRUE iff TYPE is publicly & uniquely derived from PARENT.  */
    2111              : 
    2112              : bool
    2113            0 : publicly_uniquely_derived_p (tree, tree)
    2114              : {
    2115            0 :   return false;
    2116              : }
    2117              : 
    2118              : // forked from gcc/cp/typeck.cc comp_except_types
    2119              : 
    2120              : /* Compare two exception specifier types for exactness or subsetness, if
    2121              :    allowed. Returns false for mismatch, true for match (same, or
    2122              :    derived and !exact).
    2123              : 
    2124              :    [except.spec] "If a class X ... objects of class X or any class publicly
    2125              :    and unambiguously derived from X. Similarly, if a pointer type Y * ...
    2126              :    exceptions of type Y * or that are pointers to any type publicly and
    2127              :    unambiguously derived from Y. Otherwise a function only allows exceptions
    2128              :    that have the same type ..."
    2129              :    This does not mention cv qualifiers and is different to what throw
    2130              :    [except.throw] and catch [except.catch] will do. They will ignore the
    2131              :    top level cv qualifiers, and allow qualifiers in the pointer to class
    2132              :    example.
    2133              : 
    2134              :    We implement the letter of the standard.  */
    2135              : 
    2136              : static bool
    2137            0 : comp_except_types (tree a, tree b, bool exact)
    2138              : {
    2139            0 :   if (same_type_p (a, b))
    2140              :     return true;
    2141            0 :   else if (!exact)
    2142              :     {
    2143            0 :       if (rs_type_quals (a) || rs_type_quals (b))
    2144            0 :         return false;
    2145              : 
    2146            0 :       if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
    2147              :         {
    2148            0 :           a = TREE_TYPE (a);
    2149            0 :           b = TREE_TYPE (b);
    2150            0 :           if (rs_type_quals (a) || rs_type_quals (b))
    2151            0 :             return false;
    2152              :         }
    2153              : 
    2154            0 :       if (TREE_CODE (a) != RECORD_TYPE || TREE_CODE (b) != RECORD_TYPE)
    2155              :         return false;
    2156              : 
    2157            0 :       if (publicly_uniquely_derived_p (a, b))
    2158              :         return true;
    2159              :     }
    2160              :   return false;
    2161              : }
    2162              : 
    2163              : // forked from gcc/cp/typeck.cc comp_except_specs
    2164              : 
    2165              : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
    2166              :    If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
    2167              :    If EXACT is ce_type, the C++17 type compatibility rules apply.
    2168              :    If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
    2169              :    If EXACT is ce_exact, the specs must be exactly the same. Exception lists
    2170              :    are unordered, but we've already filtered out duplicates. Most lists will
    2171              :    be in order, we should try to make use of that.  */
    2172              : 
    2173              : bool
    2174            0 : comp_except_specs (const_tree t1, const_tree t2, int exact)
    2175              : {
    2176            0 :   const_tree probe;
    2177            0 :   const_tree base;
    2178            0 :   int length = 0;
    2179              : 
    2180            0 :   if (t1 == t2)
    2181              :     return true;
    2182              : 
    2183              :   /* First handle noexcept.  */
    2184            0 :   if (exact < ce_exact)
    2185              :     {
    2186            0 :       if (exact == ce_type
    2187            0 :           && (canonical_eh_spec (const_cast<tree> (t1))
    2188            0 :               == canonical_eh_spec (const_cast<tree> (t2))))
    2189              :         return true;
    2190              : 
    2191              :       /* noexcept(false) is compatible with no exception-specification,
    2192              :          and less strict than any spec.  */
    2193            0 :       if (t1 == noexcept_false_spec)
    2194            0 :         return t2 == NULL_TREE || exact == ce_derived;
    2195              :       /* Even a derived noexcept(false) is compatible with no
    2196              :          exception-specification.  */
    2197            0 :       if (t2 == noexcept_false_spec)
    2198            0 :         return t1 == NULL_TREE;
    2199              : 
    2200              :       /* Otherwise, if we aren't looking for an exact match, noexcept is
    2201              :          equivalent to throw().  */
    2202            0 :       if (t1 == noexcept_true_spec)
    2203            0 :         t1 = empty_except_spec;
    2204            0 :       if (t2 == noexcept_true_spec)
    2205            0 :         t2 = empty_except_spec;
    2206              :     }
    2207              : 
    2208              :   /* If any noexcept is left, it is only comparable to itself;
    2209              :      either we're looking for an exact match or we're redeclaring a
    2210              :      template with dependent noexcept.  */
    2211            0 :   if ((t1 && TREE_PURPOSE (t1)) || (t2 && TREE_PURPOSE (t2)))
    2212            0 :     return (t1 && t2 && rs_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)));
    2213              : 
    2214            0 :   if (t1 == NULL_TREE) /* T1 is ...  */
    2215            0 :     return t2 == NULL_TREE || exact == ce_derived;
    2216            0 :   if (!TREE_VALUE (t1)) /* t1 is EMPTY */
    2217            0 :     return t2 != NULL_TREE && !TREE_VALUE (t2);
    2218            0 :   if (t2 == NULL_TREE) /* T2 is ...  */
    2219              :     return false;
    2220            0 :   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
    2221            0 :     return exact == ce_derived;
    2222              : 
    2223              :   /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
    2224              :      Count how many we find, to determine exactness. For exact matching and
    2225              :      ordered T1, T2, this is an O(n) operation, otherwise its worst case is
    2226              :      O(nm).  */
    2227            0 :   for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
    2228              :     {
    2229            0 :       for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
    2230              :         {
    2231            0 :           tree a = TREE_VALUE (probe);
    2232            0 :           tree b = TREE_VALUE (t2);
    2233              : 
    2234            0 :           if (comp_except_types (a, b, exact))
    2235              :             {
    2236            0 :               if (probe == base && exact > ce_derived)
    2237            0 :                 base = TREE_CHAIN (probe);
    2238            0 :               length++;
    2239            0 :               break;
    2240              :             }
    2241              :         }
    2242            0 :       if (probe == NULL_TREE)
    2243              :         return false;
    2244              :     }
    2245            0 :   return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
    2246              : }
    2247              : 
    2248              : // forked from gcc/cp/typeck.cc compparms
    2249              : 
    2250              : /* Subroutines of `comptypes'.  */
    2251              : 
    2252              : /* Return true if two parameter type lists PARMS1 and PARMS2 are
    2253              :    equivalent in the sense that functions with those parameter types
    2254              :    can have equivalent types.  The two lists must be equivalent,
    2255              :    element by element.  */
    2256              : 
    2257              : bool
    2258            0 : compparms (const_tree parms1, const_tree parms2)
    2259              : {
    2260            0 :   const_tree t1, t2;
    2261              : 
    2262              :   /* An unspecified parmlist matches any specified parmlist
    2263              :      whose argument types don't need default promotions.  */
    2264              : 
    2265            0 :   for (t1 = parms1, t2 = parms2; t1 || t2;
    2266            0 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2267              :     {
    2268              :       /* If one parmlist is shorter than the other,
    2269              :          they fail to match.  */
    2270            0 :       if (!t1 || !t2)
    2271              :         return false;
    2272            0 :       if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2273              :         return false;
    2274              :     }
    2275              :   return true;
    2276              : }
    2277              : 
    2278              : /* Set TYPE_CANONICAL like build_array_type_1, but using
    2279              :    build_cplus_array_type.  */
    2280              : 
    2281              : static void
    2282            0 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
    2283              : {
    2284              :   /* Set the canonical type for this new node.  */
    2285            0 :   if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
    2286            0 :       || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
    2287            0 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    2288            0 :   else if (TYPE_CANONICAL (elt_type) != elt_type
    2289            0 :            || (index_type && TYPE_CANONICAL (index_type) != index_type))
    2290            0 :     TYPE_CANONICAL (t)
    2291            0 :       = build_cplus_array_type (TYPE_CANONICAL (elt_type),
    2292            0 :                                 index_type ? TYPE_CANONICAL (index_type)
    2293              :                                            : index_type,
    2294              :                                 dep);
    2295              :   else
    2296            0 :     TYPE_CANONICAL (t) = t;
    2297            0 : }
    2298              : 
    2299              : // forked from gcc/cp/tree.cc cplus_array_info
    2300              : 
    2301              : struct cplus_array_info
    2302              : {
    2303              :   tree type;
    2304              :   tree domain;
    2305              : };
    2306              : 
    2307              : // forked from gcc/cp/tree.cc cplus_array_hasher
    2308              : 
    2309              : struct rust_cplus_array_hasher : ggc_ptr_hash<tree_node>
    2310              : {
    2311              :   typedef cplus_array_info *compare_type;
    2312              : 
    2313              :   static hashval_t hash (tree t);
    2314              :   static bool equal (tree, cplus_array_info *);
    2315              : };
    2316              : 
    2317              : /* Hash an ARRAY_TYPE.  K is really of type `tree'.  */
    2318              : 
    2319              : hashval_t
    2320            0 : rust_cplus_array_hasher::hash (tree t)
    2321              : {
    2322            0 :   hashval_t hash;
    2323              : 
    2324            0 :   hash = TYPE_UID (TREE_TYPE (t));
    2325            0 :   if (TYPE_DOMAIN (t))
    2326            0 :     hash ^= TYPE_UID (TYPE_DOMAIN (t));
    2327            0 :   return hash;
    2328              : }
    2329              : 
    2330              : /* Compare two ARRAY_TYPEs.  K1 is really of type `tree', K2 is really
    2331              :    of type `cplus_array_info*'. */
    2332              : 
    2333              : bool
    2334            0 : rust_cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
    2335              : {
    2336            0 :   return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
    2337              : }
    2338              : 
    2339              : // forked from gcc/cp/tree.cc cplus_array_htab
    2340              : 
    2341              : /* Hash table containing dependent array types, which are unsuitable for
    2342              :    the language-independent type hash table.  */
    2343              : static GTY (()) hash_table<rust_cplus_array_hasher> *cplus_array_htab;
    2344              : 
    2345              : // forked from gcc/cp/tree.cc is_byte_access_type
    2346              : 
    2347              : /* Returns true if TYPE is char, unsigned char, or std::byte.  */
    2348              : 
    2349              : bool
    2350            0 : is_byte_access_type (tree type)
    2351              : {
    2352            0 :   type = TYPE_MAIN_VARIANT (type);
    2353            0 :   if (type == char_type_node || type == unsigned_char_type_node)
    2354              :     return true;
    2355              : 
    2356            0 :   return (TREE_CODE (type) == ENUMERAL_TYPE && TYPE_CONTEXT (type) == std_node
    2357            0 :           && !strcmp ("byte", TYPE_NAME_STRING (type)));
    2358              : }
    2359              : 
    2360              : // forked from gcc/cp/tree.cc build_cplus_array_type
    2361              : 
    2362              : /* Like build_array_type, but handle special C++ semantics: an array of a
    2363              :    variant element type is a variant of the array of the main variant of
    2364              :    the element type.  IS_DEPENDENT is -ve if we should determine the
    2365              :    dependency.  Otherwise its bool value indicates dependency.  */
    2366              : 
    2367              : tree
    2368            0 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
    2369              : {
    2370            0 :   tree t;
    2371              : 
    2372            0 :   if (elt_type == error_mark_node || index_type == error_mark_node)
    2373              :     return error_mark_node;
    2374              : 
    2375            0 :   if (dependent < 0)
    2376              :     dependent = 0;
    2377              : 
    2378            0 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    2379              :     /* Start with an array of the TYPE_MAIN_VARIANT.  */
    2380            0 :     t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), index_type,
    2381              :                                 dependent);
    2382            0 :   else if (dependent)
    2383              :     {
    2384              :       /* Since type_hash_canon calls layout_type, we need to use our own
    2385              :          hash table.  */
    2386            0 :       cplus_array_info cai;
    2387            0 :       hashval_t hash;
    2388              : 
    2389            0 :       if (cplus_array_htab == NULL)
    2390            0 :         cplus_array_htab = hash_table<rust_cplus_array_hasher>::create_ggc (61);
    2391              : 
    2392            0 :       hash = TYPE_UID (elt_type);
    2393            0 :       if (index_type)
    2394            0 :         hash ^= TYPE_UID (index_type);
    2395            0 :       cai.type = elt_type;
    2396            0 :       cai.domain = index_type;
    2397              : 
    2398            0 :       tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
    2399            0 :       if (*e)
    2400              :         /* We have found the type: we're done.  */
    2401            0 :         return (tree) *e;
    2402              :       else
    2403              :         {
    2404              :           /* Build a new array type.  */
    2405            0 :           t = build_min_array_type (elt_type, index_type);
    2406              : 
    2407              :           /* Store it in the hash table. */
    2408            0 :           *e = t;
    2409              : 
    2410              :           /* Set the canonical type for this new node.  */
    2411            0 :           set_array_type_canon (t, elt_type, index_type, dependent);
    2412              : 
    2413              :           /* Mark it as dependent now, this saves time later.  */
    2414            0 :           TYPE_DEPENDENT_P_VALID (t) = true;
    2415            0 :           TYPE_DEPENDENT_P (t) = true;
    2416              :         }
    2417              :     }
    2418              :   else
    2419              :     {
    2420            0 :       bool typeless_storage = is_byte_access_type (elt_type);
    2421            0 :       t = build_array_type (elt_type, index_type, typeless_storage);
    2422              : 
    2423              :       /* Mark as non-dependenty now, this will save time later.  */
    2424            0 :       TYPE_DEPENDENT_P_VALID (t) = true;
    2425              :     }
    2426              : 
    2427              :   /* Now check whether we already have this array variant.  */
    2428            0 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    2429              :     {
    2430              :       tree m = t;
    2431            0 :       for (t = m; t; t = TYPE_NEXT_VARIANT (t))
    2432            0 :         if (TREE_TYPE (t) == elt_type && TYPE_NAME (t) == NULL_TREE
    2433            0 :             && TYPE_ATTRIBUTES (t) == NULL_TREE)
    2434              :           break;
    2435            0 :       if (!t)
    2436              :         {
    2437            0 :           t = build_min_array_type (elt_type, index_type);
    2438              :           /* Mark dependency now, this saves time later.  */
    2439            0 :           TYPE_DEPENDENT_P_VALID (t) = true;
    2440            0 :           TYPE_DEPENDENT_P (t) = dependent;
    2441            0 :           set_array_type_canon (t, elt_type, index_type, dependent);
    2442            0 :           if (!dependent)
    2443              :             {
    2444            0 :               layout_type (t);
    2445              :               /* Make sure sizes are shared with the main variant.
    2446              :                  layout_type can't be called after setting TYPE_NEXT_VARIANT,
    2447              :                  as it will overwrite alignment etc. of all variants.  */
    2448            0 :               TYPE_SIZE (t) = TYPE_SIZE (m);
    2449            0 :               TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
    2450            0 :               TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
    2451              :             }
    2452              : 
    2453            0 :           TYPE_MAIN_VARIANT (t) = m;
    2454            0 :           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
    2455            0 :           TYPE_NEXT_VARIANT (m) = t;
    2456              :         }
    2457              :     }
    2458              : 
    2459              :   /* Avoid spurious warnings with VLAs (c++/54583).  */
    2460            0 :   if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
    2461            0 :     suppress_warning (TYPE_SIZE (t), OPT_Wunused);
    2462              : 
    2463              :   /* Push these needs up to the ARRAY_TYPE so that initialization takes
    2464              :      place more easily.  */
    2465            0 :   bool needs_ctor
    2466            0 :     = (TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (elt_type));
    2467            0 :   bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2468            0 :                      = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
    2469              : 
    2470            0 :   if (!dependent && t == TYPE_MAIN_VARIANT (t) && !COMPLETE_TYPE_P (t)
    2471            0 :       && COMPLETE_TYPE_P (elt_type))
    2472              :     {
    2473              :       /* The element type has been completed since the last time we saw
    2474              :          this array type; update the layout and 'tor flags for any variants
    2475              :          that need it.  */
    2476            0 :       layout_type (t);
    2477            0 :       for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2478              :         {
    2479            0 :           TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
    2480            0 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
    2481              :         }
    2482              :     }
    2483              : 
    2484              :   return t;
    2485              : }
    2486              : 
    2487              : // forked from gcc/cp/tree.cc cp_build_qualified_type_real
    2488              : 
    2489              : /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
    2490              :    arrays correctly.  In particular, if TYPE is an array of T's, and
    2491              :    TYPE_QUALS is non-empty, returns an array of qualified T's.
    2492              : 
    2493              :    FLAGS determines how to deal with ill-formed qualifications. If
    2494              :    tf_ignore_bad_quals is set, then bad qualifications are dropped
    2495              :    (this is permitted if TYPE was introduced via a typedef or template
    2496              :    type parameter). If bad qualifications are dropped and tf_warning
    2497              :    is set, then a warning is issued for non-const qualifications.  If
    2498              :    tf_ignore_bad_quals is not set and tf_error is not set, we
    2499              :    return error_mark_node. Otherwise, we issue an error, and ignore
    2500              :    the qualifications.
    2501              : 
    2502              :    Qualification of a reference type is valid when the reference came
    2503              :    via a typedef or template type argument. [dcl.ref] No such
    2504              :    dispensation is provided for qualifying a function type.  [dcl.fct]
    2505              :    DR 295 queries this and the proposed resolution brings it into line
    2506              :    with qualifying a reference.  We implement the DR.  We also behave
    2507              :    in a similar manner for restricting non-pointer types.  */
    2508              : 
    2509              : tree
    2510           19 : rs_build_qualified_type_real (tree type, int type_quals,
    2511              :                               tsubst_flags_t complain)
    2512              : {
    2513           19 :   tree result;
    2514           19 :   int bad_quals = TYPE_UNQUALIFIED;
    2515              : 
    2516           19 :   if (type == error_mark_node)
    2517              :     return type;
    2518              : 
    2519           19 :   if (type_quals == rs_type_quals (type))
    2520              :     return type;
    2521              : 
    2522           10 :   if (TREE_CODE (type) == ARRAY_TYPE)
    2523              :     {
    2524              :       /* In C++, the qualification really applies to the array element
    2525              :          type.  Obtain the appropriately qualified element type.  */
    2526            0 :       tree t;
    2527            0 :       tree element_type
    2528            0 :         = rs_build_qualified_type_real (TREE_TYPE (type), type_quals, complain);
    2529              : 
    2530            0 :       if (element_type == error_mark_node)
    2531              :         return error_mark_node;
    2532              : 
    2533              :       /* See if we already have an identically qualified type.  Tests
    2534              :          should be equivalent to those in check_qualified_type.  */
    2535            0 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    2536            0 :         if (TREE_TYPE (t) == element_type && TYPE_NAME (t) == TYPE_NAME (type)
    2537            0 :             && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
    2538            0 :             && attribute_list_equal (TYPE_ATTRIBUTES (t),
    2539            0 :                                      TYPE_ATTRIBUTES (type)))
    2540              :           break;
    2541              : 
    2542            0 :       if (!t)
    2543              :         {
    2544              :           /* If we already know the dependentness, tell the array type
    2545              :              constructor.  This is important for module streaming, as we cannot
    2546              :              dynamically determine that on read in.  */
    2547            0 :           t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
    2548            0 :                                       TYPE_DEPENDENT_P_VALID (type)
    2549            0 :                                         ? int (TYPE_DEPENDENT_P (type))
    2550              :                                         : -1);
    2551              : 
    2552              :           /* Keep the typedef name.  */
    2553            0 :           if (TYPE_NAME (t) != TYPE_NAME (type))
    2554              :             {
    2555            0 :               t = build_variant_type_copy (t);
    2556            0 :               TYPE_NAME (t) = TYPE_NAME (type);
    2557            0 :               SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
    2558            0 :               TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
    2559              :             }
    2560              :         }
    2561              : 
    2562              :       /* Even if we already had this variant, we update
    2563              :          TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
    2564              :          they changed since the variant was originally created.
    2565              : 
    2566              :          This seems hokey; if there is some way to use a previous
    2567              :          variant *without* coming through here,
    2568              :          TYPE_NEEDS_CONSTRUCTING will never be updated.  */
    2569            0 :       TYPE_NEEDS_CONSTRUCTING (t)
    2570            0 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
    2571            0 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2572            0 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
    2573            0 :       return t;
    2574              :     }
    2575              : 
    2576              :   /* A reference or method type shall not be cv-qualified.
    2577              :      [dcl.ref], [dcl.fct].  This used to be an error, but as of DR 295
    2578              :      (in CD1) we always ignore extra cv-quals on functions.  */
    2579              : 
    2580              :   /* [dcl.ref/1] Cv-qualified references are ill-formed except when
    2581              :      the cv-qualifiers are introduced through the use of a typedef-name
    2582              :      ([dcl.typedef], [temp.param]) or decltype-specifier
    2583              :      ([dcl.type.decltype]),in which case the cv-qualifiers are
    2584              :      ignored.  */
    2585           10 :   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
    2586            0 :       && (TYPE_REF_P (type) || FUNC_OR_METHOD_TYPE_P (type)))
    2587              :     {
    2588            0 :       if (TYPE_REF_P (type)
    2589            0 :           && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
    2590              :         bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    2591            0 :       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    2592              :     }
    2593              : 
    2594              :   /* But preserve any function-cv-quals on a FUNCTION_TYPE.  */
    2595           10 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    2596            0 :     type_quals |= type_memfn_quals (type);
    2597              : 
    2598              :   /* A restrict-qualified type must be a pointer (or reference)
    2599              :      to object or incomplete type. */
    2600           10 :   if ((type_quals & TYPE_QUAL_RESTRICT) && TREE_CODE (type) != TYPENAME_TYPE
    2601            0 :       && !INDIRECT_TYPE_P (type))
    2602              :     {
    2603            0 :       bad_quals |= TYPE_QUAL_RESTRICT;
    2604            0 :       type_quals &= ~TYPE_QUAL_RESTRICT;
    2605              :     }
    2606              : 
    2607           10 :   if (bad_quals == TYPE_UNQUALIFIED || (complain & tf_ignore_bad_quals))
    2608              :     /*OK*/;
    2609            0 :   else if (!(complain & tf_error))
    2610            0 :     return error_mark_node;
    2611              :   else
    2612              :     {
    2613            0 :       tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
    2614            0 :       error ("%qV qualifiers cannot be applied to %qT", bad_type, type);
    2615              :     }
    2616              : 
    2617              :   /* Retrieve (or create) the appropriately qualified variant.  */
    2618           10 :   result = build_qualified_type (type, type_quals);
    2619              : 
    2620           10 :   return result;
    2621              : }
    2622              : 
    2623              : // forked from gcc/cp/c-common.cc vector_targets_convertible_p
    2624              : 
    2625              : /* vector_targets_convertible_p is used for vector pointer types.  The
    2626              :    callers perform various checks that the qualifiers are satisfactory,
    2627              :    while OTOH vector_targets_convertible_p ignores the number of elements
    2628              :    in the vectors.  That's fine with vector pointers as we can consider,
    2629              :    say, a vector of 8 elements as two consecutive vectors of 4 elements,
    2630              :    and that does not require and conversion of the pointer values.
    2631              :    In contrast, vector_types_convertible_p and
    2632              :    vector_types_compatible_elements_p are used for vector value types.  */
    2633              : /* True if pointers to distinct types T1 and T2 can be converted to
    2634              :    each other without an explicit cast.  Only returns true for opaque
    2635              :    vector types.  */
    2636              : bool
    2637            0 : vector_targets_convertible_p (const_tree t1, const_tree t2)
    2638              : {
    2639            0 :   if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
    2640            0 :       && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
    2641            0 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
    2642              :     return true;
    2643              : 
    2644              :   return false;
    2645              : }
    2646              : 
    2647              : // forked from gcc/cp/typeck.cc comp_array_types
    2648              : 
    2649              : /* Compare the array types T1 and T2.  CB says how we should behave when
    2650              :    comparing array bounds: bounds_none doesn't allow dimensionless arrays,
    2651              :    bounds_either says than any array can be [], bounds_first means that
    2652              :    onlt T1 can be an array with unknown bounds.  STRICT is true if
    2653              :    qualifiers must match when comparing the types of the array elements.  */
    2654              : 
    2655              : static bool
    2656            0 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
    2657              :                   bool strict)
    2658              : {
    2659            0 :   tree d1;
    2660            0 :   tree d2;
    2661            0 :   tree max1, max2;
    2662              : 
    2663            0 :   if (t1 == t2)
    2664              :     return true;
    2665              : 
    2666              :   /* The type of the array elements must be the same.  */
    2667            0 :   if (strict ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    2668            0 :              : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2669              :     return false;
    2670              : 
    2671            0 :   d1 = TYPE_DOMAIN (t1);
    2672            0 :   d2 = TYPE_DOMAIN (t2);
    2673              : 
    2674            0 :   if (d1 == d2)
    2675              :     return true;
    2676              : 
    2677              :   /* If one of the arrays is dimensionless, and the other has a
    2678              :      dimension, they are of different types.  However, it is valid to
    2679              :      write:
    2680              : 
    2681              :        extern int a[];
    2682              :        int a[3];
    2683              : 
    2684              :      by [basic.link]:
    2685              : 
    2686              :        declarations for an array object can specify
    2687              :        array types that differ by the presence or absence of a major
    2688              :        array bound (_dcl.array_).  */
    2689            0 :   if (!d1 && d2)
    2690            0 :     return cb >= bounds_either;
    2691            0 :   else if (d1 && !d2)
    2692            0 :     return cb == bounds_either;
    2693              : 
    2694              :   /* Check that the dimensions are the same.  */
    2695              : 
    2696            0 :   if (!rs_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    2697              :     return false;
    2698            0 :   max1 = TYPE_MAX_VALUE (d1);
    2699            0 :   max2 = TYPE_MAX_VALUE (d2);
    2700              : 
    2701            0 :   if (!rs_tree_equal (max1, max2))
    2702              :     return false;
    2703              : 
    2704              :   return true;
    2705              : }
    2706              : 
    2707              : // forked from gcc/cp/typeck.cc same_type_ignoring_top_level_qualifiers_p
    2708              : 
    2709              : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
    2710              :    top-level qualifiers.  */
    2711              : 
    2712              : bool
    2713            9 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
    2714              : {
    2715            9 :   if (type1 == error_mark_node || type2 == error_mark_node)
    2716              :     return false;
    2717            9 :   if (type1 == type2)
    2718              :     return true;
    2719              : 
    2720            8 :   type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
    2721            8 :   type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
    2722            8 :   return same_type_p (type1, type2);
    2723              : }
    2724              : 
    2725              : // forked from gcc/cp/typeck.cc comp_ptr_ttypes_const
    2726              : 
    2727              : /* Return true if TO and FROM (both of which are POINTER_TYPEs or
    2728              :    pointer-to-member types) are the same, ignoring cv-qualification at
    2729              :    all levels.  CB says how we should behave when comparing array bounds.  */
    2730              : 
    2731              : bool
    2732            0 : comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
    2733              : {
    2734            0 :   bool is_opaque_pointer = false;
    2735              : 
    2736            0 :   for (;; to = TREE_TYPE (to), from = TREE_TYPE (from))
    2737              :     {
    2738            0 :       if (TREE_CODE (to) != TREE_CODE (from))
    2739              :         return false;
    2740              : 
    2741            0 :       if (TREE_CODE (from) == OFFSET_TYPE
    2742            0 :           && same_type_p (TYPE_OFFSET_BASETYPE (from),
    2743              :                           TYPE_OFFSET_BASETYPE (to)))
    2744            0 :         continue;
    2745              : 
    2746            0 :       if (VECTOR_TYPE_P (to))
    2747            0 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
    2748              : 
    2749            0 :       if (TREE_CODE (to) == ARRAY_TYPE
    2750              :           /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
    2751              :              we must fail.  */
    2752            0 :           && !comp_array_types (to, from, cb, /*strict=*/false))
    2753              :         return false;
    2754              : 
    2755              :       /* CWG 330 says we need to look through arrays.  */
    2756            0 :       if (!TYPE_PTR_P (to) && TREE_CODE (to) != ARRAY_TYPE)
    2757            0 :         return (is_opaque_pointer
    2758            0 :                 || same_type_ignoring_top_level_qualifiers_p (to, from));
    2759              :     }
    2760              : }
    2761              : 
    2762              : // forked from gcc/cp/typeck.cc similar_type_p
    2763              : 
    2764              : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
    2765              : 
    2766              : bool
    2767            0 : similar_type_p (tree type1, tree type2)
    2768              : {
    2769            0 :   if (type1 == error_mark_node || type2 == error_mark_node)
    2770              :     return false;
    2771              : 
    2772              :   /* Informally, two types are similar if, ignoring top-level cv-qualification:
    2773              :      * they are the same type; or
    2774              :      * they are both pointers, and the pointed-to types are similar; or
    2775              :      * they are both pointers to member of the same class, and the types of
    2776              :        the pointed-to members are similar; or
    2777              :      * they are both arrays of the same size or both arrays of unknown bound,
    2778              :        and the array element types are similar.  */
    2779              : 
    2780            0 :   if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
    2781              :     return true;
    2782              : 
    2783            0 :   if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    2784            0 :       || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    2785            0 :       || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
    2786            0 :     return comp_ptr_ttypes_const (type1, type2, bounds_either);
    2787              : 
    2788              :   return false;
    2789              : }
    2790              : 
    2791              : // forked from gcc/cp/typeck.cc structural_comptypes
    2792              : // note: this fork only handles strict == COMPARE_STRICT
    2793              : // if you pass in any other value for strict i.e. COMPARE_BASE,
    2794              : // COMPARE_DERIVED, COMPARE_REDECLARATION or COMPARE_STRUCTURAL
    2795              : // see the original function in gcc/cp/typeck.cc and port the required bits
    2796              : // specifically under case UNION_TYPE.
    2797              : 
    2798              : /* Subroutine in comptypes.  */
    2799              : 
    2800              : static bool
    2801            4 : structural_comptypes (tree t1, tree t2, int strict)
    2802              : {
    2803              :   /* Both should be types that are not obviously the same.  */
    2804            4 :   gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
    2805              : 
    2806            4 :   if (TYPE_PTRMEMFUNC_P (t1))
    2807            0 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    2808            4 :   if (TYPE_PTRMEMFUNC_P (t2))
    2809            0 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
    2810              : 
    2811              :   /* Different classes of types can't be compatible.  */
    2812            4 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    2813              :     return false;
    2814              : 
    2815              :   /* Qualifiers must match.  For array types, we will check when we
    2816              :      recur on the array element types.  */
    2817            4 :   if (TREE_CODE (t1) != ARRAY_TYPE && rs_type_quals (t1) != rs_type_quals (t2))
    2818              :     return false;
    2819            1 :   if (TREE_CODE (t1) == FUNCTION_TYPE
    2820            1 :       && type_memfn_quals (t1) != type_memfn_quals (t2))
    2821              :     return false;
    2822              :   /* Need to check this before TYPE_MAIN_VARIANT.
    2823              :      FIXME function qualifiers should really change the main variant.  */
    2824            1 :   if (FUNC_OR_METHOD_TYPE_P (t1))
    2825              :     {
    2826            0 :       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
    2827              :         return false;
    2828            0 :       if (/* cxx_dialect >= cxx17 && */
    2829            0 :           !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
    2830            0 :                               TYPE_RAISES_EXCEPTIONS (t2), ce_type))
    2831              :         return false;
    2832              :     }
    2833              : 
    2834              :   /* Allow for two different type nodes which have essentially the same
    2835              :      definition.  Note that we already checked for equality of the type
    2836              :      qualifiers (just above).  */
    2837            1 :   if (TREE_CODE (t1) != ARRAY_TYPE
    2838            1 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    2839              :     return true;
    2840              : 
    2841              :   /* Compare the types.  Return false on known not-same. Break on not
    2842              :      known.   Never return true from this switch -- you'll break
    2843              :      specialization comparison.    */
    2844            0 :   switch (TREE_CODE (t1))
    2845              :     {
    2846              :     case VOID_TYPE:
    2847              :     case BOOLEAN_TYPE:
    2848              :       /* All void and bool types are the same.  */
    2849              :       break;
    2850              : 
    2851            0 :     case OPAQUE_TYPE:
    2852            0 :     case INTEGER_TYPE:
    2853            0 :     case FIXED_POINT_TYPE:
    2854            0 :     case REAL_TYPE:
    2855              :       /* With these nodes, we can't determine type equivalence by
    2856              :          looking at what is stored in the nodes themselves, because
    2857              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    2858              :          represent the same type.  For example, wchar_t and int could
    2859              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    2860              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    2861              :          and are distinct types. On the other hand, int and the
    2862              :          following typedef
    2863              : 
    2864              :            typedef int INT __attribute((may_alias));
    2865              : 
    2866              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    2867              :          represent the same type.  The canonical type system keeps
    2868              :          track of equivalence in this case, so we fall back on it.  */
    2869            0 :       if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    2870              :         return false;
    2871              : 
    2872              :       /* We don't need or want the attribute comparison.  */
    2873              :       return true;
    2874              : 
    2875              :     case RECORD_TYPE:
    2876              :     case UNION_TYPE:
    2877              :       return false;
    2878              : 
    2879            0 :     case OFFSET_TYPE:
    2880            0 :       if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
    2881              :                       strict & ~COMPARE_REDECLARATION))
    2882              :         return false;
    2883            0 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2884              :         return false;
    2885              :       break;
    2886              : 
    2887            0 :     case REFERENCE_TYPE:
    2888            0 :       if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
    2889              :         return false;
    2890              :       /* fall through to checks for pointer types */
    2891            0 :       gcc_fallthrough ();
    2892              : 
    2893            0 :     case POINTER_TYPE:
    2894            0 :       if (TYPE_MODE (t1) != TYPE_MODE (t2)
    2895            0 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2896            0 :         return false;
    2897              :       break;
    2898              : 
    2899            0 :     case METHOD_TYPE:
    2900            0 :     case FUNCTION_TYPE:
    2901              :       /* Exception specs and memfn_rquals were checked above.  */
    2902            0 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2903              :         return false;
    2904            0 :       if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
    2905              :         return false;
    2906              :       break;
    2907              : 
    2908            0 :     case ARRAY_TYPE:
    2909              :       /* Target types must match incl. qualifiers.  */
    2910            0 :       if (!comp_array_types (t1, t2,
    2911            0 :                              ((strict & COMPARE_REDECLARATION) ? bounds_either
    2912              :                                                                : bounds_none),
    2913              :                              /*strict=*/true))
    2914              :         return false;
    2915              :       break;
    2916              : 
    2917            0 :     case COMPLEX_TYPE:
    2918            0 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2919              :         return false;
    2920              :       break;
    2921              : 
    2922            0 :     case VECTOR_TYPE:
    2923            0 :       if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
    2924            0 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    2925            0 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    2926            0 :         return false;
    2927              :       break;
    2928              : 
    2929              :     default:
    2930              :       return false;
    2931              :     }
    2932              : 
    2933              :   /* If we get here, we know that from a target independent POV the
    2934              :      types are the same.  Make sure the target attributes are also
    2935              :      the same.  */
    2936            0 :   if (!comp_type_attributes (t1, t2))
    2937              :     return false;
    2938              : 
    2939              :   return true;
    2940              : }
    2941              : 
    2942              : // forked from gcc/cp/typeck.cc comptypes
    2943              : 
    2944              : /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
    2945              :    is a bitwise-or of the COMPARE_* flags.  */
    2946              : 
    2947              : bool
    2948           13 : comptypes (tree t1, tree t2, int strict)
    2949              : {
    2950           13 :   gcc_checking_assert (t1 && t2);
    2951              : 
    2952              :   /* TYPE_ARGUMENT_PACKS are not really types.  */
    2953           13 :   gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
    2954              :                        && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
    2955              : 
    2956           13 :   if (t1 == t2)
    2957              :     return true;
    2958              : 
    2959              :   /* Suppress errors caused by previously reported errors.  */
    2960            4 :   if (t1 == error_mark_node || t2 == error_mark_node)
    2961              :     return false;
    2962              : 
    2963            4 :   if (strict == COMPARE_STRICT)
    2964              :     {
    2965            4 :       if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
    2966              :         /* At least one of the types requires structural equality, so
    2967              :            perform a deep check. */
    2968            1 :         return structural_comptypes (t1, t2, strict);
    2969              : 
    2970            3 :       if (!flag_checking)
    2971            0 :         return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    2972              :       else
    2973            3 :         return structural_comptypes (t1, t2, strict);
    2974              :     }
    2975            0 :   else if (strict == COMPARE_STRUCTURAL)
    2976            0 :     return structural_comptypes (t1, t2, COMPARE_STRICT);
    2977              :   else
    2978            0 :     return structural_comptypes (t1, t2, strict);
    2979              : }
    2980              : 
    2981              : // forked from gcc/cp/decl.cc next_initializable_field
    2982              : 
    2983              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    2984              :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    2985              :    initialized.  If there are no more such fields, the return value
    2986              :    will be NULL.  */
    2987              : 
    2988              : tree
    2989            0 : next_initializable_field (tree field)
    2990              : {
    2991            0 :   while (field
    2992            0 :          && (TREE_CODE (field) != FIELD_DECL || DECL_UNNAMED_BIT_FIELD (field)
    2993            0 :              || (DECL_ARTIFICIAL (field)
    2994              :                  /* Don't skip vptr fields.  We might see them when we're
    2995              :                     called from reduced_constant_expression_p.  */
    2996            0 :                  && !DECL_VIRTUAL_P (field))))
    2997            0 :     field = DECL_CHAIN (field);
    2998              : 
    2999            0 :   return field;
    3000              : }
    3001              : 
    3002              : // forked from gcc/cp/call.cc sufficient_parms_p
    3003              : 
    3004              : /* Returns nonzero if PARMLIST consists of only default parms,
    3005              :    ellipsis, and/or undeduced parameter packs.  */
    3006              : 
    3007              : bool
    3008            0 : sufficient_parms_p (const_tree parmlist)
    3009              : {
    3010            0 :   for (; parmlist && parmlist != void_list_node;
    3011            0 :        parmlist = TREE_CHAIN (parmlist))
    3012            0 :     if (!TREE_PURPOSE (parmlist))
    3013              :       return false;
    3014              :   return true;
    3015              : }
    3016              : 
    3017              : // forked from gcc/cp/class.cc default_ctor_p
    3018              : 
    3019              : /* Returns true if FN is a default constructor.  */
    3020              : 
    3021              : bool
    3022            0 : default_ctor_p (const_tree fn)
    3023              : {
    3024            0 :   return (DECL_CONSTRUCTOR_P (fn)
    3025            0 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
    3026              : }
    3027              : 
    3028              : // forked from gcc/cp/class.cc user_provided_p
    3029              : 
    3030              : /* Returns true iff FN is a user-provided function, i.e. user-declared
    3031              :    and not defaulted at its first declaration.  */
    3032              : 
    3033              : bool
    3034            0 : user_provided_p (tree fn)
    3035              : {
    3036            0 :   return (!DECL_ARTIFICIAL (fn)
    3037            0 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    3038            0 :                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
    3039              : }
    3040              : 
    3041              : // forked from gcc/cp/class.cc type_has_non_user_provided_default_constructor
    3042              : 
    3043              : /* Returns true iff class T has a non-user-provided (i.e. implicitly
    3044              :    declared or explicitly defaulted in the class body) default
    3045              :    constructor.  */
    3046              : 
    3047              : bool
    3048            0 : type_has_non_user_provided_default_constructor (tree t)
    3049              : {
    3050            0 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    3051              :     return false;
    3052            0 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    3053              :     return true;
    3054              : 
    3055            0 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    3056              :     {
    3057            0 :       tree fn = *iter;
    3058            0 :       if (TREE_CODE (fn) == FUNCTION_DECL && default_ctor_p (fn)
    3059            0 :           && !user_provided_p (fn))
    3060            0 :         return true;
    3061              :     }
    3062              : 
    3063            0 :   return false;
    3064              : }
    3065              : 
    3066              : // forked from gcc/cp/class.cc default_init_uninitialized_part
    3067              : 
    3068              : /* If default-initialization leaves part of TYPE uninitialized, returns
    3069              :    a DECL for the field or TYPE itself (DR 253).  */
    3070              : 
    3071              : tree
    3072            0 : default_init_uninitialized_part (tree type)
    3073              : {
    3074            0 :   tree t, r, binfo;
    3075            0 :   int i;
    3076              : 
    3077            0 :   type = strip_array_types (type);
    3078            0 :   if (!CLASS_TYPE_P (type))
    3079              :     return type;
    3080            0 :   if (!type_has_non_user_provided_default_constructor (type))
    3081              :     return NULL_TREE;
    3082            0 :   for (binfo = TYPE_BINFO (type), i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
    3083              :     {
    3084            0 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    3085            0 :       if (r)
    3086              :         return r;
    3087              :     }
    3088            0 :   for (t = next_initializable_field (TYPE_FIELDS (type)); t;
    3089            0 :        t = next_initializable_field (DECL_CHAIN (t)))
    3090            0 :     if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
    3091              :       {
    3092            0 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    3093            0 :         if (r)
    3094            0 :           return DECL_P (r) ? r : t;
    3095              :       }
    3096              : 
    3097              :   return NULL_TREE;
    3098              : }
    3099              : 
    3100              : // forked from gcc/cp/name-lookup.cc extract_conversion_operator
    3101              : 
    3102              : /* FNS is an overload set of conversion functions.  Return the
    3103              :    overloads converting to TYPE.  */
    3104              : 
    3105              : static tree
    3106            0 : extract_conversion_operator (tree fns, tree type)
    3107              : {
    3108            0 :   tree convs = NULL_TREE;
    3109            0 :   tree tpls = NULL_TREE;
    3110              : 
    3111            0 :   for (ovl_iterator iter (fns); iter; ++iter)
    3112              :     {
    3113            0 :       if (same_type_p (DECL_CONV_FN_TYPE (*iter), type))
    3114            0 :         convs = lookup_add (*iter, convs);
    3115              :     }
    3116              : 
    3117            0 :   if (!convs)
    3118            0 :     convs = tpls;
    3119              : 
    3120            0 :   return convs;
    3121              : }
    3122              : 
    3123              : // forked from gcc/cp/name-lookup.cc
    3124              : 
    3125              : /* Look for NAME as an immediate member of KLASS (including
    3126              :    anon-members or unscoped enum member).  TYPE_OR_FNS is zero for
    3127              :    regular search.  >0 to get a type binding (if there is one) and <0
    3128              :    if you want (just) the member function binding.
    3129              : 
    3130              :    Use this if you do not want lazy member creation.  */
    3131              : 
    3132              : tree
    3133            0 : get_class_binding_direct (tree klass, tree name, bool want_type)
    3134              : {
    3135            0 :   gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass));
    3136              : 
    3137              :   /* Conversion operators can only be found by the marker conversion
    3138              :      operator name.  */
    3139            0 :   bool conv_op = IDENTIFIER_CONV_OP_P (name);
    3140            0 :   tree lookup = conv_op ? conv_op_identifier : name;
    3141            0 :   tree val = NULL_TREE;
    3142            0 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    3143              : 
    3144            0 :   if (COMPLETE_TYPE_P (klass) && member_vec)
    3145              :     {
    3146            0 :       val = member_vec_binary_search (member_vec, lookup);
    3147            0 :       if (!val)
    3148              :         ;
    3149            0 :       else if (STAT_HACK_P (val))
    3150            0 :         val = want_type ? STAT_TYPE (val) : STAT_DECL (val);
    3151            0 :       else if (want_type && !DECL_DECLARES_TYPE_P (val))
    3152            0 :         val = NULL_TREE;
    3153              :     }
    3154              :   else
    3155              :     {
    3156            0 :       if (member_vec && !want_type)
    3157            0 :         val = member_vec_linear_search (member_vec, lookup);
    3158              : 
    3159            0 :       if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val)))
    3160              :         /* Dependent using declarations are a 'field', make sure we
    3161              :            return that even if we saw an overload already.  */
    3162            0 :         if (tree field_val = fields_linear_search (klass, lookup, want_type))
    3163              :           {
    3164            0 :             if (!val)
    3165              :               val = field_val;
    3166            0 :             else if (TREE_CODE (field_val) == USING_DECL)
    3167            0 :               val = ovl_make (field_val, val);
    3168              :           }
    3169              :     }
    3170              : 
    3171              :   /* Extract the conversion operators asked for, unless the general
    3172              :      conversion operator was requested.   */
    3173            0 :   if (val && conv_op)
    3174              :     {
    3175            0 :       gcc_checking_assert (OVL_FUNCTION (val) == conv_op_marker);
    3176            0 :       val = OVL_CHAIN (val);
    3177            0 :       if (tree type = TREE_TYPE (name))
    3178            0 :         val = extract_conversion_operator (val, type);
    3179              :     }
    3180              : 
    3181            0 :   return val;
    3182              : }
    3183              : 
    3184              : #if defined ENABLE_TREE_CHECKING
    3185              : 
    3186              : // forked from gcc/cp/tree.cc lang_check_failed
    3187              : 
    3188              : /* Complain that some language-specific thing hanging off a tree
    3189              :    node has been accessed improperly.  */
    3190              : 
    3191              : void
    3192            0 : lang_check_failed (const char *file, int line, const char *function)
    3193              : {
    3194            0 :   internal_error ("%<lang_*%> check: failed in %s, at %s:%d", function,
    3195              :                   trim_filename (file), line);
    3196              : }
    3197              : #endif /* ENABLE_TREE_CHECKING */
    3198              : 
    3199              : // forked from gcc/cp/tree.cc skip_artificial_parms_for
    3200              : 
    3201              : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    3202              :    as there are artificial parms in FN.  */
    3203              : 
    3204              : tree
    3205            0 : skip_artificial_parms_for (const_tree fn, tree list)
    3206              : {
    3207            0 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
    3208            0 :     list = TREE_CHAIN (list);
    3209              :   else
    3210              :     return list;
    3211              : 
    3212            0 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    3213            0 :     list = TREE_CHAIN (list);
    3214            0 :   if (DECL_HAS_VTT_PARM_P (fn))
    3215            0 :     list = TREE_CHAIN (list);
    3216              :   return list;
    3217              : }
    3218              : 
    3219              : // forked from gcc/cp/class.cc in_class_defaulted_default_constructor
    3220              : 
    3221              : /* Returns the defaulted constructor if T has one. Otherwise, returns
    3222              :    NULL_TREE.  */
    3223              : 
    3224              : tree
    3225            0 : in_class_defaulted_default_constructor (tree t)
    3226              : {
    3227            0 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    3228              :     return NULL_TREE;
    3229              : 
    3230            0 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    3231              :     {
    3232            0 :       tree fn = *iter;
    3233              : 
    3234            0 :       if (DECL_DEFAULTED_IN_CLASS_P (fn) && default_ctor_p (fn))
    3235            0 :         return fn;
    3236              :     }
    3237              : 
    3238            0 :   return NULL_TREE;
    3239              : }
    3240              : 
    3241              : // forked from gcc/cp/constexpr.cc
    3242              : 
    3243              : /* Returns true iff FUN is an instantiation of a constexpr function
    3244              :    template or a defaulted constexpr function.  */
    3245              : 
    3246              : bool
    3247            0 : is_instantiation_of_constexpr (tree fun)
    3248              : {
    3249            0 :   return ((DECL_DEFAULTED_FN (fun) && DECL_DECLARED_CONSTEXPR_P (fun)));
    3250              : }
    3251              : 
    3252              : // forked from gcc/cp/decl.cc check_for_uninitialized_const_var
    3253              : 
    3254              : /* Issue an error message if DECL is an uninitialized const variable.
    3255              :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    3256              :    context from potential_constant_expression.  Returns true if all is well,
    3257              :    false otherwise.  */
    3258              : 
    3259              : bool
    3260            0 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    3261              :                                    tsubst_flags_t complain)
    3262              : {
    3263            0 :   tree type = strip_array_types (TREE_TYPE (decl));
    3264              : 
    3265              :   /* ``Unless explicitly declared extern, a const object does not have
    3266              :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    3267              :      7.1.6 */
    3268            0 :   if (VAR_P (decl) && !TYPE_REF_P (type) && (RS_TYPE_CONST_P (type))
    3269            0 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    3270              :     {
    3271            0 :       tree field = default_init_uninitialized_part (type);
    3272            0 :       if (!field)
    3273              :         return true;
    3274              : 
    3275            0 :       bool show_notes = true;
    3276              : 
    3277            0 :       if (!constexpr_context_p)
    3278              :         {
    3279            0 :           if (RS_TYPE_CONST_P (type))
    3280              :             {
    3281            0 :               if (complain & tf_error)
    3282            0 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    3283              :                                         "uninitialized %<const %D%>", decl);
    3284              :             }
    3285              :           else
    3286              :             {
    3287            0 :               if (!is_instantiation_of_constexpr (current_function_decl)
    3288            0 :                   && (complain & tf_error))
    3289            0 :                 error_at (DECL_SOURCE_LOCATION (decl),
    3290              :                           "uninitialized variable %qD in %<constexpr%> "
    3291              :                           "function",
    3292              :                           decl);
    3293              :               else
    3294              :                 show_notes = false;
    3295              :             }
    3296              :         }
    3297            0 :       else if (complain & tf_error)
    3298            0 :         error_at (DECL_SOURCE_LOCATION (decl),
    3299              :                   "uninitialized variable %qD in %<constexpr%> context", decl);
    3300              : 
    3301            0 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    3302              :         {
    3303              :           // tree defaulted_ctor;
    3304              : 
    3305              :           // inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    3306              :           //         "%q#T has no user-provided default constructor", type);
    3307              :           // defaulted_ctor = in_class_defaulted_default_constructor (type);
    3308              :           // if (defaulted_ctor)
    3309              :           //   inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    3310              :           //           "constructor is not user-provided because it is "
    3311              :           //           "explicitly defaulted in the class body");
    3312              :           // inform (DECL_SOURCE_LOCATION (field),
    3313              :           //         "and the implicitly-defined constructor does not "
    3314              :           //         "initialize %q#D",
    3315              :           //         field);
    3316              :         }
    3317              : 
    3318            0 :       return false;
    3319              :     }
    3320              : 
    3321              :   return true;
    3322              : }
    3323              : 
    3324              : // forked from gcc/cp/tree.cc cv_unqualified
    3325              : 
    3326              : /* Return TYPE with const and volatile removed.  */
    3327              : 
    3328              : tree
    3329            3 : cv_unqualified (tree type)
    3330              : {
    3331            3 :   int quals;
    3332              : 
    3333            3 :   if (type == error_mark_node)
    3334              :     return type;
    3335              : 
    3336            3 :   quals = rs_type_quals (type);
    3337            3 :   quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    3338            3 :   return rs_build_qualified_type (type, quals);
    3339              : }
    3340              : 
    3341              : /* The C and C++ parsers both use vectors to hold function arguments.
    3342              :    For efficiency, we keep a cache of unused vectors.  This is the
    3343              :    cache.  */
    3344              : 
    3345              : typedef vec<tree, va_gc> *tree_gc_vec;
    3346              : static GTY ((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
    3347              : 
    3348              : // forked from gcc/c-family/c-common.c make_tree_vector
    3349              : 
    3350              : /* Return a new vector from the cache.  If the cache is empty,
    3351              :    allocate a new vector.  These vectors are GC'ed, so it is OK if the
    3352              :    pointer is not released..  */
    3353              : 
    3354              : vec<tree, va_gc> *
    3355         8628 : make_tree_vector (void)
    3356              : {
    3357         8628 :   if (tree_vector_cache && !tree_vector_cache->is_empty ())
    3358         6195 :     return tree_vector_cache->pop ();
    3359              :   else
    3360              :     {
    3361              :       /* Passing 0 to vec::alloc returns NULL, and our callers require
    3362              :          that we always return a non-NULL value.  The vector code uses
    3363              :          4 when growing a NULL vector, so we do too.  */
    3364         2433 :       vec<tree, va_gc> *v;
    3365         2433 :       vec_alloc (v, 4);
    3366         2433 :       return v;
    3367              :     }
    3368              : }
    3369              : 
    3370              : // forked from gcc/c-family/c-common.c release_tree_vector
    3371              : 
    3372              : /* Release a vector of trees back to the cache.  */
    3373              : 
    3374              : void
    3375         8628 : release_tree_vector (vec<tree, va_gc> *vec)
    3376              : {
    3377         8628 :   if (vec != NULL)
    3378              :     {
    3379         8628 :       if (vec->allocated () >= 16)
    3380              :         /* Don't cache vecs that have expanded more than once.  On a p64
    3381              :            target, vecs double in alloc size with each power of 2 elements, e.g
    3382              :            at 16 elements the alloc increases from 128 to 256 bytes.  */
    3383            0 :         vec_free (vec);
    3384              :       else
    3385              :         {
    3386         8628 :           vec->truncate (0);
    3387         8628 :           vec_safe_push (tree_vector_cache, vec);
    3388              :         }
    3389              :     }
    3390         8628 : }
    3391              : 
    3392              : // forked from gcc/cp/cvt.cc instantiation_dependent_expression_p
    3393              : 
    3394              : /* As above, but also check value-dependence of the expression as a whole.  */
    3395              : 
    3396              : bool
    3397            0 : instantiation_dependent_expression_p (tree)
    3398              : {
    3399            0 :   return false;
    3400              : }
    3401              : 
    3402              : // forked from gcc/cp/cvt.cc cp_get_callee
    3403              : 
    3404              : /* If CALL is a call, return the callee; otherwise null.  */
    3405              : 
    3406              : tree
    3407            0 : cp_get_callee (tree call)
    3408              : {
    3409            0 :   if (call == NULL_TREE)
    3410              :     return call;
    3411            0 :   else if (TREE_CODE (call) == CALL_EXPR)
    3412            0 :     return CALL_EXPR_FN (call);
    3413              :   return NULL_TREE;
    3414              : }
    3415              : 
    3416              : // forked from gcc/cp/typeck.cc build_nop
    3417              : 
    3418              : /* Return a NOP_EXPR converting EXPR to TYPE.  */
    3419              : 
    3420              : tree
    3421            0 : build_nop (tree type, tree expr)
    3422              : {
    3423            0 :   if (type == error_mark_node || error_operand_p (expr))
    3424              :     return expr;
    3425            0 :   return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr);
    3426              : }
    3427              : 
    3428              : // forked from gcc/cp/tree.cc scalarish_type_p
    3429              : 
    3430              : /* Returns 1 iff type T is something we want to treat as a scalar type for
    3431              :    the purpose of deciding whether it is trivial/POD/standard-layout.  */
    3432              : 
    3433              : bool
    3434            3 : scalarish_type_p (const_tree t)
    3435              : {
    3436            3 :   if (t == error_mark_node)
    3437              :     return 1;
    3438              : 
    3439            3 :   return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
    3440              : }
    3441              : 
    3442              : // forked from gcc/cp/tree.cc type_has_nontrivial_copy_init
    3443              : 
    3444              : /* Returns true iff copying an object of type T (including via move
    3445              :    constructor) is non-trivial.  That is, T has no non-trivial copy
    3446              :    constructors and no non-trivial move constructors, and not all copy/move
    3447              :    constructors are deleted.  This function implements the ABI notion of
    3448              :    non-trivial copy, which has diverged from the one in the standard.  */
    3449              : 
    3450              : bool
    3451            0 : type_has_nontrivial_copy_init (const_tree)
    3452              : {
    3453            0 :   return false;
    3454              : }
    3455              : 
    3456              : // forked from gcc/cp/tree.cc build_local_temp
    3457              : 
    3458              : /* Return an undeclared local temporary of type TYPE for use in building a
    3459              :    TARGET_EXPR.  */
    3460              : 
    3461              : tree
    3462            0 : build_local_temp (tree type)
    3463              : {
    3464            0 :   tree slot = build_decl (input_location, VAR_DECL, NULL_TREE, type);
    3465            0 :   DECL_ARTIFICIAL (slot) = 1;
    3466            0 :   DECL_IGNORED_P (slot) = 1;
    3467            0 :   DECL_CONTEXT (slot) = current_function_decl;
    3468            0 :   layout_decl (slot, 0);
    3469            0 :   return slot;
    3470              : }
    3471              : 
    3472              : // forked from gcc/cp/lambda.cc is_normal_capture_proxy
    3473              : 
    3474              : /* Returns true iff DECL is a capture proxy for a normal capture
    3475              :    (i.e. without explicit initializer).  */
    3476              : 
    3477              : bool
    3478            0 : is_normal_capture_proxy (tree)
    3479              : {
    3480            0 :   return false;
    3481              : }
    3482              : 
    3483              : // forked from gcc/cp/c-common.cc reject_gcc_builtin
    3484              : 
    3485              : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
    3486              :    with no library fallback or for an ADDR_EXPR whose operand is such type
    3487              :    issues an error pointing to the location LOC.
    3488              :    Returns true when the expression has been diagnosed and false
    3489              :    otherwise.  */
    3490              : 
    3491              : bool
    3492            0 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
    3493              : {
    3494            0 :   if (TREE_CODE (expr) == ADDR_EXPR)
    3495            0 :     expr = TREE_OPERAND (expr, 0);
    3496              : 
    3497            0 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    3498              : 
    3499            0 :   if (TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
    3500            0 :       && TREE_CODE (expr) == FUNCTION_DECL
    3501              :       /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
    3502              :          false positives for user-declared built-ins such as abs or
    3503              :          strlen, and for C++ operators new and delete.
    3504              :          The c_decl_implicit() test avoids false positives for implicitly
    3505              :          declared built-ins with library fallbacks (such as abs).  */
    3506            0 :       && fndecl_built_in_p (expr) && DECL_IS_UNDECLARED_BUILTIN (expr)
    3507            0 :       && !DECL_ASSEMBLER_NAME_SET_P (expr))
    3508              :     {
    3509            0 :       if (loc == UNKNOWN_LOCATION)
    3510            0 :         loc = EXPR_LOC_OR_LOC (expr, input_location);
    3511              : 
    3512              :       /* Reject arguments that are built-in functions with
    3513              :          no library fallback.  */
    3514            0 :       error_at (loc, "built-in function %qE must be directly called", expr);
    3515              : 
    3516            0 :       return true;
    3517              :     }
    3518              : 
    3519              :   return false;
    3520              : }
    3521              : 
    3522              : // forked from gcc/cp/typeck.cc is_bitfield_expr_with_lowered_type
    3523              : 
    3524              : /* If EXP is a reference to a bit-field, and the type of EXP does not
    3525              :    match the declared type of the bit-field, return the declared type
    3526              :    of the bit-field.  Otherwise, return NULL_TREE.  */
    3527              : 
    3528              : tree
    3529            0 : is_bitfield_expr_with_lowered_type (const_tree exp)
    3530              : {
    3531            0 :   switch (TREE_CODE (exp))
    3532              :     {
    3533            0 :     case COND_EXPR:
    3534            0 :       if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
    3535            0 :                                                  ? TREE_OPERAND (exp, 1)
    3536            0 :                                                  : TREE_OPERAND (exp, 0)))
    3537              :         return NULL_TREE;
    3538            0 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
    3539              : 
    3540            0 :     case COMPOUND_EXPR:
    3541            0 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
    3542              : 
    3543            0 :     case MODIFY_EXPR:
    3544            0 :     case SAVE_EXPR:
    3545            0 :     case UNARY_PLUS_EXPR:
    3546            0 :     case PREDECREMENT_EXPR:
    3547            0 :     case PREINCREMENT_EXPR:
    3548            0 :     case POSTDECREMENT_EXPR:
    3549            0 :     case POSTINCREMENT_EXPR:
    3550            0 :     case NEGATE_EXPR:
    3551            0 :     case NON_LVALUE_EXPR:
    3552            0 :     case BIT_NOT_EXPR:
    3553            0 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    3554              : 
    3555            0 :     case COMPONENT_REF:
    3556            0 :       {
    3557            0 :         tree field;
    3558              : 
    3559            0 :         field = TREE_OPERAND (exp, 1);
    3560            0 :         if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
    3561              :           return NULL_TREE;
    3562            0 :         if (same_type_ignoring_top_level_qualifiers_p (
    3563            0 :               TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
    3564              :           return NULL_TREE;
    3565            0 :         return DECL_BIT_FIELD_TYPE (field);
    3566              :       }
    3567              : 
    3568            0 :     case VAR_DECL:
    3569            0 :       if (DECL_HAS_VALUE_EXPR_P (exp))
    3570            0 :         return is_bitfield_expr_with_lowered_type (
    3571            0 :           DECL_VALUE_EXPR (const_cast<tree> (exp)));
    3572              :       return NULL_TREE;
    3573              : 
    3574            0 :     case VIEW_CONVERT_EXPR:
    3575            0 :       if (location_wrapper_p (exp))
    3576            0 :         return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    3577              :       else
    3578              :         return NULL_TREE;
    3579              : 
    3580              :     default:
    3581              :       return NULL_TREE;
    3582              :     }
    3583              : }
    3584              : 
    3585              : // forked from gcc/cp/semantics.cc maybe_undo_parenthesized_ref
    3586              : 
    3587              : /* If T is an id-expression obfuscated by force_paren_expr, undo the
    3588              :    obfuscation and return the underlying id-expression.  Otherwise
    3589              :    return T.  */
    3590              : 
    3591              : tree
    3592            0 : maybe_undo_parenthesized_ref (tree t)
    3593              : {
    3594            0 :   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
    3595            0 :       && REF_PARENTHESIZED_P (t))
    3596            0 :     t = TREE_OPERAND (t, 0);
    3597              : 
    3598            0 :   return t;
    3599              : }
    3600              : 
    3601              : // forked from gcc/c-family/c-common.cc fold_offsetof
    3602              : 
    3603              : /* Fold an offsetof-like expression.  EXPR is a nested sequence of component
    3604              :    references with an INDIRECT_REF of a constant at the bottom; much like the
    3605              :    traditional rendering of offsetof as a macro.  TYPE is the desired type of
    3606              :    the whole expression.  Return the folded result.  */
    3607              : 
    3608              : tree
    3609            0 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
    3610              : {
    3611            0 :   tree base, off, t;
    3612            0 :   tree_code code = TREE_CODE (expr);
    3613            0 :   switch (code)
    3614              :     {
    3615              :     case ERROR_MARK:
    3616              :       return expr;
    3617              : 
    3618            0 :     case VAR_DECL:
    3619            0 :       error ("cannot apply %<offsetof%> to static data member %qD", expr);
    3620            0 :       return error_mark_node;
    3621              : 
    3622            0 :     case CALL_EXPR:
    3623            0 :     case TARGET_EXPR:
    3624            0 :       error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
    3625            0 :       return error_mark_node;
    3626              : 
    3627            0 :     case NOP_EXPR:
    3628            0 :     case INDIRECT_REF:
    3629            0 :       if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
    3630              :         {
    3631            0 :           error ("cannot apply %<offsetof%> to a non constant address");
    3632            0 :           return error_mark_node;
    3633              :         }
    3634            0 :       return convert (type, TREE_OPERAND (expr, 0));
    3635              : 
    3636            0 :     case COMPONENT_REF:
    3637            0 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    3638            0 :       if (base == error_mark_node)
    3639              :         return base;
    3640              : 
    3641            0 :       t = TREE_OPERAND (expr, 1);
    3642            0 :       if (DECL_C_BIT_FIELD (t))
    3643              :         {
    3644            0 :           error ("attempt to take address of bit-field structure "
    3645              :                  "member %qD",
    3646              :                  t);
    3647            0 :           return error_mark_node;
    3648              :         }
    3649            0 :       off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
    3650            0 :                             size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
    3651              :                                       / BITS_PER_UNIT));
    3652            0 :       break;
    3653              : 
    3654            0 :     case ARRAY_REF:
    3655            0 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    3656            0 :       if (base == error_mark_node)
    3657              :         return base;
    3658              : 
    3659            0 :       t = TREE_OPERAND (expr, 1);
    3660            0 :       STRIP_ANY_LOCATION_WRAPPER (t);
    3661              : 
    3662              :       /* Check if the offset goes beyond the upper bound of the array.  */
    3663            0 :       if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
    3664              :         {
    3665            0 :           tree upbound = array_ref_up_bound (expr);
    3666            0 :           if (upbound != NULL_TREE && TREE_CODE (upbound) == INTEGER_CST
    3667            0 :               && !tree_int_cst_equal (upbound,
    3668            0 :                                       TYPE_MAX_VALUE (TREE_TYPE (upbound))))
    3669              :             {
    3670            0 :               if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
    3671            0 :                 upbound = size_binop (PLUS_EXPR, upbound,
    3672              :                                       build_int_cst (TREE_TYPE (upbound), 1));
    3673            0 :               if (tree_int_cst_lt (upbound, t))
    3674              :                 {
    3675            0 :                   tree v;
    3676              : 
    3677            0 :                   for (v = TREE_OPERAND (expr, 0);
    3678            0 :                        TREE_CODE (v) == COMPONENT_REF; v = TREE_OPERAND (v, 0))
    3679            0 :                     if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
    3680              :                         == RECORD_TYPE)
    3681              :                       {
    3682            0 :                         tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
    3683            0 :                         for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
    3684            0 :                           if (TREE_CODE (fld_chain) == FIELD_DECL)
    3685              :                             break;
    3686              : 
    3687              :                         if (fld_chain)
    3688              :                           break;
    3689              :                       }
    3690              :                   /* Don't warn if the array might be considered a poor
    3691              :                      man's flexible array member with a very permissive
    3692              :                      definition thereof.  */
    3693            0 :                   if (TREE_CODE (v) == ARRAY_REF
    3694            0 :                       || TREE_CODE (v) == COMPONENT_REF)
    3695            0 :                     warning (OPT_Warray_bounds_,
    3696              :                              "index %E denotes an offset "
    3697              :                              "greater than size of %qT",
    3698            0 :                              t, TREE_TYPE (TREE_OPERAND (expr, 0)));
    3699              :                 }
    3700              :             }
    3701              :         }
    3702              : 
    3703            0 :       t = convert (sizetype, t);
    3704            0 :       off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
    3705            0 :       break;
    3706              : 
    3707            0 :     case COMPOUND_EXPR:
    3708              :       /* Handle static members of volatile structs.  */
    3709            0 :       t = TREE_OPERAND (expr, 1);
    3710            0 :       gcc_checking_assert (VAR_P (get_base_address (t)));
    3711              :       return fold_offsetof (t, type);
    3712              : 
    3713            0 :     default:
    3714            0 :       rust_unreachable ();
    3715              :     }
    3716              : 
    3717            0 :   if (!POINTER_TYPE_P (type))
    3718            0 :     return size_binop (PLUS_EXPR, base, convert (type, off));
    3719            0 :   return fold_build_pointer_plus (base, off);
    3720              : }
    3721              : 
    3722              : // forked from gcc/cp/tree.cc char_type_p
    3723              : 
    3724              : /* Returns nonzero if TYPE is a character type, including wchar_t.  */
    3725              : 
    3726              : int
    3727            0 : char_type_p (tree type)
    3728              : {
    3729            0 :   return (same_type_p (type, char_type_node)
    3730            0 :           || same_type_p (type, unsigned_char_type_node)
    3731            0 :           || same_type_p (type, signed_char_type_node)
    3732            0 :           || same_type_p (type, char8_type_node)
    3733            0 :           || same_type_p (type, char16_type_node)
    3734            0 :           || same_type_p (type, char32_type_node)
    3735            0 :           || same_type_p (type, wchar_type_node));
    3736              : }
    3737              : 
    3738              : // forked from gcc/cp/pt.cc resolve_nondeduced_context
    3739              : 
    3740              : /* Core DR 115: In contexts where deduction is done and fails, or in
    3741              :    contexts where deduction is not done, if a template argument list is
    3742              :    specified and it, along with any default template arguments, identifies
    3743              :    a single function template specialization, then the template-id is an
    3744              :    lvalue for the function template specialization.  */
    3745              : 
    3746              : tree
    3747            0 : resolve_nondeduced_context (tree orig_expr, tsubst_flags_t)
    3748              : {
    3749            0 :   return orig_expr;
    3750              : }
    3751              : 
    3752              : // forked from gcc/cp/pt.cc instantiate_non_dependent_or_null
    3753              : 
    3754              : /* Like instantiate_non_dependent_expr, but return NULL_TREE rather than
    3755              :    an uninstantiated expression.  */
    3756              : 
    3757              : tree
    3758            0 : instantiate_non_dependent_or_null (tree expr)
    3759              : {
    3760            0 :   if (expr == NULL_TREE)
    3761              :     return NULL_TREE;
    3762              : 
    3763              :   return expr;
    3764              : }
    3765              : 
    3766              : // forked from gcc/cp/pt.cc resolve_nondeduced_context_or_error
    3767              : 
    3768              : /* As above, but error out if the expression remains overloaded.  */
    3769              : 
    3770              : tree
    3771            0 : resolve_nondeduced_context_or_error (tree exp, tsubst_flags_t complain)
    3772              : {
    3773            0 :   exp = resolve_nondeduced_context (exp, complain);
    3774            0 :   if (type_unknown_p (exp))
    3775              :     {
    3776            0 :       if (complain & tf_error)
    3777            0 :         cxx_incomplete_type_error (exp, TREE_TYPE (exp));
    3778            0 :       return error_mark_node;
    3779              :     }
    3780              :   return exp;
    3781              : }
    3782              : 
    3783              : // forked from gcc/cp/tree.cc really_overloaded_fn
    3784              : 
    3785              : /* Returns true iff X is an expression for an overloaded function
    3786              :    whose type cannot be known without performing overload
    3787              :    resolution.  */
    3788              : 
    3789              : bool
    3790            0 : really_overloaded_fn (tree x)
    3791              : {
    3792            0 :   return is_overloaded_fn (x) == 2;
    3793              : }
    3794              : 
    3795              : // forked from gcc/cp/typeck..cc invalid_nonstatic_memfn_p
    3796              : 
    3797              : /* EXPR is being used in a context that is not a function call.
    3798              :    Enforce:
    3799              : 
    3800              :      [expr.ref]
    3801              : 
    3802              :      The expression can be used only as the left-hand operand of a
    3803              :      member function call.
    3804              : 
    3805              :      [expr.mptr.operator]
    3806              : 
    3807              :      If the result of .* or ->* is a function, then that result can be
    3808              :      used only as the operand for the function call operator ().
    3809              : 
    3810              :    by issuing an error message if appropriate.  Returns true iff EXPR
    3811              :    violates these rules.  */
    3812              : 
    3813              : bool
    3814            0 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
    3815              : {
    3816            0 :   if (expr == NULL_TREE)
    3817              :     return false;
    3818              :   /* Don't enforce this in MS mode.  */
    3819            0 :   if (flag_ms_extensions)
    3820              :     return false;
    3821            0 :   if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
    3822            0 :     expr = get_first_fn (expr);
    3823            0 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr))
    3824              :     {
    3825            0 :       if (complain & tf_error)
    3826              :         {
    3827            0 :           if (DECL_P (expr))
    3828              :             {
    3829            0 :               error_at (loc, "invalid use of non-static member function %qD",
    3830              :                         expr);
    3831            0 :               inform (DECL_SOURCE_LOCATION (expr), "declared here");
    3832              :             }
    3833              :           else
    3834            0 :             error_at (loc,
    3835              :                       "invalid use of non-static member function of "
    3836              :                       "type %qT",
    3837            0 :                       TREE_TYPE (expr));
    3838              :         }
    3839            0 :       return true;
    3840              :     }
    3841              :   return false;
    3842              : }
    3843              : 
    3844              : // forked from gcc/cp/call.cc strip_top_quals
    3845              : 
    3846              : tree
    3847            0 : strip_top_quals (tree t)
    3848              : {
    3849            0 :   if (TREE_CODE (t) == ARRAY_TYPE)
    3850              :     return t;
    3851            0 :   return rs_build_qualified_type (t, 0);
    3852              : }
    3853              : 
    3854              : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_inform
    3855              : 
    3856              : /* Print an inform about the declaration of the incomplete type TYPE.  */
    3857              : 
    3858              : // void
    3859              : // cxx_incomplete_type_inform (const_tree type)
    3860              : // {
    3861              : //   if (!TYPE_MAIN_DECL (type))
    3862              : //     return;
    3863              : 
    3864              : //   location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
    3865              : //   tree ptype = strip_top_quals (const_cast<tree> (type));
    3866              : 
    3867              : //   if (current_class_type && TYPE_BEING_DEFINED (current_class_type)
    3868              : //       && same_type_p (ptype, current_class_type))
    3869              : //     inform (loc,
    3870              : //          "definition of %q#T is not complete until "
    3871              : //          "the closing brace",
    3872              : //          ptype);
    3873              : //   else
    3874              : //     inform (loc, "forward declaration of %q#T", ptype);
    3875              : // }
    3876              : 
    3877              : // forked from gcc/cp/typeck2.cc cxx_incomplete_type_diagnostic
    3878              : 
    3879              : /* Print an error message for invalid use of an incomplete type.
    3880              :    VALUE is the expression that was used (or 0 if that isn't known)
    3881              :    and TYPE is the type that was invalid.  DIAG_KIND indicates the
    3882              :    type of diagnostic (see diagnostics/kinds.def).  */
    3883              : 
    3884              : void
    3885            0 : cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
    3886              :                                 const_tree type,
    3887              :                                 enum diagnostics::kind diag_kind)
    3888              : {
    3889              :   //  bool is_decl = false, complained = false;
    3890              : 
    3891            0 :   gcc_assert (diag_kind == diagnostics::kind::warning
    3892              :               || diag_kind == diagnostics::kind::pedwarn
    3893              :               || diag_kind == diagnostics::kind::error);
    3894              : 
    3895              :   /* Avoid duplicate error message.  */
    3896            0 :   if (TREE_CODE (type) == ERROR_MARK)
    3897              :     return;
    3898              : 
    3899            0 :   if (value)
    3900              :     {
    3901            0 :       STRIP_ANY_LOCATION_WRAPPER (value);
    3902              : 
    3903            0 :       if (VAR_P (value) || TREE_CODE (value) == PARM_DECL
    3904              :           || TREE_CODE (value) == FIELD_DECL)
    3905              :         {
    3906              :           // complained = emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION
    3907              :           // (value),
    3908              :           //                            0, "%qD has incomplete type", value);
    3909              :           // is_decl = true;
    3910              :         }
    3911              :     }
    3912            0 : retry:
    3913              :   /* We must print an error message.  Be clever about what it says.  */
    3914              : 
    3915            0 :   switch (TREE_CODE (type))
    3916              :     {
    3917              :       // case RECORD_TYPE:
    3918              :       // case UNION_TYPE:
    3919              :       // case ENUMERAL_TYPE:
    3920              :       //   if (!is_decl)
    3921              :       //     complained
    3922              :       //       = emit_diagnostic (diag_kind, loc, 0,
    3923              :       //                     "invalid use of incomplete type %q#T", type);
    3924              :       //   if (complained)
    3925              :       //     cxx_incomplete_type_inform (type);
    3926              :       //   break;
    3927              : 
    3928            0 :     case VOID_TYPE:
    3929            0 :       emit_diagnostic (diag_kind, loc, 0, "invalid use of %qT", type);
    3930            0 :       break;
    3931              : 
    3932            0 :     case ARRAY_TYPE:
    3933            0 :       if (TYPE_DOMAIN (type))
    3934              :         {
    3935            0 :           type = TREE_TYPE (type);
    3936            0 :           goto retry;
    3937              :         }
    3938            0 :       emit_diagnostic (diag_kind, loc, 0,
    3939              :                        "invalid use of array with unspecified bounds");
    3940            0 :       break;
    3941              : 
    3942            0 :     case OFFSET_TYPE:
    3943            0 :     bad_member:
    3944            0 :       {
    3945            0 :         tree member = TREE_OPERAND (value, 1);
    3946            0 :         if (is_overloaded_fn (member))
    3947            0 :           member = get_first_fn (member);
    3948              : 
    3949            0 :         if (DECL_FUNCTION_MEMBER_P (member) && !flag_ms_extensions)
    3950              :           {
    3951            0 :             gcc_rich_location richloc (loc);
    3952              :             /* If "member" has no arguments (other than "this"), then
    3953              :                add a fix-it hint.  */
    3954            0 :             if (type_num_arguments (TREE_TYPE (member)) == 1)
    3955            0 :               richloc.add_fixit_insert_after ("()");
    3956            0 :             emit_diagnostic (diag_kind, &richloc, 0,
    3957              :                              "invalid use of member function %qD "
    3958              :                              "(did you forget the %<()%> ?)",
    3959              :                              member);
    3960            0 :           }
    3961              :         else
    3962            0 :           emit_diagnostic (diag_kind, loc, 0,
    3963              :                            "invalid use of member %qD "
    3964              :                            "(did you forget the %<&%> ?)",
    3965              :                            member);
    3966              :       }
    3967              :       break;
    3968              : 
    3969            0 :     case LANG_TYPE:
    3970            0 :       if (type == init_list_type_node)
    3971              :         {
    3972            0 :           emit_diagnostic (diag_kind, loc, 0,
    3973              :                            "invalid use of brace-enclosed initializer list");
    3974            0 :           break;
    3975              :         }
    3976            0 :       gcc_assert (type == unknown_type_node);
    3977            0 :       if (value && TREE_CODE (value) == COMPONENT_REF)
    3978            0 :         goto bad_member;
    3979            0 :       else if (value && TREE_CODE (value) == ADDR_EXPR)
    3980            0 :         emit_diagnostic (diag_kind, loc, 0,
    3981              :                          "address of overloaded function with no contextual "
    3982              :                          "type information");
    3983            0 :       else if (value && TREE_CODE (value) == OVERLOAD)
    3984            0 :         emit_diagnostic (
    3985            0 :           diag_kind, loc, 0,
    3986              :           "overloaded function with no contextual type information");
    3987              :       else
    3988            0 :         emit_diagnostic (
    3989            0 :           diag_kind, loc, 0,
    3990              :           "insufficient contextual information to determine type");
    3991              :       break;
    3992              : 
    3993            0 :     default:
    3994            0 :       rust_unreachable ();
    3995              :     }
    3996              : }
    3997              : 
    3998              : // forked from gcc/cp/decl2.cc decl_constant_var_p
    3999              : 
    4000              : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
    4001              : 
    4002              :       [expr.const]
    4003              : 
    4004              :       An integral constant-expression can only involve ... const
    4005              :       variables of integral or enumeration types initialized with
    4006              :       constant expressions ...
    4007              : 
    4008              :       C++0x also allows constexpr variables and temporaries initialized
    4009              :       with constant expressions.  We handle the former here, but the latter
    4010              :       are just folded away in cxx_eval_constant_expression.
    4011              : 
    4012              :    The standard does not require that the expression be non-volatile.
    4013              :    G++ implements the proposed correction in DR 457.  */
    4014              : 
    4015              : bool
    4016            0 : decl_constant_var_p (tree decl)
    4017              : {
    4018            0 :   if (!decl_maybe_constant_var_p (decl))
    4019              :     return false;
    4020              : 
    4021            0 :   return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
    4022              : }
    4023              : 
    4024              : // forked from gcc/cp/decl.cc undeduced_auto_decl
    4025              : 
    4026              : /* Returns true iff DECL is a variable or function declared with an auto type
    4027              :    that has not yet been deduced to a real type.  */
    4028              : 
    4029              : bool
    4030            0 : undeduced_auto_decl (tree)
    4031              : {
    4032            0 :   return false;
    4033              : }
    4034              : 
    4035              : // forked from gcc/cp/decl.cc require_deduced_type
    4036              : 
    4037              : /* Complain if DECL has an undeduced return type.  */
    4038              : 
    4039              : bool
    4040            0 : require_deduced_type (tree, tsubst_flags_t)
    4041              : {
    4042            0 :   return true;
    4043              : }
    4044              : 
    4045              : /* Return the location of a tree passed to %+ formats.  */
    4046              : 
    4047              : location_t
    4048            0 : location_of (tree t)
    4049              : {
    4050            0 :   if (TYPE_P (t))
    4051              :     {
    4052            0 :       t = TYPE_MAIN_DECL (t);
    4053            0 :       if (t == NULL_TREE)
    4054            0 :         return input_location;
    4055              :     }
    4056            0 :   else if (TREE_CODE (t) == OVERLOAD)
    4057            0 :     t = OVL_FIRST (t);
    4058              : 
    4059            0 :   if (DECL_P (t))
    4060            0 :     return DECL_SOURCE_LOCATION (t);
    4061              : 
    4062            0 :   return EXPR_LOCATION (t);
    4063              : }
    4064              : 
    4065              : /* For element type ELT_TYPE, return the appropriate type of the heap object
    4066              :    containing such element(s).  COOKIE_SIZE is NULL or the size of cookie
    4067              :    in bytes.  FULL_SIZE is NULL if it is unknown how big the heap allocation
    4068              :    will be, otherwise size of the heap object.  If COOKIE_SIZE is NULL,
    4069              :    return array type ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
    4070              :    struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
    4071              :    where N is nothing (flexible array member) if FULL_SIZE is NULL, otherwise
    4072              :    it is computed such that the size of the struct fits into FULL_SIZE.  */
    4073              : 
    4074              : tree
    4075            0 : build_new_constexpr_heap_type (tree elt_type, tree cookie_size, tree full_size)
    4076              : {
    4077            0 :   gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size));
    4078            0 :   gcc_assert (full_size == NULL_TREE || tree_fits_uhwi_p (full_size));
    4079            0 :   unsigned HOST_WIDE_INT csz = cookie_size ? tree_to_uhwi (cookie_size) : 0;
    4080            0 :   tree itype2 = NULL_TREE;
    4081            0 :   if (full_size)
    4082              :     {
    4083            0 :       unsigned HOST_WIDE_INT fsz = tree_to_uhwi (full_size);
    4084            0 :       gcc_assert (fsz >= csz);
    4085            0 :       fsz -= csz;
    4086            0 :       fsz /= int_size_in_bytes (elt_type);
    4087            0 :       itype2 = build_index_type (size_int (fsz - 1));
    4088            0 :       if (!cookie_size)
    4089            0 :         return build_cplus_array_type (elt_type, itype2);
    4090              :     }
    4091              :   else
    4092            0 :     gcc_assert (cookie_size);
    4093            0 :   csz /= int_size_in_bytes (sizetype);
    4094            0 :   tree itype1 = build_index_type (size_int (csz - 1));
    4095            0 :   tree atype1 = build_cplus_array_type (sizetype, itype1);
    4096            0 :   tree atype2 = build_cplus_array_type (elt_type, itype2);
    4097            0 :   tree rtype = cxx_make_type (RECORD_TYPE);
    4098            0 :   TYPE_NAME (rtype) = heap_identifier;
    4099            0 :   tree fld1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype1);
    4100            0 :   tree fld2 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype2);
    4101            0 :   DECL_FIELD_CONTEXT (fld1) = rtype;
    4102            0 :   DECL_FIELD_CONTEXT (fld2) = rtype;
    4103            0 :   DECL_ARTIFICIAL (fld1) = true;
    4104            0 :   DECL_ARTIFICIAL (fld2) = true;
    4105            0 :   TYPE_FIELDS (rtype) = fld1;
    4106            0 :   DECL_CHAIN (fld1) = fld2;
    4107            0 :   layout_type (rtype);
    4108            0 :   return rtype;
    4109              : }
    4110              : 
    4111              : // forked from gcc/cp/class.cc field_poverlapping_p
    4112              : 
    4113              : /* Return true iff FIELD_DECL DECL is potentially overlapping.  */
    4114              : 
    4115              : static bool
    4116            0 : field_poverlapping_p (tree decl)
    4117              : {
    4118            0 :   return lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (decl));
    4119              : }
    4120              : 
    4121              : // forked from gcc/cp/class.cc is_empty_field
    4122              : 
    4123              : /* Return true iff DECL is an empty field, either for an empty base or a
    4124              :    [[no_unique_address]] data member.  */
    4125              : 
    4126              : bool
    4127            0 : is_empty_field (tree decl)
    4128              : {
    4129            0 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4130              :     return false;
    4131              : 
    4132            0 :   bool r = (is_empty_class (TREE_TYPE (decl)) && (field_poverlapping_p (decl)));
    4133              : 
    4134              :   /* Empty fields should have size zero.  */
    4135            0 :   gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
    4136              : 
    4137              :   return r;
    4138              : }
    4139              : 
    4140              : // forked from gcc/cp/call.cc in_immediate_context
    4141              : 
    4142              : /* Return true if in an immediate function context, or an unevaluated operand,
    4143              :    or a subexpression of an immediate invocation.  */
    4144              : 
    4145              : bool
    4146            0 : in_immediate_context ()
    4147              : {
    4148            0 :   return false;
    4149              : }
    4150              : 
    4151              : // forked from gcc/cp/cvt.cc cp_get_fndecl_from_callee
    4152              : 
    4153              : /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
    4154              :    if we can.  */
    4155              : 
    4156              : tree
    4157            0 : rs_get_fndecl_from_callee (tree fn, bool fold /* = true */)
    4158              : {
    4159            0 :   if (fn == NULL_TREE)
    4160              :     return fn;
    4161            0 :   if (TREE_CODE (fn) == FUNCTION_DECL)
    4162              :     return fn;
    4163            0 :   tree type = TREE_TYPE (fn);
    4164            0 :   if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
    4165              :     return NULL_TREE;
    4166            0 :   if (fold)
    4167            0 :     fn = Compile::maybe_constant_init (fn);
    4168            0 :   STRIP_NOPS (fn);
    4169            0 :   if (TREE_CODE (fn) == ADDR_EXPR || TREE_CODE (fn) == FDESC_EXPR)
    4170            0 :     fn = TREE_OPERAND (fn, 0);
    4171            0 :   if (TREE_CODE (fn) == FUNCTION_DECL)
    4172              :     return fn;
    4173              :   return NULL_TREE;
    4174              : }
    4175              : 
    4176              : // forked from gcc/cp/cvt.cc cp_get_callee_fndecl_nofold
    4177              : tree
    4178            0 : rs_get_callee_fndecl_nofold (tree call)
    4179              : {
    4180            0 :   return rs_get_fndecl_from_callee (cp_get_callee (call), false);
    4181              : }
    4182              : 
    4183              : // forked from gcc/cp/init.cc is_class_type
    4184              : 
    4185              : /* Report an error if TYPE is not a user-defined, class type.  If
    4186              :    OR_ELSE is nonzero, give an error message.  */
    4187              : 
    4188              : int
    4189            0 : is_class_type (tree type, int or_else)
    4190              : {
    4191            0 :   if (type == error_mark_node)
    4192              :     return 0;
    4193              : 
    4194            0 :   if (!CLASS_TYPE_P (type))
    4195              :     {
    4196            0 :       if (or_else)
    4197            0 :         error ("%qT is not a class type", type);
    4198            0 :       return 0;
    4199              :     }
    4200              :   return 1;
    4201              : }
    4202              : 
    4203              : // forked from gcc/cp/decl.cc lookup_enumerator
    4204              : 
    4205              : /* Look for an enumerator with the given NAME within the enumeration
    4206              :    type ENUMTYPE.  This routine is used primarily for qualified name
    4207              :    lookup into an enumerator in C++0x, e.g.,
    4208              : 
    4209              :      enum class Color { Red, Green, Blue };
    4210              : 
    4211              :      Color color = Color::Red;
    4212              : 
    4213              :    Returns the value corresponding to the enumerator, or
    4214              :    NULL_TREE if no such enumerator was found.  */
    4215              : tree
    4216            0 : lookup_enumerator (tree enumtype, tree name)
    4217              : {
    4218            0 :   tree e;
    4219            0 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
    4220              : 
    4221            0 :   e = purpose_member (name, TYPE_VALUES (enumtype));
    4222            0 :   return e ? TREE_VALUE (e) : NULL_TREE;
    4223              : }
    4224              : 
    4225              : // forked from gcc/cp/init.cc constant_value_1
    4226              : // commented out mark_used
    4227              : 
    4228              : /* If DECL is a scalar enumeration constant or variable with a
    4229              :    constant initializer, return the initializer (or, its initializers,
    4230              :    recursively); otherwise, return DECL.  If STRICT_P, the
    4231              :    initializer is only returned if DECL is a
    4232              :    constant-expression.  If RETURN_AGGREGATE_CST_OK_P, it is ok to
    4233              :    return an aggregate constant.  If UNSHARE_P, return an unshared
    4234              :    copy of the initializer.  */
    4235              : 
    4236              : static tree
    4237            0 : constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p,
    4238              :                   bool unshare_p)
    4239              : {
    4240            0 :   while (TREE_CODE (decl) == CONST_DECL || decl_constant_var_p (decl)
    4241            0 :          || (!strict_p && VAR_P (decl)
    4242            0 :              && RS_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
    4243              :     {
    4244            0 :       tree init;
    4245              :       /* If DECL is a static data member in a template
    4246              :          specialization, we must instantiate it here.  The
    4247              :          initializer for the static data member is not processed
    4248              :          until needed; we need it now.  */
    4249              :       // mark_used (decl, tf_none);
    4250            0 :       init = DECL_INITIAL (decl);
    4251            0 :       if (init == error_mark_node)
    4252              :         {
    4253            0 :           if (TREE_CODE (decl) == CONST_DECL
    4254            0 :               || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    4255              :             /* Treat the error as a constant to avoid cascading errors on
    4256              :                excessively recursive template instantiation (c++/9335).  */
    4257              :             return init;
    4258              :           else
    4259            0 :             return decl;
    4260              :         }
    4261              : 
    4262              :       /* Instantiate a non-dependent initializer for user variables.  We
    4263              :          mustn't do this for the temporary for an array compound literal;
    4264              :          trying to instatiate the initializer will keep creating new
    4265              :          temporaries until we crash.  Probably it's not useful to do it for
    4266              :          other artificial variables, either.  */
    4267            0 :       if (!DECL_ARTIFICIAL (decl))
    4268            0 :         init = instantiate_non_dependent_or_null (init);
    4269            0 :       if (!init || !TREE_TYPE (init) || !TREE_CONSTANT (init)
    4270            0 :           || (!return_aggregate_cst_ok_p
    4271              :               /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
    4272              :                  return an aggregate constant (of which string
    4273              :                  literals are a special case), as we do not want
    4274              :                  to make inadvertent copies of such entities, and
    4275              :                  we must be sure that their addresses are the
    4276              :                  same everywhere.  */
    4277            0 :               && (TREE_CODE (init) == CONSTRUCTOR
    4278            0 :                   || TREE_CODE (init) == STRING_CST)))
    4279              :         break;
    4280              :       /* Don't return a CONSTRUCTOR for a variable with partial run-time
    4281              :          initialization, since it doesn't represent the entire value.
    4282              :          Similarly for VECTOR_CSTs created by cp_folding those
    4283              :          CONSTRUCTORs.  */
    4284            0 :       if ((TREE_CODE (init) == CONSTRUCTOR || TREE_CODE (init) == VECTOR_CST)
    4285            0 :           && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    4286              :         break;
    4287              :       /* If the variable has a dynamic initializer, don't use its
    4288              :          DECL_INITIAL which doesn't reflect the real value.  */
    4289            0 :       if (VAR_P (decl) && TREE_STATIC (decl)
    4290            0 :           && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
    4291            0 :           && DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    4292              :         break;
    4293              :       decl = init;
    4294              :     }
    4295            0 :   return unshare_p ? unshare_expr (decl) : decl;
    4296              : }
    4297              : 
    4298              : // forked from gcc/cp/init.cc decl_constant_value
    4299              : 
    4300              : /* A more relaxed version of decl_really_constant_value, used by the
    4301              :    common C/C++ code.  */
    4302              : 
    4303              : tree
    4304            0 : decl_constant_value (tree decl, bool unshare_p)
    4305              : {
    4306            0 :   return constant_value_1 (decl, /*strict_p=*/false,
    4307              :                            /*return_aggregate_cst_ok_p=*/true,
    4308            0 :                            /*unshare_p=*/unshare_p);
    4309              : }
    4310              : 
    4311              : // Below is forked from gcc/cp/init.cc decl_constant_value
    4312              : 
    4313              : tree
    4314            0 : decl_constant_value (tree decl)
    4315              : {
    4316            0 :   return decl_constant_value (decl, /*unshare_p=*/true);
    4317              : }
    4318              : 
    4319              : // Below is forked from gcc/cp/cp-gimplify.cc
    4320              : 
    4321              : /* Type for source_location_table hash_set.  */
    4322              : struct GTY ((for_user)) source_location_table_entry
    4323              : {
    4324              :   location_t loc;
    4325              :   unsigned uid;
    4326              :   tree var;
    4327              : };
    4328              : 
    4329              : // exit/reenter namespace to declare some external functions
    4330              : 
    4331              : } // namespace Rust
    4332              : 
    4333              : extern void gt_pch_nx (Rust::source_location_table_entry &);
    4334              : extern void gt_pch_nx (Rust::source_location_table_entry *, gt_pointer_operator,
    4335              :                        void *);
    4336              : 
    4337              : namespace Rust {
    4338              : 
    4339              : /* Traits class for function start hash maps below.  */
    4340              : 
    4341              : struct rust_source_location_table_entry_hash
    4342              :   : ggc_remove<source_location_table_entry>
    4343              : {
    4344              :   typedef source_location_table_entry value_type;
    4345              :   typedef source_location_table_entry compare_type;
    4346              : 
    4347            0 :   static hashval_t hash (const source_location_table_entry &ref)
    4348              :   {
    4349            0 :     inchash::hash hstate (0);
    4350            0 :     hstate.add_int (ref.loc);
    4351            0 :     hstate.add_int (ref.uid);
    4352            0 :     return hstate.end ();
    4353              :   }
    4354              : 
    4355            0 :   static bool equal (const source_location_table_entry &ref1,
    4356              :                      const source_location_table_entry &ref2)
    4357              :   {
    4358            0 :     return ref1.loc == ref2.loc && ref1.uid == ref2.uid;
    4359              :   }
    4360              : 
    4361              :   static void mark_deleted (source_location_table_entry &ref)
    4362              :   {
    4363              :     ref.loc = UNKNOWN_LOCATION;
    4364              :     ref.uid = -1U;
    4365              :     ref.var = NULL_TREE;
    4366              :   }
    4367              : 
    4368              :   static const bool empty_zero_p = true;
    4369              : 
    4370            0 :   static void mark_empty (source_location_table_entry &ref)
    4371              :   {
    4372            0 :     ref.loc = UNKNOWN_LOCATION;
    4373            0 :     ref.uid = 0;
    4374            0 :     ref.var = NULL_TREE;
    4375              :   }
    4376              : 
    4377            0 :   static bool is_deleted (const source_location_table_entry &ref)
    4378              :   {
    4379            0 :     return (ref.loc == UNKNOWN_LOCATION && ref.uid == -1U
    4380            0 :             && ref.var == NULL_TREE);
    4381              :   }
    4382              : 
    4383            0 :   static bool is_empty (const source_location_table_entry &ref)
    4384              :   {
    4385            0 :     return (ref.loc == UNKNOWN_LOCATION && ref.uid == 0
    4386            0 :             && ref.var == NULL_TREE);
    4387              :   }
    4388              : 
    4389            0 :   static void pch_nx (source_location_table_entry &p) { gt_pch_nx (p); }
    4390              : 
    4391            0 :   static void pch_nx (source_location_table_entry &p, gt_pointer_operator op,
    4392              :                       void *cookie)
    4393              :   {
    4394            0 :     gt_pch_nx (&p, op, cookie);
    4395            0 :   }
    4396              : };
    4397              : 
    4398              : static GTY (())
    4399              :   hash_table<rust_source_location_table_entry_hash> *source_location_table;
    4400              : static GTY (()) unsigned int source_location_id;
    4401              : 
    4402              : // Above is forked from gcc/cp/cp-gimplify.cc
    4403              : 
    4404              : // forked from gcc/cp/tree.cc lvalue_kind
    4405              : 
    4406              : /* If REF is an lvalue, returns the kind of lvalue that REF is.
    4407              :    Otherwise, returns clk_none.  */
    4408              : 
    4409              : cp_lvalue_kind
    4410            0 : lvalue_kind (const_tree ref)
    4411              : {
    4412            0 :   cp_lvalue_kind op1_lvalue_kind = clk_none;
    4413            0 :   cp_lvalue_kind op2_lvalue_kind = clk_none;
    4414              : 
    4415              :   /* Expressions of reference type are sometimes wrapped in
    4416              :      INDIRECT_REFs.  INDIRECT_REFs are just internal compiler
    4417              :      representation, not part of the language, so we have to look
    4418              :      through them.  */
    4419            0 :   if (REFERENCE_REF_P (ref))
    4420            0 :     return lvalue_kind (TREE_OPERAND (ref, 0));
    4421              : 
    4422            0 :   if (TREE_TYPE (ref) && TYPE_REF_P (TREE_TYPE (ref)))
    4423              :     {
    4424              :       /* unnamed rvalue references are rvalues */
    4425            0 :       if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) && TREE_CODE (ref) != PARM_DECL
    4426              :           && !VAR_P (ref)
    4427              :           && TREE_CODE (ref) != COMPONENT_REF
    4428              :           /* Functions are always lvalues.  */
    4429            0 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
    4430              :         {
    4431            0 :           op1_lvalue_kind = clk_rvalueref;
    4432            0 :           if (implicit_rvalue_p (ref))
    4433            0 :             op1_lvalue_kind |= clk_implicit_rval;
    4434            0 :           return op1_lvalue_kind;
    4435              :         }
    4436              : 
    4437              :       /* lvalue references and named rvalue references are lvalues.  */
    4438              :       return clk_ordinary;
    4439              :     }
    4440              : 
    4441            0 :   if (ref == current_class_ptr)
    4442              :     return clk_none;
    4443              : 
    4444              :   /* Expressions with cv void type are prvalues.  */
    4445            0 :   if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
    4446              :     return clk_none;
    4447              : 
    4448            0 :   switch (TREE_CODE (ref))
    4449              :     {
    4450              :     case SAVE_EXPR:
    4451              :       return clk_none;
    4452              : 
    4453              :       /* preincrements and predecrements are valid lvals, provided
    4454              :          what they refer to are valid lvals.  */
    4455            0 :     case PREINCREMENT_EXPR:
    4456            0 :     case PREDECREMENT_EXPR:
    4457            0 :     case TRY_CATCH_EXPR:
    4458            0 :     case REALPART_EXPR:
    4459            0 :     case IMAGPART_EXPR:
    4460            0 :     case VIEW_CONVERT_EXPR:
    4461            0 :       return lvalue_kind (TREE_OPERAND (ref, 0));
    4462              : 
    4463            0 :     case ARRAY_REF:
    4464            0 :       {
    4465            0 :         tree op1 = TREE_OPERAND (ref, 0);
    4466            0 :         if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
    4467              :           {
    4468            0 :             op1_lvalue_kind = lvalue_kind (op1);
    4469            0 :             if (op1_lvalue_kind == clk_class)
    4470              :               /* in the case of an array operand, the result is an lvalue if
    4471              :                  that operand is an lvalue and an xvalue otherwise */
    4472            0 :               op1_lvalue_kind = clk_rvalueref;
    4473            0 :             return op1_lvalue_kind;
    4474              :           }
    4475              :         else
    4476              :           return clk_ordinary;
    4477              :       }
    4478              : 
    4479            0 :     case MEMBER_REF:
    4480            0 :     case DOTSTAR_EXPR:
    4481            0 :       if (TREE_CODE (ref) == MEMBER_REF)
    4482              :         op1_lvalue_kind = clk_ordinary;
    4483              :       else
    4484            0 :         op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
    4485            0 :       if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
    4486              :         op1_lvalue_kind = clk_none;
    4487            0 :       else if (op1_lvalue_kind == clk_class)
    4488              :         /* The result of a .* expression whose second operand is a pointer to a
    4489              :            data member is an lvalue if the first operand is an lvalue and an
    4490              :            xvalue otherwise.  */
    4491            0 :         op1_lvalue_kind = clk_rvalueref;
    4492              :       return op1_lvalue_kind;
    4493              : 
    4494            0 :     case COMPONENT_REF:
    4495            0 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
    4496            0 :       if (op1_lvalue_kind == clk_class)
    4497              :         /* If E1 is an lvalue, then E1.E2 is an lvalue;
    4498              :            otherwise E1.E2 is an xvalue.  */
    4499              :         op1_lvalue_kind = clk_rvalueref;
    4500              : 
    4501              :       /* Look at the member designator.  */
    4502            0 :       if (!op1_lvalue_kind)
    4503              :         ;
    4504            0 :       else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
    4505              :         /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
    4506              :            situations.  If we're seeing a COMPONENT_REF, it's a non-static
    4507              :            member, so it isn't an lvalue. */
    4508              :         op1_lvalue_kind = clk_none;
    4509            0 :       else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
    4510              :         /* This can be IDENTIFIER_NODE in a template.  */;
    4511            0 :       else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
    4512              :         {
    4513              :           /* Clear the ordinary bit.  If this object was a class
    4514              :              rvalue we want to preserve that information.  */
    4515            0 :           op1_lvalue_kind &= ~clk_ordinary;
    4516              :           /* The lvalue is for a bitfield.  */
    4517            0 :           op1_lvalue_kind |= clk_bitfield;
    4518              :         }
    4519            0 :       else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
    4520            0 :         op1_lvalue_kind |= clk_packed;
    4521              : 
    4522              :       return op1_lvalue_kind;
    4523              : 
    4524              :     case STRING_CST:
    4525              :     case COMPOUND_LITERAL_EXPR:
    4526              :       return clk_ordinary;
    4527              : 
    4528            0 :     case CONST_DECL:
    4529              :       /* CONST_DECL without TREE_STATIC are enumeration values and
    4530              :          thus not lvalues.  With TREE_STATIC they are used by ObjC++
    4531              :          in objc_build_string_object and need to be considered as
    4532              :          lvalues.  */
    4533            0 :       if (!TREE_STATIC (ref))
    4534              :         return clk_none;
    4535              :       /* FALLTHRU */
    4536            0 :     case VAR_DECL:
    4537            0 :       if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
    4538            0 :         return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
    4539              : 
    4540            0 :       if (TREE_READONLY (ref) && !TREE_STATIC (ref) && DECL_LANG_SPECIFIC (ref)
    4541            0 :           && DECL_IN_AGGR_P (ref))
    4542              :         return clk_none;
    4543              :       /* FALLTHRU */
    4544              :     case INDIRECT_REF:
    4545              :     case ARROW_EXPR:
    4546              :     case PARM_DECL:
    4547              :     case RESULT_DECL:
    4548              :     case PLACEHOLDER_EXPR:
    4549              :       return clk_ordinary;
    4550              : 
    4551            0 :     case MAX_EXPR:
    4552            0 :     case MIN_EXPR:
    4553              :       /* Disallow <? and >? as lvalues if either argument side-effects.  */
    4554            0 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
    4555            0 :           || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
    4556              :         return clk_none;
    4557            0 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
    4558            0 :       op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
    4559            0 :       break;
    4560              : 
    4561            0 :     case COND_EXPR:
    4562            0 :       {
    4563            0 :         tree op1 = TREE_OPERAND (ref, 1);
    4564            0 :         if (!op1)
    4565            0 :           op1 = TREE_OPERAND (ref, 0);
    4566            0 :         tree op2 = TREE_OPERAND (ref, 2);
    4567            0 :         op1_lvalue_kind = lvalue_kind (op1);
    4568            0 :         op2_lvalue_kind = lvalue_kind (op2);
    4569            0 :         if (!op1_lvalue_kind != !op2_lvalue_kind)
    4570              :           {
    4571              :             /* The second or the third operand (but not both) is a
    4572              :                throw-expression; the result is of the type
    4573              :                and value category of the other.  */
    4574            0 :             if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
    4575              :               op2_lvalue_kind = op1_lvalue_kind;
    4576            0 :             else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
    4577            0 :               op1_lvalue_kind = op2_lvalue_kind;
    4578              :           }
    4579              :       }
    4580              :       break;
    4581              : 
    4582              :     case MODIFY_EXPR:
    4583              :     case TYPEID_EXPR:
    4584              :       return clk_ordinary;
    4585              : 
    4586            0 :     case COMPOUND_EXPR:
    4587            0 :       return lvalue_kind (TREE_OPERAND (ref, 1));
    4588              : 
    4589              :     case TARGET_EXPR:
    4590              :       return clk_class;
    4591              : 
    4592            0 :     case VA_ARG_EXPR:
    4593            0 :       return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
    4594              : 
    4595            0 :     case CALL_EXPR:
    4596              :       /* We can see calls outside of TARGET_EXPR in templates.  */
    4597            0 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
    4598              :         return clk_class;
    4599              :       return clk_none;
    4600              : 
    4601            0 :     case FUNCTION_DECL:
    4602              :       /* All functions (except non-static-member functions) are
    4603              :          lvalues.  */
    4604            0 :       return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) ? clk_none : clk_ordinary);
    4605              : 
    4606            0 :     case PAREN_EXPR:
    4607            0 :       return lvalue_kind (TREE_OPERAND (ref, 0));
    4608              : 
    4609            0 :     case TEMPLATE_PARM_INDEX:
    4610            0 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
    4611              :         /* A template parameter object is an lvalue.  */
    4612              :         return clk_ordinary;
    4613              :       return clk_none;
    4614              : 
    4615            0 :     default:
    4616            0 :       if (!TREE_TYPE (ref))
    4617              :         return clk_none;
    4618            0 :       if (CLASS_TYPE_P (TREE_TYPE (ref))
    4619            0 :           || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
    4620              :         return clk_class;
    4621              :       return clk_none;
    4622              :     }
    4623              : 
    4624              :   /* If one operand is not an lvalue at all, then this expression is
    4625              :      not an lvalue.  */
    4626            0 :   if (!op1_lvalue_kind || !op2_lvalue_kind)
    4627              :     return clk_none;
    4628              : 
    4629              :   /* Otherwise, it's an lvalue, and it has all the odd properties
    4630              :      contributed by either operand.  */
    4631            0 :   op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
    4632              :   /* It's not an ordinary lvalue if it involves any other kind.  */
    4633            0 :   if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
    4634            0 :     op1_lvalue_kind &= ~clk_ordinary;
    4635              :   /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
    4636              :      A COND_EXPR of those should be wrapped in a TARGET_EXPR.  */
    4637            0 :   if ((op1_lvalue_kind & (clk_rvalueref | clk_class))
    4638            0 :       && (op1_lvalue_kind & (clk_bitfield | clk_packed)))
    4639            0 :     op1_lvalue_kind = clk_none;
    4640              :   return op1_lvalue_kind;
    4641              : }
    4642              : 
    4643              : // forked from gcc/cp/tree.cc glvalue_p
    4644              : 
    4645              : /* This differs from lvalue_p in that xvalues are included.  */
    4646              : 
    4647              : bool
    4648            0 : glvalue_p (const_tree ref)
    4649              : {
    4650            0 :   cp_lvalue_kind kind = lvalue_kind (ref);
    4651            0 :   if (kind & clk_class)
    4652              :     return false;
    4653              :   else
    4654            0 :     return (kind != clk_none);
    4655              : }
    4656              : 
    4657              : // forked from gcc/cp/init.cc cv_qualified_p
    4658              : 
    4659              : /* Returns nonzero if TYPE is const or volatile.  */
    4660              : 
    4661              : bool
    4662            0 : cv_qualified_p (const_tree type)
    4663              : {
    4664            0 :   int quals = rs_type_quals (type);
    4665            0 :   return (quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) != 0;
    4666              : }
    4667              : 
    4668              : // forked from gcc/cp/tree.cc rvalue
    4669              : 
    4670              : /* EXPR is being used in an rvalue context.  Return a version of EXPR
    4671              :    that is marked as an rvalue.  */
    4672              : 
    4673              : tree
    4674            0 : rvalue (tree expr)
    4675              : {
    4676            0 :   tree type;
    4677              : 
    4678            0 :   if (error_operand_p (expr))
    4679              :     return expr;
    4680              : 
    4681            0 :   expr = mark_rvalue_use (expr);
    4682              : 
    4683              :   /* [basic.lval]
    4684              : 
    4685              :      Non-class rvalues always have cv-unqualified types.  */
    4686            0 :   type = TREE_TYPE (expr);
    4687            0 :   if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    4688            0 :     type = cv_unqualified (type);
    4689              : 
    4690              :   /* We need to do this for rvalue refs as well to get the right answer
    4691              :      from decltype; see c++/36628.  */
    4692            0 :   if (glvalue_p (expr))
    4693              :     {
    4694              :       /* But don't use this function for class lvalues; use move (to treat an
    4695              :          lvalue as an xvalue) or force_rvalue (to make a prvalue copy).  */
    4696            0 :       gcc_checking_assert (!CLASS_TYPE_P (type));
    4697            0 :       expr = build1 (NON_LVALUE_EXPR, type, expr);
    4698              :     }
    4699            0 :   else if (type != TREE_TYPE (expr))
    4700            0 :     expr = build_nop (type, expr);
    4701              : 
    4702              :   return expr;
    4703              : }
    4704              : 
    4705              : // forked from gcc/cp/tree.cc bitfield_p
    4706              : 
    4707              : /* True if REF is a bit-field.  */
    4708              : 
    4709              : bool
    4710            0 : bitfield_p (const_tree ref)
    4711              : {
    4712            0 :   return (lvalue_kind (ref) & clk_bitfield);
    4713              : }
    4714              : 
    4715              : // forked from gcc/cp/typeck.cc cxx_mark_addressable
    4716              : 
    4717              : /* Mark EXP saying that we need to be able to take the
    4718              :    address of it; it should not be allocated in a register.
    4719              :    Value is true if successful.  ARRAY_REF_P is true if this
    4720              :    is for ARRAY_REF construction - in that case we don't want
    4721              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    4722              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    4723              :    register variables.
    4724              : 
    4725              :    C++: we do not allow `current_class_ptr' to be addressable.  */
    4726              : 
    4727              : bool
    4728            0 : cxx_mark_addressable (tree exp, bool array_ref_p)
    4729              : {
    4730            0 :   tree x = exp;
    4731              : 
    4732            0 :   while (1)
    4733            0 :     switch (TREE_CODE (x))
    4734              :       {
    4735            0 :       case VIEW_CONVERT_EXPR:
    4736            0 :         if (array_ref_p && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    4737            0 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    4738              :           return true;
    4739            0 :         x = TREE_OPERAND (x, 0);
    4740            0 :         break;
    4741              : 
    4742            0 :       case COMPONENT_REF:
    4743            0 :         if (bitfield_p (x))
    4744            0 :           error ("attempt to take address of bit-field");
    4745              :         /* FALLTHRU */
    4746            0 :       case ADDR_EXPR:
    4747            0 :       case ARRAY_REF:
    4748            0 :       case REALPART_EXPR:
    4749            0 :       case IMAGPART_EXPR:
    4750            0 :         x = TREE_OPERAND (x, 0);
    4751            0 :         break;
    4752              : 
    4753            0 :       case PARM_DECL:
    4754            0 :         if (x == current_class_ptr)
    4755              :           {
    4756            0 :             error ("cannot take the address of %<this%>, which is an rvalue "
    4757              :                    "expression");
    4758            0 :             TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later.  */
    4759            0 :             return true;
    4760              :           }
    4761              :         /* Fall through.  */
    4762              : 
    4763            0 :       case VAR_DECL:
    4764              :         /* Caller should not be trying to mark initialized
    4765              :            constant fields addressable.  */
    4766            0 :         gcc_assert (DECL_LANG_SPECIFIC (x) == 0 || DECL_IN_AGGR_P (x) == 0
    4767              :                     || TREE_STATIC (x) || DECL_EXTERNAL (x));
    4768              :         /* Fall through.  */
    4769              : 
    4770            0 :       case RESULT_DECL:
    4771            0 :         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x) && !DECL_ARTIFICIAL (x))
    4772              :           {
    4773            0 :             if (VAR_P (x) && DECL_HARD_REGISTER (x))
    4774              :               {
    4775            0 :                 error ("address of explicit register variable %qD requested",
    4776              :                        x);
    4777            0 :                 return false;
    4778              :               }
    4779            0 :             else if (extra_warnings)
    4780            0 :               warning (
    4781            0 :                 OPT_Wextra,
    4782              :                 "address requested for %qD, which is declared %<register%>", x);
    4783              :           }
    4784            0 :         TREE_ADDRESSABLE (x) = 1;
    4785            0 :         return true;
    4786              : 
    4787            0 :       case CONST_DECL:
    4788            0 :       case FUNCTION_DECL:
    4789            0 :         TREE_ADDRESSABLE (x) = 1;
    4790            0 :         return true;
    4791              : 
    4792            0 :       case CONSTRUCTOR:
    4793            0 :         TREE_ADDRESSABLE (x) = 1;
    4794            0 :         return true;
    4795              : 
    4796            0 :       case TARGET_EXPR:
    4797            0 :         TREE_ADDRESSABLE (x) = 1;
    4798            0 :         cxx_mark_addressable (TREE_OPERAND (x, 0));
    4799            0 :         return true;
    4800              : 
    4801              :       default:
    4802              :         return true;
    4803              :       }
    4804              : }
    4805              : 
    4806              : // forked from gcc/cp/typeck.cc build_address
    4807              : 
    4808              : /* Returns the address of T.  This function will fold away
    4809              :    ADDR_EXPR of INDIRECT_REF.  This is only for low-level usage;
    4810              :    most places should use cp_build_addr_expr instead.  */
    4811              : 
    4812              : tree
    4813            0 : build_address (tree t)
    4814              : {
    4815            0 :   if (error_operand_p (t) || !cxx_mark_addressable (t))
    4816            0 :     return error_mark_node;
    4817            0 :   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR);
    4818            0 :   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
    4819            0 :   if (TREE_CODE (t) != ADDR_EXPR)
    4820            0 :     t = rvalue (t);
    4821              :   return t;
    4822              : }
    4823              : 
    4824              : // forked from gcc/cp/gp-gimplify.cc fold_builtin_source_location
    4825              : 
    4826              : /* Fold __builtin_source_location () call.  LOC is the location
    4827              :    of the call.  */
    4828              : 
    4829              : tree
    4830            0 : fold_builtin_source_location (location_t loc)
    4831              : {
    4832              :   //  if (source_location_impl == NULL_TREE)
    4833              :   //  {
    4834              :   //    auto_diagnostic_group d;
    4835              :   //    source_location_impl = get_source_location_impl_type (loc);
    4836              :   //    if (source_location_impl == error_mark_node)
    4837              :   // inform (loc, "evaluating %qs", "__builtin_source_location");
    4838              :   //  }
    4839            0 :   if (source_location_impl == error_mark_node)
    4840            0 :     return build_zero_cst (const_ptr_type_node);
    4841            0 :   if (source_location_table == NULL)
    4842            0 :     source_location_table
    4843            0 :       = hash_table<rust_source_location_table_entry_hash>::create_ggc (64);
    4844            0 :   const line_map_ordinary *map;
    4845            0 :   source_location_table_entry entry;
    4846            0 :   entry.loc = linemap_resolve_location (line_table, loc,
    4847              :                                         LRK_MACRO_EXPANSION_POINT, &map);
    4848            0 :   entry.uid = current_function_decl ? DECL_UID (current_function_decl) : -1;
    4849            0 :   entry.var = error_mark_node;
    4850            0 :   source_location_table_entry *entryp
    4851            0 :     = source_location_table->find_slot (entry, INSERT);
    4852            0 :   tree var;
    4853            0 :   if (entryp->var)
    4854              :     var = entryp->var;
    4855              :   else
    4856              :     {
    4857            0 :       char tmp_name[32];
    4858            0 :       ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lsrc_loc", source_location_id++);
    4859            0 :       var = build_decl (loc, VAR_DECL, get_identifier (tmp_name),
    4860              :                         source_location_impl);
    4861            0 :       TREE_STATIC (var) = 1;
    4862            0 :       TREE_PUBLIC (var) = 0;
    4863            0 :       DECL_ARTIFICIAL (var) = 1;
    4864            0 :       DECL_IGNORED_P (var) = 1;
    4865            0 :       DECL_EXTERNAL (var) = 0;
    4866            0 :       DECL_DECLARED_CONSTEXPR_P (var) = 1;
    4867            0 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = 1;
    4868            0 :       layout_decl (var, 0);
    4869              : 
    4870            0 :       vec<constructor_elt, va_gc> *v = NULL;
    4871            0 :       vec_alloc (v, 4);
    4872            0 :       for (tree field = TYPE_FIELDS (source_location_impl);
    4873            0 :            (field = next_initializable_field (field)) != NULL_TREE;
    4874            0 :            field = DECL_CHAIN (field))
    4875              :         {
    4876            0 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (field));
    4877            0 :           tree val = NULL_TREE;
    4878            0 :           if (strcmp (n, "_M_file_name") == 0)
    4879              :             {
    4880            0 :               if (const char *fname = LOCATION_FILE (loc))
    4881              :                 {
    4882            0 :                   fname = remap_macro_filename (fname);
    4883            0 :                   val = build_string_literal (strlen (fname) + 1, fname);
    4884              :                 }
    4885              :               else
    4886            0 :                 val = build_string_literal (1, "");
    4887              :             }
    4888            0 :           else if (strcmp (n, "_M_function_name") == 0)
    4889              :             {
    4890            0 :               const char *name = "todo: add function name here";
    4891              : 
    4892              :               // if (current_function_decl)
    4893              :               // name = cxx_printable_name (current_function_decl, 2);
    4894              : 
    4895            0 :               val = build_string_literal (strlen (name) + 1, name);
    4896              :             }
    4897            0 :           else if (strcmp (n, "_M_line") == 0)
    4898            0 :             val = build_int_cst (TREE_TYPE (field), LOCATION_LINE (loc));
    4899            0 :           else if (strcmp (n, "_M_column") == 0)
    4900            0 :             val = build_int_cst (TREE_TYPE (field), LOCATION_COLUMN (loc));
    4901              :           else
    4902            0 :             rust_unreachable ();
    4903            0 :           CONSTRUCTOR_APPEND_ELT (v, field, val);
    4904              :         }
    4905              : 
    4906            0 :       tree ctor = build_constructor (source_location_impl, v);
    4907            0 :       TREE_CONSTANT (ctor) = 1;
    4908            0 :       TREE_STATIC (ctor) = 1;
    4909            0 :       DECL_INITIAL (var) = ctor;
    4910            0 :       varpool_node::finalize_decl (var);
    4911            0 :       *entryp = entry;
    4912            0 :       entryp->var = var;
    4913              :     }
    4914              : 
    4915            0 :   return build_fold_addr_expr_with_type_loc (loc, var, const_ptr_type_node);
    4916              : }
    4917              : 
    4918              : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
    4919              : 
    4920              : /* Attempt to convert a braced array initializer list CTOR for array
    4921              :    TYPE into a STRING_CST for convenience and efficiency.  Return
    4922              :    the converted string on success or the original ctor on failure.  */
    4923              : 
    4924              : static tree
    4925            0 : braced_list_to_string (tree type, tree ctor, bool member)
    4926              : {
    4927              :   /* Ignore non-members with unknown size like arrays with unspecified
    4928              :      bound.  */
    4929            0 :   tree typesize = TYPE_SIZE_UNIT (type);
    4930            0 :   if (!member && !tree_fits_uhwi_p (typesize))
    4931              :     return ctor;
    4932              : 
    4933              :   /* If the target char size differes from the host char size, we'd risk
    4934              :      loosing data and getting object sizes wrong by converting to
    4935              :      host chars.  */
    4936            0 :   if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
    4937              :     return ctor;
    4938              : 
    4939              :   /* If the array has an explicit bound, use it to constrain the size
    4940              :      of the string.  If it doesn't, be sure to create a string that's
    4941              :      as long as implied by the index of the last zero specified via
    4942              :      a designator, as in:
    4943              :        const char a[] = { [7] = 0 };  */
    4944            0 :   unsigned HOST_WIDE_INT maxelts;
    4945            0 :   if (typesize)
    4946              :     {
    4947            0 :       maxelts = tree_to_uhwi (typesize);
    4948            0 :       maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
    4949              :     }
    4950              :   else
    4951              :     maxelts = HOST_WIDE_INT_M1U;
    4952              : 
    4953              :   /* Avoid converting initializers for zero-length arrays (but do
    4954              :      create them for flexible array members).  */
    4955            0 :   if (!maxelts)
    4956              :     return ctor;
    4957              : 
    4958            0 :   unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
    4959              : 
    4960            0 :   auto_vec<char> str;
    4961            0 :   str.reserve (nelts + 1);
    4962              : 
    4963            0 :   unsigned HOST_WIDE_INT i;
    4964            0 :   tree index, value;
    4965              : 
    4966            0 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
    4967              :     {
    4968            0 :       unsigned HOST_WIDE_INT idx = i;
    4969            0 :       if (index)
    4970              :         {
    4971            0 :           if (!tree_fits_uhwi_p (index))
    4972              :             return ctor;
    4973            0 :           idx = tree_to_uhwi (index);
    4974              :         }
    4975              : 
    4976              :       /* auto_vec is limited to UINT_MAX elements.  */
    4977            0 :       if (idx > UINT_MAX)
    4978              :         return ctor;
    4979              : 
    4980              :       /* Avoid non-constant initializers.  */
    4981            0 :       if (!tree_fits_shwi_p (value))
    4982              :         return ctor;
    4983              : 
    4984              :       /* Skip over embedded nuls except the last one (initializer
    4985              :          elements are in ascending order of indices).  */
    4986            0 :       HOST_WIDE_INT val = tree_to_shwi (value);
    4987            0 :       if (!val && i + 1 < nelts)
    4988            0 :         continue;
    4989              : 
    4990            0 :       if (idx < str.length ())
    4991              :         return ctor;
    4992              : 
    4993              :       /* Bail if the CTOR has a block of more than 256 embedded nuls
    4994              :          due to implicitly initialized elements.  */
    4995            0 :       unsigned nchars = (idx - str.length ()) + 1;
    4996            0 :       if (nchars > 256)
    4997              :         return ctor;
    4998              : 
    4999            0 :       if (nchars > 1)
    5000              :         {
    5001            0 :           str.reserve (idx);
    5002            0 :           str.quick_grow_cleared (idx);
    5003              :         }
    5004              : 
    5005            0 :       if (idx >= maxelts)
    5006              :         return ctor;
    5007              : 
    5008            0 :       str.safe_insert (idx, val);
    5009              :     }
    5010              : 
    5011              :   /* Append a nul string termination.  */
    5012            0 :   if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
    5013            0 :     str.safe_push (0);
    5014              : 
    5015              :   /* Build a STRING_CST with the same type as the array.  */
    5016            0 :   tree res = build_string (str.length (), str.begin ());
    5017            0 :   TREE_TYPE (res) = type;
    5018            0 :   return res;
    5019            0 : }
    5020              : 
    5021              : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
    5022              : 
    5023              : /* Implementation of the two-argument braced_lists_to_string withe
    5024              :    the same arguments plus MEMBER which is set for struct members
    5025              :    to allow initializers for flexible member arrays.  */
    5026              : 
    5027              : static tree
    5028            0 : braced_lists_to_strings (tree type, tree ctor, bool member)
    5029              : {
    5030            0 :   if (TREE_CODE (ctor) != CONSTRUCTOR)
    5031              :     return ctor;
    5032              : 
    5033            0 :   tree_code code = TREE_CODE (type);
    5034              : 
    5035            0 :   tree ttp;
    5036            0 :   if (code == ARRAY_TYPE)
    5037            0 :     ttp = TREE_TYPE (type);
    5038            0 :   else if (code == RECORD_TYPE)
    5039              :     {
    5040            0 :       ttp = TREE_TYPE (ctor);
    5041            0 :       if (TREE_CODE (ttp) == ARRAY_TYPE)
    5042              :         {
    5043            0 :           type = ttp;
    5044            0 :           ttp = TREE_TYPE (ttp);
    5045              :         }
    5046              :     }
    5047              :   else
    5048              :     return ctor;
    5049              : 
    5050            0 :   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
    5051            0 :       && TYPE_STRING_FLAG (ttp))
    5052            0 :     return braced_list_to_string (type, ctor, member);
    5053              : 
    5054            0 :   code = TREE_CODE (ttp);
    5055            0 :   if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
    5056              :     {
    5057            0 :       bool rec = RECORD_OR_UNION_TYPE_P (ttp);
    5058              : 
    5059              :       /* Handle array of arrays or struct member initializers.  */
    5060            0 :       tree val;
    5061            0 :       unsigned HOST_WIDE_INT idx;
    5062            0 :       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
    5063              :         {
    5064            0 :           val = braced_lists_to_strings (ttp, val, rec);
    5065            0 :           CONSTRUCTOR_ELT (ctor, idx)->value = val;
    5066              :         }
    5067              :     }
    5068              : 
    5069              :   return ctor;
    5070              : }
    5071              : 
    5072              : // forked from gcc/c-family/c-common.cc braced_lists_to_strings
    5073              : 
    5074              : /* Attempt to convert a CTOR containing braced array initializer lists
    5075              :    for array TYPE into one containing STRING_CSTs, for convenience and
    5076              :    efficiency.  Recurse for arrays of arrays and member initializers.
    5077              :    Return the converted CTOR or STRING_CST on success or the original
    5078              :    CTOR otherwise.  */
    5079              : 
    5080              : tree
    5081            0 : braced_lists_to_strings (tree type, tree ctor)
    5082              : {
    5083            0 :   return braced_lists_to_strings (type, ctor, false);
    5084              : }
    5085              : 
    5086              : /*---------------------------------------------------------------------------
    5087              :                         Constraint satisfaction
    5088              : ---------------------------------------------------------------------------*/
    5089              : 
    5090              : // forked from gcc/cp/constraint.cc satisfying_constraint
    5091              : 
    5092              : /* True if we are currently satisfying a failed_type_completions.  */
    5093              : 
    5094              : static bool satisfying_constraint;
    5095              : 
    5096              : // forked from gcc/cp/constraint.cc satisfying_constraint
    5097              : 
    5098              : /* A vector of incomplete types (and of declarations with undeduced return
    5099              :    type), appended to by note_failed_type_completion_for_satisfaction.  The
    5100              :    satisfaction caches use this in order to keep track of "potentially unstable"
    5101              :    satisfaction results.
    5102              : 
    5103              :    Since references to entries in this vector are stored only in the
    5104              :    GC-deletable sat_cache, it's safe to make this deletable as well.  */
    5105              : 
    5106              : static GTY ((deletable)) vec<tree, va_gc> *failed_type_completions;
    5107              : 
    5108              : // forked from gcc/cp/constraint.cc note_failed_type_completion_for_satisfaction
    5109              : 
    5110              : /* Called whenever a type completion (or return type deduction) failure occurs
    5111              :    that definitely affects the meaning of the program, by e.g. inducing
    5112              :    substitution failure.  */
    5113              : 
    5114              : void
    5115            0 : note_failed_type_completion_for_satisfaction (tree t)
    5116              : {
    5117            0 :   if (satisfying_constraint)
    5118              :     {
    5119            0 :       gcc_checking_assert ((TYPE_P (t) && !COMPLETE_TYPE_P (t))
    5120              :                            || (DECL_P (t) && undeduced_auto_decl (t)));
    5121            0 :       vec_safe_push (failed_type_completions, t);
    5122              :     }
    5123            0 : }
    5124              : 
    5125              : // forked from gcc/cp/typeck.cc complete_type
    5126              : 
    5127              : /* Try to complete TYPE, if it is incomplete.  For example, if TYPE is
    5128              :    a template instantiation, do the instantiation.  Returns TYPE,
    5129              :    whether or not it could be completed, unless something goes
    5130              :    horribly wrong, in which case the error_mark_node is returned.  */
    5131              : 
    5132              : tree
    5133            0 : complete_type (tree type)
    5134              : {
    5135            0 :   if (type == NULL_TREE)
    5136              :     /* Rather than crash, we return something sure to cause an error
    5137              :        at some point.  */
    5138            0 :     return error_mark_node;
    5139              : 
    5140            0 :   if (type == error_mark_node || COMPLETE_TYPE_P (type))
    5141              :     ;
    5142            0 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    5143              :     {
    5144            0 :       tree t = complete_type (TREE_TYPE (type));
    5145            0 :       unsigned int needs_constructing, has_nontrivial_dtor;
    5146            0 :       if (COMPLETE_TYPE_P (t))
    5147            0 :         layout_type (type);
    5148            0 :       needs_constructing = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
    5149            0 :       has_nontrivial_dtor
    5150            0 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
    5151            0 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    5152              :         {
    5153            0 :           TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
    5154            0 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
    5155              :         }
    5156              :     }
    5157              : 
    5158              :   return type;
    5159              : }
    5160              : 
    5161              : // forked from gcc/cp/typeck.cc complete_type_or_maybe_complain
    5162              : 
    5163              : /* Like complete_type, but issue an error if the TYPE cannot be completed.
    5164              :    VALUE is used for informative diagnostics.
    5165              :    Returns NULL_TREE if the type cannot be made complete.  */
    5166              : 
    5167              : tree
    5168            0 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
    5169              : {
    5170            0 :   type = complete_type (type);
    5171            0 :   if (type == error_mark_node)
    5172              :     /* We already issued an error.  */
    5173              :     return NULL_TREE;
    5174            0 :   else if (!COMPLETE_TYPE_P (type))
    5175              :     {
    5176            0 :       if (complain & tf_error)
    5177            0 :         cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
    5178            0 :       note_failed_type_completion_for_satisfaction (type);
    5179            0 :       return NULL_TREE;
    5180              :     }
    5181              :   else
    5182              :     return type;
    5183              : }
    5184              : 
    5185              : // forked from gcc/cp/typeck.cc complete_type_or_else
    5186              : 
    5187              : tree
    5188            0 : complete_type_or_else (tree type, tree value)
    5189              : {
    5190            0 :   return complete_type_or_maybe_complain (type, value, tf_warning_or_error);
    5191              : }
    5192              : 
    5193              : // forked from gcc/cp/tree.cc std_layout_type_p
    5194              : 
    5195              : /* Returns true iff T is a standard-layout type, as defined in
    5196              :    [basic.types].  */
    5197              : 
    5198              : bool
    5199            0 : std_layout_type_p (const_tree t)
    5200              : {
    5201            0 :   t = strip_array_types (const_cast<tree> (t));
    5202              : 
    5203            0 :   if (CLASS_TYPE_P (t))
    5204            0 :     return !CLASSTYPE_NON_STD_LAYOUT (t);
    5205              :   else
    5206            0 :     return scalarish_type_p (t);
    5207              : }
    5208              : 
    5209              : // forked from /gcc/cp/semantics.cc first_nonstatic_data_member_p
    5210              : 
    5211              : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
    5212              :    return true if MEMBERTYPE is the type of the first non-static data member
    5213              :    of TYPE or for unions of any members.  */
    5214              : static bool
    5215            0 : first_nonstatic_data_member_p (tree type, tree membertype)
    5216              : {
    5217            0 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5218              :     {
    5219            0 :       if (TREE_CODE (field) != FIELD_DECL)
    5220            0 :         continue;
    5221            0 :       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
    5222            0 :         continue;
    5223            0 :       if (DECL_FIELD_IS_BASE (field))
    5224            0 :         return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
    5225            0 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    5226              :         {
    5227            0 :           if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
    5228            0 :                || std_layout_type_p (TREE_TYPE (field)))
    5229            0 :               && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
    5230              :             return true;
    5231              :         }
    5232            0 :       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
    5233              :                                                           membertype))
    5234              :         return true;
    5235            0 :       if (TREE_CODE (type) != UNION_TYPE)
    5236              :         return false;
    5237              :     }
    5238              :   return false;
    5239              : }
    5240              : 
    5241              : // forked from gcc/cp/semantics.cc
    5242              : // fold_builtin_is_pointer_inverconvertible_with_class
    5243              : 
    5244              : /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
    5245              : 
    5246              : tree
    5247            0 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
    5248              :                                                      tree *args)
    5249              : {
    5250              :   /* Unless users call the builtin directly, the following 3 checks should be
    5251              :      ensured from std::is_pointer_interconvertible_with_class function
    5252              :      template.  */
    5253            0 :   if (nargs != 1)
    5254              :     {
    5255            0 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
    5256              :                      "needs a single argument");
    5257            0 :       return boolean_false_node;
    5258              :     }
    5259            0 :   tree arg = args[0];
    5260            0 :   if (error_operand_p (arg))
    5261            0 :     return boolean_false_node;
    5262            0 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
    5263              :     {
    5264            0 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
    5265              :                      "argument is not pointer to member");
    5266            0 :       return boolean_false_node;
    5267              :     }
    5268              : 
    5269            0 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
    5270            0 :     return boolean_false_node;
    5271              : 
    5272            0 :   tree membertype = TREE_TYPE (TREE_TYPE (arg));
    5273            0 :   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
    5274            0 :   if (!complete_type_or_else (basetype, NULL_TREE))
    5275            0 :     return boolean_false_node;
    5276              : 
    5277            0 :   if (TREE_CODE (basetype) != UNION_TYPE && !std_layout_type_p (basetype))
    5278            0 :     return boolean_false_node;
    5279              : 
    5280            0 :   if (!first_nonstatic_data_member_p (basetype, membertype))
    5281            0 :     return boolean_false_node;
    5282              : 
    5283            0 :   if (integer_nonzerop (arg))
    5284            0 :     return boolean_false_node;
    5285            0 :   if (integer_zerop (arg))
    5286            0 :     return boolean_true_node;
    5287              : 
    5288            0 :   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
    5289              :                       build_zero_cst (TREE_TYPE (arg)));
    5290              : }
    5291              : 
    5292              : // forked from gcc/c-family/c-common.cc registered_builtin_types
    5293              : 
    5294              : /* Used for communication between c_common_type_for_mode and
    5295              :    c_register_builtin_type.  */
    5296              : tree registered_builtin_types;
    5297              : 
    5298              : /* Return a data type that has machine mode MODE.
    5299              :    If the mode is an integer,
    5300              :    then UNSIGNEDP selects between signed and unsigned types.
    5301              :    If the mode is a fixed-point mode,
    5302              :    then UNSIGNEDP selects between saturating and nonsaturating types.  */
    5303              : 
    5304              : // forked from gcc/c-family/c-common.cc c_common_type_for_mode
    5305              : 
    5306              : tree
    5307            0 : c_common_type_for_mode (machine_mode mode, int unsignedp)
    5308              : {
    5309            0 :   tree t;
    5310            0 :   int i;
    5311              : 
    5312            0 :   if (mode == TYPE_MODE (integer_type_node))
    5313            0 :     return unsignedp ? unsigned_type_node : integer_type_node;
    5314              : 
    5315            0 :   if (mode == TYPE_MODE (signed_char_type_node))
    5316            0 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    5317              : 
    5318            0 :   if (mode == TYPE_MODE (short_integer_type_node))
    5319            0 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    5320              : 
    5321            0 :   if (mode == TYPE_MODE (long_integer_type_node))
    5322            0 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    5323              : 
    5324            0 :   if (mode == TYPE_MODE (long_long_integer_type_node))
    5325            0 :     return unsignedp ? long_long_unsigned_type_node
    5326            0 :                      : long_long_integer_type_node;
    5327              : 
    5328            0 :   for (i = 0; i < NUM_INT_N_ENTS; i++)
    5329            0 :     if (int_n_enabled_p[i] && mode == int_n_data[i].m)
    5330            0 :       return (unsignedp ? int_n_trees[i].unsigned_type
    5331            0 :                         : int_n_trees[i].signed_type);
    5332              : 
    5333            0 :   if (mode == QImode)
    5334            0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    5335              : 
    5336            0 :   if (mode == HImode)
    5337            0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    5338              : 
    5339            0 :   if (mode == SImode)
    5340            0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    5341              : 
    5342            0 :   if (mode == DImode)
    5343            0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    5344              : 
    5345              : #if HOST_BITS_PER_WIDE_INT >= 64
    5346            0 :   if (mode == TYPE_MODE (intTI_type_node))
    5347            0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    5348              : #endif
    5349              : 
    5350            0 :   if (mode == TYPE_MODE (float_type_node))
    5351            0 :     return float_type_node;
    5352              : 
    5353            0 :   if (mode == TYPE_MODE (double_type_node))
    5354            0 :     return double_type_node;
    5355              : 
    5356            0 :   if (mode == TYPE_MODE (long_double_type_node))
    5357            0 :     return long_double_type_node;
    5358              : 
    5359            0 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    5360            0 :     if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    5361            0 :         && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
    5362            0 :       return FLOATN_NX_TYPE_NODE (i);
    5363              : 
    5364            0 :   if (mode == TYPE_MODE (void_type_node))
    5365            0 :     return void_type_node;
    5366              : 
    5367            0 :   if (mode == TYPE_MODE (build_pointer_type (char_type_node))
    5368            0 :       || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
    5369              :     {
    5370            0 :       unsigned int precision
    5371            0 :         = GET_MODE_PRECISION (as_a<scalar_int_mode> (mode));
    5372            0 :       return (unsignedp ? make_unsigned_type (precision)
    5373            0 :                         : make_signed_type (precision));
    5374              :     }
    5375              : 
    5376            0 :   if (COMPLEX_MODE_P (mode))
    5377              :     {
    5378            0 :       machine_mode inner_mode;
    5379            0 :       tree inner_type;
    5380              : 
    5381            0 :       if (mode == TYPE_MODE (complex_float_type_node))
    5382            0 :         return complex_float_type_node;
    5383            0 :       if (mode == TYPE_MODE (complex_double_type_node))
    5384            0 :         return complex_double_type_node;
    5385            0 :       if (mode == TYPE_MODE (complex_long_double_type_node))
    5386            0 :         return complex_long_double_type_node;
    5387              : 
    5388            0 :       for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    5389            0 :         if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    5390            0 :             && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
    5391            0 :           return COMPLEX_FLOATN_NX_TYPE_NODE (i);
    5392              : 
    5393            0 :       if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
    5394            0 :         return complex_integer_type_node;
    5395              : 
    5396            0 :       inner_mode = GET_MODE_INNER (mode);
    5397            0 :       inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    5398            0 :       if (inner_type != NULL_TREE)
    5399            0 :         return build_complex_type (inner_type);
    5400              :     }
    5401            0 :   else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
    5402            0 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    5403              :     {
    5404            0 :       unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
    5405              :                                                     GET_MODE_NUNITS (mode));
    5406            0 :       tree bool_type = build_nonstandard_boolean_type (elem_bits);
    5407            0 :       return build_vector_type_for_mode (bool_type, mode);
    5408              :     }
    5409            0 :   else if (VECTOR_MODE_P (mode)
    5410            0 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    5411              :     {
    5412            0 :       machine_mode inner_mode = GET_MODE_INNER (mode);
    5413            0 :       tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    5414            0 :       if (inner_type != NULL_TREE)
    5415            0 :         return build_vector_type_for_mode (inner_type, mode);
    5416              :     }
    5417              : 
    5418            0 :   if (dfloat32_type_node != NULL_TREE && mode == TYPE_MODE (dfloat32_type_node))
    5419            0 :     return dfloat32_type_node;
    5420            0 :   if (dfloat64_type_node != NULL_TREE && mode == TYPE_MODE (dfloat64_type_node))
    5421            0 :     return dfloat64_type_node;
    5422            0 :   if (dfloat128_type_node != NULL_TREE
    5423            0 :       && mode == TYPE_MODE (dfloat128_type_node))
    5424            0 :     return dfloat128_type_node;
    5425              : 
    5426            0 :   if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
    5427              :     {
    5428            0 :       if (mode == TYPE_MODE (short_fract_type_node))
    5429            0 :         return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
    5430            0 :       if (mode == TYPE_MODE (fract_type_node))
    5431            0 :         return unsignedp ? sat_fract_type_node : fract_type_node;
    5432            0 :       if (mode == TYPE_MODE (long_fract_type_node))
    5433            0 :         return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
    5434            0 :       if (mode == TYPE_MODE (long_long_fract_type_node))
    5435            0 :         return unsignedp ? sat_long_long_fract_type_node
    5436            0 :                          : long_long_fract_type_node;
    5437              : 
    5438            0 :       if (mode == TYPE_MODE (unsigned_short_fract_type_node))
    5439            0 :         return unsignedp ? sat_unsigned_short_fract_type_node
    5440            0 :                          : unsigned_short_fract_type_node;
    5441            0 :       if (mode == TYPE_MODE (unsigned_fract_type_node))
    5442            0 :         return unsignedp ? sat_unsigned_fract_type_node
    5443            0 :                          : unsigned_fract_type_node;
    5444            0 :       if (mode == TYPE_MODE (unsigned_long_fract_type_node))
    5445            0 :         return unsignedp ? sat_unsigned_long_fract_type_node
    5446            0 :                          : unsigned_long_fract_type_node;
    5447            0 :       if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
    5448            0 :         return unsignedp ? sat_unsigned_long_long_fract_type_node
    5449            0 :                          : unsigned_long_long_fract_type_node;
    5450              : 
    5451            0 :       if (mode == TYPE_MODE (short_accum_type_node))
    5452            0 :         return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
    5453            0 :       if (mode == TYPE_MODE (accum_type_node))
    5454            0 :         return unsignedp ? sat_accum_type_node : accum_type_node;
    5455            0 :       if (mode == TYPE_MODE (long_accum_type_node))
    5456            0 :         return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
    5457            0 :       if (mode == TYPE_MODE (long_long_accum_type_node))
    5458            0 :         return unsignedp ? sat_long_long_accum_type_node
    5459            0 :                          : long_long_accum_type_node;
    5460              : 
    5461            0 :       if (mode == TYPE_MODE (unsigned_short_accum_type_node))
    5462            0 :         return unsignedp ? sat_unsigned_short_accum_type_node
    5463            0 :                          : unsigned_short_accum_type_node;
    5464            0 :       if (mode == TYPE_MODE (unsigned_accum_type_node))
    5465            0 :         return unsignedp ? sat_unsigned_accum_type_node
    5466            0 :                          : unsigned_accum_type_node;
    5467            0 :       if (mode == TYPE_MODE (unsigned_long_accum_type_node))
    5468            0 :         return unsignedp ? sat_unsigned_long_accum_type_node
    5469            0 :                          : unsigned_long_accum_type_node;
    5470            0 :       if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
    5471            0 :         return unsignedp ? sat_unsigned_long_long_accum_type_node
    5472            0 :                          : unsigned_long_long_accum_type_node;
    5473              : 
    5474            0 :       if (mode == QQmode)
    5475            0 :         return unsignedp ? sat_qq_type_node : qq_type_node;
    5476              :       if (mode == HQmode)
    5477            0 :         return unsignedp ? sat_hq_type_node : hq_type_node;
    5478              :       if (mode == SQmode)
    5479            0 :         return unsignedp ? sat_sq_type_node : sq_type_node;
    5480              :       if (mode == DQmode)
    5481            0 :         return unsignedp ? sat_dq_type_node : dq_type_node;
    5482              :       if (mode == TQmode)
    5483            0 :         return unsignedp ? sat_tq_type_node : tq_type_node;
    5484              : 
    5485              :       if (mode == UQQmode)
    5486            0 :         return unsignedp ? sat_uqq_type_node : uqq_type_node;
    5487              :       if (mode == UHQmode)
    5488            0 :         return unsignedp ? sat_uhq_type_node : uhq_type_node;
    5489              :       if (mode == USQmode)
    5490            0 :         return unsignedp ? sat_usq_type_node : usq_type_node;
    5491              :       if (mode == UDQmode)
    5492            0 :         return unsignedp ? sat_udq_type_node : udq_type_node;
    5493              :       if (mode == UTQmode)
    5494            0 :         return unsignedp ? sat_utq_type_node : utq_type_node;
    5495              : 
    5496              :       if (mode == HAmode)
    5497            0 :         return unsignedp ? sat_ha_type_node : ha_type_node;
    5498              :       if (mode == SAmode)
    5499            0 :         return unsignedp ? sat_sa_type_node : sa_type_node;
    5500              :       if (mode == DAmode)
    5501            0 :         return unsignedp ? sat_da_type_node : da_type_node;
    5502              :       if (mode == TAmode)
    5503            0 :         return unsignedp ? sat_ta_type_node : ta_type_node;
    5504              : 
    5505              :       if (mode == UHAmode)
    5506            0 :         return unsignedp ? sat_uha_type_node : uha_type_node;
    5507              :       if (mode == USAmode)
    5508            0 :         return unsignedp ? sat_usa_type_node : usa_type_node;
    5509              :       if (mode == UDAmode)
    5510            0 :         return unsignedp ? sat_uda_type_node : uda_type_node;
    5511              :       if (mode == UTAmode)
    5512            0 :         return unsignedp ? sat_uta_type_node : uta_type_node;
    5513              :     }
    5514              : 
    5515            0 :   for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
    5516              :     {
    5517            0 :       tree type = TREE_VALUE (t);
    5518            0 :       if (TYPE_MODE (type) == mode
    5519            0 :           && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
    5520            0 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    5521              :         return type;
    5522              :     }
    5523              :   return NULL_TREE;
    5524              : }
    5525              : 
    5526              : // forked from gcc/cp/semantics.cc finish_underlying_type
    5527              : 
    5528              : /* Implement the __underlying_type keyword: Return the underlying
    5529              :    type of TYPE, suitable for use as a type-specifier.  */
    5530              : 
    5531              : tree
    5532            0 : finish_underlying_type (tree type)
    5533              : {
    5534            0 :   tree underlying_type;
    5535              : 
    5536            0 :   if (!complete_type_or_else (type, NULL_TREE))
    5537            0 :     return error_mark_node;
    5538              : 
    5539            0 :   if (TREE_CODE (type) != ENUMERAL_TYPE)
    5540              :     {
    5541            0 :       error ("%qT is not an enumeration type", type);
    5542            0 :       return error_mark_node;
    5543              :     }
    5544              : 
    5545            0 :   underlying_type = ENUM_UNDERLYING_TYPE (type);
    5546              : 
    5547              :   /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
    5548              :      includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
    5549              :      See finish_enum_value_list for details.  */
    5550            0 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
    5551            0 :     underlying_type = c_common_type_for_mode (TYPE_MODE (underlying_type),
    5552            0 :                                               TYPE_UNSIGNED (underlying_type));
    5553              : 
    5554              :   return underlying_type;
    5555              : }
    5556              : 
    5557              : // forked from gcc/cp/typeck.cc layout_compatible_type_p
    5558              : 
    5559              : /* Return true if TYPE1 and TYPE2 are layout-compatible types.  */
    5560              : 
    5561              : bool
    5562            0 : layout_compatible_type_p (tree type1, tree type2)
    5563              : {
    5564            0 :   if (type1 == error_mark_node || type2 == error_mark_node)
    5565              :     return false;
    5566            0 :   if (type1 == type2)
    5567              :     return true;
    5568            0 :   if (TREE_CODE (type1) != TREE_CODE (type2))
    5569              :     return false;
    5570              : 
    5571            0 :   type1 = rs_build_qualified_type (type1, TYPE_UNQUALIFIED);
    5572            0 :   type2 = rs_build_qualified_type (type2, TYPE_UNQUALIFIED);
    5573              : 
    5574            0 :   if (TREE_CODE (type1) == ENUMERAL_TYPE)
    5575            0 :     return (TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
    5576            0 :             && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))
    5577            0 :             && same_type_p (finish_underlying_type (type1),
    5578              :                             finish_underlying_type (type2)));
    5579              : 
    5580            0 :   if (CLASS_TYPE_P (type1) && std_layout_type_p (type1)
    5581            0 :       && std_layout_type_p (type2) && TYPE_ALIGN (type1) == TYPE_ALIGN (type2)
    5582            0 :       && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)))
    5583              :     {
    5584            0 :       tree field1 = TYPE_FIELDS (type1);
    5585            0 :       tree field2 = TYPE_FIELDS (type2);
    5586            0 :       if (TREE_CODE (type1) == RECORD_TYPE)
    5587              :         {
    5588            0 :           while (1)
    5589              :             {
    5590            0 :               if (!next_common_initial_seqence (field1, field2))
    5591              :                 return false;
    5592            0 :               if (field1 == NULL_TREE)
    5593              :                 return true;
    5594            0 :               field1 = DECL_CHAIN (field1);
    5595            0 :               field2 = DECL_CHAIN (field2);
    5596              :             }
    5597              :         }
    5598              :       /* Otherwise both types must be union types.
    5599              :          The standard says:
    5600              :          "Two standard-layout unions are layout-compatible if they have
    5601              :          the same number of non-static data members and corresponding
    5602              :          non-static data members (in any order) have layout-compatible
    5603              :          types."
    5604              :          but the code anticipates that bitfield vs. non-bitfield,
    5605              :          different bitfield widths or presence/absence of
    5606              :          [[no_unique_address]] should be checked as well.  */
    5607            0 :       auto_vec<tree, 16> vec;
    5608            0 :       unsigned int count = 0;
    5609            0 :       for (; field1; field1 = DECL_CHAIN (field1))
    5610            0 :         if (TREE_CODE (field1) == FIELD_DECL)
    5611            0 :           count++;
    5612            0 :       for (; field2; field2 = DECL_CHAIN (field2))
    5613            0 :         if (TREE_CODE (field2) == FIELD_DECL)
    5614            0 :           vec.safe_push (field2);
    5615              :       /* Discussions on core lean towards treating multiple union fields
    5616              :          of the same type as the same field, so this might need changing
    5617              :          in the future.  */
    5618            0 :       if (count != vec.length ())
    5619              :         return false;
    5620            0 :       for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
    5621              :         {
    5622            0 :           if (TREE_CODE (field1) != FIELD_DECL)
    5623            0 :             continue;
    5624            0 :           unsigned int j;
    5625            0 :           tree t1 = DECL_BIT_FIELD_TYPE (field1);
    5626            0 :           if (t1 == NULL_TREE)
    5627            0 :             t1 = TREE_TYPE (field1);
    5628            0 :           FOR_EACH_VEC_ELT (vec, j, field2)
    5629              :             {
    5630            0 :               tree t2 = DECL_BIT_FIELD_TYPE (field2);
    5631            0 :               if (t2 == NULL_TREE)
    5632            0 :                 t2 = TREE_TYPE (field2);
    5633            0 :               if (DECL_BIT_FIELD_TYPE (field1))
    5634              :                 {
    5635            0 :                   if (!DECL_BIT_FIELD_TYPE (field2))
    5636            0 :                     continue;
    5637            0 :                   if (TYPE_PRECISION (TREE_TYPE (field1))
    5638            0 :                       != TYPE_PRECISION (TREE_TYPE (field2)))
    5639            0 :                     continue;
    5640              :                 }
    5641            0 :               else if (DECL_BIT_FIELD_TYPE (field2))
    5642            0 :                 continue;
    5643            0 :               if (!layout_compatible_type_p (t1, t2))
    5644            0 :                 continue;
    5645            0 :               if ((!lookup_attribute ("no_unique_address",
    5646            0 :                                       DECL_ATTRIBUTES (field1)))
    5647            0 :                   != !lookup_attribute ("no_unique_address",
    5648            0 :                                         DECL_ATTRIBUTES (field2)))
    5649            0 :                 continue;
    5650              :               break;
    5651              :             }
    5652            0 :           if (j == vec.length ())
    5653              :             return false;
    5654            0 :           vec.unordered_remove (j);
    5655              :         }
    5656              :       return true;
    5657            0 :     }
    5658              : 
    5659            0 :   return same_type_p (type1, type2);
    5660              : }
    5661              : 
    5662              : // forked from gcc/cp/semnatics.cc is_corresponding_member_union
    5663              : 
    5664              : /* Helper function for is_corresponding_member_aggr.  Return true if
    5665              :    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
    5666              :    union or structure BASETYPE.  */
    5667              : 
    5668              : static bool
    5669            0 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
    5670              : {
    5671            0 :   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
    5672            0 :     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
    5673            0 :       continue;
    5674            0 :     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
    5675              :                                                         membertype))
    5676              :       {
    5677            0 :         if (TREE_CODE (arg) != INTEGER_CST
    5678            0 :             || tree_int_cst_equal (arg, byte_position (field)))
    5679            0 :           return true;
    5680              :       }
    5681            0 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    5682              :       {
    5683            0 :         tree narg = arg;
    5684            0 :         if (TREE_CODE (basetype) != UNION_TYPE
    5685            0 :             && TREE_CODE (narg) == INTEGER_CST)
    5686            0 :           narg = size_binop (MINUS_EXPR, arg, byte_position (field));
    5687            0 :         if (is_corresponding_member_union (TREE_TYPE (field), membertype, narg))
    5688              :           return true;
    5689              :       }
    5690              :   return false;
    5691              : }
    5692              : 
    5693              : // forked from gcc/cp/typeck.cc next_common_initial_seqence
    5694              : 
    5695              : /* Helper function for layout_compatible_type_p and
    5696              :    is_corresponding_member_aggr.  Advance to next members (NULL if
    5697              :    no further ones) and return true if those members are still part of
    5698              :    the common initial sequence.  */
    5699              : 
    5700              : bool
    5701            0 : next_common_initial_seqence (tree &memb1, tree &memb2)
    5702              : {
    5703            0 :   while (memb1)
    5704              :     {
    5705            0 :       if (TREE_CODE (memb1) != FIELD_DECL
    5706            0 :           || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
    5707              :         {
    5708            0 :           memb1 = DECL_CHAIN (memb1);
    5709            0 :           continue;
    5710              :         }
    5711            0 :       if (DECL_FIELD_IS_BASE (memb1))
    5712              :         {
    5713            0 :           memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
    5714            0 :           continue;
    5715              :         }
    5716              :       break;
    5717              :     }
    5718            0 :   while (memb2)
    5719              :     {
    5720            0 :       if (TREE_CODE (memb2) != FIELD_DECL
    5721            0 :           || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
    5722              :         {
    5723            0 :           memb2 = DECL_CHAIN (memb2);
    5724            0 :           continue;
    5725              :         }
    5726            0 :       if (DECL_FIELD_IS_BASE (memb2))
    5727              :         {
    5728            0 :           memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
    5729            0 :           continue;
    5730              :         }
    5731              :       break;
    5732              :     }
    5733            0 :   if (memb1 == NULL_TREE && memb2 == NULL_TREE)
    5734              :     return true;
    5735            0 :   if (memb1 == NULL_TREE || memb2 == NULL_TREE)
    5736              :     return false;
    5737            0 :   if (DECL_BIT_FIELD_TYPE (memb1))
    5738              :     {
    5739            0 :       if (!DECL_BIT_FIELD_TYPE (memb2))
    5740              :         return false;
    5741            0 :       if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
    5742            0 :                                      DECL_BIT_FIELD_TYPE (memb2)))
    5743              :         return false;
    5744            0 :       if (TYPE_PRECISION (TREE_TYPE (memb1))
    5745            0 :           != TYPE_PRECISION (TREE_TYPE (memb2)))
    5746              :         return false;
    5747              :     }
    5748            0 :   else if (DECL_BIT_FIELD_TYPE (memb2))
    5749              :     return false;
    5750            0 :   else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
    5751              :     return false;
    5752            0 :   if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
    5753            0 :       != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
    5754              :     return false;
    5755            0 :   if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
    5756              :     return false;
    5757              :   return true;
    5758              : }
    5759              : 
    5760              : // forked from gcc/cp/semantics.cc is_corresponding_member_aggr
    5761              : 
    5762              : /* Helper function for fold_builtin_is_corresponding_member call.
    5763              :    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
    5764              :    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
    5765              :    boolean_true_node if they are corresponding members, or for
    5766              :    non-constant ARG2 the highest member offset for corresponding
    5767              :    members.  */
    5768              : 
    5769              : static tree
    5770            0 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
    5771              :                               tree arg1, tree basetype2, tree membertype2,
    5772              :                               tree arg2)
    5773              : {
    5774            0 :   tree field1 = TYPE_FIELDS (basetype1);
    5775            0 :   tree field2 = TYPE_FIELDS (basetype2);
    5776            0 :   tree ret = boolean_false_node;
    5777            0 :   while (1)
    5778              :     {
    5779            0 :       bool r = next_common_initial_seqence (field1, field2);
    5780            0 :       if (field1 == NULL_TREE || field2 == NULL_TREE)
    5781              :         break;
    5782            0 :       if (r
    5783            0 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
    5784              :                                                         membertype1)
    5785            0 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
    5786              :                                                         membertype2))
    5787              :         {
    5788            0 :           tree pos = byte_position (field1);
    5789            0 :           if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_equal (arg1, pos))
    5790              :             {
    5791            0 :               if (TREE_CODE (arg2) == INTEGER_CST)
    5792            0 :                 return boolean_true_node;
    5793              :               return pos;
    5794              :             }
    5795            0 :           else if (TREE_CODE (arg1) != INTEGER_CST)
    5796            0 :             ret = pos;
    5797              :         }
    5798            0 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
    5799            0 :                && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
    5800              :         {
    5801            0 :           if ((!lookup_attribute ("no_unique_address",
    5802            0 :                                   DECL_ATTRIBUTES (field1)))
    5803            0 :               != !lookup_attribute ("no_unique_address",
    5804            0 :                                     DECL_ATTRIBUTES (field2)))
    5805              :             break;
    5806            0 :           if (!tree_int_cst_equal (bit_position (field1),
    5807            0 :                                    bit_position (field2)))
    5808              :             break;
    5809            0 :           bool overlap = true;
    5810            0 :           tree pos = byte_position (field1);
    5811            0 :           if (TREE_CODE (arg1) == INTEGER_CST)
    5812              :             {
    5813            0 :               tree off1 = fold_convert (sizetype, arg1);
    5814            0 :               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
    5815            0 :               if (tree_int_cst_lt (off1, pos)
    5816            0 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
    5817              :                 overlap = false;
    5818              :             }
    5819            0 :           if (TREE_CODE (arg2) == INTEGER_CST)
    5820              :             {
    5821            0 :               tree off2 = fold_convert (sizetype, arg2);
    5822            0 :               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
    5823            0 :               if (tree_int_cst_lt (off2, pos)
    5824            0 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
    5825              :                 overlap = false;
    5826              :             }
    5827            0 :           if (overlap && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
    5828            0 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
    5829              :             {
    5830            0 :               tree narg1 = arg1;
    5831            0 :               if (TREE_CODE (arg1) == INTEGER_CST)
    5832            0 :                 narg1
    5833            0 :                   = size_binop (MINUS_EXPR, fold_convert (sizetype, arg1), pos);
    5834            0 :               tree narg2 = arg2;
    5835            0 :               if (TREE_CODE (arg2) == INTEGER_CST)
    5836            0 :                 narg2
    5837            0 :                   = size_binop (MINUS_EXPR, fold_convert (sizetype, arg2), pos);
    5838            0 :               tree t1 = TREE_TYPE (field1);
    5839            0 :               tree t2 = TREE_TYPE (field2);
    5840            0 :               tree nret
    5841            0 :                 = is_corresponding_member_aggr (loc, t1, membertype1, narg1, t2,
    5842              :                                                 membertype2, narg2);
    5843            0 :               if (nret != boolean_false_node)
    5844              :                 {
    5845            0 :                   if (nret == boolean_true_node)
    5846              :                     return nret;
    5847            0 :                   if (TREE_CODE (arg1) == INTEGER_CST)
    5848            0 :                     return size_binop (PLUS_EXPR, nret, pos);
    5849            0 :                   ret = size_binop (PLUS_EXPR, nret, pos);
    5850              :                 }
    5851              :             }
    5852            0 :           else if (overlap && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
    5853            0 :                    && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
    5854              :             {
    5855            0 :               tree narg1 = arg1;
    5856            0 :               if (TREE_CODE (arg1) == INTEGER_CST)
    5857            0 :                 narg1
    5858            0 :                   = size_binop (MINUS_EXPR, fold_convert (sizetype, arg1), pos);
    5859            0 :               tree narg2 = arg2;
    5860            0 :               if (TREE_CODE (arg2) == INTEGER_CST)
    5861            0 :                 narg2
    5862            0 :                   = size_binop (MINUS_EXPR, fold_convert (sizetype, arg2), pos);
    5863            0 :               if (is_corresponding_member_union (TREE_TYPE (field1),
    5864              :                                                  membertype1, narg1)
    5865            0 :                   && is_corresponding_member_union (TREE_TYPE (field2),
    5866              :                                                     membertype2, narg2))
    5867              :                 {
    5868            0 :                   sorry_at (loc, "%<__builtin_is_corresponding_member%> "
    5869              :                                  "not well defined for anonymous unions");
    5870            0 :                   return boolean_false_node;
    5871              :                 }
    5872              :             }
    5873              :         }
    5874            0 :       if (!r)
    5875              :         break;
    5876            0 :       field1 = DECL_CHAIN (field1);
    5877            0 :       field2 = DECL_CHAIN (field2);
    5878            0 :     }
    5879              :   return ret;
    5880              : }
    5881              : 
    5882              : // forked from gcc/cp/call.cc null_member_pointer_value_p
    5883              : 
    5884              : /* Returns true iff T is a null member pointer value (4.11).  */
    5885              : 
    5886              : bool
    5887            0 : null_member_pointer_value_p (tree t)
    5888              : {
    5889            0 :   tree type = TREE_TYPE (t);
    5890            0 :   if (!type)
    5891              :     return false;
    5892            0 :   else if (TYPE_PTRMEMFUNC_P (type))
    5893            0 :     return (TREE_CODE (t) == CONSTRUCTOR && CONSTRUCTOR_NELTS (t)
    5894            0 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
    5895            0 :   else if (TYPE_PTRDATAMEM_P (type))
    5896            0 :     return integer_all_onesp (t);
    5897              :   else
    5898              :     return false;
    5899              : }
    5900              : 
    5901              : // forked from gcc/cp/semantics.cc fold_builtin_is_corresponding_member
    5902              : 
    5903              : /* Fold __builtin_is_corresponding_member call.  */
    5904              : 
    5905              : tree
    5906            0 : fold_builtin_is_corresponding_member (location_t loc, int nargs, tree *args)
    5907              : {
    5908              :   /* Unless users call the builtin directly, the following 3 checks should be
    5909              :      ensured from std::is_corresponding_member function template.  */
    5910            0 :   if (nargs != 2)
    5911              :     {
    5912            0 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
    5913              :                      "needs two arguments");
    5914            0 :       return boolean_false_node;
    5915              :     }
    5916            0 :   tree arg1 = args[0];
    5917            0 :   tree arg2 = args[1];
    5918            0 :   if (error_operand_p (arg1) || error_operand_p (arg2))
    5919            0 :     return boolean_false_node;
    5920            0 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1)) || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
    5921              :     {
    5922            0 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
    5923              :                      "argument is not pointer to member");
    5924            0 :       return boolean_false_node;
    5925              :     }
    5926              : 
    5927            0 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
    5928            0 :       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
    5929            0 :     return boolean_false_node;
    5930              : 
    5931            0 :   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
    5932            0 :   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
    5933            0 :   if (!complete_type_or_else (basetype1, NULL_TREE))
    5934            0 :     return boolean_false_node;
    5935              : 
    5936            0 :   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
    5937            0 :   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
    5938            0 :   if (!complete_type_or_else (basetype2, NULL_TREE))
    5939            0 :     return boolean_false_node;
    5940              : 
    5941            0 :   if (!NON_UNION_CLASS_TYPE_P (basetype1) || !NON_UNION_CLASS_TYPE_P (basetype2)
    5942            0 :       || !std_layout_type_p (basetype1) || !std_layout_type_p (basetype2))
    5943            0 :     return boolean_false_node;
    5944              : 
    5945              :   /* If the member types aren't layout compatible, then they
    5946              :      can't be corresponding members.  */
    5947            0 :   if (!layout_compatible_type_p (membertype1, membertype2))
    5948            0 :     return boolean_false_node;
    5949              : 
    5950            0 :   if (null_member_pointer_value_p (arg1) || null_member_pointer_value_p (arg2))
    5951            0 :     return boolean_false_node;
    5952              : 
    5953            0 :   if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg2) == INTEGER_CST
    5954            0 :       && !tree_int_cst_equal (arg1, arg2))
    5955            0 :     return boolean_false_node;
    5956              : 
    5957            0 :   if (TREE_CODE (arg2) == INTEGER_CST && TREE_CODE (arg1) != INTEGER_CST)
    5958              :     {
    5959              :       std::swap (arg1, arg2);
    5960              :       std::swap (membertype1, membertype2);
    5961              :       std::swap (basetype1, basetype2);
    5962              :     }
    5963              : 
    5964            0 :   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
    5965              :                                            basetype2, membertype2, arg2);
    5966            0 :   if (TREE_TYPE (ret) == boolean_type_node)
    5967              :     return ret;
    5968              :   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
    5969              :      already returns boolean_{true,false}_node whether those particular
    5970              :      members are corresponding members or not.  Otherwise, if only
    5971              :      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
    5972              :      above), it returns boolean_false_node if it is certainly not a
    5973              :      corresponding member and otherwise we need to do a runtime check that
    5974              :      those two OFFSET_TYPE offsets are equal.
    5975              :      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
    5976              :      returns the largest offset at which the members would be corresponding
    5977              :      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
    5978            0 :   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
    5979            0 :   if (TREE_CODE (arg1) == INTEGER_CST)
    5980            0 :     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
    5981              :                         fold_convert (TREE_TYPE (arg1), arg2));
    5982            0 :   ret = fold_build2 (LE_EXPR, boolean_type_node,
    5983              :                      fold_convert (pointer_sized_int_node, arg1),
    5984              :                      fold_convert (pointer_sized_int_node, ret));
    5985            0 :   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
    5986              :                       fold_build2 (EQ_EXPR, boolean_type_node, arg1,
    5987              :                                    fold_convert (TREE_TYPE (arg1), arg2)));
    5988              : }
    5989              : 
    5990              : // forked from gcc/cp/tree.cc lvalue_type
    5991              : 
    5992              : /* The type of ARG when used as an lvalue.  */
    5993              : 
    5994              : tree
    5995            0 : lvalue_type (tree arg)
    5996              : {
    5997            0 :   tree type = TREE_TYPE (arg);
    5998            0 :   return type;
    5999              : }
    6000              : 
    6001              : // forked from gcc/c-family/c-warn.cc lvalue_error
    6002              : 
    6003              : /* Print an error message for an invalid lvalue.  USE says
    6004              :    how the lvalue is being used and so selects the error message.  LOC
    6005              :    is the location for the error.  */
    6006              : 
    6007              : void
    6008            0 : lvalue_error (location_t loc, enum lvalue_use use)
    6009              : {
    6010            0 :   switch (use)
    6011              :     {
    6012            0 :     case lv_assign:
    6013            0 :       error_at (loc, "lvalue required as left operand of assignment");
    6014            0 :       break;
    6015            0 :     case lv_increment:
    6016            0 :       error_at (loc, "lvalue required as increment operand");
    6017            0 :       break;
    6018            0 :     case lv_decrement:
    6019            0 :       error_at (loc, "lvalue required as decrement operand");
    6020            0 :       break;
    6021            0 :     case lv_addressof:
    6022            0 :       error_at (loc, "lvalue required as unary %<&%> operand");
    6023            0 :       break;
    6024            0 :     case lv_asm:
    6025            0 :       error_at (loc, "lvalue required in %<asm%> statement");
    6026            0 :       break;
    6027            0 :     default:
    6028            0 :       rust_unreachable ();
    6029              :     }
    6030            0 : }
    6031              : 
    6032              : // forked from gcc/cp/cp--gimplify.cc cp_fold_maybe_rvalue
    6033              : 
    6034              : /* Fold expression X which is used as an rvalue if RVAL is true.  */
    6035              : 
    6036              : tree
    6037            0 : cp_fold_maybe_rvalue (tree x, bool rval)
    6038              : {
    6039            0 :   while (true)
    6040              :     {
    6041            0 :       x = fold (x);
    6042            0 :       if (rval)
    6043            0 :         x = mark_rvalue_use (x);
    6044            0 :       if (rval && DECL_P (x) && !TYPE_REF_P (TREE_TYPE (x)))
    6045              :         {
    6046            0 :           tree v = decl_constant_value (x);
    6047            0 :           if (v != x && v != error_mark_node)
    6048              :             {
    6049            0 :               x = v;
    6050            0 :               continue;
    6051              :             }
    6052              :         }
    6053            0 :       break;
    6054            0 :     }
    6055            0 :   return x;
    6056              : }
    6057              : 
    6058              : // forked from gcc/cp/cp--gimplify.cc cp_fold_rvalue
    6059              : 
    6060              : /* Fold expression X which is used as an rvalue.  */
    6061              : 
    6062              : tree
    6063            0 : cp_fold_rvalue (tree x)
    6064              : {
    6065            0 :   return cp_fold_maybe_rvalue (x, true);
    6066              : }
    6067              : 
    6068              : /* Returns true iff class T has a constexpr destructor or has an
    6069              :    implicitly declared destructor that we can't tell if it's constexpr
    6070              :    without forcing a lazy declaration (which might cause undesired
    6071              :    instantiations).  */
    6072              : 
    6073              : static bool
    6074            0 : type_maybe_constexpr_destructor (tree t)
    6075              : {
    6076              :   /* Until C++20, only trivial destruction is constexpr.  */
    6077            0 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    6078              :     return true;
    6079              : 
    6080            0 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    6081              :     /* Assume it's constexpr.  */
    6082              :     return true;
    6083            0 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    6084            0 :   return (fn && Compile::maybe_constexpr_fn (fn));
    6085              : }
    6086              : 
    6087              : /* T is a non-literal type used in a context which requires a constant
    6088              :    expression.  Explain why it isn't literal.  */
    6089              : 
    6090              : void
    6091            0 : explain_non_literal_class (tree t)
    6092              : {
    6093            0 :   static hash_set<tree> *diagnosed;
    6094              : 
    6095            0 :   if (!CLASS_TYPE_P (t))
    6096            0 :     return;
    6097            0 :   t = TYPE_MAIN_VARIANT (t);
    6098              : 
    6099            0 :   if (diagnosed == NULL)
    6100            0 :     diagnosed = new hash_set<tree>;
    6101            0 :   if (diagnosed->add (t))
    6102              :     /* Already explained.  */
    6103              :     return;
    6104              : 
    6105            0 :   auto_diagnostic_group d;
    6106            0 :   inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
    6107            0 :   if (LAMBDA_TYPE_P (t))
    6108            0 :     inform (UNKNOWN_LOCATION,
    6109              :             "  %qT is a closure type, which is only literal in "
    6110              :             "C++17 and later",
    6111              :             t);
    6112            0 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    6113            0 :            && !type_maybe_constexpr_destructor (t))
    6114            0 :     inform (UNKNOWN_LOCATION, "  %q+T does not have %<constexpr%> destructor",
    6115              :             t);
    6116            0 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6117            0 :     inform (UNKNOWN_LOCATION, "  %q+T has a non-trivial destructor", t);
    6118            0 :   else if (CLASSTYPE_NON_AGGREGATE (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    6119            0 :            && !LAMBDA_TYPE_P (t) && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6120              :     {
    6121            0 :       inform (UNKNOWN_LOCATION,
    6122              :               "  %q+T is not an aggregate, does not have a trivial "
    6123              :               "default constructor, and has no %<constexpr%> constructor that "
    6124              :               "is not a copy or move constructor",
    6125              :               t);
    6126            0 :       if (type_has_non_user_provided_default_constructor (t))
    6127              :         /* Note that we can't simply call locate_ctor because when the
    6128              :            constructor is deleted it just returns NULL_TREE.  */
    6129            0 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6130              :           {
    6131            0 :             tree fn = *iter;
    6132            0 :             tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6133              : 
    6134            0 :             parms = skip_artificial_parms_for (fn, parms);
    6135              : 
    6136            0 :             if (sufficient_parms_p (parms))
    6137              :               {
    6138            0 :                 Compile::explain_invalid_constexpr_fn (fn);
    6139            0 :                 break;
    6140              :               }
    6141              :           }
    6142              :     }
    6143              :   else
    6144              :     {
    6145            0 :       tree binfo, base_binfo, field;
    6146            0 :       int i;
    6147            0 :       for (binfo = TYPE_BINFO (t), i = 0;
    6148            0 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6149              :         {
    6150            0 :           tree basetype = TREE_TYPE (base_binfo);
    6151            0 :           if (!CLASSTYPE_LITERAL_P (basetype))
    6152              :             {
    6153            0 :               inform (UNKNOWN_LOCATION,
    6154              :                       "  base class %qT of %q+T is non-literal", basetype, t);
    6155            0 :               explain_non_literal_class (basetype);
    6156            0 :               return;
    6157              :             }
    6158              :         }
    6159            0 :       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
    6160              :         {
    6161            0 :           tree ftype;
    6162            0 :           if (TREE_CODE (field) != FIELD_DECL)
    6163            0 :             continue;
    6164            0 :           ftype = TREE_TYPE (field);
    6165            0 :           if (!Compile::literal_type_p (ftype))
    6166              :             {
    6167            0 :               inform (DECL_SOURCE_LOCATION (field),
    6168              :                       "  non-static data member %qD has non-literal type",
    6169              :                       field);
    6170            0 :               if (CLASS_TYPE_P (ftype))
    6171            0 :                 explain_non_literal_class (ftype);
    6172              :             }
    6173            0 :           if (RS_TYPE_VOLATILE_P (ftype))
    6174            0 :             inform (DECL_SOURCE_LOCATION (field),
    6175              :                     "  non-static data member %qD has volatile type", field);
    6176              :         }
    6177              :     }
    6178            0 : }
    6179              : 
    6180              : // forked from gcc/cp/call.cc reference_related_p
    6181              : 
    6182              : /* Returns nonzero if T1 is reference-related to T2.  */
    6183              : 
    6184              : bool
    6185            0 : reference_related_p (tree t1, tree t2)
    6186              : {
    6187            0 :   if (t1 == error_mark_node || t2 == error_mark_node)
    6188              :     return false;
    6189              : 
    6190            0 :   t1 = TYPE_MAIN_VARIANT (t1);
    6191            0 :   t2 = TYPE_MAIN_VARIANT (t2);
    6192              : 
    6193              :   /* [dcl.init.ref]
    6194              : 
    6195              :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    6196              :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    6197            0 :   return (similar_type_p (t1, t2)
    6198              :           /*|| (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    6199            0 :               && DERIVED_FROM_P (t1, t2))*/);
    6200              : }
    6201              : 
    6202              : // forked from gcc/cp/typeck2.cc ordinary_char_type_p
    6203              : 
    6204              : /* True iff TYPE is a C++20 "ordinary" character type.  */
    6205              : 
    6206              : bool
    6207            0 : ordinary_char_type_p (tree type)
    6208              : {
    6209            0 :   type = TYPE_MAIN_VARIANT (type);
    6210            0 :   return (type == char_type_node || type == signed_char_type_node
    6211            0 :           || type == unsigned_char_type_node);
    6212              : }
    6213              : 
    6214              : // forked from gcc/cp/typeck2.cc array_string_literal_compatible_p
    6215              : 
    6216              : /* True iff the string literal INIT has a type suitable for initializing array
    6217              :    TYPE.  */
    6218              : 
    6219              : bool
    6220            0 : array_string_literal_compatible_p (tree type, tree init)
    6221              : {
    6222            0 :   tree to_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
    6223            0 :   tree from_char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
    6224              : 
    6225            0 :   if (to_char_type == from_char_type)
    6226              :     return true;
    6227              :   /* The array element type does not match the initializing string
    6228              :      literal element type; this is only allowed when both types are
    6229              :      ordinary character type.  There are no string literals of
    6230              :      signed or unsigned char type in the language, but we can get
    6231              :      them internally from converting braced-init-lists to
    6232              :      STRING_CST.  */
    6233            0 :   if (ordinary_char_type_p (to_char_type)
    6234            0 :       && ordinary_char_type_p (from_char_type))
    6235              :     return true;
    6236              :   return false;
    6237              : }
    6238              : 
    6239              : } // namespace Rust
    6240              : 
    6241              : using namespace Rust;
    6242              : 
    6243              : #include "gt-rust-rust-tree.h"
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.