LCOV - code coverage report
Current view: top level - gcc/cp - semantics.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.1 % 7405 6968
Test Date: 2026-06-20 15:32:29 Functions: 98.0 % 249 244
Legend: Lines:     hit not hit

            Line data    Source code
       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-2026 Free Software Foundation, Inc.
       7              :    Written by Mark Mitchell (mmitchell@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              : #include "gimplify.h"
      49              : #include "contracts.h"
      50              : #include "c-family/c-pragma.h"
      51              : 
      52              : /* There routines provide a modular interface to perform many parsing
      53              :    operations.  They may therefore be used during actual parsing, or
      54              :    during template instantiation, which may be regarded as a
      55              :    degenerate form of parsing.  */
      56              : 
      57              : static tree finalize_nrv_r (tree *, int *, void *);
      58              : 
      59              : /* Used for OpenMP non-static data member privatization.  */
      60              : 
      61              : static hash_map<tree, tree> *omp_private_member_map;
      62              : static vec<tree> omp_private_member_vec;
      63              : static bool omp_private_member_ignore_next;
      64              : 
      65              : 
      66              : /* Deferred Access Checking Overview
      67              :    ---------------------------------
      68              : 
      69              :    Most C++ expressions and declarations require access checking
      70              :    to be performed during parsing.  However, in several cases,
      71              :    this has to be treated differently.
      72              : 
      73              :    For member declarations, access checking has to be deferred
      74              :    until more information about the declaration is known.  For
      75              :    example:
      76              : 
      77              :      class A {
      78              :          typedef int X;
      79              :        public:
      80              :          X f();
      81              :      };
      82              : 
      83              :      A::X A::f();
      84              :      A::X g();
      85              : 
      86              :    When we are parsing the function return type `A::X', we don't
      87              :    really know if this is allowed until we parse the function name.
      88              : 
      89              :    Furthermore, some contexts require that access checking is
      90              :    never performed at all.  These include class heads, and template
      91              :    instantiations.
      92              : 
      93              :    Typical use of access checking functions is described here:
      94              : 
      95              :    1. When we enter a context that requires certain access checking
      96              :       mode, the function `push_deferring_access_checks' is called with
      97              :       DEFERRING argument specifying the desired mode.  Access checking
      98              :       may be performed immediately (dk_no_deferred), deferred
      99              :       (dk_deferred), or not performed (dk_no_check).
     100              : 
     101              :    2. When a declaration such as a type, or a variable, is encountered,
     102              :       the function `perform_or_defer_access_check' is called.  It
     103              :       maintains a vector of all deferred checks.
     104              : 
     105              :    3. The global `current_class_type' or `current_function_decl' is then
     106              :       setup by the parser.  `enforce_access' relies on these information
     107              :       to check access.
     108              : 
     109              :    4. Upon exiting the context mentioned in step 1,
     110              :       `perform_deferred_access_checks' is called to check all declaration
     111              :       stored in the vector. `pop_deferring_access_checks' is then
     112              :       called to restore the previous access checking mode.
     113              : 
     114              :       In case of parsing error, we simply call `pop_deferring_access_checks'
     115              :       without `perform_deferred_access_checks'.  */
     116              : 
     117              : struct GTY(()) deferred_access {
     118              :   /* A vector representing name-lookups for which we have deferred
     119              :      checking access controls.  We cannot check the accessibility of
     120              :      names used in a decl-specifier-seq until we know what is being
     121              :      declared because code like:
     122              : 
     123              :        class A {
     124              :          class B {};
     125              :          B* f();
     126              :        }
     127              : 
     128              :        A::B* A::f() { return 0; }
     129              : 
     130              :      is valid, even though `A::B' is not generally accessible.  */
     131              :   vec<deferred_access_check, va_gc> *deferred_access_checks;
     132              : 
     133              :   /* The current mode of access checks.  */
     134              :   enum deferring_kind deferring_access_checks_kind;
     135              : };
     136              : 
     137              : /* Data for deferred access checking.  */
     138              : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
     139              : static GTY(()) unsigned deferred_access_no_check;
     140              : 
     141              : /* Save the current deferred access states and start deferred
     142              :    access checking iff DEFER_P is true.  */
     143              : 
     144              : void
     145  23141971423 : push_deferring_access_checks (deferring_kind deferring)
     146              : {
     147              :   /* For context like template instantiation, access checking
     148              :      disabling applies to all nested context.  */
     149  23141971423 :   if (deferred_access_no_check || deferring == dk_no_check)
     150    293505928 :     deferred_access_no_check++;
     151              :   else
     152              :     {
     153  22848465495 :       deferred_access e = {NULL, deferring};
     154  22848465495 :       vec_safe_push (deferred_access_stack, e);
     155              :     }
     156  23141971423 : }
     157              : 
     158              : /* Save the current deferred access states and start deferred access
     159              :    checking, continuing the set of deferred checks in CHECKS.  */
     160              : 
     161              : void
     162    365571875 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
     163              : {
     164    365571875 :   push_deferring_access_checks (dk_deferred);
     165    365571875 :   if (!deferred_access_no_check)
     166    358903440 :     deferred_access_stack->last().deferred_access_checks = checks;
     167    365571875 : }
     168              : 
     169              : /* Resume deferring access checks again after we stopped doing
     170              :    this previously.  */
     171              : 
     172              : void
     173    176932654 : resume_deferring_access_checks (void)
     174              : {
     175    176932654 :   if (!deferred_access_no_check)
     176    176912343 :     deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
     177    176932654 : }
     178              : 
     179              : /* Stop deferring access checks.  */
     180              : 
     181              : void
     182    496625400 : stop_deferring_access_checks (void)
     183              : {
     184    496625400 :   if (!deferred_access_no_check)
     185    496565187 :     deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
     186    496625400 : }
     187              : 
     188              : /* Discard the current deferred access checks and restore the
     189              :    previous states.  */
     190              : 
     191              : void
     192  14343023190 : pop_deferring_access_checks (void)
     193              : {
     194  14343023190 :   if (deferred_access_no_check)
     195    224748210 :     deferred_access_no_check--;
     196              :   else
     197  14118274980 :     deferred_access_stack->pop ();
     198  14343023190 : }
     199              : 
     200              : /* Returns a TREE_LIST representing the deferred checks.
     201              :    The TREE_PURPOSE of each node is the type through which the
     202              :    access occurred; the TREE_VALUE is the declaration named.
     203              :    */
     204              : 
     205              : vec<deferred_access_check, va_gc> *
     206   1230883165 : get_deferred_access_checks (void)
     207              : {
     208   1230883165 :   if (deferred_access_no_check)
     209              :     return NULL;
     210              :   else
     211   1217687110 :     return (deferred_access_stack->last().deferred_access_checks);
     212              : }
     213              : 
     214              : /* Take current deferred checks and combine with the
     215              :    previous states if we also defer checks previously.
     216              :    Otherwise perform checks now.  */
     217              : 
     218              : void
     219   8798811870 : pop_to_parent_deferring_access_checks (void)
     220              : {
     221   8798811870 :   if (deferred_access_no_check)
     222     68757712 :     deferred_access_no_check--;
     223              :   else
     224              :     {
     225   8730054158 :       vec<deferred_access_check, va_gc> *checks;
     226   8730054158 :       deferred_access *ptr;
     227              : 
     228   8730054158 :       checks = (deferred_access_stack->last ().deferred_access_checks);
     229              : 
     230   8730054158 :       deferred_access_stack->pop ();
     231   8730054158 :       ptr = &deferred_access_stack->last ();
     232   8730054158 :       if (ptr->deferring_access_checks_kind == dk_no_deferred)
     233              :         {
     234              :           /* Check access.  */
     235    549967341 :           perform_access_checks (checks, tf_warning_or_error);
     236              :         }
     237              :       else
     238              :         {
     239              :           /* Merge with parent.  */
     240              :           int i, j;
     241              :           deferred_access_check *chk, *probe;
     242              : 
     243   8376921111 :           FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     244              :             {
     245    107092255 :               FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
     246              :                 {
     247      9614204 :                   if (probe->binfo == chk->binfo &&
     248      7633900 :                       probe->decl == chk->decl &&
     249       939976 :                       probe->diag_decl == chk->diag_decl)
     250       939096 :                     goto found;
     251              :                 }
     252              :               /* Insert into parent's checks.  */
     253     97478051 :               vec_safe_push (ptr->deferred_access_checks, *chk);
     254     98417147 :             found:;
     255              :             }
     256              :         }
     257              :     }
     258   8798811870 : }
     259              : 
     260              : /* Called from enforce_access.  A class has attempted (but failed) to access
     261              :    DECL.  It is already established that a baseclass of that class,
     262              :    PARENT_BINFO, has private access to DECL.  Examine certain special cases
     263              :    to find a decl that accurately describes the source of the problem.  If
     264              :    none of the special cases apply, simply return DECL as the source of the
     265              :    problem.  */
     266              : 
     267              : static tree
     268          182 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
     269              : {
     270              :   /* When a class is denied access to a decl in a baseclass, most of the
     271              :      time it is because the decl itself was declared as private at the point
     272              :      of declaration.
     273              : 
     274              :      However, in C++, there are (at least) two situations in which a decl
     275              :      can be private even though it was not originally defined as such.
     276              :      These two situations only apply if a baseclass had private access to
     277              :      DECL (this function is only called if that is the case).  */
     278              : 
     279              :   /* We should first check whether the reason the parent had private access
     280              :      to DECL was simply because DECL was created and declared as private in
     281              :      the parent.  If it was, then DECL is definitively the source of the
     282              :      problem.  */
     283          182 :   if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
     284              :                          BINFO_TYPE (parent_binfo)))
     285              :     return decl;
     286              : 
     287              :   /* 1.  If the "using" keyword is used to inherit DECL within the parent,
     288              :      this may cause DECL to be private, so we should return the using
     289              :      statement as the source of the problem.
     290              : 
     291              :      Scan the fields of PARENT_BINFO and see if there are any using decls.  If
     292              :      there are, see if they inherit DECL.  If they do, that's where DECL must
     293              :      have been declared private.  */
     294              : 
     295           66 :   for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
     296          326 :        parent_field;
     297          260 :        parent_field = DECL_CHAIN (parent_field))
     298              :     /* Not necessary, but also check TREE_PRIVATE for the sake of
     299              :        eliminating obviously non-relevant using decls.  */
     300          278 :     if (TREE_CODE (parent_field) == USING_DECL
     301           81 :         && TREE_PRIVATE (parent_field))
     302              :       {
     303           78 :         tree decl_stripped = strip_using_decl (parent_field);
     304              : 
     305              :         /* The using statement might be overloaded.  If so, we need to
     306              :            check all of the overloads.  */
     307          180 :         for (ovl_iterator iter (decl_stripped); iter; ++iter)
     308              :           /* If equal, the using statement inherits DECL, and so is the
     309              :              source of the access failure, so return it.  */
     310           99 :           if (*iter == decl)
     311           18 :             return parent_field;
     312              :       }
     313              : 
     314              :   /* 2.  If DECL was privately inherited by the parent class, then DECL will
     315              :      be inaccessible, even though it may originally have been accessible to
     316              :      deriving classes.  In that case, the fault lies with the parent, since it
     317              :      used a private inheritance, so we return the parent as the source of the
     318              :      problem.
     319              : 
     320              :      Since this is the last check, we just assume it's true.  At worst, it
     321              :      will simply point to the class that failed to give access, which is
     322              :      technically true.  */
     323           48 :   return TYPE_NAME (BINFO_TYPE (parent_binfo));
     324              : }
     325              : 
     326              : /* If the current scope isn't allowed to access DECL along
     327              :    BASETYPE_PATH, give an error, or if we're parsing a function or class
     328              :    template, defer the access check to be performed at instantiation time.
     329              :    The most derived class in BASETYPE_PATH is the one used to qualify DECL.
     330              :    DIAG_DECL is the declaration to use in the error diagnostic.  */
     331              : 
     332              : static bool
     333    397685391 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
     334              :                 tsubst_flags_t complain, access_failure_info *afi = NULL)
     335              : {
     336    397685391 :   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
     337              : 
     338    397685391 :   if (flag_new_inheriting_ctors
     339    503027620 :       && DECL_INHERITED_CTOR (decl))
     340              :     {
     341              :       /* 7.3.3/18: The additional constructors are accessible if they would be
     342              :          accessible when used to construct an object of the corresponding base
     343              :          class.  */
     344        59517 :       decl = strip_inheriting_ctors (decl);
     345        59517 :       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
     346              :                                    ba_any, NULL, complain);
     347              :     }
     348              : 
     349    397685391 :   tree cs = current_scope ();
     350    397685391 :   if (in_template_context
     351    397685391 :       && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
     352     40391213 :     if (tree template_info = get_template_info (cs))
     353              :       {
     354              :         /* When parsing a function or class template, we in general need to
     355              :            defer access checks until template instantiation time, since a friend
     356              :            declaration may grant access only to a particular specialization of
     357              :            the template.  */
     358              : 
     359     40155192 :         if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     360              :           /* But if the member is deemed accessible at parse time, then we can
     361              :              assume it'll be accessible at instantiation time.  */
     362              :           return true;
     363              : 
     364              :         /* Access of a dependent decl should be rechecked after tsubst'ing
     365              :            into the user of the decl, rather than explicitly deferring the
     366              :            check here.  */
     367          135 :         gcc_assert (!uses_template_parms (decl));
     368          135 :         if (TREE_CODE (decl) == FIELD_DECL)
     369            6 :           gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
     370              : 
     371              :         /* Defer this access check until instantiation time.  */
     372          135 :         deferred_access_check access_check;
     373          135 :         access_check.binfo = basetype_path;
     374          135 :         access_check.decl = decl;
     375          135 :         access_check.diag_decl = diag_decl;
     376          135 :         access_check.loc = input_location;
     377          135 :         vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
     378          135 :         return true;
     379              :       }
     380              : 
     381    357530199 :   if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     382              :     {
     383        21499 :       if (flag_new_inheriting_ctors)
     384        21469 :         diag_decl = strip_inheriting_ctors (diag_decl);
     385        21499 :       if (complain & tf_error)
     386              :         {
     387         1153 :           access_kind access_failure_reason = ak_none;
     388              : 
     389              :           /* By default, using the decl as the source of the problem will
     390              :              usually give correct results.  */
     391         1153 :           tree diag_location = diag_decl;
     392              : 
     393              :           /* However, if a parent of BASETYPE_PATH had private access to decl,
     394              :              then it actually might be the case that the source of the problem
     395              :              is not DECL.  */
     396         1153 :           tree parent_binfo = get_parent_with_private_access (decl,
     397              :                                                               basetype_path);
     398              : 
     399              :           /* So if a parent did have private access, then we need to do
     400              :              special checks to obtain the best diagnostic location decl.  */
     401         1153 :           if (parent_binfo != NULL_TREE)
     402              :             {
     403          182 :               diag_location = get_class_access_diagnostic_decl (parent_binfo,
     404              :                                                                 diag_decl);
     405              : 
     406              :               /* We also at this point know that the reason access failed was
     407              :                  because decl was private.  */
     408          182 :               access_failure_reason = ak_private;
     409              :             }
     410              : 
     411              :           /* Finally, generate an error message.  */
     412         1153 :           complain_about_access (decl, diag_decl, diag_location, true,
     413              :                                  access_failure_reason);
     414              :         }
     415        21499 :       if (afi)
     416          412 :         afi->record_access_failure (basetype_path, decl, diag_decl);
     417        21499 :       return false;
     418              :     }
     419              : 
     420              :   return true;
     421              : }
     422              : 
     423              : /* Perform the access checks in CHECKS.  The TREE_PURPOSE of each node
     424              :    is the BINFO indicating the qualifying scope used to access the
     425              :    DECL node stored in the TREE_VALUE of the node.  If CHECKS is empty
     426              :    or we aren't in SFINAE context or all the checks succeed return TRUE,
     427              :    otherwise FALSE.  */
     428              : 
     429              : bool
     430   1048408410 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
     431              :                        tsubst_flags_t complain)
     432              : {
     433   1048408410 :   int i;
     434   1048408410 :   deferred_access_check *chk;
     435   1048408410 :   location_t loc = input_location;
     436   1048408410 :   bool ok = true;
     437              : 
     438   1048408410 :   if (!checks)
     439              :     return true;
     440              : 
     441    122775428 :   FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     442              :     {
     443     68336180 :       input_location = chk->loc;
     444     68336180 :       ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
     445              :     }
     446              : 
     447     54439248 :   input_location = loc;
     448     54439248 :   return (complain & tf_error) ? true : ok;
     449              : }
     450              : 
     451              : /* Perform the deferred access checks.
     452              : 
     453              :    After performing the checks, we still have to keep the list
     454              :    `deferred_access_stack->deferred_access_checks' since we may want
     455              :    to check access for them again later in a different context.
     456              :    For example:
     457              : 
     458              :      class A {
     459              :        typedef int X;
     460              :        static X a;
     461              :      };
     462              :      A::X A::a, x;      // No error for `A::a', error for `x'
     463              : 
     464              :    We have to perform deferred access of `A::X', first with `A::a',
     465              :    next with `x'.  Return value like perform_access_checks above.  */
     466              : 
     467              : bool
     468    274555424 : perform_deferred_access_checks (tsubst_flags_t complain)
     469              : {
     470    274555424 :   return perform_access_checks (get_deferred_access_checks (), complain);
     471              : }
     472              : 
     473              : /* Defer checking the accessibility of DECL, when looked up in
     474              :    BINFO. DIAG_DECL is the declaration to use to print diagnostics.
     475              :    Return value like perform_access_checks above.
     476              :    If non-NULL, report failures to AFI.  */
     477              : 
     478              : bool
     479    594615187 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
     480              :                                tsubst_flags_t complain,
     481              :                                access_failure_info *afi)
     482              : {
     483    594615187 :   int i;
     484    594615187 :   deferred_access *ptr;
     485    594615187 :   deferred_access_check *chk;
     486              : 
     487              :   /* Exit if we are in a context that no access checking is performed.  */
     488    594615187 :   if (deferred_access_no_check)
     489              :     return true;
     490              : 
     491    570746716 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     492              : 
     493    570746716 :   ptr = &deferred_access_stack->last ();
     494              : 
     495              :   /* If we are not supposed to defer access checks, just check now.  */
     496    570746716 :   if (ptr->deferring_access_checks_kind == dk_no_deferred)
     497              :     {
     498    329349211 :       bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
     499    501334512 :       return (complain & tf_error) ? true : ok;
     500              :     }
     501              : 
     502              :   /* See if we are already going to perform this check.  */
     503    293947767 :   FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
     504              :     {
     505     69085669 :       if (chk->decl == decl && chk->binfo == binfo &&
     506     16536386 :           chk->diag_decl == diag_decl)
     507              :         {
     508              :           return true;
     509              :         }
     510              :     }
     511              :   /* If not, record the check.  */
     512    224862098 :   deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
     513    224862098 :   vec_safe_push (ptr->deferred_access_checks, new_access);
     514              : 
     515    224862098 :   return true;
     516              : }
     517              : 
     518              : /* Returns nonzero if the current statement is a full expression,
     519              :    i.e. temporaries created during that statement should be destroyed
     520              :    at the end of the statement.  */
     521              : 
     522              : int
     523   1442425639 : stmts_are_full_exprs_p (void)
     524              : {
     525   1442425639 :   return current_stmt_tree ()->stmts_are_full_exprs_p;
     526              : }
     527              : 
     528              : /* T is a statement.  Add it to the statement-tree.  This is the C++
     529              :    version.  The C/ObjC frontends have a slightly different version of
     530              :    this function.  */
     531              : 
     532              : tree
     533   1247462576 : add_stmt (tree t)
     534              : {
     535   1247462576 :   enum tree_code code = TREE_CODE (t);
     536              : 
     537   1247462576 :   if (EXPR_P (t) && code != LABEL_EXPR)
     538              :     {
     539   1199445662 :       if (!EXPR_HAS_LOCATION (t))
     540    191874463 :         SET_EXPR_LOCATION (t, input_location);
     541              : 
     542              :       /* When we expand a statement-tree, we must know whether or not the
     543              :          statements are full-expressions.  We record that fact here.  */
     544   1199445662 :       if (STATEMENT_CODE_P (TREE_CODE (t)))
     545    312115150 :         STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
     546              :     }
     547              : 
     548   1247462576 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     549      5482330 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     550              : 
     551              :   /* Add T to the statement-tree.  Non-side-effect statements need to be
     552              :      recorded during statement expressions.  */
     553   1247462576 :   gcc_checking_assert (!stmt_list_stack->is_empty ());
     554   1247462576 :   append_to_statement_list_force (t, &cur_stmt_list);
     555              : 
     556   1247462576 :   return t;
     557              : }
     558              : 
     559              : /* Returns the stmt_tree to which statements are currently being added.  */
     560              : 
     561              : stmt_tree
     562   7379901321 : current_stmt_tree (void)
     563              : {
     564   7379901321 :   return (cfun
     565   7343260280 :           ? &cfun->language->base.x_stmt_tree
     566   7379901321 :           : &scope_chain->x_stmt_tree);
     567              : }
     568              : 
     569              : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR.  */
     570              : 
     571              : static tree
     572       303706 : maybe_cleanup_point_expr (tree expr)
     573              : {
     574       303706 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     575       290633 :     expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
     576       303706 :   return expr;
     577              : }
     578              : 
     579              : /* Like maybe_cleanup_point_expr except have the type of the new expression be
     580              :    void so we don't need to create a temporary variable to hold the inner
     581              :    expression.  The reason why we do this is because the original type might be
     582              :    an aggregate and we cannot create a temporary variable for that type.  */
     583              : 
     584              : tree
     585    309424223 : maybe_cleanup_point_expr_void (tree expr)
     586              : {
     587    309424223 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     588    103163598 :     expr = fold_build_cleanup_point_expr (void_type_node, expr);
     589    309424223 :   return expr;
     590              : }
     591              : 
     592              : 
     593              : 
     594              : /* Create a declaration statement for the declaration given by the DECL.  */
     595              : 
     596              : void
     597    104816228 : add_decl_expr (tree decl)
     598              : {
     599    104816228 :   tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
     600    104816228 :   if (DECL_INITIAL (decl)
     601    104816228 :       || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
     602     18642723 :     r = maybe_cleanup_point_expr_void (r);
     603    104816228 :   add_stmt (r);
     604    104816228 : }
     605              : 
     606              : /* Set EXPR_LOCATION on one cleanup T to LOC.  */
     607              : 
     608              : static void
     609      5560272 : set_one_cleanup_loc (tree t, location_t loc)
     610              : {
     611      5560272 :   if (!t)
     612              :     return;
     613              : 
     614      5560272 :   if (TREE_CODE (t) != POSTCONDITION_STMT)
     615      5560272 :     protected_set_expr_location (t, loc);
     616              : 
     617              :   /* Avoid locus differences for C++ cdtor calls depending on whether
     618              :      cdtor_returns_this: a conversion to void is added to discard the return
     619              :      value, and this conversion ends up carrying the location, and when it
     620              :      gets discarded, the location is lost.  So hold it in the call as well.  */
     621      5560272 :   if (TREE_CODE (t) == NOP_EXPR
     622            0 :       && TREE_TYPE (t) == void_type_node
     623      5560272 :       && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
     624            0 :     protected_set_expr_location (TREE_OPERAND (t, 0), loc);
     625              : }
     626              : 
     627              : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC.  */
     628              : 
     629              : static void
     630   1177630023 : set_cleanup_locs (tree stmts, location_t loc)
     631              : {
     632   1183190295 :   if (TREE_CODE (stmts) == CLEANUP_STMT)
     633              :     {
     634      5560272 :       set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
     635      5560272 :       set_cleanup_locs (CLEANUP_BODY (stmts), loc);
     636              :     }
     637   1177630023 :   else if (TREE_CODE (stmts) == STATEMENT_LIST)
     638   1047726445 :     for (tree stmt : tsi_range (stmts))
     639    811548719 :       set_cleanup_locs (stmt, loc);
     640   1177630023 : }
     641              : 
     642              : /* True iff the innermost block scope is a try block.  */
     643              : 
     644              : static bool
     645    366081304 : at_try_scope ()
     646              : {
     647    366081304 :   cp_binding_level *b = current_binding_level;
     648    366081610 :   while (b && b->kind == sk_cleanup)
     649          306 :     b = b->level_chain;
     650    366081304 :   return b && b->kind == sk_try;
     651              : }
     652              : 
     653              : /* Finish a scope.  */
     654              : 
     655              : tree
     656    366081304 : do_poplevel (tree stmt_list)
     657              : {
     658    366081304 :   tree block = NULL;
     659              : 
     660    366081304 :   bool was_try = at_try_scope ();
     661              : 
     662    366081304 :   if (stmts_are_full_exprs_p ())
     663    366020669 :     block = poplevel (kept_level_p (), 1, 0);
     664              : 
     665              :   /* This needs to come after poplevel merges sk_cleanup statement_lists.  */
     666    366081304 :   maybe_splice_retval_cleanup (stmt_list, was_try);
     667              : 
     668    366081304 :   stmt_list = pop_stmt_list (stmt_list);
     669              : 
     670              :   /* input_location is the last token of the scope, usually a }.  */
     671    366081304 :   set_cleanup_locs (stmt_list, input_location);
     672              : 
     673    366081304 :   if (!processing_template_decl)
     674              :     {
     675    111777474 :       stmt_list = c_build_bind_expr (input_location, block, stmt_list);
     676              :       /* ??? See c_end_compound_stmt re statement expressions.  */
     677              :     }
     678              : 
     679    366081304 :   return stmt_list;
     680              : }
     681              : 
     682              : /* Begin a new scope.  */
     683              : 
     684              : tree
     685    366045119 : do_pushlevel (scope_kind sk)
     686              : {
     687    366045119 :   tree ret = push_stmt_list ();
     688    366045119 :   if (stmts_are_full_exprs_p ())
     689    366020723 :     begin_scope (sk, NULL);
     690    366045119 :   return ret;
     691              : }
     692              : 
     693              : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
     694              :    when the current scope is exited.  EH_ONLY is true when this is not
     695              :    meant to apply to normal control flow transfer.  DECL is the VAR_DECL
     696              :    being cleaned up, if any, or null for temporaries or subobjects.  */
     697              : 
     698              : void
     699      5560157 : push_cleanup (tree decl, tree cleanup, bool eh_only)
     700              : {
     701      5560157 :   tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
     702      5560157 :   CLEANUP_EH_ONLY (stmt) = eh_only;
     703      5560157 :   add_stmt (stmt);
     704      5560157 :   CLEANUP_BODY (stmt) = push_stmt_list ();
     705      5560157 : }
     706              : 
     707              : /* Simple infinite loop tracking for -Wreturn-type.  We keep a stack of all
     708              :    the current loops, represented by 'NULL_TREE' if we've seen a possible
     709              :    exit, and 'error_mark_node' if not.  This is currently used only to
     710              :    suppress the warning about a function with no return statements, and
     711              :    therefore we don't bother noting returns as possible exits.  We also
     712              :    don't bother with gotos.  */
     713              : 
     714              : static void
     715     17573626 : begin_maybe_infinite_loop (tree cond)
     716              : {
     717              :   /* Only track this while parsing a function, not during instantiation.  */
     718     17573626 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     719      2568394 :                 && !processing_template_decl))
     720              :     return;
     721     15004740 :   bool maybe_infinite = true;
     722     15004740 :   if (cond)
     723              :     {
     724     14708972 :       cond = fold_non_dependent_expr (cond);
     725     14708972 :       maybe_infinite = integer_nonzerop (cond);
     726              :     }
     727     29713712 :   vec_safe_push (cp_function_chain->infinite_loops,
     728     15004740 :                  maybe_infinite ? error_mark_node : NULL_TREE);
     729              : 
     730              : }
     731              : 
     732              : /* A break is a possible exit for the current loop.  */
     733              : 
     734              : void
     735      1464443 : break_maybe_infinite_loop (void)
     736              : {
     737      1464443 :   if (!cfun)
     738              :     return;
     739      1464443 :   cp_function_chain->infinite_loops->last() = NULL_TREE;
     740              : }
     741              : 
     742              : /* If we reach the end of the loop without seeing a possible exit, we have
     743              :    an infinite loop.  */
     744              : 
     745              : static void
     746     17573626 : end_maybe_infinite_loop (tree cond)
     747              : {
     748     17573626 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     749      2568394 :                 && !processing_template_decl))
     750              :     return;
     751     15004740 :   tree current = cp_function_chain->infinite_loops->pop();
     752     15004740 :   if (current != NULL_TREE)
     753              :     {
     754      4838984 :       cond = fold_non_dependent_expr (cond);
     755      4838984 :       if (integer_nonzerop (cond))
     756       300934 :         current_function_infinite_loop = 1;
     757              :     }
     758              : }
     759              : 
     760              : /* Begin a conditional that might contain a declaration.  When generating
     761              :    normal code, we want the declaration to appear before the statement
     762              :    containing the conditional.  When generating template code, we want the
     763              :    conditional to be rendered as the raw DECL_EXPR.  */
     764              : 
     765              : static void
     766     84343721 : begin_cond (tree *cond_p)
     767              : {
     768     84343721 :   if (processing_template_decl)
     769     60106078 :     *cond_p = push_stmt_list ();
     770     84343721 : }
     771              : 
     772              : /* Finish such a conditional.  */
     773              : 
     774              : static void
     775     84343721 : finish_cond (tree *cond_p, tree expr)
     776              : {
     777     84343721 :   if (processing_template_decl)
     778              :     {
     779     60106078 :       tree cond = pop_stmt_list (*cond_p);
     780              : 
     781     60106078 :       if (expr == NULL_TREE)
     782              :         /* Empty condition in 'for'.  */
     783       275750 :         gcc_assert (empty_expr_stmt_p (cond));
     784     59830328 :       else if (check_for_bare_parameter_packs (expr))
     785            0 :         expr = error_mark_node;
     786     59830328 :       else if (!empty_expr_stmt_p (cond))
     787       901184 :         expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
     788              :     }
     789     84343721 :   *cond_p = expr;
     790     84343721 : }
     791              : 
     792              : /* If loop condition specifies a conditional with a declaration,
     793              :    such as
     794              :             while (A x = 42) { }
     795              :             for (; A x = 42;) { }
     796              :    move the *BODY_P statements as a BIND_EXPR into {FOR,WHILE}_COND_PREP
     797              :    and if there are any CLEANUP_STMT at the end, remember their count in
     798              :    {FOR,WHILE}_COND_CLEANUP.
     799              :    genericize_c_loop will then handle it appropriately.  In particular,
     800              :    the {FOR,WHILE}_COND, {FOR,WHILE}_BODY, if used continue label and
     801              :    FOR_EXPR will be appended into the {FOR,WHILE}_COND_PREP BIND_EXPR,
     802              :    but it can't be done too early because only the actual body should
     803              :    bind BREAK_STMT and CONTINUE_STMT to the inner loop.
     804              :    The statement list for *BODY will be empty if the conditional did
     805              :    not declare anything.  */
     806              : 
     807              : static void
     808     11854942 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
     809              : {
     810     11854942 :   if (!TREE_SIDE_EFFECTS (*body_p))
     811     11845554 :     return;
     812              : 
     813         9388 :   gcc_assert (!processing_template_decl);
     814         9388 :   *prep_p = *body_p;
     815         9388 :   if (*prep_p != cur_stmt_list)
     816              :     {
     817              :       /* There can be just one CLEANUP_STMT, or there could be multiple
     818              :          nested CLEANUP_STMTs, e.g. for structured bindings used as
     819              :          condition.  */
     820           97 :       gcc_assert (stmt_list_stack->length () > 1);
     821           97 :       for (unsigned i = stmt_list_stack->length () - 2; ; --i)
     822              :         {
     823          109 :           tree t = (*stmt_list_stack)[i];
     824          109 :           tree_stmt_iterator last = tsi_last (t);
     825          218 :           gcc_assert (tsi_one_before_end_p (last)
     826              :                       && TREE_CODE (tsi_stmt (last)) == CLEANUP_STMT
     827              :                       && (CLEANUP_BODY (tsi_stmt (last))
     828              :                           == (*stmt_list_stack)[i + 1])
     829              :                       && !CLEANUP_EH_ONLY (tsi_stmt (last)));
     830          109 :           if (t == *prep_p)
     831              :             {
     832           97 :               *cleanup_p = build_int_cst (long_unsigned_type_node,
     833           97 :                                           stmt_list_stack->length () - 1 - i);
     834           97 :               break;
     835              :             }
     836           12 :           gcc_assert (i >= 1);
     837           12 :         }
     838              :     }
     839         9388 :   current_binding_level->keep = true;
     840         9388 :   tree_stmt_iterator iter = tsi_last (cur_stmt_list);
     841              :   /* Temporarily store in {FOR,WHILE}_BODY the last statement of
     842              :      the innnermost statement list or NULL if it has no statement.
     843              :      This is used in finish_loop_cond_prep to find out the splitting
     844              :      point and then {FOR,WHILE}_BODY will be changed to the actual
     845              :      body.  */
     846         9388 :   if (tsi_end_p (iter))
     847           91 :     *body_p = NULL_TREE;
     848              :   else
     849         9297 :     *body_p = tsi_stmt (iter);
     850              : }
     851              : 
     852              : /* Finalize {FOR,WHILE}_{BODY,COND_PREP} after the loop body.
     853              :    The above function initialized *BODY_P to the last statement
     854              :    in *PREP_P at that point.
     855              :    Call do_poplevel on *PREP_P and move everything after that
     856              :    former last statement into *BODY_P.  genericize_c_loop
     857              :    will later put those parts back together.
     858              :    CLEANUP is {FOR,WHILE}_COND_CLEANUP.  */
     859              : 
     860              : static void
     861         9388 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
     862              : {
     863         9388 :   *prep_p = do_poplevel (*prep_p);
     864         9388 :   gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
     865         9388 :   if (BIND_EXPR_BODY (*prep_p) == *body_p)
     866              :     {
     867           18 :       gcc_assert (cleanup == NULL_TREE);
     868           18 :       *body_p = build_empty_stmt (input_location);
     869          109 :       return;
     870              :     }
     871         9370 :   tree stmt_list = BIND_EXPR_BODY (*prep_p);
     872         9370 :   gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
     873         9370 :   if (cleanup)
     874              :     {
     875           97 :       tree_stmt_iterator iter = tsi_last (stmt_list);
     876           97 :       gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
     877          109 :       for (unsigned depth = tree_to_uhwi (cleanup); depth > 1; --depth)
     878              :         {
     879           12 :           gcc_assert (TREE_CODE (CLEANUP_BODY (tsi_stmt (iter)))
     880              :                       == STATEMENT_LIST);
     881           12 :           iter = tsi_last (CLEANUP_BODY (tsi_stmt (iter)));
     882           12 :           gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
     883              :         }
     884           97 :       if (*body_p == NULL_TREE)
     885              :         {
     886           91 :           *body_p = CLEANUP_BODY (tsi_stmt (iter));
     887           91 :           CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
     888           91 :           return;
     889              :         }
     890            6 :       stmt_list = CLEANUP_BODY (tsi_stmt (iter));
     891              :     }
     892         9279 :   tree_stmt_iterator iter = tsi_start (stmt_list);
     893         9475 :   while (tsi_stmt (iter) != *body_p)
     894          196 :     tsi_next (&iter);
     895         9279 :   *body_p = tsi_split_stmt_list (input_location, iter);
     896              : }
     897              : 
     898              : /* Finish a goto-statement.  */
     899              : 
     900              : tree
     901         2713 : finish_goto_stmt (tree destination)
     902              : {
     903         2713 :   if (identifier_p (destination))
     904         2576 :     destination = lookup_label (destination);
     905              : 
     906              :   /* We warn about unused labels with -Wunused.  That means we have to
     907              :      mark the used labels as used.  */
     908         2713 :   if (TREE_CODE (destination) == LABEL_DECL)
     909         2576 :     TREE_USED (destination) = 1;
     910              :   else
     911              :     {
     912          137 :       destination = mark_rvalue_use (destination);
     913          137 :       if (!processing_template_decl)
     914              :         {
     915          117 :           destination = cp_convert (ptr_type_node, destination,
     916              :                                     tf_warning_or_error);
     917          117 :           if (error_operand_p (destination))
     918              :             return NULL_TREE;
     919          108 :           destination
     920          108 :             = fold_build_cleanup_point_expr (TREE_TYPE (destination),
     921              :                                              destination);
     922              :         }
     923              :     }
     924              : 
     925         2704 :   add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
     926              : 
     927         2704 :   tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
     928         2704 :   check_goto (&TREE_OPERAND (stmt, 0));
     929              : 
     930         2704 :   return add_stmt (stmt);
     931              : }
     932              : 
     933              : /* Returns true if T corresponds to an assignment operator expression.  */
     934              : 
     935              : static bool
     936       874704 : is_assignment_op_expr_p (tree t)
     937              : {
     938       874704 :   if (t == NULL_TREE)
     939              :     return false;
     940              : 
     941       874704 :   if (TREE_CODE (t) == MODIFY_EXPR
     942       874704 :       || (TREE_CODE (t) == MODOP_EXPR
     943          336 :           && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
     944              :     return true;
     945              : 
     946       874017 :   tree call = extract_call_expr (t);
     947       874017 :   if (call == NULL_TREE
     948       129136 :       || call == error_mark_node
     949      1003153 :       || !CALL_EXPR_OPERATOR_SYNTAX (call))
     950              :     return false;
     951              : 
     952         4642 :   tree fndecl = cp_get_callee_fndecl_nofold (call);
     953         4642 :   return fndecl != NULL_TREE
     954         4544 :     && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
     955         4693 :     && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
     956              : }
     957              : 
     958              : /* Return true if TYPE is a class type that is convertible to
     959              :    and assignable from bool.  */
     960              : 
     961              : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
     962              : 
     963              : static bool
     964           60 : boolish_class_type_p (tree type)
     965              : {
     966           60 :   type = TYPE_MAIN_VARIANT (type);
     967           60 :   if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
     968              :     return false;
     969              : 
     970           77 :   if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
     971           26 :     return *r;
     972              : 
     973           19 :   tree ops;
     974           19 :   bool has_bool_assignment = false;
     975           19 :   bool has_bool_conversion = false;
     976              : 
     977           19 :   ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
     978           58 :   for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
     979              :     {
     980           31 :       op = STRIP_TEMPLATE (op);
     981           31 :       if (TREE_CODE (op) != FUNCTION_DECL)
     982            0 :         continue;
     983           31 :       tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
     984           31 :       tree parm_type = non_reference (TREE_TYPE (parm));
     985           31 :       if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
     986              :         {
     987              :           has_bool_assignment = true;
     988              :           break;
     989              :         }
     990              :     }
     991              : 
     992           19 :   if (has_bool_assignment)
     993              :     {
     994            4 :       ops = lookup_conversions (type);
     995            4 :       for (; ops; ops = TREE_CHAIN (ops))
     996              :         {
     997            4 :           tree op = TREE_VALUE (ops);
     998            4 :           if (!DECL_NONCONVERTING_P (op)
     999            4 :               && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
    1000              :             {
    1001              :               has_bool_conversion = true;
    1002              :               break;
    1003              :             }
    1004              :         }
    1005              :     }
    1006              : 
    1007           19 :   bool boolish = has_bool_assignment && has_bool_conversion;
    1008           19 :   hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
    1009           19 :   return boolish;
    1010              : }
    1011              : 
    1012              : 
    1013              : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
    1014              :    boolean context where 'a == b' might have been intended).
    1015              :    NESTED_P is true if T is the RHS of another assignment.  */
    1016              : 
    1017              : void
    1018     86580984 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
    1019              :                                        tsubst_flags_t complain)
    1020              : {
    1021     86580984 :   tree type = TREE_TYPE (t);
    1022     86580984 :   t = STRIP_REFERENCE_REF (t);
    1023              : 
    1024     86580984 :   if ((complain & tf_warning)
    1025     86522385 :       && warn_parentheses
    1026       874704 :       && is_assignment_op_expr_p (t)
    1027              :       /* A parenthesized expression would've had this warning
    1028              :          suppressed by finish_parenthesized_expr.  */
    1029          738 :       && !warning_suppressed_p (t, OPT_Wparentheses)
    1030              :       /* In c = a = b, don't warn if a has type bool or bool-like class.  */
    1031     86581331 :       && (!nested_p
    1032          176 :           || (TREE_CODE (type) != BOOLEAN_TYPE
    1033           60 :               && !boolish_class_type_p (type))))
    1034              :     {
    1035          219 :       warning_at (cp_expr_loc_or_input_loc (t), OPT_Wparentheses,
    1036              :                   "suggest parentheses around assignment used as truth value");
    1037          219 :       suppress_warning (t, OPT_Wparentheses);
    1038              :     }
    1039     86580984 : }
    1040              : 
    1041              : /* Helper class for saving/restoring ANNOTATE_EXPRs.  For a tree node t, users
    1042              :    can construct one of these like so:
    1043              : 
    1044              :      annotate_saver s (&t);
    1045              : 
    1046              :    and t will be updated to have any annotations removed.  The user can then
    1047              :    transform t, and later restore the ANNOTATE_EXPRs with:
    1048              : 
    1049              :      t = s.restore (t).
    1050              : 
    1051              :    The intent is to ensure that any ANNOTATE_EXPRs remain the outermost
    1052              :    expressions following any operations on t.  */
    1053              : 
    1054              : class annotate_saver {
    1055              :   /* The chain of saved annotations, if there were any.  Otherwise null.  */
    1056              :   tree m_annotations;
    1057              : 
    1058              :   /* If M_ANNOTATIONS is non-null, then M_INNER points to TREE_OPERAND (A, 0)
    1059              :      for the innermost annotation A.  */
    1060              :   tree *m_inner;
    1061              : 
    1062              : public:
    1063              :   annotate_saver (tree *);
    1064              :   tree restore (tree);
    1065              : };
    1066              : 
    1067              : /* If *COND is an ANNOTATE_EXPR, walk through the chain of annotations, and set
    1068              :    *COND equal to the first non-ANNOTATE_EXPR (saving a pointer to the
    1069              :    original chain of annotations for later use in restore).  */
    1070              : 
    1071     51188388 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
    1072              : {
    1073     51188388 :   tree *t = cond;
    1074     51198297 :   while (TREE_CODE (*t) == ANNOTATE_EXPR)
    1075         9909 :     t = &TREE_OPERAND (*t, 0);
    1076              : 
    1077     51188388 :   if (t != cond)
    1078              :     {
    1079         9906 :       m_annotations = *cond;
    1080         9906 :       *cond = *t;
    1081         9906 :       m_inner = t;
    1082              :     }
    1083     51188388 : }
    1084              : 
    1085              : /* If we didn't strip any annotations on construction, return NEW_INNER
    1086              :    unmodified.  Otherwise, wrap the saved annotations around NEW_INNER (updating
    1087              :    the types and flags of the annotations if needed) and return the resulting
    1088              :    expression.  */
    1089              : 
    1090              : tree
    1091     51188388 : annotate_saver::restore (tree new_inner)
    1092              : {
    1093     51188388 :   if (!m_annotations)
    1094              :     return new_inner;
    1095              : 
    1096              :   /* If the type of the inner expression changed, we need to update the types
    1097              :      of all the ANNOTATE_EXPRs.  We may need to update the flags too, but we
    1098              :      assume they only change if the type of the inner expression changes.
    1099              :      The flag update logic assumes that the other operands to the
    1100              :      ANNOTATE_EXPRs are always INTEGER_CSTs.  */
    1101         9906 :   if (TREE_TYPE (new_inner) != TREE_TYPE (*m_inner))
    1102              :     {
    1103            6 :       const bool new_readonly
    1104            6 :         = TREE_READONLY (new_inner) || CONSTANT_CLASS_P (new_inner);
    1105              : 
    1106           12 :       for (tree c = m_annotations; c != *m_inner; c = TREE_OPERAND (c, 0))
    1107              :         {
    1108            6 :           gcc_checking_assert (TREE_CODE (c) == ANNOTATE_EXPR
    1109              :                                && TREE_CODE (TREE_OPERAND (c, 1)) == INTEGER_CST
    1110              :                                && TREE_CODE (TREE_OPERAND (c, 2)) == INTEGER_CST);
    1111            6 :           TREE_TYPE (c) = TREE_TYPE (new_inner);
    1112            6 :           TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (new_inner);
    1113            6 :           TREE_READONLY (c) = new_readonly;
    1114              :         }
    1115              :     }
    1116              : 
    1117         9906 :   *m_inner = new_inner;
    1118         9906 :   return m_annotations;
    1119              : }
    1120              : 
    1121              : /* COND is the condition-expression for an if, while, etc.,
    1122              :    statement.  Convert it to a boolean value, if appropriate.
    1123              :    In addition, verify sequence points if -Wsequence-point is enabled.  */
    1124              : 
    1125              : tree
    1126     89127492 : maybe_convert_cond (tree cond)
    1127              : {
    1128              :   /* Empty conditions remain empty.  */
    1129     89127492 :   if (!cond)
    1130              :     return NULL_TREE;
    1131              : 
    1132              :   /* Wait until we instantiate templates before doing conversion.  */
    1133     88774887 :   if (type_dependent_expression_p (cond))
    1134     37586499 :     return cond;
    1135              : 
    1136              :   /* Strip any ANNOTATE_EXPRs from COND.  */
    1137     51188388 :   annotate_saver annotations (&cond);
    1138              : 
    1139              :   /* For structured binding used in condition, the conversion needs to be
    1140              :      evaluated before the individual variables are initialized in the
    1141              :      std::tuple_{size,element} case.  cp_finish_decomp saved the conversion
    1142              :      result in a TARGET_EXPR, pick it up from there.  */
    1143       353514 :   if (DECL_DECOMPOSITION_P (cond)
    1144          225 :       && DECL_DECOMP_IS_BASE (cond)
    1145          225 :       && DECL_DECOMP_BASE (cond)
    1146     51188610 :       && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1147           56 :     cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1148              : 
    1149     51188388 :   if (warn_sequence_point && !processing_template_decl)
    1150       326025 :     verify_sequence_points (cond);
    1151              : 
    1152     51188388 :   maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
    1153              :                                          tf_warning_or_error);
    1154              : 
    1155              :   /* Do the conversion.  */
    1156     51188388 :   cond = convert_from_reference (cond);
    1157     51188388 :   cond = condition_conversion (cond);
    1158              : 
    1159              :   /* Restore any ANNOTATE_EXPRs around COND.  */
    1160     51188388 :   return annotations.restore (cond);
    1161              : }
    1162              : 
    1163              : /* Finish an expression-statement, whose EXPRESSION is as indicated.  */
    1164              : 
    1165              : tree
    1166    159265690 : finish_expr_stmt (tree expr)
    1167              : {
    1168    159265690 :   tree r = NULL_TREE;
    1169    159265690 :   location_t loc = EXPR_LOCATION (expr);
    1170              : 
    1171    159097766 :   if (expr != NULL_TREE)
    1172              :     {
    1173              :       /* If we ran into a problem, make sure we complained.  */
    1174    159265529 :       gcc_assert (expr != error_mark_node || seen_error ());
    1175              : 
    1176    159265529 :       if (!processing_template_decl)
    1177              :         {
    1178     57270379 :           if (warn_sequence_point)
    1179       811435 :             verify_sequence_points (expr);
    1180     57270379 :           expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1181              :         }
    1182    101995150 :       else if (!type_dependent_expression_p (expr))
    1183     22083135 :         convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1184              : 
    1185    159265526 :       if (check_for_bare_parameter_packs (expr))
    1186           24 :         expr = error_mark_node;
    1187              : 
    1188              :       /* Simplification of inner statement expressions, compound exprs,
    1189              :          etc can result in us already having an EXPR_STMT or other statement
    1190              :          tree.  Don't wrap them in EXPR_STMT.  */
    1191    159265526 :       if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    1192              :         {
    1193    159265347 :           if (TREE_CODE (expr) != EXPR_STMT
    1194    156892255 :               && !STATEMENT_CLASS_P (expr)
    1195    156888104 :               && TREE_CODE (expr) != STATEMENT_LIST)
    1196    156758488 :             expr = build_stmt (loc, EXPR_STMT, expr);
    1197    159265347 :           expr = maybe_cleanup_point_expr_void (expr);
    1198              :         }
    1199              : 
    1200    159265526 :       r = add_stmt (expr);
    1201              :     }
    1202              : 
    1203    159265687 :   return r;
    1204              : }
    1205              : 
    1206              : 
    1207              : /* Begin an if-statement.  Returns a newly created IF_STMT if
    1208              :    appropriate.  */
    1209              : 
    1210              : tree
    1211     71804864 : begin_if_stmt (void)
    1212              : {
    1213     71804864 :   tree r, scope;
    1214     71804864 :   scope = do_pushlevel (sk_cond);
    1215     71804864 :   r = build_stmt (input_location, IF_STMT, NULL_TREE,
    1216              :                   NULL_TREE, NULL_TREE, scope);
    1217     71804864 :   current_binding_level->this_entity = r;
    1218     71804864 :   begin_cond (&IF_COND (r));
    1219     71804864 :   return r;
    1220              : }
    1221              : 
    1222              : /* Returns true if FN, a CALL_EXPR, is a call to
    1223              :    std::is_constant_evaluated or __builtin_is_constant_evaluated.  */
    1224              : 
    1225              : static bool
    1226       252098 : is_std_constant_evaluated_p (tree fn)
    1227              : {
    1228              :   /* std::is_constant_evaluated takes no arguments.  */
    1229       252098 :   if (call_expr_nargs (fn) != 0)
    1230              :     return false;
    1231              : 
    1232        90234 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
    1233        90234 :   if (fndecl == NULL_TREE)
    1234              :     return false;
    1235              : 
    1236        28271 :   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    1237              :                          BUILT_IN_FRONTEND))
    1238              :     return true;
    1239              : 
    1240        28242 :   if (!decl_in_std_namespace_p (fndecl))
    1241              :     return false;
    1242              : 
    1243        12905 :   tree name = DECL_NAME (fndecl);
    1244        12905 :   return name && id_equal (name, "is_constant_evaluated");
    1245              : }
    1246              : 
    1247              : /* Callback function for maybe_warn_for_constant_evaluated that looks
    1248              :    for calls to std::is_constant_evaluated in TP.  */
    1249              : 
    1250              : static tree
    1251      4677351 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
    1252              : {
    1253      4677351 :   tree t = *tp;
    1254              : 
    1255      4677351 :   if (TYPE_P (t) || TREE_CONSTANT (t))
    1256              :     {
    1257       827524 :       *walk_subtrees = false;
    1258       827524 :       return NULL_TREE;
    1259              :     }
    1260              : 
    1261      3849827 :   switch (TREE_CODE (t))
    1262              :     {
    1263       252098 :     case CALL_EXPR:
    1264       252098 :       if (is_std_constant_evaluated_p (t))
    1265              :         return t;
    1266              :       break;
    1267            6 :     case EXPR_STMT:
    1268              :       /* Don't warn in statement expressions.  */
    1269            6 :       *walk_subtrees = false;
    1270            6 :       return NULL_TREE;
    1271              :     default:
    1272              :       break;
    1273              :     }
    1274              : 
    1275              :   return NULL_TREE;
    1276              : }
    1277              : 
    1278              : /* In certain contexts, std::is_constant_evaluated() is always true (for
    1279              :    instance, in a consteval function or in a constexpr if), or always false
    1280              :    (e.g., in a non-constexpr non-consteval function) so give the user a clue.  */
    1281              : 
    1282              : static void
    1283     71890450 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
    1284              :                                    bool trivial_infinite)
    1285              : {
    1286     71890450 :   if (!warn_tautological_compare)
    1287              :     return;
    1288              : 
    1289              :   /* Suppress warning for std::is_constant_evaluated if the conditional
    1290              :      comes from a macro.  */
    1291      1428990 :   if (from_macro_expansion_at (EXPR_LOCATION (cond)))
    1292              :     return;
    1293              : 
    1294       602954 :   cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
    1295              :                                           NULL);
    1296       602954 :   if (cond)
    1297              :     {
    1298         2392 :       if (constexpr_if)
    1299           34 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1300              :                     "%<std::is_constant_evaluated%> always evaluates to "
    1301              :                     "true in %<if constexpr%>");
    1302         2358 :       else if (trivial_infinite)
    1303              :         {
    1304            8 :           auto_diagnostic_group d;
    1305            8 :           if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1306              :                           "%<std::is_constant_evaluated%> evaluates to "
    1307              :                           "true when checking if trivially empty iteration "
    1308              :                           "statement is trivial infinite loop")
    1309            8 :               && !maybe_constexpr_fn (current_function_decl))
    1310            8 :             inform (EXPR_LOCATION (cond),
    1311              :                     "and evaluates to false when actually evaluating "
    1312              :                     "the condition in non-%<constexpr%> function");
    1313            8 :         }
    1314         2350 :       else if (!maybe_constexpr_fn (current_function_decl))
    1315           38 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1316              :                     "%<std::is_constant_evaluated%> always evaluates to "
    1317              :                     "false in a non-%<constexpr%> function");
    1318         4624 :       else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1319            3 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1320              :                     "%<std::is_constant_evaluated%> always evaluates to "
    1321              :                     "true in a %<consteval%> function");
    1322              :     }
    1323              : }
    1324              : 
    1325              : /* Process the COND of an if-statement, which may be given by
    1326              :    IF_STMT.  */
    1327              : 
    1328              : tree
    1329     71804864 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
    1330              : {
    1331     71804864 :   tree cond = maybe_convert_cond (orig_cond);
    1332     71804864 :   maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
    1333              :                                      /*trivial_infinite=*/false);
    1334     71804864 :   if (IF_STMT_CONSTEXPR_P (if_stmt)
    1335     14947401 :       && !type_dependent_expression_p (cond)
    1336     10106934 :       && require_constant_expression (cond)
    1337     10106904 :       && !instantiation_dependent_expression_p (cond)
    1338              :       /* Wait until instantiation time, since only then COND has been
    1339              :          converted to bool.  */
    1340     77278638 :       && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
    1341              :     {
    1342      5473774 :       cond = instantiate_non_dependent_expr (cond);
    1343      5473774 :       cond = cxx_constant_value (cond);
    1344              :     }
    1345     66331090 :   else if (processing_template_decl)
    1346     49898346 :     cond = orig_cond;
    1347     71804864 :   finish_cond (&IF_COND (if_stmt), cond);
    1348     71804864 :   add_stmt (if_stmt);
    1349     71804864 :   THEN_CLAUSE (if_stmt) = push_stmt_list ();
    1350     71804864 :   return cond;
    1351              : }
    1352              : 
    1353              : /* Finish the then-clause of an if-statement, which may be given by
    1354              :    IF_STMT.  */
    1355              : 
    1356              : tree
    1357     71799735 : finish_then_clause (tree if_stmt)
    1358              : {
    1359     71799735 :   THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
    1360     71799735 :   return if_stmt;
    1361              : }
    1362              : 
    1363              : /* Begin the else-clause of an if-statement.  */
    1364              : 
    1365              : void
    1366     26859225 : begin_else_clause (tree if_stmt)
    1367              : {
    1368     26859225 :   ELSE_CLAUSE (if_stmt) = push_stmt_list ();
    1369     26859225 : }
    1370              : 
    1371              : /* Finish the else-clause of an if-statement, which may be given by
    1372              :    IF_STMT.  */
    1373              : 
    1374              : void
    1375     26859187 : finish_else_clause (tree if_stmt)
    1376              : {
    1377     26859187 :   ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
    1378     26859187 : }
    1379              : 
    1380              : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
    1381              :    read.  */
    1382              : 
    1383              : static tree
    1384    802914009 : maybe_mark_exp_read_r (tree *tp, int *, void *)
    1385              : {
    1386    802914009 :   tree t = *tp;
    1387    802914009 :   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1388     46756534 :     mark_exp_read (t);
    1389    802914009 :   return NULL_TREE;
    1390              : }
    1391              : 
    1392              : /* Finish an if-statement.  */
    1393              : 
    1394              : void
    1395     71799735 : finish_if_stmt (tree if_stmt)
    1396              : {
    1397     71799735 :   tree scope = IF_SCOPE (if_stmt);
    1398     71799735 :   IF_SCOPE (if_stmt) = NULL;
    1399     71799735 :   if (IF_STMT_CONSTEXPR_P (if_stmt))
    1400              :     {
    1401              :       /* Prevent various -Wunused warnings.  We might not instantiate
    1402              :          either of these branches, so we would not mark the variables
    1403              :          used in that branch as read.  */
    1404     14942272 :       cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
    1405              :                                        maybe_mark_exp_read_r, NULL);
    1406     14942272 :       cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
    1407              :                                        maybe_mark_exp_read_r, NULL);
    1408              :     }
    1409     71799735 :   add_stmt (do_poplevel (scope));
    1410     71799735 : }
    1411              : 
    1412              : /* Determine if iteration statement with *CONDP condition and
    1413              :    loop BODY is trivially empty iteration statement or even
    1414              :    trivial infinite loop.  In the latter case for -ffinite-loops
    1415              :    add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
    1416              :    Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
    1417              :    calls in the condition when needed.  */
    1418              : 
    1419              : static void
    1420     16966735 : finish_loop_cond (tree *condp, tree body)
    1421              : {
    1422     16966735 :   if (TREE_CODE (*condp) == INTEGER_CST)
    1423              :     return;
    1424     12196636 :   bool trivially_empty = expr_first (body) == NULL_TREE;
    1425     12196636 :   bool trivial_infinite = false;
    1426     12196636 :   if (trivially_empty)
    1427              :     {
    1428        95510 :       tree c = fold_non_dependent_expr (*condp, tf_none,
    1429              :                                         /*manifestly_const_eval=*/true);
    1430        95510 :       trivial_infinite = c && integer_nonzerop (c);
    1431              :     }
    1432     12196636 :   if (warn_tautological_compare)
    1433              :     {
    1434        85788 :       tree cond = *condp;
    1435        86155 :       while (TREE_CODE (cond) == ANNOTATE_EXPR)
    1436          367 :         cond = TREE_OPERAND (cond, 0);
    1437        85788 :       if (trivial_infinite
    1438        85852 :           && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1439           64 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1440              :                                            /*trivial_infinite=*/true);
    1441        85724 :       else if (!trivially_empty
    1442          375 :                || !processing_template_decl
    1443        86128 :                || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1444        85522 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1445              :                                            /*trivial_infinite=*/false);
    1446              :     }
    1447     12196636 :   if (trivial_infinite && flag_finite_loops && !processing_template_decl)
    1448           64 :     *condp = build3 (ANNOTATE_EXPR, TREE_TYPE (*condp), *condp,
    1449              :                      build_int_cst (integer_type_node,
    1450              :                                     annot_expr_maybe_infinite_kind),
    1451              :                      integer_zero_node);
    1452              : }
    1453              : 
    1454              : /* Begin a while-statement.  Returns a newly created WHILE_STMT if
    1455              :    appropriate.  */
    1456              : 
    1457              : tree
    1458      4636109 : begin_while_stmt (void)
    1459              : {
    1460      4636109 :   tree r;
    1461      4636109 :   r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1462              :                   NULL_TREE, NULL_TREE);
    1463      4636109 :   add_stmt (r);
    1464      4636109 :   WHILE_BODY (r) = do_pushlevel (sk_block);
    1465      4636109 :   begin_cond (&WHILE_COND (r));
    1466      4636109 :   return r;
    1467              : }
    1468              : 
    1469              : /* Process the COND of a while-statement, which may be given by
    1470              :    WHILE_STMT.  */
    1471              : 
    1472              : void
    1473      4636109 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
    1474              :                         tree unroll, bool novector)
    1475              : {
    1476      4636109 :   cond = maybe_convert_cond (cond);
    1477      4636109 :   finish_cond (&WHILE_COND (while_stmt), cond);
    1478      4636109 :   begin_maybe_infinite_loop (cond);
    1479      4636109 :   if (ivdep && cond != error_mark_node)
    1480           24 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1481           12 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1482           12 :                                       WHILE_COND (while_stmt),
    1483              :                                       build_int_cst (integer_type_node,
    1484              :                                                      annot_expr_ivdep_kind),
    1485              :                                       integer_zero_node);
    1486      4636109 :   if (unroll && cond != error_mark_node)
    1487        26306 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1488        13153 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1489        13153 :                                       WHILE_COND (while_stmt),
    1490              :                                       build_int_cst (integer_type_node,
    1491              :                                                      annot_expr_unroll_kind),
    1492              :                                       unroll);
    1493      4636109 :   if (novector && cond != error_mark_node)
    1494           42 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1495           21 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1496           21 :                                       WHILE_COND (while_stmt),
    1497              :                                       build_int_cst (integer_type_node,
    1498              :                                                      annot_expr_no_vector_kind),
    1499              :                                       integer_zero_node);
    1500      4636109 :   adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
    1501              :                          &WHILE_COND_PREP (while_stmt),
    1502              :                          &WHILE_COND_CLEANUP (while_stmt));
    1503      4636109 : }
    1504              : 
    1505              : /* Finish a while-statement, which may be given by WHILE_STMT.  */
    1506              : 
    1507              : void
    1508      4636109 : finish_while_stmt (tree while_stmt)
    1509              : {
    1510      4636109 :   end_maybe_infinite_loop (boolean_true_node);
    1511      4636109 :   if (WHILE_COND_PREP (while_stmt))
    1512         9214 :     finish_loop_cond_prep (&WHILE_BODY (while_stmt),
    1513              :                            &WHILE_COND_PREP (while_stmt),
    1514         9214 :                            WHILE_COND_CLEANUP (while_stmt));
    1515              :   else
    1516      4626895 :     WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
    1517      4636109 :   finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
    1518      4636109 : }
    1519              : 
    1520              : /* Begin a do-statement.  Returns a newly created DO_STMT if
    1521              :    appropriate.  */
    1522              : 
    1523              : tree
    1524      5464398 : begin_do_stmt (void)
    1525              : {
    1526      5464398 :   tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
    1527              :                        NULL_TREE);
    1528      5464398 :   begin_maybe_infinite_loop (boolean_true_node);
    1529      5464398 :   add_stmt (r);
    1530      5464398 :   DO_BODY (r) = push_stmt_list ();
    1531      5464398 :   return r;
    1532              : }
    1533              : 
    1534              : /* Finish the body of a do-statement, which may be given by DO_STMT.  */
    1535              : 
    1536              : void
    1537      5464398 : finish_do_body (tree do_stmt)
    1538              : {
    1539      5464398 :   tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
    1540              : 
    1541      5464398 :   if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
    1542       518456 :     body = STATEMENT_LIST_TAIL (body)->stmt;
    1543              : 
    1544      5464398 :   if (IS_EMPTY_STMT (body))
    1545           30 :     warning (OPT_Wempty_body,
    1546              :             "suggest explicit braces around empty body in %<do%> statement");
    1547      5464398 : }
    1548              : 
    1549              : /* Finish a do-statement, which may be given by DO_STMT, and whose
    1550              :    COND is as indicated.  */
    1551              : 
    1552              : void
    1553      5464398 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
    1554              :                 bool novector)
    1555              : {
    1556      5464398 :   cond = maybe_convert_cond (cond);
    1557      5464398 :   end_maybe_infinite_loop (cond);
    1558              :   /* Unlike other iteration statements, the condition may not contain
    1559              :      a declaration, so we don't call finish_cond which checks for
    1560              :      unexpanded parameter packs.  */
    1561      5464398 :   if (check_for_bare_parameter_packs (cond))
    1562            3 :     cond = error_mark_node;
    1563      5464398 :   if (ivdep && cond != error_mark_node)
    1564            3 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1565              :                    build_int_cst (integer_type_node, annot_expr_ivdep_kind),
    1566              :                    integer_zero_node);
    1567      5464398 :   if (unroll && cond != error_mark_node)
    1568            9 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1569              :                    build_int_cst (integer_type_node, annot_expr_unroll_kind),
    1570              :                    unroll);
    1571      5464398 :   if (novector && cond != error_mark_node)
    1572            0 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1573              :                    build_int_cst (integer_type_node, annot_expr_no_vector_kind),
    1574              :                    integer_zero_node);
    1575      5464398 :   DO_COND (do_stmt) = cond;
    1576      5464398 :   tree do_body = DO_BODY (do_stmt);
    1577      5464368 :   if (CONVERT_EXPR_P (do_body)
    1578           30 :       && integer_zerop (TREE_OPERAND (do_body, 0))
    1579      5464428 :       && VOID_TYPE_P (TREE_TYPE (do_body)))
    1580              :     do_body = NULL_TREE;
    1581      5464398 :   finish_loop_cond (&DO_COND (do_stmt), do_body);
    1582      5464398 : }
    1583              : 
    1584              : /* Finish a return-statement.  The EXPRESSION returned, if any, is as
    1585              :    indicated.  */
    1586              : 
    1587              : tree
    1588    124683283 : finish_return_stmt (tree expr)
    1589              : {
    1590    124683283 :   tree r;
    1591    124683283 :   bool no_warning;
    1592    124683283 :   bool dangling;
    1593              : 
    1594    124683283 :   expr = check_return_expr (expr, &no_warning, &dangling);
    1595              : 
    1596    124683283 :   if (error_operand_p (expr)
    1597    124683283 :       || (flag_openmp && !check_omp_return ()))
    1598              :     {
    1599              :       /* Suppress -Wreturn-type for this function.  */
    1600         1304 :       if (warn_return_type)
    1601         1298 :         suppress_warning (current_function_decl, OPT_Wreturn_type);
    1602         1304 :       return error_mark_node;
    1603              :     }
    1604              : 
    1605    124681979 :   if (!processing_template_decl)
    1606              :     {
    1607     43642347 :       if (warn_sequence_point)
    1608      1022966 :         verify_sequence_points (expr);
    1609              :     }
    1610              : 
    1611    124681979 :   r = build_stmt (input_location, RETURN_EXPR, expr);
    1612    124681979 :   RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
    1613    124681979 :   if (no_warning)
    1614           33 :     suppress_warning (r, OPT_Wreturn_type);
    1615    124681979 :   r = maybe_cleanup_point_expr_void (r);
    1616    124681979 :   r = add_stmt (r);
    1617              : 
    1618    124681979 :   return r;
    1619              : }
    1620              : 
    1621              : /* Begin the scope of a for-statement or a range-for-statement.
    1622              :    Both the returned trees are to be used in a call to
    1623              :    begin_for_stmt or begin_range_for_stmt.  */
    1624              : 
    1625              : tree
    1626      7473119 : begin_for_scope (tree *init)
    1627              : {
    1628      7473119 :   tree scope = do_pushlevel (sk_for);
    1629              : 
    1630      7473119 :   if (processing_template_decl)
    1631      5937758 :     *init = push_stmt_list ();
    1632              :   else
    1633      1535361 :     *init = NULL_TREE;
    1634              : 
    1635      7473119 :   return scope;
    1636              : }
    1637              : 
    1638              : /* Begin a for-statement.  Returns a new FOR_STMT.
    1639              :    SCOPE and INIT should be the return of begin_for_scope,
    1640              :    or both NULL_TREE  */
    1641              : 
    1642              : tree
    1643      7218833 : begin_for_stmt (tree scope, tree init)
    1644              : {
    1645      7218833 :   tree r;
    1646              : 
    1647      7218833 :   r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
    1648              :                   NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
    1649              :                   NULL_TREE, NULL_TREE);
    1650              : 
    1651      7218833 :   if (scope == NULL_TREE)
    1652              :     {
    1653      1298622 :       gcc_assert (!init);
    1654      1298622 :       scope = begin_for_scope (&init);
    1655              :     }
    1656              : 
    1657      7218833 :   FOR_INIT_STMT (r) = init;
    1658      7218833 :   FOR_SCOPE (r) = scope;
    1659              : 
    1660      7218833 :   return r;
    1661              : }
    1662              : 
    1663              : /* Finish the init-statement of a for-statement, which may be
    1664              :    given by FOR_STMT.  */
    1665              : 
    1666              : void
    1667      7218833 : finish_init_stmt (tree for_stmt)
    1668              : {
    1669      7218833 :   if (processing_template_decl)
    1670      5683472 :     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
    1671      7218833 :   add_stmt (for_stmt);
    1672      7218833 :   FOR_BODY (for_stmt) = do_pushlevel (sk_block);
    1673      7218833 :   begin_cond (&FOR_COND (for_stmt));
    1674      7218833 : }
    1675              : 
    1676              : /* Finish the COND of a for-statement, which may be given by
    1677              :    FOR_STMT.  */
    1678              : 
    1679              : void
    1680      7218833 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
    1681              :                  bool novector)
    1682              : {
    1683      7218833 :   cond = maybe_convert_cond (cond);
    1684      7218833 :   finish_cond (&FOR_COND (for_stmt), cond);
    1685      7218833 :   begin_maybe_infinite_loop (cond);
    1686      7218833 :   if (ivdep && cond != error_mark_node)
    1687           68 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1688           34 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1689           34 :                                   FOR_COND (for_stmt),
    1690              :                                   build_int_cst (integer_type_node,
    1691              :                                                  annot_expr_ivdep_kind),
    1692              :                                   integer_zero_node);
    1693      7218833 :   if (unroll && cond != error_mark_node)
    1694          408 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1695          204 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1696          204 :                                   FOR_COND (for_stmt),
    1697              :                                   build_int_cst (integer_type_node,
    1698              :                                                  annot_expr_unroll_kind),
    1699              :                                   unroll);
    1700      7218833 :   if (novector && cond && cond != error_mark_node)
    1701          268 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1702          134 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1703          134 :                                   FOR_COND (for_stmt),
    1704              :                                   build_int_cst (integer_type_node,
    1705              :                                                  annot_expr_no_vector_kind),
    1706              :                                   integer_zero_node);
    1707      7218833 :   adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
    1708              :                          &FOR_COND_CLEANUP (for_stmt));
    1709      7218833 : }
    1710              : 
    1711              : /* Finish the increment-EXPRESSION in a for-statement, which may be
    1712              :    given by FOR_STMT.  */
    1713              : 
    1714              : void
    1715      7206689 : finish_for_expr (tree expr, tree for_stmt)
    1716              : {
    1717      7206689 :   if (!expr)
    1718              :     return;
    1719              :   /* If EXPR is an overloaded function, issue an error; there is no
    1720              :      context available to use to perform overload resolution.  */
    1721      6768551 :   if (type_unknown_p (expr))
    1722              :     {
    1723            6 :       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
    1724            6 :       expr = error_mark_node;
    1725              :     }
    1726      6768551 :   if (!processing_template_decl)
    1727              :     {
    1728      1464441 :       if (warn_sequence_point)
    1729        14943 :         verify_sequence_points (expr);
    1730      1464441 :       expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
    1731              :                               tf_warning_or_error);
    1732              :     }
    1733      5304110 :   else if (!type_dependent_expression_p (expr))
    1734      1893156 :     convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
    1735      6768551 :   expr = maybe_cleanup_point_expr_void (expr);
    1736      6768551 :   if (check_for_bare_parameter_packs (expr))
    1737            0 :     expr = error_mark_node;
    1738      6768551 :   FOR_EXPR (for_stmt) = expr;
    1739              : }
    1740              : 
    1741              : /* During parsing of the body, range for uses "__for_{range,begin,end} "
    1742              :    decl names to make those unaccessible by code in the body.
    1743              :    Find those decls and store into RANGE_FOR_DECL array, so that they
    1744              :    can be changed later to ones with underscore instead of space, so that
    1745              :    it can be inspected in the debugger.  */
    1746              : 
    1747              : void
    1748      7473232 : find_range_for_decls (tree range_for_decl[3])
    1749              : {
    1750      7473232 :   gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
    1751              :               && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
    1752              :               && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
    1753              :               && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
    1754              :               && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
    1755     29892928 :   for (int i = 0; i < 3; i++)
    1756              :     {
    1757     22419696 :       tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
    1758     22419696 :       if (IDENTIFIER_BINDING (id)
    1759     22419696 :           && IDENTIFIER_BINDING (id)->scope == current_binding_level)
    1760              :         {
    1761       258979 :           range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
    1762       258979 :           gcc_assert (VAR_P (range_for_decl[i])
    1763              :                       && DECL_ARTIFICIAL (range_for_decl[i]));
    1764              :         }
    1765              :     }
    1766      7473232 : }
    1767              : 
    1768              : /* Finish the body of a for-statement, which may be given by
    1769              :    FOR_STMT.  The increment-EXPR for the loop must be
    1770              :    provided.
    1771              :    It can also finish RANGE_FOR_STMT. */
    1772              : 
    1773              : void
    1774      7473119 : finish_for_stmt (tree for_stmt)
    1775              : {
    1776      7473119 :   end_maybe_infinite_loop (boolean_true_node);
    1777              : 
    1778      7473119 :   if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
    1779       254286 :     RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
    1780              :   else
    1781              :     {
    1782      7218833 :       if (FOR_COND_PREP (for_stmt))
    1783          174 :         finish_loop_cond_prep (&FOR_BODY (for_stmt),
    1784              :                                &FOR_COND_PREP (for_stmt),
    1785          174 :                                FOR_COND_CLEANUP (for_stmt));
    1786              :       else
    1787      7218659 :         FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
    1788      7218833 :       if (FOR_COND (for_stmt))
    1789      6866228 :         finish_loop_cond (&FOR_COND (for_stmt),
    1790      6866228 :                           FOR_EXPR (for_stmt) ? integer_one_node
    1791       136811 :                                               : FOR_BODY (for_stmt));
    1792              :     }
    1793              : 
    1794              :   /* Pop the scope for the body of the loop.  */
    1795      7473119 :   tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
    1796      7473119 :                      ? &RANGE_FOR_SCOPE (for_stmt)
    1797      7218833 :                      : &FOR_SCOPE (for_stmt));
    1798      7473119 :   tree scope = *scope_ptr;
    1799      7473119 :   *scope_ptr = NULL;
    1800              : 
    1801              :   /* During parsing of the body, range for uses "__for_{range,begin,end} "
    1802              :      decl names to make those unaccessible by code in the body.
    1803              :      Change it to ones with underscore instead of space, so that it can
    1804              :      be inspected in the debugger.  */
    1805      7473119 :   tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
    1806      7473119 :   find_range_for_decls (range_for_decl);
    1807              : 
    1808      7473119 :   add_stmt (do_poplevel (scope));
    1809              : 
    1810              :   /* If we're being called from build_vec_init, don't mess with the names of
    1811              :      the variables for an enclosing range-for.  */
    1812      7473119 :   if (!stmts_are_full_exprs_p ())
    1813        12144 :     return;
    1814              : 
    1815     29843900 :   for (int i = 0; i < 3; i++)
    1816     22382925 :     if (range_for_decl[i])
    1817       258863 :       DECL_NAME (range_for_decl[i])
    1818       258863 :         = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
    1819              : }
    1820              : 
    1821              : /* Begin a range-for-statement.  Returns a new RANGE_FOR_STMT.
    1822              :    SCOPE and INIT should be the return of begin_for_scope,
    1823              :    or both NULL_TREE  .
    1824              :    To finish it call finish_for_stmt(). */
    1825              : 
    1826              : tree
    1827       254286 : begin_range_for_stmt (tree scope, tree init)
    1828              : {
    1829       254286 :   begin_maybe_infinite_loop (boolean_false_node);
    1830              : 
    1831       254286 :   tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
    1832              :                        NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
    1833              : 
    1834       254286 :   if (scope == NULL_TREE)
    1835              :     {
    1836          254 :       gcc_assert (!init);
    1837          254 :       scope = begin_for_scope (&init);
    1838              :     }
    1839              : 
    1840              :   /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it.  */
    1841       254286 :   RANGE_FOR_INIT_STMT (r) = init;
    1842       254286 :   RANGE_FOR_SCOPE (r) = scope;
    1843              : 
    1844       254286 :   return r;
    1845              : }
    1846              : 
    1847              : /* Finish the head of a range-based for statement, which may
    1848              :    be given by RANGE_FOR_STMT.  DECL must be the declaration
    1849              :    and EXPR must be the loop expression. */
    1850              : 
    1851              : void
    1852       254286 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
    1853              : {
    1854       254286 :   if (processing_template_decl)
    1855       508572 :     RANGE_FOR_INIT_STMT (range_for_stmt)
    1856       508572 :       = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
    1857       254286 :   RANGE_FOR_DECL (range_for_stmt) = decl;
    1858       254286 :   RANGE_FOR_EXPR (range_for_stmt) = expr;
    1859       254286 :   add_stmt (range_for_stmt);
    1860       254286 :   RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
    1861       254286 : }
    1862              : 
    1863              : /* Begin the scope of an expansion-statement.  */
    1864              : 
    1865              : tree
    1866         1492 : begin_template_for_scope (tree *init)
    1867              : {
    1868         1492 :   tree scope = do_pushlevel (sk_template_for);
    1869              : 
    1870         1492 :   if (processing_template_decl)
    1871          429 :     *init = push_stmt_list ();
    1872              :   else
    1873         1063 :     *init = NULL_TREE;
    1874              : 
    1875         1492 :   return scope;
    1876              : }
    1877              : 
    1878              : /* Finish a break-statement.  */
    1879              : 
    1880              : tree
    1881      4617476 : finish_break_stmt (void)
    1882              : {
    1883              :   /* In switch statements break is sometimes stylistically used after
    1884              :      a return statement.  This can lead to spurious warnings about
    1885              :      control reaching the end of a non-void function when it is
    1886              :      inlined.  Note that we are calling block_may_fallthru with
    1887              :      language specific tree nodes; this works because
    1888              :      block_may_fallthru returns true when given something it does not
    1889              :      understand.  */
    1890      4617476 :   if (!block_may_fallthru (cur_stmt_list))
    1891          714 :     return void_node;
    1892      4616762 :   note_break_stmt ();
    1893      4616762 :   return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
    1894              : }
    1895              : 
    1896              : /* Finish a continue-statement.  */
    1897              : 
    1898              : tree
    1899       223630 : finish_continue_stmt (void)
    1900              : {
    1901       223630 :   return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
    1902              : }
    1903              : 
    1904              : /* Begin a switch-statement.  Returns a new SWITCH_STMT if
    1905              :    appropriate.  */
    1906              : 
    1907              : tree
    1908       683915 : begin_switch_stmt (void)
    1909              : {
    1910       683915 :   tree r, scope;
    1911              : 
    1912       683915 :   scope = do_pushlevel (sk_cond);
    1913       683915 :   r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1914              :                   scope, NULL_TREE);
    1915              : 
    1916       683915 :   begin_cond (&SWITCH_STMT_COND (r));
    1917              : 
    1918       683915 :   return r;
    1919              : }
    1920              : 
    1921              : /* Finish the cond of a switch-statement.  */
    1922              : 
    1923              : void
    1924       683915 : finish_switch_cond (tree cond, tree switch_stmt)
    1925              : {
    1926       683915 :   tree orig_type = NULL;
    1927              : 
    1928       683915 :   if (!processing_template_decl)
    1929              :     {
    1930              :       /* Convert the condition to an integer or enumeration type.  */
    1931       275263 :       tree orig_cond = cond;
    1932              :       /* For structured binding used in condition, the conversion needs to be
    1933              :          evaluated before the individual variables are initialized in the
    1934              :          std::tuple_{size,element} case.  cp_finish_decomp saved the
    1935              :          conversion result in a TARGET_EXPR, pick it up from there.  */
    1936          122 :       if (DECL_DECOMPOSITION_P (cond)
    1937           57 :           && DECL_DECOMP_IS_BASE (cond)
    1938           57 :           && DECL_DECOMP_BASE (cond)
    1939       275317 :           && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1940           18 :         cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1941       275263 :       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
    1942       275263 :       if (cond == NULL_TREE)
    1943              :         {
    1944           42 :           error_at (cp_expr_loc_or_input_loc (orig_cond),
    1945              :                     "switch quantity not an integer");
    1946           27 :           cond = error_mark_node;
    1947              :         }
    1948              :       /* We want unlowered type here to handle enum bit-fields.  */
    1949       275263 :       orig_type = unlowered_expr_type (cond);
    1950       275263 :       if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
    1951       197355 :         orig_type = TREE_TYPE (cond);
    1952       275263 :       if (cond != error_mark_node)
    1953              :         {
    1954              :           /* [stmt.switch]
    1955              : 
    1956              :              Integral promotions are performed.  */
    1957       275230 :           cond = perform_integral_promotions (cond);
    1958       275230 :           cond = maybe_cleanup_point_expr (cond);
    1959              :         }
    1960              :     }
    1961       683915 :   if (check_for_bare_parameter_packs (cond))
    1962            0 :     cond = error_mark_node;
    1963       683915 :   else if (!processing_template_decl && warn_sequence_point)
    1964         2797 :     verify_sequence_points (cond);
    1965              : 
    1966       683915 :   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
    1967       683915 :   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
    1968       683915 :   add_stmt (switch_stmt);
    1969       683915 :   push_switch (switch_stmt);
    1970       683915 :   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
    1971       683915 : }
    1972              : 
    1973              : /* Finish the body of a switch-statement, which may be given by
    1974              :    SWITCH_STMT.  The COND to switch on is indicated.  */
    1975              : 
    1976              : void
    1977       683915 : finish_switch_stmt (tree switch_stmt)
    1978              : {
    1979       683915 :   tree scope;
    1980              : 
    1981      1367830 :   SWITCH_STMT_BODY (switch_stmt) =
    1982       683915 :     pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
    1983       683915 :   pop_switch ();
    1984              : 
    1985       683915 :   scope = SWITCH_STMT_SCOPE (switch_stmt);
    1986       683915 :   SWITCH_STMT_SCOPE (switch_stmt) = NULL;
    1987       683915 :   add_stmt (do_poplevel (scope));
    1988       683915 : }
    1989              : 
    1990              : /* Begin a try-block.  Returns a newly-created TRY_BLOCK if
    1991              :    appropriate.  */
    1992              : 
    1993              : tree
    1994      1132081 : begin_try_block (void)
    1995              : {
    1996      1132081 :   tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
    1997      1132081 :   add_stmt (r);
    1998      1132081 :   TRY_STMTS (r) = push_stmt_list ();
    1999      1132081 :   return r;
    2000              : }
    2001              : 
    2002              : /* Likewise, for a function-try-block.  The block returned in
    2003              :    *COMPOUND_STMT is an artificial outer scope, containing the
    2004              :    function-try-block.  */
    2005              : 
    2006              : tree
    2007         1708 : begin_function_try_block (tree *compound_stmt)
    2008              : {
    2009         1708 :   tree r;
    2010              :   /* This outer scope does not exist in the C++ standard, but we need
    2011              :      a place to put __FUNCTION__ and similar variables.  */
    2012         1708 :   *compound_stmt = begin_compound_stmt (0);
    2013         1708 :   current_binding_level->artificial = 1;
    2014         1708 :   r = begin_try_block ();
    2015         1708 :   FN_TRY_BLOCK_P (r) = 1;
    2016         1708 :   return r;
    2017              : }
    2018              : 
    2019              : /* Finish a try-block, which may be given by TRY_BLOCK.  */
    2020              : 
    2021              : void
    2022      1132081 : finish_try_block (tree try_block)
    2023              : {
    2024      1132081 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2025      1132081 :   TRY_HANDLERS (try_block) = push_stmt_list ();
    2026      1132081 : }
    2027              : 
    2028              : /* Finish the body of a cleanup try-block, which may be given by
    2029              :    TRY_BLOCK.  */
    2030              : 
    2031              : void
    2032            0 : finish_cleanup_try_block (tree try_block)
    2033              : {
    2034            0 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2035            0 : }
    2036              : 
    2037              : /* Finish an implicitly generated try-block, with a cleanup is given
    2038              :    by CLEANUP.  */
    2039              : 
    2040              : void
    2041            0 : finish_cleanup (tree cleanup, tree try_block)
    2042              : {
    2043            0 :   TRY_HANDLERS (try_block) = cleanup;
    2044            0 :   CLEANUP_P (try_block) = 1;
    2045            0 : }
    2046              : 
    2047              : /* Likewise, for a function-try-block.  */
    2048              : 
    2049              : void
    2050         1708 : finish_function_try_block (tree try_block)
    2051              : {
    2052         1708 :   finish_try_block (try_block);
    2053              :   /* FIXME : something queer about CTOR_INITIALIZER somehow following
    2054              :      the try block, but moving it inside.  */
    2055         1708 :   in_function_try_handler = 1;
    2056         1708 : }
    2057              : 
    2058              : /* Finish a handler-sequence for a try-block, which may be given by
    2059              :    TRY_BLOCK.  */
    2060              : 
    2061              : void
    2062      1132081 : finish_handler_sequence (tree try_block)
    2063              : {
    2064      1132081 :   TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
    2065      1132081 :   check_handlers (TRY_HANDLERS (try_block));
    2066      1132081 : }
    2067              : 
    2068              : /* Finish the handler-seq for a function-try-block, given by
    2069              :    TRY_BLOCK.  COMPOUND_STMT is the outer block created by
    2070              :    begin_function_try_block.  */
    2071              : 
    2072              : void
    2073         1708 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
    2074              : {
    2075         1708 :   in_function_try_handler = 0;
    2076         1708 :   finish_handler_sequence (try_block);
    2077         1708 :   finish_compound_stmt (compound_stmt);
    2078         1708 : }
    2079              : 
    2080              : /* Begin a handler.  Returns a HANDLER if appropriate.  */
    2081              : 
    2082              : tree
    2083      1575910 : begin_handler (void)
    2084              : {
    2085      1575910 :   tree r;
    2086              : 
    2087      1575910 :   r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
    2088      1575910 :   add_stmt (r);
    2089              : 
    2090              :   /* Create a binding level for the eh_info and the exception object
    2091              :      cleanup.  */
    2092      1575910 :   HANDLER_BODY (r) = do_pushlevel (sk_catch);
    2093              : 
    2094      1575910 :   return r;
    2095              : }
    2096              : 
    2097              : /* Finish the handler-parameters for a handler, which may be given by
    2098              :    HANDLER.  DECL is the declaration for the catch parameter, or NULL
    2099              :    if this is a `catch (...)' clause.  */
    2100              : 
    2101              : void
    2102      1575910 : finish_handler_parms (tree decl, tree handler)
    2103              : {
    2104      1575910 :   tree type = NULL_TREE;
    2105      1575910 :   if (processing_template_decl)
    2106              :     {
    2107      1437561 :       if (decl)
    2108              :         {
    2109       466585 :           decl = pushdecl (decl);
    2110       466585 :           decl = push_template_decl (decl);
    2111       466585 :           HANDLER_PARMS (handler) = decl;
    2112       466585 :           type = TREE_TYPE (decl);
    2113              :         }
    2114              :     }
    2115              :   else
    2116              :     {
    2117       138349 :       type = expand_start_catch_block (decl);
    2118       138349 :       if (warn_catch_value
    2119         2118 :           && type != NULL_TREE
    2120          711 :           && type != error_mark_node
    2121       139060 :           && !TYPE_REF_P (TREE_TYPE (decl)))
    2122              :         {
    2123          210 :           tree orig_type = TREE_TYPE (decl);
    2124          210 :           if (CLASS_TYPE_P (orig_type))
    2125              :             {
    2126           96 :               if (TYPE_POLYMORPHIC_P (orig_type))
    2127           48 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2128           48 :                             OPT_Wcatch_value_,
    2129              :                             "catching polymorphic type %q#T by value",
    2130              :                             orig_type);
    2131           48 :               else if (warn_catch_value > 1)
    2132           36 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2133           36 :                             OPT_Wcatch_value_,
    2134              :                             "catching type %q#T by value", orig_type);
    2135              :             }
    2136          114 :           else if (warn_catch_value > 2)
    2137           54 :             warning_at (DECL_SOURCE_LOCATION (decl),
    2138           54 :                         OPT_Wcatch_value_,
    2139              :                         "catching non-reference type %q#T", orig_type);
    2140              :         }
    2141              :     }
    2142      1575910 :   HANDLER_TYPE (handler) = type;
    2143      1575910 : }
    2144              : 
    2145              : /* Finish a handler, which may be given by HANDLER.  The BLOCKs are
    2146              :    the return value from the matching call to finish_handler_parms.  */
    2147              : 
    2148              : void
    2149      1575910 : finish_handler (tree handler)
    2150              : {
    2151      1575910 :   if (!processing_template_decl)
    2152       138349 :     expand_end_catch_block ();
    2153      1575910 :   HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
    2154      1575910 : }
    2155              : 
    2156              : /* Begin a compound statement.  FLAGS contains some bits that control the
    2157              :    behavior and context.  If BCS_NO_SCOPE is set, the compound statement
    2158              :    does not define a scope.  If BCS_FN_BODY is set, this is the outermost
    2159              :    block of a function.  If BCS_TRY_BLOCK is set, this is the block
    2160              :    created on behalf of a TRY statement.  Returns a token to be passed to
    2161              :    finish_compound_stmt.  */
    2162              : 
    2163              : tree
    2164    277539531 : begin_compound_stmt (unsigned int flags)
    2165              : {
    2166    277539531 :   tree r;
    2167              : 
    2168    277539531 :   if (flags & BCS_NO_SCOPE)
    2169              :     {
    2170      5210129 :       r = push_stmt_list ();
    2171      5210129 :       STATEMENT_LIST_NO_SCOPE (r) = 1;
    2172              : 
    2173              :       /* Normally, we try hard to keep the BLOCK for a statement-expression.
    2174              :          But, if it's a statement-expression with a scopeless block, there's
    2175              :          nothing to keep, and we don't want to accidentally keep a block
    2176              :          *inside* the scopeless block.  */
    2177      5210129 :       keep_next_level (false);
    2178              :     }
    2179              :   else
    2180              :     {
    2181    272329402 :       scope_kind sk = sk_block;
    2182    272329402 :       if (flags & BCS_TRY_BLOCK)
    2183              :         sk = sk_try;
    2184    271197512 :       else if (flags & BCS_TRANSACTION)
    2185              :         sk = sk_transaction;
    2186    271197277 :       else if (flags & BCS_STMT_EXPR)
    2187        29088 :         sk = sk_stmt_expr;
    2188    272329402 :       r = do_pushlevel (sk);
    2189              :     }
    2190              : 
    2191              :   /* When processing a template, we need to remember where the braces were,
    2192              :      so that we can set up identical scopes when instantiating the template
    2193              :      later.  BIND_EXPR is a handy candidate for this.
    2194              :      Note that do_poplevel won't create a BIND_EXPR itself here (and thus
    2195              :      result in nested BIND_EXPRs), since we don't build BLOCK nodes when
    2196              :      processing templates.  */
    2197    277539531 :   if (processing_template_decl)
    2198              :     {
    2199    186562427 :       r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
    2200    186562427 :       BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
    2201    186562427 :       BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
    2202    186562427 :       TREE_SIDE_EFFECTS (r) = 1;
    2203              :     }
    2204              : 
    2205    277539531 :   return r;
    2206              : }
    2207              : 
    2208              : /* Finish a compound-statement, which is given by STMT.  */
    2209              : 
    2210              : void
    2211    277539492 : finish_compound_stmt (tree stmt)
    2212              : {
    2213    277539492 :   if (TREE_CODE (stmt) == BIND_EXPR)
    2214              :     {
    2215    186562427 :       tree body = do_poplevel (BIND_EXPR_BODY (stmt));
    2216              :       /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
    2217              :          discard the BIND_EXPR so it can be merged with the containing
    2218              :          STATEMENT_LIST.  */
    2219    186562427 :       if (TREE_CODE (body) == STATEMENT_LIST
    2220    169529246 :           && STATEMENT_LIST_HEAD (body) == NULL
    2221     11354353 :           && !BIND_EXPR_BODY_BLOCK (stmt)
    2222    197419300 :           && !BIND_EXPR_TRY_BLOCK (stmt))
    2223              :         stmt = body;
    2224              :       else
    2225    175705651 :         BIND_EXPR_BODY (stmt) = body;
    2226              :     }
    2227     90977065 :   else if (STATEMENT_LIST_NO_SCOPE (stmt))
    2228      5173890 :     stmt = pop_stmt_list (stmt);
    2229              :   else
    2230              :     {
    2231              :       /* Destroy any ObjC "super" receivers that may have been
    2232              :          created.  */
    2233     85803175 :       objc_clear_super_receiver ();
    2234              : 
    2235     85803175 :       stmt = do_poplevel (stmt);
    2236              :     }
    2237              : 
    2238              :   /* ??? See c_end_compound_stmt wrt statement expressions.  */
    2239    277539492 :   add_stmt (stmt);
    2240    277539492 : }
    2241              : 
    2242              : /* Finish an asm string literal, which can be a string literal
    2243              :    or parenthesized constant expression.  Extract the string literal
    2244              :    from the latter.  */
    2245              : 
    2246              : tree
    2247        53651 : finish_asm_string_expression (location_t loc, tree string)
    2248              : {
    2249        53651 :   if (string == error_mark_node
    2250        53638 :       || TREE_CODE (string) == STRING_CST
    2251          883 :       || processing_template_decl)
    2252              :     return string;
    2253          576 :   string = cxx_constant_value (string, tf_error);
    2254          576 :   if (TREE_CODE (string) == STRING_CST)
    2255           10 :     string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
    2256              :                          string);
    2257          576 :   cexpr_str cstr (string);
    2258          576 :   if (!cstr.type_check (loc))
    2259          171 :     return error_mark_node;
    2260          405 :   if (!cstr.extract (loc, string))
    2261           62 :     string = error_mark_node;
    2262          405 :   return string;
    2263          576 : }
    2264              : 
    2265              : /* Finish an asm-statement, whose components are a STRING, some
    2266              :    OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
    2267              :    LABELS.  Also note whether the asm-statement should be
    2268              :    considered volatile, and whether it is asm inline.  TOPLEV_P
    2269              :    is true if finishing namespace scope extended asm.  */
    2270              : 
    2271              : tree
    2272        29457 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
    2273              :                  tree output_operands, tree input_operands, tree clobbers,
    2274              :                  tree labels, bool inline_p, bool toplev_p)
    2275              : {
    2276        29457 :   tree r;
    2277        29457 :   tree t;
    2278        29457 :   int ninputs = list_length (input_operands);
    2279        29457 :   int noutputs = list_length (output_operands);
    2280              : 
    2281        29457 :   if (!processing_template_decl)
    2282              :     {
    2283        12356 :       const char *constraint;
    2284        12356 :       const char **oconstraints;
    2285        12356 :       bool allows_mem, allows_reg, is_inout;
    2286        12356 :       tree operand;
    2287        12356 :       int i;
    2288              : 
    2289        12356 :       oconstraints = XALLOCAVEC (const char *, noutputs);
    2290              : 
    2291        24610 :       string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
    2292              :                                              string);
    2293        12356 :       if (string == error_mark_node)
    2294          109 :         return error_mark_node;
    2295        36786 :       for (int i = 0; i < 2; ++i)
    2296        84290 :         for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
    2297              :           {
    2298        35242 :             tree s = TREE_VALUE (TREE_PURPOSE (t));
    2299        70466 :             s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2300        35242 :             if (s == error_mark_node)
    2301              :               return error_mark_node;
    2302        35212 :             TREE_VALUE (TREE_PURPOSE (t)) = s;
    2303              :           }
    2304        17700 :       for (t = clobbers; t; t = TREE_CHAIN (t))
    2305              :         {
    2306         5453 :           tree s = TREE_VALUE (t);
    2307        10900 :           s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2308         5453 :           TREE_VALUE (t) = s;
    2309              :         }
    2310              : 
    2311        12247 :       string = resolve_asm_operand_names (string, output_operands,
    2312              :                                           input_operands, labels);
    2313              : 
    2314        30592 :       for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
    2315              :         {
    2316        18345 :           operand = TREE_VALUE (t);
    2317              : 
    2318              :           /* ??? Really, this should not be here.  Users should be using a
    2319              :              proper lvalue, dammit.  But there's a long history of using
    2320              :              casts in the output operands.  In cases like longlong.h, this
    2321              :              becomes a primitive form of typechecking -- if the cast can be
    2322              :              removed, then the output operand had a type of the proper width;
    2323              :              otherwise we'll get an error.  Gross, but ...  */
    2324        18345 :           STRIP_NOPS (operand);
    2325              : 
    2326        18345 :           operand = mark_lvalue_use (operand);
    2327              : 
    2328        18345 :           if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
    2329            9 :             operand = error_mark_node;
    2330              : 
    2331        18345 :           if (operand != error_mark_node
    2332        18345 :               && (TREE_READONLY (operand)
    2333        18330 :                   || CP_TYPE_CONST_P (TREE_TYPE (operand))
    2334              :                   /* Functions are not modifiable, even though they are
    2335              :                      lvalues.  */
    2336        18330 :                   || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
    2337              :                   /* If it's an aggregate and any field is const, then it is
    2338              :                      effectively const.  */
    2339        18330 :                   || (CLASS_TYPE_P (TREE_TYPE (operand))
    2340          150 :                       && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
    2341            6 :             cxx_readonly_error (loc, operand, lv_asm);
    2342              : 
    2343              :           tree *op = &operand;
    2344        18352 :           while (TREE_CODE (*op) == COMPOUND_EXPR)
    2345            7 :             op = &TREE_OPERAND (*op, 1);
    2346        18345 :           switch (TREE_CODE (*op))
    2347              :             {
    2348           30 :             case PREINCREMENT_EXPR:
    2349           30 :             case PREDECREMENT_EXPR:
    2350           30 :             case MODIFY_EXPR:
    2351           30 :               *op = genericize_compound_lvalue (*op);
    2352           30 :               op = &TREE_OPERAND (*op, 1);
    2353           30 :               break;
    2354              :             default:
    2355              :               break;
    2356              :             }
    2357              : 
    2358        18345 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2359        18345 :           oconstraints[i] = constraint;
    2360              : 
    2361        18345 :           if (parse_output_constraint (&constraint, i, ninputs, noutputs,
    2362              :                                        &allows_mem, &allows_reg, &is_inout,
    2363              :                                        nullptr))
    2364              :             {
    2365              :               /* If the operand is going to end up in memory,
    2366              :                  mark it addressable.  */
    2367        18336 :               if (!allows_reg && !cxx_mark_addressable (*op))
    2368            0 :                 operand = error_mark_node;
    2369        18336 :               if (allows_reg && toplev_p)
    2370              :                 {
    2371            3 :                   error_at (loc, "constraint allows registers outside of "
    2372              :                                  "a function");
    2373            3 :                   operand = error_mark_node;
    2374              :                 }
    2375              :             }
    2376              :           else
    2377            9 :             operand = error_mark_node;
    2378              : 
    2379          447 :           if (toplev_p && operand != error_mark_node)
    2380              :             {
    2381           21 :               if (TREE_SIDE_EFFECTS (operand))
    2382              :                 {
    2383            0 :                   error_at (loc, "side-effects in output operand outside "
    2384              :                                  "of a function");
    2385            0 :                   operand = error_mark_node;
    2386              :                 }
    2387              :               else
    2388              :                 {
    2389           21 :                   tree addr
    2390           21 :                     = cp_build_addr_expr (operand, tf_warning_or_error);
    2391           21 :                   if (addr == error_mark_node)
    2392            0 :                     operand = error_mark_node;
    2393              :                   else
    2394              :                     {
    2395           21 :                       addr = maybe_constant_value (addr);
    2396           21 :                       if (!initializer_constant_valid_p (addr,
    2397           21 :                                                          TREE_TYPE (addr)))
    2398              :                         {
    2399            3 :                           error_at (loc, "output operand outside of a "
    2400              :                                          "function is not constant");
    2401            3 :                           operand = error_mark_node;
    2402              :                         }
    2403              :                       else
    2404           18 :                         operand = build_fold_indirect_ref (addr);
    2405              :                     }
    2406              :                 }
    2407              :             }
    2408        18324 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2409              :             {
    2410            3 :               error_at (loc, "%<-%> modifier used inside of a function");
    2411            3 :               operand = error_mark_node;
    2412              :             }
    2413              : 
    2414        18345 :           TREE_VALUE (t) = operand;
    2415              :         }
    2416              : 
    2417        29109 :       for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
    2418              :         {
    2419        16862 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2420        16862 :           bool constraint_parsed
    2421        16862 :             = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    2422              :                                       oconstraints, &allows_mem, &allows_reg,
    2423              :                                       nullptr);
    2424              :           /* If the operand is going to end up in memory, don't call
    2425              :              decay_conversion.  */
    2426        16862 :           if (constraint_parsed && !allows_reg && allows_mem)
    2427          315 :             operand = mark_lvalue_use (TREE_VALUE (t));
    2428              :           else
    2429        16547 :             operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
    2430              : 
    2431              :           /* If the type of the operand hasn't been determined (e.g.,
    2432              :              because it involves an overloaded function), then issue
    2433              :              an error message.  There's no context available to
    2434              :              resolve the overloading.  */
    2435        16862 :           if (TREE_TYPE (operand) == unknown_type_node)
    2436              :             {
    2437            3 :               error_at (loc,
    2438              :                         "type of %<asm%> operand %qE could not be determined",
    2439            3 :                         TREE_VALUE (t));
    2440            3 :               operand = error_mark_node;
    2441              :             }
    2442              : 
    2443        16862 :           if (constraint_parsed)
    2444              :             {
    2445              :               /* If the operand is going to end up in memory,
    2446              :                  mark it addressable.  */
    2447        16841 :               if (!allows_reg && allows_mem)
    2448              :                 {
    2449              :                   /* Strip the nops as we allow this case.  FIXME, this really
    2450              :                      should be rejected or made deprecated.  */
    2451          315 :                   STRIP_NOPS (operand);
    2452              : 
    2453          315 :                   tree *op = &operand;
    2454          322 :                   while (TREE_CODE (*op) == COMPOUND_EXPR)
    2455            7 :                     op = &TREE_OPERAND (*op, 1);
    2456          315 :                   switch (TREE_CODE (*op))
    2457              :                     {
    2458           27 :                     case PREINCREMENT_EXPR:
    2459           27 :                     case PREDECREMENT_EXPR:
    2460           27 :                     case MODIFY_EXPR:
    2461           27 :                       *op = genericize_compound_lvalue (*op);
    2462           27 :                       op = &TREE_OPERAND (*op, 1);
    2463           27 :                       break;
    2464              :                     default:
    2465              :                       break;
    2466              :                     }
    2467              : 
    2468          315 :                   if (!cxx_mark_addressable (*op))
    2469            0 :                     operand = error_mark_node;
    2470              :                 }
    2471        16526 :               else if (!allows_reg && !allows_mem)
    2472              :                 {
    2473              :                   /* If constraint allows neither register nor memory,
    2474              :                      try harder to get a constant.  */
    2475          474 :                   tree constop = maybe_constant_value (operand);
    2476          474 :                   if (TREE_CONSTANT (constop))
    2477          447 :                     operand = constop;
    2478              :                 }
    2479        16841 :               if (allows_reg && toplev_p)
    2480              :                 {
    2481            3 :                   error_at (loc, "constraint allows registers outside of "
    2482              :                                  "a function");
    2483            3 :                   operand = error_mark_node;
    2484              :                 }
    2485        16841 :               if (constraint[0] == ':' && operand != error_mark_node)
    2486              :                 {
    2487           48 :                   tree t = operand;
    2488           48 :                   STRIP_NOPS (t);
    2489           48 :                   if (TREE_CODE (t) != ADDR_EXPR
    2490           48 :                       || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
    2491           30 :                            || (VAR_P (TREE_OPERAND (t, 0))
    2492           24 :                                && is_global_var (TREE_OPERAND (t, 0)))))
    2493              :                     {
    2494           15 :                       error_at (loc, "%<:%> constraint operand is not address "
    2495              :                                 "of a function or non-automatic variable");
    2496           15 :                       operand = error_mark_node;
    2497              :                     }
    2498           33 :                   else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
    2499           12 :                     suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
    2500              :                 }
    2501              :             }
    2502              :           else
    2503           21 :             operand = error_mark_node;
    2504              : 
    2505        16862 :           if (toplev_p && operand != error_mark_node)
    2506              :             {
    2507          117 :               if (TREE_SIDE_EFFECTS (operand))
    2508              :                 {
    2509            6 :                   error_at (loc, "side-effects in input operand outside "
    2510              :                                  "of a function");
    2511            6 :                   operand = error_mark_node;
    2512              :                 }
    2513          111 :               else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
    2514              :                 {
    2515           21 :                   tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
    2516           21 :                   if (addr == error_mark_node)
    2517            0 :                     operand = error_mark_node;
    2518              :                   else
    2519              :                     {
    2520           21 :                       addr = maybe_constant_value (addr);
    2521           21 :                       if (!initializer_constant_valid_p (addr,
    2522           21 :                                                          TREE_TYPE (addr)))
    2523              :                         {
    2524            3 :                           error_at (loc, "input operand outside of a "
    2525              :                                          "function is not constant");
    2526            3 :                           operand = error_mark_node;
    2527              :                         }
    2528              :                       else
    2529           18 :                         operand = build_fold_indirect_ref (addr);
    2530              :                     }
    2531              :                 }
    2532              :               else
    2533              :                 {
    2534           90 :                   operand = maybe_constant_value (operand);
    2535           90 :                   if (!initializer_constant_valid_p (operand,
    2536           90 :                                                      TREE_TYPE (operand)))
    2537              :                     {
    2538            3 :                       error_at (loc, "input operand outside of a "
    2539              :                                      "function is not constant");
    2540            3 :                       operand = error_mark_node;
    2541              :                     }
    2542              :                 }
    2543              :             }
    2544        16745 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2545              :             {
    2546            9 :               error_at (loc, "%<-%> modifier used inside of a function");
    2547            9 :               operand = error_mark_node;
    2548              :             }
    2549              : 
    2550        16862 :           TREE_VALUE (t) = operand;
    2551              :         }
    2552              :     }
    2553              : 
    2554        29348 :   r = build_stmt (loc, ASM_EXPR, string,
    2555              :                   output_operands, input_operands,
    2556              :                   clobbers, labels);
    2557        29348 :   ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
    2558        29348 :   ASM_INLINE_P (r) = inline_p;
    2559        29348 :   if (toplev_p)
    2560              :     {
    2561           99 :       symtab->finalize_toplevel_asm (r);
    2562           99 :       return r;
    2563              :     }
    2564        29249 :   r = maybe_cleanup_point_expr_void (r);
    2565        29249 :   return add_stmt (r);
    2566              : }
    2567              : 
    2568              : /* Finish a label with the indicated NAME.  Returns the new label.  */
    2569              : 
    2570              : tree
    2571         2488 : finish_label_stmt (tree name)
    2572              : {
    2573         2488 :   tree decl = define_label (input_location, name);
    2574              : 
    2575         2488 :   if (decl == error_mark_node)
    2576              :     return error_mark_node;
    2577              : 
    2578         2482 :   add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
    2579              : 
    2580         2482 :   return decl;
    2581              : }
    2582              : 
    2583              : /* Finish a series of declarations for local labels.  G++ allows users
    2584              :    to declare "local" labels, i.e., labels with scope.  This extension
    2585              :    is useful when writing code involving statement-expressions.  */
    2586              : 
    2587              : void
    2588          219 : finish_label_decl (tree name)
    2589              : {
    2590          219 :   if (!at_function_scope_p ())
    2591              :     {
    2592            0 :       error ("%<__label__%> declarations are only allowed in function scopes");
    2593            0 :       return;
    2594              :     }
    2595              : 
    2596          219 :   add_decl_expr (declare_local_label (name));
    2597              : }
    2598              : 
    2599              : /* When DECL goes out of scope, make sure that CLEANUP is executed.  */
    2600              : 
    2601              : void
    2602      3387060 : finish_decl_cleanup (tree decl, tree cleanup)
    2603              : {
    2604      3387060 :   push_cleanup (decl, cleanup, false);
    2605      3387060 : }
    2606              : 
    2607              : /* If the current scope exits with an exception, run CLEANUP.  */
    2608              : 
    2609              : void
    2610      2163961 : finish_eh_cleanup (tree cleanup)
    2611              : {
    2612      2163961 :   push_cleanup (NULL, cleanup, true);
    2613      2163961 : }
    2614              : 
    2615              : /* The MEM_INITS is a list of mem-initializers, in reverse of the
    2616              :    order they were written by the user.  Each node is as for
    2617              :    emit_mem_initializers.  */
    2618              : 
    2619              : void
    2620     19859319 : finish_mem_initializers (tree mem_inits)
    2621              : {
    2622              :   /* Reorder the MEM_INITS so that they are in the order they appeared
    2623              :      in the source program.  */
    2624     19859319 :   mem_inits = nreverse (mem_inits);
    2625              : 
    2626     19859319 :   if (processing_template_decl)
    2627              :     {
    2628              :       tree mem;
    2629              : 
    2630     33589726 :       for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
    2631              :         {
    2632              :           /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
    2633              :              check for bare parameter packs in the TREE_VALUE, because
    2634              :              any parameter packs in the TREE_VALUE have already been
    2635              :              bound as part of the TREE_PURPOSE.  See
    2636              :              make_pack_expansion for more information.  */
    2637     19875833 :           if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
    2638     19875833 :               && check_for_bare_parameter_packs (TREE_VALUE (mem)))
    2639            3 :             TREE_VALUE (mem) = error_mark_node;
    2640              :         }
    2641              : 
    2642     13713893 :       add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
    2643              :                                   CTOR_INITIALIZER, mem_inits));
    2644              :     }
    2645              :   else
    2646      6145426 :     emit_mem_initializers (mem_inits);
    2647     19859319 : }
    2648              : 
    2649              : /* Obfuscate EXPR if it looks like an id-expression or member access so
    2650              :    that the call to finish_decltype in do_auto_deduction will give the
    2651              :    right result.  If EVEN_UNEVAL, do this even in unevaluated context.  */
    2652              : 
    2653              : tree
    2654     43602774 : force_paren_expr (tree expr, bool even_uneval /* = false */)
    2655              : {
    2656              :   /* This is only needed for decltype(auto) in C++14.  */
    2657     43602774 :   if (cxx_dialect < cxx14)
    2658              :     return expr;
    2659              : 
    2660              :   /* If we're in unevaluated context, we can't be deducing a
    2661              :      return/initializer type, so we don't need to mess with this.  */
    2662     42984112 :   if (cp_unevaluated_operand && !even_uneval)
    2663              :     return expr;
    2664              : 
    2665     35791657 :   if (TREE_CODE (expr) == COMPONENT_REF
    2666     35734587 :       || TREE_CODE (expr) == SCOPE_REF
    2667     71519799 :       || REFERENCE_REF_P (expr))
    2668       592403 :     REF_PARENTHESIZED_P (expr) = true;
    2669     35199254 :   else if (DECL_P (tree_strip_any_location_wrapper (expr)))
    2670              :     {
    2671      1695302 :       location_t loc = cp_expr_location (expr);
    2672      1695302 :       const tree_code code = processing_template_decl ? PAREN_EXPR
    2673              :                                                       : VIEW_CONVERT_EXPR;
    2674      1695302 :       expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
    2675      1695302 :       REF_PARENTHESIZED_P (expr) = true;
    2676              :     }
    2677              :   return expr;
    2678              : }
    2679              : 
    2680              : /* If T is an id-expression obfuscated by force_paren_expr, undo the
    2681              :    obfuscation and return the underlying id-expression.  Otherwise
    2682              :    return T.  */
    2683              : 
    2684              : tree
    2685    947921460 : maybe_undo_parenthesized_ref (tree t)
    2686              : {
    2687    947921460 :   if (cxx_dialect < cxx14)
    2688              :     return t;
    2689              : 
    2690    938147166 :   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
    2691   1040583460 :       && REF_PARENTHESIZED_P (t))
    2692       194594 :     t = TREE_OPERAND (t, 0);
    2693              : 
    2694              :   return t;
    2695              : }
    2696              : 
    2697              : /* Finish a parenthesized expression EXPR.  */
    2698              : 
    2699              : cp_expr
    2700     32644254 : finish_parenthesized_expr (cp_expr expr)
    2701              : {
    2702     32644254 :   if (EXPR_P (expr))
    2703              :     {
    2704              :       /* This inhibits warnings in maybe_warn_unparenthesized_assignment
    2705              :          and c_common_truthvalue_conversion.  */
    2706     65006136 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
    2707              :       /* And maybe_warn_sizeof_array_div.  */
    2708     65006136 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
    2709              :     }
    2710              : 
    2711     32644254 :   if (TREE_CODE (expr) == OFFSET_REF
    2712     32644254 :       || TREE_CODE (expr) == SCOPE_REF)
    2713              :     /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
    2714              :        enclosed in parentheses.  */
    2715        30073 :     PTRMEM_OK_P (expr) = 0;
    2716              : 
    2717     32644254 :   tree stripped_expr = tree_strip_any_location_wrapper (expr);
    2718     32644254 :   if (TREE_CODE (stripped_expr) == STRING_CST)
    2719       846710 :     PAREN_STRING_LITERAL_P (stripped_expr) = 1;
    2720     31797544 :   else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
    2721          966 :     PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
    2722              : 
    2723     32644254 :   expr = cp_expr (force_paren_expr (expr), expr.get_location ());
    2724              : 
    2725     32644254 :   return expr;
    2726              : }
    2727              : 
    2728              : /* Finish a reference to a non-static data member (DECL) that is not
    2729              :    preceded by `.' or `->'.  */
    2730              : 
    2731              : tree
    2732     74869980 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
    2733              :                                tsubst_flags_t complain /* = tf_warning_or_error */)
    2734              : {
    2735     74869980 :   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
    2736     74869980 :   bool try_omp_private = !object && omp_private_member_map;
    2737     65571713 :   tree ret;
    2738              : 
    2739     65571713 :   if (!object)
    2740              :     {
    2741     65571713 :       tree scope = qualifying_scope;
    2742     65571713 :       if (scope == NULL_TREE)
    2743              :         {
    2744     65560593 :           scope = context_for_name_lookup (decl);
    2745     65560593 :           if (!TYPE_P (scope))
    2746              :             {
    2747              :               /* Can happen during error recovery (c++/85014).  */
    2748            3 :               gcc_assert (seen_error ());
    2749            3 :               return error_mark_node;
    2750              :             }
    2751              :         }
    2752     65571710 :       object = maybe_dummy_object (scope, NULL);
    2753              :     }
    2754              : 
    2755     74869977 :   object = maybe_resolve_dummy (object, true);
    2756     74869977 :   if (object == error_mark_node)
    2757              :     return error_mark_node;
    2758              : 
    2759              :   /* DR 613/850: Can use non-static data members without an associated
    2760              :      object in sizeof/decltype/alignof.  */
    2761     74869974 :   if (is_dummy_object (object)
    2762        31702 :       && !cp_unevaluated_operand
    2763     74870073 :       && (!processing_template_decl || !current_class_ref))
    2764              :     {
    2765           84 :       if (complain & tf_error)
    2766              :         {
    2767           74 :           auto_diagnostic_group d;
    2768           74 :           if (current_function_decl
    2769           74 :               && DECL_STATIC_FUNCTION_P (current_function_decl))
    2770            3 :             error ("invalid use of member %qD in static member function", decl);
    2771           71 :           else if (current_function_decl
    2772           63 :                    && processing_contract_condition
    2773           71 :                    && DECL_CONSTRUCTOR_P (current_function_decl))
    2774            0 :             error ("invalid use of member %qD in constructor %<pre%> contract", decl);
    2775           71 :           else if (current_function_decl
    2776           63 :                    && processing_contract_condition
    2777           71 :                    && DECL_DESTRUCTOR_P (current_function_decl))
    2778            0 :             error ("invalid use of member %qD in destructor %<post%> contract", decl);
    2779              :           else
    2780           71 :             error ("invalid use of non-static data member %qD", decl);
    2781           74 :           inform (DECL_SOURCE_LOCATION (decl), "declared here");
    2782           74 :         }
    2783              : 
    2784           84 :       return error_mark_node;
    2785              :     }
    2786              : 
    2787     74869890 :   if (current_class_ptr)
    2788     74576090 :     TREE_USED (current_class_ptr) = 1;
    2789     74869890 :   if (processing_template_decl)
    2790              :     {
    2791     59807366 :       tree type = TREE_TYPE (decl);
    2792              : 
    2793     59807366 :       if (TYPE_REF_P (type))
    2794              :         /* Quals on the object don't matter.  */;
    2795     57587219 :       else if (PACK_EXPANSION_P (type))
    2796              :         /* Don't bother trying to represent this.  */
    2797              :         type = NULL_TREE;
    2798     57584747 :       else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
    2799              :         /* We don't know what the eventual quals will be, so punt until
    2800              :            instantiation time.
    2801              : 
    2802              :            This can happen when called from build_capture_proxy for an explicit
    2803              :            object lambda.  It's a bit marginal to call this function in that
    2804              :            case, since this function is for references to members of 'this',
    2805              :            but the deduced type is required to be derived from the closure
    2806              :            type, so it works.  */
    2807              :         type = NULL_TREE;
    2808              :       else
    2809              :         {
    2810              :           /* Set the cv qualifiers.  */
    2811     57582082 :           int quals = cp_type_quals (TREE_TYPE (object));
    2812              : 
    2813     57582082 :           if (DECL_MUTABLE_P (decl))
    2814       232818 :             quals &= ~TYPE_QUAL_CONST;
    2815              : 
    2816     57582082 :           quals |= cp_type_quals (TREE_TYPE (decl));
    2817     57582082 :           type = cp_build_qualified_type (type, quals);
    2818              :         }
    2819              : 
    2820     59807366 :       if (qualifying_scope)
    2821              :         /* Wrap this in a SCOPE_REF for now.  */
    2822         9141 :         ret = build_qualified_name (type, qualifying_scope, decl,
    2823              :                                     /*template_p=*/false);
    2824              :       else
    2825     59798225 :         ret = (convert_from_reference
    2826     59798225 :                (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
    2827              :     }
    2828              :   /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
    2829              :      QUALIFYING_SCOPE is also non-null.  */
    2830              :   else
    2831              :     {
    2832     15062524 :       tree access_type = TREE_TYPE (object);
    2833              : 
    2834     15062524 :       if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
    2835              :                                           decl, complain))
    2836            0 :         return error_mark_node;
    2837              : 
    2838              :       /* If the data member was named `C::M', convert `*this' to `C'
    2839              :          first.  */
    2840     15062524 :       if (qualifying_scope)
    2841              :         {
    2842         1939 :           tree binfo = NULL_TREE;
    2843         1939 :           object = build_scoped_ref (object, qualifying_scope,
    2844              :                                      &binfo);
    2845              :         }
    2846              : 
    2847     15062524 :       ret = build_class_member_access_expr (object, decl,
    2848              :                                             /*access_path=*/NULL_TREE,
    2849              :                                             /*preserve_reference=*/false,
    2850              :                                             complain);
    2851              :     }
    2852     74869890 :   if (try_omp_private)
    2853              :     {
    2854         1671 :       tree *v = omp_private_member_map->get (decl);
    2855         1671 :       if (v)
    2856         1243 :         ret = convert_from_reference (*v);
    2857              :     }
    2858              :   return ret;
    2859              : }
    2860              : 
    2861              : /* DECL was the declaration to which a qualified-id resolved.  Issue
    2862              :    an error message if it is not accessible.  If OBJECT_TYPE is
    2863              :    non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
    2864              :    type of `*x', or `x', respectively.  If the DECL was named as
    2865              :    `A::B' then NESTED_NAME_SPECIFIER is `A'.  Return value is like
    2866              :    perform_access_checks above.  */
    2867              : 
    2868              : bool
    2869   4717366236 : check_accessibility_of_qualified_id (tree decl,
    2870              :                                      tree object_type,
    2871              :                                      tree nested_name_specifier,
    2872              :                                      tsubst_flags_t complain)
    2873              : {
    2874              :   /* If we're not checking, return immediately.  */
    2875   4717366236 :   if (deferred_access_no_check)
    2876              :     return true;
    2877              : 
    2878              :   /* Determine the SCOPE of DECL.  */
    2879   4709560043 :   tree scope = context_for_name_lookup (decl);
    2880              :   /* If the SCOPE is not a type, then DECL is not a member.  */
    2881   4709560043 :   if (!TYPE_P (scope)
    2882              :       /* If SCOPE is dependent then we can't perform this access check now,
    2883              :          and since we'll perform this access check again after substitution
    2884              :          there's no need to explicitly defer it.  */
    2885   4709560043 :       || dependent_type_p (scope))
    2886   4262208663 :     return true;
    2887              : 
    2888    447351380 :   tree qualifying_type = NULL_TREE;
    2889              :   /* Compute the scope through which DECL is being accessed.  */
    2890    447351380 :   if (object_type
    2891              :       /* OBJECT_TYPE might not be a class type; consider:
    2892              : 
    2893              :            class A { typedef int I; };
    2894              :            I *p;
    2895              :            p->A::I::~I();
    2896              : 
    2897              :          In this case, we will have "A::I" as the DECL, but "I" as the
    2898              :          OBJECT_TYPE.  */
    2899        95989 :       && CLASS_TYPE_P (object_type)
    2900    447447352 :       && DERIVED_FROM_P (scope, object_type))
    2901              :     {
    2902              :       /* If we are processing a `->' or `.' expression, use the type of the
    2903              :          left-hand side.  */
    2904        95963 :       if (tree open = currently_open_class (object_type))
    2905              :         qualifying_type = open;
    2906              :       else
    2907              :         qualifying_type = object_type;
    2908              :     }
    2909    447255417 :   else if (nested_name_specifier)
    2910              :     {
    2911              :       /* If the reference is to a non-static member of the
    2912              :          current class, treat it as if it were referenced through
    2913              :          `this'.  */
    2914    590752359 :       if (DECL_NONSTATIC_MEMBER_P (decl)
    2915    295426405 :           && current_class_ptr)
    2916        39827 :         if (tree current = current_nonlambda_class_type ())
    2917              :           {
    2918        39804 :             if (dependent_type_p (current))
    2919              :             /* In general we can't know whether this access goes through
    2920              :                `this' until instantiation time.  Punt now, or else we might
    2921              :                create a deferred access check that's not relative to `this'
    2922              :                when it ought to be.  We'll check this access again after
    2923              :                substitution, e.g. from tsubst_qualified_id.  */
    2924              :               return true;
    2925              : 
    2926         3576 :             if (DERIVED_FROM_P (scope, current))
    2927              :               qualifying_type = current;
    2928              :           }
    2929              :       /* Otherwise, use the type indicated by the
    2930              :          nested-name-specifier.  */
    2931              :       if (!qualifying_type)
    2932              :         qualifying_type = nested_name_specifier;
    2933              :     }
    2934              :   else
    2935              :     /* Otherwise, the name must be from the current class or one of
    2936              :        its bases.  */
    2937    151879236 :     qualifying_type = currently_open_derived_class (scope);
    2938              : 
    2939    447255877 :   if (qualifying_type
    2940              :       /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
    2941              :          or similar in a default argument value.  */
    2942    447315152 :       && CLASS_TYPE_P (qualifying_type))
    2943    421045625 :     return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
    2944    421045625 :                                           decl, complain);
    2945              : 
    2946              :   return true;
    2947              : }
    2948              : 
    2949              : /* EXPR is the result of a qualified-id.  The QUALIFYING_CLASS was the
    2950              :    class named to the left of the "::" operator.  DONE is true if this
    2951              :    expression is a complete postfix-expression; it is false if this
    2952              :    expression is followed by '->', '[', '(', etc.  ADDRESS_P is true
    2953              :    iff this expression is the operand of '&'.  TEMPLATE_P is true iff
    2954              :    the qualified-id was of the form "A::template B".  TEMPLATE_ARG_P
    2955              :    is true iff this qualified name appears as a template argument.  */
    2956              : 
    2957              : tree
    2958     80412910 : finish_qualified_id_expr (tree qualifying_class,
    2959              :                           tree expr,
    2960              :                           bool done,
    2961              :                           bool address_p,
    2962              :                           bool template_p,
    2963              :                           bool template_arg_p,
    2964              :                           tsubst_flags_t complain)
    2965              : {
    2966     80412910 :   gcc_assert (TYPE_P (qualifying_class));
    2967              : 
    2968     80412910 :   if (error_operand_p (expr))
    2969           21 :     return error_mark_node;
    2970              : 
    2971     80412889 :   if (DECL_P (expr)
    2972              :       /* Functions are marked after overload resolution; avoid redundant
    2973              :          warnings.  */
    2974     73524401 :       && TREE_CODE (expr) != FUNCTION_DECL
    2975    153937266 :       && !mark_used (expr, complain))
    2976            0 :     return error_mark_node;
    2977              : 
    2978     80412889 :   if (template_p)
    2979              :     {
    2980       243362 :       if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
    2981              :         {
    2982              :           /* cp_parser_lookup_name thought we were looking for a type,
    2983              :              but we're actually looking for a declaration.  */
    2984            9 :           qualifying_class = TYPE_CONTEXT (expr);
    2985            9 :           expr = TYPE_IDENTIFIER (expr);
    2986              :         }
    2987              :       else
    2988       243353 :         check_template_keyword (expr);
    2989              :     }
    2990              : 
    2991              :   /* If EXPR occurs as the operand of '&', use special handling that
    2992              :      permits a pointer-to-member.  */
    2993     80412889 :   if (address_p && done
    2994       155292 :       && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
    2995              :     {
    2996       155290 :       if (TREE_CODE (expr) == SCOPE_REF)
    2997            0 :         expr = TREE_OPERAND (expr, 1);
    2998       155290 :       expr = build_offset_ref (qualifying_class, expr,
    2999              :                                /*address_p=*/true, complain);
    3000       155290 :       return expr;
    3001              :     }
    3002              : 
    3003              :   /* No need to check access within an enum.  */
    3004     80257599 :   if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
    3005      3438555 :       && TREE_CODE (expr) != IDENTIFIER_NODE)
    3006              :     return expr;
    3007              : 
    3008              :   /* Within the scope of a class, turn references to non-static
    3009              :      members into expression of the form "this->...".  */
    3010     76819047 :   if (template_arg_p)
    3011              :     /* But, within a template argument, we do not want make the
    3012              :        transformation, as there is no "this" pointer.  */
    3013              :     ;
    3014     76816407 :   else if (TREE_CODE (expr) == FIELD_DECL)
    3015              :     {
    3016        11120 :       push_deferring_access_checks (dk_no_check);
    3017        11120 :       expr = finish_non_static_data_member (expr, NULL_TREE,
    3018              :                                             qualifying_class, complain);
    3019        11120 :       pop_deferring_access_checks ();
    3020              :     }
    3021     76805287 :   else if (BASELINK_P (expr))
    3022              :     {
    3023              :       /* See if any of the functions are non-static members.  */
    3024              :       /* If so, the expression may be relative to 'this'.  */
    3025      6433715 :       if (!shared_member_p (expr)
    3026       419435 :           && current_class_ptr
    3027      6852492 :           && DERIVED_FROM_P (qualifying_class,
    3028              :                              current_nonlambda_class_type ()))
    3029       418553 :         expr = (build_class_member_access_expr
    3030       418553 :                 (maybe_dummy_object (qualifying_class, NULL),
    3031              :                  expr,
    3032       418553 :                  BASELINK_ACCESS_BINFO (expr),
    3033              :                  /*preserve_reference=*/false,
    3034              :                  complain));
    3035      6015162 :       else if (done)
    3036              :         /* The expression is a qualified name whose address is not
    3037              :            being taken.  */
    3038         2547 :         expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
    3039              :                                  complain);
    3040              :     }
    3041     70371572 :   else if (!template_p
    3042     70176120 :            && TREE_CODE (expr) == TEMPLATE_DECL
    3043     70371654 :            && !DECL_FUNCTION_TEMPLATE_P (expr))
    3044              :     {
    3045           82 :       if (complain & tf_error)
    3046            5 :         error ("%qE missing template arguments", expr);
    3047           82 :       return error_mark_node;
    3048              :     }
    3049              :   else
    3050              :     {
    3051              :       /* In a template, return a SCOPE_REF for most qualified-ids
    3052              :          so that we can check access at instantiation time.  But if
    3053              :          we're looking at a member of the current instantiation, we
    3054              :          know we have access and building up the SCOPE_REF confuses
    3055              :          non-type template argument handling.  */
    3056     70371490 :       if (processing_template_decl
    3057     70371490 :           && (!currently_open_class (qualifying_class)
    3058        10003 :               || TREE_CODE (expr) == IDENTIFIER_NODE
    3059        10003 :               || TREE_CODE (expr) == TEMPLATE_ID_EXPR
    3060           82 :               || TREE_CODE (expr) == BIT_NOT_EXPR))
    3061     10567982 :         expr = build_qualified_name (TREE_TYPE (expr),
    3062              :                                      qualifying_class, expr,
    3063              :                                      template_p);
    3064     59803508 :       else if (tree wrap = maybe_get_tls_wrapper_call (expr))
    3065            9 :         expr = wrap;
    3066              : 
    3067     70371490 :       expr = convert_from_reference (expr);
    3068              :     }
    3069              : 
    3070              :   return expr;
    3071              : }
    3072              : 
    3073              : /* Begin a statement-expression.  The value returned must be passed to
    3074              :    finish_stmt_expr.  */
    3075              : 
    3076              : tree
    3077      5231961 : begin_stmt_expr (void)
    3078              : {
    3079      5231961 :   return push_stmt_list ();
    3080              : }
    3081              : 
    3082              : /* Process the final expression of a statement expression. EXPR can be
    3083              :    NULL, if the final expression is empty.  Return a STATEMENT_LIST
    3084              :    containing all the statements in the statement-expression, or
    3085              :    ERROR_MARK_NODE if there was an error.  */
    3086              : 
    3087              : tree
    3088        28709 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
    3089              : {
    3090        28709 :   if (error_operand_p (expr))
    3091              :     {
    3092              :       /* The type of the statement-expression is the type of the last
    3093              :          expression.  */
    3094            3 :       TREE_TYPE (stmt_expr) = error_mark_node;
    3095            3 :       return error_mark_node;
    3096              :     }
    3097              : 
    3098              :   /* If the last statement does not have "void" type, then the value
    3099              :      of the last statement is the value of the entire expression.  */
    3100        28706 :   if (expr)
    3101              :     {
    3102        28691 :       tree type = TREE_TYPE (expr);
    3103              : 
    3104        28691 :       if (type && type_unknown_p (type))
    3105              :         {
    3106           15 :           error ("a statement expression is an insufficient context"
    3107              :                  " for overload resolution");
    3108           15 :           TREE_TYPE (stmt_expr) = error_mark_node;
    3109           15 :           return error_mark_node;
    3110              :         }
    3111        28676 :       else if (processing_template_decl)
    3112              :         {
    3113              :           /* Not finish_expr_stmt because we don't want convert_to_void.  */
    3114          169 :           expr = build_stmt (input_location, EXPR_STMT, expr);
    3115          169 :           expr = add_stmt (expr);
    3116              :           /* Mark the last statement so that we can recognize it as such at
    3117              :              template-instantiation time.  */
    3118          169 :           EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
    3119              :         }
    3120        28507 :       else if (VOID_TYPE_P (type))
    3121              :         {
    3122              :           /* Just treat this like an ordinary statement.  */
    3123           31 :           expr = finish_expr_stmt (expr);
    3124              :         }
    3125              :       else
    3126              :         {
    3127              :           /* It actually has a value we need to deal with.  First, force it
    3128              :              to be an rvalue so that we won't need to build up a copy
    3129              :              constructor call later when we try to assign it to something.  */
    3130        28476 :           expr = force_rvalue (expr, tf_warning_or_error);
    3131        28476 :           if (error_operand_p (expr))
    3132            0 :             return error_mark_node;
    3133              : 
    3134              :           /* Update for array-to-pointer decay.  */
    3135        28476 :           type = TREE_TYPE (expr);
    3136              : 
    3137              :           /* This TARGET_EXPR will initialize the outer one added by
    3138              :              finish_stmt_expr.  */
    3139        28476 :           set_target_expr_eliding (expr);
    3140              : 
    3141              :           /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
    3142              :              normal statement, but don't convert to void or actually add
    3143              :              the EXPR_STMT.  */
    3144        28476 :           if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    3145        28476 :             expr = maybe_cleanup_point_expr (expr);
    3146        28476 :           add_stmt (expr);
    3147              :         }
    3148              : 
    3149              :       /* The type of the statement-expression is the type of the last
    3150              :          expression.  */
    3151        28676 :       TREE_TYPE (stmt_expr) = type;
    3152              :     }
    3153              : 
    3154              :   return stmt_expr;
    3155              : }
    3156              : 
    3157              : /* Finish a statement-expression.  EXPR should be the value returned
    3158              :    by the previous begin_stmt_expr.  Returns an expression
    3159              :    representing the statement-expression.  */
    3160              : 
    3161              : tree
    3162      5231961 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
    3163              : {
    3164      5231961 :   tree type;
    3165      5231961 :   tree result;
    3166              : 
    3167      5231961 :   if (error_operand_p (stmt_expr))
    3168              :     {
    3169           18 :       pop_stmt_list (stmt_expr);
    3170           18 :       return error_mark_node;
    3171              :     }
    3172              : 
    3173      5231943 :   gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
    3174              : 
    3175      5231943 :   type = TREE_TYPE (stmt_expr);
    3176      5231943 :   result = pop_stmt_list (stmt_expr);
    3177      5231943 :   TREE_TYPE (result) = type;
    3178              : 
    3179      5231943 :   if (processing_template_decl)
    3180              :     {
    3181        36432 :       result = build_min (STMT_EXPR, type, result);
    3182        36432 :       TREE_SIDE_EFFECTS (result) = 1;
    3183        36432 :       STMT_EXPR_NO_SCOPE (result) = has_no_scope;
    3184              :     }
    3185      5195511 :   else if (CLASS_TYPE_P (type))
    3186              :     {
    3187              :       /* Wrap the statement-expression in a TARGET_EXPR so that the
    3188              :          temporary object created by the final expression is destroyed at
    3189              :          the end of the full-expression containing the
    3190              :          statement-expression.  */
    3191          118 :       result = force_target_expr (type, result, tf_warning_or_error);
    3192              :     }
    3193              : 
    3194              :   return result;
    3195              : }
    3196              : 
    3197              : /* Returns the expression which provides the value of STMT_EXPR.  */
    3198              : 
    3199              : tree
    3200          191 : stmt_expr_value_expr (tree stmt_expr)
    3201              : {
    3202          191 :   tree t = STMT_EXPR_STMT (stmt_expr);
    3203              : 
    3204          191 :   if (TREE_CODE (t) == BIND_EXPR)
    3205          191 :     t = BIND_EXPR_BODY (t);
    3206              : 
    3207          191 :   if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
    3208          158 :     t = STATEMENT_LIST_TAIL (t)->stmt;
    3209              : 
    3210          191 :   if (TREE_CODE (t) == EXPR_STMT)
    3211          173 :     t = EXPR_STMT_EXPR (t);
    3212              : 
    3213          191 :   return t;
    3214              : }
    3215              : 
    3216              : /* Return TRUE iff EXPR_STMT is an empty list of
    3217              :    expression statements.  */
    3218              : 
    3219              : bool
    3220     60106250 : empty_expr_stmt_p (tree expr_stmt)
    3221              : {
    3222     60106255 :   tree body = NULL_TREE;
    3223              : 
    3224     60106255 :   if (expr_stmt == void_node)
    3225              :     return true;
    3226              : 
    3227     60106252 :   if (expr_stmt)
    3228              :     {
    3229     60106252 :       if (TREE_CODE (expr_stmt) == EXPR_STMT)
    3230            5 :         body = EXPR_STMT_EXPR (expr_stmt);
    3231     60106247 :       else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
    3232              :         body = expr_stmt;
    3233              :     }
    3234              : 
    3235            5 :   if (body)
    3236              :     {
    3237     59204932 :       if (TREE_CODE (body) == STATEMENT_LIST)
    3238     59204927 :         return tsi_end_p (tsi_start (body));
    3239              :       else
    3240              :         return empty_expr_stmt_p (body);
    3241              :     }
    3242              :   return false;
    3243              : }
    3244              : 
    3245              : /* Perform Koenig lookup.  FN_EXPR is the postfix-expression representing
    3246              :    the function (or functions) to call; ARGS are the arguments to the
    3247              :    call.  Returns the functions to be considered by overload resolution.  */
    3248              : 
    3249              : cp_expr
    3250     18115463 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
    3251              :                        tsubst_flags_t complain)
    3252              : {
    3253     18115463 :   tree identifier = NULL_TREE;
    3254     18115463 :   tree functions = NULL_TREE;
    3255     18115463 :   tree tmpl_args = NULL_TREE;
    3256     18115463 :   bool template_id = false;
    3257     18115463 :   location_t loc = fn_expr.get_location ();
    3258     18115463 :   tree fn = fn_expr.get_value ();
    3259              : 
    3260     18115463 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3261              : 
    3262     18115463 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    3263              :     {
    3264              :       /* Use a separate flag to handle null args.  */
    3265      3494786 :       template_id = true;
    3266      3494786 :       tmpl_args = TREE_OPERAND (fn, 1);
    3267      3494786 :       fn = TREE_OPERAND (fn, 0);
    3268              :     }
    3269              : 
    3270              :   /* Find the name of the overloaded function.  */
    3271     18115463 :   if (identifier_p (fn))
    3272              :     identifier = fn;
    3273              :   else
    3274              :     {
    3275     25634749 :       functions = fn;
    3276     17930416 :       identifier = OVL_NAME (functions);
    3277              :     }
    3278              : 
    3279              :   /* A call to a namespace-scope function using an unqualified name.
    3280              : 
    3281              :      Do Koenig lookup -- unless any of the arguments are
    3282              :      type-dependent.  */
    3283     18115463 :   if (!any_type_dependent_arguments_p (args)
    3284     18115463 :       && !any_dependent_template_arguments_p (tmpl_args))
    3285              :     {
    3286     17222651 :       fn = lookup_arg_dependent (identifier, functions, args);
    3287     17222651 :       if (!fn)
    3288              :         {
    3289              :           /* The unqualified name could not be resolved.  */
    3290        56990 :           if (complain & tf_error)
    3291          391 :             fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
    3292              :           else
    3293              :             fn = identifier;
    3294              :         }
    3295              :     }
    3296              : 
    3297     18115463 :   if (fn && template_id && fn != error_mark_node)
    3298      3494773 :     fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
    3299              : 
    3300     18115463 :   return cp_expr (fn, loc);
    3301              : }
    3302              : 
    3303              : /* Generate an expression for `FN (ARGS)'.  This may change the
    3304              :    contents of ARGS.
    3305              : 
    3306              :    If DISALLOW_VIRTUAL is true, the call to FN will be not generated
    3307              :    as a virtual call, even if FN is virtual.  (This flag is set when
    3308              :    encountering an expression where the function name is explicitly
    3309              :    qualified.  For example a call to `X::f' never generates a virtual
    3310              :    call.)
    3311              : 
    3312              :    Returns code for the call.  */
    3313              : 
    3314              : tree
    3315    349319250 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
    3316              :                   bool koenig_p, tsubst_flags_t complain)
    3317              : {
    3318    349319250 :   tree result;
    3319    349319250 :   tree orig_fn;
    3320    349319250 :   vec<tree, va_gc> *orig_args = *args;
    3321    349319250 :   tsubst_flags_t orig_complain = complain;
    3322              : 
    3323    349319250 :   if (fn == error_mark_node)
    3324              :     return error_mark_node;
    3325              : 
    3326    349318199 :   complain &= ~tf_any_viable;
    3327    349318199 :   gcc_assert (!TYPE_P (fn));
    3328              : 
    3329              :   /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
    3330              :      it so that we can tell this is a call to a known function.  */
    3331    349318199 :   fn = maybe_undo_parenthesized_ref (fn);
    3332              : 
    3333    349318199 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3334              : 
    3335    349318199 :   orig_fn = fn;
    3336              : 
    3337    349318199 :   if (concept_check_p (fn))
    3338              :     {
    3339            6 :       error_at (EXPR_LOC_OR_LOC (fn, input_location),
    3340              :                 "cannot call a concept as a function");
    3341            6 :       return error_mark_node;
    3342              :     }
    3343              : 
    3344    349318193 :   if (processing_template_decl)
    3345              :     {
    3346              :       /* If FN is a local extern declaration (or set thereof) in a template,
    3347              :          look it up again at instantiation time.  */
    3348    228953932 :       if (is_overloaded_fn (fn))
    3349              :         {
    3350    140649229 :           tree ifn = get_first_fn (fn);
    3351    140649229 :           if (TREE_CODE (ifn) == FUNCTION_DECL
    3352    140649229 :               && dependent_local_decl_p (ifn))
    3353        39191 :             orig_fn = DECL_NAME (ifn);
    3354              :         }
    3355              : 
    3356              :       /* If the call expression is dependent, build a CALL_EXPR node
    3357              :          with no type; type_dependent_expression_p recognizes
    3358              :          expressions with no type as being dependent.  */
    3359    228953932 :       if (type_dependent_expression_p (fn)
    3360    228953932 :           || any_type_dependent_arguments_p (*args))
    3361              :         {
    3362    207587592 :           if (koenig_p
    3363     10219914 :               && TREE_CODE (orig_fn) == FUNCTION_DECL
    3364    210733960 :               && !fndecl_built_in_p (orig_fn))
    3365              :             /* For an ADL-enabled call where unqualified lookup found a
    3366              :                single non-template function, wrap it in an OVERLOAD so that
    3367              :                later substitution doesn't overeagerly mark the function as
    3368              :                used.  */
    3369       833388 :             orig_fn = ovl_make (orig_fn, NULL_TREE);
    3370    207587592 :           result = build_min_nt_call_vec (orig_fn, *args);
    3371    282064203 :           SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
    3372    207587592 :           KOENIG_LOOKUP_P (result) = koenig_p;
    3373              :           /* Disable the std::move warnings since this call was dependent
    3374              :              (c++/89780, c++/107363).  This also suppresses the
    3375              :              -Wredundant-move warning.  */
    3376    207587592 :           suppress_warning (result, OPT_Wpessimizing_move);
    3377              : 
    3378    207587592 :           if (cfun && cp_function_chain && !cp_unevaluated_operand)
    3379              :             {
    3380    180824990 :               bool abnormal = true;
    3381    181091196 :               for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
    3382              :                 {
    3383    100440016 :                   tree fndecl = STRIP_TEMPLATE (*iter);
    3384    100440016 :                   if (TREE_CODE (fndecl) != FUNCTION_DECL
    3385    100439938 :                       || !TREE_THIS_VOLATILE (fndecl))
    3386              :                     {
    3387              :                       abnormal = false;
    3388              :                       break;
    3389              :                     }
    3390              :                 }
    3391              :               /* FIXME: Stop warning about falling off end of non-void
    3392              :                  function.   But this is wrong.  Even if we only see
    3393              :                  no-return fns at this point, we could select a
    3394              :                  future-defined return fn during instantiation.  Or
    3395              :                  vice-versa.  */
    3396    180824990 :               if (abnormal)
    3397     80651180 :                 current_function_returns_abnormally = 1;
    3398              :             }
    3399    207587592 :           if (TREE_CODE (fn) == COMPONENT_REF)
    3400     96187047 :             maybe_generic_this_capture (TREE_OPERAND (fn, 0),
    3401     96187047 :                                         TREE_OPERAND (fn, 1));
    3402    207587592 :           return result;
    3403              :         }
    3404     21366340 :       orig_args = make_tree_vector_copy (*args);
    3405              :     }
    3406              : 
    3407    141730601 :   if (TREE_CODE (fn) == COMPONENT_REF)
    3408              :     {
    3409     28041072 :       tree member = TREE_OPERAND (fn, 1);
    3410     28041072 :       if (BASELINK_P (member))
    3411              :         {
    3412     27861025 :           tree object = TREE_OPERAND (fn, 0);
    3413     55337614 :           return build_new_method_call (object, member,
    3414              :                                         args, NULL_TREE,
    3415              :                                         (disallow_virtual
    3416              :                                          ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
    3417              :                                          : LOOKUP_NORMAL),
    3418              :                                         /*fn_p=*/NULL,
    3419     27861025 :                                         complain);
    3420              :         }
    3421              :     }
    3422              : 
    3423              :   /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'.  */
    3424    113869576 :   if (TREE_CODE (fn) == ADDR_EXPR
    3425    113869576 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
    3426            9 :     fn = TREE_OPERAND (fn, 0);
    3427              : 
    3428    113869576 :   if (is_overloaded_fn (fn))
    3429    105806537 :     fn = baselink_for_fns (fn);
    3430              : 
    3431    113869576 :   result = NULL_TREE;
    3432    113869576 :   if (BASELINK_P (fn))
    3433              :     {
    3434     13533766 :       tree object;
    3435              : 
    3436              :       /* A call to a member function.  From [over.call.func]:
    3437              : 
    3438              :            If the keyword this is in scope and refers to the class of
    3439              :            that member function, or a derived class thereof, then the
    3440              :            function call is transformed into a qualified function call
    3441              :            using (*this) as the postfix-expression to the left of the
    3442              :            . operator.... [Otherwise] a contrived object of type T
    3443              :            becomes the implied object argument.
    3444              : 
    3445              :         In this situation:
    3446              : 
    3447              :           struct A { void f(); };
    3448              :           struct B : public A {};
    3449              :           struct C : public A { void g() { B::f(); }};
    3450              : 
    3451              :         "the class of that member function" refers to `A'.  But 11.2
    3452              :         [class.access.base] says that we need to convert 'this' to B* as
    3453              :         part of the access, so we pass 'B' to maybe_dummy_object.  */
    3454              : 
    3455     13533766 :       if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
    3456              :         {
    3457              :           /* A constructor call always uses a dummy object.  (This constructor
    3458              :              call which has the form A::A () is actually invalid and we are
    3459              :              going to reject it later in build_new_method_call.)  */
    3460           39 :           object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
    3461              :         }
    3462              :       else
    3463     13533727 :         object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
    3464              :                                      NULL);
    3465              : 
    3466     15446241 :       result = build_new_method_call (object, fn, args, NULL_TREE,
    3467              :                                       (disallow_virtual
    3468              :                                        ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
    3469              :                                        : LOOKUP_NORMAL),
    3470              :                                       /*fn_p=*/NULL,
    3471              :                                       complain);
    3472              :     }
    3473    100335810 :   else if (is_overloaded_fn (fn))
    3474              :     {
    3475              :       /* If the function is an overloaded builtin, resolve it.  */
    3476     92272771 :       if (TREE_CODE (fn) == FUNCTION_DECL
    3477     92272771 :           && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
    3478     18122090 :               || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
    3479      9001796 :         result = resolve_overloaded_builtin (input_location, fn, *args,
    3480              :                                              complain & tf_error);
    3481              : 
    3482      9001796 :       if (!result)
    3483              :         {
    3484     91939930 :           tree alloc_size_attr = NULL_TREE;
    3485     91939930 :           if (warn_calloc_transposed_args
    3486       696617 :               && TREE_CODE (fn) == FUNCTION_DECL
    3487     91939930 :               && (alloc_size_attr
    3488       430877 :                   = lookup_attribute ("alloc_size",
    3489       430877 :                                       TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
    3490         3405 :             if (TREE_VALUE (alloc_size_attr) == NULL_TREE
    3491         3405 :                 || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
    3492              :               alloc_size_attr = NULL_TREE;
    3493     90241364 :           if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
    3494      1698626 :               && (complain & tf_warning)
    3495      1493447 :               && !vec_safe_is_empty (*args)
    3496     93088961 :               && !processing_template_decl)
    3497              :             {
    3498              :               location_t sizeof_arg_loc[6];
    3499              :               tree sizeof_arg[6];
    3500              :               unsigned int i;
    3501      8243324 :               for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
    3502              :                 {
    3503      3091449 :                   tree t;
    3504              : 
    3505      3091449 :                   sizeof_arg_loc[i] = UNKNOWN_LOCATION;
    3506      3091449 :                   sizeof_arg[i] = NULL_TREE;
    3507      3091449 :                   if (i >= (*args)->length ())
    3508       650841 :                     continue;
    3509      2440608 :                   t = (**args)[i];
    3510      2440608 :                   if (TREE_CODE (t) != SIZEOF_EXPR)
    3511      2433959 :                     continue;
    3512         6649 :                   if (SIZEOF_EXPR_TYPE_P (t))
    3513         2653 :                     sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
    3514              :                   else
    3515         3996 :                     sizeof_arg[i] = TREE_OPERAND (t, 0);
    3516         6649 :                   sizeof_arg_loc[i] = EXPR_LOCATION (t);
    3517              :                 }
    3518      1030423 :               if (warn_sizeof_pointer_memaccess)
    3519              :                 {
    3520      1030363 :                   auto same_p = same_type_ignoring_top_level_qualifiers_p;
    3521      1030363 :                   sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
    3522              :                                                     sizeof_arg, same_p);
    3523              :                 }
    3524      1030423 :               if (alloc_size_attr)
    3525           60 :                 warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
    3526              :                                  alloc_size_attr);
    3527              :             }
    3528              : 
    3529     91939930 :           if ((complain & tf_warning)
    3530     53074415 :               && TREE_CODE (fn) == FUNCTION_DECL
    3531     25424071 :               && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
    3532       135362 :               && vec_safe_length (*args) == 3
    3533     92075292 :               && !any_type_dependent_arguments_p (*args))
    3534              :             {
    3535       135362 :               tree arg0 = (*orig_args)[0];
    3536       135362 :               tree arg1 = (*orig_args)[1];
    3537       135362 :               tree arg2 = (*orig_args)[2];
    3538       135362 :               int literal_mask = ((literal_integer_zerop (arg1) << 1)
    3539       135362 :                                   | (literal_integer_zerop (arg2) << 2));
    3540       135362 :               warn_for_memset (input_location, arg0, arg2, literal_mask);
    3541              :             }
    3542              : 
    3543              :           /* A call to a namespace-scope function.  */
    3544     91939930 :           result = build_new_function_call (fn, args, orig_complain);
    3545              :         }
    3546              :     }
    3547      8063039 :   else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
    3548              :     {
    3549       152446 :       if (!vec_safe_is_empty (*args))
    3550            0 :         error ("arguments to destructor are not allowed");
    3551              :       /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
    3552              :          which case the postfix-expression is a possibly-parenthesized class
    3553              :          member access), the function call destroys the object of scalar type
    3554              :          denoted by the object expression of the class member access.  */
    3555       152446 :       tree ob = TREE_OPERAND (fn, 0);
    3556       152446 :       if (obvalue_p (ob))
    3557       152428 :         result = build_trivial_dtor_call (ob, true);
    3558              :       else
    3559              :         /* No location to clobber.  */
    3560           18 :         result = convert_to_void (ob, ICV_STATEMENT, complain);
    3561              :     }
    3562      7910593 :   else if (CLASS_TYPE_P (TREE_TYPE (fn)))
    3563              :     /* If the "function" is really an object of class type, it might
    3564              :        have an overloaded `operator ()'.  */
    3565      2236939 :     result = build_op_call (fn, args, complain);
    3566              : 
    3567    107849563 :   if (!result)
    3568              :     /* A call where the function is unknown.  */
    3569      5673654 :     result = cp_build_function_call_vec (fn, args, complain);
    3570              : 
    3571    113856058 :   if (processing_template_decl && result != error_mark_node)
    3572              :     {
    3573     15970510 :       if (INDIRECT_REF_P (result))
    3574      1093123 :         result = TREE_OPERAND (result, 0);
    3575              : 
    3576              :       /* Prune all but the selected function from the original overload
    3577              :          set so that we can avoid some duplicate work at instantiation time.  */
    3578     15970510 :       if (TREE_CODE (result) == CALL_EXPR
    3579     15961128 :           && really_overloaded_fn (orig_fn))
    3580              :         {
    3581      5916582 :           tree sel_fn = CALL_EXPR_FN (result);
    3582      5916582 :           if (TREE_CODE (sel_fn) == COMPONENT_REF)
    3583              :             {
    3584              :               /* The non-dependent result of build_new_method_call.  */
    3585       248898 :               sel_fn = TREE_OPERAND (sel_fn, 1);
    3586       248898 :               gcc_assert (BASELINK_P (sel_fn));
    3587              :             }
    3588      5667684 :           else if (TREE_CODE (sel_fn) == ADDR_EXPR)
    3589              :             /* Our original callee wasn't wrapped in an ADDR_EXPR,
    3590              :                so strip this ADDR_EXPR added by build_over_call.  */
    3591      5667684 :             sel_fn = TREE_OPERAND (sel_fn, 0);
    3592              :           orig_fn = sel_fn;
    3593              :         }
    3594              : 
    3595     15970510 :       tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
    3596     15970510 :       SET_EXPR_LOCATION (r, input_location);
    3597     15970510 :       KOENIG_LOOKUP_P (r) = koenig_p;
    3598     15970510 :       TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
    3599     15970510 :       release_tree_vector (orig_args);
    3600     15970510 :       result = convert_from_reference (r);
    3601              :     }
    3602              : 
    3603              :   return result;
    3604              : }
    3605              : 
    3606              : /* Finish a call to a postfix increment or decrement or EXPR.  (Which
    3607              :    is indicated by CODE, which should be POSTINCREMENT_EXPR or
    3608              :    POSTDECREMENT_EXPR.)  */
    3609              : 
    3610              : cp_expr
    3611      2569264 : finish_increment_expr (cp_expr expr, enum tree_code code)
    3612              : {
    3613              :   /* input_location holds the location of the trailing operator token.
    3614              :      Build a location of the form:
    3615              :        expr++
    3616              :        ~~~~^~
    3617              :      with the caret at the operator token, ranging from the start
    3618              :      of EXPR to the end of the operator token.  */
    3619      2569264 :   location_t combined_loc = make_location (input_location,
    3620              :                                            expr.get_start (),
    3621              :                                            get_finish (input_location));
    3622      2569264 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3623      2569264 :                                      NULL_TREE, tf_warning_or_error);
    3624              :   /* TODO: build_x_unary_op doesn't honor the location, so set it here.  */
    3625      2569264 :   result.set_location (combined_loc);
    3626      2569264 :   return result;
    3627              : }
    3628              : 
    3629              : /* Finish a use of `this'.  Returns an expression for `this'.  */
    3630              : 
    3631              : tree
    3632     35023436 : finish_this_expr (void)
    3633              : {
    3634     35023436 :   tree result = NULL_TREE;
    3635              : 
    3636     70046748 :   if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
    3637     34746806 :     result = current_class_ptr;
    3638       553244 :   else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
    3639       276554 :     result = (lambda_expr_this_capture
    3640       276554 :               (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
    3641              :   else
    3642           76 :     gcc_checking_assert (!current_class_ptr);
    3643              : 
    3644     35023360 :   if (result)
    3645              :     /* The keyword 'this' is a prvalue expression.  */
    3646     35023357 :     return rvalue (result);
    3647              : 
    3648           79 :   tree fn = current_nonlambda_function ();
    3649           79 :   if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3650              :     {
    3651            6 :       auto_diagnostic_group d;
    3652            6 :       error ("%<this%> is unavailable for explicit object member "
    3653              :              "functions");
    3654            6 :       tree xobj_parm = DECL_ARGUMENTS (fn);
    3655            6 :       gcc_assert (xobj_parm);
    3656            6 :       tree parm_name = DECL_NAME (xobj_parm);
    3657              : 
    3658            6 :       static tree remembered_fn = NULL_TREE;
    3659              :       /* Only output this diagnostic once per function.  */
    3660            6 :       if (remembered_fn == fn)
    3661              :         /* Early escape.  */;
    3662            6 :       else if (parm_name)
    3663            6 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3664              :                 "use explicit object parameter %qs instead",
    3665            3 :                 IDENTIFIER_POINTER (parm_name));
    3666              :       else
    3667            3 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3668              :                 "name the explicit object parameter");
    3669              : 
    3670            6 :       remembered_fn = fn;
    3671            6 :     }
    3672           73 :   else if (fn && DECL_STATIC_FUNCTION_P (fn))
    3673            3 :     error ("%<this%> is unavailable for static member functions");
    3674           70 :   else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
    3675            0 :     error ("invalid use of %<this%> in a constructor %<pre%> condition");
    3676           70 :   else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
    3677            0 :     error ("invalid use of %<this%> in a destructor %<post%> condition");
    3678           70 :   else if (fn)
    3679           22 :     error ("invalid use of %<this%> in non-member function");
    3680              :   else
    3681           48 :     error ("invalid use of %<this%> at top level");
    3682           79 :   return error_mark_node;
    3683              : }
    3684              : 
    3685              : /* Finish a pseudo-destructor expression.  If SCOPE is NULL, the
    3686              :    expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
    3687              :    the TYPE for the type given.  If SCOPE is non-NULL, the expression
    3688              :    was of the form `OBJECT.SCOPE::~DESTRUCTOR'.  */
    3689              : 
    3690              : tree
    3691       152497 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
    3692              :                                location_t loc, tsubst_flags_t complain)
    3693              : {
    3694       152497 :   if (object == error_mark_node || destructor == error_mark_node)
    3695              :     return error_mark_node;
    3696              : 
    3697       152488 :   gcc_assert (TYPE_P (destructor));
    3698              : 
    3699       152488 :   if (!processing_template_decl)
    3700              :     {
    3701       152467 :       if (scope == error_mark_node)
    3702              :         {
    3703            0 :           if (complain & tf_error)
    3704            0 :             error_at (loc, "invalid qualifying scope in pseudo-destructor name");
    3705            0 :           return error_mark_node;
    3706              :         }
    3707       152467 :       if (is_auto (destructor))
    3708            3 :         destructor = TREE_TYPE (object);
    3709       152467 :       if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
    3710              :         {
    3711            3 :           if (complain & tf_error)
    3712            3 :             error_at (loc,
    3713              :                       "qualified type %qT does not match destructor name ~%qT",
    3714              :                       scope, destructor);
    3715            3 :           return error_mark_node;
    3716              :         }
    3717              : 
    3718              : 
    3719              :       /* [expr.pseudo] says both:
    3720              : 
    3721              :            The type designated by the pseudo-destructor-name shall be
    3722              :            the same as the object type.
    3723              : 
    3724              :          and:
    3725              : 
    3726              :            The cv-unqualified versions of the object type and of the
    3727              :            type designated by the pseudo-destructor-name shall be the
    3728              :            same type.
    3729              : 
    3730              :          We implement the more generous second sentence, since that is
    3731              :          what most other compilers do.  */
    3732       152464 :       if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
    3733              :                                                       destructor))
    3734              :         {
    3735           12 :           if (complain & tf_error)
    3736            9 :             error_at (loc, "%qE is not of type %qT", object, destructor);
    3737           12 :           return error_mark_node;
    3738              :         }
    3739              :     }
    3740              : 
    3741       152473 :   tree type = (type_dependent_expression_p (object)
    3742       152473 :                ? NULL_TREE : void_type_node);
    3743              : 
    3744       152473 :   return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
    3745       152473 :                      scope, destructor);
    3746              : }
    3747              : 
    3748              : /* Finish an expression of the form CODE EXPR.  */
    3749              : 
    3750              : cp_expr
    3751     37362346 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
    3752              :                       tsubst_flags_t complain)
    3753              : {
    3754              :   /* Build a location of the form:
    3755              :        ++expr
    3756              :        ^~~~~~
    3757              :      with the caret at the operator token, ranging from the start
    3758              :      of the operator token to the end of EXPR.  */
    3759     37362346 :   location_t combined_loc = make_location (op_loc,
    3760              :                                            op_loc, expr.get_finish ());
    3761     37362346 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3762     37362346 :                                      NULL_TREE, complain);
    3763              :   /* TODO: build_x_unary_op doesn't always honor the location.  */
    3764     37362346 :   result.set_location (combined_loc);
    3765              : 
    3766     37362346 :   if (result == error_mark_node)
    3767              :     return result;
    3768              : 
    3769     37361861 :   if (!(complain & tf_warning))
    3770              :     return result;
    3771              : 
    3772              :   /* These will never fold into a constant, so no need to check for
    3773              :      overflow for them.  */
    3774     37361861 :   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
    3775              :     return result;
    3776              : 
    3777     20146922 :   tree result_ovl = result;
    3778     20146922 :   tree expr_ovl = expr;
    3779              : 
    3780     20146922 :   if (!processing_template_decl)
    3781      1781756 :     expr_ovl = cp_fully_fold (expr_ovl);
    3782              : 
    3783     20146922 :   if (!CONSTANT_CLASS_P (expr_ovl)
    3784     20146922 :       || TREE_OVERFLOW_P (expr_ovl))
    3785              :     return result;
    3786              : 
    3787       248385 :   if (!processing_template_decl)
    3788       239307 :     result_ovl = cp_fully_fold (result_ovl);
    3789              : 
    3790       248385 :   if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
    3791            9 :     overflow_warning (combined_loc, result_ovl);
    3792              : 
    3793              :   return result;
    3794              : }
    3795              : 
    3796              : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
    3797              :    elements.  */
    3798              : 
    3799              : static bool
    3800           12 : maybe_zero_constructor_nelts (tree expr)
    3801              : {
    3802           12 :   if (CONSTRUCTOR_NELTS (expr) == 0)
    3803              :     return true;
    3804           12 :   if (!processing_template_decl)
    3805              :     return false;
    3806           30 :   for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
    3807           21 :     if (!PACK_EXPANSION_P (elt.value))
    3808              :       return false;
    3809              :   return true;
    3810              : }
    3811              : 
    3812              : /* Finish a compound-literal expression or C++11 functional cast with aggregate
    3813              :    initializer.  TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
    3814              :    is being cast.  */
    3815              : 
    3816              : tree
    3817      9424050 : finish_compound_literal (tree type, tree compound_literal,
    3818              :                          tsubst_flags_t complain,
    3819              :                          fcl_t fcl_context)
    3820              : {
    3821      9424050 :   if (type == error_mark_node)
    3822              :     return error_mark_node;
    3823              : 
    3824      9423998 :   if (TYPE_REF_P (type))
    3825              :     {
    3826           12 :       compound_literal
    3827           12 :         = finish_compound_literal (TREE_TYPE (type), compound_literal,
    3828              :                                    complain, fcl_context);
    3829              :       /* The prvalue is then used to direct-initialize the reference.  */
    3830           12 :       tree r = (perform_implicit_conversion_flags
    3831           12 :                 (type, compound_literal, complain, LOOKUP_NORMAL));
    3832           12 :       return convert_from_reference (r);
    3833              :     }
    3834              : 
    3835      9423986 :   if (!TYPE_OBJ_P (type))
    3836              :     {
    3837              :       /* DR2351 */
    3838           60 :       if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
    3839              :         {
    3840           12 :           if (!processing_template_decl)
    3841            9 :             return void_node;
    3842            3 :           TREE_TYPE (compound_literal) = type;
    3843            3 :           TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
    3844            3 :           CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
    3845            3 :           return compound_literal;
    3846              :         }
    3847           21 :       else if (VOID_TYPE_P (type)
    3848           15 :                && processing_template_decl
    3849           33 :                && maybe_zero_constructor_nelts (compound_literal))
    3850              :         /* If there are only packs in compound_literal, it could
    3851              :            be void{} after pack expansion.  */;
    3852              :       else
    3853              :         {
    3854           12 :           if (complain & tf_error)
    3855            9 :             error ("compound literal of non-object type %qT", type);
    3856           12 :           return error_mark_node;
    3857              :         }
    3858              :     }
    3859              : 
    3860      9423962 :   if (template_placeholder_p (type))
    3861              :     {
    3862       178968 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3863              :                                 adc_variable_type);
    3864       178968 :       if (type == error_mark_node)
    3865              :         return error_mark_node;
    3866              :     }
    3867              :   /* C++23 auto{x}.  */
    3868      9244994 :   else if (is_auto (type)
    3869          162 :            && !AUTO_IS_DECLTYPE (type)
    3870      9245153 :            && CONSTRUCTOR_NELTS (compound_literal) == 1)
    3871              :     {
    3872          150 :       if (is_constrained_auto (type))
    3873              :         {
    3874            3 :           if (complain & tf_error)
    3875            3 :             error ("%<auto{x}%> cannot be constrained");
    3876            3 :           return error_mark_node;
    3877              :         }
    3878          147 :       else if (cxx_dialect < cxx23)
    3879              :         {
    3880            1 :           if ((complain & tf_warning_or_error) == 0)
    3881            0 :             return error_mark_node;
    3882            1 :           pedwarn (input_location, OPT_Wc__23_extensions,
    3883              :                    "%<auto{x}%> only available with "
    3884              :                    "%<-std=c++23%> or %<-std=gnu++23%>");
    3885              :         }
    3886          147 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3887              :                                 adc_variable_type);
    3888          147 :       if (type == error_mark_node)
    3889              :         return error_mark_node;
    3890              :     }
    3891              : 
    3892              :   /* Used to hold a copy of the compound literal in a template.  */
    3893      9423817 :   tree orig_cl = NULL_TREE;
    3894              : 
    3895      9423817 :   if (processing_template_decl)
    3896              :     {
    3897      4958028 :       const bool dependent_p
    3898      4958028 :         = (instantiation_dependent_expression_p (compound_literal)
    3899      4958028 :            || dependent_type_p (type));
    3900      1640303 :       if (dependent_p)
    3901              :         /* We're about to return, no need to copy.  */
    3902              :         orig_cl = compound_literal;
    3903              :       else
    3904              :         /* We're going to need a copy.  */
    3905      1640303 :         orig_cl = unshare_constructor (compound_literal);
    3906      4958028 :       TREE_TYPE (orig_cl) = type;
    3907              :       /* Mark the expression as a compound literal.  */
    3908      4958028 :       TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
    3909              :       /* And as instantiation-dependent.  */
    3910      4958028 :       CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
    3911      4958028 :       if (fcl_context == fcl_c99)
    3912          130 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
    3913              :       /* If the compound literal is dependent, we're done for now.  */
    3914      4958028 :       if (dependent_p)
    3915              :         return orig_cl;
    3916              :       /* Otherwise, do go on to e.g. check narrowing.  */
    3917              :     }
    3918              : 
    3919      6106092 :   type = complete_type (type);
    3920              : 
    3921      6106092 :   if (TYPE_NON_AGGREGATE_CLASS (type))
    3922              :     {
    3923              :       /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
    3924              :          everywhere that deals with function arguments would be a pain, so
    3925              :          just wrap it in a TREE_LIST.  The parser set a flag so we know
    3926              :          that it came from T{} rather than T({}).  */
    3927      1037687 :       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
    3928      1037687 :       compound_literal = build_tree_list (NULL_TREE, compound_literal);
    3929      1037687 :       return build_functional_cast (input_location, type,
    3930      1037687 :                                     compound_literal, complain);
    3931              :     }
    3932              : 
    3933      5068405 :   if (TREE_CODE (type) == ARRAY_TYPE
    3934      5068405 :       && check_array_initializer (NULL_TREE, type, compound_literal))
    3935            9 :     return error_mark_node;
    3936      5068396 :   compound_literal = reshape_init (type, compound_literal, complain);
    3937      4871464 :   if (SCALAR_TYPE_P (type)
    3938       700525 :       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
    3939      5277166 :       && !check_narrowing (type, compound_literal, complain))
    3940          129 :     return error_mark_node;
    3941      5068267 :   if (TREE_CODE (type) == ARRAY_TYPE
    3942      5068267 :       && TYPE_DOMAIN (type) == NULL_TREE)
    3943              :     {
    3944         1245 :       cp_complete_array_type_or_error (&type, compound_literal,
    3945              :                                        false, complain);
    3946         1245 :       if (type == error_mark_node)
    3947              :         return error_mark_node;
    3948              :     }
    3949      5068264 :   compound_literal = digest_init_flags (type, compound_literal,
    3950              :                                         LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
    3951              :                                         complain);
    3952      5068264 :   if (compound_literal == error_mark_node)
    3953              :     return error_mark_node;
    3954              : 
    3955              :   /* If we're in a template, return the original compound literal.  */
    3956      5067657 :   if (orig_cl)
    3957              :     return orig_cl;
    3958              : 
    3959      3519699 :   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    3960              :     {
    3961      2873107 :       TREE_HAS_CONSTRUCTOR (compound_literal) = true;
    3962      2873107 :       if (fcl_context == fcl_c99)
    3963        38263 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
    3964              :     }
    3965              : 
    3966              :   /* Put static/constant array temporaries in static variables.  */
    3967              :   /* FIXME all C99 compound literals should be variables rather than C++
    3968              :      temporaries, unless they are used as an aggregate initializer.  */
    3969      4613815 :   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
    3970      2433515 :       && fcl_context == fcl_c99
    3971           83 :       && TREE_CODE (type) == ARRAY_TYPE
    3972           31 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    3973      3519730 :       && initializer_constant_valid_p (compound_literal, type))
    3974              :     {
    3975           31 :       tree decl = create_temporary_var (type);
    3976           31 :       DECL_CONTEXT (decl) = NULL_TREE;
    3977           31 :       DECL_INITIAL (decl) = compound_literal;
    3978           31 :       TREE_STATIC (decl) = 1;
    3979           31 :       if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
    3980              :         {
    3981              :           /* 5.19 says that a constant expression can include an
    3982              :              lvalue-rvalue conversion applied to "a glvalue of literal type
    3983              :              that refers to a non-volatile temporary object initialized
    3984              :              with a constant expression".  Rather than try to communicate
    3985              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
    3986           24 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3987           24 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    3988           24 :           TREE_CONSTANT (decl) = true;
    3989              :         }
    3990           31 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    3991           31 :       decl = pushdecl_top_level (decl);
    3992           31 :       DECL_NAME (decl) = make_anon_name ();
    3993           31 :       SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
    3994              :       /* Make sure the destructor is callable.  */
    3995           31 :       tree clean = cxx_maybe_build_cleanup (decl, complain);
    3996           31 :       if (clean == error_mark_node)
    3997              :         return error_mark_node;
    3998           31 :       return decl;
    3999              :     }
    4000              : 
    4001              :   /* Represent other compound literals with TARGET_EXPR so we produce
    4002              :      a prvalue, and can elide copies.  */
    4003      3519668 :   if (!VECTOR_TYPE_P (type)
    4004      3480963 :       && (TREE_CODE (compound_literal) == CONSTRUCTOR
    4005       646586 :           || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
    4006              :     {
    4007              :       /* The CONSTRUCTOR is now an initializer, not a compound literal.  */
    4008      2834377 :       if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    4009      2834377 :         TREE_HAS_CONSTRUCTOR (compound_literal) = false;
    4010      2834377 :       compound_literal = get_target_expr (compound_literal, complain);
    4011              :     }
    4012              :   else
    4013              :     /* For e.g. int{42} just make sure it's a prvalue.  */
    4014       685291 :     compound_literal = rvalue (compound_literal);
    4015              : 
    4016              :   return compound_literal;
    4017              : }
    4018              : 
    4019              : /* Return the declaration for the function-name variable indicated by
    4020              :    ID.  */
    4021              : 
    4022              : tree
    4023       284190 : finish_fname (tree id)
    4024              : {
    4025       284190 :   tree decl = fname_decl (input_location, C_RID_CODE (id), id);
    4026              :   /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
    4027              :      of a consteval-block-declaration, a variable __func__ is implicitly
    4028              :      defined...".  We could be in a consteval block in a function, though,
    4029              :      and then we shouldn't warn.  */
    4030       284190 :   if (current_function_decl
    4031       284190 :       && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
    4032            8 :     pedwarn (input_location, 0, "%qD is not defined outside of function scope",
    4033              :              decl);
    4034       284190 :   if (processing_template_decl && current_function_decl
    4035       209962 :       && decl != error_mark_node)
    4036       209962 :     decl = DECL_NAME (decl);
    4037       284190 :   return decl;
    4038              : }
    4039              : 
    4040              : /* Finish a translation unit.  */
    4041              : 
    4042              : void
    4043        98183 : finish_translation_unit (void)
    4044              : {
    4045              :   /* In case there were missing closebraces,
    4046              :      get us back to the global binding level.  */
    4047        98183 :   pop_everything ();
    4048       196366 :   while (current_namespace != global_namespace)
    4049            0 :     pop_namespace ();
    4050              : 
    4051              :   /* Do file scope __FUNCTION__ et al.  */
    4052        98183 :   finish_fname_decls ();
    4053              : 
    4054        98183 :   if (vec_safe_length (scope_chain->omp_declare_target_attribute))
    4055              :     {
    4056           12 :       cp_omp_declare_target_attr
    4057           12 :         a = scope_chain->omp_declare_target_attribute->pop ();
    4058           12 :       if (!errorcount)
    4059            9 :         error ("%qs without corresponding %qs",
    4060              :                a.device_type >= 0 ? "#pragma omp begin declare target"
    4061              :                                   : "#pragma omp declare target",
    4062              :                "#pragma omp end declare target");
    4063           24 :       vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
    4064              :     }
    4065        98183 :   if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
    4066              :     {
    4067            0 :       if (!errorcount)
    4068            0 :         error ("%<omp begin declare variant%> without corresponding "
    4069              :                "%<omp end declare variant%>");
    4070            0 :       vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
    4071              :     }
    4072        98183 :   if (vec_safe_length (scope_chain->omp_begin_assumes))
    4073              :     {
    4074            3 :       if (!errorcount)
    4075            3 :         error ("%qs without corresponding %qs",
    4076              :                "#pragma omp begin assumes", "#pragma omp end assumes");
    4077            3 :       vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
    4078              :     }
    4079        98183 : }
    4080              : 
    4081              : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
    4082              :    Returns the parameter.  */
    4083              : 
    4084              : tree
    4085    156311882 : finish_template_type_parm (tree aggr, tree identifier)
    4086              : {
    4087    156311882 :   if (aggr != class_type_node)
    4088              :     {
    4089            0 :       permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
    4090            0 :       aggr = class_type_node;
    4091              :     }
    4092              : 
    4093    156311882 :   return build_tree_list (aggr, identifier);
    4094              : }
    4095              : 
    4096              : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
    4097              :    Returns the parameter.  */
    4098              : 
    4099              : tree
    4100       396108 : finish_template_template_parm (tree aggr, tree identifier)
    4101              : {
    4102       396108 :   tree decl = build_decl (input_location,
    4103              :                           TYPE_DECL, identifier, NULL_TREE);
    4104              : 
    4105       396108 :   tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
    4106       396108 :   DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
    4107       396108 :   DECL_TEMPLATE_RESULT (tmpl) = decl;
    4108       396108 :   DECL_ARTIFICIAL (decl) = 1;
    4109              : 
    4110              :   /* Associate the constraints with the underlying declaration,
    4111              :      not the template.  */
    4112       396108 :   tree constr = current_template_constraints ();
    4113       396108 :   set_constraints (decl, constr);
    4114              : 
    4115       396108 :   end_template_decl ();
    4116              : 
    4117       396108 :   gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
    4118              : 
    4119       396108 :   check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
    4120              :                            /*is_primary=*/true, /*is_partial=*/false,
    4121              :                            /*is_friend=*/0);
    4122              : 
    4123       396108 :   return finish_template_type_parm (aggr, tmpl);
    4124              : }
    4125              : 
    4126              : /* ARGUMENT is the default-argument value for a template template
    4127              :    parameter.  If ARGUMENT is invalid, issue error messages and return
    4128              :    the ERROR_MARK_NODE.  Otherwise, ARGUMENT itself is returned.  */
    4129              : 
    4130              : tree
    4131          849 : check_template_template_default_arg (tree argument)
    4132              : {
    4133          849 :   if (TREE_CODE (argument) != TEMPLATE_DECL
    4134              :       && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
    4135              :       && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
    4136              :     {
    4137              :       if (TREE_CODE (argument) == TYPE_DECL)
    4138              :         {
    4139           18 :           if (tree t = maybe_get_template_decl_from_type_decl (argument))
    4140           18 :             if (TREE_CODE (t) == TEMPLATE_DECL)
    4141              :               return t;
    4142           15 :           error ("invalid use of type %qT as a default value for a template "
    4143           15 :                  "template-parameter", TREE_TYPE (argument));
    4144              :         }
    4145              :       else
    4146            0 :         error ("invalid default argument for a template template parameter");
    4147           15 :       return error_mark_node;
    4148              :     }
    4149              : 
    4150              :   return argument;
    4151              : }
    4152              : 
    4153              : /* Begin a class definition, as indicated by T.  */
    4154              : 
    4155              : tree
    4156     29994414 : begin_class_definition (tree t)
    4157              : {
    4158     29994414 :   if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
    4159           33 :     return error_mark_node;
    4160              : 
    4161     29994519 :   if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
    4162              :     {
    4163            9 :       error ("definition of %q#T inside template parameter list", t);
    4164            9 :       return error_mark_node;
    4165              :     }
    4166              : 
    4167              :   /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
    4168              :      are passed the same as decimal scalar types.  */
    4169     29994372 :   if (TREE_CODE (t) == RECORD_TYPE
    4170     29489935 :       && !processing_template_decl)
    4171              :     {
    4172     10586042 :       tree ns = TYPE_CONTEXT (t);
    4173     10586039 :       if (ns && TREE_CODE (ns) == NAMESPACE_DECL
    4174      8708349 :           && DECL_CONTEXT (ns) == std_node
    4175      2103131 :           && DECL_NAME (ns)
    4176     12689153 :           && id_equal (DECL_NAME (ns), "decimal"))
    4177              :         {
    4178          150 :           const char *n = TYPE_NAME_STRING (t);
    4179          150 :           if ((strcmp (n, "decimal32") == 0)
    4180          101 :               || (strcmp (n, "decimal64") == 0)
    4181           46 :               || (strcmp (n, "decimal128") == 0))
    4182          147 :             TYPE_TRANSPARENT_AGGR (t) = 1;
    4183              :         }
    4184              :     }
    4185              : 
    4186              :   /* A non-implicit typename comes from code like:
    4187              : 
    4188              :        template <typename T> struct A {
    4189              :          template <typename U> struct A<T>::B ...
    4190              : 
    4191              :      This is erroneous.  */
    4192     19408330 :   else if (TREE_CODE (t) == TYPENAME_TYPE)
    4193              :     {
    4194            0 :       error ("invalid definition of qualified type %qT", t);
    4195            0 :       t = error_mark_node;
    4196              :     }
    4197              : 
    4198     29994372 :   if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
    4199              :     {
    4200            0 :       t = make_class_type (RECORD_TYPE);
    4201            0 :       pushtag (make_anon_name (), t);
    4202              :     }
    4203              : 
    4204     29994372 :   if (TYPE_BEING_DEFINED (t))
    4205              :     {
    4206            0 :       t = make_class_type (TREE_CODE (t));
    4207            0 :       pushtag (TYPE_IDENTIFIER (t), t);
    4208              :     }
    4209              : 
    4210     29994372 :   maybe_process_partial_specialization (t);
    4211     29994372 :   pushclass (t);
    4212     29994372 :   TYPE_BEING_DEFINED (t) = 1;
    4213     29994372 :   class_binding_level->defining_class_p = 1;
    4214              : 
    4215     29994372 :   if (flag_pack_struct)
    4216              :     {
    4217           99 :       tree v;
    4218           99 :       TYPE_PACKED (t) = 1;
    4219              :       /* Even though the type is being defined for the first time
    4220              :          here, there might have been a forward declaration, so there
    4221              :          might be cv-qualified variants of T.  */
    4222           99 :       for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    4223            0 :         TYPE_PACKED (v) = 1;
    4224              :     }
    4225              :   /* Reset the interface data, at the earliest possible
    4226              :      moment, as it might have been set via a class foo;
    4227              :      before.  */
    4228     62183454 :   if (! TYPE_UNNAMED_P (t))
    4229              :     {
    4230     29268917 :       struct c_fileinfo *finfo = \
    4231     29268917 :         get_fileinfo (LOCATION_FILE (input_location));
    4232     29268917 :       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
    4233     29268917 :       SET_CLASSTYPE_INTERFACE_UNKNOWN_X
    4234              :         (t, finfo->interface_unknown);
    4235              :     }
    4236     29994372 :   reset_specialization ();
    4237              : 
    4238              :   /* Make a declaration for this class in its own scope.  */
    4239     29994372 :   build_self_reference ();
    4240              : 
    4241     29994372 :   return t;
    4242              : }
    4243              : 
    4244              : /* Finish the member declaration given by DECL.  */
    4245              : 
    4246              : void
    4247    403715209 : finish_member_declaration (tree decl)
    4248              : {
    4249    403715209 :   if (decl == error_mark_node || decl == NULL_TREE)
    4250              :     return;
    4251              : 
    4252    403714193 :   if (decl == void_type_node)
    4253              :     /* The COMPONENT was a friend, not a member, and so there's
    4254              :        nothing for us to do.  */
    4255              :     return;
    4256              : 
    4257              :   /* We should see only one DECL at a time.  */
    4258    403714193 :   gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
    4259              : 
    4260              :   /* Don't add decls after definition.  */
    4261    403714214 :   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
    4262              :               /* We can add lambda types when late parsing default
    4263              :                  arguments.  */
    4264              :               || LAMBDA_TYPE_P (TREE_TYPE (decl)));
    4265              : 
    4266              :   /* Set up access control for DECL.  */
    4267    403714193 :   TREE_PRIVATE (decl)
    4268    403714193 :     = (current_access_specifier == access_private_node);
    4269    403714193 :   TREE_PROTECTED (decl)
    4270    403714193 :     = (current_access_specifier == access_protected_node);
    4271    403714193 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    4272              :     {
    4273     45881626 :       TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
    4274     45881626 :       TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
    4275              :     }
    4276              : 
    4277              :   /* Mark the DECL as a member of the current class, unless it's
    4278              :      a member of an enumeration.  */
    4279    403714193 :   if (TREE_CODE (decl) != CONST_DECL)
    4280    401486098 :     DECL_CONTEXT (decl) = current_class_type;
    4281              : 
    4282              :   /* Remember the single FIELD_DECL an anonymous aggregate type is used for.  */
    4283    403714193 :   if (TREE_CODE (decl) == FIELD_DECL
    4284    403714193 :       && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    4285              :     {
    4286       255897 :       gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
    4287       255897 :       SET_ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)), decl);
    4288              :     }
    4289              : 
    4290    403714193 :   if (TREE_CODE (decl) == USING_DECL)
    4291              :     /* Avoid debug info for class-scope USING_DECLS for now, we'll
    4292              :        call cp_emit_debug_info_for_using later. */
    4293      3234963 :     DECL_IGNORED_P (decl) = 1;
    4294              : 
    4295              :   /* Check for bare parameter packs in the non-static data member
    4296              :      declaration.  */
    4297    403714193 :   if (TREE_CODE (decl) == FIELD_DECL)
    4298              :     {
    4299     29233519 :       if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
    4300            9 :         TREE_TYPE (decl) = error_mark_node;
    4301     29233519 :       if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
    4302            0 :         DECL_ATTRIBUTES (decl) = NULL_TREE;
    4303              :     }
    4304              : 
    4305              :   /* [dcl.link]
    4306              : 
    4307              :      A C language linkage is ignored for the names of class members
    4308              :      and the member function type of class member functions.  */
    4309    403714193 :   if (DECL_LANG_SPECIFIC (decl))
    4310    368903855 :     SET_DECL_LANGUAGE (decl, lang_cplusplus);
    4311              : 
    4312    403714193 :   bool add = false;
    4313              : 
    4314              :   /* Functions and non-functions are added differently.  */
    4315    403714193 :   if (DECL_DECLARES_FUNCTION_P (decl))
    4316    209146556 :     add = add_method (current_class_type, decl, false);
    4317              :   /* Enter the DECL into the scope of the class, if the class
    4318              :      isn't a closure (whose fields are supposed to be unnamed).  */
    4319    194567637 :   else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
    4320    191186390 :            || maybe_push_used_methods (decl)
    4321    383915417 :            || pushdecl_class_level (decl))
    4322              :     add = true;
    4323              : 
    4324    209146556 :   if (add)
    4325              :     {
    4326              :       /* All TYPE_DECLs go at the end of TYPE_FIELDS.  Ordinary fields
    4327              :          go at the beginning.  The reason is that
    4328              :          legacy_nonfn_member_lookup searches the list in order, and we
    4329              :          want a field name to override a type name so that the "struct
    4330              :          stat hack" will work.  In particular:
    4331              : 
    4332              :            struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
    4333              : 
    4334              :          is valid.  */
    4335              : 
    4336    403703040 :       if (TREE_CODE (decl) == TYPE_DECL)
    4337    138365220 :         TYPE_FIELDS (current_class_type)
    4338    276730440 :           = chainon (TYPE_FIELDS (current_class_type), decl);
    4339              :       else
    4340              :         {
    4341    265337820 :           DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
    4342    265337820 :           TYPE_FIELDS (current_class_type) = decl;
    4343              :         }
    4344              : 
    4345    403703040 :       maybe_add_class_template_decl_list (current_class_type, decl,
    4346              :                                           /*friend_p=*/0);
    4347              :     }
    4348              : }
    4349              : 
    4350              : /* Finish processing a complete template declaration.  The PARMS are
    4351              :    the template parameters.  */
    4352              : 
    4353              : void
    4354     89486515 : finish_template_decl (tree parms)
    4355              : {
    4356     89486515 :   if (parms)
    4357     89486506 :     end_template_decl ();
    4358              :   else
    4359            9 :     end_specialization ();
    4360     89486515 : }
    4361              : 
    4362              : // Returns the template type of the class scope being entered. If we're
    4363              : // entering a constrained class scope. TYPE is the class template
    4364              : // scope being entered and we may need to match the intended type with
    4365              : // a constrained specialization. For example:
    4366              : //
    4367              : //    template<Object T>
    4368              : //      struct S { void f(); }; #1
    4369              : //
    4370              : //    template<Object T>
    4371              : //      void S<T>::f() { }      #2
    4372              : //
    4373              : // We check, in #2, that S<T> refers precisely to the type declared by
    4374              : // #1 (i.e., that the constraints match). Note that the following should
    4375              : // be an error since there is no specialization of S<T> that is
    4376              : // unconstrained, but this is not diagnosed here.
    4377              : //
    4378              : //    template<typename T>
    4379              : //      void S<T>::f() { }
    4380              : //
    4381              : // We cannot diagnose this problem here since this function also matches
    4382              : // qualified template names that are not part of a definition. For example:
    4383              : //
    4384              : //    template<Integral T, Floating_point U>
    4385              : //      typename pair<T, U>::first_type void f(T, U);
    4386              : //
    4387              : // Here, it is unlikely that there is a partial specialization of
    4388              : // pair constrained for Integral and Floating_point arguments.
    4389              : //
    4390              : // The general rule is: if a constrained specialization with matching
    4391              : // constraints is found return that type. Also note that if TYPE is not a
    4392              : // class-type (e.g. a typename type), then no fixup is needed.
    4393              : 
    4394              : static tree
    4395     17628326 : fixup_template_type (tree type)
    4396              : {
    4397              :   // Find the template parameter list at the a depth appropriate to
    4398              :   // the scope we're trying to enter.
    4399     17628326 :   tree parms = current_template_parms;
    4400     17628326 :   int depth = template_class_depth (type);
    4401     39266608 :   for (int n = current_template_depth; n > depth && parms; --n)
    4402      4009956 :     parms = TREE_CHAIN (parms);
    4403     17628326 :   if (!parms)
    4404              :     return type;
    4405     17628316 :   tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
    4406     17628316 :   tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
    4407              : 
    4408              :   // Search for a specialization whose type and constraints match.
    4409     17628316 :   tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
    4410     17628316 :   tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
    4411     34221969 :   while (specs)
    4412              :     {
    4413     17006465 :       tree spec_constr = get_constraints (TREE_VALUE (specs));
    4414              : 
    4415              :       // If the type and constraints match a specialization, then we
    4416              :       // are entering that type.
    4417     17006465 :       if (same_type_p (type, TREE_TYPE (specs))
    4418     17006465 :           && equivalent_constraints (cur_constr, spec_constr))
    4419       412812 :         return TREE_TYPE (specs);
    4420     16593653 :       specs = TREE_CHAIN (specs);
    4421              :     }
    4422              : 
    4423              :   // If no specialization matches, then must return the type
    4424              :   // previously found.
    4425              :   return type;
    4426              : }
    4427              : 
    4428              : /* Finish processing a template-id (which names a type) of the form
    4429              :    NAME < ARGS >.  Return the TYPE_DECL for the type named by the
    4430              :    template-id.  If ENTERING_SCOPE is nonzero we are about to enter
    4431              :    the scope of template-id indicated.  */
    4432              : 
    4433              : tree
    4434    182163203 : finish_template_type (tree name, tree args, int entering_scope)
    4435              : {
    4436    182163203 :   tree type;
    4437              : 
    4438    182163203 :   type = lookup_template_class (name, args,
    4439              :                                 NULL_TREE, NULL_TREE,
    4440              :                                 tf_warning_or_error | tf_user);
    4441    182163200 :   if (entering_scope)
    4442     18630974 :     type = adjust_type_for_entering_scope (type);
    4443              : 
    4444              :   /* If we might be entering the scope of a partial specialization,
    4445              :      find the one with the right constraints.  */
    4446    182163200 :   if (flag_concepts
    4447    179494719 :       && entering_scope
    4448     18274207 :       && CLASS_TYPE_P (type)
    4449     18112414 :       && CLASSTYPE_TEMPLATE_INFO (type)
    4450     18112405 :       && dependent_type_p (type)
    4451    199791526 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
    4452     17628326 :     type = fixup_template_type (type);
    4453              : 
    4454    182163200 :   if (type == error_mark_node)
    4455              :     return type;
    4456    182160910 :   else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
    4457    143275863 :     return TYPE_STUB_DECL (type);
    4458              :   else
    4459     38885047 :     return TYPE_NAME (type);
    4460              : }
    4461              : 
    4462              : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
    4463              :    and ANNOTATIONS.
    4464              :    Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
    4465              :    ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
    4466              :    and the BASE_CLASS, or NULL_TREE if an error occurred.  The
    4467              :    ACCESS_SPECIFIER is one of
    4468              :    access_{default,public,protected,private}_node.  For a virtual base
    4469              :    we set TREE_TYPE.  */
    4470              : 
    4471              : tree
    4472     11093209 : finish_base_specifier (tree base, tree access, bool virtual_p,
    4473              :                        tree annotations)
    4474              : {
    4475     11093209 :   tree result;
    4476              : 
    4477     11093209 :   if (base == error_mark_node)
    4478              :     {
    4479            0 :       error ("invalid base-class specification");
    4480            0 :       result = NULL_TREE;
    4481              :     }
    4482     11093209 :   else if (! MAYBE_CLASS_TYPE_P (base))
    4483              :     {
    4484            3 :       error ("%qT is not a class type", base);
    4485            3 :       result = NULL_TREE;
    4486              :     }
    4487              :   else
    4488              :     {
    4489     11093206 :       if (cp_type_quals (base) != 0)
    4490              :         {
    4491              :           /* DR 484: Can a base-specifier name a cv-qualified
    4492              :              class type?  */
    4493           12 :           base = TYPE_MAIN_VARIANT (base);
    4494              :         }
    4495     11093206 :       if (annotations)
    4496           18 :         access = build_tree_list (access, nreverse (annotations));
    4497     11093206 :       result = build_tree_list (access, base);
    4498     11093206 :       if (virtual_p)
    4499        25516 :         TREE_TYPE (result) = integer_type_node;
    4500              :     }
    4501              : 
    4502     11093209 :   return result;
    4503              : }
    4504              : 
    4505              : /* If FNS is a member function, a set of member functions, or a
    4506              :    template-id referring to one or more member functions, return a
    4507              :    BASELINK for FNS, incorporating the current access context.
    4508              :    Otherwise, return FNS unchanged.  */
    4509              : 
    4510              : tree
    4511    170647681 : baselink_for_fns (tree fns)
    4512              : {
    4513    170647681 :   tree scope;
    4514    170647681 :   tree cl;
    4515              : 
    4516    170647681 :   if (BASELINK_P (fns)
    4517    170647681 :       || error_operand_p (fns))
    4518              :     return fns;
    4519              : 
    4520    157228986 :   scope = ovl_scope (fns);
    4521    157228986 :   if (!CLASS_TYPE_P (scope))
    4522              :     return fns;
    4523              : 
    4524      8500297 :   cl = currently_open_derived_class (scope);
    4525      8500297 :   if (!cl)
    4526      6201950 :     cl = scope;
    4527      8500297 :   tree access_path = TYPE_BINFO (cl);
    4528      8500297 :   tree conv_path = (cl == scope ? access_path
    4529       680218 :                     : lookup_base (cl, scope, ba_any, NULL, tf_none));
    4530      8500297 :   return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
    4531              : }
    4532              : 
    4533              : /* Returns true iff we are currently parsing a lambda-declarator.  */
    4534              : 
    4535              : bool
    4536   1902057518 : parsing_lambda_declarator ()
    4537              : {
    4538   1902057518 :   cp_binding_level *b = current_binding_level;
    4539   1903948379 :   while (b->kind == sk_template_parms || b->kind == sk_function_parms)
    4540      1890861 :     b = b->level_chain;
    4541   1902057518 :   return b->kind == sk_lambda;
    4542              : }
    4543              : 
    4544              : /* Returns true iff DECL is a variable from a function outside
    4545              :    the current one.  */
    4546              : 
    4547              : static bool
    4548   2539292069 : outer_var_p (tree decl)
    4549              : {
    4550              :   /* These should have been stripped or otherwise handled by the caller.  */
    4551   2539292069 :   gcc_checking_assert (!REFERENCE_REF_P (decl));
    4552              : 
    4553   1674028859 :   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
    4554   2331134257 :           && DECL_FUNCTION_SCOPE_P (decl)
    4555              :           /* Don't get confused by temporaries.  */
    4556   1932548148 :           && DECL_NAME (decl)
    4557   4449001030 :           && (DECL_CONTEXT (decl) != current_function_decl
    4558   1900116966 :               || parsing_nsdmi ()
    4559              :               /* Also consider captures as outer vars if we are in
    4560              :                  decltype in a lambda declarator as in:
    4561              :                    auto l = [j=0]() -> decltype((j)) { ... }
    4562              :                  for the sake of finish_decltype_type.
    4563              : 
    4564              :                  (Similar issue also affects non-lambdas, but vexing parse
    4565              :                  makes it more difficult to handle than lambdas.)  */
    4566   1900115619 :               || parsing_lambda_declarator ()));
    4567              : }
    4568              : 
    4569              : /* As above, but also checks that DECL is automatic.  */
    4570              : 
    4571              : bool
    4572   2539292069 : outer_automatic_var_p (tree decl)
    4573              : {
    4574   2539292069 :   return (outer_var_p (decl)
    4575   2539292069 :           && !TREE_STATIC (decl));
    4576              : }
    4577              : 
    4578              : /* Note whether capture proxy D is only used in a contract condition.  */
    4579              : 
    4580              : static void
    4581       114660 : set_contract_capture_flag (tree d, bool val)
    4582              : {
    4583       114660 :   gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
    4584       114660 :   tree proxy = DECL_VALUE_EXPR (d);
    4585       114660 :   gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
    4586              :                        && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
    4587       114660 :   DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
    4588       114660 : }
    4589              : 
    4590              : /* DECL satisfies outer_automatic_var_p.  Possibly complain about it or
    4591              :    rewrite it for lambda capture.
    4592              : 
    4593              :    If ODR_USE is true, we're being called from mark_use, and we complain about
    4594              :    use of constant variables.  If ODR_USE is false, we're being called for the
    4595              :    id-expression, and we do lambda capture.  */
    4596              : 
    4597              : tree
    4598      4919492 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
    4599              :                        bool odr_use/*=false*/)
    4600              : {
    4601      4919492 :   if (cp_unevaluated_operand)
    4602              :     {
    4603      2977356 :       tree type = TREE_TYPE (decl);
    4604      2977356 :       if (!dependent_type_p (type)
    4605      2977356 :           && variably_modified_type_p (type, NULL_TREE))
    4606              :         /* VLAs are used even in unevaluated context.  */;
    4607              :       else
    4608              :         /* It's not a use (3.2) if we're in an unevaluated context.  */
    4609      2977350 :         return decl;
    4610              :     }
    4611      1942142 :   if (decl == error_mark_node)
    4612              :     return decl;
    4613              : 
    4614      1942136 :   tree context = DECL_CONTEXT (decl);
    4615      1942136 :   tree containing_function = current_function_decl;
    4616      1942136 :   tree lambda_stack = NULL_TREE;
    4617      1942136 :   tree lambda_expr = NULL_TREE;
    4618      1942136 :   tree initializer = convert_from_reference (decl);
    4619      1942136 :   tree var = strip_normal_capture_proxy (decl);
    4620              : 
    4621              :   /* Mark it as used now even if the use is ill-formed.  */
    4622      1942136 :   if (!mark_used (decl, complain))
    4623            3 :     return error_mark_node;
    4624              : 
    4625      1942133 :   if (parsing_nsdmi () || parsing_lambda_declarator ())
    4626              :     containing_function = NULL_TREE;
    4627              : 
    4628      3883358 :   if (containing_function && LAMBDA_FUNCTION_P (containing_function))
    4629              :     {
    4630              :       /* Check whether we've already built a proxy.  */
    4631      1941564 :       tree d = retrieve_local_specialization (var);
    4632              : 
    4633      1941564 :       if (d && d != decl && is_capture_proxy (d))
    4634              :         {
    4635       995111 :           if (flag_contracts && !processing_contract_condition)
    4636              :             /* We might have created a capture for a contract_assert ref. to
    4637              :                some var, if that is now captured 'normally' then this is OK.
    4638              :                Otherwise we leave the capture marked as incorrect.  */
    4639       114654 :             set_contract_capture_flag (d, false);
    4640       995111 :           if (DECL_CONTEXT (d) == containing_function)
    4641              :             /* We already have an inner proxy.  */
    4642              :             return d;
    4643              :           else
    4644              :             /* We need to capture an outer proxy.  */
    4645         2672 :             return process_outer_var_ref (d, complain, odr_use);
    4646              :         }
    4647              :     }
    4648              : 
    4649              :   /* If we are in a lambda function, we can move out until we hit
    4650              :      1. the context,
    4651              :      2. a non-lambda function, or
    4652              :      3. a non-default capturing lambda function.  */
    4653      1896623 :   while (context != containing_function
    4654              :          /* containing_function can be null with invalid generic lambdas.  */
    4655      1896623 :          && containing_function
    4656      2846973 :          && LAMBDA_FUNCTION_P (containing_function))
    4657              :     {
    4658       950350 :       tree closure = DECL_CONTEXT (containing_function);
    4659       950350 :       lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
    4660              : 
    4661       950350 :       if (TYPE_CLASS_SCOPE_P (closure))
    4662              :         /* A lambda in an NSDMI (c++/64496).  */
    4663              :         break;
    4664              : 
    4665       950347 :       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4666              :         break;
    4667              : 
    4668       949601 :       lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
    4669              : 
    4670       949601 :       containing_function = decl_function_context (containing_function);
    4671              :     }
    4672              : 
    4673              :   /* In a lambda within a template, wait until instantiation time to implicitly
    4674              :      capture a parameter pack.  We want to wait because we don't know if we're
    4675              :      capturing the whole pack or a single element, and it's OK to wait because
    4676              :      find_parameter_packs_r walks into the lambda body.  */
    4677       947022 :   if (context == containing_function
    4678       947022 :       && DECL_PACK_P (decl))
    4679              :     return decl;
    4680              : 
    4681       906128 :   if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
    4682              :     {
    4683            6 :       if (complain & tf_error)
    4684            6 :         error ("cannot capture member %qD of anonymous union", decl);
    4685            6 :       return error_mark_node;
    4686              :     }
    4687              :   /* Do lambda capture when processing the id-expression, not when
    4688              :      odr-using a variable, but uses in a contract must not cause a capture.  */
    4689       906122 :   if (!odr_use && context == containing_function)
    4690              :     {
    4691       904804 :       decl = add_default_capture (lambda_stack,
    4692       904804 :                                   /*id=*/DECL_NAME (decl), initializer);
    4693       904804 :       if (flag_contracts && processing_contract_condition)
    4694            6 :         set_contract_capture_flag (decl, true);
    4695              :     }
    4696              :   /* Only an odr-use of an outer automatic variable causes an
    4697              :      error, and a constant variable can decay to a prvalue
    4698              :      constant without odr-use.  So don't complain yet.  */
    4699         1318 :   else if (!odr_use && decl_constant_var_p (var))
    4700              :     return var;
    4701              :   /* Don't complain when DECL is dependent, because it can turn out to
    4702              :      be constant (and therefore needing no capture) when instantiating.  */
    4703          449 :   else if (VAR_P (var) && instantiation_dependent_expression_p (var))
    4704              :     return var;
    4705          431 :   else if (lambda_expr)
    4706              :     {
    4707           57 :       if (complain & tf_error)
    4708              :         {
    4709           53 :           auto_diagnostic_group d;
    4710           53 :           error ("%qD is not captured", decl);
    4711           53 :           tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
    4712           53 :           if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4713           50 :             inform (location_of (closure),
    4714              :                     "the lambda has no capture-default");
    4715            3 :           else if (TYPE_CLASS_SCOPE_P (closure))
    4716            3 :             inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
    4717              :                     "capture variables from the enclosing context",
    4718            3 :                     TYPE_CONTEXT (closure));
    4719           53 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4720           53 :         }
    4721           57 :       return error_mark_node;
    4722              :     }
    4723          374 :   else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
    4724              :     /* Use of a parameter in a contract condition is fine.  */
    4725              :     return decl;
    4726              :   else
    4727              :     {
    4728           53 :       if (complain & tf_error)
    4729              :         {
    4730           39 :           auto_diagnostic_group d;
    4731           57 :           error (VAR_P (decl)
    4732              :                  ? G_("use of local variable with automatic storage from "
    4733              :                       "containing function")
    4734              :                  : G_("use of parameter from containing function"));
    4735           39 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4736           39 :         }
    4737           53 :       return error_mark_node;
    4738              :     }
    4739              :   return decl;
    4740              : }
    4741              : 
    4742              : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
    4743              :    id-expression.  (See cp_parser_id_expression for details.)  SCOPE,
    4744              :    if non-NULL, is the type or namespace used to explicitly qualify
    4745              :    ID_EXPRESSION.  DECL is the entity to which that name has been
    4746              :    resolved.
    4747              : 
    4748              :    *CONSTANT_EXPRESSION_P is true if we are presently parsing a
    4749              :    constant-expression.  In that case, *NON_CONSTANT_EXPRESSION_P will
    4750              :    be set to true if this expression isn't permitted in a
    4751              :    constant-expression, but it is otherwise not set by this function.
    4752              :    *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
    4753              :    constant-expression, but a non-constant expression is also
    4754              :    permissible.
    4755              : 
    4756              :    DONE is true if this expression is a complete postfix-expression;
    4757              :    it is false if this expression is followed by '->', '[', '(', etc.
    4758              :    ADDRESS_P is true iff this expression is the operand of '&'.
    4759              :    TEMPLATE_P is true iff the qualified-id was of the form
    4760              :    "A::template B".  TEMPLATE_ARG_P is true iff this qualified name
    4761              :    appears as a template argument.
    4762              : 
    4763              :    If an error occurs, and it is the kind of error that might cause
    4764              :    the parser to abort a tentative parse, *ERROR_MSG is filled in.  It
    4765              :    is the caller's responsibility to issue the message.  *ERROR_MSG
    4766              :    will be a string with static storage duration, so the caller need
    4767              :    not "free" it.
    4768              : 
    4769              :    Return an expression for the entity, after issuing appropriate
    4770              :    diagnostics.  This function is also responsible for transforming a
    4771              :    reference to a non-static member into a COMPONENT_REF that makes
    4772              :    the use of "this" explicit.
    4773              : 
    4774              :    Upon return, *IDK will be filled in appropriately.  */
    4775              : static cp_expr
    4776    757960594 : finish_id_expression_1 (tree id_expression,
    4777              :                         tree decl,
    4778              :                         tree scope,
    4779              :                         cp_id_kind *idk,
    4780              :                         bool integral_constant_expression_p,
    4781              :                         bool allow_non_integral_constant_expression_p,
    4782              :                         bool *non_integral_constant_expression_p,
    4783              :                         bool template_p,
    4784              :                         bool done,
    4785              :                         bool address_p,
    4786              :                         bool template_arg_p,
    4787              :                         const char **error_msg,
    4788              :                         location_t location)
    4789              : {
    4790    757960594 :   decl = strip_using_decl (decl);
    4791              : 
    4792              :   /* Initialize the output parameters.  */
    4793    757960594 :   *idk = CP_ID_KIND_NONE;
    4794    757960594 :   *error_msg = NULL;
    4795              : 
    4796    757960594 :   if (id_expression == error_mark_node)
    4797           12 :     return error_mark_node;
    4798              :   /* If we have a template-id, then no further lookup is
    4799              :      required.  If the template-id was for a template-class, we
    4800              :      will sometimes have a TYPE_DECL at this point.  */
    4801    757960582 :   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4802    705702285 :            || TREE_CODE (decl) == TYPE_DECL)
    4803              :     ;
    4804              :   /* Look up the name.  */
    4805              :   else
    4806              :     {
    4807    705701370 :       if (decl == error_mark_node)
    4808              :         {
    4809              :           /* Name lookup failed.  */
    4810       123795 :           if (scope
    4811          374 :               && !dependent_namespace_p (scope)
    4812       124169 :               && (!TYPE_P (scope)
    4813          119 :                   || (!dependentish_scope_p (scope)
    4814          115 :                       && !(identifier_p (id_expression)
    4815          100 :                            && IDENTIFIER_CONV_OP_P (id_expression)
    4816            3 :                            && dependent_type_p (TREE_TYPE (id_expression))))))
    4817              :             {
    4818              :               /* If the qualifying type is non-dependent (and the name
    4819              :                  does not name a conversion operator to a dependent
    4820              :                  type), issue an error.  */
    4821          364 :               qualified_name_lookup_error (scope, id_expression, decl, location);
    4822          364 :               return error_mark_node;
    4823              :             }
    4824       123431 :           else if (!scope)
    4825              :             {
    4826              :               /* It may be resolved via Koenig lookup.  */
    4827       123421 :               *idk = CP_ID_KIND_UNQUALIFIED;
    4828       123421 :               return id_expression;
    4829              :             }
    4830              :           else
    4831              :             decl = id_expression;
    4832              :         }
    4833              : 
    4834              :       /* Remember that the name was used in the definition of
    4835              :          the current class so that we can check later to see if
    4836              :          the meaning would have been different after the class
    4837              :          was entirely defined.  */
    4838    705577575 :       if (!scope && decl != error_mark_node && identifier_p (id_expression))
    4839    631060272 :         maybe_note_name_used_in_class (id_expression, decl);
    4840              : 
    4841              :       /* A use in unevaluated operand might not be instantiated appropriately
    4842              :          if tsubst_copy builds a dummy parm, or if we never instantiate a
    4843              :          generic lambda, so mark it now.  */
    4844    705577585 :       if (processing_template_decl
    4845    705577585 :           && (cp_unevaluated_operand
    4846    609978866 :               || generic_lambda_fn_p (current_function_decl)))
    4847     19442100 :         mark_type_use (decl);
    4848              : 
    4849              :       /* Disallow uses of local variables from containing functions, except
    4850              :          within lambda-expressions.  */
    4851    705577585 :       if (outer_automatic_var_p (decl))
    4852              :         {
    4853      3499819 :           decl = process_outer_var_ref (decl, tf_warning_or_error);
    4854      3499819 :           if (decl == error_mark_node)
    4855           89 :             return error_mark_node;
    4856              :         }
    4857              : 
    4858              :       /* Also disallow uses of function parameters outside the function
    4859              :          body, except inside an unevaluated context (i.e. decltype).  */
    4860    705577496 :       if (TREE_CODE (decl) == PARM_DECL
    4861    294753330 :           && DECL_CONTEXT (decl) == NULL_TREE
    4862      7983305 :           && !CONSTRAINT_VAR_P (decl)
    4863      4298626 :           && !cp_unevaluated_operand
    4864          561 :           && !processing_contract_condition
    4865    705577552 :           && !processing_omp_trait_property_expr)
    4866              :         {
    4867           38 :           *error_msg = G_("use of parameter outside function body");
    4868           38 :           return error_mark_node;
    4869              :         }
    4870              :     }
    4871              : 
    4872              :   /* If we didn't find anything, or what we found was a type,
    4873              :      then this wasn't really an id-expression.  */
    4874    757836670 :   if (TREE_CODE (decl) == TEMPLATE_DECL
    4875    757836670 :       && !DECL_FUNCTION_TEMPLATE_P (decl))
    4876              :     {
    4877           51 :       *error_msg = G_("missing template arguments");
    4878           51 :       return error_mark_node;
    4879              :     }
    4880    757836619 :   else if (TREE_CODE (decl) == TYPE_DECL
    4881    757835704 :            || TREE_CODE (decl) == NAMESPACE_DECL)
    4882              :     {
    4883          930 :       *error_msg = G_("expected primary-expression");
    4884          930 :       return error_mark_node;
    4885              :     }
    4886              : 
    4887              :   /* If the name resolved to a template parameter, there is no
    4888              :      need to look it up again later.  */
    4889     32060181 :   if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
    4890    771299868 :       || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4891              :     {
    4892     18596002 :       tree r;
    4893              : 
    4894     18596002 :       *idk = CP_ID_KIND_NONE;
    4895     18596002 :       if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4896            0 :         decl = TEMPLATE_PARM_DECL (decl);
    4897     18596002 :       r = DECL_INITIAL (decl);
    4898     18596002 :       if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
    4899              :         {
    4900              :           /* If the entity is a template parameter object for a template
    4901              :              parameter of type T, the type of the expression is const T.  */
    4902         1094 :           tree ctype = TREE_TYPE (r);
    4903         1094 :           ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
    4904              :                                                    | TYPE_QUAL_CONST));
    4905         1094 :           r = build1 (VIEW_CONVERT_EXPR, ctype, r);
    4906              :         }
    4907     18596002 :       r = convert_from_reference (r);
    4908     18596002 :       if (integral_constant_expression_p
    4909      3203459 :           && !dependent_type_p (TREE_TYPE (decl))
    4910     21320845 :           && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
    4911              :         {
    4912          783 :           if (!allow_non_integral_constant_expression_p)
    4913            6 :             error ("template parameter %qD of type %qT is not allowed in "
    4914              :                    "an integral constant expression because it is not of "
    4915            6 :                    "integral or enumeration type", decl, TREE_TYPE (decl));
    4916          783 :           *non_integral_constant_expression_p = true;
    4917              :         }
    4918              : 
    4919     18596002 :       if (flag_contracts && processing_contract_condition)
    4920           15 :         r = constify_contract_access (r);
    4921              : 
    4922     18596002 :       return r;
    4923              :     }
    4924    739239687 :   else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
    4925              :     {
    4926            9 :       gcc_checking_assert (scope);
    4927            9 :       *idk = CP_ID_KIND_QUALIFIED;
    4928            9 :       cp_warn_deprecated_use_scopes (scope);
    4929            9 :       decl = finish_qualified_id_expr (scope, decl, done, address_p,
    4930              :                                        template_p, template_arg_p,
    4931              :                                        tf_warning_or_error);
    4932              :     }
    4933              :   else
    4934              :     {
    4935    739239678 :       if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4936     52258297 :           && variable_template_p (TREE_OPERAND (decl, 0))
    4937    751023992 :           && !concept_check_p (decl))
    4938              :         /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
    4939              :            considered type-dependent) now, so that the dependence test that
    4940              :            follows gives us the right answer: if it represents a non-dependent
    4941              :            variable template-id then finish_template_variable will yield the
    4942              :            corresponding non-dependent VAR_DECL.  */
    4943     11784314 :         decl = finish_template_variable (decl);
    4944              : 
    4945    739239678 :       bool dependent_p = type_dependent_expression_p (decl);
    4946              : 
    4947              :       /* If the declaration was explicitly qualified indicate
    4948              :          that.  The semantics of `A::f(3)' are different than
    4949              :          `f(3)' if `f' is virtual.  */
    4950   1478479356 :       *idk = (scope
    4951    739239678 :               ? CP_ID_KIND_QUALIFIED
    4952    643361522 :               : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4953    643361522 :                  ? CP_ID_KIND_TEMPLATE_ID
    4954              :                  : (dependent_p
    4955    612740281 :                     ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
    4956              :                     : CP_ID_KIND_UNQUALIFIED)));
    4957              : 
    4958    739239678 :       if (dependent_p
    4959    739239678 :           && !scope
    4960    423315025 :           && DECL_P (decl)
    4961   1132920873 :           && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
    4962              :         /* Dependent type attributes on the decl mean that the TREE_TYPE is
    4963              :            wrong, so just return the identifier.  */
    4964           39 :         return id_expression;
    4965              : 
    4966    739239639 :       if (DECL_CLASS_TEMPLATE_P (decl))
    4967              :         {
    4968            0 :           error ("use of class template %qT as expression", decl);
    4969            0 :           return error_mark_node;
    4970              :         }
    4971              : 
    4972    739239639 :       if (TREE_CODE (decl) == TREE_LIST)
    4973              :         {
    4974              :           /* Ambiguous reference to base members.  */
    4975            0 :           auto_diagnostic_group d;
    4976            0 :           error ("request for member %qD is ambiguous in "
    4977              :                  "multiple inheritance lattice", id_expression);
    4978            0 :           print_candidates (input_location, decl);
    4979            0 :           return error_mark_node;
    4980            0 :         }
    4981              : 
    4982              :       /* Mark variable-like entities as used.  Functions are similarly
    4983              :          marked either below or after overload resolution.  */
    4984    739239639 :       if ((VAR_P (decl)
    4985    536216566 :            || TREE_CODE (decl) == PARM_DECL
    4986    241463280 :            || TREE_CODE (decl) == CONST_DECL
    4987    227999101 :            || TREE_CODE (decl) == RESULT_DECL)
    4988   1047457104 :           && !mark_used (decl))
    4989           12 :         return error_mark_node;
    4990              : 
    4991              :       /* Only certain kinds of names are allowed in constant
    4992              :          expression.  Template parameters have already
    4993              :          been handled above.  */
    4994    739239624 :       if (! error_operand_p (decl)
    4995    739239294 :           && !dependent_p
    4996    739239294 :           && integral_constant_expression_p
    4997     74425868 :           && !decl_constant_var_p (decl)
    4998     60692103 :           && TREE_CODE (decl) != CONST_DECL
    4999     52445860 :           && !builtin_valid_in_constant_expr_p (decl)
    5000    791637284 :           && !concept_check_p (decl))
    5001              :         {
    5002     51876620 :           if (!allow_non_integral_constant_expression_p)
    5003              :             {
    5004           30 :               error ("%qD cannot appear in a constant-expression", decl);
    5005           30 :               return error_mark_node;
    5006              :             }
    5007     51876590 :           *non_integral_constant_expression_p = true;
    5008              :         }
    5009              : 
    5010    739239594 :       if (tree wrap = maybe_get_tls_wrapper_call (decl))
    5011              :         /* Replace an evaluated use of the thread_local variable with
    5012              :            a call to its wrapper.  */
    5013              :         decl = wrap;
    5014    739239082 :       else if (concept_check_p (decl))
    5015              :         {
    5016              :           /* Nothing more to do. All of the analysis for concept checks
    5017              :              is done by build_conept_id, called from the parser.  */
    5018              :         }
    5019    723194358 :       else if (scope)
    5020              :         {
    5021     94069319 :           if (TREE_CODE (decl) == SCOPE_REF)
    5022              :             {
    5023        85699 :               gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
    5024        85699 :               decl = TREE_OPERAND (decl, 1);
    5025              :             }
    5026              : 
    5027     94069319 :           decl = (adjust_result_of_qualified_name_lookup
    5028     94069319 :                   (decl, scope, current_nonlambda_class_type()));
    5029              : 
    5030     94069319 :           cp_warn_deprecated_use_scopes (scope);
    5031              : 
    5032     94069319 :           if (TYPE_P (scope))
    5033     13378326 :             decl = finish_qualified_id_expr (scope,
    5034              :                                              decl,
    5035              :                                              done,
    5036              :                                              address_p,
    5037              :                                              template_p,
    5038              :                                              template_arg_p,
    5039              :                                              tf_warning_or_error);
    5040              :           else
    5041     80690993 :             decl = convert_from_reference (decl);
    5042              :         }
    5043    629125039 :       else if (TREE_CODE (decl) == FIELD_DECL)
    5044              :         {
    5045     65559702 :           if (flag_contracts && processing_contract_condition
    5046           37 :               && contract_class_ptr == current_class_ptr)
    5047              :             {
    5048            6 :               error ("%qD 'this' required when accessing a member within a "
    5049              :                   "constructor precondition or destructor postcondition "
    5050              :                   "contract check", decl);
    5051            6 :                       return error_mark_node;
    5052              :             }
    5053              :           /* Since SCOPE is NULL here, this is an unqualified name.
    5054              :              Access checking has been performed during name lookup
    5055              :              already.  Turn off checking to avoid duplicate errors.  */
    5056     65559696 :           push_deferring_access_checks (dk_no_check);
    5057     65559696 :           decl = finish_non_static_data_member (decl, NULL_TREE,
    5058              :                                                 /*qualifying_scope=*/NULL_TREE);
    5059     65559696 :           pop_deferring_access_checks ();
    5060              :         }
    5061    563565337 :       else if (is_overloaded_fn (decl))
    5062              :         {
    5063              :           /* We only need to look at the first function,
    5064              :              because all the fns share the attribute we're
    5065              :              concerned with (all member fns or all non-members).  */
    5066     60320645 :           tree first_fn = get_first_fn (decl);
    5067     60320645 :           first_fn = STRIP_TEMPLATE (first_fn);
    5068              : 
    5069     60320645 :           if (!template_arg_p
    5070     60320645 :               && (TREE_CODE (first_fn) == USING_DECL
    5071     60318769 :                   || (TREE_CODE (first_fn) == FUNCTION_DECL
    5072     60318769 :                       && DECL_FUNCTION_MEMBER_P (first_fn)
    5073     36705664 :                       && !shared_member_p (decl))))
    5074              :             {
    5075              :               /* A set of member functions.  */
    5076     28321985 :               if (flag_contracts && processing_contract_condition
    5077           24 :                   && contract_class_ptr == current_class_ptr)
    5078              :                 {
    5079            3 :                   error ("%qD 'this' required when accessing a member within a "
    5080              :                       "constructor precondition or destructor postcondition "
    5081              :                       "contract check", decl);
    5082            3 :                   return error_mark_node;
    5083              :                 }
    5084     28321982 :               decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
    5085     28321982 :               return finish_class_member_access_expr (decl, id_expression,
    5086              :                                                       /*template_p=*/false,
    5087     28321982 :                                                       tf_warning_or_error);
    5088              :             }
    5089              : 
    5090     31998660 :           decl = baselink_for_fns (decl);
    5091              :         }
    5092              :       else
    5093              :         {
    5094    492356854 :           if (DECL_P (decl) && DECL_NONLOCAL (decl)
    5095    504701174 :               && DECL_CLASS_SCOPE_P (decl))
    5096              :             {
    5097      1456482 :               tree context = context_for_name_lookup (decl);
    5098      1456482 :               if (context != current_class_type)
    5099              :                 {
    5100       761814 :                   tree path = currently_open_derived_class (context);
    5101       761814 :                   if (!path)
    5102              :                     /* PATH can be null for using an enum of an unrelated
    5103              :                        class; we checked its access in lookup_using_decl.
    5104              : 
    5105              :                        ??? Should this case make a clone instead, like
    5106              :                        handle_using_decl?  */
    5107           43 :                     gcc_assert (TREE_CODE (decl) == CONST_DECL
    5108              :                                 /* This is for:
    5109              :                                     constexpr auto r = ^^S::i;
    5110              :                                     auto a = [:r:];  */
    5111              :                                 || flag_reflection);
    5112              :                   else
    5113       761771 :                     perform_or_defer_access_check (TYPE_BINFO (path),
    5114              :                                                    decl, decl,
    5115              :                                                    tf_warning_or_error);
    5116              :                 }
    5117              :             }
    5118              : 
    5119    503244692 :           decl = convert_from_reference (decl);
    5120              :         }
    5121              :     }
    5122              : 
    5123    710917612 :   check_param_in_postcondition (decl, location);
    5124    710917612 :   if (flag_contracts && processing_contract_condition)
    5125         2031 :     decl = constify_contract_access (decl);
    5126              : 
    5127    710917612 :   return cp_expr (decl, location);
    5128              : }
    5129              : 
    5130              : /* As per finish_id_expression_1, but adding a wrapper node
    5131              :    around the result if needed to express LOCATION.  */
    5132              : 
    5133              : cp_expr
    5134    757960594 : finish_id_expression (tree id_expression,
    5135              :                       tree decl,
    5136              :                       tree scope,
    5137              :                       cp_id_kind *idk,
    5138              :                       bool integral_constant_expression_p,
    5139              :                       bool allow_non_integral_constant_expression_p,
    5140              :                       bool *non_integral_constant_expression_p,
    5141              :                       bool template_p,
    5142              :                       bool done,
    5143              :                       bool address_p,
    5144              :                       bool template_arg_p,
    5145              :                       const char **error_msg,
    5146              :                       location_t location)
    5147              : {
    5148    757960594 :   cp_expr result
    5149    757960594 :     = finish_id_expression_1 (id_expression, decl, scope, idk,
    5150              :                               integral_constant_expression_p,
    5151              :                               allow_non_integral_constant_expression_p,
    5152              :                               non_integral_constant_expression_p,
    5153              :                               template_p, done, address_p, template_arg_p,
    5154              :                               error_msg, location);
    5155    757960591 :   return result.maybe_add_location_wrapper ();
    5156              : }
    5157              : 
    5158              : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
    5159              :    use as a type-specifier.  */
    5160              : 
    5161              : tree
    5162     21033172 : finish_typeof (tree expr)
    5163              : {
    5164     21033172 :   tree type;
    5165              : 
    5166     21033172 :   if (type_dependent_expression_p (expr))
    5167              :     {
    5168     20942249 :       type = cxx_make_type (TYPEOF_TYPE);
    5169     20942249 :       TYPEOF_TYPE_EXPR (type) = expr;
    5170     20942249 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
    5171              : 
    5172     20942249 :       return type;
    5173              :     }
    5174              : 
    5175        90923 :   expr = mark_type_use (expr);
    5176              : 
    5177        90923 :   type = unlowered_expr_type (expr);
    5178              : 
    5179        90923 :   if (!type || type == unknown_type_node)
    5180              :     {
    5181            3 :       error ("type of %qE is unknown", expr);
    5182            3 :       return error_mark_node;
    5183              :     }
    5184              : 
    5185              :   return type;
    5186              : }
    5187              : 
    5188              : /* Implement the __underlying_type keyword: Return the underlying
    5189              :    type of TYPE, suitable for use as a type-specifier.  */
    5190              : 
    5191              : tree
    5192        46669 : finish_underlying_type (tree type)
    5193              : {
    5194        46669 :   if (!complete_type_or_else (type, NULL_TREE))
    5195            3 :     return error_mark_node;
    5196              : 
    5197        46666 :   if (TREE_CODE (type) != ENUMERAL_TYPE)
    5198              :     {
    5199           24 :       error ("%qT is not an enumeration type", type);
    5200           24 :       return error_mark_node;
    5201              :     }
    5202              : 
    5203        46642 :   tree underlying_type = ENUM_UNDERLYING_TYPE (type);
    5204              : 
    5205              :   /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
    5206              :      includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
    5207              :      See finish_enum_value_list for details.  */
    5208        46642 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
    5209           56 :     underlying_type
    5210           56 :       = c_common_type_for_mode (TYPE_MODE (underlying_type),
    5211           56 :                                 TYPE_UNSIGNED (underlying_type));
    5212              : 
    5213              :   return underlying_type;
    5214              : }
    5215              : 
    5216              : /* Implement the __type_pack_element keyword: Return the type
    5217              :    at index IDX within TYPES.  */
    5218              : 
    5219              : static tree
    5220       117928 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
    5221              : {
    5222       117928 :   idx = maybe_constant_value (idx, NULL_TREE, mce_true);
    5223       117928 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
    5224              :     {
    5225            6 :       if (complain & tf_error)
    5226            3 :         error ("pack index has non-integral type %qT", TREE_TYPE (idx));
    5227            6 :       return error_mark_node;
    5228              :     }
    5229       117922 :   if (TREE_CODE (idx) != INTEGER_CST)
    5230              :     {
    5231            2 :       if (complain & tf_error)
    5232              :         {
    5233            2 :           error ("pack index is not an integral constant");
    5234            2 :           cxx_constant_value (idx);
    5235              :         }
    5236            2 :       return error_mark_node;
    5237              :     }
    5238       117920 :   if (tree_int_cst_sgn (idx) < 0)
    5239              :     {
    5240            3 :       if (complain & tf_error)
    5241            3 :         error ("pack index %qE is negative", idx);
    5242            3 :       return error_mark_node;
    5243              :     }
    5244       117917 :   if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
    5245              :     {
    5246           34 :       if (complain & tf_error)
    5247           28 :         error ("pack index %qE is out of range for pack of length %qd",
    5248           28 :                idx, TREE_VEC_LENGTH (types));
    5249           34 :       return error_mark_node;
    5250              :     }
    5251       117883 :   return TREE_VEC_ELT (types, tree_to_shwi (idx));
    5252              : }
    5253              : 
    5254              : /* In a pack-index T...[N], return the element at index IDX within TYPES.
    5255              :    PARENTHESIZED_P is true iff the pack index was wrapped in ().  */
    5256              : 
    5257              : tree
    5258        10948 : pack_index_element (tree idx, tree types, bool parenthesized_p,
    5259              :                     tsubst_flags_t complain)
    5260              : {
    5261        10948 :   tree r = finish_type_pack_element (idx, types, complain);
    5262        10948 :   if (parenthesized_p)
    5263              :     /* For the benefit of decltype(auto).  */
    5264           35 :     r = force_paren_expr (r);
    5265        10948 :   return r;
    5266              : }
    5267              : 
    5268              : /* Implement the __direct_bases keyword: Return the direct base classes
    5269              :    of type.  */
    5270              : 
    5271              : tree
    5272           15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
    5273              : {
    5274           15 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5275           15 :       || !NON_UNION_CLASS_TYPE_P (type))
    5276            8 :     return make_tree_vec (0);
    5277              : 
    5278            7 :   releasing_vec vector;
    5279            7 :   vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
    5280            7 :   tree binfo;
    5281            7 :   unsigned i;
    5282              : 
    5283              :   /* Virtual bases are initialized first */
    5284           20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5285           13 :     if (BINFO_VIRTUAL_P (binfo))
    5286            2 :       vec_safe_push (vector, binfo);
    5287              : 
    5288              :   /* Now non-virtuals */
    5289           20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5290           13 :     if (!BINFO_VIRTUAL_P (binfo))
    5291           11 :       vec_safe_push (vector, binfo);
    5292              : 
    5293            7 :   tree bases_vec = make_tree_vec (vector->length ());
    5294              : 
    5295           27 :   for (i = 0; i < vector->length (); ++i)
    5296           13 :     TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
    5297              : 
    5298            7 :   return bases_vec;
    5299            7 : }
    5300              : 
    5301              : /* Implement the __bases keyword: Return the base classes
    5302              :    of type */
    5303              : 
    5304              : /* Find morally non-virtual base classes by walking binfo hierarchy */
    5305              : /* Virtual base classes are handled separately in finish_bases */
    5306              : 
    5307              : static tree
    5308           73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
    5309              : {
    5310              :   /* Don't walk bases of virtual bases */
    5311           73 :   return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
    5312              : }
    5313              : 
    5314              : static tree
    5315           73 : dfs_calculate_bases_post (tree binfo, void *data_)
    5316              : {
    5317           73 :   vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
    5318           73 :   if (!BINFO_VIRTUAL_P (binfo))
    5319           48 :     vec_safe_push (*data, BINFO_TYPE (binfo));
    5320           73 :   return NULL_TREE;
    5321              : }
    5322              : 
    5323              : /* Calculates the morally non-virtual base classes of a class */
    5324              : static vec<tree, va_gc> *
    5325           16 : calculate_bases_helper (tree type)
    5326              : {
    5327           16 :   vec<tree, va_gc> *vector = make_tree_vector ();
    5328              : 
    5329              :   /* Now add non-virtual base classes in order of construction */
    5330           16 :   if (TYPE_BINFO (type))
    5331           16 :     dfs_walk_all (TYPE_BINFO (type),
    5332              :                   dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
    5333           16 :   return vector;
    5334              : }
    5335              : 
    5336              : tree
    5337           12 : calculate_bases (tree type, tsubst_flags_t complain)
    5338              : {
    5339           12 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5340           12 :       || !NON_UNION_CLASS_TYPE_P (type))
    5341            5 :     return make_tree_vec (0);
    5342              : 
    5343            7 :   releasing_vec vector;
    5344            7 :   tree bases_vec = NULL_TREE;
    5345            7 :   unsigned i;
    5346            7 :   vec<tree, va_gc> *vbases;
    5347            7 :   tree binfo;
    5348              : 
    5349              :   /* First go through virtual base classes */
    5350            7 :   for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
    5351           16 :        vec_safe_iterate (vbases, i, &binfo); i++)
    5352              :     {
    5353            9 :       releasing_vec vbase_bases
    5354            9 :         = calculate_bases_helper (BINFO_TYPE (binfo));
    5355            9 :       vec_safe_splice (vector, vbase_bases);
    5356            9 :     }
    5357              : 
    5358              :   /* Now for the non-virtual bases */
    5359            7 :   releasing_vec nonvbases = calculate_bases_helper (type);
    5360            7 :   vec_safe_splice (vector, nonvbases);
    5361              : 
    5362              :   /* Note that during error recovery vector->length can even be zero.  */
    5363            7 :   if (vector->length () > 1)
    5364              :     {
    5365              :       /* Last element is entire class, so don't copy */
    5366            6 :       bases_vec = make_tree_vec (vector->length () - 1);
    5367              : 
    5368           53 :       for (i = 0; i < vector->length () - 1; ++i)
    5369           41 :         TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
    5370              :     }
    5371              :   else
    5372            1 :     bases_vec = make_tree_vec (0);
    5373              : 
    5374            7 :   return bases_vec;
    5375            7 : }
    5376              : 
    5377              : tree
    5378           28 : finish_bases (tree type, bool direct)
    5379              : {
    5380           28 :   tree bases = NULL_TREE;
    5381              : 
    5382           28 :   if (!processing_template_decl)
    5383              :     {
    5384              :       /* Parameter packs can only be used in templates */
    5385            0 :       error ("parameter pack %<__bases%> only valid in template declaration");
    5386            0 :       return error_mark_node;
    5387              :     }
    5388              : 
    5389           28 :   bases = cxx_make_type (BASES);
    5390           28 :   BASES_TYPE (bases) = type;
    5391           28 :   BASES_DIRECT (bases) = direct;
    5392           28 :   SET_TYPE_STRUCTURAL_EQUALITY (bases);
    5393              : 
    5394           28 :   return bases;
    5395              : }
    5396              : 
    5397              : /* Perform C++-specific checks for __builtin_offsetof before calling
    5398              :    fold_offsetof.  */
    5399              : 
    5400              : tree
    5401         2419 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
    5402              : {
    5403              :   /* If we're processing a template, we can't finish the semantics yet.
    5404              :      Otherwise we can fold the entire expression now.  */
    5405         2419 :   if (processing_template_decl)
    5406              :     {
    5407           60 :       expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
    5408           60 :       SET_EXPR_LOCATION (expr, loc);
    5409           60 :       return expr;
    5410              :     }
    5411              : 
    5412         2359 :   if (expr == error_mark_node)
    5413              :     return error_mark_node;
    5414              : 
    5415         2342 :   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
    5416              :     {
    5417            6 :       error ("cannot apply %<offsetof%> to destructor %<~%T%>",
    5418            6 :               TREE_OPERAND (expr, 2));
    5419            6 :       return error_mark_node;
    5420              :     }
    5421         4657 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
    5422         4657 :       || TREE_TYPE (expr) == unknown_type_node)
    5423              :     {
    5424           30 :       while (TREE_CODE (expr) == COMPONENT_REF
    5425           30 :              || TREE_CODE (expr) == COMPOUND_EXPR)
    5426           12 :         expr = TREE_OPERAND (expr, 1);
    5427              : 
    5428           18 :       if (DECL_P (expr))
    5429              :         {
    5430            0 :           auto_diagnostic_group d;
    5431            0 :           error ("cannot apply %<offsetof%> to member function %qD", expr);
    5432            0 :           inform (DECL_SOURCE_LOCATION (expr), "declared here");
    5433            0 :         }
    5434              :       else
    5435           18 :         error ("cannot apply %<offsetof%> to member function");
    5436           18 :       return error_mark_node;
    5437              :     }
    5438         2318 :   if (TREE_CODE (expr) == CONST_DECL)
    5439              :     {
    5440            3 :       error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
    5441            3 :       return error_mark_node;
    5442              :     }
    5443         2315 :   if (REFERENCE_REF_P (expr))
    5444            9 :     expr = TREE_OPERAND (expr, 0);
    5445         2315 :   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
    5446            3 :     return error_mark_node;
    5447         2312 :   if (warn_invalid_offsetof
    5448         2312 :       && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
    5449         2312 :       && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
    5450         2357 :       && cp_unevaluated_operand == 0)
    5451           45 :     warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
    5452              :                 "non-standard-layout type %qT is conditionally-supported",
    5453           45 :                 TREE_TYPE (TREE_TYPE (object_ptr)));
    5454         2312 :   return fold_offsetof (expr);
    5455              : }
    5456              : 
    5457              : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR.  This
    5458              :    function is broken out from the above for the benefit of the tree-ssa
    5459              :    project.  */
    5460              : 
    5461              : void
    5462       337769 : simplify_aggr_init_expr (tree *tp)
    5463              : {
    5464       337769 :   tree aggr_init_expr = *tp;
    5465              : 
    5466              :   /* Form an appropriate CALL_EXPR.  */
    5467       337769 :   tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
    5468       337769 :   tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
    5469       337769 :   tree type = TREE_TYPE (slot);
    5470              : 
    5471       337769 :   tree call_expr;
    5472       337769 :   enum style_t { ctor, arg, pcc } style;
    5473              : 
    5474       337769 :   if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
    5475              :     style = ctor;
    5476              : #ifdef PCC_STATIC_STRUCT_RETURN
    5477              :   else if (1)
    5478              :     style = pcc;
    5479              : #endif
    5480              :   else
    5481              :     {
    5482        91737 :       gcc_assert (TREE_ADDRESSABLE (type));
    5483              :       style = arg;
    5484              :     }
    5485              : 
    5486       337769 :   call_expr = build_call_array_loc (input_location,
    5487       337769 :                                     TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
    5488              :                                     fn,
    5489       337769 :                                     aggr_init_expr_nargs (aggr_init_expr),
    5490       337769 :                                     AGGR_INIT_EXPR_ARGP (aggr_init_expr));
    5491       337769 :   TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
    5492       337769 :   CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
    5493       337769 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr)
    5494       337769 :     = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
    5495       337769 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
    5496       337769 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
    5497       337769 :   CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
    5498              : 
    5499       337769 :   if (style == ctor)
    5500              :     {
    5501              :       /* Replace the first argument to the ctor with the address of the
    5502              :          slot.  */
    5503       246032 :       cxx_mark_addressable (slot);
    5504       246032 :       CALL_EXPR_ARG (call_expr, 0) =
    5505       246032 :         build1 (ADDR_EXPR, build_pointer_type (type), slot);
    5506              :     }
    5507        91737 :   else if (style == arg)
    5508              :     {
    5509              :       /* Just mark it addressable here, and leave the rest to
    5510              :          expand_call{,_inline}.  */
    5511        91737 :       cxx_mark_addressable (slot);
    5512        91737 :       CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
    5513        91737 :       call_expr = cp_build_init_expr (slot, call_expr);
    5514              :     }
    5515              :   else if (style == pcc)
    5516              :     {
    5517              :       /* If we're using the non-reentrant PCC calling convention, then we
    5518              :          need to copy the returned value out of the static buffer into the
    5519              :          SLOT.  */
    5520              :       push_deferring_access_checks (dk_no_check);
    5521              :       call_expr = build_aggr_init (slot, call_expr,
    5522              :                                    DIRECT_BIND | LOOKUP_ONLYCONVERTING,
    5523              :                                    tf_warning_or_error);
    5524              :       pop_deferring_access_checks ();
    5525              :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
    5526              :     }
    5527              : 
    5528       337769 :   if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
    5529              :     {
    5530         3465 :       tree init = build_zero_init (type, NULL_TREE,
    5531              :                                    /*static_storage_p=*/false);
    5532         3465 :       init = cp_build_init_expr (slot, init);
    5533         3465 :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
    5534              :                           init, call_expr);
    5535              :     }
    5536              : 
    5537       337769 :   *tp = call_expr;
    5538       337769 : }
    5539              : 
    5540              : /* Emit all thunks to FN that should be emitted when FN is emitted.  */
    5541              : 
    5542              : void
    5543     57939508 : emit_associated_thunks (tree fn)
    5544              : {
    5545              :   /* When we use vcall offsets, we emit thunks with the virtual
    5546              :      functions to which they thunk. The whole point of vcall offsets
    5547              :      is so that you can know statically the entire set of thunks that
    5548              :      will ever be needed for a given virtual function, thereby
    5549              :      enabling you to output all the thunks with the function itself.  */
    5550     57939508 :   if (DECL_VIRTUAL_P (fn)
    5551              :       /* Do not emit thunks for extern template instantiations.  */
    5552      1099309 :       && ! DECL_REALLY_EXTERN (fn)
    5553              :       /* Do not emit thunks for tentative decls, those will be processed
    5554              :          again at_eof if really needed.  */
    5555     58939797 :       && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
    5556              :     {
    5557       999327 :       tree thunk;
    5558              : 
    5559      2002862 :       for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
    5560              :         {
    5561         4208 :           if (!THUNK_ALIAS (thunk))
    5562              :             {
    5563         4208 :               use_thunk (thunk, /*emit_p=*/1);
    5564         4208 :               if (DECL_RESULT_THUNK_P (thunk))
    5565              :                 {
    5566          178 :                   tree probe;
    5567              : 
    5568          178 :                   for (probe = DECL_THUNKS (thunk);
    5569          327 :                        probe; probe = DECL_CHAIN (probe))
    5570          149 :                     use_thunk (probe, /*emit_p=*/1);
    5571              :                 }
    5572              :             }
    5573              :           else
    5574            0 :             gcc_assert (!DECL_THUNKS (thunk));
    5575              :         }
    5576              :     }
    5577     57939508 : }
    5578              : 
    5579              : /* Generate RTL for FN.  */
    5580              : 
    5581              : bool
    5582    157963064 : expand_or_defer_fn_1 (tree fn)
    5583              : {
    5584              :   /* When the parser calls us after finishing the body of a template
    5585              :      function, we don't really want to expand the body.  */
    5586    157963064 :   if (processing_template_decl)
    5587              :     {
    5588              :       /* Normally, collection only occurs in rest_of_compilation.  So,
    5589              :          if we don't collect here, we never collect junk generated
    5590              :          during the processing of templates until we hit a
    5591              :          non-template function.  It's not safe to do this inside a
    5592              :          nested class, though, as the parser may have local state that
    5593              :          is not a GC root.  */
    5594     92254897 :       if (!function_depth)
    5595     91817224 :         ggc_collect ();
    5596     92254897 :       return false;
    5597              :     }
    5598              : 
    5599     65708167 :   gcc_assert (DECL_SAVED_TREE (fn));
    5600              : 
    5601              :   /* We make a decision about linkage for these functions at the end
    5602              :      of the compilation.  Until that point, we do not want the back
    5603              :      end to output them -- but we do want it to see the bodies of
    5604              :      these functions so that it can inline them as appropriate.  */
    5605     65708167 :   if (DECL_DECLARED_INLINE_P (fn)
    5606      1876498 :       || DECL_IMPLICIT_INSTANTIATION (fn)
    5607     65966396 :       || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
    5608              :     {
    5609     65449965 :       if (DECL_INTERFACE_KNOWN (fn))
    5610              :         /* We've already made a decision as to how this function will
    5611              :            be handled.  */;
    5612     46236748 :       else if (!at_eof
    5613     16621875 :                || DECL_IMMEDIATE_FUNCTION_P (fn)
    5614     62430725 :                || DECL_OMP_DECLARE_REDUCTION_P (fn))
    5615     30042771 :         tentative_decl_linkage (fn);
    5616              :       else
    5617     16193977 :         import_export_decl (fn);
    5618              : 
    5619              :       /* If the user wants us to keep all inline functions, then mark
    5620              :          this function as needed so that finish_file will make sure to
    5621              :          output it later.  Similarly, all dllexport'd functions must
    5622              :          be emitted; there may be callers in other DLLs.  */
    5623     65449965 :       if (DECL_DECLARED_INLINE_P (fn)
    5624     63831669 :           && !DECL_REALLY_EXTERN (fn)
    5625     60251284 :           && !DECL_IMMEDIATE_FUNCTION_P (fn)
    5626     59222278 :           && !DECL_OMP_DECLARE_REDUCTION_P (fn)
    5627    124672243 :           && (flag_keep_inline_functions
    5628     59219488 :               || (flag_keep_inline_dllexport
    5629     59219488 :                   && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
    5630              :         {
    5631         2790 :           mark_needed (fn);
    5632         2790 :           DECL_EXTERNAL (fn) = 0;
    5633              :         }
    5634              :     }
    5635              : 
    5636              :   /* If this is a constructor or destructor body, we have to clone
    5637              :      it.  */
    5638     65708167 :   if (maybe_clone_body (fn))
    5639              :     {
    5640              :       /* We don't want to process FN again, so pretend we've written
    5641              :          it out, even though we haven't.  */
    5642      7740457 :       TREE_ASM_WRITTEN (fn) = 1;
    5643              :       /* If this is a constexpr function we still need the body to be
    5644              :          able to evaluate it.  Similarly, with modules we only stream
    5645              :          the maybe-in-charge cdtor and regenerate the clones from it on
    5646              :          demand, so we also need to keep the body.  Otherwise we don't
    5647              :          need it anymore.  */
    5648      7740457 :       if (!maybe_constexpr_fn (fn)
    5649      7740457 :           && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
    5650      3668988 :         DECL_SAVED_TREE (fn) = void_node;
    5651      7740457 :       return false;
    5652              :     }
    5653              : 
    5654              :   /* There's no reason to do any of the work here if we're only doing
    5655              :      semantic analysis; this code just generates RTL.  */
    5656     57967710 :   if (flag_syntax_only)
    5657              :     {
    5658              :       /* Pretend that this function has been written out so that we don't try
    5659              :          to expand it again.  */
    5660        28186 :       TREE_ASM_WRITTEN (fn) = 1;
    5661        28186 :       return false;
    5662              :     }
    5663              : 
    5664     57939524 :   if (DECL_OMP_DECLARE_REDUCTION_P (fn))
    5665              :     return false;
    5666              : 
    5667              :   return true;
    5668              : }
    5669              : 
    5670              : void
    5671    150246507 : expand_or_defer_fn (tree fn)
    5672              : {
    5673    150246507 :   if (expand_or_defer_fn_1 (fn))
    5674              :     {
    5675     50225440 :       function_depth++;
    5676              : 
    5677              :       /* Expand or defer, at the whim of the compilation unit manager.  */
    5678     50225440 :       cgraph_node::finalize_function (fn, function_depth > 1);
    5679     50225440 :       emit_associated_thunks (fn);
    5680              : 
    5681     50225440 :       function_depth--;
    5682              : 
    5683    100450880 :       if (DECL_IMMEDIATE_FUNCTION_P (fn))
    5684              :         {
    5685       970900 :           if (cgraph_node *node = cgraph_node::get (fn))
    5686              :             {
    5687       970900 :               node->body_removed = true;
    5688       970900 :               node->analyzed = false;
    5689       970900 :               node->definition = false;
    5690       970900 :               node->force_output = false;
    5691              :             }
    5692              :         }
    5693              :     }
    5694    150246507 : }
    5695              : 
    5696       437918 : class nrv_data
    5697              : {
    5698              : public:
    5699       218959 :   nrv_data () : visited (37) {}
    5700              : 
    5701              :   tree var;
    5702              :   tree result;
    5703              :   hash_set<tree> visited;
    5704              :   bool simple;
    5705              :   bool in_nrv_cleanup;
    5706              : };
    5707              : 
    5708              : /* Helper function for walk_tree, used by finalize_nrv below.  */
    5709              : 
    5710              : static tree
    5711     19971293 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
    5712              : {
    5713     19971293 :   class nrv_data *dp = (class nrv_data *)data;
    5714              : 
    5715              :   /* No need to walk into types.  There wouldn't be any need to walk into
    5716              :      non-statements, except that we have to consider STMT_EXPRs.  */
    5717     19971293 :   if (TYPE_P (*tp))
    5718       181650 :     *walk_subtrees = 0;
    5719              : 
    5720              :   /* Replace all uses of the NRV with the RESULT_DECL.  */
    5721     19789643 :   else if (*tp == dp->var)
    5722       475077 :     *tp = dp->result;
    5723              : 
    5724              :   /* Avoid walking into the same tree more than once.  Unfortunately, we
    5725              :      can't just use walk_tree_without duplicates because it would only call
    5726              :      us for the first occurrence of dp->var in the function body.  */
    5727     19314566 :   else if (dp->visited.add (*tp))
    5728      4271915 :     *walk_subtrees = 0;
    5729              : 
    5730              :   /* If there's a label, we might need to destroy the NRV on goto (92407).  */
    5731     15042651 :   else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
    5732            3 :     dp->simple = false;
    5733              :   /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
    5734              :      but differs from using NULL_TREE in that it indicates that we care
    5735              :      about the value of the RESULT_DECL.  But preserve anything appended
    5736              :      by check_return_expr.  */
    5737     15042648 :   else if (TREE_CODE (*tp) == RETURN_EXPR)
    5738              :     {
    5739       223989 :       tree *p = &TREE_OPERAND (*tp, 0);
    5740       573571 :       while (TREE_CODE (*p) == COMPOUND_EXPR)
    5741       125593 :         p = &TREE_OPERAND (*p, 0);
    5742       223989 :       if (TREE_CODE (*p) == INIT_EXPR
    5743       223989 :           && INIT_EXPR_NRV_P (*p))
    5744       223591 :         *p = dp->result;
    5745              :     }
    5746              :   /* Change all cleanups for the NRV to only run when not returning.  */
    5747     14818659 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5748     14818659 :            && CLEANUP_DECL (*tp) == dp->var)
    5749              :     {
    5750       121529 :       dp->in_nrv_cleanup = true;
    5751       121529 :       cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
    5752       121529 :       dp->in_nrv_cleanup = false;
    5753       121529 :       cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
    5754       121529 :       *walk_subtrees = 0;
    5755              : 
    5756       121529 :       if (dp->simple)
    5757              :         /* For a simple NRV, just run it on the EH path.  */
    5758       120911 :         CLEANUP_EH_ONLY (*tp) = true;
    5759              :       else
    5760              :         {
    5761              :           /* Not simple, we need to check current_retval_sentinel to decide
    5762              :              whether to run it.  If it's set, we're returning normally and
    5763              :              don't want to destroy the NRV.  If the sentinel is not set, we're
    5764              :              leaving scope some other way, either by flowing off the end of its
    5765              :              scope or throwing an exception.  */
    5766         1854 :           tree cond = build3 (COND_EXPR, void_type_node,
    5767          618 :                               current_retval_sentinel,
    5768          618 :                               void_node, CLEANUP_EXPR (*tp));
    5769          618 :           CLEANUP_EXPR (*tp) = cond;
    5770              :         }
    5771              : 
    5772              :       /* If a cleanup might throw, we need to clear current_retval_sentinel on
    5773              :          the exception path, both so the check above succeeds and so an outer
    5774              :          cleanup added by maybe_splice_retval_cleanup doesn't run.  */
    5775       121529 :       if (cp_function_chain->throwing_cleanup)
    5776              :         {
    5777          166 :           tree clear = build2 (MODIFY_EXPR, boolean_type_node,
    5778              :                                current_retval_sentinel,
    5779              :                                boolean_false_node);
    5780          166 :           if (dp->simple)
    5781              :             {
    5782              :               /* We're already only on the EH path, just prepend it.  */
    5783          156 :               tree &exp = CLEANUP_EXPR (*tp);
    5784          156 :               exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
    5785              :             }
    5786              :           else
    5787              :             {
    5788              :               /* The cleanup runs on both normal and EH paths, we need another
    5789              :                  CLEANUP_STMT to clear the flag only on the EH path.  */
    5790           10 :               tree &bod = CLEANUP_BODY (*tp);
    5791           10 :               bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
    5792           10 :                                 bod, clear, current_retval_sentinel);
    5793           10 :               CLEANUP_EH_ONLY (bod) = true;
    5794              :             }
    5795              :         }
    5796              :     }
    5797              :   /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
    5798              :      want to destroy the retval before the variable goes out of scope.  */
    5799     14697130 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5800         4356 :            && dp->in_nrv_cleanup
    5801     14700094 :            && CLEANUP_DECL (*tp) == dp->result)
    5802            6 :     CLEANUP_EXPR (*tp) = void_node;
    5803              :   /* Replace the DECL_EXPR for the NRV with an initialization of the
    5804              :      RESULT_DECL, if needed.  */
    5805     14697124 :   else if (TREE_CODE (*tp) == DECL_EXPR
    5806     14697124 :            && DECL_EXPR_DECL (*tp) == dp->var)
    5807              :     {
    5808       218961 :       tree init;
    5809       218961 :       if (DECL_INITIAL (dp->var)
    5810       218961 :           && DECL_INITIAL (dp->var) != error_mark_node)
    5811        90156 :         init = cp_build_init_expr (dp->result,
    5812        90156 :                        DECL_INITIAL (dp->var));
    5813              :       else
    5814       128805 :         init = build_empty_stmt (EXPR_LOCATION (*tp));
    5815       218961 :       DECL_INITIAL (dp->var) = NULL_TREE;
    5816       218961 :       SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
    5817       218961 :       *tp = init;
    5818              :     }
    5819              : 
    5820              :   /* Keep iterating.  */
    5821     19971293 :   return NULL_TREE;
    5822              : }
    5823              : 
    5824              : /* Called from finish_function to implement the named return value
    5825              :    optimization by overriding all the RETURN_EXPRs and pertinent
    5826              :    CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
    5827              :    RESULT_DECL for the function.  */
    5828              : 
    5829              : void
    5830       218959 : finalize_nrv (tree fndecl, tree var)
    5831              : {
    5832       218959 :   class nrv_data data;
    5833       218959 :   tree result = DECL_RESULT (fndecl);
    5834              : 
    5835              :   /* Copy name from VAR to RESULT.  */
    5836       218959 :   DECL_NAME (result) = DECL_NAME (var);
    5837              :   /* Don't forget that we take its address.  */
    5838       218959 :   TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
    5839              :   /* Finally set DECL_VALUE_EXPR to avoid assigning
    5840              :      a stack slot at -O0 for the original var and debug info
    5841              :      uses RESULT location for VAR.  */
    5842       218959 :   SET_DECL_VALUE_EXPR (var, result);
    5843       218959 :   DECL_HAS_VALUE_EXPR_P (var) = 1;
    5844              : 
    5845       218959 :   data.var = var;
    5846       218959 :   data.result = result;
    5847       218959 :   data.in_nrv_cleanup = false;
    5848              : 
    5849              :   /* This is simpler for variables declared in the outer scope of
    5850              :      the function so we know that their lifetime always ends with a
    5851              :      return; see g++.dg/opt/nrv6.C.  */
    5852       218959 :   tree outer = outer_curly_brace_block (fndecl);
    5853       218959 :   data.simple = chain_member (var, BLOCK_VARS (outer));
    5854              : 
    5855       218959 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
    5856       218959 : }
    5857              : 
    5858              : /* Create CP_OMP_CLAUSE_INFO for clause C.  Returns true if it is invalid.  */
    5859              : 
    5860              : bool
    5861         2240 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
    5862              :                             bool need_copy_ctor, bool need_copy_assignment,
    5863              :                             bool need_dtor)
    5864              : {
    5865         2240 :   int save_errorcount = errorcount;
    5866         2240 :   tree info, t;
    5867              : 
    5868              :   /* Always allocate 3 elements for simplicity.  These are the
    5869              :      function decls for the ctor, dtor, and assignment op.
    5870              :      This layout is known to the three lang hooks,
    5871              :      cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
    5872              :      and cxx_omp_clause_assign_op.  */
    5873         2240 :   info = make_tree_vec (3);
    5874         2240 :   CP_OMP_CLAUSE_INFO (c) = info;
    5875              : 
    5876         2240 :   if (need_default_ctor || need_copy_ctor)
    5877              :     {
    5878         1654 :       if (need_default_ctor)
    5879         1255 :         t = get_default_ctor (type);
    5880              :       else
    5881          399 :         t = get_copy_ctor (type, tf_warning_or_error);
    5882              : 
    5883         1654 :       if (t && !trivial_fn_p (t))
    5884         1400 :         TREE_VEC_ELT (info, 0) = t;
    5885              :     }
    5886              : 
    5887         2240 :   if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5888         1632 :     TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
    5889              : 
    5890         2240 :   if (need_copy_assignment)
    5891              :     {
    5892          397 :       t = get_copy_assign (type);
    5893              : 
    5894          397 :       if (t && !trivial_fn_p (t))
    5895          344 :         TREE_VEC_ELT (info, 2) = t;
    5896              :     }
    5897              : 
    5898         2240 :   return errorcount != save_errorcount;
    5899              : }
    5900              : 
    5901              : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
    5902              :    FIELD_DECL, otherwise return DECL itself.  */
    5903              : 
    5904              : static tree
    5905        26244 : omp_clause_decl_field (tree decl)
    5906              : {
    5907        26244 :   if (VAR_P (decl)
    5908        18397 :       && DECL_HAS_VALUE_EXPR_P (decl)
    5909          359 :       && DECL_ARTIFICIAL (decl)
    5910          359 :       && DECL_LANG_SPECIFIC (decl)
    5911        26579 :       && DECL_OMP_PRIVATIZED_MEMBER (decl))
    5912              :     {
    5913          328 :       tree f = DECL_VALUE_EXPR (decl);
    5914          328 :       if (INDIRECT_REF_P (f))
    5915            0 :         f = TREE_OPERAND (f, 0);
    5916          328 :       if (TREE_CODE (f) == COMPONENT_REF)
    5917              :         {
    5918          328 :           f = TREE_OPERAND (f, 1);
    5919          328 :           gcc_assert (TREE_CODE (f) == FIELD_DECL);
    5920              :           return f;
    5921              :         }
    5922              :     }
    5923              :   return NULL_TREE;
    5924              : }
    5925              : 
    5926              : /* Adjust DECL if needed for printing using %qE.  */
    5927              : 
    5928              : static tree
    5929          187 : omp_clause_printable_decl (tree decl)
    5930              : {
    5931            0 :   tree t = omp_clause_decl_field (decl);
    5932          187 :   if (t)
    5933           45 :     return t;
    5934              :   return decl;
    5935              : }
    5936              : 
    5937              : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
    5938              :    VAR_DECL T that doesn't need a DECL_EXPR added, record it for
    5939              :    privatization.  */
    5940              : 
    5941              : static void
    5942          219 : omp_note_field_privatization (tree f, tree t)
    5943              : {
    5944          219 :   if (!omp_private_member_map)
    5945           71 :     omp_private_member_map = new hash_map<tree, tree>;
    5946          219 :   tree &v = omp_private_member_map->get_or_insert (f);
    5947          219 :   if (v == NULL_TREE)
    5948              :     {
    5949          146 :       v = t;
    5950          146 :       omp_private_member_vec.safe_push (f);
    5951              :       /* Signal that we don't want to create DECL_EXPR for this dummy var.  */
    5952          146 :       omp_private_member_vec.safe_push (integer_zero_node);
    5953              :     }
    5954          219 : }
    5955              : 
    5956              : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
    5957              :    dummy VAR_DECL.  */
    5958              : 
    5959              : tree
    5960          861 : omp_privatize_field (tree t, bool shared)
    5961              : {
    5962          861 :   tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    5963          861 :   if (m == error_mark_node)
    5964              :     return error_mark_node;
    5965          861 :   if (!omp_private_member_map && !shared)
    5966          365 :     omp_private_member_map = new hash_map<tree, tree>;
    5967          861 :   if (TYPE_REF_P (TREE_TYPE (t)))
    5968              :     {
    5969          123 :       gcc_assert (INDIRECT_REF_P (m));
    5970          123 :       m = TREE_OPERAND (m, 0);
    5971              :     }
    5972          861 :   tree vb = NULL_TREE;
    5973          861 :   tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
    5974          861 :   if (v == NULL_TREE)
    5975              :     {
    5976          770 :       v = create_temporary_var (TREE_TYPE (m));
    5977          770 :       retrofit_lang_decl (v);
    5978          770 :       DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
    5979          770 :       SET_DECL_VALUE_EXPR (v, m);
    5980          770 :       DECL_HAS_VALUE_EXPR_P (v) = 1;
    5981          770 :       if (!shared)
    5982          690 :         omp_private_member_vec.safe_push (t);
    5983              :     }
    5984          861 :   return v;
    5985              : }
    5986              : 
    5987              : /* C++ specialisation of the c_omp_address_inspector class.  */
    5988              : 
    5989              : class cp_omp_address_inspector : public c_omp_address_inspector
    5990              : {
    5991              : public:
    5992        30908 :   cp_omp_address_inspector (location_t loc, tree t)
    5993        30908 :     : c_omp_address_inspector (loc, t)
    5994              :     {
    5995              :     }
    5996              : 
    5997        30908 :   ~cp_omp_address_inspector ()
    5998              :     {
    5999        22599 :     }
    6000              : 
    6001       131228 :   bool processing_template_decl_p ()
    6002              :     {
    6003       131228 :       return processing_template_decl;
    6004              :     }
    6005              : 
    6006            0 :   void emit_unmappable_type_notes (tree t)
    6007              :     {
    6008            0 :       if (TREE_TYPE (t) != error_mark_node
    6009            0 :           && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    6010            0 :         cxx_incomplete_type_inform (TREE_TYPE (t));
    6011            0 :     }
    6012              : 
    6013         1062 :   tree convert_from_reference (tree x)
    6014              :     {
    6015         1062 :       return ::convert_from_reference (x);
    6016              :     }
    6017              : 
    6018          145 :   tree build_array_ref (location_t loc, tree arr, tree idx)
    6019              :     {
    6020          145 :       return ::build_array_ref (loc, arr, idx);
    6021              :     }
    6022              : 
    6023        22541 :   bool check_clause (tree clause)
    6024              :     {
    6025        22541 :       if (TREE_CODE (orig) == COMPONENT_REF
    6026        22541 :           && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
    6027              :                                         tf_warning_or_error))
    6028              :         return false;
    6029        22538 :       if (!c_omp_address_inspector::check_clause (clause))
    6030              :         return false;
    6031              :       return true;
    6032              :     }
    6033              : };
    6034              : 
    6035              : /* Helper function for handle_omp_array_sections.  Called recursively
    6036              :    to handle multiple array-section-subscripts.  C is the clause,
    6037              :    T current expression (initially OMP_CLAUSE_DECL), which is either
    6038              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
    6039              :    expression if specified, TREE_VALUE length expression if specified,
    6040              :    TREE_CHAIN is what it has been specified after, or some decl.
    6041              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
    6042              :    set to true if any of the array-section-subscript could have length
    6043              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
    6044              :    first array-section-subscript which is known not to have length
    6045              :    of one.  Given say:
    6046              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
    6047              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
    6048              :    all are or may have length of 1, array-section-subscript [:2] is the
    6049              :    first one known not to have length 1.  For array-section-subscript
    6050              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
    6051              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
    6052              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
    6053              :    case though, as some lengths could be zero.  */
    6054              : 
    6055              : static tree
    6056        20474 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
    6057              :                              bool &maybe_zero_len, unsigned int &first_non_one,
    6058              :                              enum c_omp_region_type ort)
    6059              : {
    6060        20474 :   tree ret, low_bound, length, type;
    6061        20474 :   bool openacc = (ort & C_ORT_ACC) != 0;
    6062        20474 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
    6063              :     {
    6064         9279 :       if (error_operand_p (t))
    6065            6 :         return error_mark_node;
    6066              : 
    6067         9273 :       cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6068         9273 :       tree t_refto = ai.maybe_unconvert_ref (t);
    6069              : 
    6070         9273 :       if (!ai.check_clause (c))
    6071            0 :         return error_mark_node;
    6072         9273 :       else if (ai.component_access_p ()
    6073        10661 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6074           64 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
    6075           40 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
    6076         1388 :         t = ai.get_root_term (true);
    6077              :       else
    6078         7885 :         t = ai.unconverted_ref_origin ();
    6079         9273 :       if (t == error_mark_node)
    6080              :         return error_mark_node;
    6081         9273 :       ret = t_refto;
    6082         9273 :       if (TREE_CODE (t) == FIELD_DECL)
    6083           33 :         ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6084         9240 :       else if (!VAR_P (t)
    6085         2700 :                && (openacc || !EXPR_P (t))
    6086         2505 :                && TREE_CODE (t) != PARM_DECL)
    6087              :         {
    6088           48 :           if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    6089              :             return NULL_TREE;
    6090           30 :           if (DECL_P (t))
    6091           30 :             error_at (OMP_CLAUSE_LOCATION (c),
    6092              :                       "%qD is not a variable in %qs clause", t,
    6093           30 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6094              :           else
    6095            0 :             error_at (OMP_CLAUSE_LOCATION (c),
    6096              :                       "%qE is not a variable in %qs clause", t,
    6097            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6098           30 :           return error_mark_node;
    6099              :         }
    6100         9192 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6101         9002 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6102        17265 :                && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    6103              :         {
    6104           17 :           error_at (OMP_CLAUSE_LOCATION (c),
    6105              :                     "%qD is threadprivate variable in %qs clause", t,
    6106           17 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6107           17 :           return error_mark_node;
    6108              :         }
    6109         9208 :       if (type_dependent_expression_p (ret))
    6110              :         return NULL_TREE;
    6111         8521 :       ret = convert_from_reference (ret);
    6112         8521 :       return ret;
    6113         9273 :     }
    6114              : 
    6115        11195 :   if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
    6116         7392 :       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6117         6198 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6118         4914 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6119        13801 :       && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
    6120           43 :     TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
    6121        11195 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
    6122              :                                      maybe_zero_len, first_non_one, ort);
    6123        11195 :   if (ret == error_mark_node || ret == NULL_TREE)
    6124              :     return ret;
    6125              : 
    6126        10191 :   type = TREE_TYPE (ret);
    6127        10191 :   low_bound = TREE_OPERAND (t, 1);
    6128        10191 :   length = TREE_OPERAND (t, 2);
    6129         8244 :   if ((low_bound && type_dependent_expression_p (low_bound))
    6130        18352 :       || (length && type_dependent_expression_p (length)))
    6131           88 :     return NULL_TREE;
    6132              : 
    6133        10103 :   if (low_bound == error_mark_node || length == error_mark_node)
    6134              :     return error_mark_node;
    6135              : 
    6136        10103 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
    6137              :     {
    6138           69 :       error_at (OMP_CLAUSE_LOCATION (c),
    6139              :                 "low bound %qE of array section does not have integral type",
    6140              :                 low_bound);
    6141           69 :       return error_mark_node;
    6142              :     }
    6143        10034 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
    6144              :     {
    6145           63 :       error_at (OMP_CLAUSE_LOCATION (c),
    6146              :                 "length %qE of array section does not have integral type",
    6147              :                 length);
    6148           63 :       return error_mark_node;
    6149              :     }
    6150         9971 :   if (low_bound)
    6151         8078 :     low_bound = mark_rvalue_use (low_bound);
    6152         9971 :   if (length)
    6153         9025 :     length = mark_rvalue_use (length);
    6154              :   /* We need to reduce to real constant-values for checks below.  */
    6155         9025 :   if (length)
    6156         9025 :     length = fold_simple (length);
    6157         9971 :   if (low_bound)
    6158         8078 :     low_bound = fold_simple (low_bound);
    6159         8078 :   if (low_bound
    6160         8078 :       && TREE_CODE (low_bound) == INTEGER_CST
    6161        15231 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
    6162         7153 :          > TYPE_PRECISION (sizetype))
    6163            0 :     low_bound = fold_convert (sizetype, low_bound);
    6164         9971 :   if (length
    6165         9025 :       && TREE_CODE (length) == INTEGER_CST
    6166        16985 :       && TYPE_PRECISION (TREE_TYPE (length))
    6167         7014 :          > TYPE_PRECISION (sizetype))
    6168            0 :     length = fold_convert (sizetype, length);
    6169         9971 :   if (low_bound == NULL_TREE)
    6170         1893 :     low_bound = integer_zero_node;
    6171              : 
    6172         9971 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6173         9971 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    6174         5086 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
    6175              :     {
    6176           60 :       if (length != integer_one_node)
    6177              :         {
    6178           36 :           error_at (OMP_CLAUSE_LOCATION (c),
    6179              :                     "expected single pointer in %qs clause",
    6180              :                     user_omp_clause_code_name (c, openacc));
    6181           36 :           return error_mark_node;
    6182              :         }
    6183              :     }
    6184         9935 :   if (length != NULL_TREE)
    6185              :     {
    6186         9013 :       if (!integer_nonzerop (length))
    6187              :         {
    6188         2058 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6189              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6190              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6191              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6192              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6193              :             {
    6194          459 :               if (integer_zerop (length))
    6195              :                 {
    6196           28 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6197              :                             "zero length array section in %qs clause",
    6198           28 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6199           28 :                   return error_mark_node;
    6200              :                 }
    6201              :             }
    6202              :           else
    6203         1599 :             maybe_zero_len = true;
    6204              :         }
    6205         8985 :       if (first_non_one == types.length ()
    6206         8985 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
    6207         3928 :         first_non_one++;
    6208              :     }
    6209         9907 :   if (TREE_CODE (type) == ARRAY_TYPE)
    6210              :     {
    6211         5461 :       if (length == NULL_TREE
    6212         5461 :           && (TYPE_DOMAIN (type) == NULL_TREE
    6213          850 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
    6214              :         {
    6215           30 :           error_at (OMP_CLAUSE_LOCATION (c),
    6216              :                     "for unknown bound array type length expression must "
    6217              :                     "be specified");
    6218           30 :           return error_mark_node;
    6219              :         }
    6220         5431 :       if (TREE_CODE (low_bound) == INTEGER_CST
    6221         5431 :           && tree_int_cst_sgn (low_bound) == -1)
    6222              :         {
    6223          153 :           error_at (OMP_CLAUSE_LOCATION (c),
    6224              :                     "negative low bound in array section in %qs clause",
    6225          153 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6226          153 :           return error_mark_node;
    6227              :         }
    6228         5278 :       if (length != NULL_TREE
    6229         4476 :           && TREE_CODE (length) == INTEGER_CST
    6230         8836 :           && tree_int_cst_sgn (length) == -1)
    6231              :         {
    6232          153 :           error_at (OMP_CLAUSE_LOCATION (c),
    6233              :                     "negative length in array section in %qs clause",
    6234          153 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6235          153 :           return error_mark_node;
    6236              :         }
    6237         5125 :       if (TYPE_DOMAIN (type)
    6238         5031 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    6239        10156 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
    6240              :                         == INTEGER_CST)
    6241              :         {
    6242         4635 :           tree size
    6243         4635 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
    6244         4635 :           size = size_binop (PLUS_EXPR, size, size_one_node);
    6245         4635 :           if (TREE_CODE (low_bound) == INTEGER_CST)
    6246              :             {
    6247         3868 :               if (tree_int_cst_lt (size, low_bound))
    6248              :                 {
    6249           54 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6250              :                             "low bound %qE above array section size "
    6251              :                             "in %qs clause", low_bound,
    6252           54 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6253           54 :                   return error_mark_node;
    6254              :                 }
    6255         3814 :               if (tree_int_cst_equal (size, low_bound))
    6256              :                 {
    6257           17 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6258              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6259              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6260              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6261              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6262              :                     {
    6263           17 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6264              :                                 "zero length array section in %qs clause",
    6265           17 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6266           17 :                       return error_mark_node;
    6267              :                     }
    6268            0 :                   maybe_zero_len = true;
    6269              :                 }
    6270         3797 :               else if (length == NULL_TREE
    6271         1420 :                        && first_non_one == types.length ()
    6272         4095 :                        && tree_int_cst_equal
    6273          298 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
    6274              :                              low_bound))
    6275          195 :                 first_non_one++;
    6276              :             }
    6277          767 :           else if (length == NULL_TREE)
    6278              :             {
    6279           20 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6280              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6281              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6282              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6283              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6284           13 :                 maybe_zero_len = true;
    6285           40 :               if (first_non_one == types.length ())
    6286           17 :                 first_non_one++;
    6287              :             }
    6288         4564 :           if (length && TREE_CODE (length) == INTEGER_CST)
    6289              :             {
    6290         3290 :               if (tree_int_cst_lt (size, length))
    6291              :                 {
    6292           57 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6293              :                             "length %qE above array section size "
    6294              :                             "in %qs clause", length,
    6295           57 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6296           57 :                   return error_mark_node;
    6297              :                 }
    6298         3233 :               if (TREE_CODE (low_bound) == INTEGER_CST)
    6299              :                 {
    6300         2899 :                   tree lbpluslen
    6301         2899 :                     = size_binop (PLUS_EXPR,
    6302              :                                   fold_convert (sizetype, low_bound),
    6303              :                                   fold_convert (sizetype, length));
    6304         2899 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
    6305         2899 :                       && tree_int_cst_lt (size, lbpluslen))
    6306              :                     {
    6307           54 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6308              :                                 "high bound %qE above array section size "
    6309              :                                 "in %qs clause", lbpluslen,
    6310           54 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6311           54 :                       return error_mark_node;
    6312              :                     }
    6313              :                 }
    6314              :             }
    6315              :         }
    6316          490 :       else if (length == NULL_TREE)
    6317              :         {
    6318            1 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6319              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6320              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6321              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6322              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6323            0 :             maybe_zero_len = true;
    6324            2 :           if (first_non_one == types.length ())
    6325            1 :             first_non_one++;
    6326              :         }
    6327              : 
    6328              :       /* For [lb:] we will need to evaluate lb more than once.  */
    6329         3911 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6330              :         {
    6331          650 :           tree lb = cp_save_expr (low_bound);
    6332          650 :           if (lb != low_bound)
    6333              :             {
    6334            9 :               TREE_OPERAND (t, 1) = lb;
    6335            9 :               low_bound = lb;
    6336              :             }
    6337              :         }
    6338              :     }
    6339         4446 :   else if (TYPE_PTR_P (type))
    6340              :     {
    6341         4389 :       if (length == NULL_TREE)
    6342              :         {
    6343           42 :           if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
    6344           36 :             error_at (OMP_CLAUSE_LOCATION (c),
    6345              :                       "for array function parameter length expression "
    6346              :                       "must be specified");
    6347              :           else
    6348            6 :             error_at (OMP_CLAUSE_LOCATION (c),
    6349              :                       "for pointer type length expression must be specified");
    6350           42 :           return error_mark_node;
    6351              :         }
    6352         4347 :       if (length != NULL_TREE
    6353         4347 :           && TREE_CODE (length) == INTEGER_CST
    6354         3254 :           && tree_int_cst_sgn (length) == -1)
    6355              :         {
    6356           84 :           error_at (OMP_CLAUSE_LOCATION (c),
    6357              :                     "negative length in array section in %qs clause",
    6358           84 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6359           84 :           return error_mark_node;
    6360              :         }
    6361              :       /* If there is a pointer type anywhere but in the very first
    6362              :          array-section-subscript, the array section could be non-contiguous.  */
    6363         4263 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6364         4221 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6365         7999 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
    6366              :         {
    6367              :           /* If any prior dimension has a non-one length, then deem this
    6368              :              array section as non-contiguous.  */
    6369          158 :           for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
    6370           69 :                d = TREE_OPERAND (d, 0))
    6371              :             {
    6372           89 :               tree d_length = TREE_OPERAND (d, 2);
    6373           89 :               if (d_length == NULL_TREE || !integer_onep (d_length))
    6374              :                 {
    6375           20 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6376              :                             "array section is not contiguous in %qs clause",
    6377           20 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6378           20 :                   return error_mark_node;
    6379              :                 }
    6380              :             }
    6381              :         }
    6382              :     }
    6383              :   else
    6384              :     {
    6385           57 :       error_at (OMP_CLAUSE_LOCATION (c),
    6386              :                 "%qE does not have pointer or array type", ret);
    6387           57 :       return error_mark_node;
    6388              :     }
    6389         9186 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6390         8281 :     types.safe_push (TREE_TYPE (ret));
    6391              :   /* We will need to evaluate lb more than once.  */
    6392         9186 :   tree lb = cp_save_expr (low_bound);
    6393         9186 :   if (lb != low_bound)
    6394              :     {
    6395          716 :       TREE_OPERAND (t, 1) = lb;
    6396          716 :       low_bound = lb;
    6397              :     }
    6398              :   /* Temporarily disable -fstrong-eval-order for array reductions.
    6399              :      The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
    6400              :      is something the middle-end can't cope with and more importantly,
    6401              :      it needs to be the actual base variable that is privatized, not some
    6402              :      temporary assigned previous value of it.  That, together with OpenMP
    6403              :      saying how many times the side-effects are evaluated is unspecified,
    6404              :      makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified.  */
    6405         9186 :   warning_sentinel s (flag_strong_eval_order,
    6406         9186 :                       OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6407         8173 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6408        18491 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
    6409         9186 :   ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
    6410              :                          tf_warning_or_error);
    6411         9186 :   return ret;
    6412         9186 : }
    6413              : 
    6414              : /* Handle array sections for clause C.  */
    6415              : 
    6416              : static bool
    6417         9279 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
    6418              : {
    6419         9279 :   bool maybe_zero_len = false;
    6420         9279 :   unsigned int first_non_one = 0;
    6421         9279 :   auto_vec<tree, 10> types;
    6422         9279 :   tree *tp = &OMP_CLAUSE_DECL (c);
    6423         9279 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6424         8320 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6425         9485 :       && OMP_ITERATOR_DECL_P (*tp))
    6426          258 :     tp = &TREE_VALUE (*tp);
    6427         9279 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
    6428              :                                             maybe_zero_len, first_non_one,
    6429              :                                             ort);
    6430         9279 :   if (first == error_mark_node)
    6431              :     return true;
    6432         8309 :   if (first == NULL_TREE)
    6433              :     return false;
    6434         7516 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6435         7516 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6436              :     {
    6437          851 :       tree t = *tp;
    6438          851 :       tree tem = NULL_TREE;
    6439          851 :       if (processing_template_decl)
    6440              :         return false;
    6441              :       /* Need to evaluate side effects in the length expressions
    6442              :          if any.  */
    6443          752 :       while (TREE_CODE (t) == TREE_LIST)
    6444              :         {
    6445            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
    6446              :             {
    6447            0 :               if (tem == NULL_TREE)
    6448              :                 tem = TREE_VALUE (t);
    6449              :               else
    6450            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
    6451            0 :                               TREE_VALUE (t), tem);
    6452              :             }
    6453            0 :           t = TREE_CHAIN (t);
    6454              :         }
    6455          752 :       if (tem)
    6456            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
    6457          752 :       *tp = first;
    6458              :     }
    6459              :   else
    6460              :     {
    6461         6665 :       unsigned int num = types.length (), i;
    6462         6665 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
    6463         6665 :       tree condition = NULL_TREE;
    6464              : 
    6465         6665 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
    6466            3 :         maybe_zero_len = true;
    6467         6665 :       if (processing_template_decl && maybe_zero_len)
    6468              :         return false;
    6469              : 
    6470        14020 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
    6471         7433 :            t = TREE_OPERAND (t, 0))
    6472              :         {
    6473         7504 :           gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
    6474              : 
    6475         7504 :           tree low_bound = TREE_OPERAND (t, 1);
    6476         7504 :           tree length = TREE_OPERAND (t, 2);
    6477              : 
    6478         7504 :           i--;
    6479         7504 :           if (low_bound
    6480         6121 :               && TREE_CODE (low_bound) == INTEGER_CST
    6481        13014 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
    6482         5510 :                  > TYPE_PRECISION (sizetype))
    6483            0 :             low_bound = fold_convert (sizetype, low_bound);
    6484         7504 :           if (length
    6485         6985 :               && TREE_CODE (length) == INTEGER_CST
    6486        12597 :               && TYPE_PRECISION (TREE_TYPE (length))
    6487         5093 :                  > TYPE_PRECISION (sizetype))
    6488            0 :             length = fold_convert (sizetype, length);
    6489         7504 :           if (low_bound == NULL_TREE)
    6490         1383 :             low_bound = integer_zero_node;
    6491         7504 :           if (!maybe_zero_len && i > first_non_one)
    6492              :             {
    6493          629 :               if (integer_nonzerop (low_bound))
    6494           34 :                 goto do_warn_noncontiguous;
    6495          595 :               if (length != NULL_TREE
    6496          273 :                   && TREE_CODE (length) == INTEGER_CST
    6497          273 :                   && TYPE_DOMAIN (types[i])
    6498          273 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
    6499          868 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
    6500              :                      == INTEGER_CST)
    6501              :                 {
    6502          273 :                   tree size;
    6503          273 :                   size = size_binop (PLUS_EXPR,
    6504              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6505              :                                      size_one_node);
    6506          273 :                   if (!tree_int_cst_equal (length, size))
    6507              :                     {
    6508           37 :                      do_warn_noncontiguous:
    6509          142 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6510              :                                 "array section is not contiguous in %qs "
    6511              :                                 "clause",
    6512           71 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6513           71 :                       return true;
    6514              :                     }
    6515              :                 }
    6516          558 :               if (!processing_template_decl
    6517          390 :                   && length != NULL_TREE
    6518          723 :                   && TREE_SIDE_EFFECTS (length))
    6519              :                 {
    6520            0 :                   if (side_effects == NULL_TREE)
    6521              :                     side_effects = length;
    6522              :                   else
    6523            0 :                     side_effects = build2 (COMPOUND_EXPR,
    6524            0 :                                            TREE_TYPE (side_effects),
    6525              :                                            length, side_effects);
    6526              :                 }
    6527              :             }
    6528         6875 :           else if (processing_template_decl)
    6529          698 :             continue;
    6530              :           else
    6531              :             {
    6532         6177 :               tree l;
    6533              : 
    6534         6177 :               if (i > first_non_one
    6535         6177 :                   && ((length && integer_nonzerop (length))
    6536            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6537              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6538              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
    6539            0 :                 continue;
    6540         6177 :               if (length)
    6541         6060 :                 l = fold_convert (sizetype, length);
    6542              :               else
    6543              :                 {
    6544          117 :                   l = size_binop (PLUS_EXPR,
    6545              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6546              :                                   size_one_node);
    6547          117 :                   l = size_binop (MINUS_EXPR, l,
    6548              :                                   fold_convert (sizetype, low_bound));
    6549              :                 }
    6550         6177 :               if (i > first_non_one)
    6551              :                 {
    6552            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
    6553              :                                    size_zero_node);
    6554            0 :                   if (condition == NULL_TREE)
    6555              :                     condition = l;
    6556              :                   else
    6557            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
    6558              :                                              l, condition);
    6559              :                 }
    6560         6177 :               else if (size == NULL_TREE)
    6561              :                 {
    6562         5899 :                   size = size_in_bytes (TREE_TYPE (types[i]));
    6563         5899 :                   tree eltype = TREE_TYPE (types[num - 1]);
    6564         5968 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
    6565           69 :                     eltype = TREE_TYPE (eltype);
    6566         5899 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6567         5149 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6568        10295 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6569         1599 :                     size = size_binop (EXACT_DIV_EXPR, size,
    6570              :                                        size_in_bytes (eltype));
    6571         5899 :                   size = size_binop (MULT_EXPR, size, l);
    6572         5899 :                   if (condition)
    6573            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
    6574              :                                         size, size_zero_node);
    6575              :                 }
    6576              :               else
    6577          278 :                 size = size_binop (MULT_EXPR, size, l);
    6578              :             }
    6579              :         }
    6580         6516 :       if (!processing_template_decl)
    6581              :         {
    6582         5899 :           if (side_effects)
    6583            0 :             size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
    6584         5899 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6585         5149 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6586        10295 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6587              :             {
    6588         1599 :               size = size_binop (MINUS_EXPR, size, size_one_node);
    6589         1599 :               size = save_expr (size);
    6590         1599 :               tree index_type = build_index_type (size);
    6591         1599 :               tree eltype = TREE_TYPE (first);
    6592         1628 :               while (TREE_CODE (eltype) == ARRAY_TYPE)
    6593           29 :                 eltype = TREE_TYPE (eltype);
    6594         1599 :               tree type = build_array_type (eltype, index_type);
    6595         1599 :               tree ptype = build_pointer_type (eltype);
    6596         1599 :               if (TYPE_REF_P (TREE_TYPE (t))
    6597         1599 :                   && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
    6598          152 :                 t = convert_from_reference (t);
    6599         1447 :               else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6600          629 :                 t = build_fold_addr_expr (t);
    6601         1599 :               tree t2 = build_fold_addr_expr (first);
    6602         1599 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6603              :                                      ptrdiff_type_node, t2);
    6604         1599 :               t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
    6605              :                                     ptrdiff_type_node, t2,
    6606         1599 :                                     fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6607              :                                                       ptrdiff_type_node, t));
    6608         1599 :               if (tree_fits_shwi_p (t2))
    6609         1261 :                 t = build2 (MEM_REF, type, t,
    6610         1261 :                             build_int_cst (ptype, tree_to_shwi (t2)));
    6611              :               else
    6612              :                 {
    6613          338 :                   t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6614              :                                          sizetype, t2);
    6615          338 :                   t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
    6616          338 :                                   TREE_TYPE (t), t, t2);
    6617          338 :                   t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
    6618              :                 }
    6619         1599 :               OMP_CLAUSE_DECL (c) = t;
    6620         7498 :               return false;
    6621              :             }
    6622         4300 :           OMP_CLAUSE_DECL (c) = first;
    6623         4300 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
    6624              :             return false;
    6625         4274 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    6626         4274 :               || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    6627         3734 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
    6628         3722 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
    6629         4250 :             OMP_CLAUSE_SIZE (c) = size;
    6630         4274 :           if (TREE_CODE (t) == FIELD_DECL)
    6631            3 :             t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6632              : 
    6633         4274 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    6634              :             return false;
    6635              : 
    6636         3746 :           if (TREE_CODE (first) == INDIRECT_REF)
    6637              :             {
    6638              :               /* Detect and skip adding extra nodes for pointer-to-member
    6639              :                  mappings.  These are unsupported for now.  */
    6640         2411 :               tree tmp = TREE_OPERAND (first, 0);
    6641              : 
    6642         2411 :               if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
    6643         1915 :                 tmp = TREE_OPERAND (tmp, 0);
    6644              : 
    6645         2411 :               if (TREE_CODE (tmp) == INDIRECT_REF)
    6646          158 :                 tmp = TREE_OPERAND (tmp, 0);
    6647              : 
    6648         2411 :               if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
    6649              :                 {
    6650          466 :                   tree offset = TREE_OPERAND (tmp, 1);
    6651          466 :                   STRIP_NOPS (offset);
    6652          466 :                   if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
    6653              :                     {
    6654           36 :                       sorry_at (OMP_CLAUSE_LOCATION (c),
    6655              :                                 "pointer-to-member mapping %qE not supported",
    6656           18 :                                 OMP_CLAUSE_DECL (c));
    6657           18 :                       return true;
    6658              :                     }
    6659              :                 }
    6660              :             }
    6661              : 
    6662              :           /* FIRST represents the first item of data that we are mapping.
    6663              :              E.g. if we're mapping an array, FIRST might resemble
    6664              :              "foo.bar.myarray[0]".  */
    6665              : 
    6666         3728 :           auto_vec<omp_addr_token *, 10> addr_tokens;
    6667              : 
    6668         3728 :           if (!omp_parse_expr (addr_tokens, first))
    6669              :             return true;
    6670              : 
    6671         3728 :           cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6672              : 
    6673         3728 :           tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
    6674         3728 :           if (nc != error_mark_node)
    6675              :             {
    6676         3728 :               using namespace omp_addr_tokenizer;
    6677              : 
    6678         3728 :               if (ai.maybe_zero_length_array_section (c))
    6679         3704 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
    6680              : 
    6681              :               /* !!! If we're accessing a base decl via chained access
    6682              :                  methods (e.g. multiple indirections), duplicate clause
    6683              :                  detection won't work properly.  Skip it in that case.  */
    6684         3728 :               if ((addr_tokens[0]->type == STRUCTURE_BASE
    6685         2711 :                    || addr_tokens[0]->type == ARRAY_BASE)
    6686         3728 :                   && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    6687         3717 :                   && addr_tokens[1]->type == ACCESS_METHOD
    6688         7445 :                   && omp_access_chain_p (addr_tokens, 1))
    6689          216 :                 c = nc;
    6690              : 
    6691         3728 :               return false;
    6692              :             }
    6693         7456 :         }
    6694              :     }
    6695              :   return false;
    6696         9279 : }
    6697              : 
    6698              : /* Return identifier to look up for omp declare reduction.  */
    6699              : 
    6700              : tree
    6701         7089 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
    6702              : {
    6703         7089 :   const char *p = NULL;
    6704         7089 :   const char *m = NULL;
    6705         7089 :   switch (reduction_code)
    6706              :     {
    6707         4188 :     case PLUS_EXPR:
    6708         4188 :     case MULT_EXPR:
    6709         4188 :     case MINUS_EXPR:
    6710         4188 :     case BIT_AND_EXPR:
    6711         4188 :     case BIT_XOR_EXPR:
    6712         4188 :     case BIT_IOR_EXPR:
    6713         4188 :     case TRUTH_ANDIF_EXPR:
    6714         4188 :     case TRUTH_ORIF_EXPR:
    6715         4188 :       reduction_id = ovl_op_identifier (false, reduction_code);
    6716         4188 :       break;
    6717              :     case MIN_EXPR:
    6718              :       p = "min";
    6719              :       break;
    6720              :     case MAX_EXPR:
    6721              :       p = "max";
    6722              :       break;
    6723              :     default:
    6724              :       break;
    6725              :     }
    6726              : 
    6727         4188 :   if (p == NULL)
    6728              :     {
    6729         6925 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
    6730            0 :         return error_mark_node;
    6731         6925 :       p = IDENTIFIER_POINTER (reduction_id);
    6732              :     }
    6733              : 
    6734         7089 :   if (type != NULL_TREE)
    6735         2035 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6736              : 
    6737         7089 :   const char prefix[] = "omp declare reduction ";
    6738         7089 :   size_t lenp = sizeof (prefix);
    6739         7089 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6740         2035 :     lenp = 1;
    6741         7089 :   size_t len = strlen (p);
    6742         7089 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6743         7089 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6744         7089 :   if (lenp > 1)
    6745         5054 :     memcpy (name, prefix, lenp - 1);
    6746         7089 :   memcpy (name + lenp - 1, p, len + 1);
    6747         7089 :   if (m)
    6748              :     {
    6749         2035 :       name[lenp + len - 1] = '~';
    6750         2035 :       memcpy (name + lenp + len, m, lenm);
    6751              :     }
    6752         7089 :   return get_identifier (name);
    6753              : }
    6754              : 
    6755              : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
    6756              :    FUNCTION_DECL or NULL_TREE if not found.  */
    6757              : 
    6758              : static tree
    6759         1289 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
    6760              :                       vec<tree> *ambiguousp)
    6761              : {
    6762         1289 :   tree orig_id = id;
    6763         1289 :   tree baselink = NULL_TREE;
    6764         1289 :   if (identifier_p (id))
    6765              :     {
    6766         1261 :       cp_id_kind idk;
    6767         1261 :       bool nonint_cst_expression_p;
    6768         1261 :       const char *error_msg;
    6769         1261 :       id = omp_reduction_id (ERROR_MARK, id, type);
    6770         1261 :       tree decl = lookup_name (id);
    6771         1261 :       if (decl == NULL_TREE)
    6772           80 :         decl = error_mark_node;
    6773         1261 :       id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
    6774              :                                  &nonint_cst_expression_p, false, true, false,
    6775              :                                  false, &error_msg, loc);
    6776         1261 :       if (idk == CP_ID_KIND_UNQUALIFIED
    6777         1341 :           && identifier_p (id))
    6778              :         {
    6779           80 :           vec<tree, va_gc> *args = NULL;
    6780           80 :           vec_safe_push (args, build_reference_type (type));
    6781           80 :           id = perform_koenig_lookup (id, args, tf_none);
    6782              :         }
    6783              :     }
    6784           28 :   else if (TREE_CODE (id) == SCOPE_REF)
    6785           28 :     id = lookup_qualified_name (TREE_OPERAND (id, 0),
    6786              :                                 omp_reduction_id (ERROR_MARK,
    6787           28 :                                                   TREE_OPERAND (id, 1),
    6788              :                                                   type),
    6789              :                                 LOOK_want::NORMAL, false);
    6790         1289 :   tree fns = id;
    6791         1289 :   id = NULL_TREE;
    6792         1289 :   if (fns && is_overloaded_fn (fns))
    6793              :     {
    6794         1215 :       for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
    6795              :         {
    6796         1215 :           tree fndecl = *iter;
    6797         1215 :           if (TREE_CODE (fndecl) == FUNCTION_DECL)
    6798              :             {
    6799         1215 :               tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
    6800         1215 :               if (same_type_p (TREE_TYPE (argtype), type))
    6801              :                 {
    6802         1215 :                   id = fndecl;
    6803         1215 :                   break;
    6804              :                 }
    6805              :             }
    6806              :         }
    6807              : 
    6808         1215 :       if (id && BASELINK_P (fns))
    6809              :         {
    6810           74 :           if (baselinkp)
    6811            0 :             *baselinkp = fns;
    6812              :           else
    6813           74 :             baselink = fns;
    6814              :         }
    6815              :     }
    6816              : 
    6817         1289 :   if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
    6818              :     {
    6819           35 :       auto_vec<tree> ambiguous;
    6820           35 :       tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
    6821           35 :       unsigned int ix;
    6822           35 :       if (ambiguousp == NULL)
    6823           19 :         ambiguousp = &ambiguous;
    6824           73 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    6825              :         {
    6826           52 :           id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
    6827              :                                      baselinkp ? baselinkp : &baselink,
    6828              :                                      ambiguousp);
    6829           38 :           if (id == NULL_TREE)
    6830           14 :             continue;
    6831           24 :           if (!ambiguousp->is_empty ())
    6832            3 :             ambiguousp->safe_push (id);
    6833           21 :           else if (ret != NULL_TREE)
    6834              :             {
    6835            6 :               ambiguousp->safe_push (ret);
    6836            6 :               ambiguousp->safe_push (id);
    6837            6 :               ret = NULL_TREE;
    6838              :             }
    6839              :           else
    6840           15 :             ret = id;
    6841              :         }
    6842           35 :       if (ambiguousp != &ambiguous)
    6843           16 :         return ret;
    6844           19 :       if (!ambiguous.is_empty ())
    6845              :         {
    6846            6 :           auto_diagnostic_group d;
    6847            6 :           const char *str = _("candidates are:");
    6848            6 :           unsigned int idx;
    6849            6 :           tree udr;
    6850            6 :           error_at (loc, "user defined reduction lookup is ambiguous");
    6851           27 :           FOR_EACH_VEC_ELT (ambiguous, idx, udr)
    6852              :             {
    6853           15 :               inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
    6854           15 :               if (idx == 0)
    6855            6 :                 str = get_spaces (str);
    6856              :             }
    6857            6 :           ret = error_mark_node;
    6858            6 :           baselink = NULL_TREE;
    6859            6 :         }
    6860           19 :       id = ret;
    6861           35 :     }
    6862         1273 :   if (id && baselink)
    6863           74 :     perform_or_defer_access_check (BASELINK_BINFO (baselink),
    6864              :                                    id, id, tf_warning_or_error);
    6865              :   return id;
    6866              : }
    6867              : 
    6868              : /* Return identifier to look up for omp declare mapper.  */
    6869              : 
    6870              : tree
    6871         4064 : omp_mapper_id (tree mapper_id, tree type)
    6872              : {
    6873         4064 :   const char *p = NULL;
    6874         4064 :   const char *m = NULL;
    6875              : 
    6876         4064 :   if (mapper_id == NULL_TREE)
    6877              :     p = "";
    6878           88 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
    6879           88 :     p = IDENTIFIER_POINTER (mapper_id);
    6880              :   else
    6881            0 :     return error_mark_node;
    6882              : 
    6883         4064 :   if (type != NULL_TREE)
    6884         4056 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6885              : 
    6886         4064 :   const char prefix[] = "omp declare mapper ";
    6887         4064 :   size_t lenp = sizeof (prefix);
    6888         4064 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6889            8 :     lenp = 1;
    6890         4064 :   size_t len = strlen (p);
    6891         4064 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6892         4064 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6893         4064 :   memcpy (name, prefix, lenp - 1);
    6894         4064 :   memcpy (name + lenp - 1, p, len + 1);
    6895         4064 :   if (m)
    6896              :     {
    6897         4056 :       name[lenp + len - 1] = '~';
    6898         4056 :       memcpy (name + lenp + len, m, lenm);
    6899              :     }
    6900         4064 :   return get_identifier (name);
    6901              : }
    6902              : 
    6903              : tree
    6904        11954 : cxx_omp_mapper_lookup (tree id, tree type)
    6905              : {
    6906        11954 :   if (!RECORD_OR_UNION_TYPE_P (type))
    6907              :     return NULL_TREE;
    6908         3826 :   id = omp_mapper_id (id, type);
    6909         3826 :   return lookup_name (id);
    6910              : }
    6911              : 
    6912              : tree
    6913          375 : cxx_omp_extract_mapper_directive (tree vardecl)
    6914              : {
    6915          375 :   gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
    6916              : 
    6917              :   /* Instantiate the decl if we haven't already.  */
    6918          375 :   mark_used (vardecl);
    6919          375 :   tree body = DECL_INITIAL (vardecl);
    6920              : 
    6921          375 :   if (TREE_CODE (body) == STATEMENT_LIST)
    6922              :     {
    6923            0 :       tree_stmt_iterator tsi = tsi_start (body);
    6924            0 :       gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
    6925            0 :       tsi_next (&tsi);
    6926            0 :       body = tsi_stmt (tsi);
    6927              :     }
    6928              : 
    6929          375 :   gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
    6930              : 
    6931          375 :   return body;
    6932              : }
    6933              : 
    6934              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
    6935              :    nothing more complicated.  */
    6936              : 
    6937              : tree
    6938         1910 : cxx_omp_map_array_section (location_t loc, tree t)
    6939              : {
    6940         1910 :   tree low = TREE_OPERAND (t, 1);
    6941         1910 :   tree len = TREE_OPERAND (t, 2);
    6942              : 
    6943         1910 :   if (len && integer_onep (len))
    6944              :     {
    6945          300 :       t = TREE_OPERAND (t, 0);
    6946              : 
    6947          300 :       if (!low)
    6948           17 :         low = integer_zero_node;
    6949              : 
    6950          300 :       if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
    6951            6 :         t = convert_from_reference (t);
    6952              : 
    6953          300 :       if (TYPE_PTR_P (TREE_TYPE (t))
    6954          300 :           || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6955          300 :         t = build_array_ref (loc, t, low);
    6956              :       else
    6957              :         /* handle_omp_array_sections_1 has already diagnosed the error.  */
    6958            0 :         t = error_mark_node;
    6959              :     }
    6960              : 
    6961         1910 :   return t;
    6962              : }
    6963              : 
    6964              : /* Helper function for cp_parser_omp_declare_reduction_exprs
    6965              :    and tsubst_omp_udr.
    6966              :    Remove CLEANUP_STMT for data (omp_priv variable).
    6967              :    Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
    6968              :    DECL_EXPR.  */
    6969              : 
    6970              : tree
    6971         4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
    6972              : {
    6973         4395 :   if (TYPE_P (*tp))
    6974          227 :     *walk_subtrees = 0;
    6975         4168 :   else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
    6976           52 :     *tp = CLEANUP_BODY (*tp);
    6977         4116 :   else if (TREE_CODE (*tp) == DECL_EXPR)
    6978              :     {
    6979          307 :       tree decl = DECL_EXPR_DECL (*tp);
    6980          307 :       if (!processing_template_decl
    6981          258 :           && decl == (tree) data
    6982          258 :           && DECL_INITIAL (decl)
    6983          399 :           && DECL_INITIAL (decl) != error_mark_node)
    6984              :         {
    6985           92 :           tree list = NULL_TREE;
    6986           92 :           append_to_statement_list_force (*tp, &list);
    6987           92 :           tree init_expr = build2 (INIT_EXPR, void_type_node,
    6988           92 :                                    decl, DECL_INITIAL (decl));
    6989           92 :           DECL_INITIAL (decl) = NULL_TREE;
    6990           92 :           append_to_statement_list_force (init_expr, &list);
    6991           92 :           *tp = list;
    6992              :         }
    6993              :     }
    6994         4395 :   return NULL_TREE;
    6995              : }
    6996              : 
    6997              : /* Data passed from cp_check_omp_declare_reduction to
    6998              :    cp_check_omp_declare_reduction_r.  */
    6999              : 
    7000              : struct cp_check_omp_declare_reduction_data
    7001              : {
    7002              :   location_t loc;
    7003              :   tree stmts[7];
    7004              :   bool combiner_p;
    7005              : };
    7006              : 
    7007              : /* Helper function for cp_check_omp_declare_reduction, called via
    7008              :    cp_walk_tree.  */
    7009              : 
    7010              : static tree
    7011        14955 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
    7012              : {
    7013        14955 :   struct cp_check_omp_declare_reduction_data *udr_data
    7014              :     = (struct cp_check_omp_declare_reduction_data *) data;
    7015        14955 :   if (SSA_VAR_P (*tp)
    7016         2687 :       && !DECL_ARTIFICIAL (*tp)
    7017          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
    7018          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
    7019              :     {
    7020          135 :       location_t loc = udr_data->loc;
    7021          135 :       if (udr_data->combiner_p)
    7022           45 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
    7023              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
    7024              :                   *tp);
    7025              :       else
    7026           90 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
    7027              :                        "to variable %qD which is not %<omp_priv%> nor "
    7028              :                        "%<omp_orig%>",
    7029              :                   *tp);
    7030          135 :       return *tp;
    7031              :     }
    7032              :   return NULL_TREE;
    7033              : }
    7034              : 
    7035              : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions.  */
    7036              : 
    7037              : bool
    7038         1101 : cp_check_omp_declare_reduction (tree udr)
    7039              : {
    7040         1101 :   tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
    7041         1101 :   gcc_assert (TYPE_REF_P (type));
    7042         1101 :   type = TREE_TYPE (type);
    7043         1101 :   int i;
    7044         1101 :   location_t loc = DECL_SOURCE_LOCATION (udr);
    7045              : 
    7046         1101 :   if (type == error_mark_node)
    7047              :     return false;
    7048         1101 :   if (ARITHMETIC_TYPE_P (type))
    7049              :     {
    7050              :       static enum tree_code predef_codes[]
    7051              :         = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
    7052              :             BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
    7053         3276 :       for (i = 0; i < 8; i++)
    7054              :         {
    7055         2918 :           tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
    7056         2918 :           const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
    7057         2918 :           const char *n2 = IDENTIFIER_POINTER (id);
    7058         2918 :           if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
    7059         2918 :               && (n1[IDENTIFIER_LENGTH (id)] == '~'
    7060            0 :                   || n1[IDENTIFIER_LENGTH (id)] == '\0'))
    7061              :             break;
    7062              :         }
    7063              : 
    7064          376 :       if (i == 8
    7065          358 :           && TREE_CODE (type) != COMPLEX_EXPR)
    7066              :         {
    7067          358 :           const char prefix_minmax[] = "omp declare reduction m";
    7068          358 :           size_t prefix_size = sizeof (prefix_minmax) - 1;
    7069          358 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
    7070          358 :           if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
    7071              :                        prefix_minmax, prefix_size) == 0
    7072           10 :               && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
    7073            4 :                   || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
    7074          368 :               && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
    7075            6 :             i = 0;
    7076              :         }
    7077          376 :       if (i < 8)
    7078              :         {
    7079           24 :           error_at (loc, "predeclared arithmetic type %qT in "
    7080              :                          "%<#pragma omp declare reduction%>", type);
    7081           24 :           return false;
    7082              :         }
    7083              :     }
    7084              :   else if (FUNC_OR_METHOD_TYPE_P (type)
    7085              :            || TREE_CODE (type) == ARRAY_TYPE)
    7086              :     {
    7087           24 :       error_at (loc, "function or array type %qT in "
    7088              :                      "%<#pragma omp declare reduction%>", type);
    7089           24 :       return false;
    7090              :     }
    7091              :   else if (TYPE_REF_P (type))
    7092              :     {
    7093            0 :       error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
    7094              :                 type);
    7095            0 :       return false;
    7096              :     }
    7097          701 :   else if (TYPE_QUALS_NO_ADDR_SPACE (type))
    7098              :     {
    7099           24 :       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
    7100              :                 "type %qT in %<#pragma omp declare reduction%>", type);
    7101           24 :       return false;
    7102              :     }
    7103              : 
    7104         1029 :   tree body = DECL_SAVED_TREE (udr);
    7105         1029 :   if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
    7106              :     return true;
    7107              : 
    7108          843 :   tree_stmt_iterator tsi;
    7109          843 :   struct cp_check_omp_declare_reduction_data data;
    7110          843 :   memset (data.stmts, 0, sizeof data.stmts);
    7111          843 :   for (i = 0, tsi = tsi_start (body);
    7112         4683 :        i < 7 && !tsi_end_p (tsi);
    7113         3840 :        i++, tsi_next (&tsi))
    7114         3840 :     data.stmts[i] = tsi_stmt (tsi);
    7115          843 :   data.loc = loc;
    7116          843 :   gcc_assert (tsi_end_p (tsi));
    7117          843 :   if (i >= 3)
    7118              :     {
    7119          843 :       gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
    7120              :                   && TREE_CODE (data.stmts[1]) == DECL_EXPR);
    7121          843 :       if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
    7122              :         return true;
    7123          798 :       data.combiner_p = true;
    7124          798 :       if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
    7125              :                         &data, NULL))
    7126           45 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
    7127              :     }
    7128          798 :   if (i >= 6)
    7129              :     {
    7130          336 :       gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
    7131              :                   && TREE_CODE (data.stmts[4]) == DECL_EXPR);
    7132          336 :       data.combiner_p = false;
    7133          336 :       if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
    7134              :                         &data, NULL)
    7135          336 :           || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
    7136              :                            cp_check_omp_declare_reduction_r, &data, NULL))
    7137           90 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /* Wat warning? */);
    7138          336 :       if (i == 7)
    7139          198 :         gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
    7140              :     }
    7141              :   return true;
    7142              : }
    7143              : 
    7144              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
    7145              :    an inline call.  But, remap
    7146              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
    7147              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
    7148              : 
    7149              : static tree
    7150         2199 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
    7151              :                tree decl, tree placeholder)
    7152              : {
    7153         2199 :   copy_body_data id;
    7154         2199 :   hash_map<tree, tree> decl_map;
    7155              : 
    7156         2199 :   decl_map.put (omp_decl1, placeholder);
    7157         2199 :   decl_map.put (omp_decl2, decl);
    7158         2199 :   memset (&id, 0, sizeof (id));
    7159         2199 :   id.src_fn = DECL_CONTEXT (omp_decl1);
    7160         2199 :   id.dst_fn = current_function_decl;
    7161         2199 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    7162         2199 :   id.decl_map = &decl_map;
    7163              : 
    7164         2199 :   id.copy_decl = copy_decl_no_change;
    7165         2199 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    7166         2199 :   id.transform_new_cfg = true;
    7167         2199 :   id.transform_return_to_modify = false;
    7168         2199 :   id.eh_lp_nr = 0;
    7169         2199 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
    7170         2199 :   return stmt;
    7171         2199 : }
    7172              : 
    7173              : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
    7174              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
    7175              : 
    7176              : static tree
    7177        15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
    7178              : {
    7179        15438 :   if (*tp == (tree) data)
    7180          265 :     return *tp;
    7181              :   return NULL_TREE;
    7182              : }
    7183              : 
    7184              : /* Helper function of finish_omp_clauses.  Handle OMP_CLAUSE_REDUCTION C.
    7185              :    Return true if there is some error and the clause should be removed.  */
    7186              : 
    7187              : static bool
    7188         8856 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
    7189              : {
    7190         8856 :   tree t = OMP_CLAUSE_DECL (c);
    7191         8856 :   bool predefined = false;
    7192         8856 :   if (TREE_CODE (t) == TREE_LIST)
    7193              :     {
    7194            0 :       gcc_assert (processing_template_decl);
    7195              :       return false;
    7196              :     }
    7197         8856 :   tree type = TREE_TYPE (t);
    7198         8856 :   if (TREE_CODE (t) == MEM_REF)
    7199         1596 :     type = TREE_TYPE (type);
    7200         8856 :   if (TYPE_REF_P (type))
    7201          527 :     type = TREE_TYPE (type);
    7202         8856 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7203              :     {
    7204          350 :       tree oatype = type;
    7205          350 :       gcc_assert (TREE_CODE (t) != MEM_REF);
    7206          703 :       while (TREE_CODE (type) == ARRAY_TYPE)
    7207          353 :         type = TREE_TYPE (type);
    7208          350 :       if (!processing_template_decl)
    7209              :         {
    7210          255 :           t = require_complete_type (t);
    7211          255 :           if (t == error_mark_node
    7212          255 :               || !complete_type_or_else (oatype, NULL_TREE))
    7213            9 :             return true;
    7214          246 :           tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
    7215              :                                   TYPE_SIZE_UNIT (type));
    7216          246 :           if (integer_zerop (size))
    7217              :             {
    7218            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7219              :                         "%qE in %<reduction%> clause is a zero size array",
    7220              :                         omp_clause_printable_decl (t));
    7221            3 :               return true;
    7222              :             }
    7223          243 :           size = size_binop (MINUS_EXPR, size, size_one_node);
    7224          243 :           size = save_expr (size);
    7225          243 :           tree index_type = build_index_type (size);
    7226          243 :           tree atype = build_array_type (type, index_type);
    7227          243 :           tree ptype = build_pointer_type (type);
    7228          243 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    7229          146 :             t = build_fold_addr_expr (t);
    7230          243 :           t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
    7231          243 :           OMP_CLAUSE_DECL (c) = t;
    7232              :         }
    7233              :     }
    7234         8844 :   if (type == error_mark_node)
    7235              :     return true;
    7236         8841 :   else if (ARITHMETIC_TYPE_P (type))
    7237         7590 :     switch (OMP_CLAUSE_REDUCTION_CODE (c))
    7238              :       {
    7239              :       case PLUS_EXPR:
    7240              :       case MULT_EXPR:
    7241              :       case MINUS_EXPR:
    7242              :       case TRUTH_ANDIF_EXPR:
    7243              :       case TRUTH_ORIF_EXPR:
    7244              :         predefined = true;
    7245              :         break;
    7246          246 :       case MIN_EXPR:
    7247          246 :       case MAX_EXPR:
    7248          246 :         if (TREE_CODE (type) == COMPLEX_TYPE)
    7249              :           break;
    7250              :         predefined = true;
    7251              :         break;
    7252          111 :       case BIT_AND_EXPR:
    7253          111 :       case BIT_IOR_EXPR:
    7254          111 :       case BIT_XOR_EXPR:
    7255          111 :         if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
    7256              :           break;
    7257              :         predefined = true;
    7258              :         break;
    7259              :       default:
    7260              :         break;
    7261              :       }
    7262         1251 :   else if (TYPE_READONLY (type))
    7263              :     {
    7264           18 :       error_at (OMP_CLAUSE_LOCATION (c),
    7265              :                 "%qE has const type for %<reduction%>",
    7266              :                 omp_clause_printable_decl (t));
    7267            9 :       return true;
    7268              :     }
    7269         1242 :   else if (!processing_template_decl)
    7270              :     {
    7271         1038 :       t = require_complete_type (t);
    7272         1038 :       if (t == error_mark_node)
    7273              :         return true;
    7274         1038 :       OMP_CLAUSE_DECL (c) = t;
    7275              :     }
    7276              : 
    7277         1038 :   if (predefined)
    7278              :     {
    7279         7368 :       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7280         7368 :       return false;
    7281              :     }
    7282         1464 :   else if (processing_template_decl)
    7283              :     {
    7284          213 :       if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
    7285              :         return true;
    7286              :       return false;
    7287              :     }
    7288              : 
    7289         1251 :   tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
    7290              : 
    7291         1251 :   type = TYPE_MAIN_VARIANT (type);
    7292         1251 :   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7293         1251 :   if (id == NULL_TREE)
    7294          924 :     id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
    7295              :                            NULL_TREE, NULL_TREE);
    7296         1251 :   id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
    7297         1251 :   if (id)
    7298              :     {
    7299         1206 :       if (id == error_mark_node)
    7300              :         return true;
    7301         1200 :       mark_used (id);
    7302         1200 :       tree body = DECL_SAVED_TREE (id);
    7303         1200 :       if (!body)
    7304              :         return true;
    7305         1197 :       if (TREE_CODE (body) == STATEMENT_LIST)
    7306              :         {
    7307         1197 :           tree_stmt_iterator tsi;
    7308         1197 :           tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
    7309         1197 :           int i;
    7310         1197 :           tree stmts[7];
    7311         1197 :           tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
    7312         1197 :           atype = TREE_TYPE (atype);
    7313         1197 :           bool need_static_cast = !same_type_p (type, atype);
    7314         1197 :           memset (stmts, 0, sizeof stmts);
    7315         1197 :           for (i = 0, tsi = tsi_start (body);
    7316         8522 :                i < 7 && !tsi_end_p (tsi);
    7317         7325 :                i++, tsi_next (&tsi))
    7318         7325 :             stmts[i] = tsi_stmt (tsi);
    7319         1197 :           gcc_assert (tsi_end_p (tsi));
    7320              : 
    7321         1197 :           if (i >= 3)
    7322              :             {
    7323         1197 :               gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
    7324              :                           && TREE_CODE (stmts[1]) == DECL_EXPR);
    7325         1197 :               placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
    7326         1197 :               DECL_ARTIFICIAL (placeholder) = 1;
    7327         1197 :               DECL_IGNORED_P (placeholder) = 1;
    7328         1197 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
    7329         1197 :               if (TREE_CODE (t) == MEM_REF)
    7330              :                 {
    7331          600 :                   decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
    7332              :                                                       type);
    7333          600 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
    7334          600 :                   DECL_IGNORED_P (decl_placeholder) = 1;
    7335          600 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
    7336              :                 }
    7337         1197 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
    7338          285 :                 cxx_mark_addressable (placeholder);
    7339         1197 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
    7340         1197 :                   && (decl_placeholder
    7341          149 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7342          372 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7343          118 :                                       : OMP_CLAUSE_DECL (c));
    7344         1197 :               tree omp_out = placeholder;
    7345         1197 :               tree omp_in = decl_placeholder ? decl_placeholder
    7346          597 :                             : convert_from_reference (OMP_CLAUSE_DECL (c));
    7347         1197 :               if (need_static_cast)
    7348              :                 {
    7349            7 :                   tree rtype = build_reference_type (atype);
    7350            7 :                   omp_out = build_static_cast (input_location,
    7351              :                                                rtype, omp_out,
    7352              :                                                tf_warning_or_error);
    7353            7 :                   omp_in = build_static_cast (input_location,
    7354              :                                               rtype, omp_in,
    7355              :                                               tf_warning_or_error);
    7356            7 :                   if (omp_out == error_mark_node || omp_in == error_mark_node)
    7357            3 :                     return true;
    7358            7 :                   omp_out = convert_from_reference (omp_out);
    7359            7 :                   omp_in = convert_from_reference (omp_in);
    7360              :                 }
    7361         1197 :               OMP_CLAUSE_REDUCTION_MERGE (c)
    7362         1197 :                 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
    7363         1197 :                                  DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
    7364              :             }
    7365         1197 :           if (i >= 6)
    7366              :             {
    7367         1005 :               gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
    7368              :                           && TREE_CODE (stmts[4]) == DECL_EXPR);
    7369         1005 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
    7370         1005 :                   && (decl_placeholder
    7371          232 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7372          844 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7373          170 :                                       : OMP_CLAUSE_DECL (c));
    7374         1005 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
    7375          216 :                 cxx_mark_addressable (placeholder);
    7376         1005 :               tree omp_priv = decl_placeholder ? decl_placeholder
    7377          429 :                               : convert_from_reference (OMP_CLAUSE_DECL (c));
    7378         1005 :               tree omp_orig = placeholder;
    7379         1005 :               if (need_static_cast)
    7380              :                 {
    7381            5 :                   if (i == 7)
    7382              :                     {
    7383            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    7384              :                                 "user defined reduction with constructor "
    7385              :                                 "initializer for base class %qT", atype);
    7386            3 :                       return true;
    7387              :                     }
    7388            2 :                   tree rtype = build_reference_type (atype);
    7389            2 :                   omp_priv = build_static_cast (input_location,
    7390              :                                                 rtype, omp_priv,
    7391              :                                                 tf_warning_or_error);
    7392            2 :                   omp_orig = build_static_cast (input_location,
    7393              :                                                 rtype, omp_orig,
    7394              :                                                 tf_warning_or_error);
    7395            2 :                   if (omp_priv == error_mark_node
    7396            2 :                       || omp_orig == error_mark_node)
    7397              :                     return true;
    7398            2 :                   omp_priv = convert_from_reference (omp_priv);
    7399            2 :                   omp_orig = convert_from_reference (omp_orig);
    7400              :                 }
    7401         1002 :               if (i == 6)
    7402          286 :                 *need_default_ctor = true;
    7403         1002 :               OMP_CLAUSE_REDUCTION_INIT (c)
    7404         1002 :                 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
    7405         1002 :                                  DECL_EXPR_DECL (stmts[3]),
    7406              :                                  omp_priv, omp_orig);
    7407         1002 :               if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
    7408              :                                 find_omp_placeholder_r, placeholder, NULL))
    7409          238 :                 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
    7410              :             }
    7411          192 :           else if (i >= 3)
    7412              :             {
    7413          192 :               if (CLASS_TYPE_P (type) && !pod_type_p (type))
    7414          175 :                 *need_default_ctor = true;
    7415              :               else
    7416              :                 {
    7417           17 :                   tree init;
    7418           17 :                   tree v = decl_placeholder ? decl_placeholder
    7419           17 :                            : convert_from_reference (t);
    7420           17 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
    7421            8 :                     init = build_constructor (TREE_TYPE (v), NULL);
    7422              :                   else
    7423            9 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
    7424           34 :                   OMP_CLAUSE_REDUCTION_INIT (c)
    7425           34 :                     = cp_build_init_expr (v, init);
    7426              :                 }
    7427              :             }
    7428              :         }
    7429              :     }
    7430         1239 :   if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
    7431         1194 :     *need_dtor = true;
    7432              :   else
    7433              :     {
    7434           90 :       error_at (OMP_CLAUSE_LOCATION (c),
    7435              :                 "user defined reduction not found for %qE",
    7436              :                 omp_clause_printable_decl (t));
    7437           45 :       return true;
    7438              :     }
    7439         1194 :   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
    7440          600 :     gcc_assert (TYPE_SIZE_UNIT (type)
    7441              :                 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
    7442              :   return false;
    7443              : }
    7444              : 
    7445              : /* Check an instance of an "omp declare mapper" function.  */
    7446              : 
    7447              : bool
    7448          208 : cp_check_omp_declare_mapper (tree udm)
    7449              : {
    7450          208 :   tree var = OMP_DECLARE_MAPPER_DECL (udm);
    7451          208 :   tree type = TREE_TYPE (var);
    7452          208 :   location_t loc = DECL_SOURCE_LOCATION (var);
    7453              : 
    7454          208 :   if (type == error_mark_node)
    7455              :     return false;
    7456              : 
    7457          208 :   if (processing_template_decl)
    7458              :     return true;
    7459              : 
    7460          197 :   if (!RECORD_OR_UNION_TYPE_P (type))
    7461              :     {
    7462           17 :       error_at (loc, "%qT is not a struct, union or class type in "
    7463              :                 "%<#pragma omp declare mapper%>", type);
    7464           17 :       return false;
    7465              :     }
    7466          180 :   if (CLASSTYPE_VBASECLASSES (type))
    7467              :     {
    7468            3 :       error_at (loc, "%qT must not be a virtual base class in "
    7469              :                 "%<#pragma omp declare mapper%>", type);
    7470            3 :       return false;
    7471              :     }
    7472              : 
    7473          177 :   tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
    7474          215 :   for ( ; c; c = OMP_CLAUSE_CHAIN (c))
    7475              :     {
    7476          187 :       tree dvar = OMP_CLAUSE_DECL (c);
    7477          400 :       while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
    7478          213 :         dvar = TREE_OPERAND (dvar, 0);
    7479          187 :       if (dvar == var)
    7480              :         break;
    7481              :     }
    7482          177 :   if (!c)
    7483              :     {
    7484              :       // After template handling, the var is mangled, demangle it
    7485           28 :       const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
    7486           28 :       char *n = NULL;
    7487           28 :       if (startswith (name, "omp declare mapper "))
    7488              :         {
    7489            3 :           name += strlen ("omp declare mapper ");
    7490            3 :           n = xstrdup (name);
    7491            3 :           n[strchr (n, '~')-n] = '\0';
    7492            3 :           name = n;
    7493              :         }
    7494           28 :       error_at (loc, "at least one %<map%> clause must map %qs or an "
    7495              :                      "element of it", name);
    7496           28 :       if (n)
    7497            3 :         free (n);
    7498           28 :       return false;
    7499              :     }
    7500              : 
    7501              :   /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
    7502              :      = 1, which is set to false in finalize_literal_type_property for C++ < 11,
    7503              :      leading to an error in ensure_literal_type_for_constexpr_object.
    7504              :      Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
    7505              :      libgomp.c++/declare-mapper-{5,6,8}.C.  */
    7506          149 :   if (cxx_dialect < cxx11)
    7507              :     {
    7508            0 :       sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
    7509              :                      "before C++11");
    7510            0 :       return false;
    7511              :     }
    7512              : 
    7513              :   return true;
    7514              : }
    7515              : 
    7516              : /* Called from finish_struct_1.  linear(this) or linear(this:step)
    7517              :    clauses might not be finalized yet because the class has been incomplete
    7518              :    when parsing #pragma omp declare simd methods.  Fix those up now.  */
    7519              : 
    7520              : void
    7521       118271 : finish_omp_declare_simd_methods (tree t)
    7522              : {
    7523       118271 :   if (processing_template_decl)
    7524              :     return;
    7525              : 
    7526       807799 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7527              :     {
    7528      1141427 :       if (TREE_CODE (x) == USING_DECL
    7529       689528 :           || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
    7530       451899 :         continue;
    7531       237629 :       tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
    7532       237737 :       if (!ods || !TREE_VALUE (ods))
    7533       237521 :         continue;
    7534          366 :       for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
    7535          258 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
    7536           66 :             && integer_zerop (OMP_CLAUSE_DECL (c))
    7537           18 :             && OMP_CLAUSE_LINEAR_STEP (c)
    7538          276 :             && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
    7539              :           {
    7540           18 :             tree s = OMP_CLAUSE_LINEAR_STEP (c);
    7541           18 :             s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
    7542           18 :             s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
    7543           18 :                                  sizetype, s, TYPE_SIZE_UNIT (t));
    7544           18 :             OMP_CLAUSE_LINEAR_STEP (c) = s;
    7545              :           }
    7546              :     }
    7547              : }
    7548              : 
    7549              : /* Adjust sink depend/doacross clause to take into account pointer offsets.
    7550              : 
    7551              :    Return TRUE if there was a problem processing the offset, and the
    7552              :    whole clause should be removed.  */
    7553              : 
    7554              : static bool
    7555          298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
    7556              : {
    7557          298 :   tree t = OMP_CLAUSE_DECL (sink_clause);
    7558          298 :   gcc_assert (TREE_CODE (t) == TREE_LIST);
    7559              : 
    7560              :   /* Make sure we don't adjust things twice for templates.  */
    7561          298 :   if (processing_template_decl)
    7562              :     return false;
    7563              : 
    7564          671 :   for (; t; t = TREE_CHAIN (t))
    7565              :     {
    7566          391 :       tree decl = TREE_VALUE (t);
    7567          391 :       if (TYPE_PTR_P (TREE_TYPE (decl)))
    7568              :         {
    7569            6 :           tree offset = TREE_PURPOSE (t);
    7570            6 :           bool neg = wi::neg_p (wi::to_wide (offset));
    7571            6 :           offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
    7572            6 :           decl = mark_rvalue_use (decl);
    7573            6 :           decl = convert_from_reference (decl);
    7574           12 :           tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
    7575              :                                      neg ? MINUS_EXPR : PLUS_EXPR,
    7576              :                                      decl, offset);
    7577            6 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
    7578              :                                 MINUS_EXPR, sizetype,
    7579              :                                 fold_convert (sizetype, t2),
    7580              :                                 fold_convert (sizetype, decl));
    7581            6 :           if (t2 == error_mark_node)
    7582              :             return true;
    7583            6 :           TREE_PURPOSE (t) = t2;
    7584              :         }
    7585              :     }
    7586              :   return false;
    7587              : }
    7588              : 
    7589              : /* Finish OpenMP iterators ITER.  Return true if they are erroneous
    7590              :    and clauses containing them should be removed.  */
    7591              : 
    7592              : static bool
    7593          615 : cp_omp_finish_iterators (tree iter)
    7594              : {
    7595          615 :   bool ret = false;
    7596         1395 :   for (tree it = iter; it; it = TREE_CHAIN (it))
    7597              :     {
    7598          780 :       tree var = TREE_VEC_ELT (it, 0);
    7599          780 :       tree begin = TREE_VEC_ELT (it, 1);
    7600          780 :       tree end = TREE_VEC_ELT (it, 2);
    7601          780 :       tree step = TREE_VEC_ELT (it, 3);
    7602          780 :       tree orig_step;
    7603          780 :       tree type = TREE_TYPE (var);
    7604          780 :       location_t loc = DECL_SOURCE_LOCATION (var);
    7605          780 :       if (type == error_mark_node)
    7606              :         {
    7607            0 :           ret = true;
    7608          218 :           continue;
    7609              :         }
    7610          780 :       if (type_dependent_expression_p (var))
    7611           59 :         continue;
    7612          721 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7613              :         {
    7614           27 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
    7615              :                     var);
    7616           27 :           ret = true;
    7617           27 :           continue;
    7618              :         }
    7619          694 :       else if (TYPE_READONLY (type))
    7620              :         {
    7621           24 :           error_at (loc, "iterator %qD has const qualified type", var);
    7622           24 :           ret = true;
    7623           24 :           continue;
    7624              :         }
    7625          670 :       if (type_dependent_expression_p (begin)
    7626          661 :           || type_dependent_expression_p (end)
    7627         1331 :           || type_dependent_expression_p (step))
    7628           15 :         continue;
    7629          655 :       else if (error_operand_p (step))
    7630              :         {
    7631            0 :           ret = true;
    7632            0 :           continue;
    7633              :         }
    7634          655 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
    7635              :         {
    7636           33 :           error_at (EXPR_LOC_OR_LOC (step, loc),
    7637              :                     "iterator step with non-integral type");
    7638           21 :           ret = true;
    7639           21 :           continue;
    7640              :         }
    7641              : 
    7642          634 :       begin = mark_rvalue_use (begin);
    7643          634 :       end = mark_rvalue_use (end);
    7644          634 :       step = mark_rvalue_use (step);
    7645          634 :       begin = cp_build_c_cast (input_location, type, begin,
    7646              :                                tf_warning_or_error);
    7647          634 :       end = cp_build_c_cast (input_location, type, end,
    7648              :                              tf_warning_or_error);
    7649          634 :       orig_step = step;
    7650          634 :       if (!processing_template_decl)
    7651          557 :         step = orig_step = save_expr (step);
    7652          634 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
    7653          634 :       step = cp_build_c_cast (input_location, stype, step,
    7654              :                               tf_warning_or_error);
    7655          634 :       if (POINTER_TYPE_P (type) && !processing_template_decl)
    7656              :         {
    7657           66 :           begin = save_expr (begin);
    7658           66 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
    7659           66 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
    7660              :                                   fold_convert (sizetype, step),
    7661              :                                   fold_convert (sizetype, begin));
    7662           66 :           step = fold_convert (ssizetype, step);
    7663              :         }
    7664          634 :       if (!processing_template_decl)
    7665              :         {
    7666          557 :           begin = maybe_constant_value (begin);
    7667          557 :           end = maybe_constant_value (end);
    7668          557 :           step = maybe_constant_value (step);
    7669          557 :           orig_step = maybe_constant_value (orig_step);
    7670              :         }
    7671          634 :       if (integer_zerop (step))
    7672              :         {
    7673           27 :           error_at (loc, "iterator %qD has zero step", var);
    7674           27 :           ret = true;
    7675           27 :           continue;
    7676              :         }
    7677              : 
    7678          607 :       if (begin == error_mark_node
    7679          598 :           || end == error_mark_node
    7680          589 :           || step == error_mark_node
    7681          589 :           || orig_step == error_mark_node)
    7682              :         {
    7683           18 :           ret = true;
    7684           18 :           continue;
    7685              :         }
    7686              : 
    7687          589 :       if (!processing_template_decl)
    7688              :         {
    7689          512 :           begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
    7690          512 :           end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
    7691          512 :           step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
    7692          512 :           orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
    7693              :                                                      orig_step);
    7694              :         }
    7695          589 :       hash_set<tree> pset;
    7696          589 :       tree it2;
    7697          745 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
    7698              :         {
    7699          183 :           tree var2 = TREE_VEC_ELT (it2, 0);
    7700          183 :           tree begin2 = TREE_VEC_ELT (it2, 1);
    7701          183 :           tree end2 = TREE_VEC_ELT (it2, 2);
    7702          183 :           tree step2 = TREE_VEC_ELT (it2, 3);
    7703          183 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
    7704          183 :           if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
    7705              :             {
    7706            9 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
    7707              :                         "begin expression refers to outer iterator %qD", var);
    7708           36 :               break;
    7709              :             }
    7710          174 :           else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
    7711              :             {
    7712            9 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
    7713              :                         "end expression refers to outer iterator %qD", var);
    7714            9 :               break;
    7715              :             }
    7716          165 :           else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
    7717              :             {
    7718            9 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
    7719              :                         "step expression refers to outer iterator %qD", var);
    7720            9 :               break;
    7721              :             }
    7722              :         }
    7723          589 :       if (it2)
    7724              :         {
    7725           27 :           ret = true;
    7726           27 :           continue;
    7727              :         }
    7728          562 :       TREE_VEC_ELT (it, 1) = begin;
    7729          562 :       TREE_VEC_ELT (it, 2) = end;
    7730          562 :       if (processing_template_decl)
    7731           71 :         TREE_VEC_ELT (it, 3) = orig_step;
    7732              :       else
    7733              :         {
    7734          491 :           TREE_VEC_ELT (it, 3) = step;
    7735          491 :           TREE_VEC_ELT (it, 4) = orig_step;
    7736              :         }
    7737          589 :     }
    7738          615 :   return ret;
    7739              : }
    7740              : 
    7741              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
    7742              :    Return true if an error has been detected.  */
    7743              : 
    7744              : static bool
    7745        18639 : cp_oacc_check_attachments (tree c)
    7746              : {
    7747        18639 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    7748              :     return false;
    7749              : 
    7750              :   /* OpenACC attach / detach clauses must be pointers.  */
    7751        14660 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    7752        14660 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    7753              :     {
    7754          196 :       tree t = OMP_CLAUSE_DECL (c);
    7755          196 :       tree type;
    7756              : 
    7757          232 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7758           36 :         t = TREE_OPERAND (t, 0);
    7759              : 
    7760          196 :       type = TREE_TYPE (t);
    7761              : 
    7762          196 :       if (TREE_CODE (type) == REFERENCE_TYPE)
    7763           36 :         type = TREE_TYPE (type);
    7764              : 
    7765          196 :       if (TREE_CODE (type) != POINTER_TYPE)
    7766              :         {
    7767           36 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
    7768              :                     user_omp_clause_code_name (c, true));
    7769           36 :           return true;
    7770              :         }
    7771              :     }
    7772              : 
    7773              :   return false;
    7774              : }
    7775              : 
    7776              : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
    7777              :    happened.  */
    7778              : 
    7779              : tree
    7780          813 : cp_finish_omp_init_prefer_type (tree pref_type)
    7781              : {
    7782          813 :   if (processing_template_decl
    7783          741 :       || pref_type == NULL_TREE
    7784          356 :       || TREE_CODE (pref_type) != TREE_LIST)
    7785              :     return pref_type;
    7786              : 
    7787           81 :   tree t = TREE_PURPOSE (pref_type);
    7788           81 :   char *str = const_cast<char *> (TREE_STRING_POINTER (t));
    7789           81 :   tree fr_list = TREE_VALUE (pref_type);
    7790           81 :   int len = TREE_VEC_LENGTH (fr_list);
    7791           81 :   int cnt = 0;
    7792              : 
    7793          270 :   while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
    7794              :     {
    7795          270 :       str++;
    7796          270 :       if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
    7797              :         {
    7798              :           /* Assume a no or a single 'fr'.  */
    7799          150 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7800          150 :           location_t loc = UNKNOWN_LOCATION;
    7801          150 :           tree value = TREE_VEC_ELT (fr_list, cnt);
    7802          150 :           if (value != NULL_TREE && value != error_mark_node)
    7803              :             {
    7804          126 :               loc = EXPR_LOCATION (value);
    7805          126 :               if (value && TREE_CODE (value) == NOP_EXPR)
    7806           39 :                 value = TREE_OPERAND (value, 0);
    7807          126 :               value = cp_fully_fold (value);
    7808              :             }
    7809          126 :           if (value != NULL_TREE && value != error_mark_node)
    7810              :             {
    7811          126 :               if (TREE_CODE (value) != INTEGER_CST
    7812          126 :                   || !tree_fits_shwi_p (value))
    7813            0 :                 error_at (loc,
    7814              :                           "expected string literal or "
    7815              :                           "constant integer expression instead of %qE", value);
    7816              :               else
    7817              :                 {
    7818          126 :                   HOST_WIDE_INT n = tree_to_shwi (value);
    7819          126 :                   if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
    7820              :                     {
    7821           48 :                       warning_at (loc, OPT_Wopenmp,
    7822              :                                   "unknown foreign runtime identifier %qwd", n);
    7823           48 :                       n = GOMP_INTEROP_IFR_UNKNOWN;
    7824              :                     }
    7825          126 :                   str[0] = (char) n;
    7826              :                 }
    7827              :             }
    7828          150 :           str++;
    7829              :         }
    7830          120 :       else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
    7831              :         {
    7832              :           /* Assume a no or a single 'fr'.  */
    7833          120 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7834          120 :           str++;
    7835              :         }
    7836          270 :       str++;
    7837          294 :       while (str[0] != '\0')
    7838           24 :         str += strlen (str) + 1;
    7839          270 :       str++;
    7840          270 :       cnt++;
    7841          270 :       if (cnt >= len)
    7842              :         break;
    7843              :     }
    7844              :   return t;
    7845              : }
    7846              : 
    7847              : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    7848              :    Remove any elements from the list that are invalid.  */
    7849              : 
    7850              : tree
    7851        62695 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
    7852              : {
    7853        62695 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
    7854        62695 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
    7855        62695 :   bitmap_head oacc_reduction_head, is_on_device_head;
    7856        62695 :   tree c, t, *pc;
    7857        62695 :   tree safelen = NULL_TREE;
    7858        62695 :   bool openacc = (ort & C_ORT_ACC) != 0;
    7859        62695 :   bool branch_seen = false;
    7860        62695 :   bool copyprivate_seen = false;
    7861        62695 :   bool ordered_seen = false;
    7862        62695 :   bool order_seen = false;
    7863        62695 :   bool schedule_seen = false;
    7864        62695 :   bool oacc_async = false;
    7865        62695 :   bool indir_component_ref_p = false;
    7866        62695 :   tree last_iterators = NULL_TREE;
    7867        62695 :   bool last_iterators_remove = false;
    7868              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
    7869              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
    7870        62695 :   int reduction_seen = 0;
    7871        62695 :   bool allocate_seen = false;
    7872        62695 :   tree detach_seen = NULL_TREE;
    7873        62695 :   bool mergeable_seen = false;
    7874        62695 :   bool implicit_moved = false;
    7875        62695 :   bool target_in_reduction_seen = false;
    7876        62695 :   bool num_tasks_seen = false;
    7877        62695 :   bool partial_seen = false;
    7878        62695 :   bool init_seen = false;
    7879        62695 :   bool init_use_destroy_seen = false;
    7880        62695 :   tree init_no_targetsync_clause = NULL_TREE;
    7881        62695 :   tree depend_clause = NULL_TREE;
    7882              : 
    7883        62695 :   if (!openacc)
    7884        49962 :     clauses = omp_remove_duplicate_maps (clauses, true);
    7885              : 
    7886        62695 :   bitmap_obstack_initialize (NULL);
    7887        62695 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
    7888        62695 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
    7889        62695 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
    7890        62695 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
    7891              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
    7892        62695 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
    7893        62695 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
    7894        62695 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
    7895              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
    7896              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
    7897        62695 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
    7898        62695 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
    7899              : 
    7900        62695 :   if (openacc)
    7901        28279 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
    7902        15934 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
    7903              :         {
    7904              :           oacc_async = true;
    7905              :           break;
    7906              :         }
    7907              : 
    7908        62695 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
    7909              : 
    7910       160635 :   for (pc = &clauses, c = clauses; c ; c = *pc)
    7911              :     {
    7912        97940 :       bool remove = false;
    7913        97940 :       bool field_ok = false;
    7914              : 
    7915              :       /* We've reached the end of a list of expanded nodes.  Reset the group
    7916              :          start pointer.  */
    7917        97940 :       if (c == grp_sentinel)
    7918              :         {
    7919         5662 :           if (grp_start_p
    7920         5662 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
    7921           96 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
    7922           66 :                  gc = OMP_CLAUSE_CHAIN (gc))
    7923           66 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
    7924              :           grp_start_p = NULL;
    7925              :         }
    7926              : 
    7927        97940 :       switch (OMP_CLAUSE_CODE (c))
    7928              :         {
    7929         2100 :         case OMP_CLAUSE_SHARED:
    7930         2100 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7931         2100 :           goto check_dup_generic;
    7932         2576 :         case OMP_CLAUSE_PRIVATE:
    7933         2576 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7934         2576 :           goto check_dup_generic;
    7935         7338 :         case OMP_CLAUSE_REDUCTION:
    7936         7338 :           if (reduction_seen == 0)
    7937         6234 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
    7938         1104 :           else if (reduction_seen != -2
    7939         2208 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
    7940         1104 :                                          ? -1 : 1))
    7941              :             {
    7942            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7943              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
    7944              :                         "on the same construct");
    7945            6 :               reduction_seen = -2;
    7946              :             }
    7947              :           /* FALLTHRU */
    7948         9483 :         case OMP_CLAUSE_IN_REDUCTION:
    7949         9483 :         case OMP_CLAUSE_TASK_REDUCTION:
    7950         9483 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7951         9483 :           t = OMP_CLAUSE_DECL (c);
    7952         9483 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7953              :             {
    7954         2207 :               if (handle_omp_array_sections (c, ort))
    7955              :                 {
    7956              :                   remove = true;
    7957              :                   break;
    7958              :                 }
    7959         2165 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    7960         2165 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
    7961              :                 {
    7962            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7963              :                             "%<inscan%> %<reduction%> clause with array "
    7964              :                             "section");
    7965            3 :                   remove = true;
    7966            3 :                   break;
    7967              :                 }
    7968         2162 :               if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7969              :                 {
    7970         4672 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7971         2510 :                     t = TREE_OPERAND (t, 0);
    7972              :                 }
    7973              :               else
    7974              :                 {
    7975            0 :                   gcc_assert (TREE_CODE (t) == MEM_REF);
    7976            0 :                   t = TREE_OPERAND (t, 0);
    7977            0 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
    7978            0 :                     t = TREE_OPERAND (t, 0);
    7979            0 :                   if (TREE_CODE (t) == ADDR_EXPR
    7980            0 :                       || INDIRECT_REF_P (t))
    7981            0 :                     t = TREE_OPERAND (t, 0);
    7982              :                 }
    7983         2162 :               tree n = omp_clause_decl_field (t);
    7984         2162 :               if (n)
    7985           59 :                 t = n;
    7986         2162 :               goto check_dup_generic_t;
    7987              :             }
    7988         7276 :           if (oacc_async)
    7989            7 :             cxx_mark_addressable (t);
    7990         7276 :           goto check_dup_generic;
    7991           98 :         case OMP_CLAUSE_COPYPRIVATE:
    7992           98 :           copyprivate_seen = true;
    7993           98 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7994           98 :           goto check_dup_generic;
    7995          277 :         case OMP_CLAUSE_COPYIN:
    7996          277 :           goto check_dup_generic;
    7997         1631 :         case OMP_CLAUSE_LINEAR:
    7998         1631 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7999         1631 :           t = OMP_CLAUSE_DECL (c);
    8000         1631 :           if (ort != C_ORT_OMP_DECLARE_SIMD
    8001         1631 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
    8002              :             {
    8003           84 :               if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
    8004              :                 {
    8005           42 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8006              :                             "modifier should not be specified in %<linear%> "
    8007              :                             "clause on %<simd%> or %<for%> constructs when "
    8008              :                             "not using OpenMP 5.2 modifiers");
    8009           42 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8010              :                 }
    8011           42 :               else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
    8012              :                 {
    8013           18 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8014              :                             "modifier other than %<val%> specified in "
    8015              :                             "%<linear%> clause on %<simd%> or %<for%> "
    8016              :                             "constructs when using OpenMP 5.2 modifiers");
    8017           18 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8018              :                 }
    8019              :             }
    8020         1011 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    8021         2571 :               && !type_dependent_expression_p (t))
    8022              :             {
    8023         1529 :               tree type = TREE_TYPE (t);
    8024         1529 :               if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8025         1448 :                    || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
    8026         1598 :                   && !TYPE_REF_P (type))
    8027              :                 {
    8028           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8029              :                             "linear clause with %qs modifier applied to "
    8030              :                             "non-reference variable with %qT type",
    8031           12 :                             OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8032           12 :                             ? "ref" : "uval", TREE_TYPE (t));
    8033           12 :                   remove = true;
    8034           12 :                   break;
    8035              :                 }
    8036         1517 :               if (TYPE_REF_P (type))
    8037          281 :                 type = TREE_TYPE (type);
    8038         1517 :               if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
    8039              :                 {
    8040         1442 :                   if (!INTEGRAL_TYPE_P (type)
    8041           85 :                       && !TYPE_PTR_P (type))
    8042              :                     {
    8043           18 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8044              :                                 "linear clause applied to non-integral "
    8045              :                                 "non-pointer variable with %qT type",
    8046           18 :                                 TREE_TYPE (t));
    8047           18 :                       remove = true;
    8048           18 :                       break;
    8049              :                     }
    8050              :                 }
    8051              :             }
    8052         1601 :           t = OMP_CLAUSE_LINEAR_STEP (c);
    8053         1601 :           if (t == NULL_TREE)
    8054            6 :             t = integer_one_node;
    8055         1601 :           if (t == error_mark_node)
    8056              :             {
    8057              :               remove = true;
    8058              :               break;
    8059              :             }
    8060         1601 :           else if (!type_dependent_expression_p (t)
    8061         1599 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t))
    8062         1613 :                    && (ort != C_ORT_OMP_DECLARE_SIMD
    8063            9 :                        || TREE_CODE (t) != PARM_DECL
    8064            6 :                        || !TYPE_REF_P (TREE_TYPE (t))
    8065            6 :                        || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
    8066              :             {
    8067            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8068              :                         "linear step expression must be integral");
    8069            6 :               remove = true;
    8070            6 :               break;
    8071              :             }
    8072              :           else
    8073              :             {
    8074         1595 :               t = mark_rvalue_use (t);
    8075         1595 :               if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
    8076              :                 {
    8077           42 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
    8078           42 :                   goto check_dup_generic;
    8079              :                 }
    8080         1553 :               if (!processing_template_decl
    8081         1553 :                   && (VAR_P (OMP_CLAUSE_DECL (c))
    8082          835 :                       || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
    8083              :                 {
    8084         1372 :                   if (ort == C_ORT_OMP_DECLARE_SIMD)
    8085              :                     {
    8086          589 :                       t = maybe_constant_value (t);
    8087          589 :                       if (TREE_CODE (t) != INTEGER_CST)
    8088              :                         {
    8089            6 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8090              :                                     "%<linear%> clause step %qE is neither "
    8091              :                                      "constant nor a parameter", t);
    8092            6 :                           remove = true;
    8093            6 :                           break;
    8094              :                         }
    8095              :                     }
    8096         1366 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8097         1366 :                   tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
    8098         1366 :                   if (TYPE_REF_P (type))
    8099          257 :                     type = TREE_TYPE (type);
    8100         1366 :                   if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
    8101              :                     {
    8102           66 :                       type = build_pointer_type (type);
    8103           66 :                       tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
    8104           66 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8105              :                                            d, t);
    8106           66 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8107              :                                            MINUS_EXPR, sizetype,
    8108              :                                            fold_convert (sizetype, t),
    8109              :                                            fold_convert (sizetype, d));
    8110           66 :                       if (t == error_mark_node)
    8111              :                         {
    8112              :                           remove = true;
    8113              :                           break;
    8114              :                         }
    8115              :                     }
    8116         1300 :                   else if (TYPE_PTR_P (type)
    8117              :                            /* Can't multiply the step yet if *this
    8118              :                               is still incomplete type.  */
    8119         1300 :                            && (ort != C_ORT_OMP_DECLARE_SIMD
    8120           45 :                                || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
    8121           45 :                                || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
    8122           30 :                                || DECL_NAME (OMP_CLAUSE_DECL (c))
    8123           30 :                                   != this_identifier
    8124           30 :                                || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
    8125              :                     {
    8126           37 :                       tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
    8127           37 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8128              :                                            d, t);
    8129           37 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8130              :                                            MINUS_EXPR, sizetype,
    8131              :                                            fold_convert (sizetype, t),
    8132              :                                            fold_convert (sizetype, d));
    8133           37 :                       if (t == error_mark_node)
    8134              :                         {
    8135              :                           remove = true;
    8136              :                           break;
    8137              :                         }
    8138              :                     }
    8139              :                   else
    8140         1263 :                     t = fold_convert (type, t);
    8141              :                 }
    8142         1547 :               OMP_CLAUSE_LINEAR_STEP (c) = t;
    8143              :             }
    8144         1547 :           goto check_dup_generic;
    8145        14882 :         check_dup_generic:
    8146        14882 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8147        14882 :           if (t)
    8148              :             {
    8149          101 :               if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
    8150          101 :                 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8151              :             }
    8152              :           else
    8153        14781 :             t = OMP_CLAUSE_DECL (c);
    8154        17311 :         check_dup_generic_t:
    8155        17311 :           if (t == current_class_ptr
    8156        17311 :               && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
    8157          102 :                   || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
    8158           72 :                       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
    8159              :             {
    8160           24 :               error_at (OMP_CLAUSE_LOCATION (c),
    8161              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8162              :                         " clauses");
    8163           24 :               remove = true;
    8164           24 :               break;
    8165              :             }
    8166        17287 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8167          586 :               && (!field_ok || TREE_CODE (t) != FIELD_DECL))
    8168              :             {
    8169           59 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8170              :                 break;
    8171           39 :               if (DECL_P (t))
    8172           30 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8173              :                           "%qD is not a variable in clause %qs", t,
    8174           15 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8175              :               else
    8176           48 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8177              :                           "%qE is not a variable in clause %qs", t,
    8178           24 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8179              :               remove = true;
    8180              :             }
    8181        17228 :           else if ((openacc
    8182         2707 :                     && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
    8183        14759 :                    || (ort == C_ORT_OMP
    8184        12428 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    8185        12397 :                            || (OMP_CLAUSE_CODE (c)
    8186              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
    8187        31880 :                    || (ort == C_ORT_OMP_TARGET
    8188          936 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
    8189              :             {
    8190         2854 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    8191         2854 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
    8192          275 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
    8193              :                 {
    8194            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8195              :                             "%qD appears more than once in data-sharing "
    8196              :                             "clauses", t);
    8197            6 :                   remove = true;
    8198            6 :                   break;
    8199              :                 }
    8200         2848 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
    8201          272 :                 target_in_reduction_seen = true;
    8202         2848 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8203              :                 {
    8204           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8205              :                             openacc
    8206              :                             ? "%qD appears more than once in reduction clauses"
    8207              :                             : "%qD appears more than once in data clauses",
    8208              :                             t);
    8209            6 :                   remove = true;
    8210              :                 }
    8211              :               else
    8212         2842 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8213              :             }
    8214        14374 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8215        14299 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8216        14296 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
    8217        28670 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8218              :             {
    8219           78 :               error_at (OMP_CLAUSE_LOCATION (c),
    8220              :                         "%qD appears more than once in data clauses", t);
    8221           78 :               remove = true;
    8222              :             }
    8223        14296 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    8224              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
    8225              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    8226         3115 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
    8227              :             {
    8228            9 :               if (openacc)
    8229            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8230              :                           "%qD appears more than once in data clauses", t);
    8231              :               else
    8232            9 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8233              :                           "%qD appears both in data and map clauses", t);
    8234              :               remove = true;
    8235              :             }
    8236              :           else
    8237        14287 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    8238        17261 :           if (!field_ok)
    8239              :             break;
    8240        12853 :         handle_field_decl:
    8241        21367 :           if (!remove
    8242        21170 :               && TREE_CODE (t) == FIELD_DECL
    8243        16495 :               && t == OMP_CLAUSE_DECL (c))
    8244              :             {
    8245          795 :               OMP_CLAUSE_DECL (c)
    8246          795 :                 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
    8247              :                                            == OMP_CLAUSE_SHARED));
    8248          795 :               if (OMP_CLAUSE_DECL (c) == error_mark_node)
    8249        97472 :                 remove = true;
    8250              :             }
    8251              :           break;
    8252              : 
    8253         3473 :         case OMP_CLAUSE_FIRSTPRIVATE:
    8254         3473 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
    8255              :             {
    8256          414 :             move_implicit:
    8257          414 :               implicit_moved = true;
    8258              :               /* Move firstprivate and map clauses with
    8259              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
    8260              :                  clauses chain.  */
    8261          414 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
    8262          414 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
    8263         2704 :               while (*pc1)
    8264         2290 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
    8265         2290 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
    8266              :                   {
    8267          275 :                     *pc3 = *pc1;
    8268          275 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
    8269          275 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8270              :                   }
    8271         2015 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
    8272         2015 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
    8273              :                   {
    8274          370 :                     *pc2 = *pc1;
    8275          370 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
    8276          370 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8277              :                   }
    8278              :                 else
    8279         1645 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
    8280          414 :               *pc3 = NULL;
    8281          414 :               *pc2 = cl2;
    8282          414 :               *pc1 = cl1;
    8283          414 :               continue;
    8284          414 :             }
    8285         3216 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8286         3216 :           if (t)
    8287           69 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8288              :           else
    8289         3147 :             t = OMP_CLAUSE_DECL (c);
    8290         3216 :           if (!openacc && t == current_class_ptr)
    8291              :             {
    8292            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8293              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8294              :                         " clauses");
    8295            6 :               remove = true;
    8296            6 :               break;
    8297              :             }
    8298         3210 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8299          333 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8300          333 :                   || TREE_CODE (t) != FIELD_DECL))
    8301              :             {
    8302           41 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8303              :                 break;
    8304           18 :               if (DECL_P (t))
    8305           12 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8306              :                           "%qD is not a variable in clause %<firstprivate%>",
    8307              :                           t);
    8308              :               else
    8309            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8310              :                           "%qE is not a variable in clause %<firstprivate%>",
    8311              :                           t);
    8312           18 :               remove = true;
    8313              :             }
    8314         3169 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8315          275 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
    8316         3423 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8317              :             remove = true;
    8318         3169 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8319         3160 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8320         6326 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8321              :             {
    8322           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    8323              :                         "%qD appears more than once in data clauses", t);
    8324           15 :               remove = true;
    8325              :             }
    8326         3154 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
    8327         3154 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
    8328              :             {
    8329           21 :               if (openacc)
    8330            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8331              :                           "%qD appears more than once in data clauses", t);
    8332           21 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8333           21 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
    8334              :                 /* Silently drop the clause.  */;
    8335              :               else
    8336           18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8337              :                           "%qD appears both in data and map clauses", t);
    8338           21 :               remove = true;
    8339              :             }
    8340              :           else
    8341         3133 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
    8342         3187 :           goto handle_field_decl;
    8343              : 
    8344         2790 :         case OMP_CLAUSE_LASTPRIVATE:
    8345         2790 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8346         2790 :           if (t)
    8347           35 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8348              :           else
    8349         2755 :             t = OMP_CLAUSE_DECL (c);
    8350         2790 :           if (!openacc && t == current_class_ptr)
    8351              :             {
    8352            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8353              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8354              :                         " clauses");
    8355            6 :               remove = true;
    8356            6 :               break;
    8357              :             }
    8358         2784 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8359          259 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8360          259 :                   || TREE_CODE (t) != FIELD_DECL))
    8361              :             {
    8362           35 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8363              :                 break;
    8364            9 :               if (DECL_P (t))
    8365            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8366              :                           "%qD is not a variable in clause %<lastprivate%>",
    8367              :                           t);
    8368              :               else
    8369            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8370              :                           "%qE is not a variable in clause %<lastprivate%>",
    8371              :                           t);
    8372            9 :               remove = true;
    8373              :             }
    8374         2749 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8375         2749 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
    8376              :             {
    8377           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8378              :                         "%qD appears more than once in data clauses", t);
    8379           12 :               remove = true;
    8380              :             }
    8381              :           else
    8382         2737 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
    8383         2758 :           goto handle_field_decl;
    8384              : 
    8385         2218 :         case OMP_CLAUSE_IF:
    8386         2218 :         case OMP_CLAUSE_SELF:
    8387         2218 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8388         2218 :           t = maybe_convert_cond (t);
    8389         2218 :           if (t == error_mark_node)
    8390              :             remove = true;
    8391         2203 :           else if (!processing_template_decl)
    8392         2142 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8393         2218 :           OMP_CLAUSE_OPERAND (c, 0) = t;
    8394         2218 :           break;
    8395              : 
    8396          289 :         case OMP_CLAUSE_FINAL:
    8397          289 :           t = OMP_CLAUSE_FINAL_EXPR (c);
    8398          289 :           t = maybe_convert_cond (t);
    8399          289 :           if (t == error_mark_node)
    8400              :             remove = true;
    8401          289 :           else if (!processing_template_decl)
    8402          283 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8403          289 :           OMP_CLAUSE_FINAL_EXPR (c) = t;
    8404          289 :           break;
    8405              : 
    8406           92 :         case OMP_CLAUSE_NOCONTEXT:
    8407           92 :           t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
    8408           92 :           t = maybe_convert_cond (t);
    8409           92 :           if (t == error_mark_node)
    8410              :             remove = true;
    8411           89 :           else if (!processing_template_decl)
    8412           83 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8413           92 :           OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
    8414           92 :           break;
    8415              : 
    8416           80 :         case OMP_CLAUSE_NOVARIANTS:
    8417           80 :           t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
    8418           80 :           t = maybe_convert_cond (t);
    8419           80 :           if (t == error_mark_node)
    8420              :             remove = true;
    8421           77 :           else if (!processing_template_decl)
    8422           71 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8423           80 :           OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
    8424           80 :           break;
    8425              : 
    8426         1249 :         case OMP_CLAUSE_GANG:
    8427              :           /* Operand 1 is the gang static: argument.  */
    8428         1249 :           t = OMP_CLAUSE_OPERAND (c, 1);
    8429         1249 :           if (t != NULL_TREE)
    8430              :             {
    8431          129 :               if (t == error_mark_node)
    8432              :                 remove = true;
    8433          129 :               else if (!type_dependent_expression_p (t)
    8434          129 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8435              :                 {
    8436            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8437              :                             "%<gang%> static expression must be integral");
    8438            6 :                   remove = true;
    8439              :                 }
    8440              :               else
    8441              :                 {
    8442          123 :                   t = mark_rvalue_use (t);
    8443          123 :                   if (!processing_template_decl)
    8444              :                     {
    8445          123 :                       t = maybe_constant_value (t);
    8446          123 :                       if (TREE_CODE (t) == INTEGER_CST
    8447          109 :                           && tree_int_cst_sgn (t) != 1
    8448          176 :                           && t != integer_minus_one_node)
    8449              :                         {
    8450            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8451              :                                       "%<gang%> static value must be "
    8452              :                                       "positive");
    8453            0 :                           t = integer_one_node;
    8454              :                         }
    8455          123 :                       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8456              :                     }
    8457              :                 }
    8458          129 :               OMP_CLAUSE_OPERAND (c, 1) = t;
    8459              :             }
    8460              :           /* Check operand 0, the num argument.  */
    8461              :           /* FALLTHRU */
    8462              : 
    8463         3480 :         case OMP_CLAUSE_WORKER:
    8464         3480 :         case OMP_CLAUSE_VECTOR:
    8465         3480 :           if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
    8466              :             break;
    8467              :           /* FALLTHRU */
    8468              : 
    8469          484 :         case OMP_CLAUSE_NUM_TASKS:
    8470          484 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
    8471          136 :             num_tasks_seen = true;
    8472              :           /* FALLTHRU */
    8473              : 
    8474         3034 :         case OMP_CLAUSE_NUM_TEAMS:
    8475         3034 :         case OMP_CLAUSE_NUM_THREADS:
    8476         3034 :         case OMP_CLAUSE_NUM_GANGS:
    8477         3034 :         case OMP_CLAUSE_NUM_WORKERS:
    8478         3034 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
    8479         3034 :         case OMP_CLAUSE_VECTOR_LENGTH:
    8480         3034 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8481         3034 :           if (t == error_mark_node)
    8482              :             remove = true;
    8483         3034 :           else if (!type_dependent_expression_p (t)
    8484         3034 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8485              :             {
    8486           99 :              switch (OMP_CLAUSE_CODE (c))
    8487              :                 {
    8488           12 :                 case OMP_CLAUSE_GANG:
    8489           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8490           12 :                             "%<gang%> num expression must be integral"); break;
    8491           12 :                 case OMP_CLAUSE_VECTOR:
    8492           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8493              :                             "%<vector%> length expression must be integral");
    8494           12 :                   break;
    8495           12 :                 case OMP_CLAUSE_WORKER:
    8496           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8497              :                             "%<worker%> num expression must be integral");
    8498           12 :                   break;
    8499           63 :                 default:
    8500           63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8501              :                             "%qs expression must be integral",
    8502           63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8503              :                 }
    8504              :               remove = true;
    8505              :             }
    8506              :           else
    8507              :             {
    8508         2935 :               t = mark_rvalue_use (t);
    8509         2935 :               if (!processing_template_decl)
    8510              :                 {
    8511         2687 :                   t = maybe_constant_value (t);
    8512         2687 :                   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
    8513         2652 :                       && TREE_CODE (t) == INTEGER_CST
    8514         4142 :                       && tree_int_cst_sgn (t) != 1)
    8515              :                     {
    8516           85 :                       switch (OMP_CLAUSE_CODE (c))
    8517              :                         {
    8518            3 :                         case OMP_CLAUSE_GANG:
    8519            3 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8520              :                                       "%<gang%> num value must be positive");
    8521            3 :                           break;
    8522            0 :                         case OMP_CLAUSE_VECTOR:
    8523            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8524              :                                       "%<vector%> length value must be "
    8525              :                                       "positive");
    8526            0 :                           break;
    8527            0 :                         case OMP_CLAUSE_WORKER:
    8528            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8529              :                                       "%<worker%> num value must be "
    8530              :                                       "positive");
    8531            0 :                           break;
    8532           82 :                         default:
    8533           82 :                           warning_at (OMP_CLAUSE_LOCATION (c),
    8534           46 :                                       (flag_openmp || flag_openmp_simd)
    8535           82 :                                       ? OPT_Wopenmp : 0,
    8536              :                                       "%qs value must be positive",
    8537              :                                       omp_clause_code_name
    8538           82 :                                       [OMP_CLAUSE_CODE (c)]);
    8539              :                         }
    8540           85 :                       t = integer_one_node;
    8541              :                     }
    8542         2602 :                   else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
    8543           35 :                            && TREE_CODE (t) == INTEGER_CST
    8544         2625 :                            && tree_int_cst_sgn (t) < 0)
    8545              :                     {
    8546            8 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8547              :                                   "%<dyn_groupprivate%> value must be "
    8548              :                                   "non-negative");
    8549            8 :                       t = integer_zero_node;
    8550              :                     }
    8551         2687 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8552              :                 }
    8553         2935 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8554              :             }
    8555         3034 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
    8556          752 :               && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
    8557         3313 :               && !remove)
    8558              :             {
    8559          279 :               t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
    8560          279 :               if (t == error_mark_node)
    8561              :                 remove = true;
    8562          279 :               else if (!type_dependent_expression_p (t)
    8563          279 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8564              :                 {
    8565            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8566              :                             "%qs expression must be integral",
    8567            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8568            0 :                   remove = true;
    8569              :                 }
    8570              :               else
    8571              :                 {
    8572          279 :                   t = mark_rvalue_use (t);
    8573          279 :                   if (!processing_template_decl)
    8574              :                     {
    8575          213 :                       t = maybe_constant_value (t);
    8576          213 :                       if (TREE_CODE (t) == INTEGER_CST
    8577          213 :                           && tree_int_cst_sgn (t) != 1)
    8578              :                         {
    8579           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8580              :                                       "%qs value must be positive",
    8581              :                                       omp_clause_code_name
    8582           18 :                                       [OMP_CLAUSE_CODE (c)]);
    8583           18 :                           t = NULL_TREE;
    8584              :                         }
    8585              :                       else
    8586          195 :                         t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8587          213 :                       tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
    8588          213 :                       if (t
    8589          195 :                           && TREE_CODE (t) == INTEGER_CST
    8590           43 :                           && TREE_CODE (upper) == INTEGER_CST
    8591          250 :                           && tree_int_cst_lt (upper, t))
    8592              :                         {
    8593           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8594              :                                       "%<num_teams%> lower bound %qE bigger "
    8595              :                                       "than upper bound %qE", t, upper);
    8596           18 :                           t = NULL_TREE;
    8597              :                         }
    8598              :                     }
    8599          279 :                   OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
    8600              :                 }
    8601              :             }
    8602              :           break;
    8603              : 
    8604         3862 :         case OMP_CLAUSE_SCHEDULE:
    8605         3862 :           t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
    8606         3862 :           if (t == NULL)
    8607              :             ;
    8608         2078 :           else if (t == error_mark_node)
    8609              :             remove = true;
    8610         2078 :           else if (!type_dependent_expression_p (t)
    8611         2078 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8612              :             {
    8613            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    8614              :                         "schedule chunk size expression must be integral");
    8615            9 :               remove = true;
    8616              :             }
    8617              :           else
    8618              :             {
    8619         2069 :               t = mark_rvalue_use (t);
    8620         2069 :               if (!processing_template_decl)
    8621              :                 {
    8622         2029 :                   t = maybe_constant_value (t);
    8623         2029 :                   if (TREE_CODE (t) == INTEGER_CST
    8624         2029 :                       && tree_int_cst_sgn (t) != 1)
    8625              :                   {
    8626            6 :                     warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8627              :                               "chunk size value must be positive");
    8628            6 :                     t = integer_one_node;
    8629              :                   }
    8630         2029 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8631              :                 }
    8632         2069 :               OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
    8633              :             }
    8634         2078 :           if (!remove)
    8635              :             schedule_seen = true;
    8636              :           break;
    8637              : 
    8638         1268 :         case OMP_CLAUSE_SIMDLEN:
    8639         1268 :         case OMP_CLAUSE_SAFELEN:
    8640         1268 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8641         1268 :           if (t == error_mark_node)
    8642              :             remove = true;
    8643         1268 :           else if (!type_dependent_expression_p (t)
    8644         1268 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8645              :             {
    8646            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8647              :                         "%qs length expression must be integral",
    8648            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8649            0 :               remove = true;
    8650              :             }
    8651              :           else
    8652              :             {
    8653         1268 :               t = mark_rvalue_use (t);
    8654         1268 :               if (!processing_template_decl)
    8655              :                 {
    8656         1219 :                   t = maybe_constant_value (t);
    8657         1219 :                   if (TREE_CODE (t) != INTEGER_CST
    8658         1219 :                       || tree_int_cst_sgn (t) != 1)
    8659              :                     {
    8660            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8661              :                                 "%qs length expression must be positive "
    8662              :                                 "constant integer expression",
    8663            0 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8664            0 :                       remove = true;
    8665              :                     }
    8666              :                 }
    8667         1268 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8668         1268 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
    8669          470 :                 safelen = c;
    8670              :             }
    8671              :           break;
    8672              : 
    8673          388 :         case OMP_CLAUSE_ASYNC:
    8674          388 :           t = OMP_CLAUSE_ASYNC_EXPR (c);
    8675          388 :           if (t == error_mark_node)
    8676              :             remove = true;
    8677          373 :           else if (!type_dependent_expression_p (t)
    8678          373 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8679              :             {
    8680           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8681              :                         "%<async%> expression must be integral");
    8682           12 :               remove = true;
    8683              :             }
    8684              :           else
    8685              :             {
    8686          361 :               t = mark_rvalue_use (t);
    8687          361 :               if (!processing_template_decl)
    8688          352 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8689          361 :               OMP_CLAUSE_ASYNC_EXPR (c) = t;
    8690              :             }
    8691              :           break;
    8692              : 
    8693          204 :         case OMP_CLAUSE_WAIT:
    8694          204 :           t = OMP_CLAUSE_WAIT_EXPR (c);
    8695          204 :           if (t == error_mark_node)
    8696              :             remove = true;
    8697          204 :           else if (!processing_template_decl)
    8698          196 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8699          204 :           OMP_CLAUSE_WAIT_EXPR (c) = t;
    8700          204 :           break;
    8701              : 
    8702          637 :         case OMP_CLAUSE_THREAD_LIMIT:
    8703          637 :           t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
    8704          637 :           if (t == error_mark_node)
    8705              :             remove = true;
    8706          637 :           else if (!type_dependent_expression_p (t)
    8707          637 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8708              :             {
    8709            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8710              :                         "%<thread_limit%> expression must be integral");
    8711            0 :               remove = true;
    8712              :             }
    8713              :           else
    8714              :             {
    8715          637 :               t = mark_rvalue_use (t);
    8716          637 :               if (!processing_template_decl)
    8717              :                 {
    8718          583 :                   t = maybe_constant_value (t);
    8719          583 :                   if (TREE_CODE (t) == INTEGER_CST
    8720          583 :                       && tree_int_cst_sgn (t) != 1)
    8721              :                     {
    8722            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8723              :                                   "%<thread_limit%> value must be positive");
    8724            0 :                       t = integer_one_node;
    8725              :                     }
    8726          583 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8727              :                 }
    8728          637 :               OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
    8729              :             }
    8730              :           break;
    8731              : 
    8732          770 :         case OMP_CLAUSE_DEVICE:
    8733          770 :           t = OMP_CLAUSE_DEVICE_ID (c);
    8734          770 :           if (t == error_mark_node)
    8735              :             remove = true;
    8736          770 :           else if (!type_dependent_expression_p (t)
    8737          770 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8738              :             {
    8739            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8740              :                         "%<device%> id must be integral");
    8741            6 :               remove = true;
    8742              :             }
    8743          764 :           else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
    8744           66 :                    && TREE_CODE (t) == INTEGER_CST
    8745          824 :                    && !integer_onep (t))
    8746              :             {
    8747            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    8748              :                         "the %<device%> clause expression must evaluate to "
    8749              :                         "%<1%>");
    8750            3 :               remove = true;
    8751              :             }
    8752              :           else
    8753              :             {
    8754          761 :               t = mark_rvalue_use (t);
    8755          761 :               if (!processing_template_decl)
    8756          750 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8757          761 :               OMP_CLAUSE_DEVICE_ID (c) = t;
    8758              :             }
    8759              :           break;
    8760              : 
    8761         1836 :         case OMP_CLAUSE_DIST_SCHEDULE:
    8762         1836 :           t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
    8763         1836 :           if (t == NULL)
    8764              :             ;
    8765         1815 :           else if (t == error_mark_node)
    8766              :             remove = true;
    8767         1815 :           else if (!type_dependent_expression_p (t)
    8768         1815 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8769              :             {
    8770            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8771              :                         "%<dist_schedule%> chunk size expression must be "
    8772              :                         "integral");
    8773            0 :               remove = true;
    8774              :             }
    8775              :           else
    8776              :             {
    8777         1815 :               t = mark_rvalue_use (t);
    8778         1815 :               if (!processing_template_decl)
    8779         1815 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8780         1815 :               OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
    8781              :             }
    8782              :           break;
    8783              : 
    8784          807 :         case OMP_CLAUSE_ALIGNED:
    8785          807 :           t = OMP_CLAUSE_DECL (c);
    8786          807 :           if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
    8787              :             {
    8788            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8789              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8790              :                         " clauses");
    8791            0 :               remove = true;
    8792            0 :               break;
    8793              :             }
    8794          807 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8795              :             {
    8796            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8797              :                 break;
    8798            0 :               if (DECL_P (t))
    8799            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8800              :                           "%qD is not a variable in %<aligned%> clause", t);
    8801              :               else
    8802            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8803              :                           "%qE is not a variable in %<aligned%> clause", t);
    8804              :               remove = true;
    8805              :             }
    8806          807 :           else if (!type_dependent_expression_p (t)
    8807          789 :                    && !TYPE_PTR_P (TREE_TYPE (t))
    8808          111 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    8809          864 :                    && (!TYPE_REF_P (TREE_TYPE (t))
    8810           39 :                        || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
    8811           30 :                            && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
    8812              :                                != ARRAY_TYPE))))
    8813              :             {
    8814           33 :               error_at (OMP_CLAUSE_LOCATION (c),
    8815              :                         "%qE in %<aligned%> clause is neither a pointer nor "
    8816              :                         "an array nor a reference to pointer or array", t);
    8817           33 :               remove = true;
    8818              :             }
    8819          774 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8820              :             {
    8821            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8822              :                         "%qD appears more than once in %<aligned%> clauses",
    8823              :                         t);
    8824            0 :               remove = true;
    8825              :             }
    8826              :           else
    8827          774 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
    8828          807 :           t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
    8829          807 :           if (t == error_mark_node)
    8830              :             remove = true;
    8831          807 :           else if (t == NULL_TREE)
    8832              :             break;
    8833          744 :           else if (!type_dependent_expression_p (t)
    8834          744 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8835              :             {
    8836            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8837              :                         "%<aligned%> clause alignment expression must "
    8838              :                         "be integral");
    8839            0 :               remove = true;
    8840              :             }
    8841              :           else
    8842              :             {
    8843          744 :               t = mark_rvalue_use (t);
    8844          744 :               if (!processing_template_decl)
    8845              :                 {
    8846          690 :                   t = maybe_constant_value (t);
    8847          690 :                   if (TREE_CODE (t) != INTEGER_CST
    8848          690 :                       || tree_int_cst_sgn (t) != 1)
    8849              :                     {
    8850            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8851              :                                 "%<aligned%> clause alignment expression must "
    8852              :                                 "be positive constant integer expression");
    8853            0 :                       remove = true;
    8854              :                     }
    8855              :                 }
    8856          744 :               OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
    8857              :             }
    8858              :           break;
    8859              : 
    8860          369 :         case OMP_CLAUSE_NONTEMPORAL:
    8861          369 :           t = OMP_CLAUSE_DECL (c);
    8862          369 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8863              :             {
    8864            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8865              :                 break;
    8866            0 :               if (DECL_P (t))
    8867            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8868              :                           "%qD is not a variable in %<nontemporal%> clause",
    8869              :                           t);
    8870              :               else
    8871            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8872              :                           "%qE is not a variable in %<nontemporal%> clause",
    8873              :                           t);
    8874              :               remove = true;
    8875              :             }
    8876          369 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8877              :             {
    8878            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8879              :                         "%qD appears more than once in %<nontemporal%> "
    8880              :                         "clauses", t);
    8881            6 :               remove = true;
    8882              :             }
    8883              :           else
    8884          363 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8885              :           break;
    8886              : 
    8887         2585 :         case OMP_CLAUSE_ALLOCATE:
    8888         2585 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8889         2585 :           if (t)
    8890           14 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8891              :           else
    8892         2571 :             t = OMP_CLAUSE_DECL (c);
    8893         2585 :           if (t == current_class_ptr)
    8894              :             {
    8895            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8896              :                         "%<this%> not allowed in %<allocate%> clause");
    8897            0 :               remove = true;
    8898            0 :               break;
    8899              :             }
    8900         2585 :           if (!VAR_P (t)
    8901          558 :               && TREE_CODE (t) != PARM_DECL
    8902           45 :               && TREE_CODE (t) != FIELD_DECL)
    8903              :             {
    8904            3 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8905              :                 break;
    8906            3 :               if (DECL_P (t))
    8907            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8908              :                           "%qD is not a variable in %<allocate%> clause", t);
    8909              :               else
    8910            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8911              :                           "%qE is not a variable in %<allocate%> clause", t);
    8912              :               remove = true;
    8913              :             }
    8914         2582 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8915              :             {
    8916           12 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8917              :                         "%qD appears more than once in %<allocate%> clauses",
    8918              :                         t);
    8919           12 :               remove = true;
    8920              :             }
    8921              :           else
    8922              :             {
    8923         2570 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
    8924         2570 :               allocate_seen = true;
    8925              :             }
    8926         2585 :           tree allocator, align;
    8927         2585 :           align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
    8928         2585 :           if (error_operand_p (align))
    8929              :             {
    8930              :               remove = true;
    8931              :               break;
    8932              :             }
    8933         2585 :           if (align)
    8934              :             {
    8935          207 :               if (!type_dependent_expression_p (align)
    8936          207 :                   && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    8937              :                 {
    8938            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8939              :                             "%<allocate%> clause %<align%> modifier "
    8940              :                             "argument needs to be positive constant "
    8941              :                             "power of two integer expression");
    8942            4 :                   remove = true;
    8943              :                 }
    8944              :               else
    8945              :                 {
    8946          203 :                   align = mark_rvalue_use (align);
    8947          203 :                   if (!processing_template_decl)
    8948              :                     {
    8949          188 :                       align = maybe_constant_value (align);
    8950          188 :                       if (TREE_CODE (align) != INTEGER_CST
    8951          185 :                           || !tree_fits_uhwi_p (align)
    8952          373 :                           || !integer_pow2p (align))
    8953              :                         {
    8954           10 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8955              :                                     "%<allocate%> clause %<align%> modifier "
    8956              :                                     "argument needs to be positive constant "
    8957              :                                     "power of two integer expression");
    8958           10 :                           remove = true;
    8959              :                         }
    8960              :                     }
    8961              :                 }
    8962          207 :               OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
    8963              :             }
    8964         2585 :           allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
    8965         2585 :           if (error_operand_p (allocator))
    8966              :             {
    8967              :               remove = true;
    8968              :               break;
    8969              :             }
    8970         2585 :           if (allocator == NULL_TREE)
    8971         1537 :             goto handle_field_decl;
    8972         1048 :           tree allocatort;
    8973         1048 :           allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
    8974         1048 :           if (!type_dependent_expression_p (allocator)
    8975         1048 :               && (TREE_CODE (allocatort) != ENUMERAL_TYPE
    8976         1029 :                   || TYPE_NAME (allocatort) == NULL_TREE
    8977         1029 :                   || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
    8978         2058 :                   || (DECL_NAME (TYPE_NAME (allocatort))
    8979         1029 :                       != get_identifier ("omp_allocator_handle_t"))
    8980         1029 :                   || (TYPE_CONTEXT (allocatort)
    8981         1029 :                       != DECL_CONTEXT (global_namespace))))
    8982              :             {
    8983           16 :               error_at (OMP_CLAUSE_LOCATION (c),
    8984              :                         "%<allocate%> clause allocator expression has "
    8985              :                         "type %qT rather than %<omp_allocator_handle_t%>",
    8986           16 :                         TREE_TYPE (allocator));
    8987           16 :               remove = true;
    8988           16 :               break;
    8989              :             }
    8990              :           else
    8991              :             {
    8992         1032 :               allocator = mark_rvalue_use (allocator);
    8993         1032 :               if (!processing_template_decl)
    8994         1013 :                 allocator = maybe_constant_value (allocator);
    8995         1032 :               OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
    8996              :             }
    8997         1032 :           goto handle_field_decl;
    8998              : 
    8999          654 :         case OMP_CLAUSE_DOACROSS:
    9000          654 :           t = OMP_CLAUSE_DECL (c);
    9001          654 :           if (t == NULL_TREE)
    9002              :             break;
    9003          298 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
    9004              :             {
    9005          298 :               if (cp_finish_omp_clause_doacross_sink (c))
    9006           12 :                 remove = true;
    9007              :               break;
    9008              :             }
    9009            0 :           gcc_unreachable ();
    9010          141 :         case OMP_CLAUSE_USES_ALLOCATORS:
    9011          141 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
    9012          141 :           t = convert_from_reference (t);
    9013          141 :           if (t == error_mark_node)
    9014              :             {
    9015              :               remove = true;
    9016              :               break;
    9017              :             }
    9018          129 :           if (DECL_P (t)
    9019          129 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
    9020          120 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9021          117 :                   || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9022              :             {
    9023            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9024              :                         "%qE appears more than once in data clauses", t);
    9025            3 :               remove = true;
    9026              :             }
    9027          126 :           else if (DECL_P (t))
    9028          117 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9029          129 :           if (type_dependent_expression_p (t))
    9030              :             break;
    9031          114 :           if (TREE_CODE (t) == FIELD_DECL)
    9032              :             {
    9033            0 :               sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
    9034              :                         "supported in %<uses_allocators%> clause", t);
    9035            0 :               remove = true;
    9036            0 :               break;
    9037              :             }
    9038          114 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9039          219 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9040              :                          "omp_allocator_handle_t") != 0)
    9041              :             {
    9042            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9043              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
    9044              :                         "type", t);
    9045            9 :               remove = true;
    9046            9 :               break;
    9047              :             }
    9048          105 :           tree init;
    9049          105 :           if (TREE_CODE (t) == CONST_DECL)
    9050           15 :             init = DECL_INITIAL(t);
    9051              :           else
    9052              :             init = t;
    9053          105 :           if (!DECL_P (t)
    9054          105 :               && (init == NULL_TREE
    9055            9 :                   || TREE_CODE (init) != INTEGER_CST
    9056            9 :                   || ((wi::to_widest (init) < 0
    9057            9 :                        || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
    9058            3 :                       && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
    9059            3 :                           || (wi::to_widest (init)
    9060            6 :                               > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
    9061              :             {
    9062            3 :               remove = true;
    9063            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9064              :                         "allocator %qE must be either a variable or a "
    9065              :                         "predefined allocator", t);
    9066            3 :               break;
    9067              :             }
    9068          102 :           else if (TREE_CODE (t) == CONST_DECL)
    9069              :             {
    9070              :               /* omp_null_allocator is ignored and for predefined allocators,
    9071              :                  not special handling is required; thus, remove them removed. */
    9072           15 :               remove = true;
    9073              : 
    9074           15 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
    9075           15 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
    9076              :                 {
    9077            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9078              :                             "modifiers cannot be used with predefined "
    9079              :                             "allocators");
    9080            0 :                   break;
    9081              :                 }
    9082              :             }
    9083          102 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
    9084          102 :           if (t == error_mark_node)
    9085              :             {
    9086              :               remove = true;
    9087              :               break;
    9088              :             }
    9089           99 :           if (t != NULL_TREE
    9090           18 :               && !type_dependent_expression_p (t)
    9091          117 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
    9092           15 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9093           24 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9094              :                              "omp_memspace_handle_t") != 0))
    9095              :             {
    9096            6 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
    9097              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
    9098            6 :               remove = true;
    9099            6 :               break;
    9100              :             }
    9101           93 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
    9102           93 :           if (t == error_mark_node)
    9103              :             {
    9104              :               remove = true;
    9105              :               break;
    9106              :             }
    9107           90 :           if (type_dependent_expression_p (t))
    9108              :             break;
    9109           90 :           if (t != NULL_TREE
    9110           39 :               && t != error_mark_node
    9111           39 :               && !type_dependent_expression_p (t)
    9112          129 :               && (!DECL_P (t)
    9113           39 :                   ||  DECL_EXTERNAL (t)
    9114           33 :                   || TREE_CODE (t) == PARM_DECL))
    9115              :             {
    9116           12 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
    9117              :                         "defined in same scope as the construct on which the "
    9118              :                         "clause appears", t);
    9119           12 :               remove = true;
    9120              :             }
    9121           90 :           if (t != NULL_TREE)
    9122              :             {
    9123           39 :               bool type_err = false;
    9124              : 
    9125           39 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    9126           33 :                   || DECL_SIZE (t) == NULL_TREE
    9127           69 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9128              :                 type_err = true;
    9129              :               else
    9130              :                 {
    9131           30 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
    9132           30 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
    9133           60 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
    9134              :                                  "omp_alloctrait_t") != 0
    9135           60 :                       || !TYPE_READONLY (elem_t))
    9136              :                     type_err = true;
    9137              :                 }
    9138           27 :               if (type_err)
    9139              :                 {
    9140           12 :                   error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
    9141              :                             "be of %<const omp_alloctrait_t []%> type", t);
    9142           12 :                   remove = true;
    9143              :                 }
    9144           27 :               else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
    9145              :                        != INTEGER_CST)
    9146              :                 {
    9147            3 :                   error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
    9148              :                             "arrays are not supported");
    9149            3 :                   remove = true;
    9150              :                 }
    9151              :               else
    9152              :                 {
    9153           24 :                   tree cst_val = decl_constant_value (t);
    9154           24 :                   if (cst_val == t)
    9155              :                     {
    9156            3 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
    9157              :                                 "initialized with constants");
    9158            3 :                       remove = true;
    9159              :                     }
    9160              :                 }
    9161              :             }
    9162           90 :           if (remove)
    9163              :             break;
    9164           54 :           pc = &OMP_CLAUSE_CHAIN (c);
    9165           54 :           continue;
    9166         1807 :         case OMP_CLAUSE_DEPEND:
    9167         1807 :           depend_clause = c;
    9168              :           /* FALLTHRU */
    9169         2173 :         case OMP_CLAUSE_AFFINITY:
    9170         2173 :           t = OMP_CLAUSE_DECL (c);
    9171         2173 :           if (OMP_ITERATOR_DECL_P (t))
    9172              :             {
    9173          623 :               if (TREE_PURPOSE (t) != last_iterators)
    9174          525 :                 last_iterators_remove
    9175          525 :                   = cp_omp_finish_iterators (TREE_PURPOSE (t));
    9176          623 :               last_iterators = TREE_PURPOSE (t);
    9177          623 :               t = TREE_VALUE (t);
    9178          623 :               if (last_iterators_remove)
    9179          144 :                 t = error_mark_node;
    9180              :             }
    9181              :           else
    9182              :             last_iterators = NULL_TREE;
    9183              : 
    9184         2173 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9185              :             {
    9186         1165 :               if (handle_omp_array_sections (c, ort))
    9187              :                 remove = true;
    9188          914 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9189          914 :                        && (OMP_CLAUSE_DEPEND_KIND (c)
    9190              :                            == OMP_CLAUSE_DEPEND_DEPOBJ))
    9191              :                 {
    9192            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9193              :                             "%<depend%> clause with %<depobj%> dependence "
    9194              :                             "type on array section");
    9195            6 :                   remove = true;
    9196              :                 }
    9197              :               break;
    9198              :             }
    9199         1008 :           if (t == error_mark_node)
    9200              :             remove = true;
    9201          846 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9202          846 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
    9203              :             {
    9204           33 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
    9205           33 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
    9206              :                 {
    9207            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9208              :                             "%<omp_all_memory%> used with %<depend%> kind "
    9209              :                             "other than %<out%> or %<inout%>");
    9210            9 :                   remove = true;
    9211              :                 }
    9212           33 :               if (processing_template_decl)
    9213              :                 break;
    9214              :             }
    9215          813 :           else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9216              :             break;
    9217          621 :           else if (!lvalue_p (t))
    9218              :             {
    9219           19 :               if (DECL_P (t))
    9220           24 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9221              :                           "%qD is not lvalue expression nor array section "
    9222              :                           "in %qs clause", t,
    9223           12 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9224              :               else
    9225           14 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9226              :                           "%qE is not lvalue expression nor array section "
    9227              :                           "in %qs clause", t,
    9228            7 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9229              :               remove = true;
    9230              :             }
    9231          602 :           else if (TREE_CODE (t) == COMPONENT_REF
    9232           24 :                    && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
    9233          626 :                    && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
    9234              :             {
    9235            8 :               error_at (OMP_CLAUSE_LOCATION (c),
    9236              :                         "bit-field %qE in %qs clause", t,
    9237            4 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9238            4 :               remove = true;
    9239              :             }
    9240          598 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9241          598 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
    9242              :             {
    9243          130 :               if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9244            8 :                                      ? TREE_TYPE (TREE_TYPE (t))
    9245           57 :                                      : TREE_TYPE (t)))
    9246              :                 {
    9247           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9248              :                             "%qE does not have %<omp_depend_t%> type in "
    9249              :                             "%<depend%> clause with %<depobj%> dependence "
    9250              :                             "type", t);
    9251           12 :                   remove = true;
    9252              :                 }
    9253              :             }
    9254          533 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9255          974 :                    && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9256            4 :                                         ? TREE_TYPE (TREE_TYPE (t))
    9257          437 :                                         : TREE_TYPE (t)))
    9258              :             {
    9259           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    9260              :                         "%qE should not have %<omp_depend_t%> type in "
    9261              :                         "%<depend%> clause with dependence type other than "
    9262              :                         "%<depobj%>", t);
    9263           15 :               remove = true;
    9264              :             }
    9265           64 :           if (!remove)
    9266              :             {
    9267          595 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
    9268           24 :                 t = null_pointer_node;
    9269              :               else
    9270              :                 {
    9271          571 :                   tree addr = cp_build_addr_expr (t, tf_warning_or_error);
    9272          571 :                   if (addr == error_mark_node)
    9273              :                     {
    9274              :                       remove = true;
    9275              :                       break;
    9276              :                     }
    9277          571 :                   t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
    9278              :                                              addr, RO_UNARY_STAR,
    9279              :                                              tf_warning_or_error);
    9280          571 :                   if (t == error_mark_node)
    9281              :                     {
    9282              :                       remove = true;
    9283              :                       break;
    9284              :                     }
    9285              :                 }
    9286          595 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
    9287          137 :                   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
    9288          732 :                   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
    9289              :                       == TREE_VEC))
    9290          137 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
    9291              :               else
    9292          458 :                 OMP_CLAUSE_DECL (c) = t;
    9293              :             }
    9294              :           break;
    9295           69 :         case OMP_CLAUSE_DETACH:
    9296           69 :           t = OMP_CLAUSE_DECL (c);
    9297           69 :           if (detach_seen)
    9298              :             {
    9299            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9300              :                         "too many %qs clauses on a task construct",
    9301              :                         "detach");
    9302            3 :               remove = true;
    9303            3 :               break;
    9304              :             }
    9305           66 :           else if (error_operand_p (t))
    9306              :             {
    9307              :               remove = true;
    9308              :               break;
    9309              :             }
    9310              :           else
    9311              :             {
    9312           63 :               tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
    9313           63 :               if (!type_dependent_expression_p (t)
    9314           63 :                   && (!INTEGRAL_TYPE_P (type)
    9315              :                       || TREE_CODE (type) != ENUMERAL_TYPE
    9316           51 :                       || TYPE_NAME (type) == NULL_TREE
    9317          102 :                       || (DECL_NAME (TYPE_NAME (type))
    9318           51 :                           != get_identifier ("omp_event_handle_t"))))
    9319              :                 {
    9320            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9321              :                             "%<detach%> clause event handle "
    9322              :                             "has type %qT rather than "
    9323              :                             "%<omp_event_handle_t%>",
    9324              :                             type);
    9325            6 :                   remove = true;
    9326              :                 }
    9327           63 :               detach_seen = c;
    9328           63 :               cxx_mark_addressable (t);
    9329              :             }
    9330           63 :           break;
    9331              : 
    9332        16191 :         case OMP_CLAUSE_MAP:
    9333        16191 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
    9334          157 :             goto move_implicit;
    9335        16034 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
    9336        16034 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
    9337              :             {
    9338              :               remove = true;
    9339              :               break;
    9340              :             }
    9341              :           /* FALLTHRU */
    9342        19212 :         case OMP_CLAUSE_TO:
    9343        19212 :         case OMP_CLAUSE_FROM:
    9344        19212 :           if (OMP_CLAUSE_ITERATORS (c)
    9345        19212 :               && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
    9346              :             {
    9347        97472 :               t = error_mark_node;
    9348              :               break;
    9349              :             }
    9350              :           /* FALLTHRU */
    9351        20048 :         case OMP_CLAUSE__CACHE_:
    9352        20048 :           {
    9353        20048 :             using namespace omp_addr_tokenizer;
    9354        20048 :             auto_vec<omp_addr_token *, 10> addr_tokens;
    9355              : 
    9356        20048 :             t = OMP_CLAUSE_DECL (c);
    9357        20048 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9358              :               {
    9359         5879 :                 grp_start_p = pc;
    9360         5879 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9361              : 
    9362         5879 :                 if (handle_omp_array_sections (c, ort))
    9363              :                   remove = true;
    9364              :                 else
    9365              :                   {
    9366         5113 :                     t = OMP_CLAUSE_DECL (c);
    9367         5113 :                     if (TREE_CODE (t) != OMP_ARRAY_SECTION
    9368         4256 :                         && !type_dependent_expression_p (t)
    9369         9369 :                         && !omp_mappable_type (TREE_TYPE (t)))
    9370              :                       {
    9371            3 :                         auto_diagnostic_group d;
    9372            6 :                         error_at (OMP_CLAUSE_LOCATION (c),
    9373              :                                   "array section does not have mappable type "
    9374              :                                   "in %qs clause",
    9375            3 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9376            3 :                         if (TREE_TYPE (t) != error_mark_node
    9377            3 :                             && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9378            3 :                           cxx_incomplete_type_inform (TREE_TYPE (t));
    9379            3 :                         remove = true;
    9380            3 :                       }
    9381         6963 :                     while (TREE_CODE (t) == ARRAY_REF)
    9382         1850 :                       t = TREE_OPERAND (t, 0);
    9383              : 
    9384         5113 :                     if (type_dependent_expression_p (t))
    9385              :                       break;
    9386              : 
    9387         4639 :                     cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9388              : 
    9389         4639 :                     if (!ai.map_supported_p ()
    9390         4639 :                         || !omp_parse_expr (addr_tokens, t))
    9391              :                       {
    9392           18 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
    9393              :                                   "unsupported map expression %qE",
    9394            9 :                                   OMP_CLAUSE_DECL (c));
    9395            9 :                         remove = true;
    9396            9 :                         break;
    9397              :                       }
    9398              : 
    9399              :                     /* This check is to determine if this will be the only map
    9400              :                        node created for this clause.  Otherwise, we'll check
    9401              :                        the following FIRSTPRIVATE_POINTER,
    9402              :                        FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
    9403              :                        iteration(s) of the loop.   */
    9404         9211 :                     if (addr_tokens.length () >= 4
    9405         1063 :                         && addr_tokens[0]->type == STRUCTURE_BASE
    9406         1057 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    9407         1057 :                         && addr_tokens[1]->type == ACCESS_METHOD
    9408         1057 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
    9409          977 :                         && addr_tokens[3]->type == ACCESS_METHOD
    9410         5344 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
    9411          551 :                             || (addr_tokens[3]->u.access_kind
    9412              :                                 == ACCESS_INDEXED_ARRAY)))
    9413              :                       {
    9414          165 :                         tree rt = addr_tokens[1]->expr;
    9415              : 
    9416          165 :                         gcc_assert (DECL_P (rt));
    9417              : 
    9418          165 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9419          154 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
    9420          165 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
    9421            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
    9422            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
    9423            0 :                                                  DECL_UID (rt))))
    9424              :                           {
    9425              :                             remove = true;
    9426              :                             break;
    9427              :                           }
    9428          165 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
    9429              :                           break;
    9430          116 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
    9431              :                           {
    9432            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9433            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9434              :                                         "%qD appears more than once in motion"
    9435              :                                         " clauses", rt);
    9436            0 :                             else if (openacc)
    9437            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9438              :                                         "%qD appears more than once in data"
    9439              :                                         " clauses", rt);
    9440              :                             else
    9441            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9442              :                                         "%qD appears more than once in map"
    9443              :                                         " clauses", rt);
    9444              :                             remove = true;
    9445              :                           }
    9446              :                         else
    9447              :                           {
    9448          116 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
    9449          116 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
    9450              :                           }
    9451              :                       }
    9452         4639 :                   }
    9453         5347 :                 if (cp_oacc_check_attachments (c))
    9454           12 :                   remove = true;
    9455         5347 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9456         4413 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9457         4349 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9458         5445 :                     && !OMP_CLAUSE_SIZE (c))
    9459              :                   /* In this case, we have a single array element which is a
    9460              :                      pointer, and we already set OMP_CLAUSE_SIZE in
    9461              :                      handle_omp_array_sections above.  For attach/detach
    9462              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
    9463              :                      to zero here.  */
    9464           60 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
    9465              :                 break;
    9466              :               }
    9467        14169 :             else if (type_dependent_expression_p (t))
    9468              :               break;
    9469        13386 :             else if (!omp_parse_expr (addr_tokens, t))
    9470              :               {
    9471            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9472              :                           "unsupported map expression %qE",
    9473            0 :                           OMP_CLAUSE_DECL (c));
    9474            0 :                 remove = true;
    9475            0 :                 break;
    9476              :               }
    9477        13386 :             if (t == error_mark_node)
    9478              :               {
    9479              :                 remove = true;
    9480              :                 break;
    9481              :               }
    9482              :             /* OpenACC attach / detach clauses must be pointers.  */
    9483        13292 :             if (cp_oacc_check_attachments (c))
    9484              :               {
    9485              :                 remove = true;
    9486              :                 break;
    9487              :               }
    9488        13268 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9489        10223 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9490        10174 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9491        13342 :                 && !OMP_CLAUSE_SIZE (c))
    9492              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
    9493              :                  bias) to zero here, so it is not set erroneously to the
    9494              :                  pointer size later on in gimplify.cc.  */
    9495           66 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
    9496              : 
    9497        13268 :             cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9498              : 
    9499        13268 :             if (!ai.check_clause (c))
    9500              :               {
    9501              :                 remove = true;
    9502              :                 break;
    9503              :               }
    9504              : 
    9505        13247 :             if (!ai.map_supported_p ())
    9506              :               {
    9507           88 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9508              :                           "unsupported map expression %qE",
    9509           44 :                           OMP_CLAUSE_DECL (c));
    9510           44 :                 remove = true;
    9511           44 :                 break;
    9512              :               }
    9513              : 
    9514        26406 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
    9515              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
    9516              :                         && addr_tokens[1]->type == ACCESS_METHOD);
    9517              : 
    9518        13203 :             t = addr_tokens[1]->expr;
    9519              : 
    9520              :             /* This is used to prevent cxx_mark_addressable from being called
    9521              :                on 'this' for expressions like 'this->a', i.e. typical member
    9522              :                accesses.  */
    9523        13203 :             indir_component_ref_p
    9524        26406 :               = (addr_tokens[0]->type == STRUCTURE_BASE
    9525        13203 :                  && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
    9526              : 
    9527        13203 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
    9528            1 :               goto skip_decl_checks;
    9529              : 
    9530              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
    9531              :                mapping.  OpenACC allows multiple fields of the same structure
    9532              :                to be written.  */
    9533        13202 :             if (addr_tokens[0]->type == STRUCTURE_BASE
    9534        13202 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
    9535         1263 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
    9536         1351 :               goto skip_decl_checks;
    9537              : 
    9538        11851 :             if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
    9539              :               {
    9540            0 :                 OMP_CLAUSE_DECL (c)
    9541            0 :                   = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    9542            0 :                 break;
    9543              :               }
    9544        11851 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    9545              :               {
    9546            0 :                 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9547              :                   break;
    9548            0 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9549            0 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9550            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
    9551            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
    9552            0 :                         || (!openacc && EXPR_P (t))))
    9553              :                   break;
    9554            0 :                 if (DECL_P (t))
    9555            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9556              :                             "%qD is not a variable in %qs clause", t,
    9557            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9558              :                 else
    9559            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9560              :                             "%qE is not a variable in %qs clause", t,
    9561            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9562              :                 remove = true;
    9563              :               }
    9564        11851 :             else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    9565              :               {
    9566            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9567              :                           "%qD is threadprivate variable in %qs clause", t,
    9568            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9569            0 :                 remove = true;
    9570              :               }
    9571        11851 :             else if (!processing_template_decl
    9572        11675 :                      && !TYPE_REF_P (TREE_TYPE (t))
    9573        10998 :                      && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9574         8063 :                          || (OMP_CLAUSE_MAP_KIND (c)
    9575              :                              != GOMP_MAP_FIRSTPRIVATE_POINTER))
    9576         9041 :                      && !indir_component_ref_p
    9577         8677 :                      && (t != current_class_ptr
    9578           18 :                          || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9579            6 :                          || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
    9580        20528 :                      && !cxx_mark_addressable (t))
    9581              :               remove = true;
    9582        11851 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9583         8898 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9584         8898 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9585              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
    9586         6941 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9587              :                                == GOMP_MAP_ATTACH_DETACH)))
    9588         9234 :                      && t == OMP_CLAUSE_DECL (c)
    9589         8536 :                      && !type_dependent_expression_p (t)
    9590        28923 :                      && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
    9591          278 :                                             ? TREE_TYPE (TREE_TYPE (t))
    9592         8258 :                                             : TREE_TYPE (t)))
    9593              :               {
    9594           42 :                 auto_diagnostic_group d;
    9595           84 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9596              :                           "%qD does not have a mappable type in %qs clause", t,
    9597           42 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9598           42 :                 if (TREE_TYPE (t) != error_mark_node
    9599           42 :                     && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9600           39 :                   cxx_incomplete_type_inform (TREE_TYPE (t));
    9601           42 :                 remove = true;
    9602           42 :               }
    9603        11809 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9604         8862 :                      && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
    9605           93 :                      && !type_dependent_expression_p (t)
    9606        11902 :                      && !INDIRECT_TYPE_P (TREE_TYPE (t)))
    9607              :               {
    9608            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9609              :                           "%qD is not a pointer variable", t);
    9610            6 :                 remove = true;
    9611              :               }
    9612        11803 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9613         8856 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
    9614        12173 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
    9615          367 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
    9616          367 :                          || bitmap_bit_p (&map_firstprivate_head,
    9617          367 :                                           DECL_UID (t))))
    9618              :               remove = true;
    9619        11797 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9620        11797 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9621              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
    9622              :               {
    9623         1951 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
    9624         1951 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9625         3899 :                     || (openacc
    9626         1362 :                         && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9627              :                   {
    9628           12 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9629              :                               "%qD appears more than once in data clauses", t);
    9630           12 :                     remove = true;
    9631              :                   }
    9632         1939 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9633           12 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9634         1947 :                          && openacc)
    9635              :                   {
    9636            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9637              :                               "%qD appears more than once in data clauses", t);
    9638            3 :                     remove = true;
    9639              :                   }
    9640              :                 else
    9641         1936 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9642              :               }
    9643         9846 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9644         9846 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9645              :                          == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
    9646          115 :               bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9647         9731 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9648          181 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9649           38 :                      && ort != C_ORT_OMP
    9650           38 :                      && ort != C_ORT_OMP_TARGET
    9651         9747 :                      && ort != C_ORT_OMP_EXIT_DATA)
    9652              :               {
    9653            9 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9654            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9655              :                             "%qD appears more than once in motion clauses", t);
    9656            9 :                 else if (openacc)
    9657            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9658              :                             "%qD appears more than once in data clauses", t);
    9659              :                 else
    9660            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9661              :                             "%qD appears more than once in map clauses", t);
    9662              :                 remove = true;
    9663              :               }
    9664         9722 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
    9665              :               {
    9666            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9667              :                           "%qD appears more than once in data clauses", t);
    9668            0 :                 remove = true;
    9669              :               }
    9670         9722 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9671         9722 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
    9672              :               {
    9673           27 :                 if (openacc)
    9674            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9675              :                             "%qD appears more than once in data clauses", t);
    9676              :                 else
    9677           27 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9678              :                             "%qD appears both in data and map clauses", t);
    9679              :                 remove = true;
    9680              :               }
    9681         9695 :             else if (!omp_access_chain_p (addr_tokens, 1))
    9682              :               {
    9683         9615 :                 bitmap_set_bit (&map_head, DECL_UID (t));
    9684              : 
    9685         9615 :                 tree decl = OMP_CLAUSE_DECL (c);
    9686         9615 :                 if (t != decl
    9687         9615 :                     && (TREE_CODE (decl) == COMPONENT_REF
    9688          162 :                         || (INDIRECT_REF_P (decl)
    9689          162 :                             && (TREE_CODE (TREE_OPERAND (decl, 0))
    9690              :                                 == COMPONENT_REF)
    9691          150 :                             && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
    9692              :                                                                     0))))))
    9693         1165 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
    9694              :               }
    9695              : 
    9696         4631 :           skip_decl_checks:
    9697              :             /* If we call ai.expand_map_clause in handle_omp_array_sections,
    9698              :                the containing loop (here) iterates through the new nodes
    9699              :                created by that expansion.  Avoid expanding those again (just
    9700              :                by checking the node type).  */
    9701         4631 :             if (!remove
    9702        13098 :                 && !processing_template_decl
    9703        12925 :                 && ort != C_ORT_DECLARE_SIMD
    9704        12925 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9705         9898 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
    9706         7962 :                         && (OMP_CLAUSE_MAP_KIND (c)
    9707              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
    9708         7847 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
    9709         7847 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
    9710         6848 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    9711         6799 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
    9712              :               {
    9713         9801 :                 grp_start_p = pc;
    9714         9801 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9715         9801 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
    9716              :                                                 addr_tokens, ort);
    9717         9801 :                 if (nc != error_mark_node)
    9718         9801 :                   c = nc;
    9719              :               }
    9720        20113 :           }
    9721        13203 :           break;
    9722              : 
    9723          596 :         case OMP_CLAUSE_ENTER:
    9724          596 :         case OMP_CLAUSE_LINK:
    9725          596 :           t = OMP_CLAUSE_DECL (c);
    9726          596 :           const char *cname;
    9727          596 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
    9728          596 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
    9729          596 :               && OMP_CLAUSE_ENTER_TO (c))
    9730              :             cname = "to";
    9731          596 :           if (TREE_CODE (t) == FUNCTION_DECL
    9732          596 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9733              :             ;
    9734          379 :           else if (!VAR_P (t))
    9735              :             {
    9736           12 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9737              :                 {
    9738            9 :                   if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
    9739            6 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9740              :                               "template %qE in clause %qs", t, cname);
    9741            3 :                   else if (really_overloaded_fn (t))
    9742            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9743              :                               "overloaded function name %qE in clause %qs", t,
    9744              :                               cname);
    9745              :                   else
    9746            0 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9747              :                               "%qE is neither a variable nor a function name "
    9748              :                               "in clause %qs", t, cname);
    9749              :                 }
    9750              :               else
    9751            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9752              :                           "%qE is not a variable in clause %qs", t, cname);
    9753              :               remove = true;
    9754              :             }
    9755          367 :           else if (DECL_THREAD_LOCAL_P (t))
    9756              :             {
    9757            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9758              :                         "%qD is threadprivate variable in %qs clause", t,
    9759              :                         cname);
    9760            6 :               remove = true;
    9761              :             }
    9762          361 :           else if (!omp_mappable_type (TREE_TYPE (t)))
    9763              :             {
    9764           18 :               auto_diagnostic_group d;
    9765           18 :               error_at (OMP_CLAUSE_LOCATION (c),
    9766              :                         "%qD does not have a mappable type in %qs clause", t,
    9767              :                         cname);
    9768           18 :               if (TREE_TYPE (t) != error_mark_node
    9769           18 :                   && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9770           18 :                 cxx_incomplete_type_inform (TREE_TYPE (t));
    9771           18 :               remove = true;
    9772           18 :             }
    9773           24 :           if (remove)
    9774              :             break;
    9775          560 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
    9776              :             {
    9777           24 :               error_at (OMP_CLAUSE_LOCATION (c),
    9778              :                         "%qE appears more than once on the same "
    9779              :                         "%<declare target%> directive", t);
    9780           24 :               remove = true;
    9781              :             }
    9782              :           else
    9783          536 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9784              :           break;
    9785              : 
    9786          457 :         case OMP_CLAUSE_UNIFORM:
    9787          457 :           t = OMP_CLAUSE_DECL (c);
    9788          457 :           if (TREE_CODE (t) != PARM_DECL)
    9789              :             {
    9790            0 :               if (processing_template_decl)
    9791              :                 break;
    9792            0 :               if (DECL_P (t))
    9793            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9794              :                           "%qD is not an argument in %<uniform%> clause", t);
    9795              :               else
    9796            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9797              :                           "%qE is not an argument in %<uniform%> clause", t);
    9798              :               remove = true;
    9799              :               break;
    9800              :             }
    9801              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
    9802          457 :           bitmap_set_bit (&map_head, DECL_UID (t));
    9803          457 :           goto check_dup_generic;
    9804              : 
    9805          165 :         case OMP_CLAUSE_GRAINSIZE:
    9806          165 :           t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
    9807          165 :           if (t == error_mark_node)
    9808              :             remove = true;
    9809          165 :           else if (!type_dependent_expression_p (t)
    9810          165 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9811              :             {
    9812            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9813              :                         "%<grainsize%> expression must be integral");
    9814            0 :               remove = true;
    9815              :             }
    9816              :           else
    9817              :             {
    9818          165 :               t = mark_rvalue_use (t);
    9819          165 :               if (!processing_template_decl)
    9820              :                 {
    9821          164 :                   t = maybe_constant_value (t);
    9822          164 :                   if (TREE_CODE (t) == INTEGER_CST
    9823          164 :                       && tree_int_cst_sgn (t) != 1)
    9824              :                     {
    9825            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9826              :                                   "%<grainsize%> value must be positive");
    9827            0 :                       t = integer_one_node;
    9828              :                     }
    9829          164 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9830              :                 }
    9831          165 :               OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
    9832              :             }
    9833              :           break;
    9834              : 
    9835          276 :         case OMP_CLAUSE_PRIORITY:
    9836          276 :           t = OMP_CLAUSE_PRIORITY_EXPR (c);
    9837          276 :           if (t == error_mark_node)
    9838              :             remove = true;
    9839          276 :           else if (!type_dependent_expression_p (t)
    9840          276 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9841              :             {
    9842            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9843              :                         "%<priority%> expression must be integral");
    9844            0 :               remove = true;
    9845              :             }
    9846              :           else
    9847              :             {
    9848          276 :               t = mark_rvalue_use (t);
    9849          276 :               if (!processing_template_decl)
    9850              :                 {
    9851          276 :                   t = maybe_constant_value (t);
    9852          276 :                   if (TREE_CODE (t) == INTEGER_CST
    9853          276 :                       && tree_int_cst_sgn (t) == -1)
    9854              :                     {
    9855            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9856              :                                   "%<priority%> value must be non-negative");
    9857            0 :                       t = integer_one_node;
    9858              :                     }
    9859          276 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9860              :                 }
    9861          276 :               OMP_CLAUSE_PRIORITY_EXPR (c) = t;
    9862              :             }
    9863              :           break;
    9864              : 
    9865          228 :         case OMP_CLAUSE_HINT:
    9866          228 :           t = OMP_CLAUSE_HINT_EXPR (c);
    9867          228 :           if (t == error_mark_node)
    9868              :             remove = true;
    9869          228 :           else if (!type_dependent_expression_p (t)
    9870          228 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9871              :             {
    9872            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9873              :                         "%<hint%> expression must be integral");
    9874            9 :               remove = true;
    9875              :             }
    9876              :           else
    9877              :             {
    9878          219 :               t = mark_rvalue_use (t);
    9879          219 :               if (!processing_template_decl)
    9880              :                 {
    9881          171 :                   t = maybe_constant_value (t);
    9882          171 :                   if (TREE_CODE (t) != INTEGER_CST)
    9883              :                     {
    9884           16 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9885              :                                 "%<hint%> expression must be constant integer "
    9886              :                                 "expression");
    9887           16 :                       remove = true;
    9888              :                     }
    9889              :                 }
    9890          219 :               OMP_CLAUSE_HINT_EXPR (c) = t;
    9891              :             }
    9892              :           break;
    9893              : 
    9894          186 :         case OMP_CLAUSE_FILTER:
    9895          186 :           t = OMP_CLAUSE_FILTER_EXPR (c);
    9896          186 :           if (t == error_mark_node)
    9897              :             remove = true;
    9898          186 :           else if (!type_dependent_expression_p (t)
    9899          186 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9900              :             {
    9901            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9902              :                         "%<filter%> expression must be integral");
    9903            6 :               remove = true;
    9904              :             }
    9905              :           else
    9906              :             {
    9907          180 :               t = mark_rvalue_use (t);
    9908          180 :               if (!processing_template_decl)
    9909              :                 {
    9910          177 :                   t = maybe_constant_value (t);
    9911          177 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9912              :                 }
    9913          180 :               OMP_CLAUSE_FILTER_EXPR (c) = t;
    9914              :             }
    9915              :           break;
    9916              : 
    9917          433 :         case OMP_CLAUSE_IS_DEVICE_PTR:
    9918          433 :         case OMP_CLAUSE_USE_DEVICE_PTR:
    9919          433 :           field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
    9920          433 :           t = OMP_CLAUSE_DECL (c);
    9921          433 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    9922          329 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9923          433 :           if (!type_dependent_expression_p (t))
    9924              :             {
    9925          431 :               tree type = TREE_TYPE (t);
    9926          431 :               if (!TYPE_PTR_P (type)
    9927          431 :                   && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
    9928              :                 {
    9929           57 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    9930           57 :                       && ort == C_ORT_OMP)
    9931              :                     {
    9932            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9933              :                                 "%qs variable is neither a pointer "
    9934              :                                 "nor reference to pointer",
    9935            3 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9936            3 :                       remove = true;
    9937              :                     }
    9938           54 :                   else if (TREE_CODE (type) != ARRAY_TYPE
    9939           54 :                            && (!TYPE_REF_P (type)
    9940            2 :                                || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
    9941              :                     {
    9942           12 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9943              :                                 "%qs variable is neither a pointer, nor an "
    9944              :                                 "array nor reference to pointer or array",
    9945           12 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9946           12 :                       remove = true;
    9947              :                     }
    9948              :                 }
    9949              :             }
    9950          433 :           goto check_dup_generic;
    9951              : 
    9952          267 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
    9953          267 :           t = OMP_CLAUSE_DECL (c);
    9954          267 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9955              :             {
    9956           28 :               if (handle_omp_array_sections (c, ort))
    9957              :                 remove = true;
    9958              :               else
    9959              :                 {
    9960           28 :                   t = OMP_CLAUSE_DECL (c);
    9961           30 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9962            2 :                     t = TREE_OPERAND (t, 0);
    9963           64 :                   while (INDIRECT_REF_P (t)
    9964           64 :                          || TREE_CODE (t) == ARRAY_REF)
    9965           36 :                     t = TREE_OPERAND (t, 0);
    9966              :                 }
    9967              :             }
    9968          267 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9969              :             {
    9970          267 :               bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9971          267 :               if (!processing_template_decl
    9972          267 :                   && !cxx_mark_addressable (t))
    9973              :                 remove = true;
    9974              :             }
    9975          267 :           goto check_dup_generic_t;
    9976              : 
    9977           76 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
    9978           76 :           field_ok = true;
    9979           76 :           t = OMP_CLAUSE_DECL (c);
    9980           76 :           if (!processing_template_decl
    9981           74 :               && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9982           74 :               && !TYPE_REF_P (TREE_TYPE (t))
    9983          143 :               && !cxx_mark_addressable (t))
    9984              :             remove = true;
    9985           76 :           goto check_dup_generic;
    9986              : 
    9987              :         case OMP_CLAUSE_NOWAIT:
    9988              :         case OMP_CLAUSE_DEFAULT:
    9989              :         case OMP_CLAUSE_UNTIED:
    9990              :         case OMP_CLAUSE_COLLAPSE:
    9991              :         case OMP_CLAUSE_PARALLEL:
    9992              :         case OMP_CLAUSE_FOR:
    9993              :         case OMP_CLAUSE_SECTIONS:
    9994              :         case OMP_CLAUSE_TASKGROUP:
    9995              :         case OMP_CLAUSE_PROC_BIND:
    9996              :         case OMP_CLAUSE_DEVICE_TYPE:
    9997              :         case OMP_CLAUSE_NOGROUP:
    9998              :         case OMP_CLAUSE_THREADS:
    9999              :         case OMP_CLAUSE_SIMD:
   10000              :         case OMP_CLAUSE_DEFAULTMAP:
   10001              :         case OMP_CLAUSE_BIND:
   10002              :         case OMP_CLAUSE_AUTO:
   10003              :         case OMP_CLAUSE_INDEPENDENT:
   10004              :         case OMP_CLAUSE_SEQ:
   10005              :         case OMP_CLAUSE_IF_PRESENT:
   10006              :         case OMP_CLAUSE_FINALIZE:
   10007              :         case OMP_CLAUSE_NOHOST:
   10008              :         case OMP_CLAUSE_INDIRECT:
   10009              :           break;
   10010              : 
   10011          231 :         case OMP_CLAUSE_MERGEABLE:
   10012          231 :           mergeable_seen = true;
   10013          231 :           break;
   10014              : 
   10015          322 :         case OMP_CLAUSE_TILE:
   10016          754 :           for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
   10017          432 :                list = TREE_CHAIN (list))
   10018              :             {
   10019          432 :               t = TREE_VALUE (list);
   10020              : 
   10021          432 :               if (t == error_mark_node)
   10022              :                 remove = true;
   10023          403 :               else if (!type_dependent_expression_p (t)
   10024          403 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10025              :                 {
   10026            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10027              :                             "%<tile%> argument needs integral type");
   10028            3 :                   remove = true;
   10029              :                 }
   10030              :               else
   10031              :                 {
   10032          400 :                   t = mark_rvalue_use (t);
   10033          400 :                   if (!processing_template_decl)
   10034              :                     {
   10035              :                       /* Zero is used to indicate '*', we permit you
   10036              :                          to get there via an ICE of value zero.  */
   10037          385 :                       t = maybe_constant_value (t);
   10038          385 :                       if (!tree_fits_shwi_p (t)
   10039          369 :                           || tree_to_shwi (t) < 0)
   10040              :                         {
   10041           40 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10042              :                                     "%<tile%> argument needs positive "
   10043              :                                     "integral constant");
   10044           40 :                           remove = true;
   10045              :                         }
   10046              :                     }
   10047              :                 }
   10048              : 
   10049              :                 /* Update list item.  */
   10050          432 :               TREE_VALUE (list) = t;
   10051              :             }
   10052              :           break;
   10053              : 
   10054         1027 :         case OMP_CLAUSE_SIZES:
   10055         1027 :           for (tree list = OMP_CLAUSE_SIZES_LIST (c);
   10056         2688 :                !remove && list; list = TREE_CHAIN (list))
   10057              :             {
   10058         1661 :               t = TREE_VALUE (list);
   10059              : 
   10060         1661 :               if (t == error_mark_node)
   10061            0 :                 t = integer_one_node;
   10062         1661 :               else if (!type_dependent_expression_p (t)
   10063         1661 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10064              :                 {
   10065            8 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10066              :                             "%<sizes%> argument needs positive integral "
   10067              :                             "constant");
   10068            8 :                   t = integer_one_node;
   10069              :                 }
   10070              :               else
   10071              :                 {
   10072         1653 :                   t = mark_rvalue_use (t);
   10073         1653 :                   if (!processing_template_decl)
   10074              :                     {
   10075         1636 :                       t = maybe_constant_value (t);
   10076         1636 :                       HOST_WIDE_INT n;
   10077         1636 :                       if (!tree_fits_shwi_p (t)
   10078         1632 :                           || !INTEGRAL_TYPE_P (TREE_TYPE (t))
   10079         1632 :                           || (n = tree_to_shwi (t)) <= 0
   10080         3240 :                           || (int)n != n)
   10081              :                         {
   10082           32 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10083              :                                     "%<sizes%> argument needs positive "
   10084              :                                     "integral constant");
   10085           32 :                           t = integer_one_node;
   10086              :                         }
   10087              :                     }
   10088              :                 }
   10089              : 
   10090              :               /* Update list item.  */
   10091         1661 :               TREE_VALUE (list) = t;
   10092              :             }
   10093              :           break;
   10094              : 
   10095          630 :         case OMP_CLAUSE_ORDERED:
   10096          630 :           ordered_seen = true;
   10097          630 :           break;
   10098              : 
   10099         1549 :         case OMP_CLAUSE_ORDER:
   10100         1549 :           if (order_seen)
   10101              :             remove = true;
   10102              :           else
   10103              :             order_seen = true;
   10104              :           break;
   10105              : 
   10106          638 :         case OMP_CLAUSE_INBRANCH:
   10107          638 :         case OMP_CLAUSE_NOTINBRANCH:
   10108          638 :           if (branch_seen)
   10109              :             {
   10110            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10111              :                         "%<inbranch%> clause is incompatible with "
   10112              :                         "%<notinbranch%>");
   10113            3 :               remove = true;
   10114              :             }
   10115              :           branch_seen = true;
   10116              :           break;
   10117              : 
   10118          297 :         case OMP_CLAUSE_INCLUSIVE:
   10119          297 :         case OMP_CLAUSE_EXCLUSIVE:
   10120          297 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10121          297 :           if (!t)
   10122          297 :             t = OMP_CLAUSE_DECL (c);
   10123          297 :           if (t == current_class_ptr)
   10124              :             {
   10125            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10126              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
   10127              :                         " clauses");
   10128            0 :               remove = true;
   10129            0 :               break;
   10130              :             }
   10131          297 :           if (!VAR_P (t)
   10132              :               && TREE_CODE (t) != PARM_DECL
   10133              :               && TREE_CODE (t) != FIELD_DECL)
   10134              :             {
   10135            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   10136              :                 break;
   10137            0 :               if (DECL_P (t))
   10138            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10139              :                           "%qD is not a variable in clause %qs", t,
   10140            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10141              :               else
   10142            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10143              :                           "%qE is not a variable in clause %qs", t,
   10144            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10145              :               remove = true;
   10146              :             }
   10147              :           break;
   10148              : 
   10149              :         case OMP_CLAUSE_FULL:
   10150              :           break;
   10151              : 
   10152          470 :         case OMP_CLAUSE_PARTIAL:
   10153          470 :           partial_seen = true;
   10154          470 :           t = OMP_CLAUSE_PARTIAL_EXPR (c);
   10155          470 :           if (!t)
   10156              :             break;
   10157              : 
   10158          313 :           if (t == error_mark_node)
   10159              :             t = NULL_TREE;
   10160          313 :           else if (!type_dependent_expression_p (t)
   10161          313 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10162              :             {
   10163            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10164              :                         "%<partial%> argument needs positive constant "
   10165              :                         "integer expression");
   10166            3 :               t = NULL_TREE;
   10167              :             }
   10168              :           else
   10169              :             {
   10170          310 :               t = mark_rvalue_use (t);
   10171          310 :               if (!processing_template_decl)
   10172              :                 {
   10173          292 :                   t = maybe_constant_value (t);
   10174              : 
   10175          292 :                   HOST_WIDE_INT n;
   10176          584 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   10177          292 :                       || !tree_fits_shwi_p (t)
   10178          286 :                       || (n = tree_to_shwi (t)) <= 0
   10179          560 :                       || (int)n != n)
   10180              :                     {
   10181           24 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10182              :                                 "%<partial%> argument needs positive "
   10183              :                                 "constant integer expression");
   10184           24 :                       t = NULL_TREE;
   10185              :                     }
   10186              :                 }
   10187              :             }
   10188              : 
   10189          313 :           OMP_CLAUSE_PARTIAL_EXPR (c) = t;
   10190          313 :           break;
   10191          549 :         case OMP_CLAUSE_INIT:
   10192          549 :           init_seen = true;
   10193          549 :           OMP_CLAUSE_INIT_PREFER_TYPE (c)
   10194          549 :             = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
   10195          549 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   10196          271 :             init_no_targetsync_clause = c;
   10197              :           /* FALLTHRU */
   10198          844 :         case OMP_CLAUSE_DESTROY:
   10199          844 :         case OMP_CLAUSE_USE:
   10200          844 :           init_use_destroy_seen = true;
   10201          844 :           t = OMP_CLAUSE_DECL (c);
   10202          844 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   10203              :             {
   10204            9 :               error_at (OMP_CLAUSE_LOCATION (c),
   10205              :                         "%qD appears more than once in action clauses", t);
   10206            9 :               remove = true;
   10207            9 :               break;
   10208              :             }
   10209          835 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   10210              :           /* FALLTHRU */
   10211         1099 :         case OMP_CLAUSE_INTEROP:
   10212         1099 :           if (!processing_template_decl)
   10213              :             {
   10214         1003 :               if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
   10215              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) &&  */
   10216         1003 :                   !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   10217              :                 {
   10218          126 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10219              :                             "%qD must be of %<omp_interop_t%>",
   10220           63 :                             OMP_CLAUSE_DECL (c));
   10221           63 :                   remove = true;
   10222              :                 }
   10223          940 :               else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   10224          481 :                         || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   10225         1058 :                        && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   10226              :                 {
   10227           36 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10228           18 :                             "%qD shall not be const", OMP_CLAUSE_DECL (c));
   10229           18 :                   remove = true;
   10230              :                 }
   10231              :             }
   10232         1099 :           pc = &OMP_CLAUSE_CHAIN (c);
   10233         1099 :           break;
   10234            0 :         default:
   10235            0 :           gcc_unreachable ();
   10236           54 :         }
   10237              : 
   10238        97472 :       if (remove)
   10239              :         {
   10240         2580 :           if (grp_start_p)
   10241              :             {
   10242              :               /* If we found a clause to remove, we want to remove the whole
   10243              :                  expanded group, otherwise gimplify
   10244              :                  (omp_resolve_clause_dependencies) can get confused.  */
   10245          817 :               *grp_start_p = grp_sentinel;
   10246          817 :               pc = grp_start_p;
   10247          817 :               grp_start_p = NULL;
   10248              :             }
   10249              :           else
   10250         1763 :             *pc = OMP_CLAUSE_CHAIN (c);
   10251              :         }
   10252              :       else
   10253        94892 :         pc = &OMP_CLAUSE_CHAIN (c);
   10254              :     }
   10255              : 
   10256        62695 :   if (grp_start_p
   10257        62695 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   10258          140 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   10259           86 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   10260              : 
   10261        62695 :   if (reduction_seen < 0 && (ordered_seen || schedule_seen))
   10262        62695 :     reduction_seen = -2;
   10263              : 
   10264       158551 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   10265              :     {
   10266        95856 :       enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
   10267        95856 :       bool remove = false;
   10268        95856 :       bool need_complete_type = false;
   10269        95856 :       bool need_default_ctor = false;
   10270        95856 :       bool need_copy_ctor = false;
   10271        95856 :       bool need_copy_assignment = false;
   10272        95856 :       bool need_implicitly_determined = false;
   10273        95856 :       bool need_dtor = false;
   10274        95856 :       tree type, inner_type;
   10275              : 
   10276        95856 :       switch (c_kind)
   10277              :         {
   10278              :         case OMP_CLAUSE_SHARED:
   10279              :           need_implicitly_determined = true;
   10280              :           break;
   10281         2540 :         case OMP_CLAUSE_PRIVATE:
   10282         2540 :           need_complete_type = true;
   10283         2540 :           need_default_ctor = true;
   10284         2540 :           need_dtor = true;
   10285         2540 :           need_implicitly_determined = true;
   10286         2540 :           break;
   10287         3156 :         case OMP_CLAUSE_FIRSTPRIVATE:
   10288         3156 :           need_complete_type = true;
   10289         3156 :           need_copy_ctor = true;
   10290         3156 :           need_dtor = true;
   10291         3156 :           need_implicitly_determined = true;
   10292         3156 :           break;
   10293         2763 :         case OMP_CLAUSE_LASTPRIVATE:
   10294         2763 :           need_complete_type = true;
   10295         2763 :           need_copy_assignment = true;
   10296         2763 :           need_implicitly_determined = true;
   10297         2763 :           break;
   10298         7287 :         case OMP_CLAUSE_REDUCTION:
   10299         7287 :           if (reduction_seen == -2)
   10300           27 :             OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   10301         7287 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   10302          421 :             need_copy_assignment = true;
   10303              :           need_implicitly_determined = true;
   10304              :           break;
   10305              :         case OMP_CLAUSE_IN_REDUCTION:
   10306              :         case OMP_CLAUSE_TASK_REDUCTION:
   10307              :         case OMP_CLAUSE_INCLUSIVE:
   10308              :         case OMP_CLAUSE_EXCLUSIVE:
   10309              :           need_implicitly_determined = true;
   10310              :           break;
   10311         1550 :         case OMP_CLAUSE_LINEAR:
   10312         1550 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   10313              :             need_implicitly_determined = true;
   10314          679 :           else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   10315          721 :                    && !bitmap_bit_p (&map_head,
   10316           42 :                                      DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   10317              :             {
   10318            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10319              :                         "%<linear%> clause step is a parameter %qD not "
   10320              :                         "specified in %<uniform%> clause",
   10321            6 :                         OMP_CLAUSE_LINEAR_STEP (c));
   10322            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10323        74329 :               continue;
   10324              :             }
   10325              :           break;
   10326              :         case OMP_CLAUSE_COPYPRIVATE:
   10327          366 :           need_copy_assignment = true;
   10328              :           break;
   10329              :         case OMP_CLAUSE_COPYIN:
   10330          366 :           need_copy_assignment = true;
   10331              :           break;
   10332          798 :         case OMP_CLAUSE_SIMDLEN:
   10333          798 :           if (safelen
   10334          345 :               && !processing_template_decl
   10335         1143 :               && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   10336          345 :                                   OMP_CLAUSE_SIMDLEN_EXPR (c)))
   10337              :             {
   10338            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10339              :                         "%<simdlen%> clause value is bigger than "
   10340              :                         "%<safelen%> clause value");
   10341            0 :               OMP_CLAUSE_SIMDLEN_EXPR (c)
   10342            0 :                 = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   10343              :             }
   10344          798 :           pc = &OMP_CLAUSE_CHAIN (c);
   10345          798 :           continue;
   10346         3853 :         case OMP_CLAUSE_SCHEDULE:
   10347         3853 :           if (ordered_seen
   10348         3853 :               && (OMP_CLAUSE_SCHEDULE_KIND (c)
   10349              :                   & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   10350              :             {
   10351           21 :               error_at (OMP_CLAUSE_LOCATION (c),
   10352              :                         "%<nonmonotonic%> schedule modifier specified "
   10353              :                         "together with %<ordered%> clause");
   10354           42 :               OMP_CLAUSE_SCHEDULE_KIND (c)
   10355           21 :                 = (enum omp_clause_schedule_kind)
   10356           21 :                   (OMP_CLAUSE_SCHEDULE_KIND (c)
   10357              :                    & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   10358              :             }
   10359         3853 :           if (reduction_seen == -2)
   10360            9 :             error_at (OMP_CLAUSE_LOCATION (c),
   10361              :                       "%qs clause specified together with %<inscan%> "
   10362              :                       "%<reduction%> clause", "schedule");
   10363         3853 :           pc = &OMP_CLAUSE_CHAIN (c);
   10364         3853 :           continue;
   10365           51 :         case OMP_CLAUSE_NOGROUP:
   10366           51 :           if (reduction_seen)
   10367              :             {
   10368            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10369              :                         "%<nogroup%> clause must not be used together with "
   10370              :                         "%<reduction%> clause");
   10371            3 :               *pc = OMP_CLAUSE_CHAIN (c);
   10372            3 :               continue;
   10373              :             }
   10374           48 :           pc = &OMP_CLAUSE_CHAIN (c);
   10375           48 :           continue;
   10376          165 :         case OMP_CLAUSE_GRAINSIZE:
   10377          165 :           if (num_tasks_seen)
   10378              :             {
   10379            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10380              :                         "%<grainsize%> clause must not be used together with "
   10381              :                         "%<num_tasks%> clause");
   10382            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10383            6 :               continue;
   10384              :             }
   10385          159 :           pc = &OMP_CLAUSE_CHAIN (c);
   10386          159 :           continue;
   10387          630 :         case OMP_CLAUSE_ORDERED:
   10388          630 :           if (reduction_seen == -2)
   10389            6 :             error_at (OMP_CLAUSE_LOCATION (c),
   10390              :                       "%qs clause specified together with %<inscan%> "
   10391              :                       "%<reduction%> clause", "ordered");
   10392          630 :           pc = &OMP_CLAUSE_CHAIN (c);
   10393          630 :           continue;
   10394         1525 :         case OMP_CLAUSE_ORDER:
   10395         1525 :           if (ordered_seen)
   10396              :             {
   10397           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10398              :                         "%<order%> clause must not be used together "
   10399              :                         "with %<ordered%> clause");
   10400           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10401           12 :               continue;
   10402              :             }
   10403         1513 :           pc = &OMP_CLAUSE_CHAIN (c);
   10404         1513 :           continue;
   10405           57 :         case OMP_CLAUSE_DETACH:
   10406           57 :           if (mergeable_seen)
   10407              :             {
   10408            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10409              :                         "%<detach%> clause must not be used together with "
   10410              :                         "%<mergeable%> clause");
   10411            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10412            6 :               continue;
   10413              :             }
   10414           51 :           pc = &OMP_CLAUSE_CHAIN (c);
   10415           51 :           continue;
   10416        15960 :         case OMP_CLAUSE_MAP:
   10417        15960 :           if (target_in_reduction_seen && !processing_template_decl)
   10418              :             {
   10419          684 :               t = OMP_CLAUSE_DECL (c);
   10420          684 :               while (handled_component_p (t)
   10421              :                      || INDIRECT_REF_P (t)
   10422              :                      || TREE_CODE (t) == ADDR_EXPR
   10423              :                      || TREE_CODE (t) == MEM_REF
   10424          804 :                      || TREE_CODE (t) == NON_LVALUE_EXPR)
   10425          120 :                 t = TREE_OPERAND (t, 0);
   10426          684 :               if (DECL_P (t)
   10427          684 :                   && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   10428          342 :                 OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   10429              :             }
   10430        15960 :           pc = &OMP_CLAUSE_CHAIN (c);
   10431        15960 :           continue;
   10432          225 :         case OMP_CLAUSE_FULL:
   10433          225 :           if (partial_seen)
   10434              :             {
   10435           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10436              :                         "%<full%> clause must not be used together "
   10437              :                         "with %<partial%> clause");
   10438           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10439           12 :               continue;
   10440              :             }
   10441          213 :           pc = &OMP_CLAUSE_CHAIN (c);
   10442          213 :           continue;
   10443         6894 :         case OMP_CLAUSE_NOWAIT:
   10444         6894 :           if (copyprivate_seen)
   10445              :             {
   10446            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10447              :                         "%<nowait%> clause must not be used together "
   10448              :                         "with %<copyprivate%> clause");
   10449            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10450            6 :               continue;
   10451              :             }
   10452              :           /* FALLTHRU */
   10453        50415 :         default:
   10454        50415 :           pc = &OMP_CLAUSE_CHAIN (c);
   10455        50415 :           continue;
   10456              :         }
   10457              : 
   10458        22165 :       t = OMP_CLAUSE_DECL (c);
   10459        22165 :       switch (c_kind)
   10460              :         {
   10461         2763 :         case OMP_CLAUSE_LASTPRIVATE:
   10462         2763 :           if (DECL_P (t)
   10463         2763 :               && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
   10464              :             {
   10465         2666 :               need_default_ctor = true;
   10466         2666 :               need_dtor = true;
   10467              :             }
   10468              :           break;
   10469              : 
   10470         9426 :         case OMP_CLAUSE_REDUCTION:
   10471         9426 :         case OMP_CLAUSE_IN_REDUCTION:
   10472         9426 :         case OMP_CLAUSE_TASK_REDUCTION:
   10473         9426 :           if (allocate_seen)
   10474              :             {
   10475         1561 :               if (TREE_CODE (t) == MEM_REF)
   10476              :                 {
   10477          162 :                   t = TREE_OPERAND (t, 0);
   10478          162 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   10479            0 :                     t = TREE_OPERAND (t, 0);
   10480          162 :                   if (TREE_CODE (t) == ADDR_EXPR
   10481          120 :                       || INDIRECT_REF_P (t))
   10482           80 :                     t = TREE_OPERAND (t, 0);
   10483          162 :                   if (DECL_P (t))
   10484          162 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10485              :                 }
   10486         1399 :               else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10487              :                 {
   10488          192 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10489           96 :                     t = TREE_OPERAND (t, 0);
   10490           96 :                   if (DECL_P (t))
   10491           96 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10492           96 :                   t = OMP_CLAUSE_DECL (c);
   10493              :                 }
   10494         1303 :               else if (DECL_P (t))
   10495         1303 :                 bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10496         1561 :               t = OMP_CLAUSE_DECL (c);
   10497              :             }
   10498         9426 :           if (processing_template_decl
   10499          863 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10500              :             break;
   10501         8856 :           if (finish_omp_reduction_clause (c, &need_default_ctor,
   10502              :                                            &need_dtor))
   10503              :             remove = true;
   10504              :           else
   10505         8772 :             t = OMP_CLAUSE_DECL (c);
   10506              :           break;
   10507              : 
   10508          274 :         case OMP_CLAUSE_COPYIN:
   10509          274 :           if (processing_template_decl
   10510            0 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10511              :             break;
   10512          274 :           if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
   10513              :             {
   10514           15 :               error_at (OMP_CLAUSE_LOCATION (c),
   10515              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   10516           15 :               remove = true;
   10517              :             }
   10518              :           break;
   10519              : 
   10520              :         default:
   10521              :           break;
   10522              :         }
   10523              : 
   10524        22165 :       if (processing_template_decl
   10525         1544 :           && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10526              :         {
   10527          632 :           pc = &OMP_CLAUSE_CHAIN (c);
   10528          632 :           continue;
   10529              :         }
   10530              : 
   10531        21533 :       if (need_complete_type || need_copy_assignment)
   10532              :         {
   10533         9190 :           t = require_complete_type (t);
   10534         9190 :           if (t == error_mark_node)
   10535              :             remove = true;
   10536         9166 :           else if (!processing_template_decl
   10537         8783 :                    && TYPE_REF_P (TREE_TYPE (t))
   10538         9722 :                    && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
   10539              :             remove = true;
   10540              :         }
   10541        21533 :       if (need_implicitly_determined)
   10542              :         {
   10543        20495 :           const char *share_name = NULL;
   10544              : 
   10545        20495 :           if (allocate_seen
   10546         4993 :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10547        24609 :               && DECL_P (t))
   10548         3904 :             bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10549              : 
   10550        20495 :           if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   10551              :             share_name = "threadprivate";
   10552        20453 :           else switch (cxx_omp_predetermined_sharing_1 (t))
   10553              :             {
   10554              :             case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   10555              :               break;
   10556           47 :             case OMP_CLAUSE_DEFAULT_SHARED:
   10557           47 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10558           30 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   10559           64 :                   && c_omp_predefined_variable (t))
   10560              :                 /* The __func__ variable and similar function-local predefined
   10561              :                    variables may be listed in a shared or firstprivate
   10562              :                    clause.  */
   10563              :                 break;
   10564           31 :               if (VAR_P (t)
   10565           31 :                   && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10566            9 :                   && TREE_STATIC (t)
   10567           40 :                   && cxx_omp_const_qual_no_mutable (t))
   10568              :                 {
   10569            6 :                   tree ctx = CP_DECL_CONTEXT (t);
   10570              :                   /* const qualified static data members without mutable
   10571              :                      member may be specified in firstprivate clause.  */
   10572            6 :                   if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
   10573              :                     break;
   10574              :                 }
   10575              :               share_name = "shared";
   10576              :               break;
   10577              :             case OMP_CLAUSE_DEFAULT_PRIVATE:
   10578              :               share_name = "private";
   10579              :               break;
   10580            0 :             default:
   10581            0 :               gcc_unreachable ();
   10582              :             }
   10583              :           if (share_name)
   10584              :             {
   10585           67 :               error_at (OMP_CLAUSE_LOCATION (c),
   10586              :                         "%qE is predetermined %qs for %qs",
   10587              :                         omp_clause_printable_decl (t), share_name,
   10588           67 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10589           67 :               remove = true;
   10590              :             }
   10591        20428 :           else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10592        18369 :                    && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
   10593        35670 :                    && cxx_omp_const_qual_no_mutable (t))
   10594              :             {
   10595          126 :               error_at (OMP_CLAUSE_LOCATION (c),
   10596              :                         "%<const%> qualified %qE without %<mutable%> member "
   10597              :                         "may appear only in %<shared%> or %<firstprivate%> "
   10598              :                         "clauses", omp_clause_printable_decl (t));
   10599           63 :               remove = true;
   10600              :             }
   10601              :         }
   10602              : 
   10603        21533 :       if (detach_seen
   10604           16 :           && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10605           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   10606           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10607            0 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   10608        21549 :           && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
   10609              :         {
   10610            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   10611              :                     "the event handle of a %<detach%> clause "
   10612              :                     "should not be in a data-sharing clause");
   10613            6 :           remove = true;
   10614              :         }
   10615              : 
   10616              :       /* We're interested in the base element, not arrays.  */
   10617        21533 :       inner_type = type = TREE_TYPE (t);
   10618        21533 :       if ((need_complete_type
   10619              :            || need_copy_assignment
   10620        12343 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   10621         5708 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   10622         4235 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   10623        29968 :           && TYPE_REF_P (inner_type))
   10624          878 :         inner_type = TREE_TYPE (inner_type);
   10625        24114 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   10626         2581 :         inner_type = TREE_TYPE (inner_type);
   10627              : 
   10628              :       /* Check for special function availability by building a call to one.
   10629              :          Save the results, because later we won't be in the right context
   10630              :          for making these queries.  */
   10631         2388 :       if (CLASS_TYPE_P (inner_type)
   10632         2388 :           && COMPLETE_TYPE_P (inner_type)
   10633         2319 :           && (need_default_ctor || need_copy_ctor
   10634         1082 :               || need_copy_assignment || need_dtor)
   10635         1995 :           && !type_dependent_expression_p (t)
   10636        23528 :           && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
   10637              :                                          need_copy_ctor, need_copy_assignment,
   10638              :                                          need_dtor))
   10639              :         remove = true;
   10640              : 
   10641        21533 :       if (!remove
   10642        21533 :           && c_kind == OMP_CLAUSE_SHARED
   10643         2056 :           && processing_template_decl)
   10644              :         {
   10645          125 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10646          125 :           if (t)
   10647            5 :             OMP_CLAUSE_DECL (c) = t;
   10648              :         }
   10649              : 
   10650        21533 :       if (remove)
   10651          292 :         *pc = OMP_CLAUSE_CHAIN (c);
   10652              :       else
   10653        21241 :         pc = &OMP_CLAUSE_CHAIN (c);
   10654              :     }
   10655              : 
   10656        62695 :   if (allocate_seen)
   10657        16828 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   10658              :       {
   10659        14544 :         bool remove = false;
   10660        14544 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   10661         2540 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   10662         2143 :             && DECL_P (OMP_CLAUSE_DECL (c))
   10663        16687 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   10664              :           {
   10665           15 :             error_at (OMP_CLAUSE_LOCATION (c),
   10666              :                       "%qD specified in %<allocate%> clause but not in "
   10667           15 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   10668           15 :             remove = true;
   10669              :           }
   10670        14544 :         if (remove)
   10671           15 :           *pc = OMP_CLAUSE_CHAIN (c);
   10672              :         else
   10673        14529 :           pc = &OMP_CLAUSE_CHAIN (c);
   10674              :       }
   10675              : 
   10676        62695 :   if (ort == C_ORT_OMP_INTEROP
   10677        62695 :       && depend_clause
   10678           60 :       && (!init_use_destroy_seen
   10679           57 :           || (init_seen && init_no_targetsync_clause)))
   10680              :     {
   10681            9 :       auto_diagnostic_group d;
   10682            9 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   10683              :                 "%<depend%> clause requires action clauses with "
   10684              :                 "%<targetsync%> interop-type");
   10685            9 :       if (init_no_targetsync_clause)
   10686            6 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   10687              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   10688            9 :     }
   10689              : 
   10690        62695 :   bitmap_obstack_release (NULL);
   10691        62695 :   return clauses;
   10692              : }
   10693              : 
   10694              : /* Start processing OpenMP clauses that can include any
   10695              :    privatization clauses for non-static data members.  */
   10696              : 
   10697              : tree
   10698        48543 : push_omp_privatization_clauses (bool ignore_next)
   10699              : {
   10700        48543 :   if (omp_private_member_ignore_next)
   10701              :     {
   10702          656 :       omp_private_member_ignore_next = ignore_next;
   10703          656 :       return NULL_TREE;
   10704              :     }
   10705        47887 :   omp_private_member_ignore_next = ignore_next;
   10706        47887 :   if (omp_private_member_map)
   10707           24 :     omp_private_member_vec.safe_push (error_mark_node);
   10708        47887 :   return push_stmt_list ();
   10709              : }
   10710              : 
   10711              : /* Revert remapping of any non-static data members since
   10712              :    the last push_omp_privatization_clauses () call.  */
   10713              : 
   10714              : void
   10715        48537 : pop_omp_privatization_clauses (tree stmt)
   10716              : {
   10717        48537 :   if (stmt == NULL_TREE)
   10718              :     return;
   10719        47881 :   stmt = pop_stmt_list (stmt);
   10720        47881 :   if (omp_private_member_map)
   10721              :     {
   10722         1280 :       while (!omp_private_member_vec.is_empty ())
   10723              :         {
   10724          850 :           tree t = omp_private_member_vec.pop ();
   10725          850 :           if (t == error_mark_node)
   10726              :             {
   10727           24 :               add_stmt (stmt);
   10728           24 :               return;
   10729              :             }
   10730          826 :           bool no_decl_expr = t == integer_zero_node;
   10731          826 :           if (no_decl_expr)
   10732          136 :             t = omp_private_member_vec.pop ();
   10733          826 :           tree *v = omp_private_member_map->get (t);
   10734          826 :           gcc_assert (v);
   10735          826 :           if (!no_decl_expr)
   10736          690 :             add_decl_expr (*v);
   10737          826 :           omp_private_member_map->remove (t);
   10738              :         }
   10739          860 :       delete omp_private_member_map;
   10740          430 :       omp_private_member_map = NULL;
   10741              :     }
   10742        47857 :   add_stmt (stmt);
   10743              : }
   10744              : 
   10745              : /* Remember OpenMP privatization clauses mapping and clear it.
   10746              :    Used for lambdas.  */
   10747              : 
   10748              : void
   10749     15266498 : save_omp_privatization_clauses (vec<tree> &save)
   10750              : {
   10751     15266498 :   save = vNULL;
   10752     15266498 :   if (omp_private_member_ignore_next)
   10753            2 :     save.safe_push (integer_one_node);
   10754     15266498 :   omp_private_member_ignore_next = false;
   10755     15266498 :   if (!omp_private_member_map)
   10756              :     return;
   10757              : 
   10758            0 :   while (!omp_private_member_vec.is_empty ())
   10759              :     {
   10760            0 :       tree t = omp_private_member_vec.pop ();
   10761            0 :       if (t == error_mark_node)
   10762              :         {
   10763            0 :           save.safe_push (t);
   10764            0 :           continue;
   10765              :         }
   10766            0 :       tree n = t;
   10767            0 :       if (t == integer_zero_node)
   10768            0 :         t = omp_private_member_vec.pop ();
   10769            0 :       tree *v = omp_private_member_map->get (t);
   10770            0 :       gcc_assert (v);
   10771            0 :       save.safe_push (*v);
   10772            0 :       save.safe_push (t);
   10773            0 :       if (n != t)
   10774            0 :         save.safe_push (n);
   10775              :     }
   10776            0 :   delete omp_private_member_map;
   10777            0 :   omp_private_member_map = NULL;
   10778              : }
   10779              : 
   10780              : /* Restore OpenMP privatization clauses mapping saved by the
   10781              :    above function.  */
   10782              : 
   10783              : void
   10784     15266498 : restore_omp_privatization_clauses (vec<tree> &save)
   10785              : {
   10786     15266498 :   gcc_assert (omp_private_member_vec.is_empty ());
   10787     15266498 :   omp_private_member_ignore_next = false;
   10788     15266498 :   if (save.is_empty ())
   10789              :     return;
   10790            4 :   if (save.length () == 1 && save[0] == integer_one_node)
   10791              :     {
   10792            2 :       omp_private_member_ignore_next = true;
   10793            2 :       save.release ();
   10794            2 :       return;
   10795              :     }
   10796              : 
   10797            0 :   omp_private_member_map = new hash_map <tree, tree>;
   10798            0 :   while (!save.is_empty ())
   10799              :     {
   10800            0 :       tree t = save.pop ();
   10801            0 :       tree n = t;
   10802            0 :       if (t != error_mark_node)
   10803              :         {
   10804            0 :           if (t == integer_one_node)
   10805              :             {
   10806            0 :               omp_private_member_ignore_next = true;
   10807            0 :               gcc_assert (save.is_empty ());
   10808            0 :               break;
   10809              :             }
   10810            0 :           if (t == integer_zero_node)
   10811            0 :             t = save.pop ();
   10812            0 :           tree &v = omp_private_member_map->get_or_insert (t);
   10813            0 :           v = save.pop ();
   10814              :         }
   10815            0 :       omp_private_member_vec.safe_push (t);
   10816            0 :       if (n != t)
   10817            0 :         omp_private_member_vec.safe_push (n);
   10818              :     }
   10819            0 :   save.release ();
   10820              : }
   10821              : 
   10822              : /* For all variables in the tree_list VARS, mark them as thread local.  */
   10823              : 
   10824              : void
   10825          238 : finish_omp_threadprivate (tree vars)
   10826              : {
   10827          238 :   tree t;
   10828              : 
   10829              :   /* Mark every variable in VARS to be assigned thread local storage.  */
   10830          509 :   for (t = vars; t; t = TREE_CHAIN (t))
   10831              :     {
   10832          271 :       tree v = TREE_PURPOSE (t);
   10833          271 :       location_t loc = EXPR_LOCATION (TREE_VALUE (t));
   10834              : 
   10835          271 :       if (error_operand_p (v))
   10836              :         ;
   10837          271 :       else if (!VAR_P (v))
   10838            6 :         error_at (loc, "%<threadprivate%> %qD is not file, namespace "
   10839              :                        "or block scope variable", v);
   10840              :       /* If V had already been marked threadprivate, it doesn't matter
   10841              :          whether it had been used prior to this point.  */
   10842          265 :       else if (TREE_USED (v)
   10843          265 :           && (DECL_LANG_SPECIFIC (v) == NULL
   10844            3 :               || !CP_DECL_THREADPRIVATE_P (v)))
   10845            6 :         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
   10846          259 :       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
   10847            6 :         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
   10848          253 :       else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
   10849            3 :         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
   10850          201 :       else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
   10851          273 :                && CP_DECL_CONTEXT (v) != current_class_type)
   10852            6 :         error_at (loc, "%<threadprivate%> %qE directive not "
   10853            6 :                        "in %qT definition", v, CP_DECL_CONTEXT (v));
   10854              :       else
   10855              :         {
   10856              :           /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
   10857          244 :           if (DECL_LANG_SPECIFIC (v) == NULL)
   10858          200 :             retrofit_lang_decl (v);
   10859              : 
   10860          244 :           if (! CP_DECL_THREAD_LOCAL_P (v))
   10861              :             {
   10862          244 :               CP_DECL_THREAD_LOCAL_P (v) = true;
   10863          244 :               set_decl_tls_model (v, decl_default_tls_model (v));
   10864              :               /* If rtl has been already set for this var, call
   10865              :                  make_decl_rtl once again, so that encode_section_info
   10866              :                  has a chance to look at the new decl flags.  */
   10867          244 :               if (DECL_RTL_SET_P (v))
   10868            0 :                 make_decl_rtl (v);
   10869              :             }
   10870          244 :           CP_DECL_THREADPRIVATE_P (v) = 1;
   10871              :         }
   10872              :     }
   10873          238 : }
   10874              : 
   10875              : /* Build an OpenMP structured block.  */
   10876              : 
   10877              : tree
   10878        64018 : begin_omp_structured_block (void)
   10879              : {
   10880        64018 :   return do_pushlevel (sk_omp);
   10881              : }
   10882              : 
   10883              : tree
   10884        64003 : finish_omp_structured_block (tree block)
   10885              : {
   10886        64003 :   return do_poplevel (block);
   10887              : }
   10888              : 
   10889              : /* Similarly, except force the retention of the BLOCK.  */
   10890              : 
   10891              : tree
   10892        14799 : begin_omp_parallel (void)
   10893              : {
   10894        14799 :   keep_next_level (true);
   10895        14799 :   return begin_omp_structured_block ();
   10896              : }
   10897              : 
   10898              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   10899              :    statement.  */
   10900              : 
   10901              : tree
   10902          768 : finish_oacc_data (tree clauses, tree block)
   10903              : {
   10904          768 :   tree stmt;
   10905              : 
   10906          768 :   block = finish_omp_structured_block (block);
   10907              : 
   10908          768 :   stmt = make_node (OACC_DATA);
   10909          768 :   TREE_TYPE (stmt) = void_type_node;
   10910          768 :   OACC_DATA_CLAUSES (stmt) = clauses;
   10911          768 :   OACC_DATA_BODY (stmt) = block;
   10912              : 
   10913          768 :   return add_stmt (stmt);
   10914              : }
   10915              : 
   10916              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   10917              :    statement.  */
   10918              : 
   10919              : tree
   10920           55 : finish_oacc_host_data (tree clauses, tree block)
   10921              : {
   10922           55 :   tree stmt;
   10923              : 
   10924           55 :   block = finish_omp_structured_block (block);
   10925              : 
   10926           55 :   stmt = make_node (OACC_HOST_DATA);
   10927           55 :   TREE_TYPE (stmt) = void_type_node;
   10928           55 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   10929           55 :   OACC_HOST_DATA_BODY (stmt) = block;
   10930              : 
   10931           55 :   return add_stmt (stmt);
   10932              : }
   10933              : 
   10934              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   10935              :    statement.  */
   10936              : 
   10937              : tree
   10938         4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
   10939              : {
   10940         4653 :   body = finish_omp_structured_block (body);
   10941              : 
   10942         4653 :   tree stmt = make_node (code);
   10943         4653 :   TREE_TYPE (stmt) = void_type_node;
   10944         4653 :   OMP_BODY (stmt) = body;
   10945         4653 :   OMP_CLAUSES (stmt) = clauses;
   10946              : 
   10947         4653 :   return add_stmt (stmt);
   10948              : }
   10949              : 
   10950              : /* Used to walk OpenMP target directive body.  */
   10951              : 
   10952              : struct omp_target_walk_data
   10953              : {
   10954              :   /* Holds the 'this' expression found in current function.  */
   10955              :   tree current_object;
   10956              : 
   10957              :   /* True if the 'this' expression was accessed in the target body.  */
   10958              :   bool this_expr_accessed;
   10959              : 
   10960              :   /* For non-static functions, record which pointer-typed members were
   10961              :      accessed, and the whole expression.  */
   10962              :   hash_map<tree, tree> ptr_members_accessed;
   10963              : 
   10964              :   /* Record which lambda objects were accessed in target body.  */
   10965              :   hash_set<tree> lambda_objects_accessed;
   10966              : 
   10967              :   /* For lambda functions, the __closure object expression of the current
   10968              :      function, and the set of captured variables accessed in target body.  */
   10969              :   tree current_closure;
   10970              :   hash_set<tree> closure_vars_accessed;
   10971              : 
   10972              :   /* Local variables declared inside a BIND_EXPR, used to filter out such
   10973              :      variables when recording lambda_objects_accessed.  */
   10974              :   hash_set<tree> local_decls;
   10975              : 
   10976              :   omp_mapper_list<tree> *mappers;
   10977              : };
   10978              : 
   10979              : /* Helper function of finish_omp_target_clauses, called via
   10980              :    cp_walk_tree_without_duplicates.  Traverse body of OpenMP target
   10981              :    directive *TP, and fill out omp_target_walk_data passed in *PTR.  */
   10982              : 
   10983              : static tree
   10984       228109 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
   10985              : {
   10986       228109 :   tree t = *tp;
   10987       228109 :   struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
   10988       228109 :   tree current_object = data->current_object;
   10989       228109 :   tree current_closure = data->current_closure;
   10990       228109 :   omp_mapper_list<tree> *mlist = data->mappers;
   10991              : 
   10992              :   /* References inside of these expression codes shouldn't incur any
   10993              :      form of mapping, so return early.  */
   10994       228109 :   if (TREE_CODE (t) == SIZEOF_EXPR
   10995       228101 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   10996              :     {
   10997            8 :       *walk_subtrees = 0;
   10998            8 :       return NULL_TREE;
   10999              :     }
   11000              : 
   11001       228101 :   if (TREE_CODE (t) == OMP_CLAUSE)
   11002              :     return NULL_TREE;
   11003              : 
   11004       215516 :   if (!processing_template_decl)
   11005              :     {
   11006       215516 :       tree aggr_type = NULL_TREE;
   11007              : 
   11008       215516 :       if (TREE_CODE (t) == COMPONENT_REF
   11009       215516 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   11010         2257 :         aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   11011       213259 :       else if ((TREE_CODE (t) == VAR_DECL
   11012              :                 || TREE_CODE (t) == PARM_DECL
   11013              :                 || TREE_CODE (t) == RESULT_DECL)
   11014        16942 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   11015         1216 :         aggr_type = TREE_TYPE (t);
   11016              : 
   11017         3473 :       if (aggr_type)
   11018              :         {
   11019         3473 :           tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
   11020         3473 :           if (mapper_fn)
   11021          199 :             mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   11022              :         }
   11023              :     }
   11024              : 
   11025       215516 :   if (current_object)
   11026              :     {
   11027         2564 :       tree this_expr = TREE_OPERAND (current_object, 0);
   11028              : 
   11029         2564 :       if (operand_equal_p (t, this_expr))
   11030              :         {
   11031           35 :           data->this_expr_accessed = true;
   11032           35 :           *walk_subtrees = 0;
   11033           35 :           return NULL_TREE;
   11034              :         }
   11035              : 
   11036         2529 :       if (TREE_CODE (t) == COMPONENT_REF
   11037          115 :           && POINTER_TYPE_P (TREE_TYPE (t))
   11038           36 :           && operand_equal_p (TREE_OPERAND (t, 0), current_object)
   11039         2563 :           && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
   11040              :         {
   11041           34 :           data->this_expr_accessed = true;
   11042           34 :           tree fld = TREE_OPERAND (t, 1);
   11043           34 :           if (data->ptr_members_accessed.get (fld) == NULL)
   11044              :             {
   11045           14 :               if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
   11046            4 :                 t = convert_from_reference (t);
   11047           14 :               data->ptr_members_accessed.put (fld, t);
   11048              :             }
   11049           34 :           *walk_subtrees = 0;
   11050           34 :           return NULL_TREE;
   11051              :         }
   11052              :     }
   11053              : 
   11054              :   /* When the current_function_decl is a lambda function, the closure object
   11055              :      argument's type seems to not yet have fields laid out, so a recording
   11056              :      of DECL_VALUE_EXPRs during the target body walk seems the only way to
   11057              :      find them.  */
   11058       215447 :   if (current_closure
   11059          300 :       && (VAR_P (t)
   11060              :           || TREE_CODE (t) == PARM_DECL
   11061              :           || TREE_CODE (t) == RESULT_DECL)
   11062           24 :       && DECL_HAS_VALUE_EXPR_P (t)
   11063           10 :       && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
   11064       215457 :       && operand_equal_p (current_closure,
   11065           10 :                           TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
   11066              :     {
   11067            9 :       if (!data->closure_vars_accessed.contains (t))
   11068            9 :         data->closure_vars_accessed.add (t);
   11069            9 :       *walk_subtrees = 0;
   11070            9 :       return NULL_TREE;
   11071              :     }
   11072              : 
   11073       215438 :   if (TREE_CODE (t) == BIND_EXPR)
   11074              :     {
   11075        20041 :       if (tree block = BIND_EXPR_BLOCK (t))
   11076        22482 :         for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
   11077         2445 :           if (!data->local_decls.contains (var))
   11078         2445 :             data->local_decls.add (var);
   11079        20041 :       return NULL_TREE;
   11080              :     }
   11081              : 
   11082       200000 :   if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
   11083              :     {
   11084           39 :       tree lt = TREE_TYPE (t);
   11085           39 :       gcc_assert (CLASS_TYPE_P (lt));
   11086              : 
   11087           39 :       if (!data->lambda_objects_accessed.contains (t)
   11088              :           /* Do not prepare to create target maps for locally declared
   11089              :              lambdas or anonymous ones.  */
   11090           39 :           && !data->local_decls.contains (t)
   11091           72 :           && TREE_CODE (t) != TARGET_EXPR)
   11092           13 :         data->lambda_objects_accessed.add (t);
   11093           39 :       *walk_subtrees = 0;
   11094           39 :       return NULL_TREE;
   11095              :     }
   11096              : 
   11097              :   return NULL_TREE;
   11098              : }
   11099              : 
   11100              : /* Helper function for finish_omp_target, and also from tsubst_expr.
   11101              :    Create additional clauses for mapping of non-static members, lambda objects,
   11102              :    etc.  */
   11103              : 
   11104              : void
   11105         6996 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
   11106              : {
   11107         6996 :   omp_target_walk_data data;
   11108         6996 :   data.this_expr_accessed = false;
   11109         6996 :   data.current_object = NULL_TREE;
   11110              : 
   11111         6996 :   if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
   11112           96 :     if (tree ct = current_nonlambda_class_type ())
   11113              :       {
   11114           95 :         tree object = maybe_dummy_object (ct, NULL);
   11115           95 :         object = maybe_resolve_dummy (object, true);
   11116           95 :         data.current_object = object;
   11117              :       }
   11118              : 
   11119         6996 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11120              :     {
   11121            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11122            8 :       data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11123              :     }
   11124              :   else
   11125         6988 :     data.current_closure = NULL_TREE;
   11126              : 
   11127         6996 :   auto_vec<tree, 16> new_clauses;
   11128              : 
   11129         6996 :   if (!processing_template_decl)
   11130              :     {
   11131         6996 :       hash_set<omp_name_type<tree> > seen_types;
   11132         6996 :       auto_vec<tree> mapper_fns;
   11133         6996 :       omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
   11134         6996 :       data.mappers = &mlist;
   11135              : 
   11136         6996 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11137              :                                        &data);
   11138              : 
   11139         6996 :       unsigned int i;
   11140         6996 :       tree mapper_fn;
   11141        14085 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11142           93 :         c_omp_find_nested_mappers (&mlist, mapper_fn);
   11143              : 
   11144         7159 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11145              :         {
   11146           93 :           tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
   11147           93 :           if (mapper == error_mark_node)
   11148            0 :             continue;
   11149           93 :           tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   11150           93 :           tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   11151           93 :           if (BASELINK_P (mapper_fn))
   11152            0 :             mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
   11153              : 
   11154           93 :           tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   11155           93 :           OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   11156           93 :           OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   11157           93 :           OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
   11158              : 
   11159           93 :           new_clauses.safe_push (c);
   11160              :         }
   11161         6996 :     }
   11162              :   else
   11163              :     {
   11164            0 :       data.mappers = NULL;
   11165            0 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11166              :                                        &data);
   11167              :     }
   11168              : 
   11169         6996 :   tree omp_target_this_expr = NULL_TREE;
   11170         6996 :   tree *explicit_this_deref_map = NULL;
   11171         6996 :   if (data.this_expr_accessed)
   11172              :     {
   11173           31 :       omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
   11174              : 
   11175              :       /* See if explicit user-specified map(this[:]) clause already exists.
   11176              :          If not, we create an implicit map(tofrom:this[:1]) clause.  */
   11177           80 :       for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
   11178           50 :         if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
   11179           47 :             && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
   11180           40 :                 || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
   11181           57 :             && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
   11182              :                                 omp_target_this_expr))
   11183              :           {
   11184              :             explicit_this_deref_map = cp;
   11185              :             break;
   11186              :           }
   11187              :     }
   11188              : 
   11189         6996 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11190         6996 :       && (data.this_expr_accessed
   11191            1 :           || !data.closure_vars_accessed.is_empty ()))
   11192              :     {
   11193              :       /* For lambda functions, we need to first create a copy of the
   11194              :          __closure object.  */
   11195            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11196            8 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11197            8 :       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   11198            8 :       OMP_CLAUSE_DECL (c)
   11199            8 :         = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11200            8 :       OMP_CLAUSE_SIZE (c)
   11201            8 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
   11202            8 :       new_clauses.safe_push (c);
   11203              : 
   11204            8 :       tree closure_obj = OMP_CLAUSE_DECL (c);
   11205            8 :       tree closure_type = TREE_TYPE (closure_obj);
   11206              : 
   11207           16 :       gcc_assert (LAMBDA_TYPE_P (closure_type)
   11208              :                   && CLASS_TYPE_P (closure_type));
   11209              : 
   11210            8 :       tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11211            8 :       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   11212            8 :       OMP_CLAUSE_DECL (c2) = closure;
   11213            8 :       OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11214            8 :       new_clauses.safe_push (c2);
   11215              :     }
   11216              : 
   11217         6996 :   if (data.this_expr_accessed)
   11218              :     {
   11219              :       /* If the this-expr was accessed, create a map(*this) clause.  */
   11220           31 :       enum gomp_map_kind kind = GOMP_MAP_TOFROM;
   11221           31 :       if (explicit_this_deref_map)
   11222              :         {
   11223            1 :           tree this_map = *explicit_this_deref_map;
   11224            1 :           tree nc = OMP_CLAUSE_CHAIN (this_map);
   11225            2 :           gcc_assert (nc != NULL_TREE
   11226              :                       && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11227              :                       && (OMP_CLAUSE_MAP_KIND (nc)
   11228              :                           == GOMP_MAP_FIRSTPRIVATE_POINTER));
   11229            1 :           kind = OMP_CLAUSE_MAP_KIND (this_map);
   11230              :           /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
   11231              :              two-map sequence away from the chain.  */
   11232            1 :           *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
   11233              :         }
   11234           31 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11235           31 :       OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11236           31 :       OMP_CLAUSE_DECL (c)
   11237           31 :         = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
   11238           31 :       OMP_CLAUSE_SIZE (c)
   11239           31 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
   11240           31 :       new_clauses.safe_push (c);
   11241              : 
   11242              :       /* If we're in a lambda function, the this-pointer will actually be
   11243              :          '__closure->this', a mapped member of __closure, hence always_pointer.
   11244              :          Otherwise it's a firstprivate pointer.  */
   11245           31 :       enum gomp_map_kind ptr_kind
   11246           31 :         = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11247           31 :            ? GOMP_MAP_ALWAYS_POINTER
   11248           24 :            : GOMP_MAP_FIRSTPRIVATE_POINTER);
   11249           31 :       c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11250           31 :       OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11251           31 :       OMP_CLAUSE_DECL (c) = omp_target_this_expr;
   11252           31 :       OMP_CLAUSE_SIZE (c) = size_zero_node;
   11253           31 :       new_clauses.safe_push (c);
   11254              :     }
   11255              : 
   11256         6996 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11257              :     {
   11258            8 :       if (omp_target_this_expr)
   11259              :         {
   11260            7 :           STRIP_NOPS (omp_target_this_expr);
   11261            7 :           gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
   11262            7 :           omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
   11263              :         }
   11264              : 
   11265           17 :       for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
   11266           34 :            i != data.closure_vars_accessed.end (); ++i)
   11267              :         {
   11268            9 :           tree orig_decl = *i;
   11269            9 :           tree closure_expr = DECL_VALUE_EXPR (orig_decl);
   11270              : 
   11271            9 :           if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
   11272            9 :               || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
   11273              :             {
   11274              :               /* this-pointer is processed above, outside this loop.  */
   11275            3 :               if (omp_target_this_expr
   11276            3 :                   && operand_equal_p (closure_expr, omp_target_this_expr))
   11277            0 :                 continue;
   11278              : 
   11279            3 :               bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
   11280            3 :               enum gomp_map_kind kind, ptr_kind, nc_kind;
   11281            3 :               tree size;
   11282              : 
   11283            3 :               if (ptr_p)
   11284              :                 {
   11285              :                   /* For pointers, default mapped as zero-length array
   11286              :                      section.  */
   11287            2 :                   kind = GOMP_MAP_ALLOC;
   11288            2 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   11289            2 :                   ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   11290            2 :                   size = size_zero_node;
   11291              :                 }
   11292              :               else
   11293              :                 {
   11294              :                   /* For references, default mapped as appearing on map
   11295              :                      clause.  */
   11296            1 :                   kind = GOMP_MAP_TOFROM;
   11297            1 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
   11298            1 :                   ptr_kind = GOMP_MAP_ALWAYS_POINTER;
   11299            1 :                   size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
   11300              :                 }
   11301              : 
   11302            6 :               for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
   11303            3 :                 if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
   11304            1 :                     && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
   11305            1 :                         || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
   11306            3 :                     && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
   11307              :                                         orig_decl))
   11308              :                   {
   11309              :                     /* If this was already specified by user as a map,
   11310              :                        save the user specified map kind, delete the
   11311              :                        "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
   11312              :                        and insert our own sequence:
   11313              :                        "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
   11314              :                     */
   11315            0 :                     tree nc = OMP_CLAUSE_CHAIN (*p);
   11316            0 :                     gcc_assert (nc != NULL_TREE
   11317              :                                 && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11318              :                                 && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
   11319              :                     /* Update with user specified kind and size.  */
   11320            0 :                     kind = OMP_CLAUSE_MAP_KIND (*p);
   11321            0 :                     size = OMP_CLAUSE_SIZE (*p);
   11322            0 :                     *p = OMP_CLAUSE_CHAIN (nc);
   11323            0 :                     break;
   11324              :                   }
   11325              : 
   11326            3 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11327            3 :               OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11328            3 :               OMP_CLAUSE_DECL (c)
   11329            3 :                 = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
   11330            3 :               OMP_CLAUSE_SIZE (c) = size;
   11331            3 :               if (ptr_p)
   11332            2 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11333            3 :               new_clauses.safe_push (c);
   11334              : 
   11335            3 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11336            3 :               OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11337            3 :               OMP_CLAUSE_DECL (c) = closure_expr;
   11338            3 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11339            3 :               new_clauses.safe_push (c);
   11340              :             }
   11341              :         }
   11342              :     }
   11343              : 
   11344         6996 :   if (!data.ptr_members_accessed.is_empty ())
   11345           14 :     for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
   11346           56 :          i != data.ptr_members_accessed.end (); ++i)
   11347              :       {
   11348              :         /* For each referenced member that is of pointer or reference-to-pointer
   11349              :            type, create the equivalent of map(alloc:this->ptr[:0]).  */
   11350           14 :         tree field_decl = (*i).first;
   11351           14 :         tree ptr_member = (*i).second;
   11352              : 
   11353           26 :         for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
   11354              :           {
   11355           16 :             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   11356            2 :               continue;
   11357              :             /* If map(this->ptr[:N]) already exists, avoid creating another
   11358              :                such map.  */
   11359           14 :             tree decl = OMP_CLAUSE_DECL (c);
   11360           14 :             if ((TREE_CODE (decl) == INDIRECT_REF
   11361           10 :                  || TREE_CODE (decl) == MEM_REF)
   11362           14 :                 && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
   11363            4 :               goto next_ptr_member;
   11364              :           }
   11365              : 
   11366           10 :         if (!cxx_mark_addressable (ptr_member))
   11367            0 :           gcc_unreachable ();
   11368              : 
   11369           10 :         if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
   11370              :           {
   11371              :             /* For reference to pointers, we need to map the referenced
   11372              :                pointer first for things to be correct.  */
   11373            4 :             tree ptr_member_type = TREE_TYPE (ptr_member);
   11374              : 
   11375              :             /* Map pointer target as zero-length array section.  */
   11376            4 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11377            4 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11378            4 :             OMP_CLAUSE_DECL (c)
   11379            4 :               = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
   11380            4 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11381            4 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11382              : 
   11383              :             /* Map pointer to zero-length array section.  */
   11384            4 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11385            4 :             OMP_CLAUSE_SET_MAP_KIND
   11386              :               (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
   11387            4 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11388            4 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11389              : 
   11390              :             /* Attach reference-to-pointer field to pointer.  */
   11391            4 :             tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11392            4 :             OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
   11393            4 :             OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
   11394            4 :             OMP_CLAUSE_SIZE (c3) = size_zero_node;
   11395              : 
   11396            4 :             new_clauses.safe_push (c);
   11397            4 :             new_clauses.safe_push (c2);
   11398            4 :             new_clauses.safe_push (c3);
   11399              :           }
   11400            6 :         else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
   11401              :           {
   11402              :             /* Map pointer target as zero-length array section.  */
   11403            6 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11404            6 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11405            6 :             OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
   11406              :                                                       RO_UNARY_STAR);
   11407            6 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11408            6 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11409              : 
   11410              :             /* Attach zero-length array section to pointer.  */
   11411            6 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11412            6 :             OMP_CLAUSE_SET_MAP_KIND
   11413              :               (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11414            6 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11415            6 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11416              : 
   11417            6 :             new_clauses.safe_push (c);
   11418            6 :             new_clauses.safe_push (c2);
   11419              :           }
   11420              :         else
   11421            0 :           gcc_unreachable ();
   11422              : 
   11423           14 :       next_ptr_member:
   11424           14 :         ;
   11425              :       }
   11426              : 
   11427         7009 :   for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
   11428         7022 :        i != data.lambda_objects_accessed.end (); ++i)
   11429              :     {
   11430           13 :       tree lobj = *i;
   11431           13 :       if (TREE_CODE (lobj) == TARGET_EXPR)
   11432            0 :         lobj = TARGET_EXPR_SLOT (lobj);
   11433              : 
   11434           13 :       tree lt = TREE_TYPE (lobj);
   11435           26 :       gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
   11436              : 
   11437           13 :       tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11438           13 :       OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
   11439           13 :       OMP_CLAUSE_DECL (lc) = lobj;
   11440           13 :       OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
   11441           13 :       new_clauses.safe_push (lc);
   11442              : 
   11443          180 :       for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
   11444              :         {
   11445          167 :           if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
   11446              :             {
   11447            4 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11448              :                                  lobj, fld, NULL_TREE);
   11449            4 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11450            4 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11451            4 :               OMP_CLAUSE_DECL (c)
   11452            4 :                 = build_indirect_ref (loc, exp, RO_UNARY_STAR);
   11453            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11454            4 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11455            4 :               new_clauses.safe_push (c);
   11456              : 
   11457            4 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11458            4 :               OMP_CLAUSE_SET_MAP_KIND
   11459              :                 (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11460            4 :               OMP_CLAUSE_DECL (c) = exp;
   11461            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11462            4 :               new_clauses.safe_push (c);
   11463              :             }
   11464          163 :           else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
   11465              :             {
   11466            0 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11467              :                                  lobj, fld, NULL_TREE);
   11468            0 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11469            0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   11470            0 :               OMP_CLAUSE_DECL (c)
   11471            0 :                 = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
   11472            0 :               OMP_CLAUSE_SIZE (c)
   11473            0 :                 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
   11474            0 :               new_clauses.safe_push (c);
   11475              : 
   11476            0 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11477            0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   11478            0 :               OMP_CLAUSE_DECL (c) = exp;
   11479            0 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11480            0 :               new_clauses.safe_push (c);
   11481              :             }
   11482              :         }
   11483              :     }
   11484              : 
   11485         6996 :   tree c = *clauses_ptr;
   11486        14214 :   for (int i = new_clauses.length () - 1; i >= 0; i--)
   11487              :     {
   11488          222 :       OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
   11489          222 :       c = new_clauses[i];
   11490              :     }
   11491         6996 :   *clauses_ptr = c;
   11492         6996 : }
   11493              : 
   11494              : /* Called from cp_parser_omp_target.  Create additional implicit clauses for
   11495              :    OpenMP target directives, and do sanity checks.  */
   11496              : 
   11497              : tree
   11498         6984 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
   11499              : {
   11500         6984 :   if (!processing_template_decl)
   11501         6171 :     finish_omp_target_clauses (loc, body, &clauses);
   11502              : 
   11503         6984 :   tree stmt = make_node (OMP_TARGET);
   11504         6984 :   TREE_TYPE (stmt) = void_type_node;
   11505         6984 :   OMP_TARGET_CLAUSES (stmt) = clauses;
   11506         6984 :   OMP_TARGET_BODY (stmt) = body;
   11507         6984 :   OMP_TARGET_COMBINED (stmt) = combined_p;
   11508         6984 :   SET_EXPR_LOCATION (stmt, loc);
   11509              : 
   11510         6984 :   tree c = clauses;
   11511        16670 :   while (c)
   11512              :     {
   11513         9686 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   11514         5612 :         switch (OMP_CLAUSE_MAP_KIND (c))
   11515              :           {
   11516              :           case GOMP_MAP_TO:
   11517              :           case GOMP_MAP_ALWAYS_TO:
   11518              :           case GOMP_MAP_PRESENT_TO:
   11519              :           case GOMP_MAP_ALWAYS_PRESENT_TO:
   11520              :           case GOMP_MAP_FROM:
   11521              :           case GOMP_MAP_ALWAYS_FROM:
   11522              :           case GOMP_MAP_PRESENT_FROM:
   11523              :           case GOMP_MAP_ALWAYS_PRESENT_FROM:
   11524              :           case GOMP_MAP_TOFROM:
   11525              :           case GOMP_MAP_ALWAYS_TOFROM:
   11526              :           case GOMP_MAP_PRESENT_TOFROM:
   11527              :           case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   11528              :           case GOMP_MAP_ALLOC:
   11529              :           case GOMP_MAP_PRESENT_ALLOC:
   11530              :           case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11531              :           case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11532              :           case GOMP_MAP_ALWAYS_POINTER:
   11533              :           case GOMP_MAP_ATTACH_DETACH:
   11534              :           case GOMP_MAP_ATTACH:
   11535              :           case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   11536              :           case GOMP_MAP_POINTER:
   11537              :           case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   11538              :             break;
   11539            3 :           default:
   11540            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   11541              :                       "%<#pragma omp target%> with map-type other "
   11542              :                       "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
   11543              :                       "on %<map%> clause");
   11544            3 :             break;
   11545              :           }
   11546         9686 :       c = OMP_CLAUSE_CHAIN (c);
   11547              :     }
   11548         6984 :   return add_stmt (stmt);
   11549              : }
   11550              : 
   11551              : tree
   11552         9323 : finish_omp_parallel (tree clauses, tree body)
   11553              : {
   11554         9323 :   tree stmt;
   11555              : 
   11556         9323 :   body = finish_omp_structured_block (body);
   11557              : 
   11558         9323 :   stmt = make_node (OMP_PARALLEL);
   11559         9323 :   TREE_TYPE (stmt) = void_type_node;
   11560         9323 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   11561         9323 :   OMP_PARALLEL_BODY (stmt) = body;
   11562              : 
   11563         9323 :   return add_stmt (stmt);
   11564              : }
   11565              : 
   11566              : tree
   11567         2162 : begin_omp_task (void)
   11568              : {
   11569         2162 :   keep_next_level (true);
   11570         2162 :   return begin_omp_structured_block ();
   11571              : }
   11572              : 
   11573              : tree
   11574         2162 : finish_omp_task (tree clauses, tree body)
   11575              : {
   11576         2162 :   tree stmt;
   11577              : 
   11578         2162 :   body = finish_omp_structured_block (body);
   11579              : 
   11580         2162 :   stmt = make_node (OMP_TASK);
   11581         2162 :   TREE_TYPE (stmt) = void_type_node;
   11582         2162 :   OMP_TASK_CLAUSES (stmt) = clauses;
   11583         2162 :   OMP_TASK_BODY (stmt) = body;
   11584              : 
   11585         2162 :   return add_stmt (stmt);
   11586              : }
   11587              : 
   11588              : /* Helper function for finish_omp_for.  Convert Ith random access iterator
   11589              :    into integral iterator.  Return FALSE if successful.  */
   11590              : 
   11591              : static bool
   11592          813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
   11593              :                                tree declv, tree orig_declv, tree initv,
   11594              :                                tree condv, tree incrv, tree *body,
   11595              :                                tree *pre_body, tree &clauses,
   11596              :                                int collapse, int ordered)
   11597              : {
   11598          813 :   tree diff, iter_init, iter_incr = NULL, last;
   11599          813 :   tree incr_var = NULL, orig_pre_body, orig_body, c;
   11600          813 :   tree decl = TREE_VEC_ELT (declv, i);
   11601          813 :   tree init = TREE_VEC_ELT (initv, i);
   11602          813 :   tree cond = TREE_VEC_ELT (condv, i);
   11603          813 :   tree incr = TREE_VEC_ELT (incrv, i);
   11604          813 :   tree iter = decl;
   11605          813 :   location_t elocus = locus;
   11606              : 
   11607          813 :   if (init && EXPR_HAS_LOCATION (init))
   11608           12 :     elocus = EXPR_LOCATION (init);
   11609              : 
   11610          813 :   switch (TREE_CODE (cond))
   11611              :     {
   11612          810 :     case GT_EXPR:
   11613          810 :     case GE_EXPR:
   11614          810 :     case LT_EXPR:
   11615          810 :     case LE_EXPR:
   11616          810 :     case NE_EXPR:
   11617          810 :       if (TREE_OPERAND (cond, 1) == iter)
   11618           42 :         cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
   11619           42 :                        TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
   11620          810 :       if (TREE_OPERAND (cond, 0) != iter)
   11621            0 :         cond = error_mark_node;
   11622              :       else
   11623              :         {
   11624          810 :           tree tem = build_x_binary_op (EXPR_LOCATION (cond),
   11625          810 :                                         TREE_CODE (cond),
   11626              :                                         iter, ERROR_MARK,
   11627          810 :                                         TREE_OPERAND (cond, 1), ERROR_MARK,
   11628              :                                         NULL_TREE, NULL, tf_warning_or_error);
   11629          810 :           if (error_operand_p (tem))
   11630              :             return true;
   11631              :         }
   11632              :       break;
   11633            3 :     default:
   11634            3 :       cond = error_mark_node;
   11635            3 :       break;
   11636              :     }
   11637          810 :   if (cond == error_mark_node)
   11638              :     {
   11639            3 :       error_at (elocus, "invalid controlling predicate");
   11640            3 :       return true;
   11641              :     }
   11642          807 :   diff = build_x_binary_op (elocus, MINUS_EXPR,
   11643          807 :                             TREE_OPERAND (cond, 1), ERROR_MARK,
   11644              :                             iter, ERROR_MARK,
   11645              :                             NULL_TREE, NULL, tf_warning_or_error);
   11646          807 :   diff = cp_fully_fold (diff);
   11647          807 :   if (error_operand_p (diff))
   11648              :     return true;
   11649          807 :   if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
   11650              :     {
   11651            0 :       error_at (elocus, "difference between %qE and %qD does not have integer type",
   11652            0 :                 TREE_OPERAND (cond, 1), iter);
   11653            0 :       return true;
   11654              :     }
   11655          807 :   if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
   11656          807 :                                   TREE_VEC_ELT (declv, i), NULL_TREE,
   11657              :                                   cond, cp_walk_subtrees))
   11658              :     return true;
   11659              : 
   11660          762 :   switch (TREE_CODE (incr))
   11661              :     {
   11662          370 :     case PREINCREMENT_EXPR:
   11663          370 :     case PREDECREMENT_EXPR:
   11664          370 :     case POSTINCREMENT_EXPR:
   11665          370 :     case POSTDECREMENT_EXPR:
   11666          370 :       if (TREE_OPERAND (incr, 0) != iter)
   11667              :         {
   11668            0 :           incr = error_mark_node;
   11669            0 :           break;
   11670              :         }
   11671          370 :       iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
   11672          370 :                                     TREE_CODE (incr), iter,
   11673              :                                     NULL_TREE, tf_warning_or_error);
   11674          370 :       if (error_operand_p (iter_incr))
   11675              :         return true;
   11676          370 :       else if (TREE_CODE (incr) == PREINCREMENT_EXPR
   11677          219 :                || TREE_CODE (incr) == POSTINCREMENT_EXPR)
   11678          299 :         incr = integer_one_node;
   11679              :       else
   11680           71 :         incr = integer_minus_one_node;
   11681              :       break;
   11682          392 :     case MODIFY_EXPR:
   11683          392 :       if (TREE_OPERAND (incr, 0) != iter)
   11684            0 :         incr = error_mark_node;
   11685          392 :       else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
   11686          392 :                || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
   11687              :         {
   11688          392 :           tree rhs = TREE_OPERAND (incr, 1);
   11689          392 :           if (TREE_OPERAND (rhs, 0) == iter)
   11690              :             {
   11691          299 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
   11692              :                   != INTEGER_TYPE)
   11693            0 :                 incr = error_mark_node;
   11694              :               else
   11695              :                 {
   11696          299 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11697          299 :                                                    iter, TREE_CODE (rhs),
   11698          299 :                                                    TREE_OPERAND (rhs, 1),
   11699              :                                                    NULL_TREE,
   11700              :                                                    tf_warning_or_error);
   11701          299 :                   if (error_operand_p (iter_incr))
   11702              :                     return true;
   11703          299 :                   incr = TREE_OPERAND (rhs, 1);
   11704          299 :                   incr = cp_convert (TREE_TYPE (diff), incr,
   11705              :                                      tf_warning_or_error);
   11706          299 :                   if (TREE_CODE (rhs) == MINUS_EXPR)
   11707              :                     {
   11708           16 :                       incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
   11709           16 :                       incr = fold_simple (incr);
   11710              :                     }
   11711          299 :                   if (TREE_CODE (incr) != INTEGER_CST
   11712          299 :                       && (TREE_CODE (incr) != NOP_EXPR
   11713           66 :                           || (TREE_CODE (TREE_OPERAND (incr, 0))
   11714              :                               != INTEGER_CST)))
   11715              :                     iter_incr = NULL;
   11716              :                 }
   11717              :             }
   11718           93 :           else if (TREE_OPERAND (rhs, 1) == iter)
   11719              :             {
   11720           93 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
   11721           93 :                   || TREE_CODE (rhs) != PLUS_EXPR)
   11722            0 :                 incr = error_mark_node;
   11723              :               else
   11724              :                 {
   11725           93 :                   iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
   11726              :                                                  PLUS_EXPR,
   11727           93 :                                                  TREE_OPERAND (rhs, 0),
   11728              :                                                  ERROR_MARK, iter,
   11729              :                                                  ERROR_MARK, NULL_TREE, NULL,
   11730              :                                                  tf_warning_or_error);
   11731           93 :                   if (error_operand_p (iter_incr))
   11732              :                     return true;
   11733           93 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11734              :                                                    iter, NOP_EXPR,
   11735              :                                                    iter_incr, NULL_TREE,
   11736              :                                                    tf_warning_or_error);
   11737           93 :                   if (error_operand_p (iter_incr))
   11738              :                     return true;
   11739           93 :                   incr = TREE_OPERAND (rhs, 0);
   11740           93 :                   iter_incr = NULL;
   11741              :                 }
   11742              :             }
   11743              :           else
   11744            0 :             incr = error_mark_node;
   11745              :         }
   11746              :       else
   11747            0 :         incr = error_mark_node;
   11748              :       break;
   11749            0 :     default:
   11750            0 :       incr = error_mark_node;
   11751            0 :       break;
   11752              :     }
   11753              : 
   11754          762 :   if (incr == error_mark_node)
   11755              :     {
   11756            0 :       error_at (elocus, "invalid increment expression");
   11757            0 :       return true;
   11758              :     }
   11759              : 
   11760          762 :   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
   11761          762 :   incr = cp_fully_fold (incr);
   11762          762 :   tree loop_iv_seen = NULL_TREE;
   11763         1735 :   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
   11764         1093 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   11765         1093 :         && OMP_CLAUSE_DECL (c) == iter)
   11766              :       {
   11767          120 :         if (code == OMP_TASKLOOP || code == OMP_LOOP)
   11768              :           {
   11769           60 :             loop_iv_seen = c;
   11770           60 :             OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
   11771              :           }
   11772              :         break;
   11773              :       }
   11774          973 :     else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
   11775          113 :              && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   11776         1007 :              && OMP_CLAUSE_DECL (c) == iter)
   11777              :       {
   11778           30 :         loop_iv_seen = c;
   11779           30 :         if (code == OMP_TASKLOOP)
   11780           25 :           OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
   11781              :       }
   11782              : 
   11783          762 :   decl = create_temporary_var (TREE_TYPE (diff));
   11784          762 :   pushdecl (decl);
   11785          762 :   add_decl_expr (decl);
   11786          762 :   last = create_temporary_var (TREE_TYPE (diff));
   11787          762 :   pushdecl (last);
   11788          762 :   add_decl_expr (last);
   11789          762 :   if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
   11790           10 :       && (!ordered || (i < collapse && collapse > 1)))
   11791              :     {
   11792           10 :       incr_var = create_temporary_var (TREE_TYPE (diff));
   11793           10 :       pushdecl (incr_var);
   11794           10 :       add_decl_expr (incr_var);
   11795              :     }
   11796          762 :   gcc_assert (stmts_are_full_exprs_p ());
   11797          762 :   tree diffvar = NULL_TREE;
   11798          762 :   if (code == OMP_TASKLOOP)
   11799              :     {
   11800          101 :       if (!loop_iv_seen)
   11801              :         {
   11802           38 :           tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11803           38 :           OMP_CLAUSE_DECL (ivc) = iter;
   11804           38 :           cxx_omp_finish_clause (ivc, NULL, false);
   11805           38 :           OMP_CLAUSE_CHAIN (ivc) = clauses;
   11806           38 :           clauses = ivc;
   11807              :         }
   11808          101 :       tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11809          101 :       OMP_CLAUSE_DECL (lvc) = last;
   11810          101 :       OMP_CLAUSE_CHAIN (lvc) = clauses;
   11811          101 :       clauses = lvc;
   11812          101 :       diffvar = create_temporary_var (TREE_TYPE (diff));
   11813          101 :       pushdecl (diffvar);
   11814          101 :       add_decl_expr (diffvar);
   11815              :     }
   11816          661 :   else if (code == OMP_LOOP)
   11817              :     {
   11818           43 :       if (!loop_iv_seen)
   11819              :         {
   11820              :           /* While iterators on the loop construct are predetermined
   11821              :              lastprivate, if the decl is not declared inside of the
   11822              :              loop, OMP_CLAUSE_LASTPRIVATE should have been added
   11823              :              already.  */
   11824           16 :           loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11825           16 :           OMP_CLAUSE_DECL (loop_iv_seen) = iter;
   11826           16 :           OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
   11827           16 :           clauses = loop_iv_seen;
   11828              :         }
   11829           27 :       else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
   11830              :         {
   11831            5 :           OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
   11832            5 :           OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
   11833            5 :           OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
   11834              :         }
   11835           43 :       if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
   11836           21 :         cxx_omp_finish_clause (loop_iv_seen, NULL, false);
   11837              :     }
   11838              : 
   11839          762 :   orig_pre_body = *pre_body;
   11840          762 :   *pre_body = push_stmt_list ();
   11841          762 :   if (orig_pre_body)
   11842          610 :     add_stmt (orig_pre_body);
   11843          762 :   if (init != NULL)
   11844           61 :     finish_expr_stmt (build_x_modify_expr (elocus,
   11845              :                                            iter, NOP_EXPR, init,
   11846              :                                            NULL_TREE, tf_warning_or_error));
   11847          762 :   init = build_int_cst (TREE_TYPE (diff), 0);
   11848          762 :   if (c && iter_incr == NULL
   11849           28 :       && (!ordered || (i < collapse && collapse > 1)))
   11850              :     {
   11851           28 :       if (incr_var)
   11852              :         {
   11853           10 :           finish_expr_stmt (build_x_modify_expr (elocus,
   11854              :                                                  incr_var, NOP_EXPR,
   11855              :                                                  incr, NULL_TREE,
   11856              :                                                  tf_warning_or_error));
   11857           10 :           incr = incr_var;
   11858              :         }
   11859           28 :       iter_incr = build_x_modify_expr (elocus,
   11860              :                                        iter, PLUS_EXPR, incr,
   11861              :                                        NULL_TREE, tf_warning_or_error);
   11862              :     }
   11863          762 :   if (c && ordered && i < collapse && collapse > 1)
   11864          762 :     iter_incr = incr;
   11865          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11866              :                                          last, NOP_EXPR, init,
   11867              :                                          NULL_TREE, tf_warning_or_error));
   11868          762 :   if (diffvar)
   11869              :     {
   11870          101 :       finish_expr_stmt (build_x_modify_expr (elocus,
   11871              :                                              diffvar, NOP_EXPR,
   11872              :                                              diff, NULL_TREE, tf_warning_or_error));
   11873          101 :       diff = diffvar;
   11874              :     }
   11875          762 :   *pre_body = pop_stmt_list (*pre_body);
   11876              : 
   11877         1524 :   cond = cp_build_binary_op (elocus,
   11878          762 :                              TREE_CODE (cond), decl, diff,
   11879              :                              tf_warning_or_error);
   11880          762 :   incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
   11881              :                             elocus, incr, NULL_TREE);
   11882              : 
   11883          762 :   orig_body = *body;
   11884          762 :   *body = push_stmt_list ();
   11885          762 :   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
   11886          762 :   iter_init = build_x_modify_expr (elocus,
   11887              :                                    iter, PLUS_EXPR, iter_init,
   11888              :                                    NULL_TREE, tf_warning_or_error);
   11889          762 :   if (iter_init != error_mark_node)
   11890          759 :     iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11891          762 :   finish_expr_stmt (iter_init);
   11892          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11893              :                                          last, NOP_EXPR, decl,
   11894              :                                          NULL_TREE, tf_warning_or_error));
   11895          762 :   add_stmt (orig_body);
   11896          762 :   *body = pop_stmt_list (*body);
   11897              : 
   11898          762 :   if (c)
   11899              :     {
   11900          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
   11901          120 :       if (!ordered)
   11902          114 :         finish_expr_stmt (iter_incr);
   11903              :       else
   11904              :         {
   11905            6 :           iter_init = decl;
   11906            6 :           if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
   11907            2 :             iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
   11908              :                                 iter_init, iter_incr);
   11909            6 :           iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
   11910            6 :           iter_init = build_x_modify_expr (elocus,
   11911              :                                            iter, PLUS_EXPR, iter_init,
   11912              :                                            NULL_TREE, tf_warning_or_error);
   11913            6 :           if (iter_init != error_mark_node)
   11914            6 :             iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11915            6 :           finish_expr_stmt (iter_init);
   11916              :         }
   11917          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c)
   11918          240 :         = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
   11919              :     }
   11920              : 
   11921          762 :   if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
   11922              :     {
   11923          116 :       tree t = TREE_VEC_ELT (orig_declv, i);
   11924          116 :       gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   11925              :                   && TREE_VALUE (t) == NULL_TREE
   11926              :                   && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
   11927          116 :       TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
   11928          116 :       TREE_VALUE (t) = last;
   11929              :     }
   11930              :   else
   11931          646 :     TREE_VEC_ELT (orig_declv, i)
   11932         1292 :       = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   11933          762 :   TREE_VEC_ELT (declv, i) = decl;
   11934          762 :   TREE_VEC_ELT (initv, i) = init;
   11935          762 :   TREE_VEC_ELT (condv, i) = cond;
   11936          762 :   TREE_VEC_ELT (incrv, i) = incr;
   11937              : 
   11938          762 :   return false;
   11939              : }
   11940              : 
   11941              : /* Build and validate an OMP_FOR statement.  CLAUSES, BODY, COND, INCR
   11942              :    are directly for their associated operands in the statement.  DECL
   11943              :    and INIT are a combo; if DECL is NULL then INIT ought to be a
   11944              :    MODIFY_EXPR, and the DECL should be extracted.  PRE_BODY are
   11945              :    optional statements that need to go before the loop into its
   11946              :    sk_omp scope.  */
   11947              : 
   11948              : tree
   11949        21128 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
   11950              :                 tree orig_declv, tree initv, tree condv, tree incrv,
   11951              :                 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
   11952              : {
   11953        21128 :   tree omp_for = NULL, orig_incr = NULL;
   11954        21128 :   tree decl = NULL, init, cond, incr;
   11955        21128 :   location_t elocus;
   11956        21128 :   int i;
   11957        21128 :   int collapse = 1;
   11958        21128 :   int ordered = 0;
   11959        21128 :   auto_vec<location_t> init_locv;
   11960              : 
   11961        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
   11962        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
   11963        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
   11964        21128 :   if (TREE_VEC_LENGTH (declv) > 1)
   11965              :     {
   11966         4054 :       if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
   11967           83 :         collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
   11968              :       else
   11969              :         {
   11970         3971 :           if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
   11971         3501 :             collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
   11972          470 :           else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
   11973          394 :             collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
   11974         3971 :           if (collapse != TREE_VEC_LENGTH (declv))
   11975          100 :             ordered = TREE_VEC_LENGTH (declv);
   11976              :         }
   11977              :     }
   11978        48601 :   for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   11979              :     {
   11980        27509 :       decl = TREE_VEC_ELT (declv, i);
   11981        27509 :       init = TREE_VEC_ELT (initv, i);
   11982        27509 :       cond = TREE_VEC_ELT (condv, i);
   11983        27509 :       incr = TREE_VEC_ELT (incrv, i);
   11984        27509 :       elocus = locus;
   11985              : 
   11986        27509 :       if (decl == global_namespace)
   11987              :         {
   11988         1101 :           gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
   11989         1101 :           TREE_VEC_ELT (declv, i) = NULL_TREE;
   11990         1101 :           init_locv.safe_push (UNKNOWN_LOCATION);
   11991         1101 :           continue;
   11992              :         }
   11993              :       /* We are going to throw out the init's original MODIFY_EXPR or
   11994              :          MODOP_EXPR below.  Save its location so we can use it when
   11995              :          reconstructing the expression farther down.  Alternatively, if the
   11996              :          initializer is a binding of the iteration variable, save
   11997              :          that location.  Any of these locations in the initialization clause
   11998              :          for the current nested loop are better than using the argument locus,
   11999              :          that points to the "for" of the outermost loop in the nest.  */
   12000        26408 :       if (init && EXPR_HAS_LOCATION (init))
   12001        17872 :         elocus = EXPR_LOCATION (init);
   12002         8536 :       else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
   12003              :         /* This can happen for class iterators.  */
   12004            0 :         elocus = EXPR_LOCATION (decl);
   12005         8536 :       else if (decl && DECL_P (decl))
   12006              :         {
   12007         8509 :           if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
   12008         8509 :             elocus = DECL_SOURCE_LOCATION (decl);
   12009            0 :           else if (DECL_INITIAL (decl)
   12010            0 :                    && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
   12011            0 :             elocus = EXPR_LOCATION (DECL_INITIAL (decl));
   12012              :         }
   12013        26408 :       init_locv.safe_push (elocus);
   12014              : 
   12015        26408 :       if (decl == NULL)
   12016              :         {
   12017        16564 :           if (init != NULL)
   12018        16561 :             switch (TREE_CODE (init))
   12019              :               {
   12020        16176 :               case MODIFY_EXPR:
   12021        16176 :                 decl = TREE_OPERAND (init, 0);
   12022        16176 :                 init = TREE_OPERAND (init, 1);
   12023        16176 :                 break;
   12024          367 :               case MODOP_EXPR:
   12025          367 :                 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
   12026              :                   {
   12027          367 :                     decl = TREE_OPERAND (init, 0);
   12028          367 :                     init = TREE_OPERAND (init, 2);
   12029              :                   }
   12030              :                 break;
   12031              :               default:
   12032              :                 break;
   12033              :               }
   12034              : 
   12035        16564 :           if (decl == NULL)
   12036              :             {
   12037           21 :               error_at (locus,
   12038              :                         "expected iteration declaration or initialization");
   12039           21 :               return NULL;
   12040              :             }
   12041              :         }
   12042              : 
   12043        26387 :       if (cond == global_namespace)
   12044          170 :         continue;
   12045              : 
   12046        26217 :       if (cond == NULL)
   12047              :         {
   12048            9 :           error_at (elocus, "missing controlling predicate");
   12049            9 :           return NULL;
   12050              :         }
   12051              : 
   12052        26208 :       if (incr == NULL)
   12053              :         {
   12054            6 :           error_at (elocus, "missing increment expression");
   12055            6 :           return NULL;
   12056              :         }
   12057              : 
   12058        26202 :       TREE_VEC_ELT (declv, i) = decl;
   12059        26202 :       TREE_VEC_ELT (initv, i) = init;
   12060              :     }
   12061              : 
   12062        21092 :   if (orig_inits)
   12063              :     {
   12064              :       bool fail = false;
   12065              :       tree orig_init;
   12066        21214 :       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
   12067         1181 :         if (orig_init
   12068         3396 :             && !c_omp_check_loop_iv_exprs (locus, code,
   12069              :                                            orig_declv ? orig_declv : declv, i,
   12070         1164 :                                            TREE_VEC_ELT (declv, i), orig_init,
   12071              :                                            NULL_TREE, cp_walk_subtrees))
   12072              :           fail = true;
   12073        20033 :       if (fail)
   12074          887 :         return NULL;
   12075              :     }
   12076              : 
   12077        21035 :   if (dependent_omp_for_p (declv, initv, condv, incrv, body))
   12078              :     {
   12079          453 :       tree stmt;
   12080              : 
   12081          453 :       stmt = make_node (code);
   12082              : 
   12083         1499 :       for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   12084              :         {
   12085          593 :           if (TREE_VEC_ELT (declv, i) == NULL_TREE)
   12086            9 :             continue;
   12087              :           /* This is really just a place-holder.  We'll be decomposing this
   12088              :              again and going through the cp_build_modify_expr path below when
   12089              :              we instantiate the thing.  */
   12090          584 :           TREE_VEC_ELT (initv, i)
   12091         1168 :             = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
   12092          584 :                           TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
   12093              :         }
   12094              : 
   12095          453 :       TREE_TYPE (stmt) = void_type_node;
   12096          453 :       OMP_FOR_INIT (stmt) = initv;
   12097          453 :       OMP_FOR_COND (stmt) = condv;
   12098          453 :       OMP_FOR_INCR (stmt) = incrv;
   12099          453 :       OMP_FOR_BODY (stmt) = body;
   12100          453 :       OMP_FOR_PRE_BODY (stmt) = pre_body;
   12101          453 :       OMP_FOR_CLAUSES (stmt) = clauses;
   12102              : 
   12103          453 :       SET_EXPR_LOCATION (stmt, locus);
   12104          453 :       return add_stmt (stmt);
   12105              :     }
   12106              : 
   12107        20582 :   if (!orig_declv)
   12108        19795 :     orig_declv = copy_node (declv);
   12109              : 
   12110        20582 :   if (processing_template_decl)
   12111          612 :     orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
   12112              : 
   12113        48030 :   for (i = 0; i < TREE_VEC_LENGTH (declv); )
   12114              :     {
   12115        27540 :       decl = TREE_VEC_ELT (declv, i);
   12116        27540 :       init = TREE_VEC_ELT (initv, i);
   12117        27540 :       cond = TREE_VEC_ELT (condv, i);
   12118        27540 :       incr = TREE_VEC_ELT (incrv, i);
   12119        27540 :       if (orig_incr)
   12120          844 :         TREE_VEC_ELT (orig_incr, i) = incr;
   12121        27540 :       elocus = init_locv[i];
   12122              : 
   12123        27540 :       if (decl == NULL_TREE)
   12124              :         {
   12125         1092 :           i++;
   12126         1092 :           continue;
   12127              :         }
   12128              : 
   12129        26448 :       if (!DECL_P (decl))
   12130              :         {
   12131            6 :           error_at (elocus, "expected iteration declaration or initialization");
   12132            6 :           return NULL;
   12133              :         }
   12134              : 
   12135        26442 :       if (incr && TREE_CODE (incr) == MODOP_EXPR)
   12136              :         {
   12137            1 :           if (orig_incr)
   12138            1 :             TREE_VEC_ELT (orig_incr, i) = incr;
   12139            1 :           incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
   12140            1 :                                        TREE_CODE (TREE_OPERAND (incr, 1)),
   12141            1 :                                        TREE_OPERAND (incr, 2),
   12142              :                                        tf_warning_or_error);
   12143              :         }
   12144              : 
   12145        26442 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
   12146              :         {
   12147          825 :           if (code == OMP_SIMD)
   12148              :             {
   12149           12 :               error_at (elocus, "%<#pragma omp simd%> used with class "
   12150              :                                 "iteration variable %qE", decl);
   12151           12 :               return NULL;
   12152              :             }
   12153          813 :           if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
   12154              :                                              initv, condv, incrv, &body,
   12155              :                                              &pre_body, clauses,
   12156              :                                              collapse, ordered))
   12157              :             return NULL;
   12158          762 :           continue;
   12159              :         }
   12160              : 
   12161        51234 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
   12162        27203 :           && !TYPE_PTR_P (TREE_TYPE (decl)))
   12163              :         {
   12164           14 :           error_at (elocus, "invalid type for iteration variable %qE", decl);
   12165           14 :           return NULL;
   12166              :         }
   12167              : 
   12168        25603 :       if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
   12169        24842 :         init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
   12170              :                                      tf_warning_or_error);
   12171              :       else
   12172          761 :         init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
   12173        25603 :       if (decl == error_mark_node || init == error_mark_node)
   12174              :         return NULL;
   12175              : 
   12176        25594 :       TREE_VEC_ELT (declv, i) = decl;
   12177        25594 :       TREE_VEC_ELT (initv, i) = init;
   12178        25594 :       TREE_VEC_ELT (condv, i) = cond;
   12179        25594 :       TREE_VEC_ELT (incrv, i) = incr;
   12180        25594 :       i++;
   12181              :     }
   12182              : 
   12183        20490 :   if (pre_body && IS_EMPTY_STMT (pre_body))
   12184            0 :     pre_body = NULL;
   12185              : 
   12186        40980 :   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
   12187              :                               incrv, body, pre_body,
   12188        20490 :                               !processing_template_decl);
   12189              : 
   12190              :   /* Check for iterators appearing in lb, b or incr expressions.  */
   12191        20490 :   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
   12192              :     omp_for = NULL_TREE;
   12193              : 
   12194        20004 :   if (omp_for == NULL)
   12195          702 :     return NULL;
   12196              : 
   12197        19788 :   add_stmt (omp_for);
   12198              : 
   12199        45448 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
   12200              :     {
   12201        25660 :       init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
   12202        25660 :       if (init == NULL_TREE)
   12203         1032 :         continue;
   12204        24628 :       decl = TREE_OPERAND (init, 0);
   12205        24628 :       cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
   12206        24628 :       incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
   12207              : 
   12208        24628 :       if (!processing_template_decl)
   12209              :         {
   12210        24107 :           if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
   12211              :             {
   12212          106 :               tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
   12213          106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
   12214          106 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12215          106 :               t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
   12216          106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
   12217          212 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12218              :             }
   12219              :           else
   12220              :             {
   12221        24001 :               tree t = TREE_OPERAND (init, 1);
   12222        24001 :               TREE_OPERAND (init, 1)
   12223        48002 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12224              :             }
   12225        24107 :           if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
   12226              :             {
   12227          121 :               tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
   12228          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
   12229          121 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12230          121 :               t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
   12231          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
   12232          242 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12233              :             }
   12234              :           else
   12235              :             {
   12236        23986 :               tree t = TREE_OPERAND (cond, 1);
   12237        23986 :               TREE_OPERAND (cond, 1)
   12238        47972 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12239              :             }
   12240              :         }
   12241              : 
   12242        24628 :       if (TREE_CODE (incr) != MODIFY_EXPR)
   12243        18426 :         continue;
   12244              : 
   12245         6202 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
   12246           70 :           && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
   12247         6272 :           && !processing_template_decl)
   12248              :         {
   12249           64 :           tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
   12250           64 :           if (TREE_SIDE_EFFECTS (t)
   12251            8 :               && t != decl
   12252           70 :               && (TREE_CODE (t) != NOP_EXPR
   12253            0 :                   || TREE_OPERAND (t, 0) != decl))
   12254            6 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
   12255           12 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12256              : 
   12257           64 :           t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
   12258           64 :           if (TREE_SIDE_EFFECTS (t)
   12259           56 :               && t != decl
   12260          120 :               && (TREE_CODE (t) != NOP_EXPR
   12261            5 :                   || TREE_OPERAND (t, 0) != decl))
   12262           56 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
   12263          112 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12264              :         }
   12265              : 
   12266         6202 :       if (orig_incr)
   12267          177 :         TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
   12268              :     }
   12269        19788 :   OMP_FOR_CLAUSES (omp_for) = clauses;
   12270              : 
   12271              :   /* For simd loops with non-static data member iterators, we could have added
   12272              :      OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP.  As we know the
   12273              :      step at this point, fill it in.  */
   12274         4735 :   if (code == OMP_SIMD && !processing_template_decl
   12275        24479 :       && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
   12276         4619 :     for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
   12277          561 :          c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
   12278          561 :       if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
   12279              :         {
   12280            4 :           decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
   12281            4 :           gcc_assert (decl == OMP_CLAUSE_DECL (c));
   12282            4 :           incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
   12283            4 :           tree step, stept;
   12284            4 :           switch (TREE_CODE (incr))
   12285              :             {
   12286            0 :             case PREINCREMENT_EXPR:
   12287            0 :             case POSTINCREMENT_EXPR:
   12288              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12289              :                  called to massage things appropriately.  */
   12290            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12291            0 :               OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
   12292            0 :               break;
   12293            0 :             case PREDECREMENT_EXPR:
   12294            0 :             case POSTDECREMENT_EXPR:
   12295              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12296              :                  called to massage things appropriately.  */
   12297            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12298            0 :               OMP_CLAUSE_LINEAR_STEP (c)
   12299            0 :                 = build_int_cst (TREE_TYPE (decl), -1);
   12300            0 :               break;
   12301            4 :             case MODIFY_EXPR:
   12302            4 :               gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12303            4 :               incr = TREE_OPERAND (incr, 1);
   12304            4 :               switch (TREE_CODE (incr))
   12305              :                 {
   12306            4 :                 case PLUS_EXPR:
   12307            4 :                   if (TREE_OPERAND (incr, 1) == decl)
   12308            0 :                     step = TREE_OPERAND (incr, 0);
   12309              :                   else
   12310            4 :                     step = TREE_OPERAND (incr, 1);
   12311              :                   break;
   12312            0 :                 case MINUS_EXPR:
   12313            0 :                 case POINTER_PLUS_EXPR:
   12314            0 :                   gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12315            0 :                   step = TREE_OPERAND (incr, 1);
   12316            0 :                   break;
   12317            0 :                 default:
   12318            0 :                   gcc_unreachable ();
   12319              :                 }
   12320            4 :               stept = TREE_TYPE (decl);
   12321            4 :               if (INDIRECT_TYPE_P (stept))
   12322            0 :                 stept = sizetype;
   12323            4 :               step = fold_convert (stept, step);
   12324            4 :               if (TREE_CODE (incr) == MINUS_EXPR)
   12325            0 :                 step = fold_build1 (NEGATE_EXPR, stept, step);
   12326            4 :               OMP_CLAUSE_LINEAR_STEP (c) = step;
   12327            4 :               break;
   12328            0 :             default:
   12329            0 :               gcc_unreachable ();
   12330              :             }
   12331              :         }
   12332              :   /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
   12333              :      clauses, we need copy ctor for those rather than default ctor,
   12334              :      plus as for other lastprivates assignment op and dtor.  */
   12335        19788 :   if (code == OMP_LOOP && !processing_template_decl)
   12336         1993 :     for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   12337         1285 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   12338          204 :           && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
   12339         1307 :           && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
   12340              :                                          false, true, true, true))
   12341            0 :         CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
   12342              : 
   12343              :   return omp_for;
   12344        21128 : }
   12345              : 
   12346              : /* Code walker for finish_omp_for_block: extract binding of DP->var
   12347              :    from its current block and move it to a new BIND_EXPR DP->b
   12348              :    surrounding the body of DP->omp_for.  */
   12349              : 
   12350              : struct fofb_data {
   12351              :   tree var;
   12352              :   tree b;
   12353              :   tree omp_for;
   12354              : };
   12355              : 
   12356              : static tree
   12357          389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
   12358              : {
   12359          389 :   struct fofb_data *fofb = (struct fofb_data *)dp;
   12360          389 :   if (TREE_CODE (*tp) == BIND_EXPR)
   12361          578 :     for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
   12362              :       {
   12363          576 :         if (*p == fofb->var)
   12364              :           {
   12365          363 :             *p = DECL_CHAIN (*p);
   12366          363 :             if (fofb->b == NULL_TREE)
   12367              :               {
   12368          214 :                 fofb->b = make_node (BLOCK);
   12369          214 :                 fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   12370          214 :                             OMP_FOR_BODY (fofb->omp_for), fofb->b);
   12371          214 :                 TREE_SIDE_EFFECTS (fofb->b) = 1;
   12372          214 :                 OMP_FOR_BODY (fofb->omp_for) = fofb->b;
   12373              :               }
   12374          363 :             DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
   12375          363 :             BIND_EXPR_VARS (fofb->b) = fofb->var;
   12376          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
   12377          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
   12378          363 :             return *tp;
   12379              :           }
   12380              :       }
   12381           26 :   if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
   12382           22 :     *walk_subtrees = false;
   12383              :   return NULL_TREE;
   12384              : }
   12385              : 
   12386              : /* Fix up range for decls.  Those decls were pushed into BIND's
   12387              :    BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
   12388              :    and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
   12389              :    so that processing of combined loop directives can find them.  */
   12390              : tree
   12391        14525 : finish_omp_for_block (tree bind, tree omp_for)
   12392              : {
   12393        14525 :   if (omp_for == NULL_TREE
   12394        14478 :       || !OMP_FOR_ORIG_DECLS (omp_for)
   12395        28435 :       || bind == NULL_TREE)
   12396          615 :     return bind;
   12397        13910 :   struct fofb_data fofb;
   12398        13910 :   fofb.b = NULL_TREE;
   12399        13910 :   fofb.omp_for = omp_for;
   12400        33347 :   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
   12401        19437 :     if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
   12402        19215 :         && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
   12403              :             == TREE_LIST)
   12404        20268 :         && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
   12405              :       {
   12406          237 :         tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
   12407          602 :         for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
   12408              :           {
   12409          365 :             fofb.var = TREE_VEC_ELT (v, j);
   12410          365 :             cp_walk_tree (&bind, finish_omp_for_block_walker,
   12411              :                           (void *)&fofb, NULL);
   12412              :           }
   12413              :       }
   12414        13910 :   return bind;
   12415              : }
   12416              : 
   12417              : void
   12418         3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
   12419              :                    tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
   12420              :                    tree clauses, enum omp_memory_order mo, bool weak)
   12421              : {
   12422         3342 :   tree orig_lhs;
   12423         3342 :   tree orig_rhs;
   12424         3342 :   tree orig_v;
   12425         3342 :   tree orig_lhs1;
   12426         3342 :   tree orig_rhs1;
   12427         3342 :   tree orig_r;
   12428         3342 :   bool dependent_p;
   12429         3342 :   tree stmt;
   12430              : 
   12431         3342 :   orig_lhs = lhs;
   12432         3342 :   orig_rhs = rhs;
   12433         3342 :   orig_v = v;
   12434         3342 :   orig_lhs1 = lhs1;
   12435         3342 :   orig_rhs1 = rhs1;
   12436         3342 :   orig_r = r;
   12437         3342 :   dependent_p = false;
   12438         3342 :   stmt = NULL_TREE;
   12439              : 
   12440              :   /* Even in a template, we can detect invalid uses of the atomic
   12441              :      pragma if neither LHS nor RHS is type-dependent.  */
   12442         3342 :   if (processing_template_decl)
   12443              :     {
   12444          600 :       dependent_p = (type_dependent_expression_p (lhs)
   12445          237 :                      || (rhs && type_dependent_expression_p (rhs))
   12446          234 :                      || (v && type_dependent_expression_p (v))
   12447          234 :                      || (lhs1 && type_dependent_expression_p (lhs1))
   12448          234 :                      || (rhs1 && type_dependent_expression_p (rhs1))
   12449          834 :                      || (r
   12450           25 :                          && r != void_list_node
   12451           16 :                          && type_dependent_expression_p (r)));
   12452          600 :       if (clauses)
   12453              :         {
   12454           30 :           gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
   12455              :                       && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
   12456              :                       && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
   12457           30 :           if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
   12458           30 :               || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
   12459              :             dependent_p = true;
   12460              :         }
   12461              :     }
   12462          576 :   if (!dependent_p)
   12463              :     {
   12464         2958 :       bool swapped = false;
   12465         2958 :       if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
   12466              :         {
   12467          143 :           std::swap (rhs, rhs1);
   12468          143 :           swapped = !commutative_tree_code (opcode);
   12469              :         }
   12470         2958 :       if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
   12471              :         {
   12472            0 :           if (code == OMP_ATOMIC)
   12473            0 :             error ("%<#pragma omp atomic update%> uses two different "
   12474              :                    "expressions for memory");
   12475              :           else
   12476            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12477              :                    "expressions for memory");
   12478            0 :           return;
   12479              :         }
   12480         2958 :       if (lhs1 && !cp_tree_equal (lhs, lhs1))
   12481              :         {
   12482            0 :           if (code == OMP_ATOMIC)
   12483            0 :             error ("%<#pragma omp atomic update%> uses two different "
   12484              :                    "expressions for memory");
   12485              :           else
   12486            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12487              :                    "expressions for memory");
   12488            0 :           return;
   12489              :         }
   12490         5916 :       stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
   12491              :                                   v, lhs1, rhs1, r, swapped, mo, weak,
   12492         2958 :                                   processing_template_decl != 0);
   12493         2958 :       if (stmt == error_mark_node)
   12494              :         return;
   12495              :     }
   12496         3312 :   if (processing_template_decl)
   12497              :     {
   12498          591 :       if (code == OMP_ATOMIC_READ)
   12499              :         {
   12500          167 :           stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
   12501          167 :           OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12502          167 :           stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12503              :         }
   12504              :       else
   12505              :         {
   12506          424 :           if (opcode == NOP_EXPR)
   12507           35 :             stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
   12508          389 :           else if (opcode == COND_EXPR)
   12509              :             {
   12510          124 :               stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
   12511          124 :               if (orig_r)
   12512           50 :                 stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
   12513              :                                stmt);
   12514          124 :               stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
   12515              :                              orig_lhs);
   12516          124 :               orig_rhs1 = NULL_TREE;
   12517              :             }
   12518              :           else
   12519          265 :             stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
   12520          424 :           if (orig_rhs1)
   12521          182 :             stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
   12522              :                                      COMPOUND_EXPR, orig_rhs1, stmt);
   12523          424 :           if (code != OMP_ATOMIC)
   12524              :             {
   12525          233 :               stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
   12526          233 :               OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12527          233 :               OMP_ATOMIC_WEAK (stmt) = weak;
   12528          233 :               stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12529              :             }
   12530              :         }
   12531          591 :       stmt = build2 (OMP_ATOMIC, void_type_node,
   12532              :                      clauses ? clauses : integer_zero_node, stmt);
   12533          591 :       OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12534          591 :       OMP_ATOMIC_WEAK (stmt) = weak;
   12535          591 :       SET_EXPR_LOCATION (stmt, loc);
   12536              :     }
   12537              : 
   12538              :   /* Avoid -Wunused-value warnings here, the whole construct has side-effects
   12539              :      and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
   12540              :      in some tree that appears to be unused, the value is not unused.  */
   12541         3312 :   warning_sentinel w (warn_unused_value);
   12542         3312 :   finish_expr_stmt (stmt);
   12543         3312 : }
   12544              : 
   12545              : void
   12546          359 : finish_omp_barrier (void)
   12547              : {
   12548          359 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
   12549          359 :   releasing_vec vec;
   12550          359 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12551          359 :   finish_expr_stmt (stmt);
   12552          359 : }
   12553              : 
   12554              : void
   12555          397 : finish_omp_depobj (location_t loc, tree depobj,
   12556              :                    enum omp_clause_depend_kind kind, tree clause)
   12557              : {
   12558          397 :   if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
   12559              :     {
   12560          343 :       if (!lvalue_p (depobj))
   12561              :         {
   12562            6 :           error_at (EXPR_LOC_OR_LOC (depobj, loc),
   12563              :                     "%<depobj%> expression is not lvalue expression");
   12564            6 :           depobj = error_mark_node;
   12565              :         }
   12566              :     }
   12567              : 
   12568          397 :   if (processing_template_decl)
   12569              :     {
   12570          114 :       if (clause == NULL_TREE)
   12571           47 :         clause = build_int_cst (integer_type_node, kind);
   12572          114 :       add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
   12573          114 :       return;
   12574              :     }
   12575              : 
   12576          283 :   if (!error_operand_p (depobj))
   12577              :     {
   12578          274 :       tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
   12579          274 :       if (addr == error_mark_node)
   12580              :         depobj = error_mark_node;
   12581              :       else
   12582          274 :         depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
   12583              :                                         tf_warning_or_error);
   12584              :     }
   12585              : 
   12586          283 :   c_finish_omp_depobj (loc, depobj, kind, clause);
   12587              : }
   12588              : 
   12589              : void
   12590          162 : finish_omp_flush (int mo)
   12591              : {
   12592          162 :   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   12593          162 :   releasing_vec vec;
   12594          162 :   if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
   12595              :     {
   12596           54 :       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
   12597           54 :       vec->quick_push (build_int_cst (integer_type_node, mo));
   12598              :     }
   12599          162 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12600          162 :   finish_expr_stmt (stmt);
   12601          162 : }
   12602              : 
   12603              : void
   12604          111 : finish_omp_taskwait (void)
   12605              : {
   12606          111 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
   12607          111 :   releasing_vec vec;
   12608          111 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12609          111 :   finish_expr_stmt (stmt);
   12610          111 : }
   12611              : 
   12612              : void
   12613           16 : finish_omp_taskyield (void)
   12614              : {
   12615           16 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
   12616           16 :   releasing_vec vec;
   12617           16 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12618           16 :   finish_expr_stmt (stmt);
   12619           16 : }
   12620              : 
   12621              : void
   12622          596 : finish_omp_cancel (tree clauses)
   12623              : {
   12624          596 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   12625          596 :   int mask = 0;
   12626          596 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12627              :     mask = 1;
   12628          414 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12629              :     mask = 2;
   12630          285 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12631              :     mask = 4;
   12632          164 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12633              :     mask = 8;
   12634              :   else
   12635              :     {
   12636            0 :       error ("%<#pragma omp cancel%> must specify one of "
   12637              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12638            0 :       return;
   12639              :     }
   12640          596 :   releasing_vec vec;
   12641          596 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   12642          596 :   if (ifc != NULL_TREE)
   12643              :     {
   12644           70 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   12645           70 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   12646            6 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   12647              :                   "expected %<cancel%> %<if%> clause modifier");
   12648              :       else
   12649              :         {
   12650           64 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   12651           64 :           if (ifc2 != NULL_TREE)
   12652              :             {
   12653            3 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   12654              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   12655              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   12656            3 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   12657              :                         "expected %<cancel%> %<if%> clause modifier");
   12658              :             }
   12659              :         }
   12660              : 
   12661           70 :       if (!processing_template_decl)
   12662           61 :         ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
   12663              :       else
   12664            9 :         ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   12665            9 :                                  OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
   12666              :                                  integer_zero_node, ERROR_MARK,
   12667              :                                  NULL_TREE, NULL, tf_warning_or_error);
   12668              :     }
   12669              :   else
   12670          526 :     ifc = boolean_true_node;
   12671          596 :   vec->quick_push (build_int_cst (integer_type_node, mask));
   12672          596 :   vec->quick_push (ifc);
   12673          596 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12674          596 :   finish_expr_stmt (stmt);
   12675          596 : }
   12676              : 
   12677              : void
   12678          494 : finish_omp_cancellation_point (tree clauses)
   12679              : {
   12680          494 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   12681          494 :   int mask = 0;
   12682          494 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12683              :     mask = 1;
   12684          366 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12685              :     mask = 2;
   12686          261 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12687              :     mask = 4;
   12688          156 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12689              :     mask = 8;
   12690              :   else
   12691              :     {
   12692            3 :       error ("%<#pragma omp cancellation point%> must specify one of "
   12693              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12694            3 :       return;
   12695              :     }
   12696          491 :   releasing_vec vec
   12697          491 :     = make_tree_vector_single (build_int_cst (integer_type_node, mask));
   12698          491 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12699          491 :   finish_expr_stmt (stmt);
   12700          491 : }
   12701              : 
   12702              : /* Begin a __transaction_atomic or __transaction_relaxed statement.
   12703              :    If PCOMPOUND is non-null, this is for a function-transaction-block, and we
   12704              :    should create an extra compound stmt.  */
   12705              : 
   12706              : tree
   12707          303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
   12708              : {
   12709          303 :   tree r;
   12710              : 
   12711          303 :   if (pcompound)
   12712           21 :     *pcompound = begin_compound_stmt (0);
   12713              : 
   12714          303 :   r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
   12715              : 
   12716              :   /* Only add the statement to the function if support enabled.  */
   12717          303 :   if (flag_tm)
   12718          297 :     add_stmt (r);
   12719              :   else
   12720           12 :     error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
   12721              :                     ? G_("%<__transaction_relaxed%> without "
   12722              :                          "transactional memory support enabled")
   12723              :                     : G_("%<__transaction_atomic%> without "
   12724              :                          "transactional memory support enabled")));
   12725              : 
   12726          303 :   TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
   12727          303 :   TREE_SIDE_EFFECTS (r) = 1;
   12728          303 :   return r;
   12729              : }
   12730              : 
   12731              : /* End a __transaction_atomic or __transaction_relaxed statement.
   12732              :    If COMPOUND_STMT is non-null, this is for a function-transaction-block,
   12733              :    and we should end the compound.  If NOEX is non-NULL, we wrap the body in
   12734              :    a MUST_NOT_THROW_EXPR with NOEX as condition.  */
   12735              : 
   12736              : void
   12737          303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
   12738              : {
   12739          303 :   TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
   12740          303 :   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   12741          303 :   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
   12742          303 :   TRANSACTION_EXPR_IS_STMT (stmt) = 1;
   12743              : 
   12744              :   /* noexcept specifications are not allowed for function transactions.  */
   12745          303 :   gcc_assert (!(noex && compound_stmt));
   12746          303 :   if (noex)
   12747              :     {
   12748           51 :       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
   12749              :                                              noex);
   12750           51 :       protected_set_expr_location
   12751           51 :         (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
   12752           51 :       TREE_SIDE_EFFECTS (body) = 1;
   12753           51 :       TRANSACTION_EXPR_BODY (stmt) = body;
   12754              :     }
   12755              : 
   12756          303 :   if (compound_stmt)
   12757           21 :     finish_compound_stmt (compound_stmt);
   12758          303 : }
   12759              : 
   12760              : /* Build a __transaction_atomic or __transaction_relaxed expression.  If
   12761              :    NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
   12762              :    condition.  */
   12763              : 
   12764              : tree
   12765          116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
   12766              : {
   12767          116 :   tree ret;
   12768          116 :   if (noex)
   12769              :     {
   12770           57 :       expr = build_must_not_throw_expr (expr, noex);
   12771           57 :       protected_set_expr_location (expr, loc);
   12772           57 :       TREE_SIDE_EFFECTS (expr) = 1;
   12773              :     }
   12774          116 :   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
   12775          116 :   if (flags & TM_STMT_ATTR_RELAXED)
   12776            4 :         TRANSACTION_EXPR_RELAXED (ret) = 1;
   12777          116 :   TREE_SIDE_EFFECTS (ret) = 1;
   12778          116 :   SET_EXPR_LOCATION (ret, loc);
   12779          116 :   return ret;
   12780              : }
   12781              : 
   12782              : void
   12783        99679 : init_cp_semantics (void)
   12784              : {
   12785        99679 : }
   12786              : 
   12787              : 
   12788              : /* Get constant string at LOCATION. Returns true if successful,
   12789              :    otherwise false.  */
   12790              : 
   12791              : bool
   12792     10696832 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
   12793              : {
   12794     10696832 :   tsubst_flags_t complain = tf_warning_or_error;
   12795              : 
   12796     10696832 :   if (message == NULL_TREE
   12797     10696832 :       || message == error_mark_node
   12798     21393661 :       || check_for_bare_parameter_packs (message))
   12799            3 :     return false;
   12800              : 
   12801     10696829 :   if (TREE_CODE (message) != STRING_CST
   12802     10696829 :       && !type_dependent_expression_p (message))
   12803              :     {
   12804         1053 :       message_sz
   12805         1053 :         = finish_class_member_access_expr (message,
   12806              :                                            get_identifier ("size"),
   12807              :                                            false, complain);
   12808         1053 :       if (message_sz != error_mark_node)
   12809          952 :         message_data
   12810          952 :           = finish_class_member_access_expr (message,
   12811              :                                              get_identifier ("data"),
   12812              :                                              false, complain);
   12813         1053 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12814              :         {
   12815          139 :           error_at (location, "constexpr string must be a string "
   12816              :                     "literal or object with %<size%> and "
   12817              :                     "%<data%> members");
   12818          322 :           return false;
   12819              :         }
   12820          914 :       releasing_vec size_args, data_args;
   12821          914 :       message_sz = finish_call_expr (message_sz, &size_args, false, false,
   12822              :                                      complain);
   12823          914 :       message_data = finish_call_expr (message_data, &data_args, false, false,
   12824              :                                        complain);
   12825          914 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12826              :         return false;
   12827          800 :       message_sz = build_converted_constant_expr (size_type_node, message_sz,
   12828              :                                                   complain);
   12829          800 :       if (message_sz == error_mark_node)
   12830              :         {
   12831           15 :           error_at (location, "constexpr string %<size()%> "
   12832              :                     "must be implicitly convertible to "
   12833              :                     "%<std::size_t%>");
   12834           15 :           return false;
   12835              :         }
   12836              : 
   12837          785 :       if (allow_char8_t
   12838           74 :           && POINTER_TYPE_P (TREE_TYPE (message_data))
   12839           74 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   12840           74 :               == char8_type_node)
   12841          805 :           && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
   12842              :               == TYPE_QUAL_CONST))
   12843              :         return true;
   12844              : 
   12845          765 :       message_data = build_converted_constant_expr (const_string_type_node,
   12846              :                                                     message_data, complain);
   12847          765 :       if (message_data == error_mark_node)
   12848              :         {
   12849           34 :           error_at (location, "constexpr string %<data()%> "
   12850              :                     "must be implicitly convertible to "
   12851              :                     "%<const char*%>");
   12852           34 :           return false;
   12853              :         }
   12854          914 :     }
   12855              :   return true;
   12856              : }
   12857              : 
   12858              : /* Extract constant string at LOCATON into output string STR.
   12859              :    Returns true if successful, otherwise false.  */
   12860              : 
   12861              : bool
   12862          405 : cexpr_str::extract (location_t location, tree &str)
   12863              : {
   12864          405 :   const char *msg;
   12865          405 :   int len;
   12866          405 :   if (!extract (location, msg, len))
   12867              :     return false;
   12868          343 :   str = build_string (len, msg);
   12869          343 :   return true;
   12870              : }
   12871              : 
   12872              : /* Extract constant string at LOCATION into output string MSG with LEN.
   12873              :    Returns true if successful, otherwise false.  */
   12874              : 
   12875              : bool
   12876         2391 : cexpr_str::extract (location_t location, const char * &msg, int &len,
   12877              :                     const constexpr_ctx *ctx /* = NULL */,
   12878              :                     bool *non_constant_p /* = NULL */,
   12879              :                     bool *overflow_p /* = NULL */,
   12880              :                     tree *jump_target /* = NULL */)
   12881              : {
   12882         2391 :   tsubst_flags_t complain = tf_warning_or_error;
   12883              : 
   12884         2391 :   msg = NULL;
   12885         2391 :   if (message_sz && message_data)
   12886              :     {
   12887          677 :       tree msz;
   12888          677 :       if (ctx)
   12889              :         {
   12890          110 :           msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
   12891              :                                               non_constant_p, overflow_p,
   12892              :                                               jump_target);
   12893          110 :           if (*jump_target || *non_constant_p)
   12894              :             return false;
   12895              :         }
   12896              :       else
   12897          567 :         msz = cxx_constant_value (message_sz, NULL_TREE, complain);
   12898          669 :       if (!tree_fits_uhwi_p (msz))
   12899              :         {
   12900           35 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   12901           35 :             error_at (location,
   12902              :                       "constexpr string %<size()%> "
   12903              :                       "must be a constant expression");
   12904           35 :           return false;
   12905              :         }
   12906          634 :       else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
   12907              :                != tree_to_uhwi (msz))
   12908              :         {
   12909            0 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   12910            0 :             error_at (location,
   12911              :                       "constexpr string message %<size()%> "
   12912              :                       "%qE too large", msz);
   12913            0 :           return false;
   12914              :         }
   12915          634 :       len = tree_to_uhwi (msz);
   12916          634 :       tree data;
   12917          634 :       if (ctx)
   12918              :         {
   12919          102 :           data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
   12920              :                                                non_constant_p, overflow_p,
   12921              :                                                jump_target);
   12922          102 :           if (*jump_target || *non_constant_p)
   12923              :             return false;
   12924           94 :           STRIP_NOPS (data);
   12925           94 :           if (TREE_CODE (data) != ADDR_EXPR)
   12926              :             {
   12927            0 :             unhandled:
   12928            0 :               if (!cxx_constexpr_quiet_p (ctx))
   12929            0 :                 error_at (location, "unhandled return from %<data()%>");
   12930            0 :               return false;
   12931              :             }
   12932           94 :           tree str = TREE_OPERAND (data, 0);
   12933           94 :           unsigned HOST_WIDE_INT off = 0;
   12934           94 :           if (TREE_CODE (str) == ARRAY_REF
   12935           94 :               && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
   12936              :             {
   12937           12 :               off = tree_to_uhwi (TREE_OPERAND (str, 1));
   12938           12 :               str = TREE_OPERAND (str, 0);
   12939              :             }
   12940           94 :           str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
   12941              :                                               non_constant_p, overflow_p,
   12942              :                                               jump_target);
   12943           94 :           if (*jump_target || *non_constant_p)
   12944              :             return false;
   12945           94 :           if (TREE_CODE (str) == STRING_CST)
   12946              :             {
   12947           84 :               if (TREE_STRING_LENGTH (str) < len
   12948           84 :                   || (unsigned) TREE_STRING_LENGTH (str) < off
   12949          168 :                   || (unsigned) TREE_STRING_LENGTH (str) < off + len)
   12950            0 :                 goto unhandled;
   12951           84 :               msg = TREE_STRING_POINTER (str) + off;
   12952           84 :               goto translate;
   12953              :             }
   12954           10 :           if (TREE_CODE (str) != CONSTRUCTOR
   12955           10 :               || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
   12956            0 :             goto unhandled;
   12957           10 :           char *b;
   12958           10 :           if (len < 64)
   12959           10 :             b = XALLOCAVEC (char, len + 1);
   12960              :           else
   12961              :             {
   12962            0 :               buf = XNEWVEC (char, len + 1);
   12963            0 :               b = buf;
   12964              :             }
   12965           10 :           msg = b;
   12966           10 :           memset (b, 0, len + 1);
   12967           10 :           tree field, value;
   12968           10 :           unsigned k;
   12969           10 :           unsigned HOST_WIDE_INT l = 0;
   12970          158 :           FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
   12971          158 :             if (!tree_fits_shwi_p (value))
   12972            0 :               goto unhandled;
   12973          158 :             else if (field == NULL_TREE)
   12974              :               {
   12975            0 :                 if (integer_zerop (value))
   12976              :                   break;
   12977            0 :                 if (l >= off && l < off + len)
   12978            0 :                   b[l - off] = tree_to_shwi (value);
   12979            0 :                 ++l;
   12980              :               }
   12981          158 :             else if (TREE_CODE (field) == RANGE_EXPR)
   12982              :               {
   12983            0 :                 tree lo = TREE_OPERAND (field, 0);
   12984            0 :                 tree hi = TREE_OPERAND (field, 1);
   12985            0 :                 if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
   12986            0 :                   goto unhandled;
   12987            0 :                 if (integer_zerop (value))
   12988              :                   break;
   12989            0 :                 unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
   12990            0 :                 for (l = tree_to_uhwi (lo); l <= m; ++l)
   12991            0 :                   if (l >= off && l < off + len)
   12992            0 :                     b[l - off] = tree_to_shwi (value);
   12993              :               }
   12994          158 :             else if (tree_fits_uhwi_p (field))
   12995              :               {
   12996          158 :                 l = tree_to_uhwi (field);
   12997          158 :                 if (integer_zerop (value))
   12998              :                   break;
   12999          148 :                 if (l >= off && l < off + len)
   13000          148 :                   b[l - off] = tree_to_shwi (value);
   13001          148 :                 l++;
   13002              :               }
   13003           10 :           b[len] = '\0';
   13004              :         }
   13005              :       else
   13006              :         {
   13007          532 :           data = maybe_constant_value (message_data, NULL_TREE, mce_true);
   13008          532 :           if (!reduced_constant_expression_p (data))
   13009           96 :             data = NULL_TREE;
   13010          532 :           if (len)
   13011              :             {
   13012          455 :               if (data)
   13013          381 :                 msg = c_getstr (data);
   13014          455 :               if (msg == NULL)
   13015          119 :                 buf = XNEWVEC (char, len);
   13016         1458 :               for (int i = 0; i < len; ++i)
   13017              :                 {
   13018         1033 :                   tree t = message_data;
   13019         1033 :                   if (i)
   13020         1156 :                     t = build2 (POINTER_PLUS_EXPR,
   13021          578 :                                 TREE_TYPE (message_data), message_data,
   13022          578 :                                 size_int (i));
   13023         1033 :                   t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
   13024         1033 :                   tree t2 = cxx_constant_value (t, NULL_TREE, complain);
   13025         1033 :                   if (!tree_fits_shwi_p (t2))
   13026              :                     {
   13027           30 :                       error_at (location,
   13028              :                                 "constexpr string %<data()[%d]%> "
   13029              :                                 "must be a constant expression", i);
   13030           30 :                       return false;
   13031              :                     }
   13032         1003 :                   if (msg == NULL)
   13033          362 :                     buf[i] = tree_to_shwi (t2);
   13034              :                   /* If c_getstr worked, just verify the first and
   13035              :                      last characters using constant evaluation.  */
   13036          641 :                   else if (len > 2 && i == 0)
   13037          268 :                     i = len - 2;
   13038              :                 }
   13039          425 :               if (msg == NULL)
   13040          104 :                 msg = buf;
   13041              :             }
   13042           77 :           else if (!data)
   13043              :             {
   13044              :               /* We don't have any function to test whether some
   13045              :                  expression is a core constant expression.  So, instead
   13046              :                  test whether (message.data (), 0) is a constant
   13047              :                  expression.  */
   13048           22 :               data = build2 (COMPOUND_EXPR, integer_type_node,
   13049              :                              message_data, integer_zero_node);
   13050           22 :               tree t = cxx_constant_value (data, NULL_TREE, complain);
   13051           22 :               if (!integer_zerop (t))
   13052              :                 {
   13053           22 :                   error_at (location,
   13054              :                             "constexpr string %<data()%> "
   13055              :                             "must be a core constant expression");
   13056           22 :                   return false;
   13057              :                 }
   13058              :             }
   13059              :         }
   13060              :     }
   13061              :   else
   13062              :     {
   13063         1714 :       tree eltype = TREE_TYPE (TREE_TYPE (message));
   13064         1714 :       int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
   13065         1714 :       msg = TREE_STRING_POINTER (message);
   13066         1714 :       len = TREE_STRING_LENGTH (message) / sz - 1;
   13067              :     }
   13068         2288 : translate:
   13069         2288 :   if ((message_sz && message_data) || ctx)
   13070              :     {
   13071              :       /* Convert the string from execution charset to SOURCE_CHARSET.  */
   13072          764 :       cpp_string istr, ostr;
   13073          764 :       istr.len = len;
   13074          764 :       istr.text = (const unsigned char *) msg;
   13075          764 :       enum cpp_ttype type = CPP_STRING;
   13076          764 :       if (message_sz && message_data)
   13077              :         {
   13078          574 :           if (POINTER_TYPE_P (TREE_TYPE (message_data))
   13079          574 :               && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   13080          574 :                   == char8_type_node))
   13081              :             type = CPP_UTF8STRING;
   13082              :         }
   13083          190 :       else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
   13084          190 :                == char8_type_node)
   13085          764 :         type = CPP_UTF8STRING;
   13086          764 :       if (len == 0)
   13087              :         ;
   13088          641 :       else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
   13089              :                                       true))
   13090              :         {
   13091            0 :           if (type == CPP_UTF8STRING)
   13092            0 :             error_at (location, "could not convert constexpr string from "
   13093              :                                 "UTF-8 encoding to source character "
   13094              :                                 "set");
   13095              :           else
   13096            0 :             error_at (location, "could not convert constexpr string from "
   13097              :                                 "ordinary literal encoding to source character "
   13098              :                                 "set");
   13099            0 :           return false;
   13100              :         }
   13101              :       else
   13102              :         {
   13103          641 :           if (buf)
   13104          104 :             XDELETEVEC (buf);
   13105          641 :           msg = buf = const_cast <char *> ((const char *) ostr.text);
   13106          641 :           len = ostr.len;
   13107              :         }
   13108              :     }
   13109              : 
   13110              :   return true;
   13111              : }
   13112              : 
   13113              : /* Build a STATIC_ASSERT for a static assertion with the condition
   13114              :    CONDITION and the message text MESSAGE.  LOCATION is the location
   13115              :    of the static assertion in the source code.  When MEMBER_P, this
   13116              :    static assertion is a member of a class.  If SHOW_EXPR_P is true,
   13117              :    print the condition (because it was instantiation-dependent).
   13118              :    If CONSTEVAL_BLOCK_P is true, this static assertion represents
   13119              :    a consteval block.  */
   13120              : 
   13121              : void
   13122     10696119 : finish_static_assert (tree condition, tree message, location_t location,
   13123              :                       bool member_p, bool show_expr_p,
   13124              :                       bool consteval_block_p/*=false*/)
   13125              : {
   13126     10696119 :   tsubst_flags_t complain = tf_warning_or_error;
   13127              : 
   13128     10696119 :   if (condition == NULL_TREE
   13129     10696119 :       || condition == error_mark_node)
   13130      4521186 :     return;
   13131              : 
   13132     10695919 :   if (check_for_bare_parameter_packs (condition))
   13133              :     return;
   13134              : 
   13135     10695916 :   cexpr_str cstr(message);
   13136     10695916 :   if (!cstr.type_check (location))
   13137              :     return;
   13138              : 
   13139              :   /* Save the condition in case it was a concept check.  */
   13140     10695822 :   tree orig_condition = condition;
   13141              : 
   13142     10695822 :   if (instantiation_dependent_expression_p (condition)
   13143     10695822 :       || instantiation_dependent_expression_p (message))
   13144              :     {
   13145              :       /* We're in a template; build a STATIC_ASSERT and put it in
   13146              :          the right place. */
   13147      4520374 :     defer:
   13148      4520374 :       tree assertion = make_node (STATIC_ASSERT);
   13149      4520374 :       STATIC_ASSERT_CONDITION (assertion) = orig_condition;
   13150      4520374 :       STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
   13151      4520374 :       STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
   13152      4520374 :       CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
   13153              : 
   13154      4520374 :       if (member_p)
   13155      2343864 :         maybe_add_class_template_decl_list (current_class_type,
   13156              :                                             assertion,
   13157              :                                             /*friend_p=*/0);
   13158              :       else
   13159      2176510 :         add_stmt (assertion);
   13160              : 
   13161      4520374 :       return;
   13162              :     }
   13163              : 
   13164              :   /* Evaluate the consteval { }.  This must be done only once.  */
   13165      6179319 :   if (consteval_block_p)
   13166              :     {
   13167          490 :       cxx_constant_value (condition);
   13168          490 :       return;
   13169              :     }
   13170              : 
   13171              :   /* Fold the expression and convert it to a boolean value. */
   13172      6178829 :   condition = contextual_conv_bool (condition, complain);
   13173      6178829 :   condition = fold_non_dependent_expr (condition, complain,
   13174              :                                        /*manifestly_const_eval=*/true);
   13175              : 
   13176      6178828 :   if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
   13177              :     /* Do nothing; the condition is satisfied. */
   13178              :     ;
   13179              :   else
   13180              :     {
   13181         6186 :       iloc_sentinel ils (location);
   13182              : 
   13183         6186 :       if (integer_zerop (condition))
   13184              :         {
   13185              :           /* CWG2518: static_assert failure in a template is not IFNDR.  */
   13186         5557 :           if (processing_template_decl)
   13187         3871 :             goto defer;
   13188              : 
   13189         1686 :           int len;
   13190         1686 :           const char *msg = NULL;
   13191         1686 :           if (!cstr.extract (location, msg, len))
   13192           25 :             return;
   13193              : 
   13194              :           /* See if we can find which clause was failing (for logical AND).  */
   13195         1661 :           tree bad = find_failing_clause (NULL, orig_condition);
   13196              :           /* If not, or its location is unusable, fall back to the previous
   13197              :              location.  */
   13198         1661 :           location_t cloc = cp_expr_loc_or_loc (bad, location);
   13199              : 
   13200         1661 :           auto_diagnostic_group d;
   13201              : 
   13202              :           /* Report the error. */
   13203         1661 :           if (len == 0)
   13204         1045 :             error_at (cloc, "static assertion failed");
   13205              :           else
   13206          616 :             error_at (cloc, "static assertion failed: %.*s", len, msg);
   13207              : 
   13208         1661 :           diagnose_failing_condition (bad, cloc, show_expr_p);
   13209              : 
   13210              :           /* Suppress -Wreturn-type for functions with failed static_asserts.
   13211              :              Otherwise templates like:
   13212              :              if constexpr (whatever)
   13213              :                return something (args);
   13214              :              else
   13215              :                static_assert (false, "explanation");
   13216              :              get a useless extra -Wreturn-type warning.  */
   13217         1661 :           if (current_function_decl)
   13218          601 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13219         1661 :         }
   13220          629 :       else if (condition && condition != error_mark_node)
   13221              :         {
   13222          623 :           error ("non-constant condition for static assertion");
   13223          623 :           if (require_rvalue_constant_expression (condition))
   13224          561 :             cxx_constant_value (condition);
   13225              :         }
   13226         6186 :     }
   13227     10695915 : }
   13228              : 
   13229              : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
   13230              :    suitable for use as a type-specifier.
   13231              : 
   13232              :    ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
   13233              :    id-expression or a class member access, FALSE when it was parsed as
   13234              :    a full expression.  */
   13235              : 
   13236              : tree
   13237     38825181 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
   13238              :                       tsubst_flags_t complain)
   13239              : {
   13240     38825181 :   tree type = NULL_TREE;
   13241              : 
   13242     38825181 :   if (!expr || error_operand_p (expr))
   13243       222431 :     return error_mark_node;
   13244              : 
   13245     38602750 :   if (TYPE_P (expr)
   13246     38602750 :       || TREE_CODE (expr) == TYPE_DECL
   13247     77205480 :       || (TREE_CODE (expr) == BIT_NOT_EXPR
   13248        15357 :           && TYPE_P (TREE_OPERAND (expr, 0))))
   13249              :     {
   13250           29 :       if (complain & tf_error)
   13251           29 :         error ("argument to %<decltype%> must be an expression");
   13252           29 :       return error_mark_node;
   13253              :     }
   13254              : 
   13255              :   /* decltype is an unevaluated context.  */
   13256     38602721 :   cp_unevaluated u;
   13257              : 
   13258     38602721 :   processing_template_decl_sentinel ptds (/*reset=*/false);
   13259              : 
   13260              :   /* Depending on the resolution of DR 1172, we may later need to distinguish
   13261              :      instantiation-dependent but not type-dependent expressions so that, say,
   13262              :      A<decltype(sizeof(T))>::U doesn't require 'typename'.  */
   13263     38602721 :   if (instantiation_dependent_uneval_expression_p (expr))
   13264              :     {
   13265      6953449 :     dependent:
   13266      6954025 :       type = cxx_make_type (DECLTYPE_TYPE);
   13267      6954025 :       DECLTYPE_TYPE_EXPR (type) = expr;
   13268     13908050 :       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
   13269      6954025 :         = id_expression_or_member_access_p;
   13270      6954025 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   13271              : 
   13272      6954025 :       return type;
   13273              :     }
   13274     31649272 :   else if (processing_template_decl)
   13275              :     {
   13276         6195 :       expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
   13277         6195 :       if (expr == error_mark_node)
   13278              :         return error_mark_node;
   13279              :       /* Keep processing_template_decl cleared for the rest of the function
   13280              :          (for sake of the call to lvalue_kind below, which handles templated
   13281              :          and non-templated COND_EXPR differently).  */
   13282         6158 :       processing_template_decl = 0;
   13283              :     }
   13284              : 
   13285              :   /* The type denoted by decltype(e) is defined as follows:  */
   13286              : 
   13287     31649235 :   expr = resolve_nondeduced_context (expr, complain);
   13288     31649235 :   if (!mark_single_function (expr, complain))
   13289            0 :     return error_mark_node;
   13290              : 
   13291     31649235 :   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
   13292           18 :     return error_mark_node;
   13293              : 
   13294     31649217 :   if (type_unknown_p (expr))
   13295              :     {
   13296           18 :       if (complain & tf_error)
   13297            6 :         error ("%<decltype%> cannot resolve address of overloaded function");
   13298           18 :       return error_mark_node;
   13299              :     }
   13300              : 
   13301     31649199 :   if (id_expression_or_member_access_p)
   13302              :     {
   13303              :       /* If e is an id-expression or a class member access (5.2.5
   13304              :          [expr.ref]), decltype(e) is defined as the type of the entity
   13305              :          named by e. If there is no such entity, or e names a set of
   13306              :          overloaded functions, the program is ill-formed.  */
   13307       430244 :       if (identifier_p (expr))
   13308            0 :         expr = lookup_name (expr);
   13309              : 
   13310              :       /* If e is a constified expression inside a contract assertion,
   13311              :          strip the const wrapper. Per P2900R14, "For a function f with the
   13312              :          return type T , the result name is an lvalue of type const T , decltype(r)
   13313              :          is T , and decltype((r)) is const T&."  */
   13314       430244 :       expr = strip_contract_const_wrapper (expr);
   13315              : 
   13316       287330 :       if (REFERENCE_REF_P (expr)
   13317       430248 :           || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   13318              :         /* This can happen when the expression is, e.g., "a.b". Just
   13319              :            look at the underlying operand.  */
   13320       288940 :         expr = TREE_OPERAND (expr, 0);
   13321              : 
   13322       430244 :       if (TREE_CODE (expr) == OFFSET_REF
   13323       430244 :           || TREE_CODE (expr) == MEMBER_REF
   13324       430244 :           || TREE_CODE (expr) == SCOPE_REF)
   13325              :         /* We're only interested in the field itself. If it is a
   13326              :            BASELINK, we will need to see through it in the next
   13327              :            step.  */
   13328            0 :         expr = TREE_OPERAND (expr, 1);
   13329              : 
   13330       430244 :       if (BASELINK_P (expr))
   13331              :         /* See through BASELINK nodes to the underlying function.  */
   13332            7 :         expr = BASELINK_FUNCTIONS (expr);
   13333              : 
   13334              :       /* decltype of a decomposition name drops references in the tuple case
   13335              :          (unlike decltype of a normal variable) and keeps cv-qualifiers from
   13336              :          the containing object in the other cases (unlike decltype of a member
   13337              :          access expression).  */
   13338       430244 :       if (DECL_DECOMPOSITION_P (expr))
   13339              :         {
   13340         1414 :           if (ptds.saved)
   13341              :             {
   13342          275 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
   13343              :                                    || (DECL_CONTEXT (expr)
   13344              :                                        != current_function_decl));
   13345              :               /* DECL_HAS_VALUE_EXPR_P is always set if
   13346              :                  processing_template_decl at least for structured bindings
   13347              :                  within the template.  If lookup_decomp_type
   13348              :                  returns non-NULL, it is the tuple case.  */
   13349          275 :               if (tree ret = lookup_decomp_type (expr))
   13350              :                 return ret;
   13351          191 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
   13352              :             }
   13353         1330 :           if (DECL_HAS_VALUE_EXPR_P (expr))
   13354              :             /* Expr is an array or struct subobject proxy, handle
   13355              :                bit-fields properly.  */
   13356         1018 :             return unlowered_expr_type (expr);
   13357              :           else
   13358              :             /* Expr is a reference variable for the tuple case.  */
   13359          312 :             return lookup_decomp_type (expr);
   13360              :         }
   13361              : 
   13362       428830 :       switch (TREE_CODE (expr))
   13363              :         {
   13364          242 :         case FIELD_DECL:
   13365          242 :           if (DECL_BIT_FIELD_TYPE (expr))
   13366              :             {
   13367              :               type = DECL_BIT_FIELD_TYPE (expr);
   13368              :               break;
   13369              :             }
   13370              :           /* Fall through for fields that aren't bitfields.  */
   13371       121520 :           gcc_fallthrough ();
   13372              : 
   13373       121520 :         case VAR_DECL:
   13374       121520 :           if (is_capture_proxy (expr))
   13375              :             {
   13376           99 :               if (is_normal_capture_proxy (expr))
   13377              :                 {
   13378           21 :                   expr = DECL_CAPTURED_VARIABLE (expr);
   13379           21 :                   type = TREE_TYPE (expr);
   13380              :                 }
   13381              :               else
   13382              :                 {
   13383           78 :                   expr = DECL_VALUE_EXPR (expr);
   13384           78 :                   gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
   13385           78 :                   expr = TREE_OPERAND (expr, 1);
   13386           78 :                   type = TREE_TYPE (expr);
   13387              :                 }
   13388              :               break;
   13389              :             }
   13390              :           /* Fall through for variables that aren't capture proxies.  */
   13391       421790 :           gcc_fallthrough ();
   13392              : 
   13393       421790 :         case FUNCTION_DECL:
   13394       421790 :         case CONST_DECL:
   13395       421790 :         case PARM_DECL:
   13396       421790 :         case RESULT_DECL:
   13397       421790 :         case TEMPLATE_PARM_INDEX:
   13398       421790 :           expr = mark_type_use (expr);
   13399       421790 :           type = TREE_TYPE (expr);
   13400       421790 :           if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
   13401              :             {
   13402              :               /* decltype of an NTTP object is the type of the template
   13403              :                  parameter, which is the object type modulo cv-quals.  */
   13404         1345 :               int quals = cp_type_quals (type);
   13405         1345 :               gcc_checking_assert (quals & TYPE_QUAL_CONST);
   13406         1345 :               type = cv_unqualified (type);
   13407              :             }
   13408              :           break;
   13409              : 
   13410            0 :         case ERROR_MARK:
   13411            0 :           type = error_mark_node;
   13412            0 :           break;
   13413              : 
   13414         3192 :         case COMPONENT_REF:
   13415         3192 :         case COMPOUND_EXPR:
   13416         3192 :           mark_type_use (expr);
   13417         3192 :           type = is_bitfield_expr_with_lowered_type (expr);
   13418         3192 :           if (!type)
   13419         3155 :             type = TREE_TYPE (TREE_OPERAND (expr, 1));
   13420              :           break;
   13421              : 
   13422            0 :         case BIT_FIELD_REF:
   13423            0 :           gcc_unreachable ();
   13424              : 
   13425         1966 :         case INTEGER_CST:
   13426         1966 :         case PTRMEM_CST:
   13427              :           /* We can get here when the id-expression refers to an
   13428              :              enumerator or non-type template parameter.  */
   13429         1966 :           type = TREE_TYPE (expr);
   13430         1966 :           break;
   13431              : 
   13432         1783 :         default:
   13433              :           /* Handle instantiated template non-type arguments.  */
   13434         1783 :           type = TREE_TYPE (expr);
   13435         1783 :           break;
   13436              :         }
   13437              :     }
   13438              :   else
   13439              :     {
   13440     31218955 :       tree decl = STRIP_REFERENCE_REF (expr);
   13441     31218955 :       tree lam = current_lambda_expr ();
   13442     31218955 :       if (lam && outer_automatic_var_p (decl))
   13443              :         {
   13444              :           /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
   13445              :              unevaluated operand within S would refer to an entity captured by
   13446              :              copy in some intervening lambda-expression, then let E be the
   13447              :              innermost such lambda-expression.
   13448              : 
   13449              :              If there is such a lambda-expression and if P is in E's function
   13450              :              parameter scope but not its parameter-declaration-clause, then the
   13451              :              type of the expression is the type of a class member access
   13452              :              expression naming the non-static data member that would be declared
   13453              :              for such a capture in the object parameter of the function call
   13454              :              operator of E."  */
   13455              :           /* FIXME: This transformation needs to happen for all uses of an outer
   13456              :              local variable inside decltype, not just decltype((x)) (PR83167).
   13457              :              And we don't handle nested lambdas properly, where we need to
   13458              :              consider the outer lambdas as well (PR112926). */
   13459         1379 :           tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
   13460              :                                   LOOK_want::HIDDEN_LAMBDA);
   13461              : 
   13462         1379 :           if (cap && is_capture_proxy (cap))
   13463          467 :             type = TREE_TYPE (cap);
   13464          912 :           else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
   13465              :             {
   13466          738 :               type = TREE_TYPE (decl);
   13467          738 :               if (TYPE_REF_P (type)
   13468          738 :                   && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
   13469           36 :                 type = TREE_TYPE (type);
   13470              :             }
   13471              : 
   13472         1205 :           if (type && !TYPE_REF_P (type))
   13473              :             {
   13474         1121 :               int quals;
   13475         1121 :               if (current_function_decl
   13476         2104 :                   && LAMBDA_FUNCTION_P (current_function_decl)
   13477         2104 :                   && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
   13478              :                 {
   13479          900 :                   tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
   13480          900 :                   if (WILDCARD_TYPE_P (non_reference (obtype)))
   13481              :                     /* We don't know what the eventual obtype quals will be.  */
   13482          576 :                     goto dependent;
   13483          648 :                   auto direct_type = [](tree t){
   13484          324 :                       if (INDIRECT_TYPE_P (t))
   13485          162 :                         return TREE_TYPE (t);
   13486              :                       return t;
   13487              :                    };
   13488          648 :                   quals = (cp_type_quals (type)
   13489          324 :                            | cp_type_quals (direct_type (obtype)));
   13490              :                 }
   13491              :               else
   13492              :                 /* We are in the parameter clause, trailing return type, or
   13493              :                    the requires clause and have no relevant c_f_decl yet.  */
   13494          349 :                 quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
   13495          221 :                          ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
   13496          545 :               type = cp_build_qualified_type (type, quals);
   13497          545 :               type = build_reference_type (type);
   13498              :             }
   13499              :         }
   13500     31217576 :       else if (error_operand_p (expr))
   13501            0 :         type = error_mark_node;
   13502     31217576 :       else if (expr == current_class_ptr)
   13503              :         /* If the expression is just "this", we want the
   13504              :            cv-unqualified pointer for the "this" type.  */
   13505            0 :         type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
   13506              : 
   13507          545 :       if (!type)
   13508              :         {
   13509              :           /* Otherwise, where T is the type of e, if e is an lvalue,
   13510              :              decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
   13511     31217750 :           cp_lvalue_kind clk = lvalue_kind (expr);
   13512     31217750 :           type = unlowered_expr_type (expr);
   13513     31217750 :           gcc_assert (!TYPE_REF_P (type));
   13514              : 
   13515              :           /* For vector types, pick a non-opaque variant.  */
   13516     31217750 :           if (VECTOR_TYPE_P (type))
   13517         2078 :             type = strip_typedefs (type);
   13518              : 
   13519     31217750 :           if (clk != clk_none && !(clk & clk_class))
   13520      8435798 :             type = cp_build_reference_type (type, (clk & clk_rvalueref));
   13521              :         }
   13522              :     }
   13523              : 
   13524              :   return type;
   13525     38602721 : }
   13526              : 
   13527              : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
   13528              :    __has_nothrow_copy, depending on assign_p.  Returns true iff all
   13529              :    the copy {ctor,assign} fns are nothrow.  */
   13530              : 
   13531              : static bool
   13532          279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
   13533              : {
   13534          279 :   tree fns = NULL_TREE;
   13535              : 
   13536          279 :   if (assign_p || TYPE_HAS_COPY_CTOR (type))
   13537          276 :     fns = get_class_binding (type, assign_p ? assign_op_identifier
   13538              :                              : ctor_identifier);
   13539              : 
   13540          279 :   bool saw_copy = false;
   13541          696 :   for (ovl_iterator iter (fns); iter; ++iter)
   13542              :     {
   13543          441 :       tree fn = *iter;
   13544              : 
   13545          441 :       if (copy_fn_p (fn) > 0)
   13546              :         {
   13547          423 :           saw_copy = true;
   13548          423 :           if (!maybe_instantiate_noexcept (fn)
   13549          423 :               || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
   13550          192 :             return false;
   13551              :         }
   13552              :     }
   13553              : 
   13554           87 :   return saw_copy;
   13555              : }
   13556              : 
   13557              : /* Return true if BASE is a pointer-interconvertible base of DERIVED.  */
   13558              : 
   13559              : bool
   13560          177 : pointer_interconvertible_base_of_p (tree base, tree derived,
   13561              :                                     bool explain/*=false*/)
   13562              : {
   13563          177 :   if (base == error_mark_node || derived == error_mark_node)
   13564              :     return false;
   13565              : 
   13566          177 :   base = TYPE_MAIN_VARIANT (base);
   13567          177 :   derived = TYPE_MAIN_VARIANT (derived);
   13568          177 :   if (!NON_UNION_CLASS_TYPE_P (base))
   13569              :     {
   13570           17 :       if (explain)
   13571            3 :         inform (location_of (base),
   13572              :                 "%qT is not a non-union class type", base);
   13573           17 :       return false;
   13574              :     }
   13575          160 :   if (!NON_UNION_CLASS_TYPE_P (derived))
   13576              :     {
   13577            6 :       if (explain)
   13578            3 :         inform (location_of (derived),
   13579              :                 "%qT is not a non-union class type", derived);
   13580            6 :       return false;
   13581              :     }
   13582              : 
   13583          154 :   if (same_type_p (base, derived))
   13584              :     return true;
   13585              : 
   13586          117 :   if (!std_layout_type_p (derived))
   13587              :     {
   13588           18 :       if (explain)
   13589            6 :         inform (location_of (derived),
   13590              :                 "%qT is not a standard-layout type", derived);
   13591           18 :       return false;
   13592              :     }
   13593              : 
   13594           99 :   if (!uniquely_derived_from_p (base, derived))
   13595              :     {
   13596           18 :       if (explain)
   13597              :         {
   13598              :           /* An ambiguous base should already be impossible due to
   13599              :              the std_layout_type_p check.  */
   13600            3 :           gcc_checking_assert (!DERIVED_FROM_P (base, derived));
   13601            3 :           inform (location_of (derived),
   13602              :                   "%qT is not a base of %qT", base, derived);
   13603              :         }
   13604           18 :       return false;
   13605              :     }
   13606              : 
   13607              :   return true;
   13608              : }
   13609              : 
   13610              : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
   13611              :    return true if MEMBERTYPE is the type of the first non-static data member
   13612              :    of TYPE or for unions of any members.  */
   13613              : static bool
   13614          637 : first_nonstatic_data_member_p (tree type, tree membertype)
   13615              : {
   13616         1297 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   13617              :     {
   13618         1222 :       if (TREE_CODE (field) != FIELD_DECL)
   13619          135 :         continue;
   13620         1087 :       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
   13621           60 :         continue;
   13622         1027 :       if (DECL_FIELD_IS_BASE (field))
   13623           45 :         return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
   13624          982 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13625              :         {
   13626          216 :           if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
   13627          138 :                || std_layout_type_p (TREE_TYPE (field)))
   13628          294 :               && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
   13629              :             return true;
   13630              :         }
   13631          766 :       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13632              :                                                           membertype))
   13633              :         return true;
   13634          537 :       if (TREE_CODE (type) != UNION_TYPE)
   13635              :         return false;
   13636              :     }
   13637              :   return false;
   13638              : }
   13639              : 
   13640              : /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
   13641              : 
   13642              : tree
   13643          536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
   13644              :                                                      tree *args)
   13645              : {
   13646              :   /* Unless users call the builtin directly, the following 3 checks should be
   13647              :      ensured from std::is_pointer_interconvertible_with_class function
   13648              :      template.  */
   13649          536 :   if (nargs != 1)
   13650              :     {
   13651            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13652              :                      "needs a single argument");
   13653            6 :       return boolean_false_node;
   13654              :     }
   13655          530 :   tree arg = args[0];
   13656          530 :   if (error_operand_p (arg))
   13657            0 :     return boolean_false_node;
   13658          530 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
   13659              :     {
   13660            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13661              :                      "argument is not pointer to member");
   13662            6 :       return boolean_false_node;
   13663              :     }
   13664              : 
   13665          524 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
   13666           18 :     return boolean_false_node;
   13667              : 
   13668          506 :   tree membertype = TREE_TYPE (TREE_TYPE (arg));
   13669          506 :   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
   13670          506 :   if (!complete_type_or_else (basetype, NULL_TREE))
   13671            3 :     return boolean_false_node;
   13672              : 
   13673          503 :   if (TREE_CODE (basetype) != UNION_TYPE
   13674          503 :       && !std_layout_type_p (basetype))
   13675           22 :     return boolean_false_node;
   13676              : 
   13677          481 :   if (!first_nonstatic_data_member_p (basetype, membertype))
   13678          132 :     return boolean_false_node;
   13679              : 
   13680          349 :   if (TREE_CODE (arg) == PTRMEM_CST)
   13681           68 :     arg = cplus_expand_constant (arg);
   13682              : 
   13683          349 :   if (integer_nonzerop (arg))
   13684           10 :     return boolean_false_node;
   13685          339 :   if (integer_zerop (arg))
   13686           71 :     return boolean_true_node;
   13687              : 
   13688          268 :   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
   13689              :                       build_zero_cst (TREE_TYPE (arg)));
   13690              : }
   13691              : 
   13692              : /* Helper function for is_corresponding_member_aggr.  Return true if
   13693              :    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
   13694              :    union or structure BASETYPE.  */
   13695              : 
   13696              : static bool
   13697           90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
   13698              : {
   13699          222 :   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
   13700          192 :     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
   13701           36 :       continue;
   13702          156 :     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13703              :                                                         membertype))
   13704              :       {
   13705           48 :         if (TREE_CODE (arg) != INTEGER_CST
   13706           48 :             || tree_int_cst_equal (arg, byte_position (field)))
   13707           48 :           return true;
   13708              :       }
   13709          108 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13710              :       {
   13711           18 :         tree narg = arg;
   13712           18 :         if (TREE_CODE (basetype) != UNION_TYPE
   13713            0 :             && TREE_CODE (narg) == INTEGER_CST)
   13714            0 :           narg = size_binop (MINUS_EXPR, arg, byte_position (field));
   13715           18 :         if (is_corresponding_member_union (TREE_TYPE (field),
   13716              :                                            membertype, narg))
   13717              :           return true;
   13718              :       }
   13719              :   return false;
   13720              : }
   13721              : 
   13722              : /* Helper function for fold_builtin_is_corresponding_member call.
   13723              :    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
   13724              :    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
   13725              :    boolean_true_node if they are corresponding members, or for
   13726              :    non-constant ARG2 the highest member offset for corresponding
   13727              :    members.  */
   13728              : 
   13729              : static tree
   13730          550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
   13731              :                               tree arg1, tree basetype2, tree membertype2,
   13732              :                               tree arg2)
   13733              : {
   13734          550 :   tree field1 = TYPE_FIELDS (basetype1);
   13735          550 :   tree field2 = TYPE_FIELDS (basetype2);
   13736          550 :   tree ret = boolean_false_node;
   13737         2376 :   while (1)
   13738              :     {
   13739         1463 :       bool r = next_common_initial_sequence (field1, field2);
   13740         1463 :       if (field1 == NULL_TREE || field2 == NULL_TREE)
   13741              :         break;
   13742         1331 :       if (r
   13743         1038 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
   13744              :                                                         membertype1)
   13745         1841 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
   13746              :                                                         membertype2))
   13747              :         {
   13748          504 :           tree pos = byte_position (field1);
   13749          504 :           if (TREE_CODE (arg1) == INTEGER_CST
   13750          504 :               && tree_int_cst_equal (arg1, pos))
   13751              :             {
   13752           92 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13753           92 :                 return boolean_true_node;
   13754              :               return pos;
   13755              :             }
   13756          412 :           else if (TREE_CODE (arg1) != INTEGER_CST)
   13757         1188 :             ret = pos;
   13758              :         }
   13759         1654 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
   13760          944 :                && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
   13761              :         {
   13762          117 :           if ((!lookup_attribute ("no_unique_address",
   13763          117 :                                   DECL_ATTRIBUTES (field1)))
   13764          117 :               != !lookup_attribute ("no_unique_address",
   13765          117 :                                     DECL_ATTRIBUTES (field2)))
   13766              :             break;
   13767          117 :           if (!tree_int_cst_equal (bit_position (field1),
   13768          117 :                                    bit_position (field2)))
   13769              :             break;
   13770           99 :           bool overlap = true;
   13771           99 :           tree pos = byte_position (field1);
   13772           99 :           if (TREE_CODE (arg1) == INTEGER_CST)
   13773              :             {
   13774           27 :               tree off1 = fold_convert (sizetype, arg1);
   13775           27 :               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
   13776           27 :               if (tree_int_cst_lt (off1, pos)
   13777           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
   13778              :                 overlap = false;
   13779              :             }
   13780           99 :           if (TREE_CODE (arg2) == INTEGER_CST)
   13781              :             {
   13782           27 :               tree off2 = fold_convert (sizetype, arg2);
   13783           27 :               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
   13784           27 :               if (tree_int_cst_lt (off2, pos)
   13785           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
   13786              :                 overlap = false;
   13787              :             }
   13788           87 :           if (overlap
   13789           87 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
   13790          126 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
   13791              :             {
   13792           39 :               tree narg1 = arg1;
   13793           39 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13794            9 :                 narg1 = size_binop (MINUS_EXPR,
   13795              :                                     fold_convert (sizetype, arg1), pos);
   13796           39 :               tree narg2 = arg2;
   13797           39 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13798            9 :                 narg2 = size_binop (MINUS_EXPR,
   13799              :                                     fold_convert (sizetype, arg2), pos);
   13800           39 :               tree t1 = TREE_TYPE (field1);
   13801           39 :               tree t2 = TREE_TYPE (field2);
   13802           39 :               tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
   13803              :                                                         narg1, t2, membertype2,
   13804              :                                                         narg2);
   13805           39 :               if (nret != boolean_false_node)
   13806              :                 {
   13807           39 :                   if (nret == boolean_true_node)
   13808              :                     return nret;
   13809           30 :                   if (TREE_CODE (arg1) == INTEGER_CST)
   13810            0 :                     return size_binop (PLUS_EXPR, nret, pos);
   13811           30 :                   ret = size_binop (PLUS_EXPR, nret, pos);
   13812              :                 }
   13813              :             }
   13814           60 :           else if (overlap
   13815           48 :                    && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
   13816          108 :                    && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
   13817              :             {
   13818           48 :               tree narg1 = arg1;
   13819           48 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13820            6 :                 narg1 = size_binop (MINUS_EXPR,
   13821              :                                     fold_convert (sizetype, arg1), pos);
   13822           48 :               tree narg2 = arg2;
   13823           48 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13824            6 :                 narg2 = size_binop (MINUS_EXPR,
   13825              :                                     fold_convert (sizetype, arg2), pos);
   13826           48 :               if (is_corresponding_member_union (TREE_TYPE (field1),
   13827              :                                                  membertype1, narg1)
   13828           48 :                   && is_corresponding_member_union (TREE_TYPE (field2),
   13829              :                                                     membertype2, narg2))
   13830              :                 {
   13831           24 :                   sorry_at (loc, "%<__builtin_is_corresponding_member%> "
   13832              :                                  "not well defined for anonymous unions");
   13833           24 :                   return boolean_false_node;
   13834              :                 }
   13835              :             }
   13836              :         }
   13837         1188 :       if (!r)
   13838              :         break;
   13839          913 :       field1 = DECL_CHAIN (field1);
   13840          913 :       field2 = DECL_CHAIN (field2);
   13841          913 :     }
   13842              :   return ret;
   13843              : }
   13844              : 
   13845              : /* Fold __builtin_is_corresponding_member call.  */
   13846              : 
   13847              : tree
   13848          699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
   13849              :                                       tree *args)
   13850              : {
   13851              :   /* Unless users call the builtin directly, the following 3 checks should be
   13852              :      ensured from std::is_corresponding_member function template.  */
   13853          699 :   if (nargs != 2)
   13854              :     {
   13855            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13856              :                      "needs two arguments");
   13857            9 :       return boolean_false_node;
   13858              :     }
   13859          690 :   tree arg1 = args[0];
   13860          690 :   tree arg2 = args[1];
   13861          690 :   if (error_operand_p (arg1) || error_operand_p (arg2))
   13862            0 :     return boolean_false_node;
   13863          711 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
   13864          705 :       || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
   13865              :     {
   13866            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13867              :                      "argument is not pointer to member");
   13868            9 :       return boolean_false_node;
   13869              :     }
   13870              : 
   13871          681 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
   13872          681 :       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
   13873           15 :     return boolean_false_node;
   13874              : 
   13875          666 :   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
   13876          666 :   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
   13877          666 :   if (!complete_type_or_else (basetype1, NULL_TREE))
   13878           12 :     return boolean_false_node;
   13879              : 
   13880          654 :   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
   13881          654 :   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
   13882          654 :   if (!complete_type_or_else (basetype2, NULL_TREE))
   13883           12 :     return boolean_false_node;
   13884              : 
   13885          627 :   if (!NON_UNION_CLASS_TYPE_P (basetype1)
   13886          627 :       || !NON_UNION_CLASS_TYPE_P (basetype2)
   13887          627 :       || !std_layout_type_p (basetype1)
   13888         1233 :       || !std_layout_type_p (basetype2))
   13889           51 :     return boolean_false_node;
   13890              : 
   13891              :   /* If the member types aren't layout compatible, then they
   13892              :      can't be corresponding members.  */
   13893          591 :   if (!layout_compatible_type_p (membertype1, membertype2))
   13894           18 :     return boolean_false_node;
   13895              : 
   13896          573 :   if (TREE_CODE (arg1) == PTRMEM_CST)
   13897          176 :     arg1 = cplus_expand_constant (arg1);
   13898          573 :   if (TREE_CODE (arg2) == PTRMEM_CST)
   13899          182 :     arg2 = cplus_expand_constant (arg2);
   13900              : 
   13901          573 :   if (null_member_pointer_value_p (arg1)
   13902          573 :       || null_member_pointer_value_p (arg2))
   13903            9 :     return boolean_false_node;
   13904              : 
   13905          564 :   if (TREE_CODE (arg1) == INTEGER_CST
   13906          182 :       && TREE_CODE (arg2) == INTEGER_CST
   13907          746 :       && !tree_int_cst_equal (arg1, arg2))
   13908           53 :     return boolean_false_node;
   13909              : 
   13910          511 :   if (TREE_CODE (arg2) == INTEGER_CST
   13911          129 :       && TREE_CODE (arg1) != INTEGER_CST)
   13912              :     {
   13913              :       std::swap (arg1, arg2);
   13914              :       std::swap (membertype1, membertype2);
   13915              :       std::swap (basetype1, basetype2);
   13916              :     }
   13917              : 
   13918          511 :   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
   13919              :                                            basetype2, membertype2, arg2);
   13920          511 :   if (TREE_TYPE (ret) == boolean_type_node)
   13921              :     return ret;
   13922              :   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
   13923              :      already returns boolean_{true,false}_node whether those particular
   13924              :      members are corresponding members or not.  Otherwise, if only
   13925              :      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
   13926              :      above), it returns boolean_false_node if it is certainly not a
   13927              :      corresponding member and otherwise we need to do a runtime check that
   13928              :      those two OFFSET_TYPE offsets are equal.
   13929              :      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
   13930              :      returns the largest offset at which the members would be corresponding
   13931              :      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
   13932          304 :   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
   13933          304 :   if (TREE_CODE (arg1) == INTEGER_CST)
   13934            0 :     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13935              :                         fold_convert (TREE_TYPE (arg1), arg2));
   13936          304 :   ret = fold_build2 (LE_EXPR, boolean_type_node,
   13937              :                      fold_convert (pointer_sized_int_node, arg1),
   13938              :                      fold_convert (pointer_sized_int_node, ret));
   13939          304 :   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
   13940              :                       fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13941              :                                    fold_convert (TREE_TYPE (arg1), arg2)));
   13942              : }
   13943              : 
   13944              : /* Fold __builtin_is_string_literal call.  */
   13945              : 
   13946              : tree
   13947         4046 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
   13948              : {
   13949              :   /* Unless users call the builtin directly, the following 3 checks should be
   13950              :      ensured from std::is_string_literal overloads.  */
   13951         4046 :   if (nargs != 1)
   13952              :     {
   13953            0 :       error_at (loc, "%<__builtin_is_string_literal%> needs a single "
   13954              :                 "argument");
   13955            0 :       return boolean_false_node;
   13956              :     }
   13957         4046 :   tree arg = args[0];
   13958         4046 :   if (error_operand_p (arg))
   13959            0 :     return boolean_false_node;
   13960         4046 :   if (!TYPE_PTR_P (TREE_TYPE (arg))
   13961         4046 :       || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
   13962         8092 :       || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
   13963              :     {
   13964            0 :     arg_invalid:
   13965            0 :       error_at (loc, "%<__builtin_is_string_literal%> "
   13966              :                      "argument is not %<const char*%>, %<const wchar_t*%>, "
   13967              :                      "%<const char8_t*%>, %<const char16_t*%> or "
   13968              :                      "%<const char32_t*%>");
   13969            0 :       return boolean_false_node;
   13970              :     }
   13971         4046 :   tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
   13972         4046 :   if (chart != char_type_node
   13973         3232 :       && chart != wchar_type_node
   13974         2424 :       && chart != char8_type_node
   13975         1616 :       && chart != char16_type_node
   13976          808 :       && chart != char32_type_node)
   13977            0 :     goto arg_invalid;
   13978              : 
   13979         4046 :   STRIP_NOPS (arg);
   13980         8104 :   while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
   13981              :     {
   13982           12 :       arg = TREE_OPERAND (arg, 0);
   13983           12 :       STRIP_NOPS (arg);
   13984              :     }
   13985         4046 :   if (TREE_CODE (arg) != ADDR_EXPR)
   13986         3990 :     return boolean_false_node;
   13987           56 :   arg = TREE_OPERAND (arg, 0);
   13988           56 :   if (TREE_CODE (arg) == ARRAY_REF)
   13989           24 :     arg = TREE_OPERAND (arg, 0);
   13990           56 :   if (TREE_CODE (arg) != STRING_CST)
   13991           16 :     return boolean_false_node;
   13992           40 :   return boolean_true_node;
   13993              : }
   13994              : 
   13995              : /* [basic.types] 8.  True iff TYPE is an object type.  */
   13996              : 
   13997              : static bool
   13998      2756043 : object_type_p (const_tree type)
   13999              : {
   14000      2756043 :   return (TREE_CODE (type) != FUNCTION_TYPE
   14001            0 :           && !TYPE_REF_P (type)
   14002      2756043 :           && !VOID_TYPE_P (type));
   14003              : }
   14004              : 
   14005              : /* [defns.referenceable] True iff TYPE is a referenceable type.  */
   14006              : 
   14007              : static bool
   14008      3360472 : referenceable_type_p (const_tree type)
   14009              : {
   14010      3360472 :   return (TYPE_REF_P (type)
   14011      3360915 :           || object_type_p (type)
   14012      3360915 :           || (FUNC_OR_METHOD_TYPE_P (type)
   14013          376 :               && type_memfn_quals (type) == TYPE_UNQUALIFIED
   14014          312 :               && type_memfn_rqual (type) == REF_QUAL_NONE));
   14015              : }
   14016              : 
   14017              : /* Actually evaluates the trait.  */
   14018              : 
   14019              : static bool
   14020     16950074 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
   14021              : {
   14022     16950074 :   enum tree_code type_code1;
   14023     16950074 :   tree t;
   14024              : 
   14025     16950074 :   type_code1 = TREE_CODE (type1);
   14026              : 
   14027     16950074 :   switch (kind)
   14028              :     {
   14029          317 :     case CPTK_HAS_NOTHROW_ASSIGN:
   14030          317 :       type1 = strip_array_types (type1);
   14031          601 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14032          601 :               && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
   14033          173 :                   || (CLASS_TYPE_P (type1)
   14034          129 :                       && classtype_has_nothrow_assign_or_copy_p (type1,
   14035              :                                                                  true))));
   14036              : 
   14037          215 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   14038          215 :       type1 = strip_array_types (type1);
   14039          215 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
   14040          215 :               || (CLASS_TYPE_P (type1)
   14041           93 :                   && (t = locate_ctor (type1))
   14042           60 :                   && maybe_instantiate_noexcept (t)
   14043           58 :                   && TYPE_NOTHROW_P (TREE_TYPE (t))));
   14044              : 
   14045          305 :     case CPTK_HAS_NOTHROW_COPY:
   14046          305 :       type1 = strip_array_types (type1);
   14047          305 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
   14048          305 :               || (CLASS_TYPE_P (type1)
   14049          150 :                   && classtype_has_nothrow_assign_or_copy_p (type1, false)));
   14050              : 
   14051          517 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   14052              :       /* ??? The standard seems to be missing the "or array of such a class
   14053              :          type" wording for this trait.  */
   14054          517 :       type1 = strip_array_types (type1);
   14055         1016 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14056         1001 :               && (trivial_type_p (type1)
   14057          307 :                     || (CLASS_TYPE_P (type1)
   14058          222 :                         && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
   14059              : 
   14060          542 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   14061          542 :       type1 = strip_array_types (type1);
   14062          542 :       return (trivial_type_p (type1)
   14063          542 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
   14064              : 
   14065          526 :     case CPTK_HAS_TRIVIAL_COPY:
   14066              :       /* ??? The standard seems to be missing the "or array of such a class
   14067              :          type" wording for this trait.  */
   14068          526 :       type1 = strip_array_types (type1);
   14069          878 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14070          863 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
   14071              : 
   14072          761 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   14073          761 :       type1 = strip_array_types (type1);
   14074          761 :       if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
   14075              :         {
   14076          123 :           deferring_access_check_sentinel dacs (dk_no_check);
   14077          123 :           cp_unevaluated un;
   14078          123 :           tree fn = get_dtor (type1, tf_none);
   14079          123 :           if (!fn && !seen_error ())
   14080            3 :             warning (0, "checking %qs for type %qT with a destructor that "
   14081              :                      "cannot be called", "__has_trivial_destructor", type1);
   14082          123 :         }
   14083         1092 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14084         1089 :               || (CLASS_TYPE_P (type1)
   14085          284 :                   && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
   14086              : 
   14087        57860 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   14088        57860 :       return type_has_unique_obj_representations (type1);
   14089              : 
   14090          279 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   14091          279 :       return type_has_virtual_destructor (type1);
   14092              : 
   14093        54417 :     case CPTK_IS_ABSTRACT:
   14094        54417 :       return ABSTRACT_CLASS_TYPE_P (type1);
   14095              : 
   14096          813 :     case CPTK_IS_AGGREGATE:
   14097          813 :       return CP_AGGREGATE_TYPE_P (type1);
   14098              : 
   14099       339002 :     case CPTK_IS_ARRAY:
   14100       339002 :       return (type_code1 == ARRAY_TYPE
   14101              :               /* We don't want to report T[0] as being an array type.
   14102              :                  This is for compatibility with an implementation of
   14103              :                  std::is_array by template argument deduction, because
   14104              :                  compute_array_index_type_loc rejects a zero-size array
   14105              :                  in SFINAE context.  */
   14106       339002 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14107              : 
   14108       971171 :     case CPTK_IS_ASSIGNABLE:
   14109       971171 :       return is_xible (MODIFY_EXPR, type1, type2);
   14110              : 
   14111       483871 :     case CPTK_IS_BASE_OF:
   14112       483780 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14113       949542 :               && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
   14114       439255 :                   || DERIVED_FROM_P (type1, type2)));
   14115              : 
   14116        52740 :     case CPTK_IS_BOUNDED_ARRAY:
   14117        52740 :       return (type_code1 == ARRAY_TYPE
   14118         1492 :               && TYPE_DOMAIN (type1)
   14119              :               /* We don't want to report T[0] as being a bounded array type.
   14120              :                  This is for compatibility with an implementation of
   14121              :                  std::is_bounded_array by template argument deduction, because
   14122              :                  compute_array_index_type_loc rejects a zero-size array
   14123              :                  in SFINAE context.  */
   14124        54104 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14125              : 
   14126       489566 :     case CPTK_IS_CLASS:
   14127       489566 :       return NON_UNION_CLASS_TYPE_P (type1);
   14128              : 
   14129       552546 :     case CPTK_IS_CONST:
   14130       552546 :       return CP_TYPE_CONST_P (type1);
   14131              : 
   14132      2241551 :     case CPTK_IS_CONSTRUCTIBLE:
   14133      2241551 :       return is_xible (INIT_EXPR, type1, type2);
   14134              : 
   14135      2975486 :     case CPTK_IS_CONVERTIBLE:
   14136      2975486 :       return is_convertible (type1, type2);
   14137              : 
   14138         2957 :     case CPTK_IS_DESTRUCTIBLE:
   14139         2957 :       return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14140              : 
   14141       209067 :     case CPTK_IS_EMPTY:
   14142       209067 :       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
   14143              : 
   14144       637675 :     case CPTK_IS_ENUM:
   14145       637675 :       return type_code1 == ENUMERAL_TYPE;
   14146              : 
   14147       413803 :     case CPTK_IS_FINAL:
   14148       413803 :       return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
   14149              : 
   14150        45142 :     case CPTK_IS_FUNCTION:
   14151        45142 :       return type_code1 == FUNCTION_TYPE;
   14152              : 
   14153          800 :     case CPTK_IS_IMPLICIT_LIFETIME:
   14154          800 :       return implicit_lifetime_type_p (type1);
   14155              : 
   14156        46940 :     case CPTK_IS_INVOCABLE:
   14157        46940 :       return !error_operand_p (build_invoke (type1, type2, tf_none));
   14158              : 
   14159          213 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   14160          213 :       return layout_compatible_type_p (type1, type2);
   14161              : 
   14162          197 :     case CPTK_IS_LITERAL_TYPE:
   14163          197 :       return literal_type_p (type1);
   14164              : 
   14165        46788 :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   14166        46788 :       return TYPE_PTRMEMFUNC_P (type1);
   14167              : 
   14168        46757 :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   14169        46757 :       return TYPE_PTRDATAMEM_P (type1);
   14170              : 
   14171        10308 :     case CPTK_IS_MEMBER_POINTER:
   14172        10308 :       return TYPE_PTRMEM_P (type1);
   14173              : 
   14174       434791 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   14175       434791 :       return is_nothrow_xible (MODIFY_EXPR, type1, type2);
   14176              : 
   14177       881870 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14178       881870 :       return is_nothrow_xible (INIT_EXPR, type1, type2);
   14179              : 
   14180          674 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14181          674 :       return is_nothrow_convertible (type1, type2);
   14182              : 
   14183        23189 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   14184        23189 :       return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14185              : 
   14186        41416 :     case CPTK_IS_NOTHROW_INVOCABLE:
   14187        41416 :       return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
   14188              : 
   14189      1066801 :     case CPTK_IS_OBJECT:
   14190      1066801 :       return object_type_p (type1);
   14191              : 
   14192          162 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   14193          162 :       return pointer_interconvertible_base_of_p (type1, type2);
   14194              : 
   14195        11063 :     case CPTK_IS_POD:
   14196        11063 :       return pod_type_p (type1);
   14197              : 
   14198       145158 :     case CPTK_IS_POINTER:
   14199       145158 :       return TYPE_PTR_P (type1);
   14200              : 
   14201          281 :     case CPTK_IS_POLYMORPHIC:
   14202          281 :       return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
   14203              : 
   14204       675648 :     case CPTK_IS_REFERENCE:
   14205       675648 :       return type_code1 == REFERENCE_TYPE;
   14206              : 
   14207      2471809 :     case CPTK_IS_SAME:
   14208      2471809 :       return same_type_p (type1, type2);
   14209              : 
   14210          373 :     case CPTK_IS_SCOPED_ENUM:
   14211          373 :       return SCOPED_ENUM_P (type1);
   14212              : 
   14213        60181 :     case CPTK_IS_STD_LAYOUT:
   14214        60181 :       return std_layout_type_p (type1);
   14215              : 
   14216        56246 :     case CPTK_IS_TRIVIAL:
   14217        56246 :       return trivial_type_p (type1);
   14218              : 
   14219        11866 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   14220        11866 :       return is_trivially_xible (MODIFY_EXPR, type1, type2);
   14221              : 
   14222        71328 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14223        71328 :       return is_trivially_xible (INIT_EXPR, type1, type2);
   14224              : 
   14225        95903 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   14226        95903 :       return trivially_copyable_p (type1);
   14227              : 
   14228        26107 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   14229        26107 :       return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14230              : 
   14231        93970 :     case CPTK_IS_UNBOUNDED_ARRAY:
   14232        93970 :       return array_of_unknown_bound_p (type1);
   14233              : 
   14234       257199 :     case CPTK_IS_UNION:
   14235       257199 :       return type_code1 == UNION_TYPE;
   14236              : 
   14237          731 :     case CPTK_IS_VIRTUAL_BASE_OF:
   14238          665 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14239         1379 :               && lookup_base (type2, type1, ba_require_virtual,
   14240              :                               NULL, tf_none) != NULL_TREE);
   14241              : 
   14242       577364 :     case CPTK_IS_VOLATILE:
   14243       577364 :       return CP_TYPE_VOLATILE_P (type1);
   14244              : 
   14245       210603 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14246       210603 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
   14247              : 
   14248        51963 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14249        51963 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
   14250              : 
   14251           85 :     case CPTK_IS_DEDUCIBLE:
   14252           85 :       return type_targs_deducible_from (type1, type2);
   14253              : 
   14254          161 :     case CPTK_IS_STRUCTURAL:
   14255          161 :       return structural_type_p (type1);
   14256              : 
   14257              :     /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
   14258              :        are handled in finish_trait_expr.  */
   14259            0 :     case CPTK_RANK:
   14260            0 :     case CPTK_TYPE_ORDER:
   14261            0 :     case CPTK_STRUCTURED_BINDING_SIZE:
   14262            0 :       gcc_unreachable ();
   14263              : 
   14264              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14265              :     case CPTK_##CODE:
   14266              : #include "cp-trait.def"
   14267              : #undef DEFTRAIT_TYPE
   14268              :       /* Type-yielding traits are handled in finish_trait_type.  */
   14269              :       break;
   14270              :     }
   14271              : 
   14272            0 :   gcc_unreachable ();
   14273              : }
   14274              : 
   14275              : /* Returns true if TYPE meets the requirements for the specified KIND,
   14276              :    false otherwise.
   14277              : 
   14278              :    When KIND == 1, TYPE must be an array of unknown bound,
   14279              :    or (possibly cv-qualified) void, or a complete type.
   14280              : 
   14281              :    When KIND == 2, TYPE must be a complete type, or array of complete type,
   14282              :    or (possibly cv-qualified) void.
   14283              : 
   14284              :    When KIND == 3:
   14285              :    If TYPE is a non-union class type, it must be complete.
   14286              : 
   14287              :    When KIND == 4:
   14288              :    If TYPE is a class type, it must be complete.  */
   14289              : 
   14290              : static bool
   14291     17845927 : check_trait_type (tree type, int kind = 1)
   14292              : {
   14293     17845927 :   if (type == NULL_TREE)
   14294              :     return true;
   14295              : 
   14296     17845927 :   if (TREE_CODE (type) == TREE_VEC)
   14297              :     {
   14298      5830908 :       for (tree arg : tree_vec_range (type))
   14299      2551741 :         if (!check_trait_type (arg, kind))
   14300           21 :           return false;
   14301      3279167 :       return true;
   14302              :     }
   14303              : 
   14304     14566739 :   if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   14305              :     return true; // Array of unknown bound. Don't care about completeness.
   14306              : 
   14307     14566161 :   if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
   14308              :     return true; // Not a non-union class type. Don't care about completeness.
   14309              : 
   14310     14455228 :   if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
   14311              :     return true; // Not a class type. Don't care about completeness.
   14312              : 
   14313     14454743 :   if (VOID_TYPE_P (type))
   14314              :     return true;
   14315              : 
   14316     14453594 :   type = complete_type (strip_array_types (type));
   14317     14453594 :   if (!COMPLETE_TYPE_P (type)
   14318          152 :       && cxx_incomplete_type_diagnostic (NULL_TREE, type,
   14319              :                                          diagnostics::kind::permerror)
   14320     14453746 :       && !flag_permissive)
   14321              :     return false;
   14322              :   return true;
   14323              : }
   14324              : 
   14325              : /* True iff the conversion (if any) would be a direct reference
   14326              :    binding, not requiring complete types.  This is LWG2939.  */
   14327              : 
   14328              : static bool
   14329      6521891 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
   14330              : {
   14331      6521891 :   tree from, to;
   14332      6521891 :   switch (kind)
   14333              :     {
   14334              :       /* These put the target type first.  */
   14335              :     case CPTK_IS_CONSTRUCTIBLE:
   14336              :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14337              :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14338              :     case CPTK_IS_INVOCABLE:
   14339              :     case CPTK_IS_NOTHROW_INVOCABLE:
   14340              :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14341              :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14342              :       to = type1;
   14343              :       from = type2;
   14344              :       break;
   14345              : 
   14346              :       /* These put it second.  */
   14347      2976160 :     case CPTK_IS_CONVERTIBLE:
   14348      2976160 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14349      2976160 :       to = type2;
   14350      2976160 :       from = type1;
   14351      2976160 :       break;
   14352              : 
   14353            0 :     default:
   14354            0 :       gcc_unreachable ();
   14355              :     }
   14356              : 
   14357      6521891 :   if (TREE_CODE (to) != REFERENCE_TYPE || !from)
   14358              :     return false;
   14359       866202 :   if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
   14360        59315 :     from = TREE_VEC_ELT (from, 0);
   14361       866202 :   return (TYPE_P (from)
   14362      1723564 :           && (same_type_ignoring_top_level_qualifiers_p
   14363       857362 :               (non_reference (to), non_reference (from))));
   14364              : }
   14365              : 
   14366              : /* Helper for finish_trait_expr and tsubst_expr.  Handle
   14367              :    CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
   14368              :    way.  */
   14369              : 
   14370              : tree
   14371          273 : finish_structured_binding_size (location_t loc, tree type,
   14372              :                                 tsubst_flags_t complain)
   14373              : {
   14374          273 :   if (TYPE_REF_P (type))
   14375              :     {
   14376          105 :       if (complain & tf_error)
   14377           99 :         error_at (loc, "%qs argument %qT is a reference",
   14378              :                   "__builtin_structured_binding_size", type);
   14379          105 :       return error_mark_node;
   14380              :     }
   14381          168 :   HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
   14382          168 :   if (ret == -1)
   14383           63 :     return error_mark_node;
   14384          105 :   return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
   14385              : }
   14386              : 
   14387              : /* Process a trait expression.  */
   14388              : 
   14389              : tree
   14390     20194164 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
   14391              : {
   14392     20194164 :   if (type1 == error_mark_node
   14393     20194161 :       || type2 == error_mark_node)
   14394              :     return error_mark_node;
   14395              : 
   14396     20194161 :   if (processing_template_decl)
   14397              :     {
   14398      3244195 :       tree trait_expr = make_node (TRAIT_EXPR);
   14399      3244195 :       if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
   14400        30521 :         TREE_TYPE (trait_expr) = size_type_node;
   14401      3213674 :       else if (kind == CPTK_TYPE_ORDER)
   14402              :         {
   14403         3900 :           tree val = type_order_value (type1, type1);
   14404         3900 :           if (val != error_mark_node)
   14405         3900 :             TREE_TYPE (trait_expr) = TREE_TYPE (val);
   14406              :         }
   14407              :       else
   14408      3209774 :         TREE_TYPE (trait_expr) = boolean_type_node;
   14409      3244195 :       TRAIT_EXPR_TYPE1 (trait_expr) = type1;
   14410      3244195 :       TRAIT_EXPR_TYPE2 (trait_expr) = type2;
   14411      3244195 :       TRAIT_EXPR_KIND (trait_expr) = kind;
   14412      3244195 :       TRAIT_EXPR_LOCATION (trait_expr) = loc;
   14413      3244195 :       return trait_expr;
   14414              :     }
   14415              : 
   14416     16949966 :   switch (kind)
   14417              :     {
   14418        54653 :     case CPTK_HAS_NOTHROW_ASSIGN:
   14419        54653 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   14420        54653 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   14421        54653 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   14422        54653 :     case CPTK_HAS_NOTHROW_COPY:
   14423        54653 :     case CPTK_HAS_TRIVIAL_COPY:
   14424        54653 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   14425        54653 :     case CPTK_IS_DESTRUCTIBLE:
   14426        54653 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   14427        54653 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   14428        54653 :       if (!check_trait_type (type1))
   14429           21 :         return error_mark_node;
   14430              :       break;
   14431              : 
   14432       281644 :     case CPTK_IS_LITERAL_TYPE:
   14433       281644 :     case CPTK_IS_POD:
   14434       281644 :     case CPTK_IS_STD_LAYOUT:
   14435       281644 :     case CPTK_IS_TRIVIAL:
   14436       281644 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   14437       281644 :     case CPTK_IS_STRUCTURAL:
   14438       281644 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   14439       281644 :       if (!check_trait_type (type1, /* kind = */ 2))
   14440           33 :         return error_mark_node;
   14441              :       break;
   14442              : 
   14443       264059 :     case CPTK_IS_ABSTRACT:
   14444       264059 :     case CPTK_IS_EMPTY:
   14445       264059 :     case CPTK_IS_POLYMORPHIC:
   14446       264059 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   14447       264059 :       if (!check_trait_type (type1, /* kind = */ 3))
   14448           15 :         return error_mark_node;
   14449              :       break;
   14450              : 
   14451              :     /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
   14452              :        type to know whether an array is an aggregate, so use kind=4 here.  */
   14453       415433 :     case CPTK_IS_AGGREGATE:
   14454       415433 :     case CPTK_IS_FINAL:
   14455       415433 :     case CPTK_IS_IMPLICIT_LIFETIME:
   14456       415433 :       if (!check_trait_type (type1, /* kind = */ 4))
   14457           17 :         return error_mark_node;
   14458              :       break;
   14459              : 
   14460      6521891 :     case CPTK_IS_CONSTRUCTIBLE:
   14461      6521891 :     case CPTK_IS_CONVERTIBLE:
   14462      6521891 :     case CPTK_IS_INVOCABLE:
   14463      6521891 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14464      6521891 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14465      6521891 :     case CPTK_IS_NOTHROW_INVOCABLE:
   14466      6521891 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14467      6521891 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14468      6521891 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14469      6521891 :       /* Don't check completeness for direct reference binding.  */;
   14470      6521891 :       if (same_type_ref_bind_p (kind, type1, type2))
   14471              :         break;
   14472      7139218 :       gcc_fallthrough ();
   14473              : 
   14474      7139218 :     case CPTK_IS_ASSIGNABLE:
   14475      7139218 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   14476      7139218 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   14477      7139218 :       if (!check_trait_type (type1)
   14478      7139218 :           || !check_trait_type (type2))
   14479           63 :         return error_mark_node;
   14480              :       break;
   14481              : 
   14482       484036 :     case CPTK_IS_BASE_OF:
   14483       484036 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   14484       483931 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14485       465819 :           && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
   14486       923402 :           && !complete_type_or_else (type2, NULL_TREE))
   14487              :         /* We already issued an error.  */
   14488            3 :         return error_mark_node;
   14489              :       break;
   14490              : 
   14491          734 :     case CPTK_IS_VIRTUAL_BASE_OF:
   14492          668 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14493         1385 :           && !complete_type_or_else (type2, NULL_TREE))
   14494              :         /* We already issued an error.  */
   14495            3 :         return error_mark_node;
   14496              :       break;
   14497              : 
   14498              :     case CPTK_IS_ARRAY:
   14499              :     case CPTK_IS_BOUNDED_ARRAY:
   14500              :     case CPTK_IS_CLASS:
   14501              :     case CPTK_IS_CONST:
   14502              :     case CPTK_IS_ENUM:
   14503              :     case CPTK_IS_FUNCTION:
   14504              :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   14505              :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   14506              :     case CPTK_IS_MEMBER_POINTER:
   14507              :     case CPTK_IS_OBJECT:
   14508              :     case CPTK_IS_POINTER:
   14509              :     case CPTK_IS_REFERENCE:
   14510              :     case CPTK_IS_SAME:
   14511              :     case CPTK_IS_SCOPED_ENUM:
   14512              :     case CPTK_IS_UNBOUNDED_ARRAY:
   14513              :     case CPTK_IS_UNION:
   14514              :     case CPTK_IS_VOLATILE:
   14515              :       break;
   14516              : 
   14517              :     case CPTK_RANK:
   14518              :       {
   14519              :         size_t rank = 0;
   14520          122 :         for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
   14521           80 :           ++rank;
   14522           42 :         return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
   14523              :                                          loc);
   14524              :       }
   14525              : 
   14526          346 :     case CPTK_TYPE_ORDER:
   14527          346 :       return maybe_wrap_with_location (type_order_value (type1, type2), loc);
   14528              : 
   14529          144 :     case CPTK_STRUCTURED_BINDING_SIZE:
   14530          144 :       return finish_structured_binding_size (loc, type1, tf_warning_or_error);
   14531              : 
   14532          222 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   14533          222 :       if (!array_of_unknown_bound_p (type1)
   14534          205 :           && TREE_CODE (type1) != VOID_TYPE
   14535          420 :           && !complete_type_or_else (type1, NULL_TREE))
   14536              :         /* We already issued an error.  */
   14537            6 :         return error_mark_node;
   14538          216 :       if (!array_of_unknown_bound_p (type2)
   14539          191 :           && TREE_CODE (type2) != VOID_TYPE
   14540          400 :           && !complete_type_or_else (type2, NULL_TREE))
   14541              :         /* We already issued an error.  */
   14542            3 :         return error_mark_node;
   14543              :       break;
   14544              : 
   14545           85 :     case CPTK_IS_DEDUCIBLE:
   14546           85 :       if (!DECL_TYPE_TEMPLATE_P (type1))
   14547              :         {
   14548            0 :           error ("%qD is not a class or alias template", type1);
   14549            0 :           return error_mark_node;
   14550              :         }
   14551              :       break;
   14552              : 
   14553              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14554              :     case CPTK_##CODE:
   14555              : #include "cp-trait.def"
   14556              : #undef DEFTRAIT_TYPE
   14557              :       /* Type-yielding traits are handled in finish_trait_type.  */
   14558            0 :       gcc_unreachable ();
   14559              :     }
   14560              : 
   14561     16949270 :   tree val = (trait_expr_value (kind, type1, type2)
   14562     16949270 :               ? boolean_true_node : boolean_false_node);
   14563     16949270 :   return maybe_wrap_with_location (val, loc);
   14564              : }
   14565              : 
   14566              : /* Process a trait type.  */
   14567              : 
   14568              : tree
   14569      7502817 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
   14570              :                    tsubst_flags_t complain)
   14571              : {
   14572      7502817 :   if (type1 == error_mark_node
   14573      7502814 :       || type2 == error_mark_node)
   14574              :     return error_mark_node;
   14575              : 
   14576      7502814 :   if (processing_template_decl)
   14577              :     {
   14578       223864 :       tree type = cxx_make_type (TRAIT_TYPE);
   14579       223864 :       TRAIT_TYPE_TYPE1 (type) = type1;
   14580       223864 :       TRAIT_TYPE_TYPE2 (type) = type2;
   14581       223864 :       TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
   14582              :       /* These traits are intended to be used in the definition of the ::type
   14583              :          member of the corresponding standard library type trait and aren't
   14584              :          mangleable (and thus won't appear directly in template signatures),
   14585              :          so structural equality should suffice.  */
   14586       223864 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   14587       223864 :       return type;
   14588              :     }
   14589              : 
   14590      7278950 :   switch (kind)
   14591              :     {
   14592      1173803 :     case CPTK_ADD_LVALUE_REFERENCE:
   14593              :       /* [meta.trans.ref].  */
   14594      1173803 :       if (referenceable_type_p (type1))
   14595      1173722 :         return cp_build_reference_type (type1, /*rval=*/false);
   14596              :       return type1;
   14597              : 
   14598       604173 :     case CPTK_ADD_POINTER:
   14599              :       /* [meta.trans.ptr].  */
   14600       604173 :       if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
   14601              :         {
   14602       604141 :           if (TYPE_REF_P (type1))
   14603       603014 :             type1 = TREE_TYPE (type1);
   14604       604141 :           return build_pointer_type (type1);
   14605              :         }
   14606              :       return type1;
   14607              : 
   14608      1582520 :     case CPTK_ADD_RVALUE_REFERENCE:
   14609              :       /* [meta.trans.ref].  */
   14610      1582520 :       if (referenceable_type_p (type1))
   14611      1582462 :         return cp_build_reference_type (type1, /*rval=*/true);
   14612              :       return type1;
   14613              : 
   14614       230190 :     case CPTK_DECAY:
   14615       230190 :       if (TYPE_REF_P (type1))
   14616        41192 :         type1 = TREE_TYPE (type1);
   14617              : 
   14618       230190 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14619          688 :         return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
   14620          688 :                                   complain);
   14621       229502 :       else if (TREE_CODE (type1) == FUNCTION_TYPE)
   14622          202 :         return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
   14623              :       else
   14624       229300 :         return cv_unqualified (type1);
   14625              : 
   14626          219 :     case CPTK_REMOVE_ALL_EXTENTS:
   14627          219 :       return strip_array_types (type1);
   14628              : 
   14629       940009 :     case CPTK_REMOVE_CV:
   14630       940009 :       return cv_unqualified (type1);
   14631              : 
   14632       423499 :     case CPTK_REMOVE_CVREF:
   14633       423499 :       if (TYPE_REF_P (type1))
   14634       165303 :         type1 = TREE_TYPE (type1);
   14635       423499 :       return cv_unqualified (type1);
   14636              : 
   14637        64163 :     case CPTK_REMOVE_EXTENT:
   14638        64163 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14639         9123 :         type1 = TREE_TYPE (type1);
   14640              :       return type1;
   14641              : 
   14642        42791 :     case CPTK_REMOVE_POINTER:
   14643        42791 :       if (TYPE_PTR_P (type1))
   14644        40062 :         type1 = TREE_TYPE (type1);
   14645              :       return type1;
   14646              : 
   14647      2064026 :     case CPTK_REMOVE_REFERENCE:
   14648      2064026 :       if (TYPE_REF_P (type1))
   14649      1249583 :         type1 = TREE_TYPE (type1);
   14650              :       return type1;
   14651              : 
   14652       106980 :     case CPTK_TYPE_PACK_ELEMENT:
   14653       106980 :       return finish_type_pack_element (type1, type2, complain);
   14654              : 
   14655        46577 :     case CPTK_UNDERLYING_TYPE:
   14656        46577 :       return finish_underlying_type (type1);
   14657              : 
   14658              : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
   14659              :     case CPTK_##CODE:
   14660              : #include "cp-trait.def"
   14661              : #undef DEFTRAIT_EXPR
   14662              :       /* Expression-yielding traits are handled in finish_trait_expr.  */
   14663              :     case CPTK_BASES:
   14664              :     case CPTK_DIRECT_BASES:
   14665              :       /* BASES and DIRECT_BASES are handled in finish_bases.  */
   14666              :       break;
   14667              :     }
   14668              : 
   14669            0 :   gcc_unreachable ();
   14670              : }
   14671              : 
   14672              : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
   14673              :    which is ignored for C++.  */
   14674              : 
   14675              : void
   14676            0 : set_float_const_decimal64 (void)
   14677              : {
   14678            0 : }
   14679              : 
   14680              : void
   14681            0 : clear_float_const_decimal64 (void)
   14682              : {
   14683            0 : }
   14684              : 
   14685              : bool
   14686      1903319 : float_const_decimal64_p (void)
   14687              : {
   14688      1903319 :   return 0;
   14689              : }
   14690              : 
   14691              : 
   14692              : /* Return true if T designates the implied `this' parameter.  */
   14693              : 
   14694              : bool
   14695      6128043 : is_this_parameter (tree t)
   14696              : {
   14697      6128043 :   if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
   14698              :     return false;
   14699      3649731 :   gcc_assert (TREE_CODE (t) == PARM_DECL
   14700              :               || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
   14701              :               || (cp_binding_oracle && VAR_P (t)));
   14702              :   return true;
   14703              : }
   14704              : 
   14705              : /* As above, or a C++23 explicit object parameter.  */
   14706              : 
   14707              : bool
   14708          456 : is_object_parameter (tree t)
   14709              : {
   14710          456 :   if (is_this_parameter (t))
   14711              :     return true;
   14712           91 :   if (TREE_CODE (t) != PARM_DECL)
   14713              :     return false;
   14714           34 :   tree ctx = DECL_CONTEXT (t);
   14715           34 :   return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
   14716           62 :           && t == DECL_ARGUMENTS (ctx));
   14717              : }
   14718              : 
   14719              : /* Insert the deduced return type for an auto function.  */
   14720              : 
   14721              : void
   14722       933093 : apply_deduced_return_type (tree fco, tree return_type)
   14723              : {
   14724       933093 :   tree result;
   14725              : 
   14726       933093 :   if (return_type == error_mark_node)
   14727              :     return;
   14728              : 
   14729       933090 :   if (DECL_CONV_FN_P (fco))
   14730           42 :     DECL_NAME (fco) = make_conv_op_name (return_type);
   14731              : 
   14732       933090 :   TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
   14733              : 
   14734       933090 :   maybe_update_postconditions (fco);
   14735              : 
   14736              :   /* Apply the type to the result object.  */
   14737              : 
   14738       933090 :   result = DECL_RESULT (fco);
   14739       933090 :   if (result == NULL_TREE)
   14740              :     return;
   14741       921352 :   if (TREE_TYPE (result) == return_type)
   14742              :     return;
   14743              : 
   14744       921346 :   if (!processing_template_decl && !VOID_TYPE_P (return_type)
   14745      1709995 :       && !complete_type_or_else (return_type, NULL_TREE))
   14746              :     return;
   14747              : 
   14748              :   /* We already have a DECL_RESULT from start_preparsed_function.
   14749              :      Now we need to redo the work it and allocate_struct_function
   14750              :      did to reflect the new type.  */
   14751       921349 :   result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
   14752       921349 :                        TYPE_MAIN_VARIANT (return_type));
   14753       921349 :   DECL_ARTIFICIAL (result) = 1;
   14754       921349 :   DECL_IGNORED_P (result) = 1;
   14755       921349 :   cp_apply_type_quals_to_decl (cp_type_quals (return_type),
   14756              :                                result);
   14757       921349 :   DECL_RESULT (fco) = result;
   14758              : 
   14759       921349 :   if (!uses_template_parms (fco))
   14760       921349 :     if (function *fun = DECL_STRUCT_FUNCTION (fco))
   14761              :       {
   14762       920403 :         bool aggr = aggregate_value_p (result, fco);
   14763              : #ifdef PCC_STATIC_STRUCT_RETURN
   14764              :         fun->returns_pcc_struct = aggr;
   14765              : #endif
   14766       920403 :         fun->returns_struct = aggr;
   14767              :       }
   14768              : }
   14769              : 
   14770              : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
   14771              :    this is a right unary fold. Otherwise it is a left unary fold. */
   14772              : 
   14773              : static tree
   14774       780736 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
   14775              : {
   14776              :   /* Build a pack expansion (assuming expr has pack type).  */
   14777       780736 :   if (!uses_parameter_packs (expr))
   14778              :     {
   14779            3 :       error_at (location_of (expr), "operand of fold expression has no "
   14780              :                 "unexpanded parameter packs");
   14781            3 :       return error_mark_node;
   14782              :     }
   14783       780733 :   tree pack = make_pack_expansion (expr);
   14784              : 
   14785              :   /* Build the fold expression.  */
   14786       780733 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14787       780733 :   tree fold = build_min_nt_loc (loc, dir, code, pack);
   14788       780733 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14789       780733 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14790       780733 :                                                     FOLD_EXPR_OP (fold),
   14791       780733 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14792       780733 :   return fold;
   14793              : }
   14794              : 
   14795              : tree
   14796        19485 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
   14797              : {
   14798        19485 :   return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
   14799              : }
   14800              : 
   14801              : tree
   14802       761251 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
   14803              : {
   14804       761251 :   return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
   14805              : }
   14806              : 
   14807              : /* Build a binary fold expression over EXPR1 and EXPR2. The
   14808              :    associativity of the fold is determined by EXPR1 and EXPR2 (whichever
   14809              :    has an unexpanded parameter pack). */
   14810              : 
   14811              : static tree
   14812       186249 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
   14813              :                          int op, tree_code dir)
   14814              : {
   14815       186249 :   pack = make_pack_expansion (pack);
   14816       186249 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14817       186249 :   tree fold = build_min_nt_loc (loc, dir, code, pack, init);
   14818       186249 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14819       186249 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14820       186249 :                                                     FOLD_EXPR_OP (fold),
   14821       186249 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14822       186249 :   return fold;
   14823              : }
   14824              : 
   14825              : tree
   14826       186249 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
   14827              : {
   14828              :   // Determine which expr has an unexpanded parameter pack and
   14829              :   // set the pack and initial term.
   14830       186249 :   bool pack1 = uses_parameter_packs (expr1);
   14831       186249 :   bool pack2 = uses_parameter_packs (expr2);
   14832       186249 :   if (pack1 && !pack2)
   14833          817 :     return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
   14834       185432 :   else if (pack2 && !pack1)
   14835       185432 :     return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
   14836              :   else
   14837              :     {
   14838            0 :       if (pack1)
   14839            0 :         error ("both arguments in binary fold have unexpanded parameter packs");
   14840              :       else
   14841            0 :         error ("no unexpanded parameter packs in binary fold");
   14842              :     }
   14843            0 :   return error_mark_node;
   14844              : }
   14845              : 
   14846              : /* Finish __builtin_launder (arg).  */
   14847              : 
   14848              : tree
   14849        13460 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
   14850              : {
   14851        13460 :   tree orig_arg = arg;
   14852        13460 :   if (!type_dependent_expression_p (arg))
   14853           84 :     arg = decay_conversion (arg, complain);
   14854        13460 :   if (error_operand_p (arg))
   14855            0 :     return error_mark_node;
   14856        13460 :   if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
   14857              :     {
   14858           24 :       error_at (loc, "type %qT of argument to %<__builtin_launder%> "
   14859           24 :                 "is not a pointer to object type", TREE_TYPE (arg));
   14860           24 :       return error_mark_node;
   14861              :     }
   14862        13436 :   if (processing_template_decl)
   14863        13376 :     arg = orig_arg;
   14864        13436 :   return build_call_expr_internal_loc (loc, IFN_LAUNDER,
   14865        26872 :                                        TREE_TYPE (arg), 1, arg);
   14866              : }
   14867              : 
   14868              : /* Finish __builtin_convertvector (arg, type).  */
   14869              : 
   14870              : tree
   14871          312 : cp_build_vec_convert (tree arg, location_t loc, tree type,
   14872              :                       tsubst_flags_t complain)
   14873              : {
   14874          312 :   if (error_operand_p (type))
   14875            9 :     return error_mark_node;
   14876          303 :   if (error_operand_p (arg))
   14877            0 :     return error_mark_node;
   14878              : 
   14879          303 :   tree ret = NULL_TREE;
   14880          303 :   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
   14881          295 :     ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
   14882              :                                decay_conversion (arg, complain),
   14883              :                                loc, type, (complain & tf_error) != 0);
   14884              : 
   14885          303 :   if (!processing_template_decl)
   14886              :     return ret;
   14887              : 
   14888           50 :   return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
   14889              : }
   14890              : 
   14891              : /* Finish __builtin_bit_cast (type, arg).  */
   14892              : 
   14893              : tree
   14894       279525 : cp_build_bit_cast (location_t loc, tree type, tree arg,
   14895              :                    tsubst_flags_t complain)
   14896              : {
   14897       279525 :   if (error_operand_p (type))
   14898            0 :     return error_mark_node;
   14899       279525 :   if (!dependent_type_p (type))
   14900              :     {
   14901       203030 :       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
   14902            9 :         return error_mark_node;
   14903       203021 :       if (TREE_CODE (type) == ARRAY_TYPE)
   14904              :         {
   14905              :           /* std::bit_cast for destination ARRAY_TYPE is not possible,
   14906              :              as functions may not return an array, so don't bother trying
   14907              :              to support this (and then deal with VLAs etc.).  */
   14908            9 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14909              :                          "is an array type", type);
   14910            9 :           return error_mark_node;
   14911              :         }
   14912       203012 :       if (!trivially_copyable_p (type))
   14913              :         {
   14914           18 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14915              :                          "is not trivially copyable", type);
   14916           18 :           return error_mark_node;
   14917              :         }
   14918       202994 :       if (consteval_only_p (type) || consteval_only_p (arg))
   14919              :         {
   14920            8 :           error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
   14921              :                          "consteval-only types");
   14922            8 :           return error_mark_node;
   14923              :         }
   14924              :     }
   14925              : 
   14926       279481 :   if (error_operand_p (arg))
   14927            0 :     return error_mark_node;
   14928              : 
   14929       279481 :   if (!type_dependent_expression_p (arg))
   14930              :     {
   14931       109814 :       if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
   14932              :         {
   14933              :           /* Don't perform array-to-pointer conversion.  */
   14934           39 :           arg = mark_rvalue_use (arg, loc, true);
   14935           39 :           if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
   14936            0 :             return error_mark_node;
   14937              :         }
   14938              :       else
   14939       109775 :         arg = decay_conversion (arg, complain);
   14940              : 
   14941       109814 :       if (error_operand_p (arg))
   14942           12 :         return error_mark_node;
   14943              : 
   14944       109802 :       if (!trivially_copyable_p (TREE_TYPE (arg)))
   14945              :         {
   14946            9 :           error_at (cp_expr_loc_or_loc (arg, loc),
   14947              :                     "%<__builtin_bit_cast%> source type %qT "
   14948            9 :                     "is not trivially copyable", TREE_TYPE (arg));
   14949            9 :           return error_mark_node;
   14950              :         }
   14951       109793 :       if (!dependent_type_p (type)
   14952       182781 :           && !cp_tree_equal (TYPE_SIZE_UNIT (type),
   14953        72988 :                              TYPE_SIZE_UNIT (TREE_TYPE (arg))))
   14954              :         {
   14955           18 :           error_at (loc, "%<__builtin_bit_cast%> source size %qE "
   14956              :                          "not equal to destination type size %qE",
   14957           18 :                          TYPE_SIZE_UNIT (TREE_TYPE (arg)),
   14958           18 :                          TYPE_SIZE_UNIT (type));
   14959           18 :           return error_mark_node;
   14960              :         }
   14961              :     }
   14962              : 
   14963       279442 :   tree ret = build_min (BIT_CAST_EXPR, type, arg);
   14964       279442 :   SET_EXPR_LOCATION (ret, loc);
   14965              : 
   14966       279442 :   if (!processing_template_decl && CLASS_TYPE_P (type))
   14967          300 :     ret = get_target_expr (ret, complain);
   14968              : 
   14969              :   return ret;
   14970              : }
   14971              : 
   14972              : /* Diagnose invalid #pragma GCC unroll argument and adjust
   14973              :    it if needed.  */
   14974              : 
   14975              : tree
   14976        23317 : cp_check_pragma_unroll (location_t loc, tree unroll)
   14977              : {
   14978        23317 :   HOST_WIDE_INT lunroll = 0;
   14979        23317 :   if (type_dependent_expression_p (unroll))
   14980              :     ;
   14981        46562 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
   14982        46516 :            || (!value_dependent_expression_p (unroll)
   14983        23205 :                && (!tree_fits_shwi_p (unroll)
   14984        23179 :                    || (lunroll = tree_to_shwi (unroll)) < 0
   14985        23164 :                    || lunroll >= USHRT_MAX)))
   14986              :     {
   14987           90 :       error_at (loc, "%<#pragma GCC unroll%> requires an"
   14988              :                 " assignment-expression that evaluates to a non-negative"
   14989              :                 " integral constant less than %u", USHRT_MAX);
   14990           90 :       unroll = integer_one_node;
   14991              :     }
   14992        23191 :   else if (TREE_CODE (unroll) == INTEGER_CST)
   14993              :     {
   14994        23161 :       unroll = fold_convert (integer_type_node, unroll);
   14995        23161 :       if (integer_zerop (unroll))
   14996           12 :         unroll = integer_one_node;
   14997              :     }
   14998        23317 :   return unroll;
   14999              : }
   15000              : 
   15001              : #include "gt-cp-semantics.h"
        

Generated by: LCOV version 2.4-beta

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