LCOV - code coverage report
Current view: top level - gcc/cp - semantics.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.2 % 7692 7244
Test Date: 2026-12-05 16:10:02 Functions: 98.1 % 264 259
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 "attribs.h"
      44              : #include "gomp-constants.h"
      45              : #include "predict.h"
      46              : #include "memmodel.h"
      47              : #include "gimplify.h"
      48              : #include "contracts.h"
      49              : #include "c-family/c-pragma.h"
      50              : #include "gcc-rich-location.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  24245497964 : push_deferring_access_checks (deferring_kind deferring)
     146              : {
     147              :   /* For context like template instantiation, access checking
     148              :      disabling applies to all nested context.  */
     149  24245497964 :   if (deferred_access_no_check || deferring == dk_no_check)
     150    310982664 :     deferred_access_no_check++;
     151              :   else
     152              :     {
     153  23934515300 :       deferred_access e = {NULL, deferring};
     154  23934515300 :       vec_safe_push (deferred_access_stack, e);
     155              :     }
     156  24245497964 : }
     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    390635486 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
     163              : {
     164    390635486 :   push_deferring_access_checks (dk_deferred);
     165    390635486 :   if (!deferred_access_no_check)
     166    382936954 :     deferred_access_stack->last().deferred_access_checks = checks;
     167    390635486 : }
     168              : 
     169              : /* Resume deferring access checks again after we stopped doing
     170              :    this previously.  */
     171              : 
     172              : void
     173    184916110 : resume_deferring_access_checks (void)
     174              : {
     175    184916110 :   if (!deferred_access_no_check)
     176    184889289 :     deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
     177    184916110 : }
     178              : 
     179              : /* Stop deferring access checks.  */
     180              : 
     181              : void
     182    518179240 : stop_deferring_access_checks (void)
     183              : {
     184    518179240 :   if (!deferred_access_no_check)
     185    518101418 :     deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
     186    518179240 : }
     187              : 
     188              : /* Discard the current deferred access checks and restore the
     189              :    previous states.  */
     190              : 
     191              : void
     192  15033889360 : pop_deferring_access_checks (void)
     193              : {
     194  15033889360 :   if (deferred_access_no_check)
     195    238707508 :     deferred_access_no_check--;
     196              :   else
     197  14795181852 :     deferred_access_stack->pop ();
     198  15033889360 : }
     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   1298815422 : get_deferred_access_checks (void)
     207              : {
     208   1298815422 :   if (deferred_access_no_check)
     209              :     return NULL;
     210              :   else
     211   1282944281 :     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   9211469275 : pop_to_parent_deferring_access_checks (void)
     220              : {
     221   9211469275 :   if (deferred_access_no_check)
     222     72275148 :     deferred_access_no_check--;
     223              :   else
     224              :     {
     225   9139194127 :       vec<deferred_access_check, va_gc> *checks;
     226   9139194127 :       deferred_access *ptr;
     227              : 
     228   9139194127 :       checks = (deferred_access_stack->last ().deferred_access_checks);
     229              : 
     230   9139194127 :       deferred_access_stack->pop ();
     231   9139194127 :       ptr = &deferred_access_stack->last ();
     232   9139194127 :       if (ptr->deferring_access_checks_kind == dk_no_deferred)
     233              :         {
     234              :           /* Check access.  */
     235    574997802 :           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   8767500763 :           FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     244              :             {
     245    110449919 :               FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
     246              :                 {
     247      9784688 :                   if (probe->binfo == chk->binfo &&
     248      7769057 :                       probe->decl == chk->decl &&
     249       987928 :                       probe->diag_decl == chk->diag_decl)
     250       986988 :                     goto found;
     251              :                 }
     252              :               /* Insert into parent's checks.  */
     253    100665231 :               vec_safe_push (ptr->deferred_access_checks, *chk);
     254    101652219 :             found:;
     255              :             }
     256              :         }
     257              :     }
     258   9211469275 : }
     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    421591887 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
     334              :                 tsubst_flags_t complain, access_failure_info *afi = NULL)
     335              : {
     336    421591887 :   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
     337              : 
     338    421591887 :   if (flag_new_inheriting_ctors
     339    532953715 :       && 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        62965 :       decl = strip_inheriting_ctors (decl);
     345        62965 :       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
     346              :                                    ba_any, NULL, complain);
     347              :     }
     348              : 
     349    421591887 :   tree cs = current_scope ();
     350    421591887 :   if (in_template_context
     351    421591887 :       && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
     352     41855696 :     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     41611446 :         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    379980441 :   if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     382              :     {
     383        22155 :       if (flag_new_inheriting_ctors)
     384        22125 :         diag_decl = strip_inheriting_ctors (diag_decl);
     385        22155 :       if (complain & tf_error)
     386              :         {
     387         1159 :           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         1159 :           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         1159 :           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         1159 :           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         1159 :           complain_about_access (decl, diag_decl, diag_location, true,
     413              :                                  access_failure_reason);
     414              :         }
     415        22155 :       if (afi)
     416          412 :         afi->record_access_failure (basetype_path, decl, diag_decl);
     417              :       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   1103740337 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
     431              :                        tsubst_flags_t complain)
     432              : {
     433   1103740337 :   int i;
     434   1103740337 :   deferred_access_check *chk;
     435   1103740337 :   location_t loc = input_location;
     436   1103740337 :   bool ok = true;
     437              : 
     438   1103740337 :   if (!checks)
     439              :     return true;
     440              : 
     441    127823664 :   FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     442              :     {
     443     71176826 :       input_location = chk->loc;
     444     71176826 :       ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
     445              :     }
     446              : 
     447     56646838 :   input_location = loc;
     448     56646838 :   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    288542763 : perform_deferred_access_checks (tsubst_flags_t complain)
     469              : {
     470    288542763 :   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    632792152 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
     480              :                                tsubst_flags_t complain,
     481              :                                access_failure_info *afi)
     482              : {
     483    632792152 :   int i;
     484    632792152 :   deferred_access *ptr;
     485    632792152 :   deferred_access_check *chk;
     486              : 
     487              :   /* Exit if we are in a context that no access checking is performed.  */
     488    632792152 :   if (deferred_access_no_check)
     489              :     return true;
     490              : 
     491    602236583 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     492              : 
     493    602236583 :   ptr = &deferred_access_stack->last ();
     494              : 
     495              :   /* If we are not supposed to defer access checks, just check now.  */
     496    602236583 :   if (ptr->deferring_access_checks_kind == dk_no_deferred)
     497              :     {
     498    350415061 :       bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
     499    350415061 :       return (complain & tf_error) ? true : ok;
     500              :     }
     501              : 
     502              :   /* See if we are already going to perform this check.  */
     503    306535912 :   FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
     504              :     {
     505     71843377 :       if (chk->decl == decl && chk->binfo == binfo &&
     506     17130068 :           chk->diag_decl == diag_decl)
     507              :         {
     508              :           return true;
     509              :         }
     510              :     }
     511              :   /* If not, record the check.  */
     512    234692535 :   deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
     513    234692535 :   vec_safe_push (ptr->deferred_access_checks, new_access);
     514              : 
     515    234692535 :   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   1412399764 : stmts_are_full_exprs_p (void)
     524              : {
     525   1412399764 :   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   1312231975 : add_stmt (tree t)
     534              : {
     535   1312231975 :   enum tree_code code = TREE_CODE (t);
     536              : 
     537   1312231975 :   if (EXPR_P (t) && code != LABEL_EXPR)
     538              :     {
     539   1261959901 :       if (!EXPR_HAS_LOCATION (t))
     540    201746439 :         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   1261959901 :       if (STATEMENT_CODE_P (TREE_CODE (t)))
     545    329107330 :         STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
     546              :     }
     547              : 
     548   1312231975 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     549      6009538 :     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   1312231975 :   gcc_checking_assert (!stmt_list_stack->is_empty ());
     554   1312231975 :   append_to_statement_list_force (t, &cur_stmt_list);
     555              : 
     556   1312231975 :   return t;
     557              : }
     558              : 
     559              : /* Returns the stmt_tree to which statements are currently being added.  */
     560              : 
     561              : stmt_tree
     562   8863462278 : current_stmt_tree (void)
     563              : {
     564   8863462278 :   return (cfun
     565   8839370379 :           ? &cfun->language->base.x_stmt_tree
     566   8863462278 :           : &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       331460 : maybe_cleanup_point_expr (tree expr)
     573              : {
     574       331460 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     575       318127 :     expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
     576       331460 :   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    325298009 : maybe_cleanup_point_expr_void (tree expr)
     586              : {
     587    325298009 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     588    109084449 :     expr = fold_build_cleanup_point_expr (void_type_node, expr);
     589    325298009 :   return expr;
     590              : }
     591              : 
     592              : 
     593              : 
     594              : /* Create a declaration statement for the declaration given by the DECL.  */
     595              : 
     596              : void
     597    110025184 : add_decl_expr (tree decl)
     598              : {
     599    110025184 :   tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
     600    110025184 :   if (DECL_INITIAL (decl)
     601    110025184 :       || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
     602     19594266 :     r = maybe_cleanup_point_expr_void (r);
     603    110025184 :   add_stmt (r);
     604    110025184 : }
     605              : 
     606              : /* Set EXPR_LOCATION on one cleanup T to LOC.  */
     607              : 
     608              : static void
     609      5835869 : set_one_cleanup_loc (tree t, location_t loc)
     610              : {
     611      5835869 :   if (!t)
     612              :     return;
     613              : 
     614      5835869 :   if (TREE_CODE (t) != POSTCONDITION_STMT)
     615      5835869 :     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      5835869 :   if (TREE_CODE (t) == NOP_EXPR
     622            0 :       && TREE_TYPE (t) == void_type_node
     623      5835869 :       && 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   1238086325 : set_cleanup_locs (tree stmts, location_t loc)
     631              : {
     632   1243922194 :   if (TREE_CODE (stmts) == CLEANUP_STMT)
     633              :     {
     634      5835869 :       set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
     635      5835869 :       set_cleanup_locs (CLEANUP_BODY (stmts), loc);
     636              :     }
     637   1238086325 :   else if (TREE_CODE (stmts) == STATEMENT_LIST)
     638   1099727345 :     for (tree stmt : tsi_range (stmts))
     639    851814943 :       set_cleanup_locs (stmt, loc);
     640   1238086325 : }
     641              : 
     642              : /* True iff the innermost block scope is a try block.  */
     643              : 
     644              : static bool
     645    386271382 : at_try_scope ()
     646              : {
     647    386271382 :   cp_binding_level *b = current_binding_level;
     648    386271651 :   while (b && b->kind == sk_cleanup)
     649          269 :     b = b->level_chain;
     650    386271382 :   return b && b->kind == sk_try;
     651              : }
     652              : 
     653              : /* Finish a scope.  */
     654              : 
     655              : tree
     656    386271382 : do_poplevel (tree stmt_list)
     657              : {
     658    386271382 :   tree block = NULL;
     659              : 
     660    386271382 :   bool was_try = at_try_scope ();
     661              : 
     662    386271382 :   if (stmts_are_full_exprs_p ())
     663    386193766 :     block = poplevel (kept_level_p (), 1, 0);
     664              : 
     665              :   /* This needs to come after poplevel merges sk_cleanup statement_lists.  */
     666    386271382 :   maybe_splice_retval_cleanup (stmt_list, was_try);
     667              : 
     668    386271382 :   stmt_list = pop_stmt_list (stmt_list);
     669              : 
     670              :   /* input_location is the last token of the scope, usually a }.  */
     671    386271382 :   set_cleanup_locs (stmt_list, input_location);
     672              : 
     673    386271382 :   if (!processing_template_decl)
     674              :     {
     675    118934601 :       stmt_list = c_build_bind_expr (input_location, block, stmt_list);
     676              :       /* ??? See c_end_compound_stmt re statement expressions.  */
     677              :     }
     678              : 
     679    386271382 :   return stmt_list;
     680              : }
     681              : 
     682              : /* Begin a new scope.  */
     683              : 
     684              : tree
     685    386218648 : do_pushlevel (scope_kind sk)
     686              : {
     687    386218648 :   tree ret = push_stmt_list ();
     688    386218648 :   if (stmts_are_full_exprs_p ())
     689    386193826 :     begin_scope (sk, NULL);
     690    386218648 :   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      5835735 : push_cleanup (tree decl, tree cleanup, bool eh_only)
     700              : {
     701      5835735 :   tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
     702      5835735 :   CLEANUP_EH_ONLY (stmt) = eh_only;
     703      5835735 :   add_stmt (stmt);
     704      5835735 :   CLEANUP_BODY (stmt) = push_stmt_list ();
     705      5835735 : }
     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     18446761 : begin_maybe_infinite_loop (tree cond)
     716              : {
     717              :   /* Only track this while parsing a function, not during instantiation.  */
     718     18446761 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     719      2705557 :                 && !processing_template_decl))
     720              :     return;
     721     15740700 :   bool maybe_infinite = true;
     722     15740700 :   if (cond)
     723              :     {
     724     15434378 :       cond = fold_non_dependent_expr (cond);
     725     15434378 :       maybe_infinite = integer_nonzerop (cond);
     726              :     }
     727     31175078 :   vec_safe_push (cp_function_chain->infinite_loops,
     728     15740700 :                  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      1543212 : break_maybe_infinite_loop (void)
     736              : {
     737      1543212 :   if (!cfun)
     738              :     return;
     739      1543212 :   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     18446761 : end_maybe_infinite_loop (tree cond)
     747              : {
     748     18446761 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     749      2705557 :                 && !processing_template_decl))
     750              :     return;
     751     15740700 :   tree current = cp_function_chain->infinite_loops->pop();
     752     15740700 :   if (current != NULL_TREE)
     753              :     {
     754      5110999 :       cond = fold_non_dependent_expr (cond);
     755      5110999 :       if (integer_nonzerop (cond))
     756       330863 :         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     89473802 : begin_cond (tree *cond_p)
     767              : {
     768     89473802 :   if (processing_template_decl)
     769     63310434 :     *cond_p = push_stmt_list ();
     770     89473802 : }
     771              : 
     772              : /* Finish such a conditional.  */
     773              : 
     774              : static void
     775     89473802 : finish_cond (tree *cond_p, tree expr)
     776              : {
     777     89473802 :   if (processing_template_decl)
     778              :     {
     779     63310434 :       tree cond = pop_stmt_list (*cond_p);
     780              : 
     781     63310434 :       if (expr == NULL_TREE)
     782              :         /* Empty condition in 'for'.  */
     783       285647 :         gcc_assert (empty_expr_stmt_p (cond));
     784     63024787 :       else if (check_for_bare_parameter_packs (expr))
     785            0 :         expr = error_mark_node;
     786     63024787 :       else if (!empty_expr_stmt_p (cond))
     787       974166 :         expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
     788              :     }
     789     89473802 :   *cond_p = expr;
     790     89473802 : }
     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     12413987 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
     809              : {
     810     12413987 :   if (!TREE_SIDE_EFFECTS (*body_p))
     811     12404278 :     return;
     812              : 
     813         9709 :   gcc_assert (!processing_template_decl);
     814         9709 :   *prep_p = *body_p;
     815         9709 :   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          100 :       gcc_assert (stmt_list_stack->length () > 1);
     821          100 :       for (unsigned i = stmt_list_stack->length () - 2; ; --i)
     822              :         {
     823          112 :           tree t = (*stmt_list_stack)[i];
     824          112 :           tree_stmt_iterator last = tsi_last (t);
     825          224 :           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          112 :           if (t == *prep_p)
     831              :             {
     832          100 :               *cleanup_p = build_int_cst (long_unsigned_type_node,
     833          100 :                                           stmt_list_stack->length () - 1 - i);
     834          100 :               break;
     835              :             }
     836           12 :           gcc_assert (i >= 1);
     837           12 :         }
     838              :     }
     839         9709 :   current_binding_level->keep = true;
     840         9709 :   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         9709 :   if (tsi_end_p (iter))
     847              :     *body_p = NULL_TREE;
     848              :   else
     849         9615 :     *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         9709 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
     862              : {
     863         9709 :   *prep_p = do_poplevel (*prep_p);
     864         9709 :   gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
     865         9709 :   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          112 :       return;
     870              :     }
     871         9691 :   tree stmt_list = BIND_EXPR_BODY (*prep_p);
     872         9691 :   gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
     873         9691 :   if (cleanup)
     874              :     {
     875          100 :       tree_stmt_iterator iter = tsi_last (stmt_list);
     876          100 :       gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
     877          112 :       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          100 :       if (*body_p == NULL_TREE)
     885              :         {
     886           94 :           *body_p = CLEANUP_BODY (tsi_stmt (iter));
     887           94 :           CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
     888           94 :           return;
     889              :         }
     890            6 :       stmt_list = CLEANUP_BODY (tsi_stmt (iter));
     891              :     }
     892         9597 :   tree_stmt_iterator iter = tsi_start (stmt_list);
     893         9829 :   while (tsi_stmt (iter) != *body_p)
     894          232 :     tsi_next (&iter);
     895         9597 :   *body_p = tsi_split_stmt_list (input_location, iter);
     896              : }
     897              : 
     898              : /* Finish a goto-statement.  */
     899              : 
     900              : tree
     901         2936 : finish_goto_stmt (tree destination)
     902              : {
     903         2936 :   if (identifier_p (destination))
     904         2787 :     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         2936 :   if (TREE_CODE (destination) == LABEL_DECL)
     909         2787 :     TREE_USED (destination) = 1;
     910              :   else
     911              :     {
     912          149 :       destination = mark_rvalue_use (destination);
     913          149 :       if (!processing_template_decl)
     914              :         {
     915          129 :           destination = cp_convert (ptr_type_node, destination,
     916              :                                     tf_warning_or_error);
     917          129 :           if (error_operand_p (destination))
     918              :             return NULL_TREE;
     919          120 :           destination
     920          120 :             = fold_build_cleanup_point_expr (TREE_TYPE (destination),
     921              :                                              destination);
     922              :         }
     923              :     }
     924              : 
     925         2927 :   add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
     926              : 
     927         2927 :   tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
     928         2927 :   check_goto (&TREE_OPERAND (stmt, 0));
     929              : 
     930         2927 :   return add_stmt (stmt);
     931              : }
     932              : 
     933              : /* Returns true if T corresponds to an assignment operator expression.  */
     934              : 
     935              : static bool
     936       883490 : is_assignment_op_expr_p (tree t)
     937              : {
     938       883490 :   if (t == NULL_TREE)
     939              :     return false;
     940              : 
     941       883490 :   if (TREE_CODE (t) == MODIFY_EXPR
     942       883490 :       || (TREE_CODE (t) == MODOP_EXPR
     943          336 :           && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
     944              :     return true;
     945              : 
     946       882803 :   tree call = extract_call_expr (t);
     947       882803 :   if (call == NULL_TREE
     948       129924 :       || call == error_mark_node
     949      1012727 :       || !CALL_EXPR_OPERATOR_SYNTAX (call))
     950              :     return false;
     951              : 
     952         4682 :   tree fndecl = cp_get_callee_fndecl_nofold (call);
     953         4682 :   return fndecl != NULL_TREE
     954         4584 :     && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
     955         4733 :     && 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            8 :       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     92411183 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
    1019              :                                        tsubst_flags_t complain)
    1020              : {
    1021     92411183 :   tree type = TREE_TYPE (t);
    1022     92411183 :   t = STRIP_REFERENCE_REF (t);
    1023              : 
    1024     92411183 :   if ((complain & tf_warning)
    1025     92350760 :       && warn_parentheses
    1026       883490 :       && 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     92411530 :       && (!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     92411183 : }
    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     54713809 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
    1072              : {
    1073     54713809 :   tree *t = cond;
    1074     54724094 :   while (TREE_CODE (*t) == ANNOTATE_EXPR)
    1075        10285 :     t = &TREE_OPERAND (*t, 0);
    1076              : 
    1077     54713809 :   if (t != cond)
    1078              :     {
    1079        10282 :       m_annotations = *cond;
    1080        10282 :       *cond = *t;
    1081        10282 :       m_inner = t;
    1082              :     }
    1083     54713809 : }
    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     54713809 : annotate_saver::restore (tree new_inner)
    1092              : {
    1093     54713809 :   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        10282 :   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        10282 :   *m_inner = new_inner;
    1118        10282 :   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     94496250 : maybe_convert_cond (tree cond)
    1127              : {
    1128              :   /* Empty conditions remain empty.  */
    1129     94496250 :   if (!cond)
    1130              :     return NULL_TREE;
    1131              : 
    1132              :   /* Wait until we instantiate templates before doing conversion.  */
    1133     94131133 :   if (type_dependent_expression_p (cond))
    1134     39417324 :     return cond;
    1135              : 
    1136              :   /* Strip any ANNOTATE_EXPRs from COND.  */
    1137     54713809 :   annotate_saver annotations (&cond);
    1138              : 
    1139              :   /* For structured binding used in condition, the conversion needs to be
    1140              :      evaluated before the individual variables are initialized in the
    1141              :      std::tuple_{size,element} case.  cp_finish_decomp saved the conversion
    1142              :      result in a NON_LVALUE_EXPR, pick it up from there.  */
    1143       380639 :   if (DECL_DECOMPOSITION_P (cond)
    1144          228 :       && DECL_DECOMP_IS_BASE (cond)
    1145          228 :       && DECL_DECOMP_BASE (cond)
    1146     54714034 :       && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
    1147           59 :     cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
    1148              : 
    1149     54713809 :   if (warn_sequence_point && !processing_template_decl)
    1150       329023 :     verify_sequence_points (cond);
    1151              : 
    1152     54713809 :   maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
    1153              :                                          tf_warning_or_error);
    1154              : 
    1155              :   /* Do the conversion.  */
    1156     54713809 :   cond = convert_from_reference (cond);
    1157     54713809 :   cond = condition_conversion (cond);
    1158              : 
    1159              :   /* Restore any ANNOTATE_EXPRs around COND.  */
    1160     54713809 :   return annotations.restore (cond);
    1161              : }
    1162              : 
    1163              : /* Finish an expression-statement, whose EXPRESSION is as indicated.  */
    1164              : 
    1165              : tree
    1166    166848429 : finish_expr_stmt (tree expr)
    1167              : {
    1168    166848429 :   tree r = NULL_TREE;
    1169    166848429 :   location_t loc = EXPR_LOCATION (expr);
    1170              : 
    1171    166659331 :   if (expr != NULL_TREE)
    1172              :     {
    1173              :       /* If we ran into a problem, make sure we complained.  */
    1174    166848268 :       gcc_assert (expr != error_mark_node || seen_error ());
    1175              : 
    1176    166848268 :       if (!processing_template_decl)
    1177              :         {
    1178     60871996 :           if (warn_sequence_point)
    1179       819399 :             verify_sequence_points (expr);
    1180     60871996 :           expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1181              :         }
    1182    105976272 :       else if (!type_dependent_expression_p (expr))
    1183     23023076 :         convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1184              : 
    1185    166848265 :       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    166848265 :       if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    1192              :         {
    1193    166848086 :           if (TREE_CODE (expr) != EXPR_STMT
    1194    164343881 :               && !STATEMENT_CLASS_P (expr)
    1195    164339724 :               && TREE_CODE (expr) != STATEMENT_LIST)
    1196    164182222 :             expr = build_stmt (loc, EXPR_STMT, expr);
    1197    166848086 :           expr = maybe_cleanup_point_expr_void (expr);
    1198              :         }
    1199              : 
    1200    166848265 :       r = add_stmt (expr);
    1201              :     }
    1202              : 
    1203    166848426 :   return r;
    1204              : }
    1205              : 
    1206              : 
    1207              : /* Begin an if-statement.  Returns a newly created IF_STMT if
    1208              :    appropriate.  */
    1209              : 
    1210              : tree
    1211     76323591 : begin_if_stmt (void)
    1212              : {
    1213     76323591 :   tree r, scope;
    1214     76323591 :   scope = do_pushlevel (sk_cond);
    1215     76323591 :   r = build_stmt (input_location, IF_STMT, NULL_TREE,
    1216              :                   NULL_TREE, NULL_TREE, scope);
    1217     76323591 :   current_binding_level->this_entity = r;
    1218     76323591 :   begin_cond (&IF_COND (r));
    1219     76323591 :   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       254740 : is_std_constant_evaluated_p (tree fn)
    1227              : {
    1228              :   /* std::is_constant_evaluated takes no arguments.  */
    1229       254740 :   if (call_expr_nargs (fn) != 0)
    1230              :     return false;
    1231              : 
    1232        91139 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
    1233        91139 :   if (fndecl == NULL_TREE)
    1234              :     return false;
    1235              : 
    1236        28362 :   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    1237              :                          BUILT_IN_FRONTEND))
    1238              :     return true;
    1239              : 
    1240        28333 :   if (!decl_in_std_namespace_p (fndecl))
    1241              :     return false;
    1242              : 
    1243        12992 :   tree name = DECL_NAME (fndecl);
    1244        12992 :   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      4729232 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
    1252              : {
    1253      4729232 :   tree t = *tp;
    1254              : 
    1255      4729232 :   if (TYPE_P (t) || TREE_CONSTANT (t))
    1256              :     {
    1257       837512 :       *walk_subtrees = false;
    1258       837512 :       return NULL_TREE;
    1259              :     }
    1260              : 
    1261      3891720 :   switch (TREE_CODE (t))
    1262              :     {
    1263       254740 :     case CALL_EXPR:
    1264       254740 :       if (is_std_constant_evaluated_p (t))
    1265         2396 :         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     76409413 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
    1284              :                                    bool trivial_infinite)
    1285              : {
    1286     76409413 :   if (!warn_tautological_compare)
    1287              :     return;
    1288              : 
    1289              :   /* Suppress warning for std::is_constant_evaluated if the conditional
    1290              :      comes from a macro.  */
    1291      1442136 :   if (from_macro_expansion_at (EXPR_LOCATION (cond)))
    1292              :     return;
    1293              : 
    1294       609253 :   cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
    1295              :                                           NULL);
    1296       609253 :   if (cond)
    1297              :     {
    1298         2396 :       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         2362 :       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         2354 :       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         4632 :       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     76323591 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
    1330              : {
    1331     76323591 :   tree cond = maybe_convert_cond (orig_cond);
    1332     76323591 :   maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
    1333              :                                      /*trivial_infinite=*/false);
    1334     76323591 :   if (IF_STMT_CONSTEXPR_P (if_stmt)
    1335     16364341 :       && !type_dependent_expression_p (cond)
    1336     11308769 :       && require_constant_expression (cond)
    1337     11308738 :       && !instantiation_dependent_expression_p (cond)
    1338              :       /* Wait until instantiation time, since only then COND has been
    1339              :          converted to bool.  */
    1340     82528158 :       && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
    1341              :     {
    1342      6204567 :       cond = instantiate_non_dependent_expr (cond);
    1343      6204567 :       cond = cxx_constant_value (cond);
    1344              :     }
    1345     70119024 :   else if (processing_template_decl)
    1346     52621092 :     cond = orig_cond;
    1347     76323591 :   finish_cond (&IF_COND (if_stmt), cond);
    1348     76323591 :   add_stmt (if_stmt);
    1349     76323591 :   THEN_CLAUSE (if_stmt) = push_stmt_list ();
    1350     76323591 :   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     76315729 : finish_then_clause (tree if_stmt)
    1358              : {
    1359     76315729 :   THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
    1360     76315729 :   return if_stmt;
    1361              : }
    1362              : 
    1363              : /* Begin the else-clause of an if-statement.  */
    1364              : 
    1365              : void
    1366     28436523 : begin_else_clause (tree if_stmt)
    1367              : {
    1368     28436523 :   ELSE_CLAUSE (if_stmt) = push_stmt_list ();
    1369     28436523 : }
    1370              : 
    1371              : /* Finish the else-clause of an if-statement, which may be given by
    1372              :    IF_STMT.  */
    1373              : 
    1374              : void
    1375     28436485 : finish_else_clause (tree if_stmt)
    1376              : {
    1377     28436485 :   ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
    1378     28436485 : }
    1379              : 
    1380              : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
    1381              :    read.  */
    1382              : 
    1383              : static tree
    1384    878971523 : maybe_mark_exp_read_r (tree *tp, int *, void *)
    1385              : {
    1386    878971523 :   tree t = *tp;
    1387    878971523 :   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1388     51527656 :     mark_exp_read (t);
    1389    878971523 :   return NULL_TREE;
    1390              : }
    1391              : 
    1392              : /* Finish an if-statement.  */
    1393              : 
    1394              : void
    1395     76315729 : finish_if_stmt (tree if_stmt)
    1396              : {
    1397     76315729 :   tree scope = IF_SCOPE (if_stmt);
    1398     76315729 :   IF_SCOPE (if_stmt) = NULL;
    1399     76315729 :   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     16356479 :       cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
    1405              :                                        maybe_mark_exp_read_r, NULL);
    1406     16356479 :       cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
    1407              :                                        maybe_mark_exp_read_r, NULL);
    1408              :     }
    1409     76315729 :   add_stmt (do_poplevel (scope));
    1410     76315729 : }
    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     17804243 : finish_loop_cond (tree *condp, tree body)
    1421              : {
    1422     17804243 :   if (TREE_CODE (*condp) == INTEGER_CST)
    1423              :     return;
    1424     12747004 :   bool trivially_empty = expr_first (body) == NULL_TREE;
    1425     12747004 :   bool trivial_infinite = false;
    1426     12747004 :   if (trivially_empty)
    1427              :     {
    1428        98834 :       tree c = fold_non_dependent_expr (*condp, tf_none,
    1429              :                                         /*manifestly_const_eval=*/true);
    1430        98834 :       trivial_infinite = c && integer_nonzerop (c);
    1431              :     }
    1432     12747004 :   if (warn_tautological_compare)
    1433              :     {
    1434        86024 :       tree cond = *condp;
    1435        86391 :       while (TREE_CODE (cond) == ANNOTATE_EXPR)
    1436          367 :         cond = TREE_OPERAND (cond, 0);
    1437        86024 :       if (trivial_infinite
    1438        86088 :           && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1439           64 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1440              :                                            /*trivial_infinite=*/true);
    1441        85960 :       else if (!trivially_empty
    1442          375 :                || !processing_template_decl
    1443        86364 :                || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1444        85758 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1445              :                                            /*trivial_infinite=*/false);
    1446              :     }
    1447     12747004 :   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      4858273 : begin_while_stmt (void)
    1459              : {
    1460      4858273 :   tree r;
    1461      4858273 :   r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1462              :                   NULL_TREE, NULL_TREE);
    1463      4858273 :   add_stmt (r);
    1464      4858273 :   WHILE_BODY (r) = do_pushlevel (sk_block);
    1465      4858273 :   begin_cond (&WHILE_COND (r));
    1466      4858273 :   return r;
    1467              : }
    1468              : 
    1469              : /* Process the COND of a while-statement, which may be given by
    1470              :    WHILE_STMT.  */
    1471              : 
    1472              : void
    1473      4858273 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
    1474              :                         tree unroll, bool novector)
    1475              : {
    1476      4858273 :   cond = maybe_convert_cond (cond);
    1477      4858273 :   finish_cond (&WHILE_COND (while_stmt), cond);
    1478      4858273 :   begin_maybe_infinite_loop (cond);
    1479      4858273 :   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      4858273 :   if (unroll && cond != error_mark_node)
    1487        27114 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1488        13557 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1489        13557 :                                       WHILE_COND (while_stmt),
    1490              :                                       build_int_cst (integer_type_node,
    1491              :                                                      annot_expr_unroll_kind),
    1492              :                                       unroll);
    1493      4858273 :   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      4858273 :   adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
    1501              :                          &WHILE_COND_PREP (while_stmt),
    1502              :                          &WHILE_COND_CLEANUP (while_stmt));
    1503      4858273 : }
    1504              : 
    1505              : /* Finish a while-statement, which may be given by WHILE_STMT.  */
    1506              : 
    1507              : void
    1508      4858273 : finish_while_stmt (tree while_stmt)
    1509              : {
    1510      4858273 :   end_maybe_infinite_loop (boolean_true_node);
    1511      4858273 :   if (WHILE_COND_PREP (while_stmt))
    1512         9535 :     finish_loop_cond_prep (&WHILE_BODY (while_stmt),
    1513              :                            &WHILE_COND_PREP (while_stmt),
    1514         9535 :                            WHILE_COND_CLEANUP (while_stmt));
    1515              :   else
    1516      4848738 :     WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
    1517      4858273 :   finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
    1518      4858273 : }
    1519              : 
    1520              : /* Begin a do-statement.  Returns a newly created DO_STMT if
    1521              :    appropriate.  */
    1522              : 
    1523              : tree
    1524      5755373 : begin_do_stmt (void)
    1525              : {
    1526      5755373 :   tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
    1527              :                        NULL_TREE);
    1528      5755373 :   begin_maybe_infinite_loop (boolean_true_node);
    1529      5755373 :   add_stmt (r);
    1530      5755373 :   DO_BODY (r) = push_stmt_list ();
    1531      5755373 :   return r;
    1532              : }
    1533              : 
    1534              : /* Finish the body of a do-statement, which may be given by DO_STMT.  */
    1535              : 
    1536              : void
    1537      5755373 : finish_do_body (tree do_stmt)
    1538              : {
    1539      5755373 :   tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
    1540              : 
    1541      5755373 :   if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
    1542       537668 :     body = STATEMENT_LIST_TAIL (body)->stmt;
    1543              : 
    1544      5755373 :   if (IS_EMPTY_STMT (body))
    1545           30 :     warning (OPT_Wempty_body,
    1546              :             "suggest explicit braces around empty body in %<do%> statement");
    1547      5755373 : }
    1548              : 
    1549              : /* Finish a do-statement, which may be given by DO_STMT, and whose
    1550              :    COND is as indicated.  */
    1551              : 
    1552              : void
    1553      5755373 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
    1554              :                 bool novector)
    1555              : {
    1556      5755373 :   cond = maybe_convert_cond (cond);
    1557      5755373 :   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      5755373 :   if (check_for_bare_parameter_packs (cond))
    1562            3 :     cond = error_mark_node;
    1563      5755373 :   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      5755373 :   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      5755373 :   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      5755373 :   DO_COND (do_stmt) = cond;
    1576      5755373 :   tree do_body = DO_BODY (do_stmt);
    1577      5755343 :   if (CONVERT_EXPR_P (do_body)
    1578           30 :       && integer_zerop (TREE_OPERAND (do_body, 0))
    1579      5755403 :       && VOID_TYPE_P (TREE_TYPE (do_body)))
    1580              :     do_body = NULL_TREE;
    1581      5755373 :   finish_loop_cond (&DO_COND (do_stmt), do_body);
    1582      5755373 : }
    1583              : 
    1584              : /* Finish a return-statement.  The EXPRESSION returned, if any, is as
    1585              :    indicated.  */
    1586              : 
    1587              : tree
    1588    131695111 : finish_return_stmt (tree expr)
    1589              : {
    1590    131695111 :   tree r;
    1591    131695111 :   bool no_warning;
    1592    131695111 :   bool dangling;
    1593              : 
    1594    131695111 :   expr = check_return_expr (expr, &no_warning, &dangling);
    1595              : 
    1596    131695111 :   if (error_operand_p (expr)
    1597    131695111 :       || (flag_openmp && !check_omp_return ()))
    1598              :     {
    1599              :       /* Suppress -Wreturn-type for this function.  */
    1600         1360 :       if (warn_return_type)
    1601         1354 :         suppress_warning (current_function_decl, OPT_Wreturn_type);
    1602         1360 :       return error_mark_node;
    1603              :     }
    1604              : 
    1605    131693751 :   if (!processing_template_decl)
    1606              :     {
    1607     46006770 :       if (warn_sequence_point)
    1608      1040002 :         verify_sequence_points (expr);
    1609              :     }
    1610              : 
    1611    131693751 :   r = build_stmt (input_location, RETURN_EXPR, expr);
    1612    131693751 :   RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
    1613    131693751 :   if (no_warning)
    1614           33 :     suppress_warning (r, OPT_Wreturn_type);
    1615    131693751 :   r = maybe_cleanup_point_expr_void (r);
    1616    131693751 :   r = add_stmt (r);
    1617              : 
    1618    131693751 :   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      7833115 : begin_for_scope (tree *init)
    1627              : {
    1628      7833115 :   tree scope = do_pushlevel (sk_for);
    1629              : 
    1630      7833115 :   if (processing_template_decl)
    1631      6223773 :     *init = push_stmt_list ();
    1632              :   else
    1633      1609342 :     *init = NULL_TREE;
    1634              : 
    1635      7833115 :   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      7555714 : begin_for_stmt (tree scope, tree init)
    1644              : {
    1645      7555714 :   tree r;
    1646              : 
    1647      7555714 :   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      7555714 :   if (scope == NULL_TREE)
    1652              :     {
    1653      1364870 :       gcc_assert (!init);
    1654      1364870 :       scope = begin_for_scope (&init);
    1655              :     }
    1656              : 
    1657      7555714 :   FOR_INIT_STMT (r) = init;
    1658      7555714 :   FOR_SCOPE (r) = scope;
    1659              : 
    1660      7555714 :   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      7555714 : finish_init_stmt (tree for_stmt)
    1668              : {
    1669      7555714 :   if (processing_template_decl)
    1670      5946372 :     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
    1671      7555714 :   add_stmt (for_stmt);
    1672      7555714 :   FOR_BODY (for_stmt) = do_pushlevel (sk_block);
    1673      7555714 :   begin_cond (&FOR_COND (for_stmt));
    1674      7555714 : }
    1675              : 
    1676              : /* Finish the COND of a for-statement, which may be given by
    1677              :    FOR_STMT.  */
    1678              : 
    1679              : void
    1680      7555714 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
    1681              :                  bool novector)
    1682              : {
    1683      7555714 :   cond = maybe_convert_cond (cond);
    1684      7555714 :   finish_cond (&FOR_COND (for_stmt), cond);
    1685      7555714 :   begin_maybe_infinite_loop (cond);
    1686      7555714 :   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      7555714 :   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      7555714 :   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      7555714 :   adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
    1708              :                          &FOR_COND_CLEANUP (for_stmt));
    1709      7555714 : }
    1710              : 
    1711              : /* Finish the increment-EXPRESSION in a for-statement, which may be
    1712              :    given by FOR_STMT.  */
    1713              : 
    1714              : void
    1715      7543357 : finish_for_expr (tree expr, tree for_stmt)
    1716              : {
    1717      7543357 :   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      7089917 :   if (type_unknown_p (expr))
    1722              :     {
    1723            6 :       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
    1724            6 :       expr = error_mark_node;
    1725              :     }
    1726      7089917 :   if (!processing_template_decl)
    1727              :     {
    1728      1536257 :       if (warn_sequence_point)
    1729        15015 :         verify_sequence_points (expr);
    1730      1536257 :       expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
    1731              :                               tf_warning_or_error);
    1732              :     }
    1733      5553660 :   else if (!type_dependent_expression_p (expr))
    1734      2006949 :     convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
    1735      7089917 :   expr = maybe_cleanup_point_expr_void (expr);
    1736      7089917 :   if (check_for_bare_parameter_packs (expr))
    1737            0 :     expr = error_mark_node;
    1738      7089917 :   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      7833228 : find_range_for_decls (tree range_for_decl[3])
    1749              : {
    1750      7833228 :   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     31332912 :   for (int i = 0; i < 3; i++)
    1756              :     {
    1757     23499684 :       tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
    1758     23499684 :       if (IDENTIFIER_BINDING (id)
    1759     23499684 :           && IDENTIFIER_BINDING (id)->scope == current_binding_level)
    1760              :         {
    1761       276130 :           range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
    1762       276130 :           gcc_assert (VAR_P (range_for_decl[i])
    1763              :                       && DECL_ARTIFICIAL (range_for_decl[i]));
    1764              :         }
    1765              :     }
    1766      7833228 : }
    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      7833115 : finish_for_stmt (tree for_stmt)
    1775              : {
    1776      7833115 :   end_maybe_infinite_loop (boolean_true_node);
    1777              : 
    1778      7833115 :   if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
    1779       277401 :     RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
    1780              :   else
    1781              :     {
    1782      7555714 :       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      7555540 :         FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
    1788      7555714 :       if (FOR_COND (for_stmt))
    1789      7190597 :         finish_loop_cond (&FOR_COND (for_stmt),
    1790      7190597 :                           FOR_EXPR (for_stmt) ? integer_one_node
    1791       141111 :                                               : FOR_BODY (for_stmt));
    1792              :     }
    1793              : 
    1794              :   /* Pop the scope for the body of the loop.  */
    1795      7833115 :   tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
    1796      7833115 :                      ? &RANGE_FOR_SCOPE (for_stmt)
    1797      7555714 :                      : &FOR_SCOPE (for_stmt));
    1798      7833115 :   tree scope = *scope_ptr;
    1799      7833115 :   *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      7833115 :   tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
    1806      7833115 :   find_range_for_decls (range_for_decl);
    1807              : 
    1808      7833115 :   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      7833115 :   if (!stmts_are_full_exprs_p ())
    1813        12357 :     return;
    1814              : 
    1815     31283032 :   for (int i = 0; i < 3; i++)
    1816     23462274 :     if (range_for_decl[i])
    1817       276014 :       DECL_NAME (range_for_decl[i])
    1818       276014 :         = 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       277401 : begin_range_for_stmt (tree scope, tree init)
    1828              : {
    1829       277401 :   begin_maybe_infinite_loop (boolean_false_node);
    1830              : 
    1831       277401 :   tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
    1832              :                        NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
    1833              :                        NULL_TREE);
    1834              : 
    1835       277401 :   if (scope == NULL_TREE)
    1836              :     {
    1837          506 :       gcc_assert (!init);
    1838          506 :       scope = begin_for_scope (&init);
    1839              :     }
    1840              : 
    1841              :   /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it.  */
    1842       277401 :   RANGE_FOR_INIT_STMT (r) = init;
    1843       277401 :   RANGE_FOR_SCOPE (r) = scope;
    1844              : 
    1845       277401 :   return r;
    1846              : }
    1847              : 
    1848              : /* Finish the head of a range-based for statement, which may
    1849              :    be given by RANGE_FOR_STMT.  DECL must be the declaration
    1850              :    and EXPR must be the loop expression. */
    1851              : 
    1852              : void
    1853       277401 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
    1854              : {
    1855       277401 :   if (processing_template_decl)
    1856       554802 :     RANGE_FOR_INIT_STMT (range_for_stmt)
    1857       554802 :       = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
    1858       277401 :   RANGE_FOR_DECL (range_for_stmt) = decl;
    1859       277401 :   RANGE_FOR_EXPR (range_for_stmt) = expr;
    1860       277401 :   add_stmt (range_for_stmt);
    1861       277401 :   RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
    1862       277401 : }
    1863              : 
    1864              : /* Begin the scope of an expansion-statement.  */
    1865              : 
    1866              : tree
    1867         2555 : begin_template_for_scope (tree *init)
    1868              : {
    1869         2555 :   tree scope = do_pushlevel (sk_template_for);
    1870              : 
    1871         2555 :   if (processing_template_decl)
    1872          610 :     *init = push_stmt_list ();
    1873              :   else
    1874         1945 :     *init = NULL_TREE;
    1875              : 
    1876         2555 :   return scope;
    1877              : }
    1878              : 
    1879              : /* Finish a break-statement.  */
    1880              : 
    1881              : tree
    1882      4892414 : finish_break_stmt (void)
    1883              : {
    1884              :   /* In switch statements break is sometimes stylistically used after
    1885              :      a return statement.  This can lead to spurious warnings about
    1886              :      control reaching the end of a non-void function when it is
    1887              :      inlined.  Note that we are calling block_may_fallthru with
    1888              :      language specific tree nodes; this works because
    1889              :      block_may_fallthru returns true when given something it does not
    1890              :      understand.  */
    1891      4892414 :   if (!block_may_fallthru (cur_stmt_list))
    1892          933 :     return void_node;
    1893      4891481 :   note_break_stmt ();
    1894      4891481 :   return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
    1895              : }
    1896              : 
    1897              : /* Finish a continue-statement.  */
    1898              : 
    1899              : tree
    1900       263843 : finish_continue_stmt (void)
    1901              : {
    1902       263843 :   return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
    1903              : }
    1904              : 
    1905              : /* Begin a switch-statement.  Returns a new SWITCH_STMT if
    1906              :    appropriate.  */
    1907              : 
    1908              : tree
    1909       736224 : begin_switch_stmt (void)
    1910              : {
    1911       736224 :   tree r, scope;
    1912              : 
    1913       736224 :   scope = do_pushlevel (sk_cond);
    1914       736224 :   r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1915              :                   scope, NULL_TREE);
    1916              : 
    1917       736224 :   begin_cond (&SWITCH_STMT_COND (r));
    1918              : 
    1919       736224 :   return r;
    1920              : }
    1921              : 
    1922              : /* Finish the cond of a switch-statement.  */
    1923              : 
    1924              : void
    1925       736224 : finish_switch_cond (tree cond, tree switch_stmt)
    1926              : {
    1927       736224 :   tree orig_type = NULL;
    1928              : 
    1929       736224 :   if (!processing_template_decl)
    1930              :     {
    1931              :       /* Convert the condition to an integer or enumeration type.  */
    1932       302688 :       tree orig_cond = cond;
    1933              :       /* For structured binding used in condition, the conversion needs to be
    1934              :          evaluated before the individual variables are initialized in the
    1935              :          std::tuple_{size,element} case.  cp_finish_decomp saved the
    1936              :          conversion result in a NON_LVALUE_EXPR, pick it up from there.  */
    1937          122 :       if (DECL_DECOMPOSITION_P (cond)
    1938           57 :           && DECL_DECOMP_IS_BASE (cond)
    1939           57 :           && DECL_DECOMP_BASE (cond)
    1940       302742 :           && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
    1941           18 :         cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
    1942       302688 :       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
    1943       302688 :       if (cond == NULL_TREE)
    1944              :         {
    1945           42 :           error_at (cp_expr_loc_or_input_loc (orig_cond),
    1946              :                     "switch quantity not an integer");
    1947           27 :           cond = error_mark_node;
    1948              :         }
    1949              :       /* We want unlowered type here to handle enum bit-fields.  */
    1950       302688 :       orig_type = unlowered_expr_type (cond);
    1951       302688 :       if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
    1952       208038 :         orig_type = TREE_TYPE (cond);
    1953       302688 :       if (cond != error_mark_node)
    1954              :         {
    1955              :           /* [stmt.switch]
    1956              : 
    1957              :              Integral promotions are performed.  */
    1958       302652 :           cond = perform_integral_promotions (cond);
    1959       302652 :           cond = maybe_cleanup_point_expr (cond);
    1960              :         }
    1961              :     }
    1962       736224 :   if (check_for_bare_parameter_packs (cond))
    1963            0 :     cond = error_mark_node;
    1964       736224 :   else if (!processing_template_decl && warn_sequence_point)
    1965         2853 :     verify_sequence_points (cond);
    1966              : 
    1967       736224 :   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
    1968       736224 :   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
    1969       736224 :   add_stmt (switch_stmt);
    1970       736224 :   push_switch (switch_stmt);
    1971       736224 :   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
    1972       736224 : }
    1973              : 
    1974              : /* Finish the body of a switch-statement, which may be given by
    1975              :    SWITCH_STMT.  The COND to switch on is indicated.  */
    1976              : 
    1977              : void
    1978       736224 : finish_switch_stmt (tree switch_stmt)
    1979              : {
    1980       736224 :   tree scope;
    1981              : 
    1982      1472448 :   SWITCH_STMT_BODY (switch_stmt) =
    1983       736224 :     pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
    1984       736224 :   pop_switch ();
    1985              : 
    1986       736224 :   scope = SWITCH_STMT_SCOPE (switch_stmt);
    1987       736224 :   SWITCH_STMT_SCOPE (switch_stmt) = NULL;
    1988       736224 :   add_stmt (do_poplevel (scope));
    1989       736224 : }
    1990              : 
    1991              : /* Begin a try-block.  Returns a newly-created TRY_BLOCK if
    1992              :    appropriate.  */
    1993              : 
    1994              : tree
    1995      1192301 : begin_try_block (void)
    1996              : {
    1997      1192301 :   tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
    1998      1192301 :   add_stmt (r);
    1999      1192301 :   TRY_STMTS (r) = push_stmt_list ();
    2000      1192301 :   return r;
    2001              : }
    2002              : 
    2003              : /* Likewise, for a function-try-block.  The block returned in
    2004              :    *COMPOUND_STMT is an artificial outer scope, containing the
    2005              :    function-try-block.  */
    2006              : 
    2007              : tree
    2008         2259 : begin_function_try_block (tree *compound_stmt)
    2009              : {
    2010         2259 :   tree r;
    2011              :   /* This outer scope does not exist in the C++ standard, but we need
    2012              :      a place to put __FUNCTION__ and similar variables.  */
    2013         2259 :   *compound_stmt = begin_compound_stmt (0);
    2014         2259 :   current_binding_level->artificial = 1;
    2015         2259 :   r = begin_try_block ();
    2016         2259 :   FN_TRY_BLOCK_P (r) = 1;
    2017         2259 :   return r;
    2018              : }
    2019              : 
    2020              : /* Finish a try-block, which may be given by TRY_BLOCK.  */
    2021              : 
    2022              : void
    2023      1192301 : finish_try_block (tree try_block)
    2024              : {
    2025      1192301 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2026      1192301 :   TRY_HANDLERS (try_block) = push_stmt_list ();
    2027      1192301 : }
    2028              : 
    2029              : /* Finish the body of a cleanup try-block, which may be given by
    2030              :    TRY_BLOCK.  */
    2031              : 
    2032              : void
    2033            0 : finish_cleanup_try_block (tree try_block)
    2034              : {
    2035            0 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2036            0 : }
    2037              : 
    2038              : /* Finish an implicitly generated try-block, with a cleanup is given
    2039              :    by CLEANUP.  */
    2040              : 
    2041              : void
    2042            0 : finish_cleanup (tree cleanup, tree try_block)
    2043              : {
    2044            0 :   TRY_HANDLERS (try_block) = cleanup;
    2045            0 :   CLEANUP_P (try_block) = 1;
    2046            0 : }
    2047              : 
    2048              : /* Likewise, for a function-try-block.  */
    2049              : 
    2050              : void
    2051         2259 : finish_function_try_block (tree try_block)
    2052              : {
    2053         2259 :   finish_try_block (try_block);
    2054              :   /* FIXME : something queer about CTOR_INITIALIZER somehow following
    2055              :      the try block, but moving it inside.  */
    2056         2259 :   in_function_try_handler = 1;
    2057         2259 : }
    2058              : 
    2059              : /* Finish a handler-sequence for a try-block, which may be given by
    2060              :    TRY_BLOCK.  */
    2061              : 
    2062              : void
    2063      1192301 : finish_handler_sequence (tree try_block)
    2064              : {
    2065      1192301 :   TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
    2066      1192301 :   check_handlers (TRY_HANDLERS (try_block));
    2067      1192301 : }
    2068              : 
    2069              : /* Finish the handler-seq for a function-try-block, given by
    2070              :    TRY_BLOCK.  COMPOUND_STMT is the outer block created by
    2071              :    begin_function_try_block.  */
    2072              : 
    2073              : void
    2074         2259 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
    2075              : {
    2076         2259 :   in_function_try_handler = 0;
    2077         2259 :   finish_handler_sequence (try_block);
    2078         2259 :   finish_compound_stmt (compound_stmt);
    2079         2259 : }
    2080              : 
    2081              : /* Begin a handler.  Returns a HANDLER if appropriate.  */
    2082              : 
    2083              : tree
    2084      1659484 : begin_handler (void)
    2085              : {
    2086      1659484 :   tree r;
    2087              : 
    2088      1659484 :   r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
    2089      1659484 :   add_stmt (r);
    2090              : 
    2091              :   /* Create a binding level for the eh_info and the exception object
    2092              :      cleanup.  */
    2093      1659484 :   HANDLER_BODY (r) = do_pushlevel (sk_catch);
    2094              : 
    2095      1659484 :   return r;
    2096              : }
    2097              : 
    2098              : /* Finish the handler-parameters for a handler, which may be given by
    2099              :    HANDLER.  DECL is the declaration for the catch parameter, or NULL
    2100              :    if this is a `catch (...)' clause.  */
    2101              : 
    2102              : void
    2103      1659484 : finish_handler_parms (tree decl, tree handler)
    2104              : {
    2105      1659484 :   tree type = NULL_TREE;
    2106      1659484 :   if (processing_template_decl)
    2107              :     {
    2108      1512991 :       if (decl)
    2109              :         {
    2110       490659 :           decl = pushdecl (decl);
    2111       490659 :           decl = push_template_decl (decl);
    2112       490659 :           HANDLER_PARMS (handler) = decl;
    2113       490659 :           type = TREE_TYPE (decl);
    2114              :         }
    2115              :     }
    2116              :   else
    2117              :     {
    2118       146493 :       type = expand_start_catch_block (decl);
    2119       146493 :       if (warn_catch_value
    2120         2116 :           && type != NULL_TREE
    2121          711 :           && type != error_mark_node
    2122       147204 :           && !TYPE_REF_P (TREE_TYPE (decl)))
    2123              :         {
    2124          210 :           tree orig_type = TREE_TYPE (decl);
    2125          210 :           if (CLASS_TYPE_P (orig_type))
    2126              :             {
    2127           96 :               if (TYPE_POLYMORPHIC_P (orig_type))
    2128           48 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2129           48 :                             OPT_Wcatch_value_,
    2130              :                             "catching polymorphic type %q#T by value",
    2131              :                             orig_type);
    2132           48 :               else if (warn_catch_value > 1)
    2133           36 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2134           36 :                             OPT_Wcatch_value_,
    2135              :                             "catching type %q#T by value", orig_type);
    2136              :             }
    2137          114 :           else if (warn_catch_value > 2)
    2138           54 :             warning_at (DECL_SOURCE_LOCATION (decl),
    2139           54 :                         OPT_Wcatch_value_,
    2140              :                         "catching non-reference type %q#T", orig_type);
    2141              :         }
    2142              :     }
    2143      1659484 :   HANDLER_TYPE (handler) = type;
    2144      1659484 : }
    2145              : 
    2146              : /* Finish a handler, which may be given by HANDLER.  The BLOCKs are
    2147              :    the return value from the matching call to finish_handler_parms.  */
    2148              : 
    2149              : void
    2150      1659484 : finish_handler (tree handler)
    2151              : {
    2152      1659484 :   if (!processing_template_decl)
    2153       146493 :     expand_end_catch_block ();
    2154      1659484 :   HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
    2155      1659484 : }
    2156              : 
    2157              : /* Begin a compound statement.  FLAGS contains some bits that control the
    2158              :    behavior and context.  If BCS_NO_SCOPE is set, the compound statement
    2159              :    does not define a scope.  If BCS_FN_BODY is set, this is the outermost
    2160              :    block of a function.  If BCS_TRY_BLOCK is set, this is the block
    2161              :    created on behalf of a TRY statement.  Returns a token to be passed to
    2162              :    finish_compound_stmt.  */
    2163              : 
    2164              : tree
    2165    292518558 : begin_compound_stmt (unsigned int flags)
    2166              : {
    2167    292518558 :   tree r;
    2168              : 
    2169    292518558 :   if (flags & BCS_NO_SCOPE)
    2170              :     {
    2171      5618310 :       r = push_stmt_list ();
    2172      5618310 :       STATEMENT_LIST_NO_SCOPE (r) = 1;
    2173              : 
    2174              :       /* Normally, we try hard to keep the BLOCK for a statement-expression.
    2175              :          But, if it's a statement-expression with a scopeless block, there's
    2176              :          nothing to keep, and we don't want to accidentally keep a block
    2177              :          *inside* the scopeless block.  */
    2178      5618310 :       keep_next_level (false);
    2179              :     }
    2180              :   else
    2181              :     {
    2182    286900248 :       scope_kind sk = sk_block;
    2183    286900248 :       if (flags & BCS_TRY_BLOCK)
    2184              :         sk = sk_try;
    2185    285708202 :       else if (flags & BCS_TRANSACTION)
    2186              :         sk = sk_transaction;
    2187    285707967 :       else if (flags & BCS_STMT_EXPR)
    2188        29160 :         sk = sk_stmt_expr;
    2189    286900248 :       r = do_pushlevel (sk);
    2190              :     }
    2191              : 
    2192              :   /* When processing a template, we need to remember where the braces were,
    2193              :      so that we can set up identical scopes when instantiating the template
    2194              :      later.  BIND_EXPR is a handy candidate for this.
    2195              :      Note that do_poplevel won't create a BIND_EXPR itself here (and thus
    2196              :      result in nested BIND_EXPRs), since we don't build BLOCK nodes when
    2197              :      processing templates.  */
    2198    292518558 :   if (processing_template_decl)
    2199              :     {
    2200    196005900 :       r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
    2201    196005900 :       BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
    2202    196005900 :       BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
    2203    196005900 :       TREE_SIDE_EFFECTS (r) = 1;
    2204              :     }
    2205              : 
    2206    292518558 :   return r;
    2207              : }
    2208              : 
    2209              : /* Finish a compound-statement, which is given by STMT.  */
    2210              : 
    2211              : void
    2212    292518513 : finish_compound_stmt (tree stmt)
    2213              : {
    2214    292518513 :   if (TREE_CODE (stmt) == BIND_EXPR)
    2215              :     {
    2216    196005900 :       tree body = do_poplevel (BIND_EXPR_BODY (stmt));
    2217              :       /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
    2218              :          discard the BIND_EXPR so it can be merged with the containing
    2219              :          STATEMENT_LIST.  */
    2220    196005900 :       if (TREE_CODE (body) == STATEMENT_LIST
    2221    178067352 :           && STATEMENT_LIST_HEAD (body) == NULL
    2222     11845947 :           && !BIND_EXPR_BODY_BLOCK (stmt)
    2223    207337856 :           && !BIND_EXPR_TRY_BLOCK (stmt))
    2224              :         stmt = body;
    2225              :       else
    2226    184674041 :         BIND_EXPR_BODY (stmt) = body;
    2227              :     }
    2228     96512613 :   else if (STATEMENT_LIST_NO_SCOPE (stmt))
    2229      5565516 :     stmt = pop_stmt_list (stmt);
    2230              :   else
    2231              :     {
    2232              :       /* Destroy any ObjC "super" receivers that may have been
    2233              :          created.  */
    2234     90947097 :       objc_clear_super_receiver ();
    2235              : 
    2236     90947097 :       stmt = do_poplevel (stmt);
    2237              :     }
    2238              : 
    2239              :   /* ??? See c_end_compound_stmt wrt statement expressions.  */
    2240    292518513 :   add_stmt (stmt);
    2241    292518513 : }
    2242              : 
    2243              : /* Finish an asm string literal, which can be a string literal
    2244              :    or parenthesized constant expression.  Extract the string literal
    2245              :    from the latter.  */
    2246              : 
    2247              : tree
    2248        59059 : finish_asm_string_expression (location_t loc, tree string)
    2249              : {
    2250        59059 :   if (string == error_mark_node
    2251        59046 :       || TREE_CODE (string) == STRING_CST
    2252          883 :       || processing_template_decl)
    2253              :     return string;
    2254          576 :   string = cxx_constant_value (string, tf_error);
    2255          576 :   if (TREE_CODE (string) == STRING_CST)
    2256           10 :     string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
    2257              :                          string);
    2258          576 :   cexpr_str cstr (string);
    2259          576 :   if (!cstr.type_check (loc))
    2260          171 :     return error_mark_node;
    2261          405 :   if (!cstr.extract (loc, string))
    2262           62 :     string = error_mark_node;
    2263          405 :   return string;
    2264          576 : }
    2265              : 
    2266              : /* Finish an asm-statement, whose components are a STRING, some
    2267              :    OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
    2268              :    LABELS.  Also note whether the asm-statement should be
    2269              :    considered volatile, and whether it is asm inline.  TOPLEV_P
    2270              :    is true if finishing namespace scope extended asm.  */
    2271              : 
    2272              : tree
    2273        33055 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
    2274              :                  tree output_operands, tree input_operands, tree clobbers,
    2275              :                  tree labels, bool inline_p, bool toplev_p)
    2276              : {
    2277        33055 :   tree r;
    2278        33055 :   tree t;
    2279        33055 :   int ninputs = list_length (input_operands);
    2280        33055 :   int noutputs = list_length (output_operands);
    2281              : 
    2282        33055 :   if (!processing_template_decl)
    2283              :     {
    2284        12837 :       const char *constraint;
    2285        12837 :       const char **oconstraints;
    2286        12837 :       bool allows_mem, allows_reg, is_inout;
    2287        12837 :       tree operand;
    2288        12837 :       int i;
    2289              : 
    2290        12837 :       oconstraints = XALLOCAVEC (const char *, noutputs);
    2291              : 
    2292        25572 :       string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
    2293              :                                              string);
    2294        12837 :       if (string == error_mark_node)
    2295          109 :         return error_mark_node;
    2296        38229 :       for (int i = 0; i < 2; ++i)
    2297        62031 :         for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
    2298              :           {
    2299        36560 :             tree s = TREE_VALUE (TREE_PURPOSE (t));
    2300        73102 :             s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2301        36560 :             if (s == error_mark_node)
    2302              :               return error_mark_node;
    2303        36530 :             TREE_VALUE (TREE_PURPOSE (t)) = s;
    2304              :           }
    2305        21790 :       for (t = clobbers; t; t = TREE_CHAIN (t))
    2306              :         {
    2307         9062 :           tree s = TREE_VALUE (t);
    2308        18118 :           s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2309         9062 :           TREE_VALUE (t) = s;
    2310              :         }
    2311              : 
    2312        12728 :       string = resolve_asm_operand_names (string, output_operands,
    2313              :                                           input_operands, labels);
    2314              : 
    2315        44517 :       for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
    2316              :         {
    2317        19061 :           operand = TREE_VALUE (t);
    2318              : 
    2319              :           /* ??? Really, this should not be here.  Users should be using a
    2320              :              proper lvalue, dammit.  But there's a long history of using
    2321              :              casts in the output operands.  In cases like longlong.h, this
    2322              :              becomes a primitive form of typechecking -- if the cast can be
    2323              :              removed, then the output operand had a type of the proper width;
    2324              :              otherwise we'll get an error.  Gross, but ...  */
    2325        19061 :           STRIP_NOPS (operand);
    2326              : 
    2327        19061 :           operand = mark_lvalue_use (operand);
    2328              : 
    2329        19061 :           if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
    2330            9 :             operand = error_mark_node;
    2331              : 
    2332        19061 :           if (operand != error_mark_node
    2333        19061 :               && (TREE_READONLY (operand)
    2334        19046 :                   || CP_TYPE_CONST_P (TREE_TYPE (operand))
    2335              :                   /* Functions are not modifiable, even though they are
    2336              :                      lvalues.  */
    2337        19046 :                   || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
    2338              :                   /* If it's an aggregate and any field is const, then it is
    2339              :                      effectively const.  */
    2340        19046 :                   || (CLASS_TYPE_P (TREE_TYPE (operand))
    2341          435 :                       && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
    2342            6 :             cxx_readonly_error (loc, operand, lv_asm);
    2343              : 
    2344        19061 :           tree *op = &operand;
    2345        19068 :           while (TREE_CODE (*op) == COMPOUND_EXPR)
    2346            7 :             op = &TREE_OPERAND (*op, 1);
    2347        19061 :           switch (TREE_CODE (*op))
    2348              :             {
    2349           30 :             case PREINCREMENT_EXPR:
    2350           30 :             case PREDECREMENT_EXPR:
    2351           30 :             case MODIFY_EXPR:
    2352           30 :               *op = genericize_compound_lvalue (*op);
    2353           30 :               op = &TREE_OPERAND (*op, 1);
    2354           30 :               break;
    2355              :             default:
    2356              :               break;
    2357              :             }
    2358              : 
    2359        19061 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2360        19061 :           oconstraints[i] = constraint;
    2361              : 
    2362        19061 :           if (parse_output_constraint (&constraint, i, ninputs, noutputs,
    2363              :                                        &allows_mem, &allows_reg, &is_inout,
    2364              :                                        nullptr))
    2365              :             {
    2366              :               /* If the operand is going to end up in memory,
    2367              :                  mark it addressable.  */
    2368        19052 :               if (!allows_reg && !cxx_mark_addressable (*op))
    2369            0 :                 operand = error_mark_node;
    2370        19052 :               if (allows_reg && toplev_p)
    2371              :                 {
    2372            3 :                   error_at (loc, "constraint allows registers outside of "
    2373              :                                  "a function");
    2374            3 :                   operand = error_mark_node;
    2375              :                 }
    2376              :             }
    2377              :           else
    2378            9 :             operand = error_mark_node;
    2379              : 
    2380          715 :           if (toplev_p && operand != error_mark_node)
    2381              :             {
    2382           21 :               if (TREE_SIDE_EFFECTS (operand))
    2383              :                 {
    2384            0 :                   error_at (loc, "side-effects in output operand outside "
    2385              :                                  "of a function");
    2386            0 :                   operand = error_mark_node;
    2387              :                 }
    2388              :               else
    2389              :                 {
    2390           21 :                   tree addr
    2391           21 :                     = cp_build_addr_expr (operand, tf_warning_or_error);
    2392           21 :                   if (addr == error_mark_node)
    2393            0 :                     operand = error_mark_node;
    2394              :                   else
    2395              :                     {
    2396           21 :                       addr = maybe_constant_value (addr);
    2397           21 :                       if (!initializer_constant_valid_p (addr,
    2398           21 :                                                          TREE_TYPE (addr)))
    2399              :                         {
    2400            3 :                           error_at (loc, "output operand outside of a "
    2401              :                                          "function is not constant");
    2402            3 :                           operand = error_mark_node;
    2403              :                         }
    2404              :                       else
    2405           18 :                         operand = build_fold_indirect_ref (addr);
    2406              :                     }
    2407              :                 }
    2408              :             }
    2409        19040 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2410              :             {
    2411            3 :               error_at (loc, "%<-%> modifier used inside of a function");
    2412            3 :               operand = error_mark_node;
    2413              :             }
    2414              : 
    2415        19061 :           TREE_VALUE (t) = operand;
    2416              :         }
    2417              : 
    2418        30192 :       for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
    2419              :         {
    2420        17464 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2421        17464 :           bool constraint_parsed
    2422        17464 :             = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    2423              :                                       oconstraints, &allows_mem, &allows_reg,
    2424              :                                       nullptr);
    2425              :           /* If the operand is going to end up in memory, don't call
    2426              :              decay_conversion.  */
    2427        17464 :           if (constraint_parsed && !allows_reg && allows_mem)
    2428          609 :             operand = mark_lvalue_use (TREE_VALUE (t));
    2429              :           else
    2430        16855 :             operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
    2431              : 
    2432              :           /* If the type of the operand hasn't been determined (e.g.,
    2433              :              because it involves an overloaded function), then issue
    2434              :              an error message.  There's no context available to
    2435              :              resolve the overloading.  */
    2436        17464 :           if (TREE_TYPE (operand) == unknown_type_node)
    2437              :             {
    2438            3 :               error_at (loc,
    2439              :                         "type of %<asm%> operand %qE could not be determined",
    2440            3 :                         TREE_VALUE (t));
    2441            3 :               operand = error_mark_node;
    2442              :             }
    2443              : 
    2444        17464 :           if (constraint_parsed)
    2445              :             {
    2446              :               /* If the operand is going to end up in memory,
    2447              :                  mark it addressable.  */
    2448        17443 :               if (!allows_reg && allows_mem)
    2449              :                 {
    2450              :                   /* Strip the nops as we allow this case.  FIXME, this really
    2451              :                      should be rejected or made deprecated.  */
    2452          609 :                   STRIP_NOPS (operand);
    2453              : 
    2454          609 :                   tree *op = &operand;
    2455          616 :                   while (TREE_CODE (*op) == COMPOUND_EXPR)
    2456            7 :                     op = &TREE_OPERAND (*op, 1);
    2457          609 :                   switch (TREE_CODE (*op))
    2458              :                     {
    2459           27 :                     case PREINCREMENT_EXPR:
    2460           27 :                     case PREDECREMENT_EXPR:
    2461           27 :                     case MODIFY_EXPR:
    2462           27 :                       *op = genericize_compound_lvalue (*op);
    2463           27 :                       op = &TREE_OPERAND (*op, 1);
    2464           27 :                       break;
    2465              :                     default:
    2466              :                       break;
    2467              :                     }
    2468              : 
    2469          609 :                   if (!cxx_mark_addressable (*op))
    2470            0 :                     operand = error_mark_node;
    2471              :                 }
    2472        16834 :               else if (!allows_reg && !allows_mem)
    2473              :                 {
    2474              :                   /* If constraint allows neither register nor memory,
    2475              :                      try harder to get a constant.  */
    2476          465 :                   tree constop = maybe_constant_value (operand);
    2477          465 :                   if (TREE_CONSTANT (constop))
    2478          438 :                     operand = constop;
    2479              :                 }
    2480        17443 :               if (allows_reg && toplev_p)
    2481              :                 {
    2482            3 :                   error_at (loc, "constraint allows registers outside of "
    2483              :                                  "a function");
    2484            3 :                   operand = error_mark_node;
    2485              :                 }
    2486        17443 :               if (constraint[0] == ':' && operand != error_mark_node)
    2487              :                 {
    2488           48 :                   tree t = operand;
    2489           48 :                   STRIP_NOPS (t);
    2490           48 :                   if (TREE_CODE (t) != ADDR_EXPR
    2491           48 :                       || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
    2492           30 :                            || (VAR_P (TREE_OPERAND (t, 0))
    2493           24 :                                && is_global_var (TREE_OPERAND (t, 0)))))
    2494              :                     {
    2495           15 :                       error_at (loc, "%<:%> constraint operand is not address "
    2496              :                                 "of a function or non-automatic variable");
    2497           15 :                       operand = error_mark_node;
    2498              :                     }
    2499           33 :                   else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
    2500           12 :                     suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
    2501              :                 }
    2502              :             }
    2503              :           else
    2504           21 :             operand = error_mark_node;
    2505              : 
    2506        17464 :           if (toplev_p && operand != error_mark_node)
    2507              :             {
    2508          117 :               if (TREE_SIDE_EFFECTS (operand))
    2509              :                 {
    2510            6 :                   error_at (loc, "side-effects in input operand outside "
    2511              :                                  "of a function");
    2512            6 :                   operand = error_mark_node;
    2513              :                 }
    2514          111 :               else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
    2515              :                 {
    2516           21 :                   tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
    2517           21 :                   if (addr == error_mark_node)
    2518            0 :                     operand = error_mark_node;
    2519              :                   else
    2520              :                     {
    2521           21 :                       addr = maybe_constant_value (addr);
    2522           21 :                       if (!initializer_constant_valid_p (addr,
    2523           21 :                                                          TREE_TYPE (addr)))
    2524              :                         {
    2525            3 :                           error_at (loc, "input operand outside of a "
    2526              :                                          "function is not constant");
    2527            3 :                           operand = error_mark_node;
    2528              :                         }
    2529              :                       else
    2530           18 :                         operand = build_fold_indirect_ref (addr);
    2531              :                     }
    2532              :                 }
    2533              :               else
    2534              :                 {
    2535           90 :                   operand = maybe_constant_value (operand);
    2536           90 :                   if (!initializer_constant_valid_p (operand,
    2537           90 :                                                      TREE_TYPE (operand)))
    2538              :                     {
    2539            3 :                       error_at (loc, "input operand outside of a "
    2540              :                                      "function is not constant");
    2541            3 :                       operand = error_mark_node;
    2542              :                     }
    2543              :                 }
    2544              :             }
    2545        17347 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2546              :             {
    2547            9 :               error_at (loc, "%<-%> modifier used inside of a function");
    2548            9 :               operand = error_mark_node;
    2549              :             }
    2550              : 
    2551        17464 :           TREE_VALUE (t) = operand;
    2552              :         }
    2553              :     }
    2554              : 
    2555        32946 :   r = build_stmt (loc, ASM_EXPR, string,
    2556              :                   output_operands, input_operands,
    2557              :                   clobbers, labels);
    2558        32946 :   ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
    2559        32946 :   ASM_INLINE_P (r) = inline_p;
    2560        32946 :   if (toplev_p)
    2561              :     {
    2562           99 :       symtab->finalize_toplevel_asm (r);
    2563           99 :       return r;
    2564              :     }
    2565        32847 :   r = maybe_cleanup_point_expr_void (r);
    2566        32847 :   return add_stmt (r);
    2567              : }
    2568              : 
    2569              : /* Finish a label with the indicated NAME.  Returns the new label.  */
    2570              : 
    2571              : tree
    2572         3746 : finish_label_stmt (tree name)
    2573              : {
    2574         3746 :   tree decl = define_label (input_location, name);
    2575              : 
    2576         3746 :   if (decl == error_mark_node)
    2577              :     return error_mark_node;
    2578              : 
    2579         3714 :   add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
    2580              : 
    2581         3714 :   return decl;
    2582              : }
    2583              : 
    2584              : /* Finish a series of declarations for local labels.  G++ allows users
    2585              :    to declare "local" labels, i.e., labels with scope.  This extension
    2586              :    is useful when writing code involving statement-expressions.  */
    2587              : 
    2588              : void
    2589          219 : finish_label_decl (tree name)
    2590              : {
    2591          219 :   if (!at_function_scope_p ())
    2592              :     {
    2593            0 :       error ("%<__label__%> declarations are only allowed in function scopes");
    2594            0 :       return;
    2595              :     }
    2596              : 
    2597          219 :   add_decl_expr (declare_local_label (name));
    2598              : }
    2599              : 
    2600              : /* When DECL goes out of scope, make sure that CLEANUP is executed.  */
    2601              : 
    2602              : void
    2603      3572166 : finish_decl_cleanup (tree decl, tree cleanup)
    2604              : {
    2605      3572166 :   push_cleanup (decl, cleanup, false);
    2606      3572166 : }
    2607              : 
    2608              : /* If the current scope exits with an exception, run CLEANUP.  */
    2609              : 
    2610              : void
    2611      2253665 : finish_eh_cleanup (tree cleanup)
    2612              : {
    2613      2253665 :   push_cleanup (NULL, cleanup, true);
    2614      2253665 : }
    2615              : 
    2616              : /* The MEM_INITS is a list of mem-initializers, in reverse of the
    2617              :    order they were written by the user.  Each node is as for
    2618              :    emit_mem_initializers.  */
    2619              : 
    2620              : void
    2621     20796235 : finish_mem_initializers (tree mem_inits)
    2622              : {
    2623              :   /* Reorder the MEM_INITS so that they are in the order they appeared
    2624              :      in the source program.  */
    2625     20796235 :   mem_inits = nreverse (mem_inits);
    2626              : 
    2627     20796235 :   if (processing_template_decl)
    2628              :     {
    2629              :       tree mem;
    2630              : 
    2631     35167730 :       for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
    2632              :         {
    2633              :           /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
    2634              :              check for bare parameter packs in the TREE_VALUE, because
    2635              :              any parameter packs in the TREE_VALUE have already been
    2636              :              bound as part of the TREE_PURPOSE.  See
    2637              :              make_pack_expansion for more information.  */
    2638     20804753 :           if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
    2639     20804753 :               && check_for_bare_parameter_packs (TREE_VALUE (mem)))
    2640            3 :             TREE_VALUE (mem) = error_mark_node;
    2641              :         }
    2642              : 
    2643     14362977 :       add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
    2644              :                                   CTOR_INITIALIZER, mem_inits));
    2645              :     }
    2646              :   else
    2647      6433258 :     emit_mem_initializers (mem_inits);
    2648     20796235 : }
    2649              : 
    2650              : /* Obfuscate EXPR if it looks like an id-expression or member access so
    2651              :    that the call to finish_decltype in do_auto_deduction will give the
    2652              :    right result.  If EVEN_UNEVAL, do this even in unevaluated context.  */
    2653              : 
    2654              : tree
    2655     45825887 : force_paren_expr (tree expr, bool even_uneval /* = false */)
    2656              : {
    2657              :   /* This is only needed for decltype(auto) in C++14.  */
    2658     45825887 :   if (cxx_dialect < cxx14)
    2659              :     return expr;
    2660              : 
    2661              :   /* If we're in unevaluated context, we can't be deducing a
    2662              :      return/initializer type, so we don't need to mess with this.  */
    2663     45209488 :   if (cp_unevaluated_operand && !even_uneval)
    2664              :     return expr;
    2665              : 
    2666     37561241 :   if (TREE_CODE (expr) == COMPONENT_REF
    2667     37499183 :       || TREE_CODE (expr) == SCOPE_REF
    2668     75053452 :       || REFERENCE_REF_P (expr))
    2669       626398 :     REF_PARENTHESIZED_P (expr) = true;
    2670     36934843 :   else if (DECL_P (tree_strip_any_location_wrapper (expr)))
    2671              :     {
    2672      1747367 :       location_t loc = cp_expr_location (expr);
    2673      1747367 :       const tree_code code = processing_template_decl ? PAREN_EXPR
    2674              :                                                       : VIEW_CONVERT_EXPR;
    2675      1747367 :       expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
    2676      1747367 :       REF_PARENTHESIZED_P (expr) = true;
    2677              :     }
    2678              :   return expr;
    2679              : }
    2680              : 
    2681              : /* If T is an id-expression obfuscated by force_paren_expr, undo the
    2682              :    obfuscation and return the underlying id-expression.  Otherwise
    2683              :    return T.  */
    2684              : 
    2685              : tree
    2686   1017622401 : maybe_undo_parenthesized_ref (tree t)
    2687              : {
    2688   1017622401 :   if (cxx_dialect < cxx14)
    2689              :     return t;
    2690              : 
    2691   1007773493 :   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
    2692   1117347706 :       && REF_PARENTHESIZED_P (t))
    2693       201833 :     t = TREE_OPERAND (t, 0);
    2694              : 
    2695              :   return t;
    2696              : }
    2697              : 
    2698              : /* Finish a parenthesized expression EXPR.  */
    2699              : 
    2700              : cp_expr
    2701     34076442 : finish_parenthesized_expr (cp_expr expr)
    2702              : {
    2703     34076442 :   if (EXPR_P (expr))
    2704              :     {
    2705              :       /* This inhibits warnings in maybe_warn_unparenthesized_assignment
    2706              :          and c_common_truthvalue_conversion.  */
    2707     67744175 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
    2708              :       /* And maybe_warn_sizeof_array_div.  */
    2709     67744175 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
    2710              :     }
    2711              : 
    2712     34076442 :   if (TREE_CODE (expr) == OFFSET_REF
    2713     34076442 :       || TREE_CODE (expr) == SCOPE_REF)
    2714              :     /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
    2715              :        enclosed in parentheses.  */
    2716        31453 :     PTRMEM_OK_P (expr) = 0;
    2717              : 
    2718     34076442 :   tree stripped_expr = tree_strip_any_location_wrapper (expr);
    2719     34076442 :   if (TREE_CODE (stripped_expr) == STRING_CST)
    2720       902359 :     PAREN_STRING_LITERAL_P (stripped_expr) = 1;
    2721     33174083 :   else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
    2722         1500 :     PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
    2723              : 
    2724     34076442 :   expr = cp_expr (force_paren_expr (expr), expr.get_location ());
    2725              : 
    2726     34076442 :   return expr;
    2727              : }
    2728              : 
    2729              : /* Finish a reference to a non-static data member (DECL) that is not
    2730              :    preceded by `.' or `->'.  */
    2731              : 
    2732              : tree
    2733     79083217 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
    2734              :                                tsubst_flags_t complain /* = tf_warning_or_error */)
    2735              : {
    2736     79083217 :   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
    2737     79083217 :   bool try_omp_private = !object && omp_private_member_map;
    2738     68666068 :   tree ret;
    2739              : 
    2740     68666068 :   if (!object)
    2741              :     {
    2742     68666068 :       tree scope = qualifying_scope;
    2743     68666068 :       if (scope == NULL_TREE)
    2744              :         {
    2745     68653926 :           scope = context_for_name_lookup (decl);
    2746     68653926 :           if (!TYPE_P (scope))
    2747              :             {
    2748              :               /* Can happen during error recovery (c++/85014).  */
    2749            3 :               gcc_assert (seen_error ());
    2750            3 :               return error_mark_node;
    2751              :             }
    2752              :         }
    2753     68666065 :       object = maybe_dummy_object (scope, NULL);
    2754              :     }
    2755              : 
    2756     79083214 :   object = maybe_resolve_dummy (object, true);
    2757     79083214 :   if (object == error_mark_node)
    2758              :     return error_mark_node;
    2759              : 
    2760              :   /* DR 613/850: Can use non-static data members without an associated
    2761              :      object in sizeof/decltype/alignof.  */
    2762     79083211 :   if (is_dummy_object (object)
    2763        36287 :       && !cp_unevaluated_operand
    2764     79083317 :       && (!processing_template_decl || !current_class_ref))
    2765              :     {
    2766           91 :       if (complain & tf_error)
    2767              :         {
    2768           74 :           auto_diagnostic_group d;
    2769           74 :           if (current_function_decl
    2770           74 :               && DECL_STATIC_FUNCTION_P (current_function_decl))
    2771            3 :             error ("invalid use of member %qD in static member function", decl);
    2772           71 :           else if (current_function_decl
    2773           63 :                    && processing_contract_condition
    2774           71 :                    && DECL_CONSTRUCTOR_P (current_function_decl))
    2775            0 :             error ("invalid use of member %qD in constructor %<pre%> contract", decl);
    2776           71 :           else if (current_function_decl
    2777           63 :                    && processing_contract_condition
    2778           71 :                    && DECL_DESTRUCTOR_P (current_function_decl))
    2779            0 :             error ("invalid use of member %qD in destructor %<post%> contract", decl);
    2780              :           else
    2781           71 :             error ("invalid use of non-static data member %qD", decl);
    2782           74 :           inform (DECL_SOURCE_LOCATION (decl), "declared here");
    2783           74 :         }
    2784              : 
    2785           91 :       return error_mark_node;
    2786              :     }
    2787              : 
    2788     79083120 :   if (current_class_ptr)
    2789     78752437 :     TREE_USED (current_class_ptr) = 1;
    2790     79083120 :   if (processing_template_decl)
    2791              :     {
    2792     62928906 :       tree type = TREE_TYPE (decl);
    2793              : 
    2794     62928906 :       if (TYPE_REF_P (type))
    2795              :         /* Quals on the object don't matter.  */;
    2796     60521031 :       else if (PACK_EXPANSION_P (type))
    2797              :         /* Don't bother trying to represent this.  */
    2798              :         type = NULL_TREE;
    2799     60517975 :       else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
    2800              :         /* We don't know what the eventual quals will be, so punt until
    2801              :            instantiation time.
    2802              : 
    2803              :            This can happen when called from build_capture_proxy for an explicit
    2804              :            object lambda.  It's a bit marginal to call this function in that
    2805              :            case, since this function is for references to members of 'this',
    2806              :            but the deduced type is required to be derived from the closure
    2807              :            type, so it works.  */
    2808              :         type = NULL_TREE;
    2809              :       else
    2810              :         {
    2811              :           /* Set the cv qualifiers.  */
    2812     60513357 :           auto quals = cp_type_quals (TREE_TYPE (object));
    2813              : 
    2814     60513357 :           if (DECL_MUTABLE_P (decl))
    2815       240735 :             quals &= ~TYPE_QUAL_CONST;
    2816              : 
    2817     60513357 :           quals |= cp_type_quals (TREE_TYPE (decl));
    2818     60513357 :           type = cp_build_qualified_type (type, quals);
    2819              :         }
    2820              : 
    2821     62928906 :       if (qualifying_scope)
    2822              :         /* Wrap this in a SCOPE_REF for now.  */
    2823         9464 :         ret = build_qualified_name (type, qualifying_scope, decl,
    2824              :                                     /*template_p=*/false);
    2825              :       else
    2826     62919442 :         ret = (convert_from_reference
    2827     62919442 :                (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
    2828              :     }
    2829              :   /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
    2830              :      QUALIFYING_SCOPE is also non-null.  */
    2831              :   else
    2832              :     {
    2833     16154214 :       tree access_type = TREE_TYPE (object);
    2834              : 
    2835     16154214 :       if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
    2836              :                                           decl, complain))
    2837            0 :         return error_mark_node;
    2838              : 
    2839              :       /* If the data member was named `C::M', convert `*this' to `C'
    2840              :          first.  */
    2841     16154214 :       if (qualifying_scope)
    2842              :         {
    2843         2631 :           tree binfo = NULL_TREE;
    2844         2631 :           object = build_scoped_ref (object, qualifying_scope,
    2845              :                                      &binfo);
    2846              :         }
    2847              : 
    2848     16154214 :       ret = build_class_member_access_expr (object, decl,
    2849              :                                             /*access_path=*/NULL_TREE,
    2850              :                                             /*preserve_reference=*/false,
    2851              :                                             complain);
    2852              :     }
    2853     79083120 :   if (try_omp_private)
    2854              :     {
    2855         1671 :       tree *v = omp_private_member_map->get (decl);
    2856         1671 :       if (v)
    2857         1243 :         ret = convert_from_reference (*v);
    2858              :     }
    2859              :   return ret;
    2860              : }
    2861              : 
    2862              : /* DECL was the declaration to which a qualified-id resolved.  Issue
    2863              :    an error message if it is not accessible.  If OBJECT_TYPE is
    2864              :    non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
    2865              :    type of `*x', or `x', respectively.  If the DECL was named as
    2866              :    `A::B' then NESTED_NAME_SPECIFIER is `A'.  Return value is like
    2867              :    perform_access_checks above.  */
    2868              : 
    2869              : bool
    2870   4949487958 : check_accessibility_of_qualified_id (tree decl,
    2871              :                                      tree object_type,
    2872              :                                      tree nested_name_specifier,
    2873              :                                      tsubst_flags_t complain)
    2874              : {
    2875              :   /* If we're not checking, return immediately.  */
    2876   4949487958 :   if (deferred_access_no_check)
    2877              :     return true;
    2878              : 
    2879              :   /* Determine the SCOPE of DECL.  */
    2880   4938282444 :   tree scope = context_for_name_lookup (decl);
    2881              :   /* If the SCOPE is not a type, then DECL is not a member.  */
    2882   4938282444 :   if (!TYPE_P (scope)
    2883              :       /* If SCOPE is dependent then we can't perform this access check now,
    2884              :          and since we'll perform this access check again after substitution
    2885              :          there's no need to explicitly defer it.  */
    2886   4938282444 :       || dependent_type_p (scope))
    2887              :     return true;
    2888              : 
    2889    472108153 :   tree qualifying_type = NULL_TREE;
    2890              :   /* Compute the scope through which DECL is being accessed.  */
    2891    472108153 :   if (object_type
    2892              :       /* OBJECT_TYPE might not be a class type; consider:
    2893              : 
    2894              :            class A { typedef int I; };
    2895              :            I *p;
    2896              :            p->A::I::~I();
    2897              : 
    2898              :          In this case, we will have "A::I" as the DECL, but "I" as the
    2899              :          OBJECT_TYPE.  */
    2900        99684 :       && CLASS_TYPE_P (object_type)
    2901    472207820 :       && DERIVED_FROM_P (scope, object_type))
    2902              :     {
    2903              :       /* If we are processing a `->' or `.' expression, use the type of the
    2904              :          left-hand side.  */
    2905        99658 :       if (tree open = currently_open_class (object_type))
    2906              :         qualifying_type = open;
    2907              :       else
    2908              :         qualifying_type = object_type;
    2909              :     }
    2910    472008495 :   else if (nested_name_specifier)
    2911              :     {
    2912              :       /* If the reference is to a non-static member of the
    2913              :          current class, treat it as if it were referenced through
    2914              :          `this'.  */
    2915    629541445 :       if (DECL_NONSTATIC_MEMBER_P (decl)
    2916    314823368 :           && current_class_ptr)
    2917        41759 :         if (tree current = current_nonlambda_class_type ())
    2918              :           {
    2919        41714 :             if (dependent_type_p (current))
    2920              :             /* In general we can't know whether this access goes through
    2921              :                `this' until instantiation time.  Punt now, or else we might
    2922              :                create a deferred access check that's not relative to `this'
    2923              :                when it ought to be.  We'll check this access again after
    2924              :                substitution, e.g. from tsubst_qualified_id.  */
    2925              :               return true;
    2926              : 
    2927         4199 :             if (DERIVED_FROM_P (scope, current))
    2928              :               qualifying_type = current;
    2929              :           }
    2930              :       /* Otherwise, use the type indicated by the
    2931              :          nested-name-specifier.  */
    2932              :       if (!qualifying_type)
    2933              :         qualifying_type = nested_name_specifier;
    2934              :     }
    2935              :   else
    2936              :     /* Otherwise, the name must be from the current class or one of
    2937              :        its bases.  */
    2938    157237771 :     qualifying_type = currently_open_derived_class (scope);
    2939              : 
    2940    472008462 :   if (qualifying_type
    2941              :       /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
    2942              :          or similar in a default argument value.  */
    2943    472070638 :       && CLASS_TYPE_P (qualifying_type))
    2944    444023377 :     return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
    2945    444023377 :                                           decl, complain);
    2946              : 
    2947              :   return true;
    2948              : }
    2949              : 
    2950              : /* EXPR is the result of a qualified-id.  The QUALIFYING_CLASS was the
    2951              :    class named to the left of the "::" operator.  DONE is true if this
    2952              :    expression is a complete postfix-expression; it is false if this
    2953              :    expression is followed by '->', '[', '(', etc.  ADDRESS_P is true
    2954              :    iff this expression is the operand of '&'.  TEMPLATE_P is true iff
    2955              :    the qualified-id was of the form "A::template B".  TEMPLATE_ARG_P
    2956              :    is true iff this qualified name appears as a template argument.  */
    2957              : 
    2958              : tree
    2959     85085637 : finish_qualified_id_expr (tree qualifying_class,
    2960              :                           tree expr,
    2961              :                           bool done,
    2962              :                           bool address_p,
    2963              :                           bool template_p,
    2964              :                           bool template_arg_p,
    2965              :                           tsubst_flags_t complain)
    2966              : {
    2967     85085637 :   gcc_assert (TYPE_P (qualifying_class));
    2968              : 
    2969     85085637 :   if (error_operand_p (expr))
    2970           21 :     return error_mark_node;
    2971              : 
    2972     85085616 :   if (DECL_P (expr)
    2973              :       /* Functions are marked after overload resolution; avoid redundant
    2974              :          warnings.  */
    2975     77877709 :       && TREE_CODE (expr) != FUNCTION_DECL
    2976    162963301 :       && !mark_used (expr, complain))
    2977            0 :     return error_mark_node;
    2978              : 
    2979     85085616 :   if (template_p)
    2980              :     {
    2981       263320 :       if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
    2982              :         {
    2983              :           /* cp_parser_lookup_name thought we were looking for a type,
    2984              :              but we're actually looking for a declaration.  */
    2985            9 :           qualifying_class = TYPE_CONTEXT (expr);
    2986            9 :           expr = TYPE_IDENTIFIER (expr);
    2987              :         }
    2988              :       else
    2989       263311 :         check_template_keyword (expr);
    2990              :     }
    2991              : 
    2992              :   /* If EXPR occurs as the operand of '&', use special handling that
    2993              :      permits a pointer-to-member.  */
    2994     85085616 :   if (address_p && done
    2995       162601 :       && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
    2996              :     {
    2997       162599 :       if (TREE_CODE (expr) == SCOPE_REF)
    2998            0 :         expr = TREE_OPERAND (expr, 1);
    2999       162599 :       expr = build_offset_ref (qualifying_class, expr,
    3000              :                                /*address_p=*/true, complain);
    3001       162599 :       return expr;
    3002              :     }
    3003              : 
    3004              :   /* No need to check access within an enum.  */
    3005     84923017 :   if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
    3006      3771154 :       && TREE_CODE (expr) != IDENTIFIER_NODE)
    3007              :     return expr;
    3008              : 
    3009              :   /* Within the scope of a class, turn references to non-static
    3010              :      members into expression of the form "this->...".  */
    3011     81151866 :   if (template_arg_p)
    3012              :     /* But, within a template argument, we do not want make the
    3013              :        transformation, as there is no "this" pointer.  */
    3014              :     ;
    3015     81149182 :   else if (TREE_CODE (expr) == FIELD_DECL)
    3016              :     {
    3017        12142 :       push_deferring_access_checks (dk_no_check);
    3018        12142 :       expr = finish_non_static_data_member (expr, NULL_TREE,
    3019              :                                             qualifying_class, complain);
    3020        12142 :       pop_deferring_access_checks ();
    3021              :     }
    3022     81137040 :   else if (BASELINK_P (expr))
    3023              :     {
    3024              :       /* See if any of the functions are non-static members.  */
    3025              :       /* If so, the expression may be relative to 'this'.  */
    3026      6722276 :       if (!shared_member_p (expr)
    3027       447562 :           && current_class_ptr
    3028      7169151 :           && DERIVED_FROM_P (qualifying_class,
    3029              :                              current_nonlambda_class_type ()))
    3030       446561 :         expr = (build_class_member_access_expr
    3031       446561 :                 (maybe_dummy_object (qualifying_class, NULL),
    3032              :                  expr,
    3033       446561 :                  BASELINK_ACCESS_BINFO (expr),
    3034              :                  /*preserve_reference=*/false,
    3035              :                  complain));
    3036      6275715 :       else if (done)
    3037              :         /* The expression is a qualified name whose address is not
    3038              :            being taken.  */
    3039         3633 :         expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
    3040              :                                  complain);
    3041              :     }
    3042     74414764 :   else if (!template_p
    3043     74201482 :            && TREE_CODE (expr) == TEMPLATE_DECL
    3044     74414848 :            && !DECL_FUNCTION_TEMPLATE_P (expr))
    3045              :     {
    3046           84 :       if (complain & tf_error)
    3047            5 :         error ("%qE missing template arguments", expr);
    3048           84 :       return error_mark_node;
    3049              :     }
    3050              :   else
    3051              :     {
    3052              :       /* In a template, return a SCOPE_REF for most qualified-ids
    3053              :          so that we can check access at instantiation time.  But if
    3054              :          we're looking at a member of the current instantiation, we
    3055              :          know we have access and building up the SCOPE_REF confuses
    3056              :          non-type template argument handling.  */
    3057     74414680 :       if (processing_template_decl
    3058     74414680 :           && (!currently_open_class (qualifying_class)
    3059        10602 :               || TREE_CODE (expr) == IDENTIFIER_NODE
    3060        10602 :               || TREE_CODE (expr) == TEMPLATE_ID_EXPR
    3061           82 :               || TREE_CODE (expr) == BIT_NOT_EXPR))
    3062     10909559 :         expr = build_qualified_name (TREE_TYPE (expr),
    3063              :                                      qualifying_class, expr,
    3064              :                                      template_p);
    3065     63505121 :       else if (tree wrap = maybe_get_tls_wrapper_call (expr))
    3066            9 :         expr = wrap;
    3067              : 
    3068     74414680 :       expr = convert_from_reference (expr);
    3069              :     }
    3070              : 
    3071              :   return expr;
    3072              : }
    3073              : 
    3074              : /* Begin a statement-expression.  The value returned must be passed to
    3075              :    finish_stmt_expr.  */
    3076              : 
    3077              : tree
    3078      5640080 : begin_stmt_expr (void)
    3079              : {
    3080      5640080 :   return push_stmt_list ();
    3081              : }
    3082              : 
    3083              : /* Process the final expression of a statement expression. EXPR can be
    3084              :    NULL, if the final expression is empty.  Return a STATEMENT_LIST
    3085              :    containing all the statements in the statement-expression, or
    3086              :    ERROR_MARK_NODE if there was an error.  */
    3087              : 
    3088              : tree
    3089        29041 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
    3090              : {
    3091        29041 :   if (error_operand_p (expr))
    3092              :     {
    3093              :       /* The type of the statement-expression is the type of the last
    3094              :          expression.  */
    3095            3 :       TREE_TYPE (stmt_expr) = error_mark_node;
    3096            3 :       return error_mark_node;
    3097              :     }
    3098              : 
    3099              :   /* If the last statement does not have "void" type, then the value
    3100              :      of the last statement is the value of the entire expression.  */
    3101        29038 :   if (expr)
    3102              :     {
    3103        29023 :       tree type = TREE_TYPE (expr);
    3104              : 
    3105        29023 :       if (type && type_unknown_p (type))
    3106              :         {
    3107           15 :           error ("a statement expression is an insufficient context"
    3108              :                  " for overload resolution");
    3109           15 :           TREE_TYPE (stmt_expr) = error_mark_node;
    3110           15 :           return error_mark_node;
    3111              :         }
    3112        29008 :       else if (processing_template_decl)
    3113              :         {
    3114              :           /* Not finish_expr_stmt because we don't want convert_to_void.  */
    3115          169 :           expr = build_stmt (input_location, EXPR_STMT, expr);
    3116          169 :           expr = add_stmt (expr);
    3117              :           /* Mark the last statement so that we can recognize it as such at
    3118              :              template-instantiation time.  */
    3119          169 :           EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
    3120              :         }
    3121        28839 :       else if (VOID_TYPE_P (type))
    3122              :         {
    3123              :           /* Just treat this like an ordinary statement.  */
    3124           31 :           expr = finish_expr_stmt (expr);
    3125              :         }
    3126              :       else
    3127              :         {
    3128              :           /* It actually has a value we need to deal with.  First, force it
    3129              :              to be an rvalue so that we won't need to build up a copy
    3130              :              constructor call later when we try to assign it to something.  */
    3131        28808 :           expr = force_rvalue (expr, tf_warning_or_error);
    3132        28808 :           if (error_operand_p (expr))
    3133            0 :             return error_mark_node;
    3134              : 
    3135              :           /* Update for array-to-pointer decay.  */
    3136        28808 :           type = TREE_TYPE (expr);
    3137              : 
    3138              :           /* This TARGET_EXPR will initialize the outer one added by
    3139              :              finish_stmt_expr.  */
    3140        28808 :           set_target_expr_eliding (expr);
    3141              : 
    3142              :           /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
    3143              :              normal statement, but don't convert to void or actually add
    3144              :              the EXPR_STMT.  */
    3145        28808 :           if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    3146        28808 :             expr = maybe_cleanup_point_expr (expr);
    3147        28808 :           add_stmt (expr);
    3148              :         }
    3149              : 
    3150              :       /* The type of the statement-expression is the type of the last
    3151              :          expression.  */
    3152        29008 :       TREE_TYPE (stmt_expr) = type;
    3153              :     }
    3154              : 
    3155              :   return stmt_expr;
    3156              : }
    3157              : 
    3158              : /* Finish a statement-expression.  EXPR should be the value returned
    3159              :    by the previous begin_stmt_expr.  Returns an expression
    3160              :    representing the statement-expression.  */
    3161              : 
    3162              : tree
    3163      5640080 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
    3164              : {
    3165      5640080 :   tree type;
    3166      5640080 :   tree result;
    3167              : 
    3168      5640080 :   if (error_operand_p (stmt_expr))
    3169              :     {
    3170           18 :       pop_stmt_list (stmt_expr);
    3171           18 :       return error_mark_node;
    3172              :     }
    3173              : 
    3174      5640062 :   gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
    3175              : 
    3176      5640062 :   type = TREE_TYPE (stmt_expr);
    3177      5640062 :   result = pop_stmt_list (stmt_expr);
    3178      5640062 :   TREE_TYPE (result) = type;
    3179              : 
    3180      5640062 :   if (processing_template_decl)
    3181              :     {
    3182        52987 :       result = build_min (STMT_EXPR, type, result);
    3183        52987 :       TREE_SIDE_EFFECTS (result) = 1;
    3184        52987 :       STMT_EXPR_NO_SCOPE (result) = has_no_scope;
    3185              :     }
    3186      5587075 :   else if (CLASS_TYPE_P (type))
    3187              :     {
    3188              :       /* Wrap the statement-expression in a TARGET_EXPR so that the
    3189              :          temporary object created by the final expression is destroyed at
    3190              :          the end of the full-expression containing the
    3191              :          statement-expression.  */
    3192          118 :       result = force_target_expr (type, result, tf_warning_or_error);
    3193              :     }
    3194              : 
    3195              :   return result;
    3196              : }
    3197              : 
    3198              : /* Returns the expression which provides the value of STMT_EXPR.  */
    3199              : 
    3200              : tree
    3201          191 : stmt_expr_value_expr (tree stmt_expr)
    3202              : {
    3203          191 :   tree t = STMT_EXPR_STMT (stmt_expr);
    3204              : 
    3205          191 :   if (TREE_CODE (t) == BIND_EXPR)
    3206          191 :     t = BIND_EXPR_BODY (t);
    3207              : 
    3208          191 :   if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
    3209          158 :     t = STATEMENT_LIST_TAIL (t)->stmt;
    3210              : 
    3211          191 :   if (TREE_CODE (t) == EXPR_STMT)
    3212          173 :     t = EXPR_STMT_EXPR (t);
    3213              : 
    3214          191 :   return t;
    3215              : }
    3216              : 
    3217              : /* Return TRUE iff EXPR_STMT is an empty list of
    3218              :    expression statements.  */
    3219              : 
    3220              : bool
    3221     63310606 : empty_expr_stmt_p (tree expr_stmt)
    3222              : {
    3223     63310611 :   tree body = NULL_TREE;
    3224              : 
    3225     63310611 :   if (expr_stmt == void_node)
    3226              :     return true;
    3227              : 
    3228     63310608 :   if (expr_stmt)
    3229              :     {
    3230     63310608 :       if (TREE_CODE (expr_stmt) == EXPR_STMT)
    3231            5 :         body = EXPR_STMT_EXPR (expr_stmt);
    3232     63310603 :       else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
    3233              :         body = expr_stmt;
    3234              :     }
    3235              : 
    3236            5 :   if (body)
    3237              :     {
    3238     62336306 :       if (TREE_CODE (body) == STATEMENT_LIST)
    3239     62336301 :         return tsi_end_p (tsi_start (body));
    3240              :       else
    3241              :         return empty_expr_stmt_p (body);
    3242              :     }
    3243              :   return false;
    3244              : }
    3245              : 
    3246              : /* Perform Koenig lookup.  FN_EXPR is the postfix-expression representing
    3247              :    the function (or functions) to call; ARGS are the arguments to the
    3248              :    call.  Returns the functions to be considered by overload resolution.  */
    3249              : 
    3250              : cp_expr
    3251     19172350 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
    3252              :                        tsubst_flags_t complain)
    3253              : {
    3254     19172350 :   tree identifier = NULL_TREE;
    3255     19172350 :   tree functions = NULL_TREE;
    3256     19172350 :   tree tmpl_args = NULL_TREE;
    3257     19172350 :   bool template_id = false;
    3258     19172350 :   location_t loc = fn_expr.get_location ();
    3259     19172350 :   tree fn = fn_expr.get_value ();
    3260              : 
    3261     19172350 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3262              : 
    3263     19172350 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    3264              :     {
    3265              :       /* Use a separate flag to handle null args.  */
    3266      3665669 :       template_id = true;
    3267      3665669 :       tmpl_args = TREE_OPERAND (fn, 1);
    3268      3665669 :       fn = TREE_OPERAND (fn, 0);
    3269              :     }
    3270              : 
    3271              :   /* Find the name of the overloaded function.  */
    3272     19172350 :   if (identifier_p (fn))
    3273              :     identifier = fn;
    3274              :   else
    3275              :     {
    3276     27086455 :       functions = fn;
    3277     18973468 :       identifier = OVL_NAME (functions);
    3278              :     }
    3279              : 
    3280              :   /* A call to a namespace-scope function using an unqualified name.
    3281              : 
    3282              :      Do Koenig lookup -- unless any of the arguments are
    3283              :      type-dependent.  */
    3284     19172350 :   if (!any_type_dependent_arguments_p (args)
    3285     19172350 :       && !any_dependent_template_arguments_p (tmpl_args))
    3286              :     {
    3287     18313662 :       fn = lookup_arg_dependent (identifier, functions, args);
    3288     18313662 :       if (!fn)
    3289              :         {
    3290              :           /* The unqualified name could not be resolved.  */
    3291        59028 :           if (complain & tf_error)
    3292          393 :             fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
    3293              :           else
    3294              :             fn = identifier;
    3295              :         }
    3296              :     }
    3297              : 
    3298     19172350 :   if (fn && template_id && fn != error_mark_node)
    3299      3665656 :     fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
    3300              : 
    3301     19172350 :   return cp_expr (fn, loc);
    3302              : }
    3303              : 
    3304              : /* Analyze call to a front-end builtin FN with arguments *ARGS.  Return true
    3305              :    if the call is correct, false if erroneous.  */
    3306              : 
    3307              : static bool
    3308       127426 : check_frontend_builtin (tree fn, vec<tree, va_gc> **args,
    3309              :                         tsubst_flags_t complain)
    3310              : {
    3311       127426 :   tree arg, ptype, type;
    3312       127426 :   switch (DECL_UNCHECKED_FUNCTION_CODE (fn))
    3313              :     {
    3314          866 :     case CP_BUILT_IN_IS_WITHIN_LIFETIME:
    3315          866 :     case CP_BUILT_IN_START_LIFETIME:
    3316              :       /* Unless users call the builtin directly, the following 2 checks
    3317              :          should be ensured from std::is_within_lifetime or
    3318              :          std::start_lifetime template.  */
    3319          866 :       if (vec_safe_length (*args) != 1)
    3320              :         {
    3321           14 :           if (complain & tf_error)
    3322           14 :             error ("%qE needs a single argument", DECL_NAME (fn));
    3323              :           return false;
    3324              :         }
    3325          852 :       arg = (**args)[0];
    3326          852 :       if (error_operand_p (arg))
    3327              :         return false;
    3328          852 :       ptype = TREE_TYPE (arg);
    3329          852 :       if (!POINTER_TYPE_P (ptype))
    3330              :         {
    3331           13 :           if (complain & tf_error)
    3332           13 :             error ("%qE argument type %qT is not pointer type",
    3333           13 :                    DECL_NAME (fn), ptype);
    3334              :           return false;
    3335              :         }
    3336          839 :       if (DECL_UNCHECKED_FUNCTION_CODE (fn) == CP_BUILT_IN_IS_WITHIN_LIFETIME)
    3337              :         return true;
    3338          349 :       type = TREE_TYPE (ptype);
    3339          349 :       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
    3340              :         return false;
    3341          349 :       if (!CP_AGGREGATE_TYPE_P (type))
    3342              :         {
    3343           10 :           if (complain & tf_error)
    3344           10 :             error ("%qE argument type %qT is not a pointer to aggregate type",
    3345           10 :                    DECL_NAME (fn), ptype);
    3346              :           return false;
    3347              :         }
    3348          339 :       if (!implicit_lifetime_type_p (type))
    3349              :         {
    3350            4 :           if (complain & tf_error)
    3351            4 :             error ("%qE argument type %qT is not a pointer to "
    3352            4 :                    "implicit-lifetime type", DECL_NAME (fn), ptype);
    3353              :           return false;
    3354              :         }
    3355              :       return true;
    3356              :     default:
    3357              :       return true;
    3358              :     }
    3359              : }
    3360              : 
    3361              : /* Generate an expression for `FN (ARGS)'.  This may change the
    3362              :    contents of ARGS.
    3363              : 
    3364              :    If DISALLOW_VIRTUAL is true, the call to FN will be not generated
    3365              :    as a virtual call, even if FN is virtual.  (This flag is set when
    3366              :    encountering an expression where the function name is explicitly
    3367              :    qualified.  For example a call to `X::f' never generates a virtual
    3368              :    call.)
    3369              : 
    3370              :    Returns code for the call.  */
    3371              : 
    3372              : tree
    3373    372288211 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
    3374              :                   bool koenig_p, tsubst_flags_t complain)
    3375              : {
    3376    372288211 :   tree result;
    3377    372288211 :   tree orig_fn;
    3378    372288211 :   vec<tree, va_gc> *orig_args = *args;
    3379    372288211 :   tsubst_flags_t orig_complain = complain;
    3380              : 
    3381    372288211 :   if (fn == error_mark_node)
    3382              :     return error_mark_node;
    3383              : 
    3384    372287125 :   complain &= ~tf_any_viable;
    3385    372287125 :   gcc_assert (!TYPE_P (fn));
    3386              : 
    3387              :   /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
    3388              :      it so that we can tell this is a call to a known function.  */
    3389    372287125 :   fn = maybe_undo_parenthesized_ref (fn);
    3390              : 
    3391    372287125 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3392              : 
    3393    372287125 :   orig_fn = fn;
    3394              : 
    3395    372287125 :   if (concept_check_p (fn))
    3396              :     {
    3397            6 :       error_at (EXPR_LOC_OR_LOC (fn, input_location),
    3398              :                 "cannot call a concept as a function");
    3399            6 :       return error_mark_node;
    3400              :     }
    3401              : 
    3402    372287119 :   if (processing_template_decl)
    3403              :     {
    3404              :       /* If FN is a local extern declaration (or set thereof) in a template,
    3405              :          look it up again at instantiation time.  */
    3406    239576082 :       if (is_overloaded_fn (fn))
    3407              :         {
    3408    146912974 :           tree ifn = get_first_fn (fn);
    3409    146912974 :           if (TREE_CODE (ifn) == FUNCTION_DECL
    3410    146912974 :               && dependent_local_decl_p (ifn))
    3411        40535 :             orig_fn = DECL_NAME (ifn);
    3412              :         }
    3413              : 
    3414              :       /* If the call expression is dependent, build a CALL_EXPR node
    3415              :          with no type; type_dependent_expression_p recognizes
    3416              :          expressions with no type as being dependent.  */
    3417    239576082 :       if (type_dependent_expression_p (fn)
    3418    239576082 :           || any_type_dependent_arguments_p (*args))
    3419              :         {
    3420    217792160 :           if (koenig_p
    3421     10625172 :               && TREE_CODE (orig_fn) == FUNCTION_DECL
    3422    221122938 :               && !fndecl_built_in_p (orig_fn))
    3423              :             /* For an ADL-enabled call where unqualified lookup found a
    3424              :                single non-template function, wrap it in an OVERLOAD so that
    3425              :                later substitution doesn't overeagerly mark the function as
    3426              :                used.  */
    3427       854855 :             orig_fn = ovl_make (orig_fn, NULL_TREE);
    3428    217792160 :           result = build_min_nt_call_vec (orig_fn, *args);
    3429    296071081 :           SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
    3430    217792160 :           KOENIG_LOOKUP_P (result) = koenig_p;
    3431              :           /* Disable the std::move warnings since this call was dependent
    3432              :              (c++/89780, c++/107363).  This also suppresses the
    3433              :              -Wredundant-move warning.  */
    3434    217792160 :           suppress_warning (result, OPT_Wpessimizing_move);
    3435              : 
    3436    217792160 :           if (cfun && cp_function_chain && !cp_unevaluated_operand)
    3437              :             {
    3438    189754257 :               bool abnormal = true;
    3439    190040559 :               for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
    3440              :                 {
    3441    105374688 :                   tree fndecl = STRIP_TEMPLATE (*iter);
    3442    105374688 :                   if (TREE_CODE (fndecl) != FUNCTION_DECL
    3443    105374610 :                       || !TREE_THIS_VOLATILE (fndecl))
    3444              :                     {
    3445              :                       abnormal = false;
    3446              :                       break;
    3447              :                     }
    3448              :                 }
    3449              :               /* FIXME: Stop warning about falling off end of non-void
    3450              :                  function.   But this is wrong.  Even if we only see
    3451              :                  no-return fns at this point, we could select a
    3452              :                  future-defined return fn during instantiation.  Or
    3453              :                  vice-versa.  */
    3454    189754257 :               if (abnormal)
    3455     84665871 :                 current_function_returns_abnormally = 1;
    3456              :             }
    3457    217792160 :           if (TREE_CODE (fn) == COMPONENT_REF)
    3458    100759969 :             maybe_generic_this_capture (TREE_OPERAND (fn, 0),
    3459    100759969 :                                         TREE_OPERAND (fn, 1));
    3460              :           return result;
    3461              :         }
    3462     21783922 :       orig_args = make_tree_vector_copy (*args);
    3463              :     }
    3464              : 
    3465    154494959 :   if (TREE_CODE (fn) == COMPONENT_REF)
    3466              :     {
    3467     29417750 :       tree member = TREE_OPERAND (fn, 1);
    3468     29417750 :       if (BASELINK_P (member))
    3469              :         {
    3470     29229040 :           tree object = TREE_OPERAND (fn, 0);
    3471     58049757 :           return build_new_method_call (object, member,
    3472              :                                         args, NULL_TREE,
    3473              :                                         (disallow_virtual
    3474              :                                          ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
    3475              :                                          : LOOKUP_NORMAL),
    3476              :                                         /*fn_p=*/NULL,
    3477     29229040 :                                         complain);
    3478              :         }
    3479              :     }
    3480              : 
    3481              :   /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'.  */
    3482    125265919 :   if (TREE_CODE (fn) == ADDR_EXPR
    3483    125265919 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
    3484            9 :     fn = TREE_OPERAND (fn, 0);
    3485              : 
    3486    125265919 :   if (is_overloaded_fn (fn))
    3487    116444609 :     fn = baselink_for_fns (fn);
    3488              : 
    3489    125265919 :   result = NULL_TREE;
    3490    125265919 :   if (BASELINK_P (fn))
    3491              :     {
    3492     14147539 :       tree object;
    3493              : 
    3494              :       /* A call to a member function.  From [over.call.func]:
    3495              : 
    3496              :            If the keyword this is in scope and refers to the class of
    3497              :            that member function, or a derived class thereof, then the
    3498              :            function call is transformed into a qualified function call
    3499              :            using (*this) as the postfix-expression to the left of the
    3500              :            . operator.... [Otherwise] a contrived object of type T
    3501              :            becomes the implied object argument.
    3502              : 
    3503              :         In this situation:
    3504              : 
    3505              :           struct A { void f(); };
    3506              :           struct B : public A {};
    3507              :           struct C : public A { void g() { B::f(); }};
    3508              : 
    3509              :         "the class of that member function" refers to `A'.  But 11.2
    3510              :         [class.access.base] says that we need to convert 'this' to B* as
    3511              :         part of the access, so we pass 'B' to maybe_dummy_object.  */
    3512              : 
    3513     14147539 :       if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
    3514              :         {
    3515              :           /* A constructor call always uses a dummy object.  (This constructor
    3516              :              call which has the form A::A () is actually invalid and we are
    3517              :              going to reject it later in build_new_method_call.)  */
    3518           39 :           object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
    3519              :         }
    3520              :       else
    3521     14147500 :         object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
    3522              :                                      NULL);
    3523              : 
    3524     16134879 :       result = build_new_method_call (object, fn, args, NULL_TREE,
    3525              :                                       (disallow_virtual
    3526              :                                        ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
    3527              :                                        : LOOKUP_NORMAL),
    3528              :                                       /*fn_p=*/NULL,
    3529              :                                       complain);
    3530              :     }
    3531    111118380 :   else if (is_overloaded_fn (fn))
    3532              :     {
    3533              :       /* If the function is an overloaded builtin, resolve it.  */
    3534    102297070 :       if (TREE_CODE (fn) == FUNCTION_DECL
    3535    102297070 :           && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
    3536     18932260 :               || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
    3537      9605761 :         result = resolve_overloaded_builtin (input_location, fn, *args,
    3538              :                                              complain & tf_error);
    3539              : 
    3540      9605761 :       if (!result)
    3541              :         {
    3542    101953044 :           tree alloc_size_attr = NULL_TREE;
    3543    101953044 :           if (warn_calloc_transposed_args
    3544       714737 :               && TREE_CODE (fn) == FUNCTION_DECL
    3545    101953044 :               && (alloc_size_attr
    3546       432841 :                   = lookup_attribute ("alloc_size",
    3547       432841 :                                       TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
    3548         3399 :             if (TREE_VALUE (alloc_size_attr) == NULL_TREE
    3549         3399 :                 || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
    3550              :               alloc_size_attr = NULL_TREE;
    3551    100211028 :           if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
    3552      1742076 :               && (complain & tf_warning)
    3553      1522323 :               && !vec_safe_is_empty (*args)
    3554    103120862 :               && !processing_template_decl)
    3555              :             {
    3556              :               location_t sizeof_arg_loc[6];
    3557              :               tree sizeof_arg[6];
    3558              :               unsigned int i;
    3559      8390996 :               for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
    3560              :                 {
    3561      3146826 :                   tree t;
    3562              : 
    3563      3146826 :                   sizeof_arg_loc[i] = UNKNOWN_LOCATION;
    3564      3146826 :                   sizeof_arg[i] = NULL_TREE;
    3565      3146826 :                   if (i >= (*args)->length ())
    3566       657497 :                     continue;
    3567      2489329 :                   t = (**args)[i];
    3568      2489329 :                   if (TREE_CODE (t) != SIZEOF_EXPR)
    3569      2482654 :                     continue;
    3570         6675 :                   if (SIZEOF_EXPR_TYPE_P (t))
    3571         2663 :                     sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
    3572              :                   else
    3573         4012 :                     sizeof_arg[i] = TREE_OPERAND (t, 0);
    3574         6675 :                   sizeof_arg_loc[i] = EXPR_LOCATION (t);
    3575              :                 }
    3576      1048882 :               if (warn_sizeof_pointer_memaccess)
    3577              :                 {
    3578      1048822 :                   auto same_p = same_type_ignoring_top_level_qualifiers_p;
    3579      1048822 :                   sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
    3580              :                                                     sizeof_arg, same_p);
    3581              :                 }
    3582      1048882 :               if (alloc_size_attr)
    3583           60 :                 warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
    3584              :                                  alloc_size_attr);
    3585              :             }
    3586              : 
    3587    101953044 :           if ((complain & tf_warning)
    3588     56190852 :               && TREE_CODE (fn) == FUNCTION_DECL
    3589     26791446 :               && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
    3590       145566 :               && vec_safe_length (*args) == 3
    3591    102098610 :               && !any_type_dependent_arguments_p (*args))
    3592              :             {
    3593       145566 :               tree arg0 = (*orig_args)[0];
    3594       145566 :               tree arg1 = (*orig_args)[1];
    3595       145566 :               tree arg2 = (*orig_args)[2];
    3596       145566 :               int literal_mask = ((literal_integer_zerop (arg1) << 1)
    3597       145566 :                                   | (literal_integer_zerop (arg2) << 2));
    3598       145566 :               warn_for_memset (input_location, arg0, arg2, literal_mask);
    3599              :             }
    3600              : 
    3601    101953044 :           if (TREE_CODE (fn) == FUNCTION_DECL
    3602     26917511 :               && fndecl_built_in_p (fn, BUILT_IN_FRONTEND)
    3603    102080470 :               && !check_frontend_builtin (fn, args, complain))
    3604           41 :             return error_mark_node;
    3605              : 
    3606              :           /* A call to a namespace-scope function.  */
    3607    101953003 :           result = build_new_function_call (fn, args, orig_complain);
    3608              :         }
    3609              :     }
    3610      8821310 :   else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
    3611              :     {
    3612       159043 :       if (!vec_safe_is_empty (*args))
    3613            0 :         error ("arguments to destructor are not allowed");
    3614              :       /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
    3615              :          which case the postfix-expression is a possibly-parenthesized class
    3616              :          member access), the function call destroys the object of scalar type
    3617              :          denoted by the object expression of the class member access.  */
    3618       159043 :       tree ob = TREE_OPERAND (fn, 0);
    3619       159043 :       if (obvalue_p (ob))
    3620       159025 :         result = build_trivial_dtor_call (ob, true);
    3621              :       else
    3622              :         /* No location to clobber.  */
    3623           18 :         result = convert_to_void (ob, ICV_STATEMENT, complain);
    3624              :     }
    3625      8662267 :   else if (CLASS_TYPE_P (TREE_TYPE (fn)))
    3626              :     /* If the "function" is really an object of class type, it might
    3627              :        have an overloaded `operator ()'.  */
    3628      2636593 :     result = build_op_call (fn, args, complain);
    3629              : 
    3630    118882660 :   if (!result)
    3631              :     /* A call where the function is unknown.  */
    3632      6025674 :     result = cp_build_function_call_vec (fn, args, complain);
    3633              : 
    3634    125252360 :   if (processing_template_decl && result != error_mark_node)
    3635              :     {
    3636     16672740 :       if (INDIRECT_REF_P (result))
    3637      1135188 :         result = TREE_OPERAND (result, 0);
    3638              : 
    3639              :       /* Prune all but the selected function from the original overload
    3640              :          set so that we can avoid some duplicate work at instantiation time.  */
    3641     16672740 :       if (TREE_CODE (result) == CALL_EXPR
    3642     16663029 :           && really_overloaded_fn (orig_fn))
    3643              :         {
    3644      6151694 :           tree sel_fn = CALL_EXPR_FN (result);
    3645      6151694 :           if (TREE_CODE (sel_fn) == COMPONENT_REF)
    3646              :             {
    3647              :               /* The non-dependent result of build_new_method_call.  */
    3648       259840 :               sel_fn = TREE_OPERAND (sel_fn, 1);
    3649       259840 :               gcc_assert (BASELINK_P (sel_fn));
    3650              :             }
    3651      5891854 :           else if (TREE_CODE (sel_fn) == ADDR_EXPR)
    3652              :             /* Our original callee wasn't wrapped in an ADDR_EXPR,
    3653              :                so strip this ADDR_EXPR added by build_over_call.  */
    3654      5891854 :             sel_fn = TREE_OPERAND (sel_fn, 0);
    3655              :           orig_fn = sel_fn;
    3656              :         }
    3657              : 
    3658     16672740 :       tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
    3659     16672740 :       SET_EXPR_LOCATION (r, input_location);
    3660     16672740 :       KOENIG_LOOKUP_P (r) = koenig_p;
    3661     16672740 :       TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
    3662     16672740 :       release_tree_vector (orig_args);
    3663     16672740 :       result = convert_from_reference (r);
    3664              :     }
    3665              : 
    3666              :   return result;
    3667              : }
    3668              : 
    3669              : /* Finish a call to a postfix increment or decrement or EXPR.  (Which
    3670              :    is indicated by CODE, which should be POSTINCREMENT_EXPR or
    3671              :    POSTDECREMENT_EXPR.)  */
    3672              : 
    3673              : cp_expr
    3674      2659114 : finish_increment_expr (cp_expr expr, enum tree_code code)
    3675              : {
    3676              :   /* input_location holds the location of the trailing operator token.
    3677              :      Build a location of the form:
    3678              :        expr++
    3679              :        ~~~~^~
    3680              :      with the caret at the operator token, ranging from the start
    3681              :      of EXPR to the end of the operator token.  */
    3682      2659114 :   location_t combined_loc = make_location (input_location,
    3683              :                                            expr.get_start (),
    3684              :                                            get_finish (input_location));
    3685      2659114 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3686      2659114 :                                      NULL_TREE, tf_warning_or_error);
    3687              :   /* TODO: build_x_unary_op doesn't honor the location, so set it here.  */
    3688      2659114 :   result.set_location (combined_loc);
    3689      2659114 :   return result;
    3690              : }
    3691              : 
    3692              : /* Finish a use of `this'.  Returns an expression for `this'.  */
    3693              : 
    3694              : tree
    3695     36726321 : finish_this_expr (void)
    3696              : {
    3697     36726321 :   tree result = NULL_TREE;
    3698              : 
    3699     73452518 :   if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
    3700     36427224 :     result = current_class_ptr;
    3701       598178 :   else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
    3702       299021 :     result = (lambda_expr_this_capture
    3703       299021 :               (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
    3704              :   else
    3705           76 :     gcc_checking_assert (!current_class_ptr);
    3706              : 
    3707     36726245 :   if (result)
    3708              :     /* The keyword 'this' is a prvalue expression.  */
    3709     36726242 :     return rvalue (result);
    3710              : 
    3711           79 :   tree fn = current_nonlambda_function ();
    3712           79 :   if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3713              :     {
    3714            6 :       auto_diagnostic_group d;
    3715            6 :       error ("%<this%> is unavailable for explicit object member "
    3716              :              "functions");
    3717            6 :       tree xobj_parm = DECL_ARGUMENTS (fn);
    3718            6 :       gcc_assert (xobj_parm);
    3719            6 :       tree parm_name = DECL_NAME (xobj_parm);
    3720              : 
    3721            6 :       static tree remembered_fn = NULL_TREE;
    3722              :       /* Only output this diagnostic once per function.  */
    3723            6 :       if (remembered_fn == fn)
    3724              :         /* Early escape.  */;
    3725            6 :       else if (parm_name)
    3726            6 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3727              :                 "use explicit object parameter %qs instead",
    3728            3 :                 IDENTIFIER_POINTER (parm_name));
    3729              :       else
    3730            3 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3731              :                 "name the explicit object parameter");
    3732              : 
    3733            6 :       remembered_fn = fn;
    3734            6 :     }
    3735           73 :   else if (fn && DECL_STATIC_FUNCTION_P (fn))
    3736            3 :     error ("%<this%> is unavailable for static member functions");
    3737           70 :   else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
    3738            0 :     error ("invalid use of %<this%> in a constructor %<pre%> condition");
    3739           70 :   else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
    3740            0 :     error ("invalid use of %<this%> in a destructor %<post%> condition");
    3741           70 :   else if (fn)
    3742           22 :     error ("invalid use of %<this%> in non-member function");
    3743              :   else
    3744           48 :     error ("invalid use of %<this%> at top level");
    3745           79 :   return error_mark_node;
    3746              : }
    3747              : 
    3748              : /* Finish a pseudo-destructor expression.  If SCOPE is NULL, the
    3749              :    expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
    3750              :    the TYPE for the type given.  If SCOPE is non-NULL, the expression
    3751              :    was of the form `OBJECT.SCOPE::~DESTRUCTOR'.  */
    3752              : 
    3753              : tree
    3754       159094 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
    3755              :                                location_t loc, tsubst_flags_t complain)
    3756              : {
    3757       159094 :   if (object == error_mark_node || destructor == error_mark_node)
    3758              :     return error_mark_node;
    3759              : 
    3760       159085 :   gcc_assert (TYPE_P (destructor));
    3761              : 
    3762       159085 :   if (!processing_template_decl)
    3763              :     {
    3764       159064 :       if (scope == error_mark_node)
    3765              :         {
    3766            0 :           if (complain & tf_error)
    3767            0 :             error_at (loc, "invalid qualifying scope in pseudo-destructor name");
    3768            0 :           return error_mark_node;
    3769              :         }
    3770       159064 :       if (is_auto (destructor))
    3771            3 :         destructor = TREE_TYPE (object);
    3772       159064 :       if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
    3773              :         {
    3774            3 :           if (complain & tf_error)
    3775            3 :             error_at (loc,
    3776              :                       "qualified type %qT does not match destructor name ~%qT",
    3777              :                       scope, destructor);
    3778            3 :           return error_mark_node;
    3779              :         }
    3780              : 
    3781              : 
    3782              :       /* [expr.pseudo] says both:
    3783              : 
    3784              :            The type designated by the pseudo-destructor-name shall be
    3785              :            the same as the object type.
    3786              : 
    3787              :          and:
    3788              : 
    3789              :            The cv-unqualified versions of the object type and of the
    3790              :            type designated by the pseudo-destructor-name shall be the
    3791              :            same type.
    3792              : 
    3793              :          We implement the more generous second sentence, since that is
    3794              :          what most other compilers do.  */
    3795       159061 :       if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
    3796              :                                                       destructor))
    3797              :         {
    3798           12 :           if (complain & tf_error)
    3799            9 :             error_at (loc, "%qE is not of type %qT", object, destructor);
    3800           12 :           return error_mark_node;
    3801              :         }
    3802              :     }
    3803              : 
    3804       159070 :   tree type = (type_dependent_expression_p (object)
    3805       159070 :                ? NULL_TREE : void_type_node);
    3806              : 
    3807       159070 :   return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
    3808       159070 :                      scope, destructor);
    3809              : }
    3810              : 
    3811              : /* Finish an expression of the form CODE EXPR.  */
    3812              : 
    3813              : cp_expr
    3814     39106954 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
    3815              :                       tsubst_flags_t complain)
    3816              : {
    3817              :   /* Build a location of the form:
    3818              :        ++expr
    3819              :        ^~~~~~
    3820              :      with the caret at the operator token, ranging from the start
    3821              :      of the operator token to the end of EXPR.  */
    3822     39106954 :   location_t combined_loc = make_location (op_loc,
    3823              :                                            op_loc, expr.get_finish ());
    3824     39106954 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3825     39106954 :                                      NULL_TREE, complain);
    3826              :   /* TODO: build_x_unary_op doesn't always honor the location.  */
    3827     39106954 :   result.set_location (combined_loc);
    3828              : 
    3829     39106954 :   if (result == error_mark_node)
    3830              :     return result;
    3831              : 
    3832     39106451 :   if (!(complain & tf_warning))
    3833              :     return result;
    3834              : 
    3835              :   /* These will never fold into a constant, so no need to check for
    3836              :      overflow for them.  */
    3837     39106451 :   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
    3838              :     return result;
    3839              : 
    3840     21151698 :   tree result_ovl = result;
    3841     21151698 :   tree expr_ovl = expr;
    3842              : 
    3843     21151698 :   if (!processing_template_decl)
    3844      1844956 :     expr_ovl = cp_fully_fold (expr_ovl);
    3845              : 
    3846     21151698 :   if (!CONSTANT_CLASS_P (expr_ovl)
    3847     21151698 :       || TREE_OVERFLOW_P (expr_ovl))
    3848              :     return result;
    3849              : 
    3850       256571 :   if (!processing_template_decl)
    3851       246966 :     result_ovl = cp_fully_fold (result_ovl);
    3852              : 
    3853       256571 :   if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
    3854            9 :     overflow_warning (combined_loc, result_ovl);
    3855              : 
    3856              :   return result;
    3857              : }
    3858              : 
    3859              : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
    3860              :    elements.  */
    3861              : 
    3862              : static bool
    3863           12 : maybe_zero_constructor_nelts (tree expr)
    3864              : {
    3865           12 :   if (CONSTRUCTOR_NELTS (expr) == 0)
    3866              :     return true;
    3867           12 :   if (!processing_template_decl)
    3868              :     return false;
    3869           30 :   for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
    3870           21 :     if (!PACK_EXPANSION_P (elt.value))
    3871              :       return false;
    3872              :   return true;
    3873              : }
    3874              : 
    3875              : /* Finish a compound-literal expression or C++11 functional cast with aggregate
    3876              :    initializer.  TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
    3877              :    is being cast.  */
    3878              : 
    3879              : tree
    3880     10417504 : finish_compound_literal (tree type, tree compound_literal,
    3881              :                          tsubst_flags_t complain,
    3882              :                          fcl_t fcl_context)
    3883              : {
    3884     10417504 :   if (type == error_mark_node)
    3885              :     return error_mark_node;
    3886              : 
    3887     10417452 :   if (TYPE_REF_P (type))
    3888              :     {
    3889           12 :       compound_literal
    3890           12 :         = finish_compound_literal (TREE_TYPE (type), compound_literal,
    3891              :                                    complain, fcl_context);
    3892              :       /* The prvalue is then used to direct-initialize the reference.  */
    3893           12 :       tree r = (perform_implicit_conversion_flags
    3894           12 :                 (type, compound_literal, complain, LOOKUP_NORMAL));
    3895           12 :       return convert_from_reference (r);
    3896              :     }
    3897              : 
    3898     10417440 :   if (!TYPE_OBJ_P (type))
    3899              :     {
    3900              :       /* DR2351 */
    3901           60 :       if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
    3902              :         {
    3903           12 :           if (!processing_template_decl)
    3904            9 :             return void_node;
    3905            3 :           TREE_TYPE (compound_literal) = type;
    3906            3 :           TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
    3907            3 :           CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
    3908            3 :           return compound_literal;
    3909              :         }
    3910           21 :       else if (VOID_TYPE_P (type)
    3911           15 :                && processing_template_decl
    3912           33 :                && maybe_zero_constructor_nelts (compound_literal))
    3913              :         /* If there are only packs in compound_literal, it could
    3914              :            be void{} after pack expansion.  */;
    3915              :       else
    3916              :         {
    3917           12 :           if (complain & tf_error)
    3918            9 :             error ("compound literal of non-object type %qT", type);
    3919           12 :           return error_mark_node;
    3920              :         }
    3921              :     }
    3922              : 
    3923     10417416 :   if (template_placeholder_p (type))
    3924              :     {
    3925       193399 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3926              :                                 adc_variable_type);
    3927       193399 :       if (type == error_mark_node)
    3928              :         return error_mark_node;
    3929              :     }
    3930              :   /* C++23 auto{x}.  */
    3931     10224017 :   else if (is_auto (type)
    3932          162 :            && !AUTO_IS_DECLTYPE (type)
    3933     10224176 :            && CONSTRUCTOR_NELTS (compound_literal) == 1)
    3934              :     {
    3935          150 :       if (is_constrained_auto (type))
    3936              :         {
    3937            3 :           if (complain & tf_error)
    3938            3 :             error ("%<auto{x}%> cannot be constrained");
    3939            3 :           return error_mark_node;
    3940              :         }
    3941          147 :       else if (cxx_dialect < cxx23)
    3942              :         {
    3943            1 :           if ((complain & tf_warning_or_error) == 0)
    3944            0 :             return error_mark_node;
    3945            1 :           pedwarn (input_location, OPT_Wc__23_extensions,
    3946              :                    "%<auto{x}%> only available with "
    3947              :                    "%<-std=c++23%> or %<-std=gnu++23%>");
    3948              :         }
    3949          147 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3950              :                                 adc_variable_type);
    3951          147 :       if (type == error_mark_node)
    3952              :         return error_mark_node;
    3953              :     }
    3954              : 
    3955              :   /* Used to hold a copy of the compound literal in a template.  */
    3956     10417269 :   tree orig_cl = NULL_TREE;
    3957              : 
    3958     10417269 :   if (processing_template_decl)
    3959              :     {
    3960      5484171 :       const bool dependent_p
    3961      5484171 :         = (instantiation_dependent_expression_p (compound_literal)
    3962      5484171 :            || dependent_type_p (type));
    3963      1766179 :       if (dependent_p)
    3964              :         /* We're about to return, no need to copy.  */
    3965              :         orig_cl = compound_literal;
    3966              :       else
    3967              :         /* We're going to need a copy.  */
    3968      1766179 :         orig_cl = unshare_constructor (compound_literal);
    3969      5484171 :       TREE_TYPE (orig_cl) = type;
    3970              :       /* Mark the expression as a compound literal.  */
    3971      5484171 :       TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
    3972              :       /* And as instantiation-dependent.  */
    3973      5484171 :       CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
    3974      5484171 :       if (fcl_context == fcl_c99)
    3975          130 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
    3976              :       /* If the compound literal is dependent, we're done for now.  */
    3977      5484171 :       if (dependent_p)
    3978              :         return orig_cl;
    3979              :       /* Otherwise, do go on to e.g. check narrowing.  */
    3980              :     }
    3981              : 
    3982      6699277 :   type = complete_type (type);
    3983              : 
    3984      6699277 :   if (TYPE_NON_AGGREGATE_CLASS (type))
    3985              :     {
    3986              :       /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
    3987              :          everywhere that deals with function arguments would be a pain, so
    3988              :          just wrap it in a TREE_LIST.  The parser set a flag so we know
    3989              :          that it came from T{} rather than T({}).  */
    3990      1076244 :       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
    3991      1076244 :       compound_literal = build_tree_list (NULL_TREE, compound_literal);
    3992      1076244 :       return build_functional_cast (input_location, type,
    3993      1076244 :                                     compound_literal, complain);
    3994              :     }
    3995              : 
    3996      5623033 :   if (TREE_CODE (type) == ARRAY_TYPE
    3997      5623033 :       && check_array_initializer (NULL_TREE, type, compound_literal))
    3998            9 :     return error_mark_node;
    3999      5623024 :   compound_literal = reshape_init (type, compound_literal, complain);
    4000      5623024 :   if (SCALAR_TYPE_P (type)
    4001       746257 :       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
    4002       216671 :       && !check_narrowing (type, compound_literal, complain))
    4003          131 :     return error_mark_node;
    4004      5622893 :   if (TREE_CODE (type) == ARRAY_TYPE
    4005      5622893 :       && TYPE_DOMAIN (type) == NULL_TREE)
    4006              :     {
    4007         1253 :       cp_complete_array_type_or_error (&type, compound_literal,
    4008              :                                        false, complain);
    4009         1253 :       if (type == error_mark_node)
    4010              :         return error_mark_node;
    4011              :     }
    4012      5622890 :   if (abstract_virtuals_error (ACU_UNKNOWN, type, complain))
    4013            7 :     return error_mark_node;
    4014      5622883 :   compound_literal = digest_init_flags (type, compound_literal,
    4015              :                                         LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
    4016              :                                         complain);
    4017      5622883 :   if (compound_literal == error_mark_node)
    4018              :     return error_mark_node;
    4019              : 
    4020              :   /* If we're in a template, return the original compound literal.  */
    4021      5622203 :   if (orig_cl)
    4022              :     return orig_cl;
    4023              : 
    4024      3944188 :   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    4025              :     {
    4026      3253827 :       TREE_HAS_CONSTRUCTOR (compound_literal) = true;
    4027      3253827 :       if (fcl_context == fcl_c99)
    4028        37985 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
    4029              :     }
    4030              : 
    4031              :   /* Put static/constant array temporaries in static variables.  */
    4032              :   /* FIXME all C99 compound literals should be variables rather than C++
    4033              :      temporaries, unless they are used as an aggregate initializer.  */
    4034      5283189 :   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
    4035      2614607 :       && fcl_context == fcl_c99
    4036           83 :       && TREE_CODE (type) == ARRAY_TYPE
    4037           31 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    4038      3944219 :       && initializer_constant_valid_p (compound_literal, type))
    4039              :     {
    4040           31 :       tree decl = create_temporary_var (type);
    4041           31 :       DECL_CONTEXT (decl) = NULL_TREE;
    4042           31 :       DECL_INITIAL (decl) = compound_literal;
    4043           31 :       TREE_STATIC (decl) = 1;
    4044           31 :       if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
    4045              :         {
    4046              :           /* 5.19 says that a constant expression can include an
    4047              :              lvalue-rvalue conversion applied to "a glvalue of literal type
    4048              :              that refers to a non-volatile temporary object initialized
    4049              :              with a constant expression".  Rather than try to communicate
    4050              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
    4051           24 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
    4052           24 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    4053           24 :           TREE_CONSTANT (decl) = true;
    4054              :         }
    4055           31 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    4056           31 :       decl = pushdecl_top_level (decl);
    4057           31 :       DECL_NAME (decl) = make_anon_name ();
    4058           31 :       SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
    4059              :       /* Make sure the destructor is callable.  */
    4060           31 :       tree clean = cxx_maybe_build_cleanup (decl, complain);
    4061           31 :       if (clean == error_mark_node)
    4062              :         return error_mark_node;
    4063           31 :       return decl;
    4064              :     }
    4065              : 
    4066              :   /* Represent other compound literals with TARGET_EXPR so we produce
    4067              :      a prvalue, and can elide copies.  */
    4068      3944157 :   if (!VECTOR_TYPE_P (type)
    4069      3903584 :       && (TREE_CODE (compound_literal) == CONSTRUCTOR
    4070       690355 :           || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
    4071              :     {
    4072              :       /* The CONSTRUCTOR is now an initializer, not a compound literal.  */
    4073      3213229 :       if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    4074      3213229 :         TREE_HAS_CONSTRUCTOR (compound_literal) = false;
    4075      3213229 :       compound_literal = get_target_expr (compound_literal, complain);
    4076              :     }
    4077              :   else
    4078              :     /* For e.g. int{42} just make sure it's a prvalue.  */
    4079       730928 :     compound_literal = rvalue (compound_literal);
    4080              : 
    4081              :   return compound_literal;
    4082              : }
    4083              : 
    4084              : /* Return the declaration for the function-name variable indicated by
    4085              :    ID.  */
    4086              : 
    4087              : tree
    4088       309250 : finish_fname (tree id)
    4089              : {
    4090       309250 :   tree decl = fname_decl (input_location, C_RID_CODE (id), id);
    4091              :   /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
    4092              :      of a consteval-block-declaration, a variable __func__ is implicitly
    4093              :      defined...".  We could be in a consteval block in a function, though,
    4094              :      and then we shouldn't warn.  */
    4095       309250 :   if (current_function_decl
    4096       309250 :       && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
    4097            8 :     pedwarn (input_location, 0, "%qD is not defined outside of function scope",
    4098              :              decl);
    4099       309250 :   if (processing_template_decl && current_function_decl
    4100       230290 :       && decl != error_mark_node)
    4101       230290 :     decl = DECL_NAME (decl);
    4102       309250 :   return decl;
    4103              : }
    4104              : 
    4105              : /* Finish a translation unit.  */
    4106              : 
    4107              : void
    4108       101111 : finish_translation_unit (void)
    4109              : {
    4110              :   /* In case there were missing closebraces,
    4111              :      get us back to the global binding level.  */
    4112       101111 :   pop_everything ();
    4113       202222 :   while (current_namespace != global_namespace)
    4114            0 :     pop_namespace ();
    4115              : 
    4116              :   /* Do file scope __FUNCTION__ et al.  */
    4117       101111 :   finish_fname_decls ();
    4118              : 
    4119       101111 :   if (vec_safe_length (scope_chain->omp_declare_target_attribute))
    4120              :     {
    4121           12 :       cp_omp_declare_target_attr
    4122           12 :         a = scope_chain->omp_declare_target_attribute->pop ();
    4123           12 :       if (!errorcount)
    4124            9 :         error ("%qs without corresponding %qs",
    4125              :                a.device_type >= 0 ? "#pragma omp begin declare target"
    4126              :                                   : "#pragma omp declare target",
    4127              :                "#pragma omp end declare target");
    4128           24 :       vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
    4129              :     }
    4130       101111 :   if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
    4131              :     {
    4132            0 :       if (!errorcount)
    4133            0 :         error ("%<omp begin declare variant%> without corresponding "
    4134              :                "%<omp end declare variant%>");
    4135            0 :       vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
    4136              :     }
    4137       101111 :   if (vec_safe_length (scope_chain->omp_begin_assumes))
    4138              :     {
    4139            3 :       if (!errorcount)
    4140            3 :         error ("%qs without corresponding %qs",
    4141              :                "#pragma omp begin assumes", "#pragma omp end assumes");
    4142            3 :       vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
    4143              :     }
    4144       101111 : }
    4145              : 
    4146              : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
    4147              :    Returns the parameter.  */
    4148              : 
    4149              : tree
    4150    164381707 : finish_template_type_parm (tree aggr, tree identifier)
    4151              : {
    4152    164381707 :   if (aggr != class_type_node)
    4153              :     {
    4154            0 :       permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
    4155            0 :       aggr = class_type_node;
    4156              :     }
    4157              : 
    4158    164381707 :   return build_tree_list (aggr, identifier);
    4159              : }
    4160              : 
    4161              : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
    4162              :    Returns the parameter.  */
    4163              : 
    4164              : tree
    4165       688107 : finish_template_template_parm (tree aggr, tree identifier)
    4166              : {
    4167       688107 :   tree decl = build_decl (input_location,
    4168              :                           TYPE_DECL, identifier, NULL_TREE);
    4169              : 
    4170       688107 :   tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
    4171       688107 :   DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
    4172       688107 :   DECL_TEMPLATE_RESULT (tmpl) = decl;
    4173       688107 :   DECL_ARTIFICIAL (decl) = 1;
    4174              : 
    4175              :   /* Associate the constraints with the underlying declaration,
    4176              :      not the template.  */
    4177       688107 :   tree constr = current_template_constraints ();
    4178       688107 :   set_constraints (decl, constr);
    4179              : 
    4180       688107 :   end_template_decl ();
    4181              : 
    4182       688107 :   gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
    4183              : 
    4184       688107 :   check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
    4185              :                            /*is_primary=*/true, /*is_partial=*/false,
    4186              :                            /*is_friend=*/0);
    4187              : 
    4188       688107 :   return finish_template_type_parm (aggr, tmpl);
    4189              : }
    4190              : 
    4191              : /* ARGUMENT is the default-argument value for a template template
    4192              :    parameter.  If ARGUMENT is invalid, issue error messages and return
    4193              :    the ERROR_MARK_NODE.  Otherwise, ARGUMENT itself is returned.  */
    4194              : 
    4195              : tree
    4196          864 : check_template_template_default_arg (tree argument)
    4197              : {
    4198          864 :   if (TREE_CODE (argument) != TEMPLATE_DECL
    4199              :       && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
    4200              :       && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
    4201              :     {
    4202              :       if (TREE_CODE (argument) == TYPE_DECL)
    4203              :         {
    4204           18 :           if (tree t = maybe_get_template_decl_from_type_decl (argument))
    4205           18 :             if (TREE_CODE (t) == TEMPLATE_DECL)
    4206              :               return t;
    4207           15 :           error ("invalid use of type %qT as a default value for a template "
    4208           15 :                  "template-parameter", TREE_TYPE (argument));
    4209              :         }
    4210              :       else
    4211            0 :         error ("invalid default argument for a template template parameter");
    4212           15 :       return error_mark_node;
    4213              :     }
    4214              : 
    4215              :   return argument;
    4216              : }
    4217              : 
    4218              : /* Begin a class definition, as indicated by T.  */
    4219              : 
    4220              : tree
    4221     31313295 : begin_class_definition (tree t)
    4222              : {
    4223     31313295 :   if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
    4224           33 :     return error_mark_node;
    4225              : 
    4226     31313412 :   if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
    4227              :     {
    4228           24 :       error ("definition of %q#T inside template parameter list", t);
    4229           24 :       return error_mark_node;
    4230              :     }
    4231              : 
    4232              :   /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
    4233              :      are passed the same as decimal scalar types.  */
    4234     31313238 :   if (TREE_CODE (t) == RECORD_TYPE
    4235     30791018 :       && !processing_template_decl)
    4236              :     {
    4237     11026616 :       tree ns = TYPE_CONTEXT (t);
    4238     11026613 :       if (ns && TREE_CODE (ns) == NAMESPACE_DECL
    4239      9043543 :           && DECL_CONTEXT (ns) == std_node
    4240      2200525 :           && DECL_NAME (ns)
    4241     13227121 :           && id_equal (DECL_NAME (ns), "decimal"))
    4242              :         {
    4243          150 :           const char *n = TYPE_NAME_STRING (t);
    4244          150 :           if ((strcmp (n, "decimal32") == 0)
    4245          101 :               || (strcmp (n, "decimal64") == 0)
    4246           46 :               || (strcmp (n, "decimal128") == 0))
    4247          147 :             TYPE_TRANSPARENT_AGGR (t) = 1;
    4248              :         }
    4249              :     }
    4250              : 
    4251              :   /* A non-implicit typename comes from code like:
    4252              : 
    4253              :        template <typename T> struct A {
    4254              :          template <typename U> struct A<T>::B ...
    4255              : 
    4256              :      This is erroneous.  */
    4257     20286622 :   else if (TREE_CODE (t) == TYPENAME_TYPE)
    4258              :     {
    4259            0 :       error ("invalid definition of qualified type %qT", t);
    4260            0 :       t = error_mark_node;
    4261              :     }
    4262              : 
    4263     31313238 :   if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
    4264              :     {
    4265            0 :       t = make_class_type (RECORD_TYPE);
    4266            0 :       pushtag (make_anon_name (), t);
    4267              :     }
    4268              : 
    4269     31313238 :   if (TYPE_BEING_DEFINED (t))
    4270              :     {
    4271            0 :       t = make_class_type (TREE_CODE (t));
    4272            0 :       pushtag (TYPE_IDENTIFIER (t), t);
    4273              :     }
    4274              : 
    4275     31313238 :   maybe_process_partial_specialization (t);
    4276     31313238 :   pushclass (t);
    4277     31313238 :   TYPE_BEING_DEFINED (t) = 1;
    4278     31313238 :   class_binding_level->defining_class_p = 1;
    4279              : 
    4280     31313238 :   if (flag_pack_struct)
    4281              :     {
    4282           99 :       tree v;
    4283           99 :       TYPE_PACKED (t) = 1;
    4284              :       /* Even though the type is being defined for the first time
    4285              :          here, there might have been a forward declaration, so there
    4286              :          might be cv-qualified variants of T.  */
    4287           99 :       for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    4288            0 :         TYPE_PACKED (v) = 1;
    4289              :     }
    4290              :   /* Reset the interface data, at the earliest possible
    4291              :      moment, as it might have been set via a class foo;
    4292              :      before.  */
    4293     65045503 :   if (! TYPE_UNNAMED_P (t))
    4294              :     {
    4295     30563550 :       struct c_fileinfo *finfo = \
    4296     30563550 :         get_fileinfo (LOCATION_FILE (input_location));
    4297     30563550 :       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
    4298     30563550 :       SET_CLASSTYPE_INTERFACE_UNKNOWN_X
    4299              :         (t, finfo->interface_unknown);
    4300              :     }
    4301     31313238 :   reset_specialization ();
    4302              : 
    4303              :   /* Make a declaration for this class in its own scope.  */
    4304     31313238 :   build_self_reference ();
    4305              : 
    4306     31313238 :   return t;
    4307              : }
    4308              : 
    4309              : /* Finish the member declaration given by DECL.  */
    4310              : 
    4311              : void
    4312    423027888 : finish_member_declaration (tree decl)
    4313              : {
    4314    423027888 :   if (decl == error_mark_node || decl == NULL_TREE)
    4315              :     return;
    4316              : 
    4317    423026835 :   if (decl == void_type_node)
    4318              :     /* The COMPONENT was a friend, not a member, and so there's
    4319              :        nothing for us to do.  */
    4320              :     return;
    4321              : 
    4322              :   /* We should see only one DECL at a time.  */
    4323    423026835 :   gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
    4324              : 
    4325              :   /* Don't add decls after definition.  */
    4326    423026856 :   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
    4327              :               /* We can add lambda types when late parsing default
    4328              :                  arguments.  */
    4329              :               || LAMBDA_TYPE_P (TREE_TYPE (decl)));
    4330              : 
    4331              :   /* Set up access control for DECL.  */
    4332    423026835 :   TREE_PRIVATE (decl)
    4333    423026835 :     = (current_access_specifier == access_private_node);
    4334    423026835 :   TREE_PROTECTED (decl)
    4335    423026835 :     = (current_access_specifier == access_protected_node);
    4336    423026835 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    4337              :     {
    4338     48646670 :       TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
    4339     48646670 :       TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
    4340              :     }
    4341              : 
    4342              :   /* Mark the DECL as a member of the current class, unless it's
    4343              :      a member of an enumeration.  */
    4344    423026835 :   if (TREE_CODE (decl) != CONST_DECL)
    4345    420649898 :     DECL_CONTEXT (decl) = current_class_type;
    4346              : 
    4347    423026835 :   if (TREE_TYPE (decl)
    4348    419460330 :       && ANON_AGGR_TYPE_P (TREE_TYPE (decl))
    4349    423415159 :       && TREE_CODE (decl) != TYPE_DECL)
    4350              :     {
    4351              :       /* Remember the single FIELD_DECL an anonymous aggregate type is used
    4352              :          for.  */
    4353       283093 :       if (TREE_CODE (decl) == FIELD_DECL && DECL_NAME (decl) == NULL_TREE)
    4354              :         {
    4355       283077 :           tree type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
    4356       283077 :           gcc_assert (!ANON_AGGR_TYPE_FIELD (type));
    4357       283077 :           SET_ANON_AGGR_TYPE_FIELD (type, decl);
    4358              :         }
    4359              :       /* [class.union.anon]/1: Each object of such an unnamed type shall
    4360              :          be such an unnamed object.  */
    4361           16 :       else if (ANON_UNION_TYPE_P (TREE_TYPE (decl)))
    4362              :         {
    4363           10 :           tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
    4364           10 :           auto_diagnostic_group d;
    4365           10 :           error_at (location_of (decl),
    4366              :                     "declaration of member %qD with anonymous union type %qT",
    4367           10 :                     decl, TREE_TYPE (decl));
    4368           10 :           inform (DECL_SOURCE_LOCATION (adecl),
    4369              :                   "anonymous union declared here");
    4370           10 :         }
    4371              :       else
    4372              :         {
    4373            6 :           tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
    4374            6 :           auto_diagnostic_group d;
    4375            6 :           error_at (location_of (decl),
    4376              :                     "declaration of member %qD with anonymous struct type %qT",
    4377            6 :                     decl, TREE_TYPE (decl));
    4378            6 :           inform (DECL_SOURCE_LOCATION (adecl),
    4379              :                   "anonymous struct declared here");
    4380            6 :         }
    4381              :     }
    4382    422743742 :   else if (TREE_TYPE (decl)
    4383    419177237 :            && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
    4384    424317952 :            && TREE_CODE (decl) != TYPE_DECL)
    4385              :     {
    4386      1509567 :       tree type = strip_array_types (TREE_TYPE (decl));
    4387      1509567 :       if (ANON_AGGR_TYPE_P (type))
    4388              :         {
    4389              :           /* [class.union.anon]/1: Each object of such an unnamed type shall
    4390              :              be such an unnamed object.  */
    4391           12 :           tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (type));
    4392           12 :           auto_diagnostic_group d;
    4393           12 :           if (ANON_UNION_TYPE_P (type))
    4394              :             {
    4395            8 :               error_at (location_of (decl),
    4396              :                         "declaration of member %qD with array of anonymous "
    4397            8 :                         "union type %qT", decl, TREE_TYPE (decl));
    4398            8 :               inform (DECL_SOURCE_LOCATION (adecl),
    4399              :                       "anonymous union declared here");
    4400              :             }
    4401              :           else
    4402              :             {
    4403            4 :               error_at (location_of (decl),
    4404              :                         "declaration of member %qD with array of anonymous "
    4405            4 :                         "struct type %qT", decl, TREE_TYPE (decl));
    4406            4 :               inform (DECL_SOURCE_LOCATION (adecl),
    4407              :                       "anonymous struct declared here");
    4408              :             }
    4409           12 :         }
    4410              :     }
    4411              : 
    4412    423026835 :   if (TREE_CODE (decl) == USING_DECL)
    4413              :     /* Avoid debug info for class-scope USING_DECLS for now, we'll
    4414              :        call cp_emit_debug_info_for_using later. */
    4415      3475335 :     DECL_IGNORED_P (decl) = 1;
    4416              : 
    4417              :   /* Check for bare parameter packs in the non-static data member
    4418              :      declaration.  */
    4419    423026835 :   if (TREE_CODE (decl) == FIELD_DECL)
    4420              :     {
    4421     31116881 :       if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
    4422            9 :         TREE_TYPE (decl) = error_mark_node;
    4423     31116881 :       if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
    4424            0 :         DECL_ATTRIBUTES (decl) = NULL_TREE;
    4425              :     }
    4426              : 
    4427              :   /* [dcl.link]
    4428              : 
    4429              :      A C language linkage is ignored for the names of class members
    4430              :      and the member function type of class member functions.  */
    4431    423026835 :   if (DECL_LANG_SPECIFIC (decl))
    4432    386022339 :     SET_DECL_LANGUAGE (decl, lang_cplusplus);
    4433              : 
    4434    423026835 :   bool add = false;
    4435              : 
    4436              :   /* Functions and non-functions are added differently.  */
    4437    423026835 :   if (DECL_DECLARES_FUNCTION_P (decl))
    4438    218920549 :     add = add_method (current_class_type, decl, false);
    4439              :   /* Enter the DECL into the scope of the class, if the class
    4440              :      isn't a closure (whose fields are supposed to be unnamed).  */
    4441    204106286 :   else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
    4442    200199447 :            || maybe_push_used_methods (decl)
    4443    402397798 :            || pushdecl_class_level (decl))
    4444              :     add = true;
    4445              : 
    4446    218920549 :   if (add)
    4447              :     {
    4448              :       /* All TYPE_DECLs go at the end of TYPE_FIELDS.  Ordinary fields
    4449              :          go at the beginning.  The reason is that
    4450              :          legacy_nonfn_member_lookup searches the list in order, and we
    4451              :          want a field name to override a type name so that the "struct
    4452              :          stat hack" will work.  In particular:
    4453              : 
    4454              :            struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
    4455              : 
    4456              :          is valid.  */
    4457              : 
    4458    423013327 :       if (TREE_CODE (decl) == TYPE_DECL)
    4459    144641362 :         TYPE_FIELDS (current_class_type)
    4460    289282724 :           = chainon (TYPE_FIELDS (current_class_type), decl);
    4461              :       else
    4462              :         {
    4463    278371965 :           DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
    4464    278371965 :           TYPE_FIELDS (current_class_type) = decl;
    4465              :         }
    4466              : 
    4467    423013327 :       maybe_add_class_template_decl_list (current_class_type, decl,
    4468              :                                           /*friend_p=*/0);
    4469              :     }
    4470              : }
    4471              : 
    4472              : /* Finish processing a complete template declaration.  The PARMS are
    4473              :    the template parameters.  */
    4474              : 
    4475              : void
    4476     93903692 : finish_template_decl (tree parms)
    4477              : {
    4478     93903692 :   if (parms)
    4479     93903683 :     end_template_decl ();
    4480              :   else
    4481            9 :     end_specialization ();
    4482     93903692 : }
    4483              : 
    4484              : // Returns the template type of the class scope being entered. If we're
    4485              : // entering a constrained class scope. TYPE is the class template
    4486              : // scope being entered and we may need to match the intended type with
    4487              : // a constrained specialization. For example:
    4488              : //
    4489              : //    template<Object T>
    4490              : //      struct S { void f(); }; #1
    4491              : //
    4492              : //    template<Object T>
    4493              : //      void S<T>::f() { }      #2
    4494              : //
    4495              : // We check, in #2, that S<T> refers precisely to the type declared by
    4496              : // #1 (i.e., that the constraints match). Note that the following should
    4497              : // be an error since there is no specialization of S<T> that is
    4498              : // unconstrained, but this is not diagnosed here.
    4499              : //
    4500              : //    template<typename T>
    4501              : //      void S<T>::f() { }
    4502              : //
    4503              : // We cannot diagnose this problem here since this function also matches
    4504              : // qualified template names that are not part of a definition. For example:
    4505              : //
    4506              : //    template<Integral T, Floating_point U>
    4507              : //      typename pair<T, U>::first_type void f(T, U);
    4508              : //
    4509              : // Here, it is unlikely that there is a partial specialization of
    4510              : // pair constrained for Integral and Floating_point arguments.
    4511              : //
    4512              : // The general rule is: if a constrained specialization with matching
    4513              : // constraints is found return that type. Also note that if TYPE is not a
    4514              : // class-type (e.g. a typename type), then no fixup is needed.
    4515              : 
    4516              : static tree
    4517     18399909 : fixup_template_type (tree type)
    4518              : {
    4519              :   // Find the template parameter list at the a depth appropriate to
    4520              :   // the scope we're trying to enter.
    4521     18399909 :   tree parms = current_template_parms;
    4522     18399909 :   int depth = template_class_depth (type);
    4523     22702555 :   for (int n = current_template_depth; n > depth && parms; --n)
    4524      4302646 :     parms = TREE_CHAIN (parms);
    4525     18399909 :   if (!parms)
    4526              :     return type;
    4527     18399899 :   tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
    4528     18399899 :   tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
    4529              : 
    4530              :   // Search for a specialization whose type and constraints match.
    4531     18399899 :   tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
    4532     18399899 :   tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
    4533     35663922 :   while (specs)
    4534              :     {
    4535     17706868 :       tree spec_constr = get_constraints (TREE_VALUE (specs));
    4536              : 
    4537              :       // If the type and constraints match a specialization, then we
    4538              :       // are entering that type.
    4539     17706868 :       if (same_type_p (type, TREE_TYPE (specs))
    4540     17706868 :           && equivalent_constraints (cur_constr, spec_constr))
    4541       442845 :         return TREE_TYPE (specs);
    4542     17264023 :       specs = TREE_CHAIN (specs);
    4543              :     }
    4544              : 
    4545              :   // If no specialization matches, then must return the type
    4546              :   // previously found.
    4547              :   return type;
    4548              : }
    4549              : 
    4550              : /* Finish processing a template-id (which names a type) of the form
    4551              :    NAME < ARGS >.  Return the TYPE_DECL for the type named by the
    4552              :    template-id.  If ENTERING_SCOPE is nonzero we are about to enter
    4553              :    the scope of template-id indicated.  */
    4554              : 
    4555              : tree
    4556    190451895 : finish_template_type (tree name, tree args, int entering_scope)
    4557              : {
    4558    190451895 :   tree type;
    4559              : 
    4560    190451895 :   type = lookup_template_class (name, args,
    4561              :                                 NULL_TREE, NULL_TREE,
    4562              :                                 tf_warning_or_error | tf_user);
    4563    190451892 :   if (entering_scope)
    4564     19373449 :     type = adjust_type_for_entering_scope (type);
    4565              : 
    4566              :   /* If we might be entering the scope of a partial specialization,
    4567              :      find the one with the right constraints.  */
    4568    190451892 :   if (flag_concepts
    4569    187749302 :       && entering_scope
    4570     19017620 :       && CLASS_TYPE_P (type)
    4571     18899616 :       && CLASSTYPE_TEMPLATE_INFO (type)
    4572     18899607 :       && dependent_type_p (type)
    4573    208851801 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
    4574     18399909 :     type = fixup_template_type (type);
    4575              : 
    4576    190451892 :   if (type == error_mark_node)
    4577              :     return type;
    4578    190449599 :   else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
    4579    149455560 :     return TYPE_STUB_DECL (type);
    4580              :   else
    4581     40994039 :     return TYPE_NAME (type);
    4582              : }
    4583              : 
    4584              : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
    4585              :    and ANNOTATIONS.
    4586              :    Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
    4587              :    ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
    4588              :    and the BASE_CLASS, or NULL_TREE if an error occurred.  The
    4589              :    ACCESS_SPECIFIER is one of
    4590              :    access_{default,public,protected,private}_node.  For a virtual base
    4591              :    we set TREE_TYPE.  */
    4592              : 
    4593              : tree
    4594     11512304 : finish_base_specifier (tree base, tree access, bool virtual_p,
    4595              :                        tree annotations)
    4596              : {
    4597     11512304 :   tree result;
    4598              : 
    4599     11512304 :   if (base == error_mark_node)
    4600              :     {
    4601            0 :       error ("invalid base-class specification");
    4602            0 :       result = NULL_TREE;
    4603              :     }
    4604     11512304 :   else if (! MAYBE_CLASS_TYPE_P (base))
    4605              :     {
    4606            3 :       error ("%qT is not a class type", base);
    4607            3 :       result = NULL_TREE;
    4608              :     }
    4609              :   else
    4610              :     {
    4611     11512301 :       if (cp_type_quals (base) != 0)
    4612              :         {
    4613              :           /* DR 484: Can a base-specifier name a cv-qualified
    4614              :              class type?  */
    4615           12 :           base = TYPE_MAIN_VARIANT (base);
    4616              :         }
    4617     11512301 :       if (annotations)
    4618           18 :         access = build_tree_list (access, nreverse (annotations));
    4619     11512301 :       result = build_tree_list (access, base);
    4620     11512301 :       if (virtual_p)
    4621        26163 :         TREE_TYPE (result) = integer_type_node;
    4622              :     }
    4623              : 
    4624     11512304 :   return result;
    4625              : }
    4626              : 
    4627              : /* If FNS is a member function, a set of member functions, or a
    4628              :    template-id referring to one or more member functions, return a
    4629              :    BASELINK for FNS, incorporating the current access context.
    4630              :    Otherwise, return FNS unchanged.  If IGNORE_CURRENT_CLASS_P is
    4631              :    true, we do not consider the currently open derived class.  */
    4632              : 
    4633              : tree
    4634    187248660 : baselink_for_fns (tree fns, bool ignore_current_class_p/*=false*/)
    4635              : {
    4636    187248660 :   if (BASELINK_P (fns) || error_operand_p (fns))
    4637              :     return fns;
    4638              : 
    4639    173221210 :   tree scope = ovl_scope (fns);
    4640    173221210 :   if (!CLASS_TYPE_P (scope))
    4641              :     return fns;
    4642              : 
    4643      8986044 :   tree cl = (ignore_current_class_p
    4644      8986044 :              ? NULL_TREE
    4645      8984304 :              : currently_open_derived_class (scope));
    4646      8984304 :   if (!cl)
    4647              :     cl = scope;
    4648      8986044 :   tree access_path = TYPE_BINFO (cl);
    4649      8986044 :   tree conv_path = (cl == scope ? access_path
    4650       711665 :                     : lookup_base (cl, scope, ba_any, NULL, tf_none));
    4651      8986044 :   return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
    4652              : }
    4653              : 
    4654              : /* Returns true iff we are currently parsing a lambda-declarator.  */
    4655              : 
    4656              : bool
    4657   2002481928 : parsing_lambda_declarator ()
    4658              : {
    4659   2002481928 :   cp_binding_level *b = current_binding_level;
    4660   2004533535 :   while (b->kind == sk_template_parms || b->kind == sk_function_parms)
    4661      2051607 :     b = b->level_chain;
    4662   2002481928 :   return b->kind == sk_lambda;
    4663              : }
    4664              : 
    4665              : /* Returns true iff DECL is a variable from a function outside
    4666              :    the current one.  */
    4667              : 
    4668              : static bool
    4669   2674949241 : outer_var_p (tree decl)
    4670              : {
    4671              :   /* These should have been stripped or otherwise handled by the caller.  */
    4672   2674949241 :   gcc_checking_assert (!REFERENCE_REF_P (decl));
    4673              : 
    4674   1755631568 :   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
    4675   2456337821 :           && DECL_FUNCTION_SCOPE_P (decl)
    4676              :           /* Don't get confused by temporaries.  */
    4677   2034818324 :           && DECL_NAME (decl)
    4678   4685643870 :           && (DECL_CONTEXT (decl) != current_function_decl
    4679   2000281240 :               || parsing_nsdmi ()
    4680              :               /* Also consider captures as outer vars if we are in
    4681              :                  decltype in a lambda declarator as in:
    4682              :                    auto l = [j=0]() -> decltype((j)) { ... }
    4683              :                  for the sake of finish_decltype_type.
    4684              : 
    4685              :                  (Similar issue also affects non-lambdas, but vexing parse
    4686              :                  makes it more difficult to handle than lambdas.)  */
    4687   2000279863 :               || parsing_lambda_declarator ()));
    4688              : }
    4689              : 
    4690              : /* As above, but also checks that DECL is automatic.  */
    4691              : 
    4692              : bool
    4693   2674949241 : outer_automatic_var_p (tree decl)
    4694              : {
    4695   2674949241 :   return (outer_var_p (decl)
    4696   2674949241 :           && !TREE_STATIC (decl));
    4697              : }
    4698              : 
    4699              : /* Note whether capture proxy D is only used in a contract condition.  */
    4700              : 
    4701              : static void
    4702       182971 : set_contract_capture_flag (tree d, bool val)
    4703              : {
    4704       182971 :   gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
    4705       182971 :   tree proxy = DECL_VALUE_EXPR (d);
    4706       182971 :   gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
    4707              :                        && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
    4708       182971 :   DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
    4709       182971 : }
    4710              : 
    4711              : /* DECL satisfies outer_automatic_var_p.  Possibly complain about it or
    4712              :    rewrite it for lambda capture.
    4713              : 
    4714              :    If ODR_USE is true, we're being called from mark_use, and we complain about
    4715              :    use of constant variables.  If ODR_USE is false, we're being called for the
    4716              :    id-expression, and we do lambda capture.  */
    4717              : 
    4718              : tree
    4719      5361863 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
    4720              :                        bool odr_use/*=false*/)
    4721              : {
    4722      5368400 :   bool in_typeid_probe = false;
    4723      5368400 :   if (cp_unevaluated_operand)
    4724              :     {
    4725      3166151 :       tree type = TREE_TYPE (decl);
    4726      3166151 :       if (!dependent_type_p (type)
    4727      3166151 :           && variably_modified_type_p (type, NULL_TREE))
    4728              :         /* VLAs are used even in unevaluated context.  */;
    4729      3166145 :       else if (cp_unevaluated_operand > cp_unevaluated_typeid_cutoff)
    4730              :         /* It's not a use (3.2) if we're in an unevaluated context.  */
    4731              :         return decl;
    4732              :       else
    4733              :         /* Inside a typeid operand's own probe: capture is still
    4734              :            attempted below ([expr.prim.lambda.capture]/7), but a missing
    4735              :            capture-default must not be diagnosed yet - see below.  */
    4736              :         in_typeid_probe = true;
    4737              :     }
    4738      2202318 :   if (decl == error_mark_node)
    4739              :     return decl;
    4740              : 
    4741      2202312 :   tree context = DECL_CONTEXT (decl);
    4742      2202312 :   tree containing_function = current_function_decl;
    4743      2202312 :   tree lambda_stack = NULL_TREE;
    4744      2202312 :   tree lambda_expr = NULL_TREE;
    4745      2202312 :   tree initializer = convert_from_reference (decl);
    4746      2202312 :   tree var = strip_normal_capture_proxy (decl);
    4747              : 
    4748              :   /* Mark it as used now even if the use is ill-formed.  */
    4749      2202312 :   if (!mark_used (decl, complain))
    4750            3 :     return error_mark_node;
    4751              : 
    4752      2202309 :   if (parsing_nsdmi () || parsing_lambda_declarator ())
    4753              :     containing_function = NULL_TREE;
    4754              : 
    4755      4403711 :   if (containing_function && LAMBDA_FUNCTION_P (containing_function))
    4756              :     {
    4757              :       /* Check whether we've already built a proxy.  */
    4758      2201751 :       tree d = retrieve_local_specialization (var);
    4759              : 
    4760      2201751 :       if (d && d != decl && is_capture_proxy (d))
    4761              :         {
    4762      1131082 :           if (flag_contracts && !processing_contract_condition)
    4763              :             /* We might have created a capture for a contract_assert ref. to
    4764              :                some var, if that is now captured 'normally' then this is OK.
    4765              :                Otherwise we leave the capture marked as incorrect.  */
    4766       182965 :             set_contract_capture_flag (d, false);
    4767      1131082 :           if (DECL_CONTEXT (d) == containing_function)
    4768              :             /* We already have an inner proxy.  */
    4769              :             return d;
    4770              :           else
    4771              :             /* We need to capture an outer proxy.  */
    4772              :             return process_outer_var_ref (d, complain, odr_use);
    4773              :         }
    4774              :     }
    4775              : 
    4776              :   /* If we are in a lambda function, we can move out until we hit
    4777              :      1. the context,
    4778              :      2. a non-lambda function, or
    4779              :      3. a non-default capturing lambda function.  */
    4780      2148814 :   while (context != containing_function
    4781              :          /* containing_function can be null with invalid generic lambdas.  */
    4782      2148814 :          && containing_function
    4783      3227819 :          && LAMBDA_FUNCTION_P (containing_function))
    4784              :     {
    4785      1079005 :       tree closure = DECL_CONTEXT (containing_function);
    4786      1079005 :       lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
    4787              : 
    4788      1079005 :       if (TYPE_CLASS_SCOPE_P (closure))
    4789              :         /* A lambda in an NSDMI (c++/64496).  */
    4790              :         break;
    4791              : 
    4792      1079002 :       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4793              :         break;
    4794              : 
    4795      1077587 :       lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
    4796              : 
    4797      1077587 :       containing_function = decl_function_context (containing_function);
    4798              :     }
    4799              : 
    4800              :   /* In a lambda within a template, wait until instantiation time to implicitly
    4801              :      capture a parameter pack.  We want to wait because we don't know if we're
    4802              :      capturing the whole pack or a single element, and it's OK to wait because
    4803              :      find_parameter_packs_r walks into the lambda body.  */
    4804      1071227 :   if (context == containing_function
    4805      1071227 :       && DECL_PACK_P (decl))
    4806              :     return decl;
    4807              : 
    4808      1026888 :   if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
    4809              :     {
    4810            6 :       if (complain & tf_error)
    4811            6 :         error ("cannot capture member %qD of anonymous union", decl);
    4812            6 :       return error_mark_node;
    4813              :     }
    4814              :   /* Do lambda capture when processing the id-expression, not when
    4815              :      odr-using a variable, but uses in a contract must not cause a capture.  */
    4816      1026882 :   if (!odr_use && context == containing_function)
    4817              :     {
    4818      1024906 :       decl = add_default_capture (lambda_stack,
    4819      1024906 :                                   /*id=*/DECL_NAME (decl), initializer);
    4820      1024906 :       if (flag_contracts && processing_contract_condition)
    4821            6 :         set_contract_capture_flag (decl, true);
    4822              :     }
    4823              :   /* Capture was attempted above; whether it's really needed depends on
    4824              :      an evaluated-ness we don't know yet.  Defer instead of diagnosing:
    4825              :      a later, non-probe pass will complain if the operand turns out
    4826              :      evaluated, and there's nothing to complain about if it doesn't.  */
    4827         1976 :   else if (in_typeid_probe)
    4828              :     return var;
    4829              :   /* Only an odr-use of an outer automatic variable causes an
    4830              :      error, and a constant variable can decay to a prvalue
    4831              :      constant without odr-use.  So don't complain yet.  */
    4832         1967 :   else if (!odr_use && decl_constant_var_p (var))
    4833              :     return var;
    4834              :   /* Don't complain when DECL is dependent, because it can turn out to
    4835              :      be constant (and therefore needing no capture) when instantiating.  */
    4836          438 :   else if (VAR_P (var) && instantiation_dependent_expression_p (var))
    4837              :     return var;
    4838          420 :   else if (lambda_expr)
    4839              :     {
    4840           60 :       if (complain & tf_error)
    4841              :         {
    4842           56 :           auto_diagnostic_group d;
    4843           56 :           error ("%qD is not captured", decl);
    4844           56 :           tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
    4845           56 :           if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4846           53 :             inform (location_of (closure),
    4847              :                     "the lambda has no capture-default");
    4848            3 :           else if (TYPE_CLASS_SCOPE_P (closure))
    4849            3 :             inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
    4850              :                     "capture variables from the enclosing context",
    4851            3 :                     TYPE_CONTEXT (closure));
    4852           56 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4853           56 :         }
    4854           60 :       return error_mark_node;
    4855              :     }
    4856          360 :   else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
    4857              :     /* Use of a parameter in a contract condition is fine.  */
    4858              :     return decl;
    4859              :   else
    4860              :     {
    4861           53 :       if (complain & tf_error)
    4862              :         {
    4863           39 :           auto_diagnostic_group d;
    4864           57 :           error (VAR_P (decl)
    4865              :                  ? G_("use of local variable with automatic storage from "
    4866              :                       "containing function")
    4867              :                  : G_("use of parameter from containing function"));
    4868           39 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4869           39 :         }
    4870           53 :       return error_mark_node;
    4871              :     }
    4872              :   return decl;
    4873              : }
    4874              : 
    4875              : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
    4876              :    id-expression.  (See cp_parser_id_expression for details.)  SCOPE,
    4877              :    if non-NULL, is the type or namespace used to explicitly qualify
    4878              :    ID_EXPRESSION.  DECL is the entity to which that name has been
    4879              :    resolved.
    4880              : 
    4881              :    *CONSTANT_EXPRESSION_P is true if we are presently parsing a
    4882              :    constant-expression.  In that case, *NON_CONSTANT_EXPRESSION_P will
    4883              :    be set to true if this expression isn't permitted in a
    4884              :    constant-expression, but it is otherwise not set by this function.
    4885              :    *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
    4886              :    constant-expression, but a non-constant expression is also
    4887              :    permissible.
    4888              : 
    4889              :    DONE is true if this expression is a complete postfix-expression;
    4890              :    it is false if this expression is followed by '->', '[', '(', etc.
    4891              :    ADDRESS_P is true iff this expression is the operand of '&'.
    4892              :    TEMPLATE_P is true iff the qualified-id was of the form
    4893              :    "A::template B".  TEMPLATE_ARG_P is true iff this qualified name
    4894              :    appears as a template argument.
    4895              : 
    4896              :    If an error occurs, and it is the kind of error that might cause
    4897              :    the parser to abort a tentative parse, *ERROR_MSG is filled in.  It
    4898              :    is the caller's responsibility to issue the message.  *ERROR_MSG
    4899              :    will be a string with static storage duration, so the caller need
    4900              :    not "free" it.
    4901              : 
    4902              :    Return an expression for the entity, after issuing appropriate
    4903              :    diagnostics.  This function is also responsible for transforming a
    4904              :    reference to a non-static member into a COMPONENT_REF that makes
    4905              :    the use of "this" explicit.
    4906              : 
    4907              :    Upon return, *IDK will be filled in appropriately.  */
    4908              : static cp_expr
    4909    794094263 : finish_id_expression_1 (tree id_expression,
    4910              :                         tree decl,
    4911              :                         tree scope,
    4912              :                         cp_id_kind *idk,
    4913              :                         bool integral_constant_expression_p,
    4914              :                         bool allow_non_integral_constant_expression_p,
    4915              :                         bool *non_integral_constant_expression_p,
    4916              :                         bool template_p,
    4917              :                         bool done,
    4918              :                         bool address_p,
    4919              :                         bool template_arg_p,
    4920              :                         const char **error_msg,
    4921              :                         location_t location)
    4922              : {
    4923    794094263 :   decl = strip_using_decl (decl);
    4924              : 
    4925              :   /* Initialize the output parameters.  */
    4926    794094263 :   *idk = CP_ID_KIND_NONE;
    4927    794094263 :   *error_msg = NULL;
    4928              : 
    4929    794094263 :   if (id_expression == error_mark_node)
    4930           12 :     return error_mark_node;
    4931              :   /* If we have a template-id, then no further lookup is
    4932              :      required.  If the template-id was for a template-class, we
    4933              :      will sometimes have a TYPE_DECL at this point.  */
    4934    794094251 :   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4935    738775253 :            || TREE_CODE (decl) == TYPE_DECL)
    4936              :     ;
    4937              :   /* Look up the name.  */
    4938              :   else
    4939              :     {
    4940    738774326 :       if (decl == error_mark_node)
    4941              :         {
    4942              :           /* Name lookup failed.  */
    4943       131081 :           if (scope
    4944          374 :               && !dependent_namespace_p (scope)
    4945       131455 :               && (!TYPE_P (scope)
    4946          119 :                   || (!dependentish_scope_p (scope)
    4947          115 :                       && !(identifier_p (id_expression)
    4948          100 :                            && IDENTIFIER_CONV_OP_P (id_expression)
    4949            3 :                            && dependent_type_p (TREE_TYPE (id_expression))))))
    4950              :             {
    4951              :               /* If the qualifying type is non-dependent (and the name
    4952              :                  does not name a conversion operator to a dependent
    4953              :                  type), issue an error.  */
    4954          364 :               qualified_name_lookup_error (scope, id_expression, decl, location);
    4955          364 :               return error_mark_node;
    4956              :             }
    4957       130717 :           else if (!scope)
    4958              :             {
    4959              :               /* It may be resolved via Koenig lookup.  */
    4960       130707 :               *idk = CP_ID_KIND_UNQUALIFIED;
    4961       130707 :               return id_expression;
    4962              :             }
    4963              :           else
    4964              :             decl = id_expression;
    4965              :         }
    4966              : 
    4967              :       /* Remember that the name was used in the definition of
    4968              :          the current class so that we can check later to see if
    4969              :          the meaning would have been different after the class
    4970              :          was entirely defined.  */
    4971    738643245 :       if (!scope && decl != error_mark_node && identifier_p (id_expression))
    4972    660517696 :         maybe_note_name_used_in_class (id_expression, decl);
    4973              : 
    4974              :       /* A use in unevaluated operand might not be instantiated appropriately
    4975              :          if tsubst_copy builds a dummy parm, or if we never instantiate a
    4976              :          generic lambda, so mark it now.  */
    4977    738643255 :       if (processing_template_decl
    4978    738643255 :           && (cp_unevaluated_operand
    4979    639353966 :               || generic_lambda_fn_p (current_function_decl)))
    4980     20574899 :         mark_type_use (decl);
    4981              : 
    4982              :       /* Disallow uses of local variables from containing functions, except
    4983              :          within lambda-expressions.  */
    4984    738643255 :       if (outer_automatic_var_p (decl))
    4985              :         {
    4986      3823363 :           decl = process_outer_var_ref (decl, tf_warning_or_error);
    4987      3823363 :           if (decl == error_mark_node)
    4988           92 :             return error_mark_node;
    4989              :         }
    4990              : 
    4991              :       /* Also disallow uses of function parameters outside the function
    4992              :          body, except inside an unevaluated context (i.e. decltype).  */
    4993    738643163 :       if (TREE_CODE (decl) == PARM_DECL
    4994    307472978 :           && DECL_CONTEXT (decl) == NULL_TREE
    4995      8260263 :           && !CONSTRAINT_VAR_P (decl)
    4996      4447687 :           && !cp_unevaluated_operand
    4997          601 :           && !processing_contract_condition
    4998    738643219 :           && !processing_omp_trait_property_expr)
    4999              :         {
    5000           38 :           *error_msg = G_("use of parameter outside function body");
    5001           38 :           return error_mark_node;
    5002              :         }
    5003              :     }
    5004              : 
    5005              :   /* If we didn't find anything, or what we found was a type,
    5006              :      then this wasn't really an id-expression.  */
    5007    793963050 :   if (TREE_CODE (decl) == TEMPLATE_DECL
    5008    793963050 :       && !DECL_FUNCTION_TEMPLATE_P (decl))
    5009              :     {
    5010           51 :       *error_msg = G_("missing template arguments");
    5011           51 :       return error_mark_node;
    5012              :     }
    5013    793962999 :   else if (TREE_CODE (decl) == TYPE_DECL
    5014    793962072 :            || TREE_CODE (decl) == NAMESPACE_DECL)
    5015              :     {
    5016          942 :       *error_msg = G_("expected primary-expression");
    5017          942 :       return error_mark_node;
    5018              :     }
    5019              : 
    5020              :   /* If the name resolved to a template parameter, there is no
    5021              :      need to look it up again later.  */
    5022     34074449 :   if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
    5023    808032712 :       || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    5024              :     {
    5025     20003794 :       tree r;
    5026              : 
    5027     20003794 :       *idk = CP_ID_KIND_NONE;
    5028     20003794 :       if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    5029            0 :         decl = TEMPLATE_PARM_DECL (decl);
    5030     20003794 :       r = DECL_INITIAL (decl);
    5031     20003794 :       if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
    5032              :         {
    5033              :           /* If the entity is a template parameter object for a template
    5034              :              parameter of type T, the type of the expression is const T.  */
    5035         2969 :           tree ctype = TREE_TYPE (r);
    5036         2969 :           ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
    5037              :                                                    | TYPE_QUAL_CONST));
    5038         2969 :           r = build1 (VIEW_CONVERT_EXPR, ctype, r);
    5039              :         }
    5040     20003794 :       r = convert_from_reference (r);
    5041     20003794 :       if (integral_constant_expression_p
    5042      3454964 :           && !dependent_type_p (TREE_TYPE (decl))
    5043     22956672 :           && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
    5044              :         {
    5045         1039 :           if (!allow_non_integral_constant_expression_p)
    5046            6 :             error ("template parameter %qD of type %qT is not allowed in "
    5047              :                    "an integral constant expression because it is not of "
    5048            6 :                    "integral or enumeration type", decl, TREE_TYPE (decl));
    5049         1039 :           *non_integral_constant_expression_p = true;
    5050              :         }
    5051              : 
    5052     20003794 :       if (flag_contracts && processing_contract_condition)
    5053           27 :         r = constify_contract_access (r);
    5054              : 
    5055     20003794 :       return r;
    5056              :     }
    5057    773958263 :   else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
    5058              :     {
    5059            9 :       gcc_checking_assert (scope);
    5060            9 :       *idk = CP_ID_KIND_QUALIFIED;
    5061            9 :       cp_warn_deprecated_use_scopes (scope);
    5062            9 :       decl = finish_qualified_id_expr (scope, decl, done, address_p,
    5063              :                                        template_p, template_arg_p,
    5064              :                                        tf_warning_or_error);
    5065              :     }
    5066              :   else
    5067              :     {
    5068    773958254 :       if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    5069     55318998 :           && variable_template_p (TREE_OPERAND (decl, 0))
    5070    786546265 :           && !concept_check_p (decl))
    5071              :         /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
    5072              :            considered type-dependent) now, so that the dependence test that
    5073              :            follows gives us the right answer: if it represents a non-dependent
    5074              :            variable template-id then finish_template_variable will yield the
    5075              :            corresponding non-dependent VAR_DECL.  */
    5076     12588011 :         decl = finish_template_variable (decl);
    5077              : 
    5078    773958254 :       bool dependent_p = type_dependent_expression_p (decl);
    5079              : 
    5080              :       /* If the declaration was explicitly qualified indicate
    5081              :          that.  The semantics of `A::f(3)' are different than
    5082              :          `f(3)' if `f' is virtual.  */
    5083   1547916508 :       *idk = (scope
    5084    773958254 :               ? CP_ID_KIND_QUALIFIED
    5085    673293799 :               : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    5086    673293799 :                  ? CP_ID_KIND_TEMPLATE_ID
    5087              :                  : (dependent_p
    5088    640801454 :                     ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
    5089              :                     : CP_ID_KIND_UNQUALIFIED)));
    5090              : 
    5091    773958254 :       if (dependent_p
    5092    773958254 :           && !scope
    5093    443960117 :           && DECL_P (decl)
    5094   1186394150 :           && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
    5095              :         /* Dependent type attributes on the decl mean that the TREE_TYPE is
    5096              :            wrong, so just return the identifier.  */
    5097           39 :         return id_expression;
    5098              : 
    5099    773958215 :       if (DECL_CLASS_TEMPLATE_P (decl))
    5100              :         {
    5101            0 :           error ("use of class template %qT as expression", decl);
    5102            0 :           return error_mark_node;
    5103              :         }
    5104              : 
    5105    773958215 :       if (TREE_CODE (decl) == TREE_LIST)
    5106              :         {
    5107              :           /* Ambiguous reference to base members.  */
    5108            0 :           auto_diagnostic_group d;
    5109            0 :           error ("request for member %qD is ambiguous in "
    5110              :                  "multiple inheritance lattice", id_expression);
    5111            0 :           print_candidates (input_location, decl);
    5112            0 :           return error_mark_node;
    5113            0 :         }
    5114              : 
    5115              :       /* Mark variable-like entities as used.  Functions are similarly
    5116              :          marked either below or after overload resolution.  */
    5117    773958215 :       if ((VAR_P (decl)
    5118    561019920 :            || TREE_CODE (decl) == PARM_DECL
    5119    253546986 :            || TREE_CODE (decl) == CONST_DECL
    5120    239476331 :            || TREE_CODE (decl) == RESULT_DECL)
    5121   1095501804 :           && !mark_used (decl))
    5122           12 :         return error_mark_node;
    5123              : 
    5124              :       /* Only certain kinds of names are allowed in constant
    5125              :          expression.  Template parameters have already
    5126              :          been handled above.  */
    5127    773958200 :       if (! error_operand_p (decl)
    5128    773957872 :           && !dependent_p
    5129    773957872 :           && integral_constant_expression_p
    5130     77896488 :           && !decl_constant_var_p (decl)
    5131     63326650 :           && TREE_CODE (decl) != CONST_DECL
    5132     54670884 :           && !builtin_valid_in_constant_expr_p (decl)
    5133    828579179 :           && !concept_check_p (decl))
    5134              :         {
    5135     54051389 :           if (!allow_non_integral_constant_expression_p)
    5136              :             {
    5137           31 :               error ("%qD cannot appear in a constant-expression", decl);
    5138           31 :               return error_mark_node;
    5139              :             }
    5140     54051358 :           *non_integral_constant_expression_p = true;
    5141              :         }
    5142              : 
    5143    773958169 :       if (tree wrap = maybe_get_tls_wrapper_call (decl))
    5144              :         /* Replace an evaluated use of the thread_local variable with
    5145              :            a call to its wrapper.  */
    5146              :         decl = wrap;
    5147    773957657 :       else if (concept_check_p (decl))
    5148              :         {
    5149              :           /* Nothing more to do. All of the analysis for concept checks
    5150              :              is done by build_conept_id, called from the parser.  */
    5151              :         }
    5152    756958424 :       else if (scope)
    5153              :         {
    5154     98703264 :           if (TREE_CODE (decl) == SCOPE_REF)
    5155              :             {
    5156        89959 :               gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
    5157        89959 :               decl = TREE_OPERAND (decl, 1);
    5158              :             }
    5159              : 
    5160     98703264 :           decl = (adjust_result_of_qualified_name_lookup
    5161     98703264 :                   (decl, scope, current_nonlambda_class_type()));
    5162              : 
    5163     98703264 :           cp_warn_deprecated_use_scopes (scope);
    5164              : 
    5165     98703264 :           if (TYPE_P (scope))
    5166     14052183 :             decl = finish_qualified_id_expr (scope,
    5167              :                                              decl,
    5168              :                                              done,
    5169              :                                              address_p,
    5170              :                                              template_p,
    5171              :                                              template_arg_p,
    5172              :                                              tf_warning_or_error);
    5173              :           else
    5174     84651081 :             decl = convert_from_reference (decl);
    5175              :         }
    5176    658255160 :       else if (TREE_CODE (decl) == FIELD_DECL)
    5177              :         {
    5178     68653035 :           if (flag_contracts && processing_contract_condition
    5179           40 :               && contract_class_ptr == current_class_ptr)
    5180              :             {
    5181            6 :               error ("%qD 'this' required when accessing a member within a "
    5182              :                   "constructor precondition or destructor postcondition "
    5183              :                   "contract check", decl);
    5184            6 :                       return error_mark_node;
    5185              :             }
    5186              :           /* Since SCOPE is NULL here, this is an unqualified name.
    5187              :              Access checking has been performed during name lookup
    5188              :              already.  Turn off checking to avoid duplicate errors.  */
    5189     68653029 :           push_deferring_access_checks (dk_no_check);
    5190     68653029 :           decl = finish_non_static_data_member (decl, NULL_TREE,
    5191              :                                                 /*qualifying_scope=*/NULL_TREE);
    5192     68653029 :           pop_deferring_access_checks ();
    5193              :         }
    5194    589602125 :       else if (is_overloaded_fn (decl))
    5195              :         {
    5196              :           /* We only need to look at the first function,
    5197              :              because all the fns share the attribute we're
    5198              :              concerned with (all member fns or all non-members).  */
    5199     63429777 :           tree first_fn = get_first_fn (decl);
    5200     63429777 :           first_fn = STRIP_TEMPLATE (first_fn);
    5201              : 
    5202     63429777 :           if (!template_arg_p
    5203     63429777 :               && (TREE_CODE (first_fn) == USING_DECL
    5204     63427871 :                   || (TREE_CODE (first_fn) == FUNCTION_DECL
    5205     63427871 :                       && DECL_FUNCTION_MEMBER_P (first_fn)
    5206     38809589 :                       && !shared_member_p (decl))))
    5207              :             {
    5208              :               /* A set of member functions.  */
    5209     29947093 :               if (flag_contracts && processing_contract_condition
    5210           24 :                   && contract_class_ptr == current_class_ptr)
    5211              :                 {
    5212            3 :                   error ("%qD 'this' required when accessing a member within a "
    5213              :                       "constructor precondition or destructor postcondition "
    5214              :                       "contract check", decl);
    5215            3 :                   return error_mark_node;
    5216              :                 }
    5217     29947090 :               decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
    5218     29947090 :               return finish_class_member_access_expr (decl, id_expression,
    5219              :                                                       /*template_p=*/false,
    5220     29947090 :                                                       tf_warning_or_error);
    5221              :             }
    5222              : 
    5223     33482684 :           decl = baselink_for_fns (decl);
    5224              :         }
    5225              :       else
    5226              :         {
    5227    514537808 :           if (DECL_P (decl) && DECL_NONLOCAL (decl)
    5228    527682805 :               && DECL_CLASS_SCOPE_P (decl))
    5229              :             {
    5230      1510457 :               tree context = context_for_name_lookup (decl);
    5231      1510457 :               if (context != current_class_type)
    5232              :                 {
    5233       790440 :                   tree path = currently_open_derived_class (context);
    5234       790440 :                   if (!path)
    5235              :                     /* PATH can be null for using an enum of an unrelated
    5236              :                        class; we checked its access in lookup_using_decl.
    5237              : 
    5238              :                        ??? Should this case make a clone instead, like
    5239              :                        handle_using_decl?  */
    5240           43 :                     gcc_assert (TREE_CODE (decl) == CONST_DECL
    5241              :                                 /* This is for:
    5242              :                                     constexpr auto r = ^^S::i;
    5243              :                                     auto a = [:r:];  */
    5244              :                                 || flag_reflection);
    5245              :                   else
    5246       790397 :                     perform_or_defer_access_check (TYPE_BINFO (path),
    5247              :                                                    decl, decl,
    5248              :                                                    tf_warning_or_error);
    5249              :                 }
    5250              :             }
    5251              : 
    5252    526172348 :           decl = convert_from_reference (decl);
    5253              :         }
    5254              :     }
    5255              : 
    5256    744011079 :   check_param_in_postcondition (decl, location);
    5257    744011079 :   if (flag_contracts && processing_contract_condition)
    5258         2196 :     decl = constify_contract_access (decl);
    5259              : 
    5260    744011079 :   return cp_expr (decl, location);
    5261              : }
    5262              : 
    5263              : /* As per finish_id_expression_1, but adding a wrapper node
    5264              :    around the result if needed to express LOCATION.  */
    5265              : 
    5266              : cp_expr
    5267    794094263 : finish_id_expression (tree id_expression,
    5268              :                       tree decl,
    5269              :                       tree scope,
    5270              :                       cp_id_kind *idk,
    5271              :                       bool integral_constant_expression_p,
    5272              :                       bool allow_non_integral_constant_expression_p,
    5273              :                       bool *non_integral_constant_expression_p,
    5274              :                       bool template_p,
    5275              :                       bool done,
    5276              :                       bool address_p,
    5277              :                       bool template_arg_p,
    5278              :                       const char **error_msg,
    5279              :                       location_t location)
    5280              : {
    5281    794094263 :   cp_expr result
    5282    794094263 :     = finish_id_expression_1 (id_expression, decl, scope, idk,
    5283              :                               integral_constant_expression_p,
    5284              :                               allow_non_integral_constant_expression_p,
    5285              :                               non_integral_constant_expression_p,
    5286              :                               template_p, done, address_p, template_arg_p,
    5287              :                               error_msg, location);
    5288    794094260 :   return result.maybe_add_location_wrapper ();
    5289              : }
    5290              : 
    5291              : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
    5292              :    use as a type-specifier.  */
    5293              : 
    5294              : tree
    5295     22150881 : finish_typeof (tree expr)
    5296              : {
    5297     22150881 :   tree type;
    5298              : 
    5299     22150881 :   if (type_dependent_expression_p (expr))
    5300              :     {
    5301     22058634 :       type = cxx_make_type (TYPEOF_TYPE);
    5302     22058634 :       TYPEOF_TYPE_EXPR (type) = expr;
    5303     22058634 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
    5304              : 
    5305     22058634 :       return type;
    5306              :     }
    5307              : 
    5308        92247 :   expr = mark_type_use (expr);
    5309              : 
    5310        92247 :   type = unlowered_expr_type (expr);
    5311              : 
    5312        92247 :   if (!type || type == unknown_type_node)
    5313              :     {
    5314            3 :       error ("type of %qE is unknown", expr);
    5315            3 :       return error_mark_node;
    5316              :     }
    5317              : 
    5318              :   return type;
    5319              : }
    5320              : 
    5321              : /* Implement the __underlying_type keyword: Return the underlying
    5322              :    type of TYPE, suitable for use as a type-specifier.  */
    5323              : 
    5324              : tree
    5325        48583 : finish_underlying_type (tree type)
    5326              : {
    5327        48583 :   if (!complete_type_or_else (type, NULL_TREE))
    5328            3 :     return error_mark_node;
    5329              : 
    5330        48580 :   if (TREE_CODE (type) != ENUMERAL_TYPE)
    5331              :     {
    5332           24 :       error ("%qT is not an enumeration type", type);
    5333           24 :       return error_mark_node;
    5334              :     }
    5335              : 
    5336        48556 :   tree underlying_type = ENUM_UNDERLYING_TYPE (type);
    5337              : 
    5338              :   /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
    5339              :      includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
    5340              :      See finish_enum_value_list for details.  */
    5341        48556 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
    5342           56 :     underlying_type
    5343           56 :       = c_common_type_for_mode (TYPE_MODE (underlying_type),
    5344           56 :                                 TYPE_UNSIGNED (underlying_type));
    5345              : 
    5346              :   return underlying_type;
    5347              : }
    5348              : 
    5349              : /* Implement the __type_pack_element keyword: Return the type
    5350              :    at index IDX within TYPES.  */
    5351              : 
    5352              : static tree
    5353       134973 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
    5354              : {
    5355       134973 :   idx = maybe_constant_value (idx, NULL_TREE, mce_true);
    5356       134973 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
    5357              :     {
    5358            6 :       if (complain & tf_error)
    5359            3 :         error ("pack index has non-integral type %qT", TREE_TYPE (idx));
    5360            6 :       return error_mark_node;
    5361              :     }
    5362       134967 :   if (TREE_CODE (idx) != INTEGER_CST)
    5363              :     {
    5364            2 :       if (complain & tf_error)
    5365              :         {
    5366            2 :           error ("pack index is not an integral constant");
    5367            2 :           cxx_constant_value (idx);
    5368              :         }
    5369            2 :       return error_mark_node;
    5370              :     }
    5371       134965 :   if (tree_int_cst_sgn (idx) < 0)
    5372              :     {
    5373            3 :       if (complain & tf_error)
    5374            3 :         error ("pack index %qE is negative", idx);
    5375            3 :       return error_mark_node;
    5376              :     }
    5377       134962 :   if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
    5378              :     {
    5379           35 :       if (complain & tf_error)
    5380           29 :         error ("pack index %qE is out of range for pack of length %qd",
    5381           29 :                idx, TREE_VEC_LENGTH (types));
    5382           35 :       return error_mark_node;
    5383              :     }
    5384       134927 :   return TREE_VEC_ELT (types, tree_to_shwi (idx));
    5385              : }
    5386              : 
    5387              : /* In a pack-index T...[N], return the element at index IDX within TYPES.
    5388              :    PARENTHESIZED_P is true iff the pack index was wrapped in ().  */
    5389              : 
    5390              : tree
    5391        22552 : pack_index_element (tree idx, tree types, bool parenthesized_p,
    5392              :                     tsubst_flags_t complain)
    5393              : {
    5394        22552 :   tree r = finish_type_pack_element (idx, types, complain);
    5395        22552 :   if (parenthesized_p)
    5396              :     /* For the benefit of decltype(auto).  */
    5397           35 :     r = force_paren_expr (r);
    5398        22552 :   return r;
    5399              : }
    5400              : 
    5401              : /* Implement the __direct_bases keyword: Return the direct base classes
    5402              :    of type.  */
    5403              : 
    5404              : tree
    5405           15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
    5406              : {
    5407           15 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5408           15 :       || !NON_UNION_CLASS_TYPE_P (type))
    5409            8 :     return make_tree_vec (0);
    5410              : 
    5411            7 :   releasing_vec vector;
    5412            7 :   vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
    5413            7 :   tree binfo;
    5414            7 :   unsigned i;
    5415              : 
    5416              :   /* Virtual bases are initialized first */
    5417           20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5418           13 :     if (BINFO_VIRTUAL_P (binfo))
    5419            2 :       vec_safe_push (vector, binfo);
    5420              : 
    5421              :   /* Now non-virtuals */
    5422           20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5423           13 :     if (!BINFO_VIRTUAL_P (binfo))
    5424           11 :       vec_safe_push (vector, binfo);
    5425              : 
    5426            7 :   tree bases_vec = make_tree_vec (vector->length ());
    5427              : 
    5428           27 :   for (i = 0; i < vector->length (); ++i)
    5429           13 :     TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
    5430              : 
    5431            7 :   return bases_vec;
    5432            7 : }
    5433              : 
    5434              : /* Implement the __bases keyword: Return the base classes
    5435              :    of type */
    5436              : 
    5437              : /* Find morally non-virtual base classes by walking binfo hierarchy */
    5438              : /* Virtual base classes are handled separately in finish_bases */
    5439              : 
    5440              : static tree
    5441           73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
    5442              : {
    5443              :   /* Don't walk bases of virtual bases */
    5444           73 :   return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
    5445              : }
    5446              : 
    5447              : static tree
    5448           73 : dfs_calculate_bases_post (tree binfo, void *data_)
    5449              : {
    5450           73 :   vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
    5451           73 :   if (!BINFO_VIRTUAL_P (binfo))
    5452           48 :     vec_safe_push (*data, BINFO_TYPE (binfo));
    5453           73 :   return NULL_TREE;
    5454              : }
    5455              : 
    5456              : /* Calculates the morally non-virtual base classes of a class */
    5457              : static vec<tree, va_gc> *
    5458           16 : calculate_bases_helper (tree type)
    5459              : {
    5460           16 :   vec<tree, va_gc> *vector = make_tree_vector ();
    5461              : 
    5462              :   /* Now add non-virtual base classes in order of construction */
    5463           16 :   if (TYPE_BINFO (type))
    5464           16 :     dfs_walk_all (TYPE_BINFO (type),
    5465              :                   dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
    5466           16 :   return vector;
    5467              : }
    5468              : 
    5469              : tree
    5470           12 : calculate_bases (tree type, tsubst_flags_t complain)
    5471              : {
    5472           12 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5473           12 :       || !NON_UNION_CLASS_TYPE_P (type))
    5474            5 :     return make_tree_vec (0);
    5475              : 
    5476            7 :   releasing_vec vector;
    5477            7 :   tree bases_vec = NULL_TREE;
    5478            7 :   unsigned i;
    5479            7 :   vec<tree, va_gc> *vbases;
    5480            7 :   tree binfo;
    5481              : 
    5482              :   /* First go through virtual base classes */
    5483            7 :   for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
    5484           16 :        vec_safe_iterate (vbases, i, &binfo); i++)
    5485              :     {
    5486            9 :       releasing_vec vbase_bases
    5487            9 :         = calculate_bases_helper (BINFO_TYPE (binfo));
    5488            9 :       vec_safe_splice (vector, vbase_bases);
    5489            9 :     }
    5490              : 
    5491              :   /* Now for the non-virtual bases */
    5492            7 :   releasing_vec nonvbases = calculate_bases_helper (type);
    5493            7 :   vec_safe_splice (vector, nonvbases);
    5494              : 
    5495              :   /* Note that during error recovery vector->length can even be zero.  */
    5496            7 :   if (vector->length () > 1)
    5497              :     {
    5498              :       /* Last element is entire class, so don't copy */
    5499            6 :       bases_vec = make_tree_vec (vector->length () - 1);
    5500              : 
    5501           53 :       for (i = 0; i < vector->length () - 1; ++i)
    5502           41 :         TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
    5503              :     }
    5504              :   else
    5505            1 :     bases_vec = make_tree_vec (0);
    5506              : 
    5507            7 :   return bases_vec;
    5508            7 : }
    5509              : 
    5510              : tree
    5511           28 : finish_bases (tree type, bool direct)
    5512              : {
    5513           28 :   tree bases = NULL_TREE;
    5514              : 
    5515           28 :   if (!processing_template_decl)
    5516              :     {
    5517              :       /* Parameter packs can only be used in templates */
    5518            0 :       error ("parameter pack %<__bases%> only valid in template declaration");
    5519            0 :       return error_mark_node;
    5520              :     }
    5521              : 
    5522           28 :   bases = cxx_make_type (BASES);
    5523           28 :   BASES_TYPE (bases) = type;
    5524           28 :   BASES_DIRECT (bases) = direct;
    5525           28 :   SET_TYPE_STRUCTURAL_EQUALITY (bases);
    5526              : 
    5527           28 :   return bases;
    5528              : }
    5529              : 
    5530              : /* Perform C++-specific checks for __builtin_offsetof before calling
    5531              :    fold_offsetof.  */
    5532              : 
    5533              : tree
    5534         2497 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
    5535              : {
    5536              :   /* If we're processing a template, we can't finish the semantics yet.
    5537              :      Otherwise we can fold the entire expression now.  */
    5538         2497 :   if (processing_template_decl)
    5539              :     {
    5540           60 :       expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
    5541           60 :       SET_EXPR_LOCATION (expr, loc);
    5542           60 :       return expr;
    5543              :     }
    5544              : 
    5545         2437 :   if (expr == error_mark_node)
    5546              :     return error_mark_node;
    5547              : 
    5548         2420 :   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
    5549              :     {
    5550            6 :       error ("cannot apply %<offsetof%> to destructor %<~%T%>",
    5551            6 :               TREE_OPERAND (expr, 2));
    5552            6 :       return error_mark_node;
    5553              :     }
    5554         4813 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
    5555         4813 :       || TREE_TYPE (expr) == unknown_type_node)
    5556              :     {
    5557           30 :       while (TREE_CODE (expr) == COMPONENT_REF
    5558           30 :              || TREE_CODE (expr) == COMPOUND_EXPR)
    5559           12 :         expr = TREE_OPERAND (expr, 1);
    5560              : 
    5561           18 :       if (DECL_P (expr))
    5562              :         {
    5563            0 :           auto_diagnostic_group d;
    5564            0 :           error ("cannot apply %<offsetof%> to member function %qD", expr);
    5565            0 :           inform (DECL_SOURCE_LOCATION (expr), "declared here");
    5566            0 :         }
    5567              :       else
    5568           18 :         error ("cannot apply %<offsetof%> to member function");
    5569           18 :       return error_mark_node;
    5570              :     }
    5571         2396 :   if (TREE_CODE (expr) == CONST_DECL)
    5572              :     {
    5573            3 :       error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
    5574            3 :       return error_mark_node;
    5575              :     }
    5576         2393 :   if (REFERENCE_REF_P (expr))
    5577            9 :     expr = TREE_OPERAND (expr, 0);
    5578         2393 :   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
    5579            3 :     return error_mark_node;
    5580         2390 :   if (warn_invalid_offsetof
    5581         2390 :       && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
    5582         2390 :       && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
    5583         2435 :       && cp_unevaluated_operand == 0)
    5584           45 :     warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
    5585              :                 "non-standard-layout type %qT is conditionally-supported",
    5586           45 :                 TREE_TYPE (TREE_TYPE (object_ptr)));
    5587         2390 :   return fold_offsetof (expr);
    5588              : }
    5589              : 
    5590              : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR.  This
    5591              :    function is broken out from the above for the benefit of the tree-ssa
    5592              :    project.  */
    5593              : 
    5594              : void
    5595       367996 : simplify_aggr_init_expr (tree *tp)
    5596              : {
    5597       367996 :   tree aggr_init_expr = *tp;
    5598              : 
    5599              :   /* Form an appropriate CALL_EXPR.  */
    5600       367996 :   tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
    5601       367996 :   tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
    5602       367996 :   tree type = TREE_TYPE (slot);
    5603              : 
    5604       367996 :   tree call_expr;
    5605       367996 :   enum style_t { ctor, arg, pcc } style;
    5606              : 
    5607       367996 :   if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
    5608              :     style = ctor;
    5609              : #ifdef PCC_STATIC_STRUCT_RETURN
    5610              :   else if (1)
    5611              :     style = pcc;
    5612              : #endif
    5613              :   else
    5614              :     {
    5615       100103 :       gcc_assert (TREE_ADDRESSABLE (type));
    5616              :       style = arg;
    5617              :     }
    5618              : 
    5619       367996 :   call_expr = build_call_array_loc (input_location,
    5620       367996 :                                     TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
    5621              :                                     fn,
    5622       367996 :                                     aggr_init_expr_nargs (aggr_init_expr),
    5623       367996 :                                     AGGR_INIT_EXPR_ARGP (aggr_init_expr));
    5624       367996 :   TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
    5625       367996 :   CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
    5626       367996 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr)
    5627       367996 :     = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
    5628       367996 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
    5629       367996 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
    5630       367996 :   CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
    5631              : 
    5632       367996 :   if (style == ctor)
    5633              :     {
    5634              :       /* Replace the first argument to the ctor with the address of the
    5635              :          slot.  */
    5636       267893 :       cxx_mark_addressable (slot);
    5637       267893 :       CALL_EXPR_ARG (call_expr, 0) =
    5638       267893 :         build1 (ADDR_EXPR, build_pointer_type (type), slot);
    5639              :     }
    5640       100103 :   else if (style == arg)
    5641              :     {
    5642              :       /* Just mark it addressable here, and leave the rest to
    5643              :          expand_call{,_inline}.  */
    5644       100103 :       cxx_mark_addressable (slot);
    5645       100103 :       CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
    5646       100103 :       call_expr = cp_build_init_expr (slot, call_expr);
    5647              :     }
    5648              :   else if (style == pcc)
    5649              :     {
    5650              :       /* If we're using the non-reentrant PCC calling convention, then we
    5651              :          need to copy the returned value out of the static buffer into the
    5652              :          SLOT.  */
    5653              :       push_deferring_access_checks (dk_no_check);
    5654              :       call_expr = build_aggr_init (slot, call_expr,
    5655              :                                    DIRECT_BIND | LOOKUP_ONLYCONVERTING,
    5656              :                                    tf_warning_or_error);
    5657              :       pop_deferring_access_checks ();
    5658              :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
    5659              :     }
    5660              : 
    5661       367996 :   if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
    5662              :     {
    5663         4138 :       tree init = build_zero_init (type, NULL_TREE,
    5664              :                                    /*static_storage_p=*/false);
    5665         4138 :       init = cp_build_init_expr (slot, init);
    5666         4138 :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
    5667              :                           init, call_expr);
    5668              :     }
    5669              : 
    5670       367996 :   *tp = call_expr;
    5671       367996 : }
    5672              : 
    5673              : /* Emit all thunks to FN that should be emitted when FN is emitted.  */
    5674              : 
    5675              : void
    5676     60892979 : emit_associated_thunks (tree fn)
    5677              : {
    5678              :   /* When we use vcall offsets, we emit thunks with the virtual
    5679              :      functions to which they thunk. The whole point of vcall offsets
    5680              :      is so that you can know statically the entire set of thunks that
    5681              :      will ever be needed for a given virtual function, thereby
    5682              :      enabling you to output all the thunks with the function itself.  */
    5683     60892979 :   if (DECL_VIRTUAL_P (fn)
    5684              :       /* Do not emit thunks for extern template instantiations.  */
    5685      1158390 :       && ! DECL_REALLY_EXTERN (fn)
    5686              :       /* Do not emit thunks for tentative decls, those will be processed
    5687              :          again at_eof if really needed.  */
    5688     61933350 :       && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
    5689              :     {
    5690      1039200 :       tree thunk;
    5691              : 
    5692      1043670 :       for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
    5693              :         {
    5694         4470 :           if (!THUNK_ALIAS (thunk))
    5695              :             {
    5696         4470 :               use_thunk (thunk, /*emit_p=*/1);
    5697         4470 :               if (DECL_RESULT_THUNK_P (thunk))
    5698              :                 {
    5699          181 :                   tree probe;
    5700              : 
    5701          181 :                   for (probe = DECL_THUNKS (thunk);
    5702          333 :                        probe; probe = DECL_CHAIN (probe))
    5703          152 :                     use_thunk (probe, /*emit_p=*/1);
    5704              :                 }
    5705              :             }
    5706              :           else
    5707            0 :             gcc_assert (!DECL_THUNKS (thunk));
    5708              :         }
    5709              :     }
    5710     60892979 : }
    5711              : 
    5712              : /* Generate RTL for FN.  */
    5713              : 
    5714              : bool
    5715    165648512 : expand_or_defer_fn_1 (tree fn)
    5716              : {
    5717              :   /* When the parser calls us after finishing the body of a template
    5718              :      function, we don't really want to expand the body.  */
    5719    165648512 :   if (processing_template_decl)
    5720              :     {
    5721              :       /* Normally, collection only occurs in rest_of_compilation.  So,
    5722              :          if we don't collect here, we never collect junk generated
    5723              :          during the processing of templates until we hit a
    5724              :          non-template function.  It's not safe to do this inside a
    5725              :          nested class, though, as the parser may have local state that
    5726              :          is not a GC root.  */
    5727     96627408 :       if (!function_depth)
    5728     96181562 :         ggc_collect ();
    5729              :       return false;
    5730              :     }
    5731              : 
    5732     69021104 :   gcc_assert (DECL_SAVED_TREE (fn));
    5733              : 
    5734              :   /* We make a decision about linkage for these functions at the end
    5735              :      of the compilation.  Until that point, we do not want the back
    5736              :      end to output them -- but we do want it to see the bodies of
    5737              :      these functions so that it can inline them as appropriate.  */
    5738     69021104 :   if (DECL_DECLARED_INLINE_P (fn)
    5739      1944051 :       || DECL_IMPLICIT_INSTANTIATION (fn)
    5740     69284688 :       || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
    5741              :     {
    5742     68757547 :       if (DECL_INTERFACE_KNOWN (fn))
    5743              :         /* We've already made a decision as to how this function will
    5744              :            be handled.  */;
    5745     48673312 :       else if (!at_eof
    5746     17666735 :                || DECL_IMMEDIATE_FUNCTION_P (fn)
    5747     65907244 :                || DECL_OMP_DECLARE_REDUCTION_P (fn))
    5748     31439380 :         tentative_decl_linkage (fn);
    5749              :       else
    5750     17233932 :         import_export_decl (fn);
    5751              : 
    5752              :       /* If the user wants us to keep all inline functions, then mark
    5753              :          this function as needed so that finish_file will make sure to
    5754              :          output it later.  Similarly, all dllexport'd functions must
    5755              :          be emitted; there may be callers in other DLLs.  */
    5756     68757547 :       if (DECL_DECLARED_INLINE_P (fn)
    5757     67077053 :           && !DECL_REALLY_EXTERN (fn)
    5758     63380418 :           && !DECL_IMMEDIATE_FUNCTION_P (fn)
    5759     62335066 :           && !DECL_OMP_DECLARE_REDUCTION_P (fn)
    5760    131092613 :           && (flag_keep_inline_functions
    5761     62332273 :               || (flag_keep_inline_dllexport
    5762     62332273 :                   && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
    5763              :         {
    5764         2793 :           mark_needed (fn);
    5765         2793 :           DECL_EXTERNAL (fn) = 0;
    5766              :         }
    5767              :     }
    5768              : 
    5769              :   /* If this is a constructor or destructor body, we have to clone
    5770              :      it.  */
    5771     69021104 :   if (maybe_clone_body (fn))
    5772              :     {
    5773              :       /* We don't want to process FN again, so pretend we've written
    5774              :          it out, even though we haven't.  */
    5775      8099906 :       TREE_ASM_WRITTEN (fn) = 1;
    5776              :       /* If this is a constexpr function we still need the body to be
    5777              :          able to evaluate it.  Similarly, with modules we only stream
    5778              :          the maybe-in-charge cdtor and regenerate the clones from it on
    5779              :          demand, so we also need to keep the body.  Otherwise we don't
    5780              :          need it anymore.  */
    5781      8099906 :       if (!maybe_constexpr_fn (fn)
    5782      8099906 :           && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
    5783      3778274 :         DECL_SAVED_TREE (fn) = void_node;
    5784              :       return false;
    5785              :     }
    5786              : 
    5787              :   /* There's no reason to do any of the work here if we're only doing
    5788              :      semantic analysis; this code just generates RTL.  */
    5789     60921198 :   if (flag_syntax_only)
    5790              :     {
    5791              :       /* Pretend that this function has been written out so that we don't try
    5792              :          to expand it again.  */
    5793        28203 :       TREE_ASM_WRITTEN (fn) = 1;
    5794        28203 :       return false;
    5795              :     }
    5796              : 
    5797     60892995 :   if (DECL_OMP_DECLARE_REDUCTION_P (fn))
    5798           16 :     return false;
    5799              : 
    5800              :   return true;
    5801              : }
    5802              : 
    5803              : void
    5804    157566129 : expand_or_defer_fn (tree fn)
    5805              : {
    5806    157566129 :   if (expand_or_defer_fn_1 (fn))
    5807              :     {
    5808     52813087 :       function_depth++;
    5809              : 
    5810              :       /* Expand or defer, at the whim of the compilation unit manager.  */
    5811     52813087 :       cgraph_node::finalize_function (fn, function_depth > 1);
    5812     52813087 :       emit_associated_thunks (fn);
    5813              : 
    5814     52813087 :       function_depth--;
    5815              : 
    5816    105626174 :       if (DECL_IMMEDIATE_FUNCTION_P (fn))
    5817              :         {
    5818      1001654 :           if (cgraph_node *node = cgraph_node::get (fn))
    5819              :             {
    5820      1001654 :               node->body_removed = true;
    5821      1001654 :               node->analyzed = false;
    5822      1001654 :               node->definition = false;
    5823      1001654 :               node->force_output = false;
    5824              :             }
    5825              :         }
    5826              :     }
    5827    157566129 : }
    5828              : 
    5829       459108 : class nrv_data
    5830              : {
    5831              : public:
    5832       229554 :   nrv_data () : visited (37) {}
    5833              : 
    5834              :   tree var;
    5835              :   tree result;
    5836              :   hash_set<tree> visited;
    5837              :   bool simple;
    5838              :   bool in_nrv_cleanup;
    5839              : };
    5840              : 
    5841              : /* Helper function for walk_tree, used by finalize_nrv below.  */
    5842              : 
    5843              : static tree
    5844     20900513 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
    5845              : {
    5846     20900513 :   class nrv_data *dp = (class nrv_data *)data;
    5847              : 
    5848              :   /* No need to walk into types.  There wouldn't be any need to walk into
    5849              :      non-statements, except that we have to consider STMT_EXPRs.  */
    5850     20900513 :   if (TYPE_P (*tp))
    5851       190093 :     *walk_subtrees = 0;
    5852              : 
    5853              :   /* Replace all uses of the NRV with the RESULT_DECL.  */
    5854     20710420 :   else if (*tp == dp->var)
    5855       499317 :     *tp = dp->result;
    5856              : 
    5857              :   /* Avoid walking into the same tree more than once.  Unfortunately, we
    5858              :      can't just use walk_tree_without duplicates because it would only call
    5859              :      us for the first occurrence of dp->var in the function body.  */
    5860     20211103 :   else if (dp->visited.add (*tp))
    5861      4437790 :     *walk_subtrees = 0;
    5862              : 
    5863              :   /* If there's a label, we might need to destroy the NRV on goto (92407).  */
    5864     15773313 :   else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
    5865            3 :     dp->simple = false;
    5866              :   /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
    5867              :      but differs from using NULL_TREE in that it indicates that we care
    5868              :      about the value of the RESULT_DECL.  But preserve anything appended
    5869              :      by check_return_expr.  */
    5870     15773310 :   else if (TREE_CODE (*tp) == RETURN_EXPR)
    5871              :     {
    5872       235764 :       tree *p = &TREE_OPERAND (*tp, 0);
    5873       604414 :       while (TREE_CODE (*p) == COMPOUND_EXPR)
    5874       132886 :         p = &TREE_OPERAND (*p, 0);
    5875       235764 :       if (TREE_CODE (*p) == INIT_EXPR
    5876       235764 :           && INIT_EXPR_NRV_P (*p))
    5877       235354 :         *p = dp->result;
    5878              :     }
    5879              :   /* Change all cleanups for the NRV to only run when not returning.  */
    5880     15537546 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5881     15537546 :            && CLEANUP_DECL (*tp) == dp->var)
    5882              :     {
    5883       127680 :       dp->in_nrv_cleanup = true;
    5884       127680 :       cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
    5885       127680 :       dp->in_nrv_cleanup = false;
    5886       127680 :       cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
    5887       127680 :       *walk_subtrees = 0;
    5888              : 
    5889       127680 :       if (dp->simple)
    5890              :         /* For a simple NRV, just run it on the EH path.  */
    5891       127019 :         CLEANUP_EH_ONLY (*tp) = true;
    5892              :       else
    5893              :         {
    5894              :           /* Not simple, we need to check current_retval_sentinel to decide
    5895              :              whether to run it.  If it's set, we're returning normally and
    5896              :              don't want to destroy the NRV.  If the sentinel is not set, we're
    5897              :              leaving scope some other way, either by flowing off the end of its
    5898              :              scope or throwing an exception.  */
    5899         1983 :           tree cond = build3 (COND_EXPR, void_type_node,
    5900          661 :                               current_retval_sentinel,
    5901          661 :                               void_node, CLEANUP_EXPR (*tp));
    5902          661 :           CLEANUP_EXPR (*tp) = cond;
    5903              :         }
    5904              : 
    5905              :       /* If a cleanup might throw, we need to clear current_retval_sentinel on
    5906              :          the exception path, both so the check above succeeds and so an outer
    5907              :          cleanup added by maybe_splice_retval_cleanup doesn't run.  */
    5908       127680 :       if (cp_function_chain->throwing_cleanup)
    5909              :         {
    5910          160 :           tree clear = build2 (MODIFY_EXPR, boolean_type_node,
    5911              :                                current_retval_sentinel,
    5912              :                                boolean_false_node);
    5913          160 :           if (dp->simple)
    5914              :             {
    5915              :               /* We're already only on the EH path, just prepend it.  */
    5916          150 :               tree &exp = CLEANUP_EXPR (*tp);
    5917          150 :               exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
    5918              :             }
    5919              :           else
    5920              :             {
    5921              :               /* The cleanup runs on both normal and EH paths, we need another
    5922              :                  CLEANUP_STMT to clear the flag only on the EH path.  */
    5923           10 :               tree &bod = CLEANUP_BODY (*tp);
    5924           10 :               bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
    5925           10 :                                 bod, clear, current_retval_sentinel);
    5926           10 :               CLEANUP_EH_ONLY (bod) = true;
    5927              :             }
    5928              :         }
    5929              :     }
    5930              :   /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
    5931              :      want to destroy the retval before the variable goes out of scope.  */
    5932     15409866 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5933         4854 :            && dp->in_nrv_cleanup
    5934     15413335 :            && CLEANUP_DECL (*tp) == dp->result)
    5935            6 :     CLEANUP_EXPR (*tp) = void_node;
    5936              :   /* Replace the DECL_EXPR for the NRV with an initialization of the
    5937              :      RESULT_DECL, if needed.  */
    5938     15409860 :   else if (TREE_CODE (*tp) == DECL_EXPR
    5939     15409860 :            && DECL_EXPR_DECL (*tp) == dp->var)
    5940              :     {
    5941       229556 :       tree init;
    5942       229556 :       if (DECL_INITIAL (dp->var)
    5943       229556 :           && DECL_INITIAL (dp->var) != error_mark_node)
    5944        94024 :         init = cp_build_init_expr (dp->result,
    5945        94024 :                        DECL_INITIAL (dp->var));
    5946              :       else
    5947       135532 :         init = build_empty_stmt (EXPR_LOCATION (*tp));
    5948       229556 :       DECL_INITIAL (dp->var) = NULL_TREE;
    5949       229556 :       SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
    5950       229556 :       *tp = init;
    5951              :     }
    5952              : 
    5953              :   /* Keep iterating.  */
    5954     20900513 :   return NULL_TREE;
    5955              : }
    5956              : 
    5957              : /* Called from finish_function to implement the named return value
    5958              :    optimization by overriding all the RETURN_EXPRs and pertinent
    5959              :    CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
    5960              :    RESULT_DECL for the function.  */
    5961              : 
    5962              : void
    5963       229554 : finalize_nrv (tree fndecl, tree var)
    5964              : {
    5965       229554 :   class nrv_data data;
    5966       229554 :   tree result = DECL_RESULT (fndecl);
    5967              : 
    5968              :   /* Copy name from VAR to RESULT.  */
    5969       229554 :   DECL_NAME (result) = DECL_NAME (var);
    5970              :   /* Don't forget that we take its address.  */
    5971       229554 :   TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
    5972              :   /* Finally set DECL_VALUE_EXPR to avoid assigning
    5973              :      a stack slot at -O0 for the original var and debug info
    5974              :      uses RESULT location for VAR.  */
    5975       229554 :   SET_DECL_VALUE_EXPR (var, result);
    5976       229554 :   DECL_HAS_VALUE_EXPR_P (var) = 1;
    5977              : 
    5978       229554 :   data.var = var;
    5979       229554 :   data.result = result;
    5980       229554 :   data.in_nrv_cleanup = false;
    5981              : 
    5982              :   /* This is simpler for variables declared in the outer scope of
    5983              :      the function so we know that their lifetime always ends with a
    5984              :      return; see g++.dg/opt/nrv6.C.  */
    5985       229554 :   tree outer = outer_curly_brace_block (fndecl);
    5986       229554 :   data.simple = chain_member (var, BLOCK_VARS (outer));
    5987              : 
    5988       229554 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
    5989       229554 : }
    5990              : 
    5991              : /* Create CP_OMP_CLAUSE_INFO for clause C.  Returns true if it is invalid.  */
    5992              : 
    5993              : bool
    5994         2283 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
    5995              :                             bool need_copy_ctor, bool need_copy_assignment,
    5996              :                             bool need_dtor)
    5997              : {
    5998         2283 :   int save_errorcount = errorcount;
    5999         2283 :   tree info, t;
    6000              : 
    6001              :   /* Always allocate 3 elements for simplicity.  These are the
    6002              :      function decls for the ctor, dtor, and assignment op.
    6003              :      This layout is known to the three lang hooks,
    6004              :      cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
    6005              :      and cxx_omp_clause_assign_op.  */
    6006         2283 :   info = make_tree_vec (3);
    6007         2283 :   CP_OMP_CLAUSE_INFO (c) = info;
    6008              : 
    6009         2283 :   if (need_default_ctor || need_copy_ctor)
    6010              :     {
    6011         1672 :       if (need_default_ctor)
    6012         1271 :         t = get_default_ctor (type);
    6013              :       else
    6014          401 :         t = get_copy_ctor (type, tf_warning_or_error);
    6015              : 
    6016         1672 :       if (t && !trivial_fn_p (t))
    6017         1416 :         TREE_VEC_ELT (info, 0) = t;
    6018              :     }
    6019              : 
    6020         2283 :   if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6021         1664 :     TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
    6022              : 
    6023         2283 :   if (need_copy_assignment)
    6024              :     {
    6025          397 :       t = get_copy_assign (type);
    6026              : 
    6027          397 :       if (t && !trivial_fn_p (t))
    6028          344 :         TREE_VEC_ELT (info, 2) = t;
    6029              :     }
    6030              : 
    6031         2283 :   return errorcount != save_errorcount;
    6032              : }
    6033              : 
    6034              : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
    6035              :    FIELD_DECL, otherwise return DECL itself.  */
    6036              : 
    6037              : static tree
    6038        27487 : omp_clause_decl_field (tree decl)
    6039              : {
    6040        27487 :   if (VAR_P (decl)
    6041        19173 :       && DECL_HAS_VALUE_EXPR_P (decl)
    6042          359 :       && DECL_ARTIFICIAL (decl)
    6043          359 :       && DECL_LANG_SPECIFIC (decl)
    6044        27822 :       && DECL_OMP_PRIVATIZED_MEMBER (decl))
    6045              :     {
    6046          328 :       tree f = DECL_VALUE_EXPR (decl);
    6047          328 :       if (INDIRECT_REF_P (f))
    6048            0 :         f = TREE_OPERAND (f, 0);
    6049          328 :       if (TREE_CODE (f) == COMPONENT_REF)
    6050              :         {
    6051          328 :           f = TREE_OPERAND (f, 1);
    6052          328 :           gcc_assert (TREE_CODE (f) == FIELD_DECL);
    6053              :           return f;
    6054              :         }
    6055              :     }
    6056              :   return NULL_TREE;
    6057              : }
    6058              : 
    6059              : /* Adjust DECL if needed for printing using %qE.  */
    6060              : 
    6061              : static tree
    6062          187 : omp_clause_printable_decl (tree decl)
    6063              : {
    6064            0 :   tree t = omp_clause_decl_field (decl);
    6065          187 :   if (t)
    6066           45 :     return t;
    6067              :   return decl;
    6068              : }
    6069              : 
    6070              : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
    6071              :    VAR_DECL T that doesn't need a DECL_EXPR added, record it for
    6072              :    privatization.  */
    6073              : 
    6074              : static void
    6075          219 : omp_note_field_privatization (tree f, tree t)
    6076              : {
    6077          219 :   if (!omp_private_member_map)
    6078           71 :     omp_private_member_map = new hash_map<tree, tree>;
    6079          219 :   tree &v = omp_private_member_map->get_or_insert (f);
    6080          219 :   if (v == NULL_TREE)
    6081              :     {
    6082          146 :       v = t;
    6083          146 :       omp_private_member_vec.safe_push (f);
    6084              :       /* Signal that we don't want to create DECL_EXPR for this dummy var.  */
    6085          146 :       omp_private_member_vec.safe_push (integer_zero_node);
    6086              :     }
    6087          219 : }
    6088              : 
    6089              : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
    6090              :    dummy VAR_DECL.  */
    6091              : 
    6092              : tree
    6093          861 : omp_privatize_field (tree t, bool shared)
    6094              : {
    6095          861 :   tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6096          861 :   if (m == error_mark_node)
    6097              :     return error_mark_node;
    6098          861 :   if (!omp_private_member_map && !shared)
    6099          365 :     omp_private_member_map = new hash_map<tree, tree>;
    6100          861 :   if (TYPE_REF_P (TREE_TYPE (t)))
    6101              :     {
    6102          123 :       gcc_assert (INDIRECT_REF_P (m));
    6103          123 :       m = TREE_OPERAND (m, 0);
    6104              :     }
    6105          861 :   tree vb = NULL_TREE;
    6106          861 :   tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
    6107          861 :   if (v == NULL_TREE)
    6108              :     {
    6109          770 :       v = create_temporary_var (TREE_TYPE (m));
    6110          770 :       retrofit_lang_decl (v);
    6111          770 :       DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
    6112          770 :       SET_DECL_VALUE_EXPR (v, m);
    6113          770 :       DECL_HAS_VALUE_EXPR_P (v) = 1;
    6114          770 :       if (!shared)
    6115          690 :         omp_private_member_vec.safe_push (t);
    6116              :     }
    6117          861 :   return v;
    6118              : }
    6119              : 
    6120              : /* C++ specialisation of the c_omp_address_inspector class.  */
    6121              : 
    6122              : class cp_omp_address_inspector : public c_omp_address_inspector
    6123              : {
    6124              : public:
    6125        32816 :   cp_omp_address_inspector (location_t loc, tree t)
    6126        32816 :     : c_omp_address_inspector (loc, t)
    6127              :     {
    6128              :     }
    6129              : 
    6130        32816 :   ~cp_omp_address_inspector ()
    6131              :     {
    6132        24317 :     }
    6133              : 
    6134       139733 :   bool processing_template_decl_p ()
    6135              :     {
    6136       139733 :       return processing_template_decl;
    6137              :     }
    6138              : 
    6139            0 :   void emit_unmappable_type_notes (tree t)
    6140              :     {
    6141            0 :       if (TREE_TYPE (t) != error_mark_node
    6142            0 :           && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    6143            0 :         cxx_incomplete_type_inform (TREE_TYPE (t));
    6144            0 :     }
    6145              : 
    6146         1062 :   tree convert_from_reference (tree x)
    6147              :     {
    6148         1062 :       return ::convert_from_reference (x);
    6149              :     }
    6150              : 
    6151          147 :   tree build_array_ref (location_t loc, tree arr, tree idx)
    6152              :     {
    6153          147 :       return ::build_array_ref (loc, arr, idx);
    6154              :     }
    6155              : 
    6156        24259 :   bool check_clause (tree clause)
    6157              :     {
    6158        24259 :       if (TREE_CODE (orig) == COMPONENT_REF
    6159        24259 :           && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
    6160              :                                         tf_warning_or_error))
    6161              :         return false;
    6162        24256 :       if (!c_omp_address_inspector::check_clause (clause))
    6163              :         return false;
    6164              :       return true;
    6165              :     }
    6166              : };
    6167              : 
    6168              : /* Helper function for handle_omp_array_sections.  Called recursively
    6169              :    to handle multiple array-section-subscripts.  C is the clause,
    6170              :    T current expression (initially OMP_CLAUSE_DECL), which is either
    6171              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
    6172              :    expression if specified, TREE_VALUE length expression if specified,
    6173              :    TREE_CHAIN is what it has been specified after, or some decl.
    6174              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
    6175              :    set to true if any of the array-section-subscript could have length
    6176              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
    6177              :    first array-section-subscript which is known not to have length
    6178              :    of one.  Given say:
    6179              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
    6180              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
    6181              :    all are or may have length of 1, array-section-subscript [:2] is the
    6182              :    first one known not to have length 1.  For array-section-subscript
    6183              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
    6184              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
    6185              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
    6186              :    case though, as some lengths could be zero.  */
    6187              : 
    6188              : static tree
    6189        21578 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
    6190              :                              bool &maybe_zero_len, unsigned int &first_non_one,
    6191              :                              enum c_omp_region_type ort)
    6192              : {
    6193        21578 :   tree ret, low_bound, length, type;
    6194        21578 :   bool openacc = (ort & C_ORT_ACC) != 0;
    6195        21578 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
    6196              :     {
    6197         9750 :       if (error_operand_p (t))
    6198            6 :         return error_mark_node;
    6199              : 
    6200         9744 :       cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6201         9744 :       tree t_refto = ai.maybe_unconvert_ref (t);
    6202              : 
    6203         9744 :       if (!ai.check_clause (c))
    6204            0 :         return error_mark_node;
    6205         9744 :       else if (ai.component_access_p ()
    6206        11132 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6207           64 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
    6208           40 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
    6209         1388 :         t = ai.get_root_term (true);
    6210              :       else
    6211         8356 :         t = ai.unconverted_ref_origin ();
    6212         9744 :       if (t == error_mark_node)
    6213              :         return error_mark_node;
    6214         9744 :       ret = t_refto;
    6215         9744 :       if (TREE_CODE (t) == FIELD_DECL)
    6216           33 :         ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6217         9711 :       else if (!VAR_P (t)
    6218         2895 :                && (openacc || !EXPR_P (t))
    6219         2700 :                && TREE_CODE (t) != PARM_DECL)
    6220              :         {
    6221           51 :           if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    6222              :             return NULL_TREE;
    6223           33 :           if (DECL_P (t))
    6224           33 :             error_at (OMP_CLAUSE_LOCATION (c),
    6225              :                       "%qD is not a variable in %qs clause", t,
    6226           33 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6227              :           else
    6228            0 :             error_at (OMP_CLAUSE_LOCATION (c),
    6229              :                       "%qE is not a variable in %qs clause", t,
    6230            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6231           33 :           return error_mark_node;
    6232              :         }
    6233         9660 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6234         9269 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6235        18000 :                && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    6236              :         {
    6237           18 :           error_at (OMP_CLAUSE_LOCATION (c),
    6238              :                     "%qD is threadprivate variable in %qs clause", t,
    6239           18 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6240           18 :           return error_mark_node;
    6241              :         }
    6242         9675 :       if (type_dependent_expression_p (ret))
    6243              :         return NULL_TREE;
    6244         8964 :       ret = convert_from_reference (ret);
    6245         8964 :       return ret;
    6246         9744 :     }
    6247              : 
    6248        11828 :   if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
    6249         7901 :       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6250         6593 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6251         5309 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6252        14548 :       && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
    6253           43 :     TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
    6254        11828 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
    6255              :                                      maybe_zero_len, first_non_one, ort);
    6256        11828 :   if (ret == error_mark_node || ret == NULL_TREE)
    6257              :     return ret;
    6258              : 
    6259        10758 :   type = TREE_TYPE (ret);
    6260        10758 :   low_bound = TREE_OPERAND (t, 1);
    6261        10758 :   length = TREE_OPERAND (t, 2);
    6262         8607 :   if ((low_bound && type_dependent_expression_p (low_bound))
    6263        19282 :       || (length && type_dependent_expression_p (length)))
    6264              :     return NULL_TREE;
    6265              : 
    6266        10670 :   if (low_bound == error_mark_node || length == error_mark_node)
    6267              :     return error_mark_node;
    6268              : 
    6269        10658 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
    6270              :     {
    6271           75 :       error_at (OMP_CLAUSE_LOCATION (c),
    6272              :                 "low bound %qE of array section does not have integral type",
    6273              :                 low_bound);
    6274           75 :       return error_mark_node;
    6275              :     }
    6276        10583 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
    6277              :     {
    6278           75 :       error_at (OMP_CLAUSE_LOCATION (c),
    6279              :                 "length %qE of array section does not have integral type",
    6280              :                 length);
    6281           75 :       return error_mark_node;
    6282              :     }
    6283        10508 :   if (low_bound)
    6284         8423 :     low_bound = mark_rvalue_use (low_bound);
    6285        10508 :   if (length)
    6286         9445 :     length = mark_rvalue_use (length);
    6287              :   /* We need to reduce to real constant-values for checks below.  */
    6288         9445 :   if (length)
    6289         9445 :     length = fold_simple (length);
    6290        10508 :   if (low_bound)
    6291         8423 :     low_bound = fold_simple (low_bound);
    6292         8423 :   if (low_bound
    6293         8423 :       && TREE_CODE (low_bound) == INTEGER_CST
    6294        15909 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
    6295         7486 :          > TYPE_PRECISION (sizetype))
    6296            0 :     low_bound = fold_convert (sizetype, low_bound);
    6297        10508 :   if (length
    6298         9445 :       && TREE_CODE (length) == INTEGER_CST
    6299        17930 :       && TYPE_PRECISION (TREE_TYPE (length))
    6300         7422 :          > TYPE_PRECISION (sizetype))
    6301            0 :     length = fold_convert (sizetype, length);
    6302        10508 :   if (low_bound == NULL_TREE)
    6303         2085 :     low_bound = integer_zero_node;
    6304              : 
    6305        10508 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6306        10508 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    6307         5194 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
    6308              :     {
    6309           60 :       if (length != integer_one_node)
    6310              :         {
    6311           36 :           error_at (OMP_CLAUSE_LOCATION (c),
    6312              :                     "expected single pointer in %qs clause",
    6313              :                     user_omp_clause_code_name (c, openacc));
    6314           36 :           return error_mark_node;
    6315              :         }
    6316              :     }
    6317        10472 :   if (length != NULL_TREE)
    6318              :     {
    6319         9433 :       if (!integer_nonzerop (length))
    6320              :         {
    6321         2078 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6322              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6323              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6324              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6325              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6326              :             {
    6327          479 :               if (integer_zerop (length))
    6328              :                 {
    6329           36 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6330              :                             "zero length array section in %qs clause",
    6331           36 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6332           36 :                   return error_mark_node;
    6333              :                 }
    6334              :             }
    6335              :           else
    6336         1599 :             maybe_zero_len = true;
    6337              :         }
    6338         9397 :       if (first_non_one == types.length ()
    6339         9397 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
    6340         4020 :         first_non_one++;
    6341              :     }
    6342        10436 :   if (TREE_CODE (type) == ARRAY_TYPE)
    6343              :     {
    6344         5804 :       if (length == NULL_TREE
    6345         5804 :           && (TYPE_DOMAIN (type) == NULL_TREE
    6346          955 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
    6347              :         {
    6348           33 :           error_at (OMP_CLAUSE_LOCATION (c),
    6349              :                     "for unknown bound array type length expression must "
    6350              :                     "be specified");
    6351           33 :           return error_mark_node;
    6352              :         }
    6353         5771 :       if (TREE_CODE (low_bound) == INTEGER_CST
    6354         5771 :           && tree_int_cst_sgn (low_bound) == -1)
    6355              :         {
    6356          177 :           error_at (OMP_CLAUSE_LOCATION (c),
    6357              :                     "negative low bound in array section in %qs clause",
    6358          177 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6359          177 :           return error_mark_node;
    6360              :         }
    6361         5594 :       if (length != NULL_TREE
    6362         4696 :           && TREE_CODE (length) == INTEGER_CST
    6363         9364 :           && tree_int_cst_sgn (length) == -1)
    6364              :         {
    6365          177 :           error_at (OMP_CLAUSE_LOCATION (c),
    6366              :                     "negative length in array section in %qs clause",
    6367          177 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6368          177 :           return error_mark_node;
    6369              :         }
    6370         5417 :       if (TYPE_DOMAIN (type)
    6371         5318 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    6372        10735 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
    6373              :                         == INTEGER_CST)
    6374              :         {
    6375         4922 :           tree size
    6376         4922 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
    6377         4922 :           size = size_binop (PLUS_EXPR, size, size_one_node);
    6378         4922 :           if (TREE_CODE (low_bound) == INTEGER_CST)
    6379              :             {
    6380         4145 :               if (tree_int_cst_lt (size, low_bound))
    6381              :                 {
    6382           63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6383              :                             "low bound %qE above array section size "
    6384              :                             "in %qs clause", low_bound,
    6385           63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6386           63 :                   return error_mark_node;
    6387              :                 }
    6388         4082 :               if (tree_int_cst_equal (size, low_bound))
    6389              :                 {
    6390           21 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6391              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6392              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6393              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6394              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6395              :                     {
    6396           21 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6397              :                                 "zero length array section in %qs clause",
    6398           21 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6399           21 :                       return error_mark_node;
    6400              :                     }
    6401            0 :                   maybe_zero_len = true;
    6402              :                 }
    6403         4061 :               else if (length == NULL_TREE
    6404         1578 :                        && first_non_one == types.length ()
    6405         4414 :                        && tree_int_cst_equal
    6406          353 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
    6407              :                              low_bound))
    6408          207 :                 first_non_one++;
    6409              :             }
    6410          777 :           else if (length == NULL_TREE)
    6411              :             {
    6412           24 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6413              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6414              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6415              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6416              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6417           13 :                 maybe_zero_len = true;
    6418           48 :               if (first_non_one == types.length ())
    6419           21 :                 first_non_one++;
    6420              :             }
    6421         4838 :           if (length && TREE_CODE (length) == INTEGER_CST)
    6422              :             {
    6423         3473 :               if (tree_int_cst_lt (size, length))
    6424              :                 {
    6425           63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6426              :                             "length %qE above array section size "
    6427              :                             "in %qs clause", length,
    6428           63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6429           63 :                   return error_mark_node;
    6430              :                 }
    6431         3410 :               if (TREE_CODE (low_bound) == INTEGER_CST)
    6432              :                 {
    6433         3072 :                   tree lbpluslen
    6434         3072 :                     = size_binop (PLUS_EXPR,
    6435              :                                   fold_convert (sizetype, low_bound),
    6436              :                                   fold_convert (sizetype, length));
    6437         3072 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
    6438         3072 :                       && tree_int_cst_lt (size, lbpluslen))
    6439              :                     {
    6440           60 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6441              :                                 "high bound %qE above array section size "
    6442              :                                 "in %qs clause", lbpluslen,
    6443           60 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6444           60 :                       return error_mark_node;
    6445              :                     }
    6446              :                 }
    6447              :             }
    6448              :         }
    6449          495 :       else if (length == NULL_TREE)
    6450              :         {
    6451            1 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6452              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6453              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6454              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6455              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6456            0 :             maybe_zero_len = true;
    6457            2 :           if (first_non_one == types.length ())
    6458            1 :             first_non_one++;
    6459              :         }
    6460              : 
    6461              :       /* For [lb:] we will need to evaluate lb more than once.  */
    6462         4165 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6463              :         {
    6464          733 :           tree lb = cp_save_expr (low_bound);
    6465          733 :           if (lb != low_bound)
    6466              :             {
    6467           13 :               TREE_OPERAND (t, 1) = lb;
    6468           13 :               low_bound = lb;
    6469              :             }
    6470              :         }
    6471              :     }
    6472         4632 :   else if (TYPE_PTR_P (type))
    6473              :     {
    6474         4572 :       if (length == NULL_TREE)
    6475              :         {
    6476           51 :           if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
    6477           45 :             error_at (OMP_CLAUSE_LOCATION (c),
    6478              :                       "for array function parameter length expression "
    6479              :                       "must be specified");
    6480              :           else
    6481            6 :             error_at (OMP_CLAUSE_LOCATION (c),
    6482              :                       "for pointer type length expression must be specified");
    6483           51 :           return error_mark_node;
    6484              :         }
    6485         4521 :       if (length != NULL_TREE
    6486         4521 :           && TREE_CODE (length) == INTEGER_CST
    6487         3424 :           && tree_int_cst_sgn (length) == -1)
    6488              :         {
    6489           96 :           error_at (OMP_CLAUSE_LOCATION (c),
    6490              :                     "negative length in array section in %qs clause",
    6491           96 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6492           96 :           return error_mark_node;
    6493              :         }
    6494              :       /* If there is a pointer type anywhere but in the very first
    6495              :          array-section-subscript, the array section could be non-contiguous.  */
    6496         4425 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6497         4323 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6498         8263 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
    6499              :         {
    6500              :           /* If any prior dimension has a non-one length, then deem this
    6501              :              array section as non-contiguous.  */
    6502          159 :           for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
    6503           69 :                d = TREE_OPERAND (d, 0))
    6504              :             {
    6505           90 :               tree d_length = TREE_OPERAND (d, 2);
    6506           90 :               if (d_length == NULL_TREE || !integer_onep (d_length))
    6507              :                 {
    6508           21 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6509              :                             "array section is not contiguous in %qs clause",
    6510           21 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6511           21 :                   return error_mark_node;
    6512              :                 }
    6513              :             }
    6514              :         }
    6515              :     }
    6516              :   else
    6517              :     {
    6518           60 :       error_at (OMP_CLAUSE_LOCATION (c),
    6519              :                 "%qE does not have pointer or array type", ret);
    6520           60 :       return error_mark_node;
    6521              :     }
    6522         9614 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6523         8709 :     types.safe_push (TREE_TYPE (ret));
    6524              :   /* We will need to evaluate lb more than once.  */
    6525         9614 :   tree lb = cp_save_expr (low_bound);
    6526         9614 :   if (lb != low_bound)
    6527              :     {
    6528          722 :       TREE_OPERAND (t, 1) = lb;
    6529          722 :       low_bound = lb;
    6530              :     }
    6531              :   /* Temporarily disable -fstrong-eval-order for array reductions.
    6532              :      The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
    6533              :      is something the middle-end can't cope with and more importantly,
    6534              :      it needs to be the actual base variable that is privatized, not some
    6535              :      temporary assigned previous value of it.  That, together with OpenMP
    6536              :      saying how many times the side-effects are evaluated is unspecified,
    6537              :      makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified.  */
    6538         9614 :   warning_sentinel s (flag_strong_eval_order,
    6539         9614 :                       OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6540         8511 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6541        16991 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
    6542         9614 :   ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
    6543              :                          tf_warning_or_error);
    6544         9614 :   return ret;
    6545         9614 : }
    6546              : 
    6547              : /* Handle array sections for clause C.  */
    6548              : 
    6549              : static bool
    6550         9750 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
    6551              : {
    6552         9750 :   bool maybe_zero_len = false;
    6553         9750 :   unsigned int first_non_one = 0;
    6554         9750 :   auto_vec<tree, 10> types;
    6555         9750 :   tree *tp = &OMP_CLAUSE_DECL (c);
    6556         9750 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6557         8791 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6558        10159 :       && OMP_ITERATOR_DECL_P (*tp))
    6559          258 :     tp = &TREE_VALUE (*tp);
    6560         9750 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
    6561              :                                             maybe_zero_len, first_non_one,
    6562              :                                             ort);
    6563         9750 :   if (first == error_mark_node)
    6564              :     return true;
    6565         8637 :   if (first == NULL_TREE)
    6566              :     return false;
    6567         7820 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6568         7820 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6569              :     {
    6570          951 :       tree t = *tp;
    6571          951 :       tree tem = NULL_TREE;
    6572          951 :       if (processing_template_decl)
    6573              :         return false;
    6574              :       /* Need to evaluate side effects in the length expressions
    6575              :          if any.  */
    6576          852 :       while (TREE_CODE (t) == TREE_LIST)
    6577              :         {
    6578            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
    6579              :             {
    6580            0 :               if (tem == NULL_TREE)
    6581              :                 tem = TREE_VALUE (t);
    6582              :               else
    6583            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
    6584            0 :                               TREE_VALUE (t), tem);
    6585              :             }
    6586            0 :           t = TREE_CHAIN (t);
    6587              :         }
    6588          852 :       if (tem)
    6589            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
    6590          852 :       *tp = first;
    6591              :     }
    6592              :   else
    6593              :     {
    6594         6869 :       unsigned int num = types.length (), i;
    6595         6869 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
    6596         6869 :       tree condition = NULL_TREE;
    6597              : 
    6598         6869 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
    6599            3 :         maybe_zero_len = true;
    6600         6869 :       if (processing_template_decl && maybe_zero_len)
    6601              :         return false;
    6602              : 
    6603        14446 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
    6604         7655 :            t = TREE_OPERAND (t, 0))
    6605              :         {
    6606         7730 :           gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
    6607              : 
    6608         7730 :           tree low_bound = TREE_OPERAND (t, 1);
    6609         7730 :           tree length = TREE_OPERAND (t, 2);
    6610              : 
    6611         7730 :           i--;
    6612         7730 :           if (low_bound
    6613         6252 :               && TREE_CODE (low_bound) == INTEGER_CST
    6614        13371 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
    6615         5641 :                  > TYPE_PRECISION (sizetype))
    6616            0 :             low_bound = fold_convert (sizetype, low_bound);
    6617         7730 :           if (length
    6618         7181 :               && TREE_CODE (length) == INTEGER_CST
    6619        13019 :               && TYPE_PRECISION (TREE_TYPE (length))
    6620         5289 :                  > TYPE_PRECISION (sizetype))
    6621            0 :             length = fold_convert (sizetype, length);
    6622         7730 :           if (low_bound == NULL_TREE)
    6623         1478 :             low_bound = integer_zero_node;
    6624         7730 :           if (!maybe_zero_len && i > first_non_one)
    6625              :             {
    6626          646 :               if (integer_nonzerop (low_bound))
    6627           36 :                 goto do_warn_noncontiguous;
    6628          610 :               if (length != NULL_TREE
    6629          282 :                   && TREE_CODE (length) == INTEGER_CST
    6630          282 :                   && TYPE_DOMAIN (types[i])
    6631          282 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
    6632          892 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
    6633              :                      == INTEGER_CST)
    6634              :                 {
    6635          282 :                   tree size;
    6636          282 :                   size = size_binop (PLUS_EXPR,
    6637              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6638              :                                      size_one_node);
    6639          282 :                   if (!tree_int_cst_equal (length, size))
    6640              :                     {
    6641           39 :                      do_warn_noncontiguous:
    6642          150 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6643              :                                 "array section is not contiguous in %qs "
    6644              :                                 "clause",
    6645           75 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6646           75 :                       return true;
    6647              :                     }
    6648              :                 }
    6649          571 :               if (!processing_template_decl
    6650          401 :                   && length != NULL_TREE
    6651          742 :                   && TREE_SIDE_EFFECTS (length))
    6652              :                 {
    6653            0 :                   if (side_effects == NULL_TREE)
    6654              :                     side_effects = length;
    6655              :                   else
    6656            0 :                     side_effects = build2 (COMPOUND_EXPR,
    6657            0 :                                            TREE_TYPE (side_effects),
    6658              :                                            length, side_effects);
    6659              :                 }
    6660              :             }
    6661         7084 :           else if (processing_template_decl)
    6662          726 :             continue;
    6663              :           else
    6664              :             {
    6665         6358 :               tree l;
    6666              : 
    6667         6358 :               if (i > first_non_one
    6668         6358 :                   && ((length && integer_nonzerop (length))
    6669            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6670              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6671              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
    6672            0 :                 continue;
    6673         6358 :               if (length)
    6674         6219 :                 l = fold_convert (sizetype, length);
    6675              :               else
    6676              :                 {
    6677          139 :                   l = size_binop (PLUS_EXPR,
    6678              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6679              :                                   size_one_node);
    6680          139 :                   l = size_binop (MINUS_EXPR, l,
    6681              :                                   fold_convert (sizetype, low_bound));
    6682              :                 }
    6683         6358 :               if (i > first_non_one)
    6684              :                 {
    6685            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
    6686              :                                    size_zero_node);
    6687            0 :                   if (condition == NULL_TREE)
    6688              :                     condition = l;
    6689              :                   else
    6690            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
    6691              :                                              l, condition);
    6692              :                 }
    6693         6358 :               else if (size == NULL_TREE)
    6694              :                 {
    6695         6071 :                   size = size_in_bytes (TREE_TYPE (types[i]));
    6696         6071 :                   tree eltype = TREE_TYPE (types[num - 1]);
    6697         6142 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
    6698           71 :                     eltype = TREE_TYPE (eltype);
    6699         6071 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6700         5255 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6701        10573 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6702         1665 :                     size = size_binop (EXACT_DIV_EXPR, size,
    6703              :                                        size_in_bytes (eltype));
    6704         6071 :                   size = size_binop (MULT_EXPR, size, l);
    6705         6071 :                   if (condition)
    6706            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
    6707              :                                         size, size_zero_node);
    6708              :                 }
    6709              :               else
    6710          287 :                 size = size_binop (MULT_EXPR, size, l);
    6711              :             }
    6712              :         }
    6713         6716 :       if (!processing_template_decl)
    6714              :         {
    6715         6071 :           if (side_effects)
    6716            0 :             size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
    6717         6071 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6718         5255 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6719        10573 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6720              :             {
    6721         1665 :               size = size_binop (MINUS_EXPR, size, size_one_node);
    6722         1665 :               size = save_expr (size);
    6723         1665 :               tree index_type = build_index_type (size);
    6724         1665 :               tree eltype = TREE_TYPE (first);
    6725         1694 :               while (TREE_CODE (eltype) == ARRAY_TYPE)
    6726           29 :                 eltype = TREE_TYPE (eltype);
    6727         1665 :               tree type = build_array_type (eltype, index_type);
    6728         1665 :               tree ptype = build_pointer_type (eltype);
    6729         1665 :               if (TYPE_REF_P (TREE_TYPE (t))
    6730         1665 :                   && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
    6731          170 :                 t = convert_from_reference (t);
    6732         1495 :               else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6733          647 :                 t = build_fold_addr_expr (t);
    6734         1665 :               tree t2 = build_fold_addr_expr (first);
    6735         1665 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6736              :                                      ptrdiff_type_node, t2);
    6737         1665 :               t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
    6738              :                                     ptrdiff_type_node, t2,
    6739         1665 :                                     fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6740              :                                                       ptrdiff_type_node, t));
    6741         1665 :               if (tree_fits_shwi_p (t2))
    6742         1327 :                 t = build2 (MEM_REF, type, t,
    6743         1327 :                             build_int_cst (ptype, tree_to_shwi (t2)));
    6744              :               else
    6745              :                 {
    6746          338 :                   t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6747              :                                          sizetype, t2);
    6748          338 :                   t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
    6749          338 :                                   TREE_TYPE (t), t, t2);
    6750          338 :                   t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
    6751              :                 }
    6752         1665 :               OMP_CLAUSE_DECL (c) = t;
    6753         6071 :               return false;
    6754              :             }
    6755         4406 :           OMP_CLAUSE_DECL (c) = first;
    6756         4406 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
    6757              :             return false;
    6758         4380 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    6759         4380 :               || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    6760         3814 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
    6761         3802 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
    6762         4356 :             OMP_CLAUSE_SIZE (c) = size;
    6763         4380 :           if (TREE_CODE (t) == FIELD_DECL)
    6764            3 :             t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6765              : 
    6766         4380 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    6767              :             return false;
    6768              : 
    6769         3826 :           if (TREE_CODE (first) == INDIRECT_REF)
    6770              :             {
    6771              :               /* Detect and skip adding extra nodes for pointer-to-member
    6772              :                  mappings.  These are unsupported for now.  */
    6773         2438 :               tree tmp = TREE_OPERAND (first, 0);
    6774              : 
    6775         2438 :               if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
    6776         1940 :                 tmp = TREE_OPERAND (tmp, 0);
    6777              : 
    6778         2438 :               if (TREE_CODE (tmp) == INDIRECT_REF)
    6779          158 :                 tmp = TREE_OPERAND (tmp, 0);
    6780              : 
    6781         2438 :               if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
    6782              :                 {
    6783          468 :                   tree offset = TREE_OPERAND (tmp, 1);
    6784          468 :                   STRIP_NOPS (offset);
    6785          468 :                   if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
    6786              :                     {
    6787           36 :                       sorry_at (OMP_CLAUSE_LOCATION (c),
    6788              :                                 "pointer-to-member mapping %qE not supported",
    6789           18 :                                 OMP_CLAUSE_DECL (c));
    6790           18 :                       return true;
    6791              :                     }
    6792              :                 }
    6793              :             }
    6794              : 
    6795              :           /* FIRST represents the first item of data that we are mapping.
    6796              :              E.g. if we're mapping an array, FIRST might resemble
    6797              :              "foo.bar.myarray[0]".  */
    6798              : 
    6799         3808 :           auto_vec<omp_addr_token *, 10> addr_tokens;
    6800              : 
    6801         3808 :           if (!omp_parse_expr (addr_tokens, first))
    6802              :             return true;
    6803              : 
    6804         3808 :           cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6805              : 
    6806         3808 :           tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
    6807         3808 :           if (nc != error_mark_node)
    6808              :             {
    6809         3808 :               using namespace omp_addr_tokenizer;
    6810              : 
    6811         3808 :               if (ai.maybe_zero_length_array_section (c))
    6812         3784 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
    6813              : 
    6814              :               /* !!! If we're accessing a base decl via chained access
    6815              :                  methods (e.g. multiple indirections), duplicate clause
    6816              :                  detection won't work properly.  Skip it in that case.  */
    6817         3808 :               if ((addr_tokens[0]->type == STRUCTURE_BASE
    6818         2791 :                    || addr_tokens[0]->type == ARRAY_BASE)
    6819         3808 :                   && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    6820         3797 :                   && addr_tokens[1]->type == ACCESS_METHOD
    6821         7605 :                   && omp_access_chain_p (addr_tokens, 1))
    6822          218 :                 c = nc;
    6823              : 
    6824         3808 :               return false;
    6825              :             }
    6826         7616 :         }
    6827              :     }
    6828              :   return false;
    6829         9750 : }
    6830              : 
    6831              : /* Return identifier to look up for omp declare reduction.  */
    6832              : 
    6833              : tree
    6834         7235 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
    6835              : {
    6836         7235 :   const char *p = NULL;
    6837         7235 :   const char *m = NULL;
    6838         7235 :   switch (reduction_code)
    6839              :     {
    6840         4252 :     case PLUS_EXPR:
    6841         4252 :     case MULT_EXPR:
    6842         4252 :     case MINUS_EXPR:
    6843         4252 :     case BIT_AND_EXPR:
    6844         4252 :     case BIT_XOR_EXPR:
    6845         4252 :     case BIT_IOR_EXPR:
    6846         4252 :     case TRUTH_ANDIF_EXPR:
    6847         4252 :     case TRUTH_ORIF_EXPR:
    6848         4252 :       reduction_id = ovl_op_identifier (false, reduction_code);
    6849         4252 :       break;
    6850              :     case MIN_EXPR:
    6851              :       p = "min";
    6852              :       break;
    6853              :     case MAX_EXPR:
    6854              :       p = "max";
    6855              :       break;
    6856              :     default:
    6857              :       break;
    6858              :     }
    6859              : 
    6860         4252 :   if (p == NULL)
    6861              :     {
    6862         7049 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
    6863            0 :         return error_mark_node;
    6864         7049 :       p = IDENTIFIER_POINTER (reduction_id);
    6865              :     }
    6866              : 
    6867         7235 :   if (type != NULL_TREE)
    6868         2091 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6869              : 
    6870         7235 :   const char prefix[] = "omp declare reduction ";
    6871         7235 :   size_t lenp = sizeof (prefix);
    6872         7235 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6873         2091 :     lenp = 1;
    6874         7235 :   size_t len = strlen (p);
    6875         7235 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6876         7235 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6877         7235 :   if (lenp > 1)
    6878         5144 :     memcpy (name, prefix, lenp - 1);
    6879         7235 :   memcpy (name + lenp - 1, p, len + 1);
    6880         7235 :   if (m)
    6881              :     {
    6882         2091 :       name[lenp + len - 1] = '~';
    6883         2091 :       memcpy (name + lenp + len, m, lenm);
    6884              :     }
    6885         7235 :   return get_identifier (name);
    6886              : }
    6887              : 
    6888              : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
    6889              :    FUNCTION_DECL or NULL_TREE if not found.  */
    6890              : 
    6891              : static tree
    6892         1336 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
    6893              :                       vec<tree> *ambiguousp)
    6894              : {
    6895         1336 :   tree orig_id = id;
    6896         1336 :   tree baselink = NULL_TREE;
    6897         1336 :   if (identifier_p (id))
    6898              :     {
    6899         1308 :       cp_id_kind idk;
    6900         1308 :       bool nonint_cst_expression_p;
    6901         1308 :       const char *error_msg;
    6902         1308 :       id = omp_reduction_id (ERROR_MARK, id, type);
    6903         1308 :       tree decl = lookup_name (id);
    6904         1308 :       if (decl == NULL_TREE)
    6905           80 :         decl = error_mark_node;
    6906         1308 :       id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
    6907              :                                  &nonint_cst_expression_p, false, true, false,
    6908              :                                  false, &error_msg, loc);
    6909         1308 :       if (idk == CP_ID_KIND_UNQUALIFIED
    6910         1388 :           && identifier_p (id))
    6911              :         {
    6912           80 :           vec<tree, va_gc> *args = NULL;
    6913           80 :           vec_safe_push (args, build_reference_type (type));
    6914           80 :           id = perform_koenig_lookup (id, args, tf_none);
    6915              :         }
    6916              :     }
    6917           28 :   else if (TREE_CODE (id) == SCOPE_REF)
    6918           28 :     id = lookup_qualified_name (TREE_OPERAND (id, 0),
    6919              :                                 omp_reduction_id (ERROR_MARK,
    6920           28 :                                                   TREE_OPERAND (id, 1),
    6921              :                                                   type),
    6922              :                                 LOOK_want::NORMAL, false);
    6923         1336 :   tree fns = id;
    6924         1336 :   id = NULL_TREE;
    6925         1336 :   if (fns && is_overloaded_fn (fns))
    6926              :     {
    6927         1262 :       for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
    6928              :         {
    6929         1262 :           tree fndecl = *iter;
    6930         1262 :           if (TREE_CODE (fndecl) == FUNCTION_DECL)
    6931              :             {
    6932         1262 :               tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
    6933         1262 :               if (same_type_p (TREE_TYPE (argtype), type))
    6934              :                 {
    6935         1262 :                   id = fndecl;
    6936         1262 :                   break;
    6937              :                 }
    6938              :             }
    6939              :         }
    6940              : 
    6941         1262 :       if (id && BASELINK_P (fns))
    6942              :         {
    6943           74 :           if (baselinkp)
    6944            0 :             *baselinkp = fns;
    6945              :           else
    6946           74 :             baselink = fns;
    6947              :         }
    6948              :     }
    6949              : 
    6950         1336 :   if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
    6951              :     {
    6952           35 :       auto_vec<tree> ambiguous;
    6953           35 :       tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
    6954           35 :       unsigned int ix;
    6955           35 :       if (ambiguousp == NULL)
    6956           19 :         ambiguousp = &ambiguous;
    6957           73 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    6958              :         {
    6959           62 :           id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
    6960              :                                      baselinkp ? baselinkp : &baselink,
    6961              :                                      ambiguousp);
    6962           38 :           if (id == NULL_TREE)
    6963           14 :             continue;
    6964           24 :           if (!ambiguousp->is_empty ())
    6965            3 :             ambiguousp->safe_push (id);
    6966           21 :           else if (ret != NULL_TREE)
    6967              :             {
    6968            6 :               ambiguousp->safe_push (ret);
    6969            6 :               ambiguousp->safe_push (id);
    6970            6 :               ret = NULL_TREE;
    6971              :             }
    6972              :           else
    6973           15 :             ret = id;
    6974              :         }
    6975           35 :       if (ambiguousp != &ambiguous)
    6976           16 :         return ret;
    6977           19 :       if (!ambiguous.is_empty ())
    6978              :         {
    6979            6 :           auto_diagnostic_group d;
    6980            6 :           const char *str = _("candidates are:");
    6981            6 :           unsigned int idx;
    6982            6 :           tree udr;
    6983            6 :           error_at (loc, "user defined reduction lookup is ambiguous");
    6984           27 :           FOR_EACH_VEC_ELT (ambiguous, idx, udr)
    6985              :             {
    6986           15 :               inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
    6987           15 :               if (idx == 0)
    6988            6 :                 str = get_spaces (str);
    6989              :             }
    6990            6 :           ret = error_mark_node;
    6991            6 :           baselink = NULL_TREE;
    6992            6 :         }
    6993           19 :       id = ret;
    6994           35 :     }
    6995         1320 :   if (id && baselink)
    6996           74 :     perform_or_defer_access_check (BASELINK_BINFO (baselink),
    6997              :                                    id, id, tf_warning_or_error);
    6998              :   return id;
    6999              : }
    7000              : 
    7001              : /* Return identifier to look up for omp declare mapper.  */
    7002              : 
    7003              : tree
    7004         4124 : omp_mapper_id (tree mapper_id, tree type)
    7005              : {
    7006         4124 :   const char *p = NULL;
    7007         4124 :   const char *m = NULL;
    7008              : 
    7009         4124 :   if (mapper_id == NULL_TREE)
    7010              :     p = "";
    7011           91 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
    7012           91 :     p = IDENTIFIER_POINTER (mapper_id);
    7013              :   else
    7014            0 :     return error_mark_node;
    7015              : 
    7016         4124 :   if (type != NULL_TREE)
    7017         4116 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    7018              : 
    7019         4124 :   const char prefix[] = "omp declare mapper ";
    7020         4124 :   size_t lenp = sizeof (prefix);
    7021         4124 :   if (strncmp (p, prefix, lenp - 1) == 0)
    7022            8 :     lenp = 1;
    7023         4124 :   size_t len = strlen (p);
    7024         4124 :   size_t lenm = m ? strlen (m) + 1 : 0;
    7025         4124 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    7026         4124 :   memcpy (name, prefix, lenp - 1);
    7027         4124 :   memcpy (name + lenp - 1, p, len + 1);
    7028         4124 :   if (m)
    7029              :     {
    7030         4116 :       name[lenp + len - 1] = '~';
    7031         4116 :       memcpy (name + lenp + len, m, lenm);
    7032              :     }
    7033         4124 :   return get_identifier (name);
    7034              : }
    7035              : 
    7036              : tree
    7037        12998 : cxx_omp_mapper_lookup (tree id, tree type)
    7038              : {
    7039        12998 :   if (!RECORD_OR_UNION_TYPE_P (type))
    7040              :     return NULL_TREE;
    7041         3883 :   id = omp_mapper_id (id, type);
    7042         3883 :   return lookup_name (id);
    7043              : }
    7044              : 
    7045              : tree
    7046          375 : cxx_omp_extract_mapper_directive (tree vardecl)
    7047              : {
    7048          375 :   gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
    7049              : 
    7050              :   /* Instantiate the decl if we haven't already.  */
    7051          375 :   mark_used (vardecl);
    7052          375 :   tree body = DECL_INITIAL (vardecl);
    7053              : 
    7054          375 :   if (TREE_CODE (body) == STATEMENT_LIST)
    7055              :     {
    7056            0 :       tree_stmt_iterator tsi = tsi_start (body);
    7057            0 :       gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
    7058            0 :       tsi_next (&tsi);
    7059            0 :       body = tsi_stmt (tsi);
    7060              :     }
    7061              : 
    7062          375 :   gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
    7063              : 
    7064          375 :   return body;
    7065              : }
    7066              : 
    7067              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
    7068              :    nothing more complicated.  */
    7069              : 
    7070              : tree
    7071         1990 : cxx_omp_map_array_section (location_t loc, tree t)
    7072              : {
    7073         1990 :   tree low = TREE_OPERAND (t, 1);
    7074         1990 :   tree len = TREE_OPERAND (t, 2);
    7075              : 
    7076         1990 :   if (len && integer_onep (len))
    7077              :     {
    7078          348 :       t = TREE_OPERAND (t, 0);
    7079              : 
    7080          348 :       if (!low)
    7081           47 :         low = integer_zero_node;
    7082              : 
    7083          348 :       if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
    7084            6 :         t = convert_from_reference (t);
    7085              : 
    7086          348 :       if (TYPE_PTR_P (TREE_TYPE (t))
    7087          348 :           || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    7088          348 :         t = build_array_ref (loc, t, low);
    7089              :       else
    7090              :         /* handle_omp_array_sections_1 has already diagnosed the error.  */
    7091            0 :         t = error_mark_node;
    7092              :     }
    7093              : 
    7094         1990 :   return t;
    7095              : }
    7096              : 
    7097              : /* Helper function for cp_parser_omp_declare_reduction_exprs
    7098              :    and tsubst_omp_udr.
    7099              :    Remove CLEANUP_STMT for data (omp_priv variable).
    7100              :    Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
    7101              :    DECL_EXPR.  */
    7102              : 
    7103              : tree
    7104         4533 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
    7105              : {
    7106         4533 :   if (TYPE_P (*tp))
    7107          234 :     *walk_subtrees = 0;
    7108         4299 :   else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
    7109           54 :     *tp = CLEANUP_BODY (*tp);
    7110         4245 :   else if (TREE_CODE (*tp) == DECL_EXPR)
    7111              :     {
    7112          316 :       tree decl = DECL_EXPR_DECL (*tp);
    7113          316 :       if (!processing_template_decl
    7114          267 :           && decl == (tree) data
    7115          267 :           && DECL_INITIAL (decl)
    7116          410 :           && DECL_INITIAL (decl) != error_mark_node)
    7117              :         {
    7118           94 :           tree list = NULL_TREE;
    7119           94 :           append_to_statement_list_force (*tp, &list);
    7120           94 :           tree init_expr = build2 (INIT_EXPR, void_type_node,
    7121           94 :                                    decl, DECL_INITIAL (decl));
    7122           94 :           DECL_INITIAL (decl) = NULL_TREE;
    7123           94 :           append_to_statement_list_force (init_expr, &list);
    7124           94 :           *tp = list;
    7125              :         }
    7126              :     }
    7127         4533 :   return NULL_TREE;
    7128              : }
    7129              : 
    7130              : /* Data passed from cp_check_omp_declare_reduction to
    7131              :    cp_check_omp_declare_reduction_r.  */
    7132              : 
    7133              : struct cp_check_omp_declare_reduction_data
    7134              : {
    7135              :   location_t loc;
    7136              :   tree stmts[7];
    7137              :   bool combiner_p;
    7138              : };
    7139              : 
    7140              : /* Helper function for cp_check_omp_declare_reduction, called via
    7141              :    cp_walk_tree.  */
    7142              : 
    7143              : static tree
    7144        15222 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
    7145              : {
    7146        15222 :   struct cp_check_omp_declare_reduction_data *udr_data
    7147              :     = (struct cp_check_omp_declare_reduction_data *) data;
    7148        15222 :   if (SSA_VAR_P (*tp)
    7149         2734 :       && !DECL_ARTIFICIAL (*tp)
    7150          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
    7151          225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
    7152              :     {
    7153          135 :       location_t loc = udr_data->loc;
    7154          135 :       if (udr_data->combiner_p)
    7155           45 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
    7156              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
    7157              :                   *tp);
    7158              :       else
    7159           90 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
    7160              :                        "to variable %qD which is not %<omp_priv%> nor "
    7161              :                        "%<omp_orig%>",
    7162              :                   *tp);
    7163          135 :       return *tp;
    7164              :     }
    7165              :   return NULL_TREE;
    7166              : }
    7167              : 
    7168              : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions.  */
    7169              : 
    7170              : bool
    7171         1110 : cp_check_omp_declare_reduction (tree udr)
    7172              : {
    7173         1110 :   tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
    7174         1110 :   gcc_assert (TYPE_REF_P (type));
    7175         1110 :   type = TREE_TYPE (type);
    7176         1110 :   int i;
    7177         1110 :   location_t loc = DECL_SOURCE_LOCATION (udr);
    7178              : 
    7179         1110 :   if (type == error_mark_node)
    7180              :     return false;
    7181         1110 :   if (ARITHMETIC_TYPE_P (type))
    7182              :     {
    7183              :       static enum tree_code predef_codes[]
    7184              :         = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
    7185              :             BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
    7186         3294 :       for (i = 0; i < 8; i++)
    7187              :         {
    7188         2934 :           tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
    7189         2934 :           const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
    7190         2934 :           const char *n2 = IDENTIFIER_POINTER (id);
    7191         2934 :           if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
    7192         2934 :               && (n1[IDENTIFIER_LENGTH (id)] == '~'
    7193            0 :                   || n1[IDENTIFIER_LENGTH (id)] == '\0'))
    7194              :             break;
    7195              :         }
    7196              : 
    7197          378 :       if (i == 8
    7198          360 :           && TREE_CODE (type) != COMPLEX_EXPR)
    7199              :         {
    7200          360 :           const char prefix_minmax[] = "omp declare reduction m";
    7201          360 :           size_t prefix_size = sizeof (prefix_minmax) - 1;
    7202          360 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
    7203          360 :           if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
    7204              :                        prefix_minmax, prefix_size) == 0
    7205           12 :               && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
    7206            6 :                   || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
    7207          370 :               && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
    7208            6 :             i = 0;
    7209              :         }
    7210          378 :       if (i < 8)
    7211              :         {
    7212           24 :           error_at (loc, "predeclared arithmetic type %qT in "
    7213              :                          "%<#pragma omp declare reduction%>", type);
    7214           24 :           return false;
    7215              :         }
    7216              :     }
    7217              :   else if (FUNC_OR_METHOD_TYPE_P (type)
    7218              :            || TREE_CODE (type) == ARRAY_TYPE)
    7219              :     {
    7220           24 :       error_at (loc, "function or array type %qT in "
    7221              :                      "%<#pragma omp declare reduction%>", type);
    7222           24 :       return false;
    7223              :     }
    7224              :   else if (TYPE_REF_P (type))
    7225              :     {
    7226            0 :       error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
    7227              :                 type);
    7228            0 :       return false;
    7229              :     }
    7230          708 :   else if (TYPE_QUALS_NO_ADDR_SPACE (type))
    7231              :     {
    7232           24 :       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
    7233              :                 "type %qT in %<#pragma omp declare reduction%>", type);
    7234           24 :       return false;
    7235              :     }
    7236              : 
    7237         1038 :   tree body = DECL_SAVED_TREE (udr);
    7238         1038 :   if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
    7239              :     return true;
    7240              : 
    7241          852 :   tree_stmt_iterator tsi;
    7242          852 :   struct cp_check_omp_declare_reduction_data data;
    7243          852 :   memset (data.stmts, 0, sizeof data.stmts);
    7244          852 :   for (i = 0, tsi = tsi_start (body);
    7245         4753 :        i < 7 && !tsi_end_p (tsi);
    7246         3901 :        i++, tsi_next (&tsi))
    7247         3901 :     data.stmts[i] = tsi_stmt (tsi);
    7248          852 :   data.loc = loc;
    7249          852 :   gcc_assert (tsi_end_p (tsi));
    7250          852 :   if (i >= 3)
    7251              :     {
    7252          852 :       gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
    7253              :                   && TREE_CODE (data.stmts[1]) == DECL_EXPR);
    7254          852 :       if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
    7255              :         return true;
    7256          807 :       data.combiner_p = true;
    7257          807 :       if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
    7258              :                         &data, NULL))
    7259           45 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
    7260              :     }
    7261          807 :   if (i >= 6)
    7262              :     {
    7263          345 :       gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
    7264              :                   && TREE_CODE (data.stmts[4]) == DECL_EXPR);
    7265          345 :       data.combiner_p = false;
    7266          345 :       if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
    7267              :                         &data, NULL)
    7268          345 :           || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
    7269              :                            cp_check_omp_declare_reduction_r, &data, NULL))
    7270           90 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /* Wat warning? */);
    7271          345 :       if (i == 7)
    7272          205 :         gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
    7273              :     }
    7274              :   return true;
    7275              : }
    7276              : 
    7277              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
    7278              :    an inline call.  But, remap
    7279              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
    7280              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
    7281              : 
    7282              : static tree
    7283         2293 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
    7284              :                tree decl, tree placeholder)
    7285              : {
    7286         2293 :   copy_body_data id;
    7287         2293 :   hash_map<tree, tree> decl_map;
    7288              : 
    7289         2293 :   decl_map.put (omp_decl1, placeholder);
    7290         2293 :   decl_map.put (omp_decl2, decl);
    7291         2293 :   memset (&id, 0, sizeof (id));
    7292         2293 :   id.src_fn = DECL_CONTEXT (omp_decl1);
    7293         2293 :   id.dst_fn = current_function_decl;
    7294         2293 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    7295         2293 :   id.decl_map = &decl_map;
    7296              : 
    7297         2293 :   id.copy_decl = copy_decl_no_change;
    7298         2293 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    7299         2293 :   id.transform_new_cfg = true;
    7300         2293 :   id.transform_return_to_modify = false;
    7301         2293 :   id.eh_lp_nr = 0;
    7302         2293 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
    7303         2293 :   return stmt;
    7304         2293 : }
    7305              : 
    7306              : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
    7307              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
    7308              : 
    7309              : static tree
    7310        16069 : find_omp_placeholder_r (tree *tp, int *, void *data)
    7311              : {
    7312        16069 :   if (*tp == (tree) data)
    7313          290 :     return *tp;
    7314              :   return NULL_TREE;
    7315              : }
    7316              : 
    7317              : /* Helper function of finish_omp_clauses.  Handle OMP_CLAUSE_REDUCTION C.
    7318              :    Return true if there is some error and the clause should be removed.  */
    7319              : 
    7320              : static bool
    7321         9389 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
    7322              : {
    7323         9389 :   tree t = OMP_CLAUSE_DECL (c);
    7324         9389 :   bool predefined = false;
    7325         9389 :   if (TREE_CODE (t) == TREE_LIST)
    7326              :     {
    7327            0 :       gcc_assert (processing_template_decl);
    7328              :       return false;
    7329              :     }
    7330         9389 :   tree type = TREE_TYPE (t);
    7331         9389 :   if (TREE_CODE (t) == MEM_REF)
    7332         1662 :     type = TREE_TYPE (type);
    7333         9389 :   if (TYPE_REF_P (type))
    7334          589 :     type = TREE_TYPE (type);
    7335         9389 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7336              :     {
    7337          377 :       tree oatype = type;
    7338          377 :       gcc_assert (TREE_CODE (t) != MEM_REF);
    7339          757 :       while (TREE_CODE (type) == ARRAY_TYPE)
    7340          380 :         type = TREE_TYPE (type);
    7341          377 :       if (!processing_template_decl)
    7342              :         {
    7343          270 :           t = require_complete_type (t);
    7344          270 :           if (t == error_mark_node
    7345          270 :               || !complete_type_or_else (oatype, NULL_TREE))
    7346              :             return true;
    7347          261 :           tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
    7348              :                                   TYPE_SIZE_UNIT (type));
    7349          261 :           if (integer_zerop (size))
    7350              :             {
    7351            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7352              :                         "%qE in %<reduction%> clause is a zero size array",
    7353              :                         omp_clause_printable_decl (t));
    7354            3 :               return true;
    7355              :             }
    7356          258 :           size = size_binop (MINUS_EXPR, size, size_one_node);
    7357          258 :           size = save_expr (size);
    7358          258 :           tree index_type = build_index_type (size);
    7359          258 :           tree atype = build_array_type (type, index_type);
    7360          258 :           tree ptype = build_pointer_type (type);
    7361          258 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    7362          152 :             t = build_fold_addr_expr (t);
    7363          258 :           t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
    7364          258 :           OMP_CLAUSE_DECL (c) = t;
    7365              :         }
    7366              :     }
    7367         9377 :   if (type == error_mark_node)
    7368              :     return true;
    7369         9374 :   else if (ARITHMETIC_TYPE_P (type))
    7370         8073 :     switch (OMP_CLAUSE_REDUCTION_CODE (c))
    7371              :       {
    7372              :       case PLUS_EXPR:
    7373              :       case MULT_EXPR:
    7374              :       case MINUS_EXPR:
    7375              :       case TRUTH_ANDIF_EXPR:
    7376              :       case TRUTH_ORIF_EXPR:
    7377              :         predefined = true;
    7378              :         break;
    7379          312 :       case MIN_EXPR:
    7380          312 :       case MAX_EXPR:
    7381          312 :         if (TREE_CODE (type) == COMPLEX_TYPE)
    7382              :           break;
    7383              :         predefined = true;
    7384              :         break;
    7385          165 :       case BIT_AND_EXPR:
    7386          165 :       case BIT_IOR_EXPR:
    7387          165 :       case BIT_XOR_EXPR:
    7388          165 :         if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
    7389              :           break;
    7390              :         predefined = true;
    7391              :         break;
    7392              :       default:
    7393              :         break;
    7394              :       }
    7395         1301 :   else if (TYPE_READONLY (type))
    7396              :     {
    7397           18 :       error_at (OMP_CLAUSE_LOCATION (c),
    7398              :                 "%qE has const type for %<reduction%>",
    7399              :                 omp_clause_printable_decl (t));
    7400            9 :       return true;
    7401              :     }
    7402         1292 :   else if (!processing_template_decl)
    7403              :     {
    7404         1079 :       t = require_complete_type (t);
    7405         1079 :       if (t == error_mark_node)
    7406              :         return true;
    7407         1079 :       OMP_CLAUSE_DECL (c) = t;
    7408              :     }
    7409              : 
    7410         1079 :   if (predefined)
    7411              :     {
    7412         7845 :       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7413         7845 :       return false;
    7414              :     }
    7415         1520 :   else if (processing_template_decl)
    7416              :     {
    7417          222 :       if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
    7418              :         return true;
    7419          219 :       return false;
    7420              :     }
    7421              : 
    7422         1298 :   tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
    7423              : 
    7424         1298 :   type = TYPE_MAIN_VARIANT (type);
    7425         1298 :   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7426         1298 :   if (id == NULL_TREE)
    7427          965 :     id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
    7428              :                            NULL_TREE, NULL_TREE);
    7429         1298 :   id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
    7430         1298 :   if (id)
    7431              :     {
    7432         1253 :       if (id == error_mark_node)
    7433              :         return true;
    7434         1247 :       mark_used (id);
    7435         1247 :       tree body = DECL_SAVED_TREE (id);
    7436         1247 :       if (!body)
    7437              :         return true;
    7438         1244 :       if (TREE_CODE (body) == STATEMENT_LIST)
    7439              :         {
    7440         1244 :           tree_stmt_iterator tsi;
    7441         1244 :           tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
    7442         1244 :           int i;
    7443         1244 :           tree stmts[7];
    7444         1244 :           tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
    7445         1244 :           atype = TREE_TYPE (atype);
    7446         1244 :           bool need_static_cast = !same_type_p (type, atype);
    7447         1244 :           memset (stmts, 0, sizeof stmts);
    7448         1244 :           for (i = 0, tsi = tsi_start (body);
    7449         8882 :                i < 7 && !tsi_end_p (tsi);
    7450         7638 :                i++, tsi_next (&tsi))
    7451         7638 :             stmts[i] = tsi_stmt (tsi);
    7452         1244 :           gcc_assert (tsi_end_p (tsi));
    7453              : 
    7454         1244 :           if (i >= 3)
    7455              :             {
    7456         1244 :               gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
    7457              :                           && TREE_CODE (stmts[1]) == DECL_EXPR);
    7458         1244 :               placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
    7459         1244 :               DECL_ARTIFICIAL (placeholder) = 1;
    7460         1244 :               DECL_IGNORED_P (placeholder) = 1;
    7461         1244 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
    7462         1244 :               if (TREE_CODE (t) == MEM_REF)
    7463              :                 {
    7464          600 :                   decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
    7465              :                                                       type);
    7466          600 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
    7467          600 :                   DECL_IGNORED_P (decl_placeholder) = 1;
    7468          600 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
    7469              :                 }
    7470         1244 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
    7471          310 :                 cxx_mark_addressable (placeholder);
    7472         1244 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
    7473         1244 :                   && (decl_placeholder
    7474          174 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7475          390 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7476          127 :                                       : OMP_CLAUSE_DECL (c));
    7477         1244 :               tree omp_out = placeholder;
    7478         1244 :               tree omp_in = decl_placeholder ? decl_placeholder
    7479          644 :                             : convert_from_reference (OMP_CLAUSE_DECL (c));
    7480         1244 :               if (need_static_cast)
    7481              :                 {
    7482            7 :                   tree rtype = build_reference_type (atype);
    7483            7 :                   omp_out = build_static_cast (input_location,
    7484              :                                                rtype, omp_out,
    7485              :                                                tf_warning_or_error);
    7486            7 :                   omp_in = build_static_cast (input_location,
    7487              :                                               rtype, omp_in,
    7488              :                                               tf_warning_or_error);
    7489            7 :                   if (omp_out == error_mark_node || omp_in == error_mark_node)
    7490            3 :                     return true;
    7491            7 :                   omp_out = convert_from_reference (omp_out);
    7492            7 :                   omp_in = convert_from_reference (omp_in);
    7493              :                 }
    7494         1244 :               OMP_CLAUSE_REDUCTION_MERGE (c)
    7495         1244 :                 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
    7496         1244 :                                  DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
    7497              :             }
    7498         1244 :           if (i >= 6)
    7499              :             {
    7500         1052 :               gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
    7501              :                           && TREE_CODE (stmts[4]) == DECL_EXPR);
    7502         1052 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
    7503         1052 :                   && (decl_placeholder
    7504          264 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7505          844 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7506          170 :                                       : OMP_CLAUSE_DECL (c));
    7507         1052 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
    7508          241 :                 cxx_mark_addressable (placeholder);
    7509         1052 :               tree omp_priv = decl_placeholder ? decl_placeholder
    7510          476 :                               : convert_from_reference (OMP_CLAUSE_DECL (c));
    7511         1052 :               tree omp_orig = placeholder;
    7512         1052 :               if (need_static_cast)
    7513              :                 {
    7514            5 :                   if (i == 7)
    7515              :                     {
    7516            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    7517              :                                 "user defined reduction with constructor "
    7518              :                                 "initializer for base class %qT", atype);
    7519            3 :                       return true;
    7520              :                     }
    7521            2 :                   tree rtype = build_reference_type (atype);
    7522            2 :                   omp_priv = build_static_cast (input_location,
    7523              :                                                 rtype, omp_priv,
    7524              :                                                 tf_warning_or_error);
    7525            2 :                   omp_orig = build_static_cast (input_location,
    7526              :                                                 rtype, omp_orig,
    7527              :                                                 tf_warning_or_error);
    7528            2 :                   if (omp_priv == error_mark_node
    7529            2 :                       || omp_orig == error_mark_node)
    7530              :                     return true;
    7531            2 :                   omp_priv = convert_from_reference (omp_priv);
    7532            2 :                   omp_orig = convert_from_reference (omp_orig);
    7533              :                 }
    7534         1049 :               if (i == 6)
    7535          302 :                 *need_default_ctor = true;
    7536         1049 :               OMP_CLAUSE_REDUCTION_INIT (c)
    7537         1049 :                 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
    7538         1049 :                                  DECL_EXPR_DECL (stmts[3]),
    7539              :                                  omp_priv, omp_orig);
    7540         1049 :               if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
    7541              :                                 find_omp_placeholder_r, placeholder, NULL))
    7542          263 :                 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
    7543              :             }
    7544          192 :           else if (i >= 3)
    7545              :             {
    7546          192 :               if (CLASS_TYPE_P (type) && !pod_type_p (type))
    7547          175 :                 *need_default_ctor = true;
    7548              :               else
    7549              :                 {
    7550           17 :                   tree init;
    7551           17 :                   tree v = decl_placeholder ? decl_placeholder
    7552           17 :                            : convert_from_reference (t);
    7553           17 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
    7554            8 :                     init = build_constructor (TREE_TYPE (v), NULL);
    7555              :                   else
    7556            9 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
    7557           34 :                   OMP_CLAUSE_REDUCTION_INIT (c)
    7558           34 :                     = cp_build_init_expr (v, init);
    7559              :                 }
    7560              :             }
    7561              :         }
    7562              :     }
    7563         1286 :   if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
    7564         1241 :     *need_dtor = true;
    7565              :   else
    7566              :     {
    7567           90 :       error_at (OMP_CLAUSE_LOCATION (c),
    7568              :                 "user defined reduction not found for %qE",
    7569              :                 omp_clause_printable_decl (t));
    7570           45 :       return true;
    7571              :     }
    7572         1241 :   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
    7573          600 :     gcc_assert (TYPE_SIZE_UNIT (type)
    7574              :                 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
    7575              :   return false;
    7576              : }
    7577              : 
    7578              : /* Check an instance of an "omp declare mapper" function.  */
    7579              : 
    7580              : bool
    7581          208 : cp_check_omp_declare_mapper (tree udm)
    7582              : {
    7583          208 :   tree var = OMP_DECLARE_MAPPER_DECL (udm);
    7584          208 :   tree type = TREE_TYPE (var);
    7585          208 :   location_t loc = DECL_SOURCE_LOCATION (var);
    7586              : 
    7587          208 :   if (type == error_mark_node)
    7588              :     return false;
    7589              : 
    7590          208 :   if (processing_template_decl)
    7591              :     return true;
    7592              : 
    7593          197 :   if (!RECORD_OR_UNION_TYPE_P (type))
    7594              :     {
    7595           17 :       error_at (loc, "%qT is not a struct, union or class type in "
    7596              :                 "%<#pragma omp declare mapper%>", type);
    7597           17 :       return false;
    7598              :     }
    7599          180 :   if (CLASSTYPE_VBASECLASSES (type))
    7600              :     {
    7601            3 :       error_at (loc, "%qT must not be a virtual base class in "
    7602              :                 "%<#pragma omp declare mapper%>", type);
    7603            3 :       return false;
    7604              :     }
    7605              : 
    7606          177 :   tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
    7607          215 :   for ( ; c; c = OMP_CLAUSE_CHAIN (c))
    7608              :     {
    7609          187 :       tree dvar = OMP_CLAUSE_DECL (c);
    7610          400 :       while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
    7611          213 :         dvar = TREE_OPERAND (dvar, 0);
    7612          187 :       if (dvar == var)
    7613              :         break;
    7614              :     }
    7615          177 :   if (!c)
    7616              :     {
    7617              :       // After template handling, the var is mangled, demangle it
    7618           28 :       const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
    7619           28 :       char *n = NULL;
    7620           28 :       if (startswith (name, "omp declare mapper "))
    7621              :         {
    7622            3 :           name += strlen ("omp declare mapper ");
    7623            3 :           n = xstrdup (name);
    7624            3 :           n[strchr (n, '~')-n] = '\0';
    7625            3 :           name = n;
    7626              :         }
    7627           28 :       error_at (loc, "at least one %<map%> clause must map %qs or an "
    7628              :                      "element of it", name);
    7629           28 :       if (n)
    7630            3 :         free (n);
    7631              :       return false;
    7632              :     }
    7633              : 
    7634              :   /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
    7635              :      = 1, which is set to false in finalize_literal_type_property for C++ < 11,
    7636              :      leading to an error in ensure_literal_type_for_constexpr_object.
    7637              :      Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
    7638              :      libgomp.c++/declare-mapper-{5,6,8}.C.  */
    7639          149 :   if (cxx_dialect < cxx11)
    7640              :     {
    7641            0 :       sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
    7642              :                      "before C++11");
    7643            0 :       return false;
    7644              :     }
    7645              : 
    7646              :   return true;
    7647              : }
    7648              : 
    7649              : /* Called from finish_struct_1.  linear(this) or linear(this:step)
    7650              :    clauses might not be finalized yet because the class has been incomplete
    7651              :    when parsing #pragma omp declare simd methods.  Fix those up now.  */
    7652              : 
    7653              : void
    7654       120919 : finish_omp_declare_simd_methods (tree t)
    7655              : {
    7656       120919 :   if (processing_template_decl)
    7657              :     return;
    7658              : 
    7659       820728 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7660              :     {
    7661      1159574 :       if (TREE_CODE (x) == USING_DECL
    7662       699809 :           || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
    7663       459765 :         continue;
    7664       240044 :       tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
    7665       240152 :       if (!ods || !TREE_VALUE (ods))
    7666       239936 :         continue;
    7667          366 :       for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
    7668          258 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
    7669           66 :             && integer_zerop (OMP_CLAUSE_DECL (c))
    7670           18 :             && OMP_CLAUSE_LINEAR_STEP (c)
    7671          276 :             && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
    7672              :           {
    7673           18 :             tree s = OMP_CLAUSE_LINEAR_STEP (c);
    7674           18 :             s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
    7675           18 :             s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
    7676           18 :                                  sizetype, s, TYPE_SIZE_UNIT (t));
    7677           18 :             OMP_CLAUSE_LINEAR_STEP (c) = s;
    7678              :           }
    7679              :     }
    7680              : }
    7681              : 
    7682              : /* Adjust sink depend/doacross clause to take into account pointer offsets.
    7683              : 
    7684              :    Return TRUE if there was a problem processing the offset, and the
    7685              :    whole clause should be removed.  */
    7686              : 
    7687              : static bool
    7688          298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
    7689              : {
    7690          298 :   tree t = OMP_CLAUSE_DECL (sink_clause);
    7691          298 :   gcc_assert (TREE_CODE (t) == TREE_LIST);
    7692              : 
    7693              :   /* Make sure we don't adjust things twice for templates.  */
    7694          298 :   if (processing_template_decl)
    7695              :     return false;
    7696              : 
    7697          671 :   for (; t; t = TREE_CHAIN (t))
    7698              :     {
    7699          391 :       tree decl = TREE_VALUE (t);
    7700          391 :       if (TYPE_PTR_P (TREE_TYPE (decl)))
    7701              :         {
    7702            6 :           tree offset = TREE_PURPOSE (t);
    7703            6 :           bool neg = wi::neg_p (wi::to_wide (offset));
    7704            6 :           offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
    7705            6 :           decl = mark_rvalue_use (decl);
    7706            6 :           decl = convert_from_reference (decl);
    7707           12 :           tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
    7708              :                                      neg ? MINUS_EXPR : PLUS_EXPR,
    7709              :                                      decl, offset);
    7710            6 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
    7711              :                                 MINUS_EXPR, sizetype,
    7712              :                                 fold_convert (sizetype, t2),
    7713              :                                 fold_convert (sizetype, decl));
    7714            6 :           if (t2 == error_mark_node)
    7715              :             return true;
    7716            6 :           TREE_PURPOSE (t) = t2;
    7717              :         }
    7718              :     }
    7719              :   return false;
    7720              : }
    7721              : 
    7722              : /* Finish OpenMP iterators ITER.  Return true if they are erroneous
    7723              :    and clauses containing them should be removed.  */
    7724              : 
    7725              : static bool
    7726          624 : cp_omp_finish_iterators (tree iter)
    7727              : {
    7728          624 :   bool ret = false;
    7729         1413 :   for (tree it = iter; it; it = TREE_CHAIN (it))
    7730              :     {
    7731          789 :       tree var = OMP_ITERATOR_VAR (it);
    7732          789 :       tree begin = OMP_ITERATOR_BEGIN (it);
    7733          789 :       tree end = OMP_ITERATOR_END (it);
    7734          789 :       tree step = OMP_ITERATOR_STEP (it);
    7735          789 :       tree orig_step;
    7736          789 :       tree type = TREE_TYPE (var);
    7737          789 :       location_t loc = DECL_SOURCE_LOCATION (var);
    7738          789 :       if (type == error_mark_node)
    7739              :         {
    7740            0 :           ret = true;
    7741          218 :           continue;
    7742              :         }
    7743          789 :       if (type_dependent_expression_p (var))
    7744           59 :         continue;
    7745          730 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7746              :         {
    7747           27 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
    7748              :                     var);
    7749           27 :           ret = true;
    7750           27 :           continue;
    7751              :         }
    7752          703 :       else if (TYPE_READONLY (type))
    7753              :         {
    7754           24 :           error_at (loc, "iterator %qD has const qualified type", var);
    7755           24 :           ret = true;
    7756           24 :           continue;
    7757              :         }
    7758          679 :       if (type_dependent_expression_p (begin)
    7759          670 :           || type_dependent_expression_p (end)
    7760         1349 :           || type_dependent_expression_p (step))
    7761           15 :         continue;
    7762          664 :       else if (error_operand_p (step))
    7763              :         {
    7764            0 :           ret = true;
    7765            0 :           continue;
    7766              :         }
    7767          664 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
    7768              :         {
    7769           21 :           error_at (EXPR_LOC_OR_LOC (step, loc),
    7770              :                     "iterator step with non-integral type");
    7771           21 :           ret = true;
    7772           21 :           continue;
    7773              :         }
    7774              : 
    7775          643 :       begin = mark_rvalue_use (begin);
    7776          643 :       end = mark_rvalue_use (end);
    7777          643 :       step = mark_rvalue_use (step);
    7778          643 :       begin = cp_build_c_cast (input_location, type, begin,
    7779              :                                tf_warning_or_error);
    7780          643 :       end = cp_build_c_cast (input_location, type, end,
    7781              :                              tf_warning_or_error);
    7782          643 :       orig_step = step;
    7783          643 :       if (!processing_template_decl)
    7784          566 :         step = orig_step = save_expr (step);
    7785          643 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
    7786          643 :       step = cp_build_c_cast (input_location, stype, step,
    7787              :                               tf_warning_or_error);
    7788          643 :       if (POINTER_TYPE_P (type) && !processing_template_decl)
    7789              :         {
    7790           66 :           begin = save_expr (begin);
    7791           66 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
    7792           66 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
    7793              :                                   fold_convert (sizetype, step),
    7794              :                                   fold_convert (sizetype, begin));
    7795           66 :           step = fold_convert (ssizetype, step);
    7796              :         }
    7797          643 :       if (!processing_template_decl)
    7798              :         {
    7799          566 :           begin = maybe_constant_value (begin);
    7800          566 :           end = maybe_constant_value (end);
    7801          566 :           step = maybe_constant_value (step);
    7802          566 :           orig_step = maybe_constant_value (orig_step);
    7803              :         }
    7804          643 :       if (integer_zerop (step))
    7805              :         {
    7806           27 :           error_at (loc, "iterator %qD has zero step", var);
    7807           27 :           ret = true;
    7808           27 :           continue;
    7809              :         }
    7810              : 
    7811          616 :       if (begin == error_mark_node
    7812          607 :           || end == error_mark_node
    7813          598 :           || step == error_mark_node
    7814          598 :           || orig_step == error_mark_node)
    7815              :         {
    7816           18 :           ret = true;
    7817           18 :           continue;
    7818              :         }
    7819              : 
    7820          598 :       if (!processing_template_decl)
    7821              :         {
    7822          521 :           begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
    7823          521 :           end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
    7824          521 :           step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
    7825          521 :           orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
    7826              :                                                      orig_step);
    7827              :         }
    7828          598 :       hash_set<tree> pset;
    7829          598 :       tree it2;
    7830          754 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
    7831              :         {
    7832          183 :           tree var2 = OMP_ITERATOR_VAR (it2);
    7833          183 :           tree begin2 = OMP_ITERATOR_BEGIN (it2);
    7834          183 :           tree end2 = OMP_ITERATOR_END (it2);
    7835          183 :           tree step2 = OMP_ITERATOR_STEP (it2);
    7836          183 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
    7837          183 :           if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
    7838              :             {
    7839            9 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
    7840              :                         "begin expression refers to outer iterator %qD", var);
    7841           36 :               break;
    7842              :             }
    7843          174 :           else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
    7844              :             {
    7845            9 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
    7846              :                         "end expression refers to outer iterator %qD", var);
    7847            9 :               break;
    7848              :             }
    7849          165 :           else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
    7850              :             {
    7851            9 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
    7852              :                         "step expression refers to outer iterator %qD", var);
    7853            9 :               break;
    7854              :             }
    7855              :         }
    7856          598 :       if (it2)
    7857              :         {
    7858           27 :           ret = true;
    7859           27 :           continue;
    7860              :         }
    7861          571 :       OMP_ITERATOR_BEGIN (it) = begin;
    7862          571 :       OMP_ITERATOR_END (it) = end;
    7863          571 :       if (processing_template_decl)
    7864           71 :         OMP_ITERATOR_STEP (it) = orig_step;
    7865              :       else
    7866              :         {
    7867          500 :           OMP_ITERATOR_STEP (it) = step;
    7868          500 :           OMP_ITERATOR_ORIG_STEP (it) = orig_step;
    7869              :         }
    7870          598 :     }
    7871          624 :   return ret;
    7872              : }
    7873              : 
    7874              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
    7875              :    Return true if an error has been detected.  */
    7876              : 
    7877              : static bool
    7878        20040 : cp_oacc_check_attachments (tree c)
    7879              : {
    7880        20040 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    7881              :     return false;
    7882              : 
    7883              :   /* OpenACC attach / detach clauses must be pointers.  */
    7884        15338 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    7885        15338 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    7886              :     {
    7887          196 :       tree t = OMP_CLAUSE_DECL (c);
    7888          196 :       tree type;
    7889              : 
    7890          232 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7891           36 :         t = TREE_OPERAND (t, 0);
    7892              : 
    7893          196 :       type = TREE_TYPE (t);
    7894              : 
    7895          196 :       if (TREE_CODE (type) == REFERENCE_TYPE)
    7896           36 :         type = TREE_TYPE (type);
    7897              : 
    7898          196 :       if (TREE_CODE (type) != POINTER_TYPE)
    7899              :         {
    7900           36 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
    7901              :                     user_omp_clause_code_name (c, true));
    7902           36 :           return true;
    7903              :         }
    7904              :     }
    7905              : 
    7906              :   return false;
    7907              : }
    7908              : 
    7909              : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
    7910              :    happened.  */
    7911              : 
    7912              : tree
    7913          813 : cp_finish_omp_init_prefer_type (tree pref_type)
    7914              : {
    7915          813 :   if (processing_template_decl
    7916          741 :       || pref_type == NULL_TREE
    7917          356 :       || TREE_CODE (pref_type) != TREE_LIST)
    7918              :     return pref_type;
    7919              : 
    7920           81 :   tree t = TREE_PURPOSE (pref_type);
    7921           81 :   char *str = const_cast<char *> (TREE_STRING_POINTER (t));
    7922           81 :   tree fr_list = TREE_VALUE (pref_type);
    7923           81 :   int len = TREE_VEC_LENGTH (fr_list);
    7924           81 :   int cnt = 0;
    7925              : 
    7926          270 :   while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
    7927              :     {
    7928          270 :       str++;
    7929          270 :       if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
    7930              :         {
    7931              :           /* Assume a no or a single 'fr'.  */
    7932          150 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7933          150 :           location_t loc = UNKNOWN_LOCATION;
    7934          150 :           tree value = TREE_VEC_ELT (fr_list, cnt);
    7935          150 :           if (value != NULL_TREE && value != error_mark_node)
    7936              :             {
    7937          126 :               loc = EXPR_LOCATION (value);
    7938          126 :               if (value && TREE_CODE (value) == NOP_EXPR)
    7939           39 :                 value = TREE_OPERAND (value, 0);
    7940          126 :               value = cp_fully_fold (value);
    7941              :             }
    7942          126 :           if (value != NULL_TREE && value != error_mark_node)
    7943              :             {
    7944          126 :               if (TREE_CODE (value) != INTEGER_CST
    7945          126 :                   || !tree_fits_shwi_p (value))
    7946            0 :                 error_at (loc,
    7947              :                           "expected string literal or "
    7948              :                           "constant integer expression instead of %qE", value);
    7949              :               else
    7950              :                 {
    7951          126 :                   HOST_WIDE_INT n = tree_to_shwi (value);
    7952          126 :                   if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
    7953              :                     {
    7954           48 :                       warning_at (loc, OPT_Wopenmp,
    7955              :                                   "unknown foreign runtime identifier %qwd", n);
    7956           48 :                       n = GOMP_INTEROP_IFR_UNKNOWN;
    7957              :                     }
    7958          126 :                   str[0] = (char) n;
    7959              :                 }
    7960              :             }
    7961          150 :           str++;
    7962              :         }
    7963          120 :       else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
    7964              :         {
    7965              :           /* Assume a no or a single 'fr'.  */
    7966          120 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7967          120 :           str++;
    7968              :         }
    7969          270 :       str++;
    7970          294 :       while (str[0] != '\0')
    7971           24 :         str += strlen (str) + 1;
    7972          270 :       str++;
    7973          270 :       cnt++;
    7974          270 :       if (cnt >= len)
    7975              :         break;
    7976              :     }
    7977              :   return t;
    7978              : }
    7979              : 
    7980              : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    7981              :    Remove any elements from the list that are invalid.  */
    7982              : 
    7983              : tree
    7984        65669 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
    7985              : {
    7986        65669 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
    7987        65669 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
    7988        65669 :   bitmap_head oacc_reduction_head, is_on_device_head;
    7989        65669 :   tree c, t, *pc;
    7990        65669 :   tree safelen = NULL_TREE;
    7991        65669 :   bool openacc = (ort & C_ORT_ACC) != 0;
    7992        65669 :   bool branch_seen = false;
    7993        65669 :   bool copyprivate_seen = false;
    7994        65669 :   bool ordered_seen = false;
    7995        65669 :   bool order_seen = false;
    7996        65669 :   bool schedule_seen = false;
    7997        65669 :   bool oacc_async = false;
    7998        65669 :   bool indir_component_ref_p = false;
    7999        65669 :   tree last_iterators = NULL_TREE;
    8000        65669 :   bool last_iterators_remove = false;
    8001              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
    8002              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
    8003        65669 :   int reduction_seen = 0;
    8004        65669 :   bool allocate_seen = false;
    8005        65669 :   tree detach_seen = NULL_TREE;
    8006        65669 :   bool mergeable_seen = false;
    8007        65669 :   bool implicit_moved = false;
    8008        65669 :   bool target_in_reduction_seen = false;
    8009        65669 :   bool num_tasks_seen = false;
    8010        65669 :   bool partial_seen = false;
    8011        65669 :   bool init_seen = false;
    8012        65669 :   bool init_use_destroy_seen = false;
    8013        65669 :   tree init_no_targetsync_clause = NULL_TREE;
    8014        65669 :   tree depend_clause = NULL_TREE;
    8015              : 
    8016        65669 :   if (!openacc)
    8017        52849 :     clauses = omp_remove_duplicate_maps (clauses, true);
    8018              : 
    8019        65669 :   bitmap_obstack_initialize (NULL);
    8020        65669 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
    8021        65669 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
    8022        65669 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
    8023        65669 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
    8024              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
    8025        65669 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
    8026        65669 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
    8027        65669 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
    8028              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
    8029              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
    8030        65669 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
    8031        65669 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
    8032              : 
    8033        65669 :   if (openacc)
    8034        28438 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
    8035        16006 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
    8036              :         {
    8037              :           oacc_async = true;
    8038              :           break;
    8039              :         }
    8040              : 
    8041        65669 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
    8042              : 
    8043       168342 :   for (pc = &clauses, c = clauses; c ; c = *pc)
    8044              :     {
    8045       102673 :       bool remove = false;
    8046       102673 :       bool field_ok = false;
    8047              : 
    8048              :       /* We've reached the end of a list of expanded nodes.  Reset the group
    8049              :          start pointer.  */
    8050       102673 :       if (c == grp_sentinel)
    8051              :         {
    8052         6396 :           if (grp_start_p
    8053         6396 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
    8054           96 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
    8055           66 :                  gc = OMP_CLAUSE_CHAIN (gc))
    8056           66 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
    8057              :           grp_start_p = NULL;
    8058              :         }
    8059              : 
    8060       102673 :       switch (OMP_CLAUSE_CODE (c))
    8061              :         {
    8062         2100 :         case OMP_CLAUSE_SHARED:
    8063         2100 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    8064         2100 :           goto check_dup_generic;
    8065         2614 :         case OMP_CLAUSE_PRIVATE:
    8066         2614 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    8067         2614 :           goto check_dup_generic;
    8068         7895 :         case OMP_CLAUSE_REDUCTION:
    8069         7895 :           if (reduction_seen == 0)
    8070         6764 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
    8071         1131 :           else if (reduction_seen != -2
    8072         2262 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
    8073         1131 :                                          ? -1 : 1))
    8074              :             {
    8075            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8076              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
    8077              :                         "on the same construct");
    8078            6 :               reduction_seen = -2;
    8079              :             }
    8080              :           /* FALLTHRU */
    8081        10064 :         case OMP_CLAUSE_IN_REDUCTION:
    8082        10064 :         case OMP_CLAUSE_TASK_REDUCTION:
    8083        10064 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    8084        10064 :           t = OMP_CLAUSE_DECL (c);
    8085        10064 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    8086              :             {
    8087         2321 :               if (handle_omp_array_sections (c, ort))
    8088              :                 {
    8089              :                   remove = true;
    8090              :                   break;
    8091              :                 }
    8092         2279 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    8093         2279 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
    8094              :                 {
    8095            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8096              :                             "%<inscan%> %<reduction%> clause with array "
    8097              :                             "section");
    8098            3 :                   remove = true;
    8099            3 :                   break;
    8100              :                 }
    8101         2276 :               if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    8102              :                 {
    8103         4900 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    8104         2624 :                     t = TREE_OPERAND (t, 0);
    8105              :                 }
    8106              :               else
    8107              :                 {
    8108            0 :                   gcc_assert (TREE_CODE (t) == MEM_REF);
    8109            0 :                   t = TREE_OPERAND (t, 0);
    8110            0 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
    8111            0 :                     t = TREE_OPERAND (t, 0);
    8112            0 :                   if (TREE_CODE (t) == ADDR_EXPR
    8113            0 :                       || INDIRECT_REF_P (t))
    8114            0 :                     t = TREE_OPERAND (t, 0);
    8115              :                 }
    8116         2276 :               tree n = omp_clause_decl_field (t);
    8117         2276 :               if (n)
    8118           59 :                 t = n;
    8119         2276 :               goto check_dup_generic_t;
    8120              :             }
    8121         7743 :           if (oacc_async)
    8122            7 :             cxx_mark_addressable (t);
    8123         7743 :           goto check_dup_generic;
    8124           98 :         case OMP_CLAUSE_COPYPRIVATE:
    8125           98 :           copyprivate_seen = true;
    8126           98 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    8127           98 :           goto check_dup_generic;
    8128          280 :         case OMP_CLAUSE_COPYIN:
    8129          280 :           goto check_dup_generic;
    8130         1634 :         case OMP_CLAUSE_LINEAR:
    8131         1634 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    8132         1634 :           t = OMP_CLAUSE_DECL (c);
    8133         1634 :           if (ort != C_ORT_OMP_DECLARE_SIMD
    8134         1634 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
    8135              :             {
    8136           84 :               if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
    8137              :                 {
    8138           42 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8139              :                             "modifier should not be specified in %<linear%> "
    8140              :                             "clause on %<simd%> or %<for%> constructs when "
    8141              :                             "not using OpenMP 5.2 modifiers");
    8142           42 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8143              :                 }
    8144           42 :               else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
    8145              :                 {
    8146           18 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8147              :                             "modifier other than %<val%> specified in "
    8148              :                             "%<linear%> clause on %<simd%> or %<for%> "
    8149              :                             "constructs when using OpenMP 5.2 modifiers");
    8150           18 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    8151              :                 }
    8152              :             }
    8153         1011 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    8154         2574 :               && !type_dependent_expression_p (t))
    8155              :             {
    8156         1532 :               tree type = TREE_TYPE (t);
    8157         1532 :               if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8158         1451 :                    || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
    8159         1601 :                   && !TYPE_REF_P (type))
    8160              :                 {
    8161           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8162              :                             "linear clause with %qs modifier applied to "
    8163              :                             "non-reference variable with %qT type",
    8164           12 :                             OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    8165           12 :                             ? "ref" : "uval", TREE_TYPE (t));
    8166           12 :                   remove = true;
    8167           12 :                   break;
    8168              :                 }
    8169         1520 :               if (TYPE_REF_P (type))
    8170          281 :                 type = TREE_TYPE (type);
    8171         1520 :               if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
    8172              :                 {
    8173         1445 :                   if (!INTEGRAL_TYPE_P (type)
    8174           85 :                       && !TYPE_PTR_P (type))
    8175              :                     {
    8176           18 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8177              :                                 "linear clause applied to non-integral "
    8178              :                                 "non-pointer variable with %qT type",
    8179           18 :                                 TREE_TYPE (t));
    8180           18 :                       remove = true;
    8181           18 :                       break;
    8182              :                     }
    8183              :                 }
    8184              :             }
    8185         1604 :           t = OMP_CLAUSE_LINEAR_STEP (c);
    8186         1604 :           if (t == NULL_TREE)
    8187            6 :             t = integer_one_node;
    8188         1604 :           if (t == error_mark_node)
    8189              :             {
    8190              :               remove = true;
    8191              :               break;
    8192              :             }
    8193         1604 :           else if (!type_dependent_expression_p (t)
    8194         1602 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t))
    8195         1616 :                    && (ort != C_ORT_OMP_DECLARE_SIMD
    8196            9 :                        || TREE_CODE (t) != PARM_DECL
    8197            6 :                        || !TYPE_REF_P (TREE_TYPE (t))
    8198            6 :                        || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
    8199              :             {
    8200            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8201              :                         "linear step expression must be integral");
    8202            6 :               remove = true;
    8203            6 :               break;
    8204              :             }
    8205              :           else
    8206              :             {
    8207         1598 :               t = mark_rvalue_use (t);
    8208         1598 :               if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
    8209              :                 {
    8210           42 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
    8211           42 :                   goto check_dup_generic;
    8212              :                 }
    8213         1556 :               if (!processing_template_decl
    8214         1556 :                   && (VAR_P (OMP_CLAUSE_DECL (c))
    8215          835 :                       || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
    8216              :                 {
    8217         1375 :                   if (ort == C_ORT_OMP_DECLARE_SIMD)
    8218              :                     {
    8219          589 :                       t = maybe_constant_value (t);
    8220          589 :                       if (TREE_CODE (t) != INTEGER_CST)
    8221              :                         {
    8222            6 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8223              :                                     "%<linear%> clause step %qE is neither "
    8224              :                                      "constant nor a parameter", t);
    8225            6 :                           remove = true;
    8226            6 :                           break;
    8227              :                         }
    8228              :                     }
    8229         1369 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8230         1369 :                   tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
    8231         1369 :                   if (TYPE_REF_P (type))
    8232          257 :                     type = TREE_TYPE (type);
    8233         1369 :                   if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
    8234              :                     {
    8235           66 :                       type = build_pointer_type (type);
    8236           66 :                       tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
    8237           66 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8238              :                                            d, t);
    8239           66 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8240              :                                            MINUS_EXPR, sizetype,
    8241              :                                            fold_convert (sizetype, t),
    8242              :                                            fold_convert (sizetype, d));
    8243           66 :                       if (t == error_mark_node)
    8244              :                         {
    8245              :                           remove = true;
    8246              :                           break;
    8247              :                         }
    8248              :                     }
    8249         1303 :                   else if (TYPE_PTR_P (type)
    8250              :                            /* Can't multiply the step yet if *this
    8251              :                               is still incomplete type.  */
    8252         1303 :                            && (ort != C_ORT_OMP_DECLARE_SIMD
    8253           45 :                                || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
    8254           45 :                                || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
    8255           30 :                                || DECL_NAME (OMP_CLAUSE_DECL (c))
    8256           30 :                                   != this_identifier
    8257           30 :                                || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
    8258              :                     {
    8259           37 :                       tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
    8260           37 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8261              :                                            d, t);
    8262           37 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8263              :                                            MINUS_EXPR, sizetype,
    8264              :                                            fold_convert (sizetype, t),
    8265              :                                            fold_convert (sizetype, d));
    8266           37 :                       if (t == error_mark_node)
    8267              :                         {
    8268              :                           remove = true;
    8269              :                           break;
    8270              :                         }
    8271              :                     }
    8272              :                   else
    8273         1266 :                     t = fold_convert (type, t);
    8274              :                 }
    8275         1550 :               OMP_CLAUSE_LINEAR_STEP (c) = t;
    8276              :             }
    8277         1550 :           goto check_dup_generic;
    8278        15393 :         check_dup_generic:
    8279        15393 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8280        15393 :           if (t)
    8281              :             {
    8282          101 :               if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
    8283          101 :                 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8284              :             }
    8285              :           else
    8286        15292 :             t = OMP_CLAUSE_DECL (c);
    8287        17936 :         check_dup_generic_t:
    8288        17936 :           if (t == current_class_ptr
    8289        17936 :               && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
    8290          102 :                   || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
    8291           72 :                       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
    8292              :             {
    8293           24 :               error_at (OMP_CLAUSE_LOCATION (c),
    8294              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8295              :                         " clauses");
    8296           24 :               remove = true;
    8297           24 :               break;
    8298              :             }
    8299        17912 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8300          586 :               && (!field_ok || TREE_CODE (t) != FIELD_DECL))
    8301              :             {
    8302           59 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8303              :                 break;
    8304           39 :               if (DECL_P (t))
    8305           30 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8306              :                           "%qD is not a variable in clause %qs", t,
    8307           15 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8308              :               else
    8309           48 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8310              :                           "%qE is not a variable in clause %qs", t,
    8311           24 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8312              :               remove = true;
    8313              :             }
    8314        17853 :           else if ((openacc
    8315         2707 :                     && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
    8316        15384 :                    || (ort == C_ORT_OMP
    8317        13051 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    8318        13020 :                            || (OMP_CLAUSE_CODE (c)
    8319              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
    8320        33130 :                    || (ort == C_ORT_OMP_TARGET
    8321          938 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
    8322              :             {
    8323         2854 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    8324         2854 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
    8325          275 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
    8326              :                 {
    8327            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8328              :                             "%qD appears more than once in data-sharing "
    8329              :                             "clauses", t);
    8330            6 :                   remove = true;
    8331            6 :                   break;
    8332              :                 }
    8333         2848 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
    8334          272 :                 target_in_reduction_seen = true;
    8335         2848 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8336              :                 {
    8337           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8338              :                             openacc
    8339              :                             ? "%qD appears more than once in reduction clauses"
    8340              :                             : "%qD appears more than once in data clauses",
    8341              :                             t);
    8342            6 :                   remove = true;
    8343              :                 }
    8344              :               else
    8345         2842 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8346              :             }
    8347        14999 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8348        14926 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8349        14923 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
    8350        29922 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8351              :             {
    8352           76 :               error_at (OMP_CLAUSE_LOCATION (c),
    8353              :                         "%qD appears more than once in data clauses", t);
    8354           76 :               remove = true;
    8355              :             }
    8356        14923 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    8357              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
    8358              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    8359         3155 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
    8360              :             {
    8361            9 :               if (openacc)
    8362            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8363              :                           "%qD appears more than once in data clauses", t);
    8364              :               else
    8365            9 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8366              :                           "%qD appears both in data and map clauses", t);
    8367              :               remove = true;
    8368              :             }
    8369              :           else
    8370        14914 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    8371        17886 :           if (!field_ok)
    8372              :             break;
    8373        13475 :         handle_field_decl:
    8374        22597 :           if (!remove
    8375        22402 :               && TREE_CODE (t) == FIELD_DECL
    8376        17344 :               && t == OMP_CLAUSE_DECL (c))
    8377              :             {
    8378          795 :               OMP_CLAUSE_DECL (c)
    8379          795 :                 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
    8380              :                                            == OMP_CLAUSE_SHARED));
    8381          795 :               if (OMP_CLAUSE_DECL (c) == error_mark_node)
    8382       102065 :                 remove = true;
    8383              :             }
    8384              :           break;
    8385              : 
    8386         3786 :         case OMP_CLAUSE_FIRSTPRIVATE:
    8387         3786 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
    8388              :             {
    8389          553 :             move_implicit:
    8390          553 :               implicit_moved = true;
    8391              :               /* Move firstprivate and map clauses with
    8392              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
    8393              :                  clauses chain.  */
    8394          553 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
    8395          553 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
    8396         3030 :               while (*pc1)
    8397         2477 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
    8398         2477 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
    8399              :                   {
    8400          343 :                     *pc3 = *pc1;
    8401          343 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
    8402          343 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8403              :                   }
    8404         2134 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
    8405         2134 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
    8406              :                   {
    8407          483 :                     *pc2 = *pc1;
    8408          483 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
    8409          483 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8410              :                   }
    8411              :                 else
    8412         1651 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
    8413          553 :               *pc3 = NULL;
    8414          553 :               *pc2 = cl2;
    8415          553 :               *pc1 = cl1;
    8416          553 :               continue;
    8417          553 :             }
    8418         3501 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8419         3501 :           if (t)
    8420           69 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8421              :           else
    8422         3432 :             t = OMP_CLAUSE_DECL (c);
    8423         3501 :           if (!openacc && t == current_class_ptr)
    8424              :             {
    8425            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8426              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8427              :                         " clauses");
    8428            6 :               remove = true;
    8429            6 :               break;
    8430              :             }
    8431         3495 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8432          333 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8433          333 :                   || TREE_CODE (t) != FIELD_DECL))
    8434              :             {
    8435           41 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8436              :                 break;
    8437           18 :               if (DECL_P (t))
    8438           12 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8439              :                           "%qD is not a variable in clause %<firstprivate%>",
    8440              :                           t);
    8441              :               else
    8442            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8443              :                           "%qE is not a variable in clause %<firstprivate%>",
    8444              :                           t);
    8445              :               remove = true;
    8446              :             }
    8447         3454 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8448          343 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
    8449         3754 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8450              :             remove = true;
    8451         3454 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8452         3445 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8453         6896 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8454              :             {
    8455           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    8456              :                         "%qD appears more than once in data clauses", t);
    8457           15 :               remove = true;
    8458              :             }
    8459         3439 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
    8460         3439 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
    8461              :             {
    8462           21 :               if (openacc)
    8463            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8464              :                           "%qD appears more than once in data clauses", t);
    8465           21 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8466           21 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
    8467              :                 /* Silently drop the clause.  */;
    8468              :               else
    8469           18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8470              :                           "%qD appears both in data and map clauses", t);
    8471              :               remove = true;
    8472              :             }
    8473              :           else
    8474         3418 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
    8475         3472 :           goto handle_field_decl;
    8476              : 
    8477         2889 :         case OMP_CLAUSE_LASTPRIVATE:
    8478         2889 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8479         2889 :           if (t)
    8480           35 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8481              :           else
    8482         2854 :             t = OMP_CLAUSE_DECL (c);
    8483         2889 :           if (!openacc && t == current_class_ptr)
    8484              :             {
    8485            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8486              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8487              :                         " clauses");
    8488            6 :               remove = true;
    8489            6 :               break;
    8490              :             }
    8491         2883 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8492          259 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8493          259 :                   || TREE_CODE (t) != FIELD_DECL))
    8494              :             {
    8495           35 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8496              :                 break;
    8497            9 :               if (DECL_P (t))
    8498            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8499              :                           "%qD is not a variable in clause %<lastprivate%>",
    8500              :                           t);
    8501              :               else
    8502            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8503              :                           "%qE is not a variable in clause %<lastprivate%>",
    8504              :                           t);
    8505              :               remove = true;
    8506              :             }
    8507         2848 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8508         2848 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
    8509              :             {
    8510           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8511              :                         "%qD appears more than once in data clauses", t);
    8512           12 :               remove = true;
    8513              :             }
    8514              :           else
    8515         2836 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
    8516         2857 :           goto handle_field_decl;
    8517              : 
    8518         2229 :         case OMP_CLAUSE_IF:
    8519         2229 :         case OMP_CLAUSE_SELF:
    8520         2229 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8521         2229 :           t = maybe_convert_cond (t);
    8522         2229 :           if (t == error_mark_node)
    8523              :             remove = true;
    8524         2214 :           else if (!processing_template_decl)
    8525         2151 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8526         2229 :           OMP_CLAUSE_OPERAND (c, 0) = t;
    8527         2229 :           break;
    8528              : 
    8529          289 :         case OMP_CLAUSE_FINAL:
    8530          289 :           t = OMP_CLAUSE_FINAL_EXPR (c);
    8531          289 :           t = maybe_convert_cond (t);
    8532          289 :           if (t == error_mark_node)
    8533              :             remove = true;
    8534          289 :           else if (!processing_template_decl)
    8535          283 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8536          289 :           OMP_CLAUSE_FINAL_EXPR (c) = t;
    8537          289 :           break;
    8538              : 
    8539           92 :         case OMP_CLAUSE_NOCONTEXT:
    8540           92 :           t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
    8541           92 :           t = maybe_convert_cond (t);
    8542           92 :           if (t == error_mark_node)
    8543              :             remove = true;
    8544           89 :           else if (!processing_template_decl)
    8545           83 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8546           92 :           OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
    8547           92 :           break;
    8548              : 
    8549           80 :         case OMP_CLAUSE_NOVARIANTS:
    8550           80 :           t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
    8551           80 :           t = maybe_convert_cond (t);
    8552           80 :           if (t == error_mark_node)
    8553              :             remove = true;
    8554           77 :           else if (!processing_template_decl)
    8555           71 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8556           80 :           OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
    8557           80 :           break;
    8558              : 
    8559         1249 :         case OMP_CLAUSE_GANG:
    8560              :           /* Operand 1 is the gang static: argument.  */
    8561         1249 :           t = OMP_CLAUSE_OPERAND (c, 1);
    8562         1249 :           if (t != NULL_TREE)
    8563              :             {
    8564          129 :               if (t == error_mark_node)
    8565              :                 remove = true;
    8566          129 :               else if (!type_dependent_expression_p (t)
    8567          129 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8568              :                 {
    8569            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8570              :                             "%<gang%> static expression must be integral");
    8571            6 :                   remove = true;
    8572              :                 }
    8573              :               else
    8574              :                 {
    8575          123 :                   t = mark_rvalue_use (t);
    8576          123 :                   if (!processing_template_decl)
    8577              :                     {
    8578          123 :                       t = maybe_constant_value (t);
    8579          123 :                       if (TREE_CODE (t) == INTEGER_CST
    8580          109 :                           && tree_int_cst_sgn (t) != 1
    8581          176 :                           && t != integer_minus_one_node)
    8582              :                         {
    8583            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8584              :                                       "%<gang%> static value must be "
    8585              :                                       "positive");
    8586            0 :                           t = integer_one_node;
    8587              :                         }
    8588          123 :                       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8589              :                     }
    8590              :                 }
    8591          129 :               OMP_CLAUSE_OPERAND (c, 1) = t;
    8592              :             }
    8593              :           /* Check operand 0, the num argument.  */
    8594              :           /* FALLTHRU */
    8595              : 
    8596         3480 :         case OMP_CLAUSE_WORKER:
    8597         3480 :         case OMP_CLAUSE_VECTOR:
    8598         3480 :           if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
    8599              :             break;
    8600              :           /* FALLTHRU */
    8601              : 
    8602          484 :         case OMP_CLAUSE_NUM_TASKS:
    8603          484 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
    8604          136 :             num_tasks_seen = true;
    8605              :           /* FALLTHRU */
    8606              : 
    8607         3063 :         case OMP_CLAUSE_NUM_TEAMS:
    8608         3063 :         case OMP_CLAUSE_NUM_THREADS:
    8609         3063 :         case OMP_CLAUSE_NUM_GANGS:
    8610         3063 :         case OMP_CLAUSE_NUM_WORKERS:
    8611         3063 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
    8612         3063 :         case OMP_CLAUSE_VECTOR_LENGTH:
    8613         3063 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8614         3063 :           if (t == error_mark_node)
    8615              :             remove = true;
    8616         3063 :           else if (!type_dependent_expression_p (t)
    8617         3063 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8618              :             {
    8619           99 :              switch (OMP_CLAUSE_CODE (c))
    8620              :                 {
    8621           12 :                 case OMP_CLAUSE_GANG:
    8622           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8623           12 :                             "%<gang%> num expression must be integral"); break;
    8624           12 :                 case OMP_CLAUSE_VECTOR:
    8625           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8626              :                             "%<vector%> length expression must be integral");
    8627           12 :                   break;
    8628           12 :                 case OMP_CLAUSE_WORKER:
    8629           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8630              :                             "%<worker%> num expression must be integral");
    8631           12 :                   break;
    8632           63 :                 default:
    8633           63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8634              :                             "%qs expression must be integral",
    8635           63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8636              :                 }
    8637              :               remove = true;
    8638              :             }
    8639              :           else
    8640              :             {
    8641         2964 :               t = mark_rvalue_use (t);
    8642         2964 :               if (!processing_template_decl)
    8643              :                 {
    8644         2716 :                   t = maybe_constant_value (t);
    8645         2716 :                   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
    8646         2681 :                       && TREE_CODE (t) == INTEGER_CST
    8647         4192 :                       && tree_int_cst_sgn (t) != 1)
    8648              :                     {
    8649           85 :                       switch (OMP_CLAUSE_CODE (c))
    8650              :                         {
    8651            3 :                         case OMP_CLAUSE_GANG:
    8652            3 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8653              :                                       "%<gang%> num value must be positive");
    8654            3 :                           break;
    8655            0 :                         case OMP_CLAUSE_VECTOR:
    8656            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8657              :                                       "%<vector%> length value must be "
    8658              :                                       "positive");
    8659            0 :                           break;
    8660            0 :                         case OMP_CLAUSE_WORKER:
    8661            0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8662              :                                       "%<worker%> num value must be "
    8663              :                                       "positive");
    8664            0 :                           break;
    8665           82 :                         default:
    8666           82 :                           warning_at (OMP_CLAUSE_LOCATION (c),
    8667           46 :                                       (flag_openmp || flag_openmp_simd)
    8668           82 :                                       ? OPT_Wopenmp : 0,
    8669              :                                       "%qs value must be positive",
    8670              :                                       omp_clause_code_name
    8671           82 :                                       [OMP_CLAUSE_CODE (c)]);
    8672              :                         }
    8673           85 :                       t = integer_one_node;
    8674              :                     }
    8675         2631 :                   else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
    8676           35 :                            && TREE_CODE (t) == INTEGER_CST
    8677         2654 :                            && tree_int_cst_sgn (t) < 0)
    8678              :                     {
    8679            8 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8680              :                                   "%<dyn_groupprivate%> value must be "
    8681              :                                   "non-negative");
    8682            8 :                       t = integer_zero_node;
    8683              :                     }
    8684         2716 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8685              :                 }
    8686         2964 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8687              :             }
    8688         3063 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
    8689          767 :               && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
    8690         3342 :               && !remove)
    8691              :             {
    8692          279 :               t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
    8693          279 :               if (t == error_mark_node)
    8694              :                 remove = true;
    8695          279 :               else if (!type_dependent_expression_p (t)
    8696          279 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8697              :                 {
    8698            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8699              :                             "%qs expression must be integral",
    8700            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8701            0 :                   remove = true;
    8702              :                 }
    8703              :               else
    8704              :                 {
    8705          279 :                   t = mark_rvalue_use (t);
    8706          279 :                   if (!processing_template_decl)
    8707              :                     {
    8708          213 :                       t = maybe_constant_value (t);
    8709          213 :                       if (TREE_CODE (t) == INTEGER_CST
    8710          213 :                           && tree_int_cst_sgn (t) != 1)
    8711              :                         {
    8712           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8713              :                                       "%qs value must be positive",
    8714              :                                       omp_clause_code_name
    8715           18 :                                       [OMP_CLAUSE_CODE (c)]);
    8716           18 :                           t = NULL_TREE;
    8717              :                         }
    8718              :                       else
    8719          195 :                         t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8720          213 :                       tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
    8721          213 :                       if (t
    8722          195 :                           && TREE_CODE (t) == INTEGER_CST
    8723           43 :                           && TREE_CODE (upper) == INTEGER_CST
    8724          250 :                           && tree_int_cst_lt (upper, t))
    8725              :                         {
    8726           18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8727              :                                       "%<num_teams%> lower bound %qE bigger "
    8728              :                                       "than upper bound %qE", t, upper);
    8729           18 :                           t = NULL_TREE;
    8730              :                         }
    8731              :                     }
    8732          279 :                   OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
    8733              :                 }
    8734              :             }
    8735              :           break;
    8736              : 
    8737         3896 :         case OMP_CLAUSE_SCHEDULE:
    8738         3896 :           t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
    8739         3896 :           if (t == NULL)
    8740              :             ;
    8741         2097 :           else if (t == error_mark_node)
    8742              :             remove = true;
    8743         2097 :           else if (!type_dependent_expression_p (t)
    8744         2097 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8745              :             {
    8746            9 :               error_at (OMP_CLAUSE_LOCATION (c),
    8747              :                         "schedule chunk size expression must be integral");
    8748            9 :               remove = true;
    8749              :             }
    8750              :           else
    8751              :             {
    8752         2088 :               t = mark_rvalue_use (t);
    8753         2088 :               if (!processing_template_decl)
    8754              :                 {
    8755         2048 :                   t = maybe_constant_value (t);
    8756         2048 :                   if (TREE_CODE (t) == INTEGER_CST
    8757         2048 :                       && tree_int_cst_sgn (t) != 1)
    8758              :                   {
    8759            6 :                     warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8760              :                               "chunk size value must be positive");
    8761            6 :                     t = integer_one_node;
    8762              :                   }
    8763         2048 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8764              :                 }
    8765         2088 :               OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
    8766              :             }
    8767         2097 :           if (!remove)
    8768              :             schedule_seen = true;
    8769              :           break;
    8770              : 
    8771          900 :         case OMP_CLAUSE_SIMDLEN:
    8772          900 :           t = OMP_CLAUSE_SIMDLEN_TYPE (c);
    8773          900 :           if (t == error_mark_node)
    8774              :             remove = true;
    8775           75 :           else if (t && !dependent_type_p (t)
    8776          948 :                    && !ARITHMETIC_TYPE_P (t))
    8777              :             {
    8778            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    8779              :                         "expected arithmetic type name as argument to the "
    8780              :                         "%<scaled%> modifier");
    8781            3 :               remove = true;
    8782              :             }
    8783          900 :           t = OMP_CLAUSE_SIMDLEN_DIVISOR (c);
    8784          900 :           if (t == error_mark_node)
    8785              :             remove = true;
    8786           54 :           else if (t && !type_dependent_expression_p (t)
    8787          953 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8788              :             {
    8789            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8790              :                         "%qs divisor expression of the %<scaled%> modifier "
    8791              :                         "must be integral",
    8792            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8793            0 :               remove = true;
    8794              :             }
    8795          899 :           else if (t)
    8796              :             {
    8797           54 :               t = mark_rvalue_use (t);
    8798           54 :               if (!processing_template_decl)
    8799              :                 {
    8800           40 :                   t = maybe_constant_value (t);
    8801           40 :                   if (TREE_CODE (t) != INTEGER_CST
    8802           40 :                       || tree_int_cst_sgn (t) != 1)
    8803              :                     {
    8804           16 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8805              :                                 "%qs divisor expression of the %<scaled%> "
    8806              :                                 "modifier must be a positive constant integer "
    8807              :                                 "expression",
    8808            8 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8809            8 :                       remove = true;
    8810              :                     }
    8811              :                 }
    8812           54 :               OMP_CLAUSE_SIMDLEN_DIVISOR (c) = t;
    8813              :             }
    8814              :           /* FALLTHRU */
    8815         1410 :         case OMP_CLAUSE_SAFELEN:
    8816         1410 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8817         1410 :           if (t == error_mark_node)
    8818              :             remove = true;
    8819         1404 :           else if (!type_dependent_expression_p (t)
    8820         1404 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8821              :             {
    8822            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8823              :                         "%qs length expression must be integral",
    8824            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8825            0 :               remove = true;
    8826              :             }
    8827              :           else
    8828              :             {
    8829         1404 :               t = mark_rvalue_use (t);
    8830         1404 :               if (!processing_template_decl)
    8831              :                 {
    8832         1337 :                   t = maybe_constant_value (t);
    8833         1337 :                   if (TREE_CODE (t) != INTEGER_CST
    8834         1337 :                       || tree_int_cst_sgn (t) != 1)
    8835              :                     {
    8836            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8837              :                                 "%qs length expression must be positive "
    8838              :                                 "constant integer expression",
    8839            0 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8840            0 :                       remove = true;
    8841              :                     }
    8842              :                 }
    8843         1404 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8844         1404 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
    8845          510 :                 safelen = c;
    8846              :             }
    8847              :           break;
    8848              : 
    8849          388 :         case OMP_CLAUSE_ASYNC:
    8850          388 :           t = OMP_CLAUSE_ASYNC_EXPR (c);
    8851          388 :           if (t == error_mark_node)
    8852              :             remove = true;
    8853          373 :           else if (!type_dependent_expression_p (t)
    8854          373 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8855              :             {
    8856           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8857              :                         "%<async%> expression must be integral");
    8858           12 :               remove = true;
    8859              :             }
    8860              :           else
    8861              :             {
    8862          361 :               t = mark_rvalue_use (t);
    8863          361 :               if (!processing_template_decl)
    8864          352 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8865          361 :               OMP_CLAUSE_ASYNC_EXPR (c) = t;
    8866              :             }
    8867              :           break;
    8868              : 
    8869          204 :         case OMP_CLAUSE_WAIT:
    8870          204 :           t = OMP_CLAUSE_WAIT_EXPR (c);
    8871          204 :           if (t == error_mark_node)
    8872              :             remove = true;
    8873          204 :           else if (!processing_template_decl)
    8874          196 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8875          204 :           OMP_CLAUSE_WAIT_EXPR (c) = t;
    8876          204 :           break;
    8877              : 
    8878          637 :         case OMP_CLAUSE_THREAD_LIMIT:
    8879          637 :           t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
    8880          637 :           if (t == error_mark_node)
    8881              :             remove = true;
    8882          637 :           else if (!type_dependent_expression_p (t)
    8883          637 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8884              :             {
    8885            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8886              :                         "%<thread_limit%> expression must be integral");
    8887            0 :               remove = true;
    8888              :             }
    8889              :           else
    8890              :             {
    8891          637 :               t = mark_rvalue_use (t);
    8892          637 :               if (!processing_template_decl)
    8893              :                 {
    8894          583 :                   t = maybe_constant_value (t);
    8895          583 :                   if (TREE_CODE (t) == INTEGER_CST
    8896          583 :                       && tree_int_cst_sgn (t) != 1)
    8897              :                     {
    8898            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8899              :                                   "%<thread_limit%> value must be positive");
    8900            0 :                       t = integer_one_node;
    8901              :                     }
    8902          583 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8903              :                 }
    8904          637 :               OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
    8905              :             }
    8906              :           break;
    8907              : 
    8908          770 :         case OMP_CLAUSE_DEVICE:
    8909          770 :           t = OMP_CLAUSE_DEVICE_ID (c);
    8910          770 :           if (t == error_mark_node)
    8911              :             remove = true;
    8912          770 :           else if (!type_dependent_expression_p (t)
    8913          770 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8914              :             {
    8915            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8916              :                         "%<device%> id must be integral");
    8917            6 :               remove = true;
    8918              :             }
    8919          764 :           else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
    8920           66 :                    && TREE_CODE (t) == INTEGER_CST
    8921          824 :                    && !integer_onep (t))
    8922              :             {
    8923            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    8924              :                         "the %<device%> clause expression must evaluate to "
    8925              :                         "%<1%>");
    8926            3 :               remove = true;
    8927              :             }
    8928              :           else
    8929              :             {
    8930          761 :               t = mark_rvalue_use (t);
    8931          761 :               if (!processing_template_decl)
    8932          750 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8933          761 :               OMP_CLAUSE_DEVICE_ID (c) = t;
    8934              :             }
    8935              :           break;
    8936              : 
    8937         1856 :         case OMP_CLAUSE_DIST_SCHEDULE:
    8938         1856 :           t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
    8939         1856 :           if (t == NULL)
    8940              :             ;
    8941         1835 :           else if (t == error_mark_node)
    8942              :             remove = true;
    8943         1835 :           else if (!type_dependent_expression_p (t)
    8944         1835 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8945              :             {
    8946            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8947              :                         "%<dist_schedule%> chunk size expression must be "
    8948              :                         "integral");
    8949            0 :               remove = true;
    8950              :             }
    8951              :           else
    8952              :             {
    8953         1835 :               t = mark_rvalue_use (t);
    8954         1835 :               if (!processing_template_decl)
    8955         1835 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8956         1835 :               OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
    8957              :             }
    8958              :           break;
    8959              : 
    8960          807 :         case OMP_CLAUSE_ALIGNED:
    8961          807 :           t = OMP_CLAUSE_DECL (c);
    8962          807 :           if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
    8963              :             {
    8964            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8965              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8966              :                         " clauses");
    8967            0 :               remove = true;
    8968            0 :               break;
    8969              :             }
    8970          807 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8971              :             {
    8972            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8973              :                 break;
    8974            0 :               if (DECL_P (t))
    8975            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8976              :                           "%qD is not a variable in %<aligned%> clause", t);
    8977              :               else
    8978            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8979              :                           "%qE is not a variable in %<aligned%> clause", t);
    8980              :               remove = true;
    8981              :             }
    8982          807 :           else if (!type_dependent_expression_p (t)
    8983          789 :                    && !TYPE_PTR_P (TREE_TYPE (t))
    8984          111 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    8985          864 :                    && (!TYPE_REF_P (TREE_TYPE (t))
    8986           39 :                        || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
    8987           30 :                            && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
    8988              :                                != ARRAY_TYPE))))
    8989              :             {
    8990           33 :               error_at (OMP_CLAUSE_LOCATION (c),
    8991              :                         "%qE in %<aligned%> clause is neither a pointer nor "
    8992              :                         "an array nor a reference to pointer or array", t);
    8993           33 :               remove = true;
    8994              :             }
    8995          774 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8996              :             {
    8997            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8998              :                         "%qD appears more than once in %<aligned%> clauses",
    8999              :                         t);
    9000            0 :               remove = true;
    9001              :             }
    9002              :           else
    9003          774 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
    9004          807 :           t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
    9005          807 :           if (t == error_mark_node)
    9006              :             remove = true;
    9007          807 :           else if (t == NULL_TREE)
    9008              :             break;
    9009          744 :           else if (!type_dependent_expression_p (t)
    9010          744 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9011              :             {
    9012            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9013              :                         "%<aligned%> clause alignment expression must "
    9014              :                         "be integral");
    9015            0 :               remove = true;
    9016              :             }
    9017              :           else
    9018              :             {
    9019          744 :               t = mark_rvalue_use (t);
    9020          744 :               if (!processing_template_decl)
    9021              :                 {
    9022          690 :                   t = maybe_constant_value (t);
    9023          690 :                   if (TREE_CODE (t) != INTEGER_CST
    9024          690 :                       || tree_int_cst_sgn (t) != 1)
    9025              :                     {
    9026            0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9027              :                                 "%<aligned%> clause alignment expression must "
    9028              :                                 "be positive constant integer expression");
    9029            0 :                       remove = true;
    9030              :                     }
    9031              :                 }
    9032          744 :               OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
    9033              :             }
    9034              :           break;
    9035              : 
    9036          369 :         case OMP_CLAUSE_NONTEMPORAL:
    9037          369 :           t = OMP_CLAUSE_DECL (c);
    9038          369 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    9039              :             {
    9040            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9041              :                 break;
    9042            0 :               if (DECL_P (t))
    9043            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9044              :                           "%qD is not a variable in %<nontemporal%> clause",
    9045              :                           t);
    9046              :               else
    9047            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9048              :                           "%qE is not a variable in %<nontemporal%> clause",
    9049              :                           t);
    9050              :               remove = true;
    9051              :             }
    9052          369 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    9053              :             {
    9054            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9055              :                         "%qD appears more than once in %<nontemporal%> "
    9056              :                         "clauses", t);
    9057            6 :               remove = true;
    9058              :             }
    9059              :           else
    9060          363 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    9061              :           break;
    9062              : 
    9063         2809 :         case OMP_CLAUSE_ALLOCATE:
    9064         2809 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    9065         2809 :           if (t)
    9066           14 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    9067              :           else
    9068         2795 :             t = OMP_CLAUSE_DECL (c);
    9069         2809 :           if (t == current_class_ptr)
    9070              :             {
    9071            0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9072              :                         "%<this%> not allowed in %<allocate%> clause");
    9073            0 :               remove = true;
    9074            0 :               break;
    9075              :             }
    9076         2809 :           if (!VAR_P (t)
    9077          678 :               && TREE_CODE (t) != PARM_DECL
    9078           45 :               && TREE_CODE (t) != FIELD_DECL)
    9079              :             {
    9080            3 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9081              :                 break;
    9082            3 :               if (DECL_P (t))
    9083            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9084              :                           "%qD is not a variable in %<allocate%> clause", t);
    9085              :               else
    9086            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9087              :                           "%qE is not a variable in %<allocate%> clause", t);
    9088              :               remove = true;
    9089              :             }
    9090         2806 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    9091              :             {
    9092           12 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9093              :                         "%qD appears more than once in %<allocate%> clauses",
    9094              :                         t);
    9095           12 :               remove = true;
    9096              :             }
    9097              :           else
    9098              :             {
    9099         2794 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
    9100         2794 :               allocate_seen = true;
    9101              :             }
    9102         2809 :           tree allocator, align;
    9103         2809 :           align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
    9104         2809 :           if (error_operand_p (align))
    9105              :             {
    9106              :               remove = true;
    9107              :               break;
    9108              :             }
    9109         2809 :           if (align)
    9110              :             {
    9111          211 :               if (!type_dependent_expression_p (align)
    9112          211 :                   && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    9113              :                 {
    9114            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9115              :                             "%<allocate%> clause %<align%> modifier "
    9116              :                             "argument needs to be positive constant "
    9117              :                             "power of two integer expression");
    9118            4 :                   remove = true;
    9119              :                 }
    9120              :               else
    9121              :                 {
    9122          207 :                   align = mark_rvalue_use (align);
    9123          207 :                   if (!processing_template_decl)
    9124              :                     {
    9125          192 :                       align = maybe_constant_value (align);
    9126          192 :                       if (TREE_CODE (align) != INTEGER_CST
    9127          189 :                           || !tree_fits_uhwi_p (align)
    9128          381 :                           || !integer_pow2p (align))
    9129              :                         {
    9130           10 :                           error_at (OMP_CLAUSE_LOCATION (c),
    9131              :                                     "%<allocate%> clause %<align%> modifier "
    9132              :                                     "argument needs to be positive constant "
    9133              :                                     "power of two integer expression");
    9134           10 :                           remove = true;
    9135              :                         }
    9136              :                     }
    9137              :                 }
    9138          211 :               OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
    9139              :             }
    9140         2809 :           allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
    9141         2809 :           if (error_operand_p (allocator))
    9142              :             {
    9143              :               remove = true;
    9144              :               break;
    9145              :             }
    9146         2809 :           if (allocator == NULL_TREE)
    9147         1751 :             goto handle_field_decl;
    9148         1058 :           tree allocatort;
    9149         1058 :           allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
    9150         1058 :           if (!type_dependent_expression_p (allocator)
    9151         1058 :               && (TREE_CODE (allocatort) != ENUMERAL_TYPE
    9152         1039 :                   || TYPE_NAME (allocatort) == NULL_TREE
    9153         1039 :                   || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
    9154         2078 :                   || (DECL_NAME (TYPE_NAME (allocatort))
    9155         1039 :                       != get_identifier ("omp_allocator_handle_t"))
    9156         1039 :                   || (TYPE_CONTEXT (allocatort)
    9157         1039 :                       != DECL_CONTEXT (global_namespace))))
    9158              :             {
    9159           16 :               error_at (OMP_CLAUSE_LOCATION (c),
    9160              :                         "%<allocate%> clause allocator expression has "
    9161              :                         "type %qT rather than %<omp_allocator_handle_t%>",
    9162           16 :                         TREE_TYPE (allocator));
    9163           16 :               remove = true;
    9164           16 :               break;
    9165              :             }
    9166              :           else
    9167              :             {
    9168         1042 :               allocator = mark_rvalue_use (allocator);
    9169         1042 :               if (!processing_template_decl)
    9170         1023 :                 allocator = maybe_constant_value (allocator);
    9171         1042 :               OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
    9172              :             }
    9173         1042 :           goto handle_field_decl;
    9174              : 
    9175          654 :         case OMP_CLAUSE_DOACROSS:
    9176          654 :           t = OMP_CLAUSE_DECL (c);
    9177          654 :           if (t == NULL_TREE)
    9178              :             break;
    9179          298 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
    9180              :             {
    9181          298 :               if (cp_finish_omp_clause_doacross_sink (c))
    9182       102065 :                 remove = true;
    9183              :               break;
    9184              :             }
    9185            0 :           gcc_unreachable ();
    9186           89 :         case OMP_CLAUSE_USES_ALLOCATORS:
    9187           89 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
    9188           89 :           t = convert_from_reference (t);
    9189           89 :           if (t == error_mark_node)
    9190              :             {
    9191              :               remove = true;
    9192              :               break;
    9193              :             }
    9194           82 :           if (DECL_P (t)
    9195           82 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
    9196           79 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9197           78 :                   || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9198              :             {
    9199            1 :               error_at (OMP_CLAUSE_LOCATION (c),
    9200              :                         "%qE appears more than once in data clauses", t);
    9201            1 :               remove = true;
    9202              :             }
    9203           81 :           else if (DECL_P (t))
    9204           78 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9205           82 :           if (type_dependent_expression_p (t))
    9206              :             break;
    9207           77 :           if (TREE_CODE (t) == FIELD_DECL)
    9208              :             {
    9209            0 :               sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
    9210              :                         "supported in %<uses_allocators%> clause", t);
    9211            0 :               remove = true;
    9212            0 :               break;
    9213              :             }
    9214           77 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9215          151 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9216              :                          "omp_allocator_handle_t") != 0)
    9217              :             {
    9218            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9219              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
    9220              :                         "type", t);
    9221            3 :               remove = true;
    9222            3 :               break;
    9223              :             }
    9224           74 :           tree init;
    9225           74 :           if (TREE_CODE (t) == CONST_DECL)
    9226            7 :             init = DECL_INITIAL(t);
    9227              :           else
    9228              :             init = t;
    9229           74 :           if (!DECL_P (t)
    9230           74 :               && (init == NULL_TREE
    9231            3 :                   || TREE_CODE (init) != INTEGER_CST
    9232            3 :                   || ((wi::to_widest (init) < 0
    9233            3 :                        || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
    9234            1 :                       && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
    9235            1 :                           || (wi::to_widest (init)
    9236            2 :                               > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
    9237              :             {
    9238            1 :               remove = true;
    9239            1 :               error_at (OMP_CLAUSE_LOCATION (c),
    9240              :                         "allocator %qE must be either a variable or a "
    9241              :                         "predefined allocator", t);
    9242            1 :               break;
    9243              :             }
    9244           73 :           else if (TREE_CODE (t) == CONST_DECL)
    9245              :             {
    9246              :               /* omp_null_allocator is ignored and for predefined allocators,
    9247              :                  not special handling is required; thus, remove them removed. */
    9248            7 :               remove = true;
    9249              : 
    9250            7 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
    9251            7 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
    9252              :                 {
    9253            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9254              :                             "modifiers cannot be used with predefined "
    9255              :                             "allocators");
    9256            0 :                   break;
    9257              :                 }
    9258              :             }
    9259           73 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
    9260           73 :           if (t == error_mark_node)
    9261              :             {
    9262              :               remove = true;
    9263              :               break;
    9264              :             }
    9265           72 :           if (t != NULL_TREE
    9266           16 :               && !type_dependent_expression_p (t)
    9267           88 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
    9268           15 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
    9269           28 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
    9270              :                              "omp_memspace_handle_t") != 0))
    9271              :             {
    9272            2 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
    9273              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
    9274            2 :               remove = true;
    9275            2 :               break;
    9276              :             }
    9277           70 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
    9278           70 :           if (t == error_mark_node)
    9279              :             {
    9280              :               remove = true;
    9281              :               break;
    9282              :             }
    9283           69 :           if (type_dependent_expression_p (t))
    9284              :             break;
    9285           69 :           if (t != NULL_TREE
    9286           41 :               && t != error_mark_node
    9287           41 :               && !type_dependent_expression_p (t)
    9288          110 :               && (!DECL_P (t)
    9289           41 :                   ||  DECL_EXTERNAL (t)
    9290           39 :                   || TREE_CODE (t) == PARM_DECL))
    9291              :             {
    9292            4 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
    9293              :                         "defined in same scope as the construct on which the "
    9294              :                         "clause appears", t);
    9295            4 :               remove = true;
    9296              :             }
    9297           69 :           if (t != NULL_TREE)
    9298              :             {
    9299           41 :               bool type_err = false;
    9300              : 
    9301           41 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    9302           39 :                   || DECL_SIZE (t) == NULL_TREE
    9303           79 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9304              :                 type_err = true;
    9305              :               else
    9306              :                 {
    9307           38 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
    9308           38 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
    9309           76 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
    9310              :                                  "omp_alloctrait_t") != 0
    9311           76 :                       || !TYPE_READONLY (elem_t))
    9312              :                     type_err = true;
    9313              :                 }
    9314           37 :               if (type_err)
    9315              :                 {
    9316            4 :                   error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
    9317              :                             "be of %<const omp_alloctrait_t []%> type", t);
    9318            4 :                   remove = true;
    9319              :                 }
    9320           37 :               else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
    9321              :                        != INTEGER_CST)
    9322              :                 {
    9323            1 :                   error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
    9324              :                             "arrays are not supported");
    9325            1 :                   remove = true;
    9326              :                 }
    9327              :               else
    9328              :                 {
    9329           36 :                   tree cst_val = decl_constant_value (t);
    9330           36 :                   if (cst_val == t)
    9331              :                     {
    9332            1 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
    9333              :                                 "initialized with constants");
    9334            1 :                       remove = true;
    9335              :                     }
    9336              :                 }
    9337              :             }
    9338           69 :           if (remove)
    9339              :             break;
    9340           55 :           pc = &OMP_CLAUSE_CHAIN (c);
    9341           55 :           continue;
    9342         1807 :         case OMP_CLAUSE_DEPEND:
    9343         1807 :           depend_clause = c;
    9344              :           /* FALLTHRU */
    9345         2416 :         case OMP_CLAUSE_AFFINITY:
    9346         2416 :           t = OMP_CLAUSE_DECL (c);
    9347         2416 :           if (OMP_ITERATOR_DECL_P (t))
    9348              :             {
    9349          623 :               if (TREE_PURPOSE (t) != last_iterators)
    9350          525 :                 last_iterators_remove
    9351          525 :                   = cp_omp_finish_iterators (TREE_PURPOSE (t));
    9352          623 :               last_iterators = TREE_PURPOSE (t);
    9353          623 :               t = TREE_VALUE (t);
    9354          623 :               if (last_iterators_remove)
    9355          144 :                 t = error_mark_node;
    9356              :             }
    9357              :           else
    9358              :             last_iterators = NULL_TREE;
    9359              : 
    9360         2416 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9361              :             {
    9362         1368 :               if (handle_omp_array_sections (c, ort))
    9363              :                 remove = true;
    9364         1014 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9365         1014 :                        && (OMP_CLAUSE_DEPEND_KIND (c)
    9366              :                            == OMP_CLAUSE_DEPEND_DEPOBJ))
    9367              :                 {
    9368            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9369              :                             "%<depend%> clause with %<depobj%> dependence "
    9370              :                             "type on array section");
    9371            6 :                   remove = true;
    9372              :                 }
    9373              :               break;
    9374              :             }
    9375         1048 :           if (t == error_mark_node)
    9376              :             remove = true;
    9377          886 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9378          886 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
    9379              :             {
    9380           33 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
    9381           33 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
    9382              :                 {
    9383            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9384              :                             "%<omp_all_memory%> used with %<depend%> kind "
    9385              :                             "other than %<out%> or %<inout%>");
    9386            9 :                   remove = true;
    9387              :                 }
    9388           33 :               if (processing_template_decl)
    9389              :                 break;
    9390              :             }
    9391          853 :           else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9392              :             break;
    9393          661 :           else if (!lvalue_p (t))
    9394              :             {
    9395           21 :               if (DECL_P (t))
    9396           24 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9397              :                           "%qD is not lvalue expression nor array section "
    9398              :                           "in %qs clause", t,
    9399           12 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9400              :               else
    9401           18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9402              :                           "%qE is not lvalue expression nor array section "
    9403              :                           "in %qs clause", t,
    9404            9 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9405              :               remove = true;
    9406              :             }
    9407          640 :           else if (TREE_CODE (t) == COMPONENT_REF
    9408           36 :                    && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
    9409          676 :                    && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
    9410              :             {
    9411           12 :               error_at (OMP_CLAUSE_LOCATION (c),
    9412              :                         "bit-field %qE in %qs clause", t,
    9413            6 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9414            6 :               remove = true;
    9415              :             }
    9416          634 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9417          634 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
    9418              :             {
    9419          130 :               if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9420            8 :                                      ? TREE_TYPE (TREE_TYPE (t))
    9421           57 :                                      : TREE_TYPE (t)))
    9422              :                 {
    9423           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9424              :                             "%qE does not have %<omp_depend_t%> type in "
    9425              :                             "%<depend%> clause with %<depobj%> dependence "
    9426              :                             "type", t);
    9427           12 :                   remove = true;
    9428              :                 }
    9429              :             }
    9430          569 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    9431         1010 :                    && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    9432            4 :                                         ? TREE_TYPE (TREE_TYPE (t))
    9433          437 :                                         : TREE_TYPE (t)))
    9434              :             {
    9435           15 :               error_at (OMP_CLAUSE_LOCATION (c),
    9436              :                         "%qE should not have %<omp_depend_t%> type in "
    9437              :                         "%<depend%> clause with dependence type other than "
    9438              :                         "%<depobj%>", t);
    9439           15 :               remove = true;
    9440              :             }
    9441           87 :           if (!remove)
    9442              :             {
    9443          631 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
    9444           24 :                 t = null_pointer_node;
    9445              :               else
    9446              :                 {
    9447          607 :                   tree addr = cp_build_addr_expr (t, tf_warning_or_error);
    9448          607 :                   if (addr == error_mark_node)
    9449              :                     {
    9450              :                       remove = true;
    9451              :                       break;
    9452              :                     }
    9453          607 :                   t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
    9454              :                                              addr, RO_UNARY_STAR,
    9455              :                                              tf_warning_or_error);
    9456          607 :                   if (t == error_mark_node)
    9457              :                     {
    9458              :                       remove = true;
    9459              :                       break;
    9460              :                     }
    9461              :                 }
    9462          631 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
    9463          137 :                   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
    9464          768 :                   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
    9465              :                       == TREE_VEC))
    9466          137 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
    9467              :               else
    9468          494 :                 OMP_CLAUSE_DECL (c) = t;
    9469              :             }
    9470              :           break;
    9471           69 :         case OMP_CLAUSE_DETACH:
    9472           69 :           t = OMP_CLAUSE_DECL (c);
    9473           69 :           if (detach_seen)
    9474              :             {
    9475            3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9476              :                         "too many %qs clauses on a task construct",
    9477              :                         "detach");
    9478            3 :               remove = true;
    9479            3 :               break;
    9480              :             }
    9481           66 :           else if (error_operand_p (t))
    9482              :             {
    9483              :               remove = true;
    9484              :               break;
    9485              :             }
    9486              :           else
    9487              :             {
    9488           63 :               tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
    9489           63 :               if (!type_dependent_expression_p (t)
    9490           63 :                   && (!INTEGRAL_TYPE_P (type)
    9491              :                       || TREE_CODE (type) != ENUMERAL_TYPE
    9492           51 :                       || TYPE_NAME (type) == NULL_TREE
    9493          102 :                       || (DECL_NAME (TYPE_NAME (type))
    9494           51 :                           != get_identifier ("omp_event_handle_t"))))
    9495              :                 {
    9496            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9497              :                             "%<detach%> clause event handle "
    9498              :                             "has type %qT rather than "
    9499              :                             "%<omp_event_handle_t%>",
    9500              :                             type);
    9501            6 :                   remove = true;
    9502              :                 }
    9503           63 :               detach_seen = c;
    9504           63 :               cxx_mark_addressable (t);
    9505              :             }
    9506           63 :           break;
    9507              : 
    9508        16995 :         case OMP_CLAUSE_MAP:
    9509        16995 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
    9510          268 :             goto move_implicit;
    9511        16727 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
    9512        16727 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
    9513              :             {
    9514              :               remove = true;
    9515              :               break;
    9516              :             }
    9517              :           /* FALLTHRU */
    9518        20581 :         case OMP_CLAUSE_TO:
    9519        20581 :         case OMP_CLAUSE_FROM:
    9520        20581 :           if (OMP_CLAUSE_ITERATORS (c)
    9521        20581 :               && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
    9522              :             {
    9523       102065 :               t = error_mark_node;
    9524              :               break;
    9525              :             }
    9526              :           /* FALLTHRU */
    9527        21469 :         case OMP_CLAUSE__CACHE_:
    9528        21469 :           {
    9529        21469 :             using namespace omp_addr_tokenizer;
    9530        21469 :             auto_vec<omp_addr_token *, 10> addr_tokens;
    9531              : 
    9532        21469 :             t = OMP_CLAUSE_DECL (c);
    9533        21469 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9534              :               {
    9535         6033 :                 grp_start_p = pc;
    9536         6033 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9537              : 
    9538         6033 :                 if (handle_omp_array_sections (c, ort))
    9539              :                   remove = true;
    9540              :                 else
    9541              :                   {
    9542         5223 :                     t = OMP_CLAUSE_DECL (c);
    9543         5223 :                     if (TREE_CODE (t) != OMP_ARRAY_SECTION
    9544         4362 :                         && !type_dependent_expression_p (t)
    9545         9585 :                         && !omp_mappable_type (TREE_TYPE (t)))
    9546              :                       {
    9547            3 :                         auto_diagnostic_group d;
    9548            6 :                         error_at (OMP_CLAUSE_LOCATION (c),
    9549              :                                   "array section does not have mappable type "
    9550              :                                   "in %qs clause",
    9551            3 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9552            3 :                         if (TREE_TYPE (t) != error_mark_node
    9553            3 :                             && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9554            3 :                           cxx_incomplete_type_inform (TREE_TYPE (t));
    9555            3 :                         remove = true;
    9556            3 :                       }
    9557         7150 :                     while (TREE_CODE (t) == ARRAY_REF)
    9558         1927 :                       t = TREE_OPERAND (t, 0);
    9559              : 
    9560         5223 :                     if (type_dependent_expression_p (t))
    9561              :                       break;
    9562              : 
    9563         4749 :                     cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9564              : 
    9565         4749 :                     if (!ai.map_supported_p ()
    9566         4749 :                         || !omp_parse_expr (addr_tokens, t))
    9567              :                       {
    9568           18 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
    9569              :                                   "unsupported map expression %qE",
    9570            9 :                                   OMP_CLAUSE_DECL (c));
    9571            9 :                         remove = true;
    9572            9 :                         break;
    9573              :                       }
    9574              : 
    9575              :                     /* This check is to determine if this will be the only map
    9576              :                        node created for this clause.  Otherwise, we'll check
    9577              :                        the following FIRSTPRIVATE_POINTER,
    9578              :                        FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
    9579              :                        iteration(s) of the loop.   */
    9580         9431 :                     if (addr_tokens.length () >= 4
    9581         1063 :                         && addr_tokens[0]->type == STRUCTURE_BASE
    9582         1057 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    9583         1057 :                         && addr_tokens[1]->type == ACCESS_METHOD
    9584         1057 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
    9585          977 :                         && addr_tokens[3]->type == ACCESS_METHOD
    9586         5454 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
    9587          551 :                             || (addr_tokens[3]->u.access_kind
    9588              :                                 == ACCESS_INDEXED_ARRAY)))
    9589              :                       {
    9590          165 :                         tree rt = addr_tokens[1]->expr;
    9591              : 
    9592          165 :                         gcc_assert (DECL_P (rt));
    9593              : 
    9594          165 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9595          154 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
    9596          165 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
    9597            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
    9598            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
    9599            0 :                                                  DECL_UID (rt))))
    9600              :                           {
    9601              :                             remove = true;
    9602              :                             break;
    9603              :                           }
    9604          165 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
    9605              :                           break;
    9606          116 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
    9607              :                           {
    9608            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9609            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9610              :                                         "%qD appears more than once in motion"
    9611              :                                         " clauses", rt);
    9612            0 :                             else if (openacc)
    9613            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9614              :                                         "%qD appears more than once in data"
    9615              :                                         " clauses", rt);
    9616              :                             else
    9617            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9618              :                                         "%qD appears more than once in map"
    9619              :                                         " clauses", rt);
    9620              :                             remove = true;
    9621              :                           }
    9622              :                         else
    9623              :                           {
    9624          116 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
    9625          116 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
    9626              :                           }
    9627              :                       }
    9628         4749 :                   }
    9629         5501 :                 if (cp_oacc_check_attachments (c))
    9630           12 :                   remove = true;
    9631         5501 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9632         4511 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9633         4447 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9634         5599 :                     && !OMP_CLAUSE_SIZE (c))
    9635              :                   /* In this case, we have a single array element which is a
    9636              :                      pointer, and we already set OMP_CLAUSE_SIZE in
    9637              :                      handle_omp_array_sections above.  For attach/detach
    9638              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
    9639              :                      to zero here.  */
    9640           60 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
    9641              :                 break;
    9642              :               }
    9643        15436 :             else if (type_dependent_expression_p (t))
    9644              :               break;
    9645        14653 :             else if (!omp_parse_expr (addr_tokens, t))
    9646              :               {
    9647            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9648              :                           "unsupported map expression %qE",
    9649            0 :                           OMP_CLAUSE_DECL (c));
    9650            0 :                 remove = true;
    9651            0 :                 break;
    9652              :               }
    9653        14653 :             if (t == error_mark_node)
    9654              :               {
    9655              :                 remove = true;
    9656              :                 break;
    9657              :               }
    9658              : 
    9659        14539 :             tree attr;
    9660        14539 :             if (DECL_P (t)
    9661        11853 :                 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9662         8263 :                 && (attr = lookup_attribute ("omp declare target",
    9663         8263 :                                              DECL_ATTRIBUTES (t)))
    9664        15071 :                 && value_member (get_identifier ("local"),
    9665          532 :                                  TREE_VALUE (attr)))
    9666              :               {
    9667            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9668              :                           "device-local variable %qD cannot appear "
    9669              :                           "in map clause", t);
    9670            0 :                 remove = true;
    9671            0 :                 break;
    9672              :               }
    9673              : 
    9674              :             /* OpenACC attach / detach clauses must be pointers.  */
    9675        14539 :             if (cp_oacc_check_attachments (c))
    9676              :               {
    9677              :                 remove = true;
    9678              :                 break;
    9679              :               }
    9680        14515 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9681        10803 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9682        10754 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9683        14589 :                 && !OMP_CLAUSE_SIZE (c))
    9684              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
    9685              :                  bias) to zero here, so it is not set erroneously to the
    9686              :                  pointer size later on in gimplify.cc.  */
    9687           66 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
    9688              : 
    9689        14515 :             cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9690              : 
    9691        14515 :             if (!ai.check_clause (c))
    9692              :               {
    9693              :                 remove = true;
    9694              :                 break;
    9695              :               }
    9696              : 
    9697        14494 :             if (!ai.map_supported_p ())
    9698              :               {
    9699           88 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9700              :                           "unsupported map expression %qE",
    9701           44 :                           OMP_CLAUSE_DECL (c));
    9702           44 :                 remove = true;
    9703           44 :                 break;
    9704              :               }
    9705              : 
    9706        28900 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
    9707              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
    9708              :                         && addr_tokens[1]->type == ACCESS_METHOD);
    9709              : 
    9710        14450 :             t = addr_tokens[1]->expr;
    9711              : 
    9712              :             /* This is used to prevent cxx_mark_addressable from being called
    9713              :                on 'this' for expressions like 'this->a', i.e. typical member
    9714              :                accesses.  */
    9715        14450 :             indir_component_ref_p
    9716        28900 :               = (addr_tokens[0]->type == STRUCTURE_BASE
    9717        14450 :                  && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
    9718              : 
    9719        14450 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
    9720            1 :               goto skip_decl_checks;
    9721              : 
    9722              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
    9723              :                mapping.  OpenACC allows multiple fields of the same structure
    9724              :                to be written.  */
    9725        14449 :             if (addr_tokens[0]->type == STRUCTURE_BASE
    9726        14449 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
    9727         1263 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
    9728         1351 :               goto skip_decl_checks;
    9729              : 
    9730        13098 :             if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
    9731              :               {
    9732            0 :                 OMP_CLAUSE_DECL (c)
    9733            0 :                   = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    9734            0 :                 break;
    9735              :               }
    9736        13098 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    9737              :               {
    9738            0 :                 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9739              :                   break;
    9740            0 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9741            0 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9742            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
    9743            0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
    9744            0 :                         || (!openacc && EXPR_P (t))))
    9745              :                   break;
    9746            0 :                 if (DECL_P (t))
    9747            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9748              :                             "%qD is not a variable in %qs clause", t,
    9749            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9750              :                 else
    9751            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9752              :                             "%qE is not a variable in %qs clause", t,
    9753            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9754              :                 remove = true;
    9755              :               }
    9756        13098 :             else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    9757              :               {
    9758            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9759              :                           "%qD is threadprivate variable in %qs clause", t,
    9760            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9761            0 :                 remove = true;
    9762              :               }
    9763        13098 :             else if (!processing_template_decl
    9764        12919 :                      && !TYPE_REF_P (TREE_TYPE (t))
    9765        12242 :                      && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9766         8640 :                          || (OMP_CLAUSE_MAP_KIND (c)
    9767              :                              != GOMP_MAP_FIRSTPRIVATE_POINTER))
    9768        10232 :                      && !indir_component_ref_p
    9769         9868 :                      && (t != current_class_ptr
    9770           18 :                          || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9771            6 :                          || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
    9772        22966 :                      && !cxx_mark_addressable (t))
    9773              :               remove = true;
    9774        13098 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9775         9478 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9776         9478 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9777              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
    9778         7468 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9779              :                                == GOMP_MAP_ATTACH_DETACH)))
    9780        10428 :                      && t == OMP_CLAUSE_DECL (c)
    9781         9730 :                      && !type_dependent_expression_p (t)
    9782        32558 :                      && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
    9783          278 :                                             ? TREE_TYPE (TREE_TYPE (t))
    9784         9452 :                                             : TREE_TYPE (t)))
    9785              :               {
    9786           42 :                 auto_diagnostic_group d;
    9787           84 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9788              :                           "%qD does not have a mappable type in %qs clause", t,
    9789           42 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9790           42 :                 if (TREE_TYPE (t) != error_mark_node
    9791           42 :                     && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9792           39 :                   cxx_incomplete_type_inform (TREE_TYPE (t));
    9793           42 :                 remove = true;
    9794           42 :               }
    9795        13056 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9796         9442 :                      && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
    9797           93 :                      && !type_dependent_expression_p (t)
    9798        13149 :                      && !INDIRECT_TYPE_P (TREE_TYPE (t)))
    9799              :               {
    9800            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9801              :                           "%qD is not a pointer variable", t);
    9802            6 :                 remove = true;
    9803              :               }
    9804        13050 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9805         9436 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
    9806        13533 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
    9807          480 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
    9808          480 :                          || bitmap_bit_p (&map_firstprivate_head,
    9809          480 :                                           DECL_UID (t))))
    9810              :               remove = true;
    9811        13044 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9812        13044 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9813              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
    9814              :               {
    9815         2004 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
    9816         2004 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9817         4005 :                     || (openacc
    9818         1364 :                         && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
    9819              :                   {
    9820           12 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9821              :                               "%qD appears more than once in data clauses", t);
    9822           12 :                     remove = true;
    9823              :                   }
    9824         1992 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9825           12 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9826         2000 :                          && openacc)
    9827              :                   {
    9828            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9829              :                               "%qD appears more than once in data clauses", t);
    9830            3 :                     remove = true;
    9831              :                   }
    9832              :                 else
    9833         1989 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9834              :               }
    9835        11040 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9836        11040 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9837              :                          == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
    9838          115 :               bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9839        10925 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9840          181 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9841           38 :                      && ort != C_ORT_OMP
    9842           38 :                      && ort != C_ORT_OMP_TARGET
    9843        10941 :                      && ort != C_ORT_OMP_EXIT_DATA)
    9844              :               {
    9845            9 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9846            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9847              :                             "%qD appears more than once in motion clauses", t);
    9848            9 :                 else if (openacc)
    9849            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9850              :                             "%qD appears more than once in data clauses", t);
    9851              :                 else
    9852            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9853              :                             "%qD appears more than once in map clauses", t);
    9854              :                 remove = true;
    9855              :               }
    9856        10916 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
    9857              :               {
    9858            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9859              :                           "%qD appears more than once in data clauses", t);
    9860            0 :                 remove = true;
    9861              :               }
    9862        10916 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9863        10916 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
    9864              :               {
    9865           27 :                 if (openacc)
    9866            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9867              :                             "%qD appears more than once in data clauses", t);
    9868              :                 else
    9869           27 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9870              :                             "%qD appears both in data and map clauses", t);
    9871              :                 remove = true;
    9872              :               }
    9873        10889 :             else if (!omp_access_chain_p (addr_tokens, 1))
    9874              :               {
    9875        10809 :                 bitmap_set_bit (&map_head, DECL_UID (t));
    9876              : 
    9877        10809 :                 tree decl = OMP_CLAUSE_DECL (c);
    9878        10809 :                 if (t != decl
    9879        10809 :                     && (TREE_CODE (decl) == COMPONENT_REF
    9880          162 :                         || (INDIRECT_REF_P (decl)
    9881          162 :                             && (TREE_CODE (TREE_OPERAND (decl, 0))
    9882              :                                 == COMPONENT_REF)
    9883          150 :                             && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
    9884              :                                                                     0))))))
    9885         1165 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
    9886              :               }
    9887              : 
    9888         4720 :           skip_decl_checks:
    9889              :             /* If we call ai.expand_map_clause in handle_omp_array_sections,
    9890              :                the containing loop (here) iterates through the new nodes
    9891              :                created by that expansion.  Avoid expanding those again (just
    9892              :                by checking the node type).  */
    9893         4720 :             if (!remove
    9894        14345 :                 && !processing_template_decl
    9895        14169 :                 && ort != C_ORT_DECLARE_SIMD
    9896        14169 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9897        10475 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
    9898         8486 :                         && (OMP_CLAUSE_MAP_KIND (c)
    9899              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
    9900         8371 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
    9901         8371 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
    9902         7372 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    9903         7323 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
    9904              :               {
    9905        10992 :                 grp_start_p = pc;
    9906        10992 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9907        10992 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
    9908              :                                                 addr_tokens, ort);
    9909        10992 :                 if (nc != error_mark_node)
    9910        10992 :                   c = nc;
    9911              :               }
    9912        21534 :           }
    9913        14450 :           break;
    9914              : 
    9915          645 :         case OMP_CLAUSE_ENTER:
    9916          645 :         case OMP_CLAUSE_LINK:
    9917          645 :         case OMP_CLAUSE_LOCAL:
    9918          645 :           t = OMP_CLAUSE_DECL (c);
    9919          645 :           const char *cname;
    9920          645 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
    9921          645 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
    9922          645 :               && OMP_CLAUSE_ENTER_TO (c))
    9923              :             cname = "to";
    9924          645 :           if (TREE_CODE (t) == FUNCTION_DECL
    9925          645 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9926              :             ;
    9927          428 :           else if (!VAR_P (t))
    9928              :             {
    9929           12 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9930              :                 {
    9931            9 :                   if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
    9932            6 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9933              :                               "template %qE in clause %qs", t, cname);
    9934            3 :                   else if (really_overloaded_fn (t))
    9935            3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9936              :                               "overloaded function name %qE in clause %qs", t,
    9937              :                               cname);
    9938              :                   else
    9939            0 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9940              :                               "%qE is neither a variable nor a function name "
    9941              :                               "in clause %qs", t, cname);
    9942              :                 }
    9943              :               else
    9944            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9945              :                           "%qE is not a variable in clause %qs", t, cname);
    9946              :               remove = true;
    9947              :             }
    9948          416 :           else if (DECL_THREAD_LOCAL_P (t))
    9949              :             {
    9950            6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9951              :                         "%qD is threadprivate variable in %qs clause", t,
    9952              :                         cname);
    9953            6 :               remove = true;
    9954              :             }
    9955          410 :           else if (!omp_mappable_type (TREE_TYPE (t)))
    9956              :             {
    9957           18 :               auto_diagnostic_group d;
    9958           18 :               error_at (OMP_CLAUSE_LOCATION (c),
    9959              :                         "%qD does not have a mappable type in %qs clause", t,
    9960              :                         cname);
    9961           18 :               if (TREE_TYPE (t) != error_mark_node
    9962           18 :                   && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9963           18 :                 cxx_incomplete_type_inform (TREE_TYPE (t));
    9964           18 :               remove = true;
    9965           18 :             }
    9966           36 :           if (remove)
    9967              :             break;
    9968          609 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
    9969              :             {
    9970           30 :               error_at (OMP_CLAUSE_LOCATION (c),
    9971              :                         "%qE appears more than once on the same "
    9972              :                         "%<declare target%> directive", t);
    9973           30 :               remove = true;
    9974              :             }
    9975              :           else
    9976          579 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9977              :           break;
    9978              : 
    9979          457 :         case OMP_CLAUSE_UNIFORM:
    9980          457 :           t = OMP_CLAUSE_DECL (c);
    9981          457 :           if (TREE_CODE (t) != PARM_DECL)
    9982              :             {
    9983            0 :               if (processing_template_decl)
    9984              :                 break;
    9985            0 :               if (DECL_P (t))
    9986            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9987              :                           "%qD is not an argument in %<uniform%> clause", t);
    9988              :               else
    9989            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9990              :                           "%qE is not an argument in %<uniform%> clause", t);
    9991              :               remove = true;
    9992              :               break;
    9993              :             }
    9994              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
    9995          457 :           bitmap_set_bit (&map_head, DECL_UID (t));
    9996          457 :           goto check_dup_generic;
    9997              : 
    9998          165 :         case OMP_CLAUSE_GRAINSIZE:
    9999          165 :           t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
   10000          165 :           if (t == error_mark_node)
   10001              :             remove = true;
   10002          165 :           else if (!type_dependent_expression_p (t)
   10003          165 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10004              :             {
   10005            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10006              :                         "%<grainsize%> expression must be integral");
   10007            0 :               remove = true;
   10008              :             }
   10009              :           else
   10010              :             {
   10011          165 :               t = mark_rvalue_use (t);
   10012          165 :               if (!processing_template_decl)
   10013              :                 {
   10014          164 :                   t = maybe_constant_value (t);
   10015          164 :                   if (TREE_CODE (t) == INTEGER_CST
   10016          164 :                       && tree_int_cst_sgn (t) != 1)
   10017              :                     {
   10018            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   10019              :                                   "%<grainsize%> value must be positive");
   10020            0 :                       t = integer_one_node;
   10021              :                     }
   10022          164 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10023              :                 }
   10024          165 :               OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
   10025              :             }
   10026              :           break;
   10027              : 
   10028          276 :         case OMP_CLAUSE_PRIORITY:
   10029          276 :           t = OMP_CLAUSE_PRIORITY_EXPR (c);
   10030          276 :           if (t == error_mark_node)
   10031              :             remove = true;
   10032          276 :           else if (!type_dependent_expression_p (t)
   10033          276 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10034              :             {
   10035            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10036              :                         "%<priority%> expression must be integral");
   10037            0 :               remove = true;
   10038              :             }
   10039              :           else
   10040              :             {
   10041          276 :               t = mark_rvalue_use (t);
   10042          276 :               if (!processing_template_decl)
   10043              :                 {
   10044          276 :                   t = maybe_constant_value (t);
   10045          276 :                   if (TREE_CODE (t) == INTEGER_CST
   10046          276 :                       && tree_int_cst_sgn (t) == -1)
   10047              :                     {
   10048            0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   10049              :                                   "%<priority%> value must be non-negative");
   10050            0 :                       t = integer_one_node;
   10051              :                     }
   10052          276 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10053              :                 }
   10054          276 :               OMP_CLAUSE_PRIORITY_EXPR (c) = t;
   10055              :             }
   10056              :           break;
   10057              : 
   10058          228 :         case OMP_CLAUSE_HINT:
   10059          228 :           t = OMP_CLAUSE_HINT_EXPR (c);
   10060          228 :           if (t == error_mark_node)
   10061              :             remove = true;
   10062          228 :           else if (!type_dependent_expression_p (t)
   10063          228 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10064              :             {
   10065            9 :               error_at (OMP_CLAUSE_LOCATION (c),
   10066              :                         "%<hint%> expression must be integral");
   10067            9 :               remove = true;
   10068              :             }
   10069              :           else
   10070              :             {
   10071          219 :               t = mark_rvalue_use (t);
   10072          219 :               if (!processing_template_decl)
   10073              :                 {
   10074          171 :                   t = maybe_constant_value (t);
   10075          171 :                   if (TREE_CODE (t) != INTEGER_CST)
   10076              :                     {
   10077           16 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10078              :                                 "%<hint%> expression must be constant integer "
   10079              :                                 "expression");
   10080           16 :                       remove = true;
   10081              :                     }
   10082              :                 }
   10083          219 :               OMP_CLAUSE_HINT_EXPR (c) = t;
   10084              :             }
   10085              :           break;
   10086              : 
   10087          186 :         case OMP_CLAUSE_FILTER:
   10088          186 :           t = OMP_CLAUSE_FILTER_EXPR (c);
   10089          186 :           if (t == error_mark_node)
   10090              :             remove = true;
   10091          186 :           else if (!type_dependent_expression_p (t)
   10092          186 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10093              :             {
   10094            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10095              :                         "%<filter%> expression must be integral");
   10096            6 :               remove = true;
   10097              :             }
   10098              :           else
   10099              :             {
   10100          180 :               t = mark_rvalue_use (t);
   10101          180 :               if (!processing_template_decl)
   10102              :                 {
   10103          177 :                   t = maybe_constant_value (t);
   10104          177 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   10105              :                 }
   10106          180 :               OMP_CLAUSE_FILTER_EXPR (c) = t;
   10107              :             }
   10108              :           break;
   10109              : 
   10110          433 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   10111          433 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   10112          433 :           field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
   10113          433 :           t = OMP_CLAUSE_DECL (c);
   10114          433 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   10115          329 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   10116          433 :           if (!type_dependent_expression_p (t))
   10117              :             {
   10118          431 :               tree type = TREE_TYPE (t);
   10119          431 :               if (!TYPE_PTR_P (type)
   10120          431 :                   && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
   10121              :                 {
   10122           57 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   10123           57 :                       && ort == C_ORT_OMP)
   10124              :                     {
   10125            3 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10126              :                                 "%qs variable is neither a pointer "
   10127              :                                 "nor reference to pointer",
   10128            3 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10129            3 :                       remove = true;
   10130              :                     }
   10131           54 :                   else if (TREE_CODE (type) != ARRAY_TYPE
   10132           54 :                            && (!TYPE_REF_P (type)
   10133            2 :                                || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
   10134              :                     {
   10135           12 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10136              :                                 "%qs variable is neither a pointer, nor an "
   10137              :                                 "array nor reference to pointer or array",
   10138           12 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10139           12 :                       remove = true;
   10140              :                     }
   10141              :                 }
   10142              :             }
   10143          433 :           goto check_dup_generic;
   10144              : 
   10145          267 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   10146          267 :           t = OMP_CLAUSE_DECL (c);
   10147          267 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10148              :             {
   10149           28 :               if (handle_omp_array_sections (c, ort))
   10150              :                 remove = true;
   10151              :               else
   10152              :                 {
   10153           28 :                   t = OMP_CLAUSE_DECL (c);
   10154           30 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10155            2 :                     t = TREE_OPERAND (t, 0);
   10156           64 :                   while (INDIRECT_REF_P (t)
   10157           64 :                          || TREE_CODE (t) == ARRAY_REF)
   10158           36 :                     t = TREE_OPERAND (t, 0);
   10159              :                 }
   10160              :             }
   10161          267 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   10162              :             {
   10163          267 :               bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   10164          267 :               if (!processing_template_decl
   10165          267 :                   && !cxx_mark_addressable (t))
   10166              :                 remove = true;
   10167              :             }
   10168          267 :           goto check_dup_generic_t;
   10169              : 
   10170           76 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   10171           76 :           field_ok = true;
   10172           76 :           t = OMP_CLAUSE_DECL (c);
   10173           76 :           if (!processing_template_decl
   10174           74 :               && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   10175           74 :               && !TYPE_REF_P (TREE_TYPE (t))
   10176          143 :               && !cxx_mark_addressable (t))
   10177              :             remove = true;
   10178           76 :           goto check_dup_generic;
   10179              : 
   10180              :         case OMP_CLAUSE_NOWAIT:
   10181              :         case OMP_CLAUSE_DEFAULT:
   10182              :         case OMP_CLAUSE_UNTIED:
   10183              :         case OMP_CLAUSE_COLLAPSE:
   10184              :         case OMP_CLAUSE_PARALLEL:
   10185              :         case OMP_CLAUSE_FOR:
   10186              :         case OMP_CLAUSE_SECTIONS:
   10187              :         case OMP_CLAUSE_TASKGROUP:
   10188              :         case OMP_CLAUSE_PROC_BIND:
   10189              :         case OMP_CLAUSE_DEVICE_TYPE:
   10190              :         case OMP_CLAUSE_NOGROUP:
   10191              :         case OMP_CLAUSE_THREADS:
   10192              :         case OMP_CLAUSE_SIMD:
   10193              :         case OMP_CLAUSE_DEFAULTMAP:
   10194              :         case OMP_CLAUSE_BIND:
   10195              :         case OMP_CLAUSE_AUTO:
   10196              :         case OMP_CLAUSE_INDEPENDENT:
   10197              :         case OMP_CLAUSE_SEQ:
   10198              :         case OMP_CLAUSE_IF_PRESENT:
   10199              :         case OMP_CLAUSE_FINALIZE:
   10200              :         case OMP_CLAUSE_NOHOST:
   10201              :         case OMP_CLAUSE_INDIRECT:
   10202              :           break;
   10203              : 
   10204          231 :         case OMP_CLAUSE_MERGEABLE:
   10205          231 :           mergeable_seen = true;
   10206          231 :           break;
   10207              : 
   10208          322 :         case OMP_CLAUSE_TILE:
   10209          754 :           for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
   10210          432 :                list = TREE_CHAIN (list))
   10211              :             {
   10212          432 :               t = TREE_VALUE (list);
   10213              : 
   10214          432 :               if (t == error_mark_node)
   10215              :                 remove = true;
   10216          403 :               else if (!type_dependent_expression_p (t)
   10217          403 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10218              :                 {
   10219            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10220              :                             "%<tile%> argument needs integral type");
   10221            3 :                   remove = true;
   10222              :                 }
   10223              :               else
   10224              :                 {
   10225          400 :                   t = mark_rvalue_use (t);
   10226          400 :                   if (!processing_template_decl)
   10227              :                     {
   10228              :                       /* Zero is used to indicate '*', we permit you
   10229              :                          to get there via an ICE of value zero.  */
   10230          385 :                       t = maybe_constant_value (t);
   10231          385 :                       if (!tree_fits_shwi_p (t)
   10232          369 :                           || tree_to_shwi (t) < 0)
   10233              :                         {
   10234           40 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10235              :                                     "%<tile%> argument needs positive "
   10236              :                                     "integral constant");
   10237           40 :                           remove = true;
   10238              :                         }
   10239              :                     }
   10240              :                 }
   10241              : 
   10242              :                 /* Update list item.  */
   10243          432 :               TREE_VALUE (list) = t;
   10244              :             }
   10245              :           break;
   10246              : 
   10247         1027 :         case OMP_CLAUSE_SIZES:
   10248         1027 :           for (tree list = OMP_CLAUSE_SIZES_LIST (c);
   10249         2688 :                !remove && list; list = TREE_CHAIN (list))
   10250              :             {
   10251         1661 :               t = TREE_VALUE (list);
   10252              : 
   10253         1661 :               if (t == error_mark_node)
   10254            0 :                 t = integer_one_node;
   10255         1661 :               else if (!type_dependent_expression_p (t)
   10256         1661 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10257              :                 {
   10258            8 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10259              :                             "%<sizes%> argument needs positive integral "
   10260              :                             "constant");
   10261            8 :                   t = integer_one_node;
   10262              :                 }
   10263              :               else
   10264              :                 {
   10265         1653 :                   t = mark_rvalue_use (t);
   10266         1653 :                   if (!processing_template_decl)
   10267              :                     {
   10268         1636 :                       t = maybe_constant_value (t);
   10269         1636 :                       HOST_WIDE_INT n;
   10270         1636 :                       if (!tree_fits_shwi_p (t)
   10271         1632 :                           || !INTEGRAL_TYPE_P (TREE_TYPE (t))
   10272         1632 :                           || (n = tree_to_shwi (t)) <= 0
   10273         3240 :                           || (int)n != n)
   10274              :                         {
   10275           32 :                           error_at (OMP_CLAUSE_LOCATION (c),
   10276              :                                     "%<sizes%> argument needs positive "
   10277              :                                     "integral constant");
   10278           32 :                           t = integer_one_node;
   10279              :                         }
   10280              :                     }
   10281              :                 }
   10282              : 
   10283              :               /* Update list item.  */
   10284         1661 :               TREE_VALUE (list) = t;
   10285              :             }
   10286              :           break;
   10287              : 
   10288          630 :         case OMP_CLAUSE_ORDERED:
   10289          630 :           ordered_seen = true;
   10290          630 :           break;
   10291              : 
   10292         1549 :         case OMP_CLAUSE_ORDER:
   10293         1549 :           if (order_seen)
   10294              :             remove = true;
   10295              :           else
   10296              :             order_seen = true;
   10297              :           break;
   10298              : 
   10299          638 :         case OMP_CLAUSE_INBRANCH:
   10300          638 :         case OMP_CLAUSE_NOTINBRANCH:
   10301          638 :           if (branch_seen)
   10302              :             {
   10303            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10304              :                         "%<inbranch%> clause is incompatible with "
   10305              :                         "%<notinbranch%>");
   10306            3 :               remove = true;
   10307              :             }
   10308              :           branch_seen = true;
   10309              :           break;
   10310              : 
   10311          307 :         case OMP_CLAUSE_INCLUSIVE:
   10312          307 :         case OMP_CLAUSE_EXCLUSIVE:
   10313          307 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10314          307 :           if (!t)
   10315          307 :             t = OMP_CLAUSE_DECL (c);
   10316          307 :           if (t == current_class_ptr)
   10317              :             {
   10318            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10319              :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
   10320              :                         " clauses");
   10321            0 :               remove = true;
   10322            0 :               break;
   10323              :             }
   10324          307 :           if (!VAR_P (t)
   10325              :               && TREE_CODE (t) != PARM_DECL
   10326              :               && TREE_CODE (t) != FIELD_DECL)
   10327              :             {
   10328            0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
   10329              :                 break;
   10330            0 :               if (DECL_P (t))
   10331            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10332              :                           "%qD is not a variable in clause %qs", t,
   10333            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10334              :               else
   10335            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   10336              :                           "%qE is not a variable in clause %qs", t,
   10337            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10338              :               remove = true;
   10339              :             }
   10340              :           break;
   10341              : 
   10342              :         case OMP_CLAUSE_FULL:
   10343              :           break;
   10344              : 
   10345          470 :         case OMP_CLAUSE_PARTIAL:
   10346          470 :           partial_seen = true;
   10347          470 :           t = OMP_CLAUSE_PARTIAL_EXPR (c);
   10348          470 :           if (!t)
   10349              :             break;
   10350              : 
   10351          313 :           if (t == error_mark_node)
   10352              :             t = NULL_TREE;
   10353          313 :           else if (!type_dependent_expression_p (t)
   10354          313 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
   10355              :             {
   10356            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10357              :                         "%<partial%> argument needs positive constant "
   10358              :                         "integer expression");
   10359            3 :               t = NULL_TREE;
   10360              :             }
   10361              :           else
   10362              :             {
   10363          310 :               t = mark_rvalue_use (t);
   10364          310 :               if (!processing_template_decl)
   10365              :                 {
   10366          292 :                   t = maybe_constant_value (t);
   10367              : 
   10368          292 :                   HOST_WIDE_INT n;
   10369          584 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   10370          292 :                       || !tree_fits_shwi_p (t)
   10371          286 :                       || (n = tree_to_shwi (t)) <= 0
   10372          560 :                       || (int)n != n)
   10373              :                     {
   10374           24 :                       error_at (OMP_CLAUSE_LOCATION (c),
   10375              :                                 "%<partial%> argument needs positive "
   10376              :                                 "constant integer expression");
   10377           24 :                       t = NULL_TREE;
   10378              :                     }
   10379              :                 }
   10380              :             }
   10381              : 
   10382          313 :           OMP_CLAUSE_PARTIAL_EXPR (c) = t;
   10383          313 :           break;
   10384          549 :         case OMP_CLAUSE_INIT:
   10385          549 :           init_seen = true;
   10386          549 :           OMP_CLAUSE_INIT_PREFER_TYPE (c)
   10387          549 :             = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
   10388          549 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   10389          271 :             init_no_targetsync_clause = c;
   10390              :           /* FALLTHRU */
   10391          844 :         case OMP_CLAUSE_DESTROY:
   10392          844 :         case OMP_CLAUSE_USE:
   10393          844 :           init_use_destroy_seen = true;
   10394          844 :           t = OMP_CLAUSE_DECL (c);
   10395          844 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   10396              :             {
   10397            9 :               error_at (OMP_CLAUSE_LOCATION (c),
   10398              :                         "%qD appears more than once in action clauses", t);
   10399            9 :               remove = true;
   10400            9 :               break;
   10401              :             }
   10402          835 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   10403              :           /* FALLTHRU */
   10404         1099 :         case OMP_CLAUSE_INTEROP:
   10405         1099 :           if (!processing_template_decl)
   10406              :             {
   10407         1003 :               if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
   10408              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) &&  */
   10409         1003 :                   !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   10410              :                 {
   10411          126 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10412              :                             "%qD must be of %<omp_interop_t%>",
   10413           63 :                             OMP_CLAUSE_DECL (c));
   10414           63 :                   remove = true;
   10415              :                 }
   10416          940 :               else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   10417          481 :                         || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   10418         1058 :                        && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   10419              :                 {
   10420           36 :                   error_at (OMP_CLAUSE_LOCATION (c),
   10421           18 :                             "%qD shall not be const", OMP_CLAUSE_DECL (c));
   10422           18 :                   remove = true;
   10423              :                 }
   10424              :             }
   10425         1099 :           pc = &OMP_CLAUSE_CHAIN (c);
   10426         1099 :           break;
   10427            0 :         default:
   10428            0 :           gcc_unreachable ();
   10429           55 :         }
   10430              : 
   10431       102065 :       if (remove)
   10432              :         {
   10433         2733 :           if (grp_start_p)
   10434              :             {
   10435              :               /* If we found a clause to remove, we want to remove the whole
   10436              :                  expanded group, otherwise gimplify
   10437              :                  (omp_resolve_clause_dependencies) can get confused.  */
   10438          861 :               *grp_start_p = grp_sentinel;
   10439          861 :               pc = grp_start_p;
   10440          861 :               grp_start_p = NULL;
   10441              :             }
   10442              :           else
   10443         1872 :             *pc = OMP_CLAUSE_CHAIN (c);
   10444              :         }
   10445              :       else
   10446        99332 :         pc = &OMP_CLAUSE_CHAIN (c);
   10447              :     }
   10448              : 
   10449        65669 :   if (grp_start_p
   10450        65669 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   10451          158 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   10452           95 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   10453              : 
   10454        65669 :   if (reduction_seen < 0 && (ordered_seen || schedule_seen))
   10455        65669 :     reduction_seen = -2;
   10456              : 
   10457       165968 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   10458              :     {
   10459       100299 :       enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
   10460       100299 :       bool remove = false;
   10461       100299 :       bool need_complete_type = false;
   10462       100299 :       bool need_default_ctor = false;
   10463       100299 :       bool need_copy_ctor = false;
   10464       100299 :       bool need_copy_assignment = false;
   10465       100299 :       bool need_implicitly_determined = false;
   10466       100299 :       bool need_dtor = false;
   10467       100299 :       tree type, inner_type;
   10468              : 
   10469       100299 :       switch (c_kind)
   10470              :         {
   10471              :         case OMP_CLAUSE_SHARED:
   10472              :           need_implicitly_determined = true;
   10473              :           break;
   10474         2580 :         case OMP_CLAUSE_PRIVATE:
   10475         2580 :           need_complete_type = true;
   10476         2580 :           need_default_ctor = true;
   10477         2580 :           need_dtor = true;
   10478         2580 :           need_implicitly_determined = true;
   10479         2580 :           break;
   10480         3441 :         case OMP_CLAUSE_FIRSTPRIVATE:
   10481         3441 :           need_complete_type = true;
   10482         3441 :           need_copy_ctor = true;
   10483         3441 :           need_dtor = true;
   10484         3441 :           need_implicitly_determined = true;
   10485         3441 :           break;
   10486         2862 :         case OMP_CLAUSE_LASTPRIVATE:
   10487         2862 :           need_complete_type = true;
   10488         2862 :           need_copy_assignment = true;
   10489         2862 :           need_implicitly_determined = true;
   10490         2862 :           break;
   10491         7844 :         case OMP_CLAUSE_REDUCTION:
   10492         7844 :           if (reduction_seen == -2)
   10493           27 :             OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   10494         7844 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   10495          438 :             need_copy_assignment = true;
   10496              :           need_implicitly_determined = true;
   10497              :           break;
   10498              :         case OMP_CLAUSE_IN_REDUCTION:
   10499              :         case OMP_CLAUSE_TASK_REDUCTION:
   10500              :         case OMP_CLAUSE_INCLUSIVE:
   10501              :         case OMP_CLAUSE_EXCLUSIVE:
   10502              :           need_implicitly_determined = true;
   10503              :           break;
   10504         1553 :         case OMP_CLAUSE_LINEAR:
   10505         1553 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   10506              :             need_implicitly_determined = true;
   10507          679 :           else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   10508          721 :                    && !bitmap_bit_p (&map_head,
   10509           42 :                                      DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   10510              :             {
   10511            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10512              :                         "%<linear%> clause step is a parameter %qD not "
   10513              :                         "specified in %<uniform%> clause",
   10514            6 :                         OMP_CLAUSE_LINEAR_STEP (c));
   10515            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10516        77793 :               continue;
   10517              :             }
   10518              :           break;
   10519              :         case OMP_CLAUSE_COPYPRIVATE:
   10520          369 :           need_copy_assignment = true;
   10521              :           break;
   10522              :         case OMP_CLAUSE_COPYIN:
   10523          369 :           need_copy_assignment = true;
   10524              :           break;
   10525          879 :         case OMP_CLAUSE_SIMDLEN:
   10526          879 :           if (safelen
   10527          345 :               && !processing_template_decl
   10528         1224 :               && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   10529          345 :                                   OMP_CLAUSE_SIMDLEN_EXPR (c)))
   10530              :             {
   10531              :               /* Note: How a scaling factor affects this, is underspecified in
   10532              :                  OpenMP; cf. OpenMP spec issue #5160.  Presumably, it means:
   10533              :                    savelen >= simdlen * scale_factor
   10534              :                  with
   10535              :                    scale_factor = MAX (1, FLOOR_DIV_EXPR (VL(type), divisor))
   10536              :                  and OpenMP states that VL(type) might be only known at runtime.
   10537              :                  Hence scale_factor >= 1 and, conservatively, assume == 1 for
   10538              :                  this error check.  */
   10539            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10540              :                         "%<simdlen%> clause value is bigger than "
   10541              :                         "%<safelen%> clause value");
   10542            0 :               OMP_CLAUSE_SIMDLEN_EXPR (c)
   10543            0 :                 = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   10544              :             }
   10545          879 :           pc = &OMP_CLAUSE_CHAIN (c);
   10546          879 :           continue;
   10547         3887 :         case OMP_CLAUSE_SCHEDULE:
   10548         3887 :           if (ordered_seen
   10549         3887 :               && (OMP_CLAUSE_SCHEDULE_KIND (c)
   10550              :                   & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   10551              :             {
   10552           21 :               error_at (OMP_CLAUSE_LOCATION (c),
   10553              :                         "%<nonmonotonic%> schedule modifier specified "
   10554              :                         "together with %<ordered%> clause");
   10555           42 :               OMP_CLAUSE_SCHEDULE_KIND (c)
   10556           21 :                 = (enum omp_clause_schedule_kind)
   10557           21 :                   (OMP_CLAUSE_SCHEDULE_KIND (c)
   10558              :                    & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   10559              :             }
   10560         3887 :           if (reduction_seen == -2)
   10561            9 :             error_at (OMP_CLAUSE_LOCATION (c),
   10562              :                       "%qs clause specified together with %<inscan%> "
   10563              :                       "%<reduction%> clause", "schedule");
   10564         3887 :           pc = &OMP_CLAUSE_CHAIN (c);
   10565         3887 :           continue;
   10566           51 :         case OMP_CLAUSE_NOGROUP:
   10567           51 :           if (reduction_seen)
   10568              :             {
   10569            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10570              :                         "%<nogroup%> clause must not be used together with "
   10571              :                         "%<reduction%> clause");
   10572            3 :               *pc = OMP_CLAUSE_CHAIN (c);
   10573            3 :               continue;
   10574              :             }
   10575           48 :           pc = &OMP_CLAUSE_CHAIN (c);
   10576           48 :           continue;
   10577          165 :         case OMP_CLAUSE_GRAINSIZE:
   10578          165 :           if (num_tasks_seen)
   10579              :             {
   10580            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10581              :                         "%<grainsize%> clause must not be used together with "
   10582              :                         "%<num_tasks%> clause");
   10583            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10584            6 :               continue;
   10585              :             }
   10586          159 :           pc = &OMP_CLAUSE_CHAIN (c);
   10587          159 :           continue;
   10588          630 :         case OMP_CLAUSE_ORDERED:
   10589          630 :           if (reduction_seen == -2)
   10590            6 :             error_at (OMP_CLAUSE_LOCATION (c),
   10591              :                       "%qs clause specified together with %<inscan%> "
   10592              :                       "%<reduction%> clause", "ordered");
   10593          630 :           pc = &OMP_CLAUSE_CHAIN (c);
   10594          630 :           continue;
   10595         1525 :         case OMP_CLAUSE_ORDER:
   10596         1525 :           if (ordered_seen)
   10597              :             {
   10598           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10599              :                         "%<order%> clause must not be used together "
   10600              :                         "with %<ordered%> clause");
   10601           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10602           12 :               continue;
   10603              :             }
   10604         1513 :           pc = &OMP_CLAUSE_CHAIN (c);
   10605         1513 :           continue;
   10606           57 :         case OMP_CLAUSE_DETACH:
   10607           57 :           if (mergeable_seen)
   10608              :             {
   10609            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10610              :                         "%<detach%> clause must not be used together with "
   10611              :                         "%<mergeable%> clause");
   10612            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10613            6 :               continue;
   10614              :             }
   10615           51 :           pc = &OMP_CLAUSE_CHAIN (c);
   10616           51 :           continue;
   10617        16626 :         case OMP_CLAUSE_MAP:
   10618        16626 :           if (target_in_reduction_seen && !processing_template_decl)
   10619              :             {
   10620          684 :               t = OMP_CLAUSE_DECL (c);
   10621          684 :               while (handled_component_p (t)
   10622              :                      || INDIRECT_REF_P (t)
   10623              :                      || TREE_CODE (t) == ADDR_EXPR
   10624              :                      || TREE_CODE (t) == MEM_REF
   10625          804 :                      || TREE_CODE (t) == NON_LVALUE_EXPR)
   10626          120 :                 t = TREE_OPERAND (t, 0);
   10627          684 :               if (DECL_P (t)
   10628          684 :                   && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   10629          342 :                 OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   10630              :             }
   10631        16626 :           pc = &OMP_CLAUSE_CHAIN (c);
   10632        16626 :           continue;
   10633          225 :         case OMP_CLAUSE_FULL:
   10634          225 :           if (partial_seen)
   10635              :             {
   10636           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10637              :                         "%<full%> clause must not be used together "
   10638              :                         "with %<partial%> clause");
   10639           12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10640           12 :               continue;
   10641              :             }
   10642          213 :           pc = &OMP_CLAUSE_CHAIN (c);
   10643          213 :           continue;
   10644         7263 :         case OMP_CLAUSE_NOWAIT:
   10645         7263 :           if (copyprivate_seen)
   10646              :             {
   10647            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10648              :                         "%<nowait%> clause must not be used together "
   10649              :                         "with %<copyprivate%> clause");
   10650            6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10651            6 :               continue;
   10652              :             }
   10653              :           /* FALLTHRU */
   10654        53056 :         default:
   10655        53056 :           pc = &OMP_CLAUSE_CHAIN (c);
   10656        53056 :           continue;
   10657              :         }
   10658              : 
   10659        23186 :       t = OMP_CLAUSE_DECL (c);
   10660        23186 :       switch (c_kind)
   10661              :         {
   10662         2862 :         case OMP_CLAUSE_LASTPRIVATE:
   10663         2862 :           if (DECL_P (t)
   10664         2862 :               && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
   10665              :             {
   10666         2762 :               need_default_ctor = true;
   10667         2762 :               need_dtor = true;
   10668              :             }
   10669              :           break;
   10670              : 
   10671        10007 :         case OMP_CLAUSE_REDUCTION:
   10672        10007 :         case OMP_CLAUSE_IN_REDUCTION:
   10673        10007 :         case OMP_CLAUSE_TASK_REDUCTION:
   10674        10007 :           if (allocate_seen)
   10675              :             {
   10676         1711 :               if (TREE_CODE (t) == MEM_REF)
   10677              :                 {
   10678          222 :                   t = TREE_OPERAND (t, 0);
   10679          222 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   10680            0 :                     t = TREE_OPERAND (t, 0);
   10681          222 :                   if (TREE_CODE (t) == ADDR_EXPR
   10682          168 :                       || INDIRECT_REF_P (t))
   10683          110 :                     t = TREE_OPERAND (t, 0);
   10684          222 :                   if (DECL_P (t))
   10685          222 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10686              :                 }
   10687         1489 :               else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10688              :                 {
   10689          288 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10690          144 :                     t = TREE_OPERAND (t, 0);
   10691          144 :                   if (DECL_P (t))
   10692          144 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10693          144 :                   t = OMP_CLAUSE_DECL (c);
   10694              :                 }
   10695         1345 :               else if (DECL_P (t))
   10696         1345 :                 bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10697         1711 :               t = OMP_CLAUSE_DECL (c);
   10698              :             }
   10699        10007 :           if (processing_template_decl
   10700          929 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10701              :             break;
   10702         9389 :           if (finish_omp_reduction_clause (c, &need_default_ctor,
   10703              :                                            &need_dtor))
   10704              :             remove = true;
   10705              :           else
   10706         9305 :             t = OMP_CLAUSE_DECL (c);
   10707              :           break;
   10708              : 
   10709          277 :         case OMP_CLAUSE_COPYIN:
   10710          277 :           if (processing_template_decl
   10711            0 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10712              :             break;
   10713          277 :           if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
   10714              :             {
   10715           15 :               error_at (OMP_CLAUSE_LOCATION (c),
   10716              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   10717           15 :               remove = true;
   10718              :             }
   10719              :           break;
   10720              : 
   10721              :         default:
   10722              :           break;
   10723              :         }
   10724              : 
   10725        23186 :       if (processing_template_decl
   10726         1618 :           && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10727              :         {
   10728          680 :           pc = &OMP_CLAUSE_CHAIN (c);
   10729          680 :           continue;
   10730              :         }
   10731              : 
   10732        22506 :       if (need_complete_type || need_copy_assignment)
   10733              :         {
   10734         9634 :           t = require_complete_type (t);
   10735         9634 :           if (t == error_mark_node)
   10736              :             remove = true;
   10737         9610 :           else if (!processing_template_decl
   10738         9219 :                    && TYPE_REF_P (TREE_TYPE (t))
   10739        10167 :                    && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
   10740              :             remove = true;
   10741              :         }
   10742        22506 :       if (need_implicitly_determined)
   10743              :         {
   10744        21465 :           const char *share_name = NULL;
   10745              : 
   10746        21465 :           if (allocate_seen
   10747         5114 :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10748        25700 :               && DECL_P (t))
   10749         3950 :             bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10750              : 
   10751        21465 :           if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   10752              :             share_name = "threadprivate";
   10753        21423 :           else switch (cxx_omp_predetermined_sharing_1 (t))
   10754              :             {
   10755              :             case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   10756              :               break;
   10757           47 :             case OMP_CLAUSE_DEFAULT_SHARED:
   10758           47 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10759           30 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   10760           64 :                   && c_omp_predefined_variable (t))
   10761              :                 /* The __func__ variable and similar function-local predefined
   10762              :                    variables may be listed in a shared or firstprivate
   10763              :                    clause.  */
   10764              :                 break;
   10765           31 :               if (VAR_P (t)
   10766           31 :                   && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10767            9 :                   && TREE_STATIC (t)
   10768           40 :                   && cxx_omp_const_qual_no_mutable (t))
   10769              :                 {
   10770            6 :                   tree ctx = CP_DECL_CONTEXT (t);
   10771              :                   /* const qualified static data members without mutable
   10772              :                      member may be specified in firstprivate clause.  */
   10773            6 :                   if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
   10774              :                     break;
   10775              :                 }
   10776              :               share_name = "shared";
   10777              :               break;
   10778              :             case OMP_CLAUSE_DEFAULT_PRIVATE:
   10779              :               share_name = "private";
   10780              :               break;
   10781            0 :             default:
   10782            0 :               gcc_unreachable ();
   10783              :             }
   10784              :           if (share_name)
   10785              :             {
   10786           67 :               error_at (OMP_CLAUSE_LOCATION (c),
   10787              :                         "%qE is predetermined %qs for %qs",
   10788              :                         omp_clause_printable_decl (t), share_name,
   10789           67 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10790           67 :               remove = true;
   10791              :             }
   10792        21398 :           else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10793        19339 :                    && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
   10794        37325 :                    && cxx_omp_const_qual_no_mutable (t))
   10795              :             {
   10796          126 :               error_at (OMP_CLAUSE_LOCATION (c),
   10797              :                         "%<const%> qualified %qE without %<mutable%> member "
   10798              :                         "may appear only in %<shared%> or %<firstprivate%> "
   10799              :                         "clauses", omp_clause_printable_decl (t));
   10800           63 :               remove = true;
   10801              :             }
   10802              :         }
   10803              : 
   10804        22506 :       if (detach_seen
   10805           16 :           && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10806           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   10807           10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10808            0 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   10809        22522 :           && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
   10810              :         {
   10811            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   10812              :                     "the event handle of a %<detach%> clause "
   10813              :                     "should not be in a data-sharing clause");
   10814            6 :           remove = true;
   10815              :         }
   10816              : 
   10817              :       /* We're interested in the base element, not arrays.  */
   10818        22506 :       inner_type = type = TREE_TYPE (t);
   10819        22506 :       if ((need_complete_type
   10820              :            || need_copy_assignment
   10821        12872 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   10822         5745 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   10823         4248 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   10824        31457 :           && TYPE_REF_P (inner_type))
   10825          932 :         inner_type = TREE_TYPE (inner_type);
   10826        25203 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   10827         2697 :         inner_type = TREE_TYPE (inner_type);
   10828              : 
   10829              :       /* Check for special function availability by building a call to one.
   10830              :          Save the results, because later we won't be in the right context
   10831              :          for making these queries.  */
   10832         2430 :       if (CLASS_TYPE_P (inner_type)
   10833         2430 :           && COMPLETE_TYPE_P (inner_type)
   10834         2361 :           && (need_default_ctor || need_copy_ctor
   10835         1108 :               || need_copy_assignment || need_dtor)
   10836         2037 :           && !type_dependent_expression_p (t)
   10837        24543 :           && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
   10838              :                                          need_copy_ctor, need_copy_assignment,
   10839              :                                          need_dtor))
   10840              :         remove = true;
   10841              : 
   10842        22506 :       if (!remove
   10843        22506 :           && c_kind == OMP_CLAUSE_SHARED
   10844         2056 :           && processing_template_decl)
   10845              :         {
   10846          125 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10847          125 :           if (t)
   10848            5 :             OMP_CLAUSE_DECL (c) = t;
   10849              :         }
   10850              : 
   10851        22506 :       if (remove)
   10852          292 :         *pc = OMP_CLAUSE_CHAIN (c);
   10853              :       else
   10854        22214 :         pc = &OMP_CLAUSE_CHAIN (c);
   10855              :     }
   10856              : 
   10857        65669 :   if (allocate_seen)
   10858        17449 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   10859              :       {
   10860        14948 :         bool remove = false;
   10861        14948 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   10862         2764 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   10863         2312 :             && DECL_P (OMP_CLAUSE_DECL (c))
   10864        17260 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   10865              :           {
   10866           15 :             error_at (OMP_CLAUSE_LOCATION (c),
   10867              :                       "%qD specified in %<allocate%> clause but not in "
   10868           15 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   10869           15 :             remove = true;
   10870              :           }
   10871        14948 :         if (remove)
   10872           15 :           *pc = OMP_CLAUSE_CHAIN (c);
   10873              :         else
   10874        14933 :           pc = &OMP_CLAUSE_CHAIN (c);
   10875              :       }
   10876              : 
   10877        65669 :   if (ort == C_ORT_OMP_INTEROP
   10878        65669 :       && depend_clause
   10879           60 :       && (!init_use_destroy_seen
   10880           57 :           || (init_seen && init_no_targetsync_clause)))
   10881              :     {
   10882            9 :       auto_diagnostic_group d;
   10883            9 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   10884              :                 "%<depend%> clause requires action clauses with "
   10885              :                 "%<targetsync%> interop-type");
   10886            9 :       if (init_no_targetsync_clause)
   10887            6 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   10888              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   10889            9 :     }
   10890              : 
   10891        65669 :   bitmap_obstack_release (NULL);
   10892        65669 :   return clauses;
   10893              : }
   10894              : 
   10895              : /* Start processing OpenMP clauses that can include any
   10896              :    privatization clauses for non-static data members.  */
   10897              : 
   10898              : tree
   10899        50102 : push_omp_privatization_clauses (bool ignore_next)
   10900              : {
   10901        50102 :   if (omp_private_member_ignore_next)
   10902              :     {
   10903          722 :       omp_private_member_ignore_next = ignore_next;
   10904          722 :       return NULL_TREE;
   10905              :     }
   10906        49380 :   omp_private_member_ignore_next = ignore_next;
   10907        49380 :   if (omp_private_member_map)
   10908           24 :     omp_private_member_vec.safe_push (error_mark_node);
   10909        49380 :   return push_stmt_list ();
   10910              : }
   10911              : 
   10912              : /* Revert remapping of any non-static data members since
   10913              :    the last push_omp_privatization_clauses () call.  */
   10914              : 
   10915              : void
   10916        50096 : pop_omp_privatization_clauses (tree stmt)
   10917              : {
   10918        50096 :   if (stmt == NULL_TREE)
   10919              :     return;
   10920        49374 :   stmt = pop_stmt_list (stmt);
   10921        49374 :   if (omp_private_member_map)
   10922              :     {
   10923         1280 :       while (!omp_private_member_vec.is_empty ())
   10924              :         {
   10925          850 :           tree t = omp_private_member_vec.pop ();
   10926          850 :           if (t == error_mark_node)
   10927              :             {
   10928           24 :               add_stmt (stmt);
   10929           24 :               return;
   10930              :             }
   10931          826 :           bool no_decl_expr = t == integer_zero_node;
   10932          826 :           if (no_decl_expr)
   10933          136 :             t = omp_private_member_vec.pop ();
   10934          826 :           tree *v = omp_private_member_map->get (t);
   10935          826 :           gcc_assert (v);
   10936          826 :           if (!no_decl_expr)
   10937          690 :             add_decl_expr (*v);
   10938          826 :           omp_private_member_map->remove (t);
   10939              :         }
   10940          860 :       delete omp_private_member_map;
   10941          430 :       omp_private_member_map = NULL;
   10942              :     }
   10943        49350 :   add_stmt (stmt);
   10944              : }
   10945              : 
   10946              : /* Remember OpenMP privatization clauses mapping and clear it.
   10947              :    Used for lambdas.  */
   10948              : 
   10949              : void
   10950     16252584 : save_omp_privatization_clauses (vec<tree> &save)
   10951              : {
   10952     16252584 :   save = vNULL;
   10953     16252584 :   if (omp_private_member_ignore_next)
   10954            2 :     save.safe_push (integer_one_node);
   10955     16252584 :   omp_private_member_ignore_next = false;
   10956     16252584 :   if (!omp_private_member_map)
   10957              :     return;
   10958              : 
   10959            0 :   while (!omp_private_member_vec.is_empty ())
   10960              :     {
   10961            0 :       tree t = omp_private_member_vec.pop ();
   10962            0 :       if (t == error_mark_node)
   10963              :         {
   10964            0 :           save.safe_push (t);
   10965            0 :           continue;
   10966              :         }
   10967            0 :       tree n = t;
   10968            0 :       if (t == integer_zero_node)
   10969            0 :         t = omp_private_member_vec.pop ();
   10970            0 :       tree *v = omp_private_member_map->get (t);
   10971            0 :       gcc_assert (v);
   10972            0 :       save.safe_push (*v);
   10973            0 :       save.safe_push (t);
   10974            0 :       if (n != t)
   10975            0 :         save.safe_push (n);
   10976              :     }
   10977            0 :   delete omp_private_member_map;
   10978            0 :   omp_private_member_map = NULL;
   10979              : }
   10980              : 
   10981              : /* Restore OpenMP privatization clauses mapping saved by the
   10982              :    above function.  */
   10983              : 
   10984              : void
   10985     16252584 : restore_omp_privatization_clauses (vec<tree> &save)
   10986              : {
   10987     16252584 :   gcc_assert (omp_private_member_vec.is_empty ());
   10988     16252584 :   omp_private_member_ignore_next = false;
   10989     16252584 :   if (save.is_empty ())
   10990              :     return;
   10991            4 :   if (save.length () == 1 && save[0] == integer_one_node)
   10992              :     {
   10993            2 :       omp_private_member_ignore_next = true;
   10994            2 :       save.release ();
   10995            2 :       return;
   10996              :     }
   10997              : 
   10998            0 :   omp_private_member_map = new hash_map <tree, tree>;
   10999            0 :   while (!save.is_empty ())
   11000              :     {
   11001            0 :       tree t = save.pop ();
   11002            0 :       tree n = t;
   11003            0 :       if (t != error_mark_node)
   11004              :         {
   11005            0 :           if (t == integer_one_node)
   11006              :             {
   11007            0 :               omp_private_member_ignore_next = true;
   11008            0 :               gcc_assert (save.is_empty ());
   11009            0 :               break;
   11010              :             }
   11011            0 :           if (t == integer_zero_node)
   11012            0 :             t = save.pop ();
   11013            0 :           tree &v = omp_private_member_map->get_or_insert (t);
   11014            0 :           v = save.pop ();
   11015              :         }
   11016            0 :       omp_private_member_vec.safe_push (t);
   11017            0 :       if (n != t)
   11018            0 :         omp_private_member_vec.safe_push (n);
   11019              :     }
   11020            0 :   save.release ();
   11021              : }
   11022              : 
   11023              : /* For all variables in the tree_list VARS, mark them as thread local.  */
   11024              : 
   11025              : void
   11026          244 : finish_omp_threadprivate (tree vars)
   11027              : {
   11028          244 :   tree t;
   11029              : 
   11030              :   /* Mark every variable in VARS to be assigned thread local storage.  */
   11031          521 :   for (t = vars; t; t = TREE_CHAIN (t))
   11032              :     {
   11033          277 :       tree v = TREE_PURPOSE (t);
   11034          277 :       location_t loc = EXPR_LOCATION (TREE_VALUE (t));
   11035              : 
   11036          277 :       if (error_operand_p (v))
   11037              :         ;
   11038          277 :       else if (!VAR_P (v))
   11039            6 :         error_at (loc, "%<threadprivate%> %qD is not file, namespace "
   11040              :                        "or block scope variable", v);
   11041              :       /* If V had already been marked threadprivate, it doesn't matter
   11042              :          whether it had been used prior to this point.  */
   11043          271 :       else if (TREE_USED (v)
   11044          271 :           && (DECL_LANG_SPECIFIC (v) == NULL
   11045            3 :               || !CP_DECL_THREADPRIVATE_P (v)))
   11046            6 :         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
   11047          265 :       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
   11048            6 :         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
   11049          259 :       else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
   11050            3 :         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
   11051          207 :       else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
   11052          279 :                && CP_DECL_CONTEXT (v) != current_class_type)
   11053            6 :         error_at (loc, "%<threadprivate%> %qE directive not "
   11054            6 :                        "in %qT definition", v, CP_DECL_CONTEXT (v));
   11055              :       else
   11056              :         {
   11057              :           /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
   11058          250 :           if (DECL_LANG_SPECIFIC (v) == NULL)
   11059          206 :             retrofit_lang_decl (v);
   11060              : 
   11061          250 :           if (! CP_DECL_THREAD_LOCAL_P (v))
   11062              :             {
   11063          250 :               CP_DECL_THREAD_LOCAL_P (v) = true;
   11064          250 :               set_decl_tls_model (v, decl_default_tls_model (v));
   11065              :               /* If rtl has been already set for this var, call
   11066              :                  make_decl_rtl once again, so that encode_section_info
   11067              :                  has a chance to look at the new decl flags.  */
   11068          250 :               if (DECL_RTL_SET_P (v))
   11069            0 :                 make_decl_rtl (v);
   11070              :             }
   11071          250 :           CP_DECL_THREADPRIVATE_P (v) = 1;
   11072              :         }
   11073              :     }
   11074          244 : }
   11075              : 
   11076              : /* Build an OpenMP structured block.  */
   11077              : 
   11078              : tree
   11079        66974 : begin_omp_structured_block (void)
   11080              : {
   11081        66974 :   return do_pushlevel (sk_omp);
   11082              : }
   11083              : 
   11084              : tree
   11085        66959 : finish_omp_structured_block (tree block)
   11086              : {
   11087        66959 :   return do_poplevel (block);
   11088              : }
   11089              : 
   11090              : /* Similarly, except force the retention of the BLOCK.  */
   11091              : 
   11092              : tree
   11093        15300 : begin_omp_parallel (void)
   11094              : {
   11095        15300 :   keep_next_level (true);
   11096        15300 :   return begin_omp_structured_block ();
   11097              : }
   11098              : 
   11099              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   11100              :    statement.  */
   11101              : 
   11102              : tree
   11103          768 : finish_oacc_data (tree clauses, tree block)
   11104              : {
   11105          768 :   tree stmt;
   11106              : 
   11107          768 :   block = finish_omp_structured_block (block);
   11108              : 
   11109          768 :   stmt = make_node (OACC_DATA);
   11110          768 :   TREE_TYPE (stmt) = void_type_node;
   11111          768 :   OACC_DATA_CLAUSES (stmt) = clauses;
   11112          768 :   OACC_DATA_BODY (stmt) = block;
   11113              : 
   11114          768 :   return add_stmt (stmt);
   11115              : }
   11116              : 
   11117              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   11118              :    statement.  */
   11119              : 
   11120              : tree
   11121           55 : finish_oacc_host_data (tree clauses, tree block)
   11122              : {
   11123           55 :   tree stmt;
   11124              : 
   11125           55 :   block = finish_omp_structured_block (block);
   11126              : 
   11127           55 :   stmt = make_node (OACC_HOST_DATA);
   11128           55 :   TREE_TYPE (stmt) = void_type_node;
   11129           55 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   11130           55 :   OACC_HOST_DATA_BODY (stmt) = block;
   11131              : 
   11132           55 :   return add_stmt (stmt);
   11133              : }
   11134              : 
   11135              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   11136              :    statement.  */
   11137              : 
   11138              : tree
   11139         4689 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
   11140              : {
   11141         4689 :   body = finish_omp_structured_block (body);
   11142              : 
   11143         4689 :   tree stmt = make_node (code);
   11144         4689 :   TREE_TYPE (stmt) = void_type_node;
   11145         4689 :   OMP_BODY (stmt) = body;
   11146         4689 :   OMP_CLAUSES (stmt) = clauses;
   11147              : 
   11148         4689 :   return add_stmt (stmt);
   11149              : }
   11150              : 
   11151              : /* Used to walk OpenMP target directive body.  */
   11152              : 
   11153              : struct omp_target_walk_data
   11154              : {
   11155              :   /* Holds the 'this' expression found in current function.  */
   11156              :   tree current_object;
   11157              : 
   11158              :   /* True if the 'this' expression was accessed in the target body.  */
   11159              :   bool this_expr_accessed;
   11160              : 
   11161              :   /* For non-static functions, record which pointer-typed members were
   11162              :      accessed, and the whole expression.  */
   11163              :   hash_map<tree, tree> ptr_members_accessed;
   11164              : 
   11165              :   /* Record which lambda objects were accessed in target body.  */
   11166              :   hash_set<tree> lambda_objects_accessed;
   11167              : 
   11168              :   /* For lambda functions, the __closure object expression of the current
   11169              :      function, and the set of captured variables accessed in target body.  */
   11170              :   tree current_closure;
   11171              :   hash_set<tree> closure_vars_accessed;
   11172              : 
   11173              :   /* Local variables declared inside a BIND_EXPR, used to filter out such
   11174              :      variables when recording lambda_objects_accessed.  */
   11175              :   hash_set<tree> local_decls;
   11176              : 
   11177              :   omp_mapper_list<tree> *mappers;
   11178              : };
   11179              : 
   11180              : /* Helper function of finish_omp_target_clauses, called via
   11181              :    cp_walk_tree_without_duplicates.  Traverse body of OpenMP target
   11182              :    directive *TP, and fill out omp_target_walk_data passed in *PTR.  */
   11183              : 
   11184              : static tree
   11185       254943 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
   11186              : {
   11187       254943 :   tree t = *tp;
   11188       254943 :   struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
   11189       254943 :   tree current_object = data->current_object;
   11190       254943 :   tree current_closure = data->current_closure;
   11191       254943 :   omp_mapper_list<tree> *mlist = data->mappers;
   11192              : 
   11193              :   /* References inside of these expression codes shouldn't incur any
   11194              :      form of mapping, so return early.  */
   11195       254943 :   if (TREE_CODE (t) == SIZEOF_EXPR
   11196       254935 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   11197              :     {
   11198            8 :       *walk_subtrees = 0;
   11199            8 :       return NULL_TREE;
   11200              :     }
   11201              : 
   11202       254935 :   if (TREE_CODE (t) == OMP_CLAUSE)
   11203              :     return NULL_TREE;
   11204              : 
   11205       240324 :   if (!processing_template_decl)
   11206              :     {
   11207       240324 :       tree aggr_type = NULL_TREE;
   11208              : 
   11209       240324 :       if (TREE_CODE (t) == COMPONENT_REF
   11210       240324 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   11211         2280 :         aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   11212       238044 :       else if ((TREE_CODE (t) == VAR_DECL
   11213              :                 || TREE_CODE (t) == PARM_DECL
   11214              :                 || TREE_CODE (t) == RESULT_DECL)
   11215        19032 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   11216         1250 :         aggr_type = TREE_TYPE (t);
   11217              : 
   11218         3530 :       if (aggr_type)
   11219              :         {
   11220         3530 :           tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
   11221         3530 :           if (mapper_fn)
   11222          199 :             mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   11223              :         }
   11224              :     }
   11225              : 
   11226       240324 :   if (current_object)
   11227              :     {
   11228         2565 :       tree this_expr = TREE_OPERAND (current_object, 0);
   11229              : 
   11230         2565 :       if (operand_equal_p (t, this_expr))
   11231              :         {
   11232           35 :           data->this_expr_accessed = true;
   11233           35 :           *walk_subtrees = 0;
   11234           35 :           return NULL_TREE;
   11235              :         }
   11236              : 
   11237         2530 :       if (TREE_CODE (t) == COMPONENT_REF
   11238          115 :           && POINTER_TYPE_P (TREE_TYPE (t))
   11239           36 :           && operand_equal_p (TREE_OPERAND (t, 0), current_object)
   11240         2564 :           && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
   11241              :         {
   11242           34 :           data->this_expr_accessed = true;
   11243           34 :           tree fld = TREE_OPERAND (t, 1);
   11244           34 :           if (data->ptr_members_accessed.get (fld) == NULL)
   11245              :             {
   11246           14 :               if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
   11247            4 :                 t = convert_from_reference (t);
   11248           14 :               data->ptr_members_accessed.put (fld, t);
   11249              :             }
   11250           34 :           *walk_subtrees = 0;
   11251           34 :           return NULL_TREE;
   11252              :         }
   11253              :     }
   11254              : 
   11255              :   /* When the current_function_decl is a lambda function, the closure object
   11256              :      argument's type seems to not yet have fields laid out, so a recording
   11257              :      of DECL_VALUE_EXPRs during the target body walk seems the only way to
   11258              :      find them.  */
   11259       240255 :   if (current_closure
   11260          301 :       && (VAR_P (t)
   11261              :           || TREE_CODE (t) == PARM_DECL
   11262              :           || TREE_CODE (t) == RESULT_DECL)
   11263           24 :       && DECL_HAS_VALUE_EXPR_P (t)
   11264           10 :       && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
   11265       240265 :       && operand_equal_p (current_closure,
   11266           10 :                           TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
   11267              :     {
   11268            9 :       if (!data->closure_vars_accessed.contains (t))
   11269            9 :         data->closure_vars_accessed.add (t);
   11270            9 :       *walk_subtrees = 0;
   11271            9 :       return NULL_TREE;
   11272              :     }
   11273              : 
   11274       240246 :   if (TREE_CODE (t) == BIND_EXPR)
   11275              :     {
   11276        22722 :       if (tree block = BIND_EXPR_BLOCK (t))
   11277        26041 :         for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
   11278         3323 :           if ((VAR_P (var)
   11279              :                || TREE_CODE (var) == PARM_DECL
   11280              :                || TREE_CODE (var) == RESULT_DECL)
   11281         3283 :               && !data->local_decls.contains (var))
   11282         3283 :             data->local_decls.add (var);
   11283              :       return NULL_TREE;
   11284              :     }
   11285              : 
   11286              :   /* Note, this really should be done during gimplification using
   11287              :      a target hook instead, as a magic declare mapper for the lambda
   11288              :      types.  */
   11289       217524 :   if (tree lt = TREE_TYPE (t))
   11290       209077 :     if (LAMBDA_TYPE_P (lt))
   11291              :       {
   11292          118 :         gcc_assert (CLASS_TYPE_P (lt));
   11293              : 
   11294          118 :         if (location_wrapper_p (t))
   11295              :           /* The wrapped DECL gets handled when walking its operand.  */
   11296            0 :           return NULL_TREE;
   11297              : 
   11298          118 :         if (TREE_CODE (t) == TARGET_EXPR
   11299          118 :             && !data->local_decls.contains (TARGET_EXPR_SLOT (t)))
   11300           21 :           data->local_decls.add (TARGET_EXPR_SLOT (t));
   11301              : 
   11302          118 :         tree b = t;
   11303          118 :         while (TREE_CODE (b) == COMPONENT_REF
   11304              :                /* Note, this isn't fully correct.  We can handle it
   11305              :                   this way for constant index, or when it is e.g.
   11306              :                   a value of firstprivatized variable, but we can't
   11307              :                   do that if something in the index expression is
   11308              :                   local to the target region.  */
   11309          143 :                || TREE_CODE (b) == ARRAY_REF)
   11310           25 :           b = TREE_OPERAND (b, 0);
   11311          118 :         STRIP_ANY_LOCATION_WRAPPER (b);
   11312          118 :         if ((VAR_P (b)
   11313              :              || TREE_CODE (b) == PARM_DECL
   11314              :              || TREE_CODE (b) == RESULT_DECL)
   11315           48 :             && !data->lambda_objects_accessed.contains (t)
   11316              :             /* Do not prepare to create target maps for locally declared
   11317              :                lambdas or anonymous ones.  */
   11318           48 :             && !data->local_decls.contains (b))
   11319           18 :           data->lambda_objects_accessed.add (t);
   11320              :       }
   11321              : 
   11322              :   return NULL_TREE;
   11323              : }
   11324              : 
   11325              : /* Helper function for finish_omp_target, and also from tsubst_expr.
   11326              :    Create additional clauses for mapping of non-static members, lambda objects,
   11327              :    etc.  */
   11328              : 
   11329              : void
   11330         7450 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
   11331              : {
   11332         7450 :   omp_target_walk_data data;
   11333         7450 :   data.this_expr_accessed = false;
   11334         7450 :   data.current_object = NULL_TREE;
   11335              : 
   11336         7450 :   if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
   11337           96 :     if (tree ct = current_nonlambda_class_type ())
   11338              :       {
   11339           95 :         tree object = maybe_dummy_object (ct, NULL);
   11340           95 :         object = maybe_resolve_dummy (object, true);
   11341           95 :         data.current_object = object;
   11342              :       }
   11343              : 
   11344         7450 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11345              :     {
   11346            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11347            8 :       data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11348              :     }
   11349              :   else
   11350              :     data.current_closure = NULL_TREE;
   11351              : 
   11352         7450 :   auto_vec<tree, 16> new_clauses;
   11353              : 
   11354         7450 :   if (!processing_template_decl)
   11355              :     {
   11356         7450 :       hash_set<omp_name_type<tree> > seen_types;
   11357         7450 :       auto_vec<tree> mapper_fns;
   11358         7450 :       omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
   11359         7450 :       data.mappers = &mlist;
   11360              : 
   11361         7450 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11362              :                                        &data);
   11363              : 
   11364         7450 :       unsigned int i;
   11365         7450 :       tree mapper_fn;
   11366        14993 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11367           93 :         c_omp_find_nested_mappers (&mlist, mapper_fn);
   11368              : 
   11369         7613 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   11370              :         {
   11371           93 :           tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
   11372           93 :           if (mapper == error_mark_node)
   11373            0 :             continue;
   11374           93 :           tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   11375           93 :           tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   11376           93 :           if (BASELINK_P (mapper_fn))
   11377            0 :             mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
   11378              : 
   11379           93 :           tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   11380           93 :           OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   11381           93 :           OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   11382           93 :           OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
   11383              : 
   11384           93 :           new_clauses.safe_push (c);
   11385              :         }
   11386         7450 :     }
   11387              :   else
   11388              :     {
   11389            0 :       data.mappers = NULL;
   11390            0 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   11391              :                                        &data);
   11392              :     }
   11393              : 
   11394         7450 :   tree omp_target_this_expr = NULL_TREE;
   11395         7450 :   tree *explicit_this_deref_map = NULL;
   11396         7450 :   if (data.this_expr_accessed)
   11397              :     {
   11398           31 :       omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
   11399              : 
   11400              :       /* See if explicit user-specified map(this[:]) clause already exists.
   11401              :          If not, we create an implicit map(tofrom:this[:1]) clause.  */
   11402           80 :       for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
   11403           50 :         if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
   11404           47 :             && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
   11405           40 :                 || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
   11406           57 :             && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
   11407              :                                 omp_target_this_expr))
   11408              :           {
   11409              :             explicit_this_deref_map = cp;
   11410              :             break;
   11411              :           }
   11412              :     }
   11413              : 
   11414         7450 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11415         7450 :       && (data.this_expr_accessed
   11416            1 :           || !data.closure_vars_accessed.is_empty ()))
   11417              :     {
   11418              :       /* For lambda functions, we need to first create a copy of the
   11419              :          __closure object.  */
   11420            8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   11421            8 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11422            8 :       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   11423            8 :       OMP_CLAUSE_DECL (c)
   11424            8 :         = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   11425            8 :       OMP_CLAUSE_SIZE (c)
   11426            8 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
   11427            8 :       new_clauses.safe_push (c);
   11428              : 
   11429            8 :       tree closure_obj = OMP_CLAUSE_DECL (c);
   11430            8 :       tree closure_type = TREE_TYPE (closure_obj);
   11431              : 
   11432           16 :       gcc_assert (LAMBDA_TYPE_P (closure_type)
   11433              :                   && CLASS_TYPE_P (closure_type));
   11434              : 
   11435            8 :       tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11436            8 :       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   11437            8 :       OMP_CLAUSE_DECL (c2) = closure;
   11438            8 :       OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11439            8 :       new_clauses.safe_push (c2);
   11440              :     }
   11441              : 
   11442         7450 :   if (data.this_expr_accessed)
   11443              :     {
   11444              :       /* If the this-expr was accessed, create a map(*this) clause.  */
   11445           31 :       enum gomp_map_kind kind = GOMP_MAP_TOFROM;
   11446           31 :       if (explicit_this_deref_map)
   11447              :         {
   11448            1 :           tree this_map = *explicit_this_deref_map;
   11449            1 :           tree nc = OMP_CLAUSE_CHAIN (this_map);
   11450            2 :           gcc_assert (nc != NULL_TREE
   11451              :                       && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11452              :                       && (OMP_CLAUSE_MAP_KIND (nc)
   11453              :                           == GOMP_MAP_FIRSTPRIVATE_POINTER));
   11454            1 :           kind = OMP_CLAUSE_MAP_KIND (this_map);
   11455              :           /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
   11456              :              two-map sequence away from the chain.  */
   11457            1 :           *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
   11458              :         }
   11459           31 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11460           31 :       OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11461           31 :       OMP_CLAUSE_DECL (c)
   11462           31 :         = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
   11463           31 :       OMP_CLAUSE_SIZE (c)
   11464           31 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
   11465           31 :       new_clauses.safe_push (c);
   11466              : 
   11467              :       /* If we're in a lambda function, the this-pointer will actually be
   11468              :          '__closure->this', a mapped member of __closure, hence always_pointer.
   11469              :          Otherwise it's a firstprivate pointer.  */
   11470           31 :       enum gomp_map_kind ptr_kind
   11471           31 :         = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   11472           31 :            ? GOMP_MAP_ALWAYS_POINTER
   11473           24 :            : GOMP_MAP_FIRSTPRIVATE_POINTER);
   11474           31 :       c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11475           31 :       OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11476           31 :       OMP_CLAUSE_DECL (c) = omp_target_this_expr;
   11477           31 :       OMP_CLAUSE_SIZE (c) = size_zero_node;
   11478           31 :       new_clauses.safe_push (c);
   11479              :     }
   11480              : 
   11481         7450 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   11482              :     {
   11483            8 :       if (omp_target_this_expr)
   11484              :         {
   11485            7 :           STRIP_NOPS (omp_target_this_expr);
   11486            7 :           gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
   11487            7 :           omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
   11488              :         }
   11489              : 
   11490           17 :       for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
   11491           25 :            i != data.closure_vars_accessed.end (); ++i)
   11492              :         {
   11493            9 :           tree orig_decl = *i;
   11494            9 :           tree closure_expr = DECL_VALUE_EXPR (orig_decl);
   11495              : 
   11496            9 :           if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
   11497            9 :               || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
   11498              :             {
   11499              :               /* this-pointer is processed above, outside this loop.  */
   11500            3 :               if (omp_target_this_expr
   11501            3 :                   && operand_equal_p (closure_expr, omp_target_this_expr))
   11502            0 :                 continue;
   11503              : 
   11504            3 :               bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
   11505            3 :               enum gomp_map_kind kind, ptr_kind, nc_kind;
   11506            3 :               tree size;
   11507              : 
   11508            3 :               if (ptr_p)
   11509              :                 {
   11510              :                   /* For pointers, default mapped as zero-length array
   11511              :                      section.  */
   11512            2 :                   kind = GOMP_MAP_ALLOC;
   11513            2 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   11514            2 :                   ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   11515            2 :                   size = size_zero_node;
   11516              :                 }
   11517              :               else
   11518              :                 {
   11519              :                   /* For references, default mapped as appearing on map
   11520              :                      clause.  */
   11521            1 :                   kind = GOMP_MAP_TOFROM;
   11522            1 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
   11523            1 :                   ptr_kind = GOMP_MAP_ALWAYS_POINTER;
   11524            1 :                   size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
   11525              :                 }
   11526              : 
   11527            6 :               for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
   11528            3 :                 if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
   11529            1 :                     && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
   11530            1 :                         || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
   11531            3 :                     && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
   11532              :                                         orig_decl))
   11533              :                   {
   11534              :                     /* If this was already specified by user as a map,
   11535              :                        save the user specified map kind, delete the
   11536              :                        "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
   11537              :                        and insert our own sequence:
   11538              :                        "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
   11539              :                     */
   11540            0 :                     tree nc = OMP_CLAUSE_CHAIN (*p);
   11541            0 :                     gcc_assert (nc != NULL_TREE
   11542              :                                 && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11543              :                                 && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
   11544              :                     /* Update with user specified kind and size.  */
   11545            0 :                     kind = OMP_CLAUSE_MAP_KIND (*p);
   11546            0 :                     size = OMP_CLAUSE_SIZE (*p);
   11547            0 :                     *p = OMP_CLAUSE_CHAIN (nc);
   11548            0 :                     break;
   11549              :                   }
   11550              : 
   11551            3 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11552            3 :               OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11553            3 :               OMP_CLAUSE_DECL (c)
   11554            3 :                 = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
   11555            3 :               OMP_CLAUSE_SIZE (c) = size;
   11556            3 :               if (ptr_p)
   11557            2 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11558            3 :               new_clauses.safe_push (c);
   11559              : 
   11560            3 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11561            3 :               OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11562            3 :               OMP_CLAUSE_DECL (c) = closure_expr;
   11563            3 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11564            3 :               new_clauses.safe_push (c);
   11565              :             }
   11566              :         }
   11567              :     }
   11568              : 
   11569         7450 :   if (!data.ptr_members_accessed.is_empty ())
   11570           14 :     for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
   11571           42 :          i != data.ptr_members_accessed.end (); ++i)
   11572              :       {
   11573              :         /* For each referenced member that is of pointer or reference-to-pointer
   11574              :            type, create the equivalent of map(alloc:this->ptr[:0]).  */
   11575           14 :         tree field_decl = (*i).first;
   11576           14 :         tree ptr_member = (*i).second;
   11577              : 
   11578           26 :         for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
   11579              :           {
   11580           16 :             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   11581            2 :               continue;
   11582              :             /* If map(this->ptr[:N]) already exists, avoid creating another
   11583              :                such map.  */
   11584           14 :             tree decl = OMP_CLAUSE_DECL (c);
   11585           14 :             if ((TREE_CODE (decl) == INDIRECT_REF
   11586           10 :                  || TREE_CODE (decl) == MEM_REF)
   11587           14 :                 && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
   11588            4 :               goto next_ptr_member;
   11589              :           }
   11590              : 
   11591           10 :         if (!cxx_mark_addressable (ptr_member))
   11592            0 :           gcc_unreachable ();
   11593              : 
   11594           10 :         if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
   11595              :           {
   11596              :             /* For reference to pointers, we need to map the referenced
   11597              :                pointer first for things to be correct.  */
   11598            4 :             tree ptr_member_type = TREE_TYPE (ptr_member);
   11599              : 
   11600              :             /* Map pointer target as zero-length array section.  */
   11601            4 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11602            4 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11603            4 :             OMP_CLAUSE_DECL (c)
   11604            4 :               = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
   11605            4 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11606            4 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11607              : 
   11608              :             /* Map pointer to zero-length array section.  */
   11609            4 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11610            4 :             OMP_CLAUSE_SET_MAP_KIND
   11611              :               (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
   11612            4 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11613            4 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11614              : 
   11615              :             /* Attach reference-to-pointer field to pointer.  */
   11616            4 :             tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11617            4 :             OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
   11618            4 :             OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
   11619            4 :             OMP_CLAUSE_SIZE (c3) = size_zero_node;
   11620              : 
   11621            4 :             new_clauses.safe_push (c);
   11622            4 :             new_clauses.safe_push (c2);
   11623            4 :             new_clauses.safe_push (c3);
   11624              :           }
   11625            6 :         else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
   11626              :           {
   11627              :             /* Map pointer target as zero-length array section.  */
   11628            6 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11629            6 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11630            6 :             OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
   11631              :                                                       RO_UNARY_STAR);
   11632            6 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11633            6 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11634              : 
   11635              :             /* Attach zero-length array section to pointer.  */
   11636            6 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11637            6 :             OMP_CLAUSE_SET_MAP_KIND
   11638              :               (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11639            6 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11640            6 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11641              : 
   11642            6 :             new_clauses.safe_push (c);
   11643            6 :             new_clauses.safe_push (c2);
   11644              :           }
   11645              :         else
   11646            0 :           gcc_unreachable ();
   11647              : 
   11648           14 :       next_ptr_member:
   11649           14 :         ;
   11650              :       }
   11651              : 
   11652         7468 :   for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
   11653         7468 :        i != data.lambda_objects_accessed.end (); ++i)
   11654              :     {
   11655           18 :       tree lobj = *i;
   11656           18 :       if (TREE_CODE (lobj) == TARGET_EXPR)
   11657            0 :         lobj = TARGET_EXPR_SLOT (lobj);
   11658              : 
   11659           18 :       tree lt = TREE_TYPE (lobj);
   11660           36 :       gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
   11661              : 
   11662           18 :       tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11663           18 :       OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
   11664           18 :       OMP_CLAUSE_DECL (lc) = lobj;
   11665           18 :       OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
   11666           18 :       new_clauses.safe_push (lc);
   11667              : 
   11668          274 :       for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
   11669              :         {
   11670          256 :           if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
   11671              :             {
   11672            4 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11673              :                                  lobj, fld, NULL_TREE);
   11674            4 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11675            4 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11676            4 :               OMP_CLAUSE_DECL (c)
   11677            4 :                 = build_indirect_ref (loc, exp, RO_UNARY_STAR);
   11678            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11679            4 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11680            4 :               new_clauses.safe_push (c);
   11681              : 
   11682            4 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11683            4 :               OMP_CLAUSE_SET_MAP_KIND
   11684              :                 (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11685            4 :               OMP_CLAUSE_DECL (c) = exp;
   11686            4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11687            4 :               new_clauses.safe_push (c);
   11688              :             }
   11689          252 :           else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
   11690              :             {
   11691           14 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11692              :                                  lobj, fld, NULL_TREE);
   11693           14 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11694           14 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   11695           14 :               OMP_CLAUSE_DECL (c)
   11696           14 :                 = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
   11697           14 :               OMP_CLAUSE_SIZE (c)
   11698           14 :                 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
   11699           14 :               new_clauses.safe_push (c);
   11700              : 
   11701           14 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11702           14 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   11703           14 :               OMP_CLAUSE_DECL (c) = exp;
   11704           14 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11705           14 :               new_clauses.safe_push (c);
   11706              :             }
   11707              :         }
   11708              :     }
   11709              : 
   11710         7450 :   tree c = *clauses_ptr;
   11711        15155 :   for (int i = new_clauses.length () - 1; i >= 0; i--)
   11712              :     {
   11713          255 :       OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
   11714          255 :       c = new_clauses[i];
   11715              :     }
   11716         7450 :   *clauses_ptr = c;
   11717         7450 : }
   11718              : 
   11719              : /* Called from cp_parser_omp_target.  Create additional implicit clauses for
   11720              :    OpenMP target directives, and do sanity checks.  */
   11721              : 
   11722              : tree
   11723         7440 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
   11724              : {
   11725         7440 :   if (!processing_template_decl)
   11726         6631 :     finish_omp_target_clauses (loc, body, &clauses);
   11727              : 
   11728         7440 :   tree stmt = make_node (OMP_TARGET);
   11729         7440 :   TREE_TYPE (stmt) = void_type_node;
   11730         7440 :   OMP_TARGET_CLAUSES (stmt) = clauses;
   11731         7440 :   OMP_TARGET_BODY (stmt) = body;
   11732         7440 :   OMP_TARGET_COMBINED (stmt) = combined_p;
   11733         7440 :   SET_EXPR_LOCATION (stmt, loc);
   11734              : 
   11735         7440 :   tree c = clauses;
   11736        17961 :   while (c)
   11737              :     {
   11738        10521 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   11739         6245 :         switch (OMP_CLAUSE_MAP_KIND (c))
   11740              :           {
   11741              :           case GOMP_MAP_TO:
   11742              :           case GOMP_MAP_ALWAYS_TO:
   11743              :           case GOMP_MAP_PRESENT_TO:
   11744              :           case GOMP_MAP_ALWAYS_PRESENT_TO:
   11745              :           case GOMP_MAP_FROM:
   11746              :           case GOMP_MAP_ALWAYS_FROM:
   11747              :           case GOMP_MAP_PRESENT_FROM:
   11748              :           case GOMP_MAP_ALWAYS_PRESENT_FROM:
   11749              :           case GOMP_MAP_TOFROM:
   11750              :           case GOMP_MAP_ALWAYS_TOFROM:
   11751              :           case GOMP_MAP_PRESENT_TOFROM:
   11752              :           case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   11753              :           case GOMP_MAP_ALLOC:
   11754              :           case GOMP_MAP_PRESENT_ALLOC:
   11755              :           case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11756              :           case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11757              :           case GOMP_MAP_ALWAYS_POINTER:
   11758              :           case GOMP_MAP_ATTACH_DETACH:
   11759              :           case GOMP_MAP_ATTACH:
   11760              :           case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   11761              :           case GOMP_MAP_POINTER:
   11762              :           case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   11763              :             break;
   11764            3 :           default:
   11765            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   11766              :                       "%<#pragma omp target%> with map-type other "
   11767              :                       "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
   11768              :                       "on %<map%> clause");
   11769            3 :             break;
   11770              :           }
   11771        10521 :       c = OMP_CLAUSE_CHAIN (c);
   11772              :     }
   11773         7440 :   return add_stmt (stmt);
   11774              : }
   11775              : 
   11776              : tree
   11777         9788 : finish_omp_parallel (tree clauses, tree body)
   11778              : {
   11779         9788 :   tree stmt;
   11780              : 
   11781         9788 :   body = finish_omp_structured_block (body);
   11782              : 
   11783         9788 :   stmt = make_node (OMP_PARALLEL);
   11784         9788 :   TREE_TYPE (stmt) = void_type_node;
   11785         9788 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   11786         9788 :   OMP_PARALLEL_BODY (stmt) = body;
   11787              : 
   11788         9788 :   return add_stmt (stmt);
   11789              : }
   11790              : 
   11791              : tree
   11792         2418 : begin_omp_task (void)
   11793              : {
   11794         2418 :   keep_next_level (true);
   11795         2418 :   return begin_omp_structured_block ();
   11796              : }
   11797              : 
   11798              : tree
   11799         2418 : finish_omp_task (tree clauses, tree body)
   11800              : {
   11801         2418 :   tree stmt;
   11802              : 
   11803         2418 :   body = finish_omp_structured_block (body);
   11804              : 
   11805         2418 :   stmt = make_node (OMP_TASK);
   11806         2418 :   TREE_TYPE (stmt) = void_type_node;
   11807         2418 :   OMP_TASK_CLAUSES (stmt) = clauses;
   11808         2418 :   OMP_TASK_BODY (stmt) = body;
   11809              : 
   11810         2418 :   return add_stmt (stmt);
   11811              : }
   11812              : 
   11813              : /* Helper function for finish_omp_for.  Convert Ith random access iterator
   11814              :    into integral iterator.  Return FALSE if successful.  */
   11815              : 
   11816              : static bool
   11817          813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
   11818              :                                tree declv, tree orig_declv, tree initv,
   11819              :                                tree condv, tree incrv, tree *body,
   11820              :                                tree *pre_body, tree &clauses,
   11821              :                                int collapse, int ordered)
   11822              : {
   11823          813 :   tree diff, iter_init, iter_incr = NULL, last;
   11824          813 :   tree incr_var = NULL, orig_pre_body, orig_body, c;
   11825          813 :   tree decl = TREE_VEC_ELT (declv, i);
   11826          813 :   tree init = TREE_VEC_ELT (initv, i);
   11827          813 :   tree cond = TREE_VEC_ELT (condv, i);
   11828          813 :   tree incr = TREE_VEC_ELT (incrv, i);
   11829          813 :   tree iter = decl;
   11830          813 :   location_t elocus = locus;
   11831              : 
   11832          813 :   if (init && EXPR_HAS_LOCATION (init))
   11833           12 :     elocus = EXPR_LOCATION (init);
   11834              : 
   11835          813 :   switch (TREE_CODE (cond))
   11836              :     {
   11837          810 :     case GT_EXPR:
   11838          810 :     case GE_EXPR:
   11839          810 :     case LT_EXPR:
   11840          810 :     case LE_EXPR:
   11841          810 :     case NE_EXPR:
   11842          810 :       if (TREE_OPERAND (cond, 1) == iter)
   11843           42 :         cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
   11844           42 :                        TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
   11845          810 :       if (TREE_OPERAND (cond, 0) != iter)
   11846            0 :         cond = error_mark_node;
   11847              :       else
   11848              :         {
   11849          810 :           tree tem = build_x_binary_op (EXPR_LOCATION (cond),
   11850          810 :                                         TREE_CODE (cond),
   11851              :                                         iter, ERROR_MARK,
   11852          810 :                                         TREE_OPERAND (cond, 1), ERROR_MARK,
   11853              :                                         NULL_TREE, NULL, tf_warning_or_error);
   11854          810 :           if (error_operand_p (tem))
   11855              :             return true;
   11856              :         }
   11857              :       break;
   11858            3 :     default:
   11859            3 :       cond = error_mark_node;
   11860            3 :       break;
   11861              :     }
   11862          810 :   if (cond == error_mark_node)
   11863              :     {
   11864            3 :       error_at (elocus, "invalid controlling predicate");
   11865            3 :       return true;
   11866              :     }
   11867          807 :   diff = build_x_binary_op (elocus, MINUS_EXPR,
   11868          807 :                             TREE_OPERAND (cond, 1), ERROR_MARK,
   11869              :                             iter, ERROR_MARK,
   11870              :                             NULL_TREE, NULL, tf_warning_or_error);
   11871          807 :   diff = cp_fully_fold (diff);
   11872          807 :   if (error_operand_p (diff))
   11873              :     return true;
   11874          807 :   if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
   11875              :     {
   11876            0 :       error_at (elocus, "difference between %qE and %qD does not have integer type",
   11877            0 :                 TREE_OPERAND (cond, 1), iter);
   11878            0 :       return true;
   11879              :     }
   11880          807 :   if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
   11881          807 :                                   TREE_VEC_ELT (declv, i), NULL_TREE,
   11882              :                                   cond, cp_walk_subtrees))
   11883              :     return true;
   11884              : 
   11885          762 :   switch (TREE_CODE (incr))
   11886              :     {
   11887          370 :     case PREINCREMENT_EXPR:
   11888          370 :     case PREDECREMENT_EXPR:
   11889          370 :     case POSTINCREMENT_EXPR:
   11890          370 :     case POSTDECREMENT_EXPR:
   11891          370 :       if (TREE_OPERAND (incr, 0) != iter)
   11892              :         {
   11893            0 :           incr = error_mark_node;
   11894            0 :           break;
   11895              :         }
   11896          370 :       iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
   11897          370 :                                     TREE_CODE (incr), iter,
   11898              :                                     NULL_TREE, tf_warning_or_error);
   11899          370 :       if (error_operand_p (iter_incr))
   11900              :         return true;
   11901          370 :       else if (TREE_CODE (incr) == PREINCREMENT_EXPR
   11902          219 :                || TREE_CODE (incr) == POSTINCREMENT_EXPR)
   11903          299 :         incr = integer_one_node;
   11904              :       else
   11905           71 :         incr = integer_minus_one_node;
   11906              :       break;
   11907          392 :     case MODIFY_EXPR:
   11908          392 :       if (TREE_OPERAND (incr, 0) != iter)
   11909            0 :         incr = error_mark_node;
   11910          392 :       else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
   11911          392 :                || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
   11912              :         {
   11913          392 :           tree rhs = TREE_OPERAND (incr, 1);
   11914          392 :           if (TREE_OPERAND (rhs, 0) == iter)
   11915              :             {
   11916          299 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
   11917              :                   != INTEGER_TYPE)
   11918            0 :                 incr = error_mark_node;
   11919              :               else
   11920              :                 {
   11921          299 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11922          299 :                                                    iter, TREE_CODE (rhs),
   11923          299 :                                                    TREE_OPERAND (rhs, 1),
   11924              :                                                    NULL_TREE,
   11925              :                                                    tf_warning_or_error);
   11926          299 :                   if (error_operand_p (iter_incr))
   11927              :                     return true;
   11928          299 :                   incr = TREE_OPERAND (rhs, 1);
   11929          299 :                   incr = cp_convert (TREE_TYPE (diff), incr,
   11930              :                                      tf_warning_or_error);
   11931          299 :                   if (TREE_CODE (rhs) == MINUS_EXPR)
   11932              :                     {
   11933           16 :                       incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
   11934           16 :                       incr = fold_simple (incr);
   11935              :                     }
   11936          299 :                   if (TREE_CODE (incr) != INTEGER_CST
   11937          299 :                       && (TREE_CODE (incr) != NOP_EXPR
   11938           66 :                           || (TREE_CODE (TREE_OPERAND (incr, 0))
   11939              :                               != INTEGER_CST)))
   11940              :                     iter_incr = NULL;
   11941              :                 }
   11942              :             }
   11943           93 :           else if (TREE_OPERAND (rhs, 1) == iter)
   11944              :             {
   11945           93 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
   11946           93 :                   || TREE_CODE (rhs) != PLUS_EXPR)
   11947            0 :                 incr = error_mark_node;
   11948              :               else
   11949              :                 {
   11950           93 :                   iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
   11951              :                                                  PLUS_EXPR,
   11952           93 :                                                  TREE_OPERAND (rhs, 0),
   11953              :                                                  ERROR_MARK, iter,
   11954              :                                                  ERROR_MARK, NULL_TREE, NULL,
   11955              :                                                  tf_warning_or_error);
   11956           93 :                   if (error_operand_p (iter_incr))
   11957              :                     return true;
   11958           93 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11959              :                                                    iter, NOP_EXPR,
   11960              :                                                    iter_incr, NULL_TREE,
   11961              :                                                    tf_warning_or_error);
   11962           93 :                   if (error_operand_p (iter_incr))
   11963              :                     return true;
   11964           93 :                   incr = TREE_OPERAND (rhs, 0);
   11965           93 :                   iter_incr = NULL;
   11966              :                 }
   11967              :             }
   11968              :           else
   11969            0 :             incr = error_mark_node;
   11970              :         }
   11971              :       else
   11972            0 :         incr = error_mark_node;
   11973              :       break;
   11974            0 :     default:
   11975            0 :       incr = error_mark_node;
   11976            0 :       break;
   11977              :     }
   11978              : 
   11979          762 :   if (incr == error_mark_node)
   11980              :     {
   11981            0 :       error_at (elocus, "invalid increment expression");
   11982            0 :       return true;
   11983              :     }
   11984              : 
   11985          762 :   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
   11986          762 :   incr = cp_fully_fold (incr);
   11987          762 :   tree loop_iv_seen = NULL_TREE;
   11988         1735 :   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
   11989         1093 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   11990         1093 :         && OMP_CLAUSE_DECL (c) == iter)
   11991              :       {
   11992          120 :         if (code == OMP_TASKLOOP || code == OMP_LOOP)
   11993              :           {
   11994           60 :             loop_iv_seen = c;
   11995           60 :             OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
   11996              :           }
   11997              :         break;
   11998              :       }
   11999          973 :     else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
   12000          113 :              && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   12001         1007 :              && OMP_CLAUSE_DECL (c) == iter)
   12002              :       {
   12003           30 :         loop_iv_seen = c;
   12004           30 :         if (code == OMP_TASKLOOP)
   12005           25 :           OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
   12006              :       }
   12007              : 
   12008          762 :   decl = create_temporary_var (TREE_TYPE (diff));
   12009          762 :   pushdecl (decl);
   12010          762 :   add_decl_expr (decl);
   12011          762 :   last = create_temporary_var (TREE_TYPE (diff));
   12012          762 :   pushdecl (last);
   12013          762 :   add_decl_expr (last);
   12014          762 :   if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
   12015           10 :       && (!ordered || (i < collapse && collapse > 1)))
   12016              :     {
   12017           10 :       incr_var = create_temporary_var (TREE_TYPE (diff));
   12018           10 :       pushdecl (incr_var);
   12019           10 :       add_decl_expr (incr_var);
   12020              :     }
   12021          762 :   gcc_assert (stmts_are_full_exprs_p ());
   12022          762 :   tree diffvar = NULL_TREE;
   12023          762 :   if (code == OMP_TASKLOOP)
   12024              :     {
   12025          101 :       if (!loop_iv_seen)
   12026              :         {
   12027           38 :           tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   12028           38 :           OMP_CLAUSE_DECL (ivc) = iter;
   12029           38 :           cxx_omp_finish_clause (ivc, NULL, false);
   12030           38 :           OMP_CLAUSE_CHAIN (ivc) = clauses;
   12031           38 :           clauses = ivc;
   12032              :         }
   12033          101 :       tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   12034          101 :       OMP_CLAUSE_DECL (lvc) = last;
   12035          101 :       OMP_CLAUSE_CHAIN (lvc) = clauses;
   12036          101 :       clauses = lvc;
   12037          101 :       diffvar = create_temporary_var (TREE_TYPE (diff));
   12038          101 :       pushdecl (diffvar);
   12039          101 :       add_decl_expr (diffvar);
   12040              :     }
   12041          661 :   else if (code == OMP_LOOP)
   12042              :     {
   12043           43 :       if (!loop_iv_seen)
   12044              :         {
   12045              :           /* While iterators on the loop construct are predetermined
   12046              :              lastprivate, if the decl is not declared inside of the
   12047              :              loop, OMP_CLAUSE_LASTPRIVATE should have been added
   12048              :              already.  */
   12049           16 :           loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   12050           16 :           OMP_CLAUSE_DECL (loop_iv_seen) = iter;
   12051           16 :           OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
   12052           16 :           clauses = loop_iv_seen;
   12053              :         }
   12054           27 :       else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
   12055              :         {
   12056            5 :           OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
   12057            5 :           OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
   12058            5 :           OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
   12059              :         }
   12060           43 :       if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
   12061           21 :         cxx_omp_finish_clause (loop_iv_seen, NULL, false);
   12062              :     }
   12063              : 
   12064          762 :   orig_pre_body = *pre_body;
   12065          762 :   *pre_body = push_stmt_list ();
   12066          762 :   if (orig_pre_body)
   12067          610 :     add_stmt (orig_pre_body);
   12068          762 :   if (init != NULL)
   12069           61 :     finish_expr_stmt (build_x_modify_expr (elocus,
   12070              :                                            iter, NOP_EXPR, init,
   12071              :                                            NULL_TREE, tf_warning_or_error));
   12072          762 :   init = build_int_cst (TREE_TYPE (diff), 0);
   12073          762 :   if (c && iter_incr == NULL
   12074           28 :       && (!ordered || (i < collapse && collapse > 1)))
   12075              :     {
   12076           28 :       if (incr_var)
   12077              :         {
   12078           10 :           finish_expr_stmt (build_x_modify_expr (elocus,
   12079              :                                                  incr_var, NOP_EXPR,
   12080              :                                                  incr, NULL_TREE,
   12081              :                                                  tf_warning_or_error));
   12082           10 :           incr = incr_var;
   12083              :         }
   12084           28 :       iter_incr = build_x_modify_expr (elocus,
   12085              :                                        iter, PLUS_EXPR, incr,
   12086              :                                        NULL_TREE, tf_warning_or_error);
   12087              :     }
   12088          762 :   if (c && ordered && i < collapse && collapse > 1)
   12089          762 :     iter_incr = incr;
   12090          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   12091              :                                          last, NOP_EXPR, init,
   12092              :                                          NULL_TREE, tf_warning_or_error));
   12093          762 :   if (diffvar)
   12094              :     {
   12095          101 :       finish_expr_stmt (build_x_modify_expr (elocus,
   12096              :                                              diffvar, NOP_EXPR,
   12097              :                                              diff, NULL_TREE, tf_warning_or_error));
   12098          101 :       diff = diffvar;
   12099              :     }
   12100          762 :   *pre_body = pop_stmt_list (*pre_body);
   12101              : 
   12102         1524 :   cond = cp_build_binary_op (elocus,
   12103          762 :                              TREE_CODE (cond), decl, diff,
   12104              :                              tf_warning_or_error);
   12105          762 :   incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
   12106              :                             elocus, incr, NULL_TREE);
   12107              : 
   12108          762 :   orig_body = *body;
   12109          762 :   *body = push_stmt_list ();
   12110          762 :   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
   12111          762 :   iter_init = build_x_modify_expr (elocus,
   12112              :                                    iter, PLUS_EXPR, iter_init,
   12113              :                                    NULL_TREE, tf_warning_or_error);
   12114          762 :   if (iter_init != error_mark_node)
   12115          759 :     iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   12116          762 :   finish_expr_stmt (iter_init);
   12117          762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   12118              :                                          last, NOP_EXPR, decl,
   12119              :                                          NULL_TREE, tf_warning_or_error));
   12120          762 :   add_stmt (orig_body);
   12121          762 :   *body = pop_stmt_list (*body);
   12122              : 
   12123          762 :   if (c)
   12124              :     {
   12125          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
   12126          120 :       if (!ordered)
   12127          114 :         finish_expr_stmt (iter_incr);
   12128              :       else
   12129              :         {
   12130            6 :           iter_init = decl;
   12131            6 :           if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
   12132            2 :             iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
   12133              :                                 iter_init, iter_incr);
   12134            6 :           iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
   12135            6 :           iter_init = build_x_modify_expr (elocus,
   12136              :                                            iter, PLUS_EXPR, iter_init,
   12137              :                                            NULL_TREE, tf_warning_or_error);
   12138            6 :           if (iter_init != error_mark_node)
   12139            6 :             iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   12140            6 :           finish_expr_stmt (iter_init);
   12141              :         }
   12142          120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c)
   12143          240 :         = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
   12144              :     }
   12145              : 
   12146          762 :   if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
   12147              :     {
   12148          116 :       tree t = TREE_VEC_ELT (orig_declv, i);
   12149          116 :       gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   12150              :                   && TREE_VALUE (t) == NULL_TREE
   12151              :                   && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
   12152          116 :       TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
   12153          116 :       TREE_VALUE (t) = last;
   12154              :     }
   12155              :   else
   12156          646 :     TREE_VEC_ELT (orig_declv, i)
   12157         1292 :       = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   12158          762 :   TREE_VEC_ELT (declv, i) = decl;
   12159          762 :   TREE_VEC_ELT (initv, i) = init;
   12160          762 :   TREE_VEC_ELT (condv, i) = cond;
   12161          762 :   TREE_VEC_ELT (incrv, i) = incr;
   12162              : 
   12163          762 :   return false;
   12164              : }
   12165              : 
   12166              : /* Build and validate an OMP_FOR statement.  CLAUSES, BODY, COND, INCR
   12167              :    are directly for their associated operands in the statement.  DECL
   12168              :    and INIT are a combo; if DECL is NULL then INIT ought to be a
   12169              :    MODIFY_EXPR, and the DECL should be extracted.  PRE_BODY are
   12170              :    optional statements that need to go before the loop into its
   12171              :    sk_omp scope.  */
   12172              : 
   12173              : tree
   12174        21744 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
   12175              :                 tree orig_declv, tree initv, tree condv, tree incrv,
   12176              :                 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
   12177              : {
   12178        21744 :   tree omp_for = NULL, orig_incr = NULL;
   12179        21744 :   tree decl = NULL, init, cond, incr;
   12180        21744 :   location_t elocus;
   12181        21744 :   int i;
   12182        21744 :   int collapse = 1;
   12183        21744 :   int ordered = 0;
   12184        21744 :   auto_vec<location_t> init_locv;
   12185              : 
   12186        21744 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
   12187        21744 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
   12188        21744 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
   12189        21744 :   if (TREE_VEC_LENGTH (declv) > 1)
   12190              :     {
   12191         4499 :       if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
   12192           83 :         collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
   12193              :       else
   12194              :         {
   12195         4416 :           if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
   12196         3946 :             collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
   12197          470 :           else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
   12198          394 :             collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
   12199         4416 :           if (collapse != TREE_VEC_LENGTH (declv))
   12200          100 :             ordered = TREE_VEC_LENGTH (declv);
   12201              :         }
   12202              :     }
   12203        50308 :   for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   12204              :     {
   12205        28600 :       decl = TREE_VEC_ELT (declv, i);
   12206        28600 :       init = TREE_VEC_ELT (initv, i);
   12207        28600 :       cond = TREE_VEC_ELT (condv, i);
   12208        28600 :       incr = TREE_VEC_ELT (incrv, i);
   12209        28600 :       elocus = locus;
   12210              : 
   12211        28600 :       if (decl == global_namespace)
   12212              :         {
   12213         1101 :           gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
   12214         1101 :           TREE_VEC_ELT (declv, i) = NULL_TREE;
   12215         1101 :           init_locv.safe_push (UNKNOWN_LOCATION);
   12216         1101 :           continue;
   12217              :         }
   12218              :       /* We are going to throw out the init's original MODIFY_EXPR or
   12219              :          MODOP_EXPR below.  Save its location so we can use it when
   12220              :          reconstructing the expression farther down.  Alternatively, if the
   12221              :          initializer is a binding of the iteration variable, save
   12222              :          that location.  Any of these locations in the initialization clause
   12223              :          for the current nested loop are better than using the argument locus,
   12224              :          that points to the "for" of the outermost loop in the nest.  */
   12225        27499 :       if (init && EXPR_HAS_LOCATION (init))
   12226        18215 :         elocus = EXPR_LOCATION (init);
   12227         9284 :       else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
   12228              :         /* This can happen for class iterators.  */
   12229            0 :         elocus = EXPR_LOCATION (decl);
   12230         9284 :       else if (decl && DECL_P (decl))
   12231              :         {
   12232         9257 :           if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
   12233         9257 :             elocus = DECL_SOURCE_LOCATION (decl);
   12234            0 :           else if (DECL_INITIAL (decl)
   12235            0 :                    && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
   12236            0 :             elocus = EXPR_LOCATION (DECL_INITIAL (decl));
   12237              :         }
   12238        27499 :       init_locv.safe_push (elocus);
   12239              : 
   12240        27499 :       if (decl == NULL)
   12241              :         {
   12242        16904 :           if (init != NULL)
   12243        16901 :             switch (TREE_CODE (init))
   12244              :               {
   12245        16494 :               case MODIFY_EXPR:
   12246        16494 :                 decl = TREE_OPERAND (init, 0);
   12247        16494 :                 init = TREE_OPERAND (init, 1);
   12248        16494 :                 break;
   12249          389 :               case MODOP_EXPR:
   12250          389 :                 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
   12251              :                   {
   12252          389 :                     decl = TREE_OPERAND (init, 0);
   12253          389 :                     init = TREE_OPERAND (init, 2);
   12254              :                   }
   12255              :                 break;
   12256              :               default:
   12257              :                 break;
   12258              :               }
   12259              : 
   12260        16904 :           if (decl == NULL)
   12261              :             {
   12262           21 :               error_at (locus,
   12263              :                         "expected iteration declaration or initialization");
   12264           21 :               return NULL;
   12265              :             }
   12266              :         }
   12267              : 
   12268        27478 :       if (cond == global_namespace)
   12269          170 :         continue;
   12270              : 
   12271        27308 :       if (cond == NULL)
   12272              :         {
   12273            9 :           error_at (elocus, "missing controlling predicate");
   12274            9 :           return NULL;
   12275              :         }
   12276              : 
   12277        27299 :       if (incr == NULL)
   12278              :         {
   12279            6 :           error_at (elocus, "missing increment expression");
   12280            6 :           return NULL;
   12281              :         }
   12282              : 
   12283        27293 :       TREE_VEC_ELT (declv, i) = decl;
   12284        27293 :       TREE_VEC_ELT (initv, i) = init;
   12285              :     }
   12286              : 
   12287        21708 :   if (orig_inits)
   12288              :     {
   12289              :       bool fail = false;
   12290              :       tree orig_init;
   12291        21808 :       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
   12292         1181 :         if (orig_init
   12293         3396 :             && !c_omp_check_loop_iv_exprs (locus, code,
   12294              :                                            orig_declv ? orig_declv : declv, i,
   12295         1164 :                                            TREE_VEC_ELT (declv, i), orig_init,
   12296              :                                            NULL_TREE, cp_walk_subtrees))
   12297              :           fail = true;
   12298        20627 :       if (fail)
   12299        21744 :         return NULL;
   12300              :     }
   12301              : 
   12302        21651 :   if (dependent_omp_for_p (declv, initv, condv, incrv, body))
   12303              :     {
   12304          453 :       tree stmt;
   12305              : 
   12306          453 :       stmt = make_node (code);
   12307              : 
   12308         1499 :       for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   12309              :         {
   12310          593 :           if (TREE_VEC_ELT (declv, i) == NULL_TREE)
   12311            9 :             continue;
   12312              :           /* This is really just a place-holder.  We'll be decomposing this
   12313              :              again and going through the cp_build_modify_expr path below when
   12314              :              we instantiate the thing.  */
   12315          584 :           TREE_VEC_ELT (initv, i)
   12316         1168 :             = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
   12317          584 :                           TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
   12318              :         }
   12319              : 
   12320          453 :       TREE_TYPE (stmt) = void_type_node;
   12321          453 :       OMP_FOR_INIT (stmt) = initv;
   12322          453 :       OMP_FOR_COND (stmt) = condv;
   12323          453 :       OMP_FOR_INCR (stmt) = incrv;
   12324          453 :       OMP_FOR_BODY (stmt) = body;
   12325          453 :       OMP_FOR_PRE_BODY (stmt) = pre_body;
   12326          453 :       OMP_FOR_CLAUSES (stmt) = clauses;
   12327              : 
   12328          453 :       SET_EXPR_LOCATION (stmt, locus);
   12329          453 :       return add_stmt (stmt);
   12330              :     }
   12331              : 
   12332        21198 :   if (!orig_declv)
   12333        20389 :     orig_declv = copy_node (declv);
   12334              : 
   12335        21198 :   if (processing_template_decl)
   12336          634 :     orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
   12337              : 
   12338        49737 :   for (i = 0; i < TREE_VEC_LENGTH (declv); )
   12339              :     {
   12340        28631 :       decl = TREE_VEC_ELT (declv, i);
   12341        28631 :       init = TREE_VEC_ELT (initv, i);
   12342        28631 :       cond = TREE_VEC_ELT (condv, i);
   12343        28631 :       incr = TREE_VEC_ELT (incrv, i);
   12344        28631 :       if (orig_incr)
   12345          866 :         TREE_VEC_ELT (orig_incr, i) = incr;
   12346        28631 :       elocus = init_locv[i];
   12347              : 
   12348        28631 :       if (decl == NULL_TREE)
   12349              :         {
   12350         1092 :           i++;
   12351         1092 :           continue;
   12352              :         }
   12353              : 
   12354        27539 :       if (!DECL_P (decl))
   12355              :         {
   12356            6 :           error_at (elocus, "expected iteration declaration or initialization");
   12357            6 :           return NULL;
   12358              :         }
   12359              : 
   12360        27533 :       if (incr && TREE_CODE (incr) == MODOP_EXPR)
   12361              :         {
   12362            1 :           if (orig_incr)
   12363            1 :             TREE_VEC_ELT (orig_incr, i) = incr;
   12364            1 :           incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
   12365            1 :                                        TREE_CODE (TREE_OPERAND (incr, 1)),
   12366            1 :                                        TREE_OPERAND (incr, 2),
   12367              :                                        tf_warning_or_error);
   12368              :         }
   12369              : 
   12370        27533 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
   12371              :         {
   12372          825 :           if (code == OMP_SIMD)
   12373              :             {
   12374           12 :               error_at (elocus, "%<#pragma omp simd%> used with class "
   12375              :                                 "iteration variable %qE", decl);
   12376           12 :               return NULL;
   12377              :             }
   12378          813 :           if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
   12379              :                                              initv, condv, incrv, &body,
   12380              :                                              &pre_body, clauses,
   12381              :                                              collapse, ordered))
   12382              :             return NULL;
   12383          762 :           continue;
   12384              :         }
   12385              : 
   12386        53416 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
   12387        28297 :           && !TYPE_PTR_P (TREE_TYPE (decl)))
   12388              :         {
   12389           14 :           error_at (elocus, "invalid type for iteration variable %qE", decl);
   12390           14 :           return NULL;
   12391              :         }
   12392              : 
   12393        26694 :       if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
   12394        25911 :         init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
   12395              :                                      tf_warning_or_error);
   12396              :       else
   12397          783 :         init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
   12398        26694 :       if (decl == error_mark_node || init == error_mark_node)
   12399              :         return NULL;
   12400              : 
   12401        26685 :       TREE_VEC_ELT (declv, i) = decl;
   12402        26685 :       TREE_VEC_ELT (initv, i) = init;
   12403        26685 :       TREE_VEC_ELT (condv, i) = cond;
   12404        26685 :       TREE_VEC_ELT (incrv, i) = incr;
   12405        26685 :       i++;
   12406              :     }
   12407              : 
   12408        21106 :   if (pre_body && IS_EMPTY_STMT (pre_body))
   12409            0 :     pre_body = NULL;
   12410              : 
   12411        42212 :   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
   12412              :                               incrv, body, pre_body,
   12413        21106 :                               !processing_template_decl);
   12414              : 
   12415              :   /* Check for iterators appearing in lb, b or incr expressions.  */
   12416        21106 :   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
   12417              :     omp_for = NULL_TREE;
   12418              : 
   12419        20620 :   if (omp_for == NULL)
   12420              :     return NULL;
   12421              : 
   12422        20404 :   add_stmt (omp_for);
   12423              : 
   12424        67559 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
   12425              :     {
   12426        26751 :       init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
   12427        26751 :       if (init == NULL_TREE)
   12428         1032 :         continue;
   12429        25719 :       decl = TREE_OPERAND (init, 0);
   12430        25719 :       cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
   12431        25719 :       incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
   12432              : 
   12433        25719 :       if (!processing_template_decl)
   12434              :         {
   12435        25176 :           if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
   12436              :             {
   12437          109 :               tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
   12438          109 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
   12439          109 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12440          109 :               t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
   12441          109 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
   12442          218 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12443              :             }
   12444              :           else
   12445              :             {
   12446        25067 :               tree t = TREE_OPERAND (init, 1);
   12447        25067 :               TREE_OPERAND (init, 1)
   12448        50134 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12449              :             }
   12450        25176 :           if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
   12451              :             {
   12452          121 :               tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
   12453          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
   12454          121 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12455          121 :               t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
   12456          121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
   12457          242 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12458              :             }
   12459              :           else
   12460              :             {
   12461        25055 :               tree t = TREE_OPERAND (cond, 1);
   12462        25055 :               TREE_OPERAND (cond, 1)
   12463        50110 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12464              :             }
   12465              :         }
   12466              : 
   12467        25719 :       if (TREE_CODE (incr) != MODIFY_EXPR)
   12468        19443 :         continue;
   12469              : 
   12470         6276 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
   12471           70 :           && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
   12472         6346 :           && !processing_template_decl)
   12473              :         {
   12474           64 :           tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
   12475           64 :           if (TREE_SIDE_EFFECTS (t)
   12476            8 :               && t != decl
   12477           70 :               && (TREE_CODE (t) != NOP_EXPR
   12478            0 :                   || TREE_OPERAND (t, 0) != decl))
   12479            6 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
   12480           12 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12481              : 
   12482           64 :           t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
   12483           64 :           if (TREE_SIDE_EFFECTS (t)
   12484           56 :               && t != decl
   12485          120 :               && (TREE_CODE (t) != NOP_EXPR
   12486            5 :                   || TREE_OPERAND (t, 0) != decl))
   12487           56 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
   12488          112 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   12489              :         }
   12490              : 
   12491         6276 :       if (orig_incr)
   12492          177 :         TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
   12493              :     }
   12494        20404 :   OMP_FOR_CLAUSES (omp_for) = clauses;
   12495              : 
   12496              :   /* For simd loops with non-static data member iterators, we could have added
   12497              :      OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP.  As we know the
   12498              :      step at this point, fill it in.  */
   12499         5226 :   if (code == OMP_SIMD && !processing_template_decl
   12500        25586 :       && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
   12501         4671 :     for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
   12502          561 :          c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
   12503          561 :       if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
   12504              :         {
   12505            4 :           decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
   12506            4 :           gcc_assert (decl == OMP_CLAUSE_DECL (c));
   12507            4 :           incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
   12508            4 :           tree step, stept;
   12509            4 :           switch (TREE_CODE (incr))
   12510              :             {
   12511            0 :             case PREINCREMENT_EXPR:
   12512            0 :             case POSTINCREMENT_EXPR:
   12513              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12514              :                  called to massage things appropriately.  */
   12515            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12516            0 :               OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
   12517            0 :               break;
   12518            0 :             case PREDECREMENT_EXPR:
   12519            0 :             case POSTDECREMENT_EXPR:
   12520              :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12521              :                  called to massage things appropriately.  */
   12522            0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12523            0 :               OMP_CLAUSE_LINEAR_STEP (c)
   12524            0 :                 = build_int_cst (TREE_TYPE (decl), -1);
   12525            0 :               break;
   12526            4 :             case MODIFY_EXPR:
   12527            4 :               gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12528            4 :               incr = TREE_OPERAND (incr, 1);
   12529            4 :               switch (TREE_CODE (incr))
   12530              :                 {
   12531            4 :                 case PLUS_EXPR:
   12532            4 :                   if (TREE_OPERAND (incr, 1) == decl)
   12533            0 :                     step = TREE_OPERAND (incr, 0);
   12534              :                   else
   12535            4 :                     step = TREE_OPERAND (incr, 1);
   12536              :                   break;
   12537            0 :                 case MINUS_EXPR:
   12538            0 :                 case POINTER_PLUS_EXPR:
   12539            0 :                   gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12540            0 :                   step = TREE_OPERAND (incr, 1);
   12541            0 :                   break;
   12542            0 :                 default:
   12543            0 :                   gcc_unreachable ();
   12544              :                 }
   12545            4 :               stept = TREE_TYPE (decl);
   12546            4 :               if (INDIRECT_TYPE_P (stept))
   12547            0 :                 stept = sizetype;
   12548            4 :               step = fold_convert (stept, step);
   12549            4 :               if (TREE_CODE (incr) == MINUS_EXPR)
   12550            0 :                 step = fold_build1 (NEGATE_EXPR, stept, step);
   12551            4 :               OMP_CLAUSE_LINEAR_STEP (c) = step;
   12552            4 :               break;
   12553            0 :             default:
   12554            0 :               gcc_unreachable ();
   12555              :             }
   12556              :         }
   12557              :   /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
   12558              :      clauses, we need copy ctor for those rather than default ctor,
   12559              :      plus as for other lastprivates assignment op and dtor.  */
   12560        20404 :   if (code == OMP_LOOP && !processing_template_decl)
   12561         2013 :     for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   12562         1298 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   12563          204 :           && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
   12564         1320 :           && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
   12565              :                                          false, true, true, true))
   12566            0 :         CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
   12567              : 
   12568              :   return omp_for;
   12569        21744 : }
   12570              : 
   12571              : /* Code walker for finish_omp_for_block: extract binding of DP->var
   12572              :    from its current block and move it to a new BIND_EXPR DP->b
   12573              :    surrounding the body of DP->omp_for.  */
   12574              : 
   12575              : struct fofb_data {
   12576              :   tree var;
   12577              :   tree b;
   12578              :   tree omp_for;
   12579              : };
   12580              : 
   12581              : static tree
   12582          389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
   12583              : {
   12584          389 :   struct fofb_data *fofb = (struct fofb_data *)dp;
   12585          389 :   if (TREE_CODE (*tp) == BIND_EXPR)
   12586          578 :     for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
   12587              :       {
   12588          576 :         if (*p == fofb->var)
   12589              :           {
   12590          363 :             *p = DECL_CHAIN (*p);
   12591          363 :             if (fofb->b == NULL_TREE)
   12592              :               {
   12593          214 :                 fofb->b = make_node (BLOCK);
   12594          214 :                 fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   12595          214 :                             OMP_FOR_BODY (fofb->omp_for), fofb->b);
   12596          214 :                 TREE_SIDE_EFFECTS (fofb->b) = 1;
   12597          214 :                 OMP_FOR_BODY (fofb->omp_for) = fofb->b;
   12598              :               }
   12599          363 :             DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
   12600          363 :             BIND_EXPR_VARS (fofb->b) = fofb->var;
   12601          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
   12602          363 :             BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
   12603          363 :             return *tp;
   12604              :           }
   12605              :       }
   12606           26 :   if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
   12607           22 :     *walk_subtrees = false;
   12608              :   return NULL_TREE;
   12609              : }
   12610              : 
   12611              : /* Fix up range for decls.  Those decls were pushed into BIND's
   12612              :    BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
   12613              :    and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
   12614              :    so that processing of combined loop directives can find them.  */
   12615              : tree
   12616        15163 : finish_omp_for_block (tree bind, tree omp_for)
   12617              : {
   12618        15163 :   if (omp_for == NULL_TREE
   12619        15116 :       || !OMP_FOR_ORIG_DECLS (omp_for)
   12620        29689 :       || bind == NULL_TREE)
   12621          637 :     return bind;
   12622        14526 :   struct fofb_data fofb;
   12623        14526 :   fofb.b = NULL_TREE;
   12624        14526 :   fofb.omp_for = omp_for;
   12625        35054 :   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
   12626        20528 :     if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
   12627        20306 :         && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
   12628              :             == TREE_LIST)
   12629        21359 :         && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
   12630              :       {
   12631          237 :         tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
   12632          602 :         for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
   12633              :           {
   12634          365 :             fofb.var = TREE_VEC_ELT (v, j);
   12635          365 :             cp_walk_tree (&bind, finish_omp_for_block_walker,
   12636              :                           (void *)&fofb, NULL);
   12637              :           }
   12638              :       }
   12639        14526 :   return bind;
   12640              : }
   12641              : 
   12642              : /* Validate an OpenMP allocate directive, then add the ALLOC and ALIGN exprs to
   12643              :    the "omp allocate" attr of each decl found in VARS.  The value of attr is
   12644              :    a TREE_LIST with ALLOC stored in its purpose member and ALIGN stored in its
   12645              :    value member.  ALLOC and ALIGN are exprs passed as arguments to the
   12646              :    allocator and align clauses of the directive.  VARS may be NULL_TREE if
   12647              :    there were errors during parsing.
   12648              :    #pragma omp allocate(VARS) allocator(ALLOC) align(ALIGN)
   12649              : 
   12650              :    If processing_template_decl, a stmt of tree_code OMP_ALLOCATE is added to
   12651              :    the function instead.  LOC is used to initialize EXPR_LOCATION of the stmt.
   12652              : 
   12653              :    If any errors occur, the "omp allocate" attr is marked so the middle end
   12654              :    knows to skip it during gimplification.  */
   12655              : 
   12656              : void
   12657         2949 : finish_omp_allocate (const location_t loc, const tree var_list,
   12658              :                      const tree alloc_in, const tree align_in,
   12659              :                      const tree context)
   12660              : {
   12661              :   /* Takes a VAR_DECL.  */
   12662         2949 :   using var_predicate = bool (*)(const_tree);
   12663        11994 :   const auto any_of_vars = [&var_list] (var_predicate predicate)
   12664              :     {
   12665        17329 :       for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   12666         8687 :         if (predicate (TREE_PURPOSE (vn)))
   12667              :           return true;
   12668              :       return false;
   12669         2949 :     };
   12670         2949 :   const bool global = !DECL_DECLARES_FUNCTION_P (context);
   12671         2949 :   const var_predicate tree_static_p = [&] () -> var_predicate
   12672              :     {
   12673              :       /* If this directive is not in a function, all the vars are static.  */
   12674         2949 :       if (global)
   12675              :         return [] (const_tree) -> bool { return true; };
   12676              :       else
   12677         2850 :         return [] (const_tree t) -> bool { return TREE_STATIC (t); };
   12678         2949 :     } (); /* IILE.  */
   12679         2949 :   const bool any_static_vars = any_of_vars (tree_static_p);
   12680              : 
   12681              :   /* Create an auto_diagnostic_group before calling this.  */
   12682         2949 :   const auto emit_diag_for_var_group
   12683          167 :     = [] (const var_predicate pred,
   12684              :           void (*diag_fn)(rich_location *, const char *, ...),
   12685              :           const char *msg,
   12686              :           const const_tree var_list)
   12687              :         {
   12688          678 :           auto next_match = [&pred] (const_tree first)
   12689              :             {
   12690          511 :               const_tree vn = first;
   12691          531 :               for (; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   12692          197 :                 if (TREE_PURPOSE (vn) != error_mark_node
   12693          197 :                     && pred (TREE_PURPOSE (vn)))
   12694              :                   return vn;
   12695              :               return vn;
   12696          167 :             };
   12697          167 :           gcc_assert (var_list != NULL_TREE);
   12698          167 :           const const_tree first_node = next_match (var_list);
   12699          167 :           gcc_assert (first_node != NULL_TREE);
   12700              : 
   12701          167 :           gcc_rich_location rich_loc (EXPR_LOCATION (TREE_VALUE (first_node)));
   12702              :           /* Don't add another range for the first node.  */
   12703          167 :           for (const_tree vn = next_match (TREE_CHAIN (first_node));
   12704          172 :                vn != NULL_TREE;
   12705            5 :                vn = next_match (TREE_CHAIN (vn)))
   12706            5 :             rich_loc.add_range (EXPR_LOCATION (TREE_VALUE (vn)));
   12707          167 :           diag_fn (&rich_loc, msg);
   12708              : 
   12709          167 :           const_tree vn = first_node;
   12710          506 :           for (; vn != NULL_TREE; vn = next_match (TREE_CHAIN (vn)))
   12711          344 :             inform (DECL_SOURCE_LOCATION (TREE_PURPOSE (vn)),
   12712          172 :                     "%qD declared here", TREE_PURPOSE (vn));
   12713          167 :         };
   12714              : 
   12715              :   /* Defer error marking vars until after other diagnostics are done, we might
   12716              :      still need access to them when diagnosing the allocator clause.  */
   12717         2949 :   hash_set<tree> deferred_erroneous_var_nodes;
   12718              : 
   12719         2949 :   const auto ref_var_p
   12720         2901 :     = [] (const_tree t) -> bool { return TYPE_REF_P (TREE_TYPE (t)); };
   12721         2949 :   if (any_of_vars (ref_var_p))
   12722              :     {
   12723           75 :       auto_diagnostic_group d;
   12724           75 :       emit_diag_for_var_group (ref_var_p,
   12725              :                                &error_at,
   12726              :                                G_("variables with reference type may not "
   12727              :                                   "appear in an %<allocate%> directive"),
   12728              :                                var_list);
   12729          150 :       for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   12730              :         {
   12731           75 :           if (!ref_var_p (TREE_PURPOSE (vn)))
   12732            0 :             continue;
   12733           75 :           deferred_erroneous_var_nodes.add (vn);
   12734              :         }
   12735           75 :     }
   12736              : 
   12737              :   /* (OpenMP 5.2, 174:15) Type: expression of integer type
   12738              :                           Properties: constant, positive  */
   12739         8847 :   const tree align = [&align_in] ()
   12740              :     {
   12741         2949 :       if (!align_in || align_in == error_mark_node)
   12742              :         return align_in;
   12743              : 
   12744         1313 :       auto emit_align_err = [&align_in] ()
   12745              :         {
   12746          116 :           error_at (EXPR_LOCATION (align_in),
   12747              :                     "%<align%> clause argument needs to be positive constant "
   12748              :                     "power of two integer expression");
   12749         1313 :         };
   12750         1197 :       if (processing_template_decl)
   12751              :         return align_in;
   12752              : 
   12753              :       /* Identity conversions are okay.  */
   12754          608 :       const tree converted_align
   12755          608 :         = build_converted_constant_expr (size_type_node, align_in, tf_error);
   12756          608 :       gcc_assert (converted_align != NULL_TREE);
   12757          608 :       if (converted_align == error_mark_node)
   12758              :         {
   12759           11 :           emit_align_err ();
   12760           11 :           return error_mark_node;
   12761              :         }
   12762              : 
   12763          597 :       const tree folded_align = cxx_constant_value (converted_align);
   12764          597 :       if (folded_align == error_mark_node)
   12765              :         {
   12766            5 :           emit_align_err ();
   12767            5 :           return error_mark_node;
   12768              :         }
   12769          592 :       gcc_assert (TREE_CONSTANT (folded_align));
   12770              :       /* (OpenMP 5.2, 175:10) alignment must evaluate to a power of two.  */
   12771          592 :       if (tree_int_cst_sgn (folded_align) != 1
   12772          592 :           || !integer_pow2p (folded_align))
   12773              :         {
   12774          100 :           emit_align_err ();
   12775          100 :           return error_mark_node;
   12776              :         }
   12777              :       return folded_align;
   12778         2949 :     } (); /* IILE.  */
   12779              : 
   12780              :   /* (OpenMP 5.2, 175:17) Type: expression of allocator_handle type
   12781              :                           Properties: default  */
   12782         8847 :   const tree alloc = [&] ()
   12783              :     {
   12784         2949 :       if (alloc_in == error_mark_node)
   12785              :         return error_mark_node;
   12786              :       /* (OpenMP 5.2 176:26-28)
   12787              :          If a list item has static storage duration, the allocator clause must
   12788              :          be specified and the allocator expression in the clause must be a
   12789              :          constant expression that evaluates to one of the predefined memory
   12790              :          allocator values.  */
   12791         3038 :       const auto emit_diag_for_static_vars = [&] ()
   12792              :         {
   12793           92 :           emit_diag_for_var_group (tree_static_p,
   12794              :                                    &inform,
   12795              :                                    G_("because one or more variables with "
   12796              :                                       "static storage duration appear "
   12797              :                                       "in the %<allocate%> directive"),
   12798              :                                    var_list);
   12799         3038 :         };
   12800         2946 :       if (alloc_in == NULL_TREE)
   12801              :         {
   12802         1135 :           if (!any_static_vars)
   12803              :             return NULL_TREE;
   12804              :           else
   12805              :             {
   12806            9 :               auto_diagnostic_group d;
   12807            9 :               error_at (loc, "%<allocator%> clause must be specified");
   12808            9 :               emit_diag_for_static_vars ();
   12809            9 :               return error_mark_node;
   12810            9 :             }
   12811              :           gcc_unreachable ();
   12812              :         }
   12813         1811 :       if (processing_template_decl)
   12814              :         return alloc_in;
   12815              : 
   12816         4041 :       const tree alloc_type = [&] ()
   12817              :         {
   12818         1347 :           static tree cached_alloc_type = NULL_TREE;
   12819         1347 :           if (cached_alloc_type != NULL_TREE)
   12820              :             return cached_alloc_type;
   12821              : 
   12822           68 :           const tree alloc_type_decl
   12823           68 :             = lookup_qualified_name (global_namespace,
   12824              :                                      get_identifier ("omp_allocator_handle_t"),
   12825              :                                      LOOK_want::TYPE);
   12826              :           /* User didn't include omp.h...  */
   12827           68 :           if (alloc_type_decl == error_mark_node)
   12828              :             {
   12829              :               /* We need to wait until instantiation to complain about it if
   12830              :                  alloc_in could possibly be well-formed.  */
   12831            0 :               if (processing_template_decl
   12832            0 :                   && (type_dependent_expression_p (alloc_in)
   12833              :                          /* No one sane would have a conversion template and
   12834              :                             use it this way, but it would still technically be
   12835              :                             correct so we have to account for it.  */
   12836            0 :                       || (CLASS_TYPE_P (TREE_TYPE (alloc_in))
   12837            0 :                           && TYPE_HAS_CONVERSION (TREE_TYPE (alloc_in)))))
   12838              :                 {
   12839            0 :                   gcc_assert (cached_alloc_type == NULL_TREE);
   12840              :                   return cached_alloc_type;
   12841              :                 }
   12842            0 :               auto_diagnostic_group d;
   12843            0 :               gcc_rich_location loc (EXPR_LOCATION (alloc_in));
   12844            0 :               maybe_add_include_fixit (&loc, "<omp.h>", false);
   12845            0 :               error_at (&loc,
   12846              :                         "%<allocator%> clause requires a valid declaration "
   12847              :                         "of %<omp_allocator_handle_t%>");
   12848            0 :               inform (&loc,
   12849              :                       "%<omp_allocator_handle_t%> is defined in header "
   12850              :                       "%<<omp.h>%>");
   12851            0 :               cached_alloc_type = error_mark_node;
   12852            0 :               return cached_alloc_type;
   12853            0 :             }
   12854          136 :           const auto underlying_type_is_valid = [] (const const_tree type)
   12855              :             {
   12856           68 :               const const_tree canonical_type = TYPE_CANONICAL (type);
   12857           68 :               if (cxx_dialect >= cxx11)
   12858           54 :                 return canonical_type == uintptr_type_node;
   12859           14 :               gcc_assert (cxx_dialect < cxx11);
   12860              :               /* Pre c++11 we can't just assume the underlying type.  */
   12861           14 :               return TYPE_UNSIGNED (canonical_type) == true
   12862           14 :                      && wi::to_widest (TYPE_SIZE (canonical_type))
   12863           28 :                         == wi::to_widest (TYPE_SIZE (uintptr_type_node))
   12864           14 :                      && wi::to_widest (TYPE_MIN_VALUE (canonical_type))
   12865           28 :                         == wi::to_widest (TYPE_MIN_VALUE (uintptr_type_node))
   12866           28 :                      && wi::to_widest (TYPE_MAX_VALUE (canonical_type))
   12867           28 :                         == wi::to_widest (TYPE_MAX_VALUE (uintptr_type_node));
   12868              :             };
   12869           68 :           const tree alloc_type = TREE_TYPE (alloc_type_decl);
   12870           68 :           if (TREE_CODE (alloc_type) != ENUMERAL_TYPE
   12871           68 :               || !underlying_type_is_valid (TREE_TYPE (alloc_type)))
   12872              :             {
   12873            0 :               auto_diagnostic_group d;
   12874            0 :               error_at (EXPR_LOCATION (alloc_in),
   12875              :                         "%<allocator%> clause requires a valid declaration "
   12876              :                         "of %<omp_allocator_handle_t%>");
   12877              :               /* This diagnostic is not very good, especially if it somehow
   12878              :                  is the declaration in omp.h.  */
   12879            0 :               inform (DECL_SOURCE_LOCATION (alloc_type_decl),
   12880              :                       "invalid type declared here");
   12881            0 :               cached_alloc_type = error_mark_node;
   12882            0 :             }
   12883              :           else
   12884           68 :             cached_alloc_type = alloc_type;
   12885           68 :           gcc_assert (cached_alloc_type != NULL_TREE);
   12886              :           return cached_alloc_type;
   12887         1347 :         } (); /* IILE.  */
   12888              :       /* Any sane user will include omp.h before we get here, unfortunately
   12889              :          insane doesn't mean incorrect.  */
   12890         1347 :       if (alloc_type == NULL_TREE)
   12891            0 :         return alloc_in;
   12892              :       /* We can't do anything meaningful with alloc_in if we lack a valid
   12893              :          omp_allocator_handle_t type.  */
   12894         1347 :       if (alloc_type == error_mark_node)
   12895              :         return error_mark_node;
   12896              : 
   12897              :       /* Identity conversion is okay.  */
   12898         1347 :       const tree converted_alloc
   12899         1347 :         = any_static_vars
   12900         1347 :           ? build_converted_constant_expr (alloc_type, alloc_in, tf_error)
   12901         1136 :           : perform_implicit_conversion (alloc_type, alloc_in, tf_error);
   12902              : 
   12903              :       /* The expr is not manifestly constant-evaluated in this case, only do
   12904              :          simple folding even if it is potentially a constant expression.  */
   12905         1347 :       if (!any_static_vars)
   12906         1136 :         return maybe_fold_non_dependent_expr (converted_alloc, tf_none);
   12907              : 
   12908              :       /* Per OpenMP 5.2 176:26-28 quoted above, the allocator clause is
   12909              :          manifestly constant-evaluated in this case.  */
   12910          211 :       const tree ret = cxx_constant_value (converted_alloc);
   12911          211 :       if (ret == error_mark_node)
   12912              :         {
   12913            5 :           auto_diagnostic_group d;
   12914            5 :           error_at (EXPR_LOCATION (alloc_in),
   12915              :                     "%<allocator%> clause requires a constant "
   12916              :                     "predefined allocator");
   12917            5 :           emit_diag_for_static_vars ();
   12918            5 :           return error_mark_node;
   12919            5 :         }
   12920          206 :       gcc_assert (TREE_CONSTANT (ret));
   12921          206 :       wi::tree_to_widest_ref alloc_value = wi::to_widest (ret);
   12922              :       /* MAX is inclusive.  */
   12923          206 :       const bool predefined_allocator_p
   12924          206 :         = (alloc_value >= 1
   12925          191 :            && alloc_value <= GOMP_OMP_PREDEF_ALLOC_MAX)
   12926          272 :           || (alloc_value >= GOMP_OMPX_PREDEF_ALLOC_MIN
   12927           45 :               && alloc_value <= GOMP_OMPX_PREDEF_ALLOC_MAX);
   12928          146 :       if (!predefined_allocator_p)
   12929              :         {
   12930           60 :           auto_diagnostic_group d;
   12931           60 :           error_at (EXPR_LOCATION (alloc_in),
   12932              :                     "%<allocator%> clause requires a constant "
   12933              :                     "predefined allocator");
   12934           60 :           emit_diag_for_static_vars ();
   12935           60 :           inform (EXPR_LOCATION (alloc_in),
   12936              :                   "expression evaluates to %qwu", tree_to_uhwi (ret));
   12937           60 :           return error_mark_node;
   12938           60 :         }
   12939          146 :       else if (alloc_value == GOMP_OMP_PREDEF_ALLOC_CGROUP
   12940          140 :                || alloc_value == GOMP_OMP_PREDEF_ALLOC_PTEAM
   12941          286 :                || alloc_value == GOMP_OMP_PREDEF_ALLOC_THREAD)
   12942              :         {
   12943           18 :           auto_diagnostic_group d;
   12944           18 :           error_at (EXPR_LOCATION (alloc_in),
   12945              :                     "%<allocator%> clause must not "
   12946              :                     "be %<omp_cgroup_mem_alloc%>, %<omp_pteam_mem_alloc%>, "
   12947              :                     "or %<omp_thread_mem_alloc%>");
   12948           18 :           emit_diag_for_static_vars ();
   12949           18 :           inform (EXPR_LOCATION (alloc_in),
   12950              :                   "expression evaluates to %qwu", tree_to_uhwi (ret));
   12951           18 :         }
   12952              :       return ret;
   12953         2949 :     } (); /* IILE.  */
   12954              : 
   12955         4776 :   auto finalize_allocate_attr = [] (tree var, tree alloc, tree align)
   12956              :     {
   12957              :       /* This should only be called once for each var, either after a
   12958              :          diagnostic, or when we are finished with the directive.  */
   12959         1827 :       gcc_assert (var != NULL_TREE && var != error_mark_node);
   12960              : 
   12961              :       /* Replace the old attr in place to maintain the invariants of
   12962              :          DECL_ATTRIBUTES as described in cp_parser_omp_allocate.
   12963              :          Unfortunately lookup_attribute does not return an "iterator" to the
   12964              :          attr so we have to write the lookup ourselves here.  */
   12965         5481 :       tree *const attr_it = [&] ()
   12966              :         {
   12967         1827 :           tree *it = &DECL_ATTRIBUTES (var);
   12968         1827 :           for (; *it != NULL_TREE; it = &TREE_CHAIN (*it))
   12969         1827 :             if (is_attribute_p ("omp allocate", get_attribute_name (*it)))
   12970         1827 :               return it;
   12971            0 :           gcc_unreachable ();
   12972         1827 :         } (); /* IILE.  */
   12973              :       /* Don't modify the old attr, for various reasons it isn't marked
   12974              :          dependent so substitution does not copy it.  */
   12975         1827 :       const_tree old_attr = *attr_it;
   12976              :       /* There should only be one attr.  */
   12977         1827 :       gcc_checking_assert (!lookup_attribute ("omp allocate",
   12978              :                                               TREE_CHAIN (old_attr)));
   12979              :       /* This location is where the var was specified in the directive.  */
   12980         1827 :       const tree arg_loc = TREE_VALUE (old_attr);
   12981         1827 :       gcc_assert (arg_loc != NULL_TREE && TREE_CODE (arg_loc) == NOP_EXPR);
   12982              :       /* Smuggle the location, we might still need it for diagnostics, such as
   12983              :          if we are still parsing a function.  */
   12984         1827 :       const tree attr_value = tree_cons (alloc, align, arg_loc);
   12985              : 
   12986              :       /* As noted above, we create the final attr ourselves instead of having
   12987              :          substitution handle it.  */
   12988         1827 :       *attr_it = tree_cons (TREE_PURPOSE (old_attr),
   12989              :                             attr_value,
   12990         1827 :                             TREE_CHAIN (old_attr));
   12991         1827 :     };
   12992         3178 :   auto finalize_var_node_with_error = [&] (tree node)
   12993              :     {
   12994              :       /* We can't remove the attribute, the variable still needs to be marked
   12995              :          in case that we are still parsing a function for the first time.
   12996              :          We avoid handling error_mark_node in varpool_node::finalize_decl by
   12997              :          setting align to NULL_TREE.  */
   12998          229 :       finalize_allocate_attr (TREE_PURPOSE (node), error_mark_node, NULL_TREE);
   12999              :       /* Prevent further diagnostics for this var.  */
   13000          229 :       TREE_PURPOSE (node) = error_mark_node;
   13001         3178 :     };
   13002              : 
   13003         5700 :   for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   13004         2751 :     if (deferred_erroneous_var_nodes.contains (vn))
   13005           75 :       finalize_var_node_with_error (vn);
   13006              : 
   13007              :   /* Even if there have been errors, save the current state, there might be
   13008              :      more to diagnose on a later instantiation.  */
   13009         2949 :   if (processing_template_decl)
   13010              :     {
   13011         1046 :       tree allocate_stmt = make_node (OMP_ALLOCATE);
   13012              :       /* This shouldn't matter, but better to set it anyway.  */
   13013         1046 :       TREE_SIDE_EFFECTS (allocate_stmt) = 0;
   13014         1046 :       SET_EXPR_LOCATION (allocate_stmt, loc);
   13015         1046 :       OMP_ALLOCATE_VARS (allocate_stmt) = var_list;
   13016         1046 :       OMP_ALLOCATE_ALLOCATOR (allocate_stmt) = alloc;
   13017         1046 :       OMP_ALLOCATE_ALIGN (allocate_stmt) = align;
   13018         1046 :       add_stmt (allocate_stmt);
   13019         1046 :       return;
   13020              :     }
   13021         1829 :   else if (alloc == error_mark_node || align == error_mark_node || !var_list
   13022         3499 :            || any_of_vars (&error_operand_p))
   13023              :     {
   13024              :       /* The directive is fully instantiated, but there were errors.  */
   13025          563 :       for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   13026              :         /* Don't mark vars a second time.  */
   13027          211 :         if (TREE_PURPOSE (vn) != error_mark_node)
   13028          154 :           finalize_var_node_with_error (vn);
   13029              :       return;
   13030              :     }
   13031              : 
   13032         1551 :   gcc_assert (!processing_template_decl
   13033              :               && alloc != error_mark_node
   13034              :               && align != error_mark_node
   13035              :               && var_list != NULL_TREE
   13036              :               && !any_of_vars (&error_operand_p));
   13037              : 
   13038              :   /* We can technically finalize earlier if everything (vars, alloc, align) is
   13039              :      substituted and the alloc expr doesn't contain any local variables, this
   13040              :      isn't worth the added complexity for now though.  */
   13041         3149 :   for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
   13042         1598 :     finalize_allocate_attr (TREE_PURPOSE (vn), alloc, align);
   13043         2949 : }
   13044              : 
   13045              : void
   13046         3351 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
   13047              :                    tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
   13048              :                    tree clauses, enum omp_memory_order mo, bool weak)
   13049              : {
   13050         3351 :   tree orig_lhs;
   13051         3351 :   tree orig_rhs;
   13052         3351 :   tree orig_v;
   13053         3351 :   tree orig_lhs1;
   13054         3351 :   tree orig_rhs1;
   13055         3351 :   tree orig_r;
   13056         3351 :   bool dependent_p;
   13057         3351 :   tree stmt;
   13058              : 
   13059         3351 :   orig_lhs = lhs;
   13060         3351 :   orig_rhs = rhs;
   13061         3351 :   orig_v = v;
   13062         3351 :   orig_lhs1 = lhs1;
   13063         3351 :   orig_rhs1 = rhs1;
   13064         3351 :   orig_r = r;
   13065         3351 :   dependent_p = false;
   13066         3351 :   stmt = NULL_TREE;
   13067              : 
   13068              :   /* Even in a template, we can detect invalid uses of the atomic
   13069              :      pragma if neither LHS nor RHS is type-dependent.  */
   13070         3351 :   if (processing_template_decl)
   13071              :     {
   13072          600 :       dependent_p = (type_dependent_expression_p (lhs)
   13073          237 :                      || (rhs && type_dependent_expression_p (rhs))
   13074          234 :                      || (v && type_dependent_expression_p (v))
   13075          234 :                      || (lhs1 && type_dependent_expression_p (lhs1))
   13076          234 :                      || (rhs1 && type_dependent_expression_p (rhs1))
   13077          834 :                      || (r
   13078           25 :                          && r != void_list_node
   13079           16 :                          && type_dependent_expression_p (r)));
   13080          600 :       if (clauses)
   13081              :         {
   13082           30 :           gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
   13083              :                       && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
   13084              :                       && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
   13085           30 :           if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
   13086           30 :               || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
   13087              :             dependent_p = true;
   13088              :         }
   13089              :     }
   13090          576 :   if (!dependent_p)
   13091              :     {
   13092         2967 :       bool swapped = false;
   13093         2967 :       if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
   13094              :         {
   13095          143 :           std::swap (rhs, rhs1);
   13096          143 :           swapped = !commutative_tree_code (opcode);
   13097              :         }
   13098         2967 :       if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
   13099              :         {
   13100            0 :           if (code == OMP_ATOMIC)
   13101            0 :             error ("%<#pragma omp atomic update%> uses two different "
   13102              :                    "expressions for memory");
   13103              :           else
   13104            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   13105              :                    "expressions for memory");
   13106              :           return;
   13107              :         }
   13108         2967 :       if (lhs1 && !cp_tree_equal (lhs, lhs1))
   13109              :         {
   13110            0 :           if (code == OMP_ATOMIC)
   13111            0 :             error ("%<#pragma omp atomic update%> uses two different "
   13112              :                    "expressions for memory");
   13113              :           else
   13114            0 :             error ("%<#pragma omp atomic capture%> uses two different "
   13115              :                    "expressions for memory");
   13116              :           return;
   13117              :         }
   13118         5934 :       stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
   13119              :                                   v, lhs1, rhs1, r, swapped, mo, weak,
   13120         2967 :                                   processing_template_decl != 0);
   13121         2967 :       if (stmt == error_mark_node)
   13122              :         return;
   13123              :     }
   13124         3321 :   if (processing_template_decl)
   13125              :     {
   13126          591 :       if (code == OMP_ATOMIC_READ)
   13127              :         {
   13128          167 :           stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
   13129          167 :           OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   13130          167 :           stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   13131              :         }
   13132              :       else
   13133              :         {
   13134          424 :           if (opcode == NOP_EXPR)
   13135           35 :             stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
   13136          389 :           else if (opcode == COND_EXPR)
   13137              :             {
   13138          124 :               stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
   13139          124 :               if (orig_r)
   13140           50 :                 stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
   13141              :                                stmt);
   13142          124 :               stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
   13143              :                              orig_lhs);
   13144          124 :               orig_rhs1 = NULL_TREE;
   13145              :             }
   13146              :           else
   13147          265 :             stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
   13148          424 :           if (orig_rhs1)
   13149          182 :             stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
   13150              :                                      COMPOUND_EXPR, orig_rhs1, stmt);
   13151          424 :           if (code != OMP_ATOMIC)
   13152              :             {
   13153          233 :               stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
   13154          233 :               OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   13155          233 :               OMP_ATOMIC_WEAK (stmt) = weak;
   13156          233 :               stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   13157              :             }
   13158              :         }
   13159          591 :       stmt = build2 (OMP_ATOMIC, void_type_node,
   13160              :                      clauses ? clauses : integer_zero_node, stmt);
   13161          591 :       OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   13162          591 :       OMP_ATOMIC_WEAK (stmt) = weak;
   13163          591 :       SET_EXPR_LOCATION (stmt, loc);
   13164              :     }
   13165              : 
   13166              :   /* Avoid -Wunused-value warnings here, the whole construct has side-effects
   13167              :      and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
   13168              :      in some tree that appears to be unused, the value is not unused.  */
   13169         3321 :   warning_sentinel w (warn_unused_value);
   13170         3321 :   finish_expr_stmt (stmt);
   13171         3321 : }
   13172              : 
   13173              : void
   13174          359 : finish_omp_barrier (void)
   13175              : {
   13176          359 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
   13177          359 :   releasing_vec vec;
   13178          359 :   vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
   13179          359 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13180          359 :   finish_expr_stmt (stmt);
   13181          359 : }
   13182              : 
   13183              : void
   13184          397 : finish_omp_depobj (location_t loc, tree depobj,
   13185              :                    enum omp_clause_depend_kind kind, tree clause)
   13186              : {
   13187          397 :   if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
   13188              :     {
   13189          343 :       if (!lvalue_p (depobj))
   13190              :         {
   13191            6 :           error_at (EXPR_LOC_OR_LOC (depobj, loc),
   13192              :                     "%<depobj%> expression is not lvalue expression");
   13193            6 :           depobj = error_mark_node;
   13194              :         }
   13195              :     }
   13196              : 
   13197          397 :   if (processing_template_decl)
   13198              :     {
   13199          114 :       if (clause == NULL_TREE)
   13200           47 :         clause = build_int_cst (integer_type_node, kind);
   13201          114 :       add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
   13202          114 :       return;
   13203              :     }
   13204              : 
   13205          283 :   if (!error_operand_p (depobj))
   13206              :     {
   13207          274 :       tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
   13208          274 :       if (addr == error_mark_node)
   13209              :         depobj = error_mark_node;
   13210              :       else
   13211          274 :         depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
   13212              :                                         tf_warning_or_error);
   13213              :     }
   13214              : 
   13215          283 :   c_finish_omp_depobj (loc, depobj, kind, clause);
   13216              : }
   13217              : 
   13218              : void
   13219          162 : finish_omp_flush (int mo)
   13220              : {
   13221          162 :   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   13222          162 :   releasing_vec vec;
   13223          162 :   if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
   13224              :     {
   13225           54 :       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
   13226           54 :       vec->quick_push (build_int_cst (integer_type_node, mo));
   13227              :     }
   13228          162 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13229          162 :   finish_expr_stmt (stmt);
   13230          162 : }
   13231              : 
   13232              : void
   13233          111 : finish_omp_taskwait (void)
   13234              : {
   13235          111 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
   13236          111 :   releasing_vec vec;
   13237          111 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13238          111 :   finish_expr_stmt (stmt);
   13239          111 : }
   13240              : 
   13241              : void
   13242           16 : finish_omp_taskyield (void)
   13243              : {
   13244           16 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
   13245           16 :   releasing_vec vec;
   13246           16 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13247           16 :   finish_expr_stmt (stmt);
   13248           16 : }
   13249              : 
   13250              : void
   13251          596 : finish_omp_cancel (tree clauses)
   13252              : {
   13253          596 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   13254          596 :   int mask = 0;
   13255          596 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   13256              :     mask = 1;
   13257          414 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   13258              :     mask = 2;
   13259          285 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   13260              :     mask = 4;
   13261          164 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   13262              :     mask = 8;
   13263              :   else
   13264              :     {
   13265            0 :       error ("%<#pragma omp cancel%> must specify one of "
   13266              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   13267            0 :       return;
   13268              :     }
   13269          596 :   releasing_vec vec;
   13270          596 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   13271          596 :   if (ifc != NULL_TREE)
   13272              :     {
   13273           70 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   13274           70 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   13275            6 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   13276              :                   "expected %<cancel%> %<if%> clause modifier");
   13277              :       else
   13278              :         {
   13279           64 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   13280           64 :           if (ifc2 != NULL_TREE)
   13281              :             {
   13282            3 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   13283              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   13284              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   13285            3 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   13286              :                         "expected %<cancel%> %<if%> clause modifier");
   13287              :             }
   13288              :         }
   13289              : 
   13290           70 :       if (!processing_template_decl)
   13291           61 :         ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
   13292              :       else
   13293            9 :         ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   13294            9 :                                  OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
   13295              :                                  integer_zero_node, ERROR_MARK,
   13296              :                                  NULL_TREE, NULL, tf_warning_or_error);
   13297              :     }
   13298              :   else
   13299          526 :     ifc = boolean_true_node;
   13300          596 :   vec->quick_push (build_int_cst (integer_type_node, mask));
   13301          596 :   vec->quick_push (ifc);
   13302          596 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13303          596 :   finish_expr_stmt (stmt);
   13304          596 : }
   13305              : 
   13306              : void
   13307          494 : finish_omp_cancellation_point (tree clauses)
   13308              : {
   13309          494 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   13310          494 :   int mask = 0;
   13311          494 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   13312              :     mask = 1;
   13313          366 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   13314              :     mask = 2;
   13315          261 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   13316              :     mask = 4;
   13317          156 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   13318              :     mask = 8;
   13319              :   else
   13320              :     {
   13321            3 :       error ("%<#pragma omp cancellation point%> must specify one of "
   13322              :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   13323            3 :       return;
   13324              :     }
   13325          491 :   releasing_vec vec
   13326          491 :     = make_tree_vector_single (build_int_cst (integer_type_node, mask));
   13327          491 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   13328          491 :   finish_expr_stmt (stmt);
   13329          491 : }
   13330              : 
   13331              : /* Begin a __transaction_atomic or __transaction_relaxed statement.
   13332              :    If PCOMPOUND is non-null, this is for a function-transaction-block, and we
   13333              :    should create an extra compound stmt.  */
   13334              : 
   13335              : tree
   13336          303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
   13337              : {
   13338          303 :   tree r;
   13339              : 
   13340          303 :   if (pcompound)
   13341           21 :     *pcompound = begin_compound_stmt (0);
   13342              : 
   13343          303 :   r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
   13344              : 
   13345              :   /* Only add the statement to the function if support enabled.  */
   13346          303 :   if (flag_tm)
   13347          297 :     add_stmt (r);
   13348              :   else
   13349           12 :     error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
   13350              :                     ? G_("%<__transaction_relaxed%> without "
   13351              :                          "transactional memory support enabled")
   13352              :                     : G_("%<__transaction_atomic%> without "
   13353              :                          "transactional memory support enabled")));
   13354              : 
   13355          303 :   TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
   13356          303 :   TREE_SIDE_EFFECTS (r) = 1;
   13357          303 :   return r;
   13358              : }
   13359              : 
   13360              : /* End a __transaction_atomic or __transaction_relaxed statement.
   13361              :    If COMPOUND_STMT is non-null, this is for a function-transaction-block,
   13362              :    and we should end the compound.  If NOEX is non-NULL, we wrap the body in
   13363              :    a MUST_NOT_THROW_EXPR with NOEX as condition.  */
   13364              : 
   13365              : void
   13366          303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
   13367              : {
   13368          303 :   TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
   13369          303 :   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   13370          303 :   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
   13371          303 :   TRANSACTION_EXPR_IS_STMT (stmt) = 1;
   13372              : 
   13373              :   /* noexcept specifications are not allowed for function transactions.  */
   13374          303 :   gcc_assert (!(noex && compound_stmt));
   13375          303 :   if (noex)
   13376              :     {
   13377           51 :       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
   13378              :                                              noex);
   13379           51 :       protected_set_expr_location
   13380           51 :         (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
   13381           51 :       TREE_SIDE_EFFECTS (body) = 1;
   13382           51 :       TRANSACTION_EXPR_BODY (stmt) = body;
   13383              :     }
   13384              : 
   13385          303 :   if (compound_stmt)
   13386           21 :     finish_compound_stmt (compound_stmt);
   13387          303 : }
   13388              : 
   13389              : /* Build a __transaction_atomic or __transaction_relaxed expression.  If
   13390              :    NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
   13391              :    condition.  */
   13392              : 
   13393              : tree
   13394          116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
   13395              : {
   13396          116 :   tree ret;
   13397          116 :   if (noex)
   13398              :     {
   13399           57 :       expr = build_must_not_throw_expr (expr, noex);
   13400           57 :       protected_set_expr_location (expr, loc);
   13401           57 :       TREE_SIDE_EFFECTS (expr) = 1;
   13402              :     }
   13403          116 :   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
   13404          116 :   if (flags & TM_STMT_ATTR_RELAXED)
   13405            4 :         TRANSACTION_EXPR_RELAXED (ret) = 1;
   13406          116 :   TREE_SIDE_EFFECTS (ret) = 1;
   13407          116 :   SET_EXPR_LOCATION (ret, loc);
   13408          116 :   return ret;
   13409              : }
   13410              : 
   13411              : void
   13412       102674 : init_cp_semantics (void)
   13413              : {
   13414       102674 : }
   13415              : 
   13416              : 
   13417              : /* Get constant string at LOCATION. Returns true if successful,
   13418              :    otherwise false.  */
   13419              : 
   13420              : bool
   13421     11279488 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
   13422              : {
   13423     11279488 :   tsubst_flags_t complain = tf_warning_or_error;
   13424              : 
   13425     11279488 :   if (message == NULL_TREE
   13426     11279488 :       || message == error_mark_node
   13427     22558973 :       || check_for_bare_parameter_packs (message))
   13428              :     return false;
   13429              : 
   13430     11279485 :   if (TREE_CODE (message) != STRING_CST
   13431     11279485 :       && !type_dependent_expression_p (message))
   13432              :     {
   13433         1053 :       message_sz
   13434         1053 :         = finish_class_member_access_expr (message,
   13435              :                                            get_identifier ("size"),
   13436              :                                            false, complain);
   13437         1053 :       if (message_sz != error_mark_node)
   13438          952 :         message_data
   13439          952 :           = finish_class_member_access_expr (message,
   13440              :                                              get_identifier ("data"),
   13441              :                                              false, complain);
   13442         1053 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   13443              :         {
   13444          139 :           error_at (location, "constexpr string must be a string "
   13445              :                     "literal or object with %<size%> and "
   13446              :                     "%<data%> members");
   13447          322 :           return false;
   13448              :         }
   13449          914 :       releasing_vec size_args, data_args;
   13450          914 :       message_sz = finish_call_expr (message_sz, &size_args, false, false,
   13451              :                                      complain);
   13452          914 :       message_data = finish_call_expr (message_data, &data_args, false, false,
   13453              :                                        complain);
   13454          914 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   13455              :         return false;
   13456          800 :       message_sz = build_converted_constant_expr (size_type_node, message_sz,
   13457              :                                                   complain);
   13458          800 :       if (message_sz == error_mark_node)
   13459              :         {
   13460           15 :           error_at (location, "constexpr string %<size()%> "
   13461              :                     "must be implicitly convertible to "
   13462              :                     "%<std::size_t%>");
   13463           15 :           return false;
   13464              :         }
   13465              : 
   13466          785 :       if (allow_char8_t
   13467           74 :           && POINTER_TYPE_P (TREE_TYPE (message_data))
   13468           74 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   13469           74 :               == char8_type_node)
   13470          805 :           && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
   13471          183 :               == TYPE_QUAL_CONST))
   13472              :         return true;
   13473              : 
   13474          765 :       message_data = build_converted_constant_expr (const_string_type_node,
   13475              :                                                     message_data, complain);
   13476          765 :       if (message_data == error_mark_node)
   13477              :         {
   13478           34 :           error_at (location, "constexpr string %<data()%> "
   13479              :                     "must be implicitly convertible to "
   13480              :                     "%<const char*%>");
   13481           34 :           return false;
   13482              :         }
   13483          914 :     }
   13484              :   return true;
   13485              : }
   13486              : 
   13487              : /* Extract constant string at LOCATON into output string STR.
   13488              :    Returns true if successful, otherwise false.  */
   13489              : 
   13490              : bool
   13491          405 : cexpr_str::extract (location_t location, tree &str)
   13492              : {
   13493          405 :   const char *msg;
   13494          405 :   int len;
   13495          405 :   if (!extract (location, msg, len))
   13496              :     return false;
   13497          343 :   str = build_string (len, msg);
   13498          343 :   return true;
   13499              : }
   13500              : 
   13501              : /* Extract constant string at LOCATION into output string MSG with LEN.
   13502              :    Returns true if successful, otherwise false.  */
   13503              : 
   13504              : bool
   13505         2707 : cexpr_str::extract (location_t location, const char * &msg, int &len,
   13506              :                     const constexpr_ctx *ctx /* = NULL */,
   13507              :                     bool *non_constant_p /* = NULL */,
   13508              :                     bool *overflow_p /* = NULL */,
   13509              :                     tree *jump_target /* = NULL */)
   13510              : {
   13511         2707 :   tsubst_flags_t complain = tf_warning_or_error;
   13512              : 
   13513         2707 :   msg = NULL;
   13514         2707 :   if (message_sz && message_data)
   13515              :     {
   13516          677 :       tree msz;
   13517          677 :       if (ctx)
   13518              :         {
   13519          110 :           msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
   13520              :                                               non_constant_p, overflow_p,
   13521              :                                               jump_target);
   13522          110 :           if (*jump_target || *non_constant_p)
   13523              :             return false;
   13524              :         }
   13525              :       else
   13526          567 :         msz = cxx_constant_value (message_sz, NULL_TREE, complain);
   13527          669 :       if (!tree_fits_uhwi_p (msz))
   13528              :         {
   13529           35 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   13530           35 :             error_at (location,
   13531              :                       "constexpr string %<size()%> "
   13532              :                       "must be a constant expression");
   13533              :           return false;
   13534              :         }
   13535          634 :       else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
   13536              :                != tree_to_uhwi (msz))
   13537              :         {
   13538            0 :           if (!ctx || !cxx_constexpr_quiet_p (ctx))
   13539            0 :             error_at (location,
   13540              :                       "constexpr string message %<size()%> "
   13541              :                       "%qE too large", msz);
   13542              :           return false;
   13543              :         }
   13544          634 :       len = tree_to_uhwi (msz);
   13545          634 :       tree data;
   13546          634 :       if (ctx)
   13547              :         {
   13548          102 :           data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
   13549              :                                                non_constant_p, overflow_p,
   13550              :                                                jump_target);
   13551          102 :           if (*jump_target || *non_constant_p)
   13552              :             return false;
   13553           94 :           STRIP_NOPS (data);
   13554           94 :           if (TREE_CODE (data) != ADDR_EXPR)
   13555              :             {
   13556            0 :             unhandled:
   13557            0 :               if (!cxx_constexpr_quiet_p (ctx))
   13558            0 :                 error_at (location, "unhandled return from %<data()%>");
   13559              :               return false;
   13560              :             }
   13561           94 :           tree str = TREE_OPERAND (data, 0);
   13562           94 :           unsigned HOST_WIDE_INT off = 0;
   13563           94 :           if (TREE_CODE (str) == ARRAY_REF
   13564           94 :               && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
   13565              :             {
   13566           12 :               off = tree_to_uhwi (TREE_OPERAND (str, 1));
   13567           12 :               str = TREE_OPERAND (str, 0);
   13568              :             }
   13569           94 :           str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
   13570              :                                               non_constant_p, overflow_p,
   13571              :                                               jump_target);
   13572           94 :           if (*jump_target || *non_constant_p)
   13573              :             return false;
   13574           94 :           if (TREE_CODE (str) == STRING_CST)
   13575              :             {
   13576           84 :               if (TREE_STRING_LENGTH (str) < len
   13577           84 :                   || (unsigned) TREE_STRING_LENGTH (str) < off
   13578          168 :                   || (unsigned) TREE_STRING_LENGTH (str) < off + len)
   13579            0 :                 goto unhandled;
   13580           84 :               msg = TREE_STRING_POINTER (str) + off;
   13581           84 :               goto translate;
   13582              :             }
   13583           10 :           if (TREE_CODE (str) != CONSTRUCTOR
   13584           10 :               || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
   13585            0 :             goto unhandled;
   13586           10 :           char *b;
   13587           10 :           if (len < 64)
   13588           10 :             b = XALLOCAVEC (char, len + 1);
   13589              :           else
   13590              :             {
   13591            0 :               buf = XNEWVEC (char, len + 1);
   13592            0 :               b = buf;
   13593              :             }
   13594           10 :           msg = b;
   13595           10 :           memset (b, 0, len + 1);
   13596           10 :           tree field, value;
   13597           10 :           unsigned k;
   13598           10 :           unsigned HOST_WIDE_INT l = 0;
   13599          158 :           FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
   13600          158 :             if (!tree_fits_shwi_p (value))
   13601            0 :               goto unhandled;
   13602          158 :             else if (field == NULL_TREE)
   13603              :               {
   13604            0 :                 if (integer_zerop (value))
   13605              :                   break;
   13606            0 :                 if (l >= off && l < off + len)
   13607            0 :                   b[l - off] = tree_to_shwi (value);
   13608            0 :                 ++l;
   13609              :               }
   13610          158 :             else if (TREE_CODE (field) == RANGE_EXPR)
   13611              :               {
   13612            0 :                 tree lo = TREE_OPERAND (field, 0);
   13613            0 :                 tree hi = TREE_OPERAND (field, 1);
   13614            0 :                 if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
   13615            0 :                   goto unhandled;
   13616            0 :                 if (integer_zerop (value))
   13617              :                   break;
   13618            0 :                 unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
   13619            0 :                 for (l = tree_to_uhwi (lo); l <= m; ++l)
   13620            0 :                   if (l >= off && l < off + len)
   13621            0 :                     b[l - off] = tree_to_shwi (value);
   13622              :               }
   13623          158 :             else if (tree_fits_uhwi_p (field))
   13624              :               {
   13625          158 :                 l = tree_to_uhwi (field);
   13626          158 :                 if (integer_zerop (value))
   13627              :                   break;
   13628          148 :                 if (l >= off && l < off + len)
   13629          148 :                   b[l - off] = tree_to_shwi (value);
   13630          148 :                 l++;
   13631              :               }
   13632           10 :           b[len] = '\0';
   13633              :         }
   13634              :       else
   13635              :         {
   13636          532 :           data = maybe_constant_value (message_data, NULL_TREE, mce_true);
   13637          532 :           if (!reduced_constant_expression_p (data))
   13638           96 :             data = NULL_TREE;
   13639          532 :           if (len)
   13640              :             {
   13641          455 :               if (data)
   13642          381 :                 msg = c_getstr (data);
   13643          455 :               if (msg == NULL)
   13644          119 :                 buf = XNEWVEC (char, len);
   13645         1458 :               for (int i = 0; i < len; ++i)
   13646              :                 {
   13647         1033 :                   tree t = message_data;
   13648         1033 :                   if (i)
   13649         1156 :                     t = build2 (POINTER_PLUS_EXPR,
   13650          578 :                                 TREE_TYPE (message_data), message_data,
   13651          578 :                                 size_int (i));
   13652         1033 :                   t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
   13653         1033 :                   tree t2 = cxx_constant_value (t, NULL_TREE, complain);
   13654         1033 :                   if (!tree_fits_shwi_p (t2))
   13655              :                     {
   13656           30 :                       error_at (location,
   13657              :                                 "constexpr string %<data()[%d]%> "
   13658              :                                 "must be a constant expression", i);
   13659           30 :                       return false;
   13660              :                     }
   13661         1003 :                   if (msg == NULL)
   13662          362 :                     buf[i] = tree_to_shwi (t2);
   13663              :                   /* If c_getstr worked, just verify the first and
   13664              :                      last characters using constant evaluation.  */
   13665          641 :                   else if (len > 2 && i == 0)
   13666          268 :                     i = len - 2;
   13667              :                 }
   13668          425 :               if (msg == NULL)
   13669          104 :                 msg = buf;
   13670              :             }
   13671           77 :           else if (!data)
   13672              :             {
   13673              :               /* We don't have any function to test whether some
   13674              :                  expression is a core constant expression.  So, instead
   13675              :                  test whether (message.data (), 0) is a constant
   13676              :                  expression.  */
   13677           22 :               data = build2 (COMPOUND_EXPR, integer_type_node,
   13678              :                              message_data, integer_zero_node);
   13679           22 :               tree t = cxx_constant_value (data, NULL_TREE, complain);
   13680           22 :               if (!integer_zerop (t))
   13681              :                 {
   13682           22 :                   error_at (location,
   13683              :                             "constexpr string %<data()%> "
   13684              :                             "must be a core constant expression");
   13685           22 :                   return false;
   13686              :                 }
   13687              :             }
   13688              :         }
   13689              :     }
   13690              :   else
   13691              :     {
   13692         2030 :       tree eltype = TREE_TYPE (TREE_TYPE (message));
   13693         2030 :       int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
   13694         2030 :       msg = TREE_STRING_POINTER (message);
   13695         2030 :       len = TREE_STRING_LENGTH (message) / sz - 1;
   13696              :     }
   13697         2604 : translate:
   13698         2604 :   if ((message_sz && message_data) || ctx)
   13699              :     {
   13700              :       /* Convert the string from execution charset to SOURCE_CHARSET.  */
   13701          768 :       cpp_string istr, ostr;
   13702          768 :       istr.len = len;
   13703          768 :       istr.text = (const unsigned char *) msg;
   13704          768 :       enum cpp_ttype type = CPP_STRING;
   13705          768 :       if (message_sz && message_data)
   13706              :         {
   13707          574 :           if (POINTER_TYPE_P (TREE_TYPE (message_data))
   13708          574 :               && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
   13709          574 :                   == char8_type_node))
   13710              :             type = CPP_UTF8STRING;
   13711              :         }
   13712          194 :       else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
   13713          194 :                == char8_type_node)
   13714          768 :         type = CPP_UTF8STRING;
   13715          768 :       if (len == 0)
   13716              :         ;
   13717          643 :       else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
   13718              :                                       true))
   13719              :         {
   13720            0 :           if (type == CPP_UTF8STRING)
   13721            0 :             error_at (location, "could not convert constexpr string from "
   13722              :                                 "UTF-8 encoding to source character "
   13723              :                                 "set");
   13724              :           else
   13725            0 :             error_at (location, "could not convert constexpr string from "
   13726              :                                 "ordinary literal encoding to source character "
   13727              :                                 "set");
   13728            0 :           return false;
   13729              :         }
   13730              :       else
   13731              :         {
   13732          643 :           if (buf)
   13733          104 :             XDELETEVEC (buf);
   13734          643 :           msg = buf = const_cast <char *> ((const char *) ostr.text);
   13735          643 :           len = ostr.len;
   13736              :         }
   13737              :     }
   13738              : 
   13739              :   return true;
   13740              : }
   13741              : 
   13742              : /* Build a STATIC_ASSERT for a static assertion with the condition
   13743              :    CONDITION and the message text MESSAGE.  LOCATION is the location
   13744              :    of the static assertion in the source code.  When MEMBER_P, this
   13745              :    static assertion is a member of a class.  If SHOW_EXPR_P is true,
   13746              :    print the condition (because it was instantiation-dependent).
   13747              :    If CONSTEVAL_BLOCK_P is true, this static assertion represents
   13748              :    a consteval block.  */
   13749              : 
   13750              : void
   13751     11278797 : finish_static_assert (tree condition, tree message, location_t location,
   13752              :                       bool member_p, bool show_expr_p,
   13753              :                       bool consteval_block_p/*=false*/)
   13754              : {
   13755     11278797 :   tsubst_flags_t complain = tf_warning_or_error;
   13756              : 
   13757     11278797 :   if (condition == NULL_TREE
   13758     11278797 :       || condition == error_mark_node)
   13759      4778735 :     return;
   13760              : 
   13761     11278571 :   if (check_for_bare_parameter_packs (condition))
   13762              :     return;
   13763              : 
   13764     11278568 :   cexpr_str cstr(message);
   13765     11278568 :   if (!cstr.type_check (location))
   13766              :     return;
   13767              : 
   13768              :   /* Save the condition in case it was a concept check.  */
   13769     11278474 :   tree orig_condition = condition;
   13770              : 
   13771     11278474 :   if (instantiation_dependent_expression_p (condition)
   13772     11278474 :       || instantiation_dependent_expression_p (message))
   13773              :     {
   13774              :       /* We're in a template; build a STATIC_ASSERT and put it in
   13775              :          the right place. */
   13776      4777854 :     defer:
   13777      4777854 :       tree assertion = make_node (STATIC_ASSERT);
   13778      4777854 :       STATIC_ASSERT_CONDITION (assertion) = orig_condition;
   13779      4777854 :       STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
   13780      4777854 :       STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
   13781      4777854 :       CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
   13782              : 
   13783      4777854 :       if (member_p)
   13784      2444991 :         maybe_add_class_template_decl_list (current_class_type,
   13785              :                                             assertion,
   13786              :                                             /*friend_p=*/0);
   13787              :       else
   13788      2332863 :         add_stmt (assertion);
   13789              : 
   13790              :       return;
   13791              :     }
   13792              : 
   13793              :   /* Evaluate the consteval { }.  This must be done only once.  */
   13794      6506715 :   if (consteval_block_p)
   13795              :     {
   13796          533 :       cxx_constant_value (condition);
   13797          533 :       return;
   13798              :     }
   13799              : 
   13800              :   /* Fold the expression and convert it to a boolean value. */
   13801      6506182 :   condition = contextual_conv_bool (condition, complain);
   13802      6506182 :   condition = fold_non_dependent_expr (condition, complain,
   13803              :                                        /*manifestly_const_eval=*/true);
   13804              : 
   13805      6506180 :   if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
   13806              :     /* Do nothing; the condition is satisfied. */
   13807              :     ;
   13808              :   else
   13809              :     {
   13810         8957 :       iloc_sentinel ils (location);
   13811              : 
   13812         8957 :       if (integer_zerop (condition))
   13813              :         {
   13814              :           /* CWG2518: static_assert failure in a template is not IFNDR.  */
   13815         8093 :           if (processing_template_decl)
   13816         6095 :             goto defer;
   13817              : 
   13818         1998 :           int len;
   13819         1998 :           const char *msg = NULL;
   13820         1998 :           if (!cstr.extract (location, msg, len))
   13821           25 :             return;
   13822              : 
   13823              :           /* See if we can find which clause was failing (for logical AND).  */
   13824         1973 :           tree bad = find_failing_clause (NULL, orig_condition);
   13825              :           /* If not, or its location is unusable, fall back to the previous
   13826              :              location.  */
   13827         1973 :           location_t cloc = cp_expr_loc_or_loc (bad, location);
   13828              : 
   13829         1973 :           auto_diagnostic_group d;
   13830              : 
   13831              :           /* Report the error. */
   13832         1973 :           if (len == 0)
   13833         1261 :             error_at (cloc, "static assertion failed");
   13834              :           else
   13835          712 :             error_at (cloc, "static assertion failed: %.*s", len, msg);
   13836              : 
   13837         1973 :           diagnose_failing_condition (bad, cloc, show_expr_p);
   13838              : 
   13839              :           /* Suppress -Wreturn-type for functions with failed static_asserts.
   13840              :              Otherwise templates like:
   13841              :              if constexpr (whatever)
   13842              :                return something (args);
   13843              :              else
   13844              :                static_assert (false, "explanation");
   13845              :              get a useless extra -Wreturn-type warning.  */
   13846         1973 :           if (current_function_decl)
   13847          758 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13848         1973 :         }
   13849          864 :       else if (condition && condition != error_mark_node)
   13850              :         {
   13851          858 :           error ("non-constant condition for static assertion");
   13852          858 :           if (require_rvalue_constant_expression (condition))
   13853          796 :             cxx_constant_value (condition);
   13854              :         }
   13855         8957 :     }
   13856     11278566 : }
   13857              : 
   13858              : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
   13859              :    suitable for use as a type-specifier.
   13860              : 
   13861              :    ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
   13862              :    id-expression or a class member access, FALSE when it was parsed as
   13863              :    a full expression.  */
   13864              : 
   13865              : tree
   13866     43896159 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
   13867              :                       tsubst_flags_t complain)
   13868              : {
   13869     43896159 :   tree type = NULL_TREE;
   13870              : 
   13871     43896159 :   if (!expr || error_operand_p (expr))
   13872       241359 :     return error_mark_node;
   13873              : 
   13874     43654800 :   if (TYPE_P (expr)
   13875     43654800 :       || TREE_CODE (expr) == TYPE_DECL
   13876     87309580 :       || (TREE_CODE (expr) == BIT_NOT_EXPR
   13877        16146 :           && TYPE_P (TREE_OPERAND (expr, 0))))
   13878              :     {
   13879           29 :       if (complain & tf_error)
   13880           29 :         error ("argument to %<decltype%> must be an expression");
   13881           29 :       return error_mark_node;
   13882              :     }
   13883              : 
   13884              :   /* decltype is an unevaluated context.  */
   13885     43654771 :   cp_unevaluated u;
   13886              : 
   13887     43654771 :   processing_template_decl_sentinel ptds (/*reset=*/false);
   13888              : 
   13889              :   /* Depending on the resolution of DR 1172, we may later need to distinguish
   13890              :      instantiation-dependent but not type-dependent expressions so that, say,
   13891              :      A<decltype(sizeof(T))>::U doesn't require 'typename'.  */
   13892     43654771 :   if (instantiation_dependent_uneval_expression_p (expr))
   13893              :     {
   13894      7333299 :     dependent:
   13895      7333875 :       type = cxx_make_type (DECLTYPE_TYPE);
   13896      7333875 :       DECLTYPE_TYPE_EXPR (type) = expr;
   13897     14667750 :       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
   13898      7333875 :         = id_expression_or_member_access_p;
   13899      7333875 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   13900              : 
   13901      7333875 :       return type;
   13902              :     }
   13903     36321472 :   else if (processing_template_decl)
   13904              :     {
   13905         7767 :       expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
   13906         7767 :       if (expr == error_mark_node)
   13907              :         return error_mark_node;
   13908              :       /* Keep processing_template_decl cleared for the rest of the function
   13909              :          (for sake of the call to lvalue_kind below, which handles templated
   13910              :          and non-templated COND_EXPR differently).  */
   13911         7730 :       processing_template_decl = 0;
   13912              :     }
   13913              : 
   13914              :   /* The type denoted by decltype(e) is defined as follows:  */
   13915              : 
   13916     36321435 :   expr = resolve_nondeduced_context (expr, complain);
   13917     36321435 :   if (!mark_single_function (expr, complain))
   13918            0 :     return error_mark_node;
   13919              : 
   13920     36321435 :   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
   13921           18 :     return error_mark_node;
   13922              : 
   13923     36321417 :   if (type_unknown_p (expr))
   13924              :     {
   13925           18 :       if (complain & tf_error)
   13926            6 :         error ("%<decltype%> cannot resolve address of overloaded function");
   13927           18 :       return error_mark_node;
   13928              :     }
   13929              : 
   13930     36321399 :   if (id_expression_or_member_access_p)
   13931              :     {
   13932              :       /* If e is an id-expression or a class member access (5.2.5
   13933              :          [expr.ref]), decltype(e) is defined as the type of the entity
   13934              :          named by e. If there is no such entity, or e names a set of
   13935              :          overloaded functions, the program is ill-formed.  */
   13936       557171 :       if (identifier_p (expr))
   13937            0 :         expr = lookup_name (expr);
   13938              : 
   13939              :       /* If e is a constified expression inside a contract assertion,
   13940              :          strip the const wrapper. Per P2900R14, "For a function f with the
   13941              :          return type T , the result name is an lvalue of type const T , decltype(r)
   13942              :          is T , and decltype((r)) is const T&."  */
   13943       557171 :       expr = strip_contract_const_wrapper (expr);
   13944              : 
   13945       379531 :       if (REFERENCE_REF_P (expr)
   13946       557176 :           || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   13947              :         /* This can happen when the expression is, e.g., "a.b". Just
   13948              :            look at the underlying operand.  */
   13949       387011 :         expr = TREE_OPERAND (expr, 0);
   13950              : 
   13951       557171 :       if (TREE_CODE (expr) == OFFSET_REF
   13952       557171 :           || TREE_CODE (expr) == MEMBER_REF
   13953       557171 :           || TREE_CODE (expr) == SCOPE_REF)
   13954              :         /* We're only interested in the field itself. If it is a
   13955              :            BASELINK, we will need to see through it in the next
   13956              :            step.  */
   13957            0 :         expr = TREE_OPERAND (expr, 1);
   13958              : 
   13959       557171 :       if (BASELINK_P (expr))
   13960              :         /* See through BASELINK nodes to the underlying function.  */
   13961            7 :         expr = BASELINK_FUNCTIONS (expr);
   13962              : 
   13963              :       /* decltype of a decomposition name drops references in the tuple case
   13964              :          (unlike decltype of a normal variable) and keeps cv-qualifiers from
   13965              :          the containing object in the other cases (unlike decltype of a member
   13966              :          access expression).  */
   13967       557171 :       if (DECL_DECOMPOSITION_P (expr))
   13968              :         {
   13969         1449 :           if (ptds.saved)
   13970              :             {
   13971          275 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
   13972              :                                    || (DECL_CONTEXT (expr)
   13973              :                                        != current_function_decl));
   13974              :               /* DECL_HAS_VALUE_EXPR_P is always set if
   13975              :                  processing_template_decl at least for structured bindings
   13976              :                  within the template.  If lookup_decomp_type
   13977              :                  returns non-NULL, it is the tuple case.  */
   13978          275 :               if (tree ret = lookup_decomp_type (expr))
   13979              :                 return ret;
   13980          191 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
   13981              :             }
   13982         1365 :           if (DECL_HAS_VALUE_EXPR_P (expr))
   13983              :             /* Expr is an array or struct subobject proxy, handle
   13984              :                bit-fields properly.  */
   13985         1021 :             return unlowered_expr_type (expr);
   13986              :           else
   13987              :             /* Expr is a reference variable for the tuple case.  */
   13988          344 :             return lookup_decomp_type (expr);
   13989              :         }
   13990              : 
   13991       555722 :       switch (TREE_CODE (expr))
   13992              :         {
   13993          650 :         case FIELD_DECL:
   13994          650 :           if (DECL_BIT_FIELD_TYPE (expr))
   13995              :             {
   13996              :               type = DECL_BIT_FIELD_TYPE (expr);
   13997              :               break;
   13998              :             }
   13999              :           /* Fall through for fields that aren't bitfields.  */
   14000       150190 :           gcc_fallthrough ();
   14001              : 
   14002       150190 :         case VAR_DECL:
   14003       150190 :           if (is_capture_proxy (expr))
   14004              :             {
   14005           99 :               if (is_normal_capture_proxy (expr))
   14006              :                 {
   14007           21 :                   expr = DECL_CAPTURED_VARIABLE (expr);
   14008           21 :                   type = TREE_TYPE (expr);
   14009              :                 }
   14010              :               else
   14011              :                 {
   14012           78 :                   expr = DECL_VALUE_EXPR (expr);
   14013           78 :                   gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
   14014           78 :                   expr = TREE_OPERAND (expr, 1);
   14015           78 :                   type = TREE_TYPE (expr);
   14016              :                 }
   14017              :               break;
   14018              :             }
   14019              :           /* Fall through for variables that aren't capture proxies.  */
   14020       544646 :           gcc_fallthrough ();
   14021              : 
   14022       544646 :         case FUNCTION_DECL:
   14023       544646 :         case CONST_DECL:
   14024       544646 :         case PARM_DECL:
   14025       544646 :         case RESULT_DECL:
   14026       544646 :         case TEMPLATE_PARM_INDEX:
   14027       544646 :           expr = mark_type_use (expr);
   14028       544646 :           type = TREE_TYPE (expr);
   14029       544646 :           if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
   14030              :             {
   14031              :               /* decltype of an NTTP object is the type of the template
   14032              :                  parameter, which is the object type modulo cv-quals.  */
   14033         2643 :               int quals = cp_type_quals (type);
   14034         2643 :               gcc_checking_assert (quals & TYPE_QUAL_CONST);
   14035         2643 :               type = cv_unqualified (type);
   14036              :             }
   14037              :           break;
   14038              : 
   14039            0 :         case ERROR_MARK:
   14040            0 :           type = error_mark_node;
   14041            0 :           break;
   14042              : 
   14043         3520 :         case COMPONENT_REF:
   14044         3520 :         case COMPOUND_EXPR:
   14045         3520 :           mark_type_use (expr);
   14046         3520 :           type = is_bitfield_expr_with_lowered_type (expr);
   14047         3520 :           if (!type)
   14048         3483 :             type = TREE_TYPE (TREE_OPERAND (expr, 1));
   14049              :           break;
   14050              : 
   14051            0 :         case BIT_FIELD_REF:
   14052            0 :           gcc_unreachable ();
   14053              : 
   14054         3516 :         case INTEGER_CST:
   14055         3516 :         case PTRMEM_CST:
   14056              :           /* We can get here when the id-expression refers to an
   14057              :              enumerator or non-type template parameter.  */
   14058         3516 :           type = TREE_TYPE (expr);
   14059         3516 :           break;
   14060              : 
   14061         3941 :         default:
   14062              :           /* Handle instantiated template non-type arguments.  */
   14063         3941 :           type = TREE_TYPE (expr);
   14064         3941 :           break;
   14065              :         }
   14066              :     }
   14067              :   else
   14068              :     {
   14069     35764228 :       tree decl = STRIP_REFERENCE_REF (expr);
   14070     35764228 :       tree lam = current_lambda_expr ();
   14071     35764228 :       if (lam && outer_automatic_var_p (decl))
   14072              :         {
   14073              :           /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
   14074              :              unevaluated operand within S would refer to an entity captured by
   14075              :              copy in some intervening lambda-expression, then let E be the
   14076              :              innermost such lambda-expression.
   14077              : 
   14078              :              If there is such a lambda-expression and if P is in E's function
   14079              :              parameter scope but not its parameter-declaration-clause, then the
   14080              :              type of the expression is the type of a class member access
   14081              :              expression naming the non-static data member that would be declared
   14082              :              for such a capture in the object parameter of the function call
   14083              :              operator of E."  */
   14084              :           /* FIXME: This transformation needs to happen for all uses of an outer
   14085              :              local variable inside decltype, not just decltype((x)) (PR83167).
   14086              :              And we don't handle nested lambdas properly, where we need to
   14087              :              consider the outer lambdas as well (PR112926). */
   14088         1379 :           tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
   14089              :                                   LOOK_want::HIDDEN_LAMBDA);
   14090              : 
   14091         1379 :           if (cap && is_capture_proxy (cap))
   14092          467 :             type = TREE_TYPE (cap);
   14093          912 :           else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
   14094              :             {
   14095          738 :               type = TREE_TYPE (decl);
   14096          738 :               if (TYPE_REF_P (type)
   14097          738 :                   && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
   14098           36 :                 type = TREE_TYPE (type);
   14099              :             }
   14100              : 
   14101         1205 :           if (type && !TYPE_REF_P (type))
   14102              :             {
   14103         1121 :               cv_qualifier quals;
   14104         1121 :               if (current_function_decl
   14105         2104 :                   && LAMBDA_FUNCTION_P (current_function_decl)
   14106         2104 :                   && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
   14107              :                 {
   14108          900 :                   tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
   14109          900 :                   if (WILDCARD_TYPE_P (non_reference (obtype)))
   14110              :                     /* We don't know what the eventual obtype quals will be.  */
   14111          576 :                     goto dependent;
   14112          648 :                   auto direct_type = [](tree t){
   14113          324 :                       if (INDIRECT_TYPE_P (t))
   14114          162 :                         return TREE_TYPE (t);
   14115              :                       return t;
   14116              :                    };
   14117          324 :                   quals = (cp_type_quals (type)
   14118          324 :                            | cp_type_quals (direct_type (obtype)));
   14119              :                 }
   14120              :               else
   14121              :                 /* We are in the parameter clause, trailing return type, or
   14122              :                    the requires clause and have no relevant c_f_decl yet.  */
   14123          349 :                 quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
   14124          221 :                          ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
   14125          545 :               type = cp_build_qualified_type (type, quals);
   14126          545 :               type = build_reference_type (type);
   14127              :             }
   14128              :         }
   14129     35762849 :       else if (error_operand_p (expr))
   14130            0 :         type = error_mark_node;
   14131     35762849 :       else if (expr == current_class_ptr)
   14132              :         /* If the expression is just "this", we want the
   14133              :            cv-unqualified pointer for the "this" type.  */
   14134            0 :         type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
   14135              : 
   14136          545 :       if (!type)
   14137              :         {
   14138              :           /* Otherwise, where T is the type of e, if e is an lvalue,
   14139              :              decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
   14140     35763023 :           cp_lvalue_kind clk = lvalue_kind (expr);
   14141     35763023 :           type = unlowered_expr_type (expr);
   14142     35763023 :           gcc_assert (!TYPE_REF_P (type));
   14143              : 
   14144              :           /* For vector types, pick a non-opaque variant.  */
   14145     35763023 :           if (VECTOR_TYPE_P (type))
   14146         4421 :             type = strip_typedefs (type);
   14147              : 
   14148     35763023 :           if (clk != clk_none && !(clk & clk_class))
   14149      8995195 :             type = cp_build_reference_type (type, (clk & clk_rvalueref));
   14150              :         }
   14151              :     }
   14152              : 
   14153              :   return type;
   14154     43654771 : }
   14155              : 
   14156              : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
   14157              :    __has_nothrow_copy, depending on assign_p.  Returns true iff all
   14158              :    the copy {ctor,assign} fns are nothrow.  */
   14159              : 
   14160              : static bool
   14161          351 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
   14162              : {
   14163          351 :   tree fns = NULL_TREE;
   14164              : 
   14165          351 :   if (assign_p || TYPE_HAS_COPY_CTOR (type))
   14166          348 :     fns = get_class_binding (type, assign_p ? assign_op_identifier
   14167              :                              : ctor_identifier);
   14168              : 
   14169          351 :   bool saw_copy = false;
   14170          894 :   for (ovl_iterator iter (fns); iter; ++iter)
   14171              :     {
   14172          561 :       tree fn = *iter;
   14173              : 
   14174          561 :       if (copy_fn_p (fn) > 0)
   14175              :         {
   14176          525 :           saw_copy = true;
   14177          525 :           if (!maybe_instantiate_noexcept (fn)
   14178          525 :               || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
   14179          234 :             return false;
   14180              :         }
   14181              :     }
   14182              : 
   14183          117 :   return saw_copy;
   14184              : }
   14185              : 
   14186              : /* Return true if BASE is a pointer-interconvertible base of DERIVED.  */
   14187              : 
   14188              : bool
   14189          183 : pointer_interconvertible_base_of_p (tree base, tree derived,
   14190              :                                     bool explain/*=false*/)
   14191              : {
   14192          183 :   if (base == error_mark_node || derived == error_mark_node)
   14193              :     return false;
   14194              : 
   14195          183 :   base = TYPE_MAIN_VARIANT (base);
   14196          183 :   derived = TYPE_MAIN_VARIANT (derived);
   14197          183 :   if (!NON_UNION_CLASS_TYPE_P (base))
   14198              :     {
   14199           17 :       if (explain)
   14200            3 :         inform (location_of (base),
   14201              :                 "%qT is not a non-union class type", base);
   14202              :       return false;
   14203              :     }
   14204          166 :   if (!NON_UNION_CLASS_TYPE_P (derived))
   14205              :     {
   14206            8 :       if (explain)
   14207            3 :         inform (location_of (derived),
   14208              :                 "%qT is not a non-union class type", derived);
   14209              :       return false;
   14210              :     }
   14211              : 
   14212          158 :   if (same_type_p (base, derived))
   14213              :     return true;
   14214              : 
   14215          117 :   if (!std_layout_type_p (derived))
   14216              :     {
   14217           18 :       if (explain)
   14218            6 :         inform (location_of (derived),
   14219              :                 "%qT is not a standard-layout type", derived);
   14220              :       return false;
   14221              :     }
   14222              : 
   14223           99 :   if (!uniquely_derived_from_p (base, derived))
   14224              :     {
   14225           18 :       if (explain)
   14226              :         {
   14227              :           /* An ambiguous base should already be impossible due to
   14228              :              the std_layout_type_p check.  */
   14229            3 :           gcc_checking_assert (!DERIVED_FROM_P (base, derived));
   14230            3 :           inform (location_of (derived),
   14231              :                   "%qT is not a base of %qT", base, derived);
   14232              :         }
   14233              :       return false;
   14234              :     }
   14235              : 
   14236              :   return true;
   14237              : }
   14238              : 
   14239              : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
   14240              :    return true if MEMBERTYPE is the type of the first non-static data member
   14241              :    of TYPE or for unions of any members.  */
   14242              : static bool
   14243          637 : first_nonstatic_data_member_p (tree type, tree membertype)
   14244              : {
   14245         1297 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   14246              :     {
   14247         1222 :       if (TREE_CODE (field) != FIELD_DECL)
   14248          135 :         continue;
   14249         1087 :       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
   14250           60 :         continue;
   14251         1027 :       if (DECL_FIELD_IS_BASE (field))
   14252           45 :         return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
   14253          982 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   14254              :         {
   14255          216 :           if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
   14256          138 :                || std_layout_type_p (TREE_TYPE (field)))
   14257          294 :               && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
   14258              :             return true;
   14259              :         }
   14260          766 :       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   14261              :                                                           membertype))
   14262              :         return true;
   14263          537 :       if (TREE_CODE (type) != UNION_TYPE)
   14264              :         return false;
   14265              :     }
   14266              :   return false;
   14267              : }
   14268              : 
   14269              : /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
   14270              : 
   14271              : tree
   14272          536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
   14273              :                                                      tree *args)
   14274              : {
   14275              :   /* Unless users call the builtin directly, the following 3 checks should be
   14276              :      ensured from std::is_pointer_interconvertible_with_class function
   14277              :      template.  */
   14278          536 :   if (nargs != 1)
   14279              :     {
   14280            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   14281              :                      "needs a single argument");
   14282            6 :       return boolean_false_node;
   14283              :     }
   14284          530 :   tree arg = args[0];
   14285          530 :   if (error_operand_p (arg))
   14286            0 :     return boolean_false_node;
   14287          530 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
   14288              :     {
   14289            6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   14290              :                      "argument is not pointer to member");
   14291            6 :       return boolean_false_node;
   14292              :     }
   14293              : 
   14294          524 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
   14295           18 :     return boolean_false_node;
   14296              : 
   14297          506 :   tree membertype = TREE_TYPE (TREE_TYPE (arg));
   14298          506 :   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
   14299          506 :   if (!complete_type_or_else (basetype, NULL_TREE))
   14300            3 :     return boolean_false_node;
   14301              : 
   14302          503 :   if (TREE_CODE (basetype) != UNION_TYPE
   14303          503 :       && !std_layout_type_p (basetype))
   14304           22 :     return boolean_false_node;
   14305              : 
   14306          481 :   if (!first_nonstatic_data_member_p (basetype, membertype))
   14307          132 :     return boolean_false_node;
   14308              : 
   14309          349 :   if (TREE_CODE (arg) == PTRMEM_CST)
   14310           68 :     arg = cplus_expand_constant (arg);
   14311              : 
   14312          349 :   if (integer_nonzerop (arg))
   14313           10 :     return boolean_false_node;
   14314          339 :   if (integer_zerop (arg))
   14315           71 :     return boolean_true_node;
   14316              : 
   14317          268 :   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
   14318              :                       build_zero_cst (TREE_TYPE (arg)));
   14319              : }
   14320              : 
   14321              : /* Helper function for is_corresponding_member_aggr.  Return true if
   14322              :    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
   14323              :    union or structure BASETYPE.  */
   14324              : 
   14325              : static bool
   14326           90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
   14327              : {
   14328          222 :   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
   14329          192 :     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
   14330           36 :       continue;
   14331          156 :     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   14332              :                                                         membertype))
   14333              :       {
   14334           48 :         if (TREE_CODE (arg) != INTEGER_CST
   14335           48 :             || tree_int_cst_equal (arg, byte_position (field)))
   14336              :           return true;
   14337              :       }
   14338          108 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   14339              :       {
   14340           18 :         tree narg = arg;
   14341           18 :         if (TREE_CODE (basetype) != UNION_TYPE
   14342            0 :             && TREE_CODE (narg) == INTEGER_CST)
   14343            0 :           narg = size_binop (MINUS_EXPR, arg, byte_position (field));
   14344           18 :         if (is_corresponding_member_union (TREE_TYPE (field),
   14345              :                                            membertype, narg))
   14346              :           return true;
   14347              :       }
   14348              :   return false;
   14349              : }
   14350              : 
   14351              : /* Helper function for fold_builtin_is_corresponding_member call.
   14352              :    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
   14353              :    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
   14354              :    boolean_true_node if they are corresponding members, or for
   14355              :    non-constant ARG2 the highest member offset for corresponding
   14356              :    members.  */
   14357              : 
   14358              : static tree
   14359          550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
   14360              :                               tree arg1, tree basetype2, tree membertype2,
   14361              :                               tree arg2)
   14362              : {
   14363          550 :   tree field1 = TYPE_FIELDS (basetype1);
   14364          550 :   tree field2 = TYPE_FIELDS (basetype2);
   14365          550 :   tree ret = boolean_false_node;
   14366         2376 :   while (1)
   14367              :     {
   14368         1463 :       bool r = next_common_initial_sequence (field1, field2);
   14369         1463 :       if (field1 == NULL_TREE || field2 == NULL_TREE)
   14370              :         break;
   14371         1331 :       if (r
   14372         1038 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
   14373              :                                                         membertype1)
   14374         1841 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
   14375              :                                                         membertype2))
   14376              :         {
   14377          504 :           tree pos = byte_position (field1);
   14378          504 :           if (TREE_CODE (arg1) == INTEGER_CST
   14379          504 :               && tree_int_cst_equal (arg1, pos))
   14380              :             {
   14381           92 :               if (TREE_CODE (arg2) == INTEGER_CST)
   14382           92 :                 return boolean_true_node;
   14383              :               return pos;
   14384              :             }
   14385          412 :           else if (TREE_CODE (arg1) != INTEGER_CST)
   14386         1188 :             ret = pos;
   14387              :         }
   14388         1654 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
   14389          944 :                && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
   14390              :         {
   14391          117 :           if ((!lookup_attribute ("no_unique_address",
   14392          117 :                                   DECL_ATTRIBUTES (field1)))
   14393          117 :               != !lookup_attribute ("no_unique_address",
   14394          117 :                                     DECL_ATTRIBUTES (field2)))
   14395              :             break;
   14396          117 :           if (!tree_int_cst_equal (bit_position (field1),
   14397          117 :                                    bit_position (field2)))
   14398              :             break;
   14399           99 :           bool overlap = true;
   14400           99 :           tree pos = byte_position (field1);
   14401           99 :           if (TREE_CODE (arg1) == INTEGER_CST)
   14402              :             {
   14403           27 :               tree off1 = fold_convert (sizetype, arg1);
   14404           27 :               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
   14405           27 :               if (tree_int_cst_lt (off1, pos)
   14406           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
   14407              :                 overlap = false;
   14408              :             }
   14409           99 :           if (TREE_CODE (arg2) == INTEGER_CST)
   14410              :             {
   14411           27 :               tree off2 = fold_convert (sizetype, arg2);
   14412           27 :               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
   14413           27 :               if (tree_int_cst_lt (off2, pos)
   14414           27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
   14415              :                 overlap = false;
   14416              :             }
   14417           87 :           if (overlap
   14418           87 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
   14419          126 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
   14420              :             {
   14421           39 :               tree narg1 = arg1;
   14422           39 :               if (TREE_CODE (arg1) == INTEGER_CST)
   14423            9 :                 narg1 = size_binop (MINUS_EXPR,
   14424              :                                     fold_convert (sizetype, arg1), pos);
   14425           39 :               tree narg2 = arg2;
   14426           39 :               if (TREE_CODE (arg2) == INTEGER_CST)
   14427            9 :                 narg2 = size_binop (MINUS_EXPR,
   14428              :                                     fold_convert (sizetype, arg2), pos);
   14429           39 :               tree t1 = TREE_TYPE (field1);
   14430           39 :               tree t2 = TREE_TYPE (field2);
   14431           39 :               tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
   14432              :                                                         narg1, t2, membertype2,
   14433              :                                                         narg2);
   14434           39 :               if (nret != boolean_false_node)
   14435              :                 {
   14436           39 :                   if (nret == boolean_true_node)
   14437              :                     return nret;
   14438           30 :                   if (TREE_CODE (arg1) == INTEGER_CST)
   14439            0 :                     return size_binop (PLUS_EXPR, nret, pos);
   14440           30 :                   ret = size_binop (PLUS_EXPR, nret, pos);
   14441              :                 }
   14442              :             }
   14443           60 :           else if (overlap
   14444           48 :                    && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
   14445          108 :                    && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
   14446              :             {
   14447           48 :               tree narg1 = arg1;
   14448           48 :               if (TREE_CODE (arg1) == INTEGER_CST)
   14449            6 :                 narg1 = size_binop (MINUS_EXPR,
   14450              :                                     fold_convert (sizetype, arg1), pos);
   14451           48 :               tree narg2 = arg2;
   14452           48 :               if (TREE_CODE (arg2) == INTEGER_CST)
   14453            6 :                 narg2 = size_binop (MINUS_EXPR,
   14454              :                                     fold_convert (sizetype, arg2), pos);
   14455           48 :               if (is_corresponding_member_union (TREE_TYPE (field1),
   14456              :                                                  membertype1, narg1)
   14457           48 :                   && is_corresponding_member_union (TREE_TYPE (field2),
   14458              :                                                     membertype2, narg2))
   14459              :                 {
   14460           24 :                   sorry_at (loc, "%<__builtin_is_corresponding_member%> "
   14461              :                                  "not well defined for anonymous unions");
   14462           24 :                   return boolean_false_node;
   14463              :                 }
   14464              :             }
   14465              :         }
   14466         1188 :       if (!r)
   14467              :         break;
   14468          913 :       field1 = DECL_CHAIN (field1);
   14469          913 :       field2 = DECL_CHAIN (field2);
   14470          913 :     }
   14471              :   return ret;
   14472              : }
   14473              : 
   14474              : /* Fold __builtin_is_corresponding_member call.  */
   14475              : 
   14476              : tree
   14477          699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
   14478              :                                       tree *args)
   14479              : {
   14480              :   /* Unless users call the builtin directly, the following 3 checks should be
   14481              :      ensured from std::is_corresponding_member function template.  */
   14482          699 :   if (nargs != 2)
   14483              :     {
   14484            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   14485              :                      "needs two arguments");
   14486            9 :       return boolean_false_node;
   14487              :     }
   14488          690 :   tree arg1 = args[0];
   14489          690 :   tree arg2 = args[1];
   14490          690 :   if (error_operand_p (arg1) || error_operand_p (arg2))
   14491            0 :     return boolean_false_node;
   14492          711 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
   14493          705 :       || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
   14494              :     {
   14495            9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   14496              :                      "argument is not pointer to member");
   14497            9 :       return boolean_false_node;
   14498              :     }
   14499              : 
   14500          681 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
   14501          681 :       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
   14502           15 :     return boolean_false_node;
   14503              : 
   14504          666 :   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
   14505          666 :   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
   14506          666 :   if (!complete_type_or_else (basetype1, NULL_TREE))
   14507           12 :     return boolean_false_node;
   14508              : 
   14509          654 :   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
   14510          654 :   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
   14511          654 :   if (!complete_type_or_else (basetype2, NULL_TREE))
   14512           12 :     return boolean_false_node;
   14513              : 
   14514          627 :   if (!NON_UNION_CLASS_TYPE_P (basetype1)
   14515          627 :       || !NON_UNION_CLASS_TYPE_P (basetype2)
   14516          627 :       || !std_layout_type_p (basetype1)
   14517         1233 :       || !std_layout_type_p (basetype2))
   14518           51 :     return boolean_false_node;
   14519              : 
   14520              :   /* If the member types aren't layout compatible, then they
   14521              :      can't be corresponding members.  */
   14522          591 :   if (!layout_compatible_type_p (membertype1, membertype2))
   14523           18 :     return boolean_false_node;
   14524              : 
   14525          573 :   if (TREE_CODE (arg1) == PTRMEM_CST)
   14526          176 :     arg1 = cplus_expand_constant (arg1);
   14527          573 :   if (TREE_CODE (arg2) == PTRMEM_CST)
   14528          182 :     arg2 = cplus_expand_constant (arg2);
   14529              : 
   14530          573 :   if (null_member_pointer_value_p (arg1)
   14531          573 :       || null_member_pointer_value_p (arg2))
   14532            9 :     return boolean_false_node;
   14533              : 
   14534          564 :   if (TREE_CODE (arg1) == INTEGER_CST
   14535          182 :       && TREE_CODE (arg2) == INTEGER_CST
   14536          746 :       && !tree_int_cst_equal (arg1, arg2))
   14537           53 :     return boolean_false_node;
   14538              : 
   14539          511 :   if (TREE_CODE (arg2) == INTEGER_CST
   14540          129 :       && TREE_CODE (arg1) != INTEGER_CST)
   14541              :     {
   14542              :       std::swap (arg1, arg2);
   14543              :       std::swap (membertype1, membertype2);
   14544              :       std::swap (basetype1, basetype2);
   14545              :     }
   14546              : 
   14547          511 :   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
   14548              :                                            basetype2, membertype2, arg2);
   14549          511 :   if (TREE_TYPE (ret) == boolean_type_node)
   14550              :     return ret;
   14551              :   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
   14552              :      already returns boolean_{true,false}_node whether those particular
   14553              :      members are corresponding members or not.  Otherwise, if only
   14554              :      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
   14555              :      above), it returns boolean_false_node if it is certainly not a
   14556              :      corresponding member and otherwise we need to do a runtime check that
   14557              :      those two OFFSET_TYPE offsets are equal.
   14558              :      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
   14559              :      returns the largest offset at which the members would be corresponding
   14560              :      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
   14561          304 :   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
   14562          304 :   if (TREE_CODE (arg1) == INTEGER_CST)
   14563            0 :     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   14564              :                         fold_convert (TREE_TYPE (arg1), arg2));
   14565          304 :   ret = fold_build2 (LE_EXPR, boolean_type_node,
   14566              :                      fold_convert (pointer_sized_int_node, arg1),
   14567              :                      fold_convert (pointer_sized_int_node, ret));
   14568          304 :   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
   14569              :                       fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   14570              :                                    fold_convert (TREE_TYPE (arg1), arg2)));
   14571              : }
   14572              : 
   14573              : /* Fold __builtin_is_string_literal call.  */
   14574              : 
   14575              : tree
   14576         4381 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
   14577              : {
   14578              :   /* Unless users call the builtin directly, the following 3 checks should be
   14579              :      ensured from std::is_string_literal overloads.  */
   14580         4381 :   if (nargs != 1)
   14581              :     {
   14582            0 :       error_at (loc, "%<__builtin_is_string_literal%> needs a single "
   14583              :                 "argument");
   14584            0 :       return boolean_false_node;
   14585              :     }
   14586         4381 :   tree arg = args[0];
   14587         4381 :   if (error_operand_p (arg))
   14588            0 :     return boolean_false_node;
   14589         4381 :   if (!TYPE_PTR_P (TREE_TYPE (arg))
   14590         4381 :       || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
   14591         8762 :       || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
   14592              :     {
   14593            0 :     arg_invalid:
   14594            0 :       error_at (loc, "%<__builtin_is_string_literal%> "
   14595              :                      "argument is not %<const char*%>, %<const wchar_t*%>, "
   14596              :                      "%<const char8_t*%>, %<const char16_t*%> or "
   14597              :                      "%<const char32_t*%>");
   14598            0 :       return boolean_false_node;
   14599              :     }
   14600         4381 :   tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
   14601         4381 :   if (chart != char_type_node
   14602         3500 :       && chart != wchar_type_node
   14603         2625 :       && chart != char8_type_node
   14604         1750 :       && chart != char16_type_node
   14605          875 :       && chart != char32_type_node)
   14606            0 :     goto arg_invalid;
   14607              : 
   14608         4381 :   STRIP_NOPS (arg);
   14609         8774 :   while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
   14610              :     {
   14611           12 :       arg = TREE_OPERAND (arg, 0);
   14612           12 :       STRIP_NOPS (arg);
   14613              :     }
   14614         4381 :   if (TREE_CODE (arg) != ADDR_EXPR)
   14615         4325 :     return boolean_false_node;
   14616           56 :   arg = TREE_OPERAND (arg, 0);
   14617           56 :   if (TREE_CODE (arg) == ARRAY_REF)
   14618           24 :     arg = TREE_OPERAND (arg, 0);
   14619           56 :   if (TREE_CODE (arg) != STRING_CST)
   14620           16 :     return boolean_false_node;
   14621           40 :   return boolean_true_node;
   14622              : }
   14623              : 
   14624              : /* [basic.types] 8.  True iff TYPE is an object type.  */
   14625              : 
   14626              : static bool
   14627      2935113 : object_type_p (const_tree type)
   14628              : {
   14629      2935113 :   return (TREE_CODE (type) != FUNCTION_TYPE
   14630            0 :           && !TYPE_REF_P (type)
   14631      2935113 :           && !VOID_TYPE_P (type));
   14632              : }
   14633              : 
   14634              : /* [defns.referenceable] True iff TYPE is a referenceable type.  */
   14635              : 
   14636              : static bool
   14637      3579421 : referenceable_type_p (const_tree type)
   14638              : {
   14639      3579421 :   return (TYPE_REF_P (type)
   14640      3579877 :           || object_type_p (type)
   14641      3579877 :           || (FUNC_OR_METHOD_TYPE_P (type)
   14642          385 :               && type_memfn_quals (type) == TYPE_UNQUALIFIED
   14643          319 :               && type_memfn_rqual (type) == REF_QUAL_NONE));
   14644              : }
   14645              : 
   14646              : /* Actually evaluates the trait.  */
   14647              : 
   14648              : static bool
   14649     18116534 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
   14650              : {
   14651     18116534 :   enum tree_code type_code1;
   14652     18116534 :   tree t;
   14653              : 
   14654     18116534 :   type_code1 = TREE_CODE (type1);
   14655              : 
   14656     18116534 :   switch (kind)
   14657              :     {
   14658          377 :     case CPTK_HAS_NOTHROW_ASSIGN:
   14659          377 :       type1 = strip_array_types (type1);
   14660          377 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14661          715 :               && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
   14662          206 :                   || (CLASS_TYPE_P (type1)
   14663          156 :                       && classtype_has_nothrow_assign_or_copy_p (type1,
   14664              :                                                                  true))));
   14665              : 
   14666          254 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   14667          254 :       type1 = strip_array_types (type1);
   14668          254 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
   14669          254 :               || (CLASS_TYPE_P (type1)
   14670          111 :                   && (t = locate_ctor (type1))
   14671           72 :                   && maybe_instantiate_noexcept (t)
   14672           70 :                   && TYPE_NOTHROW_P (TREE_TYPE (t))));
   14673              : 
   14674          380 :     case CPTK_HAS_NOTHROW_COPY:
   14675          380 :       type1 = strip_array_types (type1);
   14676          380 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
   14677          380 :               || (CLASS_TYPE_P (type1)
   14678          195 :                   && classtype_has_nothrow_assign_or_copy_p (type1, false)));
   14679              : 
   14680          613 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   14681              :       /* ??? The standard seems to be missing the "or array of such a class
   14682              :          type" wording for this trait.  */
   14683          613 :       type1 = strip_array_types (type1);
   14684          613 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   14685         1187 :               && (trivial_type_p (type1)
   14686          364 :                     || (CLASS_TYPE_P (type1)
   14687          267 :                         && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
   14688              : 
   14689          617 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   14690          617 :       type1 = strip_array_types (type1);
   14691          617 :       return (trivial_type_p (type1)
   14692          617 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
   14693              : 
   14694          640 :     case CPTK_HAS_TRIVIAL_COPY:
   14695              :       /* ??? The standard seems to be missing the "or array of such a class
   14696              :          type" wording for this trait.  */
   14697          640 :       type1 = strip_array_types (type1);
   14698         1073 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14699         1055 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
   14700              : 
   14701          809 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   14702          809 :       type1 = strip_array_types (type1);
   14703          809 :       if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
   14704              :         {
   14705          129 :           deferring_access_check_sentinel dacs (dk_no_check);
   14706          129 :           cp_unevaluated un;
   14707          129 :           tree fn = get_dtor (type1, tf_none);
   14708          129 :           if (!fn && !seen_error ())
   14709            3 :             warning (0, "checking %qs for type %qT with a destructor that "
   14710              :                      "cannot be called", "__has_trivial_destructor", type1);
   14711          129 :         }
   14712         1161 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   14713         1158 :               || (CLASS_TYPE_P (type1)
   14714          299 :                   && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
   14715              : 
   14716        61213 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   14717        61213 :       return type_has_unique_obj_representations (type1);
   14718              : 
   14719          338 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   14720          338 :       return type_has_virtual_destructor (type1);
   14721              : 
   14722        56376 :     case CPTK_IS_ABSTRACT:
   14723        56376 :       return ABSTRACT_CLASS_TYPE_P (type1);
   14724              : 
   14725         1162 :     case CPTK_IS_AGGREGATE:
   14726         1162 :       return CP_AGGREGATE_TYPE_P (type1);
   14727              : 
   14728       373305 :     case CPTK_IS_ARRAY:
   14729       373305 :       return (type_code1 == ARRAY_TYPE
   14730              :               /* We don't want to report T[0] as being an array type.
   14731              :                  This is for compatibility with an implementation of
   14732              :                  std::is_array by template argument deduction, because
   14733              :                  compute_array_index_type_loc rejects a zero-size array
   14734              :                  in SFINAE context.  */
   14735       373305 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14736              : 
   14737      1030891 :     case CPTK_IS_ASSIGNABLE:
   14738      1030891 :       return is_xible (MODIFY_EXPR, type1, type2);
   14739              : 
   14740       518433 :     case CPTK_IS_BASE_OF:
   14741       518330 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14742      1018009 :               && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
   14743       471447 :                   || DERIVED_FROM_P (type1, type2)));
   14744              : 
   14745        58508 :     case CPTK_IS_BOUNDED_ARRAY:
   14746        58508 :       return (type_code1 == ARRAY_TYPE
   14747         1668 :               && TYPE_DOMAIN (type1)
   14748              :               /* We don't want to report T[0] as being a bounded array type.
   14749              :                  This is for compatibility with an implementation of
   14750              :                  std::is_bounded_array by template argument deduction, because
   14751              :                  compute_array_index_type_loc rejects a zero-size array
   14752              :                  in SFINAE context.  */
   14753        60048 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   14754              : 
   14755       540618 :     case CPTK_IS_CLASS:
   14756       540618 :       return NON_UNION_CLASS_TYPE_P (type1);
   14757              : 
   14758       590667 :     case CPTK_IS_CONST:
   14759       590667 :       return CP_TYPE_CONST_P (type1);
   14760              : 
   14761      2399316 :     case CPTK_IS_CONSTRUCTIBLE:
   14762      2399316 :       return is_xible (INIT_EXPR, type1, type2);
   14763              : 
   14764      3172772 :     case CPTK_IS_CONVERTIBLE:
   14765      3172772 :       return is_convertible (type1, type2);
   14766              : 
   14767         3390 :     case CPTK_IS_DESTRUCTIBLE:
   14768         3390 :       return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14769              : 
   14770       220423 :     case CPTK_IS_EMPTY:
   14771       220423 :       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
   14772              : 
   14773       667673 :     case CPTK_IS_ENUM:
   14774       667673 :       return type_code1 == ENUMERAL_TYPE;
   14775              : 
   14776       435472 :     case CPTK_IS_FINAL:
   14777       435472 :       return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
   14778              : 
   14779        47948 :     case CPTK_IS_FUNCTION:
   14780        47948 :       return type_code1 == FUNCTION_TYPE;
   14781              : 
   14782         1403 :     case CPTK_IS_IMPLICIT_LIFETIME:
   14783         1403 :       return implicit_lifetime_type_p (type1);
   14784              : 
   14785        49386 :     case CPTK_IS_INVOCABLE:
   14786        49386 :       return !error_operand_p (build_invoke (type1, type2, tf_none));
   14787              : 
   14788          221 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   14789          221 :       return layout_compatible_type_p (type1, type2);
   14790              : 
   14791          197 :     case CPTK_IS_LITERAL_TYPE:
   14792          197 :       return literal_type_p (type1);
   14793              : 
   14794        48928 :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   14795        48928 :       return TYPE_PTRMEMFUNC_P (type1);
   14796              : 
   14797        48915 :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   14798        48915 :       return TYPE_PTRDATAMEM_P (type1);
   14799              : 
   14800        10946 :     case CPTK_IS_MEMBER_POINTER:
   14801        10946 :       return TYPE_PTRMEM_P (type1);
   14802              : 
   14803       462945 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   14804       462945 :       return is_nothrow_xible (MODIFY_EXPR, type1, type2);
   14805              : 
   14806       931105 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14807       931105 :       return is_nothrow_xible (INIT_EXPR, type1, type2);
   14808              : 
   14809          683 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14810          683 :       return is_nothrow_convertible (type1, type2);
   14811              : 
   14812        23995 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   14813        23995 :       return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14814              : 
   14815        44344 :     case CPTK_IS_NOTHROW_INVOCABLE:
   14816        44344 :       return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
   14817              : 
   14818      1132311 :     case CPTK_IS_OBJECT:
   14819      1132311 :       return object_type_p (type1);
   14820              : 
   14821          168 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   14822          168 :       return pointer_interconvertible_base_of_p (type1, type2);
   14823              : 
   14824        11467 :     case CPTK_IS_POD:
   14825        11467 :       return pod_type_p (type1);
   14826              : 
   14827       152219 :     case CPTK_IS_POINTER:
   14828       152219 :       return TYPE_PTR_P (type1);
   14829              : 
   14830          313 :     case CPTK_IS_POLYMORPHIC:
   14831          313 :       return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
   14832              : 
   14833       719103 :     case CPTK_IS_REFERENCE:
   14834       719103 :       return type_code1 == REFERENCE_TYPE;
   14835              : 
   14836      2679878 :     case CPTK_IS_SAME:
   14837      2679878 :       return same_type_p (type1, type2);
   14838              : 
   14839          373 :     case CPTK_IS_SCOPED_ENUM:
   14840          373 :       return SCOPED_ENUM_P (type1);
   14841              : 
   14842        62539 :     case CPTK_IS_STD_LAYOUT:
   14843        62539 :       return std_layout_type_p (type1);
   14844              : 
   14845        58097 :     case CPTK_IS_TRIVIAL:
   14846        58097 :       return trivial_type_p (type1);
   14847              : 
   14848        12912 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   14849        12912 :       return is_trivially_xible (MODIFY_EXPR, type1, type2);
   14850              : 
   14851        74755 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14852        74755 :       return is_trivially_xible (INIT_EXPR, type1, type2);
   14853              : 
   14854       118308 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   14855       118308 :       return trivially_copyable_p (type1);
   14856              : 
   14857        27340 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   14858        27340 :       return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   14859              : 
   14860        97374 :     case CPTK_IS_UNBOUNDED_ARRAY:
   14861        97374 :       return array_of_unknown_bound_p (type1);
   14862              : 
   14863       272118 :     case CPTK_IS_UNION:
   14864       272118 :       return type_code1 == UNION_TYPE;
   14865              : 
   14866          883 :     case CPTK_IS_VIRTUAL_BASE_OF:
   14867          803 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   14868         1664 :               && lookup_base (type2, type1, ba_require_virtual,
   14869              :                               NULL, tf_none) != NULL_TREE);
   14870              : 
   14871       614870 :     case CPTK_IS_VOLATILE:
   14872       614870 :       return CP_TYPE_VOLATILE_P (type1);
   14873              : 
   14874       221603 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14875       221603 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
   14876              : 
   14877        54225 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14878        54225 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
   14879              : 
   14880           85 :     case CPTK_IS_DEDUCIBLE:
   14881           85 :       return type_targs_deducible_from (type1, type2);
   14882              : 
   14883          330 :     case CPTK_IS_STRUCTURAL:
   14884          330 :       return structural_type_p (type1);
   14885              : 
   14886              :     /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
   14887              :        are handled in finish_trait_expr.  */
   14888            0 :     case CPTK_RANK:
   14889            0 :     case CPTK_TYPE_ORDER:
   14890            0 :     case CPTK_STRUCTURED_BINDING_SIZE:
   14891            0 :       gcc_unreachable ();
   14892              : 
   14893              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14894              :     case CPTK_##CODE:
   14895              : #include "cp-trait.def"
   14896              : #undef DEFTRAIT_TYPE
   14897              :       /* Type-yielding traits are handled in finish_trait_type.  */
   14898              :       break;
   14899              :     }
   14900              : 
   14901            0 :   gcc_unreachable ();
   14902              : }
   14903              : 
   14904              : /* Returns true if TYPE meets the requirements for the specified KIND,
   14905              :    false otherwise.
   14906              : 
   14907              :    When KIND == 1, TYPE must be an array of unknown bound,
   14908              :    or (possibly cv-qualified) void, or a complete type.
   14909              : 
   14910              :    When KIND == 2, TYPE must be a complete type, or array of complete type,
   14911              :    or (possibly cv-qualified) void.
   14912              : 
   14913              :    When KIND == 3:
   14914              :    If TYPE is a non-union class type, it must be complete.
   14915              : 
   14916              :    When KIND == 4:
   14917              :    If TYPE is a class type, it must be complete.
   14918              : 
   14919              :    If COMPLAIN is not tf_none, we permerror and return false if that doesn't
   14920              :    produce a hard error.  */
   14921              : 
   14922              : static bool
   14923     19049760 : check_trait_type (tree type, int kind, tsubst_flags_t complain)
   14924              : {
   14925     19049760 :   if (type == NULL_TREE)
   14926              :     return true;
   14927              : 
   14928     19049760 :   if (TREE_CODE (type) == TREE_VEC)
   14929              :     {
   14930      6223037 :       for (tree arg : tree_vec_range (type))
   14931      2728671 :         if (!check_trait_type (arg, kind, complain))
   14932          123 :           return false;
   14933      3494366 :       return true;
   14934              :     }
   14935              : 
   14936     15555271 :   if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   14937              :     return true; // Array of unknown bound. Don't care about completeness.
   14938              : 
   14939     15554380 :   if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
   14940              :     return true; // Not a non-union class type. Don't care about completeness.
   14941              : 
   14942     15439398 :   if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
   14943              :     return true; // Not a class type. Don't care about completeness.
   14944              : 
   14945     15438456 :   if (VOID_TYPE_P (type))
   14946              :     return true;
   14947              : 
   14948     15436785 :   type = complete_type (strip_array_types (type));
   14949     15436785 :   if (!COMPLETE_TYPE_P (type)
   14950              :       /* If we're not emitting error messages, always return false for
   14951              :          incomplete types.  */
   14952     15436785 :       && (complain == tf_none
   14953          184 :           || (cxx_incomplete_type_diagnostic (NULL_TREE, type,
   14954              :                                               diagnostics::kind::permerror)
   14955          184 :               && !flag_permissive)))
   14956          889 :     return false;
   14957              :   return true;
   14958              : }
   14959              : 
   14960              : /* True iff the conversion (if any) would be a direct reference
   14961              :    binding, not requiring complete types.  This is LWG2939.  */
   14962              : 
   14963              : static bool
   14964      6672879 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
   14965              : {
   14966      6672879 :   tree from, to;
   14967      6672879 :   switch (kind)
   14968              :     {
   14969              :       /* These put the target type first.  */
   14970              :     case CPTK_IS_CONSTRUCTIBLE:
   14971              :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   14972              :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   14973              :     case CPTK_IS_INVOCABLE:
   14974              :     case CPTK_IS_NOTHROW_INVOCABLE:
   14975              :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   14976              :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   14977              :       to = type1;
   14978              :       from = type2;
   14979              :       break;
   14980              : 
   14981              :       /* These put it second.  */
   14982      3173527 :     case CPTK_IS_CONVERTIBLE:
   14983      3173527 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   14984      3173527 :       to = type2;
   14985      3173527 :       from = type1;
   14986      3173527 :       break;
   14987              : 
   14988            0 :     default:
   14989            0 :       gcc_unreachable ();
   14990              :     }
   14991              : 
   14992      6672879 :   if (TREE_CODE (to) != REFERENCE_TYPE || !from)
   14993              :     return false;
   14994       906537 :   if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
   14995        62263 :     from = TREE_VEC_ELT (from, 0);
   14996       906537 :   return (TYPE_P (from)
   14997      1802821 :           && (same_type_ignoring_top_level_qualifiers_p
   14998       896284 :               (non_reference (to), non_reference (from))));
   14999              : }
   15000              : 
   15001              : /* Helper for finish_trait_expr and tsubst_expr.  Handle
   15002              :    CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
   15003              :    way.  */
   15004              : 
   15005              : tree
   15006          276 : finish_structured_binding_size (location_t loc, tree type,
   15007              :                                 tsubst_flags_t complain)
   15008              : {
   15009          276 :   if (TYPE_REF_P (type))
   15010              :     {
   15011          105 :       if (complain & tf_error)
   15012           99 :         error_at (loc, "%qs argument %qT is a reference",
   15013              :                   "__builtin_structured_binding_size", type);
   15014          105 :       return error_mark_node;
   15015              :     }
   15016          171 :   HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
   15017          171 :   if (ret == -1)
   15018           60 :     return error_mark_node;
   15019          111 :   return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
   15020              : }
   15021              : 
   15022              : /* Process a trait expression.  */
   15023              : 
   15024              : tree
   15025     21555577 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2,
   15026              :                    tsubst_flags_t complain/*=tf_warning_or_error*/)
   15027              : {
   15028     21555577 :   if (type1 == error_mark_node
   15029     21555574 :       || type2 == error_mark_node)
   15030              :     return error_mark_node;
   15031              : 
   15032     21555574 :   if (processing_template_decl)
   15033              :     {
   15034      3438270 :       tree trait_expr = make_node (TRAIT_EXPR);
   15035      3438270 :       if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
   15036        31425 :         TREE_TYPE (trait_expr) = size_type_node;
   15037      3406845 :       else if (kind == CPTK_TYPE_ORDER)
   15038              :         {
   15039         4665 :           tree val = type_order_value (type1, type1);
   15040         4665 :           if (val != error_mark_node)
   15041         4665 :             TREE_TYPE (trait_expr) = TREE_TYPE (val);
   15042              :         }
   15043              :       else
   15044      3402180 :         TREE_TYPE (trait_expr) = boolean_type_node;
   15045      3438270 :       TRAIT_EXPR_TYPE1 (trait_expr) = type1;
   15046      3438270 :       TRAIT_EXPR_TYPE2 (trait_expr) = type2;
   15047      3438270 :       TRAIT_EXPR_KIND (trait_expr) = kind;
   15048      3438270 :       TRAIT_EXPR_LOCATION (trait_expr) = loc;
   15049      3438270 :       return trait_expr;
   15050              :     }
   15051              : 
   15052     18117304 :   switch (kind)
   15053              :     {
   15054        57500 :     case CPTK_HAS_NOTHROW_ASSIGN:
   15055        57500 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   15056        57500 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   15057        57500 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   15058        57500 :     case CPTK_HAS_NOTHROW_COPY:
   15059        57500 :     case CPTK_HAS_TRIVIAL_COPY:
   15060        57500 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   15061        57500 :     case CPTK_IS_DESTRUCTIBLE:
   15062        57500 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   15063        57500 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   15064        57500 :       if (!check_trait_type (type1, /*kind=*/1, complain))
   15065           57 :         return error_mark_node;
   15066              :       break;
   15067              : 
   15068       312284 :     case CPTK_IS_LITERAL_TYPE:
   15069       312284 :     case CPTK_IS_POD:
   15070       312284 :     case CPTK_IS_STD_LAYOUT:
   15071       312284 :     case CPTK_IS_TRIVIAL:
   15072       312284 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   15073       312284 :     case CPTK_IS_STRUCTURAL:
   15074       312284 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   15075       312284 :       if (!check_trait_type (type1, /* kind = */ 2, complain))
   15076          133 :         return error_mark_node;
   15077              :       break;
   15078              : 
   15079       277489 :     case CPTK_IS_ABSTRACT:
   15080       277489 :     case CPTK_IS_EMPTY:
   15081       277489 :     case CPTK_IS_POLYMORPHIC:
   15082       277489 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   15083       277489 :       if (!check_trait_type (type1, /* kind = */ 3, complain))
   15084           39 :         return error_mark_node;
   15085              :       break;
   15086              : 
   15087              :     /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
   15088              :        type to know whether an array is an aggregate, so use kind=4 here.  */
   15089       438092 :     case CPTK_IS_AGGREGATE:
   15090       438092 :     case CPTK_IS_FINAL:
   15091       438092 :     case CPTK_IS_IMPLICIT_LIFETIME:
   15092       438092 :       if (!check_trait_type (type1, /* kind = */ 4, complain))
   15093           55 :         return error_mark_node;
   15094              :       break;
   15095              : 
   15096      6672879 :     case CPTK_IS_CONSTRUCTIBLE:
   15097      6672879 :     case CPTK_IS_CONVERTIBLE:
   15098      6672879 :     case CPTK_IS_INVOCABLE:
   15099      6672879 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   15100      6672879 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   15101      6672879 :     case CPTK_IS_NOTHROW_INVOCABLE:
   15102      6672879 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   15103      6672879 :       /* Don't check completeness for direct reference binding.  */;
   15104      6672879 :       if (same_type_ref_bind_p (kind, type1, type2))
   15105              :         break;
   15106      7617917 :       gcc_fallthrough ();
   15107              : 
   15108      7617917 :     case CPTK_IS_ASSIGNABLE:
   15109      7617917 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   15110      7617917 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   15111      7617917 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   15112      7617917 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   15113      7617917 :       if (!check_trait_type (type1, /*kind=*/1, complain)
   15114      7617917 :           || !check_trait_type (type2, /*kind=*/1, complain))
   15115          602 :         return error_mark_node;
   15116              :       break;
   15117              : 
   15118       518628 :     case CPTK_IS_BASE_OF:
   15119       518628 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   15120       518511 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   15121       499752 :           && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
   15122       990210 :           && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
   15123              :         /* We already issued an error.  */
   15124           27 :         return error_mark_node;
   15125              :       break;
   15126              : 
   15127          910 :     case CPTK_IS_VIRTUAL_BASE_OF:
   15128          830 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   15129         1718 :           && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
   15130              :         /* We already issued an error.  */
   15131           27 :         return error_mark_node;
   15132              :       break;
   15133              : 
   15134              :     case CPTK_IS_ARRAY:
   15135              :     case CPTK_IS_BOUNDED_ARRAY:
   15136              :     case CPTK_IS_CLASS:
   15137              :     case CPTK_IS_CONST:
   15138              :     case CPTK_IS_ENUM:
   15139              :     case CPTK_IS_FUNCTION:
   15140              :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   15141              :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   15142              :     case CPTK_IS_MEMBER_POINTER:
   15143              :     case CPTK_IS_OBJECT:
   15144              :     case CPTK_IS_POINTER:
   15145              :     case CPTK_IS_REFERENCE:
   15146              :     case CPTK_IS_SAME:
   15147              :     case CPTK_IS_SCOPED_ENUM:
   15148              :     case CPTK_IS_UNBOUNDED_ARRAY:
   15149              :     case CPTK_IS_UNION:
   15150              :     case CPTK_IS_VOLATILE:
   15151              :       break;
   15152              : 
   15153              :     case CPTK_RANK:
   15154              :       {
   15155              :         size_t rank = 0;
   15156          122 :         for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
   15157           80 :           ++rank;
   15158           42 :         return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
   15159              :                                          loc);
   15160              :       }
   15161              : 
   15162          460 :     case CPTK_TYPE_ORDER:
   15163          460 :       return maybe_wrap_with_location (type_order_value (type1, type2), loc);
   15164              : 
   15165          279 :     case CPTK_STRUCTURED_BINDING_SIZE:
   15166          279 :       if (!check_trait_type (type1, /* kind = */ 4, complain))
   15167            3 :         return error_mark_node;
   15168          276 :       return finish_structured_binding_size (loc, type1, complain);
   15169              : 
   15170          242 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   15171          242 :       if (!array_of_unknown_bound_p (type1)
   15172          223 :           && TREE_CODE (type1) != VOID_TYPE
   15173          456 :           && !complete_type_or_maybe_complain (type1, NULL_TREE, complain))
   15174              :         /* We already issued an error.  */
   15175           12 :         return error_mark_node;
   15176          230 :       if (!array_of_unknown_bound_p (type2)
   15177          203 :           && TREE_CODE (type2) != VOID_TYPE
   15178          424 :           && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
   15179              :         /* We already issued an error.  */
   15180            9 :         return error_mark_node;
   15181              :       break;
   15182              : 
   15183           85 :     case CPTK_IS_DEDUCIBLE:
   15184           85 :       if (!DECL_TYPE_TEMPLATE_P (type1))
   15185              :         {
   15186            0 :           error ("%qD is not a class or alias template", type1);
   15187            0 :           return error_mark_node;
   15188              :         }
   15189              :       break;
   15190              : 
   15191              : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   15192              :     case CPTK_##CODE:
   15193              : #include "cp-trait.def"
   15194              : #undef DEFTRAIT_TYPE
   15195              :       /* Type-yielding traits are handled in finish_trait_type.  */
   15196            0 :       gcc_unreachable ();
   15197              :     }
   15198              : 
   15199     18115562 :   tree val = (trait_expr_value (kind, type1, type2)
   15200     18115562 :               ? boolean_true_node : boolean_false_node);
   15201     18115562 :   return maybe_wrap_with_location (val, loc);
   15202              : }
   15203              : 
   15204              : /* Process a trait type.  */
   15205              : 
   15206              : tree
   15207      8002757 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
   15208              :                    tsubst_flags_t complain)
   15209              : {
   15210      8003701 :   if (type1 == error_mark_node
   15211      8003698 :       || type2 == error_mark_node)
   15212              :     return error_mark_node;
   15213              : 
   15214      8003698 :   if (processing_template_decl)
   15215              :     {
   15216       230514 :       tree type = cxx_make_type (TRAIT_TYPE);
   15217       230514 :       TRAIT_TYPE_TYPE1 (type) = type1;
   15218       230514 :       TRAIT_TYPE_TYPE2 (type) = type2;
   15219       230514 :       TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
   15220              :       /* These traits are intended to be used in the definition of the ::type
   15221              :          member of the corresponding standard library type trait and aren't
   15222              :          mangleable (and thus won't appear directly in template signatures),
   15223              :          so structural equality should suffice.  */
   15224       230514 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   15225       230514 :       return type;
   15226              :     }
   15227              : 
   15228      7773184 :   switch (kind)
   15229              :     {
   15230      1248593 :     case CPTK_ADD_LVALUE_REFERENCE:
   15231              :       /* [meta.trans.ref].  */
   15232      1248593 :       if (referenceable_type_p (type1))
   15233      1248506 :         return cp_build_reference_type (type1, /*rval=*/false);
   15234              :       return type1;
   15235              : 
   15236       644071 :     case CPTK_ADD_POINTER:
   15237              :       /* [meta.trans.ptr].  */
   15238       644071 :       if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
   15239              :         {
   15240       644039 :           if (TYPE_REF_P (type1))
   15241       642838 :             type1 = TREE_TYPE (type1);
   15242       644039 :           return build_pointer_type (type1);
   15243              :         }
   15244              :       return type1;
   15245              : 
   15246      1686781 :     case CPTK_ADD_RVALUE_REFERENCE:
   15247              :       /* [meta.trans.ref].  */
   15248      1686781 :       if (referenceable_type_p (type1))
   15249      1686723 :         return cp_build_reference_type (type1, /*rval=*/true);
   15250              :       return type1;
   15251              : 
   15252       238281 :     case CPTK_DECAY:
   15253       238281 :       if (TYPE_REF_P (type1))
   15254        43115 :         type1 = TREE_TYPE (type1);
   15255              : 
   15256       238281 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   15257          735 :         return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
   15258          735 :                                   complain);
   15259       237546 :       else if (TREE_CODE (type1) == FUNCTION_TYPE)
   15260              :         return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
   15261              :       else
   15262       237337 :         return cv_unqualified (type1);
   15263              : 
   15264          223 :     case CPTK_REMOVE_ALL_EXTENTS:
   15265          223 :       return strip_array_types (type1);
   15266              : 
   15267       998395 :     case CPTK_REMOVE_CV:
   15268       998395 :       return cv_unqualified (type1);
   15269              : 
   15270       479834 :     case CPTK_REMOVE_CVREF:
   15271       479834 :       if (TYPE_REF_P (type1))
   15272       182984 :         type1 = TREE_TYPE (type1);
   15273       479834 :       return cv_unqualified (type1);
   15274              : 
   15275        66408 :     case CPTK_REMOVE_EXTENT:
   15276        66408 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   15277         9439 :         type1 = TREE_TYPE (type1);
   15278              :       return type1;
   15279              : 
   15280        44888 :     case CPTK_REMOVE_POINTER:
   15281        44888 :       if (TYPE_PTR_P (type1))
   15282        41986 :         type1 = TREE_TYPE (type1);
   15283              :       return type1;
   15284              : 
   15285      2204798 :     case CPTK_REMOVE_REFERENCE:
   15286      2204798 :       if (TYPE_REF_P (type1))
   15287      1338276 :         type1 = TREE_TYPE (type1);
   15288              :       return type1;
   15289              : 
   15290       112421 :     case CPTK_TYPE_PACK_ELEMENT:
   15291       112421 :       return finish_type_pack_element (type1, type2, complain);
   15292              : 
   15293        48491 :     case CPTK_UNDERLYING_TYPE:
   15294        48491 :       return finish_underlying_type (type1);
   15295              : 
   15296              : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
   15297              :     case CPTK_##CODE:
   15298              : #include "cp-trait.def"
   15299              : #undef DEFTRAIT_EXPR
   15300              :       /* Expression-yielding traits are handled in finish_trait_expr.  */
   15301              :     case CPTK_BASES:
   15302              :     case CPTK_DIRECT_BASES:
   15303              :       /* BASES and DIRECT_BASES are handled in finish_bases.  */
   15304              :       break;
   15305              :     }
   15306              : 
   15307            0 :   gcc_unreachable ();
   15308              : }
   15309              : 
   15310              : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
   15311              :    which is ignored for C++.  */
   15312              : 
   15313              : void
   15314            0 : set_float_const_decimal64 (void)
   15315              : {
   15316            0 : }
   15317              : 
   15318              : void
   15319            0 : clear_float_const_decimal64 (void)
   15320              : {
   15321            0 : }
   15322              : 
   15323              : bool
   15324      1887693 : float_const_decimal64_p (void)
   15325              : {
   15326      1887693 :   return 0;
   15327              : }
   15328              : 
   15329              : 
   15330              : /* Return true if T designates the implied `this' parameter.  */
   15331              : 
   15332              : bool
   15333      6614257 : is_this_parameter (tree t)
   15334              : {
   15335      6614257 :   if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
   15336              :     return false;
   15337      3854735 :   gcc_assert (TREE_CODE (t) == PARM_DECL
   15338              :               || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
   15339              :               || (cp_binding_oracle && VAR_P (t)));
   15340              :   return true;
   15341              : }
   15342              : 
   15343              : /* As above, or a C++23 explicit object parameter.  */
   15344              : 
   15345              : bool
   15346          456 : is_object_parameter (tree t)
   15347              : {
   15348          456 :   if (is_this_parameter (t))
   15349              :     return true;
   15350           91 :   if (TREE_CODE (t) != PARM_DECL)
   15351              :     return false;
   15352           34 :   tree ctx = DECL_CONTEXT (t);
   15353           34 :   return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
   15354           62 :           && t == DECL_ARGUMENTS (ctx));
   15355              : }
   15356              : 
   15357              : /* Insert the deduced return type for an auto function.  */
   15358              : 
   15359              : void
   15360      1213371 : apply_deduced_return_type (tree fco, tree return_type)
   15361              : {
   15362      1213371 :   tree result;
   15363              : 
   15364      1213371 :   if (return_type == error_mark_node)
   15365              :     return;
   15366              : 
   15367      1213368 :   if (DECL_CONV_FN_P (fco))
   15368           42 :     DECL_NAME (fco) = make_conv_op_name (return_type);
   15369              : 
   15370      1213368 :   TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
   15371              : 
   15372      1213368 :   maybe_update_postconditions (fco);
   15373              : 
   15374              :   /* Apply the type to the result object.  */
   15375              : 
   15376      1213368 :   result = DECL_RESULT (fco);
   15377      1213368 :   if (result == NULL_TREE)
   15378              :     return;
   15379      1200857 :   if (TREE_TYPE (result) == return_type)
   15380              :     return;
   15381              : 
   15382      1200854 :   if (!processing_template_decl && !VOID_TYPE_P (return_type)
   15383      2241703 :       && !complete_type_or_else (return_type, NULL_TREE))
   15384              :     return;
   15385              : 
   15386              :   /* We already have a DECL_RESULT from start_preparsed_function.
   15387              :      Now we need to redo the work it and allocate_struct_function
   15388              :      did to reflect the new type.  */
   15389      1200854 :   result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
   15390      1200854 :                        TYPE_MAIN_VARIANT (return_type));
   15391      1200854 :   DECL_ARTIFICIAL (result) = 1;
   15392      1200854 :   DECL_IGNORED_P (result) = 1;
   15393      1200854 :   cp_apply_type_quals_to_decl (cp_type_quals (return_type),
   15394              :                                result);
   15395      1200854 :   DECL_RESULT (fco) = result;
   15396              : 
   15397      1200854 :   if (!uses_template_parms (fco))
   15398      1200854 :     if (function *fun = DECL_STRUCT_FUNCTION (fco))
   15399              :       {
   15400      1199838 :         bool aggr = aggregate_value_p (result, fco);
   15401              : #ifdef PCC_STATIC_STRUCT_RETURN
   15402              :         fun->returns_pcc_struct = aggr;
   15403              : #endif
   15404      1199838 :         fun->returns_struct = aggr;
   15405              :       }
   15406              : }
   15407              : 
   15408              : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
   15409              :    this is a right unary fold. Otherwise it is a left unary fold. */
   15410              : 
   15411              : static tree
   15412       844023 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
   15413              : {
   15414              :   /* Build a pack expansion (assuming expr has pack type).  */
   15415       844023 :   if (!uses_parameter_packs (expr))
   15416              :     {
   15417            3 :       error_at (location_of (expr), "operand of fold expression has no "
   15418              :                 "unexpanded parameter packs");
   15419            3 :       return error_mark_node;
   15420              :     }
   15421       844020 :   tree pack = make_pack_expansion (expr);
   15422              : 
   15423              :   /* Build the fold expression.  */
   15424       844020 :   tree code = build_int_cstu (integer_type_node, abs (op));
   15425       844020 :   tree fold = build_min_nt_loc (loc, dir, code, pack);
   15426       844020 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   15427       844020 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   15428       844020 :                                                     FOLD_EXPR_OP (fold),
   15429       844020 :                                                     FOLD_EXPR_MODIFY_P (fold));
   15430       844020 :   return fold;
   15431              : }
   15432              : 
   15433              : tree
   15434        26589 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
   15435              : {
   15436        26589 :   return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
   15437              : }
   15438              : 
   15439              : tree
   15440       817434 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
   15441              : {
   15442       817434 :   return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
   15443              : }
   15444              : 
   15445              : /* Build a binary fold expression over EXPR1 and EXPR2. The
   15446              :    associativity of the fold is determined by EXPR1 and EXPR2 (whichever
   15447              :    has an unexpanded parameter pack). */
   15448              : 
   15449              : static tree
   15450       196648 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
   15451              :                          int op, tree_code dir)
   15452              : {
   15453       196648 :   pack = make_pack_expansion (pack);
   15454       196648 :   tree code = build_int_cstu (integer_type_node, abs (op));
   15455       196648 :   tree fold = build_min_nt_loc (loc, dir, code, pack, init);
   15456       196648 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   15457       196648 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   15458       196648 :                                                     FOLD_EXPR_OP (fold),
   15459       196648 :                                                     FOLD_EXPR_MODIFY_P (fold));
   15460       196648 :   return fold;
   15461              : }
   15462              : 
   15463              : tree
   15464       196648 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
   15465              : {
   15466              :   // Determine which expr has an unexpanded parameter pack and
   15467              :   // set the pack and initial term.
   15468       196648 :   bool pack1 = uses_parameter_packs (expr1);
   15469       196648 :   bool pack2 = uses_parameter_packs (expr2);
   15470       196648 :   if (pack1 && !pack2)
   15471         1105 :     return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
   15472       195543 :   else if (pack2 && !pack1)
   15473       195543 :     return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
   15474              :   else
   15475              :     {
   15476            0 :       if (pack1)
   15477            0 :         error ("both arguments in binary fold have unexpanded parameter packs");
   15478              :       else
   15479            0 :         error ("no unexpanded parameter packs in binary fold");
   15480              :     }
   15481            0 :   return error_mark_node;
   15482              : }
   15483              : 
   15484              : /* Finish __builtin_launder (arg).  */
   15485              : 
   15486              : tree
   15487        13870 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
   15488              : {
   15489        13870 :   tree orig_arg = arg;
   15490        13870 :   if (!type_dependent_expression_p (arg))
   15491           84 :     arg = decay_conversion (arg, complain);
   15492        13870 :   if (error_operand_p (arg))
   15493            0 :     return error_mark_node;
   15494        13870 :   if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
   15495              :     {
   15496           24 :       error_at (loc, "type %qT of argument to %<__builtin_launder%> "
   15497           24 :                 "is not a pointer to object type", TREE_TYPE (arg));
   15498           24 :       return error_mark_node;
   15499              :     }
   15500        13846 :   if (processing_template_decl)
   15501        13786 :     arg = orig_arg;
   15502        13846 :   return build_call_expr_internal_loc (loc, IFN_LAUNDER,
   15503        27692 :                                        TREE_TYPE (arg), 1, arg);
   15504              : }
   15505              : 
   15506              : /* Finish __builtin_convertvector (arg, type).  */
   15507              : 
   15508              : tree
   15509          486 : cp_build_vec_convert (tree arg, location_t loc, tree type,
   15510              :                       tsubst_flags_t complain)
   15511              : {
   15512          486 :   if (error_operand_p (type))
   15513            9 :     return error_mark_node;
   15514          477 :   if (error_operand_p (arg))
   15515            0 :     return error_mark_node;
   15516              : 
   15517          477 :   tree ret = NULL_TREE;
   15518          477 :   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
   15519          439 :     ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
   15520              :                                decay_conversion (arg, complain),
   15521              :                                loc, type, (complain & tf_error) != 0);
   15522              : 
   15523          477 :   if (!processing_template_decl)
   15524              :     return ret;
   15525              : 
   15526           80 :   return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
   15527              : }
   15528              : 
   15529              : /* Finish __builtin_bit_cast (type, arg).  */
   15530              : 
   15531              : tree
   15532       290723 : cp_build_bit_cast (location_t loc, tree type, tree arg,
   15533              :                    tsubst_flags_t complain)
   15534              : {
   15535       290723 :   if (error_operand_p (type))
   15536            0 :     return error_mark_node;
   15537       290723 :   if (!dependent_type_p (type))
   15538              :     {
   15539       210744 :       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
   15540            9 :         return error_mark_node;
   15541       210735 :       if (TREE_CODE (type) == ARRAY_TYPE)
   15542              :         {
   15543              :           /* std::bit_cast for destination ARRAY_TYPE is not possible,
   15544              :              as functions may not return an array, so don't bother trying
   15545              :              to support this (and then deal with VLAs etc.).  */
   15546            9 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   15547              :                          "is an array type", type);
   15548            9 :           return error_mark_node;
   15549              :         }
   15550       210726 :       if (!trivially_copyable_p (type))
   15551              :         {
   15552           18 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   15553              :                          "is not trivially copyable", type);
   15554           18 :           return error_mark_node;
   15555              :         }
   15556              :     }
   15557              : 
   15558       290687 :   if (error_operand_p (arg))
   15559            0 :     return error_mark_node;
   15560              : 
   15561       290687 :   if (!type_dependent_expression_p (arg))
   15562              :     {
   15563       114580 :       if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
   15564              :         {
   15565              :           /* Don't perform array-to-pointer conversion.  */
   15566          375 :           arg = mark_rvalue_use (arg, loc, true);
   15567          375 :           if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
   15568            0 :             return error_mark_node;
   15569              :         }
   15570              :       else
   15571       114205 :         arg = decay_conversion (arg, complain);
   15572              : 
   15573       114580 :       if (error_operand_p (arg))
   15574           12 :         return error_mark_node;
   15575              : 
   15576       114568 :       if (!trivially_copyable_p (TREE_TYPE (arg)))
   15577              :         {
   15578            9 :           error_at (cp_expr_loc_or_loc (arg, loc),
   15579              :                     "%<__builtin_bit_cast%> source type %qT "
   15580            9 :                     "is not trivially copyable", TREE_TYPE (arg));
   15581            9 :           return error_mark_node;
   15582              :         }
   15583       114559 :       if (!dependent_type_p (type)
   15584       190982 :           && !cp_tree_equal (TYPE_SIZE_UNIT (type),
   15585        76423 :                              TYPE_SIZE_UNIT (TREE_TYPE (arg))))
   15586              :         {
   15587           18 :           error_at (loc, "%<__builtin_bit_cast%> source size %qE "
   15588              :                          "not equal to destination type size %qE",
   15589           18 :                          TYPE_SIZE_UNIT (TREE_TYPE (arg)),
   15590           18 :                          TYPE_SIZE_UNIT (type));
   15591           18 :           return error_mark_node;
   15592              :         }
   15593              :     }
   15594              : 
   15595       290648 :   tree ret = build_min (BIT_CAST_EXPR, type, arg);
   15596       290648 :   SET_EXPR_LOCATION (ret, loc);
   15597              : 
   15598       290648 :   if (!processing_template_decl && CLASS_TYPE_P (type))
   15599          874 :     ret = get_target_expr (ret, complain);
   15600              : 
   15601              :   return ret;
   15602              : }
   15603              : 
   15604              : /* Diagnose invalid #pragma GCC unroll argument and adjust
   15605              :    it if needed.  */
   15606              : 
   15607              : tree
   15608        24097 : cp_check_pragma_unroll (location_t loc, tree unroll)
   15609              : {
   15610        24097 :   HOST_WIDE_INT lunroll = 0;
   15611        24097 :   if (type_dependent_expression_p (unroll))
   15612              :     ;
   15613        48122 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
   15614        48076 :            || (!value_dependent_expression_p (unroll)
   15615        23985 :                && (!tree_fits_shwi_p (unroll)
   15616        23959 :                    || (lunroll = tree_to_shwi (unroll)) < 0
   15617        23944 :                    || lunroll >= USHRT_MAX)))
   15618              :     {
   15619           90 :       error_at (loc, "%<#pragma GCC unroll%> requires an"
   15620              :                 " assignment-expression that evaluates to a non-negative"
   15621              :                 " integral constant less than %u", USHRT_MAX);
   15622           90 :       unroll = integer_one_node;
   15623              :     }
   15624        23971 :   else if (TREE_CODE (unroll) == INTEGER_CST)
   15625              :     {
   15626        23941 :       unroll = fold_convert (integer_type_node, unroll);
   15627        23941 :       if (integer_zerop (unroll))
   15628           12 :         unroll = integer_one_node;
   15629              :     }
   15630        24097 :   return unroll;
   15631              : }
   15632              : 
   15633              : #include "gt-cp-semantics.h"
        

Generated by: LCOV version 2.6-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.