Home | History | Annotate | Line # | Download | only in cp
semantics.cc revision 1.1
      1 /* Perform the semantic phase of parsing, i.e., the process of
      2    building tree structure, checking semantic consistency, and
      3    building RTL.  These routines are used both during actual parsing
      4    and during the instantiation of template functions.
      5 
      6    Copyright (C) 1998-2022 Free Software Foundation, Inc.
      7    Written by Mark Mitchell (mmitchell (at) usa.net) based on code found
      8    formerly in parse.y and pt.cc.
      9 
     10    This file is part of GCC.
     11 
     12    GCC is free software; you can redistribute it and/or modify it
     13    under the terms of the GNU General Public License as published by
     14    the Free Software Foundation; either version 3, or (at your option)
     15    any later version.
     16 
     17    GCC is distributed in the hope that it will be useful, but
     18    WITHOUT ANY WARRANTY; without even the implied warranty of
     19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20    General Public License for more details.
     21 
     22 You should have received a copy of the GNU General Public License
     23 along with GCC; see the file COPYING3.  If not see
     24 <http://www.gnu.org/licenses/>.  */
     25 
     26 #include "config.h"
     27 #include "system.h"
     28 #include "coretypes.h"
     29 #include "target.h"
     30 #include "bitmap.h"
     31 #include "cp-tree.h"
     32 #include "stringpool.h"
     33 #include "cgraph.h"
     34 #include "stmt.h"
     35 #include "varasm.h"
     36 #include "stor-layout.h"
     37 #include "c-family/c-objc.h"
     38 #include "tree-inline.h"
     39 #include "intl.h"
     40 #include "tree-iterator.h"
     41 #include "omp-general.h"
     42 #include "convert.h"
     43 #include "stringpool.h"
     44 #include "attribs.h"
     45 #include "gomp-constants.h"
     46 #include "predict.h"
     47 #include "memmodel.h"
     48 
     49 /* There routines provide a modular interface to perform many parsing
     50    operations.  They may therefore be used during actual parsing, or
     51    during template instantiation, which may be regarded as a
     52    degenerate form of parsing.  */
     53 
     54 static tree maybe_convert_cond (tree);
     55 static tree finalize_nrv_r (tree *, int *, void *);
     56 static tree capture_decltype (tree);
     57 
     58 /* Used for OpenMP non-static data member privatization.  */
     59 
     60 static hash_map<tree, tree> *omp_private_member_map;
     61 static vec<tree> omp_private_member_vec;
     62 static bool omp_private_member_ignore_next;
     63 
     64 
     65 /* Deferred Access Checking Overview
     66    ---------------------------------
     67 
     68    Most C++ expressions and declarations require access checking
     69    to be performed during parsing.  However, in several cases,
     70    this has to be treated differently.
     71 
     72    For member declarations, access checking has to be deferred
     73    until more information about the declaration is known.  For
     74    example:
     75 
     76      class A {
     77 	 typedef int X;
     78        public:
     79 	 X f();
     80      };
     81 
     82      A::X A::f();
     83      A::X g();
     84 
     85    When we are parsing the function return type `A::X', we don't
     86    really know if this is allowed until we parse the function name.
     87 
     88    Furthermore, some contexts require that access checking is
     89    never performed at all.  These include class heads, and template
     90    instantiations.
     91 
     92    Typical use of access checking functions is described here:
     93 
     94    1. When we enter a context that requires certain access checking
     95       mode, the function `push_deferring_access_checks' is called with
     96       DEFERRING argument specifying the desired mode.  Access checking
     97       may be performed immediately (dk_no_deferred), deferred
     98       (dk_deferred), or not performed (dk_no_check).
     99 
    100    2. When a declaration such as a type, or a variable, is encountered,
    101       the function `perform_or_defer_access_check' is called.  It
    102       maintains a vector of all deferred checks.
    103 
    104    3. The global `current_class_type' or `current_function_decl' is then
    105       setup by the parser.  `enforce_access' relies on these information
    106       to check access.
    107 
    108    4. Upon exiting the context mentioned in step 1,
    109       `perform_deferred_access_checks' is called to check all declaration
    110       stored in the vector. `pop_deferring_access_checks' is then
    111       called to restore the previous access checking mode.
    112 
    113       In case of parsing error, we simply call `pop_deferring_access_checks'
    114       without `perform_deferred_access_checks'.  */
    115 
    116 struct GTY(()) deferred_access {
    117   /* A vector representing name-lookups for which we have deferred
    118      checking access controls.  We cannot check the accessibility of
    119      names used in a decl-specifier-seq until we know what is being
    120      declared because code like:
    121 
    122        class A {
    123 	 class B {};
    124 	 B* f();
    125        }
    126 
    127        A::B* A::f() { return 0; }
    128 
    129      is valid, even though `A::B' is not generally accessible.  */
    130   vec<deferred_access_check, va_gc> *deferred_access_checks;
    131 
    132   /* The current mode of access checks.  */
    133   enum deferring_kind deferring_access_checks_kind;
    134 };
    135 
    136 /* Data for deferred access checking.  */
    137 static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
    138 static GTY(()) unsigned deferred_access_no_check;
    139 
    140 /* Save the current deferred access states and start deferred
    141    access checking iff DEFER_P is true.  */
    142 
    143 void
    144 push_deferring_access_checks (deferring_kind deferring)
    145 {
    146   /* For context like template instantiation, access checking
    147      disabling applies to all nested context.  */
    148   if (deferred_access_no_check || deferring == dk_no_check)
    149     deferred_access_no_check++;
    150   else
    151     {
    152       deferred_access e = {NULL, deferring};
    153       vec_safe_push (deferred_access_stack, e);
    154     }
    155 }
    156 
    157 /* Save the current deferred access states and start deferred access
    158    checking, continuing the set of deferred checks in CHECKS.  */
    159 
    160 void
    161 reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
    162 {
    163   push_deferring_access_checks (dk_deferred);
    164   if (!deferred_access_no_check)
    165     deferred_access_stack->last().deferred_access_checks = checks;
    166 }
    167 
    168 /* Resume deferring access checks again after we stopped doing
    169    this previously.  */
    170 
    171 void
    172 resume_deferring_access_checks (void)
    173 {
    174   if (!deferred_access_no_check)
    175     deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
    176 }
    177 
    178 /* Stop deferring access checks.  */
    179 
    180 void
    181 stop_deferring_access_checks (void)
    182 {
    183   if (!deferred_access_no_check)
    184     deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
    185 }
    186 
    187 /* Discard the current deferred access checks and restore the
    188    previous states.  */
    189 
    190 void
    191 pop_deferring_access_checks (void)
    192 {
    193   if (deferred_access_no_check)
    194     deferred_access_no_check--;
    195   else
    196     deferred_access_stack->pop ();
    197 }
    198 
    199 /* Returns a TREE_LIST representing the deferred checks.
    200    The TREE_PURPOSE of each node is the type through which the
    201    access occurred; the TREE_VALUE is the declaration named.
    202    */
    203 
    204 vec<deferred_access_check, va_gc> *
    205 get_deferred_access_checks (void)
    206 {
    207   if (deferred_access_no_check)
    208     return NULL;
    209   else
    210     return (deferred_access_stack->last().deferred_access_checks);
    211 }
    212 
    213 /* Take current deferred checks and combine with the
    214    previous states if we also defer checks previously.
    215    Otherwise perform checks now.  */
    216 
    217 void
    218 pop_to_parent_deferring_access_checks (void)
    219 {
    220   if (deferred_access_no_check)
    221     deferred_access_no_check--;
    222   else
    223     {
    224       vec<deferred_access_check, va_gc> *checks;
    225       deferred_access *ptr;
    226 
    227       checks = (deferred_access_stack->last ().deferred_access_checks);
    228 
    229       deferred_access_stack->pop ();
    230       ptr = &deferred_access_stack->last ();
    231       if (ptr->deferring_access_checks_kind == dk_no_deferred)
    232 	{
    233 	  /* Check access.  */
    234 	  perform_access_checks (checks, tf_warning_or_error);
    235 	}
    236       else
    237 	{
    238 	  /* Merge with parent.  */
    239 	  int i, j;
    240 	  deferred_access_check *chk, *probe;
    241 
    242 	  FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
    243 	    {
    244 	      FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
    245 		{
    246 		  if (probe->binfo == chk->binfo &&
    247 		      probe->decl == chk->decl &&
    248 		      probe->diag_decl == chk->diag_decl)
    249 		    goto found;
    250 		}
    251 	      /* Insert into parent's checks.  */
    252 	      vec_safe_push (ptr->deferred_access_checks, *chk);
    253 	    found:;
    254 	    }
    255 	}
    256     }
    257 }
    258 
    259 /* Called from enforce_access.  A class has attempted (but failed) to access
    260    DECL.  It is already established that a baseclass of that class,
    261    PARENT_BINFO, has private access to DECL.  Examine certain special cases
    262    to find a decl that accurately describes the source of the problem.  If
    263    none of the special cases apply, simply return DECL as the source of the
    264    problem.  */
    265 
    266 static tree
    267 get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
    268 {
    269   /* When a class is denied access to a decl in a baseclass, most of the
    270      time it is because the decl itself was declared as private at the point
    271      of declaration.
    272 
    273      However, in C++, there are (at least) two situations in which a decl
    274      can be private even though it was not originally defined as such.
    275      These two situations only apply if a baseclass had private access to
    276      DECL (this function is only called if that is the case).  */
    277 
    278   /* We should first check whether the reason the parent had private access
    279      to DECL was simply because DECL was created and declared as private in
    280      the parent.  If it was, then DECL is definitively the source of the
    281      problem.  */
    282   if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
    283 			 BINFO_TYPE (parent_binfo)))
    284     return decl;
    285 
    286   /* 1.  If the "using" keyword is used to inherit DECL within the parent,
    287      this may cause DECL to be private, so we should return the using
    288      statement as the source of the problem.
    289 
    290      Scan the fields of PARENT_BINFO and see if there are any using decls.  If
    291      there are, see if they inherit DECL.  If they do, that's where DECL must
    292      have been declared private.  */
    293 
    294   for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
    295        parent_field;
    296        parent_field = DECL_CHAIN (parent_field))
    297     /* Not necessary, but also check TREE_PRIVATE for the sake of
    298        eliminating obviously non-relevant using decls.  */
    299     if (TREE_CODE (parent_field) == USING_DECL
    300 	&& TREE_PRIVATE (parent_field))
    301       {
    302 	tree decl_stripped = strip_using_decl (parent_field);
    303 
    304 	/* The using statement might be overloaded.  If so, we need to
    305 	   check all of the overloads.  */
    306 	for (ovl_iterator iter (decl_stripped); iter; ++iter)
    307 	  /* If equal, the using statement inherits DECL, and so is the
    308 	     source of the access failure, so return it.  */
    309 	  if (*iter == decl)
    310 	    return parent_field;
    311       }
    312 
    313   /* 2.  If DECL was privately inherited by the parent class, then DECL will
    314      be inaccessible, even though it may originally have been accessible to
    315      deriving classes.  In that case, the fault lies with the parent, since it
    316      used a private inheritance, so we return the parent as the source of the
    317      problem.
    318 
    319      Since this is the last check, we just assume it's true.  At worst, it
    320      will simply point to the class that failed to give access, which is
    321      technically true.  */
    322   return TYPE_NAME (BINFO_TYPE (parent_binfo));
    323 }
    324 
    325 /* If the current scope isn't allowed to access DECL along
    326    BASETYPE_PATH, give an error, or if we're parsing a function or class
    327    template, defer the access check to be performed at instantiation time.
    328    The most derived class in BASETYPE_PATH is the one used to qualify DECL.
    329    DIAG_DECL is the declaration to use in the error diagnostic.  */
    330 
    331 static bool
    332 enforce_access (tree basetype_path, tree decl, tree diag_decl,
    333 		tsubst_flags_t complain, access_failure_info *afi = NULL)
    334 {
    335   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
    336 
    337   if (flag_new_inheriting_ctors
    338       && DECL_INHERITED_CTOR (decl))
    339     {
    340       /* 7.3.3/18: The additional constructors are accessible if they would be
    341 	 accessible when used to construct an object of the corresponding base
    342 	 class.  */
    343       decl = strip_inheriting_ctors (decl);
    344       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
    345 				   ba_any, NULL, complain);
    346     }
    347 
    348   tree cs = current_scope ();
    349   if (processing_template_decl
    350       && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
    351     if (tree template_info = get_template_info (cs))
    352       {
    353 	/* When parsing a function or class template, we in general need to
    354 	   defer access checks until template instantiation time, since a friend
    355 	   declaration may grant access only to a particular specialization of
    356 	   the template.  */
    357 
    358 	if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
    359 	  /* But if the member is deemed accessible at parse time, then we can
    360 	     assume it'll be accessible at instantiation time.  */
    361 	  return true;
    362 
    363 	/* Access of a dependent decl should be rechecked after tsubst'ing
    364 	   into the user of the decl, rather than explicitly deferring the
    365 	   check here.  */
    366 	gcc_assert (!uses_template_parms (decl));
    367 	if (TREE_CODE (decl) == FIELD_DECL)
    368 	  gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
    369 
    370 	/* Defer this access check until instantiation time.  */
    371 	deferred_access_check access_check;
    372 	access_check.binfo = basetype_path;
    373 	access_check.decl = decl;
    374 	access_check.diag_decl = diag_decl;
    375 	access_check.loc = input_location;
    376 	vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
    377 	return true;
    378       }
    379 
    380   if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
    381     {
    382       if (flag_new_inheriting_ctors)
    383 	diag_decl = strip_inheriting_ctors (diag_decl);
    384       if (complain & tf_error)
    385 	{
    386 	  access_kind access_failure_reason = ak_none;
    387 
    388 	  /* By default, using the decl as the source of the problem will
    389 	     usually give correct results.  */
    390 	  tree diag_location = diag_decl;
    391 
    392 	  /* However, if a parent of BASETYPE_PATH had private access to decl,
    393 	     then it actually might be the case that the source of the problem
    394 	     is not DECL.  */
    395 	  tree parent_binfo = get_parent_with_private_access (decl,
    396 							      basetype_path);
    397 
    398 	  /* So if a parent did have private access, then we need to do
    399 	     special checks to obtain the best diagnostic location decl.  */
    400 	  if (parent_binfo != NULL_TREE)
    401 	    {
    402 	      diag_location = get_class_access_diagnostic_decl (parent_binfo,
    403 								diag_decl);
    404 
    405 	      /* We also at this point know that the reason access failed was
    406 		 because decl was private.  */
    407 	      access_failure_reason = ak_private;
    408 	    }
    409 
    410 	  /* Finally, generate an error message.  */
    411 	  complain_about_access (decl, diag_decl, diag_location, true,
    412 				 access_failure_reason);
    413 	}
    414       if (afi)
    415 	afi->record_access_failure (basetype_path, decl, diag_decl);
    416       return false;
    417     }
    418 
    419   return true;
    420 }
    421 
    422 /* Perform the access checks in CHECKS.  The TREE_PURPOSE of each node
    423    is the BINFO indicating the qualifying scope used to access the
    424    DECL node stored in the TREE_VALUE of the node.  If CHECKS is empty
    425    or we aren't in SFINAE context or all the checks succeed return TRUE,
    426    otherwise FALSE.  */
    427 
    428 bool
    429 perform_access_checks (vec<deferred_access_check, va_gc> *checks,
    430 		       tsubst_flags_t complain)
    431 {
    432   int i;
    433   deferred_access_check *chk;
    434   location_t loc = input_location;
    435   bool ok = true;
    436 
    437   if (!checks)
    438     return true;
    439 
    440   FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
    441     {
    442       input_location = chk->loc;
    443       ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
    444     }
    445 
    446   input_location = loc;
    447   return (complain & tf_error) ? true : ok;
    448 }
    449 
    450 /* Perform the deferred access checks.
    451 
    452    After performing the checks, we still have to keep the list
    453    `deferred_access_stack->deferred_access_checks' since we may want
    454    to check access for them again later in a different context.
    455    For example:
    456 
    457      class A {
    458        typedef int X;
    459        static X a;
    460      };
    461      A::X A::a, x;	// No error for `A::a', error for `x'
    462 
    463    We have to perform deferred access of `A::X', first with `A::a',
    464    next with `x'.  Return value like perform_access_checks above.  */
    465 
    466 bool
    467 perform_deferred_access_checks (tsubst_flags_t complain)
    468 {
    469   return perform_access_checks (get_deferred_access_checks (), complain);
    470 }
    471 
    472 /* Defer checking the accessibility of DECL, when looked up in
    473    BINFO. DIAG_DECL is the declaration to use to print diagnostics.
    474    Return value like perform_access_checks above.
    475    If non-NULL, report failures to AFI.  */
    476 
    477 bool
    478 perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
    479 			       tsubst_flags_t complain,
    480 			       access_failure_info *afi)
    481 {
    482   int i;
    483   deferred_access *ptr;
    484   deferred_access_check *chk;
    485 
    486   /* Exit if we are in a context that no access checking is performed.  */
    487   if (deferred_access_no_check)
    488     return true;
    489 
    490   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
    491 
    492   ptr = &deferred_access_stack->last ();
    493 
    494   /* If we are not supposed to defer access checks, just check now.  */
    495   if (ptr->deferring_access_checks_kind == dk_no_deferred)
    496     {
    497       bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
    498       return (complain & tf_error) ? true : ok;
    499     }
    500 
    501   /* See if we are already going to perform this check.  */
    502   FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
    503     {
    504       if (chk->decl == decl && chk->binfo == binfo &&
    505 	  chk->diag_decl == diag_decl)
    506 	{
    507 	  return true;
    508 	}
    509     }
    510   /* If not, record the check.  */
    511   deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
    512   vec_safe_push (ptr->deferred_access_checks, new_access);
    513 
    514   return true;
    515 }
    516 
    517 /* Returns nonzero if the current statement is a full expression,
    518    i.e. temporaries created during that statement should be destroyed
    519    at the end of the statement.  */
    520 
    521 int
    522 stmts_are_full_exprs_p (void)
    523 {
    524   return current_stmt_tree ()->stmts_are_full_exprs_p;
    525 }
    526 
    527 /* T is a statement.  Add it to the statement-tree.  This is the C++
    528    version.  The C/ObjC frontends have a slightly different version of
    529    this function.  */
    530 
    531 tree
    532 add_stmt (tree t)
    533 {
    534   enum tree_code code = TREE_CODE (t);
    535 
    536   if (EXPR_P (t) && code != LABEL_EXPR)
    537     {
    538       if (!EXPR_HAS_LOCATION (t))
    539 	SET_EXPR_LOCATION (t, input_location);
    540 
    541       /* When we expand a statement-tree, we must know whether or not the
    542 	 statements are full-expressions.  We record that fact here.  */
    543       if (STATEMENT_CODE_P (TREE_CODE (t)))
    544 	STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
    545     }
    546 
    547   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
    548     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
    549 
    550   /* Add T to the statement-tree.  Non-side-effect statements need to be
    551      recorded during statement expressions.  */
    552   gcc_checking_assert (!stmt_list_stack->is_empty ());
    553   append_to_statement_list_force (t, &cur_stmt_list);
    554 
    555   return t;
    556 }
    557 
    558 /* Returns the stmt_tree to which statements are currently being added.  */
    559 
    560 stmt_tree
    561 current_stmt_tree (void)
    562 {
    563   return (cfun
    564 	  ? &cfun->language->base.x_stmt_tree
    565 	  : &scope_chain->x_stmt_tree);
    566 }
    567 
    568 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR.  */
    569 
    570 static tree
    571 maybe_cleanup_point_expr (tree expr)
    572 {
    573   if (!processing_template_decl && stmts_are_full_exprs_p ())
    574     expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
    575   return expr;
    576 }
    577 
    578 /* Like maybe_cleanup_point_expr except have the type of the new expression be
    579    void so we don't need to create a temporary variable to hold the inner
    580    expression.  The reason why we do this is because the original type might be
    581    an aggregate and we cannot create a temporary variable for that type.  */
    582 
    583 tree
    584 maybe_cleanup_point_expr_void (tree expr)
    585 {
    586   if (!processing_template_decl && stmts_are_full_exprs_p ())
    587     expr = fold_build_cleanup_point_expr (void_type_node, expr);
    588   return expr;
    589 }
    590 
    591 
    592 
    593 /* Create a declaration statement for the declaration given by the DECL.  */
    594 
    595 void
    596 add_decl_expr (tree decl)
    597 {
    598   tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
    599   if (DECL_INITIAL (decl)
    600       || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
    601     r = maybe_cleanup_point_expr_void (r);
    602   add_stmt (r);
    603 }
    604 
    605 /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC.  */
    606 
    607 static void
    608 set_cleanup_locs (tree stmts, location_t loc)
    609 {
    610   if (TREE_CODE (stmts) == CLEANUP_STMT)
    611     {
    612       tree t = CLEANUP_EXPR (stmts);
    613       protected_set_expr_location (t, loc);
    614       /* Avoid locus differences for C++ cdtor calls depending on whether
    615 	 cdtor_returns_this: a conversion to void is added to discard the return
    616 	 value, and this conversion ends up carrying the location, and when it
    617 	 gets discarded, the location is lost.  So hold it in the call as
    618 	 well.  */
    619       if (TREE_CODE (t) == NOP_EXPR
    620 	  && TREE_TYPE (t) == void_type_node
    621 	  && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
    622 	protected_set_expr_location (TREE_OPERAND (t, 0), loc);
    623       set_cleanup_locs (CLEANUP_BODY (stmts), loc);
    624     }
    625   else if (TREE_CODE (stmts) == STATEMENT_LIST)
    626     for (tree stmt : tsi_range (stmts))
    627       set_cleanup_locs (stmt, loc);
    628 }
    629 
    630 /* True iff the innermost block scope is a try block.  */
    631 
    632 static bool
    633 at_try_scope ()
    634 {
    635   cp_binding_level *b = current_binding_level;
    636   while (b && b->kind == sk_cleanup)
    637     b = b->level_chain;
    638   return b && b->kind == sk_try;
    639 }
    640 
    641 /* Finish a scope.  */
    642 
    643 tree
    644 do_poplevel (tree stmt_list)
    645 {
    646   tree block = NULL;
    647 
    648   bool was_try = at_try_scope ();
    649 
    650   if (stmts_are_full_exprs_p ())
    651     block = poplevel (kept_level_p (), 1, 0);
    652 
    653   /* This needs to come after poplevel merges sk_cleanup statement_lists.  */
    654   maybe_splice_retval_cleanup (stmt_list, was_try);
    655 
    656   stmt_list = pop_stmt_list (stmt_list);
    657 
    658   /* input_location is the last token of the scope, usually a }.  */
    659   set_cleanup_locs (stmt_list, input_location);
    660 
    661   if (!processing_template_decl)
    662     {
    663       stmt_list = c_build_bind_expr (input_location, block, stmt_list);
    664       /* ??? See c_end_compound_stmt re statement expressions.  */
    665     }
    666 
    667   return stmt_list;
    668 }
    669 
    670 /* Begin a new scope.  */
    671 
    672 static tree
    673 do_pushlevel (scope_kind sk)
    674 {
    675   tree ret = push_stmt_list ();
    676   if (stmts_are_full_exprs_p ())
    677     begin_scope (sk, NULL);
    678   return ret;
    679 }
    680 
    681 /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
    682    when the current scope is exited.  EH_ONLY is true when this is not
    683    meant to apply to normal control flow transfer.  DECL is the VAR_DECL
    684    being cleaned up, if any, or null for temporaries or subobjects.  */
    685 
    686 void
    687 push_cleanup (tree decl, tree cleanup, bool eh_only)
    688 {
    689   tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
    690   CLEANUP_EH_ONLY (stmt) = eh_only;
    691   add_stmt (stmt);
    692   CLEANUP_BODY (stmt) = push_stmt_list ();
    693 }
    694 
    695 /* Simple infinite loop tracking for -Wreturn-type.  We keep a stack of all
    696    the current loops, represented by 'NULL_TREE' if we've seen a possible
    697    exit, and 'error_mark_node' if not.  This is currently used only to
    698    suppress the warning about a function with no return statements, and
    699    therefore we don't bother noting returns as possible exits.  We also
    700    don't bother with gotos.  */
    701 
    702 static void
    703 begin_maybe_infinite_loop (tree cond)
    704 {
    705   /* Only track this while parsing a function, not during instantiation.  */
    706   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
    707 		&& !processing_template_decl))
    708     return;
    709   bool maybe_infinite = true;
    710   if (cond)
    711     {
    712       cond = fold_non_dependent_expr (cond);
    713       maybe_infinite = integer_nonzerop (cond);
    714     }
    715   vec_safe_push (cp_function_chain->infinite_loops,
    716 		 maybe_infinite ? error_mark_node : NULL_TREE);
    717 
    718 }
    719 
    720 /* A break is a possible exit for the current loop.  */
    721 
    722 void
    723 break_maybe_infinite_loop (void)
    724 {
    725   if (!cfun)
    726     return;
    727   cp_function_chain->infinite_loops->last() = NULL_TREE;
    728 }
    729 
    730 /* If we reach the end of the loop without seeing a possible exit, we have
    731    an infinite loop.  */
    732 
    733 static void
    734 end_maybe_infinite_loop (tree cond)
    735 {
    736   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
    737 		&& !processing_template_decl))
    738     return;
    739   tree current = cp_function_chain->infinite_loops->pop();
    740   if (current != NULL_TREE)
    741     {
    742       cond = fold_non_dependent_expr (cond);
    743       if (integer_nonzerop (cond))
    744 	current_function_infinite_loop = 1;
    745     }
    746 }
    747 
    748 
    749 /* Begin a conditional that might contain a declaration.  When generating
    750    normal code, we want the declaration to appear before the statement
    751    containing the conditional.  When generating template code, we want the
    752    conditional to be rendered as the raw DECL_EXPR.  */
    753 
    754 static void
    755 begin_cond (tree *cond_p)
    756 {
    757   if (processing_template_decl)
    758     *cond_p = push_stmt_list ();
    759 }
    760 
    761 /* Finish such a conditional.  */
    762 
    763 static void
    764 finish_cond (tree *cond_p, tree expr)
    765 {
    766   if (processing_template_decl)
    767     {
    768       tree cond = pop_stmt_list (*cond_p);
    769 
    770       if (expr == NULL_TREE)
    771 	/* Empty condition in 'for'.  */
    772 	gcc_assert (empty_expr_stmt_p (cond));
    773       else if (check_for_bare_parameter_packs (expr))
    774         expr = error_mark_node;
    775       else if (!empty_expr_stmt_p (cond))
    776 	expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
    777     }
    778   *cond_p = expr;
    779 }
    780 
    781 /* If *COND_P specifies a conditional with a declaration, transform the
    782    loop such that
    783 	    while (A x = 42) { }
    784 	    for (; A x = 42;) { }
    785    becomes
    786 	    while (true) { A x = 42; if (!x) break; }
    787 	    for (;;) { A x = 42; if (!x) break; }
    788    The statement list for BODY will be empty if the conditional did
    789    not declare anything.  */
    790 
    791 static void
    792 simplify_loop_decl_cond (tree *cond_p, tree body)
    793 {
    794   tree cond, if_stmt;
    795 
    796   if (!TREE_SIDE_EFFECTS (body))
    797     return;
    798 
    799   cond = *cond_p;
    800   *cond_p = boolean_true_node;
    801 
    802   if_stmt = begin_if_stmt ();
    803   cond_p = &cond;
    804   while (TREE_CODE (*cond_p) == ANNOTATE_EXPR)
    805     cond_p = &TREE_OPERAND (*cond_p, 0);
    806   *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false,
    807 			       tf_warning_or_error);
    808   finish_if_stmt_cond (cond, if_stmt);
    809   finish_break_stmt ();
    810   finish_then_clause (if_stmt);
    811   finish_if_stmt (if_stmt);
    812 }
    813 
    814 /* Finish a goto-statement.  */
    815 
    816 tree
    817 finish_goto_stmt (tree destination)
    818 {
    819   if (identifier_p (destination))
    820     destination = lookup_label (destination);
    821 
    822   /* We warn about unused labels with -Wunused.  That means we have to
    823      mark the used labels as used.  */
    824   if (TREE_CODE (destination) == LABEL_DECL)
    825     TREE_USED (destination) = 1;
    826   else
    827     {
    828       destination = mark_rvalue_use (destination);
    829       if (!processing_template_decl)
    830 	{
    831 	  destination = cp_convert (ptr_type_node, destination,
    832 				    tf_warning_or_error);
    833 	  if (error_operand_p (destination))
    834 	    return NULL_TREE;
    835 	  destination
    836 	    = fold_build_cleanup_point_expr (TREE_TYPE (destination),
    837 					     destination);
    838 	}
    839     }
    840 
    841   check_goto (destination);
    842 
    843   add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
    844   return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
    845 }
    846 
    847 /* COND is the condition-expression for an if, while, etc.,
    848    statement.  Convert it to a boolean value, if appropriate.
    849    In addition, verify sequence points if -Wsequence-point is enabled.  */
    850 
    851 static tree
    852 maybe_convert_cond (tree cond)
    853 {
    854   /* Empty conditions remain empty.  */
    855   if (!cond)
    856     return NULL_TREE;
    857 
    858   /* Wait until we instantiate templates before doing conversion.  */
    859   if (type_dependent_expression_p (cond))
    860     return cond;
    861 
    862   if (warn_sequence_point && !processing_template_decl)
    863     verify_sequence_points (cond);
    864 
    865   /* Do the conversion.  */
    866   cond = convert_from_reference (cond);
    867 
    868   if (TREE_CODE (cond) == MODIFY_EXPR
    869       && warn_parentheses
    870       && !warning_suppressed_p (cond, OPT_Wparentheses)
    871       && warning_at (cp_expr_loc_or_input_loc (cond),
    872 		     OPT_Wparentheses, "suggest parentheses around "
    873 				       "assignment used as truth value"))
    874     suppress_warning (cond, OPT_Wparentheses);
    875 
    876   return condition_conversion (cond);
    877 }
    878 
    879 /* Finish an expression-statement, whose EXPRESSION is as indicated.  */
    880 
    881 tree
    882 finish_expr_stmt (tree expr)
    883 {
    884   tree r = NULL_TREE;
    885   location_t loc = EXPR_LOCATION (expr);
    886 
    887   if (expr != NULL_TREE)
    888     {
    889       /* If we ran into a problem, make sure we complained.  */
    890       gcc_assert (expr != error_mark_node || seen_error ());
    891 
    892       if (!processing_template_decl)
    893 	{
    894 	  if (warn_sequence_point)
    895 	    verify_sequence_points (expr);
    896 	  expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    897 	}
    898       else if (!type_dependent_expression_p (expr))
    899 	convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT,
    900                          tf_warning_or_error);
    901 
    902       if (check_for_bare_parameter_packs (expr))
    903         expr = error_mark_node;
    904 
    905       /* Simplification of inner statement expressions, compound exprs,
    906 	 etc can result in us already having an EXPR_STMT.  */
    907       if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    908 	{
    909 	  if (TREE_CODE (expr) != EXPR_STMT)
    910 	    expr = build_stmt (loc, EXPR_STMT, expr);
    911 	  expr = maybe_cleanup_point_expr_void (expr);
    912 	}
    913 
    914       r = add_stmt (expr);
    915     }
    916 
    917   return r;
    918 }
    919 
    920 
    921 /* Begin an if-statement.  Returns a newly created IF_STMT if
    922    appropriate.  */
    923 
    924 tree
    925 begin_if_stmt (void)
    926 {
    927   tree r, scope;
    928   scope = do_pushlevel (sk_cond);
    929   r = build_stmt (input_location, IF_STMT, NULL_TREE,
    930 		  NULL_TREE, NULL_TREE, scope);
    931   current_binding_level->this_entity = r;
    932   begin_cond (&IF_COND (r));
    933   return r;
    934 }
    935 
    936 /* Returns true if FN, a CALL_EXPR, is a call to
    937    std::is_constant_evaluated or __builtin_is_constant_evaluated.  */
    938 
    939 static bool
    940 is_std_constant_evaluated_p (tree fn)
    941 {
    942   /* std::is_constant_evaluated takes no arguments.  */
    943   if (call_expr_nargs (fn) != 0)
    944     return false;
    945 
    946   tree fndecl = cp_get_callee_fndecl_nofold (fn);
    947   if (fndecl == NULL_TREE)
    948     return false;
    949 
    950   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    951 			 BUILT_IN_FRONTEND))
    952     return true;
    953 
    954   if (!decl_in_std_namespace_p (fndecl))
    955     return false;
    956 
    957   tree name = DECL_NAME (fndecl);
    958   return name && id_equal (name, "is_constant_evaluated");
    959 }
    960 
    961 /* Callback function for maybe_warn_for_constant_evaluated that looks
    962    for calls to std::is_constant_evaluated in TP.  */
    963 
    964 static tree
    965 find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
    966 {
    967   tree t = *tp;
    968 
    969   if (TYPE_P (t) || TREE_CONSTANT (t))
    970     {
    971       *walk_subtrees = false;
    972       return NULL_TREE;
    973     }
    974 
    975   switch (TREE_CODE (t))
    976     {
    977     case CALL_EXPR:
    978       if (is_std_constant_evaluated_p (t))
    979 	return t;
    980       break;
    981     case EXPR_STMT:
    982       /* Don't warn in statement expressions.  */
    983       *walk_subtrees = false;
    984       return NULL_TREE;
    985     default:
    986       break;
    987     }
    988 
    989   return NULL_TREE;
    990 }
    991 
    992 /* In certain contexts, std::is_constant_evaluated() is always true (for
    993    instance, in a consteval function or in a constexpr if), or always false
    994    (e.g., in a non-constexpr non-consteval function) so give the user a clue.  */
    995 
    996 static void
    997 maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if)
    998 {
    999   if (!warn_tautological_compare)
   1000     return;
   1001 
   1002   /* Suppress warning for std::is_constant_evaluated if the conditional
   1003      comes from a macro.  */
   1004   if (from_macro_expansion_at (EXPR_LOCATION (cond)))
   1005     return;
   1006 
   1007   cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
   1008 					  NULL);
   1009   if (cond)
   1010     {
   1011       if (constexpr_if)
   1012 	warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
   1013 		    "%<std::is_constant_evaluated%> always evaluates to "
   1014 		    "true in %<if constexpr%>");
   1015       else if (!maybe_constexpr_fn (current_function_decl))
   1016 	warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
   1017 		    "%<std::is_constant_evaluated%> always evaluates to "
   1018 		    "false in a non-%<constexpr%> function");
   1019       else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
   1020 	warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
   1021 		    "%<std::is_constant_evaluated%> always evaluates to "
   1022 		    "true in a %<consteval%> function");
   1023     }
   1024 }
   1025 
   1026 /* Process the COND of an if-statement, which may be given by
   1027    IF_STMT.  */
   1028 
   1029 tree
   1030 finish_if_stmt_cond (tree cond, tree if_stmt)
   1031 {
   1032   cond = maybe_convert_cond (cond);
   1033   maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt));
   1034   if (IF_STMT_CONSTEXPR_P (if_stmt)
   1035       && !type_dependent_expression_p (cond)
   1036       && require_constant_expression (cond)
   1037       && !instantiation_dependent_expression_p (cond)
   1038       /* Wait until instantiation time, since only then COND has been
   1039 	 converted to bool.  */
   1040       && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
   1041     {
   1042       cond = instantiate_non_dependent_expr (cond);
   1043       cond = cxx_constant_value (cond, NULL_TREE);
   1044     }
   1045   finish_cond (&IF_COND (if_stmt), cond);
   1046   add_stmt (if_stmt);
   1047   THEN_CLAUSE (if_stmt) = push_stmt_list ();
   1048   return cond;
   1049 }
   1050 
   1051 /* Finish the then-clause of an if-statement, which may be given by
   1052    IF_STMT.  */
   1053 
   1054 tree
   1055 finish_then_clause (tree if_stmt)
   1056 {
   1057   THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
   1058   return if_stmt;
   1059 }
   1060 
   1061 /* Begin the else-clause of an if-statement.  */
   1062 
   1063 void
   1064 begin_else_clause (tree if_stmt)
   1065 {
   1066   ELSE_CLAUSE (if_stmt) = push_stmt_list ();
   1067 }
   1068 
   1069 /* Finish the else-clause of an if-statement, which may be given by
   1070    IF_STMT.  */
   1071 
   1072 void
   1073 finish_else_clause (tree if_stmt)
   1074 {
   1075   ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
   1076 }
   1077 
   1078 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
   1079    read.  */
   1080 
   1081 static tree
   1082 maybe_mark_exp_read_r (tree *tp, int *, void *)
   1083 {
   1084   tree t = *tp;
   1085   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   1086     mark_exp_read (t);
   1087   return NULL_TREE;
   1088 }
   1089 
   1090 /* Finish an if-statement.  */
   1091 
   1092 void
   1093 finish_if_stmt (tree if_stmt)
   1094 {
   1095   tree scope = IF_SCOPE (if_stmt);
   1096   IF_SCOPE (if_stmt) = NULL;
   1097   if (IF_STMT_CONSTEXPR_P (if_stmt))
   1098     {
   1099       /* Prevent various -Wunused warnings.  We might not instantiate
   1100 	 either of these branches, so we would not mark the variables
   1101 	 used in that branch as read.  */
   1102       cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
   1103 				       maybe_mark_exp_read_r, NULL);
   1104       cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
   1105 				       maybe_mark_exp_read_r, NULL);
   1106     }
   1107   add_stmt (do_poplevel (scope));
   1108 }
   1109 
   1110 /* Begin a while-statement.  Returns a newly created WHILE_STMT if
   1111    appropriate.  */
   1112 
   1113 tree
   1114 begin_while_stmt (void)
   1115 {
   1116   tree r;
   1117   r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE);
   1118   add_stmt (r);
   1119   WHILE_BODY (r) = do_pushlevel (sk_block);
   1120   begin_cond (&WHILE_COND (r));
   1121   return r;
   1122 }
   1123 
   1124 /* Process the COND of a while-statement, which may be given by
   1125    WHILE_STMT.  */
   1126 
   1127 void
   1128 finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
   1129 			unsigned short unroll)
   1130 {
   1131   cond = maybe_convert_cond (cond);
   1132   finish_cond (&WHILE_COND (while_stmt), cond);
   1133   begin_maybe_infinite_loop (cond);
   1134   if (ivdep && cond != error_mark_node)
   1135     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
   1136 				      TREE_TYPE (WHILE_COND (while_stmt)),
   1137 				      WHILE_COND (while_stmt),
   1138 				      build_int_cst (integer_type_node,
   1139 						     annot_expr_ivdep_kind),
   1140 				      integer_zero_node);
   1141   if (unroll && cond != error_mark_node)
   1142     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
   1143 				      TREE_TYPE (WHILE_COND (while_stmt)),
   1144 				      WHILE_COND (while_stmt),
   1145 				      build_int_cst (integer_type_node,
   1146 						     annot_expr_unroll_kind),
   1147 				      build_int_cst (integer_type_node,
   1148 						     unroll));
   1149   simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
   1150 }
   1151 
   1152 /* Finish a while-statement, which may be given by WHILE_STMT.  */
   1153 
   1154 void
   1155 finish_while_stmt (tree while_stmt)
   1156 {
   1157   end_maybe_infinite_loop (boolean_true_node);
   1158   WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
   1159 }
   1160 
   1161 /* Begin a do-statement.  Returns a newly created DO_STMT if
   1162    appropriate.  */
   1163 
   1164 tree
   1165 begin_do_stmt (void)
   1166 {
   1167   tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE);
   1168   begin_maybe_infinite_loop (boolean_true_node);
   1169   add_stmt (r);
   1170   DO_BODY (r) = push_stmt_list ();
   1171   return r;
   1172 }
   1173 
   1174 /* Finish the body of a do-statement, which may be given by DO_STMT.  */
   1175 
   1176 void
   1177 finish_do_body (tree do_stmt)
   1178 {
   1179   tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
   1180 
   1181   if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
   1182     body = STATEMENT_LIST_TAIL (body)->stmt;
   1183 
   1184   if (IS_EMPTY_STMT (body))
   1185     warning (OPT_Wempty_body,
   1186             "suggest explicit braces around empty body in %<do%> statement");
   1187 }
   1188 
   1189 /* Finish a do-statement, which may be given by DO_STMT, and whose
   1190    COND is as indicated.  */
   1191 
   1192 void
   1193 finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll)
   1194 {
   1195   cond = maybe_convert_cond (cond);
   1196   end_maybe_infinite_loop (cond);
   1197   /* Unlike other iteration statements, the condition may not contain
   1198      a declaration, so we don't call finish_cond which checks for
   1199      unexpanded parameter packs.  */
   1200   if (check_for_bare_parameter_packs (cond))
   1201     cond = error_mark_node;
   1202   if (ivdep && cond != error_mark_node)
   1203     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
   1204 		   build_int_cst (integer_type_node, annot_expr_ivdep_kind),
   1205 		   integer_zero_node);
   1206   if (unroll && cond != error_mark_node)
   1207     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
   1208 		   build_int_cst (integer_type_node, annot_expr_unroll_kind),
   1209 		   build_int_cst (integer_type_node, unroll));
   1210   DO_COND (do_stmt) = cond;
   1211 }
   1212 
   1213 /* Finish a return-statement.  The EXPRESSION returned, if any, is as
   1214    indicated.  */
   1215 
   1216 tree
   1217 finish_return_stmt (tree expr)
   1218 {
   1219   tree r;
   1220   bool no_warning;
   1221 
   1222   expr = check_return_expr (expr, &no_warning);
   1223 
   1224   if (error_operand_p (expr)
   1225       || (flag_openmp && !check_omp_return ()))
   1226     {
   1227       /* Suppress -Wreturn-type for this function.  */
   1228       if (warn_return_type)
   1229 	suppress_warning (current_function_decl, OPT_Wreturn_type);
   1230       return error_mark_node;
   1231     }
   1232 
   1233   if (!processing_template_decl)
   1234     {
   1235       if (warn_sequence_point)
   1236 	verify_sequence_points (expr);
   1237 
   1238       if (DECL_DESTRUCTOR_P (current_function_decl)
   1239 	  || (DECL_CONSTRUCTOR_P (current_function_decl)
   1240 	      && targetm.cxx.cdtor_returns_this ()))
   1241 	{
   1242 	  /* Similarly, all destructors must run destructors for
   1243 	     base-classes before returning.  So, all returns in a
   1244 	     destructor get sent to the DTOR_LABEL; finish_function emits
   1245 	     code to return a value there.  */
   1246 	  return finish_goto_stmt (cdtor_label);
   1247 	}
   1248     }
   1249 
   1250   r = build_stmt (input_location, RETURN_EXPR, expr);
   1251   if (no_warning)
   1252     suppress_warning (r, OPT_Wreturn_type);
   1253   r = maybe_cleanup_point_expr_void (r);
   1254   r = add_stmt (r);
   1255 
   1256   return r;
   1257 }
   1258 
   1259 /* Begin the scope of a for-statement or a range-for-statement.
   1260    Both the returned trees are to be used in a call to
   1261    begin_for_stmt or begin_range_for_stmt.  */
   1262 
   1263 tree
   1264 begin_for_scope (tree *init)
   1265 {
   1266   tree scope = do_pushlevel (sk_for);
   1267 
   1268   if (processing_template_decl)
   1269     *init = push_stmt_list ();
   1270   else
   1271     *init = NULL_TREE;
   1272 
   1273   return scope;
   1274 }
   1275 
   1276 /* Begin a for-statement.  Returns a new FOR_STMT.
   1277    SCOPE and INIT should be the return of begin_for_scope,
   1278    or both NULL_TREE  */
   1279 
   1280 tree
   1281 begin_for_stmt (tree scope, tree init)
   1282 {
   1283   tree r;
   1284 
   1285   r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
   1286 		  NULL_TREE, NULL_TREE, NULL_TREE);
   1287 
   1288   if (scope == NULL_TREE)
   1289     {
   1290       gcc_assert (!init);
   1291       scope = begin_for_scope (&init);
   1292     }
   1293 
   1294   FOR_INIT_STMT (r) = init;
   1295   FOR_SCOPE (r) = scope;
   1296 
   1297   return r;
   1298 }
   1299 
   1300 /* Finish the init-statement of a for-statement, which may be
   1301    given by FOR_STMT.  */
   1302 
   1303 void
   1304 finish_init_stmt (tree for_stmt)
   1305 {
   1306   if (processing_template_decl)
   1307     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
   1308   add_stmt (for_stmt);
   1309   FOR_BODY (for_stmt) = do_pushlevel (sk_block);
   1310   begin_cond (&FOR_COND (for_stmt));
   1311 }
   1312 
   1313 /* Finish the COND of a for-statement, which may be given by
   1314    FOR_STMT.  */
   1315 
   1316 void
   1317 finish_for_cond (tree cond, tree for_stmt, bool ivdep, unsigned short unroll)
   1318 {
   1319   cond = maybe_convert_cond (cond);
   1320   finish_cond (&FOR_COND (for_stmt), cond);
   1321   begin_maybe_infinite_loop (cond);
   1322   if (ivdep && cond != error_mark_node)
   1323     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
   1324 				  TREE_TYPE (FOR_COND (for_stmt)),
   1325 				  FOR_COND (for_stmt),
   1326 				  build_int_cst (integer_type_node,
   1327 						 annot_expr_ivdep_kind),
   1328 				  integer_zero_node);
   1329   if (unroll && cond != error_mark_node)
   1330     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
   1331 				  TREE_TYPE (FOR_COND (for_stmt)),
   1332 				  FOR_COND (for_stmt),
   1333 				  build_int_cst (integer_type_node,
   1334 						 annot_expr_unroll_kind),
   1335 				  build_int_cst (integer_type_node,
   1336 						 unroll));
   1337   simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
   1338 }
   1339 
   1340 /* Finish the increment-EXPRESSION in a for-statement, which may be
   1341    given by FOR_STMT.  */
   1342 
   1343 void
   1344 finish_for_expr (tree expr, tree for_stmt)
   1345 {
   1346   if (!expr)
   1347     return;
   1348   /* If EXPR is an overloaded function, issue an error; there is no
   1349      context available to use to perform overload resolution.  */
   1350   if (type_unknown_p (expr))
   1351     {
   1352       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
   1353       expr = error_mark_node;
   1354     }
   1355   if (!processing_template_decl)
   1356     {
   1357       if (warn_sequence_point)
   1358 	verify_sequence_points (expr);
   1359       expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
   1360                               tf_warning_or_error);
   1361     }
   1362   else if (!type_dependent_expression_p (expr))
   1363     convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR,
   1364                      tf_warning_or_error);
   1365   expr = maybe_cleanup_point_expr_void (expr);
   1366   if (check_for_bare_parameter_packs (expr))
   1367     expr = error_mark_node;
   1368   FOR_EXPR (for_stmt) = expr;
   1369 }
   1370 
   1371 /* Finish the body of a for-statement, which may be given by
   1372    FOR_STMT.  The increment-EXPR for the loop must be
   1373    provided.
   1374    It can also finish RANGE_FOR_STMT. */
   1375 
   1376 void
   1377 finish_for_stmt (tree for_stmt)
   1378 {
   1379   end_maybe_infinite_loop (boolean_true_node);
   1380 
   1381   if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
   1382     RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
   1383   else
   1384     FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
   1385 
   1386   /* Pop the scope for the body of the loop.  */
   1387   tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
   1388 		     ? &RANGE_FOR_SCOPE (for_stmt)
   1389 		     : &FOR_SCOPE (for_stmt));
   1390   tree scope = *scope_ptr;
   1391   *scope_ptr = NULL;
   1392 
   1393   /* During parsing of the body, range for uses "__for_{range,begin,end} "
   1394      decl names to make those unaccessible by code in the body.
   1395      Change it to ones with underscore instead of space, so that it can
   1396      be inspected in the debugger.  */
   1397   tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
   1398   gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
   1399 	      && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
   1400 	      && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
   1401 	      && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
   1402 	      && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
   1403   for (int i = 0; i < 3; i++)
   1404     {
   1405       tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
   1406       if (IDENTIFIER_BINDING (id)
   1407 	  && IDENTIFIER_BINDING (id)->scope == current_binding_level)
   1408 	{
   1409 	  range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
   1410 	  gcc_assert (VAR_P (range_for_decl[i])
   1411 		      && DECL_ARTIFICIAL (range_for_decl[i]));
   1412 	}
   1413     }
   1414 
   1415   add_stmt (do_poplevel (scope));
   1416 
   1417   /* If we're being called from build_vec_init, don't mess with the names of
   1418      the variables for an enclosing range-for.  */
   1419   if (!stmts_are_full_exprs_p ())
   1420     return;
   1421 
   1422   for (int i = 0; i < 3; i++)
   1423     if (range_for_decl[i])
   1424       DECL_NAME (range_for_decl[i])
   1425 	= cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
   1426 }
   1427 
   1428 /* Begin a range-for-statement.  Returns a new RANGE_FOR_STMT.
   1429    SCOPE and INIT should be the return of begin_for_scope,
   1430    or both NULL_TREE  .
   1431    To finish it call finish_for_stmt(). */
   1432 
   1433 tree
   1434 begin_range_for_stmt (tree scope, tree init)
   1435 {
   1436   begin_maybe_infinite_loop (boolean_false_node);
   1437 
   1438   tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
   1439 		       NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
   1440 
   1441   if (scope == NULL_TREE)
   1442     {
   1443       gcc_assert (!init);
   1444       scope = begin_for_scope (&init);
   1445     }
   1446 
   1447   /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it.  */
   1448   RANGE_FOR_INIT_STMT (r) = init;
   1449   RANGE_FOR_SCOPE (r) = scope;
   1450 
   1451   return r;
   1452 }
   1453 
   1454 /* Finish the head of a range-based for statement, which may
   1455    be given by RANGE_FOR_STMT.  DECL must be the declaration
   1456    and EXPR must be the loop expression. */
   1457 
   1458 void
   1459 finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
   1460 {
   1461   if (processing_template_decl)
   1462     RANGE_FOR_INIT_STMT (range_for_stmt)
   1463       = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
   1464   RANGE_FOR_DECL (range_for_stmt) = decl;
   1465   RANGE_FOR_EXPR (range_for_stmt) = expr;
   1466   add_stmt (range_for_stmt);
   1467   RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
   1468 }
   1469 
   1470 /* Finish a break-statement.  */
   1471 
   1472 tree
   1473 finish_break_stmt (void)
   1474 {
   1475   /* In switch statements break is sometimes stylistically used after
   1476      a return statement.  This can lead to spurious warnings about
   1477      control reaching the end of a non-void function when it is
   1478      inlined.  Note that we are calling block_may_fallthru with
   1479      language specific tree nodes; this works because
   1480      block_may_fallthru returns true when given something it does not
   1481      understand.  */
   1482   if (!block_may_fallthru (cur_stmt_list))
   1483     return void_node;
   1484   note_break_stmt ();
   1485   return add_stmt (build_stmt (input_location, BREAK_STMT));
   1486 }
   1487 
   1488 /* Finish a continue-statement.  */
   1489 
   1490 tree
   1491 finish_continue_stmt (void)
   1492 {
   1493   return add_stmt (build_stmt (input_location, CONTINUE_STMT));
   1494 }
   1495 
   1496 /* Begin a switch-statement.  Returns a new SWITCH_STMT if
   1497    appropriate.  */
   1498 
   1499 tree
   1500 begin_switch_stmt (void)
   1501 {
   1502   tree r, scope;
   1503 
   1504   scope = do_pushlevel (sk_cond);
   1505   r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope);
   1506 
   1507   begin_cond (&SWITCH_STMT_COND (r));
   1508 
   1509   return r;
   1510 }
   1511 
   1512 /* Finish the cond of a switch-statement.  */
   1513 
   1514 void
   1515 finish_switch_cond (tree cond, tree switch_stmt)
   1516 {
   1517   tree orig_type = NULL;
   1518 
   1519   if (!processing_template_decl)
   1520     {
   1521       /* Convert the condition to an integer or enumeration type.  */
   1522       tree orig_cond = cond;
   1523       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
   1524       if (cond == NULL_TREE)
   1525 	{
   1526 	  error_at (cp_expr_loc_or_input_loc (orig_cond),
   1527 		    "switch quantity not an integer");
   1528 	  cond = error_mark_node;
   1529 	}
   1530       /* We want unlowered type here to handle enum bit-fields.  */
   1531       orig_type = unlowered_expr_type (cond);
   1532       if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
   1533 	orig_type = TREE_TYPE (cond);
   1534       if (cond != error_mark_node)
   1535 	{
   1536 	  /* [stmt.switch]
   1537 
   1538 	     Integral promotions are performed.  */
   1539 	  cond = perform_integral_promotions (cond);
   1540 	  cond = maybe_cleanup_point_expr (cond);
   1541 	}
   1542     }
   1543   if (check_for_bare_parameter_packs (cond))
   1544     cond = error_mark_node;
   1545   else if (!processing_template_decl && warn_sequence_point)
   1546     verify_sequence_points (cond);
   1547 
   1548   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
   1549   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
   1550   add_stmt (switch_stmt);
   1551   push_switch (switch_stmt);
   1552   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
   1553 }
   1554 
   1555 /* Finish the body of a switch-statement, which may be given by
   1556    SWITCH_STMT.  The COND to switch on is indicated.  */
   1557 
   1558 void
   1559 finish_switch_stmt (tree switch_stmt)
   1560 {
   1561   tree scope;
   1562 
   1563   SWITCH_STMT_BODY (switch_stmt) =
   1564     pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
   1565   pop_switch ();
   1566 
   1567   scope = SWITCH_STMT_SCOPE (switch_stmt);
   1568   SWITCH_STMT_SCOPE (switch_stmt) = NULL;
   1569   add_stmt (do_poplevel (scope));
   1570 }
   1571 
   1572 /* Begin a try-block.  Returns a newly-created TRY_BLOCK if
   1573    appropriate.  */
   1574 
   1575 tree
   1576 begin_try_block (void)
   1577 {
   1578   tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
   1579   add_stmt (r);
   1580   TRY_STMTS (r) = push_stmt_list ();
   1581   return r;
   1582 }
   1583 
   1584 /* Likewise, for a function-try-block.  The block returned in
   1585    *COMPOUND_STMT is an artificial outer scope, containing the
   1586    function-try-block.  */
   1587 
   1588 tree
   1589 begin_function_try_block (tree *compound_stmt)
   1590 {
   1591   tree r;
   1592   /* This outer scope does not exist in the C++ standard, but we need
   1593      a place to put __FUNCTION__ and similar variables.  */
   1594   *compound_stmt = begin_compound_stmt (0);
   1595   r = begin_try_block ();
   1596   FN_TRY_BLOCK_P (r) = 1;
   1597   return r;
   1598 }
   1599 
   1600 /* Finish a try-block, which may be given by TRY_BLOCK.  */
   1601 
   1602 void
   1603 finish_try_block (tree try_block)
   1604 {
   1605   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
   1606   TRY_HANDLERS (try_block) = push_stmt_list ();
   1607 }
   1608 
   1609 /* Finish the body of a cleanup try-block, which may be given by
   1610    TRY_BLOCK.  */
   1611 
   1612 void
   1613 finish_cleanup_try_block (tree try_block)
   1614 {
   1615   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
   1616 }
   1617 
   1618 /* Finish an implicitly generated try-block, with a cleanup is given
   1619    by CLEANUP.  */
   1620 
   1621 void
   1622 finish_cleanup (tree cleanup, tree try_block)
   1623 {
   1624   TRY_HANDLERS (try_block) = cleanup;
   1625   CLEANUP_P (try_block) = 1;
   1626 }
   1627 
   1628 /* Likewise, for a function-try-block.  */
   1629 
   1630 void
   1631 finish_function_try_block (tree try_block)
   1632 {
   1633   finish_try_block (try_block);
   1634   /* FIXME : something queer about CTOR_INITIALIZER somehow following
   1635      the try block, but moving it inside.  */
   1636   in_function_try_handler = 1;
   1637 }
   1638 
   1639 /* Finish a handler-sequence for a try-block, which may be given by
   1640    TRY_BLOCK.  */
   1641 
   1642 void
   1643 finish_handler_sequence (tree try_block)
   1644 {
   1645   TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
   1646   check_handlers (TRY_HANDLERS (try_block));
   1647 }
   1648 
   1649 /* Finish the handler-seq for a function-try-block, given by
   1650    TRY_BLOCK.  COMPOUND_STMT is the outer block created by
   1651    begin_function_try_block.  */
   1652 
   1653 void
   1654 finish_function_handler_sequence (tree try_block, tree compound_stmt)
   1655 {
   1656   in_function_try_handler = 0;
   1657   finish_handler_sequence (try_block);
   1658   finish_compound_stmt (compound_stmt);
   1659 }
   1660 
   1661 /* Begin a handler.  Returns a HANDLER if appropriate.  */
   1662 
   1663 tree
   1664 begin_handler (void)
   1665 {
   1666   tree r;
   1667 
   1668   r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
   1669   add_stmt (r);
   1670 
   1671   /* Create a binding level for the eh_info and the exception object
   1672      cleanup.  */
   1673   HANDLER_BODY (r) = do_pushlevel (sk_catch);
   1674 
   1675   return r;
   1676 }
   1677 
   1678 /* Finish the handler-parameters for a handler, which may be given by
   1679    HANDLER.  DECL is the declaration for the catch parameter, or NULL
   1680    if this is a `catch (...)' clause.  */
   1681 
   1682 void
   1683 finish_handler_parms (tree decl, tree handler)
   1684 {
   1685   tree type = NULL_TREE;
   1686   if (processing_template_decl)
   1687     {
   1688       if (decl)
   1689 	{
   1690 	  decl = pushdecl (decl);
   1691 	  decl = push_template_decl (decl);
   1692 	  HANDLER_PARMS (handler) = decl;
   1693 	  type = TREE_TYPE (decl);
   1694 	}
   1695     }
   1696   else
   1697     {
   1698       type = expand_start_catch_block (decl);
   1699       if (warn_catch_value
   1700 	  && type != NULL_TREE
   1701 	  && type != error_mark_node
   1702 	  && !TYPE_REF_P (TREE_TYPE (decl)))
   1703 	{
   1704 	  tree orig_type = TREE_TYPE (decl);
   1705 	  if (CLASS_TYPE_P (orig_type))
   1706 	    {
   1707 	      if (TYPE_POLYMORPHIC_P (orig_type))
   1708 		warning_at (DECL_SOURCE_LOCATION (decl),
   1709 			    OPT_Wcatch_value_,
   1710 			    "catching polymorphic type %q#T by value",
   1711 			    orig_type);
   1712 	      else if (warn_catch_value > 1)
   1713 		warning_at (DECL_SOURCE_LOCATION (decl),
   1714 			    OPT_Wcatch_value_,
   1715 			    "catching type %q#T by value", orig_type);
   1716 	    }
   1717 	  else if (warn_catch_value > 2)
   1718 	    warning_at (DECL_SOURCE_LOCATION (decl),
   1719 			OPT_Wcatch_value_,
   1720 			"catching non-reference type %q#T", orig_type);
   1721 	}
   1722     }
   1723   HANDLER_TYPE (handler) = type;
   1724 }
   1725 
   1726 /* Finish a handler, which may be given by HANDLER.  The BLOCKs are
   1727    the return value from the matching call to finish_handler_parms.  */
   1728 
   1729 void
   1730 finish_handler (tree handler)
   1731 {
   1732   if (!processing_template_decl)
   1733     expand_end_catch_block ();
   1734   HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
   1735 }
   1736 
   1737 /* Begin a compound statement.  FLAGS contains some bits that control the
   1738    behavior and context.  If BCS_NO_SCOPE is set, the compound statement
   1739    does not define a scope.  If BCS_FN_BODY is set, this is the outermost
   1740    block of a function.  If BCS_TRY_BLOCK is set, this is the block
   1741    created on behalf of a TRY statement.  Returns a token to be passed to
   1742    finish_compound_stmt.  */
   1743 
   1744 tree
   1745 begin_compound_stmt (unsigned int flags)
   1746 {
   1747   tree r;
   1748 
   1749   if (flags & BCS_NO_SCOPE)
   1750     {
   1751       r = push_stmt_list ();
   1752       STATEMENT_LIST_NO_SCOPE (r) = 1;
   1753 
   1754       /* Normally, we try hard to keep the BLOCK for a statement-expression.
   1755 	 But, if it's a statement-expression with a scopeless block, there's
   1756 	 nothing to keep, and we don't want to accidentally keep a block
   1757 	 *inside* the scopeless block.  */
   1758       keep_next_level (false);
   1759     }
   1760   else
   1761     {
   1762       scope_kind sk = sk_block;
   1763       if (flags & BCS_TRY_BLOCK)
   1764 	sk = sk_try;
   1765       else if (flags & BCS_TRANSACTION)
   1766 	sk = sk_transaction;
   1767       r = do_pushlevel (sk);
   1768     }
   1769 
   1770   /* When processing a template, we need to remember where the braces were,
   1771      so that we can set up identical scopes when instantiating the template
   1772      later.  BIND_EXPR is a handy candidate for this.
   1773      Note that do_poplevel won't create a BIND_EXPR itself here (and thus
   1774      result in nested BIND_EXPRs), since we don't build BLOCK nodes when
   1775      processing templates.  */
   1776   if (processing_template_decl)
   1777     {
   1778       r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
   1779       BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
   1780       BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
   1781       TREE_SIDE_EFFECTS (r) = 1;
   1782     }
   1783 
   1784   return r;
   1785 }
   1786 
   1787 /* Finish a compound-statement, which is given by STMT.  */
   1788 
   1789 void
   1790 finish_compound_stmt (tree stmt)
   1791 {
   1792   if (TREE_CODE (stmt) == BIND_EXPR)
   1793     {
   1794       tree body = do_poplevel (BIND_EXPR_BODY (stmt));
   1795       /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
   1796 	 discard the BIND_EXPR so it can be merged with the containing
   1797 	 STATEMENT_LIST.  */
   1798       if (TREE_CODE (body) == STATEMENT_LIST
   1799 	  && STATEMENT_LIST_HEAD (body) == NULL
   1800 	  && !BIND_EXPR_BODY_BLOCK (stmt)
   1801 	  && !BIND_EXPR_TRY_BLOCK (stmt))
   1802 	stmt = body;
   1803       else
   1804 	BIND_EXPR_BODY (stmt) = body;
   1805     }
   1806   else if (STATEMENT_LIST_NO_SCOPE (stmt))
   1807     stmt = pop_stmt_list (stmt);
   1808   else
   1809     {
   1810       /* Destroy any ObjC "super" receivers that may have been
   1811 	 created.  */
   1812       objc_clear_super_receiver ();
   1813 
   1814       stmt = do_poplevel (stmt);
   1815     }
   1816 
   1817   /* ??? See c_end_compound_stmt wrt statement expressions.  */
   1818   add_stmt (stmt);
   1819 }
   1820 
   1821 /* Finish an asm-statement, whose components are a STRING, some
   1822    OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
   1823    LABELS.  Also note whether the asm-statement should be
   1824    considered volatile, and whether it is asm inline.  */
   1825 
   1826 tree
   1827 finish_asm_stmt (location_t loc, int volatile_p, tree string,
   1828 		 tree output_operands, tree input_operands, tree clobbers,
   1829 		 tree labels, bool inline_p)
   1830 {
   1831   tree r;
   1832   tree t;
   1833   int ninputs = list_length (input_operands);
   1834   int noutputs = list_length (output_operands);
   1835 
   1836   if (!processing_template_decl)
   1837     {
   1838       const char *constraint;
   1839       const char **oconstraints;
   1840       bool allows_mem, allows_reg, is_inout;
   1841       tree operand;
   1842       int i;
   1843 
   1844       oconstraints = XALLOCAVEC (const char *, noutputs);
   1845 
   1846       string = resolve_asm_operand_names (string, output_operands,
   1847 					  input_operands, labels);
   1848 
   1849       for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
   1850 	{
   1851 	  operand = TREE_VALUE (t);
   1852 
   1853 	  /* ??? Really, this should not be here.  Users should be using a
   1854 	     proper lvalue, dammit.  But there's a long history of using
   1855 	     casts in the output operands.  In cases like longlong.h, this
   1856 	     becomes a primitive form of typechecking -- if the cast can be
   1857 	     removed, then the output operand had a type of the proper width;
   1858 	     otherwise we'll get an error.  Gross, but ...  */
   1859 	  STRIP_NOPS (operand);
   1860 
   1861 	  operand = mark_lvalue_use (operand);
   1862 
   1863 	  if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
   1864 	    operand = error_mark_node;
   1865 
   1866 	  if (operand != error_mark_node
   1867 	      && (TREE_READONLY (operand)
   1868 		  || CP_TYPE_CONST_P (TREE_TYPE (operand))
   1869 		  /* Functions are not modifiable, even though they are
   1870 		     lvalues.  */
   1871 		  || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
   1872 		  /* If it's an aggregate and any field is const, then it is
   1873 		     effectively const.  */
   1874 		  || (CLASS_TYPE_P (TREE_TYPE (operand))
   1875 		      && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
   1876 	    cxx_readonly_error (loc, operand, lv_asm);
   1877 
   1878 	  tree *op = &operand;
   1879 	  while (TREE_CODE (*op) == COMPOUND_EXPR)
   1880 	    op = &TREE_OPERAND (*op, 1);
   1881 	  switch (TREE_CODE (*op))
   1882 	    {
   1883 	    case PREINCREMENT_EXPR:
   1884 	    case PREDECREMENT_EXPR:
   1885 	    case MODIFY_EXPR:
   1886 	      *op = genericize_compound_lvalue (*op);
   1887 	      op = &TREE_OPERAND (*op, 1);
   1888 	      break;
   1889 	    default:
   1890 	      break;
   1891 	    }
   1892 
   1893 	  constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
   1894 	  oconstraints[i] = constraint;
   1895 
   1896 	  if (parse_output_constraint (&constraint, i, ninputs, noutputs,
   1897 				       &allows_mem, &allows_reg, &is_inout))
   1898 	    {
   1899 	      /* If the operand is going to end up in memory,
   1900 		 mark it addressable.  */
   1901 	      if (!allows_reg && !cxx_mark_addressable (*op))
   1902 		operand = error_mark_node;
   1903 	    }
   1904 	  else
   1905 	    operand = error_mark_node;
   1906 
   1907 	  TREE_VALUE (t) = operand;
   1908 	}
   1909 
   1910       for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
   1911 	{
   1912 	  constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
   1913 	  bool constraint_parsed
   1914 	    = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
   1915 				      oconstraints, &allows_mem, &allows_reg);
   1916 	  /* If the operand is going to end up in memory, don't call
   1917 	     decay_conversion.  */
   1918 	  if (constraint_parsed && !allows_reg && allows_mem)
   1919 	    operand = mark_lvalue_use (TREE_VALUE (t));
   1920 	  else
   1921 	    operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
   1922 
   1923 	  /* If the type of the operand hasn't been determined (e.g.,
   1924 	     because it involves an overloaded function), then issue
   1925 	     an error message.  There's no context available to
   1926 	     resolve the overloading.  */
   1927 	  if (TREE_TYPE (operand) == unknown_type_node)
   1928 	    {
   1929 	      error_at (loc,
   1930 			"type of %<asm%> operand %qE could not be determined",
   1931 			TREE_VALUE (t));
   1932 	      operand = error_mark_node;
   1933 	    }
   1934 
   1935 	  if (constraint_parsed)
   1936 	    {
   1937 	      /* If the operand is going to end up in memory,
   1938 		 mark it addressable.  */
   1939 	      if (!allows_reg && allows_mem)
   1940 		{
   1941 		  /* Strip the nops as we allow this case.  FIXME, this really
   1942 		     should be rejected or made deprecated.  */
   1943 		  STRIP_NOPS (operand);
   1944 
   1945 		  tree *op = &operand;
   1946 		  while (TREE_CODE (*op) == COMPOUND_EXPR)
   1947 		    op = &TREE_OPERAND (*op, 1);
   1948 		  switch (TREE_CODE (*op))
   1949 		    {
   1950 		    case PREINCREMENT_EXPR:
   1951 		    case PREDECREMENT_EXPR:
   1952 		    case MODIFY_EXPR:
   1953 		      *op = genericize_compound_lvalue (*op);
   1954 		      op = &TREE_OPERAND (*op, 1);
   1955 		      break;
   1956 		    default:
   1957 		      break;
   1958 		    }
   1959 
   1960 		  if (!cxx_mark_addressable (*op))
   1961 		    operand = error_mark_node;
   1962 		}
   1963 	      else if (!allows_reg && !allows_mem)
   1964 		{
   1965 		  /* If constraint allows neither register nor memory,
   1966 		     try harder to get a constant.  */
   1967 		  tree constop = maybe_constant_value (operand);
   1968 		  if (TREE_CONSTANT (constop))
   1969 		    operand = constop;
   1970 		}
   1971 	    }
   1972 	  else
   1973 	    operand = error_mark_node;
   1974 
   1975 	  TREE_VALUE (t) = operand;
   1976 	}
   1977     }
   1978 
   1979   r = build_stmt (loc, ASM_EXPR, string,
   1980 		  output_operands, input_operands,
   1981 		  clobbers, labels);
   1982   ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
   1983   ASM_INLINE_P (r) = inline_p;
   1984   r = maybe_cleanup_point_expr_void (r);
   1985   return add_stmt (r);
   1986 }
   1987 
   1988 /* Finish a label with the indicated NAME.  Returns the new label.  */
   1989 
   1990 tree
   1991 finish_label_stmt (tree name)
   1992 {
   1993   tree decl = define_label (input_location, name);
   1994 
   1995   if (decl == error_mark_node)
   1996     return error_mark_node;
   1997 
   1998   add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
   1999 
   2000   return decl;
   2001 }
   2002 
   2003 /* Finish a series of declarations for local labels.  G++ allows users
   2004    to declare "local" labels, i.e., labels with scope.  This extension
   2005    is useful when writing code involving statement-expressions.  */
   2006 
   2007 void
   2008 finish_label_decl (tree name)
   2009 {
   2010   if (!at_function_scope_p ())
   2011     {
   2012       error ("%<__label__%> declarations are only allowed in function scopes");
   2013       return;
   2014     }
   2015 
   2016   add_decl_expr (declare_local_label (name));
   2017 }
   2018 
   2019 /* When DECL goes out of scope, make sure that CLEANUP is executed.  */
   2020 
   2021 void
   2022 finish_decl_cleanup (tree decl, tree cleanup)
   2023 {
   2024   push_cleanup (decl, cleanup, false);
   2025 }
   2026 
   2027 /* If the current scope exits with an exception, run CLEANUP.  */
   2028 
   2029 void
   2030 finish_eh_cleanup (tree cleanup)
   2031 {
   2032   push_cleanup (NULL, cleanup, true);
   2033 }
   2034 
   2035 /* The MEM_INITS is a list of mem-initializers, in reverse of the
   2036    order they were written by the user.  Each node is as for
   2037    emit_mem_initializers.  */
   2038 
   2039 void
   2040 finish_mem_initializers (tree mem_inits)
   2041 {
   2042   /* Reorder the MEM_INITS so that they are in the order they appeared
   2043      in the source program.  */
   2044   mem_inits = nreverse (mem_inits);
   2045 
   2046   if (processing_template_decl)
   2047     {
   2048       tree mem;
   2049 
   2050       for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
   2051         {
   2052           /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
   2053              check for bare parameter packs in the TREE_VALUE, because
   2054              any parameter packs in the TREE_VALUE have already been
   2055              bound as part of the TREE_PURPOSE.  See
   2056              make_pack_expansion for more information.  */
   2057           if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
   2058               && check_for_bare_parameter_packs (TREE_VALUE (mem)))
   2059             TREE_VALUE (mem) = error_mark_node;
   2060         }
   2061 
   2062       add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
   2063 				  CTOR_INITIALIZER, mem_inits));
   2064     }
   2065   else
   2066     emit_mem_initializers (mem_inits);
   2067 }
   2068 
   2069 /* Obfuscate EXPR if it looks like an id-expression or member access so
   2070    that the call to finish_decltype in do_auto_deduction will give the
   2071    right result.  If EVEN_UNEVAL, do this even in unevaluated context.  */
   2072 
   2073 tree
   2074 force_paren_expr (tree expr, bool even_uneval)
   2075 {
   2076   /* This is only needed for decltype(auto) in C++14.  */
   2077   if (cxx_dialect < cxx14)
   2078     return expr;
   2079 
   2080   /* If we're in unevaluated context, we can't be deducing a
   2081      return/initializer type, so we don't need to mess with this.  */
   2082   if (cp_unevaluated_operand && !even_uneval)
   2083     return expr;
   2084 
   2085   if (TREE_CODE (expr) == COMPONENT_REF
   2086       || TREE_CODE (expr) == SCOPE_REF
   2087       || REFERENCE_REF_P (expr))
   2088     REF_PARENTHESIZED_P (expr) = true;
   2089   else if (DECL_P (tree_strip_any_location_wrapper (expr)))
   2090     {
   2091       location_t loc = cp_expr_location (expr);
   2092       const tree_code code = processing_template_decl ? PAREN_EXPR
   2093 						      : VIEW_CONVERT_EXPR;
   2094       expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
   2095       REF_PARENTHESIZED_P (expr) = true;
   2096     }
   2097   return expr;
   2098 }
   2099 
   2100 /* If T is an id-expression obfuscated by force_paren_expr, undo the
   2101    obfuscation and return the underlying id-expression.  Otherwise
   2102    return T.  */
   2103 
   2104 tree
   2105 maybe_undo_parenthesized_ref (tree t)
   2106 {
   2107   if (cxx_dialect < cxx14)
   2108     return t;
   2109 
   2110   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
   2111       && REF_PARENTHESIZED_P (t))
   2112     t = TREE_OPERAND (t, 0);
   2113 
   2114   return t;
   2115 }
   2116 
   2117 /* Finish a parenthesized expression EXPR.  */
   2118 
   2119 cp_expr
   2120 finish_parenthesized_expr (cp_expr expr)
   2121 {
   2122   if (EXPR_P (expr))
   2123     /* This inhibits warnings in c_common_truthvalue_conversion.  */
   2124     suppress_warning (expr, OPT_Wparentheses);
   2125 
   2126   if (TREE_CODE (expr) == OFFSET_REF
   2127       || TREE_CODE (expr) == SCOPE_REF)
   2128     /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
   2129        enclosed in parentheses.  */
   2130     PTRMEM_OK_P (expr) = 0;
   2131 
   2132   tree stripped_expr = tree_strip_any_location_wrapper (expr);
   2133   if (TREE_CODE (stripped_expr) == STRING_CST)
   2134     PAREN_STRING_LITERAL_P (stripped_expr) = 1;
   2135 
   2136   expr = cp_expr (force_paren_expr (expr), expr.get_location ());
   2137 
   2138   return expr;
   2139 }
   2140 
   2141 /* Finish a reference to a non-static data member (DECL) that is not
   2142    preceded by `.' or `->'.  */
   2143 
   2144 tree
   2145 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
   2146 {
   2147   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
   2148   bool try_omp_private = !object && omp_private_member_map;
   2149   tree ret;
   2150 
   2151   if (!object)
   2152     {
   2153       tree scope = qualifying_scope;
   2154       if (scope == NULL_TREE)
   2155 	{
   2156 	  scope = context_for_name_lookup (decl);
   2157 	  if (!TYPE_P (scope))
   2158 	    {
   2159 	      /* Can happen during error recovery (c++/85014).  */
   2160 	      gcc_assert (seen_error ());
   2161 	      return error_mark_node;
   2162 	    }
   2163 	}
   2164       object = maybe_dummy_object (scope, NULL);
   2165     }
   2166 
   2167   object = maybe_resolve_dummy (object, true);
   2168   if (object == error_mark_node)
   2169     return error_mark_node;
   2170 
   2171   /* DR 613/850: Can use non-static data members without an associated
   2172      object in sizeof/decltype/alignof.  */
   2173   if (is_dummy_object (object) && cp_unevaluated_operand == 0
   2174       && (!processing_template_decl || !current_class_ref))
   2175     {
   2176       if (current_function_decl
   2177 	  && DECL_STATIC_FUNCTION_P (current_function_decl))
   2178 	error ("invalid use of member %qD in static member function", decl);
   2179       else
   2180 	error ("invalid use of non-static data member %qD", decl);
   2181       inform (DECL_SOURCE_LOCATION (decl), "declared here");
   2182 
   2183       return error_mark_node;
   2184     }
   2185 
   2186   if (current_class_ptr)
   2187     TREE_USED (current_class_ptr) = 1;
   2188   if (processing_template_decl)
   2189     {
   2190       tree type = TREE_TYPE (decl);
   2191 
   2192       if (TYPE_REF_P (type))
   2193 	/* Quals on the object don't matter.  */;
   2194       else if (PACK_EXPANSION_P (type))
   2195 	/* Don't bother trying to represent this.  */
   2196 	type = NULL_TREE;
   2197       else
   2198 	{
   2199 	  /* Set the cv qualifiers.  */
   2200 	  int quals = cp_type_quals (TREE_TYPE (object));
   2201 
   2202 	  if (DECL_MUTABLE_P (decl))
   2203 	    quals &= ~TYPE_QUAL_CONST;
   2204 
   2205 	  quals |= cp_type_quals (TREE_TYPE (decl));
   2206 	  type = cp_build_qualified_type (type, quals);
   2207 	}
   2208 
   2209       if (qualifying_scope)
   2210 	/* Wrap this in a SCOPE_REF for now.  */
   2211 	ret = build_qualified_name (type, qualifying_scope, decl,
   2212 				    /*template_p=*/false);
   2213       else
   2214 	ret = (convert_from_reference
   2215 	       (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
   2216     }
   2217   /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
   2218      QUALIFYING_SCOPE is also non-null.  */
   2219   else
   2220     {
   2221       tree access_type = TREE_TYPE (object);
   2222 
   2223       perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
   2224 				     decl, tf_warning_or_error);
   2225 
   2226       /* If the data member was named `C::M', convert `*this' to `C'
   2227 	 first.  */
   2228       if (qualifying_scope)
   2229 	{
   2230 	  tree binfo = NULL_TREE;
   2231 	  object = build_scoped_ref (object, qualifying_scope,
   2232 				     &binfo);
   2233 	}
   2234 
   2235       ret = build_class_member_access_expr (object, decl,
   2236 					    /*access_path=*/NULL_TREE,
   2237 					    /*preserve_reference=*/false,
   2238 					    tf_warning_or_error);
   2239     }
   2240   if (try_omp_private)
   2241     {
   2242       tree *v = omp_private_member_map->get (decl);
   2243       if (v)
   2244 	ret = convert_from_reference (*v);
   2245     }
   2246   return ret;
   2247 }
   2248 
   2249 /* DECL was the declaration to which a qualified-id resolved.  Issue
   2250    an error message if it is not accessible.  If OBJECT_TYPE is
   2251    non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
   2252    type of `*x', or `x', respectively.  If the DECL was named as
   2253    `A::B' then NESTED_NAME_SPECIFIER is `A'.  Return value is like
   2254    perform_access_checks above.  */
   2255 
   2256 bool
   2257 check_accessibility_of_qualified_id (tree decl,
   2258 				     tree object_type,
   2259 				     tree nested_name_specifier,
   2260 				     tsubst_flags_t complain)
   2261 {
   2262   /* If we're not checking, return immediately.  */
   2263   if (deferred_access_no_check)
   2264     return true;
   2265 
   2266   /* Determine the SCOPE of DECL.  */
   2267   tree scope = context_for_name_lookup (decl);
   2268   /* If the SCOPE is not a type, then DECL is not a member.  */
   2269   if (!TYPE_P (scope)
   2270       /* If SCOPE is dependent then we can't perform this access check now,
   2271 	 and since we'll perform this access check again after substitution
   2272 	 there's no need to explicitly defer it.  */
   2273       || dependent_type_p (scope))
   2274     return true;
   2275 
   2276   tree qualifying_type = NULL_TREE;
   2277   /* Compute the scope through which DECL is being accessed.  */
   2278   if (object_type
   2279       /* OBJECT_TYPE might not be a class type; consider:
   2280 
   2281 	   class A { typedef int I; };
   2282 	   I *p;
   2283 	   p->A::I::~I();
   2284 
   2285 	 In this case, we will have "A::I" as the DECL, but "I" as the
   2286 	 OBJECT_TYPE.  */
   2287       && CLASS_TYPE_P (object_type)
   2288       && DERIVED_FROM_P (scope, object_type))
   2289     {
   2290       /* If we are processing a `->' or `.' expression, use the type of the
   2291 	 left-hand side.  */
   2292       if (tree open = currently_open_class (object_type))
   2293 	qualifying_type = open;
   2294       else
   2295 	qualifying_type = object_type;
   2296     }
   2297   else if (nested_name_specifier)
   2298     {
   2299       /* If the reference is to a non-static member of the
   2300 	 current class, treat it as if it were referenced through
   2301 	 `this'.  */
   2302       if (DECL_NONSTATIC_MEMBER_P (decl)
   2303 	  && current_class_ptr)
   2304 	if (tree current = current_nonlambda_class_type ())
   2305 	  {
   2306 	    if (dependent_type_p (current))
   2307 	    /* In general we can't know whether this access goes through
   2308 	       `this' until instantiation time.  Punt now, or else we might
   2309 	       create a deferred access check that's not relative to `this'
   2310 	       when it ought to be.  We'll check this access again after
   2311 	       substitution, e.g. from tsubst_qualified_id.  */
   2312 	      return true;
   2313 
   2314 	    if (DERIVED_FROM_P (scope, current))
   2315 	      qualifying_type = current;
   2316 	  }
   2317       /* Otherwise, use the type indicated by the
   2318 	 nested-name-specifier.  */
   2319       if (!qualifying_type)
   2320 	qualifying_type = nested_name_specifier;
   2321     }
   2322   else
   2323     /* Otherwise, the name must be from the current class or one of
   2324        its bases.  */
   2325     qualifying_type = currently_open_derived_class (scope);
   2326 
   2327   if (qualifying_type
   2328       /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
   2329 	 or similar in a default argument value.  */
   2330       && CLASS_TYPE_P (qualifying_type))
   2331     return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
   2332 					  decl, complain);
   2333 
   2334   return true;
   2335 }
   2336 
   2337 /* EXPR is the result of a qualified-id.  The QUALIFYING_CLASS was the
   2338    class named to the left of the "::" operator.  DONE is true if this
   2339    expression is a complete postfix-expression; it is false if this
   2340    expression is followed by '->', '[', '(', etc.  ADDRESS_P is true
   2341    iff this expression is the operand of '&'.  TEMPLATE_P is true iff
   2342    the qualified-id was of the form "A::template B".  TEMPLATE_ARG_P
   2343    is true iff this qualified name appears as a template argument.  */
   2344 
   2345 tree
   2346 finish_qualified_id_expr (tree qualifying_class,
   2347 			  tree expr,
   2348 			  bool done,
   2349 			  bool address_p,
   2350 			  bool template_p,
   2351 			  bool template_arg_p,
   2352 			  tsubst_flags_t complain)
   2353 {
   2354   gcc_assert (TYPE_P (qualifying_class));
   2355 
   2356   if (error_operand_p (expr))
   2357     return error_mark_node;
   2358 
   2359   if (DECL_P (expr)
   2360       /* Functions are marked after overload resolution; avoid redundant
   2361 	 warnings.  */
   2362       && TREE_CODE (expr) != FUNCTION_DECL
   2363       && !mark_used (expr, complain))
   2364     return error_mark_node;
   2365 
   2366   if (template_p)
   2367     {
   2368       if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
   2369 	{
   2370 	  /* cp_parser_lookup_name thought we were looking for a type,
   2371 	     but we're actually looking for a declaration.  */
   2372 	  qualifying_class = TYPE_CONTEXT (expr);
   2373 	  expr = TYPE_IDENTIFIER (expr);
   2374 	}
   2375       else
   2376 	check_template_keyword (expr);
   2377     }
   2378 
   2379   /* If EXPR occurs as the operand of '&', use special handling that
   2380      permits a pointer-to-member.  */
   2381   if (address_p && done
   2382       && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
   2383     {
   2384       if (TREE_CODE (expr) == SCOPE_REF)
   2385 	expr = TREE_OPERAND (expr, 1);
   2386       expr = build_offset_ref (qualifying_class, expr,
   2387 			       /*address_p=*/true, complain);
   2388       return expr;
   2389     }
   2390 
   2391   /* No need to check access within an enum.  */
   2392   if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
   2393       && TREE_CODE (expr) != IDENTIFIER_NODE)
   2394     return expr;
   2395 
   2396   /* Within the scope of a class, turn references to non-static
   2397      members into expression of the form "this->...".  */
   2398   if (template_arg_p)
   2399     /* But, within a template argument, we do not want make the
   2400        transformation, as there is no "this" pointer.  */
   2401     ;
   2402   else if (TREE_CODE (expr) == FIELD_DECL)
   2403     {
   2404       push_deferring_access_checks (dk_no_check);
   2405       expr = finish_non_static_data_member (expr, NULL_TREE,
   2406 					    qualifying_class);
   2407       pop_deferring_access_checks ();
   2408     }
   2409   else if (BASELINK_P (expr))
   2410     {
   2411       /* See if any of the functions are non-static members.  */
   2412       /* If so, the expression may be relative to 'this'.  */
   2413       if (!shared_member_p (expr)
   2414 	  && current_class_ptr
   2415 	  && DERIVED_FROM_P (qualifying_class,
   2416 			     current_nonlambda_class_type ()))
   2417 	expr = (build_class_member_access_expr
   2418 		(maybe_dummy_object (qualifying_class, NULL),
   2419 		 expr,
   2420 		 BASELINK_ACCESS_BINFO (expr),
   2421 		 /*preserve_reference=*/false,
   2422 		 complain));
   2423       else if (done)
   2424 	/* The expression is a qualified name whose address is not
   2425 	   being taken.  */
   2426 	expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
   2427 				 complain);
   2428     }
   2429   else if (!template_p
   2430 	   && TREE_CODE (expr) == TEMPLATE_DECL
   2431 	   && !DECL_FUNCTION_TEMPLATE_P (expr))
   2432     {
   2433       if (complain & tf_error)
   2434 	error ("%qE missing template arguments", expr);
   2435       return error_mark_node;
   2436     }
   2437   else
   2438     {
   2439       /* In a template, return a SCOPE_REF for most qualified-ids
   2440 	 so that we can check access at instantiation time.  But if
   2441 	 we're looking at a member of the current instantiation, we
   2442 	 know we have access and building up the SCOPE_REF confuses
   2443 	 non-type template argument handling.  */
   2444       if (processing_template_decl
   2445 	  && (!currently_open_class (qualifying_class)
   2446 	      || TREE_CODE (expr) == IDENTIFIER_NODE
   2447 	      || TREE_CODE (expr) == TEMPLATE_ID_EXPR
   2448 	      || TREE_CODE (expr) == BIT_NOT_EXPR))
   2449 	expr = build_qualified_name (TREE_TYPE (expr),
   2450 				     qualifying_class, expr,
   2451 				     template_p);
   2452       else if (tree wrap = maybe_get_tls_wrapper_call (expr))
   2453 	expr = wrap;
   2454 
   2455       expr = convert_from_reference (expr);
   2456     }
   2457 
   2458   return expr;
   2459 }
   2460 
   2461 /* Begin a statement-expression.  The value returned must be passed to
   2462    finish_stmt_expr.  */
   2463 
   2464 tree
   2465 begin_stmt_expr (void)
   2466 {
   2467   return push_stmt_list ();
   2468 }
   2469 
   2470 /* Process the final expression of a statement expression. EXPR can be
   2471    NULL, if the final expression is empty.  Return a STATEMENT_LIST
   2472    containing all the statements in the statement-expression, or
   2473    ERROR_MARK_NODE if there was an error.  */
   2474 
   2475 tree
   2476 finish_stmt_expr_expr (tree expr, tree stmt_expr)
   2477 {
   2478   if (error_operand_p (expr))
   2479     {
   2480       /* The type of the statement-expression is the type of the last
   2481          expression.  */
   2482       TREE_TYPE (stmt_expr) = error_mark_node;
   2483       return error_mark_node;
   2484     }
   2485 
   2486   /* If the last statement does not have "void" type, then the value
   2487      of the last statement is the value of the entire expression.  */
   2488   if (expr)
   2489     {
   2490       tree type = TREE_TYPE (expr);
   2491 
   2492       if (type && type_unknown_p (type))
   2493 	{
   2494 	  error ("a statement expression is an insufficient context"
   2495 		 " for overload resolution");
   2496 	  TREE_TYPE (stmt_expr) = error_mark_node;
   2497 	  return error_mark_node;
   2498 	}
   2499       else if (processing_template_decl)
   2500 	{
   2501 	  expr = build_stmt (input_location, EXPR_STMT, expr);
   2502 	  expr = add_stmt (expr);
   2503 	  /* Mark the last statement so that we can recognize it as such at
   2504 	     template-instantiation time.  */
   2505 	  EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
   2506 	}
   2507       else if (VOID_TYPE_P (type))
   2508 	{
   2509 	  /* Just treat this like an ordinary statement.  */
   2510 	  expr = finish_expr_stmt (expr);
   2511 	}
   2512       else
   2513 	{
   2514 	  /* It actually has a value we need to deal with.  First, force it
   2515 	     to be an rvalue so that we won't need to build up a copy
   2516 	     constructor call later when we try to assign it to something.  */
   2517 	  expr = force_rvalue (expr, tf_warning_or_error);
   2518 	  if (error_operand_p (expr))
   2519 	    return error_mark_node;
   2520 
   2521 	  /* Update for array-to-pointer decay.  */
   2522 	  type = TREE_TYPE (expr);
   2523 
   2524 	  /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
   2525 	     normal statement, but don't convert to void or actually add
   2526 	     the EXPR_STMT.  */
   2527 	  if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
   2528 	    expr = maybe_cleanup_point_expr (expr);
   2529 	  add_stmt (expr);
   2530 	}
   2531 
   2532       /* The type of the statement-expression is the type of the last
   2533 	 expression.  */
   2534       TREE_TYPE (stmt_expr) = type;
   2535     }
   2536 
   2537   return stmt_expr;
   2538 }
   2539 
   2540 /* Finish a statement-expression.  EXPR should be the value returned
   2541    by the previous begin_stmt_expr.  Returns an expression
   2542    representing the statement-expression.  */
   2543 
   2544 tree
   2545 finish_stmt_expr (tree stmt_expr, bool has_no_scope)
   2546 {
   2547   tree type;
   2548   tree result;
   2549 
   2550   if (error_operand_p (stmt_expr))
   2551     {
   2552       pop_stmt_list (stmt_expr);
   2553       return error_mark_node;
   2554     }
   2555 
   2556   gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
   2557 
   2558   type = TREE_TYPE (stmt_expr);
   2559   result = pop_stmt_list (stmt_expr);
   2560   TREE_TYPE (result) = type;
   2561 
   2562   if (processing_template_decl)
   2563     {
   2564       result = build_min (STMT_EXPR, type, result);
   2565       TREE_SIDE_EFFECTS (result) = 1;
   2566       STMT_EXPR_NO_SCOPE (result) = has_no_scope;
   2567     }
   2568   else if (CLASS_TYPE_P (type))
   2569     {
   2570       /* Wrap the statement-expression in a TARGET_EXPR so that the
   2571 	 temporary object created by the final expression is destroyed at
   2572 	 the end of the full-expression containing the
   2573 	 statement-expression.  */
   2574       result = force_target_expr (type, result, tf_warning_or_error);
   2575     }
   2576 
   2577   return result;
   2578 }
   2579 
   2580 /* Returns the expression which provides the value of STMT_EXPR.  */
   2581 
   2582 tree
   2583 stmt_expr_value_expr (tree stmt_expr)
   2584 {
   2585   tree t = STMT_EXPR_STMT (stmt_expr);
   2586 
   2587   if (TREE_CODE (t) == BIND_EXPR)
   2588     t = BIND_EXPR_BODY (t);
   2589 
   2590   if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
   2591     t = STATEMENT_LIST_TAIL (t)->stmt;
   2592 
   2593   if (TREE_CODE (t) == EXPR_STMT)
   2594     t = EXPR_STMT_EXPR (t);
   2595 
   2596   return t;
   2597 }
   2598 
   2599 /* Return TRUE iff EXPR_STMT is an empty list of
   2600    expression statements.  */
   2601 
   2602 bool
   2603 empty_expr_stmt_p (tree expr_stmt)
   2604 {
   2605   tree body = NULL_TREE;
   2606 
   2607   if (expr_stmt == void_node)
   2608     return true;
   2609 
   2610   if (expr_stmt)
   2611     {
   2612       if (TREE_CODE (expr_stmt) == EXPR_STMT)
   2613 	body = EXPR_STMT_EXPR (expr_stmt);
   2614       else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
   2615 	body = expr_stmt;
   2616     }
   2617 
   2618   if (body)
   2619     {
   2620       if (TREE_CODE (body) == STATEMENT_LIST)
   2621 	return tsi_end_p (tsi_start (body));
   2622       else
   2623 	return empty_expr_stmt_p (body);
   2624     }
   2625   return false;
   2626 }
   2627 
   2628 /* Perform Koenig lookup.  FN_EXPR is the postfix-expression representing
   2629    the function (or functions) to call; ARGS are the arguments to the
   2630    call.  Returns the functions to be considered by overload resolution.  */
   2631 
   2632 cp_expr
   2633 perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
   2634 		       tsubst_flags_t complain)
   2635 {
   2636   tree identifier = NULL_TREE;
   2637   tree functions = NULL_TREE;
   2638   tree tmpl_args = NULL_TREE;
   2639   bool template_id = false;
   2640   location_t loc = fn_expr.get_location ();
   2641   tree fn = fn_expr.get_value ();
   2642 
   2643   STRIP_ANY_LOCATION_WRAPPER (fn);
   2644 
   2645   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
   2646     {
   2647       /* Use a separate flag to handle null args.  */
   2648       template_id = true;
   2649       tmpl_args = TREE_OPERAND (fn, 1);
   2650       fn = TREE_OPERAND (fn, 0);
   2651     }
   2652 
   2653   /* Find the name of the overloaded function.  */
   2654   if (identifier_p (fn))
   2655     identifier = fn;
   2656   else
   2657     {
   2658       functions = fn;
   2659       identifier = OVL_NAME (functions);
   2660     }
   2661 
   2662   /* A call to a namespace-scope function using an unqualified name.
   2663 
   2664      Do Koenig lookup -- unless any of the arguments are
   2665      type-dependent.  */
   2666   if (!any_type_dependent_arguments_p (args)
   2667       && !any_dependent_template_arguments_p (tmpl_args))
   2668     {
   2669       fn = lookup_arg_dependent (identifier, functions, args);
   2670       if (!fn)
   2671 	{
   2672 	  /* The unqualified name could not be resolved.  */
   2673 	  if (complain & tf_error)
   2674 	    fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
   2675 	  else
   2676 	    fn = identifier;
   2677 	}
   2678     }
   2679 
   2680   if (fn && template_id && fn != error_mark_node)
   2681     fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
   2682 
   2683   return cp_expr (fn, loc);
   2684 }
   2685 
   2686 /* Generate an expression for `FN (ARGS)'.  This may change the
   2687    contents of ARGS.
   2688 
   2689    If DISALLOW_VIRTUAL is true, the call to FN will be not generated
   2690    as a virtual call, even if FN is virtual.  (This flag is set when
   2691    encountering an expression where the function name is explicitly
   2692    qualified.  For example a call to `X::f' never generates a virtual
   2693    call.)
   2694 
   2695    Returns code for the call.  */
   2696 
   2697 tree
   2698 finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
   2699 		  bool koenig_p, tsubst_flags_t complain)
   2700 {
   2701   tree result;
   2702   tree orig_fn;
   2703   vec<tree, va_gc> *orig_args = *args;
   2704 
   2705   if (fn == error_mark_node)
   2706     return error_mark_node;
   2707 
   2708   gcc_assert (!TYPE_P (fn));
   2709 
   2710   /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
   2711      it so that we can tell this is a call to a known function.  */
   2712   fn = maybe_undo_parenthesized_ref (fn);
   2713 
   2714   STRIP_ANY_LOCATION_WRAPPER (fn);
   2715 
   2716   orig_fn = fn;
   2717 
   2718   if (processing_template_decl)
   2719     {
   2720       /* If FN is a local extern declaration (or set thereof) in a template,
   2721 	 look it up again at instantiation time.  */
   2722       if (is_overloaded_fn (fn))
   2723 	{
   2724 	  tree ifn = get_first_fn (fn);
   2725 	  if (TREE_CODE (ifn) == FUNCTION_DECL
   2726 	      && dependent_local_decl_p (ifn))
   2727 	    orig_fn = DECL_NAME (ifn);
   2728 	}
   2729 
   2730       /* If the call expression is dependent, build a CALL_EXPR node
   2731 	 with no type; type_dependent_expression_p recognizes
   2732 	 expressions with no type as being dependent.  */
   2733       if (type_dependent_expression_p (fn)
   2734 	  || any_type_dependent_arguments_p (*args))
   2735 	{
   2736 	  result = build_min_nt_call_vec (orig_fn, *args);
   2737 	  SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
   2738 	  KOENIG_LOOKUP_P (result) = koenig_p;
   2739 	  if (is_overloaded_fn (fn))
   2740 	    fn = get_fns (fn);
   2741 
   2742 	  if (cfun)
   2743 	    {
   2744 	      bool abnormal = true;
   2745 	      for (lkp_iterator iter (fn); abnormal && iter; ++iter)
   2746 		{
   2747 		  tree fndecl = STRIP_TEMPLATE (*iter);
   2748 		  if (TREE_CODE (fndecl) != FUNCTION_DECL
   2749 		      || !TREE_THIS_VOLATILE (fndecl))
   2750 		    abnormal = false;
   2751 		}
   2752 	      /* FIXME: Stop warning about falling off end of non-void
   2753 		 function.   But this is wrong.  Even if we only see
   2754 		 no-return fns at this point, we could select a
   2755 		 future-defined return fn during instantiation.  Or
   2756 		 vice-versa.  */
   2757 	      if (abnormal)
   2758 		current_function_returns_abnormally = 1;
   2759 	    }
   2760 	  return result;
   2761 	}
   2762       orig_args = make_tree_vector_copy (*args);
   2763       if (!BASELINK_P (fn)
   2764 	  && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
   2765 	  && TREE_TYPE (fn) != unknown_type_node)
   2766 	fn = build_non_dependent_expr (fn);
   2767       make_args_non_dependent (*args);
   2768     }
   2769 
   2770   if (TREE_CODE (fn) == COMPONENT_REF)
   2771     {
   2772       tree member = TREE_OPERAND (fn, 1);
   2773       if (BASELINK_P (member))
   2774 	{
   2775 	  tree object = TREE_OPERAND (fn, 0);
   2776 	  return build_new_method_call (object, member,
   2777 					args, NULL_TREE,
   2778                                         (disallow_virtual
   2779                                          ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
   2780 					 : LOOKUP_NORMAL),
   2781 					/*fn_p=*/NULL,
   2782 					complain);
   2783 	}
   2784     }
   2785 
   2786   /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'.  */
   2787   if (TREE_CODE (fn) == ADDR_EXPR
   2788       && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
   2789     fn = TREE_OPERAND (fn, 0);
   2790 
   2791   if (is_overloaded_fn (fn))
   2792     fn = baselink_for_fns (fn);
   2793 
   2794   result = NULL_TREE;
   2795   if (BASELINK_P (fn))
   2796     {
   2797       tree object;
   2798 
   2799       /* A call to a member function.  From [over.call.func]:
   2800 
   2801 	   If the keyword this is in scope and refers to the class of
   2802 	   that member function, or a derived class thereof, then the
   2803 	   function call is transformed into a qualified function call
   2804 	   using (*this) as the postfix-expression to the left of the
   2805 	   . operator.... [Otherwise] a contrived object of type T
   2806 	   becomes the implied object argument.
   2807 
   2808 	In this situation:
   2809 
   2810 	  struct A { void f(); };
   2811 	  struct B : public A {};
   2812 	  struct C : public A { void g() { B::f(); }};
   2813 
   2814 	"the class of that member function" refers to `A'.  But 11.2
   2815 	[class.access.base] says that we need to convert 'this' to B* as
   2816 	part of the access, so we pass 'B' to maybe_dummy_object.  */
   2817 
   2818       if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
   2819 	{
   2820 	  /* A constructor call always uses a dummy object.  (This constructor
   2821 	     call which has the form A::A () is actually invalid and we are
   2822 	     going to reject it later in build_new_method_call.)  */
   2823 	  object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
   2824 	}
   2825       else
   2826 	object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
   2827 				     NULL);
   2828 
   2829       result = build_new_method_call (object, fn, args, NULL_TREE,
   2830 				      (disallow_virtual
   2831 				       ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
   2832 				       : LOOKUP_NORMAL),
   2833 				      /*fn_p=*/NULL,
   2834 				      complain);
   2835     }
   2836   else if (concept_check_p (fn))
   2837     {
   2838       /* FN is actually a template-id referring to a concept definition.  */
   2839       tree id = unpack_concept_check (fn);
   2840       tree tmpl = TREE_OPERAND (id, 0);
   2841       tree args = TREE_OPERAND (id, 1);
   2842 
   2843       if (!function_concept_p (tmpl))
   2844 	{
   2845 	  error_at (EXPR_LOC_OR_LOC (fn, input_location),
   2846 		    "cannot call a concept as a function");
   2847 	  return error_mark_node;
   2848 	}
   2849 
   2850       /* Ensure the result is wrapped as a call expression.  */
   2851       result = build_concept_check (tmpl, args, tf_warning_or_error);
   2852     }
   2853   else if (is_overloaded_fn (fn))
   2854     {
   2855       /* If the function is an overloaded builtin, resolve it.  */
   2856       if (TREE_CODE (fn) == FUNCTION_DECL
   2857 	  && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
   2858 	      || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
   2859 	result = resolve_overloaded_builtin (input_location, fn, *args);
   2860 
   2861       if (!result)
   2862 	{
   2863 	  if (warn_sizeof_pointer_memaccess
   2864 	      && (complain & tf_warning)
   2865 	      && !vec_safe_is_empty (*args)
   2866 	      && !processing_template_decl)
   2867 	    {
   2868 	      location_t sizeof_arg_loc[3];
   2869 	      tree sizeof_arg[3];
   2870 	      unsigned int i;
   2871 	      for (i = 0; i < 3; i++)
   2872 		{
   2873 		  tree t;
   2874 
   2875 		  sizeof_arg_loc[i] = UNKNOWN_LOCATION;
   2876 		  sizeof_arg[i] = NULL_TREE;
   2877 		  if (i >= (*args)->length ())
   2878 		    continue;
   2879 		  t = (**args)[i];
   2880 		  if (TREE_CODE (t) != SIZEOF_EXPR)
   2881 		    continue;
   2882 		  if (SIZEOF_EXPR_TYPE_P (t))
   2883 		    sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
   2884 		  else
   2885 		    sizeof_arg[i] = TREE_OPERAND (t, 0);
   2886 		  sizeof_arg_loc[i] = EXPR_LOCATION (t);
   2887 		}
   2888 	      sizeof_pointer_memaccess_warning
   2889 		(sizeof_arg_loc, fn, *args,
   2890 		 sizeof_arg, same_type_ignoring_top_level_qualifiers_p);
   2891 	    }
   2892 
   2893 	  if ((complain & tf_warning)
   2894 	      && TREE_CODE (fn) == FUNCTION_DECL
   2895 	      && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
   2896 	      && vec_safe_length (*args) == 3
   2897 	      && !any_type_dependent_arguments_p (*args))
   2898 	    {
   2899 	      tree arg0 = (*orig_args)[0];
   2900 	      tree arg1 = (*orig_args)[1];
   2901 	      tree arg2 = (*orig_args)[2];
   2902 	      int literal_mask = ((literal_integer_zerop (arg1) << 1)
   2903 				  | (literal_integer_zerop (arg2) << 2));
   2904 	      warn_for_memset (input_location, arg0, arg2, literal_mask);
   2905 	    }
   2906 
   2907 	  /* A call to a namespace-scope function.  */
   2908 	  result = build_new_function_call (fn, args, complain);
   2909 	}
   2910     }
   2911   else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
   2912     {
   2913       if (!vec_safe_is_empty (*args))
   2914 	error ("arguments to destructor are not allowed");
   2915       /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
   2916 	 which case the postfix-expression is a possibly-parenthesized class
   2917 	 member access), the function call destroys the object of scalar type
   2918 	 denoted by the object expression of the class member access.  */
   2919       tree ob = TREE_OPERAND (fn, 0);
   2920       if (obvalue_p (ob))
   2921 	result = build_trivial_dtor_call (ob, true);
   2922       else
   2923 	/* No location to clobber.  */
   2924 	result = convert_to_void (ob, ICV_STATEMENT, complain);
   2925     }
   2926   else if (CLASS_TYPE_P (TREE_TYPE (fn)))
   2927     /* If the "function" is really an object of class type, it might
   2928        have an overloaded `operator ()'.  */
   2929     result = build_op_call (fn, args, complain);
   2930 
   2931   if (!result)
   2932     /* A call where the function is unknown.  */
   2933     result = cp_build_function_call_vec (fn, args, complain);
   2934 
   2935   if (processing_template_decl && result != error_mark_node)
   2936     {
   2937       if (INDIRECT_REF_P (result))
   2938 	result = TREE_OPERAND (result, 0);
   2939 
   2940       /* Prune all but the selected function from the original overload
   2941 	 set so that we can avoid some duplicate work at instantiation time.  */
   2942       if (TREE_CODE (result) == CALL_EXPR
   2943 	  && really_overloaded_fn (orig_fn))
   2944 	{
   2945 	  tree sel_fn = CALL_EXPR_FN (result);
   2946 	  if (TREE_CODE (sel_fn) == COMPONENT_REF)
   2947 	    {
   2948 	      /* The non-dependent result of build_new_method_call.  */
   2949 	      sel_fn = TREE_OPERAND (sel_fn, 1);
   2950 	      gcc_assert (BASELINK_P (sel_fn));
   2951 	    }
   2952 	  else if (TREE_CODE (sel_fn) == ADDR_EXPR)
   2953 	    /* Our original callee wasn't wrapped in an ADDR_EXPR,
   2954 	       so strip this ADDR_EXPR added by build_over_call.  */
   2955 	    sel_fn = TREE_OPERAND (sel_fn, 0);
   2956 	  orig_fn = sel_fn;
   2957 	}
   2958 
   2959       result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
   2960       SET_EXPR_LOCATION (result, input_location);
   2961       KOENIG_LOOKUP_P (result) = koenig_p;
   2962       release_tree_vector (orig_args);
   2963       result = convert_from_reference (result);
   2964     }
   2965 
   2966   return result;
   2967 }
   2968 
   2969 /* Finish a call to a postfix increment or decrement or EXPR.  (Which
   2970    is indicated by CODE, which should be POSTINCREMENT_EXPR or
   2971    POSTDECREMENT_EXPR.)  */
   2972 
   2973 cp_expr
   2974 finish_increment_expr (cp_expr expr, enum tree_code code)
   2975 {
   2976   /* input_location holds the location of the trailing operator token.
   2977      Build a location of the form:
   2978        expr++
   2979        ~~~~^~
   2980      with the caret at the operator token, ranging from the start
   2981      of EXPR to the end of the operator token.  */
   2982   location_t combined_loc = make_location (input_location,
   2983 					   expr.get_start (),
   2984 					   get_finish (input_location));
   2985   cp_expr result = build_x_unary_op (combined_loc, code, expr,
   2986 				     NULL_TREE, tf_warning_or_error);
   2987   /* TODO: build_x_unary_op doesn't honor the location, so set it here.  */
   2988   result.set_location (combined_loc);
   2989   return result;
   2990 }
   2991 
   2992 /* Finish a use of `this'.  Returns an expression for `this'.  */
   2993 
   2994 tree
   2995 finish_this_expr (void)
   2996 {
   2997   tree result = NULL_TREE;
   2998 
   2999   if (current_class_ptr)
   3000     {
   3001       tree type = TREE_TYPE (current_class_ref);
   3002 
   3003       /* In a lambda expression, 'this' refers to the captured 'this'.  */
   3004       if (LAMBDA_TYPE_P (type))
   3005         result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true);
   3006       else
   3007         result = current_class_ptr;
   3008     }
   3009 
   3010   if (result)
   3011     /* The keyword 'this' is a prvalue expression.  */
   3012     return rvalue (result);
   3013 
   3014   tree fn = current_nonlambda_function ();
   3015   if (fn && DECL_STATIC_FUNCTION_P (fn))
   3016     error ("%<this%> is unavailable for static member functions");
   3017   else if (fn)
   3018     error ("invalid use of %<this%> in non-member function");
   3019   else
   3020     error ("invalid use of %<this%> at top level");
   3021   return error_mark_node;
   3022 }
   3023 
   3024 /* Finish a pseudo-destructor expression.  If SCOPE is NULL, the
   3025    expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
   3026    the TYPE for the type given.  If SCOPE is non-NULL, the expression
   3027    was of the form `OBJECT.SCOPE::~DESTRUCTOR'.  */
   3028 
   3029 tree
   3030 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
   3031 			       location_t loc)
   3032 {
   3033   if (object == error_mark_node || destructor == error_mark_node)
   3034     return error_mark_node;
   3035 
   3036   gcc_assert (TYPE_P (destructor));
   3037 
   3038   if (!processing_template_decl)
   3039     {
   3040       if (scope == error_mark_node)
   3041 	{
   3042 	  error_at (loc, "invalid qualifying scope in pseudo-destructor name");
   3043 	  return error_mark_node;
   3044 	}
   3045       if (is_auto (destructor))
   3046 	destructor = TREE_TYPE (object);
   3047       if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
   3048 	{
   3049 	  error_at (loc,
   3050 		    "qualified type %qT does not match destructor name ~%qT",
   3051 		    scope, destructor);
   3052 	  return error_mark_node;
   3053 	}
   3054 
   3055 
   3056       /* [expr.pseudo] says both:
   3057 
   3058 	   The type designated by the pseudo-destructor-name shall be
   3059 	   the same as the object type.
   3060 
   3061 	 and:
   3062 
   3063 	   The cv-unqualified versions of the object type and of the
   3064 	   type designated by the pseudo-destructor-name shall be the
   3065 	   same type.
   3066 
   3067 	 We implement the more generous second sentence, since that is
   3068 	 what most other compilers do.  */
   3069       if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
   3070 						      destructor))
   3071 	{
   3072 	  error_at (loc, "%qE is not of type %qT", object, destructor);
   3073 	  return error_mark_node;
   3074 	}
   3075     }
   3076 
   3077   tree type = (type_dependent_expression_p (object)
   3078 	       ? NULL_TREE : void_type_node);
   3079 
   3080   return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
   3081 		     scope, destructor);
   3082 }
   3083 
   3084 /* Finish an expression of the form CODE EXPR.  */
   3085 
   3086 cp_expr
   3087 finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
   3088 		      tsubst_flags_t complain)
   3089 {
   3090   /* Build a location of the form:
   3091        ++expr
   3092        ^~~~~~
   3093      with the caret at the operator token, ranging from the start
   3094      of the operator token to the end of EXPR.  */
   3095   location_t combined_loc = make_location (op_loc,
   3096 					   op_loc, expr.get_finish ());
   3097   cp_expr result = build_x_unary_op (combined_loc, code, expr,
   3098 				     NULL_TREE, complain);
   3099   /* TODO: build_x_unary_op doesn't always honor the location.  */
   3100   result.set_location (combined_loc);
   3101 
   3102   if (result == error_mark_node)
   3103     return result;
   3104 
   3105   if (!(complain & tf_warning))
   3106     return result;
   3107 
   3108   tree result_ovl = result;
   3109   tree expr_ovl = expr;
   3110 
   3111   if (!processing_template_decl)
   3112     expr_ovl = cp_fully_fold (expr_ovl);
   3113 
   3114   if (!CONSTANT_CLASS_P (expr_ovl)
   3115       || TREE_OVERFLOW_P (expr_ovl))
   3116     return result;
   3117 
   3118   if (!processing_template_decl)
   3119     result_ovl = cp_fully_fold (result_ovl);
   3120 
   3121   if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
   3122     overflow_warning (combined_loc, result_ovl);
   3123 
   3124   return result;
   3125 }
   3126 
   3127 /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
   3128    elements.  */
   3129 
   3130 static bool
   3131 maybe_zero_constructor_nelts (tree expr)
   3132 {
   3133   if (CONSTRUCTOR_NELTS (expr) == 0)
   3134     return true;
   3135   if (!processing_template_decl)
   3136     return false;
   3137   for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
   3138     if (!PACK_EXPANSION_P (elt.value))
   3139       return false;
   3140   return true;
   3141 }
   3142 
   3143 /* Finish a compound-literal expression or C++11 functional cast with aggregate
   3144    initializer.  TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
   3145    is being cast.  */
   3146 
   3147 tree
   3148 finish_compound_literal (tree type, tree compound_literal,
   3149 			 tsubst_flags_t complain,
   3150 			 fcl_t fcl_context)
   3151 {
   3152   if (type == error_mark_node)
   3153     return error_mark_node;
   3154 
   3155   if (TYPE_REF_P (type))
   3156     {
   3157       compound_literal
   3158 	= finish_compound_literal (TREE_TYPE (type), compound_literal,
   3159 				   complain, fcl_context);
   3160       /* The prvalue is then used to direct-initialize the reference.  */
   3161       tree r = (perform_implicit_conversion_flags
   3162 		(type, compound_literal, complain, LOOKUP_NORMAL));
   3163       return convert_from_reference (r);
   3164     }
   3165 
   3166   if (!TYPE_OBJ_P (type))
   3167     {
   3168       /* DR2351 */
   3169       if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
   3170 	return void_node;
   3171       else if (VOID_TYPE_P (type)
   3172 	       && processing_template_decl
   3173 	       && maybe_zero_constructor_nelts (compound_literal))
   3174 	/* If there are only packs in compound_literal, it could
   3175 	   be void{} after pack expansion.  */;
   3176       else
   3177 	{
   3178 	  if (complain & tf_error)
   3179 	    error ("compound literal of non-object type %qT", type);
   3180 	  return error_mark_node;
   3181 	}
   3182     }
   3183 
   3184   if (template_placeholder_p (type))
   3185     {
   3186       type = do_auto_deduction (type, compound_literal, type, complain,
   3187 				adc_variable_type);
   3188       if (type == error_mark_node)
   3189 	return error_mark_node;
   3190     }
   3191   /* C++23 auto{x}.  */
   3192   else if (is_auto (type)
   3193 	   && !AUTO_IS_DECLTYPE (type)
   3194 	   && CONSTRUCTOR_NELTS (compound_literal) == 1)
   3195     {
   3196       if (is_constrained_auto (type))
   3197 	{
   3198 	  if (complain & tf_error)
   3199 	    error ("%<auto{x}%> cannot be constrained");
   3200 	  return error_mark_node;
   3201 	}
   3202       else if (cxx_dialect < cxx23)
   3203 	pedwarn (input_location, OPT_Wc__23_extensions,
   3204 		 "%<auto{x}%> only available with "
   3205 		 "%<-std=c++2b%> or %<-std=gnu++2b%>");
   3206       type = do_auto_deduction (type, compound_literal, type, complain,
   3207 				adc_variable_type);
   3208       if (type == error_mark_node)
   3209 	return error_mark_node;
   3210     }
   3211 
   3212   /* Used to hold a copy of the compound literal in a template.  */
   3213   tree orig_cl = NULL_TREE;
   3214 
   3215   if (processing_template_decl)
   3216     {
   3217       const bool dependent_p
   3218 	= (instantiation_dependent_expression_p (compound_literal)
   3219 	   || dependent_type_p (type));
   3220       if (dependent_p)
   3221 	/* We're about to return, no need to copy.  */
   3222 	orig_cl = compound_literal;
   3223       else
   3224 	/* We're going to need a copy.  */
   3225 	orig_cl = unshare_constructor (compound_literal);
   3226       TREE_TYPE (orig_cl) = type;
   3227       /* Mark the expression as a compound literal.  */
   3228       TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
   3229       /* And as instantiation-dependent.  */
   3230       CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
   3231       if (fcl_context == fcl_c99)
   3232 	CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
   3233       /* If the compound literal is dependent, we're done for now.  */
   3234       if (dependent_p)
   3235 	return orig_cl;
   3236       /* Otherwise, do go on to e.g. check narrowing.  */
   3237     }
   3238 
   3239   type = complete_type (type);
   3240 
   3241   if (TYPE_NON_AGGREGATE_CLASS (type))
   3242     {
   3243       /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
   3244 	 everywhere that deals with function arguments would be a pain, so
   3245 	 just wrap it in a TREE_LIST.  The parser set a flag so we know
   3246 	 that it came from T{} rather than T({}).  */
   3247       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
   3248       compound_literal = build_tree_list (NULL_TREE, compound_literal);
   3249       return build_functional_cast (input_location, type,
   3250 				    compound_literal, complain);
   3251     }
   3252 
   3253   if (TREE_CODE (type) == ARRAY_TYPE
   3254       && check_array_initializer (NULL_TREE, type, compound_literal))
   3255     return error_mark_node;
   3256   compound_literal = reshape_init (type, compound_literal, complain);
   3257   if (SCALAR_TYPE_P (type)
   3258       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
   3259       && !check_narrowing (type, compound_literal, complain))
   3260     return error_mark_node;
   3261   if (TREE_CODE (type) == ARRAY_TYPE
   3262       && TYPE_DOMAIN (type) == NULL_TREE)
   3263     {
   3264       cp_complete_array_type_or_error (&type, compound_literal,
   3265 				       false, complain);
   3266       if (type == error_mark_node)
   3267 	return error_mark_node;
   3268     }
   3269   compound_literal = digest_init_flags (type, compound_literal,
   3270 					LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
   3271 					complain);
   3272   if (compound_literal == error_mark_node)
   3273     return error_mark_node;
   3274 
   3275   /* If we're in a template, return the original compound literal.  */
   3276   if (orig_cl)
   3277     return orig_cl;
   3278 
   3279   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
   3280     {
   3281       TREE_HAS_CONSTRUCTOR (compound_literal) = true;
   3282       if (fcl_context == fcl_c99)
   3283 	CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
   3284     }
   3285 
   3286   /* Put static/constant array temporaries in static variables.  */
   3287   /* FIXME all C99 compound literals should be variables rather than C++
   3288      temporaries, unless they are used as an aggregate initializer.  */
   3289   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
   3290       && fcl_context == fcl_c99
   3291       && TREE_CODE (type) == ARRAY_TYPE
   3292       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   3293       && initializer_constant_valid_p (compound_literal, type))
   3294     {
   3295       tree decl = create_temporary_var (type);
   3296       DECL_CONTEXT (decl) = NULL_TREE;
   3297       DECL_INITIAL (decl) = compound_literal;
   3298       TREE_STATIC (decl) = 1;
   3299       if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
   3300 	{
   3301 	  /* 5.19 says that a constant expression can include an
   3302 	     lvalue-rvalue conversion applied to "a glvalue of literal type
   3303 	     that refers to a non-volatile temporary object initialized
   3304 	     with a constant expression".  Rather than try to communicate
   3305 	     that this VAR_DECL is a temporary, just mark it constexpr.  */
   3306 	  DECL_DECLARED_CONSTEXPR_P (decl) = true;
   3307 	  DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
   3308 	  TREE_CONSTANT (decl) = true;
   3309 	}
   3310       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
   3311       decl = pushdecl_top_level (decl);
   3312       DECL_NAME (decl) = make_anon_name ();
   3313       SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
   3314       /* Make sure the destructor is callable.  */
   3315       tree clean = cxx_maybe_build_cleanup (decl, complain);
   3316       if (clean == error_mark_node)
   3317 	return error_mark_node;
   3318       return decl;
   3319     }
   3320 
   3321   /* Represent other compound literals with TARGET_EXPR so we produce
   3322      a prvalue, and can elide copies.  */
   3323   if (!VECTOR_TYPE_P (type)
   3324       && (TREE_CODE (compound_literal) == CONSTRUCTOR
   3325 	  || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
   3326     {
   3327       /* The CONSTRUCTOR is now an initializer, not a compound literal.  */
   3328       if (TREE_CODE (compound_literal) == CONSTRUCTOR)
   3329 	TREE_HAS_CONSTRUCTOR (compound_literal) = false;
   3330       compound_literal = get_target_expr_sfinae (compound_literal, complain);
   3331     }
   3332   else
   3333     /* For e.g. int{42} just make sure it's a prvalue.  */
   3334     compound_literal = rvalue (compound_literal);
   3335 
   3336   return compound_literal;
   3337 }
   3338 
   3339 /* Return the declaration for the function-name variable indicated by
   3340    ID.  */
   3341 
   3342 tree
   3343 finish_fname (tree id)
   3344 {
   3345   tree decl;
   3346 
   3347   decl = fname_decl (input_location, C_RID_CODE (id), id);
   3348   if (processing_template_decl && current_function_decl
   3349       && decl != error_mark_node)
   3350     decl = DECL_NAME (decl);
   3351   return decl;
   3352 }
   3353 
   3354 /* Finish a translation unit.  */
   3355 
   3356 void
   3357 finish_translation_unit (void)
   3358 {
   3359   /* In case there were missing closebraces,
   3360      get us back to the global binding level.  */
   3361   pop_everything ();
   3362   while (current_namespace != global_namespace)
   3363     pop_namespace ();
   3364 
   3365   /* Do file scope __FUNCTION__ et al.  */
   3366   finish_fname_decls ();
   3367 
   3368   if (vec_safe_length (scope_chain->omp_declare_target_attribute))
   3369     {
   3370       if (!errorcount)
   3371 	error ("%<#pragma omp declare target%> without corresponding "
   3372 	       "%<#pragma omp end declare target%>");
   3373       vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
   3374     }
   3375 }
   3376 
   3377 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
   3378    Returns the parameter.  */
   3379 
   3380 tree
   3381 finish_template_type_parm (tree aggr, tree identifier)
   3382 {
   3383   if (aggr != class_type_node)
   3384     {
   3385       permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
   3386       aggr = class_type_node;
   3387     }
   3388 
   3389   return build_tree_list (aggr, identifier);
   3390 }
   3391 
   3392 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
   3393    Returns the parameter.  */
   3394 
   3395 tree
   3396 finish_template_template_parm (tree aggr, tree identifier)
   3397 {
   3398   tree decl = build_decl (input_location,
   3399 			  TYPE_DECL, identifier, NULL_TREE);
   3400 
   3401   tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
   3402   DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
   3403   DECL_TEMPLATE_RESULT (tmpl) = decl;
   3404   DECL_ARTIFICIAL (decl) = 1;
   3405 
   3406   /* Associate the constraints with the underlying declaration,
   3407      not the template.  */
   3408   tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   3409   tree constr = build_constraints (reqs, NULL_TREE);
   3410   set_constraints (decl, constr);
   3411 
   3412   end_template_decl ();
   3413 
   3414   gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
   3415 
   3416   check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
   3417 			   /*is_primary=*/true, /*is_partial=*/false,
   3418 			   /*is_friend=*/0);
   3419 
   3420   return finish_template_type_parm (aggr, tmpl);
   3421 }
   3422 
   3423 /* ARGUMENT is the default-argument value for a template template
   3424    parameter.  If ARGUMENT is invalid, issue error messages and return
   3425    the ERROR_MARK_NODE.  Otherwise, ARGUMENT itself is returned.  */
   3426 
   3427 tree
   3428 check_template_template_default_arg (tree argument)
   3429 {
   3430   if (TREE_CODE (argument) != TEMPLATE_DECL
   3431       && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
   3432       && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
   3433     {
   3434       if (TREE_CODE (argument) == TYPE_DECL)
   3435 	error ("invalid use of type %qT as a default value for a template "
   3436 	       "template-parameter", TREE_TYPE (argument));
   3437       else
   3438 	error ("invalid default argument for a template template parameter");
   3439       return error_mark_node;
   3440     }
   3441 
   3442   return argument;
   3443 }
   3444 
   3445 /* Begin a class definition, as indicated by T.  */
   3446 
   3447 tree
   3448 begin_class_definition (tree t)
   3449 {
   3450   if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
   3451     return error_mark_node;
   3452 
   3453   if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
   3454     {
   3455       error ("definition of %q#T inside template parameter list", t);
   3456       return error_mark_node;
   3457     }
   3458 
   3459   /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
   3460      are passed the same as decimal scalar types.  */
   3461   if (TREE_CODE (t) == RECORD_TYPE
   3462       && !processing_template_decl)
   3463     {
   3464       tree ns = TYPE_CONTEXT (t);
   3465       if (ns && TREE_CODE (ns) == NAMESPACE_DECL
   3466 	  && DECL_CONTEXT (ns) == std_node
   3467 	  && DECL_NAME (ns)
   3468 	  && id_equal (DECL_NAME (ns), "decimal"))
   3469 	{
   3470 	  const char *n = TYPE_NAME_STRING (t);
   3471 	  if ((strcmp (n, "decimal32") == 0)
   3472 	      || (strcmp (n, "decimal64") == 0)
   3473 	      || (strcmp (n, "decimal128") == 0))
   3474 	    TYPE_TRANSPARENT_AGGR (t) = 1;
   3475 	}
   3476     }
   3477 
   3478   /* A non-implicit typename comes from code like:
   3479 
   3480        template <typename T> struct A {
   3481 	 template <typename U> struct A<T>::B ...
   3482 
   3483      This is erroneous.  */
   3484   else if (TREE_CODE (t) == TYPENAME_TYPE)
   3485     {
   3486       error ("invalid definition of qualified type %qT", t);
   3487       t = error_mark_node;
   3488     }
   3489 
   3490   if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
   3491     {
   3492       t = make_class_type (RECORD_TYPE);
   3493       pushtag (make_anon_name (), t);
   3494     }
   3495 
   3496   if (TYPE_BEING_DEFINED (t))
   3497     {
   3498       t = make_class_type (TREE_CODE (t));
   3499       pushtag (TYPE_IDENTIFIER (t), t);
   3500     }
   3501 
   3502   if (modules_p ())
   3503     {
   3504       if (!module_may_redeclare (TYPE_NAME (t)))
   3505 	{
   3506 	  error ("cannot declare %qD in a different module", TYPE_NAME (t));
   3507 	  inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "declared here");
   3508 	  return error_mark_node;
   3509 	}
   3510       set_instantiating_module (TYPE_NAME (t));
   3511       set_defining_module (TYPE_NAME (t));
   3512     }
   3513 
   3514   maybe_process_partial_specialization (t);
   3515   pushclass (t);
   3516   TYPE_BEING_DEFINED (t) = 1;
   3517   class_binding_level->defining_class_p = 1;
   3518 
   3519   if (flag_pack_struct)
   3520     {
   3521       tree v;
   3522       TYPE_PACKED (t) = 1;
   3523       /* Even though the type is being defined for the first time
   3524 	 here, there might have been a forward declaration, so there
   3525 	 might be cv-qualified variants of T.  */
   3526       for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
   3527 	TYPE_PACKED (v) = 1;
   3528     }
   3529   /* Reset the interface data, at the earliest possible
   3530      moment, as it might have been set via a class foo;
   3531      before.  */
   3532   if (! TYPE_UNNAMED_P (t))
   3533     {
   3534       struct c_fileinfo *finfo = \
   3535 	get_fileinfo (LOCATION_FILE (input_location));
   3536       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
   3537       SET_CLASSTYPE_INTERFACE_UNKNOWN_X
   3538 	(t, finfo->interface_unknown);
   3539     }
   3540   reset_specialization ();
   3541 
   3542   /* Make a declaration for this class in its own scope.  */
   3543   build_self_reference ();
   3544 
   3545   return t;
   3546 }
   3547 
   3548 /* Finish the member declaration given by DECL.  */
   3549 
   3550 void
   3551 finish_member_declaration (tree decl)
   3552 {
   3553   if (decl == error_mark_node || decl == NULL_TREE)
   3554     return;
   3555 
   3556   if (decl == void_type_node)
   3557     /* The COMPONENT was a friend, not a member, and so there's
   3558        nothing for us to do.  */
   3559     return;
   3560 
   3561   /* We should see only one DECL at a time.  */
   3562   gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
   3563 
   3564   /* Don't add decls after definition.  */
   3565   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
   3566 	      /* We can add lambda types when late parsing default
   3567 		 arguments.  */
   3568 	      || LAMBDA_TYPE_P (TREE_TYPE (decl)));
   3569 
   3570   /* Set up access control for DECL.  */
   3571   TREE_PRIVATE (decl)
   3572     = (current_access_specifier == access_private_node);
   3573   TREE_PROTECTED (decl)
   3574     = (current_access_specifier == access_protected_node);
   3575   if (TREE_CODE (decl) == TEMPLATE_DECL)
   3576     {
   3577       TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
   3578       TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
   3579     }
   3580 
   3581   /* Mark the DECL as a member of the current class, unless it's
   3582      a member of an enumeration.  */
   3583   if (TREE_CODE (decl) != CONST_DECL)
   3584     DECL_CONTEXT (decl) = current_class_type;
   3585 
   3586   /* Remember the single FIELD_DECL an anonymous aggregate type is used for.  */
   3587   if (TREE_CODE (decl) == FIELD_DECL
   3588       && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
   3589     {
   3590       gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
   3591       ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
   3592     }
   3593 
   3594   if (TREE_CODE (decl) == USING_DECL)
   3595     /* Avoid debug info for class-scope USING_DECLS for now, we'll
   3596        call cp_emit_debug_info_for_using later. */
   3597     DECL_IGNORED_P (decl) = 1;
   3598 
   3599   /* Check for bare parameter packs in the non-static data member
   3600      declaration.  */
   3601   if (TREE_CODE (decl) == FIELD_DECL)
   3602     {
   3603       if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
   3604         TREE_TYPE (decl) = error_mark_node;
   3605       if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
   3606         DECL_ATTRIBUTES (decl) = NULL_TREE;
   3607     }
   3608 
   3609   /* [dcl.link]
   3610 
   3611      A C language linkage is ignored for the names of class members
   3612      and the member function type of class member functions.  */
   3613   if (DECL_LANG_SPECIFIC (decl))
   3614     SET_DECL_LANGUAGE (decl, lang_cplusplus);
   3615 
   3616   bool add = false;
   3617 
   3618   /* Functions and non-functions are added differently.  */
   3619   if (DECL_DECLARES_FUNCTION_P (decl))
   3620     add = add_method (current_class_type, decl, false);
   3621   /* Enter the DECL into the scope of the class, if the class
   3622      isn't a closure (whose fields are supposed to be unnamed).  */
   3623   else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
   3624 	   || maybe_push_used_methods (decl)
   3625 	   || pushdecl_class_level (decl))
   3626     add = true;
   3627 
   3628   if (add)
   3629     {
   3630       /* All TYPE_DECLs go at the end of TYPE_FIELDS.  Ordinary fields
   3631 	 go at the beginning.  The reason is that
   3632 	 legacy_nonfn_member_lookup searches the list in order, and we
   3633 	 want a field name to override a type name so that the "struct
   3634 	 stat hack" will work.  In particular:
   3635 
   3636 	   struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
   3637 
   3638 	 is valid.  */
   3639 
   3640       if (TREE_CODE (decl) == TYPE_DECL)
   3641 	TYPE_FIELDS (current_class_type)
   3642 	  = chainon (TYPE_FIELDS (current_class_type), decl);
   3643       else
   3644 	{
   3645 	  DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
   3646 	  TYPE_FIELDS (current_class_type) = decl;
   3647 	}
   3648 
   3649       maybe_add_class_template_decl_list (current_class_type, decl,
   3650 					  /*friend_p=*/0);
   3651     }
   3652 }
   3653 
   3654 /* Finish processing a complete template declaration.  The PARMS are
   3655    the template parameters.  */
   3656 
   3657 void
   3658 finish_template_decl (tree parms)
   3659 {
   3660   if (parms)
   3661     end_template_decl ();
   3662   else
   3663     end_specialization ();
   3664 }
   3665 
   3666 // Returns the template type of the class scope being entered. If we're
   3667 // entering a constrained class scope. TYPE is the class template
   3668 // scope being entered and we may need to match the intended type with
   3669 // a constrained specialization. For example:
   3670 //
   3671 //    template<Object T>
   3672 //      struct S { void f(); }; #1
   3673 //
   3674 //    template<Object T>
   3675 //      void S<T>::f() { }      #2
   3676 //
   3677 // We check, in #2, that S<T> refers precisely to the type declared by
   3678 // #1 (i.e., that the constraints match). Note that the following should
   3679 // be an error since there is no specialization of S<T> that is
   3680 // unconstrained, but this is not diagnosed here.
   3681 //
   3682 //    template<typename T>
   3683 //      void S<T>::f() { }
   3684 //
   3685 // We cannot diagnose this problem here since this function also matches
   3686 // qualified template names that are not part of a definition. For example:
   3687 //
   3688 //    template<Integral T, Floating_point U>
   3689 //      typename pair<T, U>::first_type void f(T, U);
   3690 //
   3691 // Here, it is unlikely that there is a partial specialization of
   3692 // pair constrained for for Integral and Floating_point arguments.
   3693 //
   3694 // The general rule is: if a constrained specialization with matching
   3695 // constraints is found return that type. Also note that if TYPE is not a
   3696 // class-type (e.g. a typename type), then no fixup is needed.
   3697 
   3698 static tree
   3699 fixup_template_type (tree type)
   3700 {
   3701   // Find the template parameter list at the a depth appropriate to
   3702   // the scope we're trying to enter.
   3703   tree parms = current_template_parms;
   3704   int depth = template_class_depth (type);
   3705   for (int n = current_template_depth; n > depth && parms; --n)
   3706     parms = TREE_CHAIN (parms);
   3707   if (!parms)
   3708     return type;
   3709   tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
   3710   tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
   3711 
   3712   // Search for a specialization whose type and constraints match.
   3713   tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
   3714   tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
   3715   while (specs)
   3716     {
   3717       tree spec_constr = get_constraints (TREE_VALUE (specs));
   3718 
   3719       // If the type and constraints match a specialization, then we
   3720       // are entering that type.
   3721       if (same_type_p (type, TREE_TYPE (specs))
   3722 	  && equivalent_constraints (cur_constr, spec_constr))
   3723         return TREE_TYPE (specs);
   3724       specs = TREE_CHAIN (specs);
   3725     }
   3726 
   3727   // If no specialization matches, then must return the type
   3728   // previously found.
   3729   return type;
   3730 }
   3731 
   3732 /* Finish processing a template-id (which names a type) of the form
   3733    NAME < ARGS >.  Return the TYPE_DECL for the type named by the
   3734    template-id.  If ENTERING_SCOPE is nonzero we are about to enter
   3735    the scope of template-id indicated.  */
   3736 
   3737 tree
   3738 finish_template_type (tree name, tree args, int entering_scope)
   3739 {
   3740   tree type;
   3741 
   3742   type = lookup_template_class (name, args,
   3743 				NULL_TREE, NULL_TREE, entering_scope,
   3744 				tf_warning_or_error | tf_user);
   3745 
   3746   /* If we might be entering the scope of a partial specialization,
   3747      find the one with the right constraints.  */
   3748   if (flag_concepts
   3749       && entering_scope
   3750       && CLASS_TYPE_P (type)
   3751       && CLASSTYPE_TEMPLATE_INFO (type)
   3752       && dependent_type_p (type)
   3753       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
   3754     type = fixup_template_type (type);
   3755 
   3756   if (type == error_mark_node)
   3757     return type;
   3758   else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
   3759     return TYPE_STUB_DECL (type);
   3760   else
   3761     return TYPE_NAME (type);
   3762 }
   3763 
   3764 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
   3765    Return a TREE_LIST containing the ACCESS_SPECIFIER and the
   3766    BASE_CLASS, or NULL_TREE if an error occurred.  The
   3767    ACCESS_SPECIFIER is one of
   3768    access_{default,public,protected_private}_node.  For a virtual base
   3769    we set TREE_TYPE.  */
   3770 
   3771 tree
   3772 finish_base_specifier (tree base, tree access, bool virtual_p)
   3773 {
   3774   tree result;
   3775 
   3776   if (base == error_mark_node)
   3777     {
   3778       error ("invalid base-class specification");
   3779       result = NULL_TREE;
   3780     }
   3781   else if (! MAYBE_CLASS_TYPE_P (base))
   3782     {
   3783       error ("%qT is not a class type", base);
   3784       result = NULL_TREE;
   3785     }
   3786   else
   3787     {
   3788       if (cp_type_quals (base) != 0)
   3789 	{
   3790 	  /* DR 484: Can a base-specifier name a cv-qualified
   3791 	     class type?  */
   3792 	  base = TYPE_MAIN_VARIANT (base);
   3793 	}
   3794       result = build_tree_list (access, base);
   3795       if (virtual_p)
   3796 	TREE_TYPE (result) = integer_type_node;
   3797     }
   3798 
   3799   return result;
   3800 }
   3801 
   3802 /* If FNS is a member function, a set of member functions, or a
   3803    template-id referring to one or more member functions, return a
   3804    BASELINK for FNS, incorporating the current access context.
   3805    Otherwise, return FNS unchanged.  */
   3806 
   3807 tree
   3808 baselink_for_fns (tree fns)
   3809 {
   3810   tree scope;
   3811   tree cl;
   3812 
   3813   if (BASELINK_P (fns)
   3814       || error_operand_p (fns))
   3815     return fns;
   3816 
   3817   scope = ovl_scope (fns);
   3818   if (!CLASS_TYPE_P (scope))
   3819     return fns;
   3820 
   3821   cl = currently_open_derived_class (scope);
   3822   if (!cl)
   3823     cl = scope;
   3824   tree access_path = TYPE_BINFO (cl);
   3825   tree conv_path = (cl == scope ? access_path
   3826 		    : lookup_base (cl, scope, ba_any, NULL, tf_none));
   3827   return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
   3828 }
   3829 
   3830 /* Returns true iff DECL is a variable from a function outside
   3831    the current one.  */
   3832 
   3833 static bool
   3834 outer_var_p (tree decl)
   3835 {
   3836   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
   3837 	  && DECL_FUNCTION_SCOPE_P (decl)
   3838 	  /* Don't get confused by temporaries.  */
   3839 	  && DECL_NAME (decl)
   3840 	  && (DECL_CONTEXT (decl) != current_function_decl
   3841 	      || parsing_nsdmi ()));
   3842 }
   3843 
   3844 /* As above, but also checks that DECL is automatic.  */
   3845 
   3846 bool
   3847 outer_automatic_var_p (tree decl)
   3848 {
   3849   return (outer_var_p (decl)
   3850 	  && !TREE_STATIC (decl));
   3851 }
   3852 
   3853 /* DECL satisfies outer_automatic_var_p.  Possibly complain about it or
   3854    rewrite it for lambda capture.
   3855 
   3856    If ODR_USE is true, we're being called from mark_use, and we complain about
   3857    use of constant variables.  If ODR_USE is false, we're being called for the
   3858    id-expression, and we do lambda capture.  */
   3859 
   3860 tree
   3861 process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
   3862 {
   3863   if (cp_unevaluated_operand)
   3864     {
   3865       tree type = TREE_TYPE (decl);
   3866       if (!dependent_type_p (type)
   3867 	  && variably_modified_type_p (type, NULL_TREE))
   3868 	/* VLAs are used even in unevaluated context.  */;
   3869       else
   3870 	/* It's not a use (3.2) if we're in an unevaluated context.  */
   3871 	return decl;
   3872     }
   3873   if (decl == error_mark_node)
   3874     return decl;
   3875 
   3876   tree context = DECL_CONTEXT (decl);
   3877   tree containing_function = current_function_decl;
   3878   tree lambda_stack = NULL_TREE;
   3879   tree lambda_expr = NULL_TREE;
   3880   tree initializer = convert_from_reference (decl);
   3881 
   3882   /* Mark it as used now even if the use is ill-formed.  */
   3883   if (!mark_used (decl, complain))
   3884     return error_mark_node;
   3885 
   3886   if (parsing_nsdmi ())
   3887     containing_function = NULL_TREE;
   3888 
   3889   if (containing_function && LAMBDA_FUNCTION_P (containing_function))
   3890     {
   3891       /* Check whether we've already built a proxy.  */
   3892       tree var = decl;
   3893       while (is_normal_capture_proxy (var))
   3894 	var = DECL_CAPTURED_VARIABLE (var);
   3895       tree d = retrieve_local_specialization (var);
   3896 
   3897       if (d && d != decl && is_capture_proxy (d))
   3898 	{
   3899 	  if (DECL_CONTEXT (d) == containing_function)
   3900 	    /* We already have an inner proxy.  */
   3901 	    return d;
   3902 	  else
   3903 	    /* We need to capture an outer proxy.  */
   3904 	    return process_outer_var_ref (d, complain, odr_use);
   3905 	}
   3906     }
   3907 
   3908   /* If we are in a lambda function, we can move out until we hit
   3909      1. the context,
   3910      2. a non-lambda function, or
   3911      3. a non-default capturing lambda function.  */
   3912   while (context != containing_function
   3913 	 /* containing_function can be null with invalid generic lambdas.  */
   3914 	 && containing_function
   3915 	 && LAMBDA_FUNCTION_P (containing_function))
   3916     {
   3917       tree closure = DECL_CONTEXT (containing_function);
   3918       lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
   3919 
   3920       if (TYPE_CLASS_SCOPE_P (closure))
   3921 	/* A lambda in an NSDMI (c++/64496).  */
   3922 	break;
   3923 
   3924       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
   3925 	break;
   3926 
   3927       lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
   3928 
   3929       containing_function = decl_function_context (containing_function);
   3930     }
   3931 
   3932   /* In a lambda within a template, wait until instantiation time to implicitly
   3933      capture a parameter pack.  We want to wait because we don't know if we're
   3934      capturing the whole pack or a single element, and it's OK to wait because
   3935      find_parameter_packs_r walks into the lambda body.  */
   3936   if (context == containing_function
   3937       && DECL_PACK_P (decl))
   3938     return decl;
   3939 
   3940   if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
   3941     {
   3942       if (complain & tf_error)
   3943 	error ("cannot capture member %qD of anonymous union", decl);
   3944       return error_mark_node;
   3945     }
   3946   /* Do lambda capture when processing the id-expression, not when
   3947      odr-using a variable.  */
   3948   if (!odr_use && context == containing_function)
   3949     decl = add_default_capture (lambda_stack,
   3950 				/*id=*/DECL_NAME (decl), initializer);
   3951   /* Only an odr-use of an outer automatic variable causes an
   3952      error, and a constant variable can decay to a prvalue
   3953      constant without odr-use.  So don't complain yet.  */
   3954   else if (!odr_use && decl_constant_var_p (decl))
   3955     return decl;
   3956   else if (lambda_expr)
   3957     {
   3958       if (complain & tf_error)
   3959 	{
   3960 	  error ("%qD is not captured", decl);
   3961 	  tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
   3962 	  if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
   3963 	    inform (location_of (closure),
   3964 		    "the lambda has no capture-default");
   3965 	  else if (TYPE_CLASS_SCOPE_P (closure))
   3966 	    inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
   3967 		    "capture variables from the enclosing context",
   3968 		    TYPE_CONTEXT (closure));
   3969 	  inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
   3970 	}
   3971       return error_mark_node;
   3972     }
   3973   else
   3974     {
   3975       if (complain & tf_error)
   3976 	{
   3977 	  error (VAR_P (decl)
   3978 		 ? G_("use of local variable with automatic storage from "
   3979 		      "containing function")
   3980 		 : G_("use of parameter from containing function"));
   3981 	  inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
   3982 	}
   3983       return error_mark_node;
   3984     }
   3985   return decl;
   3986 }
   3987 
   3988 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
   3989    id-expression.  (See cp_parser_id_expression for details.)  SCOPE,
   3990    if non-NULL, is the type or namespace used to explicitly qualify
   3991    ID_EXPRESSION.  DECL is the entity to which that name has been
   3992    resolved.
   3993 
   3994    *CONSTANT_EXPRESSION_P is true if we are presently parsing a
   3995    constant-expression.  In that case, *NON_CONSTANT_EXPRESSION_P will
   3996    be set to true if this expression isn't permitted in a
   3997    constant-expression, but it is otherwise not set by this function.
   3998    *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
   3999    constant-expression, but a non-constant expression is also
   4000    permissible.
   4001 
   4002    DONE is true if this expression is a complete postfix-expression;
   4003    it is false if this expression is followed by '->', '[', '(', etc.
   4004    ADDRESS_P is true iff this expression is the operand of '&'.
   4005    TEMPLATE_P is true iff the qualified-id was of the form
   4006    "A::template B".  TEMPLATE_ARG_P is true iff this qualified name
   4007    appears as a template argument.
   4008 
   4009    If an error occurs, and it is the kind of error that might cause
   4010    the parser to abort a tentative parse, *ERROR_MSG is filled in.  It
   4011    is the caller's responsibility to issue the message.  *ERROR_MSG
   4012    will be a string with static storage duration, so the caller need
   4013    not "free" it.
   4014 
   4015    Return an expression for the entity, after issuing appropriate
   4016    diagnostics.  This function is also responsible for transforming a
   4017    reference to a non-static member into a COMPONENT_REF that makes
   4018    the use of "this" explicit.
   4019 
   4020    Upon return, *IDK will be filled in appropriately.  */
   4021 static cp_expr
   4022 finish_id_expression_1 (tree id_expression,
   4023 			tree decl,
   4024 			tree scope,
   4025 			cp_id_kind *idk,
   4026 			bool integral_constant_expression_p,
   4027 			bool allow_non_integral_constant_expression_p,
   4028 			bool *non_integral_constant_expression_p,
   4029 			bool template_p,
   4030 			bool done,
   4031 			bool address_p,
   4032 			bool template_arg_p,
   4033 			const char **error_msg,
   4034 			location_t location)
   4035 {
   4036   decl = strip_using_decl (decl);
   4037 
   4038   /* Initialize the output parameters.  */
   4039   *idk = CP_ID_KIND_NONE;
   4040   *error_msg = NULL;
   4041 
   4042   if (id_expression == error_mark_node)
   4043     return error_mark_node;
   4044   /* If we have a template-id, then no further lookup is
   4045      required.  If the template-id was for a template-class, we
   4046      will sometimes have a TYPE_DECL at this point.  */
   4047   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
   4048 	   || TREE_CODE (decl) == TYPE_DECL)
   4049     ;
   4050   /* Look up the name.  */
   4051   else
   4052     {
   4053       if (decl == error_mark_node)
   4054 	{
   4055 	  /* Name lookup failed.  */
   4056 	  if (scope
   4057 	      && (!TYPE_P (scope)
   4058 		  || (!dependent_type_p (scope)
   4059 		      && !(identifier_p (id_expression)
   4060 			   && IDENTIFIER_CONV_OP_P (id_expression)
   4061 			   && dependent_type_p (TREE_TYPE (id_expression))))))
   4062 	    {
   4063 	      /* If the qualifying type is non-dependent (and the name
   4064 		 does not name a conversion operator to a dependent
   4065 		 type), issue an error.  */
   4066 	      qualified_name_lookup_error (scope, id_expression, decl, location);
   4067 	      return error_mark_node;
   4068 	    }
   4069 	  else if (!scope)
   4070 	    {
   4071 	      /* It may be resolved via Koenig lookup.  */
   4072 	      *idk = CP_ID_KIND_UNQUALIFIED;
   4073 	      return id_expression;
   4074 	    }
   4075 	  else
   4076 	    decl = id_expression;
   4077 	}
   4078 
   4079       /* Remember that the name was used in the definition of
   4080 	 the current class so that we can check later to see if
   4081 	 the meaning would have been different after the class
   4082 	 was entirely defined.  */
   4083       if (!scope && decl != error_mark_node && identifier_p (id_expression))
   4084 	maybe_note_name_used_in_class (id_expression, decl);
   4085 
   4086       /* A use in unevaluated operand might not be instantiated appropriately
   4087 	 if tsubst_copy builds a dummy parm, or if we never instantiate a
   4088 	 generic lambda, so mark it now.  */
   4089       if (processing_template_decl && cp_unevaluated_operand)
   4090 	mark_type_use (decl);
   4091 
   4092       /* Disallow uses of local variables from containing functions, except
   4093 	 within lambda-expressions.  */
   4094       if (outer_automatic_var_p (decl))
   4095 	{
   4096 	  decl = process_outer_var_ref (decl, tf_warning_or_error);
   4097 	  if (decl == error_mark_node)
   4098 	    return error_mark_node;
   4099 	}
   4100 
   4101       /* Also disallow uses of function parameters outside the function
   4102 	 body, except inside an unevaluated context (i.e. decltype).  */
   4103       if (TREE_CODE (decl) == PARM_DECL
   4104 	  && DECL_CONTEXT (decl) == NULL_TREE
   4105 	  && !cp_unevaluated_operand)
   4106 	{
   4107 	  *error_msg = G_("use of parameter outside function body");
   4108 	  return error_mark_node;
   4109 	}
   4110     }
   4111 
   4112   /* If we didn't find anything, or what we found was a type,
   4113      then this wasn't really an id-expression.  */
   4114   if (TREE_CODE (decl) == TEMPLATE_DECL
   4115       && !DECL_FUNCTION_TEMPLATE_P (decl))
   4116     {
   4117       *error_msg = G_("missing template arguments");
   4118       return error_mark_node;
   4119     }
   4120   else if (TREE_CODE (decl) == TYPE_DECL
   4121 	   || TREE_CODE (decl) == NAMESPACE_DECL)
   4122     {
   4123       *error_msg = G_("expected primary-expression");
   4124       return error_mark_node;
   4125     }
   4126 
   4127   /* If the name resolved to a template parameter, there is no
   4128      need to look it up again later.  */
   4129   if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
   4130       || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
   4131     {
   4132       tree r;
   4133 
   4134       *idk = CP_ID_KIND_NONE;
   4135       if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
   4136 	decl = TEMPLATE_PARM_DECL (decl);
   4137       r = DECL_INITIAL (decl);
   4138       if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
   4139 	{
   4140 	  /* If the entity is a template parameter object for a template
   4141 	     parameter of type T, the type of the expression is const T.  */
   4142 	  tree ctype = TREE_TYPE (r);
   4143 	  ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
   4144 						   | TYPE_QUAL_CONST));
   4145 	  r = build1 (VIEW_CONVERT_EXPR, ctype, r);
   4146 	}
   4147       r = convert_from_reference (r);
   4148       if (integral_constant_expression_p
   4149 	  && !dependent_type_p (TREE_TYPE (decl))
   4150 	  && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
   4151 	{
   4152 	  if (!allow_non_integral_constant_expression_p)
   4153 	    error ("template parameter %qD of type %qT is not allowed in "
   4154 		   "an integral constant expression because it is not of "
   4155 		   "integral or enumeration type", decl, TREE_TYPE (decl));
   4156 	  *non_integral_constant_expression_p = true;
   4157 	}
   4158       return r;
   4159     }
   4160   else
   4161     {
   4162       bool dependent_p = type_dependent_expression_p (decl);
   4163 
   4164       /* If the declaration was explicitly qualified indicate
   4165 	 that.  The semantics of `A::f(3)' are different than
   4166 	 `f(3)' if `f' is virtual.  */
   4167       *idk = (scope
   4168 	      ? CP_ID_KIND_QUALIFIED
   4169 	      : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
   4170 		 ? CP_ID_KIND_TEMPLATE_ID
   4171 		 : (dependent_p
   4172 		    ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
   4173 		    : CP_ID_KIND_UNQUALIFIED)));
   4174 
   4175       if (dependent_p
   4176 	  && !scope
   4177 	  && DECL_P (decl)
   4178 	  && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
   4179 	/* Dependent type attributes on the decl mean that the TREE_TYPE is
   4180 	   wrong, so just return the identifier.  */
   4181 	return id_expression;
   4182 
   4183       if (DECL_CLASS_TEMPLATE_P (decl))
   4184 	{
   4185 	  error ("use of class template %qT as expression", decl);
   4186 	  return error_mark_node;
   4187 	}
   4188 
   4189       if (TREE_CODE (decl) == TREE_LIST)
   4190 	{
   4191 	  /* Ambiguous reference to base members.  */
   4192 	  error ("request for member %qD is ambiguous in "
   4193 		 "multiple inheritance lattice", id_expression);
   4194 	  print_candidates (decl);
   4195 	  return error_mark_node;
   4196 	}
   4197 
   4198       /* Mark variable-like entities as used.  Functions are similarly
   4199 	 marked either below or after overload resolution.  */
   4200       if ((VAR_P (decl)
   4201 	   || TREE_CODE (decl) == PARM_DECL
   4202 	   || TREE_CODE (decl) == CONST_DECL
   4203 	   || TREE_CODE (decl) == RESULT_DECL)
   4204 	  && !mark_used (decl))
   4205 	return error_mark_node;
   4206 
   4207       /* Only certain kinds of names are allowed in constant
   4208 	 expression.  Template parameters have already
   4209 	 been handled above.  */
   4210       if (! error_operand_p (decl)
   4211 	  && !dependent_p
   4212 	  && integral_constant_expression_p
   4213 	  && !decl_constant_var_p (decl)
   4214 	  && TREE_CODE (decl) != CONST_DECL
   4215 	  && !builtin_valid_in_constant_expr_p (decl)
   4216 	  && !concept_check_p (decl))
   4217 	{
   4218 	  if (!allow_non_integral_constant_expression_p)
   4219 	    {
   4220 	      error ("%qD cannot appear in a constant-expression", decl);
   4221 	      return error_mark_node;
   4222 	    }
   4223 	  *non_integral_constant_expression_p = true;
   4224 	}
   4225 
   4226       if (tree wrap = maybe_get_tls_wrapper_call (decl))
   4227 	/* Replace an evaluated use of the thread_local variable with
   4228 	   a call to its wrapper.  */
   4229 	decl = wrap;
   4230       else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
   4231 	       && !dependent_p
   4232 	       && variable_template_p (TREE_OPERAND (decl, 0))
   4233 	       && !concept_check_p (decl))
   4234 	{
   4235 	  decl = finish_template_variable (decl);
   4236 	  mark_used (decl);
   4237 	  decl = convert_from_reference (decl);
   4238 	}
   4239       else if (concept_check_p (decl))
   4240 	{
   4241 	  /* Nothing more to do. All of the analysis for concept checks
   4242 	     is done by build_conept_id, called from the parser.  */
   4243 	}
   4244       else if (scope)
   4245 	{
   4246 	  if (TREE_CODE (decl) == SCOPE_REF)
   4247 	    {
   4248 	      gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
   4249 	      decl = TREE_OPERAND (decl, 1);
   4250 	    }
   4251 
   4252 	  decl = (adjust_result_of_qualified_name_lookup
   4253 		  (decl, scope, current_nonlambda_class_type()));
   4254 
   4255 	  cp_warn_deprecated_use_scopes (scope);
   4256 
   4257 	  if (TYPE_P (scope))
   4258 	    decl = finish_qualified_id_expr (scope,
   4259 					     decl,
   4260 					     done,
   4261 					     address_p,
   4262 					     template_p,
   4263 					     template_arg_p,
   4264 					     tf_warning_or_error);
   4265 	  else
   4266 	    decl = convert_from_reference (decl);
   4267 	}
   4268       else if (TREE_CODE (decl) == FIELD_DECL)
   4269 	{
   4270 	  /* Since SCOPE is NULL here, this is an unqualified name.
   4271 	     Access checking has been performed during name lookup
   4272 	     already.  Turn off checking to avoid duplicate errors.  */
   4273 	  push_deferring_access_checks (dk_no_check);
   4274 	  decl = finish_non_static_data_member (decl, NULL_TREE,
   4275 						/*qualifying_scope=*/NULL_TREE);
   4276 	  pop_deferring_access_checks ();
   4277 	}
   4278       else if (is_overloaded_fn (decl))
   4279 	{
   4280 	  /* We only need to look at the first function,
   4281 	     because all the fns share the attribute we're
   4282 	     concerned with (all member fns or all non-members).  */
   4283 	  tree first_fn = get_first_fn (decl);
   4284 	  first_fn = STRIP_TEMPLATE (first_fn);
   4285 
   4286 	  if (!template_arg_p
   4287 	      && (TREE_CODE (first_fn) == USING_DECL
   4288 		  || (TREE_CODE (first_fn) == FUNCTION_DECL
   4289 		      && DECL_FUNCTION_MEMBER_P (first_fn)
   4290 		      && !shared_member_p (decl))))
   4291 	    {
   4292 	      /* A set of member functions.  */
   4293 	      decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
   4294 	      return finish_class_member_access_expr (decl, id_expression,
   4295 						      /*template_p=*/false,
   4296 						      tf_warning_or_error);
   4297 	    }
   4298 
   4299 	  decl = baselink_for_fns (decl);
   4300 	}
   4301       else
   4302 	{
   4303 	  if (DECL_P (decl) && DECL_NONLOCAL (decl)
   4304 	      && DECL_CLASS_SCOPE_P (decl))
   4305 	    {
   4306 	      tree context = context_for_name_lookup (decl);
   4307 	      if (context != current_class_type)
   4308 		{
   4309 		  tree path = currently_open_derived_class (context);
   4310 		  if (!path)
   4311 		    /* PATH can be null for using an enum of an unrelated
   4312 		       class; we checked its access in lookup_using_decl.
   4313 
   4314 		       ??? Should this case make a clone instead, like
   4315 		       handle_using_decl?  */
   4316 		    gcc_assert (TREE_CODE (decl) == CONST_DECL);
   4317 		  else
   4318 		    perform_or_defer_access_check (TYPE_BINFO (path),
   4319 						   decl, decl,
   4320 						   tf_warning_or_error);
   4321 		}
   4322 	    }
   4323 
   4324 	  decl = convert_from_reference (decl);
   4325 	}
   4326     }
   4327 
   4328   return cp_expr (decl, location);
   4329 }
   4330 
   4331 /* As per finish_id_expression_1, but adding a wrapper node
   4332    around the result if needed to express LOCATION.  */
   4333 
   4334 cp_expr
   4335 finish_id_expression (tree id_expression,
   4336 		      tree decl,
   4337 		      tree scope,
   4338 		      cp_id_kind *idk,
   4339 		      bool integral_constant_expression_p,
   4340 		      bool allow_non_integral_constant_expression_p,
   4341 		      bool *non_integral_constant_expression_p,
   4342 		      bool template_p,
   4343 		      bool done,
   4344 		      bool address_p,
   4345 		      bool template_arg_p,
   4346 		      const char **error_msg,
   4347 		      location_t location)
   4348 {
   4349   cp_expr result
   4350     = finish_id_expression_1 (id_expression, decl, scope, idk,
   4351 			      integral_constant_expression_p,
   4352 			      allow_non_integral_constant_expression_p,
   4353 			      non_integral_constant_expression_p,
   4354 			      template_p, done, address_p, template_arg_p,
   4355 			      error_msg, location);
   4356   return result.maybe_add_location_wrapper ();
   4357 }
   4358 
   4359 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
   4360    use as a type-specifier.  */
   4361 
   4362 tree
   4363 finish_typeof (tree expr)
   4364 {
   4365   tree type;
   4366 
   4367   if (type_dependent_expression_p (expr))
   4368     {
   4369       type = cxx_make_type (TYPEOF_TYPE);
   4370       TYPEOF_TYPE_EXPR (type) = expr;
   4371       SET_TYPE_STRUCTURAL_EQUALITY (type);
   4372 
   4373       return type;
   4374     }
   4375 
   4376   expr = mark_type_use (expr);
   4377 
   4378   type = unlowered_expr_type (expr);
   4379 
   4380   if (!type || type == unknown_type_node)
   4381     {
   4382       error ("type of %qE is unknown", expr);
   4383       return error_mark_node;
   4384     }
   4385 
   4386   return type;
   4387 }
   4388 
   4389 /* Implement the __underlying_type keyword: Return the underlying
   4390    type of TYPE, suitable for use as a type-specifier.  */
   4391 
   4392 tree
   4393 finish_underlying_type (tree type)
   4394 {
   4395   tree underlying_type;
   4396 
   4397   if (processing_template_decl)
   4398     {
   4399       underlying_type = cxx_make_type (UNDERLYING_TYPE);
   4400       UNDERLYING_TYPE_TYPE (underlying_type) = type;
   4401       SET_TYPE_STRUCTURAL_EQUALITY (underlying_type);
   4402 
   4403       return underlying_type;
   4404     }
   4405 
   4406   if (!complete_type_or_else (type, NULL_TREE))
   4407     return error_mark_node;
   4408 
   4409   if (TREE_CODE (type) != ENUMERAL_TYPE)
   4410     {
   4411       error ("%qT is not an enumeration type", type);
   4412       return error_mark_node;
   4413     }
   4414 
   4415   underlying_type = ENUM_UNDERLYING_TYPE (type);
   4416 
   4417   /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
   4418      includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
   4419      See finish_enum_value_list for details.  */
   4420   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
   4421     underlying_type
   4422       = c_common_type_for_mode (TYPE_MODE (underlying_type),
   4423 				TYPE_UNSIGNED (underlying_type));
   4424 
   4425   return underlying_type;
   4426 }
   4427 
   4428 /* Implement the __direct_bases keyword: Return the direct base classes
   4429    of type.  */
   4430 
   4431 tree
   4432 calculate_direct_bases (tree type, tsubst_flags_t complain)
   4433 {
   4434   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
   4435       || !NON_UNION_CLASS_TYPE_P (type))
   4436     return make_tree_vec (0);
   4437 
   4438   releasing_vec vector;
   4439   vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
   4440   tree binfo;
   4441   unsigned i;
   4442 
   4443   /* Virtual bases are initialized first */
   4444   for (i = 0; base_binfos->iterate (i, &binfo); i++)
   4445     if (BINFO_VIRTUAL_P (binfo))
   4446       vec_safe_push (vector, binfo);
   4447 
   4448   /* Now non-virtuals */
   4449   for (i = 0; base_binfos->iterate (i, &binfo); i++)
   4450     if (!BINFO_VIRTUAL_P (binfo))
   4451       vec_safe_push (vector, binfo);
   4452 
   4453   tree bases_vec = make_tree_vec (vector->length ());
   4454 
   4455   for (i = 0; i < vector->length (); ++i)
   4456     TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
   4457 
   4458   return bases_vec;
   4459 }
   4460 
   4461 /* Implement the __bases keyword: Return the base classes
   4462    of type */
   4463 
   4464 /* Find morally non-virtual base classes by walking binfo hierarchy */
   4465 /* Virtual base classes are handled separately in finish_bases */
   4466 
   4467 static tree
   4468 dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
   4469 {
   4470   /* Don't walk bases of virtual bases */
   4471   return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
   4472 }
   4473 
   4474 static tree
   4475 dfs_calculate_bases_post (tree binfo, void *data_)
   4476 {
   4477   vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
   4478   if (!BINFO_VIRTUAL_P (binfo))
   4479     vec_safe_push (*data, BINFO_TYPE (binfo));
   4480   return NULL_TREE;
   4481 }
   4482 
   4483 /* Calculates the morally non-virtual base classes of a class */
   4484 static vec<tree, va_gc> *
   4485 calculate_bases_helper (tree type)
   4486 {
   4487   vec<tree, va_gc> *vector = make_tree_vector ();
   4488 
   4489   /* Now add non-virtual base classes in order of construction */
   4490   if (TYPE_BINFO (type))
   4491     dfs_walk_all (TYPE_BINFO (type),
   4492 		  dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
   4493   return vector;
   4494 }
   4495 
   4496 tree
   4497 calculate_bases (tree type, tsubst_flags_t complain)
   4498 {
   4499   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
   4500       || !NON_UNION_CLASS_TYPE_P (type))
   4501     return make_tree_vec (0);
   4502 
   4503   releasing_vec vector;
   4504   tree bases_vec = NULL_TREE;
   4505   unsigned i;
   4506   vec<tree, va_gc> *vbases;
   4507   tree binfo;
   4508 
   4509   /* First go through virtual base classes */
   4510   for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
   4511        vec_safe_iterate (vbases, i, &binfo); i++)
   4512     {
   4513       releasing_vec vbase_bases
   4514 	= calculate_bases_helper (BINFO_TYPE (binfo));
   4515       vec_safe_splice (vector, vbase_bases);
   4516     }
   4517 
   4518   /* Now for the non-virtual bases */
   4519   releasing_vec nonvbases = calculate_bases_helper (type);
   4520   vec_safe_splice (vector, nonvbases);
   4521 
   4522   /* Note that during error recovery vector->length can even be zero.  */
   4523   if (vector->length () > 1)
   4524     {
   4525       /* Last element is entire class, so don't copy */
   4526       bases_vec = make_tree_vec (vector->length () - 1);
   4527 
   4528       for (i = 0; i < vector->length () - 1; ++i)
   4529 	TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
   4530     }
   4531   else
   4532     bases_vec = make_tree_vec (0);
   4533 
   4534   return bases_vec;
   4535 }
   4536 
   4537 tree
   4538 finish_bases (tree type, bool direct)
   4539 {
   4540   tree bases = NULL_TREE;
   4541 
   4542   if (!processing_template_decl)
   4543     {
   4544       /* Parameter packs can only be used in templates */
   4545       error ("parameter pack %<__bases%> only valid in template declaration");
   4546       return error_mark_node;
   4547     }
   4548 
   4549   bases = cxx_make_type (BASES);
   4550   BASES_TYPE (bases) = type;
   4551   BASES_DIRECT (bases) = direct;
   4552   SET_TYPE_STRUCTURAL_EQUALITY (bases);
   4553 
   4554   return bases;
   4555 }
   4556 
   4557 /* Perform C++-specific checks for __builtin_offsetof before calling
   4558    fold_offsetof.  */
   4559 
   4560 tree
   4561 finish_offsetof (tree object_ptr, tree expr, location_t loc)
   4562 {
   4563   /* If we're processing a template, we can't finish the semantics yet.
   4564      Otherwise we can fold the entire expression now.  */
   4565   if (processing_template_decl)
   4566     {
   4567       expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
   4568       SET_EXPR_LOCATION (expr, loc);
   4569       return expr;
   4570     }
   4571 
   4572   if (expr == error_mark_node)
   4573     return error_mark_node;
   4574 
   4575   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
   4576     {
   4577       error ("cannot apply %<offsetof%> to destructor %<~%T%>",
   4578 	      TREE_OPERAND (expr, 2));
   4579       return error_mark_node;
   4580     }
   4581   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
   4582       || TREE_TYPE (expr) == unknown_type_node)
   4583     {
   4584       while (TREE_CODE (expr) == COMPONENT_REF
   4585 	     || TREE_CODE (expr) == COMPOUND_EXPR)
   4586 	expr = TREE_OPERAND (expr, 1);
   4587 
   4588       if (DECL_P (expr))
   4589 	{
   4590 	  error ("cannot apply %<offsetof%> to member function %qD", expr);
   4591 	  inform (DECL_SOURCE_LOCATION (expr), "declared here");
   4592 	}
   4593       else
   4594 	error ("cannot apply %<offsetof%> to member function");
   4595       return error_mark_node;
   4596     }
   4597   if (TREE_CODE (expr) == CONST_DECL)
   4598     {
   4599       error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
   4600       return error_mark_node;
   4601     }
   4602   if (REFERENCE_REF_P (expr))
   4603     expr = TREE_OPERAND (expr, 0);
   4604   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
   4605     return error_mark_node;
   4606   if (warn_invalid_offsetof
   4607       && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
   4608       && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
   4609       && cp_unevaluated_operand == 0)
   4610     warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
   4611 		"non-standard-layout type %qT is conditionally-supported",
   4612 		TREE_TYPE (TREE_TYPE (object_ptr)));
   4613   return fold_offsetof (expr);
   4614 }
   4615 
   4616 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR.  This
   4617    function is broken out from the above for the benefit of the tree-ssa
   4618    project.  */
   4619 
   4620 void
   4621 simplify_aggr_init_expr (tree *tp)
   4622 {
   4623   tree aggr_init_expr = *tp;
   4624 
   4625   /* Form an appropriate CALL_EXPR.  */
   4626   tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
   4627   tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
   4628   tree type = TREE_TYPE (slot);
   4629 
   4630   tree call_expr;
   4631   enum style_t { ctor, arg, pcc } style;
   4632 
   4633   if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
   4634     style = ctor;
   4635 #ifdef PCC_STATIC_STRUCT_RETURN
   4636   else if (1)
   4637     style = pcc;
   4638 #endif
   4639   else
   4640     {
   4641       gcc_assert (TREE_ADDRESSABLE (type));
   4642       style = arg;
   4643     }
   4644 
   4645   call_expr = build_call_array_loc (input_location,
   4646 				    TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
   4647 				    fn,
   4648 				    aggr_init_expr_nargs (aggr_init_expr),
   4649 				    AGGR_INIT_EXPR_ARGP (aggr_init_expr));
   4650   TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
   4651   CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
   4652   CALL_EXPR_OPERATOR_SYNTAX (call_expr)
   4653     = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
   4654   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
   4655   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
   4656 
   4657   if (style == ctor)
   4658     {
   4659       /* Replace the first argument to the ctor with the address of the
   4660 	 slot.  */
   4661       cxx_mark_addressable (slot);
   4662       CALL_EXPR_ARG (call_expr, 0) =
   4663 	build1 (ADDR_EXPR, build_pointer_type (type), slot);
   4664     }
   4665   else if (style == arg)
   4666     {
   4667       /* Just mark it addressable here, and leave the rest to
   4668 	 expand_call{,_inline}.  */
   4669       cxx_mark_addressable (slot);
   4670       CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
   4671       call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr);
   4672     }
   4673   else if (style == pcc)
   4674     {
   4675       /* If we're using the non-reentrant PCC calling convention, then we
   4676 	 need to copy the returned value out of the static buffer into the
   4677 	 SLOT.  */
   4678       push_deferring_access_checks (dk_no_check);
   4679       call_expr = build_aggr_init (slot, call_expr,
   4680 				   DIRECT_BIND | LOOKUP_ONLYCONVERTING,
   4681                                    tf_warning_or_error);
   4682       pop_deferring_access_checks ();
   4683       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
   4684     }
   4685 
   4686   if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
   4687     {
   4688       tree init = build_zero_init (type, NULL_TREE,
   4689 				   /*static_storage_p=*/false);
   4690       init = build2 (INIT_EXPR, void_type_node, slot, init);
   4691       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
   4692 			  init, call_expr);
   4693     }
   4694 
   4695   *tp = call_expr;
   4696 }
   4697 
   4698 /* Emit all thunks to FN that should be emitted when FN is emitted.  */
   4699 
   4700 void
   4701 emit_associated_thunks (tree fn)
   4702 {
   4703   /* When we use vcall offsets, we emit thunks with the virtual
   4704      functions to which they thunk. The whole point of vcall offsets
   4705      is so that you can know statically the entire set of thunks that
   4706      will ever be needed for a given virtual function, thereby
   4707      enabling you to output all the thunks with the function itself.  */
   4708   if (DECL_VIRTUAL_P (fn)
   4709       /* Do not emit thunks for extern template instantiations.  */
   4710       && ! DECL_REALLY_EXTERN (fn)
   4711       /* Do not emit thunks for tentative decls, those will be processed
   4712 	 again at_eof if really needed.  */
   4713       && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
   4714     {
   4715       tree thunk;
   4716 
   4717       for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
   4718 	{
   4719 	  if (!THUNK_ALIAS (thunk))
   4720 	    {
   4721 	      use_thunk (thunk, /*emit_p=*/1);
   4722 	      if (DECL_RESULT_THUNK_P (thunk))
   4723 		{
   4724 		  tree probe;
   4725 
   4726 		  for (probe = DECL_THUNKS (thunk);
   4727 		       probe; probe = DECL_CHAIN (probe))
   4728 		    use_thunk (probe, /*emit_p=*/1);
   4729 		}
   4730 	    }
   4731 	  else
   4732 	    gcc_assert (!DECL_THUNKS (thunk));
   4733 	}
   4734     }
   4735 }
   4736 
   4737 /* Generate RTL for FN.  */
   4738 
   4739 bool
   4740 expand_or_defer_fn_1 (tree fn)
   4741 {
   4742   /* When the parser calls us after finishing the body of a template
   4743      function, we don't really want to expand the body.  */
   4744   if (processing_template_decl)
   4745     {
   4746       /* Normally, collection only occurs in rest_of_compilation.  So,
   4747 	 if we don't collect here, we never collect junk generated
   4748 	 during the processing of templates until we hit a
   4749 	 non-template function.  It's not safe to do this inside a
   4750 	 nested class, though, as the parser may have local state that
   4751 	 is not a GC root.  */
   4752       if (!function_depth)
   4753 	ggc_collect ();
   4754       return false;
   4755     }
   4756 
   4757   gcc_assert (DECL_SAVED_TREE (fn));
   4758 
   4759   /* We make a decision about linkage for these functions at the end
   4760      of the compilation.  Until that point, we do not want the back
   4761      end to output them -- but we do want it to see the bodies of
   4762      these functions so that it can inline them as appropriate.  */
   4763   if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
   4764     {
   4765       if (DECL_INTERFACE_KNOWN (fn))
   4766 	/* We've already made a decision as to how this function will
   4767 	   be handled.  */;
   4768       else if (!at_eof
   4769 	       || DECL_IMMEDIATE_FUNCTION_P (fn)
   4770 	       || DECL_OMP_DECLARE_REDUCTION_P (fn))
   4771 	tentative_decl_linkage (fn);
   4772       else
   4773 	import_export_decl (fn);
   4774 
   4775       /* If the user wants us to keep all inline functions, then mark
   4776 	 this function as needed so that finish_file will make sure to
   4777 	 output it later.  Similarly, all dllexport'd functions must
   4778 	 be emitted; there may be callers in other DLLs.  */
   4779       if (DECL_DECLARED_INLINE_P (fn)
   4780 	  && !DECL_REALLY_EXTERN (fn)
   4781 	  && !DECL_IMMEDIATE_FUNCTION_P (fn)
   4782 	  && !DECL_OMP_DECLARE_REDUCTION_P (fn)
   4783 	  && (flag_keep_inline_functions
   4784 	      || (flag_keep_inline_dllexport
   4785 		  && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
   4786 	{
   4787 	  mark_needed (fn);
   4788 	  DECL_EXTERNAL (fn) = 0;
   4789 	}
   4790     }
   4791 
   4792   /* If this is a constructor or destructor body, we have to clone
   4793      it.  */
   4794   if (maybe_clone_body (fn))
   4795     {
   4796       /* We don't want to process FN again, so pretend we've written
   4797 	 it out, even though we haven't.  */
   4798       TREE_ASM_WRITTEN (fn) = 1;
   4799       /* If this is a constexpr function, keep DECL_SAVED_TREE.  */
   4800       if (!DECL_DECLARED_CONSTEXPR_P (fn)
   4801 	  && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
   4802 	DECL_SAVED_TREE (fn) = NULL_TREE;
   4803       return false;
   4804     }
   4805 
   4806   /* There's no reason to do any of the work here if we're only doing
   4807      semantic analysis; this code just generates RTL.  */
   4808   if (flag_syntax_only)
   4809     {
   4810       /* Pretend that this function has been written out so that we don't try
   4811 	 to expand it again.  */
   4812       TREE_ASM_WRITTEN (fn) = 1;
   4813       return false;
   4814     }
   4815 
   4816   if (DECL_OMP_DECLARE_REDUCTION_P (fn))
   4817     return false;
   4818 
   4819   return true;
   4820 }
   4821 
   4822 void
   4823 expand_or_defer_fn (tree fn)
   4824 {
   4825   if (expand_or_defer_fn_1 (fn))
   4826     {
   4827       function_depth++;
   4828 
   4829       /* Expand or defer, at the whim of the compilation unit manager.  */
   4830       cgraph_node::finalize_function (fn, function_depth > 1);
   4831       emit_associated_thunks (fn);
   4832 
   4833       function_depth--;
   4834 
   4835       if (DECL_IMMEDIATE_FUNCTION_P (fn))
   4836 	{
   4837 	  if (cgraph_node *node = cgraph_node::get (fn))
   4838 	    {
   4839 	      node->body_removed = true;
   4840 	      node->analyzed = false;
   4841 	      node->definition = false;
   4842 	      node->force_output = false;
   4843 	    }
   4844 	}
   4845     }
   4846 }
   4847 
   4848 class nrv_data
   4849 {
   4850 public:
   4851   nrv_data () : visited (37) {}
   4852 
   4853   tree var;
   4854   tree result;
   4855   hash_table<nofree_ptr_hash <tree_node> > visited;
   4856   bool in_nrv_cleanup;
   4857 };
   4858 
   4859 /* Helper function for walk_tree, used by finalize_nrv below.  */
   4860 
   4861 static tree
   4862 finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
   4863 {
   4864   class nrv_data *dp = (class nrv_data *)data;
   4865   tree_node **slot;
   4866 
   4867   /* No need to walk into types.  There wouldn't be any need to walk into
   4868      non-statements, except that we have to consider STMT_EXPRs.  */
   4869   if (TYPE_P (*tp))
   4870     *walk_subtrees = 0;
   4871   /* Change all returns to just refer to the RESULT_DECL; this is a nop,
   4872      but differs from using NULL_TREE in that it indicates that we care
   4873      about the value of the RESULT_DECL.  But preserve anything appended
   4874      by check_return_expr.  */
   4875   else if (TREE_CODE (*tp) == RETURN_EXPR)
   4876     {
   4877       tree *p = &TREE_OPERAND (*tp, 0);
   4878       while (TREE_CODE (*p) == COMPOUND_EXPR)
   4879 	p = &TREE_OPERAND (*p, 0);
   4880       gcc_checking_assert (TREE_CODE (*p) == INIT_EXPR
   4881 			   && TREE_OPERAND (*p, 0) == dp->result);
   4882       *p = dp->result;
   4883     }
   4884   /* Change all cleanups for the NRV to only run when an exception is
   4885      thrown.  */
   4886   else if (TREE_CODE (*tp) == CLEANUP_STMT
   4887 	   && CLEANUP_DECL (*tp) == dp->var)
   4888     {
   4889       dp->in_nrv_cleanup = true;
   4890       cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
   4891       dp->in_nrv_cleanup = false;
   4892       cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
   4893       *walk_subtrees = 0;
   4894 
   4895       CLEANUP_EH_ONLY (*tp) = true;
   4896 
   4897       /* If a cleanup might throw, we need to clear current_retval_sentinel on
   4898 	 the exception path so an outer cleanup added by
   4899 	 maybe_splice_retval_cleanup doesn't run.  */
   4900       if (current_retval_sentinel
   4901 	  && cp_function_chain->throwing_cleanup)
   4902 	{
   4903 	  tree clear = build2 (MODIFY_EXPR, boolean_type_node,
   4904 			       current_retval_sentinel,
   4905 			       boolean_false_node);
   4906 
   4907 	  /* We're already only on the EH path, just prepend it.  */
   4908 	  tree &exp = CLEANUP_EXPR (*tp);
   4909 	  exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
   4910 	}
   4911     }
   4912   /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
   4913      want to destroy the retval before the variable goes out of scope.  */
   4914   else if (TREE_CODE (*tp) == CLEANUP_STMT
   4915 	   && dp->in_nrv_cleanup
   4916 	   && CLEANUP_DECL (*tp) == dp->result)
   4917     CLEANUP_EXPR (*tp) = void_node;
   4918   /* Replace the DECL_EXPR for the NRV with an initialization of the
   4919      RESULT_DECL, if needed.  */
   4920   else if (TREE_CODE (*tp) == DECL_EXPR
   4921 	   && DECL_EXPR_DECL (*tp) == dp->var)
   4922     {
   4923       tree init;
   4924       if (DECL_INITIAL (dp->var)
   4925 	  && DECL_INITIAL (dp->var) != error_mark_node)
   4926 	init = build2 (INIT_EXPR, void_type_node, dp->result,
   4927 		       DECL_INITIAL (dp->var));
   4928       else
   4929 	init = build_empty_stmt (EXPR_LOCATION (*tp));
   4930       DECL_INITIAL (dp->var) = NULL_TREE;
   4931       SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
   4932       *tp = init;
   4933     }
   4934   /* And replace all uses of the NRV with the RESULT_DECL.  */
   4935   else if (*tp == dp->var)
   4936     *tp = dp->result;
   4937 
   4938   /* Avoid walking into the same tree more than once.  Unfortunately, we
   4939      can't just use walk_tree_without duplicates because it would only call
   4940      us for the first occurrence of dp->var in the function body.  */
   4941   slot = dp->visited.find_slot (*tp, INSERT);
   4942   if (*slot)
   4943     *walk_subtrees = 0;
   4944   else
   4945     *slot = *tp;
   4946 
   4947   /* Keep iterating.  */
   4948   return NULL_TREE;
   4949 }
   4950 
   4951 /* Called from finish_function to implement the named return value
   4952    optimization by overriding all the RETURN_EXPRs and pertinent
   4953    CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
   4954    RESULT_DECL for the function.  */
   4955 
   4956 void
   4957 finalize_nrv (tree *tp, tree var, tree result)
   4958 {
   4959   class nrv_data data;
   4960 
   4961   /* Copy name from VAR to RESULT.  */
   4962   DECL_NAME (result) = DECL_NAME (var);
   4963   /* Don't forget that we take its address.  */
   4964   TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
   4965   /* Finally set DECL_VALUE_EXPR to avoid assigning
   4966      a stack slot at -O0 for the original var and debug info
   4967      uses RESULT location for VAR.  */
   4968   SET_DECL_VALUE_EXPR (var, result);
   4969   DECL_HAS_VALUE_EXPR_P (var) = 1;
   4970 
   4971   data.var = var;
   4972   data.result = result;
   4973   data.in_nrv_cleanup = false;
   4974   cp_walk_tree (tp, finalize_nrv_r, &data, 0);
   4975 }
   4976 
   4977 /* Create CP_OMP_CLAUSE_INFO for clause C.  Returns true if it is invalid.  */
   4979 
   4980 bool
   4981 cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
   4982 			    bool need_copy_ctor, bool need_copy_assignment,
   4983 			    bool need_dtor)
   4984 {
   4985   int save_errorcount = errorcount;
   4986   tree info, t;
   4987 
   4988   /* Always allocate 3 elements for simplicity.  These are the
   4989      function decls for the ctor, dtor, and assignment op.
   4990      This layout is known to the three lang hooks,
   4991      cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
   4992      and cxx_omp_clause_assign_op.  */
   4993   info = make_tree_vec (3);
   4994   CP_OMP_CLAUSE_INFO (c) = info;
   4995 
   4996   if (need_default_ctor || need_copy_ctor)
   4997     {
   4998       if (need_default_ctor)
   4999 	t = get_default_ctor (type);
   5000       else
   5001 	t = get_copy_ctor (type, tf_warning_or_error);
   5002 
   5003       if (t && !trivial_fn_p (t))
   5004 	TREE_VEC_ELT (info, 0) = t;
   5005     }
   5006 
   5007   if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   5008     TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
   5009 
   5010   if (need_copy_assignment)
   5011     {
   5012       t = get_copy_assign (type);
   5013 
   5014       if (t && !trivial_fn_p (t))
   5015 	TREE_VEC_ELT (info, 2) = t;
   5016     }
   5017 
   5018   return errorcount != save_errorcount;
   5019 }
   5020 
   5021 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
   5022    FIELD_DECL, otherwise return DECL itself.  */
   5023 
   5024 static tree
   5025 omp_clause_decl_field (tree decl)
   5026 {
   5027   if (VAR_P (decl)
   5028       && DECL_HAS_VALUE_EXPR_P (decl)
   5029       && DECL_ARTIFICIAL (decl)
   5030       && DECL_LANG_SPECIFIC (decl)
   5031       && DECL_OMP_PRIVATIZED_MEMBER (decl))
   5032     {
   5033       tree f = DECL_VALUE_EXPR (decl);
   5034       if (INDIRECT_REF_P (f))
   5035 	f = TREE_OPERAND (f, 0);
   5036       if (TREE_CODE (f) == COMPONENT_REF)
   5037 	{
   5038 	  f = TREE_OPERAND (f, 1);
   5039 	  gcc_assert (TREE_CODE (f) == FIELD_DECL);
   5040 	  return f;
   5041 	}
   5042     }
   5043   return NULL_TREE;
   5044 }
   5045 
   5046 /* Adjust DECL if needed for printing using %qE.  */
   5047 
   5048 static tree
   5049 omp_clause_printable_decl (tree decl)
   5050 {
   5051   tree t = omp_clause_decl_field (decl);
   5052   if (t)
   5053     return t;
   5054   return decl;
   5055 }
   5056 
   5057 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
   5058    VAR_DECL T that doesn't need a DECL_EXPR added, record it for
   5059    privatization.  */
   5060 
   5061 static void
   5062 omp_note_field_privatization (tree f, tree t)
   5063 {
   5064   if (!omp_private_member_map)
   5065     omp_private_member_map = new hash_map<tree, tree>;
   5066   tree &v = omp_private_member_map->get_or_insert (f);
   5067   if (v == NULL_TREE)
   5068     {
   5069       v = t;
   5070       omp_private_member_vec.safe_push (f);
   5071       /* Signal that we don't want to create DECL_EXPR for this dummy var.  */
   5072       omp_private_member_vec.safe_push (integer_zero_node);
   5073     }
   5074 }
   5075 
   5076 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
   5077    dummy VAR_DECL.  */
   5078 
   5079 tree
   5080 omp_privatize_field (tree t, bool shared)
   5081 {
   5082   tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
   5083   if (m == error_mark_node)
   5084     return error_mark_node;
   5085   if (!omp_private_member_map && !shared)
   5086     omp_private_member_map = new hash_map<tree, tree>;
   5087   if (TYPE_REF_P (TREE_TYPE (t)))
   5088     {
   5089       gcc_assert (INDIRECT_REF_P (m));
   5090       m = TREE_OPERAND (m, 0);
   5091     }
   5092   tree vb = NULL_TREE;
   5093   tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
   5094   if (v == NULL_TREE)
   5095     {
   5096       v = create_temporary_var (TREE_TYPE (m));
   5097       retrofit_lang_decl (v);
   5098       DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
   5099       SET_DECL_VALUE_EXPR (v, m);
   5100       DECL_HAS_VALUE_EXPR_P (v) = 1;
   5101       if (!shared)
   5102 	omp_private_member_vec.safe_push (t);
   5103     }
   5104   return v;
   5105 }
   5106 
   5107 /* Helper function for handle_omp_array_sections.  Called recursively
   5108    to handle multiple array-section-subscripts.  C is the clause,
   5109    T current expression (initially OMP_CLAUSE_DECL), which is either
   5110    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
   5111    expression if specified, TREE_VALUE length expression if specified,
   5112    TREE_CHAIN is what it has been specified after, or some decl.
   5113    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
   5114    set to true if any of the array-section-subscript could have length
   5115    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
   5116    first array-section-subscript which is known not to have length
   5117    of one.  Given say:
   5118    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
   5119    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
   5120    all are or may have length of 1, array-section-subscript [:2] is the
   5121    first one known not to have length 1.  For array-section-subscript
   5122    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
   5123    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
   5124    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
   5125    case though, as some lengths could be zero.  */
   5126 
   5127 static tree
   5128 handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   5129 			     bool &maybe_zero_len, unsigned int &first_non_one,
   5130 			     enum c_omp_region_type ort)
   5131 {
   5132   tree ret, low_bound, length, type;
   5133   if (TREE_CODE (t) != TREE_LIST)
   5134     {
   5135       if (error_operand_p (t))
   5136 	return error_mark_node;
   5137       if (REFERENCE_REF_P (t)
   5138 	  && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
   5139 	t = TREE_OPERAND (t, 0);
   5140       ret = t;
   5141       while (TREE_CODE (t) == INDIRECT_REF)
   5142 	{
   5143 	  t = TREE_OPERAND (t, 0);
   5144 	  STRIP_NOPS (t);
   5145 	  if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   5146 	    t = TREE_OPERAND (t, 0);
   5147 	}
   5148       while (TREE_CODE (t) == COMPOUND_EXPR)
   5149 	{
   5150 	  t = TREE_OPERAND (t, 1);
   5151 	  STRIP_NOPS (t);
   5152 	}
   5153       if (TREE_CODE (t) == COMPONENT_REF
   5154 	  && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   5155 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
   5156 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
   5157 	  && !type_dependent_expression_p (t))
   5158 	{
   5159 	  if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
   5160 	      && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
   5161 	    {
   5162 	      error_at (OMP_CLAUSE_LOCATION (c),
   5163 			"bit-field %qE in %qs clause",
   5164 			t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5165 	      return error_mark_node;
   5166 	    }
   5167 	  while (TREE_CODE (t) == COMPONENT_REF)
   5168 	    {
   5169 	      if (TREE_TYPE (TREE_OPERAND (t, 0))
   5170 		  && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE)
   5171 		{
   5172 		  error_at (OMP_CLAUSE_LOCATION (c),
   5173 			    "%qE is a member of a union", t);
   5174 		  return error_mark_node;
   5175 		}
   5176 	      t = TREE_OPERAND (t, 0);
   5177 	      while (TREE_CODE (t) == MEM_REF
   5178 		     || TREE_CODE (t) == INDIRECT_REF
   5179 		     || TREE_CODE (t) == ARRAY_REF)
   5180 		{
   5181 		  t = TREE_OPERAND (t, 0);
   5182 		  STRIP_NOPS (t);
   5183 		  if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   5184 		    t = TREE_OPERAND (t, 0);
   5185 		}
   5186 	    }
   5187 	  if (REFERENCE_REF_P (t))
   5188 	    t = TREE_OPERAND (t, 0);
   5189 	}
   5190       if (TREE_CODE (t) == FIELD_DECL)
   5191 	ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
   5192       else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   5193 	{
   5194 	  if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   5195 	    return NULL_TREE;
   5196 	  if (DECL_P (t))
   5197 	    error_at (OMP_CLAUSE_LOCATION (c),
   5198 		      "%qD is not a variable in %qs clause", t,
   5199 		      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5200 	  else
   5201 	    error_at (OMP_CLAUSE_LOCATION (c),
   5202 		      "%qE is not a variable in %qs clause", t,
   5203 		      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5204 	  return error_mark_node;
   5205 	}
   5206       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   5207 	       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   5208 	       && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   5209 	{
   5210 	  error_at (OMP_CLAUSE_LOCATION (c),
   5211 		    "%qD is threadprivate variable in %qs clause", t,
   5212 		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5213 	  return error_mark_node;
   5214 	}
   5215       if (type_dependent_expression_p (ret))
   5216 	return NULL_TREE;
   5217       ret = convert_from_reference (ret);
   5218       return ret;
   5219     }
   5220 
   5221   if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
   5222       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5223 	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5224 	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   5225       && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL)
   5226     TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false);
   5227   ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types,
   5228 				     maybe_zero_len, first_non_one, ort);
   5229   if (ret == error_mark_node || ret == NULL_TREE)
   5230     return ret;
   5231 
   5232   type = TREE_TYPE (ret);
   5233   low_bound = TREE_PURPOSE (t);
   5234   length = TREE_VALUE (t);
   5235   if ((low_bound && type_dependent_expression_p (low_bound))
   5236       || (length && type_dependent_expression_p (length)))
   5237     return NULL_TREE;
   5238 
   5239   if (low_bound == error_mark_node || length == error_mark_node)
   5240     return error_mark_node;
   5241 
   5242   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
   5243     {
   5244       error_at (OMP_CLAUSE_LOCATION (c),
   5245 		"low bound %qE of array section does not have integral type",
   5246 		low_bound);
   5247       return error_mark_node;
   5248     }
   5249   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
   5250     {
   5251       error_at (OMP_CLAUSE_LOCATION (c),
   5252 		"length %qE of array section does not have integral type",
   5253 		length);
   5254       return error_mark_node;
   5255     }
   5256   if (low_bound)
   5257     low_bound = mark_rvalue_use (low_bound);
   5258   if (length)
   5259     length = mark_rvalue_use (length);
   5260   /* We need to reduce to real constant-values for checks below.  */
   5261   if (length)
   5262     length = fold_simple (length);
   5263   if (low_bound)
   5264     low_bound = fold_simple (low_bound);
   5265   if (low_bound
   5266       && TREE_CODE (low_bound) == INTEGER_CST
   5267       && TYPE_PRECISION (TREE_TYPE (low_bound))
   5268 	 > TYPE_PRECISION (sizetype))
   5269     low_bound = fold_convert (sizetype, low_bound);
   5270   if (length
   5271       && TREE_CODE (length) == INTEGER_CST
   5272       && TYPE_PRECISION (TREE_TYPE (length))
   5273 	 > TYPE_PRECISION (sizetype))
   5274     length = fold_convert (sizetype, length);
   5275   if (low_bound == NULL_TREE)
   5276     low_bound = integer_zero_node;
   5277 
   5278   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   5279       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   5280 	  || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   5281     {
   5282       if (length != integer_one_node)
   5283 	{
   5284 	  error_at (OMP_CLAUSE_LOCATION (c),
   5285 		    "expected single pointer in %qs clause",
   5286 		    user_omp_clause_code_name (c, ort == C_ORT_ACC));
   5287 	  return error_mark_node;
   5288 	}
   5289     }
   5290   if (length != NULL_TREE)
   5291     {
   5292       if (!integer_nonzerop (length))
   5293 	{
   5294 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   5295 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   5296 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5297 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5298 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   5299 	    {
   5300 	      if (integer_zerop (length))
   5301 		{
   5302 		  error_at (OMP_CLAUSE_LOCATION (c),
   5303 			    "zero length array section in %qs clause",
   5304 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5305 		  return error_mark_node;
   5306 		}
   5307 	    }
   5308 	  else
   5309 	    maybe_zero_len = true;
   5310 	}
   5311       if (first_non_one == types.length ()
   5312 	  && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
   5313 	first_non_one++;
   5314     }
   5315   if (TREE_CODE (type) == ARRAY_TYPE)
   5316     {
   5317       if (length == NULL_TREE
   5318 	  && (TYPE_DOMAIN (type) == NULL_TREE
   5319 	      || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
   5320 	{
   5321 	  error_at (OMP_CLAUSE_LOCATION (c),
   5322 		    "for unknown bound array type length expression must "
   5323 		    "be specified");
   5324 	  return error_mark_node;
   5325 	}
   5326       if (TREE_CODE (low_bound) == INTEGER_CST
   5327 	  && tree_int_cst_sgn (low_bound) == -1)
   5328 	{
   5329 	  error_at (OMP_CLAUSE_LOCATION (c),
   5330 		    "negative low bound in array section in %qs clause",
   5331 		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5332 	  return error_mark_node;
   5333 	}
   5334       if (length != NULL_TREE
   5335 	  && TREE_CODE (length) == INTEGER_CST
   5336 	  && tree_int_cst_sgn (length) == -1)
   5337 	{
   5338 	  error_at (OMP_CLAUSE_LOCATION (c),
   5339 		    "negative length in array section in %qs clause",
   5340 		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5341 	  return error_mark_node;
   5342 	}
   5343       if (TYPE_DOMAIN (type)
   5344 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   5345 	  && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
   5346 			== INTEGER_CST)
   5347 	{
   5348 	  tree size
   5349 	    = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
   5350 	  size = size_binop (PLUS_EXPR, size, size_one_node);
   5351 	  if (TREE_CODE (low_bound) == INTEGER_CST)
   5352 	    {
   5353 	      if (tree_int_cst_lt (size, low_bound))
   5354 		{
   5355 		  error_at (OMP_CLAUSE_LOCATION (c),
   5356 			    "low bound %qE above array section size "
   5357 			    "in %qs clause", low_bound,
   5358 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5359 		  return error_mark_node;
   5360 		}
   5361 	      if (tree_int_cst_equal (size, low_bound))
   5362 		{
   5363 		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   5364 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   5365 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5366 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5367 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   5368 		    {
   5369 		      error_at (OMP_CLAUSE_LOCATION (c),
   5370 				"zero length array section in %qs clause",
   5371 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5372 		      return error_mark_node;
   5373 		    }
   5374 		  maybe_zero_len = true;
   5375 		}
   5376 	      else if (length == NULL_TREE
   5377 		       && first_non_one == types.length ()
   5378 		       && tree_int_cst_equal
   5379 			    (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
   5380 			     low_bound))
   5381 		first_non_one++;
   5382 	    }
   5383 	  else if (length == NULL_TREE)
   5384 	    {
   5385 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   5386 		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   5387 		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   5388 		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   5389 		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   5390 		maybe_zero_len = true;
   5391 	      if (first_non_one == types.length ())
   5392 		first_non_one++;
   5393 	    }
   5394 	  if (length && TREE_CODE (length) == INTEGER_CST)
   5395 	    {
   5396 	      if (tree_int_cst_lt (size, length))
   5397 		{
   5398 		  error_at (OMP_CLAUSE_LOCATION (c),
   5399 			    "length %qE above array section size "
   5400 			    "in %qs clause", length,
   5401 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5402 		  return error_mark_node;
   5403 		}
   5404 	      if (TREE_CODE (low_bound) == INTEGER_CST)
   5405 		{
   5406 		  tree lbpluslen
   5407 		    = size_binop (PLUS_EXPR,
   5408 				  fold_convert (sizetype, low_bound),
   5409 				  fold_convert (sizetype, length));
   5410 		  if (TREE_CODE (lbpluslen) == INTEGER_CST
   5411 		      && tree_int_cst_lt (size, lbpluslen))
   5412 		    {
   5413 		      error_at (OMP_CLAUSE_LOCATION (c),
   5414 				"high bound %qE above array section size "
   5415 				"in %qs clause", lbpluslen,
   5416 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5417 		      return error_mark_node;
   5418 		    }
   5419 		}
   5420 	    }
   5421 	}
   5422       else if (length == NULL_TREE)
   5423 	{
   5424 	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   5425 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   5426 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   5427 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   5428 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   5429 	    maybe_zero_len = true;
   5430 	  if (first_non_one == types.length ())
   5431 	    first_non_one++;
   5432 	}
   5433 
   5434       /* For [lb:] we will need to evaluate lb more than once.  */
   5435       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   5436 	{
   5437 	  tree lb = cp_save_expr (low_bound);
   5438 	  if (lb != low_bound)
   5439 	    {
   5440 	      TREE_PURPOSE (t) = lb;
   5441 	      low_bound = lb;
   5442 	    }
   5443 	}
   5444     }
   5445   else if (TYPE_PTR_P (type))
   5446     {
   5447       if (length == NULL_TREE)
   5448 	{
   5449 	  if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
   5450 	    error_at (OMP_CLAUSE_LOCATION (c),
   5451 		      "for array function parameter length expression "
   5452 		      "must be specified");
   5453 	  else
   5454 	    error_at (OMP_CLAUSE_LOCATION (c),
   5455 		      "for pointer type length expression must be specified");
   5456 	  return error_mark_node;
   5457 	}
   5458       if (length != NULL_TREE
   5459 	  && TREE_CODE (length) == INTEGER_CST
   5460 	  && tree_int_cst_sgn (length) == -1)
   5461 	{
   5462 	  error_at (OMP_CLAUSE_LOCATION (c),
   5463 		    "negative length in array section in %qs clause",
   5464 		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5465 	  return error_mark_node;
   5466 	}
   5467       /* If there is a pointer type anywhere but in the very first
   5468 	 array-section-subscript, the array section could be non-contiguous.  */
   5469       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   5470 	  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   5471 	  && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST)
   5472 	{
   5473 	  /* If any prior dimension has a non-one length, then deem this
   5474 	     array section as non-contiguous.  */
   5475 	  for (tree d = TREE_CHAIN (t); TREE_CODE (d) == TREE_LIST;
   5476 	       d = TREE_CHAIN (d))
   5477 	    {
   5478 	      tree d_length = TREE_VALUE (d);
   5479 	      if (d_length == NULL_TREE || !integer_onep (d_length))
   5480 		{
   5481 		  error_at (OMP_CLAUSE_LOCATION (c),
   5482 			    "array section is not contiguous in %qs clause",
   5483 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5484 		  return error_mark_node;
   5485 		}
   5486 	    }
   5487 	}
   5488     }
   5489   else
   5490     {
   5491       error_at (OMP_CLAUSE_LOCATION (c),
   5492 		"%qE does not have pointer or array type", ret);
   5493       return error_mark_node;
   5494     }
   5495   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   5496     types.safe_push (TREE_TYPE (ret));
   5497   /* We will need to evaluate lb more than once.  */
   5498   tree lb = cp_save_expr (low_bound);
   5499   if (lb != low_bound)
   5500     {
   5501       TREE_PURPOSE (t) = lb;
   5502       low_bound = lb;
   5503     }
   5504   /* Temporarily disable -fstrong-eval-order for array reductions.
   5505      The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
   5506      is something the middle-end can't cope with and more importantly,
   5507      it needs to be the actual base variable that is privatized, not some
   5508      temporary assigned previous value of it.  That, together with OpenMP
   5509      saying how many times the side-effects are evaluated is unspecified,
   5510      makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified.  */
   5511   warning_sentinel s (flag_strong_eval_order,
   5512 		      OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5513 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5514 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
   5515   ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
   5516 			 tf_warning_or_error);
   5517   return ret;
   5518 }
   5519 
   5520 /* Handle array sections for clause C.  */
   5521 
   5522 static bool
   5523 handle_omp_array_sections (tree c, enum c_omp_region_type ort)
   5524 {
   5525   bool maybe_zero_len = false;
   5526   unsigned int first_non_one = 0;
   5527   auto_vec<tree, 10> types;
   5528   tree *tp = &OMP_CLAUSE_DECL (c);
   5529   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   5530        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   5531       && TREE_CODE (*tp) == TREE_LIST
   5532       && TREE_PURPOSE (*tp)
   5533       && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
   5534     tp = &TREE_VALUE (*tp);
   5535   tree first = handle_omp_array_sections_1 (c, *tp, types,
   5536 					    maybe_zero_len, first_non_one,
   5537 					    ort);
   5538   if (first == error_mark_node)
   5539     return true;
   5540   if (first == NULL_TREE)
   5541     return false;
   5542   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   5543       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   5544     {
   5545       tree t = *tp;
   5546       tree tem = NULL_TREE;
   5547       if (processing_template_decl)
   5548 	return false;
   5549       /* Need to evaluate side effects in the length expressions
   5550 	 if any.  */
   5551       while (TREE_CODE (t) == TREE_LIST)
   5552 	{
   5553 	  if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
   5554 	    {
   5555 	      if (tem == NULL_TREE)
   5556 		tem = TREE_VALUE (t);
   5557 	      else
   5558 		tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
   5559 			      TREE_VALUE (t), tem);
   5560 	    }
   5561 	  t = TREE_CHAIN (t);
   5562 	}
   5563       if (tem)
   5564 	first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
   5565       *tp = first;
   5566     }
   5567   else
   5568     {
   5569       unsigned int num = types.length (), i;
   5570       tree t, side_effects = NULL_TREE, size = NULL_TREE;
   5571       tree condition = NULL_TREE;
   5572 
   5573       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
   5574 	maybe_zero_len = true;
   5575       if (processing_template_decl && maybe_zero_len)
   5576 	return false;
   5577 
   5578       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
   5579 	   t = TREE_CHAIN (t))
   5580 	{
   5581 	  tree low_bound = TREE_PURPOSE (t);
   5582 	  tree length = TREE_VALUE (t);
   5583 
   5584 	  i--;
   5585 	  if (low_bound
   5586 	      && TREE_CODE (low_bound) == INTEGER_CST
   5587 	      && TYPE_PRECISION (TREE_TYPE (low_bound))
   5588 		 > TYPE_PRECISION (sizetype))
   5589 	    low_bound = fold_convert (sizetype, low_bound);
   5590 	  if (length
   5591 	      && TREE_CODE (length) == INTEGER_CST
   5592 	      && TYPE_PRECISION (TREE_TYPE (length))
   5593 		 > TYPE_PRECISION (sizetype))
   5594 	    length = fold_convert (sizetype, length);
   5595 	  if (low_bound == NULL_TREE)
   5596 	    low_bound = integer_zero_node;
   5597 	  if (!maybe_zero_len && i > first_non_one)
   5598 	    {
   5599 	      if (integer_nonzerop (low_bound))
   5600 		goto do_warn_noncontiguous;
   5601 	      if (length != NULL_TREE
   5602 		  && TREE_CODE (length) == INTEGER_CST
   5603 		  && TYPE_DOMAIN (types[i])
   5604 		  && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
   5605 		  && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
   5606 		     == INTEGER_CST)
   5607 		{
   5608 		  tree size;
   5609 		  size = size_binop (PLUS_EXPR,
   5610 				     TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   5611 				     size_one_node);
   5612 		  if (!tree_int_cst_equal (length, size))
   5613 		    {
   5614 		     do_warn_noncontiguous:
   5615 		      error_at (OMP_CLAUSE_LOCATION (c),
   5616 				"array section is not contiguous in %qs "
   5617 				"clause",
   5618 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   5619 		      return true;
   5620 		    }
   5621 		}
   5622 	      if (!processing_template_decl
   5623 		  && length != NULL_TREE
   5624 		  && TREE_SIDE_EFFECTS (length))
   5625 		{
   5626 		  if (side_effects == NULL_TREE)
   5627 		    side_effects = length;
   5628 		  else
   5629 		    side_effects = build2 (COMPOUND_EXPR,
   5630 					   TREE_TYPE (side_effects),
   5631 					   length, side_effects);
   5632 		}
   5633 	    }
   5634 	  else if (processing_template_decl)
   5635 	    continue;
   5636 	  else
   5637 	    {
   5638 	      tree l;
   5639 
   5640 	      if (i > first_non_one
   5641 		  && ((length && integer_nonzerop (length))
   5642 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5643 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5644 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
   5645 		continue;
   5646 	      if (length)
   5647 		l = fold_convert (sizetype, length);
   5648 	      else
   5649 		{
   5650 		  l = size_binop (PLUS_EXPR,
   5651 				  TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   5652 				  size_one_node);
   5653 		  l = size_binop (MINUS_EXPR, l,
   5654 				  fold_convert (sizetype, low_bound));
   5655 		}
   5656 	      if (i > first_non_one)
   5657 		{
   5658 		  l = fold_build2 (NE_EXPR, boolean_type_node, l,
   5659 				   size_zero_node);
   5660 		  if (condition == NULL_TREE)
   5661 		    condition = l;
   5662 		  else
   5663 		    condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
   5664 					     l, condition);
   5665 		}
   5666 	      else if (size == NULL_TREE)
   5667 		{
   5668 		  size = size_in_bytes (TREE_TYPE (types[i]));
   5669 		  tree eltype = TREE_TYPE (types[num - 1]);
   5670 		  while (TREE_CODE (eltype) == ARRAY_TYPE)
   5671 		    eltype = TREE_TYPE (eltype);
   5672 		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5673 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5674 		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   5675 		    size = size_binop (EXACT_DIV_EXPR, size,
   5676 				       size_in_bytes (eltype));
   5677 		  size = size_binop (MULT_EXPR, size, l);
   5678 		  if (condition)
   5679 		    size = fold_build3 (COND_EXPR, sizetype, condition,
   5680 					size, size_zero_node);
   5681 		}
   5682 	      else
   5683 		size = size_binop (MULT_EXPR, size, l);
   5684 	    }
   5685 	}
   5686       if (!processing_template_decl)
   5687 	{
   5688 	  if (side_effects)
   5689 	    size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
   5690 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   5691 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   5692 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   5693 	    {
   5694 	      size = size_binop (MINUS_EXPR, size, size_one_node);
   5695 	      size = save_expr (size);
   5696 	      tree index_type = build_index_type (size);
   5697 	      tree eltype = TREE_TYPE (first);
   5698 	      while (TREE_CODE (eltype) == ARRAY_TYPE)
   5699 		eltype = TREE_TYPE (eltype);
   5700 	      tree type = build_array_type (eltype, index_type);
   5701 	      tree ptype = build_pointer_type (eltype);
   5702 	      if (TYPE_REF_P (TREE_TYPE (t))
   5703 		  && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
   5704 		t = convert_from_reference (t);
   5705 	      else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   5706 		t = build_fold_addr_expr (t);
   5707 	      tree t2 = build_fold_addr_expr (first);
   5708 	      t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   5709 				     ptrdiff_type_node, t2);
   5710 	      t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   5711 				    ptrdiff_type_node, t2,
   5712 				    fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   5713 						      ptrdiff_type_node, t));
   5714 	      if (tree_fits_shwi_p (t2))
   5715 		t = build2 (MEM_REF, type, t,
   5716 			    build_int_cst (ptype, tree_to_shwi (t2)));
   5717 	      else
   5718 		{
   5719 		  t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   5720 					 sizetype, t2);
   5721 		  t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
   5722 				  TREE_TYPE (t), t, t2);
   5723 		  t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
   5724 		}
   5725 	      OMP_CLAUSE_DECL (c) = t;
   5726 	      return false;
   5727 	    }
   5728 	  OMP_CLAUSE_DECL (c) = first;
   5729 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
   5730 	    return false;
   5731 	  OMP_CLAUSE_SIZE (c) = size;
   5732 	  if (TREE_CODE (t) == FIELD_DECL)
   5733 	    t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
   5734 	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   5735 	      || (TREE_CODE (t) == COMPONENT_REF
   5736 		  && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE))
   5737 	    return false;
   5738 	  switch (OMP_CLAUSE_MAP_KIND (c))
   5739 	    {
   5740 	    case GOMP_MAP_ALLOC:
   5741 	    case GOMP_MAP_IF_PRESENT:
   5742 	    case GOMP_MAP_TO:
   5743 	    case GOMP_MAP_FROM:
   5744 	    case GOMP_MAP_TOFROM:
   5745 	    case GOMP_MAP_ALWAYS_TO:
   5746 	    case GOMP_MAP_ALWAYS_FROM:
   5747 	    case GOMP_MAP_ALWAYS_TOFROM:
   5748 	    case GOMP_MAP_RELEASE:
   5749 	    case GOMP_MAP_DELETE:
   5750 	    case GOMP_MAP_FORCE_TO:
   5751 	    case GOMP_MAP_FORCE_FROM:
   5752 	    case GOMP_MAP_FORCE_TOFROM:
   5753 	    case GOMP_MAP_FORCE_PRESENT:
   5754 	      OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   5755 	      break;
   5756 	    default:
   5757 	      break;
   5758 	    }
   5759 	  bool reference_always_pointer = true;
   5760 	  tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   5761 				      OMP_CLAUSE_MAP);
   5762 	  if (TREE_CODE (t) == COMPONENT_REF)
   5763 	    {
   5764 	      OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ATTACH_DETACH);
   5765 
   5766 	      if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
   5767 		  && TYPE_REF_P (TREE_TYPE (t)))
   5768 		{
   5769 		  if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == ARRAY_TYPE)
   5770 		    OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
   5771 		  else
   5772 		    t = convert_from_reference (t);
   5773 
   5774 		  reference_always_pointer = false;
   5775 		}
   5776 	    }
   5777 	  else if (REFERENCE_REF_P (t)
   5778 		   && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
   5779 	    {
   5780 	      gomp_map_kind k;
   5781 	      if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
   5782 		  && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
   5783 		k = GOMP_MAP_ATTACH_DETACH;
   5784 	      else
   5785 		{
   5786 		  t = TREE_OPERAND (t, 0);
   5787 		  k = (ort == C_ORT_ACC
   5788 		       ? GOMP_MAP_ATTACH_DETACH : GOMP_MAP_ALWAYS_POINTER);
   5789 		}
   5790 	      OMP_CLAUSE_SET_MAP_KIND (c2, k);
   5791 	    }
   5792 	  else
   5793 	    OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   5794 	  OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c);
   5795 	  if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
   5796 	      && !cxx_mark_addressable (t))
   5797 	    return false;
   5798 	  OMP_CLAUSE_DECL (c2) = t;
   5799 	  t = build_fold_addr_expr (first);
   5800 	  t = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   5801 				ptrdiff_type_node, t);
   5802 	  tree ptr = OMP_CLAUSE_DECL (c2);
   5803 	  ptr = convert_from_reference (ptr);
   5804 	  if (!INDIRECT_TYPE_P (TREE_TYPE (ptr)))
   5805 	    ptr = build_fold_addr_expr (ptr);
   5806 	  t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   5807 			       ptrdiff_type_node, t,
   5808 			       fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   5809 						 ptrdiff_type_node, ptr));
   5810 	  OMP_CLAUSE_SIZE (c2) = t;
   5811 	  OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
   5812 	  OMP_CLAUSE_CHAIN (c) = c2;
   5813 
   5814 	  ptr = OMP_CLAUSE_DECL (c2);
   5815 	  if (reference_always_pointer
   5816 	      && OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
   5817 	      && TYPE_REF_P (TREE_TYPE (ptr))
   5818 	      && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr))))
   5819 	    {
   5820 	      tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   5821 					  OMP_CLAUSE_MAP);
   5822 	      OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2));
   5823 	      OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c);
   5824 	      OMP_CLAUSE_DECL (c3) = ptr;
   5825 	      if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER
   5826 		  || OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ATTACH_DETACH)
   5827 		{
   5828 		  OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr);
   5829 		  OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
   5830 		}
   5831 	      else
   5832 		OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr);
   5833 	      OMP_CLAUSE_SIZE (c3) = size_zero_node;
   5834 	      OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2);
   5835 	      OMP_CLAUSE_CHAIN (c2) = c3;
   5836 	    }
   5837 	}
   5838     }
   5839   return false;
   5840 }
   5841 
   5842 /* Return identifier to look up for omp declare reduction.  */
   5843 
   5844 tree
   5845 omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
   5846 {
   5847   const char *p = NULL;
   5848   const char *m = NULL;
   5849   switch (reduction_code)
   5850     {
   5851     case PLUS_EXPR:
   5852     case MULT_EXPR:
   5853     case MINUS_EXPR:
   5854     case BIT_AND_EXPR:
   5855     case BIT_XOR_EXPR:
   5856     case BIT_IOR_EXPR:
   5857     case TRUTH_ANDIF_EXPR:
   5858     case TRUTH_ORIF_EXPR:
   5859       reduction_id = ovl_op_identifier (false, reduction_code);
   5860       break;
   5861     case MIN_EXPR:
   5862       p = "min";
   5863       break;
   5864     case MAX_EXPR:
   5865       p = "max";
   5866       break;
   5867     default:
   5868       break;
   5869     }
   5870 
   5871   if (p == NULL)
   5872     {
   5873       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
   5874 	return error_mark_node;
   5875       p = IDENTIFIER_POINTER (reduction_id);
   5876     }
   5877 
   5878   if (type != NULL_TREE)
   5879     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
   5880 
   5881   const char prefix[] = "omp declare reduction ";
   5882   size_t lenp = sizeof (prefix);
   5883   if (strncmp (p, prefix, lenp - 1) == 0)
   5884     lenp = 1;
   5885   size_t len = strlen (p);
   5886   size_t lenm = m ? strlen (m) + 1 : 0;
   5887   char *name = XALLOCAVEC (char, lenp + len + lenm);
   5888   if (lenp > 1)
   5889     memcpy (name, prefix, lenp - 1);
   5890   memcpy (name + lenp - 1, p, len + 1);
   5891   if (m)
   5892     {
   5893       name[lenp + len - 1] = '~';
   5894       memcpy (name + lenp + len, m, lenm);
   5895     }
   5896   return get_identifier (name);
   5897 }
   5898 
   5899 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
   5900    FUNCTION_DECL or NULL_TREE if not found.  */
   5901 
   5902 static tree
   5903 omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
   5904 		      vec<tree> *ambiguousp)
   5905 {
   5906   tree orig_id = id;
   5907   tree baselink = NULL_TREE;
   5908   if (identifier_p (id))
   5909     {
   5910       cp_id_kind idk;
   5911       bool nonint_cst_expression_p;
   5912       const char *error_msg;
   5913       id = omp_reduction_id (ERROR_MARK, id, type);
   5914       tree decl = lookup_name (id);
   5915       if (decl == NULL_TREE)
   5916 	decl = error_mark_node;
   5917       id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
   5918 				 &nonint_cst_expression_p, false, true, false,
   5919 				 false, &error_msg, loc);
   5920       if (idk == CP_ID_KIND_UNQUALIFIED
   5921 	  && identifier_p (id))
   5922 	{
   5923 	  vec<tree, va_gc> *args = NULL;
   5924 	  vec_safe_push (args, build_reference_type (type));
   5925 	  id = perform_koenig_lookup (id, args, tf_none);
   5926 	}
   5927     }
   5928   else if (TREE_CODE (id) == SCOPE_REF)
   5929     id = lookup_qualified_name (TREE_OPERAND (id, 0),
   5930 				omp_reduction_id (ERROR_MARK,
   5931 						  TREE_OPERAND (id, 1),
   5932 						  type),
   5933 				LOOK_want::NORMAL, false);
   5934   tree fns = id;
   5935   id = NULL_TREE;
   5936   if (fns && is_overloaded_fn (fns))
   5937     {
   5938       for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
   5939 	{
   5940 	  tree fndecl = *iter;
   5941 	  if (TREE_CODE (fndecl) == FUNCTION_DECL)
   5942 	    {
   5943 	      tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
   5944 	      if (same_type_p (TREE_TYPE (argtype), type))
   5945 		{
   5946 		  id = fndecl;
   5947 		  break;
   5948 		}
   5949 	    }
   5950 	}
   5951 
   5952       if (id && BASELINK_P (fns))
   5953 	{
   5954 	  if (baselinkp)
   5955 	    *baselinkp = fns;
   5956 	  else
   5957 	    baselink = fns;
   5958 	}
   5959     }
   5960 
   5961   if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
   5962     {
   5963       auto_vec<tree> ambiguous;
   5964       tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
   5965       unsigned int ix;
   5966       if (ambiguousp == NULL)
   5967 	ambiguousp = &ambiguous;
   5968       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
   5969 	{
   5970 	  id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
   5971 				     baselinkp ? baselinkp : &baselink,
   5972 				     ambiguousp);
   5973 	  if (id == NULL_TREE)
   5974 	    continue;
   5975 	  if (!ambiguousp->is_empty ())
   5976 	    ambiguousp->safe_push (id);
   5977 	  else if (ret != NULL_TREE)
   5978 	    {
   5979 	      ambiguousp->safe_push (ret);
   5980 	      ambiguousp->safe_push (id);
   5981 	      ret = NULL_TREE;
   5982 	    }
   5983 	  else
   5984 	    ret = id;
   5985 	}
   5986       if (ambiguousp != &ambiguous)
   5987 	return ret;
   5988       if (!ambiguous.is_empty ())
   5989 	{
   5990 	  const char *str = _("candidates are:");
   5991 	  unsigned int idx;
   5992 	  tree udr;
   5993 	  error_at (loc, "user defined reduction lookup is ambiguous");
   5994 	  FOR_EACH_VEC_ELT (ambiguous, idx, udr)
   5995 	    {
   5996 	      inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
   5997 	      if (idx == 0)
   5998 		str = get_spaces (str);
   5999 	    }
   6000 	  ret = error_mark_node;
   6001 	  baselink = NULL_TREE;
   6002 	}
   6003       id = ret;
   6004     }
   6005   if (id && baselink)
   6006     perform_or_defer_access_check (BASELINK_BINFO (baselink),
   6007 				   id, id, tf_warning_or_error);
   6008   return id;
   6009 }
   6010 
   6011 /* Helper function for cp_parser_omp_declare_reduction_exprs
   6012    and tsubst_omp_udr.
   6013    Remove CLEANUP_STMT for data (omp_priv variable).
   6014    Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
   6015    DECL_EXPR.  */
   6016 
   6017 tree
   6018 cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
   6019 {
   6020   if (TYPE_P (*tp))
   6021     *walk_subtrees = 0;
   6022   else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
   6023     *tp = CLEANUP_BODY (*tp);
   6024   else if (TREE_CODE (*tp) == DECL_EXPR)
   6025     {
   6026       tree decl = DECL_EXPR_DECL (*tp);
   6027       if (!processing_template_decl
   6028 	  && decl == (tree) data
   6029 	  && DECL_INITIAL (decl)
   6030 	  && DECL_INITIAL (decl) != error_mark_node)
   6031 	{
   6032 	  tree list = NULL_TREE;
   6033 	  append_to_statement_list_force (*tp, &list);
   6034 	  tree init_expr = build2 (INIT_EXPR, void_type_node,
   6035 				   decl, DECL_INITIAL (decl));
   6036 	  DECL_INITIAL (decl) = NULL_TREE;
   6037 	  append_to_statement_list_force (init_expr, &list);
   6038 	  *tp = list;
   6039 	}
   6040     }
   6041   return NULL_TREE;
   6042 }
   6043 
   6044 /* Data passed from cp_check_omp_declare_reduction to
   6045    cp_check_omp_declare_reduction_r.  */
   6046 
   6047 struct cp_check_omp_declare_reduction_data
   6048 {
   6049   location_t loc;
   6050   tree stmts[7];
   6051   bool combiner_p;
   6052 };
   6053 
   6054 /* Helper function for cp_check_omp_declare_reduction, called via
   6055    cp_walk_tree.  */
   6056 
   6057 static tree
   6058 cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
   6059 {
   6060   struct cp_check_omp_declare_reduction_data *udr_data
   6061     = (struct cp_check_omp_declare_reduction_data *) data;
   6062   if (SSA_VAR_P (*tp)
   6063       && !DECL_ARTIFICIAL (*tp)
   6064       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
   6065       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
   6066     {
   6067       location_t loc = udr_data->loc;
   6068       if (udr_data->combiner_p)
   6069 	error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
   6070 		       "variable %qD which is not %<omp_out%> nor %<omp_in%>",
   6071 		  *tp);
   6072       else
   6073 	error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
   6074 		       "to variable %qD which is not %<omp_priv%> nor "
   6075 		       "%<omp_orig%>",
   6076 		  *tp);
   6077       return *tp;
   6078     }
   6079   return NULL_TREE;
   6080 }
   6081 
   6082 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions.  */
   6083 
   6084 bool
   6085 cp_check_omp_declare_reduction (tree udr)
   6086 {
   6087   tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
   6088   gcc_assert (TYPE_REF_P (type));
   6089   type = TREE_TYPE (type);
   6090   int i;
   6091   location_t loc = DECL_SOURCE_LOCATION (udr);
   6092 
   6093   if (type == error_mark_node)
   6094     return false;
   6095   if (ARITHMETIC_TYPE_P (type))
   6096     {
   6097       static enum tree_code predef_codes[]
   6098 	= { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
   6099 	    BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
   6100       for (i = 0; i < 8; i++)
   6101 	{
   6102 	  tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
   6103 	  const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
   6104 	  const char *n2 = IDENTIFIER_POINTER (id);
   6105 	  if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
   6106 	      && (n1[IDENTIFIER_LENGTH (id)] == '~'
   6107 		  || n1[IDENTIFIER_LENGTH (id)] == '\0'))
   6108 	    break;
   6109 	}
   6110 
   6111       if (i == 8
   6112 	  && TREE_CODE (type) != COMPLEX_EXPR)
   6113 	{
   6114 	  const char prefix_minmax[] = "omp declare reduction m";
   6115 	  size_t prefix_size = sizeof (prefix_minmax) - 1;
   6116 	  const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
   6117 	  if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
   6118 		       prefix_minmax, prefix_size) == 0
   6119 	      && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
   6120 		  || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
   6121 	      && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
   6122 	    i = 0;
   6123 	}
   6124       if (i < 8)
   6125 	{
   6126 	  error_at (loc, "predeclared arithmetic type %qT in "
   6127 			 "%<#pragma omp declare reduction%>", type);
   6128 	  return false;
   6129 	}
   6130     }
   6131   else if (FUNC_OR_METHOD_TYPE_P (type)
   6132 	   || TREE_CODE (type) == ARRAY_TYPE)
   6133     {
   6134       error_at (loc, "function or array type %qT in "
   6135 		     "%<#pragma omp declare reduction%>", type);
   6136       return false;
   6137     }
   6138   else if (TYPE_REF_P (type))
   6139     {
   6140       error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
   6141 		type);
   6142       return false;
   6143     }
   6144   else if (TYPE_QUALS_NO_ADDR_SPACE (type))
   6145     {
   6146       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
   6147 		"type %qT in %<#pragma omp declare reduction%>", type);
   6148       return false;
   6149     }
   6150 
   6151   tree body = DECL_SAVED_TREE (udr);
   6152   if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
   6153     return true;
   6154 
   6155   tree_stmt_iterator tsi;
   6156   struct cp_check_omp_declare_reduction_data data;
   6157   memset (data.stmts, 0, sizeof data.stmts);
   6158   for (i = 0, tsi = tsi_start (body);
   6159        i < 7 && !tsi_end_p (tsi);
   6160        i++, tsi_next (&tsi))
   6161     data.stmts[i] = tsi_stmt (tsi);
   6162   data.loc = loc;
   6163   gcc_assert (tsi_end_p (tsi));
   6164   if (i >= 3)
   6165     {
   6166       gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
   6167 		  && TREE_CODE (data.stmts[1]) == DECL_EXPR);
   6168       if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
   6169 	return true;
   6170       data.combiner_p = true;
   6171       if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
   6172 			&data, NULL))
   6173 	suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
   6174     }
   6175   if (i >= 6)
   6176     {
   6177       gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
   6178 		  && TREE_CODE (data.stmts[4]) == DECL_EXPR);
   6179       data.combiner_p = false;
   6180       if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
   6181 			&data, NULL)
   6182 	  || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
   6183 			   cp_check_omp_declare_reduction_r, &data, NULL))
   6184 	suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /* Wat warning? */);
   6185       if (i == 7)
   6186 	gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
   6187     }
   6188   return true;
   6189 }
   6190 
   6191 /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
   6192    an inline call.  But, remap
   6193    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
   6194    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
   6195 
   6196 static tree
   6197 clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   6198 	       tree decl, tree placeholder)
   6199 {
   6200   copy_body_data id;
   6201   hash_map<tree, tree> decl_map;
   6202 
   6203   decl_map.put (omp_decl1, placeholder);
   6204   decl_map.put (omp_decl2, decl);
   6205   memset (&id, 0, sizeof (id));
   6206   id.src_fn = DECL_CONTEXT (omp_decl1);
   6207   id.dst_fn = current_function_decl;
   6208   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
   6209   id.decl_map = &decl_map;
   6210 
   6211   id.copy_decl = copy_decl_no_change;
   6212   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   6213   id.transform_new_cfg = true;
   6214   id.transform_return_to_modify = false;
   6215   id.eh_lp_nr = 0;
   6216   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
   6217   return stmt;
   6218 }
   6219 
   6220 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
   6221    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
   6222 
   6223 static tree
   6224 find_omp_placeholder_r (tree *tp, int *, void *data)
   6225 {
   6226   if (*tp == (tree) data)
   6227     return *tp;
   6228   return NULL_TREE;
   6229 }
   6230 
   6231 /* Helper function of finish_omp_clauses.  Handle OMP_CLAUSE_REDUCTION C.
   6232    Return true if there is some error and the clause should be removed.  */
   6233 
   6234 static bool
   6235 finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
   6236 {
   6237   tree t = OMP_CLAUSE_DECL (c);
   6238   bool predefined = false;
   6239   if (TREE_CODE (t) == TREE_LIST)
   6240     {
   6241       gcc_assert (processing_template_decl);
   6242       return false;
   6243     }
   6244   tree type = TREE_TYPE (t);
   6245   if (TREE_CODE (t) == MEM_REF)
   6246     type = TREE_TYPE (type);
   6247   if (TYPE_REF_P (type))
   6248     type = TREE_TYPE (type);
   6249   if (TREE_CODE (type) == ARRAY_TYPE)
   6250     {
   6251       tree oatype = type;
   6252       gcc_assert (TREE_CODE (t) != MEM_REF);
   6253       while (TREE_CODE (type) == ARRAY_TYPE)
   6254 	type = TREE_TYPE (type);
   6255       if (!processing_template_decl)
   6256 	{
   6257 	  t = require_complete_type (t);
   6258 	  if (t == error_mark_node
   6259 	      || !complete_type_or_else (oatype, NULL_TREE))
   6260 	    return true;
   6261 	  tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
   6262 				  TYPE_SIZE_UNIT (type));
   6263 	  if (integer_zerop (size))
   6264 	    {
   6265 	      error_at (OMP_CLAUSE_LOCATION (c),
   6266 			"%qE in %<reduction%> clause is a zero size array",
   6267 			omp_clause_printable_decl (t));
   6268 	      return true;
   6269 	    }
   6270 	  size = size_binop (MINUS_EXPR, size, size_one_node);
   6271 	  size = save_expr (size);
   6272 	  tree index_type = build_index_type (size);
   6273 	  tree atype = build_array_type (type, index_type);
   6274 	  tree ptype = build_pointer_type (type);
   6275 	  if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   6276 	    t = build_fold_addr_expr (t);
   6277 	  t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
   6278 	  OMP_CLAUSE_DECL (c) = t;
   6279 	}
   6280     }
   6281   if (type == error_mark_node)
   6282     return true;
   6283   else if (ARITHMETIC_TYPE_P (type))
   6284     switch (OMP_CLAUSE_REDUCTION_CODE (c))
   6285       {
   6286       case PLUS_EXPR:
   6287       case MULT_EXPR:
   6288       case MINUS_EXPR:
   6289       case TRUTH_ANDIF_EXPR:
   6290       case TRUTH_ORIF_EXPR:
   6291 	predefined = true;
   6292 	break;
   6293       case MIN_EXPR:
   6294       case MAX_EXPR:
   6295 	if (TREE_CODE (type) == COMPLEX_TYPE)
   6296 	  break;
   6297 	predefined = true;
   6298 	break;
   6299       case BIT_AND_EXPR:
   6300       case BIT_IOR_EXPR:
   6301       case BIT_XOR_EXPR:
   6302 	if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
   6303 	  break;
   6304 	predefined = true;
   6305 	break;
   6306       default:
   6307 	break;
   6308       }
   6309   else if (TYPE_READONLY (type))
   6310     {
   6311       error_at (OMP_CLAUSE_LOCATION (c),
   6312 		"%qE has const type for %<reduction%>",
   6313 		omp_clause_printable_decl (t));
   6314       return true;
   6315     }
   6316   else if (!processing_template_decl)
   6317     {
   6318       t = require_complete_type (t);
   6319       if (t == error_mark_node)
   6320 	return true;
   6321       OMP_CLAUSE_DECL (c) = t;
   6322     }
   6323 
   6324   if (predefined)
   6325     {
   6326       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
   6327       return false;
   6328     }
   6329   else if (processing_template_decl)
   6330     {
   6331       if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
   6332 	return true;
   6333       return false;
   6334     }
   6335 
   6336   tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
   6337 
   6338   type = TYPE_MAIN_VARIANT (type);
   6339   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
   6340   if (id == NULL_TREE)
   6341     id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
   6342 			   NULL_TREE, NULL_TREE);
   6343   id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
   6344   if (id)
   6345     {
   6346       if (id == error_mark_node)
   6347 	return true;
   6348       mark_used (id);
   6349       tree body = DECL_SAVED_TREE (id);
   6350       if (!body)
   6351 	return true;
   6352       if (TREE_CODE (body) == STATEMENT_LIST)
   6353 	{
   6354 	  tree_stmt_iterator tsi;
   6355 	  tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
   6356 	  int i;
   6357 	  tree stmts[7];
   6358 	  tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
   6359 	  atype = TREE_TYPE (atype);
   6360 	  bool need_static_cast = !same_type_p (type, atype);
   6361 	  memset (stmts, 0, sizeof stmts);
   6362 	  for (i = 0, tsi = tsi_start (body);
   6363 	       i < 7 && !tsi_end_p (tsi);
   6364 	       i++, tsi_next (&tsi))
   6365 	    stmts[i] = tsi_stmt (tsi);
   6366 	  gcc_assert (tsi_end_p (tsi));
   6367 
   6368 	  if (i >= 3)
   6369 	    {
   6370 	      gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
   6371 			  && TREE_CODE (stmts[1]) == DECL_EXPR);
   6372 	      placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
   6373 	      DECL_ARTIFICIAL (placeholder) = 1;
   6374 	      DECL_IGNORED_P (placeholder) = 1;
   6375 	      OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
   6376 	      if (TREE_CODE (t) == MEM_REF)
   6377 		{
   6378 		  decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
   6379 						      type);
   6380 		  DECL_ARTIFICIAL (decl_placeholder) = 1;
   6381 		  DECL_IGNORED_P (decl_placeholder) = 1;
   6382 		  OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
   6383 		}
   6384 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
   6385 		cxx_mark_addressable (placeholder);
   6386 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
   6387 		  && (decl_placeholder
   6388 		      || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
   6389 		cxx_mark_addressable (decl_placeholder ? decl_placeholder
   6390 				      : OMP_CLAUSE_DECL (c));
   6391 	      tree omp_out = placeholder;
   6392 	      tree omp_in = decl_placeholder ? decl_placeholder
   6393 			    : convert_from_reference (OMP_CLAUSE_DECL (c));
   6394 	      if (need_static_cast)
   6395 		{
   6396 		  tree rtype = build_reference_type (atype);
   6397 		  omp_out = build_static_cast (input_location,
   6398 					       rtype, omp_out,
   6399 					       tf_warning_or_error);
   6400 		  omp_in = build_static_cast (input_location,
   6401 					      rtype, omp_in,
   6402 					      tf_warning_or_error);
   6403 		  if (omp_out == error_mark_node || omp_in == error_mark_node)
   6404 		    return true;
   6405 		  omp_out = convert_from_reference (omp_out);
   6406 		  omp_in = convert_from_reference (omp_in);
   6407 		}
   6408 	      OMP_CLAUSE_REDUCTION_MERGE (c)
   6409 		= clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
   6410 				 DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
   6411 	    }
   6412 	  if (i >= 6)
   6413 	    {
   6414 	      gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
   6415 			  && TREE_CODE (stmts[4]) == DECL_EXPR);
   6416 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
   6417 		  && (decl_placeholder
   6418 		      || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
   6419 		cxx_mark_addressable (decl_placeholder ? decl_placeholder
   6420 				      : OMP_CLAUSE_DECL (c));
   6421 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
   6422 		cxx_mark_addressable (placeholder);
   6423 	      tree omp_priv = decl_placeholder ? decl_placeholder
   6424 			      : convert_from_reference (OMP_CLAUSE_DECL (c));
   6425 	      tree omp_orig = placeholder;
   6426 	      if (need_static_cast)
   6427 		{
   6428 		  if (i == 7)
   6429 		    {
   6430 		      error_at (OMP_CLAUSE_LOCATION (c),
   6431 				"user defined reduction with constructor "
   6432 				"initializer for base class %qT", atype);
   6433 		      return true;
   6434 		    }
   6435 		  tree rtype = build_reference_type (atype);
   6436 		  omp_priv = build_static_cast (input_location,
   6437 						rtype, omp_priv,
   6438 						tf_warning_or_error);
   6439 		  omp_orig = build_static_cast (input_location,
   6440 						rtype, omp_orig,
   6441 						tf_warning_or_error);
   6442 		  if (omp_priv == error_mark_node
   6443 		      || omp_orig == error_mark_node)
   6444 		    return true;
   6445 		  omp_priv = convert_from_reference (omp_priv);
   6446 		  omp_orig = convert_from_reference (omp_orig);
   6447 		}
   6448 	      if (i == 6)
   6449 		*need_default_ctor = true;
   6450 	      OMP_CLAUSE_REDUCTION_INIT (c)
   6451 		= clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
   6452 				 DECL_EXPR_DECL (stmts[3]),
   6453 				 omp_priv, omp_orig);
   6454 	      if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   6455 				find_omp_placeholder_r, placeholder, NULL))
   6456 		OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
   6457 	    }
   6458 	  else if (i >= 3)
   6459 	    {
   6460 	      if (CLASS_TYPE_P (type) && !pod_type_p (type))
   6461 		*need_default_ctor = true;
   6462 	      else
   6463 		{
   6464 		  tree init;
   6465 		  tree v = decl_placeholder ? decl_placeholder
   6466 			   : convert_from_reference (t);
   6467 		  if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
   6468 		    init = build_constructor (TREE_TYPE (v), NULL);
   6469 		  else
   6470 		    init = fold_convert (TREE_TYPE (v), integer_zero_node);
   6471 		  OMP_CLAUSE_REDUCTION_INIT (c)
   6472 		    = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
   6473 		}
   6474 	    }
   6475 	}
   6476     }
   6477   if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   6478     *need_dtor = true;
   6479   else
   6480     {
   6481       error_at (OMP_CLAUSE_LOCATION (c),
   6482 		"user defined reduction not found for %qE",
   6483 		omp_clause_printable_decl (t));
   6484       return true;
   6485     }
   6486   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
   6487     gcc_assert (TYPE_SIZE_UNIT (type)
   6488 		&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
   6489   return false;
   6490 }
   6491 
   6492 /* Called from finish_struct_1.  linear(this) or linear(this:step)
   6493    clauses might not be finalized yet because the class has been incomplete
   6494    when parsing #pragma omp declare simd methods.  Fix those up now.  */
   6495 
   6496 void
   6497 finish_omp_declare_simd_methods (tree t)
   6498 {
   6499   if (processing_template_decl)
   6500     return;
   6501 
   6502   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
   6503     {
   6504       if (TREE_CODE (x) == USING_DECL
   6505 	  || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x))
   6506 	continue;
   6507       tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
   6508       if (!ods || !TREE_VALUE (ods))
   6509 	continue;
   6510       for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
   6511 	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   6512 	    && integer_zerop (OMP_CLAUSE_DECL (c))
   6513 	    && OMP_CLAUSE_LINEAR_STEP (c)
   6514 	    && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
   6515 	  {
   6516 	    tree s = OMP_CLAUSE_LINEAR_STEP (c);
   6517 	    s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
   6518 	    s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
   6519 				 sizetype, s, TYPE_SIZE_UNIT (t));
   6520 	    OMP_CLAUSE_LINEAR_STEP (c) = s;
   6521 	  }
   6522     }
   6523 }
   6524 
   6525 /* Adjust sink depend clause to take into account pointer offsets.
   6526 
   6527    Return TRUE if there was a problem processing the offset, and the
   6528    whole clause should be removed.  */
   6529 
   6530 static bool
   6531 cp_finish_omp_clause_depend_sink (tree sink_clause)
   6532 {
   6533   tree t = OMP_CLAUSE_DECL (sink_clause);
   6534   gcc_assert (TREE_CODE (t) == TREE_LIST);
   6535 
   6536   /* Make sure we don't adjust things twice for templates.  */
   6537   if (processing_template_decl)
   6538     return false;
   6539 
   6540   for (; t; t = TREE_CHAIN (t))
   6541     {
   6542       tree decl = TREE_VALUE (t);
   6543       if (TYPE_PTR_P (TREE_TYPE (decl)))
   6544 	{
   6545 	  tree offset = TREE_PURPOSE (t);
   6546 	  bool neg = wi::neg_p (wi::to_wide (offset));
   6547 	  offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
   6548 	  decl = mark_rvalue_use (decl);
   6549 	  decl = convert_from_reference (decl);
   6550 	  tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
   6551 				     neg ? MINUS_EXPR : PLUS_EXPR,
   6552 				     decl, offset);
   6553 	  t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
   6554 				MINUS_EXPR, sizetype,
   6555 				fold_convert (sizetype, t2),
   6556 				fold_convert (sizetype, decl));
   6557 	  if (t2 == error_mark_node)
   6558 	    return true;
   6559 	  TREE_PURPOSE (t) = t2;
   6560 	}
   6561     }
   6562   return false;
   6563 }
   6564 
   6565 /* Finish OpenMP iterators ITER.  Return true if they are errorneous
   6566    and clauses containing them should be removed.  */
   6567 
   6568 static bool
   6569 cp_omp_finish_iterators (tree iter)
   6570 {
   6571   bool ret = false;
   6572   for (tree it = iter; it; it = TREE_CHAIN (it))
   6573     {
   6574       tree var = TREE_VEC_ELT (it, 0);
   6575       tree begin = TREE_VEC_ELT (it, 1);
   6576       tree end = TREE_VEC_ELT (it, 2);
   6577       tree step = TREE_VEC_ELT (it, 3);
   6578       tree orig_step;
   6579       tree type = TREE_TYPE (var);
   6580       location_t loc = DECL_SOURCE_LOCATION (var);
   6581       if (type == error_mark_node)
   6582 	{
   6583 	  ret = true;
   6584 	  continue;
   6585 	}
   6586       if (type_dependent_expression_p (var))
   6587 	continue;
   6588       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
   6589 	{
   6590 	  error_at (loc, "iterator %qD has neither integral nor pointer type",
   6591 		    var);
   6592 	  ret = true;
   6593 	  continue;
   6594 	}
   6595       else if (TYPE_READONLY (type))
   6596 	{
   6597 	  error_at (loc, "iterator %qD has const qualified type", var);
   6598 	  ret = true;
   6599 	  continue;
   6600 	}
   6601       if (type_dependent_expression_p (begin)
   6602 	  || type_dependent_expression_p (end)
   6603 	  || type_dependent_expression_p (step))
   6604 	continue;
   6605       else if (error_operand_p (step))
   6606 	{
   6607 	  ret = true;
   6608 	  continue;
   6609 	}
   6610       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
   6611 	{
   6612 	  error_at (EXPR_LOC_OR_LOC (step, loc),
   6613 		    "iterator step with non-integral type");
   6614 	  ret = true;
   6615 	  continue;
   6616 	}
   6617 
   6618       begin = mark_rvalue_use (begin);
   6619       end = mark_rvalue_use (end);
   6620       step = mark_rvalue_use (step);
   6621       begin = cp_build_c_cast (input_location, type, begin,
   6622 			       tf_warning_or_error);
   6623       end = cp_build_c_cast (input_location, type, end,
   6624 			     tf_warning_or_error);
   6625       orig_step = step;
   6626       if (!processing_template_decl)
   6627 	step = orig_step = save_expr (step);
   6628       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
   6629       step = cp_build_c_cast (input_location, stype, step,
   6630 			      tf_warning_or_error);
   6631       if (POINTER_TYPE_P (type) && !processing_template_decl)
   6632 	{
   6633 	  begin = save_expr (begin);
   6634 	  step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
   6635 	  step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
   6636 				  fold_convert (sizetype, step),
   6637 				  fold_convert (sizetype, begin));
   6638 	  step = fold_convert (ssizetype, step);
   6639 	}
   6640       if (!processing_template_decl)
   6641 	{
   6642 	  begin = maybe_constant_value (begin);
   6643 	  end = maybe_constant_value (end);
   6644 	  step = maybe_constant_value (step);
   6645 	  orig_step = maybe_constant_value (orig_step);
   6646 	}
   6647       if (integer_zerop (step))
   6648 	{
   6649 	  error_at (loc, "iterator %qD has zero step", var);
   6650 	  ret = true;
   6651 	  continue;
   6652 	}
   6653 
   6654       if (begin == error_mark_node
   6655 	  || end == error_mark_node
   6656 	  || step == error_mark_node
   6657 	  || orig_step == error_mark_node)
   6658 	{
   6659 	  ret = true;
   6660 	  continue;
   6661 	}
   6662 
   6663       if (!processing_template_decl)
   6664 	{
   6665 	  begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
   6666 	  end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
   6667 	  step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
   6668 	  orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
   6669 						     orig_step);
   6670 	}
   6671       hash_set<tree> pset;
   6672       tree it2;
   6673       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
   6674 	{
   6675 	  tree var2 = TREE_VEC_ELT (it2, 0);
   6676 	  tree begin2 = TREE_VEC_ELT (it2, 1);
   6677 	  tree end2 = TREE_VEC_ELT (it2, 2);
   6678 	  tree step2 = TREE_VEC_ELT (it2, 3);
   6679 	  location_t loc2 = DECL_SOURCE_LOCATION (var2);
   6680 	  if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
   6681 	    {
   6682 	      error_at (EXPR_LOC_OR_LOC (begin2, loc2),
   6683 			"begin expression refers to outer iterator %qD", var);
   6684 	      break;
   6685 	    }
   6686 	  else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
   6687 	    {
   6688 	      error_at (EXPR_LOC_OR_LOC (end2, loc2),
   6689 			"end expression refers to outer iterator %qD", var);
   6690 	      break;
   6691 	    }
   6692 	  else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
   6693 	    {
   6694 	      error_at (EXPR_LOC_OR_LOC (step2, loc2),
   6695 			"step expression refers to outer iterator %qD", var);
   6696 	      break;
   6697 	    }
   6698 	}
   6699       if (it2)
   6700 	{
   6701 	  ret = true;
   6702 	  continue;
   6703 	}
   6704       TREE_VEC_ELT (it, 1) = begin;
   6705       TREE_VEC_ELT (it, 2) = end;
   6706       if (processing_template_decl)
   6707 	TREE_VEC_ELT (it, 3) = orig_step;
   6708       else
   6709 	{
   6710 	  TREE_VEC_ELT (it, 3) = step;
   6711 	  TREE_VEC_ELT (it, 4) = orig_step;
   6712 	}
   6713     }
   6714   return ret;
   6715 }
   6716 
   6717 /* Ensure that pointers are used in OpenACC attach and detach clauses.
   6718    Return true if an error has been detected.  */
   6719 
   6720 static bool
   6721 cp_oacc_check_attachments (tree c)
   6722 {
   6723   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   6724     return false;
   6725 
   6726   /* OpenACC attach / detach clauses must be pointers.  */
   6727   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   6728       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   6729     {
   6730       tree t = OMP_CLAUSE_DECL (c);
   6731       tree type;
   6732 
   6733       while (TREE_CODE (t) == TREE_LIST)
   6734 	t = TREE_CHAIN (t);
   6735 
   6736       type = TREE_TYPE (t);
   6737 
   6738       if (TREE_CODE (type) == REFERENCE_TYPE)
   6739 	type = TREE_TYPE (type);
   6740 
   6741       if (TREE_CODE (type) != POINTER_TYPE)
   6742 	{
   6743 	  error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
   6744 		    user_omp_clause_code_name (c, true));
   6745 	  return true;
   6746 	}
   6747     }
   6748 
   6749   return false;
   6750 }
   6751 
   6752 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
   6753    Remove any elements from the list that are invalid.  */
   6754 
   6755 tree
   6756 finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   6757 {
   6758   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   6759   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
   6760   bitmap_head oacc_reduction_head, is_on_device_head;
   6761   tree c, t, *pc;
   6762   tree safelen = NULL_TREE;
   6763   bool branch_seen = false;
   6764   bool copyprivate_seen = false;
   6765   bool ordered_seen = false;
   6766   bool order_seen = false;
   6767   bool schedule_seen = false;
   6768   bool oacc_async = false;
   6769   bool indir_component_ref_p = false;
   6770   tree last_iterators = NULL_TREE;
   6771   bool last_iterators_remove = false;
   6772   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
   6773      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
   6774   int reduction_seen = 0;
   6775   bool allocate_seen = false;
   6776   tree detach_seen = NULL_TREE;
   6777   bool mergeable_seen = false;
   6778   bool implicit_moved = false;
   6779   bool target_in_reduction_seen = false;
   6780 
   6781   bitmap_obstack_initialize (NULL);
   6782   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   6783   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   6784   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   6785   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
   6786   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   6787   bitmap_initialize (&map_head, &bitmap_default_obstack);
   6788   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
   6789   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
   6790   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
   6791      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
   6792   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
   6793   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
   6794 
   6795   if (ort & C_ORT_ACC)
   6796     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   6797       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
   6798 	{
   6799 	  oacc_async = true;
   6800 	  break;
   6801 	}
   6802 
   6803   for (pc = &clauses, c = clauses; c ; c = *pc)
   6804     {
   6805       bool remove = false;
   6806       bool field_ok = false;
   6807 
   6808       switch (OMP_CLAUSE_CODE (c))
   6809 	{
   6810 	case OMP_CLAUSE_SHARED:
   6811 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
   6812 	  goto check_dup_generic;
   6813 	case OMP_CLAUSE_PRIVATE:
   6814 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
   6815 	  goto check_dup_generic;
   6816 	case OMP_CLAUSE_REDUCTION:
   6817 	  if (reduction_seen == 0)
   6818 	    reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
   6819 	  else if (reduction_seen != -2
   6820 		   && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
   6821 					 ? -1 : 1))
   6822 	    {
   6823 	      error_at (OMP_CLAUSE_LOCATION (c),
   6824 			"%<inscan%> and non-%<inscan%> %<reduction%> clauses "
   6825 			"on the same construct");
   6826 	      reduction_seen = -2;
   6827 	    }
   6828 	  /* FALLTHRU */
   6829 	case OMP_CLAUSE_IN_REDUCTION:
   6830 	case OMP_CLAUSE_TASK_REDUCTION:
   6831 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
   6832 	  t = OMP_CLAUSE_DECL (c);
   6833 	  if (TREE_CODE (t) == TREE_LIST)
   6834 	    {
   6835 	      if (handle_omp_array_sections (c, ort))
   6836 		{
   6837 		  remove = true;
   6838 		  break;
   6839 		}
   6840 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   6841 		  && OMP_CLAUSE_REDUCTION_INSCAN (c))
   6842 		{
   6843 		  error_at (OMP_CLAUSE_LOCATION (c),
   6844 			    "%<inscan%> %<reduction%> clause with array "
   6845 			    "section");
   6846 		  remove = true;
   6847 		  break;
   6848 		}
   6849 	      if (TREE_CODE (t) == TREE_LIST)
   6850 		{
   6851 		  while (TREE_CODE (t) == TREE_LIST)
   6852 		    t = TREE_CHAIN (t);
   6853 		}
   6854 	      else
   6855 		{
   6856 		  gcc_assert (TREE_CODE (t) == MEM_REF);
   6857 		  t = TREE_OPERAND (t, 0);
   6858 		  if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   6859 		    t = TREE_OPERAND (t, 0);
   6860 		  if (TREE_CODE (t) == ADDR_EXPR
   6861 		      || INDIRECT_REF_P (t))
   6862 		    t = TREE_OPERAND (t, 0);
   6863 		}
   6864 	      tree n = omp_clause_decl_field (t);
   6865 	      if (n)
   6866 		t = n;
   6867 	      goto check_dup_generic_t;
   6868 	    }
   6869 	  if (oacc_async)
   6870 	    cxx_mark_addressable (t);
   6871 	  goto check_dup_generic;
   6872 	case OMP_CLAUSE_COPYPRIVATE:
   6873 	  copyprivate_seen = true;
   6874 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
   6875 	  goto check_dup_generic;
   6876 	case OMP_CLAUSE_COPYIN:
   6877 	  goto check_dup_generic;
   6878 	case OMP_CLAUSE_LINEAR:
   6879 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
   6880 	  t = OMP_CLAUSE_DECL (c);
   6881 	  if (ort != C_ORT_OMP_DECLARE_SIMD
   6882 	      && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
   6883 	    {
   6884 	      error_at (OMP_CLAUSE_LOCATION (c),
   6885 			"modifier should not be specified in %<linear%> "
   6886 			"clause on %<simd%> or %<for%> constructs");
   6887 	      OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
   6888 	    }
   6889 	  if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   6890 	      && !type_dependent_expression_p (t))
   6891 	    {
   6892 	      tree type = TREE_TYPE (t);
   6893 	      if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
   6894 		   || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
   6895 		  && !TYPE_REF_P (type))
   6896 		{
   6897 		  error_at (OMP_CLAUSE_LOCATION (c),
   6898 			    "linear clause with %qs modifier applied to "
   6899 			    "non-reference variable with %qT type",
   6900 			    OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
   6901 			    ? "ref" : "uval", TREE_TYPE (t));
   6902 		  remove = true;
   6903 		  break;
   6904 		}
   6905 	      if (TYPE_REF_P (type))
   6906 		type = TREE_TYPE (type);
   6907 	      if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
   6908 		{
   6909 		  if (!INTEGRAL_TYPE_P (type)
   6910 		      && !TYPE_PTR_P (type))
   6911 		    {
   6912 		      error_at (OMP_CLAUSE_LOCATION (c),
   6913 				"linear clause applied to non-integral "
   6914 				"non-pointer variable with %qT type",
   6915 				TREE_TYPE (t));
   6916 		      remove = true;
   6917 		      break;
   6918 		    }
   6919 		}
   6920 	    }
   6921 	  t = OMP_CLAUSE_LINEAR_STEP (c);
   6922 	  if (t == NULL_TREE)
   6923 	    t = integer_one_node;
   6924 	  if (t == error_mark_node)
   6925 	    {
   6926 	      remove = true;
   6927 	      break;
   6928 	    }
   6929 	  else if (!type_dependent_expression_p (t)
   6930 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t))
   6931 		   && (ort != C_ORT_OMP_DECLARE_SIMD
   6932 		       || TREE_CODE (t) != PARM_DECL
   6933 		       || !TYPE_REF_P (TREE_TYPE (t))
   6934 		       || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
   6935 	    {
   6936 	      error_at (OMP_CLAUSE_LOCATION (c),
   6937 			"linear step expression must be integral");
   6938 	      remove = true;
   6939 	      break;
   6940 	    }
   6941 	  else
   6942 	    {
   6943 	      t = mark_rvalue_use (t);
   6944 	      if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
   6945 		{
   6946 		  OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
   6947 		  goto check_dup_generic;
   6948 		}
   6949 	      if (!processing_template_decl
   6950 		  && (VAR_P (OMP_CLAUSE_DECL (c))
   6951 		      || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
   6952 		{
   6953 		  if (ort == C_ORT_OMP_DECLARE_SIMD)
   6954 		    {
   6955 		      t = maybe_constant_value (t);
   6956 		      if (TREE_CODE (t) != INTEGER_CST)
   6957 			{
   6958 			  error_at (OMP_CLAUSE_LOCATION (c),
   6959 				    "%<linear%> clause step %qE is neither "
   6960 				     "constant nor a parameter", t);
   6961 			  remove = true;
   6962 			  break;
   6963 			}
   6964 		    }
   6965 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   6966 		  tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
   6967 		  if (TYPE_REF_P (type))
   6968 		    type = TREE_TYPE (type);
   6969 		  if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
   6970 		    {
   6971 		      type = build_pointer_type (type);
   6972 		      tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
   6973 		      t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   6974 					   d, t);
   6975 		      t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
   6976 					   MINUS_EXPR, sizetype,
   6977 					   fold_convert (sizetype, t),
   6978 					   fold_convert (sizetype, d));
   6979 		      if (t == error_mark_node)
   6980 			{
   6981 			  remove = true;
   6982 			  break;
   6983 			}
   6984 		    }
   6985 		  else if (TYPE_PTR_P (type)
   6986 			   /* Can't multiply the step yet if *this
   6987 			      is still incomplete type.  */
   6988 			   && (ort != C_ORT_OMP_DECLARE_SIMD
   6989 			       || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
   6990 			       || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
   6991 			       || DECL_NAME (OMP_CLAUSE_DECL (c))
   6992 				  != this_identifier
   6993 			       || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
   6994 		    {
   6995 		      tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
   6996 		      t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   6997 					   d, t);
   6998 		      t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
   6999 					   MINUS_EXPR, sizetype,
   7000 					   fold_convert (sizetype, t),
   7001 					   fold_convert (sizetype, d));
   7002 		      if (t == error_mark_node)
   7003 			{
   7004 			  remove = true;
   7005 			  break;
   7006 			}
   7007 		    }
   7008 		  else
   7009 		    t = fold_convert (type, t);
   7010 		}
   7011 	      OMP_CLAUSE_LINEAR_STEP (c) = t;
   7012 	    }
   7013 	  goto check_dup_generic;
   7014 	check_dup_generic:
   7015 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   7016 	  if (t)
   7017 	    {
   7018 	      if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
   7019 		omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
   7020 	    }
   7021 	  else
   7022 	    t = OMP_CLAUSE_DECL (c);
   7023 	check_dup_generic_t:
   7024 	  if (t == current_class_ptr
   7025 	      && ((ort != C_ORT_OMP_DECLARE_SIMD && ort != C_ORT_ACC)
   7026 		  || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
   7027 		      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
   7028 	    {
   7029 	      error_at (OMP_CLAUSE_LOCATION (c),
   7030 			"%<this%> allowed in OpenMP only in %<declare simd%>"
   7031 			" clauses");
   7032 	      remove = true;
   7033 	      break;
   7034 	    }
   7035 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
   7036 	      && (!field_ok || TREE_CODE (t) != FIELD_DECL))
   7037 	    {
   7038 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7039 		break;
   7040 	      if (DECL_P (t))
   7041 		error_at (OMP_CLAUSE_LOCATION (c),
   7042 			  "%qD is not a variable in clause %qs", t,
   7043 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7044 	      else
   7045 		error_at (OMP_CLAUSE_LOCATION (c),
   7046 			  "%qE is not a variable in clause %qs", t,
   7047 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7048 	      remove = true;
   7049 	    }
   7050 	  else if ((ort == C_ORT_ACC
   7051 		    && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
   7052 		   || (ort == C_ORT_OMP
   7053 		       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   7054 			   || (OMP_CLAUSE_CODE (c)
   7055 			       == OMP_CLAUSE_USE_DEVICE_ADDR)))
   7056 		   || (ort == C_ORT_OMP_TARGET
   7057 		       && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
   7058 	    {
   7059 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   7060 		  && (bitmap_bit_p (&generic_head, DECL_UID (t))
   7061 		      || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
   7062 		{
   7063 		  error_at (OMP_CLAUSE_LOCATION (c),
   7064 			    "%qD appears more than once in data-sharing "
   7065 			    "clauses", t);
   7066 		  remove = true;
   7067 		  break;
   7068 		}
   7069 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
   7070 		target_in_reduction_seen = true;
   7071 	      if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   7072 		{
   7073 		  error_at (OMP_CLAUSE_LOCATION (c),
   7074 			    ort == C_ORT_ACC
   7075 			    ? "%qD appears more than once in reduction clauses"
   7076 			    : "%qD appears more than once in data clauses",
   7077 			    t);
   7078 		  remove = true;
   7079 		}
   7080 	      else
   7081 		bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   7082 	    }
   7083 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   7084 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   7085 		   || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
   7086 		   || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   7087 	    {
   7088 	      error_at (OMP_CLAUSE_LOCATION (c),
   7089 			"%qD appears more than once in data clauses", t);
   7090 	      remove = true;
   7091 	    }
   7092 	  else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   7093 		    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
   7094 		    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   7095 		   && bitmap_bit_p (&map_head, DECL_UID (t)))
   7096 	    {
   7097 	      if (ort == C_ORT_ACC)
   7098 		error_at (OMP_CLAUSE_LOCATION (c),
   7099 			  "%qD appears more than once in data clauses", t);
   7100 	      else
   7101 		error_at (OMP_CLAUSE_LOCATION (c),
   7102 			  "%qD appears both in data and map clauses", t);
   7103 	      remove = true;
   7104 	    }
   7105 	  else
   7106 	    bitmap_set_bit (&generic_head, DECL_UID (t));
   7107 	  if (!field_ok)
   7108 	    break;
   7109 	handle_field_decl:
   7110 	  if (!remove
   7111 	      && TREE_CODE (t) == FIELD_DECL
   7112 	      && t == OMP_CLAUSE_DECL (c))
   7113 	    {
   7114 	      OMP_CLAUSE_DECL (c)
   7115 		= omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
   7116 					   == OMP_CLAUSE_SHARED));
   7117 	      if (OMP_CLAUSE_DECL (c) == error_mark_node)
   7118 		remove = true;
   7119 	    }
   7120 	  break;
   7121 
   7122 	case OMP_CLAUSE_FIRSTPRIVATE:
   7123 	  if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
   7124 	    {
   7125 	    move_implicit:
   7126 	      implicit_moved = true;
   7127 	      /* Move firstprivate and map clauses with
   7128 		 OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
   7129 		 clauses chain.  */
   7130 	      tree cl1 = NULL_TREE, cl2 = NULL_TREE;
   7131 	      tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
   7132 	      while (*pc1)
   7133 		if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
   7134 		    && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
   7135 		  {
   7136 		    *pc3 = *pc1;
   7137 		    pc3 = &OMP_CLAUSE_CHAIN (*pc3);
   7138 		    *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   7139 		  }
   7140 		else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
   7141 			 && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
   7142 		  {
   7143 		    *pc2 = *pc1;
   7144 		    pc2 = &OMP_CLAUSE_CHAIN (*pc2);
   7145 		    *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   7146 		  }
   7147 		else
   7148 		  pc1 = &OMP_CLAUSE_CHAIN (*pc1);
   7149 	      *pc3 = NULL;
   7150 	      *pc2 = cl2;
   7151 	      *pc1 = cl1;
   7152 	      continue;
   7153 	    }
   7154 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   7155 	  if (t)
   7156 	    omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
   7157 	  else
   7158 	    t = OMP_CLAUSE_DECL (c);
   7159 	  if (ort != C_ORT_ACC && t == current_class_ptr)
   7160 	    {
   7161 	      error_at (OMP_CLAUSE_LOCATION (c),
   7162 			"%<this%> allowed in OpenMP only in %<declare simd%>"
   7163 			" clauses");
   7164 	      remove = true;
   7165 	      break;
   7166 	    }
   7167 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
   7168 	      && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
   7169 		  || TREE_CODE (t) != FIELD_DECL))
   7170 	    {
   7171 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7172 		break;
   7173 	      if (DECL_P (t))
   7174 		error_at (OMP_CLAUSE_LOCATION (c),
   7175 			  "%qD is not a variable in clause %<firstprivate%>",
   7176 			  t);
   7177 	      else
   7178 		error_at (OMP_CLAUSE_LOCATION (c),
   7179 			  "%qE is not a variable in clause %<firstprivate%>",
   7180 			  t);
   7181 	      remove = true;
   7182 	    }
   7183 	  else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   7184 		   && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
   7185 		   && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   7186 	    remove = true;
   7187 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   7188 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   7189 		   || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   7190 	    {
   7191 	      error_at (OMP_CLAUSE_LOCATION (c),
   7192 			"%qD appears more than once in data clauses", t);
   7193 	      remove = true;
   7194 	    }
   7195 	  else if (bitmap_bit_p (&map_head, DECL_UID (t)))
   7196 	    {
   7197 	      if (ort == C_ORT_ACC)
   7198 		error_at (OMP_CLAUSE_LOCATION (c),
   7199 			  "%qD appears more than once in data clauses", t);
   7200 	      else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   7201 		       && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
   7202 		/* Silently drop the clause.  */;
   7203 	      else
   7204 		error_at (OMP_CLAUSE_LOCATION (c),
   7205 			  "%qD appears both in data and map clauses", t);
   7206 	      remove = true;
   7207 	    }
   7208 	  else
   7209 	    bitmap_set_bit (&firstprivate_head, DECL_UID (t));
   7210 	  goto handle_field_decl;
   7211 
   7212 	case OMP_CLAUSE_LASTPRIVATE:
   7213 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   7214 	  if (t)
   7215 	    omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
   7216 	  else
   7217 	    t = OMP_CLAUSE_DECL (c);
   7218 	  if (ort != C_ORT_ACC && t == current_class_ptr)
   7219 	    {
   7220 	      error_at (OMP_CLAUSE_LOCATION (c),
   7221 			"%<this%> allowed in OpenMP only in %<declare simd%>"
   7222 			" clauses");
   7223 	      remove = true;
   7224 	      break;
   7225 	    }
   7226 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
   7227 	      && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
   7228 		  || TREE_CODE (t) != FIELD_DECL))
   7229 	    {
   7230 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7231 		break;
   7232 	      if (DECL_P (t))
   7233 		error_at (OMP_CLAUSE_LOCATION (c),
   7234 			  "%qD is not a variable in clause %<lastprivate%>",
   7235 			  t);
   7236 	      else
   7237 		error_at (OMP_CLAUSE_LOCATION (c),
   7238 			  "%qE is not a variable in clause %<lastprivate%>",
   7239 			  t);
   7240 	      remove = true;
   7241 	    }
   7242 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   7243 		   || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
   7244 	    {
   7245 	      error_at (OMP_CLAUSE_LOCATION (c),
   7246 			"%qD appears more than once in data clauses", t);
   7247 	      remove = true;
   7248 	    }
   7249 	  else
   7250 	    bitmap_set_bit (&lastprivate_head, DECL_UID (t));
   7251 	  goto handle_field_decl;
   7252 
   7253 	case OMP_CLAUSE_IF:
   7254 	  t = OMP_CLAUSE_IF_EXPR (c);
   7255 	  t = maybe_convert_cond (t);
   7256 	  if (t == error_mark_node)
   7257 	    remove = true;
   7258 	  else if (!processing_template_decl)
   7259 	    t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7260 	  OMP_CLAUSE_IF_EXPR (c) = t;
   7261 	  break;
   7262 
   7263 	case OMP_CLAUSE_FINAL:
   7264 	  t = OMP_CLAUSE_FINAL_EXPR (c);
   7265 	  t = maybe_convert_cond (t);
   7266 	  if (t == error_mark_node)
   7267 	    remove = true;
   7268 	  else if (!processing_template_decl)
   7269 	    t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7270 	  OMP_CLAUSE_FINAL_EXPR (c) = t;
   7271 	  break;
   7272 
   7273 	case OMP_CLAUSE_GANG:
   7274 	  /* Operand 1 is the gang static: argument.  */
   7275 	  t = OMP_CLAUSE_OPERAND (c, 1);
   7276 	  if (t != NULL_TREE)
   7277 	    {
   7278 	      if (t == error_mark_node)
   7279 		remove = true;
   7280 	      else if (!type_dependent_expression_p (t)
   7281 		       && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7282 		{
   7283 		  error_at (OMP_CLAUSE_LOCATION (c),
   7284 			    "%<gang%> static expression must be integral");
   7285 		  remove = true;
   7286 		}
   7287 	      else
   7288 		{
   7289 		  t = mark_rvalue_use (t);
   7290 		  if (!processing_template_decl)
   7291 		    {
   7292 		      t = maybe_constant_value (t);
   7293 		      if (TREE_CODE (t) == INTEGER_CST
   7294 			  && tree_int_cst_sgn (t) != 1
   7295 			  && t != integer_minus_one_node)
   7296 			{
   7297 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7298 				      "%<gang%> static value must be "
   7299 				      "positive");
   7300 			  t = integer_one_node;
   7301 			}
   7302 		      t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7303 		    }
   7304 		}
   7305 	      OMP_CLAUSE_OPERAND (c, 1) = t;
   7306 	    }
   7307 	  /* Check operand 0, the num argument.  */
   7308 	  /* FALLTHRU */
   7309 
   7310 	case OMP_CLAUSE_WORKER:
   7311 	case OMP_CLAUSE_VECTOR:
   7312 	  if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
   7313 	    break;
   7314 	  /* FALLTHRU */
   7315 
   7316 	case OMP_CLAUSE_NUM_TASKS:
   7317 	case OMP_CLAUSE_NUM_TEAMS:
   7318 	case OMP_CLAUSE_NUM_THREADS:
   7319 	case OMP_CLAUSE_NUM_GANGS:
   7320 	case OMP_CLAUSE_NUM_WORKERS:
   7321 	case OMP_CLAUSE_VECTOR_LENGTH:
   7322 	  t = OMP_CLAUSE_OPERAND (c, 0);
   7323 	  if (t == error_mark_node)
   7324 	    remove = true;
   7325 	  else if (!type_dependent_expression_p (t)
   7326 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7327 	    {
   7328 	     switch (OMP_CLAUSE_CODE (c))
   7329 		{
   7330 		case OMP_CLAUSE_GANG:
   7331 		  error_at (OMP_CLAUSE_LOCATION (c),
   7332 			    "%<gang%> num expression must be integral"); break;
   7333 		case OMP_CLAUSE_VECTOR:
   7334 		  error_at (OMP_CLAUSE_LOCATION (c),
   7335 			    "%<vector%> length expression must be integral");
   7336 		  break;
   7337 		case OMP_CLAUSE_WORKER:
   7338 		  error_at (OMP_CLAUSE_LOCATION (c),
   7339 			    "%<worker%> num expression must be integral");
   7340 		  break;
   7341 		default:
   7342 		  error_at (OMP_CLAUSE_LOCATION (c),
   7343 			    "%qs expression must be integral",
   7344 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7345 		}
   7346 	      remove = true;
   7347 	    }
   7348 	  else
   7349 	    {
   7350 	      t = mark_rvalue_use (t);
   7351 	      if (!processing_template_decl)
   7352 		{
   7353 		  t = maybe_constant_value (t);
   7354 		  if (TREE_CODE (t) == INTEGER_CST
   7355 		      && tree_int_cst_sgn (t) != 1)
   7356 		    {
   7357 		      switch (OMP_CLAUSE_CODE (c))
   7358 			{
   7359 			case OMP_CLAUSE_GANG:
   7360 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7361 				      "%<gang%> num value must be positive");
   7362 			  break;
   7363 			case OMP_CLAUSE_VECTOR:
   7364 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7365 				      "%<vector%> length value must be "
   7366 				      "positive");
   7367 			  break;
   7368 			case OMP_CLAUSE_WORKER:
   7369 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7370 				      "%<worker%> num value must be "
   7371 				      "positive");
   7372 			  break;
   7373 			default:
   7374 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7375 				      "%qs value must be positive",
   7376 				      omp_clause_code_name
   7377 				      [OMP_CLAUSE_CODE (c)]);
   7378 			}
   7379 		      t = integer_one_node;
   7380 		    }
   7381 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7382 		}
   7383 	      OMP_CLAUSE_OPERAND (c, 0) = t;
   7384 	    }
   7385 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
   7386 	      && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
   7387 	      && !remove)
   7388 	    {
   7389 	      t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
   7390 	      if (t == error_mark_node)
   7391 		remove = true;
   7392 	      else if (!type_dependent_expression_p (t)
   7393 		       && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7394 		{
   7395 		  error_at (OMP_CLAUSE_LOCATION (c),
   7396 			    "%qs expression must be integral",
   7397 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7398 		  remove = true;
   7399 		}
   7400 	      else
   7401 		{
   7402 		  t = mark_rvalue_use (t);
   7403 		  if (!processing_template_decl)
   7404 		    {
   7405 		      t = maybe_constant_value (t);
   7406 		      if (TREE_CODE (t) == INTEGER_CST
   7407 			  && tree_int_cst_sgn (t) != 1)
   7408 			{
   7409 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7410 				      "%qs value must be positive",
   7411 				      omp_clause_code_name
   7412 				      [OMP_CLAUSE_CODE (c)]);
   7413 			  t = NULL_TREE;
   7414 			}
   7415 		      else
   7416 			t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7417 		      tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
   7418 		      if (t
   7419 			  && TREE_CODE (t) == INTEGER_CST
   7420 			  && TREE_CODE (upper) == INTEGER_CST
   7421 			  && tree_int_cst_lt (upper, t))
   7422 			{
   7423 			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7424 				      "%<num_teams%> lower bound %qE bigger "
   7425 				      "than upper bound %qE", t, upper);
   7426 			  t = NULL_TREE;
   7427 			}
   7428 		    }
   7429 		  OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
   7430 		}
   7431 	    }
   7432 	  break;
   7433 
   7434 	case OMP_CLAUSE_SCHEDULE:
   7435 	  t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
   7436 	  if (t == NULL)
   7437 	    ;
   7438 	  else if (t == error_mark_node)
   7439 	    remove = true;
   7440 	  else if (!type_dependent_expression_p (t)
   7441 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7442 	    {
   7443 	      error_at (OMP_CLAUSE_LOCATION (c),
   7444 			"schedule chunk size expression must be integral");
   7445 	      remove = true;
   7446 	    }
   7447 	  else
   7448 	    {
   7449 	      t = mark_rvalue_use (t);
   7450 	      if (!processing_template_decl)
   7451 		{
   7452 		  t = maybe_constant_value (t);
   7453 		  if (TREE_CODE (t) == INTEGER_CST
   7454 		      && tree_int_cst_sgn (t) != 1)
   7455 		  {
   7456 		    warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7457 			      "chunk size value must be positive");
   7458 		    t = integer_one_node;
   7459 		  }
   7460 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7461 		}
   7462 	      OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
   7463 	    }
   7464 	  if (!remove)
   7465 	    schedule_seen = true;
   7466 	  break;
   7467 
   7468 	case OMP_CLAUSE_SIMDLEN:
   7469 	case OMP_CLAUSE_SAFELEN:
   7470 	  t = OMP_CLAUSE_OPERAND (c, 0);
   7471 	  if (t == error_mark_node)
   7472 	    remove = true;
   7473 	  else if (!type_dependent_expression_p (t)
   7474 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7475 	    {
   7476 	      error_at (OMP_CLAUSE_LOCATION (c),
   7477 			"%qs length expression must be integral",
   7478 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7479 	      remove = true;
   7480 	    }
   7481 	  else
   7482 	    {
   7483 	      t = mark_rvalue_use (t);
   7484 	      if (!processing_template_decl)
   7485 		{
   7486 		  t = maybe_constant_value (t);
   7487 		  if (TREE_CODE (t) != INTEGER_CST
   7488 		      || tree_int_cst_sgn (t) != 1)
   7489 		    {
   7490 		      error_at (OMP_CLAUSE_LOCATION (c),
   7491 				"%qs length expression must be positive "
   7492 				"constant integer expression",
   7493 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7494 		      remove = true;
   7495 		    }
   7496 		}
   7497 	      OMP_CLAUSE_OPERAND (c, 0) = t;
   7498 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
   7499 		safelen = c;
   7500 	    }
   7501 	  break;
   7502 
   7503 	case OMP_CLAUSE_ASYNC:
   7504 	  t = OMP_CLAUSE_ASYNC_EXPR (c);
   7505 	  if (t == error_mark_node)
   7506 	    remove = true;
   7507 	  else if (!type_dependent_expression_p (t)
   7508 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7509 	    {
   7510 	      error_at (OMP_CLAUSE_LOCATION (c),
   7511 			"%<async%> expression must be integral");
   7512 	      remove = true;
   7513 	    }
   7514 	  else
   7515 	    {
   7516 	      t = mark_rvalue_use (t);
   7517 	      if (!processing_template_decl)
   7518 		t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7519 	      OMP_CLAUSE_ASYNC_EXPR (c) = t;
   7520 	    }
   7521 	  break;
   7522 
   7523 	case OMP_CLAUSE_WAIT:
   7524 	  t = OMP_CLAUSE_WAIT_EXPR (c);
   7525 	  if (t == error_mark_node)
   7526 	    remove = true;
   7527 	  else if (!processing_template_decl)
   7528 	    t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7529 	  OMP_CLAUSE_WAIT_EXPR (c) = t;
   7530 	  break;
   7531 
   7532 	case OMP_CLAUSE_THREAD_LIMIT:
   7533 	  t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
   7534 	  if (t == error_mark_node)
   7535 	    remove = true;
   7536 	  else if (!type_dependent_expression_p (t)
   7537 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7538 	    {
   7539 	      error_at (OMP_CLAUSE_LOCATION (c),
   7540 			"%<thread_limit%> expression must be integral");
   7541 	      remove = true;
   7542 	    }
   7543 	  else
   7544 	    {
   7545 	      t = mark_rvalue_use (t);
   7546 	      if (!processing_template_decl)
   7547 		{
   7548 		  t = maybe_constant_value (t);
   7549 		  if (TREE_CODE (t) == INTEGER_CST
   7550 		      && tree_int_cst_sgn (t) != 1)
   7551 		    {
   7552 		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7553 				  "%<thread_limit%> value must be positive");
   7554 		      t = integer_one_node;
   7555 		    }
   7556 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7557 		}
   7558 	      OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
   7559 	    }
   7560 	  break;
   7561 
   7562 	case OMP_CLAUSE_DEVICE:
   7563 	  t = OMP_CLAUSE_DEVICE_ID (c);
   7564 	  if (t == error_mark_node)
   7565 	    remove = true;
   7566 	  else if (!type_dependent_expression_p (t)
   7567 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7568 	    {
   7569 	      error_at (OMP_CLAUSE_LOCATION (c),
   7570 			"%<device%> id must be integral");
   7571 	      remove = true;
   7572 	    }
   7573 	  else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
   7574 		   && TREE_CODE (t) == INTEGER_CST
   7575 		   && !integer_onep (t))
   7576 	    {
   7577 	      error_at (OMP_CLAUSE_LOCATION (c),
   7578 			"the %<device%> clause expression must evaluate to "
   7579 			"%<1%>");
   7580 	      remove = true;
   7581 	    }
   7582 	  else
   7583 	    {
   7584 	      t = mark_rvalue_use (t);
   7585 	      if (!processing_template_decl)
   7586 		t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7587 	      OMP_CLAUSE_DEVICE_ID (c) = t;
   7588 	    }
   7589 	  break;
   7590 
   7591 	case OMP_CLAUSE_DIST_SCHEDULE:
   7592 	  t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
   7593 	  if (t == NULL)
   7594 	    ;
   7595 	  else if (t == error_mark_node)
   7596 	    remove = true;
   7597 	  else if (!type_dependent_expression_p (t)
   7598 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7599 	    {
   7600 	      error_at (OMP_CLAUSE_LOCATION (c),
   7601 			"%<dist_schedule%> chunk size expression must be "
   7602 			"integral");
   7603 	      remove = true;
   7604 	    }
   7605 	  else
   7606 	    {
   7607 	      t = mark_rvalue_use (t);
   7608  	      if (!processing_template_decl)
   7609 		t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7610 	      OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
   7611 	    }
   7612 	  break;
   7613 
   7614 	case OMP_CLAUSE_ALIGNED:
   7615 	  t = OMP_CLAUSE_DECL (c);
   7616 	  if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
   7617 	    {
   7618 	      error_at (OMP_CLAUSE_LOCATION (c),
   7619 			"%<this%> allowed in OpenMP only in %<declare simd%>"
   7620 			" clauses");
   7621 	      remove = true;
   7622 	      break;
   7623 	    }
   7624 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   7625 	    {
   7626 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7627 		break;
   7628 	      if (DECL_P (t))
   7629 		error_at (OMP_CLAUSE_LOCATION (c),
   7630 			  "%qD is not a variable in %<aligned%> clause", t);
   7631 	      else
   7632 		error_at (OMP_CLAUSE_LOCATION (c),
   7633 			  "%qE is not a variable in %<aligned%> clause", t);
   7634 	      remove = true;
   7635 	    }
   7636 	  else if (!type_dependent_expression_p (t)
   7637 		   && !TYPE_PTR_P (TREE_TYPE (t))
   7638 		   && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
   7639 		   && (!TYPE_REF_P (TREE_TYPE (t))
   7640 		       || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
   7641 			   && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
   7642 			       != ARRAY_TYPE))))
   7643 	    {
   7644 	      error_at (OMP_CLAUSE_LOCATION (c),
   7645 			"%qE in %<aligned%> clause is neither a pointer nor "
   7646 			"an array nor a reference to pointer or array", t);
   7647 	      remove = true;
   7648 	    }
   7649 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   7650 	    {
   7651 	      error_at (OMP_CLAUSE_LOCATION (c),
   7652 			"%qD appears more than once in %<aligned%> clauses",
   7653 			t);
   7654 	      remove = true;
   7655 	    }
   7656 	  else
   7657 	    bitmap_set_bit (&aligned_head, DECL_UID (t));
   7658 	  t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
   7659 	  if (t == error_mark_node)
   7660 	    remove = true;
   7661 	  else if (t == NULL_TREE)
   7662 	    break;
   7663 	  else if (!type_dependent_expression_p (t)
   7664 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   7665 	    {
   7666 	      error_at (OMP_CLAUSE_LOCATION (c),
   7667 			"%<aligned%> clause alignment expression must "
   7668 			"be integral");
   7669 	      remove = true;
   7670 	    }
   7671 	  else
   7672 	    {
   7673 	      t = mark_rvalue_use (t);
   7674 	      if (!processing_template_decl)
   7675 		{
   7676 		  t = maybe_constant_value (t);
   7677 		  if (TREE_CODE (t) != INTEGER_CST
   7678 		      || tree_int_cst_sgn (t) != 1)
   7679 		    {
   7680 		      error_at (OMP_CLAUSE_LOCATION (c),
   7681 				"%<aligned%> clause alignment expression must "
   7682 				"be positive constant integer expression");
   7683 		      remove = true;
   7684 		    }
   7685 		  else
   7686 		    t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   7687 		}
   7688 	      OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
   7689 	    }
   7690 	  break;
   7691 
   7692 	case OMP_CLAUSE_NONTEMPORAL:
   7693 	  t = OMP_CLAUSE_DECL (c);
   7694 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   7695 	    {
   7696 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7697 		break;
   7698 	      if (DECL_P (t))
   7699 		error_at (OMP_CLAUSE_LOCATION (c),
   7700 			  "%qD is not a variable in %<nontemporal%> clause",
   7701 			  t);
   7702 	      else
   7703 		error_at (OMP_CLAUSE_LOCATION (c),
   7704 			  "%qE is not a variable in %<nontemporal%> clause",
   7705 			  t);
   7706 	      remove = true;
   7707 	    }
   7708 	  else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   7709 	    {
   7710 	      error_at (OMP_CLAUSE_LOCATION (c),
   7711 			"%qD appears more than once in %<nontemporal%> "
   7712 			"clauses", t);
   7713 	      remove = true;
   7714 	    }
   7715 	  else
   7716 	    bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   7717 	  break;
   7718 
   7719 	case OMP_CLAUSE_ALLOCATE:
   7720 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   7721 	  if (t)
   7722 	    omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
   7723 	  else
   7724 	    t = OMP_CLAUSE_DECL (c);
   7725 	  if (t == current_class_ptr)
   7726 	    {
   7727 	      error_at (OMP_CLAUSE_LOCATION (c),
   7728 			"%<this%> not allowed in %<allocate%> clause");
   7729 	      remove = true;
   7730 	      break;
   7731 	    }
   7732 	  if (!VAR_P (t)
   7733 	      && TREE_CODE (t) != PARM_DECL
   7734 	      && TREE_CODE (t) != FIELD_DECL)
   7735 	    {
   7736 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7737 		break;
   7738 	      if (DECL_P (t))
   7739 		error_at (OMP_CLAUSE_LOCATION (c),
   7740 			  "%qD is not a variable in %<allocate%> clause", t);
   7741 	      else
   7742 		error_at (OMP_CLAUSE_LOCATION (c),
   7743 			  "%qE is not a variable in %<allocate%> clause", t);
   7744 	      remove = true;
   7745 	    }
   7746 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   7747 	    {
   7748 	      warning_at (OMP_CLAUSE_LOCATION (c), 0,
   7749 			"%qD appears more than once in %<allocate%> clauses",
   7750 			t);
   7751 	      remove = true;
   7752 	    }
   7753 	  else
   7754 	    {
   7755 	      bitmap_set_bit (&aligned_head, DECL_UID (t));
   7756 	      allocate_seen = true;
   7757 	    }
   7758 	  tree allocator, align;
   7759 	  align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
   7760 	  if (error_operand_p (align))
   7761 	    {
   7762 	      remove = true;
   7763 	      break;
   7764 	    }
   7765 	  if (align)
   7766 	    {
   7767 	      if (!type_dependent_expression_p (align)
   7768 		  && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
   7769 		{
   7770 		  error_at (OMP_CLAUSE_LOCATION (c),
   7771 			    "%<allocate%> clause %<align%> modifier "
   7772 			    "argument needs to be positive constant "
   7773 			    "power of two integer expression");
   7774 		  remove = true;
   7775 		}
   7776 	      else
   7777 		{
   7778 		  align = mark_rvalue_use (align);
   7779 		  if (!processing_template_decl)
   7780 		    {
   7781 		      align = maybe_constant_value (align);
   7782 		      if (TREE_CODE (align) != INTEGER_CST
   7783 			  || !tree_fits_uhwi_p (align)
   7784 			  || !integer_pow2p (align))
   7785 			{
   7786 			  error_at (OMP_CLAUSE_LOCATION (c),
   7787 				    "%<allocate%> clause %<align%> modifier "
   7788 				    "argument needs to be positive constant "
   7789 				    "power of two integer expression");
   7790 			  remove = true;
   7791 			}
   7792 		    }
   7793 		}
   7794 	      OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
   7795 	    }
   7796 	  allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
   7797 	  if (error_operand_p (allocator))
   7798 	    {
   7799 	      remove = true;
   7800 	      break;
   7801 	    }
   7802 	  if (allocator == NULL_TREE)
   7803 	    goto handle_field_decl;
   7804 	  tree allocatort;
   7805 	  allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
   7806 	  if (!type_dependent_expression_p (allocator)
   7807 	      && (TREE_CODE (allocatort) != ENUMERAL_TYPE
   7808 		  || TYPE_NAME (allocatort) == NULL_TREE
   7809 		  || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
   7810 		  || (DECL_NAME (TYPE_NAME (allocatort))
   7811 		      != get_identifier ("omp_allocator_handle_t"))
   7812 		  || (TYPE_CONTEXT (allocatort)
   7813 		      != DECL_CONTEXT (global_namespace))))
   7814 	    {
   7815 	      error_at (OMP_CLAUSE_LOCATION (c),
   7816 			"%<allocate%> clause allocator expression has "
   7817 			"type %qT rather than %<omp_allocator_handle_t%>",
   7818 			TREE_TYPE (allocator));
   7819 	      remove = true;
   7820 	      break;
   7821 	    }
   7822 	  else
   7823 	    {
   7824 	      allocator = mark_rvalue_use (allocator);
   7825 	      if (!processing_template_decl)
   7826 		allocator = maybe_constant_value (allocator);
   7827 	      OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
   7828 	    }
   7829 	  goto handle_field_decl;
   7830 
   7831 	case OMP_CLAUSE_DEPEND:
   7832 	  t = OMP_CLAUSE_DECL (c);
   7833 	  if (t == NULL_TREE)
   7834 	    {
   7835 	      gcc_assert (OMP_CLAUSE_DEPEND_KIND (c)
   7836 			  == OMP_CLAUSE_DEPEND_SOURCE);
   7837 	      break;
   7838 	    }
   7839 	  if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK)
   7840 	    {
   7841 	      if (cp_finish_omp_clause_depend_sink (c))
   7842 		remove = true;
   7843 	      break;
   7844 	    }
   7845 	  /* FALLTHRU */
   7846 	case OMP_CLAUSE_AFFINITY:
   7847 	  t = OMP_CLAUSE_DECL (c);
   7848 	  if (TREE_CODE (t) == TREE_LIST
   7849 	      && TREE_PURPOSE (t)
   7850 	      && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
   7851 	    {
   7852 	      if (TREE_PURPOSE (t) != last_iterators)
   7853 		last_iterators_remove
   7854 		  = cp_omp_finish_iterators (TREE_PURPOSE (t));
   7855 	      last_iterators = TREE_PURPOSE (t);
   7856 	      t = TREE_VALUE (t);
   7857 	      if (last_iterators_remove)
   7858 		t = error_mark_node;
   7859 	    }
   7860 	  else
   7861 	    last_iterators = NULL_TREE;
   7862 
   7863 	  if (TREE_CODE (t) == TREE_LIST)
   7864 	    {
   7865 	      if (handle_omp_array_sections (c, ort))
   7866 		remove = true;
   7867 	      else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   7868 		       && (OMP_CLAUSE_DEPEND_KIND (c)
   7869 			   == OMP_CLAUSE_DEPEND_DEPOBJ))
   7870 		{
   7871 		  error_at (OMP_CLAUSE_LOCATION (c),
   7872 			    "%<depend%> clause with %<depobj%> dependence "
   7873 			    "type on array section");
   7874 		  remove = true;
   7875 		}
   7876 	      break;
   7877 	    }
   7878 	  if (t == error_mark_node)
   7879 	    remove = true;
   7880 	  else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   7881 	    break;
   7882 	  else if (!lvalue_p (t))
   7883 	    {
   7884 	      if (DECL_P (t))
   7885 		error_at (OMP_CLAUSE_LOCATION (c),
   7886 			  "%qD is not lvalue expression nor array section "
   7887 			  "in %qs clause", t,
   7888 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7889 	      else
   7890 		error_at (OMP_CLAUSE_LOCATION (c),
   7891 			  "%qE is not lvalue expression nor array section "
   7892 			  "in %qs clause", t,
   7893 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7894 	      remove = true;
   7895 	    }
   7896 	  else if (TREE_CODE (t) == COMPONENT_REF
   7897 		   && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
   7898 		   && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
   7899 	    {
   7900 	      error_at (OMP_CLAUSE_LOCATION (c),
   7901 			"bit-field %qE in %qs clause", t,
   7902 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   7903 	      remove = true;
   7904 	    }
   7905 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   7906 		   && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   7907 	    {
   7908 	      if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
   7909 				     ? TREE_TYPE (TREE_TYPE (t))
   7910 				     : TREE_TYPE (t)))
   7911 		{
   7912 		  error_at (OMP_CLAUSE_LOCATION (c),
   7913 			    "%qE does not have %<omp_depend_t%> type in "
   7914 			    "%<depend%> clause with %<depobj%> dependence "
   7915 			    "type", t);
   7916 		  remove = true;
   7917 		}
   7918 	    }
   7919 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   7920 		   && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
   7921 					? TREE_TYPE (TREE_TYPE (t))
   7922 					: TREE_TYPE (t)))
   7923 	    {
   7924 	      error_at (OMP_CLAUSE_LOCATION (c),
   7925 			"%qE should not have %<omp_depend_t%> type in "
   7926 			"%<depend%> clause with dependence type other than "
   7927 			"%<depobj%>", t);
   7928 	      remove = true;
   7929 	    }
   7930 	  if (!remove)
   7931 	    {
   7932 	      tree addr = cp_build_addr_expr (t, tf_warning_or_error);
   7933 	      if (addr == error_mark_node)
   7934 		remove = true;
   7935 	      else
   7936 		{
   7937 		  t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
   7938 					     addr, RO_UNARY_STAR,
   7939 					     tf_warning_or_error);
   7940 		  if (t == error_mark_node)
   7941 		    remove = true;
   7942 		  else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
   7943 			   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
   7944 			   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
   7945 			       == TREE_VEC))
   7946 		    TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
   7947 		  else
   7948 		    OMP_CLAUSE_DECL (c) = t;
   7949 		}
   7950 	    }
   7951 	  break;
   7952 	case OMP_CLAUSE_DETACH:
   7953 	  t = OMP_CLAUSE_DECL (c);
   7954 	  if (detach_seen)
   7955 	    {
   7956 	      error_at (OMP_CLAUSE_LOCATION (c),
   7957 			"too many %qs clauses on a task construct",
   7958 			"detach");
   7959 	      remove = true;
   7960 	      break;
   7961 	    }
   7962 	  else if (error_operand_p (t))
   7963 	    {
   7964 	      remove = true;
   7965 	      break;
   7966 	    }
   7967 	  else
   7968 	    {
   7969 	      tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   7970 	      if (!type_dependent_expression_p (t)
   7971 		  && (!INTEGRAL_TYPE_P (type)
   7972 		      || TREE_CODE (type) != ENUMERAL_TYPE
   7973 		      || TYPE_NAME (type) == NULL_TREE
   7974 		      || (DECL_NAME (TYPE_NAME (type))
   7975 			  != get_identifier ("omp_event_handle_t"))))
   7976 		{
   7977 		  error_at (OMP_CLAUSE_LOCATION (c),
   7978 			    "%<detach%> clause event handle "
   7979 			    "has type %qT rather than "
   7980 			    "%<omp_event_handle_t%>",
   7981 			    type);
   7982 		  remove = true;
   7983 		}
   7984 	      detach_seen = c;
   7985 	      cxx_mark_addressable (t);
   7986 	    }
   7987 	  break;
   7988 
   7989 	case OMP_CLAUSE_MAP:
   7990 	  if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
   7991 	    goto move_implicit;
   7992 	  /* FALLTHRU */
   7993 	case OMP_CLAUSE_TO:
   7994 	case OMP_CLAUSE_FROM:
   7995 	case OMP_CLAUSE__CACHE_:
   7996 	  t = OMP_CLAUSE_DECL (c);
   7997 	  if (TREE_CODE (t) == TREE_LIST)
   7998 	    {
   7999 	      if (handle_omp_array_sections (c, ort))
   8000 		remove = true;
   8001 	      else
   8002 		{
   8003 		  t = OMP_CLAUSE_DECL (c);
   8004 		  if (TREE_CODE (t) != TREE_LIST
   8005 		      && !type_dependent_expression_p (t)
   8006 		      && !cp_omp_mappable_type (TREE_TYPE (t)))
   8007 		    {
   8008 		      error_at (OMP_CLAUSE_LOCATION (c),
   8009 				"array section does not have mappable type "
   8010 				"in %qs clause",
   8011 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8012 		      cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
   8013 		      remove = true;
   8014 		    }
   8015 		  while (TREE_CODE (t) == ARRAY_REF)
   8016 		    t = TREE_OPERAND (t, 0);
   8017 		  if (TREE_CODE (t) == COMPONENT_REF
   8018 		      && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   8019 		    {
   8020 		      do
   8021 			{
   8022 			  t = TREE_OPERAND (t, 0);
   8023 			  if (REFERENCE_REF_P (t))
   8024 			    t = TREE_OPERAND (t, 0);
   8025 			  if (TREE_CODE (t) == MEM_REF
   8026 			      || TREE_CODE (t) == INDIRECT_REF)
   8027 			    {
   8028 			      t = TREE_OPERAND (t, 0);
   8029 			      STRIP_NOPS (t);
   8030 			      if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   8031 				t = TREE_OPERAND (t, 0);
   8032 			    }
   8033 			}
   8034 		      while (TREE_CODE (t) == COMPONENT_REF
   8035 			     || TREE_CODE (t) == ARRAY_REF);
   8036 
   8037 		      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8038 			  && OMP_CLAUSE_MAP_IMPLICIT (c)
   8039 			  && (bitmap_bit_p (&map_head, DECL_UID (t))
   8040 			      || bitmap_bit_p (&map_field_head, DECL_UID (t))
   8041 			      || bitmap_bit_p (&map_firstprivate_head,
   8042 					       DECL_UID (t))))
   8043 			{
   8044 			  remove = true;
   8045 			  break;
   8046 			}
   8047 		      if (bitmap_bit_p (&map_field_head, DECL_UID (t)))
   8048 			break;
   8049 		      if (bitmap_bit_p (&map_head, DECL_UID (t)))
   8050 			{
   8051 			  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   8052 			    error_at (OMP_CLAUSE_LOCATION (c),
   8053 				      "%qD appears more than once in motion"
   8054 				      " clauses", t);
   8055 			  else if (ort == C_ORT_ACC)
   8056 			    error_at (OMP_CLAUSE_LOCATION (c),
   8057 				      "%qD appears more than once in data"
   8058 				      " clauses", t);
   8059 			  else
   8060 			    error_at (OMP_CLAUSE_LOCATION (c),
   8061 				      "%qD appears more than once in map"
   8062 				      " clauses", t);
   8063 			  remove = true;
   8064 			}
   8065 		      else
   8066 			{
   8067 			  bitmap_set_bit (&map_head, DECL_UID (t));
   8068 			  bitmap_set_bit (&map_field_head, DECL_UID (t));
   8069 			}
   8070 		    }
   8071 		}
   8072 	      if (cp_oacc_check_attachments (c))
   8073 		remove = true;
   8074 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8075 		  && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   8076 		      || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   8077 		/* In this case, we have a single array element which is a
   8078 		   pointer, and we already set OMP_CLAUSE_SIZE in
   8079 		   handle_omp_array_sections above.  For attach/detach clauses,
   8080 		   reset the OMP_CLAUSE_SIZE (representing a bias) to zero
   8081 		   here.  */
   8082 		OMP_CLAUSE_SIZE (c) = size_zero_node;
   8083 	      break;
   8084 	    }
   8085 	  if (t == error_mark_node)
   8086 	    {
   8087 	      remove = true;
   8088 	      break;
   8089 	    }
   8090 	  /* OpenACC attach / detach clauses must be pointers.  */
   8091 	  if (cp_oacc_check_attachments (c))
   8092 	    {
   8093 	      remove = true;
   8094 	      break;
   8095 	    }
   8096 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8097 	      && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   8098 		  || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   8099 	    /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
   8100 	       bias) to zero here, so it is not set erroneously to the pointer
   8101 	       size later on in gimplify.cc.  */
   8102 	    OMP_CLAUSE_SIZE (c) = size_zero_node;
   8103 	  if (REFERENCE_REF_P (t)
   8104 	      && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
   8105 	    {
   8106 	      t = TREE_OPERAND (t, 0);
   8107 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8108 		  && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
   8109 		OMP_CLAUSE_DECL (c) = t;
   8110 	    }
   8111 	  while (TREE_CODE (t) == INDIRECT_REF
   8112 		 || TREE_CODE (t) == ARRAY_REF)
   8113 	    {
   8114 	      t = TREE_OPERAND (t, 0);
   8115 	      STRIP_NOPS (t);
   8116 	      if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   8117 		t = TREE_OPERAND (t, 0);
   8118 	    }
   8119 	  while (TREE_CODE (t) == COMPOUND_EXPR)
   8120 	    {
   8121 	      t = TREE_OPERAND (t, 1);
   8122 	      STRIP_NOPS (t);
   8123 	    }
   8124 	  indir_component_ref_p = false;
   8125 	  if (TREE_CODE (t) == COMPONENT_REF
   8126 	      && (TREE_CODE (TREE_OPERAND (t, 0)) == INDIRECT_REF
   8127 		  || TREE_CODE (TREE_OPERAND (t, 0)) == ARRAY_REF))
   8128 	    {
   8129 	      t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
   8130 	      indir_component_ref_p = true;
   8131 	      STRIP_NOPS (t);
   8132 	      if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   8133 		t = TREE_OPERAND (t, 0);
   8134 	    }
   8135 	  if (TREE_CODE (t) == COMPONENT_REF
   8136 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_)
   8137 	    {
   8138 	      if (type_dependent_expression_p (t))
   8139 		break;
   8140 	      if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
   8141 		  && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
   8142 		{
   8143 		  error_at (OMP_CLAUSE_LOCATION (c),
   8144 			    "bit-field %qE in %qs clause",
   8145 			    t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8146 		  remove = true;
   8147 		}
   8148 	      else if (!cp_omp_mappable_type (TREE_TYPE (t)))
   8149 		{
   8150 		  error_at (OMP_CLAUSE_LOCATION (c),
   8151 			    "%qE does not have a mappable type in %qs clause",
   8152 			    t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8153 		  cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
   8154 		  remove = true;
   8155 		}
   8156 	      while (TREE_CODE (t) == COMPONENT_REF)
   8157 		{
   8158 		  if (TREE_TYPE (TREE_OPERAND (t, 0))
   8159 		      && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
   8160 			  == UNION_TYPE))
   8161 		    {
   8162 		      error_at (OMP_CLAUSE_LOCATION (c),
   8163 				"%qE is a member of a union", t);
   8164 		      remove = true;
   8165 		      break;
   8166 		    }
   8167 		  t = TREE_OPERAND (t, 0);
   8168 		  if (TREE_CODE (t) == MEM_REF)
   8169 		    {
   8170 		      if (maybe_ne (mem_ref_offset (t), 0))
   8171 			error_at (OMP_CLAUSE_LOCATION (c),
   8172 				  "cannot dereference %qE in %qs clause", t,
   8173 				  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8174 		      else
   8175 			t = TREE_OPERAND (t, 0);
   8176 		    }
   8177 		  while (TREE_CODE (t) == MEM_REF
   8178 			 || TREE_CODE (t) == INDIRECT_REF
   8179 			 || TREE_CODE (t) == ARRAY_REF)
   8180 		    {
   8181 		      t = TREE_OPERAND (t, 0);
   8182 		      STRIP_NOPS (t);
   8183 		      if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   8184 			t = TREE_OPERAND (t, 0);
   8185 		    }
   8186 		}
   8187 	      if (remove)
   8188 		break;
   8189 	      if (REFERENCE_REF_P (t))
   8190 		t = TREE_OPERAND (t, 0);
   8191 	      if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   8192 		{
   8193 		  if (bitmap_bit_p (&map_field_head, DECL_UID (t))
   8194 		      || (ort != C_ORT_ACC
   8195 			  && bitmap_bit_p (&map_head, DECL_UID (t))))
   8196 		    goto handle_map_references;
   8197 		}
   8198 	    }
   8199 	  if (!processing_template_decl
   8200 	      && TREE_CODE (t) == FIELD_DECL)
   8201 	    {
   8202 	      OMP_CLAUSE_DECL (c) = finish_non_static_data_member (t, NULL_TREE,
   8203 								   NULL_TREE);
   8204 	      break;
   8205 	    }
   8206 	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   8207 	    {
   8208 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   8209 		break;
   8210 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8211 		  && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   8212 		      || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
   8213 		      || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH))
   8214 		break;
   8215 	      if (DECL_P (t))
   8216 		error_at (OMP_CLAUSE_LOCATION (c),
   8217 			  "%qD is not a variable in %qs clause", t,
   8218 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8219 	      else
   8220 		error_at (OMP_CLAUSE_LOCATION (c),
   8221 			  "%qE is not a variable in %qs clause", t,
   8222 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8223 	      remove = true;
   8224 	    }
   8225 	  else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   8226 	    {
   8227 	      error_at (OMP_CLAUSE_LOCATION (c),
   8228 			"%qD is threadprivate variable in %qs clause", t,
   8229 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8230 	      remove = true;
   8231 	    }
   8232 	  else if (!processing_template_decl
   8233 		   && !TYPE_REF_P (TREE_TYPE (t))
   8234 		   && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   8235 		       || (OMP_CLAUSE_MAP_KIND (c)
   8236 			   != GOMP_MAP_FIRSTPRIVATE_POINTER))
   8237 		   && !indir_component_ref_p
   8238 		   && !cxx_mark_addressable (t))
   8239 	    remove = true;
   8240 	  else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8241 		     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   8242 			 || (OMP_CLAUSE_MAP_KIND (c)
   8243 			     == GOMP_MAP_FIRSTPRIVATE_POINTER)))
   8244 		   && t == OMP_CLAUSE_DECL (c)
   8245 		   && !type_dependent_expression_p (t)
   8246 		   && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
   8247 					     ? TREE_TYPE (TREE_TYPE (t))
   8248 					     : TREE_TYPE (t)))
   8249 	    {
   8250 	      error_at (OMP_CLAUSE_LOCATION (c),
   8251 			"%qD does not have a mappable type in %qs clause", t,
   8252 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8253 	      cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
   8254 	      remove = true;
   8255 	    }
   8256 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8257 		   && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
   8258 		   && !type_dependent_expression_p (t)
   8259 		   && !INDIRECT_TYPE_P (TREE_TYPE (t)))
   8260 	    {
   8261 	      error_at (OMP_CLAUSE_LOCATION (c),
   8262 			"%qD is not a pointer variable", t);
   8263 	      remove = true;
   8264 	    }
   8265 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8266 		   && OMP_CLAUSE_MAP_IMPLICIT (c)
   8267 		   && (bitmap_bit_p (&map_head, DECL_UID (t))
   8268 		       || bitmap_bit_p (&map_field_head, DECL_UID (t))
   8269 		       || bitmap_bit_p (&map_firstprivate_head,
   8270 					DECL_UID (t))))
   8271 	    remove = true;
   8272 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   8273 		   && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
   8274 	    {
   8275 	      if (bitmap_bit_p (&generic_head, DECL_UID (t))
   8276 		  || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   8277 		  || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   8278 		{
   8279 		  error_at (OMP_CLAUSE_LOCATION (c),
   8280 			    "%qD appears more than once in data clauses", t);
   8281 		  remove = true;
   8282 		}
   8283 	      else if (bitmap_bit_p (&map_head, DECL_UID (t))
   8284 		       && !bitmap_bit_p (&map_field_head, DECL_UID (t)))
   8285 		{
   8286 		  if (ort == C_ORT_ACC)
   8287 		    error_at (OMP_CLAUSE_LOCATION (c),
   8288 			      "%qD appears more than once in data clauses", t);
   8289 		  else
   8290 		    error_at (OMP_CLAUSE_LOCATION (c),
   8291 			      "%qD appears both in data and map clauses", t);
   8292 		  remove = true;
   8293 		}
   8294 	      else
   8295 		bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
   8296 	    }
   8297 	  else if (bitmap_bit_p (&map_head, DECL_UID (t))
   8298 		   && !bitmap_bit_p (&map_field_head, DECL_UID (t)))
   8299 	    {
   8300 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   8301 		error_at (OMP_CLAUSE_LOCATION (c),
   8302 			  "%qD appears more than once in motion clauses", t);
   8303 	      else if (ort == C_ORT_ACC)
   8304 		error_at (OMP_CLAUSE_LOCATION (c),
   8305 			  "%qD appears more than once in data clauses", t);
   8306 	      else
   8307 		error_at (OMP_CLAUSE_LOCATION (c),
   8308 			  "%qD appears more than once in map clauses", t);
   8309 	      remove = true;
   8310 	    }
   8311 	  else if (ort == C_ORT_ACC
   8312 		   && bitmap_bit_p (&generic_head, DECL_UID (t)))
   8313 	    {
   8314 	      error_at (OMP_CLAUSE_LOCATION (c),
   8315 			"%qD appears more than once in data clauses", t);
   8316 	      remove = true;
   8317 	    }
   8318 	  else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   8319 		   || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
   8320 	    {
   8321 	      if (ort == C_ORT_ACC)
   8322 		error_at (OMP_CLAUSE_LOCATION (c),
   8323 			  "%qD appears more than once in data clauses", t);
   8324 	      else
   8325 		error_at (OMP_CLAUSE_LOCATION (c),
   8326 			  "%qD appears both in data and map clauses", t);
   8327 	      remove = true;
   8328 	    }
   8329 	  else
   8330 	    {
   8331 	      bitmap_set_bit (&map_head, DECL_UID (t));
   8332 
   8333 	      tree decl = OMP_CLAUSE_DECL (c);
   8334 	      if (t != decl
   8335 		  && (TREE_CODE (decl) == COMPONENT_REF
   8336 		      || (INDIRECT_REF_P (decl)
   8337 			  && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
   8338 			  && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl, 0))))))
   8339 		bitmap_set_bit (&map_field_head, DECL_UID (t));
   8340 	    }
   8341 	handle_map_references:
   8342 	  if (!remove
   8343 	      && !processing_template_decl
   8344 	      && ort != C_ORT_DECLARE_SIMD
   8345 	      && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   8346 	    {
   8347 	      t = OMP_CLAUSE_DECL (c);
   8348 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   8349 		{
   8350 		  OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
   8351 		  if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   8352 		    OMP_CLAUSE_SIZE (c)
   8353 		      = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
   8354 		}
   8355 	      else if (OMP_CLAUSE_MAP_KIND (c)
   8356 		       != GOMP_MAP_FIRSTPRIVATE_POINTER
   8357 		       && (OMP_CLAUSE_MAP_KIND (c)
   8358 			   != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   8359 		       && (OMP_CLAUSE_MAP_KIND (c)
   8360 			   != GOMP_MAP_ALWAYS_POINTER)
   8361 		       && (OMP_CLAUSE_MAP_KIND (c)
   8362 			   != GOMP_MAP_ATTACH_DETACH))
   8363 		{
   8364 		  tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
   8365 					      OMP_CLAUSE_MAP);
   8366 		  if (TREE_CODE (t) == COMPONENT_REF)
   8367 		    OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
   8368 		  else
   8369 		    OMP_CLAUSE_SET_MAP_KIND (c2,
   8370 					     GOMP_MAP_FIRSTPRIVATE_REFERENCE);
   8371 		  OMP_CLAUSE_DECL (c2) = t;
   8372 		  OMP_CLAUSE_SIZE (c2) = size_zero_node;
   8373 		  OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
   8374 		  OMP_CLAUSE_CHAIN (c) = c2;
   8375 		  OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
   8376 		  if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
   8377 		    OMP_CLAUSE_SIZE (c)
   8378 		      = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
   8379 		  c = c2;
   8380 		}
   8381 	    }
   8382 	  break;
   8383 
   8384 	case OMP_CLAUSE_TO_DECLARE:
   8385 	case OMP_CLAUSE_LINK:
   8386 	  t = OMP_CLAUSE_DECL (c);
   8387 	  if (TREE_CODE (t) == FUNCTION_DECL
   8388 	      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
   8389 	    ;
   8390 	  else if (!VAR_P (t))
   8391 	    {
   8392 	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
   8393 		{
   8394 		  if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
   8395 		    error_at (OMP_CLAUSE_LOCATION (c),
   8396 			      "template %qE in clause %qs", t,
   8397 			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8398 		  else if (really_overloaded_fn (t))
   8399 		    error_at (OMP_CLAUSE_LOCATION (c),
   8400 			      "overloaded function name %qE in clause %qs", t,
   8401 			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8402 		  else
   8403 		    error_at (OMP_CLAUSE_LOCATION (c),
   8404 			      "%qE is neither a variable nor a function name "
   8405 			      "in clause %qs", t,
   8406 			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8407 		}
   8408 	      else
   8409 		error_at (OMP_CLAUSE_LOCATION (c),
   8410 			  "%qE is not a variable in clause %qs", t,
   8411 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8412 	      remove = true;
   8413 	    }
   8414 	  else if (DECL_THREAD_LOCAL_P (t))
   8415 	    {
   8416 	      error_at (OMP_CLAUSE_LOCATION (c),
   8417 			"%qD is threadprivate variable in %qs clause", t,
   8418 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8419 	      remove = true;
   8420 	    }
   8421 	  else if (!cp_omp_mappable_type (TREE_TYPE (t)))
   8422 	    {
   8423 	      error_at (OMP_CLAUSE_LOCATION (c),
   8424 			"%qD does not have a mappable type in %qs clause", t,
   8425 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8426 	      cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
   8427 	      remove = true;
   8428 	    }
   8429 	  if (remove)
   8430 	    break;
   8431 	  if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   8432 	    {
   8433 	      error_at (OMP_CLAUSE_LOCATION (c),
   8434 			"%qE appears more than once on the same "
   8435 			"%<declare target%> directive", t);
   8436 	      remove = true;
   8437 	    }
   8438 	  else
   8439 	    bitmap_set_bit (&generic_head, DECL_UID (t));
   8440 	  break;
   8441 
   8442 	case OMP_CLAUSE_UNIFORM:
   8443 	  t = OMP_CLAUSE_DECL (c);
   8444 	  if (TREE_CODE (t) != PARM_DECL)
   8445 	    {
   8446 	      if (processing_template_decl)
   8447 		break;
   8448 	      if (DECL_P (t))
   8449 		error_at (OMP_CLAUSE_LOCATION (c),
   8450 			  "%qD is not an argument in %<uniform%> clause", t);
   8451 	      else
   8452 		error_at (OMP_CLAUSE_LOCATION (c),
   8453 			  "%qE is not an argument in %<uniform%> clause", t);
   8454 	      remove = true;
   8455 	      break;
   8456 	    }
   8457 	  /* map_head bitmap is used as uniform_head if declare_simd.  */
   8458 	  bitmap_set_bit (&map_head, DECL_UID (t));
   8459 	  goto check_dup_generic;
   8460 
   8461 	case OMP_CLAUSE_GRAINSIZE:
   8462 	  t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
   8463 	  if (t == error_mark_node)
   8464 	    remove = true;
   8465 	  else if (!type_dependent_expression_p (t)
   8466 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   8467 	    {
   8468 	      error_at (OMP_CLAUSE_LOCATION (c),
   8469 			"%<grainsize%> expression must be integral");
   8470 	      remove = true;
   8471 	    }
   8472 	  else
   8473 	    {
   8474 	      t = mark_rvalue_use (t);
   8475 	      if (!processing_template_decl)
   8476 		{
   8477 		  t = maybe_constant_value (t);
   8478 		  if (TREE_CODE (t) == INTEGER_CST
   8479 		      && tree_int_cst_sgn (t) != 1)
   8480 		    {
   8481 		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
   8482 				  "%<grainsize%> value must be positive");
   8483 		      t = integer_one_node;
   8484 		    }
   8485 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   8486 		}
   8487 	      OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
   8488 	    }
   8489 	  break;
   8490 
   8491 	case OMP_CLAUSE_PRIORITY:
   8492 	  t = OMP_CLAUSE_PRIORITY_EXPR (c);
   8493 	  if (t == error_mark_node)
   8494 	    remove = true;
   8495 	  else if (!type_dependent_expression_p (t)
   8496 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   8497 	    {
   8498 	      error_at (OMP_CLAUSE_LOCATION (c),
   8499 			"%<priority%> expression must be integral");
   8500 	      remove = true;
   8501 	    }
   8502 	  else
   8503 	    {
   8504 	      t = mark_rvalue_use (t);
   8505 	      if (!processing_template_decl)
   8506 		{
   8507 		  t = maybe_constant_value (t);
   8508 		  if (TREE_CODE (t) == INTEGER_CST
   8509 		      && tree_int_cst_sgn (t) == -1)
   8510 		    {
   8511 		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
   8512 				  "%<priority%> value must be non-negative");
   8513 		      t = integer_one_node;
   8514 		    }
   8515 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   8516 		}
   8517 	      OMP_CLAUSE_PRIORITY_EXPR (c) = t;
   8518 	    }
   8519 	  break;
   8520 
   8521 	case OMP_CLAUSE_HINT:
   8522 	  t = OMP_CLAUSE_HINT_EXPR (c);
   8523 	  if (t == error_mark_node)
   8524 	    remove = true;
   8525 	  else if (!type_dependent_expression_p (t)
   8526 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   8527 	    {
   8528 	      error_at (OMP_CLAUSE_LOCATION (c),
   8529 			"%<hint%> expression must be integral");
   8530 	      remove = true;
   8531 	    }
   8532 	  else
   8533 	    {
   8534 	      t = mark_rvalue_use (t);
   8535 	      if (!processing_template_decl)
   8536 		{
   8537 		  t = maybe_constant_value (t);
   8538 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   8539 		  if (TREE_CODE (t) != INTEGER_CST)
   8540 		    {
   8541 		      error_at (OMP_CLAUSE_LOCATION (c),
   8542 				"%<hint%> expression must be constant integer "
   8543 				"expression");
   8544 		      remove = true;
   8545 		    }
   8546 		}
   8547 	      OMP_CLAUSE_HINT_EXPR (c) = t;
   8548 	    }
   8549 	  break;
   8550 
   8551 	case OMP_CLAUSE_FILTER:
   8552 	  t = OMP_CLAUSE_FILTER_EXPR (c);
   8553 	  if (t == error_mark_node)
   8554 	    remove = true;
   8555 	  else if (!type_dependent_expression_p (t)
   8556 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   8557 	    {
   8558 	      error_at (OMP_CLAUSE_LOCATION (c),
   8559 			"%<filter%> expression must be integral");
   8560 	      remove = true;
   8561 	    }
   8562 	  else
   8563 	    {
   8564 	      t = mark_rvalue_use (t);
   8565 	      if (!processing_template_decl)
   8566 		{
   8567 		  t = maybe_constant_value (t);
   8568 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   8569 		}
   8570 	      OMP_CLAUSE_FILTER_EXPR (c) = t;
   8571 	    }
   8572 	  break;
   8573 
   8574 	case OMP_CLAUSE_IS_DEVICE_PTR:
   8575 	case OMP_CLAUSE_USE_DEVICE_PTR:
   8576 	  field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
   8577 	  t = OMP_CLAUSE_DECL (c);
   8578 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   8579 	    bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   8580 	  if (!type_dependent_expression_p (t))
   8581 	    {
   8582 	      tree type = TREE_TYPE (t);
   8583 	      if (!TYPE_PTR_P (type)
   8584 		  && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
   8585 		{
   8586 		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   8587 		      && ort == C_ORT_OMP)
   8588 		    {
   8589 		      error_at (OMP_CLAUSE_LOCATION (c),
   8590 				"%qs variable is neither a pointer "
   8591 				"nor reference to pointer",
   8592 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8593 		      remove = true;
   8594 		    }
   8595 		  else if (TREE_CODE (type) != ARRAY_TYPE
   8596 			   && (!TYPE_REF_P (type)
   8597 			       || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
   8598 		    {
   8599 		      error_at (OMP_CLAUSE_LOCATION (c),
   8600 				"%qs variable is neither a pointer, nor an "
   8601 				"array nor reference to pointer or array",
   8602 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8603 		      remove = true;
   8604 		    }
   8605 		}
   8606 	    }
   8607 	  goto check_dup_generic;
   8608 
   8609 	case OMP_CLAUSE_HAS_DEVICE_ADDR:
   8610 	  t = OMP_CLAUSE_DECL (c);
   8611 	  if (TREE_CODE (t) == TREE_LIST)
   8612 	    {
   8613 	      if (handle_omp_array_sections (c, ort))
   8614 		remove = true;
   8615 	      else
   8616 		{
   8617 		  t = OMP_CLAUSE_DECL (c);
   8618 		  while (TREE_CODE (t) == INDIRECT_REF
   8619 			 || TREE_CODE (t) == ARRAY_REF)
   8620 		    t = TREE_OPERAND (t, 0);
   8621 		}
   8622 	    }
   8623 	  bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   8624 	  if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   8625 	    cxx_mark_addressable (t);
   8626 	  goto check_dup_generic_t;
   8627 
   8628 	case OMP_CLAUSE_USE_DEVICE_ADDR:
   8629 	  field_ok = true;
   8630 	  t = OMP_CLAUSE_DECL (c);
   8631 	  if (!processing_template_decl
   8632 	      && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   8633 	      && !TYPE_REF_P (TREE_TYPE (t))
   8634 	      && !cxx_mark_addressable (t))
   8635 	    remove = true;
   8636 	  goto check_dup_generic;
   8637 
   8638 	case OMP_CLAUSE_NOWAIT:
   8639 	case OMP_CLAUSE_DEFAULT:
   8640 	case OMP_CLAUSE_UNTIED:
   8641 	case OMP_CLAUSE_COLLAPSE:
   8642 	case OMP_CLAUSE_PARALLEL:
   8643 	case OMP_CLAUSE_FOR:
   8644 	case OMP_CLAUSE_SECTIONS:
   8645 	case OMP_CLAUSE_TASKGROUP:
   8646 	case OMP_CLAUSE_PROC_BIND:
   8647 	case OMP_CLAUSE_DEVICE_TYPE:
   8648 	case OMP_CLAUSE_NOGROUP:
   8649 	case OMP_CLAUSE_THREADS:
   8650 	case OMP_CLAUSE_SIMD:
   8651 	case OMP_CLAUSE_DEFAULTMAP:
   8652 	case OMP_CLAUSE_BIND:
   8653 	case OMP_CLAUSE_AUTO:
   8654 	case OMP_CLAUSE_INDEPENDENT:
   8655 	case OMP_CLAUSE_SEQ:
   8656 	case OMP_CLAUSE_IF_PRESENT:
   8657 	case OMP_CLAUSE_FINALIZE:
   8658 	case OMP_CLAUSE_NOHOST:
   8659 	  break;
   8660 
   8661 	case OMP_CLAUSE_MERGEABLE:
   8662 	  mergeable_seen = true;
   8663 	  break;
   8664 
   8665 	case OMP_CLAUSE_TILE:
   8666 	  for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
   8667 	       list = TREE_CHAIN (list))
   8668 	    {
   8669 	      t = TREE_VALUE (list);
   8670 
   8671 	      if (t == error_mark_node)
   8672 		remove = true;
   8673 	      else if (!type_dependent_expression_p (t)
   8674 		       && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   8675 		{
   8676 		  error_at (OMP_CLAUSE_LOCATION (c),
   8677 			    "%<tile%> argument needs integral type");
   8678 		  remove = true;
   8679 		}
   8680 	      else
   8681 		{
   8682 		  t = mark_rvalue_use (t);
   8683 		  if (!processing_template_decl)
   8684 		    {
   8685 		      /* Zero is used to indicate '*', we permit you
   8686 			 to get there via an ICE of value zero.  */
   8687 		      t = maybe_constant_value (t);
   8688 		      if (!tree_fits_shwi_p (t)
   8689 			  || tree_to_shwi (t) < 0)
   8690 			{
   8691 			  error_at (OMP_CLAUSE_LOCATION (c),
   8692 				    "%<tile%> argument needs positive "
   8693 				    "integral constant");
   8694 			  remove = true;
   8695 			}
   8696 		      t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   8697 		    }
   8698 		}
   8699 
   8700 		/* Update list item.  */
   8701 	      TREE_VALUE (list) = t;
   8702 	    }
   8703 	  break;
   8704 
   8705 	case OMP_CLAUSE_ORDERED:
   8706 	  ordered_seen = true;
   8707 	  break;
   8708 
   8709 	case OMP_CLAUSE_ORDER:
   8710 	  if (order_seen)
   8711 	    remove = true;
   8712 	  else
   8713 	    order_seen = true;
   8714 	  break;
   8715 
   8716 	case OMP_CLAUSE_INBRANCH:
   8717 	case OMP_CLAUSE_NOTINBRANCH:
   8718 	  if (branch_seen)
   8719 	    {
   8720 	      error_at (OMP_CLAUSE_LOCATION (c),
   8721 			"%<inbranch%> clause is incompatible with "
   8722 			"%<notinbranch%>");
   8723 	      remove = true;
   8724 	    }
   8725 	  branch_seen = true;
   8726 	  break;
   8727 
   8728 	case OMP_CLAUSE_INCLUSIVE:
   8729 	case OMP_CLAUSE_EXCLUSIVE:
   8730 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   8731 	  if (!t)
   8732 	    t = OMP_CLAUSE_DECL (c);
   8733 	  if (t == current_class_ptr)
   8734 	    {
   8735 	      error_at (OMP_CLAUSE_LOCATION (c),
   8736 			"%<this%> allowed in OpenMP only in %<declare simd%>"
   8737 			" clauses");
   8738 	      remove = true;
   8739 	      break;
   8740 	    }
   8741 	  if (!VAR_P (t)
   8742 	      && TREE_CODE (t) != PARM_DECL
   8743 	      && TREE_CODE (t) != FIELD_DECL)
   8744 	    {
   8745 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   8746 		break;
   8747 	      if (DECL_P (t))
   8748 		error_at (OMP_CLAUSE_LOCATION (c),
   8749 			  "%qD is not a variable in clause %qs", t,
   8750 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8751 	      else
   8752 		error_at (OMP_CLAUSE_LOCATION (c),
   8753 			  "%qE is not a variable in clause %qs", t,
   8754 			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   8755 	      remove = true;
   8756 	    }
   8757 	  break;
   8758 
   8759 	default:
   8760 	  gcc_unreachable ();
   8761 	}
   8762 
   8763       if (remove)
   8764 	*pc = OMP_CLAUSE_CHAIN (c);
   8765       else
   8766 	pc = &OMP_CLAUSE_CHAIN (c);
   8767     }
   8768 
   8769   if (reduction_seen < 0 && (ordered_seen || schedule_seen))
   8770     reduction_seen = -2;
   8771 
   8772   for (pc = &clauses, c = clauses; c ; c = *pc)
   8773     {
   8774       enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
   8775       bool remove = false;
   8776       bool need_complete_type = false;
   8777       bool need_default_ctor = false;
   8778       bool need_copy_ctor = false;
   8779       bool need_copy_assignment = false;
   8780       bool need_implicitly_determined = false;
   8781       bool need_dtor = false;
   8782       tree type, inner_type;
   8783 
   8784       switch (c_kind)
   8785 	{
   8786 	case OMP_CLAUSE_SHARED:
   8787 	  need_implicitly_determined = true;
   8788 	  break;
   8789 	case OMP_CLAUSE_PRIVATE:
   8790 	  need_complete_type = true;
   8791 	  need_default_ctor = true;
   8792 	  need_dtor = true;
   8793 	  need_implicitly_determined = true;
   8794 	  break;
   8795 	case OMP_CLAUSE_FIRSTPRIVATE:
   8796 	  need_complete_type = true;
   8797 	  need_copy_ctor = true;
   8798 	  need_dtor = true;
   8799 	  need_implicitly_determined = true;
   8800 	  break;
   8801 	case OMP_CLAUSE_LASTPRIVATE:
   8802 	  need_complete_type = true;
   8803 	  need_copy_assignment = true;
   8804 	  need_implicitly_determined = true;
   8805 	  break;
   8806 	case OMP_CLAUSE_REDUCTION:
   8807 	  if (reduction_seen == -2)
   8808 	    OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   8809 	  if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   8810 	    need_copy_assignment = true;
   8811 	  need_implicitly_determined = true;
   8812 	  break;
   8813 	case OMP_CLAUSE_IN_REDUCTION:
   8814 	case OMP_CLAUSE_TASK_REDUCTION:
   8815 	case OMP_CLAUSE_INCLUSIVE:
   8816 	case OMP_CLAUSE_EXCLUSIVE:
   8817 	  need_implicitly_determined = true;
   8818 	  break;
   8819 	case OMP_CLAUSE_LINEAR:
   8820 	  if (ort != C_ORT_OMP_DECLARE_SIMD)
   8821 	    need_implicitly_determined = true;
   8822 	  else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   8823 		   && !bitmap_bit_p (&map_head,
   8824 				     DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   8825 	    {
   8826 	      error_at (OMP_CLAUSE_LOCATION (c),
   8827 			"%<linear%> clause step is a parameter %qD not "
   8828 			"specified in %<uniform%> clause",
   8829 			OMP_CLAUSE_LINEAR_STEP (c));
   8830 	      *pc = OMP_CLAUSE_CHAIN (c);
   8831 	      continue;
   8832 	    }
   8833 	  break;
   8834 	case OMP_CLAUSE_COPYPRIVATE:
   8835 	  need_copy_assignment = true;
   8836 	  break;
   8837 	case OMP_CLAUSE_COPYIN:
   8838 	  need_copy_assignment = true;
   8839 	  break;
   8840 	case OMP_CLAUSE_SIMDLEN:
   8841 	  if (safelen
   8842 	      && !processing_template_decl
   8843 	      && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   8844 				  OMP_CLAUSE_SIMDLEN_EXPR (c)))
   8845 	    {
   8846 	      error_at (OMP_CLAUSE_LOCATION (c),
   8847 			"%<simdlen%> clause value is bigger than "
   8848 			"%<safelen%> clause value");
   8849 	      OMP_CLAUSE_SIMDLEN_EXPR (c)
   8850 		= OMP_CLAUSE_SAFELEN_EXPR (safelen);
   8851 	    }
   8852 	  pc = &OMP_CLAUSE_CHAIN (c);
   8853 	  continue;
   8854 	case OMP_CLAUSE_SCHEDULE:
   8855 	  if (ordered_seen
   8856 	      && (OMP_CLAUSE_SCHEDULE_KIND (c)
   8857 		  & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   8858 	    {
   8859 	      error_at (OMP_CLAUSE_LOCATION (c),
   8860 			"%<nonmonotonic%> schedule modifier specified "
   8861 			"together with %<ordered%> clause");
   8862 	      OMP_CLAUSE_SCHEDULE_KIND (c)
   8863 		= (enum omp_clause_schedule_kind)
   8864 		  (OMP_CLAUSE_SCHEDULE_KIND (c)
   8865 		   & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   8866 	    }
   8867 	  if (reduction_seen == -2)
   8868 	    error_at (OMP_CLAUSE_LOCATION (c),
   8869 		      "%qs clause specified together with %<inscan%> "
   8870 		      "%<reduction%> clause", "schedule");
   8871 	  pc = &OMP_CLAUSE_CHAIN (c);
   8872 	  continue;
   8873 	case OMP_CLAUSE_NOGROUP:
   8874 	  if (reduction_seen)
   8875 	    {
   8876 	      error_at (OMP_CLAUSE_LOCATION (c),
   8877 			"%<nogroup%> clause must not be used together with "
   8878 			"%<reduction%> clause");
   8879 	      *pc = OMP_CLAUSE_CHAIN (c);
   8880 	      continue;
   8881 	    }
   8882 	  pc = &OMP_CLAUSE_CHAIN (c);
   8883 	  continue;
   8884 	case OMP_CLAUSE_ORDERED:
   8885 	  if (reduction_seen == -2)
   8886 	    error_at (OMP_CLAUSE_LOCATION (c),
   8887 		      "%qs clause specified together with %<inscan%> "
   8888 		      "%<reduction%> clause", "ordered");
   8889 	  pc = &OMP_CLAUSE_CHAIN (c);
   8890 	  continue;
   8891 	case OMP_CLAUSE_ORDER:
   8892 	  if (ordered_seen)
   8893 	    {
   8894 	      error_at (OMP_CLAUSE_LOCATION (c),
   8895 			"%<order%> clause must not be used together "
   8896 			"with %<ordered%>");
   8897 	      *pc = OMP_CLAUSE_CHAIN (c);
   8898 	      continue;
   8899 	    }
   8900 	  pc = &OMP_CLAUSE_CHAIN (c);
   8901 	  continue;
   8902 	case OMP_CLAUSE_DETACH:
   8903 	  if (mergeable_seen)
   8904 	    {
   8905 	      error_at (OMP_CLAUSE_LOCATION (c),
   8906 			"%<detach%> clause must not be used together with "
   8907 			"%<mergeable%> clause");
   8908 	      *pc = OMP_CLAUSE_CHAIN (c);
   8909 	      continue;
   8910 	    }
   8911 	  pc = &OMP_CLAUSE_CHAIN (c);
   8912 	  continue;
   8913 	case OMP_CLAUSE_MAP:
   8914 	  if (target_in_reduction_seen && !processing_template_decl)
   8915 	    {
   8916 	      t = OMP_CLAUSE_DECL (c);
   8917 	      while (handled_component_p (t)
   8918 		     || TREE_CODE (t) == INDIRECT_REF
   8919 		     || TREE_CODE (t) == ADDR_EXPR
   8920 		     || TREE_CODE (t) == MEM_REF
   8921 		     || TREE_CODE (t) == NON_LVALUE_EXPR)
   8922 		t = TREE_OPERAND (t, 0);
   8923 	      if (DECL_P (t)
   8924 		  && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   8925 		OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   8926 	    }
   8927 	  pc = &OMP_CLAUSE_CHAIN (c);
   8928 	  continue;
   8929 	case OMP_CLAUSE_NOWAIT:
   8930 	  if (copyprivate_seen)
   8931 	    {
   8932 	      error_at (OMP_CLAUSE_LOCATION (c),
   8933 			"%<nowait%> clause must not be used together "
   8934 			"with %<copyprivate%>");
   8935 	      *pc = OMP_CLAUSE_CHAIN (c);
   8936 	      continue;
   8937 	    }
   8938 	  /* FALLTHRU */
   8939 	default:
   8940 	  pc = &OMP_CLAUSE_CHAIN (c);
   8941 	  continue;
   8942 	}
   8943 
   8944       t = OMP_CLAUSE_DECL (c);
   8945       switch (c_kind)
   8946 	{
   8947 	case OMP_CLAUSE_LASTPRIVATE:
   8948 	  if (DECL_P (t)
   8949 	      && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
   8950 	    {
   8951 	      need_default_ctor = true;
   8952 	      need_dtor = true;
   8953 	    }
   8954 	  break;
   8955 
   8956 	case OMP_CLAUSE_REDUCTION:
   8957 	case OMP_CLAUSE_IN_REDUCTION:
   8958 	case OMP_CLAUSE_TASK_REDUCTION:
   8959 	  if (allocate_seen)
   8960 	    {
   8961 	      if (TREE_CODE (t) == MEM_REF)
   8962 		{
   8963 		  t = TREE_OPERAND (t, 0);
   8964 		  if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   8965 		    t = TREE_OPERAND (t, 0);
   8966 		  if (TREE_CODE (t) == ADDR_EXPR
   8967 		      || TREE_CODE (t) == INDIRECT_REF)
   8968 		    t = TREE_OPERAND (t, 0);
   8969 		  if (DECL_P (t))
   8970 		    bitmap_clear_bit (&aligned_head, DECL_UID (t));
   8971 		}
   8972 	      else if (TREE_CODE (t) == TREE_LIST)
   8973 		{
   8974 		  while (TREE_CODE (t) == TREE_LIST)
   8975 		    t = TREE_CHAIN (t);
   8976 		  if (DECL_P (t))
   8977 		    bitmap_clear_bit (&aligned_head, DECL_UID (t));
   8978 		  t = OMP_CLAUSE_DECL (c);
   8979 		}
   8980 	      else if (DECL_P (t))
   8981 		bitmap_clear_bit (&aligned_head, DECL_UID (t));
   8982 	      t = OMP_CLAUSE_DECL (c);
   8983 	    }
   8984 	  if (processing_template_decl
   8985 	      && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   8986 	    break;
   8987 	  if (finish_omp_reduction_clause (c, &need_default_ctor,
   8988 					   &need_dtor))
   8989 	    remove = true;
   8990 	  else
   8991 	    t = OMP_CLAUSE_DECL (c);
   8992 	  break;
   8993 
   8994 	case OMP_CLAUSE_COPYIN:
   8995 	  if (processing_template_decl
   8996 	      && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   8997 	    break;
   8998 	  if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
   8999 	    {
   9000 	      error_at (OMP_CLAUSE_LOCATION (c),
   9001 			"%qE must be %<threadprivate%> for %<copyin%>", t);
   9002 	      remove = true;
   9003 	    }
   9004 	  break;
   9005 
   9006 	default:
   9007 	  break;
   9008 	}
   9009 
   9010       if (processing_template_decl
   9011 	  && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   9012 	{
   9013 	  pc = &OMP_CLAUSE_CHAIN (c);
   9014 	  continue;
   9015 	}
   9016 
   9017       if (need_complete_type || need_copy_assignment)
   9018 	{
   9019 	  t = require_complete_type (t);
   9020 	  if (t == error_mark_node)
   9021 	    remove = true;
   9022 	  else if (!processing_template_decl
   9023 		   && TYPE_REF_P (TREE_TYPE (t))
   9024 		   && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
   9025 	    remove = true;
   9026 	}
   9027       if (need_implicitly_determined)
   9028 	{
   9029 	  const char *share_name = NULL;
   9030 
   9031 	  if (allocate_seen
   9032 	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   9033 	      && DECL_P (t))
   9034 	    bitmap_clear_bit (&aligned_head, DECL_UID (t));
   9035 
   9036 	  if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   9037 	    share_name = "threadprivate";
   9038 	  else switch (cxx_omp_predetermined_sharing_1 (t))
   9039 	    {
   9040 	    case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   9041 	      break;
   9042 	    case OMP_CLAUSE_DEFAULT_SHARED:
   9043 	      if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   9044 		   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   9045 		  && c_omp_predefined_variable (t))
   9046 		/* The __func__ variable and similar function-local predefined
   9047 		   variables may be listed in a shared or firstprivate
   9048 		   clause.  */
   9049 		break;
   9050 	      if (VAR_P (t)
   9051 		  && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   9052 		  && TREE_STATIC (t)
   9053 		  && cxx_omp_const_qual_no_mutable (t))
   9054 		{
   9055 		  tree ctx = CP_DECL_CONTEXT (t);
   9056 		  /* const qualified static data members without mutable
   9057 		     member may be specified in firstprivate clause.  */
   9058 		  if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
   9059 		    break;
   9060 		}
   9061 	      share_name = "shared";
   9062 	      break;
   9063 	    case OMP_CLAUSE_DEFAULT_PRIVATE:
   9064 	      share_name = "private";
   9065 	      break;
   9066 	    default:
   9067 	      gcc_unreachable ();
   9068 	    }
   9069 	  if (share_name)
   9070 	    {
   9071 	      error_at (OMP_CLAUSE_LOCATION (c),
   9072 			"%qE is predetermined %qs for %qs",
   9073 			omp_clause_printable_decl (t), share_name,
   9074 			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   9075 	      remove = true;
   9076 	    }
   9077 	  else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   9078 		   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
   9079 		   && cxx_omp_const_qual_no_mutable (t))
   9080 	    {
   9081 	      error_at (OMP_CLAUSE_LOCATION (c),
   9082 			"%<const%> qualified %qE without %<mutable%> member "
   9083 			"may appear only in %<shared%> or %<firstprivate%> "
   9084 			"clauses", omp_clause_printable_decl (t));
   9085 	      remove = true;
   9086 	    }
   9087 	}
   9088 
   9089       if (detach_seen
   9090 	  && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   9091 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   9092 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   9093 	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   9094 	  && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
   9095 	{
   9096 	  error_at (OMP_CLAUSE_LOCATION (c),
   9097 		    "the event handle of a %<detach%> clause "
   9098 		    "should not be in a data-sharing clause");
   9099 	  remove = true;
   9100 	}
   9101 
   9102       /* We're interested in the base element, not arrays.  */
   9103       inner_type = type = TREE_TYPE (t);
   9104       if ((need_complete_type
   9105 	   || need_copy_assignment
   9106 	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   9107 	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   9108 	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   9109 	  && TYPE_REF_P (inner_type))
   9110 	inner_type = TREE_TYPE (inner_type);
   9111       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   9112 	inner_type = TREE_TYPE (inner_type);
   9113 
   9114       /* Check for special function availability by building a call to one.
   9115 	 Save the results, because later we won't be in the right context
   9116 	 for making these queries.  */
   9117       if (CLASS_TYPE_P (inner_type)
   9118 	  && COMPLETE_TYPE_P (inner_type)
   9119 	  && (need_default_ctor || need_copy_ctor
   9120 	      || need_copy_assignment || need_dtor)
   9121 	  && !type_dependent_expression_p (t)
   9122 	  && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
   9123 					 need_copy_ctor, need_copy_assignment,
   9124 					 need_dtor))
   9125 	remove = true;
   9126 
   9127       if (!remove
   9128 	  && c_kind == OMP_CLAUSE_SHARED
   9129 	  && processing_template_decl)
   9130 	{
   9131 	  t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   9132 	  if (t)
   9133 	    OMP_CLAUSE_DECL (c) = t;
   9134 	}
   9135 
   9136       if (remove)
   9137 	*pc = OMP_CLAUSE_CHAIN (c);
   9138       else
   9139 	pc = &OMP_CLAUSE_CHAIN (c);
   9140     }
   9141 
   9142   if (allocate_seen)
   9143     for (pc = &clauses, c = clauses; c ; c = *pc)
   9144       {
   9145 	bool remove = false;
   9146 	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   9147 	    && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   9148 	    && DECL_P (OMP_CLAUSE_DECL (c))
   9149 	    && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   9150 	  {
   9151 	    error_at (OMP_CLAUSE_LOCATION (c),
   9152 		      "%qD specified in %<allocate%> clause but not in "
   9153 		      "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   9154 	    remove = true;
   9155 	  }
   9156 	if (remove)
   9157 	  *pc = OMP_CLAUSE_CHAIN (c);
   9158 	else
   9159 	  pc = &OMP_CLAUSE_CHAIN (c);
   9160       }
   9161 
   9162   bitmap_obstack_release (NULL);
   9163   return clauses;
   9164 }
   9165 
   9166 /* Start processing OpenMP clauses that can include any
   9167    privatization clauses for non-static data members.  */
   9168 
   9169 tree
   9170 push_omp_privatization_clauses (bool ignore_next)
   9171 {
   9172   if (omp_private_member_ignore_next)
   9173     {
   9174       omp_private_member_ignore_next = ignore_next;
   9175       return NULL_TREE;
   9176     }
   9177   omp_private_member_ignore_next = ignore_next;
   9178   if (omp_private_member_map)
   9179     omp_private_member_vec.safe_push (error_mark_node);
   9180   return push_stmt_list ();
   9181 }
   9182 
   9183 /* Revert remapping of any non-static data members since
   9184    the last push_omp_privatization_clauses () call.  */
   9185 
   9186 void
   9187 pop_omp_privatization_clauses (tree stmt)
   9188 {
   9189   if (stmt == NULL_TREE)
   9190     return;
   9191   stmt = pop_stmt_list (stmt);
   9192   if (omp_private_member_map)
   9193     {
   9194       while (!omp_private_member_vec.is_empty ())
   9195 	{
   9196 	  tree t = omp_private_member_vec.pop ();
   9197 	  if (t == error_mark_node)
   9198 	    {
   9199 	      add_stmt (stmt);
   9200 	      return;
   9201 	    }
   9202 	  bool no_decl_expr = t == integer_zero_node;
   9203 	  if (no_decl_expr)
   9204 	    t = omp_private_member_vec.pop ();
   9205 	  tree *v = omp_private_member_map->get (t);
   9206 	  gcc_assert (v);
   9207 	  if (!no_decl_expr)
   9208 	    add_decl_expr (*v);
   9209 	  omp_private_member_map->remove (t);
   9210 	}
   9211       delete omp_private_member_map;
   9212       omp_private_member_map = NULL;
   9213     }
   9214   add_stmt (stmt);
   9215 }
   9216 
   9217 /* Remember OpenMP privatization clauses mapping and clear it.
   9218    Used for lambdas.  */
   9219 
   9220 void
   9221 save_omp_privatization_clauses (vec<tree> &save)
   9222 {
   9223   save = vNULL;
   9224   if (omp_private_member_ignore_next)
   9225     save.safe_push (integer_one_node);
   9226   omp_private_member_ignore_next = false;
   9227   if (!omp_private_member_map)
   9228     return;
   9229 
   9230   while (!omp_private_member_vec.is_empty ())
   9231     {
   9232       tree t = omp_private_member_vec.pop ();
   9233       if (t == error_mark_node)
   9234 	{
   9235 	  save.safe_push (t);
   9236 	  continue;
   9237 	}
   9238       tree n = t;
   9239       if (t == integer_zero_node)
   9240 	t = omp_private_member_vec.pop ();
   9241       tree *v = omp_private_member_map->get (t);
   9242       gcc_assert (v);
   9243       save.safe_push (*v);
   9244       save.safe_push (t);
   9245       if (n != t)
   9246 	save.safe_push (n);
   9247     }
   9248   delete omp_private_member_map;
   9249   omp_private_member_map = NULL;
   9250 }
   9251 
   9252 /* Restore OpenMP privatization clauses mapping saved by the
   9253    above function.  */
   9254 
   9255 void
   9256 restore_omp_privatization_clauses (vec<tree> &save)
   9257 {
   9258   gcc_assert (omp_private_member_vec.is_empty ());
   9259   omp_private_member_ignore_next = false;
   9260   if (save.is_empty ())
   9261     return;
   9262   if (save.length () == 1 && save[0] == integer_one_node)
   9263     {
   9264       omp_private_member_ignore_next = true;
   9265       save.release ();
   9266       return;
   9267     }
   9268 
   9269   omp_private_member_map = new hash_map <tree, tree>;
   9270   while (!save.is_empty ())
   9271     {
   9272       tree t = save.pop ();
   9273       tree n = t;
   9274       if (t != error_mark_node)
   9275 	{
   9276 	  if (t == integer_one_node)
   9277 	    {
   9278 	      omp_private_member_ignore_next = true;
   9279 	      gcc_assert (save.is_empty ());
   9280 	      break;
   9281 	    }
   9282 	  if (t == integer_zero_node)
   9283 	    t = save.pop ();
   9284 	  tree &v = omp_private_member_map->get_or_insert (t);
   9285 	  v = save.pop ();
   9286 	}
   9287       omp_private_member_vec.safe_push (t);
   9288       if (n != t)
   9289 	omp_private_member_vec.safe_push (n);
   9290     }
   9291   save.release ();
   9292 }
   9293 
   9294 /* For all variables in the tree_list VARS, mark them as thread local.  */
   9295 
   9296 void
   9297 finish_omp_threadprivate (tree vars)
   9298 {
   9299   tree t;
   9300 
   9301   /* Mark every variable in VARS to be assigned thread local storage.  */
   9302   for (t = vars; t; t = TREE_CHAIN (t))
   9303     {
   9304       tree v = TREE_PURPOSE (t);
   9305 
   9306       if (error_operand_p (v))
   9307 	;
   9308       else if (!VAR_P (v))
   9309 	error ("%<threadprivate%> %qD is not file, namespace "
   9310 	       "or block scope variable", v);
   9311       /* If V had already been marked threadprivate, it doesn't matter
   9312 	 whether it had been used prior to this point.  */
   9313       else if (TREE_USED (v)
   9314 	  && (DECL_LANG_SPECIFIC (v) == NULL
   9315 	      || !CP_DECL_THREADPRIVATE_P (v)))
   9316 	error ("%qE declared %<threadprivate%> after first use", v);
   9317       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
   9318 	error ("automatic variable %qE cannot be %<threadprivate%>", v);
   9319       else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
   9320 	error ("%<threadprivate%> %qE has incomplete type", v);
   9321       else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
   9322 	       && CP_DECL_CONTEXT (v) != current_class_type)
   9323 	error ("%<threadprivate%> %qE directive not "
   9324 	       "in %qT definition", v, CP_DECL_CONTEXT (v));
   9325       else
   9326 	{
   9327 	  /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
   9328 	  if (DECL_LANG_SPECIFIC (v) == NULL)
   9329 	    retrofit_lang_decl (v);
   9330 
   9331 	  if (! CP_DECL_THREAD_LOCAL_P (v))
   9332 	    {
   9333 	      CP_DECL_THREAD_LOCAL_P (v) = true;
   9334 	      set_decl_tls_model (v, decl_default_tls_model (v));
   9335 	      /* If rtl has been already set for this var, call
   9336 		 make_decl_rtl once again, so that encode_section_info
   9337 		 has a chance to look at the new decl flags.  */
   9338 	      if (DECL_RTL_SET_P (v))
   9339 		make_decl_rtl (v);
   9340 	    }
   9341 	  CP_DECL_THREADPRIVATE_P (v) = 1;
   9342 	}
   9343     }
   9344 }
   9345 
   9346 /* Build an OpenMP structured block.  */
   9347 
   9348 tree
   9349 begin_omp_structured_block (void)
   9350 {
   9351   return do_pushlevel (sk_omp);
   9352 }
   9353 
   9354 tree
   9355 finish_omp_structured_block (tree block)
   9356 {
   9357   return do_poplevel (block);
   9358 }
   9359 
   9360 /* Similarly, except force the retention of the BLOCK.  */
   9361 
   9362 tree
   9363 begin_omp_parallel (void)
   9364 {
   9365   keep_next_level (true);
   9366   return begin_omp_structured_block ();
   9367 }
   9368 
   9369 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   9370    statement.  */
   9371 
   9372 tree
   9373 finish_oacc_data (tree clauses, tree block)
   9374 {
   9375   tree stmt;
   9376 
   9377   block = finish_omp_structured_block (block);
   9378 
   9379   stmt = make_node (OACC_DATA);
   9380   TREE_TYPE (stmt) = void_type_node;
   9381   OACC_DATA_CLAUSES (stmt) = clauses;
   9382   OACC_DATA_BODY (stmt) = block;
   9383 
   9384   return add_stmt (stmt);
   9385 }
   9386 
   9387 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   9388    statement.  */
   9389 
   9390 tree
   9391 finish_oacc_host_data (tree clauses, tree block)
   9392 {
   9393   tree stmt;
   9394 
   9395   block = finish_omp_structured_block (block);
   9396 
   9397   stmt = make_node (OACC_HOST_DATA);
   9398   TREE_TYPE (stmt) = void_type_node;
   9399   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   9400   OACC_HOST_DATA_BODY (stmt) = block;
   9401 
   9402   return add_stmt (stmt);
   9403 }
   9404 
   9405 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   9406    statement.  */
   9407 
   9408 tree
   9409 finish_omp_construct (enum tree_code code, tree body, tree clauses)
   9410 {
   9411   body = finish_omp_structured_block (body);
   9412 
   9413   tree stmt = make_node (code);
   9414   TREE_TYPE (stmt) = void_type_node;
   9415   OMP_BODY (stmt) = body;
   9416   OMP_CLAUSES (stmt) = clauses;
   9417 
   9418   return add_stmt (stmt);
   9419 }
   9420 
   9421 /* Used to walk OpenMP target directive body.  */
   9422 
   9423 struct omp_target_walk_data
   9424 {
   9425   /* Holds the 'this' expression found in current function.  */
   9426   tree current_object;
   9427 
   9428   /* True if the 'this' expression was accessed in the target body.  */
   9429   bool this_expr_accessed;
   9430 
   9431   /* For non-static functions, record which pointer-typed members were
   9432      accessed, and the whole expression.  */
   9433   hash_map<tree, tree> ptr_members_accessed;
   9434 
   9435   /* Record which lambda objects were accessed in target body.  */
   9436   hash_set<tree> lambda_objects_accessed;
   9437 
   9438   /* For lambda functions, the __closure object expression of the current
   9439      function, and the set of captured variables accessed in target body.  */
   9440   tree current_closure;
   9441   hash_set<tree> closure_vars_accessed;
   9442 
   9443   /* Local variables declared inside a BIND_EXPR, used to filter out such
   9444      variables when recording lambda_objects_accessed.  */
   9445   hash_set<tree> local_decls;
   9446 };
   9447 
   9448 /* Helper function of finish_omp_target_clauses, called via
   9449    cp_walk_tree_without_duplicates.  Traverse body of OpenMP target
   9450    directive *TP, and fill out omp_target_walk_data passed in *PTR.  */
   9451 
   9452 static tree
   9453 finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
   9454 {
   9455   tree t = *tp;
   9456   struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
   9457   tree current_object = data->current_object;
   9458   tree current_closure = data->current_closure;
   9459 
   9460   /* References inside of these expression codes shouldn't incur any
   9461      form of mapping, so return early.  */
   9462   if (TREE_CODE (t) == SIZEOF_EXPR
   9463       || TREE_CODE (t) == ALIGNOF_EXPR)
   9464     {
   9465       *walk_subtrees = 0;
   9466       return NULL_TREE;
   9467     }
   9468 
   9469   if (TREE_CODE (t) == OMP_CLAUSE)
   9470     return NULL_TREE;
   9471 
   9472   if (current_object)
   9473     {
   9474       tree this_expr = TREE_OPERAND (current_object, 0);
   9475 
   9476       if (operand_equal_p (t, this_expr))
   9477 	{
   9478 	  data->this_expr_accessed = true;
   9479 	  *walk_subtrees = 0;
   9480 	  return NULL_TREE;
   9481 	}
   9482 
   9483       if (TREE_CODE (t) == COMPONENT_REF
   9484 	  && POINTER_TYPE_P (TREE_TYPE (t))
   9485 	  && operand_equal_p (TREE_OPERAND (t, 0), current_object)
   9486 	  && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
   9487 	{
   9488 	  data->this_expr_accessed = true;
   9489 	  tree fld = TREE_OPERAND (t, 1);
   9490 	  if (data->ptr_members_accessed.get (fld) == NULL)
   9491 	    {
   9492 	      if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
   9493 		t = convert_from_reference (t);
   9494 	      data->ptr_members_accessed.put (fld, t);
   9495 	    }
   9496 	  *walk_subtrees = 0;
   9497 	  return NULL_TREE;
   9498 	}
   9499     }
   9500 
   9501   /* When the current_function_decl is a lambda function, the closure object
   9502      argument's type seems to not yet have fields layed out, so a recording
   9503      of DECL_VALUE_EXPRs during the target body walk seems the only way to
   9504      find them.  */
   9505   if (current_closure
   9506       && (TREE_CODE (t) == VAR_DECL
   9507 	  || TREE_CODE (t) == PARM_DECL
   9508 	  || TREE_CODE (t) == RESULT_DECL)
   9509       && DECL_HAS_VALUE_EXPR_P (t)
   9510       && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
   9511       && operand_equal_p (current_closure,
   9512 			  TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
   9513     {
   9514       if (!data->closure_vars_accessed.contains (t))
   9515 	data->closure_vars_accessed.add (t);
   9516       *walk_subtrees = 0;
   9517       return NULL_TREE;
   9518     }
   9519 
   9520   if (TREE_CODE (t) == BIND_EXPR)
   9521     {
   9522       tree block = BIND_EXPR_BLOCK (t);
   9523       for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
   9524 	if (!data->local_decls.contains (var))
   9525 	  data->local_decls.add (var);
   9526       return NULL_TREE;
   9527     }
   9528 
   9529   if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
   9530     {
   9531       tree lt = TREE_TYPE (t);
   9532       gcc_assert (CLASS_TYPE_P (lt));
   9533 
   9534       if (!data->lambda_objects_accessed.contains (t)
   9535 	  /* Do not prepare to create target maps for locally declared
   9536 	     lambdas or anonymous ones.  */
   9537 	  && !data->local_decls.contains (t)
   9538 	  && TREE_CODE (t) != TARGET_EXPR)
   9539 	data->lambda_objects_accessed.add (t);
   9540       *walk_subtrees = 0;
   9541       return NULL_TREE;
   9542     }
   9543 
   9544   return NULL_TREE;
   9545 }
   9546 
   9547 /* Helper function for finish_omp_target, and also from tsubst_expr.
   9548    Create additional clauses for mapping of non-static members, lambda objects,
   9549    etc.  */
   9550 
   9551 void
   9552 finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
   9553 {
   9554   omp_target_walk_data data;
   9555   data.this_expr_accessed = false;
   9556   data.current_object = NULL_TREE;
   9557 
   9558   if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
   9559     if (tree ct = current_nonlambda_class_type ())
   9560       {
   9561 	tree object = maybe_dummy_object (ct, NULL);
   9562 	object = maybe_resolve_dummy (object, true);
   9563 	data.current_object = object;
   9564       }
   9565 
   9566   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   9567     {
   9568       tree closure = DECL_ARGUMENTS (current_function_decl);
   9569       data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   9570     }
   9571   else
   9572     data.current_closure = NULL_TREE;
   9573 
   9574   cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r, &data);
   9575 
   9576   auto_vec<tree, 16> new_clauses;
   9577 
   9578   tree omp_target_this_expr = NULL_TREE;
   9579   tree *explicit_this_deref_map = NULL;
   9580   if (data.this_expr_accessed)
   9581     {
   9582       omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
   9583 
   9584       /* See if explicit user-specified map(this[:]) clause already exists.
   9585 	 If not, we create an implicit map(tofrom:this[:1]) clause.  */
   9586       for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
   9587 	if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
   9588 	    && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
   9589 		|| TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
   9590 	    && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
   9591 				omp_target_this_expr))
   9592 	  {
   9593 	    explicit_this_deref_map = cp;
   9594 	    break;
   9595 	  }
   9596     }
   9597 
   9598   if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   9599       && (data.this_expr_accessed
   9600 	  || !data.closure_vars_accessed.is_empty ()))
   9601     {
   9602       /* For lambda functions, we need to first create a copy of the
   9603 	 __closure object.  */
   9604       tree closure = DECL_ARGUMENTS (current_function_decl);
   9605       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9606       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   9607       OMP_CLAUSE_DECL (c)
   9608 	= build_indirect_ref (loc, closure, RO_UNARY_STAR);
   9609       OMP_CLAUSE_SIZE (c)
   9610 	= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
   9611       new_clauses.safe_push (c);
   9612 
   9613       tree closure_obj = OMP_CLAUSE_DECL (c);
   9614       tree closure_type = TREE_TYPE (closure_obj);
   9615 
   9616       gcc_assert (LAMBDA_TYPE_P (closure_type)
   9617 		  && CLASS_TYPE_P (closure_type));
   9618 
   9619       tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9620       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   9621       OMP_CLAUSE_DECL (c2) = closure;
   9622       OMP_CLAUSE_SIZE (c2) = size_zero_node;
   9623       new_clauses.safe_push (c2);
   9624     }
   9625 
   9626   if (data.this_expr_accessed)
   9627     {
   9628       /* If the this-expr was accessed, create a map(*this) clause.  */
   9629       enum gomp_map_kind kind = GOMP_MAP_TOFROM;
   9630       if (explicit_this_deref_map)
   9631 	{
   9632 	  tree this_map = *explicit_this_deref_map;
   9633 	  tree nc = OMP_CLAUSE_CHAIN (this_map);
   9634 	  gcc_assert (nc != NULL_TREE
   9635 		      && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   9636 		      && (OMP_CLAUSE_MAP_KIND (nc)
   9637 			  == GOMP_MAP_FIRSTPRIVATE_POINTER));
   9638 	  kind = OMP_CLAUSE_MAP_KIND (this_map);
   9639 	  /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
   9640 	     two-map sequence away from the chain.  */
   9641 	  *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
   9642 	}
   9643       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9644       OMP_CLAUSE_SET_MAP_KIND (c, kind);
   9645       OMP_CLAUSE_DECL (c)
   9646 	= build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
   9647       OMP_CLAUSE_SIZE (c)
   9648 	= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
   9649       new_clauses.safe_push (c);
   9650 
   9651       /* If we're in a lambda function, the this-pointer will actually be
   9652 	 '__closure->this', a mapped member of __closure, hence always_pointer.
   9653 	 Otherwise it's a firstprivate pointer.  */
   9654       enum gomp_map_kind ptr_kind
   9655 	= (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   9656 	   ? GOMP_MAP_ALWAYS_POINTER
   9657 	   : GOMP_MAP_FIRSTPRIVATE_POINTER);
   9658       c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9659       OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   9660       OMP_CLAUSE_DECL (c) = omp_target_this_expr;
   9661       OMP_CLAUSE_SIZE (c) = size_zero_node;
   9662       new_clauses.safe_push (c);
   9663     }
   9664 
   9665   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   9666     {
   9667       if (omp_target_this_expr)
   9668 	{
   9669 	  STRIP_NOPS (omp_target_this_expr);
   9670 	  gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
   9671 	  omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
   9672 	}
   9673 
   9674       for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
   9675 	   i != data.closure_vars_accessed.end (); ++i)
   9676 	{
   9677 	  tree orig_decl = *i;
   9678 	  tree closure_expr = DECL_VALUE_EXPR (orig_decl);
   9679 
   9680 	  if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
   9681 	      || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
   9682 	    {
   9683 	      /* this-pointer is processed above, outside this loop.  */
   9684 	      if (omp_target_this_expr
   9685 		  && operand_equal_p (closure_expr, omp_target_this_expr))
   9686 		continue;
   9687 
   9688 	      bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
   9689 	      enum gomp_map_kind kind, ptr_kind, nc_kind;
   9690 	      tree size;
   9691 
   9692 	      if (ptr_p)
   9693 		{
   9694 		  /* For pointers, default mapped as zero-length array
   9695 		     section.  */
   9696 		  kind = GOMP_MAP_ALLOC;
   9697 		  nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   9698 		  ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   9699 		  size = size_zero_node;
   9700 		}
   9701 	      else
   9702 		{
   9703 		  /* For references, default mapped as appearing on map
   9704 		     clause.  */
   9705 		  kind = GOMP_MAP_TOFROM;
   9706 		  nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
   9707 		  ptr_kind = GOMP_MAP_ALWAYS_POINTER;
   9708 		  size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
   9709 		}
   9710 
   9711 	      for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
   9712 		if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
   9713 		    && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
   9714 			|| TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
   9715 		    && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
   9716 					orig_decl))
   9717 		  {
   9718 		    /* If this was already specified by user as a map,
   9719 		       save the user specified map kind, delete the
   9720 		       "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
   9721 		       and insert our own sequence:
   9722 		       "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
   9723 		    */
   9724 		    tree nc = OMP_CLAUSE_CHAIN (*p);
   9725 		    gcc_assert (nc != NULL_TREE
   9726 				&& OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   9727 				&& OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
   9728 		    /* Update with user specified kind and size.  */
   9729 		    kind = OMP_CLAUSE_MAP_KIND (*p);
   9730 		    size = OMP_CLAUSE_SIZE (*p);
   9731 		    *p = OMP_CLAUSE_CHAIN (nc);
   9732 		    break;
   9733 		  }
   9734 
   9735 	      tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9736 	      OMP_CLAUSE_SET_MAP_KIND (c, kind);
   9737 	      OMP_CLAUSE_DECL (c)
   9738 		= build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
   9739 	      OMP_CLAUSE_SIZE (c) = size;
   9740 	      if (ptr_p)
   9741 		OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   9742 	      new_clauses.safe_push (c);
   9743 
   9744 	      c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9745 	      OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   9746 	      OMP_CLAUSE_DECL (c) = closure_expr;
   9747 	      OMP_CLAUSE_SIZE (c) = size_zero_node;
   9748 	      new_clauses.safe_push (c);
   9749 	    }
   9750 	}
   9751     }
   9752 
   9753   if (!data.ptr_members_accessed.is_empty ())
   9754     for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
   9755 	 i != data.ptr_members_accessed.end (); ++i)
   9756       {
   9757 	/* For each referenced member that is of pointer or reference-to-pointer
   9758 	   type, create the equivalent of map(alloc:this->ptr[:0]).  */
   9759 	tree field_decl = (*i).first;
   9760 	tree ptr_member = (*i).second;
   9761 
   9762 	for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
   9763 	  {
   9764 	    if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   9765 	      continue;
   9766 	    /* If map(this->ptr[:N]) already exists, avoid creating another
   9767 	       such map.  */
   9768 	    tree decl = OMP_CLAUSE_DECL (c);
   9769 	    if ((TREE_CODE (decl) == INDIRECT_REF
   9770 		 || TREE_CODE (decl) == MEM_REF)
   9771 		&& operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
   9772 	      goto next_ptr_member;
   9773 	  }
   9774 
   9775 	if (!cxx_mark_addressable (ptr_member))
   9776 	  gcc_unreachable ();
   9777 
   9778 	if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
   9779 	  {
   9780 	    /* For reference to pointers, we need to map the referenced
   9781 	       pointer first for things to be correct.  */
   9782 	    tree ptr_member_type = TREE_TYPE (ptr_member);
   9783 
   9784 	    /* Map pointer target as zero-length array section.  */
   9785 	    tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9786 	    OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   9787 	    OMP_CLAUSE_DECL (c)
   9788 	      = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
   9789 	    OMP_CLAUSE_SIZE (c) = size_zero_node;
   9790 	    OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   9791 
   9792 	    /* Map pointer to zero-length array section.  */
   9793 	    tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9794 	    OMP_CLAUSE_SET_MAP_KIND
   9795 	      (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
   9796 	    OMP_CLAUSE_DECL (c2) = ptr_member;
   9797 	    OMP_CLAUSE_SIZE (c2) = size_zero_node;
   9798 
   9799 	    /* Attach reference-to-pointer field to pointer.  */
   9800 	    tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9801 	    OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
   9802 	    OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
   9803 	    OMP_CLAUSE_SIZE (c3) = size_zero_node;
   9804 
   9805 	    new_clauses.safe_push (c);
   9806 	    new_clauses.safe_push (c2);
   9807 	    new_clauses.safe_push (c3);
   9808 	  }
   9809 	else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
   9810 	  {
   9811 	    /* Map pointer target as zero-length array section.  */
   9812 	    tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9813 	    OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   9814 	    OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
   9815 						      RO_UNARY_STAR);
   9816 	    OMP_CLAUSE_SIZE (c) = size_zero_node;
   9817 	    OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   9818 
   9819 	    /* Attach zero-length array section to pointer.  */
   9820 	    tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9821 	    OMP_CLAUSE_SET_MAP_KIND
   9822 	      (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   9823 	    OMP_CLAUSE_DECL (c2) = ptr_member;
   9824 	    OMP_CLAUSE_SIZE (c2) = size_zero_node;
   9825 
   9826 	    new_clauses.safe_push (c);
   9827 	    new_clauses.safe_push (c2);
   9828 	  }
   9829 	else
   9830 	  gcc_unreachable ();
   9831 
   9832       next_ptr_member:
   9833 	;
   9834       }
   9835 
   9836   for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
   9837        i != data.lambda_objects_accessed.end (); ++i)
   9838     {
   9839       tree lobj = *i;
   9840       if (TREE_CODE (lobj) == TARGET_EXPR)
   9841 	lobj = TREE_OPERAND (lobj, 0);
   9842 
   9843       tree lt = TREE_TYPE (lobj);
   9844       gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
   9845 
   9846       tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9847       OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
   9848       OMP_CLAUSE_DECL (lc) = lobj;
   9849       OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
   9850       new_clauses.safe_push (lc);
   9851 
   9852       for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
   9853 	{
   9854 	  if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
   9855 	    {
   9856 	      tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   9857 				 lobj, fld, NULL_TREE);
   9858 	      tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9859 	      OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   9860 	      OMP_CLAUSE_DECL (c)
   9861 		= build_indirect_ref (loc, exp, RO_UNARY_STAR);
   9862 	      OMP_CLAUSE_SIZE (c) = size_zero_node;
   9863 	      OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   9864 	      new_clauses.safe_push (c);
   9865 
   9866 	      c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9867 	      OMP_CLAUSE_SET_MAP_KIND
   9868 		(c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   9869 	      OMP_CLAUSE_DECL (c) = exp;
   9870 	      OMP_CLAUSE_SIZE (c) = size_zero_node;
   9871 	      new_clauses.safe_push (c);
   9872 	    }
   9873 	  else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
   9874 	    {
   9875 	      tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   9876 				 lobj, fld, NULL_TREE);
   9877 	      tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9878 	      OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   9879 	      OMP_CLAUSE_DECL (c)
   9880 		= build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
   9881 	      OMP_CLAUSE_SIZE (c)
   9882 		= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
   9883 	      new_clauses.safe_push (c);
   9884 
   9885 	      c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   9886 	      OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   9887 	      OMP_CLAUSE_DECL (c) = exp;
   9888 	      OMP_CLAUSE_SIZE (c) = size_zero_node;
   9889 	      new_clauses.safe_push (c);
   9890 	    }
   9891 	}
   9892     }
   9893 
   9894   tree c = *clauses_ptr;
   9895   for (int i = new_clauses.length () - 1; i >= 0; i--)
   9896     {
   9897       OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
   9898       c = new_clauses[i];
   9899     }
   9900   *clauses_ptr = c;
   9901 }
   9902 
   9903 /* Called from cp_parser_omp_target.  Create additional implicit clauses for
   9904    OpenMP target directives, and do sanity checks.  */
   9905 
   9906 tree
   9907 finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
   9908 {
   9909   if (!processing_template_decl)
   9910     finish_omp_target_clauses (loc, body, &clauses);
   9911 
   9912   tree stmt = make_node (OMP_TARGET);
   9913   TREE_TYPE (stmt) = void_type_node;
   9914   OMP_TARGET_CLAUSES (stmt) = clauses;
   9915   OMP_TARGET_BODY (stmt) = body;
   9916   OMP_TARGET_COMBINED (stmt) = combined_p;
   9917   SET_EXPR_LOCATION (stmt, loc);
   9918 
   9919   tree c = clauses;
   9920   while (c)
   9921     {
   9922       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   9923 	switch (OMP_CLAUSE_MAP_KIND (c))
   9924 	  {
   9925 	  case GOMP_MAP_TO:
   9926 	  case GOMP_MAP_ALWAYS_TO:
   9927 	  case GOMP_MAP_FROM:
   9928 	  case GOMP_MAP_ALWAYS_FROM:
   9929 	  case GOMP_MAP_TOFROM:
   9930 	  case GOMP_MAP_ALWAYS_TOFROM:
   9931 	  case GOMP_MAP_ALLOC:
   9932 	  case GOMP_MAP_FIRSTPRIVATE_POINTER:
   9933 	  case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   9934 	  case GOMP_MAP_ALWAYS_POINTER:
   9935 	  case GOMP_MAP_ATTACH_DETACH:
   9936 	  case GOMP_MAP_ATTACH:
   9937 	  case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   9938 	  case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   9939 	    break;
   9940 	  default:
   9941 	    error_at (OMP_CLAUSE_LOCATION (c),
   9942 		      "%<#pragma omp target%> with map-type other "
   9943 		      "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
   9944 		      "on %<map%> clause");
   9945 	    break;
   9946 	  }
   9947       c = OMP_CLAUSE_CHAIN (c);
   9948     }
   9949   return add_stmt (stmt);
   9950 }
   9951 
   9952 tree
   9953 finish_omp_parallel (tree clauses, tree body)
   9954 {
   9955   tree stmt;
   9956 
   9957   body = finish_omp_structured_block (body);
   9958 
   9959   stmt = make_node (OMP_PARALLEL);
   9960   TREE_TYPE (stmt) = void_type_node;
   9961   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   9962   OMP_PARALLEL_BODY (stmt) = body;
   9963 
   9964   return add_stmt (stmt);
   9965 }
   9966 
   9967 tree
   9968 begin_omp_task (void)
   9969 {
   9970   keep_next_level (true);
   9971   return begin_omp_structured_block ();
   9972 }
   9973 
   9974 tree
   9975 finish_omp_task (tree clauses, tree body)
   9976 {
   9977   tree stmt;
   9978 
   9979   body = finish_omp_structured_block (body);
   9980 
   9981   stmt = make_node (OMP_TASK);
   9982   TREE_TYPE (stmt) = void_type_node;
   9983   OMP_TASK_CLAUSES (stmt) = clauses;
   9984   OMP_TASK_BODY (stmt) = body;
   9985 
   9986   return add_stmt (stmt);
   9987 }
   9988 
   9989 /* Helper function for finish_omp_for.  Convert Ith random access iterator
   9990    into integral iterator.  Return FALSE if successful.  */
   9991 
   9992 static bool
   9993 handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
   9994 			       tree declv, tree orig_declv, tree initv,
   9995 			       tree condv, tree incrv, tree *body,
   9996 			       tree *pre_body, tree &clauses,
   9997 			       int collapse, int ordered)
   9998 {
   9999   tree diff, iter_init, iter_incr = NULL, last;
   10000   tree incr_var = NULL, orig_pre_body, orig_body, c;
   10001   tree decl = TREE_VEC_ELT (declv, i);
   10002   tree init = TREE_VEC_ELT (initv, i);
   10003   tree cond = TREE_VEC_ELT (condv, i);
   10004   tree incr = TREE_VEC_ELT (incrv, i);
   10005   tree iter = decl;
   10006   location_t elocus = locus;
   10007 
   10008   if (init && EXPR_HAS_LOCATION (init))
   10009     elocus = EXPR_LOCATION (init);
   10010 
   10011   switch (TREE_CODE (cond))
   10012     {
   10013     case GT_EXPR:
   10014     case GE_EXPR:
   10015     case LT_EXPR:
   10016     case LE_EXPR:
   10017     case NE_EXPR:
   10018       if (TREE_OPERAND (cond, 1) == iter)
   10019 	cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
   10020 		       TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
   10021       if (TREE_OPERAND (cond, 0) != iter)
   10022 	cond = error_mark_node;
   10023       else
   10024 	{
   10025 	  tree tem = build_x_binary_op (EXPR_LOCATION (cond),
   10026 					TREE_CODE (cond),
   10027 					iter, ERROR_MARK,
   10028 					TREE_OPERAND (cond, 1), ERROR_MARK,
   10029 					NULL_TREE, NULL, tf_warning_or_error);
   10030 	  if (error_operand_p (tem))
   10031 	    return true;
   10032 	}
   10033       break;
   10034     default:
   10035       cond = error_mark_node;
   10036       break;
   10037     }
   10038   if (cond == error_mark_node)
   10039     {
   10040       error_at (elocus, "invalid controlling predicate");
   10041       return true;
   10042     }
   10043   diff = build_x_binary_op (elocus, MINUS_EXPR,
   10044 			    TREE_OPERAND (cond, 1), ERROR_MARK,
   10045 			    iter, ERROR_MARK,
   10046 			    NULL_TREE, NULL, tf_warning_or_error);
   10047   diff = cp_fully_fold (diff);
   10048   if (error_operand_p (diff))
   10049     return true;
   10050   if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
   10051     {
   10052       error_at (elocus, "difference between %qE and %qD does not have integer type",
   10053 		TREE_OPERAND (cond, 1), iter);
   10054       return true;
   10055     }
   10056   if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
   10057 				  TREE_VEC_ELT (declv, i), NULL_TREE,
   10058 				  cond, cp_walk_subtrees))
   10059     return true;
   10060 
   10061   switch (TREE_CODE (incr))
   10062     {
   10063     case PREINCREMENT_EXPR:
   10064     case PREDECREMENT_EXPR:
   10065     case POSTINCREMENT_EXPR:
   10066     case POSTDECREMENT_EXPR:
   10067       if (TREE_OPERAND (incr, 0) != iter)
   10068 	{
   10069 	  incr = error_mark_node;
   10070 	  break;
   10071 	}
   10072       iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
   10073 				    TREE_CODE (incr), iter,
   10074 				    NULL_TREE, tf_warning_or_error);
   10075       if (error_operand_p (iter_incr))
   10076 	return true;
   10077       else if (TREE_CODE (incr) == PREINCREMENT_EXPR
   10078 	       || TREE_CODE (incr) == POSTINCREMENT_EXPR)
   10079 	incr = integer_one_node;
   10080       else
   10081 	incr = integer_minus_one_node;
   10082       break;
   10083     case MODIFY_EXPR:
   10084       if (TREE_OPERAND (incr, 0) != iter)
   10085 	incr = error_mark_node;
   10086       else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
   10087 	       || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
   10088 	{
   10089 	  tree rhs = TREE_OPERAND (incr, 1);
   10090 	  if (TREE_OPERAND (rhs, 0) == iter)
   10091 	    {
   10092 	      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
   10093 		  != INTEGER_TYPE)
   10094 		incr = error_mark_node;
   10095 	      else
   10096 		{
   10097 		  iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   10098 						   iter, TREE_CODE (rhs),
   10099 						   TREE_OPERAND (rhs, 1),
   10100 						   NULL_TREE,
   10101 						   tf_warning_or_error);
   10102 		  if (error_operand_p (iter_incr))
   10103 		    return true;
   10104 		  incr = TREE_OPERAND (rhs, 1);
   10105 		  incr = cp_convert (TREE_TYPE (diff), incr,
   10106 				     tf_warning_or_error);
   10107 		  if (TREE_CODE (rhs) == MINUS_EXPR)
   10108 		    {
   10109 		      incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
   10110 		      incr = fold_simple (incr);
   10111 		    }
   10112 		  if (TREE_CODE (incr) != INTEGER_CST
   10113 		      && (TREE_CODE (incr) != NOP_EXPR
   10114 			  || (TREE_CODE (TREE_OPERAND (incr, 0))
   10115 			      != INTEGER_CST)))
   10116 		    iter_incr = NULL;
   10117 		}
   10118 	    }
   10119 	  else if (TREE_OPERAND (rhs, 1) == iter)
   10120 	    {
   10121 	      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
   10122 		  || TREE_CODE (rhs) != PLUS_EXPR)
   10123 		incr = error_mark_node;
   10124 	      else
   10125 		{
   10126 		  iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
   10127 						 PLUS_EXPR,
   10128 						 TREE_OPERAND (rhs, 0),
   10129 						 ERROR_MARK, iter,
   10130 						 ERROR_MARK, NULL_TREE, NULL,
   10131 						 tf_warning_or_error);
   10132 		  if (error_operand_p (iter_incr))
   10133 		    return true;
   10134 		  iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   10135 						   iter, NOP_EXPR,
   10136 						   iter_incr, NULL_TREE,
   10137 						   tf_warning_or_error);
   10138 		  if (error_operand_p (iter_incr))
   10139 		    return true;
   10140 		  incr = TREE_OPERAND (rhs, 0);
   10141 		  iter_incr = NULL;
   10142 		}
   10143 	    }
   10144 	  else
   10145 	    incr = error_mark_node;
   10146 	}
   10147       else
   10148 	incr = error_mark_node;
   10149       break;
   10150     default:
   10151       incr = error_mark_node;
   10152       break;
   10153     }
   10154 
   10155   if (incr == error_mark_node)
   10156     {
   10157       error_at (elocus, "invalid increment expression");
   10158       return true;
   10159     }
   10160 
   10161   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
   10162   incr = cp_fully_fold (incr);
   10163   tree loop_iv_seen = NULL_TREE;
   10164   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
   10165     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   10166 	&& OMP_CLAUSE_DECL (c) == iter)
   10167       {
   10168 	if (code == OMP_TASKLOOP || code == OMP_LOOP)
   10169 	  {
   10170 	    loop_iv_seen = c;
   10171 	    OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
   10172 	  }
   10173 	break;
   10174       }
   10175     else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
   10176 	     && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   10177 	     && OMP_CLAUSE_DECL (c) == iter)
   10178       {
   10179 	loop_iv_seen = c;
   10180 	if (code == OMP_TASKLOOP)
   10181 	  OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
   10182       }
   10183 
   10184   decl = create_temporary_var (TREE_TYPE (diff));
   10185   pushdecl (decl);
   10186   add_decl_expr (decl);
   10187   last = create_temporary_var (TREE_TYPE (diff));
   10188   pushdecl (last);
   10189   add_decl_expr (last);
   10190   if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
   10191       && (!ordered || (i < collapse && collapse > 1)))
   10192     {
   10193       incr_var = create_temporary_var (TREE_TYPE (diff));
   10194       pushdecl (incr_var);
   10195       add_decl_expr (incr_var);
   10196     }
   10197   gcc_assert (stmts_are_full_exprs_p ());
   10198   tree diffvar = NULL_TREE;
   10199   if (code == OMP_TASKLOOP)
   10200     {
   10201       if (!loop_iv_seen)
   10202 	{
   10203 	  tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   10204 	  OMP_CLAUSE_DECL (ivc) = iter;
   10205 	  cxx_omp_finish_clause (ivc, NULL, false);
   10206 	  OMP_CLAUSE_CHAIN (ivc) = clauses;
   10207 	  clauses = ivc;
   10208 	}
   10209       tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   10210       OMP_CLAUSE_DECL (lvc) = last;
   10211       OMP_CLAUSE_CHAIN (lvc) = clauses;
   10212       clauses = lvc;
   10213       diffvar = create_temporary_var (TREE_TYPE (diff));
   10214       pushdecl (diffvar);
   10215       add_decl_expr (diffvar);
   10216     }
   10217   else if (code == OMP_LOOP)
   10218     {
   10219       if (!loop_iv_seen)
   10220 	{
   10221 	  /* While iterators on the loop construct are predetermined
   10222 	     lastprivate, if the decl is not declared inside of the
   10223 	     loop, OMP_CLAUSE_LASTPRIVATE should have been added
   10224 	     already.  */
   10225 	  loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   10226 	  OMP_CLAUSE_DECL (loop_iv_seen) = iter;
   10227 	  OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
   10228 	  clauses = loop_iv_seen;
   10229 	}
   10230       else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
   10231 	{
   10232 	  OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
   10233 	  OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
   10234 	  OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
   10235 	}
   10236       if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
   10237 	cxx_omp_finish_clause (loop_iv_seen, NULL, false);
   10238     }
   10239 
   10240   orig_pre_body = *pre_body;
   10241   *pre_body = push_stmt_list ();
   10242   if (orig_pre_body)
   10243     add_stmt (orig_pre_body);
   10244   if (init != NULL)
   10245     finish_expr_stmt (build_x_modify_expr (elocus,
   10246 					   iter, NOP_EXPR, init,
   10247 					   NULL_TREE, tf_warning_or_error));
   10248   init = build_int_cst (TREE_TYPE (diff), 0);
   10249   if (c && iter_incr == NULL
   10250       && (!ordered || (i < collapse && collapse > 1)))
   10251     {
   10252       if (incr_var)
   10253 	{
   10254 	  finish_expr_stmt (build_x_modify_expr (elocus,
   10255 						 incr_var, NOP_EXPR,
   10256 						 incr, NULL_TREE,
   10257 						 tf_warning_or_error));
   10258 	  incr = incr_var;
   10259 	}
   10260       iter_incr = build_x_modify_expr (elocus,
   10261 				       iter, PLUS_EXPR, incr,
   10262 				       NULL_TREE, tf_warning_or_error);
   10263     }
   10264   if (c && ordered && i < collapse && collapse > 1)
   10265     iter_incr = incr;
   10266   finish_expr_stmt (build_x_modify_expr (elocus,
   10267 					 last, NOP_EXPR, init,
   10268 					 NULL_TREE, tf_warning_or_error));
   10269   if (diffvar)
   10270     {
   10271       finish_expr_stmt (build_x_modify_expr (elocus,
   10272 					     diffvar, NOP_EXPR,
   10273 					     diff, NULL_TREE, tf_warning_or_error));
   10274       diff = diffvar;
   10275     }
   10276   *pre_body = pop_stmt_list (*pre_body);
   10277 
   10278   cond = cp_build_binary_op (elocus,
   10279 			     TREE_CODE (cond), decl, diff,
   10280 			     tf_warning_or_error);
   10281   incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
   10282 			    elocus, incr, NULL_TREE);
   10283 
   10284   orig_body = *body;
   10285   *body = push_stmt_list ();
   10286   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
   10287   iter_init = build_x_modify_expr (elocus,
   10288 				   iter, PLUS_EXPR, iter_init,
   10289 				   NULL_TREE, tf_warning_or_error);
   10290   if (iter_init != error_mark_node)
   10291     iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   10292   finish_expr_stmt (iter_init);
   10293   finish_expr_stmt (build_x_modify_expr (elocus,
   10294 					 last, NOP_EXPR, decl,
   10295 					 NULL_TREE, tf_warning_or_error));
   10296   add_stmt (orig_body);
   10297   *body = pop_stmt_list (*body);
   10298 
   10299   if (c)
   10300     {
   10301       OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
   10302       if (!ordered)
   10303 	finish_expr_stmt (iter_incr);
   10304       else
   10305 	{
   10306 	  iter_init = decl;
   10307 	  if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
   10308 	    iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
   10309 				iter_init, iter_incr);
   10310 	  iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
   10311 	  iter_init = build_x_modify_expr (elocus,
   10312 					   iter, PLUS_EXPR, iter_init,
   10313 					   NULL_TREE, tf_warning_or_error);
   10314 	  if (iter_init != error_mark_node)
   10315 	    iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   10316 	  finish_expr_stmt (iter_init);
   10317 	}
   10318       OMP_CLAUSE_LASTPRIVATE_STMT (c)
   10319 	= pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
   10320     }
   10321 
   10322   if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
   10323     {
   10324       tree t = TREE_VEC_ELT (orig_declv, i);
   10325       gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   10326 		  && TREE_VALUE (t) == NULL_TREE
   10327 		  && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
   10328       TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
   10329       TREE_VALUE (t) = last;
   10330     }
   10331   else
   10332     TREE_VEC_ELT (orig_declv, i)
   10333       = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   10334   TREE_VEC_ELT (declv, i) = decl;
   10335   TREE_VEC_ELT (initv, i) = init;
   10336   TREE_VEC_ELT (condv, i) = cond;
   10337   TREE_VEC_ELT (incrv, i) = incr;
   10338 
   10339   return false;
   10340 }
   10341 
   10342 /* Build and validate an OMP_FOR statement.  CLAUSES, BODY, COND, INCR
   10343    are directly for their associated operands in the statement.  DECL
   10344    and INIT are a combo; if DECL is NULL then INIT ought to be a
   10345    MODIFY_EXPR, and the DECL should be extracted.  PRE_BODY are
   10346    optional statements that need to go before the loop into its
   10347    sk_omp scope.  */
   10348 
   10349 tree
   10350 finish_omp_for (location_t locus, enum tree_code code, tree declv,
   10351 		tree orig_declv, tree initv, tree condv, tree incrv,
   10352 		tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
   10353 {
   10354   tree omp_for = NULL, orig_incr = NULL;
   10355   tree decl = NULL, init, cond, incr;
   10356   location_t elocus;
   10357   int i;
   10358   int collapse = 1;
   10359   int ordered = 0;
   10360 
   10361   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
   10362   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
   10363   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
   10364   if (TREE_VEC_LENGTH (declv) > 1)
   10365     {
   10366       tree c;
   10367 
   10368       c = omp_find_clause (clauses, OMP_CLAUSE_TILE);
   10369       if (c)
   10370 	collapse = list_length (OMP_CLAUSE_TILE_LIST (c));
   10371       else
   10372 	{
   10373 	  c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE);
   10374 	  if (c)
   10375 	    collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c));
   10376 	  if (collapse != TREE_VEC_LENGTH (declv))
   10377 	    ordered = TREE_VEC_LENGTH (declv);
   10378 	}
   10379     }
   10380   for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   10381     {
   10382       decl = TREE_VEC_ELT (declv, i);
   10383       init = TREE_VEC_ELT (initv, i);
   10384       cond = TREE_VEC_ELT (condv, i);
   10385       incr = TREE_VEC_ELT (incrv, i);
   10386       elocus = locus;
   10387 
   10388       if (decl == NULL)
   10389 	{
   10390 	  if (init != NULL)
   10391 	    switch (TREE_CODE (init))
   10392 	      {
   10393 	      case MODIFY_EXPR:
   10394 		decl = TREE_OPERAND (init, 0);
   10395 		init = TREE_OPERAND (init, 1);
   10396 		break;
   10397 	      case MODOP_EXPR:
   10398 		if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
   10399 		  {
   10400 		    decl = TREE_OPERAND (init, 0);
   10401 		    init = TREE_OPERAND (init, 2);
   10402 		  }
   10403 		break;
   10404 	      default:
   10405 		break;
   10406 	      }
   10407 
   10408 	  if (decl == NULL)
   10409 	    {
   10410 	      error_at (locus,
   10411 			"expected iteration declaration or initialization");
   10412 	      return NULL;
   10413 	    }
   10414 	}
   10415 
   10416       if (init && EXPR_HAS_LOCATION (init))
   10417 	elocus = EXPR_LOCATION (init);
   10418 
   10419       if (cond == global_namespace)
   10420 	continue;
   10421 
   10422       if (cond == NULL)
   10423 	{
   10424 	  error_at (elocus, "missing controlling predicate");
   10425 	  return NULL;
   10426 	}
   10427 
   10428       if (incr == NULL)
   10429 	{
   10430 	  error_at (elocus, "missing increment expression");
   10431 	  return NULL;
   10432 	}
   10433 
   10434       TREE_VEC_ELT (declv, i) = decl;
   10435       TREE_VEC_ELT (initv, i) = init;
   10436     }
   10437 
   10438   if (orig_inits)
   10439     {
   10440       bool fail = false;
   10441       tree orig_init;
   10442       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
   10443 	if (orig_init
   10444 	    && !c_omp_check_loop_iv_exprs (locus, code,
   10445 					   orig_declv ? orig_declv : declv, i,
   10446 					   TREE_VEC_ELT (declv, i), orig_init,
   10447 					   NULL_TREE, cp_walk_subtrees))
   10448 	  fail = true;
   10449       if (fail)
   10450 	return NULL;
   10451     }
   10452 
   10453   if (dependent_omp_for_p (declv, initv, condv, incrv))
   10454     {
   10455       tree stmt;
   10456 
   10457       stmt = make_node (code);
   10458 
   10459       for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   10460 	{
   10461 	  /* This is really just a place-holder.  We'll be decomposing this
   10462 	     again and going through the cp_build_modify_expr path below when
   10463 	     we instantiate the thing.  */
   10464 	  TREE_VEC_ELT (initv, i)
   10465 	    = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i),
   10466 		      TREE_VEC_ELT (initv, i));
   10467 	}
   10468 
   10469       TREE_TYPE (stmt) = void_type_node;
   10470       OMP_FOR_INIT (stmt) = initv;
   10471       OMP_FOR_COND (stmt) = condv;
   10472       OMP_FOR_INCR (stmt) = incrv;
   10473       OMP_FOR_BODY (stmt) = body;
   10474       OMP_FOR_PRE_BODY (stmt) = pre_body;
   10475       OMP_FOR_CLAUSES (stmt) = clauses;
   10476 
   10477       SET_EXPR_LOCATION (stmt, locus);
   10478       return add_stmt (stmt);
   10479     }
   10480 
   10481   if (!orig_declv)
   10482     orig_declv = copy_node (declv);
   10483 
   10484   if (processing_template_decl)
   10485     orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
   10486 
   10487   for (i = 0; i < TREE_VEC_LENGTH (declv); )
   10488     {
   10489       decl = TREE_VEC_ELT (declv, i);
   10490       init = TREE_VEC_ELT (initv, i);
   10491       cond = TREE_VEC_ELT (condv, i);
   10492       incr = TREE_VEC_ELT (incrv, i);
   10493       if (orig_incr)
   10494 	TREE_VEC_ELT (orig_incr, i) = incr;
   10495       elocus = locus;
   10496 
   10497       if (init && EXPR_HAS_LOCATION (init))
   10498 	elocus = EXPR_LOCATION (init);
   10499 
   10500       if (!DECL_P (decl))
   10501 	{
   10502 	  error_at (elocus, "expected iteration declaration or initialization");
   10503 	  return NULL;
   10504 	}
   10505 
   10506       if (incr && TREE_CODE (incr) == MODOP_EXPR)
   10507 	{
   10508 	  if (orig_incr)
   10509 	    TREE_VEC_ELT (orig_incr, i) = incr;
   10510 	  incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
   10511 				       TREE_CODE (TREE_OPERAND (incr, 1)),
   10512 				       TREE_OPERAND (incr, 2),
   10513 				       tf_warning_or_error);
   10514 	}
   10515 
   10516       if (CLASS_TYPE_P (TREE_TYPE (decl)))
   10517 	{
   10518 	  if (code == OMP_SIMD)
   10519 	    {
   10520 	      error_at (elocus, "%<#pragma omp simd%> used with class "
   10521 				"iteration variable %qE", decl);
   10522 	      return NULL;
   10523 	    }
   10524 	  if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
   10525 					     initv, condv, incrv, &body,
   10526 					     &pre_body, clauses,
   10527 					     collapse, ordered))
   10528 	    return NULL;
   10529 	  continue;
   10530 	}
   10531 
   10532       if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
   10533 	  && !TYPE_PTR_P (TREE_TYPE (decl)))
   10534 	{
   10535 	  error_at (elocus, "invalid type for iteration variable %qE", decl);
   10536 	  return NULL;
   10537 	}
   10538 
   10539       if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
   10540 	init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
   10541 				     tf_warning_or_error);
   10542       else
   10543 	init = build2 (MODIFY_EXPR, void_type_node, decl, init);
   10544       if (decl == error_mark_node || init == error_mark_node)
   10545 	return NULL;
   10546 
   10547       TREE_VEC_ELT (declv, i) = decl;
   10548       TREE_VEC_ELT (initv, i) = init;
   10549       TREE_VEC_ELT (condv, i) = cond;
   10550       TREE_VEC_ELT (incrv, i) = incr;
   10551       i++;
   10552     }
   10553 
   10554   if (pre_body && IS_EMPTY_STMT (pre_body))
   10555     pre_body = NULL;
   10556 
   10557   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
   10558 			      incrv, body, pre_body,
   10559 			      !processing_template_decl);
   10560 
   10561   /* Check for iterators appearing in lb, b or incr expressions.  */
   10562   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
   10563     omp_for = NULL_TREE;
   10564 
   10565   if (omp_for == NULL)
   10566     return NULL;
   10567 
   10568   add_stmt (omp_for);
   10569 
   10570   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
   10571     {
   10572       init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
   10573       decl = TREE_OPERAND (init, 0);
   10574       cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
   10575       incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
   10576 
   10577       if (!processing_template_decl)
   10578 	{
   10579 	  if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
   10580 	    {
   10581 	      tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
   10582 	      TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
   10583 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10584 	      t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
   10585 	      TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
   10586 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10587 	    }
   10588 	  else
   10589 	    {
   10590 	      tree t = TREE_OPERAND (init, 1);
   10591 	      TREE_OPERAND (init, 1)
   10592 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10593 	    }
   10594 	  if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
   10595 	    {
   10596 	      tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
   10597 	      TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
   10598 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10599 	      t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
   10600 	      TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
   10601 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10602 	    }
   10603 	  else
   10604 	    {
   10605 	      tree t = TREE_OPERAND (cond, 1);
   10606 	      TREE_OPERAND (cond, 1)
   10607 		= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10608 	    }
   10609 	}
   10610 
   10611       if (TREE_CODE (incr) != MODIFY_EXPR)
   10612 	continue;
   10613 
   10614       if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
   10615 	  && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
   10616 	  && !processing_template_decl)
   10617 	{
   10618 	  tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
   10619 	  if (TREE_SIDE_EFFECTS (t)
   10620 	      && t != decl
   10621 	      && (TREE_CODE (t) != NOP_EXPR
   10622 		  || TREE_OPERAND (t, 0) != decl))
   10623 	    TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
   10624 	      = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10625 
   10626 	  t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
   10627 	  if (TREE_SIDE_EFFECTS (t)
   10628 	      && t != decl
   10629 	      && (TREE_CODE (t) != NOP_EXPR
   10630 		  || TREE_OPERAND (t, 0) != decl))
   10631 	    TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
   10632 	      = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10633 	}
   10634 
   10635       if (orig_incr)
   10636 	TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
   10637     }
   10638   OMP_FOR_CLAUSES (omp_for) = clauses;
   10639 
   10640   /* For simd loops with non-static data member iterators, we could have added
   10641      OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP.  As we know the
   10642      step at this point, fill it in.  */
   10643   if (code == OMP_SIMD && !processing_template_decl
   10644       && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
   10645     for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
   10646 	 c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
   10647       if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
   10648 	{
   10649 	  decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
   10650 	  gcc_assert (decl == OMP_CLAUSE_DECL (c));
   10651 	  incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
   10652 	  tree step, stept;
   10653 	  switch (TREE_CODE (incr))
   10654 	    {
   10655 	    case PREINCREMENT_EXPR:
   10656 	    case POSTINCREMENT_EXPR:
   10657 	      /* c_omp_for_incr_canonicalize_ptr() should have been
   10658 		 called to massage things appropriately.  */
   10659 	      gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   10660 	      OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
   10661 	      break;
   10662 	    case PREDECREMENT_EXPR:
   10663 	    case POSTDECREMENT_EXPR:
   10664 	      /* c_omp_for_incr_canonicalize_ptr() should have been
   10665 		 called to massage things appropriately.  */
   10666 	      gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   10667 	      OMP_CLAUSE_LINEAR_STEP (c)
   10668 		= build_int_cst (TREE_TYPE (decl), -1);
   10669 	      break;
   10670 	    case MODIFY_EXPR:
   10671 	      gcc_assert (TREE_OPERAND (incr, 0) == decl);
   10672 	      incr = TREE_OPERAND (incr, 1);
   10673 	      switch (TREE_CODE (incr))
   10674 		{
   10675 		case PLUS_EXPR:
   10676 		  if (TREE_OPERAND (incr, 1) == decl)
   10677 		    step = TREE_OPERAND (incr, 0);
   10678 		  else
   10679 		    step = TREE_OPERAND (incr, 1);
   10680 		  break;
   10681 		case MINUS_EXPR:
   10682 		case POINTER_PLUS_EXPR:
   10683 		  gcc_assert (TREE_OPERAND (incr, 0) == decl);
   10684 		  step = TREE_OPERAND (incr, 1);
   10685 		  break;
   10686 		default:
   10687 		  gcc_unreachable ();
   10688 		}
   10689 	      stept = TREE_TYPE (decl);
   10690 	      if (INDIRECT_TYPE_P (stept))
   10691 		stept = sizetype;
   10692 	      step = fold_convert (stept, step);
   10693 	      if (TREE_CODE (incr) == MINUS_EXPR)
   10694 		step = fold_build1 (NEGATE_EXPR, stept, step);
   10695 	      OMP_CLAUSE_LINEAR_STEP (c) = step;
   10696 	      break;
   10697 	    default:
   10698 	      gcc_unreachable ();
   10699 	    }
   10700 	}
   10701   /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
   10702      clauses, we need copy ctor for those rather than default ctor,
   10703      plus as for other lastprivates assignment op and dtor.  */
   10704   if (code == OMP_LOOP && !processing_template_decl)
   10705     for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   10706       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   10707 	  && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
   10708 	  && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
   10709 					 false, true, true, true))
   10710 	CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
   10711 
   10712   return omp_for;
   10713 }
   10714 
   10715 /* Fix up range for decls.  Those decls were pushed into BIND's BIND_EXPR_VARS
   10716    and need to be moved into the BIND_EXPR inside of the OMP_FOR's body.  */
   10717 
   10718 tree
   10719 finish_omp_for_block (tree bind, tree omp_for)
   10720 {
   10721   if (omp_for == NULL_TREE
   10722       || !OMP_FOR_ORIG_DECLS (omp_for)
   10723       || bind == NULL_TREE
   10724       || TREE_CODE (bind) != BIND_EXPR)
   10725     return bind;
   10726   tree b = NULL_TREE;
   10727   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
   10728     if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST
   10729 	&& TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
   10730       {
   10731 	tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
   10732 	gcc_assert (BIND_EXPR_BLOCK (bind)
   10733 		    && (BIND_EXPR_VARS (bind)
   10734 			== BLOCK_VARS (BIND_EXPR_BLOCK (bind))));
   10735 	for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
   10736 	  for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p))
   10737 	    {
   10738 	      if (*p == TREE_VEC_ELT (v, j))
   10739 		{
   10740 		  tree var = *p;
   10741 		  *p = DECL_CHAIN (*p);
   10742 		  if (b == NULL_TREE)
   10743 		    {
   10744 		      b = make_node (BLOCK);
   10745 		      b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   10746 				  OMP_FOR_BODY (omp_for), b);
   10747 		      TREE_SIDE_EFFECTS (b) = 1;
   10748 		      OMP_FOR_BODY (omp_for) = b;
   10749 		    }
   10750 		  DECL_CHAIN (var) = BIND_EXPR_VARS (b);
   10751 		  BIND_EXPR_VARS (b) = var;
   10752 		  BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var;
   10753 		}
   10754 	    }
   10755 	BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind);
   10756       }
   10757   return bind;
   10758 }
   10759 
   10760 void
   10761 finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
   10762 		   tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
   10763 		   tree clauses, enum omp_memory_order mo, bool weak)
   10764 {
   10765   tree orig_lhs;
   10766   tree orig_rhs;
   10767   tree orig_v;
   10768   tree orig_lhs1;
   10769   tree orig_rhs1;
   10770   tree orig_r;
   10771   bool dependent_p;
   10772   tree stmt;
   10773 
   10774   orig_lhs = lhs;
   10775   orig_rhs = rhs;
   10776   orig_v = v;
   10777   orig_lhs1 = lhs1;
   10778   orig_rhs1 = rhs1;
   10779   orig_r = r;
   10780   dependent_p = false;
   10781   stmt = NULL_TREE;
   10782 
   10783   /* Even in a template, we can detect invalid uses of the atomic
   10784      pragma if neither LHS nor RHS is type-dependent.  */
   10785   if (processing_template_decl)
   10786     {
   10787       dependent_p = (type_dependent_expression_p (lhs)
   10788 		     || (rhs && type_dependent_expression_p (rhs))
   10789 		     || (v && type_dependent_expression_p (v))
   10790 		     || (lhs1 && type_dependent_expression_p (lhs1))
   10791 		     || (rhs1 && type_dependent_expression_p (rhs1))
   10792 		     || (r
   10793 			 && r != void_list_node
   10794 			 && type_dependent_expression_p (r)));
   10795       if (clauses)
   10796 	{
   10797 	  gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
   10798 		      && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
   10799 		      && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
   10800 	  if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
   10801 	      || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
   10802 	    dependent_p = true;
   10803 	}
   10804       if (!dependent_p)
   10805 	{
   10806 	  lhs = build_non_dependent_expr (lhs);
   10807 	  if (rhs)
   10808 	    rhs = build_non_dependent_expr (rhs);
   10809 	  if (v)
   10810 	    v = build_non_dependent_expr (v);
   10811 	  if (lhs1)
   10812 	    lhs1 = build_non_dependent_expr (lhs1);
   10813 	  if (rhs1)
   10814 	    rhs1 = build_non_dependent_expr (rhs1);
   10815 	  if (r && r != void_list_node)
   10816 	    r = build_non_dependent_expr (r);
   10817 	}
   10818     }
   10819   if (!dependent_p)
   10820     {
   10821       bool swapped = false;
   10822       if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
   10823 	{
   10824 	  std::swap (rhs, rhs1);
   10825 	  swapped = !commutative_tree_code (opcode);
   10826 	}
   10827       if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
   10828 	{
   10829 	  if (code == OMP_ATOMIC)
   10830 	    error ("%<#pragma omp atomic update%> uses two different "
   10831 		   "expressions for memory");
   10832 	  else
   10833 	    error ("%<#pragma omp atomic capture%> uses two different "
   10834 		   "expressions for memory");
   10835 	  return;
   10836 	}
   10837       if (lhs1 && !cp_tree_equal (lhs, lhs1))
   10838 	{
   10839 	  if (code == OMP_ATOMIC)
   10840 	    error ("%<#pragma omp atomic update%> uses two different "
   10841 		   "expressions for memory");
   10842 	  else
   10843 	    error ("%<#pragma omp atomic capture%> uses two different "
   10844 		   "expressions for memory");
   10845 	  return;
   10846 	}
   10847       stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
   10848 				  v, lhs1, rhs1, r, swapped, mo, weak,
   10849 				  processing_template_decl != 0);
   10850       if (stmt == error_mark_node)
   10851 	return;
   10852     }
   10853   if (processing_template_decl)
   10854     {
   10855       if (code == OMP_ATOMIC_READ)
   10856 	{
   10857 	  stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
   10858 	  OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   10859 	  stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   10860 	}
   10861       else
   10862 	{
   10863 	  if (opcode == NOP_EXPR)
   10864 	    stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
   10865 	  else if (opcode == COND_EXPR)
   10866 	    {
   10867 	      stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
   10868 	      if (orig_r)
   10869 		stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
   10870 			       stmt);
   10871 	      stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
   10872 			     orig_lhs);
   10873 	      orig_rhs1 = NULL_TREE;
   10874 	    }
   10875 	  else
   10876 	    stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
   10877 	  if (orig_rhs1)
   10878 	    stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
   10879 				     COMPOUND_EXPR, orig_rhs1, stmt);
   10880 	  if (code != OMP_ATOMIC)
   10881 	    {
   10882 	      stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
   10883 	      OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   10884 	      OMP_ATOMIC_WEAK (stmt) = weak;
   10885 	      stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   10886 	    }
   10887 	}
   10888       stmt = build2 (OMP_ATOMIC, void_type_node,
   10889 		     clauses ? clauses : integer_zero_node, stmt);
   10890       OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   10891       OMP_ATOMIC_WEAK (stmt) = weak;
   10892       SET_EXPR_LOCATION (stmt, loc);
   10893     }
   10894 
   10895   /* Avoid -Wunused-value warnings here, the whole construct has side-effects
   10896      and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
   10897      in some tree that appears to be unused, the value is not unused.  */
   10898   warning_sentinel w (warn_unused_value);
   10899   finish_expr_stmt (stmt);
   10900 }
   10901 
   10902 void
   10903 finish_omp_barrier (void)
   10904 {
   10905   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
   10906   releasing_vec vec;
   10907   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   10908   finish_expr_stmt (stmt);
   10909 }
   10910 
   10911 void
   10912 finish_omp_depobj (location_t loc, tree depobj,
   10913 		   enum omp_clause_depend_kind kind, tree clause)
   10914 {
   10915   if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
   10916     {
   10917       if (!lvalue_p (depobj))
   10918 	{
   10919 	  error_at (EXPR_LOC_OR_LOC (depobj, loc),
   10920 		    "%<depobj%> expression is not lvalue expression");
   10921 	  depobj = error_mark_node;
   10922 	}
   10923     }
   10924 
   10925   if (processing_template_decl)
   10926     {
   10927       if (clause == NULL_TREE)
   10928 	clause = build_int_cst (integer_type_node, kind);
   10929       add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
   10930       return;
   10931     }
   10932 
   10933   if (!error_operand_p (depobj))
   10934     {
   10935       tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
   10936       if (addr == error_mark_node)
   10937 	depobj = error_mark_node;
   10938       else
   10939 	depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
   10940 					tf_warning_or_error);
   10941     }
   10942 
   10943   c_finish_omp_depobj (loc, depobj, kind, clause);
   10944 }
   10945 
   10946 void
   10947 finish_omp_flush (int mo)
   10948 {
   10949   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   10950   releasing_vec vec;
   10951   if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
   10952     {
   10953       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
   10954       vec->quick_push (build_int_cst (integer_type_node, mo));
   10955     }
   10956   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   10957   finish_expr_stmt (stmt);
   10958 }
   10959 
   10960 void
   10961 finish_omp_taskwait (void)
   10962 {
   10963   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
   10964   releasing_vec vec;
   10965   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   10966   finish_expr_stmt (stmt);
   10967 }
   10968 
   10969 void
   10970 finish_omp_taskyield (void)
   10971 {
   10972   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
   10973   releasing_vec vec;
   10974   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   10975   finish_expr_stmt (stmt);
   10976 }
   10977 
   10978 void
   10979 finish_omp_cancel (tree clauses)
   10980 {
   10981   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   10982   int mask = 0;
   10983   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   10984     mask = 1;
   10985   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   10986     mask = 2;
   10987   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   10988     mask = 4;
   10989   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   10990     mask = 8;
   10991   else
   10992     {
   10993       error ("%<#pragma omp cancel%> must specify one of "
   10994 	     "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   10995       return;
   10996     }
   10997   releasing_vec vec;
   10998   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   10999   if (ifc != NULL_TREE)
   11000     {
   11001       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   11002 	  && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   11003 	error_at (OMP_CLAUSE_LOCATION (ifc),
   11004 		  "expected %<cancel%> %<if%> clause modifier");
   11005       else
   11006 	{
   11007 	  tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   11008 	  if (ifc2 != NULL_TREE)
   11009 	    {
   11010 	      gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   11011 			  && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   11012 			  && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   11013 	      error_at (OMP_CLAUSE_LOCATION (ifc2),
   11014 			"expected %<cancel%> %<if%> clause modifier");
   11015 	    }
   11016 	}
   11017 
   11018       if (!processing_template_decl)
   11019 	ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
   11020       else
   11021 	ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   11022 				 OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
   11023 				 integer_zero_node, ERROR_MARK,
   11024 				 NULL_TREE, NULL, tf_warning_or_error);
   11025     }
   11026   else
   11027     ifc = boolean_true_node;
   11028   vec->quick_push (build_int_cst (integer_type_node, mask));
   11029   vec->quick_push (ifc);
   11030   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   11031   finish_expr_stmt (stmt);
   11032 }
   11033 
   11034 void
   11035 finish_omp_cancellation_point (tree clauses)
   11036 {
   11037   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   11038   int mask = 0;
   11039   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   11040     mask = 1;
   11041   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   11042     mask = 2;
   11043   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   11044     mask = 4;
   11045   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   11046     mask = 8;
   11047   else
   11048     {
   11049       error ("%<#pragma omp cancellation point%> must specify one of "
   11050 	     "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   11051       return;
   11052     }
   11053   releasing_vec vec
   11054     = make_tree_vector_single (build_int_cst (integer_type_node, mask));
   11055   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   11056   finish_expr_stmt (stmt);
   11057 }
   11058 
   11059 /* Begin a __transaction_atomic or __transaction_relaxed statement.
   11061    If PCOMPOUND is non-null, this is for a function-transaction-block, and we
   11062    should create an extra compound stmt.  */
   11063 
   11064 tree
   11065 begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
   11066 {
   11067   tree r;
   11068 
   11069   if (pcompound)
   11070     *pcompound = begin_compound_stmt (0);
   11071 
   11072   r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
   11073 
   11074   /* Only add the statement to the function if support enabled.  */
   11075   if (flag_tm)
   11076     add_stmt (r);
   11077   else
   11078     error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
   11079 		    ? G_("%<__transaction_relaxed%> without "
   11080 			 "transactional memory support enabled")
   11081 		    : G_("%<__transaction_atomic%> without "
   11082 			 "transactional memory support enabled")));
   11083 
   11084   TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
   11085   TREE_SIDE_EFFECTS (r) = 1;
   11086   return r;
   11087 }
   11088 
   11089 /* End a __transaction_atomic or __transaction_relaxed statement.
   11090    If COMPOUND_STMT is non-null, this is for a function-transaction-block,
   11091    and we should end the compound.  If NOEX is non-NULL, we wrap the body in
   11092    a MUST_NOT_THROW_EXPR with NOEX as condition.  */
   11093 
   11094 void
   11095 finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
   11096 {
   11097   TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
   11098   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   11099   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
   11100   TRANSACTION_EXPR_IS_STMT (stmt) = 1;
   11101 
   11102   /* noexcept specifications are not allowed for function transactions.  */
   11103   gcc_assert (!(noex && compound_stmt));
   11104   if (noex)
   11105     {
   11106       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
   11107 					     noex);
   11108       protected_set_expr_location
   11109 	(body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
   11110       TREE_SIDE_EFFECTS (body) = 1;
   11111       TRANSACTION_EXPR_BODY (stmt) = body;
   11112     }
   11113 
   11114   if (compound_stmt)
   11115     finish_compound_stmt (compound_stmt);
   11116 }
   11117 
   11118 /* Build a __transaction_atomic or __transaction_relaxed expression.  If
   11119    NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
   11120    condition.  */
   11121 
   11122 tree
   11123 build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
   11124 {
   11125   tree ret;
   11126   if (noex)
   11127     {
   11128       expr = build_must_not_throw_expr (expr, noex);
   11129       protected_set_expr_location (expr, loc);
   11130       TREE_SIDE_EFFECTS (expr) = 1;
   11131     }
   11132   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
   11133   if (flags & TM_STMT_ATTR_RELAXED)
   11134 	TRANSACTION_EXPR_RELAXED (ret) = 1;
   11135   TREE_SIDE_EFFECTS (ret) = 1;
   11136   SET_EXPR_LOCATION (ret, loc);
   11137   return ret;
   11138 }
   11139 
   11140 void
   11142 init_cp_semantics (void)
   11143 {
   11144 }
   11145 
   11146 
   11148 /* If we have a condition in conjunctive normal form (CNF), find the first
   11149    failing clause.  In other words, given an expression like
   11150 
   11151      true && true && false && true && false
   11152 
   11153    return the first 'false'.  EXPR is the expression.  */
   11154 
   11155 static tree
   11156 find_failing_clause_r (tree expr)
   11157 {
   11158   if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR)
   11159     {
   11160       /* First check the left side...  */
   11161       tree e = find_failing_clause_r (TREE_OPERAND (expr, 0));
   11162       if (e == NULL_TREE)
   11163 	/* ...if we didn't find a false clause, check the right side.  */
   11164 	e = find_failing_clause_r (TREE_OPERAND (expr, 1));
   11165       return e;
   11166     }
   11167   tree e = contextual_conv_bool (expr, tf_none);
   11168   e = fold_non_dependent_expr (e, tf_none, /*manifestly_const_eval=*/true);
   11169   if (integer_zerop (e))
   11170     /* This is the failing clause.  */
   11171     return expr;
   11172   return NULL_TREE;
   11173 }
   11174 
   11175 /* Wrapper for find_failing_clause_r.  */
   11176 
   11177 static tree
   11178 find_failing_clause (tree expr)
   11179 {
   11180   if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR)
   11181     if (tree e = find_failing_clause_r (expr))
   11182       expr = e;
   11183   return expr;
   11184 }
   11185 
   11186 /* Build a STATIC_ASSERT for a static assertion with the condition
   11187    CONDITION and the message text MESSAGE.  LOCATION is the location
   11188    of the static assertion in the source code.  When MEMBER_P, this
   11189    static assertion is a member of a class.  If SHOW_EXPR_P is true,
   11190    print the condition (because it was instantiation-dependent).  */
   11191 
   11192 void
   11193 finish_static_assert (tree condition, tree message, location_t location,
   11194 		      bool member_p, bool show_expr_p)
   11195 {
   11196   tsubst_flags_t complain = tf_warning_or_error;
   11197 
   11198   if (message == NULL_TREE
   11199       || message == error_mark_node
   11200       || condition == NULL_TREE
   11201       || condition == error_mark_node)
   11202     return;
   11203 
   11204   if (check_for_bare_parameter_packs (condition))
   11205     condition = error_mark_node;
   11206 
   11207   if (instantiation_dependent_expression_p (condition))
   11208     {
   11209       /* We're in a template; build a STATIC_ASSERT and put it in
   11210          the right place. */
   11211       tree assertion;
   11212 
   11213       assertion = make_node (STATIC_ASSERT);
   11214       STATIC_ASSERT_CONDITION (assertion) = condition;
   11215       STATIC_ASSERT_MESSAGE (assertion) = message;
   11216       STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
   11217 
   11218       if (member_p)
   11219         maybe_add_class_template_decl_list (current_class_type,
   11220                                             assertion,
   11221                                             /*friend_p=*/0);
   11222       else
   11223         add_stmt (assertion);
   11224 
   11225       return;
   11226     }
   11227 
   11228   /* Save the condition in case it was a concept check.  */
   11229   tree orig_condition = condition;
   11230 
   11231   /* Fold the expression and convert it to a boolean value. */
   11232   condition = contextual_conv_bool (condition, complain);
   11233   condition = fold_non_dependent_expr (condition, complain,
   11234 				       /*manifestly_const_eval=*/true);
   11235 
   11236   if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
   11237     /* Do nothing; the condition is satisfied. */
   11238     ;
   11239   else
   11240     {
   11241       iloc_sentinel ils (location);
   11242 
   11243       if (integer_zerop (condition))
   11244 	{
   11245 	  int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT
   11246 				     (TREE_TYPE (TREE_TYPE (message))));
   11247 	  int len = TREE_STRING_LENGTH (message) / sz - 1;
   11248 
   11249 	  /* See if we can find which clause was failing (for logical AND).  */
   11250 	  tree bad = find_failing_clause (orig_condition);
   11251 	  /* If not, or its location is unusable, fall back to the previous
   11252 	     location.  */
   11253 	  location_t cloc = cp_expr_loc_or_loc (bad, location);
   11254 	  /* Nobody wants to see the artificial (bool) cast.  */
   11255 	  bad = tree_strip_nop_conversions (bad);
   11256 
   11257           /* Report the error. */
   11258 	  if (len == 0)
   11259 	    error_at (cloc, "static assertion failed");
   11260 	  else
   11261 	    error_at (cloc, "static assertion failed: %s",
   11262 		      TREE_STRING_POINTER (message));
   11263 
   11264 	  /* Actually explain the failure if this is a concept check or a
   11265 	     requires-expression.  */
   11266 	  if (concept_check_p (bad)
   11267 	      || TREE_CODE (bad) == REQUIRES_EXPR)
   11268 	    diagnose_constraints (location, bad, NULL_TREE);
   11269 	  else if (COMPARISON_CLASS_P (bad)
   11270 		   && ARITHMETIC_TYPE_P (TREE_TYPE (TREE_OPERAND (bad, 0))))
   11271 	    {
   11272 	      tree op0 = fold_non_dependent_expr (TREE_OPERAND (bad, 0));
   11273 	      tree op1 = fold_non_dependent_expr (TREE_OPERAND (bad, 1));
   11274 	      tree cond = build2 (TREE_CODE (bad), boolean_type_node, op0, op1);
   11275 	      inform (cloc, "the comparison reduces to %qE", cond);
   11276 	    }
   11277 	  else if (show_expr_p)
   11278 	    inform (cloc, "%qE evaluates to false", bad);
   11279 	}
   11280       else if (condition && condition != error_mark_node)
   11281 	{
   11282 	  error ("non-constant condition for static assertion");
   11283 	  if (require_rvalue_constant_expression (condition))
   11284 	    cxx_constant_value (condition);
   11285 	}
   11286     }
   11287 }
   11288 
   11289 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
   11291    suitable for use as a type-specifier.
   11292 
   11293    ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
   11294    id-expression or a class member access, FALSE when it was parsed as
   11295    a full expression.  */
   11296 
   11297 tree
   11298 finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
   11299 		      tsubst_flags_t complain)
   11300 {
   11301   tree type = NULL_TREE;
   11302 
   11303   if (!expr || error_operand_p (expr))
   11304     return error_mark_node;
   11305 
   11306   if (TYPE_P (expr)
   11307       || TREE_CODE (expr) == TYPE_DECL
   11308       || (TREE_CODE (expr) == BIT_NOT_EXPR
   11309 	  && TYPE_P (TREE_OPERAND (expr, 0))))
   11310     {
   11311       if (complain & tf_error)
   11312 	error ("argument to %<decltype%> must be an expression");
   11313       return error_mark_node;
   11314     }
   11315 
   11316   /* decltype is an unevaluated context.  */
   11317   cp_unevaluated u;
   11318 
   11319   processing_template_decl_sentinel ptds (/*reset=*/false);
   11320 
   11321   /* Depending on the resolution of DR 1172, we may later need to distinguish
   11322      instantiation-dependent but not type-dependent expressions so that, say,
   11323      A<decltype(sizeof(T))>::U doesn't require 'typename'.  */
   11324   if (instantiation_dependent_uneval_expression_p (expr))
   11325     {
   11326       type = cxx_make_type (DECLTYPE_TYPE);
   11327       DECLTYPE_TYPE_EXPR (type) = expr;
   11328       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
   11329         = id_expression_or_member_access_p;
   11330       SET_TYPE_STRUCTURAL_EQUALITY (type);
   11331 
   11332       return type;
   11333     }
   11334   else if (processing_template_decl)
   11335     {
   11336       expr = instantiate_non_dependent_expr_sfinae (expr, complain|tf_decltype);
   11337       if (expr == error_mark_node)
   11338 	return error_mark_node;
   11339       /* Keep processing_template_decl cleared for the rest of the function
   11340 	 (for sake of the call to lvalue_kind below, which handles templated
   11341 	 and non-templated COND_EXPR differently).  */
   11342       processing_template_decl = 0;
   11343     }
   11344 
   11345   /* The type denoted by decltype(e) is defined as follows:  */
   11346 
   11347   expr = resolve_nondeduced_context (expr, complain);
   11348   if (!mark_single_function (expr, complain))
   11349     return error_mark_node;
   11350 
   11351   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
   11352     return error_mark_node;
   11353 
   11354   if (type_unknown_p (expr))
   11355     {
   11356       if (complain & tf_error)
   11357 	error ("%<decltype%> cannot resolve address of overloaded function");
   11358       return error_mark_node;
   11359     }
   11360 
   11361   /* To get the size of a static data member declared as an array of
   11362      unknown bound, we need to instantiate it.  */
   11363   if (VAR_P (expr)
   11364       && VAR_HAD_UNKNOWN_BOUND (expr)
   11365       && DECL_TEMPLATE_INSTANTIATION (expr))
   11366     instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false);
   11367 
   11368   if (id_expression_or_member_access_p)
   11369     {
   11370       /* If e is an id-expression or a class member access (5.2.5
   11371          [expr.ref]), decltype(e) is defined as the type of the entity
   11372          named by e. If there is no such entity, or e names a set of
   11373          overloaded functions, the program is ill-formed.  */
   11374       if (identifier_p (expr))
   11375         expr = lookup_name (expr);
   11376 
   11377       if (INDIRECT_REF_P (expr)
   11378 	  || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   11379         /* This can happen when the expression is, e.g., "a.b". Just
   11380            look at the underlying operand.  */
   11381         expr = TREE_OPERAND (expr, 0);
   11382 
   11383       if (TREE_CODE (expr) == OFFSET_REF
   11384           || TREE_CODE (expr) == MEMBER_REF
   11385 	  || TREE_CODE (expr) == SCOPE_REF)
   11386         /* We're only interested in the field itself. If it is a
   11387            BASELINK, we will need to see through it in the next
   11388            step.  */
   11389         expr = TREE_OPERAND (expr, 1);
   11390 
   11391       if (BASELINK_P (expr))
   11392         /* See through BASELINK nodes to the underlying function.  */
   11393         expr = BASELINK_FUNCTIONS (expr);
   11394 
   11395       /* decltype of a decomposition name drops references in the tuple case
   11396 	 (unlike decltype of a normal variable) and keeps cv-qualifiers from
   11397 	 the containing object in the other cases (unlike decltype of a member
   11398 	 access expression).  */
   11399       if (DECL_DECOMPOSITION_P (expr))
   11400 	{
   11401 	  if (DECL_HAS_VALUE_EXPR_P (expr))
   11402 	    /* Expr is an array or struct subobject proxy, handle
   11403 	       bit-fields properly.  */
   11404 	    return unlowered_expr_type (expr);
   11405 	  else
   11406 	    /* Expr is a reference variable for the tuple case.  */
   11407 	    return lookup_decomp_type (expr);
   11408 	}
   11409 
   11410       switch (TREE_CODE (expr))
   11411         {
   11412         case FIELD_DECL:
   11413           if (DECL_BIT_FIELD_TYPE (expr))
   11414             {
   11415               type = DECL_BIT_FIELD_TYPE (expr);
   11416               break;
   11417             }
   11418           /* Fall through for fields that aren't bitfields.  */
   11419 	  gcc_fallthrough ();
   11420 
   11421         case FUNCTION_DECL:
   11422         case VAR_DECL:
   11423         case CONST_DECL:
   11424         case PARM_DECL:
   11425         case RESULT_DECL:
   11426         case TEMPLATE_PARM_INDEX:
   11427 	  expr = mark_type_use (expr);
   11428           type = TREE_TYPE (expr);
   11429           break;
   11430 
   11431         case ERROR_MARK:
   11432           type = error_mark_node;
   11433           break;
   11434 
   11435         case COMPONENT_REF:
   11436 	case COMPOUND_EXPR:
   11437 	  mark_type_use (expr);
   11438           type = is_bitfield_expr_with_lowered_type (expr);
   11439           if (!type)
   11440             type = TREE_TYPE (TREE_OPERAND (expr, 1));
   11441           break;
   11442 
   11443         case BIT_FIELD_REF:
   11444           gcc_unreachable ();
   11445 
   11446         case INTEGER_CST:
   11447 	case PTRMEM_CST:
   11448           /* We can get here when the id-expression refers to an
   11449              enumerator or non-type template parameter.  */
   11450           type = TREE_TYPE (expr);
   11451           break;
   11452 
   11453         default:
   11454 	  /* Handle instantiated template non-type arguments.  */
   11455 	  type = TREE_TYPE (expr);
   11456           break;
   11457         }
   11458     }
   11459   else
   11460     {
   11461       /* Within a lambda-expression:
   11462 
   11463 	 Every occurrence of decltype((x)) where x is a possibly
   11464 	 parenthesized id-expression that names an entity of
   11465 	 automatic storage duration is treated as if x were
   11466 	 transformed into an access to a corresponding data member
   11467 	 of the closure type that would have been declared if x
   11468 	 were a use of the denoted entity.  */
   11469       if (outer_automatic_var_p (expr)
   11470 	  && current_function_decl
   11471 	  && LAMBDA_FUNCTION_P (current_function_decl))
   11472 	type = capture_decltype (expr);
   11473       else if (error_operand_p (expr))
   11474 	type = error_mark_node;
   11475       else if (expr == current_class_ptr)
   11476 	/* If the expression is just "this", we want the
   11477 	   cv-unqualified pointer for the "this" type.  */
   11478 	type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
   11479       else
   11480 	{
   11481 	  /* Otherwise, where T is the type of e, if e is an lvalue,
   11482 	     decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
   11483 	  cp_lvalue_kind clk = lvalue_kind (expr);
   11484 	  type = unlowered_expr_type (expr);
   11485 	  gcc_assert (!TYPE_REF_P (type));
   11486 
   11487 	  /* For vector types, pick a non-opaque variant.  */
   11488 	  if (VECTOR_TYPE_P (type))
   11489 	    type = strip_typedefs (type);
   11490 
   11491 	  if (clk != clk_none && !(clk & clk_class))
   11492 	    type = cp_build_reference_type (type, (clk & clk_rvalueref));
   11493 	}
   11494     }
   11495 
   11496   return type;
   11497 }
   11498 
   11499 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
   11500    __has_nothrow_copy, depending on assign_p.  Returns true iff all
   11501    the copy {ctor,assign} fns are nothrow.  */
   11502 
   11503 static bool
   11504 classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
   11505 {
   11506   tree fns = NULL_TREE;
   11507 
   11508   if (assign_p || TYPE_HAS_COPY_CTOR (type))
   11509     fns = get_class_binding (type, assign_p ? assign_op_identifier
   11510 			     : ctor_identifier);
   11511 
   11512   bool saw_copy = false;
   11513   for (ovl_iterator iter (fns); iter; ++iter)
   11514     {
   11515       tree fn = *iter;
   11516 
   11517       if (copy_fn_p (fn) > 0)
   11518 	{
   11519 	  saw_copy = true;
   11520 	  if (!maybe_instantiate_noexcept (fn)
   11521 	      || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
   11522 	    return false;
   11523 	}
   11524     }
   11525 
   11526   return saw_copy;
   11527 }
   11528 
   11529 /* Return true if DERIVED is pointer interconvertible base of BASE.  */
   11530 
   11531 static bool
   11532 pointer_interconvertible_base_of_p (tree base, tree derived)
   11533 {
   11534   if (base == error_mark_node || derived == error_mark_node)
   11535     return false;
   11536   base = TYPE_MAIN_VARIANT (base);
   11537   derived = TYPE_MAIN_VARIANT (derived);
   11538   if (!NON_UNION_CLASS_TYPE_P (base)
   11539       || !NON_UNION_CLASS_TYPE_P (derived))
   11540     return false;
   11541 
   11542   if (same_type_p (base, derived))
   11543     return true;
   11544 
   11545   if (!std_layout_type_p (derived))
   11546     return false;
   11547 
   11548   return uniquely_derived_from_p (base, derived);
   11549 }
   11550 
   11551 /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
   11552    return true if MEMBERTYPE is the type of the first non-static data member
   11553    of TYPE or for unions of any members.  */
   11554 static bool
   11555 first_nonstatic_data_member_p (tree type, tree membertype)
   11556 {
   11557   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   11558     {
   11559       if (TREE_CODE (field) != FIELD_DECL)
   11560 	continue;
   11561       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
   11562 	continue;
   11563       if (DECL_FIELD_IS_BASE (field))
   11564 	return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
   11565       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   11566 	{
   11567 	  if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
   11568 	       || std_layout_type_p (TREE_TYPE (field)))
   11569 	      && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
   11570 	    return true;
   11571 	}
   11572       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   11573 							  membertype))
   11574 	return true;
   11575       if (TREE_CODE (type) != UNION_TYPE)
   11576 	return false;
   11577     }
   11578   return false;
   11579 }
   11580 
   11581 /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
   11582 
   11583 tree
   11584 fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
   11585 						     tree *args)
   11586 {
   11587   /* Unless users call the builtin directly, the following 3 checks should be
   11588      ensured from std::is_pointer_interconvertible_with_class function
   11589      template.  */
   11590   if (nargs != 1)
   11591     {
   11592       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   11593 		     "needs a single argument");
   11594       return boolean_false_node;
   11595     }
   11596   tree arg = args[0];
   11597   if (error_operand_p (arg))
   11598     return boolean_false_node;
   11599   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
   11600     {
   11601       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   11602 		     "argument is not pointer to member");
   11603       return boolean_false_node;
   11604     }
   11605 
   11606   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
   11607     return boolean_false_node;
   11608 
   11609   tree membertype = TREE_TYPE (TREE_TYPE (arg));
   11610   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
   11611   if (!complete_type_or_else (basetype, NULL_TREE))
   11612     return boolean_false_node;
   11613 
   11614   if (TREE_CODE (basetype) != UNION_TYPE
   11615       && !std_layout_type_p (basetype))
   11616     return boolean_false_node;
   11617 
   11618   if (!first_nonstatic_data_member_p (basetype, membertype))
   11619     return boolean_false_node;
   11620 
   11621   if (TREE_CODE (arg) == PTRMEM_CST)
   11622     arg = cplus_expand_constant (arg);
   11623 
   11624   if (integer_nonzerop (arg))
   11625     return boolean_false_node;
   11626   if (integer_zerop (arg))
   11627     return boolean_true_node;
   11628 
   11629   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
   11630 		      build_zero_cst (TREE_TYPE (arg)));
   11631 }
   11632 
   11633 /* Helper function for is_corresponding_member_aggr.  Return true if
   11634    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
   11635    union or structure BASETYPE.  */
   11636 
   11637 static bool
   11638 is_corresponding_member_union (tree basetype, tree membertype, tree arg)
   11639 {
   11640   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
   11641     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
   11642       continue;
   11643     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   11644 							membertype))
   11645       {
   11646 	if (TREE_CODE (arg) != INTEGER_CST
   11647 	    || tree_int_cst_equal (arg, byte_position (field)))
   11648 	  return true;
   11649       }
   11650     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   11651       {
   11652 	tree narg = arg;
   11653 	if (TREE_CODE (basetype) != UNION_TYPE
   11654 	    && TREE_CODE (narg) == INTEGER_CST)
   11655 	  narg = size_binop (MINUS_EXPR, arg, byte_position (field));
   11656 	if (is_corresponding_member_union (TREE_TYPE (field),
   11657 					   membertype, narg))
   11658 	  return true;
   11659       }
   11660   return false;
   11661 }
   11662 
   11663 /* Helper function for fold_builtin_is_corresponding_member call.
   11664    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
   11665    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
   11666    boolean_true_node if they are corresponding members, or for
   11667    non-constant ARG2 the highest member offset for corresponding
   11668    members.  */
   11669 
   11670 static tree
   11671 is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
   11672 			      tree arg1, tree basetype2, tree membertype2,
   11673 			      tree arg2)
   11674 {
   11675   tree field1 = TYPE_FIELDS (basetype1);
   11676   tree field2 = TYPE_FIELDS (basetype2);
   11677   tree ret = boolean_false_node;
   11678   while (1)
   11679     {
   11680       bool r = next_common_initial_sequence (field1, field2);
   11681       if (field1 == NULL_TREE || field2 == NULL_TREE)
   11682 	break;
   11683       if (r
   11684 	  && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
   11685 							membertype1)
   11686 	  && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
   11687 							membertype2))
   11688 	{
   11689 	  tree pos = byte_position (field1);
   11690 	  if (TREE_CODE (arg1) == INTEGER_CST
   11691 	      && tree_int_cst_equal (arg1, pos))
   11692 	    {
   11693 	      if (TREE_CODE (arg2) == INTEGER_CST)
   11694 		return boolean_true_node;
   11695 	      return pos;
   11696 	    }
   11697 	  else if (TREE_CODE (arg1) != INTEGER_CST)
   11698 	    ret = pos;
   11699 	}
   11700       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
   11701 	       && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
   11702 	{
   11703 	  if ((!lookup_attribute ("no_unique_address",
   11704 				  DECL_ATTRIBUTES (field1)))
   11705 	      != !lookup_attribute ("no_unique_address",
   11706 				    DECL_ATTRIBUTES (field2)))
   11707 	    break;
   11708 	  if (!tree_int_cst_equal (bit_position (field1),
   11709 				   bit_position (field2)))
   11710 	    break;
   11711 	  bool overlap = true;
   11712 	  tree pos = byte_position (field1);
   11713 	  if (TREE_CODE (arg1) == INTEGER_CST)
   11714 	    {
   11715 	      tree off1 = fold_convert (sizetype, arg1);
   11716 	      tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
   11717 	      if (tree_int_cst_lt (off1, pos)
   11718 		  || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
   11719 		overlap = false;
   11720 	    }
   11721 	  if (TREE_CODE (arg2) == INTEGER_CST)
   11722 	    {
   11723 	      tree off2 = fold_convert (sizetype, arg2);
   11724 	      tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
   11725 	      if (tree_int_cst_lt (off2, pos)
   11726 		  || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
   11727 		overlap = false;
   11728 	    }
   11729 	  if (overlap
   11730 	      && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
   11731 	      && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
   11732 	    {
   11733 	      tree narg1 = arg1;
   11734 	      if (TREE_CODE (arg1) == INTEGER_CST)
   11735 		narg1 = size_binop (MINUS_EXPR,
   11736 				    fold_convert (sizetype, arg1), pos);
   11737 	      tree narg2 = arg2;
   11738 	      if (TREE_CODE (arg2) == INTEGER_CST)
   11739 		narg2 = size_binop (MINUS_EXPR,
   11740 				    fold_convert (sizetype, arg2), pos);
   11741 	      tree t1 = TREE_TYPE (field1);
   11742 	      tree t2 = TREE_TYPE (field2);
   11743 	      tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
   11744 							narg1, t2, membertype2,
   11745 							narg2);
   11746 	      if (nret != boolean_false_node)
   11747 		{
   11748 		  if (nret == boolean_true_node)
   11749 		    return nret;
   11750 		  if (TREE_CODE (arg1) == INTEGER_CST)
   11751 		    return size_binop (PLUS_EXPR, nret, pos);
   11752 		  ret = size_binop (PLUS_EXPR, nret, pos);
   11753 		}
   11754 	    }
   11755 	  else if (overlap
   11756 		   && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
   11757 		   && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
   11758 	    {
   11759 	      tree narg1 = arg1;
   11760 	      if (TREE_CODE (arg1) == INTEGER_CST)
   11761 		narg1 = size_binop (MINUS_EXPR,
   11762 				    fold_convert (sizetype, arg1), pos);
   11763 	      tree narg2 = arg2;
   11764 	      if (TREE_CODE (arg2) == INTEGER_CST)
   11765 		narg2 = size_binop (MINUS_EXPR,
   11766 				    fold_convert (sizetype, arg2), pos);
   11767 	      if (is_corresponding_member_union (TREE_TYPE (field1),
   11768 						 membertype1, narg1)
   11769 		  && is_corresponding_member_union (TREE_TYPE (field2),
   11770 						    membertype2, narg2))
   11771 		{
   11772 		  sorry_at (loc, "%<__builtin_is_corresponding_member%> "
   11773 				 "not well defined for anonymous unions");
   11774 		  return boolean_false_node;
   11775 		}
   11776 	    }
   11777 	}
   11778       if (!r)
   11779 	break;
   11780       field1 = DECL_CHAIN (field1);
   11781       field2 = DECL_CHAIN (field2);
   11782     }
   11783   return ret;
   11784 }
   11785 
   11786 /* Fold __builtin_is_corresponding_member call.  */
   11787 
   11788 tree
   11789 fold_builtin_is_corresponding_member (location_t loc, int nargs,
   11790 				      tree *args)
   11791 {
   11792   /* Unless users call the builtin directly, the following 3 checks should be
   11793      ensured from std::is_corresponding_member function template.  */
   11794   if (nargs != 2)
   11795     {
   11796       error_at (loc, "%<__builtin_is_corresponding_member%> "
   11797 		     "needs two arguments");
   11798       return boolean_false_node;
   11799     }
   11800   tree arg1 = args[0];
   11801   tree arg2 = args[1];
   11802   if (error_operand_p (arg1) || error_operand_p (arg2))
   11803     return boolean_false_node;
   11804   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
   11805       || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
   11806     {
   11807       error_at (loc, "%<__builtin_is_corresponding_member%> "
   11808 		     "argument is not pointer to member");
   11809       return boolean_false_node;
   11810     }
   11811 
   11812   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
   11813       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
   11814     return boolean_false_node;
   11815 
   11816   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
   11817   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
   11818   if (!complete_type_or_else (basetype1, NULL_TREE))
   11819     return boolean_false_node;
   11820 
   11821   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
   11822   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
   11823   if (!complete_type_or_else (basetype2, NULL_TREE))
   11824     return boolean_false_node;
   11825 
   11826   if (!NON_UNION_CLASS_TYPE_P (basetype1)
   11827       || !NON_UNION_CLASS_TYPE_P (basetype2)
   11828       || !std_layout_type_p (basetype1)
   11829       || !std_layout_type_p (basetype2))
   11830     return boolean_false_node;
   11831 
   11832   /* If the member types aren't layout compatible, then they
   11833      can't be corresponding members.  */
   11834   if (!layout_compatible_type_p (membertype1, membertype2))
   11835     return boolean_false_node;
   11836 
   11837   if (TREE_CODE (arg1) == PTRMEM_CST)
   11838     arg1 = cplus_expand_constant (arg1);
   11839   if (TREE_CODE (arg2) == PTRMEM_CST)
   11840     arg2 = cplus_expand_constant (arg2);
   11841 
   11842   if (null_member_pointer_value_p (arg1)
   11843       || null_member_pointer_value_p (arg2))
   11844     return boolean_false_node;
   11845 
   11846   if (TREE_CODE (arg1) == INTEGER_CST
   11847       && TREE_CODE (arg2) == INTEGER_CST
   11848       && !tree_int_cst_equal (arg1, arg2))
   11849     return boolean_false_node;
   11850 
   11851   if (TREE_CODE (arg2) == INTEGER_CST
   11852       && TREE_CODE (arg1) != INTEGER_CST)
   11853     {
   11854       std::swap (arg1, arg2);
   11855       std::swap (membertype1, membertype2);
   11856       std::swap (basetype1, basetype2);
   11857     }
   11858 
   11859   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
   11860 					   basetype2, membertype2, arg2);
   11861   if (TREE_TYPE (ret) == boolean_type_node)
   11862     return ret;
   11863   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
   11864      already returns boolean_{true,false}_node whether those particular
   11865      members are corresponding members or not.  Otherwise, if only
   11866      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
   11867      above), it returns boolean_false_node if it is certainly not a
   11868      corresponding member and otherwise we need to do a runtime check that
   11869      those two OFFSET_TYPE offsets are equal.
   11870      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
   11871      returns the largest offset at which the members would be corresponding
   11872      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
   11873   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
   11874   if (TREE_CODE (arg1) == INTEGER_CST)
   11875     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   11876 			fold_convert (TREE_TYPE (arg1), arg2));
   11877   ret = fold_build2 (LE_EXPR, boolean_type_node,
   11878 		     fold_convert (pointer_sized_int_node, arg1),
   11879 		     fold_convert (pointer_sized_int_node, ret));
   11880   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
   11881 		      fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   11882 				   fold_convert (TREE_TYPE (arg1), arg2)));
   11883 }
   11884 
   11885 /* Actually evaluates the trait.  */
   11886 
   11887 static bool
   11888 trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
   11889 {
   11890   enum tree_code type_code1;
   11891   tree t;
   11892 
   11893   type_code1 = TREE_CODE (type1);
   11894 
   11895   switch (kind)
   11896     {
   11897     case CPTK_HAS_NOTHROW_ASSIGN:
   11898       type1 = strip_array_types (type1);
   11899       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   11900 	      && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
   11901 		  || (CLASS_TYPE_P (type1)
   11902 		      && classtype_has_nothrow_assign_or_copy_p (type1,
   11903 								 true))));
   11904 
   11905     case CPTK_HAS_TRIVIAL_ASSIGN:
   11906       /* ??? The standard seems to be missing the "or array of such a class
   11907 	 type" wording for this trait.  */
   11908       type1 = strip_array_types (type1);
   11909       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   11910 	      && (trivial_type_p (type1)
   11911 		    || (CLASS_TYPE_P (type1)
   11912 			&& TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
   11913 
   11914     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   11915       type1 = strip_array_types (type1);
   11916       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
   11917 	      || (CLASS_TYPE_P (type1)
   11918 		  && (t = locate_ctor (type1))
   11919 		  && maybe_instantiate_noexcept (t)
   11920 		  && TYPE_NOTHROW_P (TREE_TYPE (t))));
   11921 
   11922     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   11923       type1 = strip_array_types (type1);
   11924       return (trivial_type_p (type1)
   11925 	      || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
   11926 
   11927     case CPTK_HAS_NOTHROW_COPY:
   11928       type1 = strip_array_types (type1);
   11929       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
   11930 	      || (CLASS_TYPE_P (type1)
   11931 		  && classtype_has_nothrow_assign_or_copy_p (type1, false)));
   11932 
   11933     case CPTK_HAS_TRIVIAL_COPY:
   11934       /* ??? The standard seems to be missing the "or array of such a class
   11935 	 type" wording for this trait.  */
   11936       type1 = strip_array_types (type1);
   11937       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   11938 	      || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
   11939 
   11940     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   11941       type1 = strip_array_types (type1);
   11942       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   11943 	      || (CLASS_TYPE_P (type1)
   11944 		  && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
   11945 
   11946     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   11947       return type_has_virtual_destructor (type1);
   11948 
   11949     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   11950       return type_has_unique_obj_representations (type1);
   11951 
   11952     case CPTK_IS_ABSTRACT:
   11953       return ABSTRACT_CLASS_TYPE_P (type1);
   11954 
   11955     case CPTK_IS_AGGREGATE:
   11956       return CP_AGGREGATE_TYPE_P (type1);
   11957 
   11958     case CPTK_IS_BASE_OF:
   11959       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   11960 	      && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
   11961 		  || DERIVED_FROM_P (type1, type2)));
   11962 
   11963     case CPTK_IS_CLASS:
   11964       return NON_UNION_CLASS_TYPE_P (type1);
   11965 
   11966     case CPTK_IS_EMPTY:
   11967       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
   11968 
   11969     case CPTK_IS_ENUM:
   11970       return type_code1 == ENUMERAL_TYPE;
   11971 
   11972     case CPTK_IS_FINAL:
   11973       return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
   11974 
   11975     case CPTK_IS_LAYOUT_COMPATIBLE:
   11976       return layout_compatible_type_p (type1, type2);
   11977 
   11978     case CPTK_IS_LITERAL_TYPE:
   11979       return literal_type_p (type1);
   11980 
   11981     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   11982       return pointer_interconvertible_base_of_p (type1, type2);
   11983 
   11984     case CPTK_IS_POD:
   11985       return pod_type_p (type1);
   11986 
   11987     case CPTK_IS_POLYMORPHIC:
   11988       return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
   11989 
   11990     case CPTK_IS_SAME_AS:
   11991       return same_type_p (type1, type2);
   11992 
   11993     case CPTK_IS_STD_LAYOUT:
   11994       return std_layout_type_p (type1);
   11995 
   11996     case CPTK_IS_TRIVIAL:
   11997       return trivial_type_p (type1);
   11998 
   11999     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   12000       return is_trivially_xible (MODIFY_EXPR, type1, type2);
   12001 
   12002     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   12003       return is_trivially_xible (INIT_EXPR, type1, type2);
   12004 
   12005     case CPTK_IS_TRIVIALLY_COPYABLE:
   12006       return trivially_copyable_p (type1);
   12007 
   12008     case CPTK_IS_UNION:
   12009       return type_code1 == UNION_TYPE;
   12010 
   12011     case CPTK_IS_ASSIGNABLE:
   12012       return is_xible (MODIFY_EXPR, type1, type2);
   12013 
   12014     case CPTK_IS_CONSTRUCTIBLE:
   12015       return is_xible (INIT_EXPR, type1, type2);
   12016 
   12017     case CPTK_IS_NOTHROW_ASSIGNABLE:
   12018       return is_nothrow_xible (MODIFY_EXPR, type1, type2);
   12019 
   12020     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   12021       return is_nothrow_xible (INIT_EXPR, type1, type2);
   12022 
   12023     default:
   12024       gcc_unreachable ();
   12025       return false;
   12026     }
   12027 }
   12028 
   12029 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
   12030    void, or a complete type, returns true, otherwise false.  */
   12031 
   12032 static bool
   12033 check_trait_type (tree type)
   12034 {
   12035   if (type == NULL_TREE)
   12036     return true;
   12037 
   12038   if (TREE_CODE (type) == TREE_LIST)
   12039     return (check_trait_type (TREE_VALUE (type))
   12040 	    && check_trait_type (TREE_CHAIN (type)));
   12041 
   12042   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   12043       && COMPLETE_TYPE_P (TREE_TYPE (type)))
   12044     return true;
   12045 
   12046   if (VOID_TYPE_P (type))
   12047     return true;
   12048 
   12049   return !!complete_type_or_else (strip_array_types (type), NULL_TREE);
   12050 }
   12051 
   12052 /* True iff the conversion (if any) would be a direct reference
   12053    binding, not requiring complete types.  This is LWG2939.  */
   12054 
   12055 static bool
   12056 same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
   12057 {
   12058   tree from, to;
   12059   switch (kind)
   12060     {
   12061       /* These put the target type first.  */
   12062     case CPTK_IS_CONSTRUCTIBLE:
   12063     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   12064     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   12065       to = type1;
   12066       from = type2;
   12067       break;
   12068 
   12069     default:
   12070       gcc_unreachable ();
   12071     }
   12072 
   12073   if (TREE_CODE (to) != REFERENCE_TYPE || !from)
   12074     return false;
   12075   if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
   12076     from = TREE_VEC_ELT (from, 0);
   12077   else if (TREE_CODE (from) == TREE_LIST && !TREE_CHAIN (from))
   12078     from = TREE_VALUE (from);
   12079   return (TYPE_P (from)
   12080 	  && (same_type_ignoring_top_level_qualifiers_p
   12081 	      (non_reference (to), non_reference (from))));
   12082 }
   12083 
   12084 /* Process a trait expression.  */
   12085 
   12086 tree
   12087 finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
   12088 {
   12089   if (type1 == error_mark_node
   12090       || type2 == error_mark_node)
   12091     return error_mark_node;
   12092 
   12093   if (processing_template_decl)
   12094     {
   12095       tree trait_expr = make_node (TRAIT_EXPR);
   12096       TREE_TYPE (trait_expr) = boolean_type_node;
   12097       TRAIT_EXPR_TYPE1 (trait_expr) = type1;
   12098       TRAIT_EXPR_TYPE2 (trait_expr) = type2;
   12099       TRAIT_EXPR_KIND (trait_expr) = kind;
   12100       TRAIT_EXPR_LOCATION (trait_expr) = loc;
   12101       return trait_expr;
   12102     }
   12103 
   12104   switch (kind)
   12105     {
   12106     case CPTK_HAS_NOTHROW_ASSIGN:
   12107     case CPTK_HAS_TRIVIAL_ASSIGN:
   12108     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   12109     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   12110     case CPTK_HAS_NOTHROW_COPY:
   12111     case CPTK_HAS_TRIVIAL_COPY:
   12112     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   12113     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   12114     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   12115     case CPTK_IS_ABSTRACT:
   12116     case CPTK_IS_AGGREGATE:
   12117     case CPTK_IS_EMPTY:
   12118     case CPTK_IS_FINAL:
   12119     case CPTK_IS_LITERAL_TYPE:
   12120     case CPTK_IS_POD:
   12121     case CPTK_IS_POLYMORPHIC:
   12122     case CPTK_IS_STD_LAYOUT:
   12123     case CPTK_IS_TRIVIAL:
   12124     case CPTK_IS_TRIVIALLY_COPYABLE:
   12125       if (!check_trait_type (type1))
   12126 	return error_mark_node;
   12127       break;
   12128 
   12129     case CPTK_IS_ASSIGNABLE:
   12130     case CPTK_IS_CONSTRUCTIBLE:
   12131       break;
   12132 
   12133     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   12134     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   12135       /* Don't check completeness for direct reference binding.  */;
   12136       if (same_type_ref_bind_p (kind, type1, type2))
   12137 	break;
   12138       gcc_fallthrough ();
   12139 
   12140     case CPTK_IS_NOTHROW_ASSIGNABLE:
   12141     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   12142       if (!check_trait_type (type1)
   12143 	  || !check_trait_type (type2))
   12144 	return error_mark_node;
   12145       break;
   12146 
   12147     case CPTK_IS_BASE_OF:
   12148     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   12149       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   12150 	  && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
   12151 	  && !complete_type_or_else (type2, NULL_TREE))
   12152 	/* We already issued an error.  */
   12153 	return error_mark_node;
   12154       break;
   12155 
   12156     case CPTK_IS_CLASS:
   12157     case CPTK_IS_ENUM:
   12158     case CPTK_IS_UNION:
   12159     case CPTK_IS_SAME_AS:
   12160       break;
   12161 
   12162     case CPTK_IS_LAYOUT_COMPATIBLE:
   12163       if (!array_of_unknown_bound_p (type1)
   12164 	  && TREE_CODE (type1) != VOID_TYPE
   12165 	  && !complete_type_or_else (type1, NULL_TREE))
   12166 	/* We already issued an error.  */
   12167 	return error_mark_node;
   12168       if (!array_of_unknown_bound_p (type2)
   12169 	  && TREE_CODE (type2) != VOID_TYPE
   12170 	  && !complete_type_or_else (type2, NULL_TREE))
   12171 	/* We already issued an error.  */
   12172 	return error_mark_node;
   12173       break;
   12174 
   12175     default:
   12176       gcc_unreachable ();
   12177     }
   12178 
   12179   tree val = (trait_expr_value (kind, type1, type2)
   12180 	      ? boolean_true_node : boolean_false_node);
   12181   return maybe_wrap_with_location (val, loc);
   12182 }
   12183 
   12184 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
   12185    which is ignored for C++.  */
   12186 
   12187 void
   12188 set_float_const_decimal64 (void)
   12189 {
   12190 }
   12191 
   12192 void
   12193 clear_float_const_decimal64 (void)
   12194 {
   12195 }
   12196 
   12197 bool
   12198 float_const_decimal64_p (void)
   12199 {
   12200   return 0;
   12201 }
   12202 
   12203 
   12204 /* Return true if T designates the implied `this' parameter.  */
   12206 
   12207 bool
   12208 is_this_parameter (tree t)
   12209 {
   12210   if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
   12211     return false;
   12212   gcc_assert (TREE_CODE (t) == PARM_DECL
   12213 	      || (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
   12214 	      || (cp_binding_oracle && TREE_CODE (t) == VAR_DECL));
   12215   return true;
   12216 }
   12217 
   12218 /* Insert the deduced return type for an auto function.  */
   12219 
   12220 void
   12221 apply_deduced_return_type (tree fco, tree return_type)
   12222 {
   12223   tree result;
   12224 
   12225   if (return_type == error_mark_node)
   12226     return;
   12227 
   12228   if (DECL_CONV_FN_P (fco))
   12229     DECL_NAME (fco) = make_conv_op_name (return_type);
   12230 
   12231   TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
   12232 
   12233   result = DECL_RESULT (fco);
   12234   if (result == NULL_TREE)
   12235     return;
   12236   if (TREE_TYPE (result) == return_type)
   12237     return;
   12238 
   12239   if (!processing_template_decl && !VOID_TYPE_P (return_type)
   12240       && !complete_type_or_else (return_type, NULL_TREE))
   12241     return;
   12242 
   12243   /* We already have a DECL_RESULT from start_preparsed_function.
   12244      Now we need to redo the work it and allocate_struct_function
   12245      did to reflect the new type.  */
   12246   gcc_assert (current_function_decl == fco);
   12247   result = build_decl (input_location, RESULT_DECL, NULL_TREE,
   12248 		       TYPE_MAIN_VARIANT (return_type));
   12249   DECL_ARTIFICIAL (result) = 1;
   12250   DECL_IGNORED_P (result) = 1;
   12251   cp_apply_type_quals_to_decl (cp_type_quals (return_type),
   12252                                result);
   12253 
   12254   DECL_RESULT (fco) = result;
   12255 
   12256   if (!processing_template_decl)
   12257     {
   12258       bool aggr = aggregate_value_p (result, fco);
   12259 #ifdef PCC_STATIC_STRUCT_RETURN
   12260       cfun->returns_pcc_struct = aggr;
   12261 #endif
   12262       cfun->returns_struct = aggr;
   12263     }
   12264 }
   12265 
   12266 /* DECL is a local variable or parameter from the surrounding scope of a
   12267    lambda-expression.  Returns the decltype for a use of the capture field
   12268    for DECL even if it hasn't been captured yet.  */
   12269 
   12270 static tree
   12271 capture_decltype (tree decl)
   12272 {
   12273   tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl));
   12274   tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
   12275 			  LOOK_want::HIDDEN_LAMBDA);
   12276   tree type;
   12277 
   12278   if (cap && is_capture_proxy (cap))
   12279     type = TREE_TYPE (cap);
   12280   else
   12281     switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam))
   12282       {
   12283       case CPLD_NONE:
   12284 	error ("%qD is not captured", decl);
   12285 	return error_mark_node;
   12286 
   12287       case CPLD_COPY:
   12288 	type = TREE_TYPE (decl);
   12289 	if (TYPE_REF_P (type)
   12290 	    && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
   12291 	  type = TREE_TYPE (type);
   12292 	break;
   12293 
   12294       case CPLD_REFERENCE:
   12295 	type = TREE_TYPE (decl);
   12296 	if (!TYPE_REF_P (type))
   12297 	  type = build_reference_type (TREE_TYPE (decl));
   12298 	break;
   12299 
   12300       default:
   12301 	gcc_unreachable ();
   12302       }
   12303 
   12304   if (!TYPE_REF_P (type))
   12305     {
   12306       if (!LAMBDA_EXPR_MUTABLE_P (lam))
   12307 	type = cp_build_qualified_type (type, (cp_type_quals (type)
   12308 					       |TYPE_QUAL_CONST));
   12309       type = build_reference_type (type);
   12310     }
   12311   return type;
   12312 }
   12313 
   12314 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
   12315    this is a right unary fold. Otherwise it is a left unary fold. */
   12316 
   12317 static tree
   12318 finish_unary_fold_expr (tree expr, int op, tree_code dir)
   12319 {
   12320   /* Build a pack expansion (assuming expr has pack type).  */
   12321   if (!uses_parameter_packs (expr))
   12322     {
   12323       error_at (location_of (expr), "operand of fold expression has no "
   12324 		"unexpanded parameter packs");
   12325       return error_mark_node;
   12326     }
   12327   tree pack = make_pack_expansion (expr);
   12328 
   12329   /* Build the fold expression.  */
   12330   tree code = build_int_cstu (integer_type_node, abs (op));
   12331   tree fold = build_min_nt_loc (input_location, dir, code, pack);
   12332   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   12333   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   12334 						    FOLD_EXPR_OP (fold),
   12335 						    FOLD_EXPR_MODIFY_P (fold));
   12336   return fold;
   12337 }
   12338 
   12339 tree
   12340 finish_left_unary_fold_expr (tree expr, int op)
   12341 {
   12342   return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR);
   12343 }
   12344 
   12345 tree
   12346 finish_right_unary_fold_expr (tree expr, int op)
   12347 {
   12348   return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR);
   12349 }
   12350 
   12351 /* Build a binary fold expression over EXPR1 and EXPR2. The
   12352    associativity of the fold is determined by EXPR1 and EXPR2 (whichever
   12353    has an unexpanded parameter pack). */
   12354 
   12355 tree
   12356 finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir)
   12357 {
   12358   pack = make_pack_expansion (pack);
   12359   tree code = build_int_cstu (integer_type_node, abs (op));
   12360   tree fold = build_min_nt_loc (input_location, dir, code, pack, init);
   12361   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   12362   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   12363 						    FOLD_EXPR_OP (fold),
   12364 						    FOLD_EXPR_MODIFY_P (fold));
   12365   return fold;
   12366 }
   12367 
   12368 tree
   12369 finish_binary_fold_expr (tree expr1, tree expr2, int op)
   12370 {
   12371   // Determine which expr has an unexpanded parameter pack and
   12372   // set the pack and initial term.
   12373   bool pack1 = uses_parameter_packs (expr1);
   12374   bool pack2 = uses_parameter_packs (expr2);
   12375   if (pack1 && !pack2)
   12376     return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
   12377   else if (pack2 && !pack1)
   12378     return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
   12379   else
   12380     {
   12381       if (pack1)
   12382         error ("both arguments in binary fold have unexpanded parameter packs");
   12383       else
   12384         error ("no unexpanded parameter packs in binary fold");
   12385     }
   12386   return error_mark_node;
   12387 }
   12388 
   12389 /* Finish __builtin_launder (arg).  */
   12390 
   12391 tree
   12392 finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
   12393 {
   12394   tree orig_arg = arg;
   12395   if (!type_dependent_expression_p (arg))
   12396     arg = decay_conversion (arg, complain);
   12397   if (error_operand_p (arg))
   12398     return error_mark_node;
   12399   if (!type_dependent_expression_p (arg)
   12400       && !TYPE_PTR_P (TREE_TYPE (arg)))
   12401     {
   12402       error_at (loc, "non-pointer argument to %<__builtin_launder%>");
   12403       return error_mark_node;
   12404     }
   12405   if (processing_template_decl)
   12406     arg = orig_arg;
   12407   return build_call_expr_internal_loc (loc, IFN_LAUNDER,
   12408 				       TREE_TYPE (arg), 1, arg);
   12409 }
   12410 
   12411 /* Finish __builtin_convertvector (arg, type).  */
   12412 
   12413 tree
   12414 cp_build_vec_convert (tree arg, location_t loc, tree type,
   12415 		      tsubst_flags_t complain)
   12416 {
   12417   if (error_operand_p (type))
   12418     return error_mark_node;
   12419   if (error_operand_p (arg))
   12420     return error_mark_node;
   12421 
   12422   tree ret = NULL_TREE;
   12423   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
   12424     ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
   12425 			       decay_conversion (arg, complain),
   12426 			       loc, type, (complain & tf_error) != 0);
   12427 
   12428   if (!processing_template_decl)
   12429     return ret;
   12430 
   12431   return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
   12432 }
   12433 
   12434 /* Finish __builtin_bit_cast (type, arg).  */
   12435 
   12436 tree
   12437 cp_build_bit_cast (location_t loc, tree type, tree arg,
   12438 		   tsubst_flags_t complain)
   12439 {
   12440   if (error_operand_p (type))
   12441     return error_mark_node;
   12442   if (!dependent_type_p (type))
   12443     {
   12444       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
   12445 	return error_mark_node;
   12446       if (TREE_CODE (type) == ARRAY_TYPE)
   12447 	{
   12448 	  /* std::bit_cast for destination ARRAY_TYPE is not possible,
   12449 	     as functions may not return an array, so don't bother trying
   12450 	     to support this (and then deal with VLAs etc.).  */
   12451 	  error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   12452 			 "is an array type", type);
   12453 	  return error_mark_node;
   12454 	}
   12455       if (!trivially_copyable_p (type))
   12456 	{
   12457 	  error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   12458 			 "is not trivially copyable", type);
   12459 	  return error_mark_node;
   12460 	}
   12461     }
   12462 
   12463   if (error_operand_p (arg))
   12464     return error_mark_node;
   12465 
   12466   if (!type_dependent_expression_p (arg))
   12467     {
   12468       if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
   12469 	{
   12470 	  /* Don't perform array-to-pointer conversion.  */
   12471 	  arg = mark_rvalue_use (arg, loc, true);
   12472 	  if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
   12473 	    return error_mark_node;
   12474 	}
   12475       else
   12476 	arg = decay_conversion (arg, complain);
   12477 
   12478       if (error_operand_p (arg))
   12479 	return error_mark_node;
   12480 
   12481       if (!trivially_copyable_p (TREE_TYPE (arg)))
   12482 	{
   12483 	  error_at (cp_expr_loc_or_loc (arg, loc),
   12484 		    "%<__builtin_bit_cast%> source type %qT "
   12485 		    "is not trivially copyable", TREE_TYPE (arg));
   12486 	  return error_mark_node;
   12487 	}
   12488       if (!dependent_type_p (type)
   12489 	  && !cp_tree_equal (TYPE_SIZE_UNIT (type),
   12490 			     TYPE_SIZE_UNIT (TREE_TYPE (arg))))
   12491 	{
   12492 	  error_at (loc, "%<__builtin_bit_cast%> source size %qE "
   12493 			 "not equal to destination type size %qE",
   12494 			 TYPE_SIZE_UNIT (TREE_TYPE (arg)),
   12495 			 TYPE_SIZE_UNIT (type));
   12496 	  return error_mark_node;
   12497 	}
   12498     }
   12499 
   12500   tree ret = build_min (BIT_CAST_EXPR, type, arg);
   12501   SET_EXPR_LOCATION (ret, loc);
   12502 
   12503   if (!processing_template_decl && CLASS_TYPE_P (type))
   12504     ret = get_target_expr_sfinae (ret, complain);
   12505 
   12506   return ret;
   12507 }
   12508 
   12509 #include "gt-cp-semantics.h"
   12510