LCOV - code coverage report
Current view: top level - gcc/cp - semantics.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.1 % 7402 6966
Test Date: 2026-05-30 15:37:04 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  23155201601 : push_deferring_access_checks (deferring_kind deferring)
     146              : {
     147              :   /* For context like template instantiation, access checking
     148              :      disabling applies to all nested context.  */
     149  23155201601 :   if (deferred_access_no_check || deferring == dk_no_check)
     150    296059483 :     deferred_access_no_check++;
     151              :   else
     152              :     {
     153  22859142118 :       deferred_access e = {NULL, deferring};
     154  22859142118 :       vec_safe_push (deferred_access_stack, e);
     155              :     }
     156  23155201601 : }
     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    361826514 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
     163              : {
     164    361826514 :   push_deferring_access_checks (dk_deferred);
     165    361826514 :   if (!deferred_access_no_check)
     166    355062584 :     deferred_access_stack->last().deferred_access_checks = checks;
     167    361826514 : }
     168              : 
     169              : /* Resume deferring access checks again after we stopped doing
     170              :    this previously.  */
     171              : 
     172              : void
     173    177291419 : resume_deferring_access_checks (void)
     174              : {
     175    177291419 :   if (!deferred_access_no_check)
     176    177271110 :     deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
     177    177291419 : }
     178              : 
     179              : /* Stop deferring access checks.  */
     180              : 
     181              : void
     182    497619620 : stop_deferring_access_checks (void)
     183              : {
     184    497619620 :   if (!deferred_access_no_check)
     185    497559411 :     deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
     186    497619620 : }
     187              : 
     188              : /* Discard the current deferred access checks and restore the
     189              :    previous states.  */
     190              : 
     191              : void
     192  14348041810 : pop_deferring_access_checks (void)
     193              : {
     194  14348041810 :   if (deferred_access_no_check)
     195    226294710 :     deferred_access_no_check--;
     196              :   else
     197  14121747100 :     deferred_access_stack->pop ();
     198  14348041810 : }
     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   1226957433 : get_deferred_access_checks (void)
     207              : {
     208   1226957433 :   if (deferred_access_no_check)
     209              :     return NULL;
     210              :   else
     211   1213564022 :     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   8807024677 : pop_to_parent_deferring_access_checks (void)
     220              : {
     221   8807024677 :   if (deferred_access_no_check)
     222     69764767 :     deferred_access_no_check--;
     223              :   else
     224              :     {
     225   8737259910 :       vec<deferred_access_check, va_gc> *checks;
     226   8737259910 :       deferred_access *ptr;
     227              : 
     228   8737259910 :       checks = (deferred_access_stack->last ().deferred_access_checks);
     229              : 
     230   8737259910 :       deferred_access_stack->pop ();
     231   8737259910 :       ptr = &deferred_access_stack->last ();
     232   8737259910 :       if (ptr->deferring_access_checks_kind == dk_no_deferred)
     233              :         {
     234              :           /* Check access.  */
     235    551012949 :           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   8383635551 :           FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     244              :             {
     245    107393500 :               FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
     246              :                 {
     247      9639981 :                   if (probe->binfo == chk->binfo &&
     248      7652787 :                       probe->decl == chk->decl &&
     249       941540 :                       probe->diag_decl == chk->diag_decl)
     250       940776 :                     goto found;
     251              :                 }
     252              :               /* Insert into parent's checks.  */
     253     97753519 :               vec_safe_push (ptr->deferred_access_checks, *chk);
     254     98694295 :             found:;
     255              :             }
     256              :         }
     257              :     }
     258   8807024677 : }
     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    391680378 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
     334              :                 tsubst_flags_t complain, access_failure_info *afi = NULL)
     335              : {
     336    391680378 :   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
     337              : 
     338    391680378 :   if (flag_new_inheriting_ctors
     339    496838119 :       && 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        59602 :       decl = strip_inheriting_ctors (decl);
     345        59602 :       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
     346              :                                    ba_any, NULL, complain);
     347              :     }
     348              : 
     349    391680378 :   tree cs = current_scope ();
     350    391680378 :   if (in_template_context
     351    391680378 :       && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
     352     40777894 :     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     40540968 :         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    351139410 :   if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     382              :     {
     383        21726 :       if (flag_new_inheriting_ctors)
     384        21696 :         diag_decl = strip_inheriting_ctors (diag_decl);
     385        21726 :       if (complain & tf_error)
     386              :         {
     387         1151 :           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         1151 :           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         1151 :           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         1151 :           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         1151 :           complain_about_access (decl, diag_decl, diag_location, true,
     413              :                                  access_failure_reason);
     414              :         }
     415        21726 :       if (afi)
     416          412 :         afi->record_access_failure (basetype_path, decl, diag_decl);
     417        21726 :       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   1045924462 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
     431              :                        tsubst_flags_t complain)
     432              : {
     433   1045924462 :   int i;
     434   1045924462 :   deferred_access_check *chk;
     435   1045924462 :   location_t loc = input_location;
     436   1045924462 :   bool ok = true;
     437              : 
     438   1045924462 :   if (!checks)
     439              :     return true;
     440              : 
     441    123053046 :   FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     442              :     {
     443     68502650 :       input_location = chk->loc;
     444     68502650 :       ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
     445              :     }
     446              : 
     447     54550396 :   input_location = loc;
     448     54550396 :   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    274392843 : perform_deferred_access_checks (tsubst_flags_t complain)
     469              : {
     470    274392843 :   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    589686470 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
     480              :                                tsubst_flags_t complain,
     481              :                                access_failure_info *afi)
     482              : {
     483    589686470 :   int i;
     484    589686470 :   deferred_access *ptr;
     485    589686470 :   deferred_access_check *chk;
     486              : 
     487              :   /* Exit if we are in a context that no access checking is performed.  */
     488    589686470 :   if (deferred_access_no_check)
     489              :     return true;
     490              : 
     491    565776909 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     492              : 
     493    565776909 :   ptr = &deferred_access_stack->last ();
     494              : 
     495              :   /* If we are not supposed to defer access checks, just check now.  */
     496    565776909 :   if (ptr->deferring_access_checks_kind == dk_no_deferred)
     497              :     {
     498    323177728 :       bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
     499    495385005 :       return (complain & tf_error) ? true : ok;
     500              :     }
     501              : 
     502              :   /* See if we are already going to perform this check.  */
     503    295541050 :   FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
     504              :     {
     505     69710288 :       if (chk->decl == decl && chk->binfo == binfo &&
     506     16769296 :           chk->diag_decl == diag_decl)
     507              :         {
     508              :           return true;
     509              :         }
     510              :     }
     511              :   /* If not, record the check.  */
     512    225830762 :   deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
     513    225830762 :   vec_safe_push (ptr->deferred_access_checks, new_access);
     514              : 
     515    225830762 :   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   1442558993 : stmts_are_full_exprs_p (void)
     524              : {
     525   1442558993 :   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   1251883466 : add_stmt (tree t)
     534              : {
     535   1251883466 :   enum tree_code code = TREE_CODE (t);
     536              : 
     537   1251883466 :   if (EXPR_P (t) && code != LABEL_EXPR)
     538              :     {
     539   1203611269 :       if (!EXPR_HAS_LOCATION (t))
     540    192222441 :         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   1203611269 :       if (STATEMENT_CODE_P (TREE_CODE (t)))
     545    312460429 :         STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
     546              :     }
     547              : 
     548   1251883466 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     549      5375024 :     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   1251883466 :   gcc_checking_assert (!stmt_list_stack->is_empty ());
     554   1251883466 :   append_to_statement_list_force (t, &cur_stmt_list);
     555              : 
     556   1251883466 :   return t;
     557              : }
     558              : 
     559              : /* Returns the stmt_tree to which statements are currently being added.  */
     560              : 
     561              : stmt_tree
     562   7388615201 : current_stmt_tree (void)
     563              : {
     564   7388615201 :   return (cfun
     565   7351646029 :           ? &cfun->language->base.x_stmt_tree
     566   7388615201 :           : &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       290452 : maybe_cleanup_point_expr (tree expr)
     573              : {
     574       290452 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     575       276364 :     expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
     576       290452 :   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    309775132 : maybe_cleanup_point_expr_void (tree expr)
     586              : {
     587    309775132 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     588    102879525 :     expr = fold_build_cleanup_point_expr (void_type_node, expr);
     589    309775132 :   return expr;
     590              : }
     591              : 
     592              : 
     593              : 
     594              : /* Create a declaration statement for the declaration given by the DECL.  */
     595              : 
     596              : void
     597    105127484 : add_decl_expr (tree decl)
     598              : {
     599    105127484 :   tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
     600    105127484 :   if (DECL_INITIAL (decl)
     601    105127484 :       || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
     602     18727204 :     r = maybe_cleanup_point_expr_void (r);
     603    105127484 :   add_stmt (r);
     604    105127484 : }
     605              : 
     606              : /* Set EXPR_LOCATION on one cleanup T to LOC.  */
     607              : 
     608              : static void
     609      5542986 : set_one_cleanup_loc (tree t, location_t loc)
     610              : {
     611      5542986 :   if (!t)
     612              :     return;
     613              : 
     614      5542986 :   if (TREE_CODE (t) != POSTCONDITION_STMT)
     615      5542986 :     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      5542986 :   if (TREE_CODE (t) == NOP_EXPR
     622            0 :       && TREE_TYPE (t) == void_type_node
     623      5542986 :       && 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   1183789029 : set_cleanup_locs (tree stmts, location_t loc)
     631              : {
     632   1189332015 :   if (TREE_CODE (stmts) == CLEANUP_STMT)
     633              :     {
     634      5542986 :       set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
     635      5542986 :       set_cleanup_locs (CLEANUP_BODY (stmts), loc);
     636              :     }
     637   1183789029 :   else if (TREE_CODE (stmts) == STATEMENT_LIST)
     638   1055610090 :     for (tree stmt : tsi_range (stmts))
     639    817706702 :       set_cleanup_locs (stmt, loc);
     640   1183789029 : }
     641              : 
     642              : /* True iff the innermost block scope is a try block.  */
     643              : 
     644              : static bool
     645    366082327 : at_try_scope ()
     646              : {
     647    366082327 :   cp_binding_level *b = current_binding_level;
     648    366082741 :   while (b && b->kind == sk_cleanup)
     649          414 :     b = b->level_chain;
     650    366082327 :   return b && b->kind == sk_try;
     651              : }
     652              : 
     653              : /* Finish a scope.  */
     654              : 
     655              : tree
     656    366082327 : do_poplevel (tree stmt_list)
     657              : {
     658    366082327 :   tree block = NULL;
     659              : 
     660    366082327 :   bool was_try = at_try_scope ();
     661              : 
     662    366082327 :   if (stmts_are_full_exprs_p ())
     663    366021230 :     block = poplevel (kept_level_p (), 1, 0);
     664              : 
     665              :   /* This needs to come after poplevel merges sk_cleanup statement_lists.  */
     666    366082327 :   maybe_splice_retval_cleanup (stmt_list, was_try);
     667              : 
     668    366082327 :   stmt_list = pop_stmt_list (stmt_list);
     669              : 
     670              :   /* input_location is the last token of the scope, usually a }.  */
     671    366082327 :   set_cleanup_locs (stmt_list, input_location);
     672              : 
     673    366082327 :   if (!processing_template_decl)
     674              :     {
     675    111284313 :       stmt_list = c_build_bind_expr (input_location, block, stmt_list);
     676              :       /* ??? See c_end_compound_stmt re statement expressions.  */
     677              :     }
     678              : 
     679    366082327 :   return stmt_list;
     680              : }
     681              : 
     682              : /* Begin a new scope.  */
     683              : 
     684              : tree
     685    366045909 : do_pushlevel (scope_kind sk)
     686              : {
     687    366045909 :   tree ret = push_stmt_list ();
     688    366045909 :   if (stmts_are_full_exprs_p ())
     689    366021284 :     begin_scope (sk, NULL);
     690    366045909 :   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      5542907 : push_cleanup (tree decl, tree cleanup, bool eh_only)
     700              : {
     701      5542907 :   tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
     702      5542907 :   CLEANUP_EH_ONLY (stmt) = eh_only;
     703      5542907 :   add_stmt (stmt);
     704      5542907 :   CLEANUP_BODY (stmt) = push_stmt_list ();
     705      5542907 : }
     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     17614456 : begin_maybe_infinite_loop (tree cond)
     716              : {
     717              :   /* Only track this while parsing a function, not during instantiation.  */
     718     17614456 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     719      2563148 :                 && !processing_template_decl))
     720              :     return;
     721     15050763 :   bool maybe_infinite = true;
     722     15050763 :   if (cond)
     723              :     {
     724     14752849 :       cond = fold_non_dependent_expr (cond);
     725     14752849 :       maybe_infinite = integer_nonzerop (cond);
     726              :     }
     727     29803612 :   vec_safe_push (cp_function_chain->infinite_loops,
     728     15050763 :                  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      1481343 : break_maybe_infinite_loop (void)
     736              : {
     737      1481343 :   if (!cfun)
     738              :     return;
     739      1481343 :   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     17614456 : end_maybe_infinite_loop (tree cond)
     747              : {
     748     17614456 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     749      2563148 :                 && !processing_template_decl))
     750              :     return;
     751     15050763 :   tree current = cp_function_chain->infinite_loops->pop();
     752     15050763 :   if (current != NULL_TREE)
     753              :     {
     754      4835487 :       cond = fold_non_dependent_expr (cond);
     755      4835487 :       if (integer_nonzerop (cond))
     756       303034 :         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     84315142 : begin_cond (tree *cond_p)
     767              : {
     768     84315142 :   if (processing_template_decl)
     769     60263641 :     *cond_p = push_stmt_list ();
     770     84315142 : }
     771              : 
     772              : /* Finish such a conditional.  */
     773              : 
     774              : static void
     775     84315142 : finish_cond (tree *cond_p, tree expr)
     776              : {
     777     84315142 :   if (processing_template_decl)
     778              :     {
     779     60263641 :       tree cond = pop_stmt_list (*cond_p);
     780              : 
     781     60263641 :       if (expr == NULL_TREE)
     782              :         /* Empty condition in 'for'.  */
     783       277771 :         gcc_assert (empty_expr_stmt_p (cond));
     784     59985870 :       else if (check_for_bare_parameter_packs (expr))
     785            0 :         expr = error_mark_node;
     786     59985870 :       else if (!empty_expr_stmt_p (cond))
     787       904008 :         expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
     788              :     }
     789     84315142 :   *cond_p = expr;
     790     84315142 : }
     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     11901902 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
     809              : {
     810     11901902 :   if (!TREE_SIDE_EFFECTS (*body_p))
     811     11892451 :     return;
     812              : 
     813         9451 :   gcc_assert (!processing_template_decl);
     814         9451 :   *prep_p = *body_p;
     815         9451 :   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         9451 :   current_binding_level->keep = true;
     840         9451 :   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         9451 :   if (tsi_end_p (iter))
     847           91 :     *body_p = NULL_TREE;
     848              :   else
     849         9360 :     *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         9451 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
     862              : {
     863         9451 :   *prep_p = do_poplevel (*prep_p);
     864         9451 :   gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
     865         9451 :   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         9433 :   tree stmt_list = BIND_EXPR_BODY (*prep_p);
     872         9433 :   gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
     873         9433 :   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         9342 :   tree_stmt_iterator iter = tsi_start (stmt_list);
     893         9538 :   while (tsi_stmt (iter) != *body_p)
     894          196 :     tsi_next (&iter);
     895         9342 :   *body_p = tsi_split_stmt_list (input_location, iter);
     896              : }
     897              : 
     898              : /* Finish a goto-statement.  */
     899              : 
     900              : tree
     901         2710 : finish_goto_stmt (tree destination)
     902              : {
     903         2710 :   if (identifier_p (destination))
     904         2573 :     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         2710 :   if (TREE_CODE (destination) == LABEL_DECL)
     909         2573 :     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         2701 :   add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
     926              : 
     927         2701 :   tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
     928         2701 :   check_goto (&TREE_OPERAND (stmt, 0));
     929              : 
     930         2701 :   return add_stmt (stmt);
     931              : }
     932              : 
     933              : /* Returns true if T corresponds to an assignment operator expression.  */
     934              : 
     935              : static bool
     936       874285 : is_assignment_op_expr_p (tree t)
     937              : {
     938       874285 :   if (t == NULL_TREE)
     939              :     return false;
     940              : 
     941       874285 :   if (TREE_CODE (t) == MODIFY_EXPR
     942       874285 :       || (TREE_CODE (t) == MODOP_EXPR
     943          336 :           && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
     944              :     return true;
     945              : 
     946       873598 :   tree call = extract_call_expr (t);
     947       873598 :   if (call == NULL_TREE
     948       129136 :       || call == error_mark_node
     949      1002734 :       || !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     86254687 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
    1019              :                                        tsubst_flags_t complain)
    1020              : {
    1021     86254687 :   tree type = TREE_TYPE (t);
    1022     86254687 :   t = STRIP_REFERENCE_REF (t);
    1023              : 
    1024     86254687 :   if ((complain & tf_warning)
    1025     86195238 :       && warn_parentheses
    1026       874285 :       && 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     86255034 :       && (!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     86254687 : }
    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     51025830 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
    1072              : {
    1073     51025830 :   tree *t = cond;
    1074     51035780 :   while (TREE_CODE (*t) == ANNOTATE_EXPR)
    1075         9950 :     t = &TREE_OPERAND (*t, 0);
    1076              : 
    1077     51025830 :   if (t != cond)
    1078              :     {
    1079         9947 :       m_annotations = *cond;
    1080         9947 :       *cond = *t;
    1081         9947 :       m_inner = t;
    1082              :     }
    1083     51025830 : }
    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     51025830 : annotate_saver::restore (tree new_inner)
    1092              : {
    1093     51025830 :   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         9947 :   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         9947 :   *m_inner = new_inner;
    1118         9947 :   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     89104706 : maybe_convert_cond (tree cond)
    1127              : {
    1128              :   /* Empty conditions remain empty.  */
    1129     89104706 :   if (!cond)
    1130              :     return NULL_TREE;
    1131              : 
    1132              :   /* Wait until we instantiate templates before doing conversion.  */
    1133     88750614 :   if (type_dependent_expression_p (cond))
    1134     37724784 :     return cond;
    1135              : 
    1136              :   /* Strip any ANNOTATE_EXPRs from COND.  */
    1137     51025830 :   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,elemenet} case.  cp_finish_decomp saved the conversion
    1142              :      result in a TARGET_EXPR, pick it up from there.  */
    1143       352193 :   if (DECL_DECOMPOSITION_P (cond)
    1144          224 :       && DECL_DECOMP_IS_BASE (cond)
    1145          224 :       && DECL_DECOMP_BASE (cond)
    1146     51026051 :       && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1147           56 :     cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1148              : 
    1149     51025830 :   if (warn_sequence_point && !processing_template_decl)
    1150       325738 :     verify_sequence_points (cond);
    1151              : 
    1152     51025830 :   maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
    1153              :                                          tf_warning_or_error);
    1154              : 
    1155              :   /* Do the conversion.  */
    1156     51025830 :   cond = convert_from_reference (cond);
    1157     51025830 :   cond = condition_conversion (cond);
    1158              : 
    1159              :   /* Restore any ANNOTATE_EXPRs around COND.  */
    1160     51025830 :   return annotations.restore (cond);
    1161              : }
    1162              : 
    1163              : /* Finish an expression-statement, whose EXPRESSION is as indicated.  */
    1164              : 
    1165              : tree
    1166    159676787 : finish_expr_stmt (tree expr)
    1167              : {
    1168    159676787 :   tree r = NULL_TREE;
    1169    159676787 :   location_t loc = EXPR_LOCATION (expr);
    1170              : 
    1171    159509822 :   if (expr != NULL_TREE)
    1172              :     {
    1173              :       /* If we ran into a problem, make sure we complained.  */
    1174    159676626 :       gcc_assert (expr != error_mark_node || seen_error ());
    1175              : 
    1176    159676626 :       if (!processing_template_decl)
    1177              :         {
    1178     57279370 :           if (warn_sequence_point)
    1179       811756 :             verify_sequence_points (expr);
    1180     57279370 :           expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1181              :         }
    1182    102397256 :       else if (!type_dependent_expression_p (expr))
    1183     22240825 :         convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1184              : 
    1185    159676623 :       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    159676623 :       if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    1192              :         {
    1193    159676444 :           if (TREE_CODE (expr) != EXPR_STMT
    1194    157297519 :               && !STATEMENT_CLASS_P (expr)
    1195    157293368 :               && TREE_CODE (expr) != STATEMENT_LIST)
    1196    157164591 :             expr = build_stmt (loc, EXPR_STMT, expr);
    1197    159676444 :           expr = maybe_cleanup_point_expr_void (expr);
    1198              :         }
    1199              : 
    1200    159676623 :       r = add_stmt (expr);
    1201              :     }
    1202              : 
    1203    159676784 :   return r;
    1204              : }
    1205              : 
    1206              : 
    1207              : /* Begin an if-statement.  Returns a newly created IF_STMT if
    1208              :    appropriate.  */
    1209              : 
    1210              : tree
    1211     71741894 : begin_if_stmt (void)
    1212              : {
    1213     71741894 :   tree r, scope;
    1214     71741894 :   scope = do_pushlevel (sk_cond);
    1215     71741894 :   r = build_stmt (input_location, IF_STMT, NULL_TREE,
    1216              :                   NULL_TREE, NULL_TREE, scope);
    1217     71741894 :   current_binding_level->this_entity = r;
    1218     71741894 :   begin_cond (&IF_COND (r));
    1219     71741894 :   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       252055 : is_std_constant_evaluated_p (tree fn)
    1227              : {
    1228              :   /* std::is_constant_evaluated takes no arguments.  */
    1229       252055 :   if (call_expr_nargs (fn) != 0)
    1230              :     return false;
    1231              : 
    1232        90218 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
    1233        90218 :   if (fndecl == NULL_TREE)
    1234              :     return false;
    1235              : 
    1236        28255 :   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    1237              :                          BUILT_IN_FRONTEND))
    1238              :     return true;
    1239              : 
    1240        28226 :   if (!decl_in_std_namespace_p (fndecl))
    1241              :     return false;
    1242              : 
    1243        12889 :   tree name = DECL_NAME (fndecl);
    1244        12889 :   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      4675941 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
    1252              : {
    1253      4675941 :   tree t = *tp;
    1254              : 
    1255      4675941 :   if (TYPE_P (t) || TREE_CONSTANT (t))
    1256              :     {
    1257       827057 :       *walk_subtrees = false;
    1258       827057 :       return NULL_TREE;
    1259              :     }
    1260              : 
    1261      3848884 :   switch (TREE_CODE (t))
    1262              :     {
    1263       252055 :     case CALL_EXPR:
    1264       252055 :       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     71827467 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
    1284              :                                    bool trivial_infinite)
    1285              : {
    1286     71827467 :   if (!warn_tautological_compare)
    1287              :     return;
    1288              : 
    1289              :   /* Suppress warning for std::is_constant_evaluated if the conditional
    1290              :      comes from a macro.  */
    1291      1428298 :   if (from_macro_expansion_at (EXPR_LOCATION (cond)))
    1292              :     return;
    1293              : 
    1294       602608 :   cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
    1295              :                                           NULL);
    1296       602608 :   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     71741894 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
    1330              : {
    1331     71741894 :   tree cond = maybe_convert_cond (orig_cond);
    1332     71741894 :   maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
    1333              :                                      /*trivial_infinite=*/false);
    1334     71741894 :   if (IF_STMT_CONSTEXPR_P (if_stmt)
    1335     14779633 :       && !type_dependent_expression_p (cond)
    1336      9943053 :       && require_constant_expression (cond)
    1337      9943024 :       && !instantiation_dependent_expression_p (cond)
    1338              :       /* Wait until instantiation time, since only then COND has been
    1339              :          converted to bool.  */
    1340     77086185 :       && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
    1341              :     {
    1342      5344291 :       cond = instantiate_non_dependent_expr (cond);
    1343      5344291 :       cond = cxx_constant_value (cond);
    1344              :     }
    1345     66397603 :   else if (processing_template_decl)
    1346     50004524 :     cond = orig_cond;
    1347     71741894 :   finish_cond (&IF_COND (if_stmt), cond);
    1348     71741894 :   add_stmt (if_stmt);
    1349     71741894 :   THEN_CLAUSE (if_stmt) = push_stmt_list ();
    1350     71741894 :   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     71736975 : finish_then_clause (tree if_stmt)
    1358              : {
    1359     71736975 :   THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
    1360     71736975 :   return if_stmt;
    1361              : }
    1362              : 
    1363              : /* Begin the else-clause of an if-statement.  */
    1364              : 
    1365              : void
    1366     26809401 : begin_else_clause (tree if_stmt)
    1367              : {
    1368     26809401 :   ELSE_CLAUSE (if_stmt) = push_stmt_list ();
    1369     26809401 : }
    1370              : 
    1371              : /* Finish the else-clause of an if-statement, which may be given by
    1372              :    IF_STMT.  */
    1373              : 
    1374              : void
    1375     26809363 : finish_else_clause (tree if_stmt)
    1376              : {
    1377     26809363 :   ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
    1378     26809363 : }
    1379              : 
    1380              : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
    1381              :    read.  */
    1382              : 
    1383              : static tree
    1384    798606426 : maybe_mark_exp_read_r (tree *tp, int *, void *)
    1385              : {
    1386    798606426 :   tree t = *tp;
    1387    798606426 :   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1388     46292551 :     mark_exp_read (t);
    1389    798606426 :   return NULL_TREE;
    1390              : }
    1391              : 
    1392              : /* Finish an if-statement.  */
    1393              : 
    1394              : void
    1395     71736975 : finish_if_stmt (tree if_stmt)
    1396              : {
    1397     71736975 :   tree scope = IF_SCOPE (if_stmt);
    1398     71736975 :   IF_SCOPE (if_stmt) = NULL;
    1399     71736975 :   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     14774714 :       cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
    1405              :                                        maybe_mark_exp_read_r, NULL);
    1406     14774714 :       cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
    1407              :                                        maybe_mark_exp_read_r, NULL);
    1408              :     }
    1409     71736975 :   add_stmt (do_poplevel (scope));
    1410     71736975 : }
    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     17005432 : finish_loop_cond (tree *condp, tree body)
    1421              : {
    1422     17005432 :   if (TREE_CODE (*condp) == INTEGER_CST)
    1423              :     return;
    1424     12242627 :   bool trivially_empty = expr_first (body) == NULL_TREE;
    1425     12242627 :   bool trivial_infinite = false;
    1426     12242627 :   if (trivially_empty)
    1427              :     {
    1428        95869 :       tree c = fold_non_dependent_expr (*condp, tf_none,
    1429              :                                         /*manifestly_const_eval=*/true);
    1430        95869 :       trivial_infinite = c && integer_nonzerop (c);
    1431              :     }
    1432     12242627 :   if (warn_tautological_compare)
    1433              :     {
    1434        85775 :       tree cond = *condp;
    1435        86142 :       while (TREE_CODE (cond) == ANNOTATE_EXPR)
    1436          367 :         cond = TREE_OPERAND (cond, 0);
    1437        85775 :       if (trivial_infinite
    1438        85839 :           && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1439           64 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1440              :                                            /*trivial_infinite=*/true);
    1441        85711 :       else if (!trivially_empty
    1442          375 :                || !processing_template_decl
    1443        86115 :                || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1444        85509 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1445              :                                            /*trivial_infinite=*/false);
    1446              :     }
    1447     12242627 :   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      4662161 : begin_while_stmt (void)
    1459              : {
    1460      4662161 :   tree r;
    1461      4662161 :   r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1462              :                   NULL_TREE, NULL_TREE);
    1463      4662161 :   add_stmt (r);
    1464      4662161 :   WHILE_BODY (r) = do_pushlevel (sk_block);
    1465      4662161 :   begin_cond (&WHILE_COND (r));
    1466      4662161 :   return r;
    1467              : }
    1468              : 
    1469              : /* Process the COND of a while-statement, which may be given by
    1470              :    WHILE_STMT.  */
    1471              : 
    1472              : void
    1473      4662161 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
    1474              :                         tree unroll, bool novector)
    1475              : {
    1476      4662161 :   cond = maybe_convert_cond (cond);
    1477      4662161 :   finish_cond (&WHILE_COND (while_stmt), cond);
    1478      4662161 :   begin_maybe_infinite_loop (cond);
    1479      4662161 :   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      4662161 :   if (unroll && cond != error_mark_node)
    1487        26106 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1488        13053 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1489        13053 :                                       WHILE_COND (while_stmt),
    1490              :                                       build_int_cst (integer_type_node,
    1491              :                                                      annot_expr_unroll_kind),
    1492              :                                       unroll);
    1493      4662161 :   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      4662161 :   adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
    1501              :                          &WHILE_COND_PREP (while_stmt),
    1502              :                          &WHILE_COND_CLEANUP (while_stmt));
    1503      4662161 : }
    1504              : 
    1505              : /* Finish a while-statement, which may be given by WHILE_STMT.  */
    1506              : 
    1507              : void
    1508      4662161 : finish_while_stmt (tree while_stmt)
    1509              : {
    1510      4662161 :   end_maybe_infinite_loop (boolean_true_node);
    1511      4662161 :   if (WHILE_COND_PREP (while_stmt))
    1512         9277 :     finish_loop_cond_prep (&WHILE_BODY (while_stmt),
    1513              :                            &WHILE_COND_PREP (while_stmt),
    1514         9277 :                            WHILE_COND_CLEANUP (while_stmt));
    1515              :   else
    1516      4652884 :     WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
    1517      4662161 :   finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
    1518      4662161 : }
    1519              : 
    1520              : /* Begin a do-statement.  Returns a newly created DO_STMT if
    1521              :    appropriate.  */
    1522              : 
    1523              : tree
    1524      5457622 : begin_do_stmt (void)
    1525              : {
    1526      5457622 :   tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
    1527              :                        NULL_TREE);
    1528      5457622 :   begin_maybe_infinite_loop (boolean_true_node);
    1529      5457622 :   add_stmt (r);
    1530      5457622 :   DO_BODY (r) = push_stmt_list ();
    1531      5457622 :   return r;
    1532              : }
    1533              : 
    1534              : /* Finish the body of a do-statement, which may be given by DO_STMT.  */
    1535              : 
    1536              : void
    1537      5457622 : finish_do_body (tree do_stmt)
    1538              : {
    1539      5457622 :   tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
    1540              : 
    1541      5457622 :   if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
    1542       522433 :     body = STATEMENT_LIST_TAIL (body)->stmt;
    1543              : 
    1544      5457622 :   if (IS_EMPTY_STMT (body))
    1545           30 :     warning (OPT_Wempty_body,
    1546              :             "suggest explicit braces around empty body in %<do%> statement");
    1547      5457622 : }
    1548              : 
    1549              : /* Finish a do-statement, which may be given by DO_STMT, and whose
    1550              :    COND is as indicated.  */
    1551              : 
    1552              : void
    1553      5457622 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
    1554              :                 bool novector)
    1555              : {
    1556      5457622 :   cond = maybe_convert_cond (cond);
    1557      5457622 :   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      5457622 :   if (check_for_bare_parameter_packs (cond))
    1562            3 :     cond = error_mark_node;
    1563      5457622 :   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      5457622 :   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      5457622 :   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      5457622 :   DO_COND (do_stmt) = cond;
    1576      5457622 :   tree do_body = DO_BODY (do_stmt);
    1577      5457592 :   if (CONVERT_EXPR_P (do_body)
    1578           30 :       && integer_zerop (TREE_OPERAND (do_body, 0))
    1579      5457652 :       && VOID_TYPE_P (TREE_TYPE (do_body)))
    1580              :     do_body = NULL_TREE;
    1581      5457622 :   finish_loop_cond (&DO_COND (do_stmt), do_body);
    1582      5457622 : }
    1583              : 
    1584              : /* Finish a return-statement.  The EXPRESSION returned, if any, is as
    1585              :    indicated.  */
    1586              : 
    1587              : tree
    1588    124522979 : finish_return_stmt (tree expr)
    1589              : {
    1590    124522979 :   tree r;
    1591    124522979 :   bool no_warning;
    1592    124522979 :   bool dangling;
    1593              : 
    1594    124522979 :   expr = check_return_expr (expr, &no_warning, &dangling);
    1595              : 
    1596    124522979 :   if (error_operand_p (expr)
    1597    124522979 :       || (flag_openmp && !check_omp_return ()))
    1598              :     {
    1599              :       /* Suppress -Wreturn-type for this function.  */
    1600         1258 :       if (warn_return_type)
    1601         1252 :         suppress_warning (current_function_decl, OPT_Wreturn_type);
    1602         1258 :       return error_mark_node;
    1603              :     }
    1604              : 
    1605    124521721 :   if (!processing_template_decl)
    1606              :     {
    1607     43418085 :       if (warn_sequence_point)
    1608      1022548 :         verify_sequence_points (expr);
    1609              :     }
    1610              : 
    1611    124521721 :   r = build_stmt (input_location, RETURN_EXPR, expr);
    1612    124521721 :   RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
    1613    124521721 :   if (no_warning)
    1614           33 :     suppress_warning (r, OPT_Wreturn_type);
    1615    124521721 :   r = maybe_cleanup_point_expr_void (r);
    1616    124521721 :   r = add_stmt (r);
    1617              : 
    1618    124521721 :   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      7494673 : begin_for_scope (tree *init)
    1627              : {
    1628      7494673 :   tree scope = do_pushlevel (sk_for);
    1629              : 
    1630      7494673 :   if (processing_template_decl)
    1631      5958398 :     *init = push_stmt_list ();
    1632              :   else
    1633      1536275 :     *init = NULL_TREE;
    1634              : 
    1635      7494673 :   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      7239741 : begin_for_stmt (tree scope, tree init)
    1644              : {
    1645      7239741 :   tree r;
    1646              : 
    1647      7239741 :   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      7239741 :   if (scope == NULL_TREE)
    1652              :     {
    1653      1299913 :       gcc_assert (!init);
    1654      1299913 :       scope = begin_for_scope (&init);
    1655              :     }
    1656              : 
    1657      7239741 :   FOR_INIT_STMT (r) = init;
    1658      7239741 :   FOR_SCOPE (r) = scope;
    1659              : 
    1660      7239741 :   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      7239741 : finish_init_stmt (tree for_stmt)
    1668              : {
    1669      7239741 :   if (processing_template_decl)
    1670      5703466 :     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
    1671      7239741 :   add_stmt (for_stmt);
    1672      7239741 :   FOR_BODY (for_stmt) = do_pushlevel (sk_block);
    1673      7239741 :   begin_cond (&FOR_COND (for_stmt));
    1674      7239741 : }
    1675              : 
    1676              : /* Finish the COND of a for-statement, which may be given by
    1677              :    FOR_STMT.  */
    1678              : 
    1679              : void
    1680      7239741 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
    1681              :                  bool novector)
    1682              : {
    1683      7239741 :   cond = maybe_convert_cond (cond);
    1684      7239741 :   finish_cond (&FOR_COND (for_stmt), cond);
    1685      7239741 :   begin_maybe_infinite_loop (cond);
    1686      7239741 :   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      7239741 :   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      7239741 :   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      7239741 :   adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
    1708              :                          &FOR_COND_CLEANUP (for_stmt));
    1709      7239741 : }
    1710              : 
    1711              : /* Finish the increment-EXPRESSION in a for-statement, which may be
    1712              :    given by FOR_STMT.  */
    1713              : 
    1714              : void
    1715      7227481 : finish_for_expr (tree expr, tree for_stmt)
    1716              : {
    1717      7227481 :   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      6787527 :   if (type_unknown_p (expr))
    1722              :     {
    1723            6 :       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
    1724            6 :       expr = error_mark_node;
    1725              :     }
    1726      6787527 :   if (!processing_template_decl)
    1727              :     {
    1728      1465901 :       if (warn_sequence_point)
    1729        14927 :         verify_sequence_points (expr);
    1730      1465901 :       expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
    1731              :                               tf_warning_or_error);
    1732              :     }
    1733      5321626 :   else if (!type_dependent_expression_p (expr))
    1734      1900487 :     convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
    1735      6787527 :   expr = maybe_cleanup_point_expr_void (expr);
    1736      6787527 :   if (check_for_bare_parameter_packs (expr))
    1737            0 :     expr = error_mark_node;
    1738      6787527 :   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      7494786 : find_range_for_decls (tree range_for_decl[3])
    1749              : {
    1750      7494786 :   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     29979144 :   for (int i = 0; i < 3; i++)
    1756              :     {
    1757     22484358 :       tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
    1758     22484358 :       if (IDENTIFIER_BINDING (id)
    1759     22484358 :           && IDENTIFIER_BINDING (id)->scope == current_binding_level)
    1760              :         {
    1761       259798 :           range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
    1762       259798 :           gcc_assert (VAR_P (range_for_decl[i])
    1763              :                       && DECL_ARTIFICIAL (range_for_decl[i]));
    1764              :         }
    1765              :     }
    1766      7494786 : }
    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      7494673 : finish_for_stmt (tree for_stmt)
    1775              : {
    1776      7494673 :   end_maybe_infinite_loop (boolean_true_node);
    1777              : 
    1778      7494673 :   if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
    1779       254932 :     RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
    1780              :   else
    1781              :     {
    1782      7239741 :       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      7239567 :         FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
    1788      7239741 :       if (FOR_COND (for_stmt))
    1789      6885649 :         finish_loop_cond (&FOR_COND (for_stmt),
    1790      6885649 :                           FOR_EXPR (for_stmt) ? integer_one_node
    1791       137681 :                                               : FOR_BODY (for_stmt));
    1792              :     }
    1793              : 
    1794              :   /* Pop the scope for the body of the loop.  */
    1795      7494673 :   tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
    1796      7494673 :                      ? &RANGE_FOR_SCOPE (for_stmt)
    1797      7239741 :                      : &FOR_SCOPE (for_stmt));
    1798      7494673 :   tree scope = *scope_ptr;
    1799      7494673 :   *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      7494673 :   tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
    1806      7494673 :   find_range_for_decls (range_for_decl);
    1807              : 
    1808      7494673 :   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      7494673 :   if (!stmts_are_full_exprs_p ())
    1813        12260 :     return;
    1814              : 
    1815     29929652 :   for (int i = 0; i < 3; i++)
    1816     22447239 :     if (range_for_decl[i])
    1817       259682 :       DECL_NAME (range_for_decl[i])
    1818       259682 :         = 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       254932 : begin_range_for_stmt (tree scope, tree init)
    1828              : {
    1829       254932 :   begin_maybe_infinite_loop (boolean_false_node);
    1830              : 
    1831       254932 :   tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
    1832              :                        NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
    1833              : 
    1834       254932 :   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       254932 :   RANGE_FOR_INIT_STMT (r) = init;
    1842       254932 :   RANGE_FOR_SCOPE (r) = scope;
    1843              : 
    1844       254932 :   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       254932 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
    1853              : {
    1854       254932 :   if (processing_template_decl)
    1855       509864 :     RANGE_FOR_INIT_STMT (range_for_stmt)
    1856       509864 :       = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
    1857       254932 :   RANGE_FOR_DECL (range_for_stmt) = decl;
    1858       254932 :   RANGE_FOR_EXPR (range_for_stmt) = expr;
    1859       254932 :   add_stmt (range_for_stmt);
    1860       254932 :   RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
    1861       254932 : }
    1862              : 
    1863              : /* Begin the scope of an expansion-statement.  */
    1864              : 
    1865              : tree
    1866         1446 : begin_template_for_scope (tree *init)
    1867              : {
    1868         1446 :   tree scope = do_pushlevel (sk_template_for);
    1869              : 
    1870         1446 :   if (processing_template_decl)
    1871          419 :     *init = push_stmt_list ();
    1872              :   else
    1873         1027 :     *init = NULL_TREE;
    1874              : 
    1875         1446 :   return scope;
    1876              : }
    1877              : 
    1878              : /* Finish a break-statement.  */
    1879              : 
    1880              : tree
    1881      4655544 : 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      4655544 :   if (!block_may_fallthru (cur_stmt_list))
    1891          711 :     return void_node;
    1892      4654833 :   note_break_stmt ();
    1893      4654833 :   return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
    1894              : }
    1895              : 
    1896              : /* Finish a continue-statement.  */
    1897              : 
    1898              : tree
    1899       225871 : finish_continue_stmt (void)
    1900              : {
    1901       225871 :   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       671346 : begin_switch_stmt (void)
    1909              : {
    1910       671346 :   tree r, scope;
    1911              : 
    1912       671346 :   scope = do_pushlevel (sk_cond);
    1913       671346 :   r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1914              :                   scope, NULL_TREE);
    1915              : 
    1916       671346 :   begin_cond (&SWITCH_STMT_COND (r));
    1917              : 
    1918       671346 :   return r;
    1919              : }
    1920              : 
    1921              : /* Finish the cond of a switch-statement.  */
    1922              : 
    1923              : void
    1924       671346 : finish_switch_cond (tree cond, tree switch_stmt)
    1925              : {
    1926       671346 :   tree orig_type = NULL;
    1927              : 
    1928       671346 :   if (!processing_template_decl)
    1929              :     {
    1930              :       /* Convert the condition to an integer or enumeration type.  */
    1931       261000 :       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,elemenet} 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       261054 :           && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1940           18 :         cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1941       261000 :       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
    1942       261000 :       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       261000 :       orig_type = unlowered_expr_type (cond);
    1950       261000 :       if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
    1951       183456 :         orig_type = TREE_TYPE (cond);
    1952       261000 :       if (cond != error_mark_node)
    1953              :         {
    1954              :           /* [stmt.switch]
    1955              : 
    1956              :              Integral promotions are performed.  */
    1957       260967 :           cond = perform_integral_promotions (cond);
    1958       260967 :           cond = maybe_cleanup_point_expr (cond);
    1959              :         }
    1960              :     }
    1961       671346 :   if (check_for_bare_parameter_packs (cond))
    1962            0 :     cond = error_mark_node;
    1963       671346 :   else if (!processing_template_decl && warn_sequence_point)
    1964         2776 :     verify_sequence_points (cond);
    1965              : 
    1966       671346 :   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
    1967       671346 :   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
    1968       671346 :   add_stmt (switch_stmt);
    1969       671346 :   push_switch (switch_stmt);
    1970       671346 :   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
    1971       671346 : }
    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       671346 : finish_switch_stmt (tree switch_stmt)
    1978              : {
    1979       671346 :   tree scope;
    1980              : 
    1981      1342692 :   SWITCH_STMT_BODY (switch_stmt) =
    1982       671346 :     pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
    1983       671346 :   pop_switch ();
    1984              : 
    1985       671346 :   scope = SWITCH_STMT_SCOPE (switch_stmt);
    1986       671346 :   SWITCH_STMT_SCOPE (switch_stmt) = NULL;
    1987       671346 :   add_stmt (do_poplevel (scope));
    1988       671346 : }
    1989              : 
    1990              : /* Begin a try-block.  Returns a newly-created TRY_BLOCK if
    1991              :    appropriate.  */
    1992              : 
    1993              : tree
    1994      1141225 : begin_try_block (void)
    1995              : {
    1996      1141225 :   tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
    1997      1141225 :   add_stmt (r);
    1998      1141225 :   TRY_STMTS (r) = push_stmt_list ();
    1999      1141225 :   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         1684 : begin_function_try_block (tree *compound_stmt)
    2008              : {
    2009         1684 :   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         1684 :   *compound_stmt = begin_compound_stmt (0);
    2013         1684 :   current_binding_level->artificial = 1;
    2014         1684 :   r = begin_try_block ();
    2015         1684 :   FN_TRY_BLOCK_P (r) = 1;
    2016         1684 :   return r;
    2017              : }
    2018              : 
    2019              : /* Finish a try-block, which may be given by TRY_BLOCK.  */
    2020              : 
    2021              : void
    2022      1141225 : finish_try_block (tree try_block)
    2023              : {
    2024      1141225 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2025      1141225 :   TRY_HANDLERS (try_block) = push_stmt_list ();
    2026      1141225 : }
    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         1684 : finish_function_try_block (tree try_block)
    2051              : {
    2052         1684 :   finish_try_block (try_block);
    2053              :   /* FIXME : something queer about CTOR_INITIALIZER somehow following
    2054              :      the try block, but moving it inside.  */
    2055         1684 :   in_function_try_handler = 1;
    2056         1684 : }
    2057              : 
    2058              : /* Finish a handler-sequence for a try-block, which may be given by
    2059              :    TRY_BLOCK.  */
    2060              : 
    2061              : void
    2062      1141225 : finish_handler_sequence (tree try_block)
    2063              : {
    2064      1141225 :   TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
    2065      1141225 :   check_handlers (TRY_HANDLERS (try_block));
    2066      1141225 : }
    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         1684 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
    2074              : {
    2075         1684 :   in_function_try_handler = 0;
    2076         1684 :   finish_handler_sequence (try_block);
    2077         1684 :   finish_compound_stmt (compound_stmt);
    2078         1684 : }
    2079              : 
    2080              : /* Begin a handler.  Returns a HANDLER if appropriate.  */
    2081              : 
    2082              : tree
    2083      1590673 : begin_handler (void)
    2084              : {
    2085      1590673 :   tree r;
    2086              : 
    2087      1590673 :   r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
    2088      1590673 :   add_stmt (r);
    2089              : 
    2090              :   /* Create a binding level for the eh_info and the exception object
    2091              :      cleanup.  */
    2092      1590673 :   HANDLER_BODY (r) = do_pushlevel (sk_catch);
    2093              : 
    2094      1590673 :   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      1590673 : finish_handler_parms (tree decl, tree handler)
    2103              : {
    2104      1590673 :   tree type = NULL_TREE;
    2105      1590673 :   if (processing_template_decl)
    2106              :     {
    2107      1451772 :       if (decl)
    2108              :         {
    2109       472653 :           decl = pushdecl (decl);
    2110       472653 :           decl = push_template_decl (decl);
    2111       472653 :           HANDLER_PARMS (handler) = decl;
    2112       472653 :           type = TREE_TYPE (decl);
    2113              :         }
    2114              :     }
    2115              :   else
    2116              :     {
    2117       138901 :       type = expand_start_catch_block (decl);
    2118       138901 :       if (warn_catch_value
    2119         2118 :           && type != NULL_TREE
    2120          711 :           && type != error_mark_node
    2121       139612 :           && !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      1590673 :   HANDLER_TYPE (handler) = type;
    2143      1590673 : }
    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      1590673 : finish_handler (tree handler)
    2150              : {
    2151      1590673 :   if (!processing_template_decl)
    2152       138901 :     expand_end_catch_block ();
    2153      1590673 :   HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
    2154      1590673 : }
    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    277550516 : begin_compound_stmt (unsigned int flags)
    2165              : {
    2166    277550516 :   tree r;
    2167              : 
    2168    277550516 :   if (flags & BCS_NO_SCOPE)
    2169              :     {
    2170      5228525 :       r = push_stmt_list ();
    2171      5228525 :       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      5228525 :       keep_next_level (false);
    2178              :     }
    2179              :   else
    2180              :     {
    2181    272321991 :       scope_kind sk = sk_block;
    2182    272321991 :       if (flags & BCS_TRY_BLOCK)
    2183              :         sk = sk_try;
    2184    271180886 :       else if (flags & BCS_TRANSACTION)
    2185              :         sk = sk_transaction;
    2186    271180651 :       else if (flags & BCS_STMT_EXPR)
    2187        29082 :         sk = sk_stmt_expr;
    2188    272321991 :       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    277550516 :   if (processing_template_decl)
    2198              :     {
    2199    186863595 :       r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
    2200    186863595 :       BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
    2201    186863595 :       BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
    2202    186863595 :       TREE_SIDE_EFFECTS (r) = 1;
    2203              :     }
    2204              : 
    2205    277550516 :   return r;
    2206              : }
    2207              : 
    2208              : /* Finish a compound-statement, which is given by STMT.  */
    2209              : 
    2210              : void
    2211    277550477 : finish_compound_stmt (tree stmt)
    2212              : {
    2213    277550477 :   if (TREE_CODE (stmt) == BIND_EXPR)
    2214              :     {
    2215    186863595 :       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    186863595 :       if (TREE_CODE (body) == STATEMENT_LIST
    2220    170939013 :           && STATEMENT_LIST_HEAD (body) == NULL
    2221     11370906 :           && !BIND_EXPR_BODY_BLOCK (stmt)
    2222    197732145 :           && !BIND_EXPR_TRY_BLOCK (stmt))
    2223              :         stmt = body;
    2224              :       else
    2225    175995142 :         BIND_EXPR_BODY (stmt) = body;
    2226              :     }
    2227     90686882 :   else if (STATEMENT_LIST_NO_SCOPE (stmt))
    2228      5192053 :     stmt = pop_stmt_list (stmt);
    2229              :   else
    2230              :     {
    2231              :       /* Destroy any ObjC "super" receivers that may have been
    2232              :          created.  */
    2233     85494829 :       objc_clear_super_receiver ();
    2234              : 
    2235     85494829 :       stmt = do_poplevel (stmt);
    2236              :     }
    2237              : 
    2238              :   /* ??? See c_end_compound_stmt wrt statement expressions.  */
    2239    277550477 :   add_stmt (stmt);
    2240    277550477 : }
    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        53765 : finish_asm_string_expression (location_t loc, tree string)
    2248              : {
    2249        53765 :   if (string == error_mark_node
    2250        53752 :       || 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        26015 : 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        26015 :   tree r;
    2277        26015 :   tree t;
    2278        26015 :   int ninputs = list_length (input_operands);
    2279        26015 :   int noutputs = list_length (output_operands);
    2280              : 
    2281        26015 :   if (!processing_template_decl)
    2282              :     {
    2283        12362 :       const char *constraint;
    2284        12362 :       const char **oconstraints;
    2285        12362 :       bool allows_mem, allows_reg, is_inout;
    2286        12362 :       tree operand;
    2287        12362 :       int i;
    2288              : 
    2289        12362 :       oconstraints = XALLOCAVEC (const char *, noutputs);
    2290              : 
    2291        24622 :       string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
    2292              :                                              string);
    2293        12362 :       if (string == error_mark_node)
    2294          109 :         return error_mark_node;
    2295        36804 :       for (int i = 0; i < 2; ++i)
    2296        84422 :         for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
    2297              :           {
    2298        35350 :             tree s = TREE_VALUE (TREE_PURPOSE (t));
    2299        70682 :             s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2300        35350 :             if (s == error_mark_node)
    2301              :               return error_mark_node;
    2302        35320 :             TREE_VALUE (TREE_PURPOSE (t)) = s;
    2303              :           }
    2304        17706 :       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        12253 :       string = resolve_asm_operand_names (string, output_operands,
    2312              :                                           input_operands, labels);
    2313              : 
    2314        30700 :       for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
    2315              :         {
    2316        18447 :           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        18447 :           STRIP_NOPS (operand);
    2325              : 
    2326        18447 :           operand = mark_lvalue_use (operand);
    2327              : 
    2328        18447 :           if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
    2329            9 :             operand = error_mark_node;
    2330              : 
    2331        18447 :           if (operand != error_mark_node
    2332        18447 :               && (TREE_READONLY (operand)
    2333        18432 :                   || CP_TYPE_CONST_P (TREE_TYPE (operand))
    2334              :                   /* Functions are not modifiable, even though they are
    2335              :                      lvalues.  */
    2336        18432 :                   || 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        18432 :                   || (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        18454 :           while (TREE_CODE (*op) == COMPOUND_EXPR)
    2345            7 :             op = &TREE_OPERAND (*op, 1);
    2346        18447 :           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        18447 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2359        18447 :           oconstraints[i] = constraint;
    2360              : 
    2361        18447 :           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        18438 :               if (!allows_reg && !cxx_mark_addressable (*op))
    2368            0 :                 operand = error_mark_node;
    2369        18438 :               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        18426 :           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        18447 :           TREE_VALUE (t) = operand;
    2415              :         }
    2416              : 
    2417        29121 :       for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
    2418              :         {
    2419        16868 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2420        16868 :           bool constraint_parsed
    2421        16868 :             = 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        16868 :           if (constraint_parsed && !allows_reg && allows_mem)
    2427          307 :             operand = mark_lvalue_use (TREE_VALUE (t));
    2428              :           else
    2429        16561 :             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        16868 :           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        16868 :           if (constraint_parsed)
    2444              :             {
    2445              :               /* If the operand is going to end up in memory,
    2446              :                  mark it addressable.  */
    2447        16847 :               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          307 :                   STRIP_NOPS (operand);
    2452              : 
    2453          307 :                   tree *op = &operand;
    2454          314 :                   while (TREE_CODE (*op) == COMPOUND_EXPR)
    2455            7 :                     op = &TREE_OPERAND (*op, 1);
    2456          307 :                   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          307 :                   if (!cxx_mark_addressable (*op))
    2469            0 :                     operand = error_mark_node;
    2470              :                 }
    2471        16540 :               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        16847 :               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        16847 :               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        16868 :           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        16751 :           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        16868 :           TREE_VALUE (t) = operand;
    2551              :         }
    2552              :     }
    2553              : 
    2554        25906 :   r = build_stmt (loc, ASM_EXPR, string,
    2555              :                   output_operands, input_operands,
    2556              :                   clobbers, labels);
    2557        25906 :   ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
    2558        25906 :   ASM_INLINE_P (r) = inline_p;
    2559        25906 :   if (toplev_p)
    2560              :     {
    2561           99 :       symtab->finalize_toplevel_asm (r);
    2562           99 :       return r;
    2563              :     }
    2564        25807 :   r = maybe_cleanup_point_expr_void (r);
    2565        25807 :   return add_stmt (r);
    2566              : }
    2567              : 
    2568              : /* Finish a label with the indicated NAME.  Returns the new label.  */
    2569              : 
    2570              : tree
    2571         2478 : finish_label_stmt (tree name)
    2572              : {
    2573         2478 :   tree decl = define_label (input_location, name);
    2574              : 
    2575         2478 :   if (decl == error_mark_node)
    2576              :     return error_mark_node;
    2577              : 
    2578         2472 :   add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
    2579              : 
    2580         2472 :   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      3371550 : finish_decl_cleanup (tree decl, tree cleanup)
    2603              : {
    2604      3371550 :   push_cleanup (decl, cleanup, false);
    2605      3371550 : }
    2606              : 
    2607              : /* If the current scope exits with an exception, run CLEANUP.  */
    2608              : 
    2609              : void
    2610      2162322 : finish_eh_cleanup (tree cleanup)
    2611              : {
    2612      2162322 :   push_cleanup (NULL, cleanup, true);
    2613      2162322 : }
    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     19879272 : 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     19879272 :   mem_inits = nreverse (mem_inits);
    2625              : 
    2626     19879272 :   if (processing_template_decl)
    2627              :     {
    2628              :       tree mem;
    2629              : 
    2630     33670671 :       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     19939251 :           if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
    2638     19939251 :               && check_for_bare_parameter_packs (TREE_VALUE (mem)))
    2639            3 :             TREE_VALUE (mem) = error_mark_node;
    2640              :         }
    2641              : 
    2642     13731420 :       add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
    2643              :                                   CTOR_INITIALIZER, mem_inits));
    2644              :     }
    2645              :   else
    2646      6147852 :     emit_mem_initializers (mem_inits);
    2647     19879272 : }
    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     43445670 : force_paren_expr (tree expr, bool even_uneval /* = false */)
    2655              : {
    2656              :   /* This is only needed for decltype(auto) in C++14.  */
    2657     43445670 :   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     42807642 :   if (cp_unevaluated_operand && !even_uneval)
    2663              :     return expr;
    2664              : 
    2665     35724859 :   if (TREE_CODE (expr) == COMPONENT_REF
    2666     35667609 :       || TREE_CODE (expr) == SCOPE_REF
    2667     71386454 :       || REFERENCE_REF_P (expr))
    2668       581956 :     REF_PARENTHESIZED_P (expr) = true;
    2669     35142903 :   else if (DECL_P (tree_strip_any_location_wrapper (expr)))
    2670              :     {
    2671      1721096 :       location_t loc = cp_expr_location (expr);
    2672      1721096 :       const tree_code code = processing_template_decl ? PAREN_EXPR
    2673              :                                                       : VIEW_CONVERT_EXPR;
    2674      1721096 :       expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
    2675      1721096 :       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    936611101 : maybe_undo_parenthesized_ref (tree t)
    2686              : {
    2687    936611101 :   if (cxx_dialect < cxx14)
    2688              :     return t;
    2689              : 
    2690    926612148 :   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
    2691   1028678936 :       && REF_PARENTHESIZED_P (t))
    2692       193299 :     t = TREE_OPERAND (t, 0);
    2693              : 
    2694              :   return t;
    2695              : }
    2696              : 
    2697              : /* Finish a parenthesized expression EXPR.  */
    2698              : 
    2699              : cp_expr
    2700     32619825 : finish_parenthesized_expr (cp_expr expr)
    2701              : {
    2702     32619825 :   if (EXPR_P (expr))
    2703              :     {
    2704              :       /* This inhibits warnings in maybe_warn_unparenthesized_assignment
    2705              :          and c_common_truthvalue_conversion.  */
    2706     64971742 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
    2707              :       /* And maybe_warn_sizeof_array_div.  */
    2708     64971742 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
    2709              :     }
    2710              : 
    2711     32619825 :   if (TREE_CODE (expr) == OFFSET_REF
    2712     32619825 :       || 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        29188 :     PTRMEM_OK_P (expr) = 0;
    2716              : 
    2717     32619825 :   tree stripped_expr = tree_strip_any_location_wrapper (expr);
    2718     32619825 :   if (TREE_CODE (stripped_expr) == STRING_CST)
    2719       848506 :     PAREN_STRING_LITERAL_P (stripped_expr) = 1;
    2720     31771319 :   else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
    2721          928 :     PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
    2722              : 
    2723     32619825 :   expr = cp_expr (force_paren_expr (expr), expr.get_location ());
    2724              : 
    2725     32619825 :   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     75171789 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
    2733              :                                tsubst_flags_t complain /* = tf_warning_or_error */)
    2734              : {
    2735     75171789 :   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
    2736     75171789 :   bool try_omp_private = !object && omp_private_member_map;
    2737     65901121 :   tree ret;
    2738              : 
    2739     65901121 :   if (!object)
    2740              :     {
    2741     65901121 :       tree scope = qualifying_scope;
    2742     65901121 :       if (scope == NULL_TREE)
    2743              :         {
    2744     65889942 :           scope = context_for_name_lookup (decl);
    2745     65889942 :           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     65901118 :       object = maybe_dummy_object (scope, NULL);
    2753              :     }
    2754              : 
    2755     75171786 :   object = maybe_resolve_dummy (object, true);
    2756     75171786 :   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     75171783 :   if (is_dummy_object (object)
    2762        31116 :       && !cp_unevaluated_operand
    2763     75171881 :       && (!processing_template_decl || !current_class_ref))
    2764              :     {
    2765           83 :       if (complain & tf_error)
    2766              :         {
    2767           73 :           auto_diagnostic_group d;
    2768           73 :           if (current_function_decl
    2769           73 :               && DECL_STATIC_FUNCTION_P (current_function_decl))
    2770            3 :             error ("invalid use of member %qD in static member function", decl);
    2771           70 :           else if (current_function_decl
    2772           63 :                    && processing_contract_condition
    2773           70 :                    && DECL_CONSTRUCTOR_P (current_function_decl))
    2774            0 :             error ("invalid use of member %qD in constructor %<pre%> contract", decl);
    2775           70 :           else if (current_function_decl
    2776           63 :                    && processing_contract_condition
    2777           70 :                    && DECL_DESTRUCTOR_P (current_function_decl))
    2778            0 :             error ("invalid use of member %qD in destructor %<post%> contract", decl);
    2779              :           else
    2780           70 :             error ("invalid use of non-static data member %qD", decl);
    2781           73 :           inform (DECL_SOURCE_LOCATION (decl), "declared here");
    2782           73 :         }
    2783              : 
    2784           83 :       return error_mark_node;
    2785              :     }
    2786              : 
    2787     75171700 :   if (current_class_ptr)
    2788     74887958 :     TREE_USED (current_class_ptr) = 1;
    2789     75171700 :   if (processing_template_decl)
    2790              :     {
    2791     60117294 :       tree type = TREE_TYPE (decl);
    2792              : 
    2793     60117294 :       if (TYPE_REF_P (type))
    2794              :         /* Quals on the object don't matter.  */;
    2795     57888485 :       else if (PACK_EXPANSION_P (type))
    2796              :         /* Don't bother trying to represent this.  */
    2797              :         type = NULL_TREE;
    2798     57886057 :       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     57883722 :           int quals = cp_type_quals (TREE_TYPE (object));
    2812              : 
    2813     57883722 :           if (DECL_MUTABLE_P (decl))
    2814       235720 :             quals &= ~TYPE_QUAL_CONST;
    2815              : 
    2816     57883722 :           quals |= cp_type_quals (TREE_TYPE (decl));
    2817     57883722 :           type = cp_build_qualified_type (type, quals);
    2818              :         }
    2819              : 
    2820     60117294 :       if (qualifying_scope)
    2821              :         /* Wrap this in a SCOPE_REF for now.  */
    2822         9205 :         ret = build_qualified_name (type, qualifying_scope, decl,
    2823              :                                     /*template_p=*/false);
    2824              :       else
    2825     60108089 :         ret = (convert_from_reference
    2826     60108089 :                (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     15054406 :       tree access_type = TREE_TYPE (object);
    2833              : 
    2834     15054406 :       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     15054406 :       if (qualifying_scope)
    2841              :         {
    2842         1934 :           tree binfo = NULL_TREE;
    2843         1934 :           object = build_scoped_ref (object, qualifying_scope,
    2844              :                                      &binfo);
    2845              :         }
    2846              : 
    2847     15054406 :       ret = build_class_member_access_expr (object, decl,
    2848              :                                             /*access_path=*/NULL_TREE,
    2849              :                                             /*preserve_reference=*/false,
    2850              :                                             complain);
    2851              :     }
    2852     75171700 :   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   4720788778 : 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   4720788778 :   if (deferred_access_no_check)
    2876              :     return true;
    2877              : 
    2878              :   /* Determine the SCOPE of DECL.  */
    2879   4712883580 :   tree scope = context_for_name_lookup (decl);
    2880              :   /* If the SCOPE is not a type, then DECL is not a member.  */
    2881   4712883580 :   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   4712883580 :       || dependent_type_p (scope))
    2886   4270327315 :     return true;
    2887              : 
    2888    442556265 :   tree qualifying_type = NULL_TREE;
    2889              :   /* Compute the scope through which DECL is being accessed.  */
    2890    442556265 :   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        95750 :       && CLASS_TYPE_P (object_type)
    2900    442651998 :       && 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        95724 :       if (tree open = currently_open_class (object_type))
    2905              :         qualifying_type = open;
    2906              :       else
    2907              :         qualifying_type = object_type;
    2908              :     }
    2909    442460541 :   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    580053861 :       if (DECL_NONSTATIC_MEMBER_P (decl)
    2915    290076924 :           && current_class_ptr)
    2916        40076 :         if (tree current = current_nonlambda_class_type ())
    2917              :           {
    2918        40053 :             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         3569 :             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    152433609 :     qualifying_type = currently_open_derived_class (scope);
    2938              : 
    2939    442461091 :   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    442519781 :       && CLASS_TYPE_P (qualifying_type))
    2943    416191764 :     return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
    2944    416191764 :                                           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     80936116 : 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     80936116 :   gcc_assert (TYPE_P (qualifying_class));
    2967              : 
    2968     80936116 :   if (error_operand_p (expr))
    2969           21 :     return error_mark_node;
    2970              : 
    2971     80936095 :   if (DECL_P (expr)
    2972              :       /* Functions are marked after overload resolution; avoid redundant
    2973              :          warnings.  */
    2974     74040208 :       && TREE_CODE (expr) != FUNCTION_DECL
    2975    154976279 :       && !mark_used (expr, complain))
    2976            0 :     return error_mark_node;
    2977              : 
    2978     80936095 :   if (template_p)
    2979              :     {
    2980       243379 :       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       243370 :         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     80936095 :   if (address_p && done
    2994       156283 :       && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
    2995              :     {
    2996       156281 :       if (TREE_CODE (expr) == SCOPE_REF)
    2997            0 :         expr = TREE_OPERAND (expr, 1);
    2998       156281 :       expr = build_offset_ref (qualifying_class, expr,
    2999              :                                /*address_p=*/true, complain);
    3000       156281 :       return expr;
    3001              :     }
    3002              : 
    3003              :   /* No need to check access within an enum.  */
    3004     80779814 :   if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
    3005      3440522 :       && 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     77339295 :   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     77336655 :   else if (TREE_CODE (expr) == FIELD_DECL)
    3015              :     {
    3016        11179 :       push_deferring_access_checks (dk_no_check);
    3017        11179 :       expr = finish_non_static_data_member (expr, NULL_TREE,
    3018              :                                             qualifying_class, complain);
    3019        11179 :       pop_deferring_access_checks ();
    3020              :     }
    3021     77325476 :   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      6442555 :       if (!shared_member_p (expr)
    3026       415165 :           && current_class_ptr
    3027      6857080 :           && DERIVED_FROM_P (qualifying_class,
    3028              :                              current_nonlambda_class_type ()))
    3029       414305 :         expr = (build_class_member_access_expr
    3030       414305 :                 (maybe_dummy_object (qualifying_class, NULL),
    3031              :                  expr,
    3032       414305 :                  BASELINK_ACCESS_BINFO (expr),
    3033              :                  /*preserve_reference=*/false,
    3034              :                  complain));
    3035      6028250 :       else if (done)
    3036              :         /* The expression is a qualified name whose address is not
    3037              :            being taken.  */
    3038         2500 :         expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
    3039              :                                  complain);
    3040              :     }
    3041     70882921 :   else if (!template_p
    3042     70687238 :            && TREE_CODE (expr) == TEMPLATE_DECL
    3043     70883001 :            && !DECL_FUNCTION_TEMPLATE_P (expr))
    3044              :     {
    3045           80 :       if (complain & tf_error)
    3046            4 :         error ("%qE missing template arguments", expr);
    3047           80 :       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     70882841 :       if (processing_template_decl
    3057     70882841 :           && (!currently_open_class (qualifying_class)
    3058         9970 :               || TREE_CODE (expr) == IDENTIFIER_NODE
    3059         9970 :               || TREE_CODE (expr) == TEMPLATE_ID_EXPR
    3060           82 :               || TREE_CODE (expr) == BIT_NOT_EXPR))
    3061     10693259 :         expr = build_qualified_name (TREE_TYPE (expr),
    3062              :                                      qualifying_class, expr,
    3063              :                                      template_p);
    3064     60189582 :       else if (tree wrap = maybe_get_tls_wrapper_call (expr))
    3065            9 :         expr = wrap;
    3066              : 
    3067     70882841 :       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      5250151 : begin_stmt_expr (void)
    3078              : {
    3079      5250151 :   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        29718 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
    3089              : {
    3090        29718 :   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        29715 :   if (expr)
    3101              :     {
    3102        29700 :       tree type = TREE_TYPE (expr);
    3103              : 
    3104        29700 :       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        29685 :       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        29516 :       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        29485 :           expr = force_rvalue (expr, tf_warning_or_error);
    3131        29485 :           if (error_operand_p (expr))
    3132            0 :             return error_mark_node;
    3133              : 
    3134              :           /* Update for array-to-pointer decay.  */
    3135        29485 :           type = TREE_TYPE (expr);
    3136              : 
    3137              :           /* This TARGET_EXPR will initialize the outer one added by
    3138              :              finish_stmt_expr.  */
    3139        29485 :           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        29485 :           if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    3145        29485 :             expr = maybe_cleanup_point_expr (expr);
    3146        29485 :           add_stmt (expr);
    3147              :         }
    3148              : 
    3149              :       /* The type of the statement-expression is the type of the last
    3150              :          expression.  */
    3151        29685 :       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      5250151 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
    3163              : {
    3164      5250151 :   tree type;
    3165      5250151 :   tree result;
    3166              : 
    3167      5250151 :   if (error_operand_p (stmt_expr))
    3168              :     {
    3169           18 :       pop_stmt_list (stmt_expr);
    3170           18 :       return error_mark_node;
    3171              :     }
    3172              : 
    3173      5250133 :   gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
    3174              : 
    3175      5250133 :   type = TREE_TYPE (stmt_expr);
    3176      5250133 :   result = pop_stmt_list (stmt_expr);
    3177      5250133 :   TREE_TYPE (result) = type;
    3178              : 
    3179      5250133 :   if (processing_template_decl)
    3180              :     {
    3181        36665 :       result = build_min (STMT_EXPR, type, result);
    3182        36665 :       TREE_SIDE_EFFECTS (result) = 1;
    3183        36665 :       STMT_EXPR_NO_SCOPE (result) = has_no_scope;
    3184              :     }
    3185      5213468 :   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     60263813 : empty_expr_stmt_p (tree expr_stmt)
    3221              : {
    3222     60263817 :   tree body = NULL_TREE;
    3223              : 
    3224     60263817 :   if (expr_stmt == void_node)
    3225              :     return true;
    3226              : 
    3227     60263814 :   if (expr_stmt)
    3228              :     {
    3229     60263814 :       if (TREE_CODE (expr_stmt) == EXPR_STMT)
    3230            4 :         body = EXPR_STMT_EXPR (expr_stmt);
    3231     60263810 :       else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
    3232              :         body = expr_stmt;
    3233              :     }
    3234              : 
    3235            4 :   if (body)
    3236              :     {
    3237     59359670 :       if (TREE_CODE (body) == STATEMENT_LIST)
    3238     59359666 :         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     18088867 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
    3251              :                        tsubst_flags_t complain)
    3252              : {
    3253     18088867 :   tree identifier = NULL_TREE;
    3254     18088867 :   tree functions = NULL_TREE;
    3255     18088867 :   tree tmpl_args = NULL_TREE;
    3256     18088867 :   bool template_id = false;
    3257     18088867 :   location_t loc = fn_expr.get_location ();
    3258     18088867 :   tree fn = fn_expr.get_value ();
    3259              : 
    3260     18088867 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3261              : 
    3262     18088867 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    3263              :     {
    3264              :       /* Use a separate flag to handle null args.  */
    3265      3482814 :       template_id = true;
    3266      3482814 :       tmpl_args = TREE_OPERAND (fn, 1);
    3267      3482814 :       fn = TREE_OPERAND (fn, 0);
    3268              :     }
    3269              : 
    3270              :   /* Find the name of the overloaded function.  */
    3271     18088867 :   if (identifier_p (fn))
    3272              :     identifier = fn;
    3273              :   else
    3274              :     {
    3275     25598059 :       functions = fn;
    3276     17903481 :       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     18088867 :   if (!any_type_dependent_arguments_p (args)
    3284     18088867 :       && !any_dependent_template_arguments_p (tmpl_args))
    3285              :     {
    3286     17187179 :       fn = lookup_arg_dependent (identifier, functions, args);
    3287     17187179 :       if (!fn)
    3288              :         {
    3289              :           /* The unqualified name could not be resolved.  */
    3290        57250 :           if (complain & tf_error)
    3291          390 :             fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
    3292              :           else
    3293              :             fn = identifier;
    3294              :         }
    3295              :     }
    3296              : 
    3297     18088867 :   if (fn && template_id && fn != error_mark_node)
    3298      3482801 :     fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
    3299              : 
    3300     18088867 :   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    345858670 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
    3316              :                   bool koenig_p, tsubst_flags_t complain)
    3317              : {
    3318    345858670 :   tree result;
    3319    345858670 :   tree orig_fn;
    3320    345858670 :   vec<tree, va_gc> *orig_args = *args;
    3321    345858670 :   tsubst_flags_t orig_complain = complain;
    3322              : 
    3323    345858670 :   if (fn == error_mark_node)
    3324              :     return error_mark_node;
    3325              : 
    3326    345857655 :   complain &= ~tf_any_viable;
    3327    345857655 :   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    345857655 :   fn = maybe_undo_parenthesized_ref (fn);
    3332              : 
    3333    345857655 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3334              : 
    3335    345857655 :   orig_fn = fn;
    3336              : 
    3337    345857655 :   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    345857649 :   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    229112039 :       if (is_overloaded_fn (fn))
    3349              :         {
    3350    140538697 :           tree ifn = get_first_fn (fn);
    3351    140538697 :           if (TREE_CODE (ifn) == FUNCTION_DECL
    3352    140538697 :               && dependent_local_decl_p (ifn))
    3353        39246 :             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    229112039 :       if (type_dependent_expression_p (fn)
    3360    229112039 :           || any_type_dependent_arguments_p (*args))
    3361              :         {
    3362    207628397 :           if (koenig_p
    3363     10273257 :               && TREE_CODE (orig_fn) == FUNCTION_DECL
    3364    210801559 :               && !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       837609 :             orig_fn = ovl_make (orig_fn, NULL_TREE);
    3370    207628397 :           result = build_min_nt_call_vec (orig_fn, *args);
    3371    282022339 :           SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
    3372    207628397 :           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    207628397 :           suppress_warning (result, OPT_Wpessimizing_move);
    3377              : 
    3378    207628397 :           if (cfun && cp_function_chain && !cp_unevaluated_operand)
    3379              :             {
    3380    181066630 :               bool abnormal = true;
    3381    181288233 :               for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
    3382              :                 {
    3383    100379123 :                   tree fndecl = STRIP_TEMPLATE (*iter);
    3384    100379123 :                   if (TREE_CODE (fndecl) != FUNCTION_DECL
    3385    100379045 :                       || !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    181066630 :               if (abnormal)
    3397     80909110 :                 current_function_returns_abnormally = 1;
    3398              :             }
    3399    207628397 :           if (TREE_CODE (fn) == COMPONENT_REF)
    3400     96405280 :             maybe_generic_this_capture (TREE_OPERAND (fn, 0),
    3401     96405280 :                                         TREE_OPERAND (fn, 1));
    3402    207628397 :           return result;
    3403              :         }
    3404     21483642 :       orig_args = make_tree_vector_copy (*args);
    3405              :     }
    3406              : 
    3407    138229252 :   if (TREE_CODE (fn) == COMPONENT_REF)
    3408              :     {
    3409     28068456 :       tree member = TREE_OPERAND (fn, 1);
    3410     28068456 :       if (BASELINK_P (member))
    3411              :         {
    3412     27887213 :           tree object = TREE_OPERAND (fn, 0);
    3413     55394532 :           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     27887213 :                                         complain);
    3420              :         }
    3421              :     }
    3422              : 
    3423              :   /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'.  */
    3424    110342039 :   if (TREE_CODE (fn) == ADDR_EXPR
    3425    110342039 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
    3426            9 :     fn = TREE_OPERAND (fn, 0);
    3427              : 
    3428    110342039 :   if (is_overloaded_fn (fn))
    3429    102405793 :     fn = baselink_for_fns (fn);
    3430              : 
    3431    110342039 :   result = NULL_TREE;
    3432    110342039 :   if (BASELINK_P (fn))
    3433              :     {
    3434     13617732 :       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     13617732 :       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     13617693 :         object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
    3464              :                                      NULL);
    3465              : 
    3466     15529565 :       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     96724307 :   else if (is_overloaded_fn (fn))
    3474              :     {
    3475              :       /* If the function is an overloaded builtin, resolve it.  */
    3476     88788061 :       if (TREE_CODE (fn) == FUNCTION_DECL
    3477     88788061 :           && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
    3478     18087468 :               || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
    3479      8994190 :         result = resolve_overloaded_builtin (input_location, fn, *args,
    3480              :                                              complain & tf_error);
    3481              : 
    3482      8994190 :       if (!result)
    3483              :         {
    3484     88452659 :           tree alloc_size_attr = NULL_TREE;
    3485     88452659 :           if (warn_calloc_transposed_args
    3486       688024 :               && TREE_CODE (fn) == FUNCTION_DECL
    3487     88452659 :               && (alloc_size_attr
    3488       431031 :                   = lookup_attribute ("alloc_size",
    3489       431031 :                                       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     86764479 :           if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
    3494      1688240 :               && (complain & tf_warning)
    3495      1493433 :               && !vec_safe_is_empty (*args)
    3496     89601741 :               && !processing_template_decl)
    3497              :             {
    3498              :               location_t sizeof_arg_loc[6];
    3499              :               tree sizeof_arg[6];
    3500              :               unsigned int i;
    3501      8243732 :               for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
    3502              :                 {
    3503      3091602 :                   tree t;
    3504              : 
    3505      3091602 :                   sizeof_arg_loc[i] = UNKNOWN_LOCATION;
    3506      3091602 :                   sizeof_arg[i] = NULL_TREE;
    3507      3091602 :                   if (i >= (*args)->length ())
    3508       650521 :                     continue;
    3509      2441081 :                   t = (**args)[i];
    3510      2441081 :                   if (TREE_CODE (t) != SIZEOF_EXPR)
    3511      2434432 :                     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      1030474 :               if (warn_sizeof_pointer_memaccess)
    3519              :                 {
    3520      1030414 :                   auto same_p = same_type_ignoring_top_level_qualifiers_p;
    3521      1030414 :                   sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
    3522              :                                                     sizeof_arg, same_p);
    3523              :                 }
    3524      1030474 :               if (alloc_size_attr)
    3525           60 :                 warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
    3526              :                                  alloc_size_attr);
    3527              :             }
    3528              : 
    3529     88452659 :           if ((complain & tf_warning)
    3530     53022545 :               && TREE_CODE (fn) == FUNCTION_DECL
    3531     25378489 :               && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
    3532       134563 :               && vec_safe_length (*args) == 3
    3533     88587222 :               && !any_type_dependent_arguments_p (*args))
    3534              :             {
    3535       134563 :               tree arg0 = (*orig_args)[0];
    3536       134563 :               tree arg1 = (*orig_args)[1];
    3537       134563 :               tree arg2 = (*orig_args)[2];
    3538       134563 :               int literal_mask = ((literal_integer_zerop (arg1) << 1)
    3539       134563 :                                   | (literal_integer_zerop (arg2) << 2));
    3540       134563 :               warn_for_memset (input_location, arg0, arg2, literal_mask);
    3541              :             }
    3542              : 
    3543              :           /* A call to a namespace-scope function.  */
    3544     88452659 :           result = build_new_function_call (fn, args, orig_complain);
    3545              :         }
    3546              :     }
    3547      7936246 :   else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
    3548              :     {
    3549       151770 :       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       151770 :       tree ob = TREE_OPERAND (fn, 0);
    3556       151770 :       if (obvalue_p (ob))
    3557       151752 :         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      7784476 :   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      2153336 :     result = build_op_call (fn, args, complain);
    3566              : 
    3567    104361979 :   if (!result)
    3568              :     /* A call where the function is unknown.  */
    3569      5631140 :     result = cp_build_function_call_vec (fn, args, complain);
    3570              : 
    3571    110328521 :   if (processing_template_decl && result != error_mark_node)
    3572              :     {
    3573     16006780 :       if (INDIRECT_REF_P (result))
    3574      1099063 :         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     16006780 :       if (TREE_CODE (result) == CALL_EXPR
    3579     15997336 :           && really_overloaded_fn (orig_fn))
    3580              :         {
    3581      5973144 :           tree sel_fn = CALL_EXPR_FN (result);
    3582      5973144 :           if (TREE_CODE (sel_fn) == COMPONENT_REF)
    3583              :             {
    3584              :               /* The non-dependent result of build_new_method_call.  */
    3585       250075 :               sel_fn = TREE_OPERAND (sel_fn, 1);
    3586       250075 :               gcc_assert (BASELINK_P (sel_fn));
    3587              :             }
    3588      5723069 :           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      5723069 :             sel_fn = TREE_OPERAND (sel_fn, 0);
    3592              :           orig_fn = sel_fn;
    3593              :         }
    3594              : 
    3595     16006780 :       tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
    3596     16006780 :       SET_EXPR_LOCATION (r, input_location);
    3597     16006780 :       KOENIG_LOOKUP_P (r) = koenig_p;
    3598     16006780 :       TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
    3599     16006780 :       release_tree_vector (orig_args);
    3600     16006780 :       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      2581431 : 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      2581431 :   location_t combined_loc = make_location (input_location,
    3620              :                                            expr.get_start (),
    3621              :                                            get_finish (input_location));
    3622      2581431 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3623      2581431 :                                      NULL_TREE, tf_warning_or_error);
    3624              :   /* TODO: build_x_unary_op doesn't honor the location, so set it here.  */
    3625      2581431 :   result.set_location (combined_loc);
    3626      2581431 :   return result;
    3627              : }
    3628              : 
    3629              : /* Finish a use of `this'.  Returns an expression for `this'.  */
    3630              : 
    3631              : tree
    3632     35023657 : finish_this_expr (void)
    3633              : {
    3634     35023657 :   tree result = NULL_TREE;
    3635              : 
    3636     70047200 :   if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
    3637     34745979 :     result = current_class_ptr;
    3638       555340 :   else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
    3639       277604 :     result = (lambda_expr_this_capture
    3640       277604 :               (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
    3641              :   else
    3642           74 :     gcc_checking_assert (!current_class_ptr);
    3643              : 
    3644     35023583 :   if (result)
    3645              :     /* The keyword 'this' is a prvalue expression.  */
    3646     35023580 :     return rvalue (result);
    3647              : 
    3648           77 :   tree fn = current_nonlambda_function ();
    3649           77 :   if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3650              :     {
    3651            4 :       auto_diagnostic_group d;
    3652            4 :       error ("%<this%> is unavailable for explicit object member "
    3653              :              "functions");
    3654            4 :       tree xobj_parm = DECL_ARGUMENTS (fn);
    3655            4 :       gcc_assert (xobj_parm);
    3656            4 :       tree parm_name = DECL_NAME (xobj_parm);
    3657              : 
    3658            4 :       static tree remembered_fn = NULL_TREE;
    3659              :       /* Only output this diagnostic once per function.  */
    3660            4 :       if (remembered_fn == fn)
    3661              :         /* Early escape.  */;
    3662            4 :       else if (parm_name)
    3663            4 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3664              :                 "use explicit object parameter %qs instead",
    3665            2 :                 IDENTIFIER_POINTER (parm_name));
    3666              :       else
    3667            2 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3668              :                 "name the explicit object parameter");
    3669              : 
    3670            4 :       remembered_fn = fn;
    3671            4 :     }
    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           77 :   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       151821 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
    3692              :                                location_t loc, tsubst_flags_t complain)
    3693              : {
    3694       151821 :   if (object == error_mark_node || destructor == error_mark_node)
    3695              :     return error_mark_node;
    3696              : 
    3697       151812 :   gcc_assert (TYPE_P (destructor));
    3698              : 
    3699       151812 :   if (!processing_template_decl)
    3700              :     {
    3701       151791 :       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       151791 :       if (is_auto (destructor))
    3708            3 :         destructor = TREE_TYPE (object);
    3709       151791 :       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       151788 :       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       151797 :   tree type = (type_dependent_expression_p (object)
    3742       151797 :                ? NULL_TREE : void_type_node);
    3743              : 
    3744       151797 :   return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
    3745       151797 :                      scope, destructor);
    3746              : }
    3747              : 
    3748              : /* Finish an expression of the form CODE EXPR.  */
    3749              : 
    3750              : cp_expr
    3751     37387509 : 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     37387509 :   location_t combined_loc = make_location (op_loc,
    3760              :                                            op_loc, expr.get_finish ());
    3761     37387509 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3762     37387509 :                                      NULL_TREE, complain);
    3763              :   /* TODO: build_x_unary_op doesn't always honor the location.  */
    3764     37387509 :   result.set_location (combined_loc);
    3765              : 
    3766     37387509 :   if (result == error_mark_node)
    3767              :     return result;
    3768              : 
    3769     37387042 :   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     37387042 :   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
    3775              :     return result;
    3776              : 
    3777     20111184 :   tree result_ovl = result;
    3778     20111184 :   tree expr_ovl = expr;
    3779              : 
    3780     20111184 :   if (!processing_template_decl)
    3781      1773655 :     expr_ovl = cp_fully_fold (expr_ovl);
    3782              : 
    3783     20111184 :   if (!CONSTANT_CLASS_P (expr_ovl)
    3784     20111184 :       || TREE_OVERFLOW_P (expr_ovl))
    3785              :     return result;
    3786              : 
    3787       245113 :   if (!processing_template_decl)
    3788       235973 :     result_ovl = cp_fully_fold (result_ovl);
    3789              : 
    3790       245113 :   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      9371918 : finish_compound_literal (tree type, tree compound_literal,
    3818              :                          tsubst_flags_t complain,
    3819              :                          fcl_t fcl_context)
    3820              : {
    3821      9371918 :   if (type == error_mark_node)
    3822              :     return error_mark_node;
    3823              : 
    3824      9371866 :   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      9371854 :   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      9371830 :   if (template_placeholder_p (type))
    3861              :     {
    3862       177337 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3863              :                                 adc_variable_type);
    3864       177337 :       if (type == error_mark_node)
    3865              :         return error_mark_node;
    3866              :     }
    3867              :   /* C++23 auto{x}.  */
    3868      9194493 :   else if (is_auto (type)
    3869          109 :            && !AUTO_IS_DECLTYPE (type)
    3870      9194600 :            && CONSTRUCTOR_NELTS (compound_literal) == 1)
    3871              :     {
    3872          101 :       if (is_constrained_auto (type))
    3873              :         {
    3874            2 :           if (complain & tf_error)
    3875            2 :             error ("%<auto{x}%> cannot be constrained");
    3876            2 :           return error_mark_node;
    3877              :         }
    3878           99 :       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           99 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3887              :                                 adc_variable_type);
    3888           99 :       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      9371710 :   tree orig_cl = NULL_TREE;
    3894              : 
    3895      9371710 :   if (processing_template_decl)
    3896              :     {
    3897      4933089 :       const bool dependent_p
    3898      4933089 :         = (instantiation_dependent_expression_p (compound_literal)
    3899      4933089 :            || dependent_type_p (type));
    3900      1631937 :       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      1631937 :         orig_cl = unshare_constructor (compound_literal);
    3906      4933089 :       TREE_TYPE (orig_cl) = type;
    3907              :       /* Mark the expression as a compound literal.  */
    3908      4933089 :       TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
    3909              :       /* And as instantiation-dependent.  */
    3910      4933089 :       CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
    3911      4933089 :       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      4933089 :       if (dependent_p)
    3915              :         return orig_cl;
    3916              :       /* Otherwise, do go on to e.g. check narrowing.  */
    3917              :     }
    3918              : 
    3919      6070558 :   type = complete_type (type);
    3920              : 
    3921      6070558 :   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      1031085 :       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
    3928      1031085 :       compound_literal = build_tree_list (NULL_TREE, compound_literal);
    3929      1031085 :       return build_functional_cast (input_location, type,
    3930      1031085 :                                     compound_literal, complain);
    3931              :     }
    3932              : 
    3933      5039473 :   if (TREE_CODE (type) == ARRAY_TYPE
    3934      5039473 :       && check_array_initializer (NULL_TREE, type, compound_literal))
    3935            9 :     return error_mark_node;
    3936      5039464 :   compound_literal = reshape_init (type, compound_literal, complain);
    3937      4852460 :   if (SCALAR_TYPE_P (type)
    3938       686184 :       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
    3939      5249534 :       && !check_narrowing (type, compound_literal, complain))
    3940          102 :     return error_mark_node;
    3941      5039362 :   if (TREE_CODE (type) == ARRAY_TYPE
    3942      5039362 :       && 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      5039359 :   compound_literal = digest_init_flags (type, compound_literal,
    3950              :                                         LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
    3951              :                                         complain);
    3952      5039359 :   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      5038761 :   if (orig_cl)
    3957              :     return orig_cl;
    3958              : 
    3959      3498037 :   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    3960              :     {
    3961      2865231 :       TREE_HAS_CONSTRUCTOR (compound_literal) = true;
    3962      2865231 :       if (fcl_context == fcl_c99)
    3963        38257 :         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      4575312 :   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
    3970      2426622 :       && fcl_context == fcl_c99
    3971           83 :       && TREE_CODE (type) == ARRAY_TYPE
    3972           31 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    3973      3498068 :       && 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      3498006 :   if (!VECTOR_TYPE_P (type)
    4004      3459301 :       && (TREE_CODE (compound_literal) == CONSTRUCTOR
    4005       632800 :           || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
    4006              :     {
    4007              :       /* The CONSTRUCTOR is now an initializer, not a compound literal.  */
    4008      2826501 :       if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    4009      2826501 :         TREE_HAS_CONSTRUCTOR (compound_literal) = false;
    4010      2826501 :       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       671505 :     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       238686 : finish_fname (tree id)
    4024              : {
    4025       238686 :   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       238686 :   if (current_function_decl
    4031       238686 :       && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
    4032            4 :     pedwarn (input_location, 0, "%qD is not defined outside of function scope",
    4033              :              decl);
    4034       238686 :   if (processing_template_decl && current_function_decl
    4035       166942 :       && decl != error_mark_node)
    4036       166942 :     decl = DECL_NAME (decl);
    4037       238686 :   return decl;
    4038              : }
    4039              : 
    4040              : /* Finish a translation unit.  */
    4041              : 
    4042              : void
    4043        96934 : finish_translation_unit (void)
    4044              : {
    4045              :   /* In case there were missing closebraces,
    4046              :      get us back to the global binding level.  */
    4047        96934 :   pop_everything ();
    4048       193868 :   while (current_namespace != global_namespace)
    4049            0 :     pop_namespace ();
    4050              : 
    4051              :   /* Do file scope __FUNCTION__ et al.  */
    4052        96934 :   finish_fname_decls ();
    4053              : 
    4054        96934 :   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        96934 :   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        96934 :   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        96934 : }
    4080              : 
    4081              : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
    4082              :    Returns the parameter.  */
    4083              : 
    4084              : tree
    4085    156423714 : finish_template_type_parm (tree aggr, tree identifier)
    4086              : {
    4087    156423714 :   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    156423714 :   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       391084 : finish_template_template_parm (tree aggr, tree identifier)
    4101              : {
    4102       391084 :   tree decl = build_decl (input_location,
    4103              :                           TYPE_DECL, identifier, NULL_TREE);
    4104              : 
    4105       391084 :   tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
    4106       391084 :   DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
    4107       391084 :   DECL_TEMPLATE_RESULT (tmpl) = decl;
    4108       391084 :   DECL_ARTIFICIAL (decl) = 1;
    4109              : 
    4110              :   /* Associate the constraints with the underlying declaration,
    4111              :      not the template.  */
    4112       391084 :   tree constr = current_template_constraints ();
    4113       391084 :   set_constraints (decl, constr);
    4114              : 
    4115       391084 :   end_template_decl ();
    4116              : 
    4117       391084 :   gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
    4118              : 
    4119       391084 :   check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
    4120              :                            /*is_primary=*/true, /*is_partial=*/false,
    4121              :                            /*is_friend=*/0);
    4122              : 
    4123       391084 :   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          921 : check_template_template_default_arg (tree argument)
    4132              : {
    4133          921 :   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     29881685 : begin_class_definition (tree t)
    4157              : {
    4158     29881685 :   if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
    4159           33 :     return error_mark_node;
    4160              : 
    4161     29881783 :   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     29881643 :   if (TREE_CODE (t) == RECORD_TYPE
    4170     29377393 :       && !processing_template_decl)
    4171              :     {
    4172     10519083 :       tree ns = TYPE_CONTEXT (t);
    4173     10519081 :       if (ns && TREE_CODE (ns) == NAMESPACE_DECL
    4174      8679943 :           && DECL_CONTEXT (ns) == std_node
    4175      2111018 :           && DECL_NAME (ns)
    4176     12630081 :           && 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     19362560 :   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     29881643 :   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     29881643 :   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     29881643 :   maybe_process_partial_specialization (t);
    4211     29881643 :   pushclass (t);
    4212     29881643 :   TYPE_BEING_DEFINED (t) = 1;
    4213     29881643 :   class_binding_level->defining_class_p = 1;
    4214              : 
    4215     29881643 :   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     61950874 :   if (! TYPE_UNNAMED_P (t))
    4229              :     {
    4230     29155533 :       struct c_fileinfo *finfo = \
    4231     29155533 :         get_fileinfo (LOCATION_FILE (input_location));
    4232     29155533 :       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
    4233     29155533 :       SET_CLASSTYPE_INTERFACE_UNKNOWN_X
    4234              :         (t, finfo->interface_unknown);
    4235              :     }
    4236     29881643 :   reset_specialization ();
    4237              : 
    4238              :   /* Make a declaration for this class in its own scope.  */
    4239     29881643 :   build_self_reference ();
    4240              : 
    4241     29881643 :   return t;
    4242              : }
    4243              : 
    4244              : /* Finish the member declaration given by DECL.  */
    4245              : 
    4246              : void
    4247    404030338 : finish_member_declaration (tree decl)
    4248              : {
    4249    404030338 :   if (decl == error_mark_node || decl == NULL_TREE)
    4250              :     return;
    4251              : 
    4252    404029334 :   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    404029334 :   gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
    4259              : 
    4260              :   /* Don't add decls after definition.  */
    4261    404029355 :   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    404029334 :   TREE_PRIVATE (decl)
    4268    404029334 :     = (current_access_specifier == access_private_node);
    4269    404029334 :   TREE_PROTECTED (decl)
    4270    404029334 :     = (current_access_specifier == access_protected_node);
    4271    404029334 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    4272              :     {
    4273     45877964 :       TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
    4274     45877964 :       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    404029334 :   if (TREE_CODE (decl) != CONST_DECL)
    4280    401813499 :     DECL_CONTEXT (decl) = current_class_type;
    4281              : 
    4282              :   /* Remember the single FIELD_DECL an anonymous aggregate type is used for.  */
    4283    404029334 :   if (TREE_CODE (decl) == FIELD_DECL
    4284    404029334 :       && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    4285              :     {
    4286       256348 :       gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
    4287       256348 :       SET_ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)), decl);
    4288              :     }
    4289              : 
    4290    404029334 :   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      3217567 :     DECL_IGNORED_P (decl) = 1;
    4294              : 
    4295              :   /* Check for bare parameter packs in the non-static data member
    4296              :      declaration.  */
    4297    404029334 :   if (TREE_CODE (decl) == FIELD_DECL)
    4298              :     {
    4299     29305616 :       if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
    4300            9 :         TREE_TYPE (decl) = error_mark_node;
    4301     29305616 :       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    404029334 :   if (DECL_LANG_SPECIFIC (decl))
    4310    369164146 :     SET_DECL_LANGUAGE (decl, lang_cplusplus);
    4311              : 
    4312    404029334 :   bool add = false;
    4313              : 
    4314              :   /* Functions and non-functions are added differently.  */
    4315    404029334 :   if (DECL_DECLARES_FUNCTION_P (decl))
    4316    209608616 :     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    194420718 :   else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
    4320    191053695 :            || maybe_push_used_methods (decl)
    4321    383632197 :            || pushdecl_class_level (decl))
    4322              :     add = true;
    4323              : 
    4324    209608616 :   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    404019692 :       if (TREE_CODE (decl) == TYPE_DECL)
    4337    138232898 :         TYPE_FIELDS (current_class_type)
    4338    276465796 :           = chainon (TYPE_FIELDS (current_class_type), decl);
    4339              :       else
    4340              :         {
    4341    265786794 :           DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
    4342    265786794 :           TYPE_FIELDS (current_class_type) = decl;
    4343              :         }
    4344              : 
    4345    404019692 :       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     89410079 : finish_template_decl (tree parms)
    4355              : {
    4356     89410079 :   if (parms)
    4357     89410070 :     end_template_decl ();
    4358              :   else
    4359            9 :     end_specialization ();
    4360     89410079 : }
    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     17688122 : 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     17688122 :   tree parms = current_template_parms;
    4400     17688122 :   int depth = template_class_depth (type);
    4401     39405476 :   for (int n = current_template_depth; n > depth && parms; --n)
    4402      4029232 :     parms = TREE_CHAIN (parms);
    4403     17688122 :   if (!parms)
    4404              :     return type;
    4405     17688112 :   tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
    4406     17688112 :   tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
    4407              : 
    4408              :   // Search for a specialization whose type and constraints match.
    4409     17688112 :   tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
    4410     17688112 :   tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
    4411     34346634 :   while (specs)
    4412              :     {
    4413     17070814 :       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     17070814 :       if (same_type_p (type, TREE_TYPE (specs))
    4418     17070814 :           && equivalent_constraints (cur_constr, spec_constr))
    4419       412292 :         return TREE_TYPE (specs);
    4420     16658522 :       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    182360374 : finish_template_type (tree name, tree args, int entering_scope)
    4435              : {
    4436    182360374 :   tree type;
    4437              : 
    4438    182360374 :   type = lookup_template_class (name, args,
    4439              :                                 NULL_TREE, NULL_TREE,
    4440              :                                 tf_warning_or_error | tf_user);
    4441    182360371 :   if (entering_scope)
    4442     18708189 :     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    182360371 :   if (flag_concepts
    4447    179636349 :       && entering_scope
    4448     18340608 :       && CLASS_TYPE_P (type)
    4449     18179928 :       && CLASSTYPE_TEMPLATE_INFO (type)
    4450     18179919 :       && dependent_type_p (type)
    4451    200048493 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
    4452     17688122 :     type = fixup_template_type (type);
    4453              : 
    4454    182360371 :   if (type == error_mark_node)
    4455              :     return type;
    4456    182358098 :   else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
    4457    143623138 :     return TYPE_STUB_DECL (type);
    4458              :   else
    4459     38734960 :     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     11066267 : finish_base_specifier (tree base, tree access, bool virtual_p,
    4473              :                        tree annotations)
    4474              : {
    4475     11066267 :   tree result;
    4476              : 
    4477     11066267 :   if (base == error_mark_node)
    4478              :     {
    4479            0 :       error ("invalid base-class specification");
    4480            0 :       result = NULL_TREE;
    4481              :     }
    4482     11066267 :   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     11066264 :       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     11066264 :       if (annotations)
    4496            9 :         access = build_tree_list (access, nreverse (annotations));
    4497     11066264 :       result = build_tree_list (access, base);
    4498     11066264 :       if (virtual_p)
    4499        25470 :         TREE_TYPE (result) = integer_type_node;
    4500              :     }
    4501              : 
    4502     11066267 :   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    165319875 : baselink_for_fns (tree fns)
    4512              : {
    4513    165319875 :   tree scope;
    4514    165319875 :   tree cl;
    4515              : 
    4516    165319875 :   if (BASELINK_P (fns)
    4517    165319875 :       || error_operand_p (fns))
    4518              :     return fns;
    4519              : 
    4520    151818286 :   scope = ovl_scope (fns);
    4521    151818286 :   if (!CLASS_TYPE_P (scope))
    4522              :     return fns;
    4523              : 
    4524      8421378 :   cl = currently_open_derived_class (scope);
    4525      8421378 :   if (!cl)
    4526      6131007 :     cl = scope;
    4527      8421378 :   tree access_path = TYPE_BINFO (cl);
    4528      8421378 :   tree conv_path = (cl == scope ? access_path
    4529       682088 :                     : lookup_base (cl, scope, ba_any, NULL, tf_none));
    4530      8421378 :   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   1903408576 : parsing_lambda_declarator ()
    4537              : {
    4538   1903408576 :   cp_binding_level *b = current_binding_level;
    4539   1905273250 :   while (b->kind == sk_template_parms || b->kind == sk_function_parms)
    4540      1864674 :     b = b->level_chain;
    4541   1903408576 :   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   2540283743 : outer_var_p (tree decl)
    4549              : {
    4550              :   /* These should have been stripped or otherwise handled by the caller.  */
    4551   2540283743 :   gcc_checking_assert (!REFERENCE_REF_P (decl));
    4552              : 
    4553   1673226077 :   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
    4554   2331831469 :           && DECL_FUNCTION_SCOPE_P (decl)
    4555              :           /* Don't get confused by temporaries.  */
    4556   1933791137 :           && DECL_NAME (decl)
    4557   4451274474 :           && (DECL_CONTEXT (decl) != current_function_decl
    4558   1901470530 :               || 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   1901469587 :               || parsing_lambda_declarator ()));
    4567              : }
    4568              : 
    4569              : /* As above, but also checks that DECL is automatic.  */
    4570              : 
    4571              : bool
    4572   2540283743 : outer_automatic_var_p (tree decl)
    4573              : {
    4574   2540283743 :   return (outer_var_p (decl)
    4575   2540283743 :           && !TREE_STATIC (decl));
    4576              : }
    4577              : 
    4578              : /* Note whether capture proxy D is only used in a contract condition.  */
    4579              : 
    4580              : static void
    4581       104855 : set_contract_capture_flag (tree d, bool val)
    4582              : {
    4583       104855 :   gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
    4584       104855 :   tree proxy = DECL_VALUE_EXPR (d);
    4585       104855 :   gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
    4586              :                        && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
    4587       104855 :   DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
    4588       104855 : }
    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      4892902 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
    4599              :                        bool odr_use/*=false*/)
    4600              : {
    4601      4892902 :   if (cp_unevaluated_operand)
    4602              :     {
    4603      2953742 :       tree type = TREE_TYPE (decl);
    4604      2953742 :       if (!dependent_type_p (type)
    4605      2953742 :           && 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      2953736 :         return decl;
    4610              :     }
    4611      1939166 :   if (decl == error_mark_node)
    4612              :     return decl;
    4613              : 
    4614      1939160 :   tree context = DECL_CONTEXT (decl);
    4615      1939160 :   tree containing_function = current_function_decl;
    4616      1939160 :   tree lambda_stack = NULL_TREE;
    4617      1939160 :   tree lambda_expr = NULL_TREE;
    4618      1939160 :   tree initializer = convert_from_reference (decl);
    4619      1939160 :   tree var = strip_normal_capture_proxy (decl);
    4620              : 
    4621              :   /* Mark it as used now even if the use is ill-formed.  */
    4622      1939160 :   if (!mark_used (decl, complain))
    4623            3 :     return error_mark_node;
    4624              : 
    4625      1939157 :   if (parsing_nsdmi () || parsing_lambda_declarator ())
    4626              :     containing_function = NULL_TREE;
    4627              : 
    4628      3877611 :   if (containing_function && LAMBDA_FUNCTION_P (containing_function))
    4629              :     {
    4630              :       /* Check whether we've already built a proxy.  */
    4631      1938715 :       tree d = retrieve_local_specialization (var);
    4632              : 
    4633      1938715 :       if (d && d != decl && is_capture_proxy (d))
    4634              :         {
    4635       993996 :           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       104852 :             set_contract_capture_flag (d, false);
    4640       993996 :           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         2558 :             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      1892895 :   while (context != containing_function
    4654              :          /* containing_function can be null with invalid generic lambdas.  */
    4655      1892895 :          && containing_function
    4656      2841361 :          && LAMBDA_FUNCTION_P (containing_function))
    4657              :     {
    4658       948466 :       tree closure = DECL_CONTEXT (containing_function);
    4659       948466 :       lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
    4660              : 
    4661       948466 :       if (TYPE_CLASS_SCOPE_P (closure))
    4662              :         /* A lambda in an NSDMI (c++/64496).  */
    4663              :         break;
    4664              : 
    4665       948463 :       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4666              :         break;
    4667              : 
    4668       947734 :       lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
    4669              : 
    4670       947734 :       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       945161 :   if (context == containing_function
    4678       945161 :       && DECL_PACK_P (decl))
    4679              :     return decl;
    4680              : 
    4681       904135 :   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       904129 :   if (!odr_use && context == containing_function)
    4690              :     {
    4691       902955 :       decl = add_default_capture (lambda_stack,
    4692       902955 :                                   /*id=*/DECL_NAME (decl), initializer);
    4693       902955 :       if (flag_contracts && processing_contract_condition)
    4694            3 :         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         1174 :   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          335 :   else if (VAR_P (var) && instantiation_dependent_expression_p (var))
    4704              :     return var;
    4705          317 :   else if (lambda_expr)
    4706              :     {
    4707           54 :       if (complain & tf_error)
    4708              :         {
    4709           52 :           auto_diagnostic_group d;
    4710           52 :           error ("%qD is not captured", decl);
    4711           52 :           tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
    4712           52 :           if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4713           49 :             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           52 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4720           52 :         }
    4721           54 :       return error_mark_node;
    4722              :     }
    4723          263 :   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           46 :       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           46 :       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    759390480 : 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    759390480 :   decl = strip_using_decl (decl);
    4791              : 
    4792              :   /* Initialize the output parameters.  */
    4793    759390480 :   *idk = CP_ID_KIND_NONE;
    4794    759390480 :   *error_msg = NULL;
    4795              : 
    4796    759390480 :   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    759390468 :   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4802    707612693 :            || TREE_CODE (decl) == TYPE_DECL)
    4803              :     ;
    4804              :   /* Look up the name.  */
    4805              :   else
    4806              :     {
    4807    707611788 :       if (decl == error_mark_node)
    4808              :         {
    4809              :           /* Name lookup failed.  */
    4810       123454 :           if (scope
    4811          373 :               && !dependent_namespace_p (scope)
    4812       123827 :               && (!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          363 :               qualified_name_lookup_error (scope, id_expression, decl, location);
    4822          363 :               return error_mark_node;
    4823              :             }
    4824       123091 :           else if (!scope)
    4825              :             {
    4826              :               /* It may be resolved via Koenig lookup.  */
    4827       123081 :               *idk = CP_ID_KIND_UNQUALIFIED;
    4828       123081 :               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    707488334 :       if (!scope && decl != error_mark_node && identifier_p (id_expression))
    4839    632867556 :         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    707488344 :       if (processing_template_decl
    4845    707488344 :           && (cp_unevaluated_operand
    4846    612000305 :               || generic_lambda_fn_p (current_function_decl)))
    4847     19293110 :         mark_type_use (decl);
    4848              : 
    4849              :       /* Disallow uses of local variables from containing functions, except
    4850              :          within lambda-expressions.  */
    4851    707488344 :       if (outer_automatic_var_p (decl))
    4852              :         {
    4853      3470614 :           decl = process_outer_var_ref (decl, tf_warning_or_error);
    4854      3470614 :           if (decl == error_mark_node)
    4855           88 :             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    707488256 :       if (TREE_CODE (decl) == PARM_DECL
    4861    295367424 :           && DECL_CONTEXT (decl) == NULL_TREE
    4862      7947230 :           && !CONSTRAINT_VAR_P (decl)
    4863      4281036 :           && !cp_unevaluated_operand
    4864          386 :           && !processing_contract_condition
    4865    707488312 :           && !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    759266898 :   if (TREE_CODE (decl) == TEMPLATE_DECL
    4875    759266898 :       && !DECL_FUNCTION_TEMPLATE_P (decl))
    4876              :     {
    4877           51 :       *error_msg = G_("missing template arguments");
    4878           51 :       return error_mark_node;
    4879              :     }
    4880    759266847 :   else if (TREE_CODE (decl) == TYPE_DECL
    4881    759265942 :            || TREE_CODE (decl) == NAMESPACE_DECL)
    4882              :     {
    4883          920 :       *error_msg = G_("expected primary-expression");
    4884          920 :       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     32063868 :   if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
    4890    772806351 :       || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4891              :     {
    4892     18523444 :       tree r;
    4893              : 
    4894     18523444 :       *idk = CP_ID_KIND_NONE;
    4895     18523444 :       if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4896            0 :         decl = TEMPLATE_PARM_DECL (decl);
    4897     18523444 :       r = DECL_INITIAL (decl);
    4898     18523444 :       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         1085 :           tree ctype = TREE_TYPE (r);
    4903         1085 :           ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
    4904              :                                                    | TYPE_QUAL_CONST));
    4905         1085 :           r = build1 (VIEW_CONVERT_EXPR, ctype, r);
    4906              :         }
    4907     18523444 :       r = convert_from_reference (r);
    4908     18523444 :       if (integral_constant_expression_p
    4909      3206632 :           && !dependent_type_p (TREE_TYPE (decl))
    4910     21252991 :           && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
    4911              :         {
    4912          506 :           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          506 :           *non_integral_constant_expression_p = true;
    4917              :         }
    4918              : 
    4919     18523444 :       if (flag_contracts && processing_contract_condition)
    4920            9 :         r = constify_contract_access (r);
    4921              : 
    4922     18523444 :       return r;
    4923              :     }
    4924    740742483 :   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    740742474 :       if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4936     51777775 :           && variable_template_p (TREE_OPERAND (decl, 0))
    4937    752385454 :           && !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     11642980 :         decl = finish_template_variable (decl);
    4944              : 
    4945    740742474 :       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   1481484948 :       *idk = (scope
    4951    740742474 :               ? CP_ID_KIND_QUALIFIED
    4952    644928029 :               : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4953    644928029 :                  ? CP_ID_KIND_TEMPLATE_ID
    4954              :                  : (dependent_p
    4955    614617670 :                     ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
    4956              :                     : CP_ID_KIND_UNQUALIFIED)));
    4957              : 
    4958    740742474 :       if (dependent_p
    4959    740742474 :           && !scope
    4960    424313600 :           && DECL_P (decl)
    4961   1135641751 :           && 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    740742435 :       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    740742435 :       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    740742435 :       if ((VAR_P (decl)
    4985    536746504 :            || TREE_CODE (decl) == PARM_DECL
    4986    241379124 :            || TREE_CODE (decl) == CONST_DECL
    4987    227838700 :            || TREE_CODE (decl) == RESULT_DECL)
    4988   1049650239 :           && !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    740742420 :       if (! error_operand_p (decl)
    4995    740742105 :           && !dependent_p
    4996    740742105 :           && integral_constant_expression_p
    4997     74667826 :           && !decl_constant_var_p (decl)
    4998     60897662 :           && TREE_CODE (decl) != CONST_DECL
    4999     52600584 :           && !builtin_valid_in_constant_expr_p (decl)
    5000    793294922 :           && !concept_check_p (decl))
    5001              :         {
    5002     52035620 :           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     52035590 :           *non_integral_constant_expression_p = true;
    5008              :         }
    5009              : 
    5010    740742390 :       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    740741878 :       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    724836651 :       else if (scope)
    5020              :         {
    5021     94033397 :           if (TREE_CODE (decl) == SCOPE_REF)
    5022              :             {
    5023        83059 :               gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
    5024        83059 :               decl = TREE_OPERAND (decl, 1);
    5025              :             }
    5026              : 
    5027     94033397 :           decl = (adjust_result_of_qualified_name_lookup
    5028     94033397 :                   (decl, scope, current_nonlambda_class_type()));
    5029              : 
    5030     94033397 :           cp_warn_deprecated_use_scopes (scope);
    5031              : 
    5032     94033397 :           if (TYPE_P (scope))
    5033     13491114 :             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     80542283 :             decl = convert_from_reference (decl);
    5042              :         }
    5043    630803254 :       else if (TREE_CODE (decl) == FIELD_DECL)
    5044              :         {
    5045     65889049 :           if (flag_contracts && processing_contract_condition
    5046           22 :               && contract_class_ptr == current_class_ptr)
    5047              :             {
    5048            4 :               error ("%qD 'this' required when accessing a member within a "
    5049              :                   "constructor precondition or destructor postcondition "
    5050              :                   "contract check", decl);
    5051            4 :                       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     65889045 :           push_deferring_access_checks (dk_no_check);
    5057     65889045 :           decl = finish_non_static_data_member (decl, NULL_TREE,
    5058              :                                                 /*qualifying_scope=*/NULL_TREE);
    5059     65889045 :           pop_deferring_access_checks ();
    5060              :         }
    5061    564914205 :       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     60232028 :           tree first_fn = get_first_fn (decl);
    5067     60232028 :           first_fn = STRIP_TEMPLATE (first_fn);
    5068              : 
    5069     60232028 :           if (!template_arg_p
    5070     60232028 :               && (TREE_CODE (first_fn) == USING_DECL
    5071     60230152 :                   || (TREE_CODE (first_fn) == FUNCTION_DECL
    5072     60230152 :                       && DECL_FUNCTION_MEMBER_P (first_fn)
    5073     36595345 :                       && !shared_member_p (decl))))
    5074              :             {
    5075              :               /* A set of member functions.  */
    5076     28291327 :               if (flag_contracts && processing_contract_condition
    5077           16 :                   && contract_class_ptr == current_class_ptr)
    5078              :                 {
    5079            2 :                   error ("%qD 'this' required when accessing a member within a "
    5080              :                       "constructor precondition or destructor postcondition "
    5081              :                       "contract check", decl);
    5082            2 :                   return error_mark_node;
    5083              :                 }
    5084     28291325 :               decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
    5085     28291325 :               return finish_class_member_access_expr (decl, id_expression,
    5086              :                                                       /*template_p=*/false,
    5087     28291325 :                                                       tf_warning_or_error);
    5088              :             }
    5089              : 
    5090     31940701 :           decl = baselink_for_fns (decl);
    5091              :         }
    5092              :       else
    5093              :         {
    5094    493929326 :           if (DECL_P (decl) && DECL_NONLOCAL (decl)
    5095    506148932 :               && DECL_CLASS_SCOPE_P (decl))
    5096              :             {
    5097      1466755 :               tree context = context_for_name_lookup (decl);
    5098      1466755 :               if (context != current_class_type)
    5099              :                 {
    5100       767896 :                   tree path = currently_open_derived_class (context);
    5101       767896 :                   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           31 :                     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       767865 :                     perform_or_defer_access_check (TYPE_BINFO (path),
    5114              :                                                    decl, decl,
    5115              :                                                    tf_warning_or_error);
    5116              :                 }
    5117              :             }
    5118              : 
    5119    504682177 :           decl = convert_from_reference (decl);
    5120              :         }
    5121              :     }
    5122              : 
    5123    712451068 :   check_param_in_postcondition (decl, location);
    5124    712451068 :   if (flag_contracts && processing_contract_condition)
    5125         1311 :     decl = constify_contract_access (decl);
    5126              : 
    5127    712451068 :   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    759390480 : 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    759390480 :   cp_expr result
    5149    759390480 :     = 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    759390477 :   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     21088166 : finish_typeof (tree expr)
    5163              : {
    5164     21088166 :   tree type;
    5165              : 
    5166     21088166 :   if (type_dependent_expression_p (expr))
    5167              :     {
    5168     20997014 :       type = cxx_make_type (TYPEOF_TYPE);
    5169     20997014 :       TYPEOF_TYPE_EXPR (type) = expr;
    5170     20997014 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
    5171              : 
    5172     20997014 :       return type;
    5173              :     }
    5174              : 
    5175        91152 :   expr = mark_type_use (expr);
    5176              : 
    5177        91152 :   type = unlowered_expr_type (expr);
    5178              : 
    5179        91152 :   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        46905 : finish_underlying_type (tree type)
    5193              : {
    5194        46905 :   if (!complete_type_or_else (type, NULL_TREE))
    5195            3 :     return error_mark_node;
    5196              : 
    5197        46902 :   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        46878 :   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        46878 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
    5209           54 :     underlying_type
    5210           54 :       = c_common_type_for_mode (TYPE_MODE (underlying_type),
    5211           54 :                                 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       118438 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
    5221              : {
    5222       118438 :   idx = maybe_constant_value (idx, NULL_TREE, mce_true);
    5223       118438 :   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       118432 :   if (TREE_CODE (idx) != INTEGER_CST)
    5230              :     {
    5231            1 :       if (complain & tf_error)
    5232              :         {
    5233            1 :           error ("pack index is not an integral constant");
    5234            1 :           cxx_constant_value (idx);
    5235              :         }
    5236            1 :       return error_mark_node;
    5237              :     }
    5238       118431 :   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       118428 :   if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
    5245              :     {
    5246           30 :       if (complain & tf_error)
    5247           24 :         error ("pack index %qE is out of range for pack of length %qd",
    5248           24 :                idx, TREE_VEC_LENGTH (types));
    5249           30 :       return error_mark_node;
    5250              :     }
    5251       118398 :   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        10832 : pack_index_element (tree idx, tree types, bool parenthesized_p,
    5259              :                     tsubst_flags_t complain)
    5260              : {
    5261        10832 :   tree r = finish_type_pack_element (idx, types, complain);
    5262        10832 :   if (parenthesized_p)
    5263              :     /* For the benefit of decltype(auto).  */
    5264           22 :     r = force_paren_expr (r);
    5265        10832 :   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         2400 : 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         2400 :   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         2340 :   if (expr == error_mark_node)
    5413              :     return error_mark_node;
    5414              : 
    5415         2323 :   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         4619 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
    5422         4619 :       || 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         2299 :   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         2296 :   if (REFERENCE_REF_P (expr))
    5444            9 :     expr = TREE_OPERAND (expr, 0);
    5445         2296 :   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
    5446            3 :     return error_mark_node;
    5447         2293 :   if (warn_invalid_offsetof
    5448         2293 :       && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
    5449         2293 :       && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
    5450         2338 :       && 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         2293 :   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       345914 : simplify_aggr_init_expr (tree *tp)
    5463              : {
    5464       345914 :   tree aggr_init_expr = *tp;
    5465              : 
    5466              :   /* Form an appropriate CALL_EXPR.  */
    5467       345914 :   tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
    5468       345914 :   tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
    5469       345914 :   tree type = TREE_TYPE (slot);
    5470              : 
    5471       345914 :   tree call_expr;
    5472       345914 :   enum style_t { ctor, arg, pcc } style;
    5473              : 
    5474       345914 :   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        92282 :       gcc_assert (TREE_ADDRESSABLE (type));
    5483              :       style = arg;
    5484              :     }
    5485              : 
    5486       345914 :   call_expr = build_call_array_loc (input_location,
    5487       345914 :                                     TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
    5488              :                                     fn,
    5489       345914 :                                     aggr_init_expr_nargs (aggr_init_expr),
    5490       345914 :                                     AGGR_INIT_EXPR_ARGP (aggr_init_expr));
    5491       345914 :   TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
    5492       345914 :   CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
    5493       345914 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr)
    5494       345914 :     = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
    5495       345914 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
    5496       345914 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
    5497       345914 :   CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
    5498              : 
    5499       345914 :   if (style == ctor)
    5500              :     {
    5501              :       /* Replace the first argument to the ctor with the address of the
    5502              :          slot.  */
    5503       253632 :       cxx_mark_addressable (slot);
    5504       253632 :       CALL_EXPR_ARG (call_expr, 0) =
    5505       253632 :         build1 (ADDR_EXPR, build_pointer_type (type), slot);
    5506              :     }
    5507        92282 :   else if (style == arg)
    5508              :     {
    5509              :       /* Just mark it addressable here, and leave the rest to
    5510              :          expand_call{,_inline}.  */
    5511        92282 :       cxx_mark_addressable (slot);
    5512        92282 :       CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
    5513        92282 :       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       345914 :   if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
    5529              :     {
    5530         3494 :       tree init = build_zero_init (type, NULL_TREE,
    5531              :                                    /*static_storage_p=*/false);
    5532         3494 :       init = cp_build_init_expr (slot, init);
    5533         3494 :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
    5534              :                           init, call_expr);
    5535              :     }
    5536              : 
    5537       345914 :   *tp = call_expr;
    5538       345914 : }
    5539              : 
    5540              : /* Emit all thunks to FN that should be emitted when FN is emitted.  */
    5541              : 
    5542              : void
    5543     57825942 : 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     57825942 :   if (DECL_VIRTUAL_P (fn)
    5551              :       /* Do not emit thunks for extern template instantiations.  */
    5552      1092234 :       && ! DECL_REALLY_EXTERN (fn)
    5553              :       /* Do not emit thunks for tentative decls, those will be processed
    5554              :          again at_eof if really needed.  */
    5555     58834431 :       && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
    5556              :     {
    5557      1007758 :       tree thunk;
    5558              : 
    5559      2019716 :       for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
    5560              :         {
    5561         4200 :           if (!THUNK_ALIAS (thunk))
    5562              :             {
    5563         4200 :               use_thunk (thunk, /*emit_p=*/1);
    5564         4200 :               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     57825942 : }
    5578              : 
    5579              : /* Generate RTL for FN.  */
    5580              : 
    5581              : bool
    5582    157981909 : 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    157981909 :   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     92392681 :       if (!function_depth)
    5595     91955860 :         ggc_collect ();
    5596     92392681 :       return false;
    5597              :     }
    5598              : 
    5599     65589228 :   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     65589228 :   if (DECL_DECLARED_INLINE_P (fn)
    5606      1898344 :       || DECL_IMPLICIT_INSTANTIATION (fn)
    5607     65848172 :       || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
    5608              :     {
    5609     65330311 :       if (DECL_INTERFACE_KNOWN (fn))
    5610              :         /* We've already made a decision as to how this function will
    5611              :            be handled.  */;
    5612     46115414 :       else if (!at_eof
    5613     16641256 :                || DECL_IMMEDIATE_FUNCTION_P (fn)
    5614     62327659 :                || DECL_OMP_DECLARE_REDUCTION_P (fn))
    5615     29903169 :         tentative_decl_linkage (fn);
    5616              :       else
    5617     16212245 :         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     65330311 :       if (DECL_DECLARED_INLINE_P (fn)
    5624     63690884 :           && !DECL_REALLY_EXTERN (fn)
    5625     60126011 :           && !DECL_IMMEDIATE_FUNCTION_P (fn)
    5626     59162831 :           && !DECL_OMP_DECLARE_REDUCTION_P (fn)
    5627    124493142 :           && (flag_keep_inline_functions
    5628     59160041 :               || (flag_keep_inline_dllexport
    5629     59160041 :                   && 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     65589228 :   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      7735106 :       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      7735106 :       if (!maybe_constexpr_fn (fn)
    5649      7735106 :           && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
    5650      3714279 :         DECL_SAVED_TREE (fn) = void_node;
    5651      7735106 :       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     57854122 :   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        28164 :       TREE_ASM_WRITTEN (fn) = 1;
    5661        28164 :       return false;
    5662              :     }
    5663              : 
    5664     57825958 :   if (DECL_OMP_DECLARE_REDUCTION_P (fn))
    5665              :     return false;
    5666              : 
    5667              :   return true;
    5668              : }
    5669              : 
    5670              : void
    5671    150267095 : expand_or_defer_fn (tree fn)
    5672              : {
    5673    150267095 :   if (expand_or_defer_fn_1 (fn))
    5674              :     {
    5675     50113617 :       function_depth++;
    5676              : 
    5677              :       /* Expand or defer, at the whim of the compilation unit manager.  */
    5678     50113617 :       cgraph_node::finalize_function (fn, function_depth > 1);
    5679     50113617 :       emit_associated_thunks (fn);
    5680              : 
    5681     50113617 :       function_depth--;
    5682              : 
    5683    100227234 :       if (DECL_IMMEDIATE_FUNCTION_P (fn))
    5684              :         {
    5685       916912 :           if (cgraph_node *node = cgraph_node::get (fn))
    5686              :             {
    5687       916912 :               node->body_removed = true;
    5688       916912 :               node->analyzed = false;
    5689       916912 :               node->definition = false;
    5690       916912 :               node->force_output = false;
    5691              :             }
    5692              :         }
    5693              :     }
    5694    150267095 : }
    5695              : 
    5696       433574 : class nrv_data
    5697              : {
    5698              : public:
    5699       216787 :   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     19852925 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
    5712              : {
    5713     19852925 :   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     19852925 :   if (TYPE_P (*tp))
    5718       180010 :     *walk_subtrees = 0;
    5719              : 
    5720              :   /* Replace all uses of the NRV with the RESULT_DECL.  */
    5721     19672915 :   else if (*tp == dp->var)
    5722       470368 :     *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     19202547 :   else if (dp->visited.add (*tp))
    5728      4251553 :     *walk_subtrees = 0;
    5729              : 
    5730              :   /* If there's a label, we might need to destroy the NRV on goto (92407).  */
    5731     14950994 :   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     14950991 :   else if (TREE_CODE (*tp) == RETURN_EXPR)
    5738              :     {
    5739       221769 :       tree *p = &TREE_OPERAND (*tp, 0);
    5740       567306 :       while (TREE_CODE (*p) == COMPOUND_EXPR)
    5741       123768 :         p = &TREE_OPERAND (*p, 0);
    5742       221769 :       if (TREE_CODE (*p) == INIT_EXPR
    5743       221769 :           && INIT_EXPR_NRV_P (*p))
    5744       221382 :         *p = dp->result;
    5745              :     }
    5746              :   /* Change all cleanups for the NRV to only run when not returning.  */
    5747     14729222 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5748     14729222 :            && CLEANUP_DECL (*tp) == dp->var)
    5749              :     {
    5750       119784 :       dp->in_nrv_cleanup = true;
    5751       119784 :       cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
    5752       119784 :       dp->in_nrv_cleanup = false;
    5753       119784 :       cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
    5754       119784 :       *walk_subtrees = 0;
    5755              : 
    5756       119784 :       if (dp->simple)
    5757              :         /* For a simple NRV, just run it on the EH path.  */
    5758       119168 :         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         1848 :           tree cond = build3 (COND_EXPR, void_type_node,
    5767          616 :                               current_retval_sentinel,
    5768          616 :                               void_node, CLEANUP_EXPR (*tp));
    5769          616 :           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       119784 :       if (cp_function_chain->throwing_cleanup)
    5776              :         {
    5777          202 :           tree clear = build2 (MODIFY_EXPR, boolean_type_node,
    5778              :                                current_retval_sentinel,
    5779              :                                boolean_false_node);
    5780          202 :           if (dp->simple)
    5781              :             {
    5782              :               /* We're already only on the EH path, just prepend it.  */
    5783          192 :               tree &exp = CLEANUP_EXPR (*tp);
    5784          192 :               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     14609438 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5800         4492 :            && dp->in_nrv_cleanup
    5801     14612537 :            && 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     14609432 :   else if (TREE_CODE (*tp) == DECL_EXPR
    5806     14609432 :            && DECL_EXPR_DECL (*tp) == dp->var)
    5807              :     {
    5808       216789 :       tree init;
    5809       216789 :       if (DECL_INITIAL (dp->var)
    5810       216789 :           && DECL_INITIAL (dp->var) != error_mark_node)
    5811        88494 :         init = cp_build_init_expr (dp->result,
    5812        88494 :                        DECL_INITIAL (dp->var));
    5813              :       else
    5814       128295 :         init = build_empty_stmt (EXPR_LOCATION (*tp));
    5815       216789 :       DECL_INITIAL (dp->var) = NULL_TREE;
    5816       216789 :       SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
    5817       216789 :       *tp = init;
    5818              :     }
    5819              : 
    5820              :   /* Keep iterating.  */
    5821     19852925 :   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       216787 : finalize_nrv (tree fndecl, tree var)
    5831              : {
    5832       216787 :   class nrv_data data;
    5833       216787 :   tree result = DECL_RESULT (fndecl);
    5834              : 
    5835              :   /* Copy name from VAR to RESULT.  */
    5836       216787 :   DECL_NAME (result) = DECL_NAME (var);
    5837              :   /* Don't forget that we take its address.  */
    5838       216787 :   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       216787 :   SET_DECL_VALUE_EXPR (var, result);
    5843       216787 :   DECL_HAS_VALUE_EXPR_P (var) = 1;
    5844              : 
    5845       216787 :   data.var = var;
    5846       216787 :   data.result = result;
    5847       216787 :   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       216787 :   tree outer = outer_curly_brace_block (fndecl);
    5853       216787 :   data.simple = chain_member (var, BLOCK_VARS (outer));
    5854              : 
    5855       216787 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
    5856       216787 : }
    5857              : 
    5858              : /* Create CP_OMP_CLAUSE_INFO for clause C.  Returns true if it is invalid.  */
    5859              : 
    5860              : bool
    5861         2239 : 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         2239 :   int save_errorcount = errorcount;
    5866         2239 :   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         2239 :   info = make_tree_vec (3);
    5874         2239 :   CP_OMP_CLAUSE_INFO (c) = info;
    5875              : 
    5876         2239 :   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         2239 :   if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5888         1632 :     TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
    5889              : 
    5890         2239 :   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         2239 :   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        26243 : omp_clause_decl_field (tree decl)
    5906              : {
    5907        26243 :   if (VAR_P (decl)
    5908        18396 :       && DECL_HAS_VALUE_EXPR_P (decl)
    5909          359 :       && DECL_ARTIFICIAL (decl)
    5910          359 :       && DECL_LANG_SPECIFIC (decl)
    5911        26578 :       && 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        30905 :   cp_omp_address_inspector (location_t loc, tree t)
    5993        30905 :     : c_omp_address_inspector (loc, t)
    5994              :     {
    5995              :     }
    5996              : 
    5997        30905 :   ~cp_omp_address_inspector ()
    5998              :     {
    5999        22596 :     }
    6000              : 
    6001       131213 :   bool processing_template_decl_p ()
    6002              :     {
    6003       131213 :       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        22538 :   bool check_clause (tree clause)
    6024              :     {
    6025        22538 :       if (TREE_CODE (orig) == COMPONENT_REF
    6026        22538 :           && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
    6027              :                                         tf_warning_or_error))
    6028              :         return false;
    6029        22535 :       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        20472 : 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        20472 :   tree ret, low_bound, length, type;
    6061        20472 :   bool openacc = (ort & C_ORT_ACC) != 0;
    6062        20472 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
    6063              :     {
    6064         9278 :       if (error_operand_p (t))
    6065            6 :         return error_mark_node;
    6066              : 
    6067         9272 :       cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6068         9272 :       tree t_refto = ai.maybe_unconvert_ref (t);
    6069              : 
    6070         9272 :       if (!ai.check_clause (c))
    6071            0 :         return error_mark_node;
    6072         9272 :       else if (ai.component_access_p ()
    6073        10660 :                && (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         7884 :         t = ai.unconverted_ref_origin ();
    6079         9272 :       if (t == error_mark_node)
    6080              :         return error_mark_node;
    6081         9272 :       ret = t_refto;
    6082         9272 :       if (TREE_CODE (t) == FIELD_DECL)
    6083           33 :         ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6084         9239 :       else if (!VAR_P (t)
    6085         2699 :                && (openacc || !EXPR_P (t))
    6086         2504 :                && 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         9191 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6101         9001 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6102        17264 :                && 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         9207 :       if (type_dependent_expression_p (ret))
    6110              :         return NULL_TREE;
    6111         8520 :       ret = convert_from_reference (ret);
    6112         8520 :       return ret;
    6113         9272 :     }
    6114              : 
    6115        11194 :   if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
    6116         7391 :       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6117         6197 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6118         4913 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6119        13800 :       && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
    6120           43 :     TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
    6121        11194 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
    6122              :                                      maybe_zero_len, first_non_one, ort);
    6123        11194 :   if (ret == error_mark_node || ret == NULL_TREE)
    6124              :     return ret;
    6125              : 
    6126        10190 :   type = TREE_TYPE (ret);
    6127        10190 :   low_bound = TREE_OPERAND (t, 1);
    6128        10190 :   length = TREE_OPERAND (t, 2);
    6129         8243 :   if ((low_bound && type_dependent_expression_p (low_bound))
    6130        18350 :       || (length && type_dependent_expression_p (length)))
    6131           88 :     return NULL_TREE;
    6132              : 
    6133        10102 :   if (low_bound == error_mark_node || length == error_mark_node)
    6134              :     return error_mark_node;
    6135              : 
    6136        10102 :   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        10033 :   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         9970 :   if (low_bound)
    6151         8077 :     low_bound = mark_rvalue_use (low_bound);
    6152         9970 :   if (length)
    6153         9024 :     length = mark_rvalue_use (length);
    6154              :   /* We need to reduce to real constant-values for checks below.  */
    6155         9024 :   if (length)
    6156         9024 :     length = fold_simple (length);
    6157         9970 :   if (low_bound)
    6158         8077 :     low_bound = fold_simple (low_bound);
    6159         8077 :   if (low_bound
    6160         8077 :       && TREE_CODE (low_bound) == INTEGER_CST
    6161        15229 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
    6162         7152 :          > TYPE_PRECISION (sizetype))
    6163            0 :     low_bound = fold_convert (sizetype, low_bound);
    6164         9970 :   if (length
    6165         9024 :       && TREE_CODE (length) == INTEGER_CST
    6166        16983 :       && TYPE_PRECISION (TREE_TYPE (length))
    6167         7013 :          > TYPE_PRECISION (sizetype))
    6168            0 :     length = fold_convert (sizetype, length);
    6169         9970 :   if (low_bound == NULL_TREE)
    6170         1893 :     low_bound = integer_zero_node;
    6171              : 
    6172         9970 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6173         9970 :       && (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         9934 :   if (length != NULL_TREE)
    6185              :     {
    6186         9012 :       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         8984 :       if (first_non_one == types.length ()
    6206         8984 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
    6207         3927 :         first_non_one++;
    6208              :     }
    6209         9906 :   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         4445 :   else if (TYPE_PTR_P (type))
    6340              :     {
    6341         4388 :       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         4346 :       if (length != NULL_TREE
    6353         4346 :           && TREE_CODE (length) == INTEGER_CST
    6354         3253 :           && 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         4262 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6364         4220 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6365         7998 :           && 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         9185 :   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         9185 :   tree lb = cp_save_expr (low_bound);
    6393         9185 :   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         9185 :   warning_sentinel s (flag_strong_eval_order,
    6406         9185 :                       OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6407         8172 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6408        18489 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
    6409         9185 :   ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
    6410              :                          tf_warning_or_error);
    6411         9185 :   return ret;
    6412         9185 : }
    6413              : 
    6414              : /* Handle array sections for clause C.  */
    6415              : 
    6416              : static bool
    6417         9278 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
    6418              : {
    6419         9278 :   bool maybe_zero_len = false;
    6420         9278 :   unsigned int first_non_one = 0;
    6421         9278 :   auto_vec<tree, 10> types;
    6422         9278 :   tree *tp = &OMP_CLAUSE_DECL (c);
    6423         9278 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6424         8320 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6425         9484 :       && OMP_ITERATOR_DECL_P (*tp))
    6426          258 :     tp = &TREE_VALUE (*tp);
    6427         9278 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
    6428              :                                             maybe_zero_len, first_non_one,
    6429              :                                             ort);
    6430         9278 :   if (first == error_mark_node)
    6431              :     return true;
    6432         8308 :   if (first == NULL_TREE)
    6433              :     return false;
    6434         7515 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6435         7515 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6436              :     {
    6437          850 :       tree t = *tp;
    6438          850 :       tree tem = NULL_TREE;
    6439          850 :       if (processing_template_decl)
    6440              :         return false;
    6441              :       /* Need to evaluate side effects in the length expressions
    6442              :          if any.  */
    6443          751 :       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          751 :       if (tem)
    6456            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
    6457          751 :       *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         9278 : }
    6697              : 
    6698              : /* Return identifier to look up for omp declare reduction.  */
    6699              : 
    6700              : tree
    6701         7085 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
    6702              : {
    6703         7085 :   const char *p = NULL;
    6704         7085 :   const char *m = NULL;
    6705         7085 :   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         6921 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
    6730            0 :         return error_mark_node;
    6731         6921 :       p = IDENTIFIER_POINTER (reduction_id);
    6732              :     }
    6733              : 
    6734         7085 :   if (type != NULL_TREE)
    6735         2033 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6736              : 
    6737         7085 :   const char prefix[] = "omp declare reduction ";
    6738         7085 :   size_t lenp = sizeof (prefix);
    6739         7085 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6740         2033 :     lenp = 1;
    6741         7085 :   size_t len = strlen (p);
    6742         7085 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6743         7085 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6744         7085 :   if (lenp > 1)
    6745         5052 :     memcpy (name, prefix, lenp - 1);
    6746         7085 :   memcpy (name + lenp - 1, p, len + 1);
    6747         7085 :   if (m)
    6748              :     {
    6749         2033 :       name[lenp + len - 1] = '~';
    6750         2033 :       memcpy (name + lenp + len, m, lenm);
    6751              :     }
    6752         7085 :   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         1288 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
    6760              :                       vec<tree> *ambiguousp)
    6761              : {
    6762         1288 :   tree orig_id = id;
    6763         1288 :   tree baselink = NULL_TREE;
    6764         1288 :   if (identifier_p (id))
    6765              :     {
    6766         1260 :       cp_id_kind idk;
    6767         1260 :       bool nonint_cst_expression_p;
    6768         1260 :       const char *error_msg;
    6769         1260 :       id = omp_reduction_id (ERROR_MARK, id, type);
    6770         1260 :       tree decl = lookup_name (id);
    6771         1260 :       if (decl == NULL_TREE)
    6772           80 :         decl = error_mark_node;
    6773         1260 :       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         1260 :       if (idk == CP_ID_KIND_UNQUALIFIED
    6777         1340 :           && 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         1288 :   tree fns = id;
    6791         1288 :   id = NULL_TREE;
    6792         1288 :   if (fns && is_overloaded_fn (fns))
    6793              :     {
    6794         1214 :       for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
    6795              :         {
    6796         1214 :           tree fndecl = *iter;
    6797         1214 :           if (TREE_CODE (fndecl) == FUNCTION_DECL)
    6798              :             {
    6799         1214 :               tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
    6800         1214 :               if (same_type_p (TREE_TYPE (argtype), type))
    6801              :                 {
    6802         1214 :                   id = fndecl;
    6803         1214 :                   break;
    6804              :                 }
    6805              :             }
    6806              :         }
    6807              : 
    6808         1214 :       if (id && BASELINK_P (fns))
    6809              :         {
    6810           74 :           if (baselinkp)
    6811            0 :             *baselinkp = fns;
    6812              :           else
    6813           74 :             baselink = fns;
    6814              :         }
    6815              :     }
    6816              : 
    6817         1288 :   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         1272 :   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        11896 : cxx_omp_mapper_lookup (tree id, tree type)
    6905              : {
    6906        11896 :   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          244 :         t = build_array_ref (loc, t, low);
    6955              :       else
    6956           56 :         t = error_mark_node;
    6957              :     }
    6958              : 
    6959         1910 :   return t;
    6960              : }
    6961              : 
    6962              : /* Helper function for cp_parser_omp_declare_reduction_exprs
    6963              :    and tsubst_omp_udr.
    6964              :    Remove CLEANUP_STMT for data (omp_priv variable).
    6965              :    Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
    6966              :    DECL_EXPR.  */
    6967              : 
    6968              : tree
    6969         4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
    6970              : {
    6971         4395 :   if (TYPE_P (*tp))
    6972          227 :     *walk_subtrees = 0;
    6973         4168 :   else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
    6974           52 :     *tp = CLEANUP_BODY (*tp);
    6975         4116 :   else if (TREE_CODE (*tp) == DECL_EXPR)
    6976              :     {
    6977          307 :       tree decl = DECL_EXPR_DECL (*tp);
    6978          307 :       if (!processing_template_decl
    6979          258 :           && decl == (tree) data
    6980          258 :           && DECL_INITIAL (decl)
    6981          399 :           && DECL_INITIAL (decl) != error_mark_node)
    6982              :         {
    6983           92 :           tree list = NULL_TREE;
    6984           92 :           append_to_statement_list_force (*tp, &list);
    6985           92 :           tree init_expr = build2 (INIT_EXPR, void_type_node,
    6986           92 :                                    decl, DECL_INITIAL (decl));
    6987           92 :           DECL_INITIAL (decl) = NULL_TREE;
    6988           92 :           append_to_statement_list_force (init_expr, &list);
    6989           92 :           *tp = list;
    6990              :         }
    6991              :     }
    6992         4395 :   return NULL_TREE;
    6993              : }
    6994              : 
    6995              : /* Data passed from cp_check_omp_declare_reduction to
    6996              :    cp_check_omp_declare_reduction_r.  */
    6997              : 
    6998              : struct cp_check_omp_declare_reduction_data
    6999              : {
    7000              :   location_t loc;
    7001              :   tree stmts[7];
    7002              :   bool combiner_p;
    7003              : };
    7004              : 
    7005              : /* Helper function for cp_check_omp_declare_reduction, called via
    7006              :    cp_walk_tree.  */
    7007              : 
    7008              : static tree
    7009        14952 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
    7010              : {
    7011        14952 :   struct cp_check_omp_declare_reduction_data *udr_data
    7012              :     = (struct cp_check_omp_declare_reduction_data *) data;
    7013        14952 :   if (SSA_VAR_P (*tp)
    7014         2687 :       && !DECL_ARTIFICIAL (*tp)
    7015          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
    7016          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
    7017              :     {
    7018          135 :       location_t loc = udr_data->loc;
    7019          135 :       if (udr_data->combiner_p)
    7020           45 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
    7021              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
    7022              :                   *tp);
    7023              :       else
    7024           90 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
    7025              :                        "to variable %qD which is not %<omp_priv%> nor "
    7026              :                        "%<omp_orig%>",
    7027              :                   *tp);
    7028          135 :       return *tp;
    7029              :     }
    7030              :   return NULL_TREE;
    7031              : }
    7032              : 
    7033              : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions.  */
    7034              : 
    7035              : bool
    7036         1100 : cp_check_omp_declare_reduction (tree udr)
    7037              : {
    7038         1100 :   tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
    7039         1100 :   gcc_assert (TYPE_REF_P (type));
    7040         1100 :   type = TREE_TYPE (type);
    7041         1100 :   int i;
    7042         1100 :   location_t loc = DECL_SOURCE_LOCATION (udr);
    7043              : 
    7044         1100 :   if (type == error_mark_node)
    7045              :     return false;
    7046         1100 :   if (ARITHMETIC_TYPE_P (type))
    7047              :     {
    7048              :       static enum tree_code predef_codes[]
    7049              :         = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
    7050              :             BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
    7051         3276 :       for (i = 0; i < 8; i++)
    7052              :         {
    7053         2918 :           tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
    7054         2918 :           const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
    7055         2918 :           const char *n2 = IDENTIFIER_POINTER (id);
    7056         2918 :           if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
    7057         2918 :               && (n1[IDENTIFIER_LENGTH (id)] == '~'
    7058            0 :                   || n1[IDENTIFIER_LENGTH (id)] == '\0'))
    7059              :             break;
    7060              :         }
    7061              : 
    7062          376 :       if (i == 8
    7063          358 :           && TREE_CODE (type) != COMPLEX_EXPR)
    7064              :         {
    7065          358 :           const char prefix_minmax[] = "omp declare reduction m";
    7066          358 :           size_t prefix_size = sizeof (prefix_minmax) - 1;
    7067          358 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
    7068          358 :           if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
    7069              :                        prefix_minmax, prefix_size) == 0
    7070           10 :               && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
    7071            4 :                   || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
    7072          368 :               && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
    7073            6 :             i = 0;
    7074              :         }
    7075          376 :       if (i < 8)
    7076              :         {
    7077           24 :           error_at (loc, "predeclared arithmetic type %qT in "
    7078              :                          "%<#pragma omp declare reduction%>", type);
    7079           24 :           return false;
    7080              :         }
    7081              :     }
    7082              :   else if (FUNC_OR_METHOD_TYPE_P (type)
    7083              :            || TREE_CODE (type) == ARRAY_TYPE)
    7084              :     {
    7085           24 :       error_at (loc, "function or array type %qT in "
    7086              :                      "%<#pragma omp declare reduction%>", type);
    7087           24 :       return false;
    7088              :     }
    7089              :   else if (TYPE_REF_P (type))
    7090              :     {
    7091            0 :       error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
    7092              :                 type);
    7093            0 :       return false;
    7094              :     }
    7095          700 :   else if (TYPE_QUALS_NO_ADDR_SPACE (type))
    7096              :     {
    7097           24 :       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
    7098              :                 "type %qT in %<#pragma omp declare reduction%>", type);
    7099           24 :       return false;
    7100              :     }
    7101              : 
    7102         1028 :   tree body = DECL_SAVED_TREE (udr);
    7103         1028 :   if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
    7104              :     return true;
    7105              : 
    7106          842 :   tree_stmt_iterator tsi;
    7107          842 :   struct cp_check_omp_declare_reduction_data data;
    7108          842 :   memset (data.stmts, 0, sizeof data.stmts);
    7109          842 :   for (i = 0, tsi = tsi_start (body);
    7110         4679 :        i < 7 && !tsi_end_p (tsi);
    7111         3837 :        i++, tsi_next (&tsi))
    7112         3837 :     data.stmts[i] = tsi_stmt (tsi);
    7113          842 :   data.loc = loc;
    7114          842 :   gcc_assert (tsi_end_p (tsi));
    7115          842 :   if (i >= 3)
    7116              :     {
    7117          842 :       gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
    7118              :                   && TREE_CODE (data.stmts[1]) == DECL_EXPR);
    7119          842 :       if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
    7120              :         return true;
    7121          797 :       data.combiner_p = true;
    7122          797 :       if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
    7123              :                         &data, NULL))
    7124           45 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
    7125              :     }
    7126          797 :   if (i >= 6)
    7127              :     {
    7128          336 :       gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
    7129              :                   && TREE_CODE (data.stmts[4]) == DECL_EXPR);
    7130          336 :       data.combiner_p = false;
    7131          336 :       if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
    7132              :                         &data, NULL)
    7133          336 :           || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
    7134              :                            cp_check_omp_declare_reduction_r, &data, NULL))
    7135           90 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /* Wat warning? */);
    7136          336 :       if (i == 7)
    7137          198 :         gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
    7138              :     }
    7139              :   return true;
    7140              : }
    7141              : 
    7142              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
    7143              :    an inline call.  But, remap
    7144              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
    7145              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
    7146              : 
    7147              : static tree
    7148         2198 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
    7149              :                tree decl, tree placeholder)
    7150              : {
    7151         2198 :   copy_body_data id;
    7152         2198 :   hash_map<tree, tree> decl_map;
    7153              : 
    7154         2198 :   decl_map.put (omp_decl1, placeholder);
    7155         2198 :   decl_map.put (omp_decl2, decl);
    7156         2198 :   memset (&id, 0, sizeof (id));
    7157         2198 :   id.src_fn = DECL_CONTEXT (omp_decl1);
    7158         2198 :   id.dst_fn = current_function_decl;
    7159         2198 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    7160         2198 :   id.decl_map = &decl_map;
    7161              : 
    7162         2198 :   id.copy_decl = copy_decl_no_change;
    7163         2198 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    7164         2198 :   id.transform_new_cfg = true;
    7165         2198 :   id.transform_return_to_modify = false;
    7166         2198 :   id.eh_lp_nr = 0;
    7167         2198 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
    7168         2198 :   return stmt;
    7169         2198 : }
    7170              : 
    7171              : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
    7172              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
    7173              : 
    7174              : static tree
    7175        15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
    7176              : {
    7177        15438 :   if (*tp == (tree) data)
    7178          265 :     return *tp;
    7179              :   return NULL_TREE;
    7180              : }
    7181              : 
    7182              : /* Helper function of finish_omp_clauses.  Handle OMP_CLAUSE_REDUCTION C.
    7183              :    Return true if there is some error and the clause should be removed.  */
    7184              : 
    7185              : static bool
    7186         8855 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
    7187              : {
    7188         8855 :   tree t = OMP_CLAUSE_DECL (c);
    7189         8855 :   bool predefined = false;
    7190         8855 :   if (TREE_CODE (t) == TREE_LIST)
    7191              :     {
    7192            0 :       gcc_assert (processing_template_decl);
    7193              :       return false;
    7194              :     }
    7195         8855 :   tree type = TREE_TYPE (t);
    7196         8855 :   if (TREE_CODE (t) == MEM_REF)
    7197         1596 :     type = TREE_TYPE (type);
    7198         8855 :   if (TYPE_REF_P (type))
    7199          527 :     type = TREE_TYPE (type);
    7200         8855 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7201              :     {
    7202          350 :       tree oatype = type;
    7203          350 :       gcc_assert (TREE_CODE (t) != MEM_REF);
    7204          703 :       while (TREE_CODE (type) == ARRAY_TYPE)
    7205          353 :         type = TREE_TYPE (type);
    7206          350 :       if (!processing_template_decl)
    7207              :         {
    7208          255 :           t = require_complete_type (t);
    7209          255 :           if (t == error_mark_node
    7210          255 :               || !complete_type_or_else (oatype, NULL_TREE))
    7211            9 :             return true;
    7212          246 :           tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
    7213              :                                   TYPE_SIZE_UNIT (type));
    7214          246 :           if (integer_zerop (size))
    7215              :             {
    7216            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7217              :                         "%qE in %<reduction%> clause is a zero size array",
    7218              :                         omp_clause_printable_decl (t));
    7219            3 :               return true;
    7220              :             }
    7221          243 :           size = size_binop (MINUS_EXPR, size, size_one_node);
    7222          243 :           size = save_expr (size);
    7223          243 :           tree index_type = build_index_type (size);
    7224          243 :           tree atype = build_array_type (type, index_type);
    7225          243 :           tree ptype = build_pointer_type (type);
    7226          243 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    7227          146 :             t = build_fold_addr_expr (t);
    7228          243 :           t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
    7229          243 :           OMP_CLAUSE_DECL (c) = t;
    7230              :         }
    7231              :     }
    7232         8843 :   if (type == error_mark_node)
    7233              :     return true;
    7234         8840 :   else if (ARITHMETIC_TYPE_P (type))
    7235         7590 :     switch (OMP_CLAUSE_REDUCTION_CODE (c))
    7236              :       {
    7237              :       case PLUS_EXPR:
    7238              :       case MULT_EXPR:
    7239              :       case MINUS_EXPR:
    7240              :       case TRUTH_ANDIF_EXPR:
    7241              :       case TRUTH_ORIF_EXPR:
    7242              :         predefined = true;
    7243              :         break;
    7244          246 :       case MIN_EXPR:
    7245          246 :       case MAX_EXPR:
    7246          246 :         if (TREE_CODE (type) == COMPLEX_TYPE)
    7247              :           break;
    7248              :         predefined = true;
    7249              :         break;
    7250          111 :       case BIT_AND_EXPR:
    7251          111 :       case BIT_IOR_EXPR:
    7252          111 :       case BIT_XOR_EXPR:
    7253          111 :         if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
    7254              :           break;
    7255              :         predefined = true;
    7256              :         break;
    7257              :       default:
    7258              :         break;
    7259              :       }
    7260         1250 :   else if (TYPE_READONLY (type))
    7261              :     {
    7262           18 :       error_at (OMP_CLAUSE_LOCATION (c),
    7263              :                 "%qE has const type for %<reduction%>",
    7264              :                 omp_clause_printable_decl (t));
    7265            9 :       return true;
    7266              :     }
    7267         1241 :   else if (!processing_template_decl)
    7268              :     {
    7269         1037 :       t = require_complete_type (t);
    7270         1037 :       if (t == error_mark_node)
    7271              :         return true;
    7272         1037 :       OMP_CLAUSE_DECL (c) = t;
    7273              :     }
    7274              : 
    7275         1037 :   if (predefined)
    7276              :     {
    7277         7368 :       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7278         7368 :       return false;
    7279              :     }
    7280         1463 :   else if (processing_template_decl)
    7281              :     {
    7282          213 :       if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
    7283              :         return true;
    7284              :       return false;
    7285              :     }
    7286              : 
    7287         1250 :   tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
    7288              : 
    7289         1250 :   type = TYPE_MAIN_VARIANT (type);
    7290         1250 :   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7291         1250 :   if (id == NULL_TREE)
    7292          924 :     id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
    7293              :                            NULL_TREE, NULL_TREE);
    7294         1250 :   id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
    7295         1250 :   if (id)
    7296              :     {
    7297         1205 :       if (id == error_mark_node)
    7298              :         return true;
    7299         1199 :       mark_used (id);
    7300         1199 :       tree body = DECL_SAVED_TREE (id);
    7301         1199 :       if (!body)
    7302              :         return true;
    7303         1196 :       if (TREE_CODE (body) == STATEMENT_LIST)
    7304              :         {
    7305         1196 :           tree_stmt_iterator tsi;
    7306         1196 :           tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
    7307         1196 :           int i;
    7308         1196 :           tree stmts[7];
    7309         1196 :           tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
    7310         1196 :           atype = TREE_TYPE (atype);
    7311         1196 :           bool need_static_cast = !same_type_p (type, atype);
    7312         1196 :           memset (stmts, 0, sizeof stmts);
    7313         1196 :           for (i = 0, tsi = tsi_start (body);
    7314         8518 :                i < 7 && !tsi_end_p (tsi);
    7315         7322 :                i++, tsi_next (&tsi))
    7316         7322 :             stmts[i] = tsi_stmt (tsi);
    7317         1196 :           gcc_assert (tsi_end_p (tsi));
    7318              : 
    7319         1196 :           if (i >= 3)
    7320              :             {
    7321         1196 :               gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
    7322              :                           && TREE_CODE (stmts[1]) == DECL_EXPR);
    7323         1196 :               placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
    7324         1196 :               DECL_ARTIFICIAL (placeholder) = 1;
    7325         1196 :               DECL_IGNORED_P (placeholder) = 1;
    7326         1196 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
    7327         1196 :               if (TREE_CODE (t) == MEM_REF)
    7328              :                 {
    7329          600 :                   decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
    7330              :                                                       type);
    7331          600 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
    7332          600 :                   DECL_IGNORED_P (decl_placeholder) = 1;
    7333          600 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
    7334              :                 }
    7335         1196 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
    7336          285 :                 cxx_mark_addressable (placeholder);
    7337         1196 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
    7338         1196 :                   && (decl_placeholder
    7339          149 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7340          372 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7341          118 :                                       : OMP_CLAUSE_DECL (c));
    7342         1196 :               tree omp_out = placeholder;
    7343         1196 :               tree omp_in = decl_placeholder ? decl_placeholder
    7344          596 :                             : convert_from_reference (OMP_CLAUSE_DECL (c));
    7345         1196 :               if (need_static_cast)
    7346              :                 {
    7347            7 :                   tree rtype = build_reference_type (atype);
    7348            7 :                   omp_out = build_static_cast (input_location,
    7349              :                                                rtype, omp_out,
    7350              :                                                tf_warning_or_error);
    7351            7 :                   omp_in = build_static_cast (input_location,
    7352              :                                               rtype, omp_in,
    7353              :                                               tf_warning_or_error);
    7354            7 :                   if (omp_out == error_mark_node || omp_in == error_mark_node)
    7355            3 :                     return true;
    7356            7 :                   omp_out = convert_from_reference (omp_out);
    7357            7 :                   omp_in = convert_from_reference (omp_in);
    7358              :                 }
    7359         1196 :               OMP_CLAUSE_REDUCTION_MERGE (c)
    7360         1196 :                 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
    7361         1196 :                                  DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
    7362              :             }
    7363         1196 :           if (i >= 6)
    7364              :             {
    7365         1005 :               gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
    7366              :                           && TREE_CODE (stmts[4]) == DECL_EXPR);
    7367         1005 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
    7368         1005 :                   && (decl_placeholder
    7369          232 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7370          844 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7371          170 :                                       : OMP_CLAUSE_DECL (c));
    7372         1005 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
    7373          216 :                 cxx_mark_addressable (placeholder);
    7374         1005 :               tree omp_priv = decl_placeholder ? decl_placeholder
    7375          429 :                               : convert_from_reference (OMP_CLAUSE_DECL (c));
    7376         1005 :               tree omp_orig = placeholder;
    7377         1005 :               if (need_static_cast)
    7378              :                 {
    7379            5 :                   if (i == 7)
    7380              :                     {
    7381            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    7382              :                                 "user defined reduction with constructor "
    7383              :                                 "initializer for base class %qT", atype);
    7384            3 :                       return true;
    7385              :                     }
    7386            2 :                   tree rtype = build_reference_type (atype);
    7387            2 :                   omp_priv = build_static_cast (input_location,
    7388              :                                                 rtype, omp_priv,
    7389              :                                                 tf_warning_or_error);
    7390            2 :                   omp_orig = build_static_cast (input_location,
    7391              :                                                 rtype, omp_orig,
    7392              :                                                 tf_warning_or_error);
    7393            2 :                   if (omp_priv == error_mark_node
    7394            2 :                       || omp_orig == error_mark_node)
    7395              :                     return true;
    7396            2 :                   omp_priv = convert_from_reference (omp_priv);
    7397            2 :                   omp_orig = convert_from_reference (omp_orig);
    7398              :                 }
    7399         1002 :               if (i == 6)
    7400          286 :                 *need_default_ctor = true;
    7401         1002 :               OMP_CLAUSE_REDUCTION_INIT (c)
    7402         1002 :                 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
    7403         1002 :                                  DECL_EXPR_DECL (stmts[3]),
    7404              :                                  omp_priv, omp_orig);
    7405         1002 :               if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
    7406              :                                 find_omp_placeholder_r, placeholder, NULL))
    7407          238 :                 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
    7408              :             }
    7409          191 :           else if (i >= 3)
    7410              :             {
    7411          191 :               if (CLASS_TYPE_P (type) && !pod_type_p (type))
    7412          175 :                 *need_default_ctor = true;
    7413              :               else
    7414              :                 {
    7415           16 :                   tree init;
    7416           16 :                   tree v = decl_placeholder ? decl_placeholder
    7417           16 :                            : convert_from_reference (t);
    7418           16 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
    7419            7 :                     init = build_constructor (TREE_TYPE (v), NULL);
    7420              :                   else
    7421            9 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
    7422           32 :                   OMP_CLAUSE_REDUCTION_INIT (c)
    7423           32 :                     = cp_build_init_expr (v, init);
    7424              :                 }
    7425              :             }
    7426              :         }
    7427              :     }
    7428         1238 :   if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
    7429         1193 :     *need_dtor = true;
    7430              :   else
    7431              :     {
    7432           90 :       error_at (OMP_CLAUSE_LOCATION (c),
    7433              :                 "user defined reduction not found for %qE",
    7434              :                 omp_clause_printable_decl (t));
    7435           45 :       return true;
    7436              :     }
    7437         1193 :   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
    7438          600 :     gcc_assert (TYPE_SIZE_UNIT (type)
    7439              :                 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
    7440              :   return false;
    7441              : }
    7442              : 
    7443              : /* Check an instance of an "omp declare mapper" function.  */
    7444              : 
    7445              : bool
    7446          208 : cp_check_omp_declare_mapper (tree udm)
    7447              : {
    7448          208 :   tree var = OMP_DECLARE_MAPPER_DECL (udm);
    7449          208 :   tree type = TREE_TYPE (var);
    7450          208 :   location_t loc = DECL_SOURCE_LOCATION (var);
    7451              : 
    7452          208 :   if (type == error_mark_node)
    7453              :     return false;
    7454              : 
    7455          208 :   if (processing_template_decl)
    7456              :     return true;
    7457              : 
    7458          197 :   if (!RECORD_OR_UNION_TYPE_P (type))
    7459              :     {
    7460           17 :       error_at (loc, "%qT is not a struct, union or class type in "
    7461              :                 "%<#pragma omp declare mapper%>", type);
    7462           17 :       return false;
    7463              :     }
    7464          180 :   if (CLASSTYPE_VBASECLASSES (type))
    7465              :     {
    7466            3 :       error_at (loc, "%qT must not be a virtual base class in "
    7467              :                 "%<#pragma omp declare mapper%>", type);
    7468            3 :       return false;
    7469              :     }
    7470              : 
    7471          177 :   tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
    7472          215 :   for ( ; c; c = OMP_CLAUSE_CHAIN (c))
    7473              :     {
    7474          187 :       tree dvar = OMP_CLAUSE_DECL (c);
    7475          400 :       while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
    7476          213 :         dvar = TREE_OPERAND (dvar, 0);
    7477          187 :       if (dvar == var)
    7478              :         break;
    7479              :     }
    7480          177 :   if (!c)
    7481              :     {
    7482              :       // After template handling, the var is mangled, demangle it
    7483           28 :       const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
    7484           28 :       char *n = NULL;
    7485           28 :       if (startswith (name, "omp declare mapper "))
    7486              :         {
    7487            3 :           name += strlen ("omp declare mapper ");
    7488            3 :           n = xstrdup (name);
    7489            3 :           n[strchr (n, '~')-n] = '\0';
    7490            3 :           name = n;
    7491              :         }
    7492           28 :       error_at (loc, "at least one %<map%> clause must map %qs or an "
    7493              :                      "element of it", name);
    7494           28 :       if (n)
    7495            3 :         free (n);
    7496           28 :       return false;
    7497              :     }
    7498              : 
    7499              :   /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
    7500              :      = 1, which is set to false in finalize_literal_type_property for C++ < 11,
    7501              :      leading to an error in ensure_literal_type_for_constexpr_object.
    7502              :      Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
    7503              :      libgomp.c++/declare-mapper-{5,6,8}.C.  */
    7504          149 :   if (cxx_dialect < cxx11)
    7505              :     {
    7506            0 :       sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
    7507              :                      "before C++11");
    7508            0 :       return false;
    7509              :     }
    7510              : 
    7511              :   return true;
    7512              : }
    7513              : 
    7514              : /* Called from finish_struct_1.  linear(this) or linear(this:step)
    7515              :    clauses might not be finalized yet because the class has been incomplete
    7516              :    when parsing #pragma omp declare simd methods.  Fix those up now.  */
    7517              : 
    7518              : void
    7519       118255 : finish_omp_declare_simd_methods (tree t)
    7520              : {
    7521       118255 :   if (processing_template_decl)
    7522              :     return;
    7523              : 
    7524       807742 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7525              :     {
    7526      1141350 :       if (TREE_CODE (x) == USING_DECL
    7527       689487 :           || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
    7528       451863 :         continue;
    7529       237624 :       tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
    7530       237732 :       if (!ods || !TREE_VALUE (ods))
    7531       237516 :         continue;
    7532          366 :       for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
    7533          258 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
    7534           66 :             && integer_zerop (OMP_CLAUSE_DECL (c))
    7535           18 :             && OMP_CLAUSE_LINEAR_STEP (c)
    7536          276 :             && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
    7537              :           {
    7538           18 :             tree s = OMP_CLAUSE_LINEAR_STEP (c);
    7539           18 :             s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
    7540           18 :             s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
    7541           18 :                                  sizetype, s, TYPE_SIZE_UNIT (t));
    7542           18 :             OMP_CLAUSE_LINEAR_STEP (c) = s;
    7543              :           }
    7544              :     }
    7545              : }
    7546              : 
    7547              : /* Adjust sink depend/doacross clause to take into account pointer offsets.
    7548              : 
    7549              :    Return TRUE if there was a problem processing the offset, and the
    7550              :    whole clause should be removed.  */
    7551              : 
    7552              : static bool
    7553          298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
    7554              : {
    7555          298 :   tree t = OMP_CLAUSE_DECL (sink_clause);
    7556          298 :   gcc_assert (TREE_CODE (t) == TREE_LIST);
    7557              : 
    7558              :   /* Make sure we don't adjust things twice for templates.  */
    7559          298 :   if (processing_template_decl)
    7560              :     return false;
    7561              : 
    7562          671 :   for (; t; t = TREE_CHAIN (t))
    7563              :     {
    7564          391 :       tree decl = TREE_VALUE (t);
    7565          391 :       if (TYPE_PTR_P (TREE_TYPE (decl)))
    7566              :         {
    7567            6 :           tree offset = TREE_PURPOSE (t);
    7568            6 :           bool neg = wi::neg_p (wi::to_wide (offset));
    7569            6 :           offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
    7570            6 :           decl = mark_rvalue_use (decl);
    7571            6 :           decl = convert_from_reference (decl);
    7572           12 :           tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
    7573              :                                      neg ? MINUS_EXPR : PLUS_EXPR,
    7574              :                                      decl, offset);
    7575            6 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
    7576              :                                 MINUS_EXPR, sizetype,
    7577              :                                 fold_convert (sizetype, t2),
    7578              :                                 fold_convert (sizetype, decl));
    7579            6 :           if (t2 == error_mark_node)
    7580              :             return true;
    7581            6 :           TREE_PURPOSE (t) = t2;
    7582              :         }
    7583              :     }
    7584              :   return false;
    7585              : }
    7586              : 
    7587              : /* Finish OpenMP iterators ITER.  Return true if they are errorneous
    7588              :    and clauses containing them should be removed.  */
    7589              : 
    7590              : static bool
    7591          614 : cp_omp_finish_iterators (tree iter)
    7592              : {
    7593          614 :   bool ret = false;
    7594         1393 :   for (tree it = iter; it; it = TREE_CHAIN (it))
    7595              :     {
    7596          779 :       tree var = TREE_VEC_ELT (it, 0);
    7597          779 :       tree begin = TREE_VEC_ELT (it, 1);
    7598          779 :       tree end = TREE_VEC_ELT (it, 2);
    7599          779 :       tree step = TREE_VEC_ELT (it, 3);
    7600          779 :       tree orig_step;
    7601          779 :       tree type = TREE_TYPE (var);
    7602          779 :       location_t loc = DECL_SOURCE_LOCATION (var);
    7603          779 :       if (type == error_mark_node)
    7604              :         {
    7605            0 :           ret = true;
    7606          218 :           continue;
    7607              :         }
    7608          779 :       if (type_dependent_expression_p (var))
    7609           59 :         continue;
    7610          720 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7611              :         {
    7612           27 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
    7613              :                     var);
    7614           27 :           ret = true;
    7615           27 :           continue;
    7616              :         }
    7617          693 :       else if (TYPE_READONLY (type))
    7618              :         {
    7619           24 :           error_at (loc, "iterator %qD has const qualified type", var);
    7620           24 :           ret = true;
    7621           24 :           continue;
    7622              :         }
    7623          669 :       if (type_dependent_expression_p (begin)
    7624          660 :           || type_dependent_expression_p (end)
    7625         1329 :           || type_dependent_expression_p (step))
    7626           15 :         continue;
    7627          654 :       else if (error_operand_p (step))
    7628              :         {
    7629            0 :           ret = true;
    7630            0 :           continue;
    7631              :         }
    7632          654 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
    7633              :         {
    7634           33 :           error_at (EXPR_LOC_OR_LOC (step, loc),
    7635              :                     "iterator step with non-integral type");
    7636           21 :           ret = true;
    7637           21 :           continue;
    7638              :         }
    7639              : 
    7640          633 :       begin = mark_rvalue_use (begin);
    7641          633 :       end = mark_rvalue_use (end);
    7642          633 :       step = mark_rvalue_use (step);
    7643          633 :       begin = cp_build_c_cast (input_location, type, begin,
    7644              :                                tf_warning_or_error);
    7645          633 :       end = cp_build_c_cast (input_location, type, end,
    7646              :                              tf_warning_or_error);
    7647          633 :       orig_step = step;
    7648          633 :       if (!processing_template_decl)
    7649          556 :         step = orig_step = save_expr (step);
    7650          633 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
    7651          633 :       step = cp_build_c_cast (input_location, stype, step,
    7652              :                               tf_warning_or_error);
    7653          633 :       if (POINTER_TYPE_P (type) && !processing_template_decl)
    7654              :         {
    7655           66 :           begin = save_expr (begin);
    7656           66 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
    7657           66 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
    7658              :                                   fold_convert (sizetype, step),
    7659              :                                   fold_convert (sizetype, begin));
    7660           66 :           step = fold_convert (ssizetype, step);
    7661              :         }
    7662          633 :       if (!processing_template_decl)
    7663              :         {
    7664          556 :           begin = maybe_constant_value (begin);
    7665          556 :           end = maybe_constant_value (end);
    7666          556 :           step = maybe_constant_value (step);
    7667          556 :           orig_step = maybe_constant_value (orig_step);
    7668              :         }
    7669          633 :       if (integer_zerop (step))
    7670              :         {
    7671           27 :           error_at (loc, "iterator %qD has zero step", var);
    7672           27 :           ret = true;
    7673           27 :           continue;
    7674              :         }
    7675              : 
    7676          606 :       if (begin == error_mark_node
    7677          597 :           || end == error_mark_node
    7678          588 :           || step == error_mark_node
    7679          588 :           || orig_step == error_mark_node)
    7680              :         {
    7681           18 :           ret = true;
    7682           18 :           continue;
    7683              :         }
    7684              : 
    7685          588 :       if (!processing_template_decl)
    7686              :         {
    7687          511 :           begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
    7688          511 :           end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
    7689          511 :           step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
    7690          511 :           orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
    7691              :                                                      orig_step);
    7692              :         }
    7693          588 :       hash_set<tree> pset;
    7694          588 :       tree it2;
    7695          744 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
    7696              :         {
    7697          183 :           tree var2 = TREE_VEC_ELT (it2, 0);
    7698          183 :           tree begin2 = TREE_VEC_ELT (it2, 1);
    7699          183 :           tree end2 = TREE_VEC_ELT (it2, 2);
    7700          183 :           tree step2 = TREE_VEC_ELT (it2, 3);
    7701          183 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
    7702          183 :           if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
    7703              :             {
    7704            9 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
    7705              :                         "begin expression refers to outer iterator %qD", var);
    7706           36 :               break;
    7707              :             }
    7708          174 :           else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
    7709              :             {
    7710            9 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
    7711              :                         "end expression refers to outer iterator %qD", var);
    7712            9 :               break;
    7713              :             }
    7714          165 :           else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
    7715              :             {
    7716            9 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
    7717              :                         "step expression refers to outer iterator %qD", var);
    7718            9 :               break;
    7719              :             }
    7720              :         }
    7721          588 :       if (it2)
    7722              :         {
    7723           27 :           ret = true;
    7724           27 :           continue;
    7725              :         }
    7726          561 :       TREE_VEC_ELT (it, 1) = begin;
    7727          561 :       TREE_VEC_ELT (it, 2) = end;
    7728          561 :       if (processing_template_decl)
    7729           71 :         TREE_VEC_ELT (it, 3) = orig_step;
    7730              :       else
    7731              :         {
    7732          490 :           TREE_VEC_ELT (it, 3) = step;
    7733          490 :           TREE_VEC_ELT (it, 4) = orig_step;
    7734              :         }
    7735          588 :     }
    7736          614 :   return ret;
    7737              : }
    7738              : 
    7739              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
    7740              :    Return true if an error has been detected.  */
    7741              : 
    7742              : static bool
    7743        18637 : cp_oacc_check_attachments (tree c)
    7744              : {
    7745        18637 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    7746              :     return false;
    7747              : 
    7748              :   /* OpenACC attach / detach clauses must be pointers.  */
    7749        14658 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    7750        14658 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    7751              :     {
    7752          196 :       tree t = OMP_CLAUSE_DECL (c);
    7753          196 :       tree type;
    7754              : 
    7755          232 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7756           36 :         t = TREE_OPERAND (t, 0);
    7757              : 
    7758          196 :       type = TREE_TYPE (t);
    7759              : 
    7760          196 :       if (TREE_CODE (type) == REFERENCE_TYPE)
    7761           36 :         type = TREE_TYPE (type);
    7762              : 
    7763          196 :       if (TREE_CODE (type) != POINTER_TYPE)
    7764              :         {
    7765           36 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
    7766              :                     user_omp_clause_code_name (c, true));
    7767           36 :           return true;
    7768              :         }
    7769              :     }
    7770              : 
    7771              :   return false;
    7772              : }
    7773              : 
    7774              : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
    7775              :    happened.  */
    7776              : 
    7777              : tree
    7778          813 : cp_finish_omp_init_prefer_type (tree pref_type)
    7779              : {
    7780          813 :   if (processing_template_decl
    7781          741 :       || pref_type == NULL_TREE
    7782          356 :       || TREE_CODE (pref_type) != TREE_LIST)
    7783              :     return pref_type;
    7784              : 
    7785           81 :   tree t = TREE_PURPOSE (pref_type);
    7786           81 :   char *str = const_cast<char *> (TREE_STRING_POINTER (t));
    7787           81 :   tree fr_list = TREE_VALUE (pref_type);
    7788           81 :   int len = TREE_VEC_LENGTH (fr_list);
    7789           81 :   int cnt = 0;
    7790              : 
    7791          270 :   while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
    7792              :     {
    7793          270 :       str++;
    7794          270 :       if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
    7795              :         {
    7796              :           /* Assume a no or a single 'fr'.  */
    7797          150 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7798          150 :           location_t loc = UNKNOWN_LOCATION;
    7799          150 :           tree value = TREE_VEC_ELT (fr_list, cnt);
    7800          150 :           if (value != NULL_TREE && value != error_mark_node)
    7801              :             {
    7802          126 :               loc = EXPR_LOCATION (value);
    7803          126 :               if (value && TREE_CODE (value) == NOP_EXPR)
    7804           39 :                 value = TREE_OPERAND (value, 0);
    7805          126 :               value = cp_fully_fold (value);
    7806              :             }
    7807          126 :           if (value != NULL_TREE && value != error_mark_node)
    7808              :             {
    7809          126 :               if (TREE_CODE (value) != INTEGER_CST
    7810          126 :                   || !tree_fits_shwi_p (value))
    7811            0 :                 error_at (loc,
    7812              :                           "expected string literal or "
    7813              :                           "constant integer expression instead of %qE", value);
    7814              :               else
    7815              :                 {
    7816          126 :                   HOST_WIDE_INT n = tree_to_shwi (value);
    7817          126 :                   if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
    7818              :                     {
    7819           48 :                       warning_at (loc, OPT_Wopenmp,
    7820              :                                   "unknown foreign runtime identifier %qwd", n);
    7821           48 :                       n = GOMP_INTEROP_IFR_UNKNOWN;
    7822              :                     }
    7823          126 :                   str[0] = (char) n;
    7824              :                 }
    7825              :             }
    7826          150 :           str++;
    7827              :         }
    7828          120 :       else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
    7829              :         {
    7830              :           /* Assume a no or a single 'fr'.  */
    7831          120 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7832          120 :           str++;
    7833              :         }
    7834          270 :       str++;
    7835          294 :       while (str[0] != '\0')
    7836           24 :         str += strlen (str) + 1;
    7837          270 :       str++;
    7838          270 :       cnt++;
    7839          270 :       if (cnt >= len)
    7840              :         break;
    7841              :     }
    7842              :   return t;
    7843              : }
    7844              : 
    7845              : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    7846              :    Remove any elements from the list that are invalid.  */
    7847              : 
    7848              : tree
    7849        62688 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
    7850              : {
    7851        62688 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
    7852        62688 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
    7853        62688 :   bitmap_head oacc_reduction_head, is_on_device_head;
    7854        62688 :   tree c, t, *pc;
    7855        62688 :   tree safelen = NULL_TREE;
    7856        62688 :   bool openacc = (ort & C_ORT_ACC) != 0;
    7857        62688 :   bool branch_seen = false;
    7858        62688 :   bool copyprivate_seen = false;
    7859        62688 :   bool ordered_seen = false;
    7860        62688 :   bool order_seen = false;
    7861        62688 :   bool schedule_seen = false;
    7862        62688 :   bool oacc_async = false;
    7863        62688 :   bool indir_component_ref_p = false;
    7864        62688 :   tree last_iterators = NULL_TREE;
    7865        62688 :   bool last_iterators_remove = false;
    7866              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
    7867              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
    7868        62688 :   int reduction_seen = 0;
    7869        62688 :   bool allocate_seen = false;
    7870        62688 :   tree detach_seen = NULL_TREE;
    7871        62688 :   bool mergeable_seen = false;
    7872        62688 :   bool implicit_moved = false;
    7873        62688 :   bool target_in_reduction_seen = false;
    7874        62688 :   bool num_tasks_seen = false;
    7875        62688 :   bool partial_seen = false;
    7876        62688 :   bool init_seen = false;
    7877        62688 :   bool init_use_destroy_seen = false;
    7878        62688 :   tree init_no_targetsync_clause = NULL_TREE;
    7879        62688 :   tree depend_clause = NULL_TREE;
    7880              : 
    7881        62688 :   if (!openacc)
    7882        49956 :     clauses = omp_remove_duplicate_maps (clauses, true);
    7883              : 
    7884        62688 :   bitmap_obstack_initialize (NULL);
    7885        62688 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
    7886        62688 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
    7887        62688 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
    7888        62688 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
    7889              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
    7890        62688 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
    7891        62688 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
    7892        62688 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
    7893              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
    7894              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
    7895        62688 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
    7896        62688 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
    7897              : 
    7898        62688 :   if (openacc)
    7899        28277 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
    7900        15933 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
    7901              :         {
    7902              :           oacc_async = true;
    7903              :           break;
    7904              :         }
    7905              : 
    7906        62688 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
    7907              : 
    7908       160622 :   for (pc = &clauses, c = clauses; c ; c = *pc)
    7909              :     {
    7910        97934 :       bool remove = false;
    7911        97934 :       bool field_ok = false;
    7912              : 
    7913              :       /* We've reached the end of a list of expanded nodes.  Reset the group
    7914              :          start pointer.  */
    7915        97934 :       if (c == grp_sentinel)
    7916              :         {
    7917         5662 :           if (grp_start_p
    7918         5662 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
    7919           96 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
    7920           66 :                  gc = OMP_CLAUSE_CHAIN (gc))
    7921           66 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
    7922              :           grp_start_p = NULL;
    7923              :         }
    7924              : 
    7925        97934 :       switch (OMP_CLAUSE_CODE (c))
    7926              :         {
    7927         2100 :         case OMP_CLAUSE_SHARED:
    7928         2100 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7929         2100 :           goto check_dup_generic;
    7930         2576 :         case OMP_CLAUSE_PRIVATE:
    7931         2576 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7932         2576 :           goto check_dup_generic;
    7933         7337 :         case OMP_CLAUSE_REDUCTION:
    7934         7337 :           if (reduction_seen == 0)
    7935         6233 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
    7936         1104 :           else if (reduction_seen != -2
    7937         2208 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
    7938         1104 :                                          ? -1 : 1))
    7939              :             {
    7940            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7941              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
    7942              :                         "on the same construct");
    7943            6 :               reduction_seen = -2;
    7944              :             }
    7945              :           /* FALLTHRU */
    7946         9482 :         case OMP_CLAUSE_IN_REDUCTION:
    7947         9482 :         case OMP_CLAUSE_TASK_REDUCTION:
    7948         9482 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7949         9482 :           t = OMP_CLAUSE_DECL (c);
    7950         9482 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7951              :             {
    7952         2207 :               if (handle_omp_array_sections (c, ort))
    7953              :                 {
    7954              :                   remove = true;
    7955              :                   break;
    7956              :                 }
    7957         2165 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    7958         2165 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
    7959              :                 {
    7960            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7961              :                             "%<inscan%> %<reduction%> clause with array "
    7962              :                             "section");
    7963            3 :                   remove = true;
    7964            3 :                   break;
    7965              :                 }
    7966         2162 :               if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7967              :                 {
    7968         4672 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7969         2510 :                     t = TREE_OPERAND (t, 0);
    7970              :                 }
    7971              :               else
    7972              :                 {
    7973            0 :                   gcc_assert (TREE_CODE (t) == MEM_REF);
    7974            0 :                   t = TREE_OPERAND (t, 0);
    7975            0 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
    7976            0 :                     t = TREE_OPERAND (t, 0);
    7977            0 :                   if (TREE_CODE (t) == ADDR_EXPR
    7978            0 :                       || INDIRECT_REF_P (t))
    7979            0 :                     t = TREE_OPERAND (t, 0);
    7980              :                 }
    7981         2162 :               tree n = omp_clause_decl_field (t);
    7982         2162 :               if (n)
    7983           59 :                 t = n;
    7984         2162 :               goto check_dup_generic_t;
    7985              :             }
    7986         7275 :           if (oacc_async)
    7987            7 :             cxx_mark_addressable (t);
    7988         7275 :           goto check_dup_generic;
    7989           98 :         case OMP_CLAUSE_COPYPRIVATE:
    7990           98 :           copyprivate_seen = true;
    7991           98 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7992           98 :           goto check_dup_generic;
    7993          277 :         case OMP_CLAUSE_COPYIN:
    7994          277 :           goto check_dup_generic;
    7995         1631 :         case OMP_CLAUSE_LINEAR:
    7996         1631 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7997         1631 :           t = OMP_CLAUSE_DECL (c);
    7998         1631 :           if (ort != C_ORT_OMP_DECLARE_SIMD
    7999         1631 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
    8000              :             {
    8001           84 :               if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
    8002              :                 {
    8003           42 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8004              :                             "modifier should not be specified in %<linear%> "
    8005              :                             "clause on %<simd%> or %<for%> constructs when "
    8006              :                             "not using OpenMP 5.2 modifiers");
    8007           42 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8008              :                 }
    8009           42 :               else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
    8010              :                 {
    8011           18 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8012              :                             "modifier other than %<val%> specified in "
    8013              :                             "%<linear%> clause on %<simd%> or %<for%> "
    8014              :                             "constructs when using OpenMP 5.2 modifiers");
    8015           18 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8016              :                 }
    8017              :             }
    8018         1011 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    8019         2571 :               && !type_dependent_expression_p (t))
    8020              :             {
    8021         1529 :               tree type = TREE_TYPE (t);
    8022         1529 :               if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8023         1448 :                    || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
    8024         1598 :                   && !TYPE_REF_P (type))
    8025              :                 {
    8026           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8027              :                             "linear clause with %qs modifier applied to "
    8028              :                             "non-reference variable with %qT type",
    8029           12 :                             OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8030           12 :                             ? "ref" : "uval", TREE_TYPE (t));
    8031           12 :                   remove = true;
    8032           12 :                   break;
    8033              :                 }
    8034         1517 :               if (TYPE_REF_P (type))
    8035          281 :                 type = TREE_TYPE (type);
    8036         1517 :               if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
    8037              :                 {
    8038         1442 :                   if (!INTEGRAL_TYPE_P (type)
    8039           85 :                       && !TYPE_PTR_P (type))
    8040              :                     {
    8041           18 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8042              :                                 "linear clause applied to non-integral "
    8043              :                                 "non-pointer variable with %qT type",
    8044           18 :                                 TREE_TYPE (t));
    8045           18 :                       remove = true;
    8046           18 :                       break;
    8047              :                     }
    8048              :                 }
    8049              :             }
    8050         1601 :           t = OMP_CLAUSE_LINEAR_STEP (c);
    8051         1601 :           if (t == NULL_TREE)
    8052            6 :             t = integer_one_node;
    8053         1601 :           if (t == error_mark_node)
    8054              :             {
    8055              :               remove = true;
    8056              :               break;
    8057              :             }
    8058         1601 :           else if (!type_dependent_expression_p (t)
    8059         1599 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t))
    8060         1613 :                    && (ort != C_ORT_OMP_DECLARE_SIMD
    8061            9 :                        || TREE_CODE (t) != PARM_DECL
    8062            6 :                        || !TYPE_REF_P (TREE_TYPE (t))
    8063            6 :                        || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
    8064              :             {
    8065            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8066              :                         "linear step expression must be integral");
    8067            6 :               remove = true;
    8068            6 :               break;
    8069              :             }
    8070              :           else
    8071              :             {
    8072         1595 :               t = mark_rvalue_use (t);
    8073         1595 :               if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
    8074              :                 {
    8075           42 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
    8076           42 :                   goto check_dup_generic;
    8077              :                 }
    8078         1553 :               if (!processing_template_decl
    8079         1553 :                   && (VAR_P (OMP_CLAUSE_DECL (c))
    8080          835 :                       || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
    8081              :                 {
    8082         1372 :                   if (ort == C_ORT_OMP_DECLARE_SIMD)
    8083              :                     {
    8084          589 :                       t = maybe_constant_value (t);
    8085          589 :                       if (TREE_CODE (t) != INTEGER_CST)
    8086              :                         {
    8087            6 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8088              :                                     "%<linear%> clause step %qE is neither "
    8089              :                                      "constant nor a parameter", t);
    8090            6 :                           remove = true;
    8091            6 :                           break;
    8092              :                         }
    8093              :                     }
    8094         1366 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8095         1366 :                   tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
    8096         1366 :                   if (TYPE_REF_P (type))
    8097          257 :                     type = TREE_TYPE (type);
    8098         1366 :                   if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
    8099              :                     {
    8100           66 :                       type = build_pointer_type (type);
    8101           66 :                       tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
    8102           66 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8103              :                                            d, t);
    8104           66 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8105              :                                            MINUS_EXPR, sizetype,
    8106              :                                            fold_convert (sizetype, t),
    8107              :                                            fold_convert (sizetype, d));
    8108           66 :                       if (t == error_mark_node)
    8109              :                         {
    8110              :                           remove = true;
    8111              :                           break;
    8112              :                         }
    8113              :                     }
    8114         1300 :                   else if (TYPE_PTR_P (type)
    8115              :                            /* Can't multiply the step yet if *this
    8116              :                               is still incomplete type.  */
    8117         1300 :                            && (ort != C_ORT_OMP_DECLARE_SIMD
    8118           45 :                                || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
    8119           45 :                                || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
    8120           30 :                                || DECL_NAME (OMP_CLAUSE_DECL (c))
    8121           30 :                                   != this_identifier
    8122           30 :                                || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
    8123              :                     {
    8124           37 :                       tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
    8125           37 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8126              :                                            d, t);
    8127           37 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8128              :                                            MINUS_EXPR, sizetype,
    8129              :                                            fold_convert (sizetype, t),
    8130              :                                            fold_convert (sizetype, d));
    8131           37 :                       if (t == error_mark_node)
    8132              :                         {
    8133              :                           remove = true;
    8134              :                           break;
    8135              :                         }
    8136              :                     }
    8137              :                   else
    8138         1263 :                     t = fold_convert (type, t);
    8139              :                 }
    8140         1547 :               OMP_CLAUSE_LINEAR_STEP (c) = t;
    8141              :             }
    8142         1547 :           goto check_dup_generic;
    8143        14881 :         check_dup_generic:
    8144        14881 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8145        14881 :           if (t)
    8146              :             {
    8147          101 :               if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
    8148          101 :                 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8149              :             }
    8150              :           else
    8151        14780 :             t = OMP_CLAUSE_DECL (c);
    8152        17310 :         check_dup_generic_t:
    8153        17310 :           if (t == current_class_ptr
    8154        17310 :               && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
    8155          102 :                   || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
    8156           72 :                       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
    8157              :             {
    8158           24 :               error_at (OMP_CLAUSE_LOCATION (c),
    8159              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8160              :                         " clauses");
    8161           24 :               remove = true;
    8162           24 :               break;
    8163              :             }
    8164        17286 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8165          586 :               && (!field_ok || TREE_CODE (t) != FIELD_DECL))
    8166              :             {
    8167           59 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8168              :                 break;
    8169           39 :               if (DECL_P (t))
    8170           30 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8171              :                           "%qD is not a variable in clause %qs", t,
    8172           15 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8173              :               else
    8174           48 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8175              :                           "%qE is not a variable in clause %qs", t,
    8176           24 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8177              :               remove = true;
    8178              :             }
    8179        17227 :           else if ((openacc
    8180         2707 :                     && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
    8181        14758 :                    || (ort == C_ORT_OMP
    8182        12427 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    8183        12396 :                            || (OMP_CLAUSE_CODE (c)
    8184              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
    8185        31878 :                    || (ort == C_ORT_OMP_TARGET
    8186          936 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
    8187              :             {
    8188         2854 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    8189         2854 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
    8190          275 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
    8191              :                 {
    8192            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8193              :                             "%qD appears more than once in data-sharing "
    8194              :                             "clauses", t);
    8195            6 :                   remove = true;
    8196            6 :                   break;
    8197              :                 }
    8198         2848 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
    8199          272 :                 target_in_reduction_seen = true;
    8200         2848 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8201              :                 {
    8202           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8203              :                             openacc
    8204              :                             ? "%qD appears more than once in reduction clauses"
    8205              :                             : "%qD appears more than once in data clauses",
    8206              :                             t);
    8207            6 :                   remove = true;
    8208              :                 }
    8209              :               else
    8210         2842 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8211              :             }
    8212        14373 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8213        14298 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8214        14295 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
    8215        28668 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8216              :             {
    8217           78 :               error_at (OMP_CLAUSE_LOCATION (c),
    8218              :                         "%qD appears more than once in data clauses", t);
    8219           78 :               remove = true;
    8220              :             }
    8221        14295 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    8222              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
    8223              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    8224         3115 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
    8225              :             {
    8226            9 :               if (openacc)
    8227            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8228              :                           "%qD appears more than once in data clauses", t);
    8229              :               else
    8230            9 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8231              :                           "%qD appears both in data and map clauses", t);
    8232              :               remove = true;
    8233              :             }
    8234              :           else
    8235        14286 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    8236        17260 :           if (!field_ok)
    8237              :             break;
    8238        12852 :         handle_field_decl:
    8239        21366 :           if (!remove
    8240        21169 :               && TREE_CODE (t) == FIELD_DECL
    8241        16494 :               && t == OMP_CLAUSE_DECL (c))
    8242              :             {
    8243          795 :               OMP_CLAUSE_DECL (c)
    8244          795 :                 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
    8245              :                                            == OMP_CLAUSE_SHARED));
    8246          795 :               if (OMP_CLAUSE_DECL (c) == error_mark_node)
    8247        97466 :                 remove = true;
    8248              :             }
    8249              :           break;
    8250              : 
    8251         3473 :         case OMP_CLAUSE_FIRSTPRIVATE:
    8252         3473 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
    8253              :             {
    8254          414 :             move_implicit:
    8255          414 :               implicit_moved = true;
    8256              :               /* Move firstprivate and map clauses with
    8257              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
    8258              :                  clauses chain.  */
    8259          414 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
    8260          414 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
    8261         2704 :               while (*pc1)
    8262         2290 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
    8263         2290 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
    8264              :                   {
    8265          275 :                     *pc3 = *pc1;
    8266          275 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
    8267          275 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8268              :                   }
    8269         2015 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
    8270         2015 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
    8271              :                   {
    8272          370 :                     *pc2 = *pc1;
    8273          370 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
    8274          370 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8275              :                   }
    8276              :                 else
    8277         1645 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
    8278          414 :               *pc3 = NULL;
    8279          414 :               *pc2 = cl2;
    8280          414 :               *pc1 = cl1;
    8281          414 :               continue;
    8282          414 :             }
    8283         3216 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8284         3216 :           if (t)
    8285           69 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8286              :           else
    8287         3147 :             t = OMP_CLAUSE_DECL (c);
    8288         3216 :           if (!openacc && t == current_class_ptr)
    8289              :             {
    8290            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8291              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8292              :                         " clauses");
    8293            6 :               remove = true;
    8294            6 :               break;
    8295              :             }
    8296         3210 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8297          333 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8298          333 :                   || TREE_CODE (t) != FIELD_DECL))
    8299              :             {
    8300           41 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8301              :                 break;
    8302           18 :               if (DECL_P (t))
    8303           12 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8304              :                           "%qD is not a variable in clause %<firstprivate%>",
    8305              :                           t);
    8306              :               else
    8307            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8308              :                           "%qE is not a variable in clause %<firstprivate%>",
    8309              :                           t);
    8310           18 :               remove = true;
    8311              :             }
    8312         3169 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8313          275 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
    8314         3423 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8315              :             remove = true;
    8316         3169 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8317         3160 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8318         6326 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8319              :             {
    8320           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    8321              :                         "%qD appears more than once in data clauses", t);
    8322           15 :               remove = true;
    8323              :             }
    8324         3154 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
    8325         3154 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
    8326              :             {
    8327           21 :               if (openacc)
    8328            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8329              :                           "%qD appears more than once in data clauses", t);
    8330           21 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8331           21 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
    8332              :                 /* Silently drop the clause.  */;
    8333              :               else
    8334           18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8335              :                           "%qD appears both in data and map clauses", t);
    8336           21 :               remove = true;
    8337              :             }
    8338              :           else
    8339         3133 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
    8340         3187 :           goto handle_field_decl;
    8341              : 
    8342         2790 :         case OMP_CLAUSE_LASTPRIVATE:
    8343         2790 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8344         2790 :           if (t)
    8345           35 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8346              :           else
    8347         2755 :             t = OMP_CLAUSE_DECL (c);
    8348         2790 :           if (!openacc && t == current_class_ptr)
    8349              :             {
    8350            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8351              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8352              :                         " clauses");
    8353            6 :               remove = true;
    8354            6 :               break;
    8355              :             }
    8356         2784 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8357          259 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8358          259 :                   || TREE_CODE (t) != FIELD_DECL))
    8359              :             {
    8360           35 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8361              :                 break;
    8362            9 :               if (DECL_P (t))
    8363            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8364              :                           "%qD is not a variable in clause %<lastprivate%>",
    8365              :                           t);
    8366              :               else
    8367            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8368              :                           "%qE is not a variable in clause %<lastprivate%>",
    8369              :                           t);
    8370            9 :               remove = true;
    8371              :             }
    8372         2749 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8373         2749 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
    8374              :             {
    8375           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8376              :                         "%qD appears more than once in data clauses", t);
    8377           12 :               remove = true;
    8378              :             }
    8379              :           else
    8380         2737 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
    8381         2758 :           goto handle_field_decl;
    8382              : 
    8383         2218 :         case OMP_CLAUSE_IF:
    8384         2218 :         case OMP_CLAUSE_SELF:
    8385         2218 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8386         2218 :           t = maybe_convert_cond (t);
    8387         2218 :           if (t == error_mark_node)
    8388              :             remove = true;
    8389         2203 :           else if (!processing_template_decl)
    8390         2142 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8391         2218 :           OMP_CLAUSE_OPERAND (c, 0) = t;
    8392         2218 :           break;
    8393              : 
    8394          289 :         case OMP_CLAUSE_FINAL:
    8395          289 :           t = OMP_CLAUSE_FINAL_EXPR (c);
    8396          289 :           t = maybe_convert_cond (t);
    8397          289 :           if (t == error_mark_node)
    8398              :             remove = true;
    8399          289 :           else if (!processing_template_decl)
    8400          283 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8401          289 :           OMP_CLAUSE_FINAL_EXPR (c) = t;
    8402          289 :           break;
    8403              : 
    8404           92 :         case OMP_CLAUSE_NOCONTEXT:
    8405           92 :           t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
    8406           92 :           t = maybe_convert_cond (t);
    8407           92 :           if (t == error_mark_node)
    8408              :             remove = true;
    8409           89 :           else if (!processing_template_decl)
    8410           83 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8411           92 :           OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
    8412           92 :           break;
    8413              : 
    8414           80 :         case OMP_CLAUSE_NOVARIANTS:
    8415           80 :           t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
    8416           80 :           t = maybe_convert_cond (t);
    8417           80 :           if (t == error_mark_node)
    8418              :             remove = true;
    8419           77 :           else if (!processing_template_decl)
    8420           71 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8421           80 :           OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
    8422           80 :           break;
    8423              : 
    8424         1249 :         case OMP_CLAUSE_GANG:
    8425              :           /* Operand 1 is the gang static: argument.  */
    8426         1249 :           t = OMP_CLAUSE_OPERAND (c, 1);
    8427         1249 :           if (t != NULL_TREE)
    8428              :             {
    8429          129 :               if (t == error_mark_node)
    8430              :                 remove = true;
    8431          129 :               else if (!type_dependent_expression_p (t)
    8432          129 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8433              :                 {
    8434            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8435              :                             "%<gang%> static expression must be integral");
    8436            6 :                   remove = true;
    8437              :                 }
    8438              :               else
    8439              :                 {
    8440          123 :                   t = mark_rvalue_use (t);
    8441          123 :                   if (!processing_template_decl)
    8442              :                     {
    8443          123 :                       t = maybe_constant_value (t);
    8444          123 :                       if (TREE_CODE (t) == INTEGER_CST
    8445          109 :                           && tree_int_cst_sgn (t) != 1
    8446          176 :                           && t != integer_minus_one_node)
    8447              :                         {
    8448            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8449              :                                       "%<gang%> static value must be "
    8450              :                                       "positive");
    8451            0 :                           t = integer_one_node;
    8452              :                         }
    8453          123 :                       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8454              :                     }
    8455              :                 }
    8456          129 :               OMP_CLAUSE_OPERAND (c, 1) = t;
    8457              :             }
    8458              :           /* Check operand 0, the num argument.  */
    8459              :           /* FALLTHRU */
    8460              : 
    8461         3480 :         case OMP_CLAUSE_WORKER:
    8462         3480 :         case OMP_CLAUSE_VECTOR:
    8463         3480 :           if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
    8464              :             break;
    8465              :           /* FALLTHRU */
    8466              : 
    8467          484 :         case OMP_CLAUSE_NUM_TASKS:
    8468          484 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
    8469          136 :             num_tasks_seen = true;
    8470              :           /* FALLTHRU */
    8471              : 
    8472         3034 :         case OMP_CLAUSE_NUM_TEAMS:
    8473         3034 :         case OMP_CLAUSE_NUM_THREADS:
    8474         3034 :         case OMP_CLAUSE_NUM_GANGS:
    8475         3034 :         case OMP_CLAUSE_NUM_WORKERS:
    8476         3034 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
    8477         3034 :         case OMP_CLAUSE_VECTOR_LENGTH:
    8478         3034 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8479         3034 :           if (t == error_mark_node)
    8480              :             remove = true;
    8481         3034 :           else if (!type_dependent_expression_p (t)
    8482         3034 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8483              :             {
    8484           99 :              switch (OMP_CLAUSE_CODE (c))
    8485              :                 {
    8486           12 :                 case OMP_CLAUSE_GANG:
    8487           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8488           12 :                             "%<gang%> num expression must be integral"); break;
    8489           12 :                 case OMP_CLAUSE_VECTOR:
    8490           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8491              :                             "%<vector%> length expression must be integral");
    8492           12 :                   break;
    8493           12 :                 case OMP_CLAUSE_WORKER:
    8494           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8495              :                             "%<worker%> num expression must be integral");
    8496           12 :                   break;
    8497           63 :                 default:
    8498           63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8499              :                             "%qs expression must be integral",
    8500           63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8501              :                 }
    8502              :               remove = true;
    8503              :             }
    8504              :           else
    8505              :             {
    8506         2935 :               t = mark_rvalue_use (t);
    8507         2935 :               if (!processing_template_decl)
    8508              :                 {
    8509         2687 :                   t = maybe_constant_value (t);
    8510         2687 :                   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
    8511         2652 :                       && TREE_CODE (t) == INTEGER_CST
    8512         4142 :                       && tree_int_cst_sgn (t) != 1)
    8513              :                     {
    8514           85 :                       switch (OMP_CLAUSE_CODE (c))
    8515              :                         {
    8516            3 :                         case OMP_CLAUSE_GANG:
    8517            3 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8518              :                                       "%<gang%> num value must be positive");
    8519            3 :                           break;
    8520            0 :                         case OMP_CLAUSE_VECTOR:
    8521            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8522              :                                       "%<vector%> length value must be "
    8523              :                                       "positive");
    8524            0 :                           break;
    8525            0 :                         case OMP_CLAUSE_WORKER:
    8526            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8527              :                                       "%<worker%> num value must be "
    8528              :                                       "positive");
    8529            0 :                           break;
    8530           82 :                         default:
    8531           82 :                           warning_at (OMP_CLAUSE_LOCATION (c),
    8532           46 :                                       (flag_openmp || flag_openmp_simd)
    8533           82 :                                       ? OPT_Wopenmp : 0,
    8534              :                                       "%qs value must be positive",
    8535              :                                       omp_clause_code_name
    8536           82 :                                       [OMP_CLAUSE_CODE (c)]);
    8537              :                         }
    8538           85 :                       t = integer_one_node;
    8539              :                     }
    8540         2602 :                   else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
    8541           35 :                            && TREE_CODE (t) == INTEGER_CST
    8542         2625 :                            && tree_int_cst_sgn (t) < 0)
    8543              :                     {
    8544            8 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8545              :                                   "%<dyn_groupprivate%> value must be "
    8546              :                                   "non-negative");
    8547            8 :                       t = integer_zero_node;
    8548              :                     }
    8549         2687 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8550              :                 }
    8551         2935 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8552              :             }
    8553         3034 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
    8554          752 :               && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
    8555         3313 :               && !remove)
    8556              :             {
    8557          279 :               t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
    8558          279 :               if (t == error_mark_node)
    8559              :                 remove = true;
    8560          279 :               else if (!type_dependent_expression_p (t)
    8561          279 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8562              :                 {
    8563            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8564              :                             "%qs expression must be integral",
    8565            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8566            0 :                   remove = true;
    8567              :                 }
    8568              :               else
    8569              :                 {
    8570          279 :                   t = mark_rvalue_use (t);
    8571          279 :                   if (!processing_template_decl)
    8572              :                     {
    8573          213 :                       t = maybe_constant_value (t);
    8574          213 :                       if (TREE_CODE (t) == INTEGER_CST
    8575          213 :                           && tree_int_cst_sgn (t) != 1)
    8576              :                         {
    8577           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8578              :                                       "%qs value must be positive",
    8579              :                                       omp_clause_code_name
    8580           18 :                                       [OMP_CLAUSE_CODE (c)]);
    8581           18 :                           t = NULL_TREE;
    8582              :                         }
    8583              :                       else
    8584          195 :                         t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8585          213 :                       tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
    8586          213 :                       if (t
    8587          195 :                           && TREE_CODE (t) == INTEGER_CST
    8588           43 :                           && TREE_CODE (upper) == INTEGER_CST
    8589          250 :                           && tree_int_cst_lt (upper, t))
    8590              :                         {
    8591           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8592              :                                       "%<num_teams%> lower bound %qE bigger "
    8593              :                                       "than upper bound %qE", t, upper);
    8594           18 :                           t = NULL_TREE;
    8595              :                         }
    8596              :                     }
    8597          279 :                   OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
    8598              :                 }
    8599              :             }
    8600              :           break;
    8601              : 
    8602         3862 :         case OMP_CLAUSE_SCHEDULE:
    8603         3862 :           t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
    8604         3862 :           if (t == NULL)
    8605              :             ;
    8606         2078 :           else if (t == error_mark_node)
    8607              :             remove = true;
    8608         2078 :           else if (!type_dependent_expression_p (t)
    8609         2078 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8610              :             {
    8611            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    8612              :                         "schedule chunk size expression must be integral");
    8613            9 :               remove = true;
    8614              :             }
    8615              :           else
    8616              :             {
    8617         2069 :               t = mark_rvalue_use (t);
    8618         2069 :               if (!processing_template_decl)
    8619              :                 {
    8620         2029 :                   t = maybe_constant_value (t);
    8621         2029 :                   if (TREE_CODE (t) == INTEGER_CST
    8622         2029 :                       && tree_int_cst_sgn (t) != 1)
    8623              :                   {
    8624            6 :                     warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8625              :                               "chunk size value must be positive");
    8626            6 :                     t = integer_one_node;
    8627              :                   }
    8628         2029 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8629              :                 }
    8630         2069 :               OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
    8631              :             }
    8632         2078 :           if (!remove)
    8633              :             schedule_seen = true;
    8634              :           break;
    8635              : 
    8636         1268 :         case OMP_CLAUSE_SIMDLEN:
    8637         1268 :         case OMP_CLAUSE_SAFELEN:
    8638         1268 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8639         1268 :           if (t == error_mark_node)
    8640              :             remove = true;
    8641         1268 :           else if (!type_dependent_expression_p (t)
    8642         1268 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8643              :             {
    8644            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8645              :                         "%qs length expression must be integral",
    8646            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8647            0 :               remove = true;
    8648              :             }
    8649              :           else
    8650              :             {
    8651         1268 :               t = mark_rvalue_use (t);
    8652         1268 :               if (!processing_template_decl)
    8653              :                 {
    8654         1219 :                   t = maybe_constant_value (t);
    8655         1219 :                   if (TREE_CODE (t) != INTEGER_CST
    8656         1219 :                       || tree_int_cst_sgn (t) != 1)
    8657              :                     {
    8658            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8659              :                                 "%qs length expression must be positive "
    8660              :                                 "constant integer expression",
    8661            0 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8662            0 :                       remove = true;
    8663              :                     }
    8664              :                 }
    8665         1268 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8666         1268 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
    8667          470 :                 safelen = c;
    8668              :             }
    8669              :           break;
    8670              : 
    8671          388 :         case OMP_CLAUSE_ASYNC:
    8672          388 :           t = OMP_CLAUSE_ASYNC_EXPR (c);
    8673          388 :           if (t == error_mark_node)
    8674              :             remove = true;
    8675          373 :           else if (!type_dependent_expression_p (t)
    8676          373 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8677              :             {
    8678           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8679              :                         "%<async%> expression must be integral");
    8680           12 :               remove = true;
    8681              :             }
    8682              :           else
    8683              :             {
    8684          361 :               t = mark_rvalue_use (t);
    8685          361 :               if (!processing_template_decl)
    8686          352 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8687          361 :               OMP_CLAUSE_ASYNC_EXPR (c) = t;
    8688              :             }
    8689              :           break;
    8690              : 
    8691          204 :         case OMP_CLAUSE_WAIT:
    8692          204 :           t = OMP_CLAUSE_WAIT_EXPR (c);
    8693          204 :           if (t == error_mark_node)
    8694              :             remove = true;
    8695          204 :           else if (!processing_template_decl)
    8696          196 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8697          204 :           OMP_CLAUSE_WAIT_EXPR (c) = t;
    8698          204 :           break;
    8699              : 
    8700          637 :         case OMP_CLAUSE_THREAD_LIMIT:
    8701          637 :           t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
    8702          637 :           if (t == error_mark_node)
    8703              :             remove = true;
    8704          637 :           else if (!type_dependent_expression_p (t)
    8705          637 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8706              :             {
    8707            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8708              :                         "%<thread_limit%> expression must be integral");
    8709            0 :               remove = true;
    8710              :             }
    8711              :           else
    8712              :             {
    8713          637 :               t = mark_rvalue_use (t);
    8714          637 :               if (!processing_template_decl)
    8715              :                 {
    8716          583 :                   t = maybe_constant_value (t);
    8717          583 :                   if (TREE_CODE (t) == INTEGER_CST
    8718          583 :                       && tree_int_cst_sgn (t) != 1)
    8719              :                     {
    8720            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8721              :                                   "%<thread_limit%> value must be positive");
    8722            0 :                       t = integer_one_node;
    8723              :                     }
    8724          583 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8725              :                 }
    8726          637 :               OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
    8727              :             }
    8728              :           break;
    8729              : 
    8730          770 :         case OMP_CLAUSE_DEVICE:
    8731          770 :           t = OMP_CLAUSE_DEVICE_ID (c);
    8732          770 :           if (t == error_mark_node)
    8733              :             remove = true;
    8734          770 :           else if (!type_dependent_expression_p (t)
    8735          770 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8736              :             {
    8737            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8738              :                         "%<device%> id must be integral");
    8739            6 :               remove = true;
    8740              :             }
    8741          764 :           else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
    8742           66 :                    && TREE_CODE (t) == INTEGER_CST
    8743          824 :                    && !integer_onep (t))
    8744              :             {
    8745            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    8746              :                         "the %<device%> clause expression must evaluate to "
    8747              :                         "%<1%>");
    8748            3 :               remove = true;
    8749              :             }
    8750              :           else
    8751              :             {
    8752          761 :               t = mark_rvalue_use (t);
    8753          761 :               if (!processing_template_decl)
    8754          750 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8755          761 :               OMP_CLAUSE_DEVICE_ID (c) = t;
    8756              :             }
    8757              :           break;
    8758              : 
    8759         1836 :         case OMP_CLAUSE_DIST_SCHEDULE:
    8760         1836 :           t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
    8761         1836 :           if (t == NULL)
    8762              :             ;
    8763         1815 :           else if (t == error_mark_node)
    8764              :             remove = true;
    8765         1815 :           else if (!type_dependent_expression_p (t)
    8766         1815 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8767              :             {
    8768            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8769              :                         "%<dist_schedule%> chunk size expression must be "
    8770              :                         "integral");
    8771            0 :               remove = true;
    8772              :             }
    8773              :           else
    8774              :             {
    8775         1815 :               t = mark_rvalue_use (t);
    8776         1815 :               if (!processing_template_decl)
    8777         1815 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8778         1815 :               OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
    8779              :             }
    8780              :           break;
    8781              : 
    8782          807 :         case OMP_CLAUSE_ALIGNED:
    8783          807 :           t = OMP_CLAUSE_DECL (c);
    8784          807 :           if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
    8785              :             {
    8786            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8787              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8788              :                         " clauses");
    8789            0 :               remove = true;
    8790            0 :               break;
    8791              :             }
    8792          807 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8793              :             {
    8794            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8795              :                 break;
    8796            0 :               if (DECL_P (t))
    8797            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8798              :                           "%qD is not a variable in %<aligned%> clause", t);
    8799              :               else
    8800            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8801              :                           "%qE is not a variable in %<aligned%> clause", t);
    8802              :               remove = true;
    8803              :             }
    8804          807 :           else if (!type_dependent_expression_p (t)
    8805          789 :                    && !TYPE_PTR_P (TREE_TYPE (t))
    8806          111 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    8807          864 :                    && (!TYPE_REF_P (TREE_TYPE (t))
    8808           39 :                        || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
    8809           30 :                            && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
    8810              :                                != ARRAY_TYPE))))
    8811              :             {
    8812           33 :               error_at (OMP_CLAUSE_LOCATION (c),
    8813              :                         "%qE in %<aligned%> clause is neither a pointer nor "
    8814              :                         "an array nor a reference to pointer or array", t);
    8815           33 :               remove = true;
    8816              :             }
    8817          774 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8818              :             {
    8819            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8820              :                         "%qD appears more than once in %<aligned%> clauses",
    8821              :                         t);
    8822            0 :               remove = true;
    8823              :             }
    8824              :           else
    8825          774 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
    8826          807 :           t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
    8827          807 :           if (t == error_mark_node)
    8828              :             remove = true;
    8829          807 :           else if (t == NULL_TREE)
    8830              :             break;
    8831          744 :           else if (!type_dependent_expression_p (t)
    8832          744 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8833              :             {
    8834            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8835              :                         "%<aligned%> clause alignment expression must "
    8836              :                         "be integral");
    8837            0 :               remove = true;
    8838              :             }
    8839              :           else
    8840              :             {
    8841          744 :               t = mark_rvalue_use (t);
    8842          744 :               if (!processing_template_decl)
    8843              :                 {
    8844          690 :                   t = maybe_constant_value (t);
    8845          690 :                   if (TREE_CODE (t) != INTEGER_CST
    8846          690 :                       || tree_int_cst_sgn (t) != 1)
    8847              :                     {
    8848            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8849              :                                 "%<aligned%> clause alignment expression must "
    8850              :                                 "be positive constant integer expression");
    8851            0 :                       remove = true;
    8852              :                     }
    8853              :                 }
    8854          744 :               OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
    8855              :             }
    8856              :           break;
    8857              : 
    8858          369 :         case OMP_CLAUSE_NONTEMPORAL:
    8859          369 :           t = OMP_CLAUSE_DECL (c);
    8860          369 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8861              :             {
    8862            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8863              :                 break;
    8864            0 :               if (DECL_P (t))
    8865            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8866              :                           "%qD is not a variable in %<nontemporal%> clause",
    8867              :                           t);
    8868              :               else
    8869            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8870              :                           "%qE is not a variable in %<nontemporal%> clause",
    8871              :                           t);
    8872              :               remove = true;
    8873              :             }
    8874          369 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8875              :             {
    8876            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8877              :                         "%qD appears more than once in %<nontemporal%> "
    8878              :                         "clauses", t);
    8879            6 :               remove = true;
    8880              :             }
    8881              :           else
    8882          363 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8883              :           break;
    8884              : 
    8885         2585 :         case OMP_CLAUSE_ALLOCATE:
    8886         2585 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8887         2585 :           if (t)
    8888           14 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8889              :           else
    8890         2571 :             t = OMP_CLAUSE_DECL (c);
    8891         2585 :           if (t == current_class_ptr)
    8892              :             {
    8893            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8894              :                         "%<this%> not allowed in %<allocate%> clause");
    8895            0 :               remove = true;
    8896            0 :               break;
    8897              :             }
    8898         2585 :           if (!VAR_P (t)
    8899          558 :               && TREE_CODE (t) != PARM_DECL
    8900           45 :               && TREE_CODE (t) != FIELD_DECL)
    8901              :             {
    8902            3 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8903              :                 break;
    8904            3 :               if (DECL_P (t))
    8905            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8906              :                           "%qD is not a variable in %<allocate%> clause", t);
    8907              :               else
    8908            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8909              :                           "%qE is not a variable in %<allocate%> clause", t);
    8910              :               remove = true;
    8911              :             }
    8912         2582 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8913              :             {
    8914           12 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8915              :                         "%qD appears more than once in %<allocate%> clauses",
    8916              :                         t);
    8917           12 :               remove = true;
    8918              :             }
    8919              :           else
    8920              :             {
    8921         2570 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
    8922         2570 :               allocate_seen = true;
    8923              :             }
    8924         2585 :           tree allocator, align;
    8925         2585 :           align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
    8926         2585 :           if (error_operand_p (align))
    8927              :             {
    8928              :               remove = true;
    8929              :               break;
    8930              :             }
    8931         2585 :           if (align)
    8932              :             {
    8933          207 :               if (!type_dependent_expression_p (align)
    8934          207 :                   && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    8935              :                 {
    8936            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8937              :                             "%<allocate%> clause %<align%> modifier "
    8938              :                             "argument needs to be positive constant "
    8939              :                             "power of two integer expression");
    8940            4 :                   remove = true;
    8941              :                 }
    8942              :               else
    8943              :                 {
    8944          203 :                   align = mark_rvalue_use (align);
    8945          203 :                   if (!processing_template_decl)
    8946              :                     {
    8947          188 :                       align = maybe_constant_value (align);
    8948          188 :                       if (TREE_CODE (align) != INTEGER_CST
    8949          185 :                           || !tree_fits_uhwi_p (align)
    8950          373 :                           || !integer_pow2p (align))
    8951              :                         {
    8952           10 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8953              :                                     "%<allocate%> clause %<align%> modifier "
    8954              :                                     "argument needs to be positive constant "
    8955              :                                     "power of two integer expression");
    8956           10 :                           remove = true;
    8957              :                         }
    8958              :                     }
    8959              :                 }
    8960          207 :               OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
    8961              :             }
    8962         2585 :           allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
    8963         2585 :           if (error_operand_p (allocator))
    8964              :             {
    8965              :               remove = true;
    8966              :               break;
    8967              :             }
    8968         2585 :           if (allocator == NULL_TREE)
    8969         1537 :             goto handle_field_decl;
    8970         1048 :           tree allocatort;
    8971         1048 :           allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
    8972         1048 :           if (!type_dependent_expression_p (allocator)
    8973         1048 :               && (TREE_CODE (allocatort) != ENUMERAL_TYPE
    8974         1029 :                   || TYPE_NAME (allocatort) == NULL_TREE
    8975         1029 :                   || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
    8976         2058 :                   || (DECL_NAME (TYPE_NAME (allocatort))
    8977         1029 :                       != get_identifier ("omp_allocator_handle_t"))
    8978         1029 :                   || (TYPE_CONTEXT (allocatort)
    8979         1029 :                       != DECL_CONTEXT (global_namespace))))
    8980              :             {
    8981           16 :               error_at (OMP_CLAUSE_LOCATION (c),
    8982              :                         "%<allocate%> clause allocator expression has "
    8983              :                         "type %qT rather than %<omp_allocator_handle_t%>",
    8984           16 :                         TREE_TYPE (allocator));
    8985           16 :               remove = true;
    8986           16 :               break;
    8987              :             }
    8988              :           else
    8989              :             {
    8990         1032 :               allocator = mark_rvalue_use (allocator);
    8991         1032 :               if (!processing_template_decl)
    8992         1013 :                 allocator = maybe_constant_value (allocator);
    8993         1032 :               OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
    8994              :             }
    8995         1032 :           goto handle_field_decl;
    8996              : 
    8997          654 :         case OMP_CLAUSE_DOACROSS:
    8998          654 :           t = OMP_CLAUSE_DECL (c);
    8999          654 :           if (t == NULL_TREE)
    9000              :             break;
    9001          298 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
    9002              :             {
    9003          298 :               if (cp_finish_omp_clause_doacross_sink (c))
    9004           12 :                 remove = true;
    9005              :               break;
    9006              :             }
    9007            0 :           gcc_unreachable ();
    9008          141 :         case OMP_CLAUSE_USES_ALLOCATORS:
    9009          141 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
    9010          141 :           t = convert_from_reference (t);
    9011          141 :           if (t == error_mark_node)
    9012              :             {
    9013              :               remove = true;
    9014              :               break;
    9015              :             }
    9016          129 :           if (DECL_P (t)
    9017          129 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
    9018          120 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9019          117 :                   || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9020              :             {
    9021            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9022              :                         "%qE appears more than once in data clauses", t);
    9023            3 :               remove = true;
    9024              :             }
    9025          126 :           else if (DECL_P (t))
    9026          117 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9027          129 :           if (type_dependent_expression_p (t))
    9028              :             break;
    9029          114 :           if (TREE_CODE (t) == FIELD_DECL)
    9030              :             {
    9031            0 :               sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
    9032              :                         "supported in %<uses_allocators%> clause", t);
    9033            0 :               remove = true;
    9034            0 :               break;
    9035              :             }
    9036          114 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9037          219 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9038              :                          "omp_allocator_handle_t") != 0)
    9039              :             {
    9040            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9041              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
    9042              :                         "type", t);
    9043            9 :               remove = true;
    9044            9 :               break;
    9045              :             }
    9046          105 :           tree init;
    9047          105 :           if (TREE_CODE (t) == CONST_DECL)
    9048           15 :             init = DECL_INITIAL(t);
    9049              :           else
    9050              :             init = t;
    9051          105 :           if (!DECL_P (t)
    9052          105 :               && (init == NULL_TREE
    9053            9 :                   || TREE_CODE (init) != INTEGER_CST
    9054            9 :                   || ((wi::to_widest (init) < 0
    9055            9 :                        || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
    9056            3 :                       && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
    9057            3 :                           || (wi::to_widest (init)
    9058            6 :                               > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
    9059              :             {
    9060            3 :               remove = true;
    9061            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9062              :                         "allocator %qE must be either a variable or a "
    9063              :                         "predefined allocator", t);
    9064            3 :               break;
    9065              :             }
    9066          102 :           else if (TREE_CODE (t) == CONST_DECL)
    9067              :             {
    9068              :               /* omp_null_allocator is ignored and for predefined allocators,
    9069              :                  not special handling is required; thus, remove them removed. */
    9070           15 :               remove = true;
    9071              : 
    9072           15 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
    9073           15 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
    9074              :                 {
    9075            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9076              :                             "modifiers cannot be used with predefined "
    9077              :                             "allocators");
    9078            0 :                   break;
    9079              :                 }
    9080              :             }
    9081          102 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
    9082          102 :           if (t == error_mark_node)
    9083              :             {
    9084              :               remove = true;
    9085              :               break;
    9086              :             }
    9087           99 :           if (t != NULL_TREE
    9088           18 :               && !type_dependent_expression_p (t)
    9089          117 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
    9090           15 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9091           24 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9092              :                              "omp_memspace_handle_t") != 0))
    9093              :             {
    9094            6 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
    9095              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
    9096            6 :               remove = true;
    9097            6 :               break;
    9098              :             }
    9099           93 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
    9100           93 :           if (t == error_mark_node)
    9101              :             {
    9102              :               remove = true;
    9103              :               break;
    9104              :             }
    9105           90 :           if (type_dependent_expression_p (t))
    9106              :             break;
    9107           90 :           if (t != NULL_TREE
    9108           39 :               && t != error_mark_node
    9109           39 :               && !type_dependent_expression_p (t)
    9110          129 :               && (!DECL_P (t)
    9111           39 :                   ||  DECL_EXTERNAL (t)
    9112           33 :                   || TREE_CODE (t) == PARM_DECL))
    9113              :             {
    9114           12 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
    9115              :                         "defined in same scope as the construct on which the "
    9116              :                         "clause appears", t);
    9117           12 :               remove = true;
    9118              :             }
    9119           90 :           if (t != NULL_TREE)
    9120              :             {
    9121           39 :               bool type_err = false;
    9122              : 
    9123           39 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    9124           33 :                   || DECL_SIZE (t) == NULL_TREE
    9125           69 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9126              :                 type_err = true;
    9127              :               else
    9128              :                 {
    9129           30 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
    9130           30 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
    9131           60 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
    9132              :                                  "omp_alloctrait_t") != 0
    9133           60 :                       || !TYPE_READONLY (elem_t))
    9134              :                     type_err = true;
    9135              :                 }
    9136           27 :               if (type_err)
    9137              :                 {
    9138           12 :                   error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
    9139              :                             "be of %<const omp_alloctrait_t []%> type", t);
    9140           12 :                   remove = true;
    9141              :                 }
    9142           27 :               else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
    9143              :                        != INTEGER_CST)
    9144              :                 {
    9145            3 :                   error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
    9146              :                             "arrays are not supported");
    9147            3 :                   remove = true;
    9148              :                 }
    9149              :               else
    9150              :                 {
    9151           24 :                   tree cst_val = decl_constant_value (t);
    9152           24 :                   if (cst_val == t)
    9153              :                     {
    9154            3 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
    9155              :                                 "initialized with constants");
    9156            3 :                       remove = true;
    9157              :                     }
    9158              :                 }
    9159              :             }
    9160           90 :           if (remove)
    9161              :             break;
    9162           54 :           pc = &OMP_CLAUSE_CHAIN (c);
    9163           54 :           continue;
    9164         1805 :         case OMP_CLAUSE_DEPEND:
    9165         1805 :           depend_clause = c;
    9166              :           /* FALLTHRU */
    9167         2171 :         case OMP_CLAUSE_AFFINITY:
    9168         2171 :           t = OMP_CLAUSE_DECL (c);
    9169         2171 :           if (OMP_ITERATOR_DECL_P (t))
    9170              :             {
    9171          622 :               if (TREE_PURPOSE (t) != last_iterators)
    9172          524 :                 last_iterators_remove
    9173          524 :                   = cp_omp_finish_iterators (TREE_PURPOSE (t));
    9174          622 :               last_iterators = TREE_PURPOSE (t);
    9175          622 :               t = TREE_VALUE (t);
    9176          622 :               if (last_iterators_remove)
    9177          144 :                 t = error_mark_node;
    9178              :             }
    9179              :           else
    9180              :             last_iterators = NULL_TREE;
    9181              : 
    9182         2171 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9183              :             {
    9184         1164 :               if (handle_omp_array_sections (c, ort))
    9185              :                 remove = true;
    9186          913 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9187          913 :                        && (OMP_CLAUSE_DEPEND_KIND (c)
    9188              :                            == OMP_CLAUSE_DEPEND_DEPOBJ))
    9189              :                 {
    9190            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9191              :                             "%<depend%> clause with %<depobj%> dependence "
    9192              :                             "type on array section");
    9193            6 :                   remove = true;
    9194              :                 }
    9195              :               break;
    9196              :             }
    9197         1007 :           if (t == error_mark_node)
    9198              :             remove = true;
    9199          845 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9200          845 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
    9201              :             {
    9202           33 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
    9203           33 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
    9204              :                 {
    9205            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9206              :                             "%<omp_all_memory%> used with %<depend%> kind "
    9207              :                             "other than %<out%> or %<inout%>");
    9208            9 :                   remove = true;
    9209              :                 }
    9210           33 :               if (processing_template_decl)
    9211              :                 break;
    9212              :             }
    9213          812 :           else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9214              :             break;
    9215          620 :           else if (!lvalue_p (t))
    9216              :             {
    9217           19 :               if (DECL_P (t))
    9218           24 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9219              :                           "%qD is not lvalue expression nor array section "
    9220              :                           "in %qs clause", t,
    9221           12 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9222              :               else
    9223           14 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9224              :                           "%qE is not lvalue expression nor array section "
    9225              :                           "in %qs clause", t,
    9226            7 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9227              :               remove = true;
    9228              :             }
    9229          601 :           else if (TREE_CODE (t) == COMPONENT_REF
    9230           24 :                    && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
    9231          625 :                    && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
    9232              :             {
    9233            8 :               error_at (OMP_CLAUSE_LOCATION (c),
    9234              :                         "bit-field %qE in %qs clause", t,
    9235            4 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9236            4 :               remove = true;
    9237              :             }
    9238          597 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9239          597 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
    9240              :             {
    9241          130 :               if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9242            8 :                                      ? TREE_TYPE (TREE_TYPE (t))
    9243           57 :                                      : TREE_TYPE (t)))
    9244              :                 {
    9245           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9246              :                             "%qE does not have %<omp_depend_t%> type in "
    9247              :                             "%<depend%> clause with %<depobj%> dependence "
    9248              :                             "type", t);
    9249           12 :                   remove = true;
    9250              :                 }
    9251              :             }
    9252          532 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9253          972 :                    && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9254            4 :                                         ? TREE_TYPE (TREE_TYPE (t))
    9255          436 :                                         : TREE_TYPE (t)))
    9256              :             {
    9257           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    9258              :                         "%qE should not have %<omp_depend_t%> type in "
    9259              :                         "%<depend%> clause with dependence type other than "
    9260              :                         "%<depobj%>", t);
    9261           15 :               remove = true;
    9262              :             }
    9263           64 :           if (!remove)
    9264              :             {
    9265          594 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
    9266           24 :                 t = null_pointer_node;
    9267              :               else
    9268              :                 {
    9269          570 :                   tree addr = cp_build_addr_expr (t, tf_warning_or_error);
    9270          570 :                   if (addr == error_mark_node)
    9271              :                     {
    9272              :                       remove = true;
    9273              :                       break;
    9274              :                     }
    9275          570 :                   t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
    9276              :                                              addr, RO_UNARY_STAR,
    9277              :                                              tf_warning_or_error);
    9278          570 :                   if (t == error_mark_node)
    9279              :                     {
    9280              :                       remove = true;
    9281              :                       break;
    9282              :                     }
    9283              :                 }
    9284          594 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
    9285          136 :                   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
    9286          730 :                   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
    9287              :                       == TREE_VEC))
    9288          136 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
    9289              :               else
    9290          458 :                 OMP_CLAUSE_DECL (c) = t;
    9291              :             }
    9292              :           break;
    9293           69 :         case OMP_CLAUSE_DETACH:
    9294           69 :           t = OMP_CLAUSE_DECL (c);
    9295           69 :           if (detach_seen)
    9296              :             {
    9297            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9298              :                         "too many %qs clauses on a task construct",
    9299              :                         "detach");
    9300            3 :               remove = true;
    9301            3 :               break;
    9302              :             }
    9303           66 :           else if (error_operand_p (t))
    9304              :             {
    9305              :               remove = true;
    9306              :               break;
    9307              :             }
    9308              :           else
    9309              :             {
    9310           63 :               tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
    9311           63 :               if (!type_dependent_expression_p (t)
    9312           63 :                   && (!INTEGRAL_TYPE_P (type)
    9313              :                       || TREE_CODE (type) != ENUMERAL_TYPE
    9314           51 :                       || TYPE_NAME (type) == NULL_TREE
    9315          102 :                       || (DECL_NAME (TYPE_NAME (type))
    9316           51 :                           != get_identifier ("omp_event_handle_t"))))
    9317              :                 {
    9318            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9319              :                             "%<detach%> clause event handle "
    9320              :                             "has type %qT rather than "
    9321              :                             "%<omp_event_handle_t%>",
    9322              :                             type);
    9323            6 :                   remove = true;
    9324              :                 }
    9325           63 :               detach_seen = c;
    9326           63 :               cxx_mark_addressable (t);
    9327              :             }
    9328           63 :           break;
    9329              : 
    9330        16189 :         case OMP_CLAUSE_MAP:
    9331        16189 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
    9332          157 :             goto move_implicit;
    9333        16032 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
    9334        16032 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
    9335              :             {
    9336              :               remove = true;
    9337              :               break;
    9338              :             }
    9339              :           /* FALLTHRU */
    9340        19210 :         case OMP_CLAUSE_TO:
    9341        19210 :         case OMP_CLAUSE_FROM:
    9342        19210 :           if (OMP_CLAUSE_ITERATORS (c)
    9343        19210 :               && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
    9344              :             {
    9345        97466 :               t = error_mark_node;
    9346              :               break;
    9347              :             }
    9348              :           /* FALLTHRU */
    9349        20046 :         case OMP_CLAUSE__CACHE_:
    9350        20046 :           {
    9351        20046 :             using namespace omp_addr_tokenizer;
    9352        20046 :             auto_vec<omp_addr_token *, 10> addr_tokens;
    9353              : 
    9354        20046 :             t = OMP_CLAUSE_DECL (c);
    9355        20046 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9356              :               {
    9357         5879 :                 grp_start_p = pc;
    9358         5879 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9359              : 
    9360         5879 :                 if (handle_omp_array_sections (c, ort))
    9361              :                   remove = true;
    9362              :                 else
    9363              :                   {
    9364         5113 :                     t = OMP_CLAUSE_DECL (c);
    9365         5113 :                     if (TREE_CODE (t) != OMP_ARRAY_SECTION
    9366         4256 :                         && !type_dependent_expression_p (t)
    9367         9369 :                         && !omp_mappable_type (TREE_TYPE (t)))
    9368              :                       {
    9369            3 :                         auto_diagnostic_group d;
    9370            6 :                         error_at (OMP_CLAUSE_LOCATION (c),
    9371              :                                   "array section does not have mappable type "
    9372              :                                   "in %qs clause",
    9373            3 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9374            3 :                         if (TREE_TYPE (t) != error_mark_node
    9375            3 :                             && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9376            3 :                           cxx_incomplete_type_inform (TREE_TYPE (t));
    9377            3 :                         remove = true;
    9378            3 :                       }
    9379         6963 :                     while (TREE_CODE (t) == ARRAY_REF)
    9380         1850 :                       t = TREE_OPERAND (t, 0);
    9381              : 
    9382         5113 :                     if (type_dependent_expression_p (t))
    9383              :                       break;
    9384              : 
    9385         4639 :                     cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9386              : 
    9387         4639 :                     if (!ai.map_supported_p ()
    9388         4639 :                         || !omp_parse_expr (addr_tokens, t))
    9389              :                       {
    9390           18 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
    9391              :                                   "unsupported map expression %qE",
    9392            9 :                                   OMP_CLAUSE_DECL (c));
    9393            9 :                         remove = true;
    9394            9 :                         break;
    9395              :                       }
    9396              : 
    9397              :                     /* This check is to determine if this will be the only map
    9398              :                        node created for this clause.  Otherwise, we'll check
    9399              :                        the following FIRSTPRIVATE_POINTER,
    9400              :                        FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
    9401              :                        iteration(s) of the loop.   */
    9402         9211 :                     if (addr_tokens.length () >= 4
    9403         1063 :                         && addr_tokens[0]->type == STRUCTURE_BASE
    9404         1057 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    9405         1057 :                         && addr_tokens[1]->type == ACCESS_METHOD
    9406         1057 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
    9407          977 :                         && addr_tokens[3]->type == ACCESS_METHOD
    9408         5344 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
    9409          551 :                             || (addr_tokens[3]->u.access_kind
    9410              :                                 == ACCESS_INDEXED_ARRAY)))
    9411              :                       {
    9412          165 :                         tree rt = addr_tokens[1]->expr;
    9413              : 
    9414          165 :                         gcc_assert (DECL_P (rt));
    9415              : 
    9416          165 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9417          154 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
    9418          165 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
    9419            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
    9420            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
    9421            0 :                                                  DECL_UID (rt))))
    9422              :                           {
    9423              :                             remove = true;
    9424              :                             break;
    9425              :                           }
    9426          165 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
    9427              :                           break;
    9428          116 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
    9429              :                           {
    9430            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9431            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9432              :                                         "%qD appears more than once in motion"
    9433              :                                         " clauses", rt);
    9434            0 :                             else if (openacc)
    9435            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9436              :                                         "%qD appears more than once in data"
    9437              :                                         " clauses", rt);
    9438              :                             else
    9439            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9440              :                                         "%qD appears more than once in map"
    9441              :                                         " clauses", rt);
    9442              :                             remove = true;
    9443              :                           }
    9444              :                         else
    9445              :                           {
    9446          116 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
    9447          116 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
    9448              :                           }
    9449              :                       }
    9450         4639 :                   }
    9451         5347 :                 if (cp_oacc_check_attachments (c))
    9452           12 :                   remove = true;
    9453         5347 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9454         4413 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9455         4349 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9456         5445 :                     && !OMP_CLAUSE_SIZE (c))
    9457              :                   /* In this case, we have a single array element which is a
    9458              :                      pointer, and we already set OMP_CLAUSE_SIZE in
    9459              :                      handle_omp_array_sections above.  For attach/detach
    9460              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
    9461              :                      to zero here.  */
    9462           60 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
    9463              :                 break;
    9464              :               }
    9465        14167 :             else if (type_dependent_expression_p (t))
    9466              :               break;
    9467        13384 :             else if (!omp_parse_expr (addr_tokens, t))
    9468              :               {
    9469            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9470              :                           "unsupported map expression %qE",
    9471            0 :                           OMP_CLAUSE_DECL (c));
    9472            0 :                 remove = true;
    9473            0 :                 break;
    9474              :               }
    9475        13384 :             if (t == error_mark_node)
    9476              :               {
    9477              :                 remove = true;
    9478              :                 break;
    9479              :               }
    9480              :             /* OpenACC attach / detach clauses must be pointers.  */
    9481        13290 :             if (cp_oacc_check_attachments (c))
    9482              :               {
    9483              :                 remove = true;
    9484              :                 break;
    9485              :               }
    9486        13266 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9487        10221 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9488        10172 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9489        13340 :                 && !OMP_CLAUSE_SIZE (c))
    9490              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
    9491              :                  bias) to zero here, so it is not set erroneously to the
    9492              :                  pointer size later on in gimplify.cc.  */
    9493           66 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
    9494              : 
    9495        13266 :             cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9496              : 
    9497        13266 :             if (!ai.check_clause (c))
    9498              :               {
    9499              :                 remove = true;
    9500              :                 break;
    9501              :               }
    9502              : 
    9503        13245 :             if (!ai.map_supported_p ())
    9504              :               {
    9505           88 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9506              :                           "unsupported map expression %qE",
    9507           44 :                           OMP_CLAUSE_DECL (c));
    9508           44 :                 remove = true;
    9509           44 :                 break;
    9510              :               }
    9511              : 
    9512        26402 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
    9513              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
    9514              :                         && addr_tokens[1]->type == ACCESS_METHOD);
    9515              : 
    9516        13201 :             t = addr_tokens[1]->expr;
    9517              : 
    9518              :             /* This is used to prevent cxx_mark_addressable from being called
    9519              :                on 'this' for expressions like 'this->a', i.e. typical member
    9520              :                accesses.  */
    9521        13201 :             indir_component_ref_p
    9522        26402 :               = (addr_tokens[0]->type == STRUCTURE_BASE
    9523        13201 :                  && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
    9524              : 
    9525        13201 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
    9526            1 :               goto skip_decl_checks;
    9527              : 
    9528              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
    9529              :                mapping.  OpenACC allows multiple fields of the same structure
    9530              :                to be written.  */
    9531        13200 :             if (addr_tokens[0]->type == STRUCTURE_BASE
    9532        13200 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
    9533         1263 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
    9534         1351 :               goto skip_decl_checks;
    9535              : 
    9536        11849 :             if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
    9537              :               {
    9538            0 :                 OMP_CLAUSE_DECL (c)
    9539            0 :                   = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    9540            0 :                 break;
    9541              :               }
    9542        11849 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    9543              :               {
    9544            0 :                 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9545              :                   break;
    9546            0 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9547            0 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9548            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
    9549            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
    9550            0 :                         || (!openacc && EXPR_P (t))))
    9551              :                   break;
    9552            0 :                 if (DECL_P (t))
    9553            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9554              :                             "%qD is not a variable in %qs clause", t,
    9555            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9556              :                 else
    9557            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9558              :                             "%qE is not a variable in %qs clause", t,
    9559            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9560              :                 remove = true;
    9561              :               }
    9562        11849 :             else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    9563              :               {
    9564            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9565              :                           "%qD is threadprivate variable in %qs clause", t,
    9566            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9567            0 :                 remove = true;
    9568              :               }
    9569        11849 :             else if (!processing_template_decl
    9570        11673 :                      && !TYPE_REF_P (TREE_TYPE (t))
    9571        10996 :                      && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9572         8061 :                          || (OMP_CLAUSE_MAP_KIND (c)
    9573              :                              != GOMP_MAP_FIRSTPRIVATE_POINTER))
    9574         9039 :                      && !indir_component_ref_p
    9575         8675 :                      && (t != current_class_ptr
    9576           18 :                          || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9577            6 :                          || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
    9578        20524 :                      && !cxx_mark_addressable (t))
    9579              :               remove = true;
    9580        11849 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9581         8896 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9582         8896 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9583              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
    9584         6939 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9585              :                                == GOMP_MAP_ATTACH_DETACH)))
    9586         9232 :                      && t == OMP_CLAUSE_DECL (c)
    9587         8534 :                      && !type_dependent_expression_p (t)
    9588        28917 :                      && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
    9589          278 :                                             ? TREE_TYPE (TREE_TYPE (t))
    9590         8256 :                                             : TREE_TYPE (t)))
    9591              :               {
    9592           42 :                 auto_diagnostic_group d;
    9593           84 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9594              :                           "%qD does not have a mappable type in %qs clause", t,
    9595           42 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9596           42 :                 if (TREE_TYPE (t) != error_mark_node
    9597           42 :                     && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9598           39 :                   cxx_incomplete_type_inform (TREE_TYPE (t));
    9599           42 :                 remove = true;
    9600           42 :               }
    9601        11807 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9602         8860 :                      && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
    9603           93 :                      && !type_dependent_expression_p (t)
    9604        11900 :                      && !INDIRECT_TYPE_P (TREE_TYPE (t)))
    9605              :               {
    9606            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9607              :                           "%qD is not a pointer variable", t);
    9608            6 :                 remove = true;
    9609              :               }
    9610        11801 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9611         8854 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
    9612        12171 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
    9613          367 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
    9614          367 :                          || bitmap_bit_p (&map_firstprivate_head,
    9615          367 :                                           DECL_UID (t))))
    9616              :               remove = true;
    9617        11795 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9618        11795 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9619              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
    9620              :               {
    9621         1951 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
    9622         1951 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9623         3899 :                     || (openacc
    9624         1362 :                         && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9625              :                   {
    9626           12 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9627              :                               "%qD appears more than once in data clauses", t);
    9628           12 :                     remove = true;
    9629              :                   }
    9630         1939 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9631           12 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9632         1947 :                          && openacc)
    9633              :                   {
    9634            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9635              :                               "%qD appears more than once in data clauses", t);
    9636            3 :                     remove = true;
    9637              :                   }
    9638              :                 else
    9639         1936 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9640              :               }
    9641         9844 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9642         9844 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9643              :                          == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
    9644          115 :               bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9645         9729 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9646          181 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9647           38 :                      && ort != C_ORT_OMP
    9648           38 :                      && ort != C_ORT_OMP_TARGET
    9649         9745 :                      && ort != C_ORT_OMP_EXIT_DATA)
    9650              :               {
    9651            9 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9652            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9653              :                             "%qD appears more than once in motion clauses", t);
    9654            9 :                 else if (openacc)
    9655            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9656              :                             "%qD appears more than once in data clauses", t);
    9657              :                 else
    9658            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9659              :                             "%qD appears more than once in map clauses", t);
    9660              :                 remove = true;
    9661              :               }
    9662         9720 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
    9663              :               {
    9664            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9665              :                           "%qD appears more than once in data clauses", t);
    9666            0 :                 remove = true;
    9667              :               }
    9668         9720 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9669         9720 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
    9670              :               {
    9671           27 :                 if (openacc)
    9672            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9673              :                             "%qD appears more than once in data clauses", t);
    9674              :                 else
    9675           27 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9676              :                             "%qD appears both in data and map clauses", t);
    9677              :                 remove = true;
    9678              :               }
    9679         9693 :             else if (!omp_access_chain_p (addr_tokens, 1))
    9680              :               {
    9681         9613 :                 bitmap_set_bit (&map_head, DECL_UID (t));
    9682              : 
    9683         9613 :                 tree decl = OMP_CLAUSE_DECL (c);
    9684         9613 :                 if (t != decl
    9685         9613 :                     && (TREE_CODE (decl) == COMPONENT_REF
    9686          162 :                         || (INDIRECT_REF_P (decl)
    9687          162 :                             && (TREE_CODE (TREE_OPERAND (decl, 0))
    9688              :                                 == COMPONENT_REF)
    9689          150 :                             && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
    9690              :                                                                     0))))))
    9691         1165 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
    9692              :               }
    9693              : 
    9694         4631 :           skip_decl_checks:
    9695              :             /* If we call ai.expand_map_clause in handle_omp_array_sections,
    9696              :                the containing loop (here) iterates through the new nodes
    9697              :                created by that expansion.  Avoid expanding those again (just
    9698              :                by checking the node type).  */
    9699         4631 :             if (!remove
    9700        13096 :                 && !processing_template_decl
    9701        12923 :                 && ort != C_ORT_DECLARE_SIMD
    9702        12923 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9703         9896 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
    9704         7960 :                         && (OMP_CLAUSE_MAP_KIND (c)
    9705              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
    9706         7845 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
    9707         7845 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
    9708         6846 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    9709         6797 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
    9710              :               {
    9711         9799 :                 grp_start_p = pc;
    9712         9799 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9713         9799 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
    9714              :                                                 addr_tokens, ort);
    9715         9799 :                 if (nc != error_mark_node)
    9716         9799 :                   c = nc;
    9717              :               }
    9718        20111 :           }
    9719        13201 :           break;
    9720              : 
    9721          596 :         case OMP_CLAUSE_ENTER:
    9722          596 :         case OMP_CLAUSE_LINK:
    9723          596 :           t = OMP_CLAUSE_DECL (c);
    9724          596 :           const char *cname;
    9725          596 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
    9726          596 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
    9727          596 :               && OMP_CLAUSE_ENTER_TO (c))
    9728              :             cname = "to";
    9729          596 :           if (TREE_CODE (t) == FUNCTION_DECL
    9730          596 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9731              :             ;
    9732          379 :           else if (!VAR_P (t))
    9733              :             {
    9734           12 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9735              :                 {
    9736            9 :                   if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
    9737            6 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9738              :                               "template %qE in clause %qs", t, cname);
    9739            3 :                   else if (really_overloaded_fn (t))
    9740            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9741              :                               "overloaded function name %qE in clause %qs", t,
    9742              :                               cname);
    9743              :                   else
    9744            0 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9745              :                               "%qE is neither a variable nor a function name "
    9746              :                               "in clause %qs", t, cname);
    9747              :                 }
    9748              :               else
    9749            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9750              :                           "%qE is not a variable in clause %qs", t, cname);
    9751              :               remove = true;
    9752              :             }
    9753          367 :           else if (DECL_THREAD_LOCAL_P (t))
    9754              :             {
    9755            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9756              :                         "%qD is threadprivate variable in %qs clause", t,
    9757              :                         cname);
    9758            6 :               remove = true;
    9759              :             }
    9760          361 :           else if (!omp_mappable_type (TREE_TYPE (t)))
    9761              :             {
    9762           18 :               auto_diagnostic_group d;
    9763           18 :               error_at (OMP_CLAUSE_LOCATION (c),
    9764              :                         "%qD does not have a mappable type in %qs clause", t,
    9765              :                         cname);
    9766           18 :               if (TREE_TYPE (t) != error_mark_node
    9767           18 :                   && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9768           18 :                 cxx_incomplete_type_inform (TREE_TYPE (t));
    9769           18 :               remove = true;
    9770           18 :             }
    9771           24 :           if (remove)
    9772              :             break;
    9773          560 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
    9774              :             {
    9775           24 :               error_at (OMP_CLAUSE_LOCATION (c),
    9776              :                         "%qE appears more than once on the same "
    9777              :                         "%<declare target%> directive", t);
    9778           24 :               remove = true;
    9779              :             }
    9780              :           else
    9781          536 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9782              :           break;
    9783              : 
    9784          457 :         case OMP_CLAUSE_UNIFORM:
    9785          457 :           t = OMP_CLAUSE_DECL (c);
    9786          457 :           if (TREE_CODE (t) != PARM_DECL)
    9787              :             {
    9788            0 :               if (processing_template_decl)
    9789              :                 break;
    9790            0 :               if (DECL_P (t))
    9791            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9792              :                           "%qD is not an argument in %<uniform%> clause", t);
    9793              :               else
    9794            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9795              :                           "%qE is not an argument in %<uniform%> clause", t);
    9796              :               remove = true;
    9797              :               break;
    9798              :             }
    9799              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
    9800          457 :           bitmap_set_bit (&map_head, DECL_UID (t));
    9801          457 :           goto check_dup_generic;
    9802              : 
    9803          165 :         case OMP_CLAUSE_GRAINSIZE:
    9804          165 :           t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
    9805          165 :           if (t == error_mark_node)
    9806              :             remove = true;
    9807          165 :           else if (!type_dependent_expression_p (t)
    9808          165 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9809              :             {
    9810            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9811              :                         "%<grainsize%> expression must be integral");
    9812            0 :               remove = true;
    9813              :             }
    9814              :           else
    9815              :             {
    9816          165 :               t = mark_rvalue_use (t);
    9817          165 :               if (!processing_template_decl)
    9818              :                 {
    9819          164 :                   t = maybe_constant_value (t);
    9820          164 :                   if (TREE_CODE (t) == INTEGER_CST
    9821          164 :                       && tree_int_cst_sgn (t) != 1)
    9822              :                     {
    9823            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9824              :                                   "%<grainsize%> value must be positive");
    9825            0 :                       t = integer_one_node;
    9826              :                     }
    9827          164 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9828              :                 }
    9829          165 :               OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
    9830              :             }
    9831              :           break;
    9832              : 
    9833          276 :         case OMP_CLAUSE_PRIORITY:
    9834          276 :           t = OMP_CLAUSE_PRIORITY_EXPR (c);
    9835          276 :           if (t == error_mark_node)
    9836              :             remove = true;
    9837          276 :           else if (!type_dependent_expression_p (t)
    9838          276 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9839              :             {
    9840            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9841              :                         "%<priority%> expression must be integral");
    9842            0 :               remove = true;
    9843              :             }
    9844              :           else
    9845              :             {
    9846          276 :               t = mark_rvalue_use (t);
    9847          276 :               if (!processing_template_decl)
    9848              :                 {
    9849          276 :                   t = maybe_constant_value (t);
    9850          276 :                   if (TREE_CODE (t) == INTEGER_CST
    9851          276 :                       && tree_int_cst_sgn (t) == -1)
    9852              :                     {
    9853            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9854              :                                   "%<priority%> value must be non-negative");
    9855            0 :                       t = integer_one_node;
    9856              :                     }
    9857          276 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9858              :                 }
    9859          276 :               OMP_CLAUSE_PRIORITY_EXPR (c) = t;
    9860              :             }
    9861              :           break;
    9862              : 
    9863          228 :         case OMP_CLAUSE_HINT:
    9864          228 :           t = OMP_CLAUSE_HINT_EXPR (c);
    9865          228 :           if (t == error_mark_node)
    9866              :             remove = true;
    9867          228 :           else if (!type_dependent_expression_p (t)
    9868          228 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9869              :             {
    9870            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9871              :                         "%<hint%> expression must be integral");
    9872            9 :               remove = true;
    9873              :             }
    9874              :           else
    9875              :             {
    9876          219 :               t = mark_rvalue_use (t);
    9877          219 :               if (!processing_template_decl)
    9878              :                 {
    9879          171 :                   t = maybe_constant_value (t);
    9880          171 :                   if (TREE_CODE (t) != INTEGER_CST)
    9881              :                     {
    9882           16 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9883              :                                 "%<hint%> expression must be constant integer "
    9884              :                                 "expression");
    9885           16 :                       remove = true;
    9886              :                     }
    9887              :                 }
    9888          219 :               OMP_CLAUSE_HINT_EXPR (c) = t;
    9889              :             }
    9890              :           break;
    9891              : 
    9892          186 :         case OMP_CLAUSE_FILTER:
    9893          186 :           t = OMP_CLAUSE_FILTER_EXPR (c);
    9894          186 :           if (t == error_mark_node)
    9895              :             remove = true;
    9896          186 :           else if (!type_dependent_expression_p (t)
    9897          186 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9898              :             {
    9899            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9900              :                         "%<filter%> expression must be integral");
    9901            6 :               remove = true;
    9902              :             }
    9903              :           else
    9904              :             {
    9905          180 :               t = mark_rvalue_use (t);
    9906          180 :               if (!processing_template_decl)
    9907              :                 {
    9908          177 :                   t = maybe_constant_value (t);
    9909          177 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9910              :                 }
    9911          180 :               OMP_CLAUSE_FILTER_EXPR (c) = t;
    9912              :             }
    9913              :           break;
    9914              : 
    9915          433 :         case OMP_CLAUSE_IS_DEVICE_PTR:
    9916          433 :         case OMP_CLAUSE_USE_DEVICE_PTR:
    9917          433 :           field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
    9918          433 :           t = OMP_CLAUSE_DECL (c);
    9919          433 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    9920          329 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9921          433 :           if (!type_dependent_expression_p (t))
    9922              :             {
    9923          431 :               tree type = TREE_TYPE (t);
    9924          431 :               if (!TYPE_PTR_P (type)
    9925          431 :                   && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
    9926              :                 {
    9927           57 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    9928           57 :                       && ort == C_ORT_OMP)
    9929              :                     {
    9930            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9931              :                                 "%qs variable is neither a pointer "
    9932              :                                 "nor reference to pointer",
    9933            3 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9934            3 :                       remove = true;
    9935              :                     }
    9936           54 :                   else if (TREE_CODE (type) != ARRAY_TYPE
    9937           54 :                            && (!TYPE_REF_P (type)
    9938            2 :                                || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
    9939              :                     {
    9940           12 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9941              :                                 "%qs variable is neither a pointer, nor an "
    9942              :                                 "array nor reference to pointer or array",
    9943           12 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9944           12 :                       remove = true;
    9945              :                     }
    9946              :                 }
    9947              :             }
    9948          433 :           goto check_dup_generic;
    9949              : 
    9950          267 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
    9951          267 :           t = OMP_CLAUSE_DECL (c);
    9952          267 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9953              :             {
    9954           28 :               if (handle_omp_array_sections (c, ort))
    9955              :                 remove = true;
    9956              :               else
    9957              :                 {
    9958           28 :                   t = OMP_CLAUSE_DECL (c);
    9959           30 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9960            2 :                     t = TREE_OPERAND (t, 0);
    9961           64 :                   while (INDIRECT_REF_P (t)
    9962           64 :                          || TREE_CODE (t) == ARRAY_REF)
    9963           36 :                     t = TREE_OPERAND (t, 0);
    9964              :                 }
    9965              :             }
    9966          267 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9967              :             {
    9968          267 :               bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9969          267 :               if (!processing_template_decl
    9970          267 :                   && !cxx_mark_addressable (t))
    9971              :                 remove = true;
    9972              :             }
    9973          267 :           goto check_dup_generic_t;
    9974              : 
    9975           76 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
    9976           76 :           field_ok = true;
    9977           76 :           t = OMP_CLAUSE_DECL (c);
    9978           76 :           if (!processing_template_decl
    9979           74 :               && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9980           74 :               && !TYPE_REF_P (TREE_TYPE (t))
    9981          143 :               && !cxx_mark_addressable (t))
    9982              :             remove = true;
    9983           76 :           goto check_dup_generic;
    9984              : 
    9985              :         case OMP_CLAUSE_NOWAIT:
    9986              :         case OMP_CLAUSE_DEFAULT:
    9987              :         case OMP_CLAUSE_UNTIED:
    9988              :         case OMP_CLAUSE_COLLAPSE:
    9989              :         case OMP_CLAUSE_PARALLEL:
    9990              :         case OMP_CLAUSE_FOR:
    9991              :         case OMP_CLAUSE_SECTIONS:
    9992              :         case OMP_CLAUSE_TASKGROUP:
    9993              :         case OMP_CLAUSE_PROC_BIND:
    9994              :         case OMP_CLAUSE_DEVICE_TYPE:
    9995              :         case OMP_CLAUSE_NOGROUP:
    9996              :         case OMP_CLAUSE_THREADS:
    9997              :         case OMP_CLAUSE_SIMD:
    9998              :         case OMP_CLAUSE_DEFAULTMAP:
    9999              :         case OMP_CLAUSE_BIND:
   10000              :         case OMP_CLAUSE_AUTO:
   10001              :         case OMP_CLAUSE_INDEPENDENT:
   10002              :         case OMP_CLAUSE_SEQ:
   10003              :         case OMP_CLAUSE_IF_PRESENT:
   10004              :         case OMP_CLAUSE_FINALIZE:
   10005              :         case OMP_CLAUSE_NOHOST:
   10006              :         case OMP_CLAUSE_INDIRECT:
   10007              :           break;
   10008              : 
   10009          231 :         case OMP_CLAUSE_MERGEABLE:
   10010          231 :           mergeable_seen = true;
   10011          231 :           break;
   10012              : 
   10013          322 :         case OMP_CLAUSE_TILE:
   10014          754 :           for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
   10015          432 :                list = TREE_CHAIN (list))
   10016              :             {
   10017          432 :               t = TREE_VALUE (list);
   10018              : 
   10019          432 :               if (t == error_mark_node)
   10020              :                 remove = true;
   10021          403 :               else if (!type_dependent_expression_p (t)
   10022          403 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10023              :                 {
   10024            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10025              :                             "%<tile%> argument needs integral type");
   10026            3 :                   remove = true;
   10027              :                 }
   10028              :               else
   10029              :                 {
   10030          400 :                   t = mark_rvalue_use (t);
   10031          400 :                   if (!processing_template_decl)
   10032              :                     {
   10033              :                       /* Zero is used to indicate '*', we permit you
   10034              :                          to get there via an ICE of value zero.  */
   10035          385 :                       t = maybe_constant_value (t);
   10036          385 :                       if (!tree_fits_shwi_p (t)
   10037          369 :                           || tree_to_shwi (t) < 0)
   10038              :                         {
   10039           40 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10040              :                                     "%<tile%> argument needs positive "
   10041              :                                     "integral constant");
   10042           40 :                           remove = true;
   10043              :                         }
   10044              :                     }
   10045              :                 }
   10046              : 
   10047              :                 /* Update list item.  */
   10048          432 :               TREE_VALUE (list) = t;
   10049              :             }
   10050              :           break;
   10051              : 
   10052         1027 :         case OMP_CLAUSE_SIZES:
   10053         1027 :           for (tree list = OMP_CLAUSE_SIZES_LIST (c);
   10054         2688 :                !remove && list; list = TREE_CHAIN (list))
   10055              :             {
   10056         1661 :               t = TREE_VALUE (list);
   10057              : 
   10058         1661 :               if (t == error_mark_node)
   10059            0 :                 t = integer_one_node;
   10060         1661 :               else if (!type_dependent_expression_p (t)
   10061         1661 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10062              :                 {
   10063            8 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10064              :                             "%<sizes%> argument needs positive integral "
   10065              :                             "constant");
   10066            8 :                   t = integer_one_node;
   10067              :                 }
   10068              :               else
   10069              :                 {
   10070         1653 :                   t = mark_rvalue_use (t);
   10071         1653 :                   if (!processing_template_decl)
   10072              :                     {
   10073         1636 :                       t = maybe_constant_value (t);
   10074         1636 :                       HOST_WIDE_INT n;
   10075         1636 :                       if (!tree_fits_shwi_p (t)
   10076         1632 :                           || !INTEGRAL_TYPE_P (TREE_TYPE (t))
   10077         1632 :                           || (n = tree_to_shwi (t)) <= 0
   10078         3240 :                           || (int)n != n)
   10079              :                         {
   10080           32 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10081              :                                     "%<sizes%> argument needs positive "
   10082              :                                     "integral constant");
   10083           32 :                           t = integer_one_node;
   10084              :                         }
   10085              :                     }
   10086              :                 }
   10087              : 
   10088              :               /* Update list item.  */
   10089         1661 :               TREE_VALUE (list) = t;
   10090              :             }
   10091              :           break;
   10092              : 
   10093          630 :         case OMP_CLAUSE_ORDERED:
   10094          630 :           ordered_seen = true;
   10095          630 :           break;
   10096              : 
   10097         1549 :         case OMP_CLAUSE_ORDER:
   10098         1549 :           if (order_seen)
   10099              :             remove = true;
   10100              :           else
   10101              :             order_seen = true;
   10102              :           break;
   10103              : 
   10104          638 :         case OMP_CLAUSE_INBRANCH:
   10105          638 :         case OMP_CLAUSE_NOTINBRANCH:
   10106          638 :           if (branch_seen)
   10107              :             {
   10108            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10109              :                         "%<inbranch%> clause is incompatible with "
   10110              :                         "%<notinbranch%>");
   10111            3 :               remove = true;
   10112              :             }
   10113              :           branch_seen = true;
   10114              :           break;
   10115              : 
   10116          297 :         case OMP_CLAUSE_INCLUSIVE:
   10117          297 :         case OMP_CLAUSE_EXCLUSIVE:
   10118          297 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10119          297 :           if (!t)
   10120          297 :             t = OMP_CLAUSE_DECL (c);
   10121          297 :           if (t == current_class_ptr)
   10122              :             {
   10123            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10124              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
   10125              :                         " clauses");
   10126            0 :               remove = true;
   10127            0 :               break;
   10128              :             }
   10129          297 :           if (!VAR_P (t)
   10130              :               && TREE_CODE (t) != PARM_DECL
   10131              :               && TREE_CODE (t) != FIELD_DECL)
   10132              :             {
   10133            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   10134              :                 break;
   10135            0 :               if (DECL_P (t))
   10136            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10137              :                           "%qD is not a variable in clause %qs", t,
   10138            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10139              :               else
   10140            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10141              :                           "%qE is not a variable in clause %qs", t,
   10142            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10143              :               remove = true;
   10144              :             }
   10145              :           break;
   10146              : 
   10147              :         case OMP_CLAUSE_FULL:
   10148              :           break;
   10149              : 
   10150          470 :         case OMP_CLAUSE_PARTIAL:
   10151          470 :           partial_seen = true;
   10152          470 :           t = OMP_CLAUSE_PARTIAL_EXPR (c);
   10153          470 :           if (!t)
   10154              :             break;
   10155              : 
   10156          313 :           if (t == error_mark_node)
   10157              :             t = NULL_TREE;
   10158          313 :           else if (!type_dependent_expression_p (t)
   10159          313 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10160              :             {
   10161            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10162              :                         "%<partial%> argument needs positive constant "
   10163              :                         "integer expression");
   10164            3 :               t = NULL_TREE;
   10165              :             }
   10166              :           else
   10167              :             {
   10168          310 :               t = mark_rvalue_use (t);
   10169          310 :               if (!processing_template_decl)
   10170              :                 {
   10171          292 :                   t = maybe_constant_value (t);
   10172              : 
   10173          292 :                   HOST_WIDE_INT n;
   10174          584 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   10175          292 :                       || !tree_fits_shwi_p (t)
   10176          286 :                       || (n = tree_to_shwi (t)) <= 0
   10177          560 :                       || (int)n != n)
   10178              :                     {
   10179           24 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10180              :                                 "%<partial%> argument needs positive "
   10181              :                                 "constant integer expression");
   10182           24 :                       t = NULL_TREE;
   10183              :                     }
   10184              :                 }
   10185              :             }
   10186              : 
   10187          313 :           OMP_CLAUSE_PARTIAL_EXPR (c) = t;
   10188          313 :           break;
   10189          549 :         case OMP_CLAUSE_INIT:
   10190          549 :           init_seen = true;
   10191          549 :           OMP_CLAUSE_INIT_PREFER_TYPE (c)
   10192          549 :             = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
   10193          549 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   10194          271 :             init_no_targetsync_clause = c;
   10195              :           /* FALLTHRU */
   10196          844 :         case OMP_CLAUSE_DESTROY:
   10197          844 :         case OMP_CLAUSE_USE:
   10198          844 :           init_use_destroy_seen = true;
   10199          844 :           t = OMP_CLAUSE_DECL (c);
   10200          844 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   10201              :             {
   10202            9 :               error_at (OMP_CLAUSE_LOCATION (c),
   10203              :                         "%qD appears more than once in action clauses", t);
   10204            9 :               remove = true;
   10205            9 :               break;
   10206              :             }
   10207          835 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   10208              :           /* FALLTHRU */
   10209         1099 :         case OMP_CLAUSE_INTEROP:
   10210         1099 :           if (!processing_template_decl)
   10211              :             {
   10212         1003 :               if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
   10213              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) &&  */
   10214         1003 :                   !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   10215              :                 {
   10216          126 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10217              :                             "%qD must be of %<omp_interop_t%>",
   10218           63 :                             OMP_CLAUSE_DECL (c));
   10219           63 :                   remove = true;
   10220              :                 }
   10221          940 :               else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   10222          481 :                         || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   10223         1058 :                        && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   10224              :                 {
   10225           36 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10226           18 :                             "%qD shall not be const", OMP_CLAUSE_DECL (c));
   10227           18 :                   remove = true;
   10228              :                 }
   10229              :             }
   10230         1099 :           pc = &OMP_CLAUSE_CHAIN (c);
   10231         1099 :           break;
   10232            0 :         default:
   10233            0 :           gcc_unreachable ();
   10234           54 :         }
   10235              : 
   10236        97466 :       if (remove)
   10237              :         {
   10238         2580 :           if (grp_start_p)
   10239              :             {
   10240              :               /* If we found a clause to remove, we want to remove the whole
   10241              :                  expanded group, otherwise gimplify
   10242              :                  (omp_resolve_clause_dependencies) can get confused.  */
   10243          817 :               *grp_start_p = grp_sentinel;
   10244          817 :               pc = grp_start_p;
   10245          817 :               grp_start_p = NULL;
   10246              :             }
   10247              :           else
   10248         1763 :             *pc = OMP_CLAUSE_CHAIN (c);
   10249              :         }
   10250              :       else
   10251        94886 :         pc = &OMP_CLAUSE_CHAIN (c);
   10252              :     }
   10253              : 
   10254        62688 :   if (grp_start_p
   10255        62688 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   10256          140 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   10257           86 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   10258              : 
   10259        62688 :   if (reduction_seen < 0 && (ordered_seen || schedule_seen))
   10260        62688 :     reduction_seen = -2;
   10261              : 
   10262       158538 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   10263              :     {
   10264        95850 :       enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
   10265        95850 :       bool remove = false;
   10266        95850 :       bool need_complete_type = false;
   10267        95850 :       bool need_default_ctor = false;
   10268        95850 :       bool need_copy_ctor = false;
   10269        95850 :       bool need_copy_assignment = false;
   10270        95850 :       bool need_implicitly_determined = false;
   10271        95850 :       bool need_dtor = false;
   10272        95850 :       tree type, inner_type;
   10273              : 
   10274        95850 :       switch (c_kind)
   10275              :         {
   10276              :         case OMP_CLAUSE_SHARED:
   10277              :           need_implicitly_determined = true;
   10278              :           break;
   10279         2540 :         case OMP_CLAUSE_PRIVATE:
   10280         2540 :           need_complete_type = true;
   10281         2540 :           need_default_ctor = true;
   10282         2540 :           need_dtor = true;
   10283         2540 :           need_implicitly_determined = true;
   10284         2540 :           break;
   10285         3156 :         case OMP_CLAUSE_FIRSTPRIVATE:
   10286         3156 :           need_complete_type = true;
   10287         3156 :           need_copy_ctor = true;
   10288         3156 :           need_dtor = true;
   10289         3156 :           need_implicitly_determined = true;
   10290         3156 :           break;
   10291         2763 :         case OMP_CLAUSE_LASTPRIVATE:
   10292         2763 :           need_complete_type = true;
   10293         2763 :           need_copy_assignment = true;
   10294         2763 :           need_implicitly_determined = true;
   10295         2763 :           break;
   10296         7286 :         case OMP_CLAUSE_REDUCTION:
   10297         7286 :           if (reduction_seen == -2)
   10298           27 :             OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   10299         7286 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   10300          421 :             need_copy_assignment = true;
   10301              :           need_implicitly_determined = true;
   10302              :           break;
   10303              :         case OMP_CLAUSE_IN_REDUCTION:
   10304              :         case OMP_CLAUSE_TASK_REDUCTION:
   10305              :         case OMP_CLAUSE_INCLUSIVE:
   10306              :         case OMP_CLAUSE_EXCLUSIVE:
   10307              :           need_implicitly_determined = true;
   10308              :           break;
   10309         1550 :         case OMP_CLAUSE_LINEAR:
   10310         1550 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   10311              :             need_implicitly_determined = true;
   10312          679 :           else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   10313          721 :                    && !bitmap_bit_p (&map_head,
   10314           42 :                                      DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   10315              :             {
   10316            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10317              :                         "%<linear%> clause step is a parameter %qD not "
   10318              :                         "specified in %<uniform%> clause",
   10319            6 :                         OMP_CLAUSE_LINEAR_STEP (c));
   10320            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10321        74324 :               continue;
   10322              :             }
   10323              :           break;
   10324              :         case OMP_CLAUSE_COPYPRIVATE:
   10325          366 :           need_copy_assignment = true;
   10326              :           break;
   10327              :         case OMP_CLAUSE_COPYIN:
   10328          366 :           need_copy_assignment = true;
   10329              :           break;
   10330          798 :         case OMP_CLAUSE_SIMDLEN:
   10331          798 :           if (safelen
   10332          345 :               && !processing_template_decl
   10333         1143 :               && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   10334          345 :                                   OMP_CLAUSE_SIMDLEN_EXPR (c)))
   10335              :             {
   10336            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10337              :                         "%<simdlen%> clause value is bigger than "
   10338              :                         "%<safelen%> clause value");
   10339            0 :               OMP_CLAUSE_SIMDLEN_EXPR (c)
   10340            0 :                 = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   10341              :             }
   10342          798 :           pc = &OMP_CLAUSE_CHAIN (c);
   10343          798 :           continue;
   10344         3853 :         case OMP_CLAUSE_SCHEDULE:
   10345         3853 :           if (ordered_seen
   10346         3853 :               && (OMP_CLAUSE_SCHEDULE_KIND (c)
   10347              :                   & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   10348              :             {
   10349           21 :               error_at (OMP_CLAUSE_LOCATION (c),
   10350              :                         "%<nonmonotonic%> schedule modifier specified "
   10351              :                         "together with %<ordered%> clause");
   10352           42 :               OMP_CLAUSE_SCHEDULE_KIND (c)
   10353           21 :                 = (enum omp_clause_schedule_kind)
   10354           21 :                   (OMP_CLAUSE_SCHEDULE_KIND (c)
   10355              :                    & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   10356              :             }
   10357         3853 :           if (reduction_seen == -2)
   10358            9 :             error_at (OMP_CLAUSE_LOCATION (c),
   10359              :                       "%qs clause specified together with %<inscan%> "
   10360              :                       "%<reduction%> clause", "schedule");
   10361         3853 :           pc = &OMP_CLAUSE_CHAIN (c);
   10362         3853 :           continue;
   10363           51 :         case OMP_CLAUSE_NOGROUP:
   10364           51 :           if (reduction_seen)
   10365              :             {
   10366            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10367              :                         "%<nogroup%> clause must not be used together with "
   10368              :                         "%<reduction%> clause");
   10369            3 :               *pc = OMP_CLAUSE_CHAIN (c);
   10370            3 :               continue;
   10371              :             }
   10372           48 :           pc = &OMP_CLAUSE_CHAIN (c);
   10373           48 :           continue;
   10374          165 :         case OMP_CLAUSE_GRAINSIZE:
   10375          165 :           if (num_tasks_seen)
   10376              :             {
   10377            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10378              :                         "%<grainsize%> clause must not be used together with "
   10379              :                         "%<num_tasks%> clause");
   10380            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10381            6 :               continue;
   10382              :             }
   10383          159 :           pc = &OMP_CLAUSE_CHAIN (c);
   10384          159 :           continue;
   10385          630 :         case OMP_CLAUSE_ORDERED:
   10386          630 :           if (reduction_seen == -2)
   10387            6 :             error_at (OMP_CLAUSE_LOCATION (c),
   10388              :                       "%qs clause specified together with %<inscan%> "
   10389              :                       "%<reduction%> clause", "ordered");
   10390          630 :           pc = &OMP_CLAUSE_CHAIN (c);
   10391          630 :           continue;
   10392         1525 :         case OMP_CLAUSE_ORDER:
   10393         1525 :           if (ordered_seen)
   10394              :             {
   10395           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10396              :                         "%<order%> clause must not be used together "
   10397              :                         "with %<ordered%> clause");
   10398           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10399           12 :               continue;
   10400              :             }
   10401         1513 :           pc = &OMP_CLAUSE_CHAIN (c);
   10402         1513 :           continue;
   10403           57 :         case OMP_CLAUSE_DETACH:
   10404           57 :           if (mergeable_seen)
   10405              :             {
   10406            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10407              :                         "%<detach%> clause must not be used together with "
   10408              :                         "%<mergeable%> clause");
   10409            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10410            6 :               continue;
   10411              :             }
   10412           51 :           pc = &OMP_CLAUSE_CHAIN (c);
   10413           51 :           continue;
   10414        15958 :         case OMP_CLAUSE_MAP:
   10415        15958 :           if (target_in_reduction_seen && !processing_template_decl)
   10416              :             {
   10417          684 :               t = OMP_CLAUSE_DECL (c);
   10418          684 :               while (handled_component_p (t)
   10419              :                      || INDIRECT_REF_P (t)
   10420              :                      || TREE_CODE (t) == ADDR_EXPR
   10421              :                      || TREE_CODE (t) == MEM_REF
   10422          804 :                      || TREE_CODE (t) == NON_LVALUE_EXPR)
   10423          120 :                 t = TREE_OPERAND (t, 0);
   10424          684 :               if (DECL_P (t)
   10425          684 :                   && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   10426          342 :                 OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   10427              :             }
   10428        15958 :           pc = &OMP_CLAUSE_CHAIN (c);
   10429        15958 :           continue;
   10430          225 :         case OMP_CLAUSE_FULL:
   10431          225 :           if (partial_seen)
   10432              :             {
   10433           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10434              :                         "%<full%> clause must not be used together "
   10435              :                         "with %<partial%> clause");
   10436           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10437           12 :               continue;
   10438              :             }
   10439          213 :           pc = &OMP_CLAUSE_CHAIN (c);
   10440          213 :           continue;
   10441         6894 :         case OMP_CLAUSE_NOWAIT:
   10442         6894 :           if (copyprivate_seen)
   10443              :             {
   10444            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10445              :                         "%<nowait%> clause must not be used together "
   10446              :                         "with %<copyprivate%> clause");
   10447            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10448            6 :               continue;
   10449              :             }
   10450              :           /* FALLTHRU */
   10451        50412 :         default:
   10452        50412 :           pc = &OMP_CLAUSE_CHAIN (c);
   10453        50412 :           continue;
   10454              :         }
   10455              : 
   10456        22164 :       t = OMP_CLAUSE_DECL (c);
   10457        22164 :       switch (c_kind)
   10458              :         {
   10459         2763 :         case OMP_CLAUSE_LASTPRIVATE:
   10460         2763 :           if (DECL_P (t)
   10461         2763 :               && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
   10462              :             {
   10463         2666 :               need_default_ctor = true;
   10464         2666 :               need_dtor = true;
   10465              :             }
   10466              :           break;
   10467              : 
   10468         9425 :         case OMP_CLAUSE_REDUCTION:
   10469         9425 :         case OMP_CLAUSE_IN_REDUCTION:
   10470         9425 :         case OMP_CLAUSE_TASK_REDUCTION:
   10471         9425 :           if (allocate_seen)
   10472              :             {
   10473         1561 :               if (TREE_CODE (t) == MEM_REF)
   10474              :                 {
   10475          162 :                   t = TREE_OPERAND (t, 0);
   10476          162 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   10477            0 :                     t = TREE_OPERAND (t, 0);
   10478          162 :                   if (TREE_CODE (t) == ADDR_EXPR
   10479          120 :                       || INDIRECT_REF_P (t))
   10480           80 :                     t = TREE_OPERAND (t, 0);
   10481          162 :                   if (DECL_P (t))
   10482          162 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10483              :                 }
   10484         1399 :               else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10485              :                 {
   10486          192 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10487           96 :                     t = TREE_OPERAND (t, 0);
   10488           96 :                   if (DECL_P (t))
   10489           96 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10490           96 :                   t = OMP_CLAUSE_DECL (c);
   10491              :                 }
   10492         1303 :               else if (DECL_P (t))
   10493         1303 :                 bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10494         1561 :               t = OMP_CLAUSE_DECL (c);
   10495              :             }
   10496         9425 :           if (processing_template_decl
   10497          863 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10498              :             break;
   10499         8855 :           if (finish_omp_reduction_clause (c, &need_default_ctor,
   10500              :                                            &need_dtor))
   10501              :             remove = true;
   10502              :           else
   10503         8771 :             t = OMP_CLAUSE_DECL (c);
   10504              :           break;
   10505              : 
   10506          274 :         case OMP_CLAUSE_COPYIN:
   10507          274 :           if (processing_template_decl
   10508            0 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10509              :             break;
   10510          274 :           if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
   10511              :             {
   10512           15 :               error_at (OMP_CLAUSE_LOCATION (c),
   10513              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   10514           15 :               remove = true;
   10515              :             }
   10516              :           break;
   10517              : 
   10518              :         default:
   10519              :           break;
   10520              :         }
   10521              : 
   10522        22164 :       if (processing_template_decl
   10523         1544 :           && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10524              :         {
   10525          632 :           pc = &OMP_CLAUSE_CHAIN (c);
   10526          632 :           continue;
   10527              :         }
   10528              : 
   10529        21532 :       if (need_complete_type || need_copy_assignment)
   10530              :         {
   10531         9190 :           t = require_complete_type (t);
   10532         9190 :           if (t == error_mark_node)
   10533              :             remove = true;
   10534         9166 :           else if (!processing_template_decl
   10535         8783 :                    && TYPE_REF_P (TREE_TYPE (t))
   10536         9722 :                    && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
   10537              :             remove = true;
   10538              :         }
   10539        21532 :       if (need_implicitly_determined)
   10540              :         {
   10541        20494 :           const char *share_name = NULL;
   10542              : 
   10543        20494 :           if (allocate_seen
   10544         4993 :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10545        24608 :               && DECL_P (t))
   10546         3904 :             bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10547              : 
   10548        20494 :           if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   10549              :             share_name = "threadprivate";
   10550        20452 :           else switch (cxx_omp_predetermined_sharing_1 (t))
   10551              :             {
   10552              :             case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   10553              :               break;
   10554           47 :             case OMP_CLAUSE_DEFAULT_SHARED:
   10555           47 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10556           30 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   10557           64 :                   && c_omp_predefined_variable (t))
   10558              :                 /* The __func__ variable and similar function-local predefined
   10559              :                    variables may be listed in a shared or firstprivate
   10560              :                    clause.  */
   10561              :                 break;
   10562           31 :               if (VAR_P (t)
   10563           31 :                   && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10564            9 :                   && TREE_STATIC (t)
   10565           40 :                   && cxx_omp_const_qual_no_mutable (t))
   10566              :                 {
   10567            6 :                   tree ctx = CP_DECL_CONTEXT (t);
   10568              :                   /* const qualified static data members without mutable
   10569              :                      member may be specified in firstprivate clause.  */
   10570            6 :                   if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
   10571              :                     break;
   10572              :                 }
   10573              :               share_name = "shared";
   10574              :               break;
   10575              :             case OMP_CLAUSE_DEFAULT_PRIVATE:
   10576              :               share_name = "private";
   10577              :               break;
   10578            0 :             default:
   10579            0 :               gcc_unreachable ();
   10580              :             }
   10581              :           if (share_name)
   10582              :             {
   10583           67 :               error_at (OMP_CLAUSE_LOCATION (c),
   10584              :                         "%qE is predetermined %qs for %qs",
   10585              :                         omp_clause_printable_decl (t), share_name,
   10586           67 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10587           67 :               remove = true;
   10588              :             }
   10589        20427 :           else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10590        18368 :                    && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
   10591        35668 :                    && cxx_omp_const_qual_no_mutable (t))
   10592              :             {
   10593          126 :               error_at (OMP_CLAUSE_LOCATION (c),
   10594              :                         "%<const%> qualified %qE without %<mutable%> member "
   10595              :                         "may appear only in %<shared%> or %<firstprivate%> "
   10596              :                         "clauses", omp_clause_printable_decl (t));
   10597           63 :               remove = true;
   10598              :             }
   10599              :         }
   10600              : 
   10601        21532 :       if (detach_seen
   10602           16 :           && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10603           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   10604           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10605            0 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   10606        21548 :           && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
   10607              :         {
   10608            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   10609              :                     "the event handle of a %<detach%> clause "
   10610              :                     "should not be in a data-sharing clause");
   10611            6 :           remove = true;
   10612              :         }
   10613              : 
   10614              :       /* We're interested in the base element, not arrays.  */
   10615        21532 :       inner_type = type = TREE_TYPE (t);
   10616        21532 :       if ((need_complete_type
   10617              :            || need_copy_assignment
   10618        12342 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   10619         5708 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   10620         4235 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   10621        29966 :           && TYPE_REF_P (inner_type))
   10622          878 :         inner_type = TREE_TYPE (inner_type);
   10623        24113 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   10624         2581 :         inner_type = TREE_TYPE (inner_type);
   10625              : 
   10626              :       /* Check for special function availability by building a call to one.
   10627              :          Save the results, because later we won't be in the right context
   10628              :          for making these queries.  */
   10629         2387 :       if (CLASS_TYPE_P (inner_type)
   10630         2387 :           && COMPLETE_TYPE_P (inner_type)
   10631         2318 :           && (need_default_ctor || need_copy_ctor
   10632         1081 :               || need_copy_assignment || need_dtor)
   10633         1994 :           && !type_dependent_expression_p (t)
   10634        23526 :           && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
   10635              :                                          need_copy_ctor, need_copy_assignment,
   10636              :                                          need_dtor))
   10637              :         remove = true;
   10638              : 
   10639        21532 :       if (!remove
   10640        21532 :           && c_kind == OMP_CLAUSE_SHARED
   10641         2056 :           && processing_template_decl)
   10642              :         {
   10643          125 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10644          125 :           if (t)
   10645            5 :             OMP_CLAUSE_DECL (c) = t;
   10646              :         }
   10647              : 
   10648        21532 :       if (remove)
   10649          292 :         *pc = OMP_CLAUSE_CHAIN (c);
   10650              :       else
   10651        21240 :         pc = &OMP_CLAUSE_CHAIN (c);
   10652              :     }
   10653              : 
   10654        62688 :   if (allocate_seen)
   10655        16828 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   10656              :       {
   10657        14544 :         bool remove = false;
   10658        14544 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   10659         2540 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   10660         2143 :             && DECL_P (OMP_CLAUSE_DECL (c))
   10661        16687 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   10662              :           {
   10663           15 :             error_at (OMP_CLAUSE_LOCATION (c),
   10664              :                       "%qD specified in %<allocate%> clause but not in "
   10665           15 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   10666           15 :             remove = true;
   10667              :           }
   10668        14544 :         if (remove)
   10669           15 :           *pc = OMP_CLAUSE_CHAIN (c);
   10670              :         else
   10671        14529 :           pc = &OMP_CLAUSE_CHAIN (c);
   10672              :       }
   10673              : 
   10674        62688 :   if (ort == C_ORT_OMP_INTEROP
   10675        62688 :       && depend_clause
   10676           60 :       && (!init_use_destroy_seen
   10677           57 :           || (init_seen && init_no_targetsync_clause)))
   10678              :     {
   10679            9 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   10680              :                 "%<depend%> clause requires action clauses with "
   10681              :                 "%<targetsync%> interop-type");
   10682            9 :       if (init_no_targetsync_clause)
   10683            6 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   10684              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   10685              :     }
   10686              : 
   10687        62688 :   bitmap_obstack_release (NULL);
   10688        62688 :   return clauses;
   10689              : }
   10690              : 
   10691              : /* Start processing OpenMP clauses that can include any
   10692              :    privatization clauses for non-static data members.  */
   10693              : 
   10694              : tree
   10695        48538 : push_omp_privatization_clauses (bool ignore_next)
   10696              : {
   10697        48538 :   if (omp_private_member_ignore_next)
   10698              :     {
   10699          656 :       omp_private_member_ignore_next = ignore_next;
   10700          656 :       return NULL_TREE;
   10701              :     }
   10702        47882 :   omp_private_member_ignore_next = ignore_next;
   10703        47882 :   if (omp_private_member_map)
   10704           24 :     omp_private_member_vec.safe_push (error_mark_node);
   10705        47882 :   return push_stmt_list ();
   10706              : }
   10707              : 
   10708              : /* Revert remapping of any non-static data members since
   10709              :    the last push_omp_privatization_clauses () call.  */
   10710              : 
   10711              : void
   10712        48532 : pop_omp_privatization_clauses (tree stmt)
   10713              : {
   10714        48532 :   if (stmt == NULL_TREE)
   10715              :     return;
   10716        47876 :   stmt = pop_stmt_list (stmt);
   10717        47876 :   if (omp_private_member_map)
   10718              :     {
   10719         1280 :       while (!omp_private_member_vec.is_empty ())
   10720              :         {
   10721          850 :           tree t = omp_private_member_vec.pop ();
   10722          850 :           if (t == error_mark_node)
   10723              :             {
   10724           24 :               add_stmt (stmt);
   10725           24 :               return;
   10726              :             }
   10727          826 :           bool no_decl_expr = t == integer_zero_node;
   10728          826 :           if (no_decl_expr)
   10729          136 :             t = omp_private_member_vec.pop ();
   10730          826 :           tree *v = omp_private_member_map->get (t);
   10731          826 :           gcc_assert (v);
   10732          826 :           if (!no_decl_expr)
   10733          690 :             add_decl_expr (*v);
   10734          826 :           omp_private_member_map->remove (t);
   10735              :         }
   10736          860 :       delete omp_private_member_map;
   10737          430 :       omp_private_member_map = NULL;
   10738              :     }
   10739        47852 :   add_stmt (stmt);
   10740              : }
   10741              : 
   10742              : /* Remember OpenMP privatization clauses mapping and clear it.
   10743              :    Used for lambdas.  */
   10744              : 
   10745              : void
   10746     15120490 : save_omp_privatization_clauses (vec<tree> &save)
   10747              : {
   10748     15120490 :   save = vNULL;
   10749     15120490 :   if (omp_private_member_ignore_next)
   10750            2 :     save.safe_push (integer_one_node);
   10751     15120490 :   omp_private_member_ignore_next = false;
   10752     15120490 :   if (!omp_private_member_map)
   10753              :     return;
   10754              : 
   10755            0 :   while (!omp_private_member_vec.is_empty ())
   10756              :     {
   10757            0 :       tree t = omp_private_member_vec.pop ();
   10758            0 :       if (t == error_mark_node)
   10759              :         {
   10760            0 :           save.safe_push (t);
   10761            0 :           continue;
   10762              :         }
   10763            0 :       tree n = t;
   10764            0 :       if (t == integer_zero_node)
   10765            0 :         t = omp_private_member_vec.pop ();
   10766            0 :       tree *v = omp_private_member_map->get (t);
   10767            0 :       gcc_assert (v);
   10768            0 :       save.safe_push (*v);
   10769            0 :       save.safe_push (t);
   10770            0 :       if (n != t)
   10771            0 :         save.safe_push (n);
   10772              :     }
   10773            0 :   delete omp_private_member_map;
   10774            0 :   omp_private_member_map = NULL;
   10775              : }
   10776              : 
   10777              : /* Restore OpenMP privatization clauses mapping saved by the
   10778              :    above function.  */
   10779              : 
   10780              : void
   10781     15120490 : restore_omp_privatization_clauses (vec<tree> &save)
   10782              : {
   10783     15120490 :   gcc_assert (omp_private_member_vec.is_empty ());
   10784     15120490 :   omp_private_member_ignore_next = false;
   10785     15120490 :   if (save.is_empty ())
   10786              :     return;
   10787            4 :   if (save.length () == 1 && save[0] == integer_one_node)
   10788              :     {
   10789            2 :       omp_private_member_ignore_next = true;
   10790            2 :       save.release ();
   10791            2 :       return;
   10792              :     }
   10793              : 
   10794            0 :   omp_private_member_map = new hash_map <tree, tree>;
   10795            0 :   while (!save.is_empty ())
   10796              :     {
   10797            0 :       tree t = save.pop ();
   10798            0 :       tree n = t;
   10799            0 :       if (t != error_mark_node)
   10800              :         {
   10801            0 :           if (t == integer_one_node)
   10802              :             {
   10803            0 :               omp_private_member_ignore_next = true;
   10804            0 :               gcc_assert (save.is_empty ());
   10805            0 :               break;
   10806              :             }
   10807            0 :           if (t == integer_zero_node)
   10808            0 :             t = save.pop ();
   10809            0 :           tree &v = omp_private_member_map->get_or_insert (t);
   10810            0 :           v = save.pop ();
   10811              :         }
   10812            0 :       omp_private_member_vec.safe_push (t);
   10813            0 :       if (n != t)
   10814            0 :         omp_private_member_vec.safe_push (n);
   10815              :     }
   10816            0 :   save.release ();
   10817              : }
   10818              : 
   10819              : /* For all variables in the tree_list VARS, mark them as thread local.  */
   10820              : 
   10821              : void
   10822          238 : finish_omp_threadprivate (tree vars)
   10823              : {
   10824          238 :   tree t;
   10825              : 
   10826              :   /* Mark every variable in VARS to be assigned thread local storage.  */
   10827          509 :   for (t = vars; t; t = TREE_CHAIN (t))
   10828              :     {
   10829          271 :       tree v = TREE_PURPOSE (t);
   10830          271 :       location_t loc = EXPR_LOCATION (TREE_VALUE (t));
   10831              : 
   10832          271 :       if (error_operand_p (v))
   10833              :         ;
   10834          271 :       else if (!VAR_P (v))
   10835            6 :         error_at (loc, "%<threadprivate%> %qD is not file, namespace "
   10836              :                        "or block scope variable", v);
   10837              :       /* If V had already been marked threadprivate, it doesn't matter
   10838              :          whether it had been used prior to this point.  */
   10839          265 :       else if (TREE_USED (v)
   10840          265 :           && (DECL_LANG_SPECIFIC (v) == NULL
   10841            3 :               || !CP_DECL_THREADPRIVATE_P (v)))
   10842            6 :         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
   10843          259 :       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
   10844            6 :         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
   10845          253 :       else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
   10846            3 :         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
   10847          201 :       else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
   10848          273 :                && CP_DECL_CONTEXT (v) != current_class_type)
   10849            6 :         error_at (loc, "%<threadprivate%> %qE directive not "
   10850            6 :                        "in %qT definition", v, CP_DECL_CONTEXT (v));
   10851              :       else
   10852              :         {
   10853              :           /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
   10854          244 :           if (DECL_LANG_SPECIFIC (v) == NULL)
   10855          200 :             retrofit_lang_decl (v);
   10856              : 
   10857          244 :           if (! CP_DECL_THREAD_LOCAL_P (v))
   10858              :             {
   10859          244 :               CP_DECL_THREAD_LOCAL_P (v) = true;
   10860          244 :               set_decl_tls_model (v, decl_default_tls_model (v));
   10861              :               /* If rtl has been already set for this var, call
   10862              :                  make_decl_rtl once again, so that encode_section_info
   10863              :                  has a chance to look at the new decl flags.  */
   10864          244 :               if (DECL_RTL_SET_P (v))
   10865            0 :                 make_decl_rtl (v);
   10866              :             }
   10867          244 :           CP_DECL_THREADPRIVATE_P (v) = 1;
   10868              :         }
   10869              :     }
   10870          238 : }
   10871              : 
   10872              : /* Build an OpenMP structured block.  */
   10873              : 
   10874              : tree
   10875        64012 : begin_omp_structured_block (void)
   10876              : {
   10877        64012 :   return do_pushlevel (sk_omp);
   10878              : }
   10879              : 
   10880              : tree
   10881        63997 : finish_omp_structured_block (tree block)
   10882              : {
   10883        63997 :   return do_poplevel (block);
   10884              : }
   10885              : 
   10886              : /* Similarly, except force the retention of the BLOCK.  */
   10887              : 
   10888              : tree
   10889        14797 : begin_omp_parallel (void)
   10890              : {
   10891        14797 :   keep_next_level (true);
   10892        14797 :   return begin_omp_structured_block ();
   10893              : }
   10894              : 
   10895              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   10896              :    statement.  */
   10897              : 
   10898              : tree
   10899          768 : finish_oacc_data (tree clauses, tree block)
   10900              : {
   10901          768 :   tree stmt;
   10902              : 
   10903          768 :   block = finish_omp_structured_block (block);
   10904              : 
   10905          768 :   stmt = make_node (OACC_DATA);
   10906          768 :   TREE_TYPE (stmt) = void_type_node;
   10907          768 :   OACC_DATA_CLAUSES (stmt) = clauses;
   10908          768 :   OACC_DATA_BODY (stmt) = block;
   10909              : 
   10910          768 :   return add_stmt (stmt);
   10911              : }
   10912              : 
   10913              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   10914              :    statement.  */
   10915              : 
   10916              : tree
   10917           55 : finish_oacc_host_data (tree clauses, tree block)
   10918              : {
   10919           55 :   tree stmt;
   10920              : 
   10921           55 :   block = finish_omp_structured_block (block);
   10922              : 
   10923           55 :   stmt = make_node (OACC_HOST_DATA);
   10924           55 :   TREE_TYPE (stmt) = void_type_node;
   10925           55 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   10926           55 :   OACC_HOST_DATA_BODY (stmt) = block;
   10927              : 
   10928           55 :   return add_stmt (stmt);
   10929              : }
   10930              : 
   10931              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   10932              :    statement.  */
   10933              : 
   10934              : tree
   10935         4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
   10936              : {
   10937         4653 :   body = finish_omp_structured_block (body);
   10938              : 
   10939         4653 :   tree stmt = make_node (code);
   10940         4653 :   TREE_TYPE (stmt) = void_type_node;
   10941         4653 :   OMP_BODY (stmt) = body;
   10942         4653 :   OMP_CLAUSES (stmt) = clauses;
   10943              : 
   10944         4653 :   return add_stmt (stmt);
   10945              : }
   10946              : 
   10947              : /* Used to walk OpenMP target directive body.  */
   10948              : 
   10949              : struct omp_target_walk_data
   10950              : {
   10951              :   /* Holds the 'this' expression found in current function.  */
   10952              :   tree current_object;
   10953              : 
   10954              :   /* True if the 'this' expression was accessed in the target body.  */
   10955              :   bool this_expr_accessed;
   10956              : 
   10957              :   /* For non-static functions, record which pointer-typed members were
   10958              :      accessed, and the whole expression.  */
   10959              :   hash_map<tree, tree> ptr_members_accessed;
   10960              : 
   10961              :   /* Record which lambda objects were accessed in target body.  */
   10962              :   hash_set<tree> lambda_objects_accessed;
   10963              : 
   10964              :   /* For lambda functions, the __closure object expression of the current
   10965              :      function, and the set of captured variables accessed in target body.  */
   10966              :   tree current_closure;
   10967              :   hash_set<tree> closure_vars_accessed;
   10968              : 
   10969              :   /* Local variables declared inside a BIND_EXPR, used to filter out such
   10970              :      variables when recording lambda_objects_accessed.  */
   10971              :   hash_set<tree> local_decls;
   10972              : 
   10973              :   omp_mapper_list<tree> *mappers;
   10974              : };
   10975              : 
   10976              : /* Helper function of finish_omp_target_clauses, called via
   10977              :    cp_walk_tree_without_duplicates.  Traverse body of OpenMP target
   10978              :    directive *TP, and fill out omp_target_walk_data passed in *PTR.  */
   10979              : 
   10980              : static tree
   10981       228087 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
   10982              : {
   10983       228087 :   tree t = *tp;
   10984       228087 :   struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
   10985       228087 :   tree current_object = data->current_object;
   10986       228087 :   tree current_closure = data->current_closure;
   10987       228087 :   omp_mapper_list<tree> *mlist = data->mappers;
   10988              : 
   10989              :   /* References inside of these expression codes shouldn't incur any
   10990              :      form of mapping, so return early.  */
   10991       228087 :   if (TREE_CODE (t) == SIZEOF_EXPR
   10992       228079 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   10993              :     {
   10994            8 :       *walk_subtrees = 0;
   10995            8 :       return NULL_TREE;
   10996              :     }
   10997              : 
   10998       228079 :   if (TREE_CODE (t) == OMP_CLAUSE)
   10999              :     return NULL_TREE;
   11000              : 
   11001       215494 :   if (!processing_template_decl)
   11002              :     {
   11003       215494 :       tree aggr_type = NULL_TREE;
   11004              : 
   11005       215494 :       if (TREE_CODE (t) == COMPONENT_REF
   11006       215494 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   11007         2257 :         aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   11008       213237 :       else if ((TREE_CODE (t) == VAR_DECL
   11009              :                 || TREE_CODE (t) == PARM_DECL
   11010              :                 || TREE_CODE (t) == RESULT_DECL)
   11011        16940 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   11012         1216 :         aggr_type = TREE_TYPE (t);
   11013              : 
   11014         3473 :       if (aggr_type)
   11015              :         {
   11016         3473 :           tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
   11017         3473 :           if (mapper_fn)
   11018          199 :             mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   11019              :         }
   11020              :     }
   11021              : 
   11022       215494 :   if (current_object)
   11023              :     {
   11024         2564 :       tree this_expr = TREE_OPERAND (current_object, 0);
   11025              : 
   11026         2564 :       if (operand_equal_p (t, this_expr))
   11027              :         {
   11028           35 :           data->this_expr_accessed = true;
   11029           35 :           *walk_subtrees = 0;
   11030           35 :           return NULL_TREE;
   11031              :         }
   11032              : 
   11033         2529 :       if (TREE_CODE (t) == COMPONENT_REF
   11034          115 :           && POINTER_TYPE_P (TREE_TYPE (t))
   11035           36 :           && operand_equal_p (TREE_OPERAND (t, 0), current_object)
   11036         2563 :           && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
   11037              :         {
   11038           34 :           data->this_expr_accessed = true;
   11039           34 :           tree fld = TREE_OPERAND (t, 1);
   11040           34 :           if (data->ptr_members_accessed.get (fld) == NULL)
   11041              :             {
   11042           14 :               if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
   11043            4 :                 t = convert_from_reference (t);
   11044           14 :               data->ptr_members_accessed.put (fld, t);
   11045              :             }
   11046           34 :           *walk_subtrees = 0;
   11047           34 :           return NULL_TREE;
   11048              :         }
   11049              :     }
   11050              : 
   11051              :   /* When the current_function_decl is a lambda function, the closure object
   11052              :      argument's type seems to not yet have fields layed out, so a recording
   11053              :      of DECL_VALUE_EXPRs during the target body walk seems the only way to
   11054              :      find them.  */
   11055       215425 :   if (current_closure
   11056          300 :       && (VAR_P (t)
   11057              :           || TREE_CODE (t) == PARM_DECL
   11058              :           || TREE_CODE (t) == RESULT_DECL)
   11059           24 :       && DECL_HAS_VALUE_EXPR_P (t)
   11060           10 :       && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
   11061       215435 :       && operand_equal_p (current_closure,
   11062           10 :                           TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
   11063              :     {
   11064            9 :       if (!data->closure_vars_accessed.contains (t))
   11065            9 :         data->closure_vars_accessed.add (t);
   11066            9 :       *walk_subtrees = 0;
   11067            9 :       return NULL_TREE;
   11068              :     }
   11069              : 
   11070       215416 :   if (TREE_CODE (t) == BIND_EXPR)
   11071              :     {
   11072        20039 :       if (tree block = BIND_EXPR_BLOCK (t))
   11073        22480 :         for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
   11074         2445 :           if (!data->local_decls.contains (var))
   11075         2445 :             data->local_decls.add (var);
   11076        20039 :       return NULL_TREE;
   11077              :     }
   11078              : 
   11079       199980 :   if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
   11080              :     {
   11081           39 :       tree lt = TREE_TYPE (t);
   11082           39 :       gcc_assert (CLASS_TYPE_P (lt));
   11083              : 
   11084           39 :       if (!data->lambda_objects_accessed.contains (t)
   11085              :           /* Do not prepare to create target maps for locally declared
   11086              :              lambdas or anonymous ones.  */
   11087           39 :           && !data->local_decls.contains (t)
   11088           72 :           && TREE_CODE (t) != TARGET_EXPR)
   11089           13 :         data->lambda_objects_accessed.add (t);
   11090           39 :       *walk_subtrees = 0;
   11091           39 :       return NULL_TREE;
   11092              :     }
   11093              : 
   11094              :   return NULL_TREE;
   11095              : }
   11096              : 
   11097              : /* Helper function for finish_omp_target, and also from tsubst_expr.
   11098              :    Create additional clauses for mapping of non-static members, lambda objects,
   11099              :    etc.  */
   11100              : 
   11101              : void
   11102         6994 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
   11103              : {
   11104         6994 :   omp_target_walk_data data;
   11105         6994 :   data.this_expr_accessed = false;
   11106         6994 :   data.current_object = NULL_TREE;
   11107              : 
   11108         6994 :   if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
   11109           96 :     if (tree ct = current_nonlambda_class_type ())
   11110              :       {
   11111           95 :         tree object = maybe_dummy_object (ct, NULL);
   11112           95 :         object = maybe_resolve_dummy (object, true);
   11113           95 :         data.current_object = object;
   11114              :       }
   11115              : 
   11116         6994 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11117              :     {
   11118            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11119            8 :       data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11120              :     }
   11121              :   else
   11122         6986 :     data.current_closure = NULL_TREE;
   11123              : 
   11124         6994 :   auto_vec<tree, 16> new_clauses;
   11125              : 
   11126         6994 :   if (!processing_template_decl)
   11127              :     {
   11128         6994 :       hash_set<omp_name_type<tree> > seen_types;
   11129         6994 :       auto_vec<tree> mapper_fns;
   11130         6994 :       omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
   11131         6994 :       data.mappers = &mlist;
   11132              : 
   11133         6994 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11134              :                                        &data);
   11135              : 
   11136         6994 :       unsigned int i;
   11137         6994 :       tree mapper_fn;
   11138        14081 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11139           93 :         c_omp_find_nested_mappers (&mlist, mapper_fn);
   11140              : 
   11141         7157 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11142              :         {
   11143           93 :           tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
   11144           93 :           if (mapper == error_mark_node)
   11145            0 :             continue;
   11146           93 :           tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   11147           93 :           tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   11148           93 :           if (BASELINK_P (mapper_fn))
   11149            0 :             mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
   11150              : 
   11151           93 :           tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   11152           93 :           OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   11153           93 :           OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   11154           93 :           OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
   11155              : 
   11156           93 :           new_clauses.safe_push (c);
   11157              :         }
   11158         6994 :     }
   11159              :   else
   11160              :     {
   11161            0 :       data.mappers = NULL;
   11162            0 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11163              :                                        &data);
   11164              :     }
   11165              : 
   11166         6994 :   tree omp_target_this_expr = NULL_TREE;
   11167         6994 :   tree *explicit_this_deref_map = NULL;
   11168         6994 :   if (data.this_expr_accessed)
   11169              :     {
   11170           31 :       omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
   11171              : 
   11172              :       /* See if explicit user-specified map(this[:]) clause already exists.
   11173              :          If not, we create an implicit map(tofrom:this[:1]) clause.  */
   11174           80 :       for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
   11175           50 :         if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
   11176           47 :             && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
   11177           40 :                 || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
   11178           57 :             && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
   11179              :                                 omp_target_this_expr))
   11180              :           {
   11181              :             explicit_this_deref_map = cp;
   11182              :             break;
   11183              :           }
   11184              :     }
   11185              : 
   11186         6994 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11187         6994 :       && (data.this_expr_accessed
   11188            1 :           || !data.closure_vars_accessed.is_empty ()))
   11189              :     {
   11190              :       /* For lambda functions, we need to first create a copy of the
   11191              :          __closure object.  */
   11192            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11193            8 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11194            8 :       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   11195            8 :       OMP_CLAUSE_DECL (c)
   11196            8 :         = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11197            8 :       OMP_CLAUSE_SIZE (c)
   11198            8 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
   11199            8 :       new_clauses.safe_push (c);
   11200              : 
   11201            8 :       tree closure_obj = OMP_CLAUSE_DECL (c);
   11202            8 :       tree closure_type = TREE_TYPE (closure_obj);
   11203              : 
   11204           16 :       gcc_assert (LAMBDA_TYPE_P (closure_type)
   11205              :                   && CLASS_TYPE_P (closure_type));
   11206              : 
   11207            8 :       tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11208            8 :       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   11209            8 :       OMP_CLAUSE_DECL (c2) = closure;
   11210            8 :       OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11211            8 :       new_clauses.safe_push (c2);
   11212              :     }
   11213              : 
   11214         6994 :   if (data.this_expr_accessed)
   11215              :     {
   11216              :       /* If the this-expr was accessed, create a map(*this) clause.  */
   11217           31 :       enum gomp_map_kind kind = GOMP_MAP_TOFROM;
   11218           31 :       if (explicit_this_deref_map)
   11219              :         {
   11220            1 :           tree this_map = *explicit_this_deref_map;
   11221            1 :           tree nc = OMP_CLAUSE_CHAIN (this_map);
   11222            2 :           gcc_assert (nc != NULL_TREE
   11223              :                       && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11224              :                       && (OMP_CLAUSE_MAP_KIND (nc)
   11225              :                           == GOMP_MAP_FIRSTPRIVATE_POINTER));
   11226            1 :           kind = OMP_CLAUSE_MAP_KIND (this_map);
   11227              :           /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
   11228              :              two-map sequence away from the chain.  */
   11229            1 :           *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
   11230              :         }
   11231           31 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11232           31 :       OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11233           31 :       OMP_CLAUSE_DECL (c)
   11234           31 :         = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
   11235           31 :       OMP_CLAUSE_SIZE (c)
   11236           31 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
   11237           31 :       new_clauses.safe_push (c);
   11238              : 
   11239              :       /* If we're in a lambda function, the this-pointer will actually be
   11240              :          '__closure->this', a mapped member of __closure, hence always_pointer.
   11241              :          Otherwise it's a firstprivate pointer.  */
   11242           31 :       enum gomp_map_kind ptr_kind
   11243           31 :         = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11244           31 :            ? GOMP_MAP_ALWAYS_POINTER
   11245           24 :            : GOMP_MAP_FIRSTPRIVATE_POINTER);
   11246           31 :       c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11247           31 :       OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11248           31 :       OMP_CLAUSE_DECL (c) = omp_target_this_expr;
   11249           31 :       OMP_CLAUSE_SIZE (c) = size_zero_node;
   11250           31 :       new_clauses.safe_push (c);
   11251              :     }
   11252              : 
   11253         6994 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11254              :     {
   11255            8 :       if (omp_target_this_expr)
   11256              :         {
   11257            7 :           STRIP_NOPS (omp_target_this_expr);
   11258            7 :           gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
   11259            7 :           omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
   11260              :         }
   11261              : 
   11262           17 :       for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
   11263           34 :            i != data.closure_vars_accessed.end (); ++i)
   11264              :         {
   11265            9 :           tree orig_decl = *i;
   11266            9 :           tree closure_expr = DECL_VALUE_EXPR (orig_decl);
   11267              : 
   11268            9 :           if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
   11269            9 :               || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
   11270              :             {
   11271              :               /* this-pointer is processed above, outside this loop.  */
   11272            3 :               if (omp_target_this_expr
   11273            3 :                   && operand_equal_p (closure_expr, omp_target_this_expr))
   11274            0 :                 continue;
   11275              : 
   11276            3 :               bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
   11277            3 :               enum gomp_map_kind kind, ptr_kind, nc_kind;
   11278            3 :               tree size;
   11279              : 
   11280            3 :               if (ptr_p)
   11281              :                 {
   11282              :                   /* For pointers, default mapped as zero-length array
   11283              :                      section.  */
   11284            2 :                   kind = GOMP_MAP_ALLOC;
   11285            2 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   11286            2 :                   ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   11287            2 :                   size = size_zero_node;
   11288              :                 }
   11289              :               else
   11290              :                 {
   11291              :                   /* For references, default mapped as appearing on map
   11292              :                      clause.  */
   11293            1 :                   kind = GOMP_MAP_TOFROM;
   11294            1 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
   11295            1 :                   ptr_kind = GOMP_MAP_ALWAYS_POINTER;
   11296            1 :                   size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
   11297              :                 }
   11298              : 
   11299            6 :               for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
   11300            3 :                 if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
   11301            1 :                     && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
   11302            1 :                         || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
   11303            3 :                     && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
   11304              :                                         orig_decl))
   11305              :                   {
   11306              :                     /* If this was already specified by user as a map,
   11307              :                        save the user specified map kind, delete the
   11308              :                        "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
   11309              :                        and insert our own sequence:
   11310              :                        "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
   11311              :                     */
   11312            0 :                     tree nc = OMP_CLAUSE_CHAIN (*p);
   11313            0 :                     gcc_assert (nc != NULL_TREE
   11314              :                                 && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11315              :                                 && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
   11316              :                     /* Update with user specified kind and size.  */
   11317            0 :                     kind = OMP_CLAUSE_MAP_KIND (*p);
   11318            0 :                     size = OMP_CLAUSE_SIZE (*p);
   11319            0 :                     *p = OMP_CLAUSE_CHAIN (nc);
   11320            0 :                     break;
   11321              :                   }
   11322              : 
   11323            3 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11324            3 :               OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11325            3 :               OMP_CLAUSE_DECL (c)
   11326            3 :                 = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
   11327            3 :               OMP_CLAUSE_SIZE (c) = size;
   11328            3 :               if (ptr_p)
   11329            2 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11330            3 :               new_clauses.safe_push (c);
   11331              : 
   11332            3 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11333            3 :               OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11334            3 :               OMP_CLAUSE_DECL (c) = closure_expr;
   11335            3 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11336            3 :               new_clauses.safe_push (c);
   11337              :             }
   11338              :         }
   11339              :     }
   11340              : 
   11341         6994 :   if (!data.ptr_members_accessed.is_empty ())
   11342           14 :     for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
   11343           56 :          i != data.ptr_members_accessed.end (); ++i)
   11344              :       {
   11345              :         /* For each referenced member that is of pointer or reference-to-pointer
   11346              :            type, create the equivalent of map(alloc:this->ptr[:0]).  */
   11347           14 :         tree field_decl = (*i).first;
   11348           14 :         tree ptr_member = (*i).second;
   11349              : 
   11350           26 :         for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
   11351              :           {
   11352           16 :             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   11353            2 :               continue;
   11354              :             /* If map(this->ptr[:N]) already exists, avoid creating another
   11355              :                such map.  */
   11356           14 :             tree decl = OMP_CLAUSE_DECL (c);
   11357           14 :             if ((TREE_CODE (decl) == INDIRECT_REF
   11358           10 :                  || TREE_CODE (decl) == MEM_REF)
   11359           14 :                 && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
   11360            4 :               goto next_ptr_member;
   11361              :           }
   11362              : 
   11363           10 :         if (!cxx_mark_addressable (ptr_member))
   11364            0 :           gcc_unreachable ();
   11365              : 
   11366           10 :         if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
   11367              :           {
   11368              :             /* For reference to pointers, we need to map the referenced
   11369              :                pointer first for things to be correct.  */
   11370            4 :             tree ptr_member_type = TREE_TYPE (ptr_member);
   11371              : 
   11372              :             /* Map pointer target as zero-length array section.  */
   11373            4 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11374            4 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11375            4 :             OMP_CLAUSE_DECL (c)
   11376            4 :               = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
   11377            4 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11378            4 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11379              : 
   11380              :             /* Map pointer to zero-length array section.  */
   11381            4 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11382            4 :             OMP_CLAUSE_SET_MAP_KIND
   11383              :               (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
   11384            4 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11385            4 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11386              : 
   11387              :             /* Attach reference-to-pointer field to pointer.  */
   11388            4 :             tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11389            4 :             OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
   11390            4 :             OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
   11391            4 :             OMP_CLAUSE_SIZE (c3) = size_zero_node;
   11392              : 
   11393            4 :             new_clauses.safe_push (c);
   11394            4 :             new_clauses.safe_push (c2);
   11395            4 :             new_clauses.safe_push (c3);
   11396              :           }
   11397            6 :         else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
   11398              :           {
   11399              :             /* Map pointer target as zero-length array section.  */
   11400            6 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11401            6 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11402            6 :             OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
   11403              :                                                       RO_UNARY_STAR);
   11404            6 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11405            6 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11406              : 
   11407              :             /* Attach zero-length array section to pointer.  */
   11408            6 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11409            6 :             OMP_CLAUSE_SET_MAP_KIND
   11410              :               (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11411            6 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11412            6 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11413              : 
   11414            6 :             new_clauses.safe_push (c);
   11415            6 :             new_clauses.safe_push (c2);
   11416              :           }
   11417              :         else
   11418            0 :           gcc_unreachable ();
   11419              : 
   11420           14 :       next_ptr_member:
   11421           14 :         ;
   11422              :       }
   11423              : 
   11424         7007 :   for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
   11425         7020 :        i != data.lambda_objects_accessed.end (); ++i)
   11426              :     {
   11427           13 :       tree lobj = *i;
   11428           13 :       if (TREE_CODE (lobj) == TARGET_EXPR)
   11429            0 :         lobj = TARGET_EXPR_SLOT (lobj);
   11430              : 
   11431           13 :       tree lt = TREE_TYPE (lobj);
   11432           26 :       gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
   11433              : 
   11434           13 :       tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11435           13 :       OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
   11436           13 :       OMP_CLAUSE_DECL (lc) = lobj;
   11437           13 :       OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
   11438           13 :       new_clauses.safe_push (lc);
   11439              : 
   11440          180 :       for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
   11441              :         {
   11442          167 :           if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
   11443              :             {
   11444            4 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11445              :                                  lobj, fld, NULL_TREE);
   11446            4 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11447            4 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11448            4 :               OMP_CLAUSE_DECL (c)
   11449            4 :                 = build_indirect_ref (loc, exp, RO_UNARY_STAR);
   11450            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11451            4 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11452            4 :               new_clauses.safe_push (c);
   11453              : 
   11454            4 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11455            4 :               OMP_CLAUSE_SET_MAP_KIND
   11456              :                 (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11457            4 :               OMP_CLAUSE_DECL (c) = exp;
   11458            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11459            4 :               new_clauses.safe_push (c);
   11460              :             }
   11461          163 :           else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
   11462              :             {
   11463            0 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11464              :                                  lobj, fld, NULL_TREE);
   11465            0 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11466            0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   11467            0 :               OMP_CLAUSE_DECL (c)
   11468            0 :                 = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
   11469            0 :               OMP_CLAUSE_SIZE (c)
   11470            0 :                 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
   11471            0 :               new_clauses.safe_push (c);
   11472              : 
   11473            0 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11474            0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   11475            0 :               OMP_CLAUSE_DECL (c) = exp;
   11476            0 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11477            0 :               new_clauses.safe_push (c);
   11478              :             }
   11479              :         }
   11480              :     }
   11481              : 
   11482         6994 :   tree c = *clauses_ptr;
   11483        14210 :   for (int i = new_clauses.length () - 1; i >= 0; i--)
   11484              :     {
   11485          222 :       OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
   11486          222 :       c = new_clauses[i];
   11487              :     }
   11488         6994 :   *clauses_ptr = c;
   11489         6994 : }
   11490              : 
   11491              : /* Called from cp_parser_omp_target.  Create additional implicit clauses for
   11492              :    OpenMP target directives, and do sanity checks.  */
   11493              : 
   11494              : tree
   11495         6982 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
   11496              : {
   11497         6982 :   if (!processing_template_decl)
   11498         6169 :     finish_omp_target_clauses (loc, body, &clauses);
   11499              : 
   11500         6982 :   tree stmt = make_node (OMP_TARGET);
   11501         6982 :   TREE_TYPE (stmt) = void_type_node;
   11502         6982 :   OMP_TARGET_CLAUSES (stmt) = clauses;
   11503         6982 :   OMP_TARGET_BODY (stmt) = body;
   11504         6982 :   OMP_TARGET_COMBINED (stmt) = combined_p;
   11505         6982 :   SET_EXPR_LOCATION (stmt, loc);
   11506              : 
   11507         6982 :   tree c = clauses;
   11508        16666 :   while (c)
   11509              :     {
   11510         9684 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   11511         5610 :         switch (OMP_CLAUSE_MAP_KIND (c))
   11512              :           {
   11513              :           case GOMP_MAP_TO:
   11514              :           case GOMP_MAP_ALWAYS_TO:
   11515              :           case GOMP_MAP_PRESENT_TO:
   11516              :           case GOMP_MAP_ALWAYS_PRESENT_TO:
   11517              :           case GOMP_MAP_FROM:
   11518              :           case GOMP_MAP_ALWAYS_FROM:
   11519              :           case GOMP_MAP_PRESENT_FROM:
   11520              :           case GOMP_MAP_ALWAYS_PRESENT_FROM:
   11521              :           case GOMP_MAP_TOFROM:
   11522              :           case GOMP_MAP_ALWAYS_TOFROM:
   11523              :           case GOMP_MAP_PRESENT_TOFROM:
   11524              :           case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   11525              :           case GOMP_MAP_ALLOC:
   11526              :           case GOMP_MAP_PRESENT_ALLOC:
   11527              :           case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11528              :           case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11529              :           case GOMP_MAP_ALWAYS_POINTER:
   11530              :           case GOMP_MAP_ATTACH_DETACH:
   11531              :           case GOMP_MAP_ATTACH:
   11532              :           case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   11533              :           case GOMP_MAP_POINTER:
   11534              :           case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   11535              :             break;
   11536            3 :           default:
   11537            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   11538              :                       "%<#pragma omp target%> with map-type other "
   11539              :                       "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
   11540              :                       "on %<map%> clause");
   11541            3 :             break;
   11542              :           }
   11543         9684 :       c = OMP_CLAUSE_CHAIN (c);
   11544              :     }
   11545         6982 :   return add_stmt (stmt);
   11546              : }
   11547              : 
   11548              : tree
   11549         9321 : finish_omp_parallel (tree clauses, tree body)
   11550              : {
   11551         9321 :   tree stmt;
   11552              : 
   11553         9321 :   body = finish_omp_structured_block (body);
   11554              : 
   11555         9321 :   stmt = make_node (OMP_PARALLEL);
   11556         9321 :   TREE_TYPE (stmt) = void_type_node;
   11557         9321 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   11558         9321 :   OMP_PARALLEL_BODY (stmt) = body;
   11559              : 
   11560         9321 :   return add_stmt (stmt);
   11561              : }
   11562              : 
   11563              : tree
   11564         2161 : begin_omp_task (void)
   11565              : {
   11566         2161 :   keep_next_level (true);
   11567         2161 :   return begin_omp_structured_block ();
   11568              : }
   11569              : 
   11570              : tree
   11571         2161 : finish_omp_task (tree clauses, tree body)
   11572              : {
   11573         2161 :   tree stmt;
   11574              : 
   11575         2161 :   body = finish_omp_structured_block (body);
   11576              : 
   11577         2161 :   stmt = make_node (OMP_TASK);
   11578         2161 :   TREE_TYPE (stmt) = void_type_node;
   11579         2161 :   OMP_TASK_CLAUSES (stmt) = clauses;
   11580         2161 :   OMP_TASK_BODY (stmt) = body;
   11581              : 
   11582         2161 :   return add_stmt (stmt);
   11583              : }
   11584              : 
   11585              : /* Helper function for finish_omp_for.  Convert Ith random access iterator
   11586              :    into integral iterator.  Return FALSE if successful.  */
   11587              : 
   11588              : static bool
   11589          813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
   11590              :                                tree declv, tree orig_declv, tree initv,
   11591              :                                tree condv, tree incrv, tree *body,
   11592              :                                tree *pre_body, tree &clauses,
   11593              :                                int collapse, int ordered)
   11594              : {
   11595          813 :   tree diff, iter_init, iter_incr = NULL, last;
   11596          813 :   tree incr_var = NULL, orig_pre_body, orig_body, c;
   11597          813 :   tree decl = TREE_VEC_ELT (declv, i);
   11598          813 :   tree init = TREE_VEC_ELT (initv, i);
   11599          813 :   tree cond = TREE_VEC_ELT (condv, i);
   11600          813 :   tree incr = TREE_VEC_ELT (incrv, i);
   11601          813 :   tree iter = decl;
   11602          813 :   location_t elocus = locus;
   11603              : 
   11604          813 :   if (init && EXPR_HAS_LOCATION (init))
   11605           12 :     elocus = EXPR_LOCATION (init);
   11606              : 
   11607          813 :   switch (TREE_CODE (cond))
   11608              :     {
   11609          810 :     case GT_EXPR:
   11610          810 :     case GE_EXPR:
   11611          810 :     case LT_EXPR:
   11612          810 :     case LE_EXPR:
   11613          810 :     case NE_EXPR:
   11614          810 :       if (TREE_OPERAND (cond, 1) == iter)
   11615           42 :         cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
   11616           42 :                        TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
   11617          810 :       if (TREE_OPERAND (cond, 0) != iter)
   11618            0 :         cond = error_mark_node;
   11619              :       else
   11620              :         {
   11621          810 :           tree tem = build_x_binary_op (EXPR_LOCATION (cond),
   11622          810 :                                         TREE_CODE (cond),
   11623              :                                         iter, ERROR_MARK,
   11624          810 :                                         TREE_OPERAND (cond, 1), ERROR_MARK,
   11625              :                                         NULL_TREE, NULL, tf_warning_or_error);
   11626          810 :           if (error_operand_p (tem))
   11627              :             return true;
   11628              :         }
   11629              :       break;
   11630            3 :     default:
   11631            3 :       cond = error_mark_node;
   11632            3 :       break;
   11633              :     }
   11634          810 :   if (cond == error_mark_node)
   11635              :     {
   11636            3 :       error_at (elocus, "invalid controlling predicate");
   11637            3 :       return true;
   11638              :     }
   11639          807 :   diff = build_x_binary_op (elocus, MINUS_EXPR,
   11640          807 :                             TREE_OPERAND (cond, 1), ERROR_MARK,
   11641              :                             iter, ERROR_MARK,
   11642              :                             NULL_TREE, NULL, tf_warning_or_error);
   11643          807 :   diff = cp_fully_fold (diff);
   11644          807 :   if (error_operand_p (diff))
   11645              :     return true;
   11646          807 :   if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
   11647              :     {
   11648            0 :       error_at (elocus, "difference between %qE and %qD does not have integer type",
   11649            0 :                 TREE_OPERAND (cond, 1), iter);
   11650            0 :       return true;
   11651              :     }
   11652          807 :   if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
   11653          807 :                                   TREE_VEC_ELT (declv, i), NULL_TREE,
   11654              :                                   cond, cp_walk_subtrees))
   11655              :     return true;
   11656              : 
   11657          762 :   switch (TREE_CODE (incr))
   11658              :     {
   11659          370 :     case PREINCREMENT_EXPR:
   11660          370 :     case PREDECREMENT_EXPR:
   11661          370 :     case POSTINCREMENT_EXPR:
   11662          370 :     case POSTDECREMENT_EXPR:
   11663          370 :       if (TREE_OPERAND (incr, 0) != iter)
   11664              :         {
   11665            0 :           incr = error_mark_node;
   11666            0 :           break;
   11667              :         }
   11668          370 :       iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
   11669          370 :                                     TREE_CODE (incr), iter,
   11670              :                                     NULL_TREE, tf_warning_or_error);
   11671          370 :       if (error_operand_p (iter_incr))
   11672              :         return true;
   11673          370 :       else if (TREE_CODE (incr) == PREINCREMENT_EXPR
   11674          219 :                || TREE_CODE (incr) == POSTINCREMENT_EXPR)
   11675          299 :         incr = integer_one_node;
   11676              :       else
   11677           71 :         incr = integer_minus_one_node;
   11678              :       break;
   11679          392 :     case MODIFY_EXPR:
   11680          392 :       if (TREE_OPERAND (incr, 0) != iter)
   11681            0 :         incr = error_mark_node;
   11682          392 :       else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
   11683          392 :                || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
   11684              :         {
   11685          392 :           tree rhs = TREE_OPERAND (incr, 1);
   11686          392 :           if (TREE_OPERAND (rhs, 0) == iter)
   11687              :             {
   11688          299 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
   11689              :                   != INTEGER_TYPE)
   11690            0 :                 incr = error_mark_node;
   11691              :               else
   11692              :                 {
   11693          299 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11694          299 :                                                    iter, TREE_CODE (rhs),
   11695          299 :                                                    TREE_OPERAND (rhs, 1),
   11696              :                                                    NULL_TREE,
   11697              :                                                    tf_warning_or_error);
   11698          299 :                   if (error_operand_p (iter_incr))
   11699              :                     return true;
   11700          299 :                   incr = TREE_OPERAND (rhs, 1);
   11701          299 :                   incr = cp_convert (TREE_TYPE (diff), incr,
   11702              :                                      tf_warning_or_error);
   11703          299 :                   if (TREE_CODE (rhs) == MINUS_EXPR)
   11704              :                     {
   11705           16 :                       incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
   11706           16 :                       incr = fold_simple (incr);
   11707              :                     }
   11708          299 :                   if (TREE_CODE (incr) != INTEGER_CST
   11709          299 :                       && (TREE_CODE (incr) != NOP_EXPR
   11710           66 :                           || (TREE_CODE (TREE_OPERAND (incr, 0))
   11711              :                               != INTEGER_CST)))
   11712              :                     iter_incr = NULL;
   11713              :                 }
   11714              :             }
   11715           93 :           else if (TREE_OPERAND (rhs, 1) == iter)
   11716              :             {
   11717           93 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
   11718           93 :                   || TREE_CODE (rhs) != PLUS_EXPR)
   11719            0 :                 incr = error_mark_node;
   11720              :               else
   11721              :                 {
   11722           93 :                   iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
   11723              :                                                  PLUS_EXPR,
   11724           93 :                                                  TREE_OPERAND (rhs, 0),
   11725              :                                                  ERROR_MARK, iter,
   11726              :                                                  ERROR_MARK, NULL_TREE, NULL,
   11727              :                                                  tf_warning_or_error);
   11728           93 :                   if (error_operand_p (iter_incr))
   11729              :                     return true;
   11730           93 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11731              :                                                    iter, NOP_EXPR,
   11732              :                                                    iter_incr, NULL_TREE,
   11733              :                                                    tf_warning_or_error);
   11734           93 :                   if (error_operand_p (iter_incr))
   11735              :                     return true;
   11736           93 :                   incr = TREE_OPERAND (rhs, 0);
   11737           93 :                   iter_incr = NULL;
   11738              :                 }
   11739              :             }
   11740              :           else
   11741            0 :             incr = error_mark_node;
   11742              :         }
   11743              :       else
   11744            0 :         incr = error_mark_node;
   11745              :       break;
   11746            0 :     default:
   11747            0 :       incr = error_mark_node;
   11748            0 :       break;
   11749              :     }
   11750              : 
   11751          762 :   if (incr == error_mark_node)
   11752              :     {
   11753            0 :       error_at (elocus, "invalid increment expression");
   11754            0 :       return true;
   11755              :     }
   11756              : 
   11757          762 :   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
   11758          762 :   incr = cp_fully_fold (incr);
   11759          762 :   tree loop_iv_seen = NULL_TREE;
   11760         1735 :   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
   11761         1093 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   11762         1093 :         && OMP_CLAUSE_DECL (c) == iter)
   11763              :       {
   11764          120 :         if (code == OMP_TASKLOOP || code == OMP_LOOP)
   11765              :           {
   11766           60 :             loop_iv_seen = c;
   11767           60 :             OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
   11768              :           }
   11769              :         break;
   11770              :       }
   11771          973 :     else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
   11772          113 :              && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   11773         1007 :              && OMP_CLAUSE_DECL (c) == iter)
   11774              :       {
   11775           30 :         loop_iv_seen = c;
   11776           30 :         if (code == OMP_TASKLOOP)
   11777           25 :           OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
   11778              :       }
   11779              : 
   11780          762 :   decl = create_temporary_var (TREE_TYPE (diff));
   11781          762 :   pushdecl (decl);
   11782          762 :   add_decl_expr (decl);
   11783          762 :   last = create_temporary_var (TREE_TYPE (diff));
   11784          762 :   pushdecl (last);
   11785          762 :   add_decl_expr (last);
   11786          762 :   if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
   11787           10 :       && (!ordered || (i < collapse && collapse > 1)))
   11788              :     {
   11789           10 :       incr_var = create_temporary_var (TREE_TYPE (diff));
   11790           10 :       pushdecl (incr_var);
   11791           10 :       add_decl_expr (incr_var);
   11792              :     }
   11793          762 :   gcc_assert (stmts_are_full_exprs_p ());
   11794          762 :   tree diffvar = NULL_TREE;
   11795          762 :   if (code == OMP_TASKLOOP)
   11796              :     {
   11797          101 :       if (!loop_iv_seen)
   11798              :         {
   11799           38 :           tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11800           38 :           OMP_CLAUSE_DECL (ivc) = iter;
   11801           38 :           cxx_omp_finish_clause (ivc, NULL, false);
   11802           38 :           OMP_CLAUSE_CHAIN (ivc) = clauses;
   11803           38 :           clauses = ivc;
   11804              :         }
   11805          101 :       tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11806          101 :       OMP_CLAUSE_DECL (lvc) = last;
   11807          101 :       OMP_CLAUSE_CHAIN (lvc) = clauses;
   11808          101 :       clauses = lvc;
   11809          101 :       diffvar = create_temporary_var (TREE_TYPE (diff));
   11810          101 :       pushdecl (diffvar);
   11811          101 :       add_decl_expr (diffvar);
   11812              :     }
   11813          661 :   else if (code == OMP_LOOP)
   11814              :     {
   11815           43 :       if (!loop_iv_seen)
   11816              :         {
   11817              :           /* While iterators on the loop construct are predetermined
   11818              :              lastprivate, if the decl is not declared inside of the
   11819              :              loop, OMP_CLAUSE_LASTPRIVATE should have been added
   11820              :              already.  */
   11821           16 :           loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11822           16 :           OMP_CLAUSE_DECL (loop_iv_seen) = iter;
   11823           16 :           OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
   11824           16 :           clauses = loop_iv_seen;
   11825              :         }
   11826           27 :       else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
   11827              :         {
   11828            5 :           OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
   11829            5 :           OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
   11830            5 :           OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
   11831              :         }
   11832           43 :       if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
   11833           21 :         cxx_omp_finish_clause (loop_iv_seen, NULL, false);
   11834              :     }
   11835              : 
   11836          762 :   orig_pre_body = *pre_body;
   11837          762 :   *pre_body = push_stmt_list ();
   11838          762 :   if (orig_pre_body)
   11839          610 :     add_stmt (orig_pre_body);
   11840          762 :   if (init != NULL)
   11841           61 :     finish_expr_stmt (build_x_modify_expr (elocus,
   11842              :                                            iter, NOP_EXPR, init,
   11843              :                                            NULL_TREE, tf_warning_or_error));
   11844          762 :   init = build_int_cst (TREE_TYPE (diff), 0);
   11845          762 :   if (c && iter_incr == NULL
   11846           28 :       && (!ordered || (i < collapse && collapse > 1)))
   11847              :     {
   11848           28 :       if (incr_var)
   11849              :         {
   11850           10 :           finish_expr_stmt (build_x_modify_expr (elocus,
   11851              :                                                  incr_var, NOP_EXPR,
   11852              :                                                  incr, NULL_TREE,
   11853              :                                                  tf_warning_or_error));
   11854           10 :           incr = incr_var;
   11855              :         }
   11856           28 :       iter_incr = build_x_modify_expr (elocus,
   11857              :                                        iter, PLUS_EXPR, incr,
   11858              :                                        NULL_TREE, tf_warning_or_error);
   11859              :     }
   11860          762 :   if (c && ordered && i < collapse && collapse > 1)
   11861          762 :     iter_incr = incr;
   11862          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11863              :                                          last, NOP_EXPR, init,
   11864              :                                          NULL_TREE, tf_warning_or_error));
   11865          762 :   if (diffvar)
   11866              :     {
   11867          101 :       finish_expr_stmt (build_x_modify_expr (elocus,
   11868              :                                              diffvar, NOP_EXPR,
   11869              :                                              diff, NULL_TREE, tf_warning_or_error));
   11870          101 :       diff = diffvar;
   11871              :     }
   11872          762 :   *pre_body = pop_stmt_list (*pre_body);
   11873              : 
   11874         1524 :   cond = cp_build_binary_op (elocus,
   11875          762 :                              TREE_CODE (cond), decl, diff,
   11876              :                              tf_warning_or_error);
   11877          762 :   incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
   11878              :                             elocus, incr, NULL_TREE);
   11879              : 
   11880          762 :   orig_body = *body;
   11881          762 :   *body = push_stmt_list ();
   11882          762 :   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
   11883          762 :   iter_init = build_x_modify_expr (elocus,
   11884              :                                    iter, PLUS_EXPR, iter_init,
   11885              :                                    NULL_TREE, tf_warning_or_error);
   11886          762 :   if (iter_init != error_mark_node)
   11887          759 :     iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11888          762 :   finish_expr_stmt (iter_init);
   11889          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11890              :                                          last, NOP_EXPR, decl,
   11891              :                                          NULL_TREE, tf_warning_or_error));
   11892          762 :   add_stmt (orig_body);
   11893          762 :   *body = pop_stmt_list (*body);
   11894              : 
   11895          762 :   if (c)
   11896              :     {
   11897          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
   11898          120 :       if (!ordered)
   11899          114 :         finish_expr_stmt (iter_incr);
   11900              :       else
   11901              :         {
   11902            6 :           iter_init = decl;
   11903            6 :           if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
   11904            2 :             iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
   11905              :                                 iter_init, iter_incr);
   11906            6 :           iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
   11907            6 :           iter_init = build_x_modify_expr (elocus,
   11908              :                                            iter, PLUS_EXPR, iter_init,
   11909              :                                            NULL_TREE, tf_warning_or_error);
   11910            6 :           if (iter_init != error_mark_node)
   11911            6 :             iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11912            6 :           finish_expr_stmt (iter_init);
   11913              :         }
   11914          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c)
   11915          240 :         = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
   11916              :     }
   11917              : 
   11918          762 :   if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
   11919              :     {
   11920          116 :       tree t = TREE_VEC_ELT (orig_declv, i);
   11921          116 :       gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   11922              :                   && TREE_VALUE (t) == NULL_TREE
   11923              :                   && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
   11924          116 :       TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
   11925          116 :       TREE_VALUE (t) = last;
   11926              :     }
   11927              :   else
   11928          646 :     TREE_VEC_ELT (orig_declv, i)
   11929         1292 :       = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   11930          762 :   TREE_VEC_ELT (declv, i) = decl;
   11931          762 :   TREE_VEC_ELT (initv, i) = init;
   11932          762 :   TREE_VEC_ELT (condv, i) = cond;
   11933          762 :   TREE_VEC_ELT (incrv, i) = incr;
   11934              : 
   11935          762 :   return false;
   11936              : }
   11937              : 
   11938              : /* Build and validate an OMP_FOR statement.  CLAUSES, BODY, COND, INCR
   11939              :    are directly for their associated operands in the statement.  DECL
   11940              :    and INIT are a combo; if DECL is NULL then INIT ought to be a
   11941              :    MODIFY_EXPR, and the DECL should be extracted.  PRE_BODY are
   11942              :    optional statements that need to go before the loop into its
   11943              :    sk_omp scope.  */
   11944              : 
   11945              : tree
   11946        21128 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
   11947              :                 tree orig_declv, tree initv, tree condv, tree incrv,
   11948              :                 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
   11949              : {
   11950        21128 :   tree omp_for = NULL, orig_incr = NULL;
   11951        21128 :   tree decl = NULL, init, cond, incr;
   11952        21128 :   location_t elocus;
   11953        21128 :   int i;
   11954        21128 :   int collapse = 1;
   11955        21128 :   int ordered = 0;
   11956        21128 :   auto_vec<location_t> init_locv;
   11957              : 
   11958        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
   11959        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
   11960        21128 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
   11961        21128 :   if (TREE_VEC_LENGTH (declv) > 1)
   11962              :     {
   11963         4054 :       if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
   11964           83 :         collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
   11965              :       else
   11966              :         {
   11967         3971 :           if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
   11968         3501 :             collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
   11969          470 :           else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
   11970          394 :             collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
   11971         3971 :           if (collapse != TREE_VEC_LENGTH (declv))
   11972          100 :             ordered = TREE_VEC_LENGTH (declv);
   11973              :         }
   11974              :     }
   11975        48601 :   for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   11976              :     {
   11977        27509 :       decl = TREE_VEC_ELT (declv, i);
   11978        27509 :       init = TREE_VEC_ELT (initv, i);
   11979        27509 :       cond = TREE_VEC_ELT (condv, i);
   11980        27509 :       incr = TREE_VEC_ELT (incrv, i);
   11981        27509 :       elocus = locus;
   11982              : 
   11983        27509 :       if (decl == global_namespace)
   11984              :         {
   11985         1101 :           gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
   11986         1101 :           TREE_VEC_ELT (declv, i) = NULL_TREE;
   11987         1101 :           init_locv.safe_push (UNKNOWN_LOCATION);
   11988         1101 :           continue;
   11989              :         }
   11990              :       /* We are going to throw out the init's original MODIFY_EXPR or
   11991              :          MODOP_EXPR below.  Save its location so we can use it when
   11992              :          reconstructing the expression farther down.  Alternatively, if the
   11993              :          initializer is a binding of the iteration variable, save
   11994              :          that location.  Any of these locations in the initialization clause
   11995              :          for the current nested loop are better than using the argument locus,
   11996              :          that points to the "for" of the outermost loop in the nest.  */
   11997        26408 :       if (init && EXPR_HAS_LOCATION (init))
   11998        17872 :         elocus = EXPR_LOCATION (init);
   11999         8536 :       else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
   12000              :         /* This can happen for class iterators.  */
   12001            0 :         elocus = EXPR_LOCATION (decl);
   12002         8536 :       else if (decl && DECL_P (decl))
   12003              :         {
   12004         8509 :           if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
   12005         8509 :             elocus = DECL_SOURCE_LOCATION (decl);
   12006            0 :           else if (DECL_INITIAL (decl)
   12007            0 :                    && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
   12008            0 :             elocus = EXPR_LOCATION (DECL_INITIAL (decl));
   12009              :         }
   12010        26408 :       init_locv.safe_push (elocus);
   12011              : 
   12012        26408 :       if (decl == NULL)
   12013              :         {
   12014        16564 :           if (init != NULL)
   12015        16561 :             switch (TREE_CODE (init))
   12016              :               {
   12017        16176 :               case MODIFY_EXPR:
   12018        16176 :                 decl = TREE_OPERAND (init, 0);
   12019        16176 :                 init = TREE_OPERAND (init, 1);
   12020        16176 :                 break;
   12021          367 :               case MODOP_EXPR:
   12022          367 :                 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
   12023              :                   {
   12024          367 :                     decl = TREE_OPERAND (init, 0);
   12025          367 :                     init = TREE_OPERAND (init, 2);
   12026              :                   }
   12027              :                 break;
   12028              :               default:
   12029              :                 break;
   12030              :               }
   12031              : 
   12032        16564 :           if (decl == NULL)
   12033              :             {
   12034           21 :               error_at (locus,
   12035              :                         "expected iteration declaration or initialization");
   12036           21 :               return NULL;
   12037              :             }
   12038              :         }
   12039              : 
   12040        26387 :       if (cond == global_namespace)
   12041          170 :         continue;
   12042              : 
   12043        26217 :       if (cond == NULL)
   12044              :         {
   12045            9 :           error_at (elocus, "missing controlling predicate");
   12046            9 :           return NULL;
   12047              :         }
   12048              : 
   12049        26208 :       if (incr == NULL)
   12050              :         {
   12051            6 :           error_at (elocus, "missing increment expression");
   12052            6 :           return NULL;
   12053              :         }
   12054              : 
   12055        26202 :       TREE_VEC_ELT (declv, i) = decl;
   12056        26202 :       TREE_VEC_ELT (initv, i) = init;
   12057              :     }
   12058              : 
   12059        21092 :   if (orig_inits)
   12060              :     {
   12061              :       bool fail = false;
   12062              :       tree orig_init;
   12063        21214 :       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
   12064         1181 :         if (orig_init
   12065         3396 :             && !c_omp_check_loop_iv_exprs (locus, code,
   12066              :                                            orig_declv ? orig_declv : declv, i,
   12067         1164 :                                            TREE_VEC_ELT (declv, i), orig_init,
   12068              :                                            NULL_TREE, cp_walk_subtrees))
   12069              :           fail = true;
   12070        20033 :       if (fail)
   12071          887 :         return NULL;
   12072              :     }
   12073              : 
   12074        21035 :   if (dependent_omp_for_p (declv, initv, condv, incrv, body))
   12075              :     {
   12076          453 :       tree stmt;
   12077              : 
   12078          453 :       stmt = make_node (code);
   12079              : 
   12080         1499 :       for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   12081              :         {
   12082          593 :           if (TREE_VEC_ELT (declv, i) == NULL_TREE)
   12083            9 :             continue;
   12084              :           /* This is really just a place-holder.  We'll be decomposing this
   12085              :              again and going through the cp_build_modify_expr path below when
   12086              :              we instantiate the thing.  */
   12087          584 :           TREE_VEC_ELT (initv, i)
   12088         1168 :             = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
   12089          584 :                           TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
   12090              :         }
   12091              : 
   12092          453 :       TREE_TYPE (stmt) = void_type_node;
   12093          453 :       OMP_FOR_INIT (stmt) = initv;
   12094          453 :       OMP_FOR_COND (stmt) = condv;
   12095          453 :       OMP_FOR_INCR (stmt) = incrv;
   12096          453 :       OMP_FOR_BODY (stmt) = body;
   12097          453 :       OMP_FOR_PRE_BODY (stmt) = pre_body;
   12098          453 :       OMP_FOR_CLAUSES (stmt) = clauses;
   12099              : 
   12100          453 :       SET_EXPR_LOCATION (stmt, locus);
   12101          453 :       return add_stmt (stmt);
   12102              :     }
   12103              : 
   12104        20582 :   if (!orig_declv)
   12105        19795 :     orig_declv = copy_node (declv);
   12106              : 
   12107        20582 :   if (processing_template_decl)
   12108          612 :     orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
   12109              : 
   12110        48030 :   for (i = 0; i < TREE_VEC_LENGTH (declv); )
   12111              :     {
   12112        27540 :       decl = TREE_VEC_ELT (declv, i);
   12113        27540 :       init = TREE_VEC_ELT (initv, i);
   12114        27540 :       cond = TREE_VEC_ELT (condv, i);
   12115        27540 :       incr = TREE_VEC_ELT (incrv, i);
   12116        27540 :       if (orig_incr)
   12117          844 :         TREE_VEC_ELT (orig_incr, i) = incr;
   12118        27540 :       elocus = init_locv[i];
   12119              : 
   12120        27540 :       if (decl == NULL_TREE)
   12121              :         {
   12122         1092 :           i++;
   12123         1092 :           continue;
   12124              :         }
   12125              : 
   12126        26448 :       if (!DECL_P (decl))
   12127              :         {
   12128            6 :           error_at (elocus, "expected iteration declaration or initialization");
   12129            6 :           return NULL;
   12130              :         }
   12131              : 
   12132        26442 :       if (incr && TREE_CODE (incr) == MODOP_EXPR)
   12133              :         {
   12134            1 :           if (orig_incr)
   12135            1 :             TREE_VEC_ELT (orig_incr, i) = incr;
   12136            1 :           incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
   12137            1 :                                        TREE_CODE (TREE_OPERAND (incr, 1)),
   12138            1 :                                        TREE_OPERAND (incr, 2),
   12139              :                                        tf_warning_or_error);
   12140              :         }
   12141              : 
   12142        26442 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
   12143              :         {
   12144          825 :           if (code == OMP_SIMD)
   12145              :             {
   12146           12 :               error_at (elocus, "%<#pragma omp simd%> used with class "
   12147              :                                 "iteration variable %qE", decl);
   12148           12 :               return NULL;
   12149              :             }
   12150          813 :           if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
   12151              :                                              initv, condv, incrv, &body,
   12152              :                                              &pre_body, clauses,
   12153              :                                              collapse, ordered))
   12154              :             return NULL;
   12155          762 :           continue;
   12156              :         }
   12157              : 
   12158        51234 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
   12159        27203 :           && !TYPE_PTR_P (TREE_TYPE (decl)))
   12160              :         {
   12161           14 :           error_at (elocus, "invalid type for iteration variable %qE", decl);
   12162           14 :           return NULL;
   12163              :         }
   12164              : 
   12165        25603 :       if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
   12166        24842 :         init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
   12167              :                                      tf_warning_or_error);
   12168              :       else
   12169          761 :         init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
   12170        25603 :       if (decl == error_mark_node || init == error_mark_node)
   12171              :         return NULL;
   12172              : 
   12173        25594 :       TREE_VEC_ELT (declv, i) = decl;
   12174        25594 :       TREE_VEC_ELT (initv, i) = init;
   12175        25594 :       TREE_VEC_ELT (condv, i) = cond;
   12176        25594 :       TREE_VEC_ELT (incrv, i) = incr;
   12177        25594 :       i++;
   12178              :     }
   12179              : 
   12180        20490 :   if (pre_body && IS_EMPTY_STMT (pre_body))
   12181            0 :     pre_body = NULL;
   12182              : 
   12183        40980 :   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
   12184              :                               incrv, body, pre_body,
   12185        20490 :                               !processing_template_decl);
   12186              : 
   12187              :   /* Check for iterators appearing in lb, b or incr expressions.  */
   12188        20490 :   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
   12189              :     omp_for = NULL_TREE;
   12190              : 
   12191        20004 :   if (omp_for == NULL)
   12192          702 :     return NULL;
   12193              : 
   12194        19788 :   add_stmt (omp_for);
   12195              : 
   12196        45448 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
   12197              :     {
   12198        25660 :       init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
   12199        25660 :       if (init == NULL_TREE)
   12200         1032 :         continue;
   12201        24628 :       decl = TREE_OPERAND (init, 0);
   12202        24628 :       cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
   12203        24628 :       incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
   12204              : 
   12205        24628 :       if (!processing_template_decl)
   12206              :         {
   12207        24107 :           if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
   12208              :             {
   12209          106 :               tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
   12210          106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
   12211          106 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12212          106 :               t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
   12213          106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
   12214          212 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12215              :             }
   12216              :           else
   12217              :             {
   12218        24001 :               tree t = TREE_OPERAND (init, 1);
   12219        24001 :               TREE_OPERAND (init, 1)
   12220        48002 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12221              :             }
   12222        24107 :           if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
   12223              :             {
   12224          121 :               tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
   12225          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
   12226          121 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12227          121 :               t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
   12228          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
   12229          242 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12230              :             }
   12231              :           else
   12232              :             {
   12233        23986 :               tree t = TREE_OPERAND (cond, 1);
   12234        23986 :               TREE_OPERAND (cond, 1)
   12235        47972 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12236              :             }
   12237              :         }
   12238              : 
   12239        24628 :       if (TREE_CODE (incr) != MODIFY_EXPR)
   12240        18426 :         continue;
   12241              : 
   12242         6202 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
   12243           70 :           && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
   12244         6272 :           && !processing_template_decl)
   12245              :         {
   12246           64 :           tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
   12247           64 :           if (TREE_SIDE_EFFECTS (t)
   12248            8 :               && t != decl
   12249           70 :               && (TREE_CODE (t) != NOP_EXPR
   12250            0 :                   || TREE_OPERAND (t, 0) != decl))
   12251            6 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
   12252           12 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12253              : 
   12254           64 :           t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
   12255           64 :           if (TREE_SIDE_EFFECTS (t)
   12256           56 :               && t != decl
   12257          120 :               && (TREE_CODE (t) != NOP_EXPR
   12258            5 :                   || TREE_OPERAND (t, 0) != decl))
   12259           56 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
   12260          112 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12261              :         }
   12262              : 
   12263         6202 :       if (orig_incr)
   12264          177 :         TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
   12265              :     }
   12266        19788 :   OMP_FOR_CLAUSES (omp_for) = clauses;
   12267              : 
   12268              :   /* For simd loops with non-static data member iterators, we could have added
   12269              :      OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP.  As we know the
   12270              :      step at this point, fill it in.  */
   12271         4735 :   if (code == OMP_SIMD && !processing_template_decl
   12272        24479 :       && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
   12273         4619 :     for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
   12274          561 :          c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
   12275          561 :       if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
   12276              :         {
   12277            4 :           decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
   12278            4 :           gcc_assert (decl == OMP_CLAUSE_DECL (c));
   12279            4 :           incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
   12280            4 :           tree step, stept;
   12281            4 :           switch (TREE_CODE (incr))
   12282              :             {
   12283            0 :             case PREINCREMENT_EXPR:
   12284            0 :             case POSTINCREMENT_EXPR:
   12285              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12286              :                  called to massage things appropriately.  */
   12287            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12288            0 :               OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
   12289            0 :               break;
   12290            0 :             case PREDECREMENT_EXPR:
   12291            0 :             case POSTDECREMENT_EXPR:
   12292              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12293              :                  called to massage things appropriately.  */
   12294            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12295            0 :               OMP_CLAUSE_LINEAR_STEP (c)
   12296            0 :                 = build_int_cst (TREE_TYPE (decl), -1);
   12297            0 :               break;
   12298            4 :             case MODIFY_EXPR:
   12299            4 :               gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12300            4 :               incr = TREE_OPERAND (incr, 1);
   12301            4 :               switch (TREE_CODE (incr))
   12302              :                 {
   12303            4 :                 case PLUS_EXPR:
   12304            4 :                   if (TREE_OPERAND (incr, 1) == decl)
   12305            0 :                     step = TREE_OPERAND (incr, 0);
   12306              :                   else
   12307            4 :                     step = TREE_OPERAND (incr, 1);
   12308              :                   break;
   12309            0 :                 case MINUS_EXPR:
   12310            0 :                 case POINTER_PLUS_EXPR:
   12311            0 :                   gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12312            0 :                   step = TREE_OPERAND (incr, 1);
   12313            0 :                   break;
   12314            0 :                 default:
   12315            0 :                   gcc_unreachable ();
   12316              :                 }
   12317            4 :               stept = TREE_TYPE (decl);
   12318            4 :               if (INDIRECT_TYPE_P (stept))
   12319            0 :                 stept = sizetype;
   12320            4 :               step = fold_convert (stept, step);
   12321            4 :               if (TREE_CODE (incr) == MINUS_EXPR)
   12322            0 :                 step = fold_build1 (NEGATE_EXPR, stept, step);
   12323            4 :               OMP_CLAUSE_LINEAR_STEP (c) = step;
   12324            4 :               break;
   12325            0 :             default:
   12326            0 :               gcc_unreachable ();
   12327              :             }
   12328              :         }
   12329              :   /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
   12330              :      clauses, we need copy ctor for those rather than default ctor,
   12331              :      plus as for other lastprivates assignment op and dtor.  */
   12332        19788 :   if (code == OMP_LOOP && !processing_template_decl)
   12333         1993 :     for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   12334         1285 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   12335          204 :           && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
   12336         1307 :           && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
   12337              :                                          false, true, true, true))
   12338            0 :         CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
   12339              : 
   12340              :   return omp_for;
   12341        21128 : }
   12342              : 
   12343              : /* Code walker for finish_omp_for_block: extract binding of DP->var
   12344              :    from its current block and move it to a new BIND_EXPR DP->b
   12345              :    surrounding the body of DP->omp_for.  */
   12346              : 
   12347              : struct fofb_data {
   12348              :   tree var;
   12349              :   tree b;
   12350              :   tree omp_for;
   12351              : };
   12352              : 
   12353              : static tree
   12354          389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
   12355              : {
   12356          389 :   struct fofb_data *fofb = (struct fofb_data *)dp;
   12357          389 :   if (TREE_CODE (*tp) == BIND_EXPR)
   12358          578 :     for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
   12359              :       {
   12360          576 :         if (*p == fofb->var)
   12361              :           {
   12362          363 :             *p = DECL_CHAIN (*p);
   12363          363 :             if (fofb->b == NULL_TREE)
   12364              :               {
   12365          214 :                 fofb->b = make_node (BLOCK);
   12366          214 :                 fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   12367          214 :                             OMP_FOR_BODY (fofb->omp_for), fofb->b);
   12368          214 :                 TREE_SIDE_EFFECTS (fofb->b) = 1;
   12369          214 :                 OMP_FOR_BODY (fofb->omp_for) = fofb->b;
   12370              :               }
   12371          363 :             DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
   12372          363 :             BIND_EXPR_VARS (fofb->b) = fofb->var;
   12373          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
   12374          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
   12375          363 :             return *tp;
   12376              :           }
   12377              :       }
   12378           26 :   if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
   12379           22 :     *walk_subtrees = false;
   12380              :   return NULL_TREE;
   12381              : }
   12382              : 
   12383              : /* Fix up range for decls.  Those decls were pushed into BIND's
   12384              :    BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
   12385              :    and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
   12386              :    so that processing of combined loop directives can find them.  */
   12387              : tree
   12388        14525 : finish_omp_for_block (tree bind, tree omp_for)
   12389              : {
   12390        14525 :   if (omp_for == NULL_TREE
   12391        14478 :       || !OMP_FOR_ORIG_DECLS (omp_for)
   12392        28435 :       || bind == NULL_TREE)
   12393          615 :     return bind;
   12394        13910 :   struct fofb_data fofb;
   12395        13910 :   fofb.b = NULL_TREE;
   12396        13910 :   fofb.omp_for = omp_for;
   12397        33347 :   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
   12398        19437 :     if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
   12399        19215 :         && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
   12400              :             == TREE_LIST)
   12401        20268 :         && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
   12402              :       {
   12403          237 :         tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
   12404          602 :         for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
   12405              :           {
   12406          365 :             fofb.var = TREE_VEC_ELT (v, j);
   12407          365 :             cp_walk_tree (&bind, finish_omp_for_block_walker,
   12408              :                           (void *)&fofb, NULL);
   12409              :           }
   12410              :       }
   12411        13910 :   return bind;
   12412              : }
   12413              : 
   12414              : void
   12415         3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
   12416              :                    tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
   12417              :                    tree clauses, enum omp_memory_order mo, bool weak)
   12418              : {
   12419         3342 :   tree orig_lhs;
   12420         3342 :   tree orig_rhs;
   12421         3342 :   tree orig_v;
   12422         3342 :   tree orig_lhs1;
   12423         3342 :   tree orig_rhs1;
   12424         3342 :   tree orig_r;
   12425         3342 :   bool dependent_p;
   12426         3342 :   tree stmt;
   12427              : 
   12428         3342 :   orig_lhs = lhs;
   12429         3342 :   orig_rhs = rhs;
   12430         3342 :   orig_v = v;
   12431         3342 :   orig_lhs1 = lhs1;
   12432         3342 :   orig_rhs1 = rhs1;
   12433         3342 :   orig_r = r;
   12434         3342 :   dependent_p = false;
   12435         3342 :   stmt = NULL_TREE;
   12436              : 
   12437              :   /* Even in a template, we can detect invalid uses of the atomic
   12438              :      pragma if neither LHS nor RHS is type-dependent.  */
   12439         3342 :   if (processing_template_decl)
   12440              :     {
   12441          600 :       dependent_p = (type_dependent_expression_p (lhs)
   12442          237 :                      || (rhs && type_dependent_expression_p (rhs))
   12443          234 :                      || (v && type_dependent_expression_p (v))
   12444          234 :                      || (lhs1 && type_dependent_expression_p (lhs1))
   12445          234 :                      || (rhs1 && type_dependent_expression_p (rhs1))
   12446          834 :                      || (r
   12447           25 :                          && r != void_list_node
   12448           16 :                          && type_dependent_expression_p (r)));
   12449          600 :       if (clauses)
   12450              :         {
   12451           30 :           gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
   12452              :                       && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
   12453              :                       && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
   12454           30 :           if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
   12455           30 :               || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
   12456              :             dependent_p = true;
   12457              :         }
   12458              :     }
   12459          576 :   if (!dependent_p)
   12460              :     {
   12461         2958 :       bool swapped = false;
   12462         2958 :       if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
   12463              :         {
   12464          143 :           std::swap (rhs, rhs1);
   12465          143 :           swapped = !commutative_tree_code (opcode);
   12466              :         }
   12467         2958 :       if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
   12468              :         {
   12469            0 :           if (code == OMP_ATOMIC)
   12470            0 :             error ("%<#pragma omp atomic update%> uses two different "
   12471              :                    "expressions for memory");
   12472              :           else
   12473            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12474              :                    "expressions for memory");
   12475            0 :           return;
   12476              :         }
   12477         2958 :       if (lhs1 && !cp_tree_equal (lhs, lhs1))
   12478              :         {
   12479            0 :           if (code == OMP_ATOMIC)
   12480            0 :             error ("%<#pragma omp atomic update%> uses two different "
   12481              :                    "expressions for memory");
   12482              :           else
   12483            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12484              :                    "expressions for memory");
   12485            0 :           return;
   12486              :         }
   12487         5916 :       stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
   12488              :                                   v, lhs1, rhs1, r, swapped, mo, weak,
   12489         2958 :                                   processing_template_decl != 0);
   12490         2958 :       if (stmt == error_mark_node)
   12491              :         return;
   12492              :     }
   12493         3312 :   if (processing_template_decl)
   12494              :     {
   12495          591 :       if (code == OMP_ATOMIC_READ)
   12496              :         {
   12497          167 :           stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
   12498          167 :           OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12499          167 :           stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12500              :         }
   12501              :       else
   12502              :         {
   12503          424 :           if (opcode == NOP_EXPR)
   12504           35 :             stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
   12505          389 :           else if (opcode == COND_EXPR)
   12506              :             {
   12507          124 :               stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
   12508          124 :               if (orig_r)
   12509           50 :                 stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
   12510              :                                stmt);
   12511          124 :               stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
   12512              :                              orig_lhs);
   12513          124 :               orig_rhs1 = NULL_TREE;
   12514              :             }
   12515              :           else
   12516          265 :             stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
   12517          424 :           if (orig_rhs1)
   12518          182 :             stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
   12519              :                                      COMPOUND_EXPR, orig_rhs1, stmt);
   12520          424 :           if (code != OMP_ATOMIC)
   12521              :             {
   12522          233 :               stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
   12523          233 :               OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12524          233 :               OMP_ATOMIC_WEAK (stmt) = weak;
   12525          233 :               stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12526              :             }
   12527              :         }
   12528          591 :       stmt = build2 (OMP_ATOMIC, void_type_node,
   12529              :                      clauses ? clauses : integer_zero_node, stmt);
   12530          591 :       OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12531          591 :       OMP_ATOMIC_WEAK (stmt) = weak;
   12532          591 :       SET_EXPR_LOCATION (stmt, loc);
   12533              :     }
   12534              : 
   12535              :   /* Avoid -Wunused-value warnings here, the whole construct has side-effects
   12536              :      and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
   12537              :      in some tree that appears to be unused, the value is not unused.  */
   12538         3312 :   warning_sentinel w (warn_unused_value);
   12539         3312 :   finish_expr_stmt (stmt);
   12540         3312 : }
   12541              : 
   12542              : void
   12543          359 : finish_omp_barrier (void)
   12544              : {
   12545          359 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
   12546          359 :   releasing_vec vec;
   12547          359 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12548          359 :   finish_expr_stmt (stmt);
   12549          359 : }
   12550              : 
   12551              : void
   12552          397 : finish_omp_depobj (location_t loc, tree depobj,
   12553              :                    enum omp_clause_depend_kind kind, tree clause)
   12554              : {
   12555          397 :   if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
   12556              :     {
   12557          343 :       if (!lvalue_p (depobj))
   12558              :         {
   12559            6 :           error_at (EXPR_LOC_OR_LOC (depobj, loc),
   12560              :                     "%<depobj%> expression is not lvalue expression");
   12561            6 :           depobj = error_mark_node;
   12562              :         }
   12563              :     }
   12564              : 
   12565          397 :   if (processing_template_decl)
   12566              :     {
   12567          114 :       if (clause == NULL_TREE)
   12568           47 :         clause = build_int_cst (integer_type_node, kind);
   12569          114 :       add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
   12570          114 :       return;
   12571              :     }
   12572              : 
   12573          283 :   if (!error_operand_p (depobj))
   12574              :     {
   12575          274 :       tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
   12576          274 :       if (addr == error_mark_node)
   12577              :         depobj = error_mark_node;
   12578              :       else
   12579          274 :         depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
   12580              :                                         tf_warning_or_error);
   12581              :     }
   12582              : 
   12583          283 :   c_finish_omp_depobj (loc, depobj, kind, clause);
   12584              : }
   12585              : 
   12586              : void
   12587          162 : finish_omp_flush (int mo)
   12588              : {
   12589          162 :   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   12590          162 :   releasing_vec vec;
   12591          162 :   if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
   12592              :     {
   12593           54 :       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
   12594           54 :       vec->quick_push (build_int_cst (integer_type_node, mo));
   12595              :     }
   12596          162 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12597          162 :   finish_expr_stmt (stmt);
   12598          162 : }
   12599              : 
   12600              : void
   12601          111 : finish_omp_taskwait (void)
   12602              : {
   12603          111 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
   12604          111 :   releasing_vec vec;
   12605          111 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12606          111 :   finish_expr_stmt (stmt);
   12607          111 : }
   12608              : 
   12609              : void
   12610           16 : finish_omp_taskyield (void)
   12611              : {
   12612           16 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
   12613           16 :   releasing_vec vec;
   12614           16 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12615           16 :   finish_expr_stmt (stmt);
   12616           16 : }
   12617              : 
   12618              : void
   12619          596 : finish_omp_cancel (tree clauses)
   12620              : {
   12621          596 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   12622          596 :   int mask = 0;
   12623          596 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12624              :     mask = 1;
   12625          414 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12626              :     mask = 2;
   12627          285 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12628              :     mask = 4;
   12629          164 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12630              :     mask = 8;
   12631              :   else
   12632              :     {
   12633            0 :       error ("%<#pragma omp cancel%> must specify one of "
   12634              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12635            0 :       return;
   12636              :     }
   12637          596 :   releasing_vec vec;
   12638          596 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   12639          596 :   if (ifc != NULL_TREE)
   12640              :     {
   12641           70 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   12642           70 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   12643            6 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   12644              :                   "expected %<cancel%> %<if%> clause modifier");
   12645              :       else
   12646              :         {
   12647           64 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   12648           64 :           if (ifc2 != NULL_TREE)
   12649              :             {
   12650            3 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   12651              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   12652              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   12653            3 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   12654              :                         "expected %<cancel%> %<if%> clause modifier");
   12655              :             }
   12656              :         }
   12657              : 
   12658           70 :       if (!processing_template_decl)
   12659           61 :         ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
   12660              :       else
   12661            9 :         ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   12662            9 :                                  OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
   12663              :                                  integer_zero_node, ERROR_MARK,
   12664              :                                  NULL_TREE, NULL, tf_warning_or_error);
   12665              :     }
   12666              :   else
   12667          526 :     ifc = boolean_true_node;
   12668          596 :   vec->quick_push (build_int_cst (integer_type_node, mask));
   12669          596 :   vec->quick_push (ifc);
   12670          596 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12671          596 :   finish_expr_stmt (stmt);
   12672          596 : }
   12673              : 
   12674              : void
   12675          494 : finish_omp_cancellation_point (tree clauses)
   12676              : {
   12677          494 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   12678          494 :   int mask = 0;
   12679          494 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12680              :     mask = 1;
   12681          366 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12682              :     mask = 2;
   12683          261 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12684              :     mask = 4;
   12685          156 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12686              :     mask = 8;
   12687              :   else
   12688              :     {
   12689            3 :       error ("%<#pragma omp cancellation point%> must specify one of "
   12690              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12691            3 :       return;
   12692              :     }
   12693          491 :   releasing_vec vec
   12694          491 :     = make_tree_vector_single (build_int_cst (integer_type_node, mask));
   12695          491 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12696          491 :   finish_expr_stmt (stmt);
   12697          491 : }
   12698              : 
   12699              : /* Begin a __transaction_atomic or __transaction_relaxed statement.
   12700              :    If PCOMPOUND is non-null, this is for a function-transaction-block, and we
   12701              :    should create an extra compound stmt.  */
   12702              : 
   12703              : tree
   12704          303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
   12705              : {
   12706          303 :   tree r;
   12707              : 
   12708          303 :   if (pcompound)
   12709           21 :     *pcompound = begin_compound_stmt (0);
   12710              : 
   12711          303 :   r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
   12712              : 
   12713              :   /* Only add the statement to the function if support enabled.  */
   12714          303 :   if (flag_tm)
   12715          297 :     add_stmt (r);
   12716              :   else
   12717           12 :     error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
   12718              :                     ? G_("%<__transaction_relaxed%> without "
   12719              :                          "transactional memory support enabled")
   12720              :                     : G_("%<__transaction_atomic%> without "
   12721              :                          "transactional memory support enabled")));
   12722              : 
   12723          303 :   TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
   12724          303 :   TREE_SIDE_EFFECTS (r) = 1;
   12725          303 :   return r;
   12726              : }
   12727              : 
   12728              : /* End a __transaction_atomic or __transaction_relaxed statement.
   12729              :    If COMPOUND_STMT is non-null, this is for a function-transaction-block,
   12730              :    and we should end the compound.  If NOEX is non-NULL, we wrap the body in
   12731              :    a MUST_NOT_THROW_EXPR with NOEX as condition.  */
   12732              : 
   12733              : void
   12734          303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
   12735              : {
   12736          303 :   TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
   12737          303 :   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   12738          303 :   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
   12739          303 :   TRANSACTION_EXPR_IS_STMT (stmt) = 1;
   12740              : 
   12741              :   /* noexcept specifications are not allowed for function transactions.  */
   12742          303 :   gcc_assert (!(noex && compound_stmt));
   12743          303 :   if (noex)
   12744              :     {
   12745           51 :       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
   12746              :                                              noex);
   12747           51 :       protected_set_expr_location
   12748           51 :         (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
   12749           51 :       TREE_SIDE_EFFECTS (body) = 1;
   12750           51 :       TRANSACTION_EXPR_BODY (stmt) = body;
   12751              :     }
   12752              : 
   12753          303 :   if (compound_stmt)
   12754           21 :     finish_compound_stmt (compound_stmt);
   12755          303 : }
   12756              : 
   12757              : /* Build a __transaction_atomic or __transaction_relaxed expression.  If
   12758              :    NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
   12759              :    condition.  */
   12760              : 
   12761              : tree
   12762          116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
   12763              : {
   12764          116 :   tree ret;
   12765          116 :   if (noex)
   12766              :     {
   12767           57 :       expr = build_must_not_throw_expr (expr, noex);
   12768           57 :       protected_set_expr_location (expr, loc);
   12769           57 :       TREE_SIDE_EFFECTS (expr) = 1;
   12770              :     }
   12771          116 :   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
   12772          116 :   if (flags & TM_STMT_ATTR_RELAXED)
   12773            4 :         TRANSACTION_EXPR_RELAXED (ret) = 1;
   12774          116 :   TREE_SIDE_EFFECTS (ret) = 1;
   12775          116 :   SET_EXPR_LOCATION (ret, loc);
   12776          116 :   return ret;
   12777              : }
   12778              : 
   12779              : void
   12780        98453 : init_cp_semantics (void)
   12781              : {
   12782        98453 : }
   12783              : 
   12784              : 
   12785              : /* Get constant string at LOCATION. Returns true if successful,
   12786              :    otherwise false.  */
   12787              : 
   12788              : bool
   12789     10668764 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
   12790              : {
   12791     10668764 :   tsubst_flags_t complain = tf_warning_or_error;
   12792              : 
   12793     10668764 :   if (message == NULL_TREE
   12794     10668764 :       || message == error_mark_node
   12795     21337525 :       || check_for_bare_parameter_packs (message))
   12796            3 :     return false;
   12797              : 
   12798     10668761 :   if (TREE_CODE (message) != STRING_CST
   12799     10668761 :       && !type_dependent_expression_p (message))
   12800              :     {
   12801          976 :       message_sz
   12802          976 :         = finish_class_member_access_expr (message,
   12803              :                                            get_identifier ("size"),
   12804              :                                            false, complain);
   12805          976 :       if (message_sz != error_mark_node)
   12806          889 :         message_data
   12807          889 :           = finish_class_member_access_expr (message,
   12808              :                                              get_identifier ("data"),
   12809              :                                              false, complain);
   12810          976 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12811              :         {
   12812          121 :           error_at (location, "constexpr string must be a string "
   12813              :                     "literal or object with %<size%> and "
   12814              :                     "%<data%> members");
   12815          292 :           return false;
   12816              :         }
   12817          855 :       releasing_vec size_args, data_args;
   12818          855 :       message_sz = finish_call_expr (message_sz, &size_args, false, false,
   12819              :                                      complain);
   12820          855 :       message_data = finish_call_expr (message_data, &data_args, false, false,
   12821              :                                        complain);
   12822          855 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12823              :         return false;
   12824          741 :       message_sz = build_converted_constant_expr (size_type_node, message_sz,
   12825              :                                                   complain);
   12826          741 :       if (message_sz == error_mark_node)
   12827              :         {
   12828           15 :           error_at (location, "constexpr string %<size()%> "
   12829              :                     "must be implicitly convertible to "
   12830              :                     "%<std::size_t%>");
   12831           15 :           return false;
   12832              :         }
   12833              : 
   12834          726 :       if (allow_char8_t
   12835           37 :           && POINTER_TYPE_P (TREE_TYPE (message_data))
   12836           37 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   12837           37 :               == char8_type_node)
   12838          736 :           && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
   12839              :               == TYPE_QUAL_CONST))
   12840              :         return true;
   12841              : 
   12842          716 :       message_data = build_converted_constant_expr (const_string_type_node,
   12843              :                                                     message_data, complain);
   12844          716 :       if (message_data == error_mark_node)
   12845              :         {
   12846           32 :           error_at (location, "constexpr string %<data()%> "
   12847              :                     "must be implicitly convertible to "
   12848              :                     "%<const char*%>");
   12849           32 :           return false;
   12850              :         }
   12851          855 :     }
   12852              :   return true;
   12853              : }
   12854              : 
   12855              : /* Extract constant string at LOCATON into output string STR.
   12856              :    Returns true if successful, otherwise false.  */
   12857              : 
   12858              : bool
   12859          405 : cexpr_str::extract (location_t location, tree &str)
   12860              : {
   12861          405 :   const char *msg;
   12862          405 :   int len;
   12863          405 :   if (!extract (location, msg, len))
   12864              :     return false;
   12865          343 :   str = build_string (len, msg);
   12866          343 :   return true;
   12867              : }
   12868              : 
   12869              : /* Extract constant string at LOCATION into output string MSG with LEN.
   12870              :    Returns true if successful, otherwise false.  */
   12871              : 
   12872              : bool
   12873         2202 : cexpr_str::extract (location_t location, const char * &msg, int &len,
   12874              :                     const constexpr_ctx *ctx /* = NULL */,
   12875              :                     bool *non_constant_p /* = NULL */,
   12876              :                     bool *overflow_p /* = NULL */,
   12877              :                     tree *jump_target /* = NULL */)
   12878              : {
   12879         2202 :   tsubst_flags_t complain = tf_warning_or_error;
   12880              : 
   12881         2202 :   msg = NULL;
   12882         2202 :   if (message_sz && message_data)
   12883              :     {
   12884          620 :       tree msz;
   12885          620 :       if (ctx)
   12886              :         {
   12887           55 :           msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
   12888              :                                               non_constant_p, overflow_p,
   12889              :                                               jump_target);
   12890           55 :           if (*jump_target || *non_constant_p)
   12891              :             return false;
   12892              :         }
   12893              :       else
   12894          565 :         msz = cxx_constant_value (message_sz, NULL_TREE, complain);
   12895          616 :       if (!tree_fits_uhwi_p (msz))
   12896              :         {
   12897           35 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   12898           35 :             error_at (location,
   12899              :                       "constexpr string %<size()%> "
   12900              :                       "must be a constant expression");
   12901           35 :           return false;
   12902              :         }
   12903          581 :       else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
   12904              :                != tree_to_uhwi (msz))
   12905              :         {
   12906            0 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   12907            0 :             error_at (location,
   12908              :                       "constexpr string message %<size()%> "
   12909              :                       "%qE too large", msz);
   12910            0 :           return false;
   12911              :         }
   12912          581 :       len = tree_to_uhwi (msz);
   12913          581 :       tree data;
   12914          581 :       if (ctx)
   12915              :         {
   12916           51 :           data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
   12917              :                                                non_constant_p, overflow_p,
   12918              :                                                jump_target);
   12919           51 :           if (*jump_target || *non_constant_p)
   12920              :             return false;
   12921           47 :           STRIP_NOPS (data);
   12922           47 :           if (TREE_CODE (data) != ADDR_EXPR)
   12923              :             {
   12924            0 :             unhandled:
   12925            0 :               if (!cxx_constexpr_quiet_p (ctx))
   12926            0 :                 error_at (location, "unhandled return from %<data()%>");
   12927            0 :               return false;
   12928              :             }
   12929           47 :           tree str = TREE_OPERAND (data, 0);
   12930           47 :           unsigned HOST_WIDE_INT off = 0;
   12931           47 :           if (TREE_CODE (str) == ARRAY_REF
   12932           47 :               && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
   12933              :             {
   12934            6 :               off = tree_to_uhwi (TREE_OPERAND (str, 1));
   12935            6 :               str = TREE_OPERAND (str, 0);
   12936              :             }
   12937           47 :           str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
   12938              :                                               non_constant_p, overflow_p,
   12939              :                                               jump_target);
   12940           47 :           if (*jump_target || *non_constant_p)
   12941              :             return false;
   12942           47 :           if (TREE_CODE (str) == STRING_CST)
   12943              :             {
   12944           42 :               if (TREE_STRING_LENGTH (str) < len
   12945           42 :                   || (unsigned) TREE_STRING_LENGTH (str) < off
   12946           84 :                   || (unsigned) TREE_STRING_LENGTH (str) < off + len)
   12947            0 :                 goto unhandled;
   12948           42 :               msg = TREE_STRING_POINTER (str) + off;
   12949           42 :               goto translate;
   12950              :             }
   12951            5 :           if (TREE_CODE (str) != CONSTRUCTOR
   12952            5 :               || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
   12953            0 :             goto unhandled;
   12954            5 :           char *b;
   12955            5 :           if (len < 64)
   12956            5 :             b = XALLOCAVEC (char, len + 1);
   12957              :           else
   12958              :             {
   12959            0 :               buf = XNEWVEC (char, len + 1);
   12960            0 :               b = buf;
   12961              :             }
   12962            5 :           msg = b;
   12963            5 :           memset (b, 0, len + 1);
   12964            5 :           tree field, value;
   12965            5 :           unsigned k;
   12966            5 :           unsigned HOST_WIDE_INT l = 0;
   12967           79 :           FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
   12968           79 :             if (!tree_fits_shwi_p (value))
   12969            0 :               goto unhandled;
   12970           79 :             else if (field == NULL_TREE)
   12971              :               {
   12972            0 :                 if (integer_zerop (value))
   12973              :                   break;
   12974            0 :                 if (l >= off && l < off + len)
   12975            0 :                   b[l - off] = tree_to_shwi (value);
   12976            0 :                 ++l;
   12977              :               }
   12978           79 :             else if (TREE_CODE (field) == RANGE_EXPR)
   12979              :               {
   12980            0 :                 tree lo = TREE_OPERAND (field, 0);
   12981            0 :                 tree hi = TREE_OPERAND (field, 1);
   12982            0 :                 if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
   12983            0 :                   goto unhandled;
   12984            0 :                 if (integer_zerop (value))
   12985              :                   break;
   12986            0 :                 unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
   12987            0 :                 for (l = tree_to_uhwi (lo); l <= m; ++l)
   12988            0 :                   if (l >= off && l < off + len)
   12989            0 :                     b[l - off] = tree_to_shwi (value);
   12990              :               }
   12991           79 :             else if (tree_fits_uhwi_p (field))
   12992              :               {
   12993           79 :                 l = tree_to_uhwi (field);
   12994           79 :                 if (integer_zerop (value))
   12995              :                   break;
   12996           74 :                 if (l >= off && l < off + len)
   12997           74 :                   b[l - off] = tree_to_shwi (value);
   12998           74 :                 l++;
   12999              :               }
   13000            5 :           b[len] = '\0';
   13001              :         }
   13002              :       else
   13003              :         {
   13004          530 :           data = maybe_constant_value (message_data, NULL_TREE, mce_true);
   13005          530 :           if (!reduced_constant_expression_p (data))
   13006           96 :             data = NULL_TREE;
   13007          530 :           if (len)
   13008              :             {
   13009          453 :               if (data)
   13010          379 :                 msg = c_getstr (data);
   13011          453 :               if (msg == NULL)
   13012          119 :                 buf = XNEWVEC (char, len);
   13013         1452 :               for (int i = 0; i < len; ++i)
   13014              :                 {
   13015         1029 :                   tree t = message_data;
   13016         1029 :                   if (i)
   13017         1152 :                     t = build2 (POINTER_PLUS_EXPR,
   13018          576 :                                 TREE_TYPE (message_data), message_data,
   13019          576 :                                 size_int (i));
   13020         1029 :                   t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
   13021         1029 :                   tree t2 = cxx_constant_value (t, NULL_TREE, complain);
   13022         1029 :                   if (!tree_fits_shwi_p (t2))
   13023              :                     {
   13024           30 :                       error_at (location,
   13025              :                                 "constexpr string %<data()[%d]%> "
   13026              :                                 "must be a constant expression", i);
   13027           30 :                       return false;
   13028              :                     }
   13029          999 :                   if (msg == NULL)
   13030          362 :                     buf[i] = tree_to_shwi (t2);
   13031              :                   /* If c_getstr worked, just verify the first and
   13032              :                      last characters using constant evaluation.  */
   13033          637 :                   else if (len > 2 && i == 0)
   13034          266 :                     i = len - 2;
   13035              :                 }
   13036          423 :               if (msg == NULL)
   13037          104 :                 msg = buf;
   13038              :             }
   13039           77 :           else if (!data)
   13040              :             {
   13041              :               /* We don't have any function to test whether some
   13042              :                  expression is a core constant expression.  So, instead
   13043              :                  test whether (message.data (), 0) is a constant
   13044              :                  expression.  */
   13045           22 :               data = build2 (COMPOUND_EXPR, integer_type_node,
   13046              :                              message_data, integer_zero_node);
   13047           22 :               tree t = cxx_constant_value (data, NULL_TREE, complain);
   13048           22 :               if (!integer_zerop (t))
   13049              :                 {
   13050           22 :                   error_at (location,
   13051              :                             "constexpr string %<data()%> "
   13052              :                             "must be a core constant expression");
   13053           22 :                   return false;
   13054              :                 }
   13055              :             }
   13056              :         }
   13057              :     }
   13058              :   else
   13059              :     {
   13060         1582 :       tree eltype = TREE_TYPE (TREE_TYPE (message));
   13061         1582 :       int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
   13062         1582 :       msg = TREE_STRING_POINTER (message);
   13063         1582 :       len = TREE_STRING_LENGTH (message) / sz - 1;
   13064              :     }
   13065         2107 : translate:
   13066         2107 :   if ((message_sz && message_data) || ctx)
   13067              :     {
   13068              :       /* Convert the string from execution charset to SOURCE_CHARSET.  */
   13069          618 :       cpp_string istr, ostr;
   13070          618 :       istr.len = len;
   13071          618 :       istr.text = (const unsigned char *) msg;
   13072          618 :       enum cpp_ttype type = CPP_STRING;
   13073          618 :       if (message_sz && message_data)
   13074              :         {
   13075          525 :           if (POINTER_TYPE_P (TREE_TYPE (message_data))
   13076          525 :               && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   13077          525 :                   == char8_type_node))
   13078              :             type = CPP_UTF8STRING;
   13079              :         }
   13080           93 :       else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
   13081           93 :                == char8_type_node)
   13082          618 :         type = CPP_UTF8STRING;
   13083          618 :       if (len == 0)
   13084              :         ;
   13085          530 :       else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
   13086              :                                       true))
   13087              :         {
   13088            0 :           if (type == CPP_UTF8STRING)
   13089            0 :             error_at (location, "could not convert constexpr string from "
   13090              :                                 "UTF-8 encoding to source character "
   13091              :                                 "set");
   13092              :           else
   13093            0 :             error_at (location, "could not convert constexpr string from "
   13094              :                                 "ordinary literal encoding to source character "
   13095              :                                 "set");
   13096            0 :           return false;
   13097              :         }
   13098              :       else
   13099              :         {
   13100          530 :           if (buf)
   13101          104 :             XDELETEVEC (buf);
   13102          530 :           msg = buf = const_cast <char *> ((const char *) ostr.text);
   13103          530 :           len = ostr.len;
   13104              :         }
   13105              :     }
   13106              : 
   13107              :   return true;
   13108              : }
   13109              : 
   13110              : /* Build a STATIC_ASSERT for a static assertion with the condition
   13111              :    CONDITION and the message text MESSAGE.  LOCATION is the location
   13112              :    of the static assertion in the source code.  When MEMBER_P, this
   13113              :    static assertion is a member of a class.  If SHOW_EXPR_P is true,
   13114              :    print the condition (because it was instantiation-dependent).
   13115              :    If CONSTEVAL_BLOCK_P is true, this static assertion represents
   13116              :    a consteval block.  */
   13117              : 
   13118              : void
   13119     10668201 : finish_static_assert (tree condition, tree message, location_t location,
   13120              :                       bool member_p, bool show_expr_p,
   13121              :                       bool consteval_block_p/*=false*/)
   13122              : {
   13123     10668201 :   tsubst_flags_t complain = tf_warning_or_error;
   13124              : 
   13125     10668201 :   if (condition == NULL_TREE
   13126     10668201 :       || condition == error_mark_node)
   13127      4498286 :     return;
   13128              : 
   13129     10668023 :   if (check_for_bare_parameter_packs (condition))
   13130              :     return;
   13131              : 
   13132     10668020 :   cexpr_str cstr(message);
   13133     10668020 :   if (!cstr.type_check (location))
   13134              :     return;
   13135              : 
   13136              :   /* Save the condition in case it was a concept check.  */
   13137     10667926 :   tree orig_condition = condition;
   13138              : 
   13139     10667926 :   if (instantiation_dependent_expression_p (condition)
   13140     10667926 :       || instantiation_dependent_expression_p (message))
   13141              :     {
   13142              :       /* We're in a template; build a STATIC_ASSERT and put it in
   13143              :          the right place. */
   13144      4497742 :     defer:
   13145      4497742 :       tree assertion = make_node (STATIC_ASSERT);
   13146      4497742 :       STATIC_ASSERT_CONDITION (assertion) = orig_condition;
   13147      4497742 :       STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
   13148      4497742 :       STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
   13149      4497742 :       CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
   13150              : 
   13151      4497742 :       if (member_p)
   13152      2340188 :         maybe_add_class_template_decl_list (current_class_type,
   13153              :                                             assertion,
   13154              :                                             /*friend_p=*/0);
   13155              :       else
   13156      2157554 :         add_stmt (assertion);
   13157              : 
   13158      4497742 :       return;
   13159              :     }
   13160              : 
   13161              :   /* Evaluate the consteval { }.  This must be done only once.  */
   13162      6173572 :   if (consteval_block_p)
   13163              :     {
   13164          244 :       cxx_constant_value (condition);
   13165          244 :       return;
   13166              :     }
   13167              : 
   13168              :   /* Fold the expression and convert it to a boolean value. */
   13169      6173328 :   condition = contextual_conv_bool (condition, complain);
   13170      6173328 :   condition = fold_non_dependent_expr (condition, complain,
   13171              :                                        /*manifestly_const_eval=*/true);
   13172              : 
   13173      6173327 :   if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
   13174              :     /* Do nothing; the condition is satisfied. */
   13175              :     ;
   13176              :   else
   13177              :     {
   13178         5570 :       iloc_sentinel ils (location);
   13179              : 
   13180         5570 :       if (integer_zerop (condition))
   13181              :         {
   13182              :           /* CWG2518: static_assert failure in a template is not IFNDR.  */
   13183         5037 :           if (processing_template_decl)
   13184         3388 :             goto defer;
   13185              : 
   13186         1649 :           int len;
   13187         1649 :           const char *msg = NULL;
   13188         1649 :           if (!cstr.extract (location, msg, len))
   13189           25 :             return;
   13190              : 
   13191              :           /* See if we can find which clause was failing (for logical AND).  */
   13192         1624 :           tree bad = find_failing_clause (NULL, orig_condition);
   13193              :           /* If not, or its location is unusable, fall back to the previous
   13194              :              location.  */
   13195         1624 :           location_t cloc = cp_expr_loc_or_loc (bad, location);
   13196              : 
   13197         1624 :           auto_diagnostic_group d;
   13198              : 
   13199              :           /* Report the error. */
   13200         1624 :           if (len == 0)
   13201         1014 :             error_at (cloc, "static assertion failed");
   13202              :           else
   13203          610 :             error_at (cloc, "static assertion failed: %.*s", len, msg);
   13204              : 
   13205         1624 :           diagnose_failing_condition (bad, cloc, show_expr_p);
   13206              : 
   13207              :           /* Suppress -Wreturn-type for functions with failed static_asserts.
   13208              :              Otherwise templates like:
   13209              :              if constexpr (whatever)
   13210              :                return something (args);
   13211              :              else
   13212              :                static_assert (false, "explanation");
   13213              :              get a useless extra -Wreturn-type warning.  */
   13214         1624 :           if (current_function_decl)
   13215          600 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13216         1624 :         }
   13217          533 :       else if (condition && condition != error_mark_node)
   13218              :         {
   13219          528 :           error ("non-constant condition for static assertion");
   13220          528 :           if (require_rvalue_constant_expression (condition))
   13221          466 :             cxx_constant_value (condition);
   13222              :         }
   13223         5570 :     }
   13224     10668019 : }
   13225              : 
   13226              : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
   13227              :    suitable for use as a type-specifier.
   13228              : 
   13229              :    ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
   13230              :    id-expression or a class member access, FALSE when it was parsed as
   13231              :    a full expression.  */
   13232              : 
   13233              : tree
   13234     36903924 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
   13235              :                       tsubst_flags_t complain)
   13236              : {
   13237     36903924 :   tree type = NULL_TREE;
   13238              : 
   13239     36903924 :   if (!expr || error_operand_p (expr))
   13240       222401 :     return error_mark_node;
   13241              : 
   13242     36681523 :   if (TYPE_P (expr)
   13243     36681523 :       || TREE_CODE (expr) == TYPE_DECL
   13244     73363027 :       || (TREE_CODE (expr) == BIT_NOT_EXPR
   13245        13415 :           && TYPE_P (TREE_OPERAND (expr, 0))))
   13246              :     {
   13247           28 :       if (complain & tf_error)
   13248           28 :         error ("argument to %<decltype%> must be an expression");
   13249           28 :       return error_mark_node;
   13250              :     }
   13251              : 
   13252              :   /* decltype is an unevaluated context.  */
   13253     36681495 :   cp_unevaluated u;
   13254              : 
   13255     36681495 :   processing_template_decl_sentinel ptds (/*reset=*/false);
   13256              : 
   13257              :   /* Depending on the resolution of DR 1172, we may later need to distinguish
   13258              :      instantiation-dependent but not type-dependent expressions so that, say,
   13259              :      A<decltype(sizeof(T))>::U doesn't require 'typename'.  */
   13260     36681495 :   if (instantiation_dependent_uneval_expression_p (expr))
   13261              :     {
   13262      6892290 :     dependent:
   13263      6892674 :       type = cxx_make_type (DECLTYPE_TYPE);
   13264      6892674 :       DECLTYPE_TYPE_EXPR (type) = expr;
   13265     13785348 :       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
   13266      6892674 :         = id_expression_or_member_access_p;
   13267      6892674 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   13268              : 
   13269      6892674 :       return type;
   13270              :     }
   13271     29789205 :   else if (processing_template_decl)
   13272              :     {
   13273         4718 :       expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
   13274         4718 :       if (expr == error_mark_node)
   13275              :         return error_mark_node;
   13276              :       /* Keep processing_template_decl cleared for the rest of the function
   13277              :          (for sake of the call to lvalue_kind below, which handles templated
   13278              :          and non-templated COND_EXPR differently).  */
   13279         4681 :       processing_template_decl = 0;
   13280              :     }
   13281              : 
   13282              :   /* The type denoted by decltype(e) is defined as follows:  */
   13283              : 
   13284     29789168 :   expr = resolve_nondeduced_context (expr, complain);
   13285     29789168 :   if (!mark_single_function (expr, complain))
   13286            0 :     return error_mark_node;
   13287              : 
   13288     29789168 :   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
   13289           18 :     return error_mark_node;
   13290              : 
   13291     29789150 :   if (type_unknown_p (expr))
   13292              :     {
   13293           18 :       if (complain & tf_error)
   13294            6 :         error ("%<decltype%> cannot resolve address of overloaded function");
   13295           18 :       return error_mark_node;
   13296              :     }
   13297              : 
   13298     29789132 :   if (id_expression_or_member_access_p)
   13299              :     {
   13300              :       /* If e is an id-expression or a class member access (5.2.5
   13301              :          [expr.ref]), decltype(e) is defined as the type of the entity
   13302              :          named by e. If there is no such entity, or e names a set of
   13303              :          overloaded functions, the program is ill-formed.  */
   13304       418335 :       if (identifier_p (expr))
   13305            0 :         expr = lookup_name (expr);
   13306              : 
   13307              :       /* If e is a constified expression inside a contract assertion,
   13308              :          strip the const wrapper. Per P2900R14, "For a function f with the
   13309              :          return type T , the result name is an lvalue of type const T , decltype(r)
   13310              :          is T , and decltype((r)) is const T&."  */
   13311       418335 :       expr = strip_contract_const_wrapper (expr);
   13312              : 
   13313       283817 :       if (REFERENCE_REF_P (expr)
   13314       418338 :           || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   13315              :         /* This can happen when the expression is, e.g., "a.b". Just
   13316              :            look at the underlying operand.  */
   13317       284500 :         expr = TREE_OPERAND (expr, 0);
   13318              : 
   13319       418335 :       if (TREE_CODE (expr) == OFFSET_REF
   13320       418335 :           || TREE_CODE (expr) == MEMBER_REF
   13321       418335 :           || TREE_CODE (expr) == SCOPE_REF)
   13322              :         /* We're only interested in the field itself. If it is a
   13323              :            BASELINK, we will need to see through it in the next
   13324              :            step.  */
   13325            0 :         expr = TREE_OPERAND (expr, 1);
   13326              : 
   13327       418335 :       if (BASELINK_P (expr))
   13328              :         /* See through BASELINK nodes to the underlying function.  */
   13329            5 :         expr = BASELINK_FUNCTIONS (expr);
   13330              : 
   13331              :       /* decltype of a decomposition name drops references in the tuple case
   13332              :          (unlike decltype of a normal variable) and keeps cv-qualifiers from
   13333              :          the containing object in the other cases (unlike decltype of a member
   13334              :          access expression).  */
   13335       418335 :       if (DECL_DECOMPOSITION_P (expr))
   13336              :         {
   13337         1413 :           if (ptds.saved)
   13338              :             {
   13339          275 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
   13340              :                                    || (DECL_CONTEXT (expr)
   13341              :                                        != current_function_decl));
   13342              :               /* DECL_HAS_VALUE_EXPR_P is always set if
   13343              :                  processing_template_decl at least for structured bindings
   13344              :                  within the template.  If lookup_decomp_type
   13345              :                  returns non-NULL, it is the tuple case.  */
   13346          275 :               if (tree ret = lookup_decomp_type (expr))
   13347              :                 return ret;
   13348          191 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
   13349              :             }
   13350         1329 :           if (DECL_HAS_VALUE_EXPR_P (expr))
   13351              :             /* Expr is an array or struct subobject proxy, handle
   13352              :                bit-fields properly.  */
   13353         1017 :             return unlowered_expr_type (expr);
   13354              :           else
   13355              :             /* Expr is a reference variable for the tuple case.  */
   13356          312 :             return lookup_decomp_type (expr);
   13357              :         }
   13358              : 
   13359       416922 :       switch (TREE_CODE (expr))
   13360              :         {
   13361          241 :         case FIELD_DECL:
   13362          241 :           if (DECL_BIT_FIELD_TYPE (expr))
   13363              :             {
   13364              :               type = DECL_BIT_FIELD_TYPE (expr);
   13365              :               break;
   13366              :             }
   13367              :           /* Fall through for fields that aren't bitfields.  */
   13368       118687 :           gcc_fallthrough ();
   13369              : 
   13370       118687 :         case VAR_DECL:
   13371       118687 :           if (is_capture_proxy (expr))
   13372              :             {
   13373           85 :               if (is_normal_capture_proxy (expr))
   13374              :                 {
   13375           21 :                   expr = DECL_CAPTURED_VARIABLE (expr);
   13376           21 :                   type = TREE_TYPE (expr);
   13377              :                 }
   13378              :               else
   13379              :                 {
   13380           64 :                   expr = DECL_VALUE_EXPR (expr);
   13381           64 :                   gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
   13382           64 :                   expr = TREE_OPERAND (expr, 1);
   13383           64 :                   type = TREE_TYPE (expr);
   13384              :                 }
   13385              :               break;
   13386              :             }
   13387              :           /* Fall through for variables that aren't capture proxies.  */
   13388       412714 :           gcc_fallthrough ();
   13389              : 
   13390       412714 :         case FUNCTION_DECL:
   13391       412714 :         case CONST_DECL:
   13392       412714 :         case PARM_DECL:
   13393       412714 :         case RESULT_DECL:
   13394       412714 :         case TEMPLATE_PARM_INDEX:
   13395       412714 :           expr = mark_type_use (expr);
   13396       412714 :           type = TREE_TYPE (expr);
   13397       412714 :           if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
   13398              :             {
   13399              :               /* decltype of an NTTP object is the type of the template
   13400              :                  parameter, which is the object type modulo cv-quals.  */
   13401         1399 :               int quals = cp_type_quals (type);
   13402         1399 :               gcc_checking_assert (quals & TYPE_QUAL_CONST);
   13403         1399 :               type = cv_unqualified (type);
   13404              :             }
   13405              :           break;
   13406              : 
   13407            0 :         case ERROR_MARK:
   13408            0 :           type = error_mark_node;
   13409            0 :           break;
   13410              : 
   13411         3157 :         case COMPONENT_REF:
   13412         3157 :         case COMPOUND_EXPR:
   13413         3157 :           mark_type_use (expr);
   13414         3157 :           type = is_bitfield_expr_with_lowered_type (expr);
   13415         3157 :           if (!type)
   13416         3122 :             type = TREE_TYPE (TREE_OPERAND (expr, 1));
   13417              :           break;
   13418              : 
   13419            0 :         case BIT_FIELD_REF:
   13420            0 :           gcc_unreachable ();
   13421              : 
   13422          252 :         case INTEGER_CST:
   13423          252 :         case PTRMEM_CST:
   13424              :           /* We can get here when the id-expression refers to an
   13425              :              enumerator or non-type template parameter.  */
   13426          252 :           type = TREE_TYPE (expr);
   13427          252 :           break;
   13428              : 
   13429          714 :         default:
   13430              :           /* Handle instantiated template non-type arguments.  */
   13431          714 :           type = TREE_TYPE (expr);
   13432          714 :           break;
   13433              :         }
   13434              :     }
   13435              :   else
   13436              :     {
   13437     29370797 :       tree decl = STRIP_REFERENCE_REF (expr);
   13438     29370797 :       tree lam = current_lambda_expr ();
   13439     29370797 :       if (lam && outer_automatic_var_p (decl))
   13440              :         {
   13441              :           /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
   13442              :              unevaluated operand within S would refer to an entity captured by
   13443              :              copy in some intervening lambda-expression, then let E be the
   13444              :              innermost such lambda-expression.
   13445              : 
   13446              :              If there is such a lambda-expression and if P is in E's function
   13447              :              parameter scope but not its parameter-declaration-clause, then the
   13448              :              type of the expression is the type of a class member access
   13449              :              expression naming the non-static data member that would be declared
   13450              :              for such a capture in the object parameter of the function call
   13451              :              operator of E."  */
   13452              :           /* FIXME: This transformation needs to happen for all uses of an outer
   13453              :              local variable inside decltype, not just decltype((x)) (PR83167).
   13454              :              And we don't handle nested lambdas properly, where we need to
   13455              :              consider the outer lambdas as well (PR112926). */
   13456          940 :           tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
   13457              :                                   LOOK_want::HIDDEN_LAMBDA);
   13458              : 
   13459          940 :           if (cap && is_capture_proxy (cap))
   13460          319 :             type = TREE_TYPE (cap);
   13461          621 :           else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
   13462              :             {
   13463          500 :               type = TREE_TYPE (decl);
   13464          500 :               if (TYPE_REF_P (type)
   13465          500 :                   && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
   13466           25 :                 type = TREE_TYPE (type);
   13467              :             }
   13468              : 
   13469          819 :           if (type && !TYPE_REF_P (type))
   13470              :             {
   13471          761 :               int quals;
   13472          761 :               if (current_function_decl
   13473         1428 :                   && LAMBDA_FUNCTION_P (current_function_decl)
   13474         1428 :                   && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
   13475              :                 {
   13476          600 :                   tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
   13477          600 :                   if (WILDCARD_TYPE_P (non_reference (obtype)))
   13478              :                     /* We don't know what the eventual obtype quals will be.  */
   13479          384 :                     goto dependent;
   13480          432 :                   auto direct_type = [](tree t){
   13481          216 :                       if (INDIRECT_TYPE_P (t))
   13482          108 :                         return TREE_TYPE (t);
   13483              :                       return t;
   13484              :                    };
   13485          432 :                   quals = (cp_type_quals (type)
   13486          216 :                            | cp_type_quals (direct_type (obtype)));
   13487              :                 }
   13488              :               else
   13489              :                 /* We are in the parameter clause, trailing return type, or
   13490              :                    the requires clause and have no relevant c_f_decl yet.  */
   13491          251 :                 quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
   13492          161 :                          ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
   13493          377 :               type = cp_build_qualified_type (type, quals);
   13494          377 :               type = build_reference_type (type);
   13495              :             }
   13496              :         }
   13497     29369857 :       else if (error_operand_p (expr))
   13498            0 :         type = error_mark_node;
   13499     29369857 :       else if (expr == current_class_ptr)
   13500              :         /* If the expression is just "this", we want the
   13501              :            cv-unqualified pointer for the "this" type.  */
   13502            0 :         type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
   13503              : 
   13504          377 :       if (!type)
   13505              :         {
   13506              :           /* Otherwise, where T is the type of e, if e is an lvalue,
   13507              :              decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
   13508     29369978 :           cp_lvalue_kind clk = lvalue_kind (expr);
   13509     29369978 :           type = unlowered_expr_type (expr);
   13510     29369978 :           gcc_assert (!TYPE_REF_P (type));
   13511              : 
   13512              :           /* For vector types, pick a non-opaque variant.  */
   13513     29369978 :           if (VECTOR_TYPE_P (type))
   13514         2078 :             type = strip_typedefs (type);
   13515              : 
   13516     29369978 :           if (clk != clk_none && !(clk & clk_class))
   13517      8326316 :             type = cp_build_reference_type (type, (clk & clk_rvalueref));
   13518              :         }
   13519              :     }
   13520              : 
   13521              :   return type;
   13522     36681495 : }
   13523              : 
   13524              : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
   13525              :    __has_nothrow_copy, depending on assign_p.  Returns true iff all
   13526              :    the copy {ctor,assign} fns are nothrow.  */
   13527              : 
   13528              : static bool
   13529          279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
   13530              : {
   13531          279 :   tree fns = NULL_TREE;
   13532              : 
   13533          279 :   if (assign_p || TYPE_HAS_COPY_CTOR (type))
   13534          276 :     fns = get_class_binding (type, assign_p ? assign_op_identifier
   13535              :                              : ctor_identifier);
   13536              : 
   13537          279 :   bool saw_copy = false;
   13538          696 :   for (ovl_iterator iter (fns); iter; ++iter)
   13539              :     {
   13540          441 :       tree fn = *iter;
   13541              : 
   13542          441 :       if (copy_fn_p (fn) > 0)
   13543              :         {
   13544          423 :           saw_copy = true;
   13545          423 :           if (!maybe_instantiate_noexcept (fn)
   13546          423 :               || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
   13547          192 :             return false;
   13548              :         }
   13549              :     }
   13550              : 
   13551           87 :   return saw_copy;
   13552              : }
   13553              : 
   13554              : /* Return true if BASE is a pointer-interconvertible base of DERIVED.  */
   13555              : 
   13556              : bool
   13557          157 : pointer_interconvertible_base_of_p (tree base, tree derived,
   13558              :                                     bool explain/*=false*/)
   13559              : {
   13560          157 :   if (base == error_mark_node || derived == error_mark_node)
   13561              :     return false;
   13562              : 
   13563          157 :   base = TYPE_MAIN_VARIANT (base);
   13564          157 :   derived = TYPE_MAIN_VARIANT (derived);
   13565          157 :   if (!NON_UNION_CLASS_TYPE_P (base))
   13566              :     {
   13567           15 :       if (explain)
   13568            3 :         inform (location_of (base),
   13569              :                 "%qT is not a non-union class type", base);
   13570           15 :       return false;
   13571              :     }
   13572          142 :   if (!NON_UNION_CLASS_TYPE_P (derived))
   13573              :     {
   13574            6 :       if (explain)
   13575            3 :         inform (location_of (derived),
   13576              :                 "%qT is not a non-union class type", derived);
   13577            6 :       return false;
   13578              :     }
   13579              : 
   13580          136 :   if (same_type_p (base, derived))
   13581              :     return true;
   13582              : 
   13583          106 :   if (!std_layout_type_p (derived))
   13584              :     {
   13585           17 :       if (explain)
   13586            6 :         inform (location_of (derived),
   13587              :                 "%qT is not a standard-layout type", derived);
   13588           17 :       return false;
   13589              :     }
   13590              : 
   13591           89 :   if (!uniquely_derived_from_p (base, derived))
   13592              :     {
   13593           16 :       if (explain)
   13594              :         {
   13595              :           /* An ambiguous base should already be impossible due to
   13596              :              the std_layout_type_p check.  */
   13597            3 :           gcc_checking_assert (!DERIVED_FROM_P (base, derived));
   13598            3 :           inform (location_of (derived),
   13599              :                   "%qT is not a base of %qT", base, derived);
   13600              :         }
   13601           16 :       return false;
   13602              :     }
   13603              : 
   13604              :   return true;
   13605              : }
   13606              : 
   13607              : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
   13608              :    return true if MEMBERTYPE is the type of the first non-static data member
   13609              :    of TYPE or for unions of any members.  */
   13610              : static bool
   13611          637 : first_nonstatic_data_member_p (tree type, tree membertype)
   13612              : {
   13613         1297 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   13614              :     {
   13615         1222 :       if (TREE_CODE (field) != FIELD_DECL)
   13616          135 :         continue;
   13617         1087 :       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
   13618           60 :         continue;
   13619         1027 :       if (DECL_FIELD_IS_BASE (field))
   13620           45 :         return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
   13621          982 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13622              :         {
   13623          216 :           if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
   13624          138 :                || std_layout_type_p (TREE_TYPE (field)))
   13625          294 :               && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
   13626              :             return true;
   13627              :         }
   13628          766 :       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13629              :                                                           membertype))
   13630              :         return true;
   13631          537 :       if (TREE_CODE (type) != UNION_TYPE)
   13632              :         return false;
   13633              :     }
   13634              :   return false;
   13635              : }
   13636              : 
   13637              : /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
   13638              : 
   13639              : tree
   13640          536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
   13641              :                                                      tree *args)
   13642              : {
   13643              :   /* Unless users call the builtin directly, the following 3 checks should be
   13644              :      ensured from std::is_pointer_interconvertible_with_class function
   13645              :      template.  */
   13646          536 :   if (nargs != 1)
   13647              :     {
   13648            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13649              :                      "needs a single argument");
   13650            6 :       return boolean_false_node;
   13651              :     }
   13652          530 :   tree arg = args[0];
   13653          530 :   if (error_operand_p (arg))
   13654            0 :     return boolean_false_node;
   13655          530 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
   13656              :     {
   13657            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13658              :                      "argument is not pointer to member");
   13659            6 :       return boolean_false_node;
   13660              :     }
   13661              : 
   13662          524 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
   13663           18 :     return boolean_false_node;
   13664              : 
   13665          506 :   tree membertype = TREE_TYPE (TREE_TYPE (arg));
   13666          506 :   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
   13667          506 :   if (!complete_type_or_else (basetype, NULL_TREE))
   13668            3 :     return boolean_false_node;
   13669              : 
   13670          503 :   if (TREE_CODE (basetype) != UNION_TYPE
   13671          503 :       && !std_layout_type_p (basetype))
   13672           22 :     return boolean_false_node;
   13673              : 
   13674          481 :   if (!first_nonstatic_data_member_p (basetype, membertype))
   13675          132 :     return boolean_false_node;
   13676              : 
   13677          349 :   if (TREE_CODE (arg) == PTRMEM_CST)
   13678           68 :     arg = cplus_expand_constant (arg);
   13679              : 
   13680          349 :   if (integer_nonzerop (arg))
   13681           10 :     return boolean_false_node;
   13682          339 :   if (integer_zerop (arg))
   13683           71 :     return boolean_true_node;
   13684              : 
   13685          268 :   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
   13686              :                       build_zero_cst (TREE_TYPE (arg)));
   13687              : }
   13688              : 
   13689              : /* Helper function for is_corresponding_member_aggr.  Return true if
   13690              :    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
   13691              :    union or structure BASETYPE.  */
   13692              : 
   13693              : static bool
   13694           90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
   13695              : {
   13696          222 :   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
   13697          192 :     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
   13698           36 :       continue;
   13699          156 :     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13700              :                                                         membertype))
   13701              :       {
   13702           48 :         if (TREE_CODE (arg) != INTEGER_CST
   13703           48 :             || tree_int_cst_equal (arg, byte_position (field)))
   13704           48 :           return true;
   13705              :       }
   13706          108 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13707              :       {
   13708           18 :         tree narg = arg;
   13709           18 :         if (TREE_CODE (basetype) != UNION_TYPE
   13710            0 :             && TREE_CODE (narg) == INTEGER_CST)
   13711            0 :           narg = size_binop (MINUS_EXPR, arg, byte_position (field));
   13712           18 :         if (is_corresponding_member_union (TREE_TYPE (field),
   13713              :                                            membertype, narg))
   13714              :           return true;
   13715              :       }
   13716              :   return false;
   13717              : }
   13718              : 
   13719              : /* Helper function for fold_builtin_is_corresponding_member call.
   13720              :    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
   13721              :    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
   13722              :    boolean_true_node if they are corresponding members, or for
   13723              :    non-constant ARG2 the highest member offset for corresponding
   13724              :    members.  */
   13725              : 
   13726              : static tree
   13727          550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
   13728              :                               tree arg1, tree basetype2, tree membertype2,
   13729              :                               tree arg2)
   13730              : {
   13731          550 :   tree field1 = TYPE_FIELDS (basetype1);
   13732          550 :   tree field2 = TYPE_FIELDS (basetype2);
   13733          550 :   tree ret = boolean_false_node;
   13734         2376 :   while (1)
   13735              :     {
   13736         1463 :       bool r = next_common_initial_sequence (field1, field2);
   13737         1463 :       if (field1 == NULL_TREE || field2 == NULL_TREE)
   13738              :         break;
   13739         1331 :       if (r
   13740         1038 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
   13741              :                                                         membertype1)
   13742         1841 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
   13743              :                                                         membertype2))
   13744              :         {
   13745          504 :           tree pos = byte_position (field1);
   13746          504 :           if (TREE_CODE (arg1) == INTEGER_CST
   13747          504 :               && tree_int_cst_equal (arg1, pos))
   13748              :             {
   13749           92 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13750           92 :                 return boolean_true_node;
   13751              :               return pos;
   13752              :             }
   13753          412 :           else if (TREE_CODE (arg1) != INTEGER_CST)
   13754         1188 :             ret = pos;
   13755              :         }
   13756         1654 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
   13757          944 :                && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
   13758              :         {
   13759          117 :           if ((!lookup_attribute ("no_unique_address",
   13760          117 :                                   DECL_ATTRIBUTES (field1)))
   13761          117 :               != !lookup_attribute ("no_unique_address",
   13762          117 :                                     DECL_ATTRIBUTES (field2)))
   13763              :             break;
   13764          117 :           if (!tree_int_cst_equal (bit_position (field1),
   13765          117 :                                    bit_position (field2)))
   13766              :             break;
   13767           99 :           bool overlap = true;
   13768           99 :           tree pos = byte_position (field1);
   13769           99 :           if (TREE_CODE (arg1) == INTEGER_CST)
   13770              :             {
   13771           27 :               tree off1 = fold_convert (sizetype, arg1);
   13772           27 :               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
   13773           27 :               if (tree_int_cst_lt (off1, pos)
   13774           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
   13775              :                 overlap = false;
   13776              :             }
   13777           99 :           if (TREE_CODE (arg2) == INTEGER_CST)
   13778              :             {
   13779           27 :               tree off2 = fold_convert (sizetype, arg2);
   13780           27 :               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
   13781           27 :               if (tree_int_cst_lt (off2, pos)
   13782           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
   13783              :                 overlap = false;
   13784              :             }
   13785           87 :           if (overlap
   13786           87 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
   13787          126 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
   13788              :             {
   13789           39 :               tree narg1 = arg1;
   13790           39 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13791            9 :                 narg1 = size_binop (MINUS_EXPR,
   13792              :                                     fold_convert (sizetype, arg1), pos);
   13793           39 :               tree narg2 = arg2;
   13794           39 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13795            9 :                 narg2 = size_binop (MINUS_EXPR,
   13796              :                                     fold_convert (sizetype, arg2), pos);
   13797           39 :               tree t1 = TREE_TYPE (field1);
   13798           39 :               tree t2 = TREE_TYPE (field2);
   13799           39 :               tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
   13800              :                                                         narg1, t2, membertype2,
   13801              :                                                         narg2);
   13802           39 :               if (nret != boolean_false_node)
   13803              :                 {
   13804           39 :                   if (nret == boolean_true_node)
   13805              :                     return nret;
   13806           30 :                   if (TREE_CODE (arg1) == INTEGER_CST)
   13807            0 :                     return size_binop (PLUS_EXPR, nret, pos);
   13808           30 :                   ret = size_binop (PLUS_EXPR, nret, pos);
   13809              :                 }
   13810              :             }
   13811           60 :           else if (overlap
   13812           48 :                    && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
   13813          108 :                    && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
   13814              :             {
   13815           48 :               tree narg1 = arg1;
   13816           48 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13817            6 :                 narg1 = size_binop (MINUS_EXPR,
   13818              :                                     fold_convert (sizetype, arg1), pos);
   13819           48 :               tree narg2 = arg2;
   13820           48 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13821            6 :                 narg2 = size_binop (MINUS_EXPR,
   13822              :                                     fold_convert (sizetype, arg2), pos);
   13823           48 :               if (is_corresponding_member_union (TREE_TYPE (field1),
   13824              :                                                  membertype1, narg1)
   13825           48 :                   && is_corresponding_member_union (TREE_TYPE (field2),
   13826              :                                                     membertype2, narg2))
   13827              :                 {
   13828           24 :                   sorry_at (loc, "%<__builtin_is_corresponding_member%> "
   13829              :                                  "not well defined for anonymous unions");
   13830           24 :                   return boolean_false_node;
   13831              :                 }
   13832              :             }
   13833              :         }
   13834         1188 :       if (!r)
   13835              :         break;
   13836          913 :       field1 = DECL_CHAIN (field1);
   13837          913 :       field2 = DECL_CHAIN (field2);
   13838          913 :     }
   13839              :   return ret;
   13840              : }
   13841              : 
   13842              : /* Fold __builtin_is_corresponding_member call.  */
   13843              : 
   13844              : tree
   13845          699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
   13846              :                                       tree *args)
   13847              : {
   13848              :   /* Unless users call the builtin directly, the following 3 checks should be
   13849              :      ensured from std::is_corresponding_member function template.  */
   13850          699 :   if (nargs != 2)
   13851              :     {
   13852            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13853              :                      "needs two arguments");
   13854            9 :       return boolean_false_node;
   13855              :     }
   13856          690 :   tree arg1 = args[0];
   13857          690 :   tree arg2 = args[1];
   13858          690 :   if (error_operand_p (arg1) || error_operand_p (arg2))
   13859            0 :     return boolean_false_node;
   13860          711 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
   13861          705 :       || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
   13862              :     {
   13863            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13864              :                      "argument is not pointer to member");
   13865            9 :       return boolean_false_node;
   13866              :     }
   13867              : 
   13868          681 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
   13869          681 :       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
   13870           15 :     return boolean_false_node;
   13871              : 
   13872          666 :   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
   13873          666 :   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
   13874          666 :   if (!complete_type_or_else (basetype1, NULL_TREE))
   13875           12 :     return boolean_false_node;
   13876              : 
   13877          654 :   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
   13878          654 :   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
   13879          654 :   if (!complete_type_or_else (basetype2, NULL_TREE))
   13880           12 :     return boolean_false_node;
   13881              : 
   13882          627 :   if (!NON_UNION_CLASS_TYPE_P (basetype1)
   13883          627 :       || !NON_UNION_CLASS_TYPE_P (basetype2)
   13884          627 :       || !std_layout_type_p (basetype1)
   13885         1233 :       || !std_layout_type_p (basetype2))
   13886           51 :     return boolean_false_node;
   13887              : 
   13888              :   /* If the member types aren't layout compatible, then they
   13889              :      can't be corresponding members.  */
   13890          591 :   if (!layout_compatible_type_p (membertype1, membertype2))
   13891           18 :     return boolean_false_node;
   13892              : 
   13893          573 :   if (TREE_CODE (arg1) == PTRMEM_CST)
   13894          176 :     arg1 = cplus_expand_constant (arg1);
   13895          573 :   if (TREE_CODE (arg2) == PTRMEM_CST)
   13896          182 :     arg2 = cplus_expand_constant (arg2);
   13897              : 
   13898          573 :   if (null_member_pointer_value_p (arg1)
   13899          573 :       || null_member_pointer_value_p (arg2))
   13900            9 :     return boolean_false_node;
   13901              : 
   13902          564 :   if (TREE_CODE (arg1) == INTEGER_CST
   13903          182 :       && TREE_CODE (arg2) == INTEGER_CST
   13904          746 :       && !tree_int_cst_equal (arg1, arg2))
   13905           53 :     return boolean_false_node;
   13906              : 
   13907          511 :   if (TREE_CODE (arg2) == INTEGER_CST
   13908          129 :       && TREE_CODE (arg1) != INTEGER_CST)
   13909              :     {
   13910              :       std::swap (arg1, arg2);
   13911              :       std::swap (membertype1, membertype2);
   13912              :       std::swap (basetype1, basetype2);
   13913              :     }
   13914              : 
   13915          511 :   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
   13916              :                                            basetype2, membertype2, arg2);
   13917          511 :   if (TREE_TYPE (ret) == boolean_type_node)
   13918              :     return ret;
   13919              :   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
   13920              :      already returns boolean_{true,false}_node whether those particular
   13921              :      members are corresponding members or not.  Otherwise, if only
   13922              :      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
   13923              :      above), it returns boolean_false_node if it is certainly not a
   13924              :      corresponding member and otherwise we need to do a runtime check that
   13925              :      those two OFFSET_TYPE offsets are equal.
   13926              :      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
   13927              :      returns the largest offset at which the members would be corresponding
   13928              :      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
   13929          304 :   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
   13930          304 :   if (TREE_CODE (arg1) == INTEGER_CST)
   13931            0 :     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13932              :                         fold_convert (TREE_TYPE (arg1), arg2));
   13933          304 :   ret = fold_build2 (LE_EXPR, boolean_type_node,
   13934              :                      fold_convert (pointer_sized_int_node, arg1),
   13935              :                      fold_convert (pointer_sized_int_node, ret));
   13936          304 :   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
   13937              :                       fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13938              :                                    fold_convert (TREE_TYPE (arg1), arg2)));
   13939              : }
   13940              : 
   13941              : /* Fold __builtin_is_string_literal call.  */
   13942              : 
   13943              : tree
   13944         2008 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
   13945              : {
   13946              :   /* Unless users call the builtin directly, the following 3 checks should be
   13947              :      ensured from std::is_string_literal overloads.  */
   13948         2008 :   if (nargs != 1)
   13949              :     {
   13950            0 :       error_at (loc, "%<__builtin_is_string_literal%> needs a single "
   13951              :                 "argument");
   13952            0 :       return boolean_false_node;
   13953              :     }
   13954         2008 :   tree arg = args[0];
   13955         2008 :   if (error_operand_p (arg))
   13956            0 :     return boolean_false_node;
   13957         2008 :   if (!TYPE_PTR_P (TREE_TYPE (arg))
   13958         2008 :       || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
   13959         4016 :       || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
   13960              :     {
   13961            0 :     arg_invalid:
   13962            0 :       error_at (loc, "%<__builtin_is_string_literal%> "
   13963              :                      "argument is not %<const char*%>, %<const wchar_t*%>, "
   13964              :                      "%<const char8_t*%>, %<const char16_t*%> or "
   13965              :                      "%<const char32_t*%>");
   13966            0 :       return boolean_false_node;
   13967              :     }
   13968         2008 :   tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
   13969         2008 :   if (chart != char_type_node
   13970         1604 :       && chart != wchar_type_node
   13971         1203 :       && chart != char8_type_node
   13972          802 :       && chart != char16_type_node
   13973          401 :       && chart != char32_type_node)
   13974            0 :     goto arg_invalid;
   13975              : 
   13976         2008 :   STRIP_NOPS (arg);
   13977         4022 :   while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
   13978              :     {
   13979            6 :       arg = TREE_OPERAND (arg, 0);
   13980            6 :       STRIP_NOPS (arg);
   13981              :     }
   13982         2008 :   if (TREE_CODE (arg) != ADDR_EXPR)
   13983         1980 :     return boolean_false_node;
   13984           28 :   arg = TREE_OPERAND (arg, 0);
   13985           28 :   if (TREE_CODE (arg) == ARRAY_REF)
   13986           12 :     arg = TREE_OPERAND (arg, 0);
   13987           28 :   if (TREE_CODE (arg) != STRING_CST)
   13988            8 :     return boolean_false_node;
   13989           20 :   return boolean_true_node;
   13990              : }
   13991              : 
   13992              : /* [basic.types] 8.  True iff TYPE is an object type.  */
   13993              : 
   13994              : static bool
   13995      2753882 : object_type_p (const_tree type)
   13996              : {
   13997      2753882 :   return (TREE_CODE (type) != FUNCTION_TYPE
   13998            0 :           && !TYPE_REF_P (type)
   13999      2753882 :           && !VOID_TYPE_P (type));
   14000              : }
   14001              : 
   14002              : /* [defns.referenceable] True iff TYPE is a referenceable type.  */
   14003              : 
   14004              : static bool
   14005      3353816 : referenceable_type_p (const_tree type)
   14006              : {
   14007      3353816 :   return (TYPE_REF_P (type)
   14008      3354213 :           || object_type_p (type)
   14009      3354213 :           || (FUNC_OR_METHOD_TYPE_P (type)
   14010          334 :               && type_memfn_quals (type) == TYPE_UNQUALIFIED
   14011          274 :               && type_memfn_rqual (type) == REF_QUAL_NONE));
   14012              : }
   14013              : 
   14014              : /* Actually evaluates the trait.  */
   14015              : 
   14016              : static bool
   14017     16853797 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
   14018              : {
   14019     16853797 :   enum tree_code type_code1;
   14020     16853797 :   tree t;
   14021              : 
   14022     16853797 :   type_code1 = TREE_CODE (type1);
   14023              : 
   14024     16853797 :   switch (kind)
   14025              :     {
   14026          317 :     case CPTK_HAS_NOTHROW_ASSIGN:
   14027          317 :       type1 = strip_array_types (type1);
   14028          601 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14029          601 :               && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
   14030          173 :                   || (CLASS_TYPE_P (type1)
   14031          129 :                       && classtype_has_nothrow_assign_or_copy_p (type1,
   14032              :                                                                  true))));
   14033              : 
   14034          215 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   14035          215 :       type1 = strip_array_types (type1);
   14036          215 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
   14037          215 :               || (CLASS_TYPE_P (type1)
   14038           93 :                   && (t = locate_ctor (type1))
   14039           60 :                   && maybe_instantiate_noexcept (t)
   14040           58 :                   && TYPE_NOTHROW_P (TREE_TYPE (t))));
   14041              : 
   14042          305 :     case CPTK_HAS_NOTHROW_COPY:
   14043          305 :       type1 = strip_array_types (type1);
   14044          305 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
   14045          305 :               || (CLASS_TYPE_P (type1)
   14046          150 :                   && classtype_has_nothrow_assign_or_copy_p (type1, false)));
   14047              : 
   14048          517 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   14049              :       /* ??? The standard seems to be missing the "or array of such a class
   14050              :          type" wording for this trait.  */
   14051          517 :       type1 = strip_array_types (type1);
   14052         1016 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14053         1001 :               && (trivial_type_p (type1)
   14054          307 :                     || (CLASS_TYPE_P (type1)
   14055          222 :                         && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
   14056              : 
   14057          542 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   14058          542 :       type1 = strip_array_types (type1);
   14059          542 :       return (trivial_type_p (type1)
   14060          542 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
   14061              : 
   14062          526 :     case CPTK_HAS_TRIVIAL_COPY:
   14063              :       /* ??? The standard seems to be missing the "or array of such a class
   14064              :          type" wording for this trait.  */
   14065          526 :       type1 = strip_array_types (type1);
   14066          878 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14067          863 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
   14068              : 
   14069          761 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   14070          761 :       type1 = strip_array_types (type1);
   14071          761 :       if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
   14072              :         {
   14073          123 :           deferring_access_check_sentinel dacs (dk_no_check);
   14074          123 :           cp_unevaluated un;
   14075          123 :           tree fn = get_dtor (type1, tf_none);
   14076          123 :           if (!fn && !seen_error ())
   14077            3 :             warning (0, "checking %qs for type %qT with a destructor that "
   14078              :                      "cannot be called", "__has_trivial_destructor", type1);
   14079          123 :         }
   14080         1092 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14081         1089 :               || (CLASS_TYPE_P (type1)
   14082          284 :                   && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
   14083              : 
   14084        58199 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   14085        58199 :       return type_has_unique_obj_representations (type1);
   14086              : 
   14087          279 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   14088          279 :       return type_has_virtual_destructor (type1);
   14089              : 
   14090        54799 :     case CPTK_IS_ABSTRACT:
   14091        54799 :       return ABSTRACT_CLASS_TYPE_P (type1);
   14092              : 
   14093          813 :     case CPTK_IS_AGGREGATE:
   14094          813 :       return CP_AGGREGATE_TYPE_P (type1);
   14095              : 
   14096       326459 :     case CPTK_IS_ARRAY:
   14097       326459 :       return (type_code1 == ARRAY_TYPE
   14098              :               /* We don't want to report T[0] as being an array type.
   14099              :                  This is for compatibility with an implementation of
   14100              :                  std::is_array by template argument deduction, because
   14101              :                  compute_array_index_type_loc rejects a zero-size array
   14102              :                  in SFINAE context.  */
   14103       326459 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14104              : 
   14105       973261 :     case CPTK_IS_ASSIGNABLE:
   14106       973261 :       return is_xible (MODIFY_EXPR, type1, type2);
   14107              : 
   14108       471550 :     case CPTK_IS_BASE_OF:
   14109       471459 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14110       924775 :               && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
   14111       427866 :                   || DERIVED_FROM_P (type1, type2)));
   14112              : 
   14113        43022 :     case CPTK_IS_BOUNDED_ARRAY:
   14114        43022 :       return (type_code1 == ARRAY_TYPE
   14115         1263 :               && TYPE_DOMAIN (type1)
   14116              :               /* We don't want to report T[0] as being a bounded array type.
   14117              :                  This is for compatibility with an implementation of
   14118              :                  std::is_bounded_array by template argument deduction, because
   14119              :                  compute_array_index_type_loc rejects a zero-size array
   14120              :                  in SFINAE context.  */
   14121        44169 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14122              : 
   14123       486249 :     case CPTK_IS_CLASS:
   14124       486249 :       return NON_UNION_CLASS_TYPE_P (type1);
   14125              : 
   14126       548065 :     case CPTK_IS_CONST:
   14127       548065 :       return CP_TYPE_CONST_P (type1);
   14128              : 
   14129      2235115 :     case CPTK_IS_CONSTRUCTIBLE:
   14130      2235115 :       return is_xible (INIT_EXPR, type1, type2);
   14131              : 
   14132      2958755 :     case CPTK_IS_CONVERTIBLE:
   14133      2958755 :       return is_convertible (type1, type2);
   14134              : 
   14135         2057 :     case CPTK_IS_DESTRUCTIBLE:
   14136         2057 :       return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14137              : 
   14138       210910 :     case CPTK_IS_EMPTY:
   14139       210910 :       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
   14140              : 
   14141       634041 :     case CPTK_IS_ENUM:
   14142       634041 :       return type_code1 == ENUMERAL_TYPE;
   14143              : 
   14144       416904 :     case CPTK_IS_FINAL:
   14145       416904 :       return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
   14146              : 
   14147        45238 :     case CPTK_IS_FUNCTION:
   14148        45238 :       return type_code1 == FUNCTION_TYPE;
   14149              : 
   14150          800 :     case CPTK_IS_IMPLICIT_LIFETIME:
   14151          800 :       return implicit_lifetime_type_p (type1);
   14152              : 
   14153        47081 :     case CPTK_IS_INVOCABLE:
   14154        47081 :       return !error_operand_p (build_invoke (type1, type2, tf_none));
   14155              : 
   14156          195 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   14157          195 :       return layout_compatible_type_p (type1, type2);
   14158              : 
   14159          197 :     case CPTK_IS_LITERAL_TYPE:
   14160          197 :       return literal_type_p (type1);
   14161              : 
   14162        46792 :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   14163        46792 :       return TYPE_PTRMEMFUNC_P (type1);
   14164              : 
   14165        46761 :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   14166        46761 :       return TYPE_PTRDATAMEM_P (type1);
   14167              : 
   14168        10370 :     case CPTK_IS_MEMBER_POINTER:
   14169        10370 :       return TYPE_PTRMEM_P (type1);
   14170              : 
   14171       435019 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   14172       435019 :       return is_nothrow_xible (MODIFY_EXPR, type1, type2);
   14173              : 
   14174       882860 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14175       882860 :       return is_nothrow_xible (INIT_EXPR, type1, type2);
   14176              : 
   14177          667 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14178          667 :       return is_nothrow_convertible (type1, type2);
   14179              : 
   14180        23405 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   14181        23405 :       return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14182              : 
   14183        41407 :     case CPTK_IS_NOTHROW_INVOCABLE:
   14184        41407 :       return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
   14185              : 
   14186      1063899 :     case CPTK_IS_OBJECT:
   14187      1063899 :       return object_type_p (type1);
   14188              : 
   14189          142 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   14190          142 :       return pointer_interconvertible_base_of_p (type1, type2);
   14191              : 
   14192        11199 :     case CPTK_IS_POD:
   14193        11199 :       return pod_type_p (type1);
   14194              : 
   14195       145860 :     case CPTK_IS_POINTER:
   14196       145860 :       return TYPE_PTR_P (type1);
   14197              : 
   14198          271 :     case CPTK_IS_POLYMORPHIC:
   14199          271 :       return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
   14200              : 
   14201       670055 :     case CPTK_IS_REFERENCE:
   14202       670055 :       return type_code1 == REFERENCE_TYPE;
   14203              : 
   14204      2455586 :     case CPTK_IS_SAME:
   14205      2455586 :       return same_type_p (type1, type2);
   14206              : 
   14207          373 :     case CPTK_IS_SCOPED_ENUM:
   14208          373 :       return SCOPED_ENUM_P (type1);
   14209              : 
   14210        59583 :     case CPTK_IS_STD_LAYOUT:
   14211        59583 :       return std_layout_type_p (type1);
   14212              : 
   14213        56178 :     case CPTK_IS_TRIVIAL:
   14214        56178 :       return trivial_type_p (type1);
   14215              : 
   14216        10284 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   14217        10284 :       return is_trivially_xible (MODIFY_EXPR, type1, type2);
   14218              : 
   14219        68917 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14220        68917 :       return is_trivially_xible (INIT_EXPR, type1, type2);
   14221              : 
   14222        94357 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   14223        94357 :       return trivially_copyable_p (type1);
   14224              : 
   14225        25060 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   14226        25060 :       return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14227              : 
   14228        93529 :     case CPTK_IS_UNBOUNDED_ARRAY:
   14229        93529 :       return array_of_unknown_bound_p (type1);
   14230              : 
   14231       256004 :     case CPTK_IS_UNION:
   14232       256004 :       return type_code1 == UNION_TYPE;
   14233              : 
   14234          712 :     case CPTK_IS_VIRTUAL_BASE_OF:
   14235          646 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14236         1342 :               && lookup_base (type2, type1, ba_require_virtual,
   14237              :                               NULL, tf_none) != NULL_TREE);
   14238              : 
   14239       573095 :     case CPTK_IS_VOLATILE:
   14240       573095 :       return CP_TYPE_VOLATILE_P (type1);
   14241              : 
   14242       211876 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14243       211876 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
   14244              : 
   14245        52148 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14246        52148 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
   14247              : 
   14248           85 :     case CPTK_IS_DEDUCIBLE:
   14249           85 :       return type_targs_deducible_from (type1, type2);
   14250              : 
   14251          131 :     case CPTK_IS_STRUCTURAL:
   14252          131 :       return structural_type_p (type1);
   14253              : 
   14254              :     /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
   14255              :        are handled in finish_trait_expr.  */
   14256            0 :     case CPTK_RANK:
   14257            0 :     case CPTK_TYPE_ORDER:
   14258            0 :     case CPTK_STRUCTURED_BINDING_SIZE:
   14259            0 :       gcc_unreachable ();
   14260              : 
   14261              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14262              :     case CPTK_##CODE:
   14263              : #include "cp-trait.def"
   14264              : #undef DEFTRAIT_TYPE
   14265              :       /* Type-yielding traits are handled in finish_trait_type.  */
   14266              :       break;
   14267              :     }
   14268              : 
   14269            0 :   gcc_unreachable ();
   14270              : }
   14271              : 
   14272              : /* Returns true if TYPE meets the requirements for the specified KIND,
   14273              :    false otherwise.
   14274              : 
   14275              :    When KIND == 1, TYPE must be an array of unknown bound,
   14276              :    or (possibly cv-qualified) void, or a complete type.
   14277              : 
   14278              :    When KIND == 2, TYPE must be a complete type, or array of complete type,
   14279              :    or (possibly cv-qualified) void.
   14280              : 
   14281              :    When KIND == 3:
   14282              :    If TYPE is a non-union class type, it must be complete.
   14283              : 
   14284              :    When KIND == 4:
   14285              :    If TYPE is a class type, it must be complete.  */
   14286              : 
   14287              : static bool
   14288     17808308 : check_trait_type (tree type, int kind = 1)
   14289              : {
   14290     17808308 :   if (type == NULL_TREE)
   14291              :     return true;
   14292              : 
   14293     17808308 :   if (TREE_CODE (type) == TREE_VEC)
   14294              :     {
   14295      5816017 :       for (tree arg : tree_vec_range (type))
   14296      2544624 :         if (!check_trait_type (arg, kind))
   14297           21 :           return false;
   14298      3271393 :       return true;
   14299              :     }
   14300              : 
   14301     14536894 :   if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   14302              :     return true; // Array of unknown bound. Don't care about completeness.
   14303              : 
   14304     14536350 :   if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
   14305              :     return true; // Not a non-union class type. Don't care about completeness.
   14306              : 
   14307     14424669 :   if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
   14308              :     return true; // Not a class type. Don't care about completeness.
   14309              : 
   14310     14424184 :   if (VOID_TYPE_P (type))
   14311              :     return true;
   14312              : 
   14313     14423084 :   type = complete_type (strip_array_types (type));
   14314     14423084 :   if (!COMPLETE_TYPE_P (type)
   14315          152 :       && cxx_incomplete_type_diagnostic (NULL_TREE, type,
   14316              :                                          diagnostics::kind::permerror)
   14317     14423236 :       && !flag_permissive)
   14318              :     return false;
   14319              :   return true;
   14320              : }
   14321              : 
   14322              : /* True iff the conversion (if any) would be a direct reference
   14323              :    binding, not requiring complete types.  This is LWG2939.  */
   14324              : 
   14325              : static bool
   14326      6498886 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
   14327              : {
   14328      6498886 :   tree from, to;
   14329      6498886 :   switch (kind)
   14330              :     {
   14331              :       /* These put the target type first.  */
   14332              :     case CPTK_IS_CONSTRUCTIBLE:
   14333              :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14334              :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14335              :     case CPTK_IS_INVOCABLE:
   14336              :     case CPTK_IS_NOTHROW_INVOCABLE:
   14337              :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14338              :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14339              :       to = type1;
   14340              :       from = type2;
   14341              :       break;
   14342              : 
   14343              :       /* These put it second.  */
   14344      2959422 :     case CPTK_IS_CONVERTIBLE:
   14345      2959422 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14346      2959422 :       to = type2;
   14347      2959422 :       from = type1;
   14348      2959422 :       break;
   14349              : 
   14350            0 :     default:
   14351            0 :       gcc_unreachable ();
   14352              :     }
   14353              : 
   14354      6498886 :   if (TREE_CODE (to) != REFERENCE_TYPE || !from)
   14355              :     return false;
   14356       860325 :   if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
   14357        59567 :     from = TREE_VEC_ELT (from, 0);
   14358       860325 :   return (TYPE_P (from)
   14359      1711853 :           && (same_type_ignoring_top_level_qualifiers_p
   14360       851528 :               (non_reference (to), non_reference (from))));
   14361              : }
   14362              : 
   14363              : /* Helper for finish_trait_expr and tsubst_expr.  Handle
   14364              :    CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
   14365              :    way.  */
   14366              : 
   14367              : tree
   14368          273 : finish_structured_binding_size (location_t loc, tree type,
   14369              :                                 tsubst_flags_t complain)
   14370              : {
   14371          273 :   if (TYPE_REF_P (type))
   14372              :     {
   14373          105 :       if (complain & tf_error)
   14374           99 :         error_at (loc, "%qs argument %qT is a reference",
   14375              :                   "__builtin_structured_binding_size", type);
   14376          105 :       return error_mark_node;
   14377              :     }
   14378          168 :   HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
   14379          168 :   if (ret == -1)
   14380           63 :     return error_mark_node;
   14381          105 :   return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
   14382              : }
   14383              : 
   14384              : /* Process a trait expression.  */
   14385              : 
   14386              : tree
   14387     20079273 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
   14388              : {
   14389     20079273 :   if (type1 == error_mark_node
   14390     20079270 :       || type2 == error_mark_node)
   14391              :     return error_mark_node;
   14392              : 
   14393     20079270 :   if (processing_template_decl)
   14394              :     {
   14395      3225697 :       tree trait_expr = make_node (TRAIT_EXPR);
   14396      3225697 :       if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
   14397        30241 :         TREE_TYPE (trait_expr) = size_type_node;
   14398      3195456 :       else if (kind == CPTK_TYPE_ORDER)
   14399              :         {
   14400         3024 :           tree val = type_order_value (type1, type1);
   14401         3024 :           if (val != error_mark_node)
   14402         3024 :             TREE_TYPE (trait_expr) = TREE_TYPE (val);
   14403              :         }
   14404              :       else
   14405      3192432 :         TREE_TYPE (trait_expr) = boolean_type_node;
   14406      3225697 :       TRAIT_EXPR_TYPE1 (trait_expr) = type1;
   14407      3225697 :       TRAIT_EXPR_TYPE2 (trait_expr) = type2;
   14408      3225697 :       TRAIT_EXPR_KIND (trait_expr) = kind;
   14409      3225697 :       TRAIT_EXPR_LOCATION (trait_expr) = loc;
   14410      3225697 :       return trait_expr;
   14411              :     }
   14412              : 
   14413     16853573 :   switch (kind)
   14414              :     {
   14415        52922 :     case CPTK_HAS_NOTHROW_ASSIGN:
   14416        52922 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   14417        52922 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   14418        52922 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   14419        52922 :     case CPTK_HAS_NOTHROW_COPY:
   14420        52922 :     case CPTK_HAS_TRIVIAL_COPY:
   14421        52922 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   14422        52922 :     case CPTK_IS_DESTRUCTIBLE:
   14423        52922 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   14424        52922 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   14425        52922 :       if (!check_trait_type (type1))
   14426           21 :         return error_mark_node;
   14427              :       break;
   14428              : 
   14429       279877 :     case CPTK_IS_LITERAL_TYPE:
   14430       279877 :     case CPTK_IS_POD:
   14431       279877 :     case CPTK_IS_STD_LAYOUT:
   14432       279877 :     case CPTK_IS_TRIVIAL:
   14433       279877 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   14434       279877 :     case CPTK_IS_STRUCTURAL:
   14435       279877 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   14436       279877 :       if (!check_trait_type (type1, /* kind = */ 2))
   14437           33 :         return error_mark_node;
   14438              :       break;
   14439              : 
   14440       266274 :     case CPTK_IS_ABSTRACT:
   14441       266274 :     case CPTK_IS_EMPTY:
   14442       266274 :     case CPTK_IS_POLYMORPHIC:
   14443       266274 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   14444       266274 :       if (!check_trait_type (type1, /* kind = */ 3))
   14445           15 :         return error_mark_node;
   14446              :       break;
   14447              : 
   14448              :     /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
   14449              :        type to know whether an array is an aggregate, so use kind=4 here.  */
   14450       418534 :     case CPTK_IS_AGGREGATE:
   14451       418534 :     case CPTK_IS_FINAL:
   14452       418534 :     case CPTK_IS_IMPLICIT_LIFETIME:
   14453       418534 :       if (!check_trait_type (type1, /* kind = */ 4))
   14454           17 :         return error_mark_node;
   14455              :       break;
   14456              : 
   14457      6498886 :     case CPTK_IS_CONSTRUCTIBLE:
   14458      6498886 :     case CPTK_IS_CONVERTIBLE:
   14459      6498886 :     case CPTK_IS_INVOCABLE:
   14460      6498886 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14461      6498886 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14462      6498886 :     case CPTK_IS_NOTHROW_INVOCABLE:
   14463      6498886 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14464      6498886 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14465      6498886 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14466      6498886 :       /* Don't check completeness for direct reference binding.  */;
   14467      6498886 :       if (same_type_ref_bind_p (kind, type1, type2))
   14468              :         break;
   14469      7123058 :       gcc_fallthrough ();
   14470              : 
   14471      7123058 :     case CPTK_IS_ASSIGNABLE:
   14472      7123058 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   14473      7123058 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   14474      7123058 :       if (!check_trait_type (type1)
   14475      7123058 :           || !check_trait_type (type2))
   14476           63 :         return error_mark_node;
   14477              :       break;
   14478              : 
   14479       471695 :     case CPTK_IS_BASE_OF:
   14480       471695 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   14481       471592 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14482       453355 :           && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
   14483       899661 :           && !complete_type_or_else (type2, NULL_TREE))
   14484              :         /* We already issued an error.  */
   14485            3 :         return error_mark_node;
   14486              :       break;
   14487              : 
   14488          715 :     case CPTK_IS_VIRTUAL_BASE_OF:
   14489          649 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14490         1348 :           && !complete_type_or_else (type2, NULL_TREE))
   14491              :         /* We already issued an error.  */
   14492            3 :         return error_mark_node;
   14493              :       break;
   14494              : 
   14495              :     case CPTK_IS_ARRAY:
   14496              :     case CPTK_IS_BOUNDED_ARRAY:
   14497              :     case CPTK_IS_CLASS:
   14498              :     case CPTK_IS_CONST:
   14499              :     case CPTK_IS_ENUM:
   14500              :     case CPTK_IS_FUNCTION:
   14501              :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   14502              :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   14503              :     case CPTK_IS_MEMBER_POINTER:
   14504              :     case CPTK_IS_OBJECT:
   14505              :     case CPTK_IS_POINTER:
   14506              :     case CPTK_IS_REFERENCE:
   14507              :     case CPTK_IS_SAME:
   14508              :     case CPTK_IS_SCOPED_ENUM:
   14509              :     case CPTK_IS_UNBOUNDED_ARRAY:
   14510              :     case CPTK_IS_UNION:
   14511              :     case CPTK_IS_VOLATILE:
   14512              :       break;
   14513              : 
   14514              :     case CPTK_RANK:
   14515              :       {
   14516              :         size_t rank = 0;
   14517          122 :         for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
   14518           80 :           ++rank;
   14519           42 :         return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
   14520              :                                          loc);
   14521              :       }
   14522              : 
   14523          230 :     case CPTK_TYPE_ORDER:
   14524          230 :       return maybe_wrap_with_location (type_order_value (type1, type2), loc);
   14525              : 
   14526          144 :     case CPTK_STRUCTURED_BINDING_SIZE:
   14527          144 :       return finish_structured_binding_size (loc, type1, tf_warning_or_error);
   14528              : 
   14529          204 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   14530          204 :       if (!array_of_unknown_bound_p (type1)
   14531          189 :           && TREE_CODE (type1) != VOID_TYPE
   14532          387 :           && !complete_type_or_else (type1, NULL_TREE))
   14533              :         /* We already issued an error.  */
   14534            6 :         return error_mark_node;
   14535          198 :       if (!array_of_unknown_bound_p (type2)
   14536          177 :           && TREE_CODE (type2) != VOID_TYPE
   14537          369 :           && !complete_type_or_else (type2, NULL_TREE))
   14538              :         /* We already issued an error.  */
   14539            3 :         return error_mark_node;
   14540              :       break;
   14541              : 
   14542           85 :     case CPTK_IS_DEDUCIBLE:
   14543           85 :       if (!DECL_TYPE_TEMPLATE_P (type1))
   14544              :         {
   14545            0 :           error ("%qD is not a class or alias template", type1);
   14546            0 :           return error_mark_node;
   14547              :         }
   14548              :       break;
   14549              : 
   14550              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14551              :     case CPTK_##CODE:
   14552              : #include "cp-trait.def"
   14553              : #undef DEFTRAIT_TYPE
   14554              :       /* Type-yielding traits are handled in finish_trait_type.  */
   14555            0 :       gcc_unreachable ();
   14556              :     }
   14557              : 
   14558     16852993 :   tree val = (trait_expr_value (kind, type1, type2)
   14559     16852993 :               ? boolean_true_node : boolean_false_node);
   14560     16852993 :   return maybe_wrap_with_location (val, loc);
   14561              : }
   14562              : 
   14563              : /* Process a trait type.  */
   14564              : 
   14565              : tree
   14566      7458135 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
   14567              :                    tsubst_flags_t complain)
   14568              : {
   14569      7458135 :   if (type1 == error_mark_node
   14570      7458132 :       || type2 == error_mark_node)
   14571              :     return error_mark_node;
   14572              : 
   14573      7458132 :   if (processing_template_decl)
   14574              :     {
   14575       221606 :       tree type = cxx_make_type (TRAIT_TYPE);
   14576       221606 :       TRAIT_TYPE_TYPE1 (type) = type1;
   14577       221606 :       TRAIT_TYPE_TYPE2 (type) = type2;
   14578       221606 :       TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
   14579              :       /* These traits are intended to be used in the definition of the ::type
   14580              :          member of the corresponding standard library type trait and aren't
   14581              :          mangleable (and thus won't appear directly in template signatures),
   14582              :          so structural equality should suffice.  */
   14583       221606 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   14584       221606 :       return type;
   14585              :     }
   14586              : 
   14587      7236526 :   switch (kind)
   14588              :     {
   14589      1170749 :     case CPTK_ADD_LVALUE_REFERENCE:
   14590              :       /* [meta.trans.ref].  */
   14591      1170749 :       if (referenceable_type_p (type1))
   14592      1170673 :         return cp_build_reference_type (type1, /*rval=*/false);
   14593              :       return type1;
   14594              : 
   14595       599564 :     case CPTK_ADD_POINTER:
   14596              :       /* [meta.trans.ptr].  */
   14597       599564 :       if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
   14598              :         {
   14599       599532 :           if (TYPE_REF_P (type1))
   14600       598470 :             type1 = TREE_TYPE (type1);
   14601       599532 :           return build_pointer_type (type1);
   14602              :         }
   14603              :       return type1;
   14604              : 
   14605      1583523 :     case CPTK_ADD_RVALUE_REFERENCE:
   14606              :       /* [meta.trans.ref].  */
   14607      1583523 :       if (referenceable_type_p (type1))
   14608      1583470 :         return cp_build_reference_type (type1, /*rval=*/true);
   14609              :       return type1;
   14610              : 
   14611       223127 :     case CPTK_DECAY:
   14612       223127 :       if (TYPE_REF_P (type1))
   14613        41398 :         type1 = TREE_TYPE (type1);
   14614              : 
   14615       223127 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14616          671 :         return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
   14617          671 :                                   complain);
   14618       222456 :       else if (TREE_CODE (type1) == FUNCTION_TYPE)
   14619          178 :         return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
   14620              :       else
   14621       222278 :         return cv_unqualified (type1);
   14622              : 
   14623          219 :     case CPTK_REMOVE_ALL_EXTENTS:
   14624          219 :       return strip_array_types (type1);
   14625              : 
   14626       934447 :     case CPTK_REMOVE_CV:
   14627       934447 :       return cv_unqualified (type1);
   14628              : 
   14629       415692 :     case CPTK_REMOVE_CVREF:
   14630       415692 :       if (TYPE_REF_P (type1))
   14631       162473 :         type1 = TREE_TYPE (type1);
   14632       415692 :       return cv_unqualified (type1);
   14633              : 
   14634        64611 :     case CPTK_REMOVE_EXTENT:
   14635        64611 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14636         9187 :         type1 = TREE_TYPE (type1);
   14637              :       return type1;
   14638              : 
   14639        42511 :     case CPTK_REMOVE_POINTER:
   14640        42511 :       if (TYPE_PTR_P (type1))
   14641        39798 :         type1 = TREE_TYPE (type1);
   14642              :       return type1;
   14643              : 
   14644      2047646 :     case CPTK_REMOVE_REFERENCE:
   14645      2047646 :       if (TYPE_REF_P (type1))
   14646      1234450 :         type1 = TREE_TYPE (type1);
   14647              :       return type1;
   14648              : 
   14649       107606 :     case CPTK_TYPE_PACK_ELEMENT:
   14650       107606 :       return finish_type_pack_element (type1, type2, complain);
   14651              : 
   14652        46831 :     case CPTK_UNDERLYING_TYPE:
   14653        46831 :       return finish_underlying_type (type1);
   14654              : 
   14655              : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
   14656              :     case CPTK_##CODE:
   14657              : #include "cp-trait.def"
   14658              : #undef DEFTRAIT_EXPR
   14659              :       /* Expression-yielding traits are handled in finish_trait_expr.  */
   14660              :     case CPTK_BASES:
   14661              :     case CPTK_DIRECT_BASES:
   14662              :       /* BASES and DIRECT_BASES are handled in finish_bases.  */
   14663              :       break;
   14664              :     }
   14665              : 
   14666            0 :   gcc_unreachable ();
   14667              : }
   14668              : 
   14669              : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
   14670              :    which is ignored for C++.  */
   14671              : 
   14672              : void
   14673            0 : set_float_const_decimal64 (void)
   14674              : {
   14675            0 : }
   14676              : 
   14677              : void
   14678            0 : clear_float_const_decimal64 (void)
   14679              : {
   14680            0 : }
   14681              : 
   14682              : bool
   14683      1910474 : float_const_decimal64_p (void)
   14684              : {
   14685      1910474 :   return 0;
   14686              : }
   14687              : 
   14688              : 
   14689              : /* Return true if T designates the implied `this' parameter.  */
   14690              : 
   14691              : bool
   14692      6053254 : is_this_parameter (tree t)
   14693              : {
   14694      6053254 :   if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
   14695              :     return false;
   14696      3596090 :   gcc_assert (TREE_CODE (t) == PARM_DECL
   14697              :               || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
   14698              :               || (cp_binding_oracle && VAR_P (t)));
   14699              :   return true;
   14700              : }
   14701              : 
   14702              : /* As above, or a C++23 explicit object parameter.  */
   14703              : 
   14704              : bool
   14705          456 : is_object_parameter (tree t)
   14706              : {
   14707          456 :   if (is_this_parameter (t))
   14708              :     return true;
   14709           91 :   if (TREE_CODE (t) != PARM_DECL)
   14710              :     return false;
   14711           34 :   tree ctx = DECL_CONTEXT (t);
   14712           34 :   return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
   14713           62 :           && t == DECL_ARGUMENTS (ctx));
   14714              : }
   14715              : 
   14716              : /* Insert the deduced return type for an auto function.  */
   14717              : 
   14718              : void
   14719       897090 : apply_deduced_return_type (tree fco, tree return_type)
   14720              : {
   14721       897090 :   tree result;
   14722              : 
   14723       897090 :   if (return_type == error_mark_node)
   14724              :     return;
   14725              : 
   14726       897087 :   if (DECL_CONV_FN_P (fco))
   14727           42 :     DECL_NAME (fco) = make_conv_op_name (return_type);
   14728              : 
   14729       897087 :   TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
   14730              : 
   14731       897087 :   maybe_update_postconditions (fco);
   14732              : 
   14733              :   /* Apply the type to the result object.  */
   14734              : 
   14735       897087 :   result = DECL_RESULT (fco);
   14736       897087 :   if (result == NULL_TREE)
   14737              :     return;
   14738       886158 :   if (TREE_TYPE (result) == return_type)
   14739              :     return;
   14740              : 
   14741       886152 :   if (!processing_template_decl && !VOID_TYPE_P (return_type)
   14742      1641220 :       && !complete_type_or_else (return_type, NULL_TREE))
   14743              :     return;
   14744              : 
   14745              :   /* We already have a DECL_RESULT from start_preparsed_function.
   14746              :      Now we need to redo the work it and allocate_struct_function
   14747              :      did to reflect the new type.  */
   14748       886155 :   result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
   14749       886155 :                        TYPE_MAIN_VARIANT (return_type));
   14750       886155 :   DECL_ARTIFICIAL (result) = 1;
   14751       886155 :   DECL_IGNORED_P (result) = 1;
   14752       886155 :   cp_apply_type_quals_to_decl (cp_type_quals (return_type),
   14753              :                                result);
   14754       886155 :   DECL_RESULT (fco) = result;
   14755              : 
   14756       886155 :   if (!uses_template_parms (fco))
   14757       886155 :     if (function *fun = DECL_STRUCT_FUNCTION (fco))
   14758              :       {
   14759       885621 :         bool aggr = aggregate_value_p (result, fco);
   14760              : #ifdef PCC_STATIC_STRUCT_RETURN
   14761              :         fun->returns_pcc_struct = aggr;
   14762              : #endif
   14763       885621 :         fun->returns_struct = aggr;
   14764              :       }
   14765              : }
   14766              : 
   14767              : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
   14768              :    this is a right unary fold. Otherwise it is a left unary fold. */
   14769              : 
   14770              : static tree
   14771       770943 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
   14772              : {
   14773              :   /* Build a pack expansion (assuming expr has pack type).  */
   14774       770943 :   if (!uses_parameter_packs (expr))
   14775              :     {
   14776            3 :       error_at (location_of (expr), "operand of fold expression has no "
   14777              :                 "unexpanded parameter packs");
   14778            3 :       return error_mark_node;
   14779              :     }
   14780       770940 :   tree pack = make_pack_expansion (expr);
   14781              : 
   14782              :   /* Build the fold expression.  */
   14783       770940 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14784       770940 :   tree fold = build_min_nt_loc (loc, dir, code, pack);
   14785       770940 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14786       770940 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14787       770940 :                                                     FOLD_EXPR_OP (fold),
   14788       770940 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14789       770940 :   return fold;
   14790              : }
   14791              : 
   14792              : tree
   14793        18287 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
   14794              : {
   14795        18287 :   return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
   14796              : }
   14797              : 
   14798              : tree
   14799       752656 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
   14800              : {
   14801       752656 :   return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
   14802              : }
   14803              : 
   14804              : /* Build a binary fold expression over EXPR1 and EXPR2. The
   14805              :    associativity of the fold is determined by EXPR1 and EXPR2 (whichever
   14806              :    has an unexpanded parameter pack). */
   14807              : 
   14808              : static tree
   14809       186667 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
   14810              :                          int op, tree_code dir)
   14811              : {
   14812       186667 :   pack = make_pack_expansion (pack);
   14813       186667 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14814       186667 :   tree fold = build_min_nt_loc (loc, dir, code, pack, init);
   14815       186667 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14816       186667 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14817       186667 :                                                     FOLD_EXPR_OP (fold),
   14818       186667 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14819       186667 :   return fold;
   14820              : }
   14821              : 
   14822              : tree
   14823       186667 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
   14824              : {
   14825              :   // Determine which expr has an unexpanded parameter pack and
   14826              :   // set the pack and initial term.
   14827       186667 :   bool pack1 = uses_parameter_packs (expr1);
   14828       186667 :   bool pack2 = uses_parameter_packs (expr2);
   14829       186667 :   if (pack1 && !pack2)
   14830          808 :     return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
   14831       185859 :   else if (pack2 && !pack1)
   14832       185859 :     return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
   14833              :   else
   14834              :     {
   14835            0 :       if (pack1)
   14836            0 :         error ("both arguments in binary fold have unexpanded parameter packs");
   14837              :       else
   14838            0 :         error ("no unexpanded parameter packs in binary fold");
   14839              :     }
   14840            0 :   return error_mark_node;
   14841              : }
   14842              : 
   14843              : /* Finish __builtin_launder (arg).  */
   14844              : 
   14845              : tree
   14846        13333 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
   14847              : {
   14848        13333 :   tree orig_arg = arg;
   14849        13333 :   if (!type_dependent_expression_p (arg))
   14850           84 :     arg = decay_conversion (arg, complain);
   14851        13333 :   if (error_operand_p (arg))
   14852            0 :     return error_mark_node;
   14853        13333 :   if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
   14854              :     {
   14855           24 :       error_at (loc, "type %qT of argument to %<__builtin_launder%> "
   14856           24 :                 "is not a pointer to object type", TREE_TYPE (arg));
   14857           24 :       return error_mark_node;
   14858              :     }
   14859        13309 :   if (processing_template_decl)
   14860        13249 :     arg = orig_arg;
   14861        13309 :   return build_call_expr_internal_loc (loc, IFN_LAUNDER,
   14862        26618 :                                        TREE_TYPE (arg), 1, arg);
   14863              : }
   14864              : 
   14865              : /* Finish __builtin_convertvector (arg, type).  */
   14866              : 
   14867              : tree
   14868          312 : cp_build_vec_convert (tree arg, location_t loc, tree type,
   14869              :                       tsubst_flags_t complain)
   14870              : {
   14871          312 :   if (error_operand_p (type))
   14872            9 :     return error_mark_node;
   14873          303 :   if (error_operand_p (arg))
   14874            0 :     return error_mark_node;
   14875              : 
   14876          303 :   tree ret = NULL_TREE;
   14877          303 :   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
   14878          295 :     ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
   14879              :                                decay_conversion (arg, complain),
   14880              :                                loc, type, (complain & tf_error) != 0);
   14881              : 
   14882          303 :   if (!processing_template_decl)
   14883              :     return ret;
   14884              : 
   14885           50 :   return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
   14886              : }
   14887              : 
   14888              : /* Finish __builtin_bit_cast (type, arg).  */
   14889              : 
   14890              : tree
   14891       279379 : cp_build_bit_cast (location_t loc, tree type, tree arg,
   14892              :                    tsubst_flags_t complain)
   14893              : {
   14894       279379 :   if (error_operand_p (type))
   14895            0 :     return error_mark_node;
   14896       279379 :   if (!dependent_type_p (type))
   14897              :     {
   14898       202998 :       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
   14899            9 :         return error_mark_node;
   14900       202989 :       if (TREE_CODE (type) == ARRAY_TYPE)
   14901              :         {
   14902              :           /* std::bit_cast for destination ARRAY_TYPE is not possible,
   14903              :              as functions may not return an array, so don't bother trying
   14904              :              to support this (and then deal with VLAs etc.).  */
   14905            9 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14906              :                          "is an array type", type);
   14907            9 :           return error_mark_node;
   14908              :         }
   14909       202980 :       if (!trivially_copyable_p (type))
   14910              :         {
   14911           18 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14912              :                          "is not trivially copyable", type);
   14913           18 :           return error_mark_node;
   14914              :         }
   14915       202962 :       if (consteval_only_p (type) || consteval_only_p (arg))
   14916              :         {
   14917            4 :           error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
   14918              :                          "consteval-only types");
   14919            4 :           return error_mark_node;
   14920              :         }
   14921              :     }
   14922              : 
   14923       279339 :   if (error_operand_p (arg))
   14924            0 :     return error_mark_node;
   14925              : 
   14926       279339 :   if (!type_dependent_expression_p (arg))
   14927              :     {
   14928       110570 :       if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
   14929              :         {
   14930              :           /* Don't perform array-to-pointer conversion.  */
   14931           39 :           arg = mark_rvalue_use (arg, loc, true);
   14932           39 :           if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
   14933            0 :             return error_mark_node;
   14934              :         }
   14935              :       else
   14936       110531 :         arg = decay_conversion (arg, complain);
   14937              : 
   14938       110570 :       if (error_operand_p (arg))
   14939           12 :         return error_mark_node;
   14940              : 
   14941       110558 :       if (!trivially_copyable_p (TREE_TYPE (arg)))
   14942              :         {
   14943            9 :           error_at (cp_expr_loc_or_loc (arg, loc),
   14944              :                     "%<__builtin_bit_cast%> source type %qT "
   14945            9 :                     "is not trivially copyable", TREE_TYPE (arg));
   14946            9 :           return error_mark_node;
   14947              :         }
   14948       110549 :       if (!dependent_type_p (type)
   14949       184045 :           && !cp_tree_equal (TYPE_SIZE_UNIT (type),
   14950        73496 :                              TYPE_SIZE_UNIT (TREE_TYPE (arg))))
   14951              :         {
   14952           18 :           error_at (loc, "%<__builtin_bit_cast%> source size %qE "
   14953              :                          "not equal to destination type size %qE",
   14954           18 :                          TYPE_SIZE_UNIT (TREE_TYPE (arg)),
   14955           18 :                          TYPE_SIZE_UNIT (type));
   14956           18 :           return error_mark_node;
   14957              :         }
   14958              :     }
   14959              : 
   14960       279300 :   tree ret = build_min (BIT_CAST_EXPR, type, arg);
   14961       279300 :   SET_EXPR_LOCATION (ret, loc);
   14962              : 
   14963       279300 :   if (!processing_template_decl && CLASS_TYPE_P (type))
   14964          300 :     ret = get_target_expr (ret, complain);
   14965              : 
   14966              :   return ret;
   14967              : }
   14968              : 
   14969              : /* Diagnose invalid #pragma GCC unroll argument and adjust
   14970              :    it if needed.  */
   14971              : 
   14972              : tree
   14973        23258 : cp_check_pragma_unroll (location_t loc, tree unroll)
   14974              : {
   14975        23258 :   HOST_WIDE_INT lunroll = 0;
   14976        23258 :   if (type_dependent_expression_p (unroll))
   14977              :     ;
   14978        46444 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
   14979        46398 :            || (!value_dependent_expression_p (unroll)
   14980        23146 :                && (!tree_fits_shwi_p (unroll)
   14981        23120 :                    || (lunroll = tree_to_shwi (unroll)) < 0
   14982        23105 :                    || lunroll >= USHRT_MAX)))
   14983              :     {
   14984           90 :       error_at (loc, "%<#pragma GCC unroll%> requires an"
   14985              :                 " assignment-expression that evaluates to a non-negative"
   14986              :                 " integral constant less than %u", USHRT_MAX);
   14987           90 :       unroll = integer_one_node;
   14988              :     }
   14989        23132 :   else if (TREE_CODE (unroll) == INTEGER_CST)
   14990              :     {
   14991        23102 :       unroll = fold_convert (integer_type_node, unroll);
   14992        23102 :       if (integer_zerop (unroll))
   14993           12 :         unroll = integer_one_node;
   14994              :     }
   14995        23258 :   return unroll;
   14996              : }
   14997              : 
   14998              : #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.