LCOV - code coverage report
Current view: top level - gcc/cp - semantics.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.5 % 7106 6717
Test Date: 2025-10-18 14:39:06 Functions: 97.2 % 247 240
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     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-2025 Free Software Foundation, Inc.
       7                 :             :    Written by Mark Mitchell (mmitchell@usa.net) based on code found
       8                 :             :    formerly in parse.y and pt.cc.
       9                 :             : 
      10                 :             :    This file is part of GCC.
      11                 :             : 
      12                 :             :    GCC is free software; you can redistribute it and/or modify it
      13                 :             :    under the terms of the GNU General Public License as published by
      14                 :             :    the Free Software Foundation; either version 3, or (at your option)
      15                 :             :    any later version.
      16                 :             : 
      17                 :             :    GCC is distributed in the hope that it will be useful, but
      18                 :             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      19                 :             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      20                 :             :    General Public License for more details.
      21                 :             : 
      22                 :             : You should have received a copy of the GNU General Public License
      23                 :             : along with GCC; see the file COPYING3.  If not see
      24                 :             : <http://www.gnu.org/licenses/>.  */
      25                 :             : 
      26                 :             : #include "config.h"
      27                 :             : #include "system.h"
      28                 :             : #include "coretypes.h"
      29                 :             : #include "target.h"
      30                 :             : #include "bitmap.h"
      31                 :             : #include "cp-tree.h"
      32                 :             : #include "stringpool.h"
      33                 :             : #include "cgraph.h"
      34                 :             : #include "stmt.h"
      35                 :             : #include "varasm.h"
      36                 :             : #include "stor-layout.h"
      37                 :             : #include "c-family/c-objc.h"
      38                 :             : #include "tree-inline.h"
      39                 :             : #include "intl.h"
      40                 :             : #include "tree-iterator.h"
      41                 :             : #include "omp-general.h"
      42                 :             : #include "convert.h"
      43                 :             : #include "stringpool.h"
      44                 :             : #include "attribs.h"
      45                 :             : #include "gomp-constants.h"
      46                 :             : #include "predict.h"
      47                 :             : #include "memmodel.h"
      48                 :             : #include "gimplify.h"
      49                 :             : #include "contracts.h"
      50                 :             : 
      51                 :             : /* There routines provide a modular interface to perform many parsing
      52                 :             :    operations.  They may therefore be used during actual parsing, or
      53                 :             :    during template instantiation, which may be regarded as a
      54                 :             :    degenerate form of parsing.  */
      55                 :             : 
      56                 :             : static tree finalize_nrv_r (tree *, int *, void *);
      57                 :             : 
      58                 :             : /* Used for OpenMP non-static data member privatization.  */
      59                 :             : 
      60                 :             : static hash_map<tree, tree> *omp_private_member_map;
      61                 :             : static vec<tree> omp_private_member_vec;
      62                 :             : static bool omp_private_member_ignore_next;
      63                 :             : 
      64                 :             : 
      65                 :             : /* Deferred Access Checking Overview
      66                 :             :    ---------------------------------
      67                 :             : 
      68                 :             :    Most C++ expressions and declarations require access checking
      69                 :             :    to be performed during parsing.  However, in several cases,
      70                 :             :    this has to be treated differently.
      71                 :             : 
      72                 :             :    For member declarations, access checking has to be deferred
      73                 :             :    until more information about the declaration is known.  For
      74                 :             :    example:
      75                 :             : 
      76                 :             :      class A {
      77                 :             :          typedef int X;
      78                 :             :        public:
      79                 :             :          X f();
      80                 :             :      };
      81                 :             : 
      82                 :             :      A::X A::f();
      83                 :             :      A::X g();
      84                 :             : 
      85                 :             :    When we are parsing the function return type `A::X', we don't
      86                 :             :    really know if this is allowed until we parse the function name.
      87                 :             : 
      88                 :             :    Furthermore, some contexts require that access checking is
      89                 :             :    never performed at all.  These include class heads, and template
      90                 :             :    instantiations.
      91                 :             : 
      92                 :             :    Typical use of access checking functions is described here:
      93                 :             : 
      94                 :             :    1. When we enter a context that requires certain access checking
      95                 :             :       mode, the function `push_deferring_access_checks' is called with
      96                 :             :       DEFERRING argument specifying the desired mode.  Access checking
      97                 :             :       may be performed immediately (dk_no_deferred), deferred
      98                 :             :       (dk_deferred), or not performed (dk_no_check).
      99                 :             : 
     100                 :             :    2. When a declaration such as a type, or a variable, is encountered,
     101                 :             :       the function `perform_or_defer_access_check' is called.  It
     102                 :             :       maintains a vector of all deferred checks.
     103                 :             : 
     104                 :             :    3. The global `current_class_type' or `current_function_decl' is then
     105                 :             :       setup by the parser.  `enforce_access' relies on these information
     106                 :             :       to check access.
     107                 :             : 
     108                 :             :    4. Upon exiting the context mentioned in step 1,
     109                 :             :       `perform_deferred_access_checks' is called to check all declaration
     110                 :             :       stored in the vector. `pop_deferring_access_checks' is then
     111                 :             :       called to restore the previous access checking mode.
     112                 :             : 
     113                 :             :       In case of parsing error, we simply call `pop_deferring_access_checks'
     114                 :             :       without `perform_deferred_access_checks'.  */
     115                 :             : 
     116                 :             : struct GTY(()) deferred_access {
     117                 :             :   /* A vector representing name-lookups for which we have deferred
     118                 :             :      checking access controls.  We cannot check the accessibility of
     119                 :             :      names used in a decl-specifier-seq until we know what is being
     120                 :             :      declared because code like:
     121                 :             : 
     122                 :             :        class A {
     123                 :             :          class B {};
     124                 :             :          B* f();
     125                 :             :        }
     126                 :             : 
     127                 :             :        A::B* A::f() { return 0; }
     128                 :             : 
     129                 :             :      is valid, even though `A::B' is not generally accessible.  */
     130                 :             :   vec<deferred_access_check, va_gc> *deferred_access_checks;
     131                 :             : 
     132                 :             :   /* The current mode of access checks.  */
     133                 :             :   enum deferring_kind deferring_access_checks_kind;
     134                 :             : };
     135                 :             : 
     136                 :             : /* Data for deferred access checking.  */
     137                 :             : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
     138                 :             : static GTY(()) unsigned deferred_access_no_check;
     139                 :             : 
     140                 :             : /* Save the current deferred access states and start deferred
     141                 :             :    access checking iff DEFER_P is true.  */
     142                 :             : 
     143                 :             : void
     144                 : 19613817867 : push_deferring_access_checks (deferring_kind deferring)
     145                 :             : {
     146                 :             :   /* For context like template instantiation, access checking
     147                 :             :      disabling applies to all nested context.  */
     148                 : 19613817867 :   if (deferred_access_no_check || deferring == dk_no_check)
     149                 :   278543848 :     deferred_access_no_check++;
     150                 :             :   else
     151                 :             :     {
     152                 : 19335274019 :       deferred_access e = {NULL, deferring};
     153                 : 19335274019 :       vec_safe_push (deferred_access_stack, e);
     154                 :             :     }
     155                 : 19613817867 : }
     156                 :             : 
     157                 :             : /* Save the current deferred access states and start deferred access
     158                 :             :    checking, continuing the set of deferred checks in CHECKS.  */
     159                 :             : 
     160                 :             : void
     161                 :   313048912 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
     162                 :             : {
     163                 :   313048912 :   push_deferring_access_checks (dk_deferred);
     164                 :   313048912 :   if (!deferred_access_no_check)
     165                 :   306342849 :     deferred_access_stack->last().deferred_access_checks = checks;
     166                 :   313048912 : }
     167                 :             : 
     168                 :             : /* Resume deferring access checks again after we stopped doing
     169                 :             :    this previously.  */
     170                 :             : 
     171                 :             : void
     172                 :   164829646 : resume_deferring_access_checks (void)
     173                 :             : {
     174                 :   164829646 :   if (!deferred_access_no_check)
     175                 :   164811541 :     deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
     176                 :   164829646 : }
     177                 :             : 
     178                 :             : /* Stop deferring access checks.  */
     179                 :             : 
     180                 :             : void
     181                 :   453494902 : stop_deferring_access_checks (void)
     182                 :             : {
     183                 :   453494902 :   if (!deferred_access_no_check)
     184                 :   453441041 :     deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
     185                 :   453494902 : }
     186                 :             : 
     187                 :             : /* Discard the current deferred access checks and restore the
     188                 :             :    previous states.  */
     189                 :             : 
     190                 :             : void
     191                 : 11903115415 : pop_deferring_access_checks (void)
     192                 :             : {
     193                 : 11903115415 :   if (deferred_access_no_check)
     194                 :   207549439 :     deferred_access_no_check--;
     195                 :             :   else
     196                 : 11695565976 :     deferred_access_stack->pop ();
     197                 : 11903115415 : }
     198                 :             : 
     199                 :             : /* Returns a TREE_LIST representing the deferred checks.
     200                 :             :    The TREE_PURPOSE of each node is the type through which the
     201                 :             :    access occurred; the TREE_VALUE is the declaration named.
     202                 :             :    */
     203                 :             : 
     204                 :             : vec<deferred_access_check, va_gc> *
     205                 :  1050357744 : get_deferred_access_checks (void)
     206                 :             : {
     207                 :  1050357744 :   if (deferred_access_no_check)
     208                 :             :     return NULL;
     209                 :             :   else
     210                 :  1037066628 :     return (deferred_access_stack->last().deferred_access_checks);
     211                 :             : }
     212                 :             : 
     213                 :             : /* Take current deferred checks and combine with the
     214                 :             :    previous states if we also defer checks previously.
     215                 :             :    Otherwise perform checks now.  */
     216                 :             : 
     217                 :             : void
     218                 :  7710569328 : pop_to_parent_deferring_access_checks (void)
     219                 :             : {
     220                 :  7710569328 :   if (deferred_access_no_check)
     221                 :    70994403 :     deferred_access_no_check--;
     222                 :             :   else
     223                 :             :     {
     224                 :  7639574925 :       vec<deferred_access_check, va_gc> *checks;
     225                 :  7639574925 :       deferred_access *ptr;
     226                 :             : 
     227                 :  7639574925 :       checks = (deferred_access_stack->last ().deferred_access_checks);
     228                 :             : 
     229                 :  7639574925 :       deferred_access_stack->pop ();
     230                 :  7639574925 :       ptr = &deferred_access_stack->last ();
     231                 :  7639574925 :       if (ptr->deferring_access_checks_kind == dk_no_deferred)
     232                 :             :         {
     233                 :             :           /* Check access.  */
     234                 :   485266380 :           perform_access_checks (checks, tf_warning_or_error);
     235                 :             :         }
     236                 :             :       else
     237                 :             :         {
     238                 :             :           /* Merge with parent.  */
     239                 :             :           int i, j;
     240                 :             :           deferred_access_check *chk, *probe;
     241                 :             : 
     242                 :  7319826909 :           FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     243                 :             :             {
     244                 :    90642882 :               FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
     245                 :             :                 {
     246                 :     8664313 :                   if (probe->binfo == chk->binfo &&
     247                 :     6859711 :                       probe->decl == chk->decl &&
     248                 :      781333 :                       probe->diag_decl == chk->diag_decl)
     249                 :      780613 :                     goto found;
     250                 :             :                 }
     251                 :             :               /* Insert into parent's checks.  */
     252                 :    81978569 :               vec_safe_push (ptr->deferred_access_checks, *chk);
     253                 :    82759182 :             found:;
     254                 :             :             }
     255                 :             :         }
     256                 :             :     }
     257                 :  7710569328 : }
     258                 :             : 
     259                 :             : /* Called from enforce_access.  A class has attempted (but failed) to access
     260                 :             :    DECL.  It is already established that a baseclass of that class,
     261                 :             :    PARENT_BINFO, has private access to DECL.  Examine certain special cases
     262                 :             :    to find a decl that accurately describes the source of the problem.  If
     263                 :             :    none of the special cases apply, simply return DECL as the source of the
     264                 :             :    problem.  */
     265                 :             : 
     266                 :             : static tree
     267                 :         179 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
     268                 :             : {
     269                 :             :   /* When a class is denied access to a decl in a baseclass, most of the
     270                 :             :      time it is because the decl itself was declared as private at the point
     271                 :             :      of declaration.
     272                 :             : 
     273                 :             :      However, in C++, there are (at least) two situations in which a decl
     274                 :             :      can be private even though it was not originally defined as such.
     275                 :             :      These two situations only apply if a baseclass had private access to
     276                 :             :      DECL (this function is only called if that is the case).  */
     277                 :             : 
     278                 :             :   /* We should first check whether the reason the parent had private access
     279                 :             :      to DECL was simply because DECL was created and declared as private in
     280                 :             :      the parent.  If it was, then DECL is definitively the source of the
     281                 :             :      problem.  */
     282                 :         179 :   if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
     283                 :             :                          BINFO_TYPE (parent_binfo)))
     284                 :             :     return decl;
     285                 :             : 
     286                 :             :   /* 1.  If the "using" keyword is used to inherit DECL within the parent,
     287                 :             :      this may cause DECL to be private, so we should return the using
     288                 :             :      statement as the source of the problem.
     289                 :             : 
     290                 :             :      Scan the fields of PARENT_BINFO and see if there are any using decls.  If
     291                 :             :      there are, see if they inherit DECL.  If they do, that's where DECL must
     292                 :             :      have been declared private.  */
     293                 :             : 
     294                 :          66 :   for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
     295                 :         326 :        parent_field;
     296                 :         260 :        parent_field = DECL_CHAIN (parent_field))
     297                 :             :     /* Not necessary, but also check TREE_PRIVATE for the sake of
     298                 :             :        eliminating obviously non-relevant using decls.  */
     299                 :         278 :     if (TREE_CODE (parent_field) == USING_DECL
     300                 :          81 :         && TREE_PRIVATE (parent_field))
     301                 :             :       {
     302                 :          78 :         tree decl_stripped = strip_using_decl (parent_field);
     303                 :             : 
     304                 :             :         /* The using statement might be overloaded.  If so, we need to
     305                 :             :            check all of the overloads.  */
     306                 :         180 :         for (ovl_iterator iter (decl_stripped); iter; ++iter)
     307                 :             :           /* If equal, the using statement inherits DECL, and so is the
     308                 :             :              source of the access failure, so return it.  */
     309                 :          99 :           if (*iter == decl)
     310                 :          18 :             return parent_field;
     311                 :             :       }
     312                 :             : 
     313                 :             :   /* 2.  If DECL was privately inherited by the parent class, then DECL will
     314                 :             :      be inaccessible, even though it may originally have been accessible to
     315                 :             :      deriving classes.  In that case, the fault lies with the parent, since it
     316                 :             :      used a private inheritance, so we return the parent as the source of the
     317                 :             :      problem.
     318                 :             : 
     319                 :             :      Since this is the last check, we just assume it's true.  At worst, it
     320                 :             :      will simply point to the class that failed to give access, which is
     321                 :             :      technically true.  */
     322                 :          48 :   return TYPE_NAME (BINFO_TYPE (parent_binfo));
     323                 :             : }
     324                 :             : 
     325                 :             : /* If the current scope isn't allowed to access DECL along
     326                 :             :    BASETYPE_PATH, give an error, or if we're parsing a function or class
     327                 :             :    template, defer the access check to be performed at instantiation time.
     328                 :             :    The most derived class in BASETYPE_PATH is the one used to qualify DECL.
     329                 :             :    DIAG_DECL is the declaration to use in the error diagnostic.  */
     330                 :             : 
     331                 :             : static bool
     332                 :   309952676 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
     333                 :             :                 tsubst_flags_t complain, access_failure_info *afi = NULL)
     334                 :             : {
     335                 :   309952676 :   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
     336                 :             : 
     337                 :   309952676 :   if (flag_new_inheriting_ctors
     338                 :   398418690 :       && DECL_INHERITED_CTOR (decl))
     339                 :             :     {
     340                 :             :       /* 7.3.3/18: The additional constructors are accessible if they would be
     341                 :             :          accessible when used to construct an object of the corresponding base
     342                 :             :          class.  */
     343                 :       51541 :       decl = strip_inheriting_ctors (decl);
     344                 :       51541 :       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
     345                 :             :                                    ba_any, NULL, complain);
     346                 :             :     }
     347                 :             : 
     348                 :   309952676 :   tree cs = current_scope ();
     349                 :   309952676 :   if (in_template_context
     350                 :   309952676 :       && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
     351                 :    37958872 :     if (tree template_info = get_template_info (cs))
     352                 :             :       {
     353                 :             :         /* When parsing a function or class template, we in general need to
     354                 :             :            defer access checks until template instantiation time, since a friend
     355                 :             :            declaration may grant access only to a particular specialization of
     356                 :             :            the template.  */
     357                 :             : 
     358                 :    37741554 :         if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     359                 :             :           /* But if the member is deemed accessible at parse time, then we can
     360                 :             :              assume it'll be accessible at instantiation time.  */
     361                 :             :           return true;
     362                 :             : 
     363                 :             :         /* Access of a dependent decl should be rechecked after tsubst'ing
     364                 :             :            into the user of the decl, rather than explicitly deferring the
     365                 :             :            check here.  */
     366                 :         135 :         gcc_assert (!uses_template_parms (decl));
     367                 :         135 :         if (TREE_CODE (decl) == FIELD_DECL)
     368                 :           6 :           gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
     369                 :             : 
     370                 :             :         /* Defer this access check until instantiation time.  */
     371                 :         135 :         deferred_access_check access_check;
     372                 :         135 :         access_check.binfo = basetype_path;
     373                 :         135 :         access_check.decl = decl;
     374                 :         135 :         access_check.diag_decl = diag_decl;
     375                 :         135 :         access_check.loc = input_location;
     376                 :         135 :         vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
     377                 :         135 :         return true;
     378                 :             :       }
     379                 :             : 
     380                 :   272211122 :   if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
     381                 :             :     {
     382                 :       22865 :       if (flag_new_inheriting_ctors)
     383                 :       22835 :         diag_decl = strip_inheriting_ctors (diag_decl);
     384                 :       22865 :       if (complain & tf_error)
     385                 :             :         {
     386                 :        1144 :           access_kind access_failure_reason = ak_none;
     387                 :             : 
     388                 :             :           /* By default, using the decl as the source of the problem will
     389                 :             :              usually give correct results.  */
     390                 :        1144 :           tree diag_location = diag_decl;
     391                 :             : 
     392                 :             :           /* However, if a parent of BASETYPE_PATH had private access to decl,
     393                 :             :              then it actually might be the case that the source of the problem
     394                 :             :              is not DECL.  */
     395                 :        1144 :           tree parent_binfo = get_parent_with_private_access (decl,
     396                 :             :                                                               basetype_path);
     397                 :             : 
     398                 :             :           /* So if a parent did have private access, then we need to do
     399                 :             :              special checks to obtain the best diagnostic location decl.  */
     400                 :        1144 :           if (parent_binfo != NULL_TREE)
     401                 :             :             {
     402                 :         179 :               diag_location = get_class_access_diagnostic_decl (parent_binfo,
     403                 :             :                                                                 diag_decl);
     404                 :             : 
     405                 :             :               /* We also at this point know that the reason access failed was
     406                 :             :                  because decl was private.  */
     407                 :         179 :               access_failure_reason = ak_private;
     408                 :             :             }
     409                 :             : 
     410                 :             :           /* Finally, generate an error message.  */
     411                 :        1144 :           complain_about_access (decl, diag_decl, diag_location, true,
     412                 :             :                                  access_failure_reason);
     413                 :             :         }
     414                 :       22865 :       if (afi)
     415                 :         412 :         afi->record_access_failure (basetype_path, decl, diag_decl);
     416                 :       22865 :       return false;
     417                 :             :     }
     418                 :             : 
     419                 :             :   return true;
     420                 :             : }
     421                 :             : 
     422                 :             : /* Perform the access checks in CHECKS.  The TREE_PURPOSE of each node
     423                 :             :    is the BINFO indicating the qualifying scope used to access the
     424                 :             :    DECL node stored in the TREE_VALUE of the node.  If CHECKS is empty
     425                 :             :    or we aren't in SFINAE context or all the checks succeed return TRUE,
     426                 :             :    otherwise FALSE.  */
     427                 :             : 
     428                 :             : bool
     429                 :   919694068 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
     430                 :             :                        tsubst_flags_t complain)
     431                 :             : {
     432                 :   919694068 :   int i;
     433                 :   919694068 :   deferred_access_check *chk;
     434                 :   919694068 :   location_t loc = input_location;
     435                 :   919694068 :   bool ok = true;
     436                 :             : 
     437                 :   919694068 :   if (!checks)
     438                 :             :     return true;
     439                 :             : 
     440                 :   102611706 :   FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
     441                 :             :     {
     442                 :    57177656 :       input_location = chk->loc;
     443                 :    57177656 :       ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
     444                 :             :     }
     445                 :             : 
     446                 :    45434050 :   input_location = loc;
     447                 :    45434050 :   return (complain & tf_error) ? true : ok;
     448                 :             : }
     449                 :             : 
     450                 :             : /* Perform the deferred access checks.
     451                 :             : 
     452                 :             :    After performing the checks, we still have to keep the list
     453                 :             :    `deferred_access_stack->deferred_access_checks' since we may want
     454                 :             :    to check access for them again later in a different context.
     455                 :             :    For example:
     456                 :             : 
     457                 :             :      class A {
     458                 :             :        typedef int X;
     459                 :             :        static X a;
     460                 :             :      };
     461                 :             :      A::X A::a, x;      // No error for `A::a', error for `x'
     462                 :             : 
     463                 :             :    We have to perform deferred access of `A::X', first with `A::a',
     464                 :             :    next with `x'.  Return value like perform_access_checks above.  */
     465                 :             : 
     466                 :             : bool
     467                 :   234804462 : perform_deferred_access_checks (tsubst_flags_t complain)
     468                 :             : {
     469                 :   234804462 :   return perform_access_checks (get_deferred_access_checks (), complain);
     470                 :             : }
     471                 :             : 
     472                 :             : /* Defer checking the accessibility of DECL, when looked up in
     473                 :             :    BINFO. DIAG_DECL is the declaration to use to print diagnostics.
     474                 :             :    Return value like perform_access_checks above.
     475                 :             :    If non-NULL, report failures to AFI.  */
     476                 :             : 
     477                 :             : bool
     478                 :   479220591 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
     479                 :             :                                tsubst_flags_t complain,
     480                 :             :                                access_failure_info *afi)
     481                 :             : {
     482                 :   479220591 :   int i;
     483                 :   479220591 :   deferred_access *ptr;
     484                 :   479220591 :   deferred_access_check *chk;
     485                 :             : 
     486                 :             :   /* Exit if we are in a context that no access checking is performed.  */
     487                 :   479220591 :   if (deferred_access_no_check)
     488                 :             :     return true;
     489                 :             : 
     490                 :   458443735 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     491                 :             : 
     492                 :   458443735 :   ptr = &deferred_access_stack->last ();
     493                 :             : 
     494                 :             :   /* If we are not supposed to defer access checks, just check now.  */
     495                 :   458443735 :   if (ptr->deferring_access_checks_kind == dk_no_deferred)
     496                 :             :     {
     497                 :   252775020 :       bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
     498                 :   403529536 :       return (complain & tf_error) ? true : ok;
     499                 :             :     }
     500                 :             : 
     501                 :             :   /* See if we are already going to perform this check.  */
     502                 :   241651084 :   FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
     503                 :             :     {
     504                 :    47696355 :       if (chk->decl == decl && chk->binfo == binfo &&
     505                 :    11714620 :           chk->diag_decl == diag_decl)
     506                 :             :         {
     507                 :             :           return true;
     508                 :             :         }
     509                 :             :     }
     510                 :             :   /* If not, record the check.  */
     511                 :   193954729 :   deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
     512                 :   193954729 :   vec_safe_push (ptr->deferred_access_checks, new_access);
     513                 :             : 
     514                 :   193954729 :   return true;
     515                 :             : }
     516                 :             : 
     517                 :             : /* Returns nonzero if the current statement is a full expression,
     518                 :             :    i.e. temporaries created during that statement should be destroyed
     519                 :             :    at the end of the statement.  */
     520                 :             : 
     521                 :             : int
     522                 :  1145108435 : stmts_are_full_exprs_p (void)
     523                 :             : {
     524                 :  1145108435 :   return current_stmt_tree ()->stmts_are_full_exprs_p;
     525                 :             : }
     526                 :             : 
     527                 :             : /* T is a statement.  Add it to the statement-tree.  This is the C++
     528                 :             :    version.  The C/ObjC frontends have a slightly different version of
     529                 :             :    this function.  */
     530                 :             : 
     531                 :             : tree
     532                 :  1059220430 : add_stmt (tree t)
     533                 :             : {
     534                 :  1059220430 :   enum tree_code code = TREE_CODE (t);
     535                 :             : 
     536                 :  1059220430 :   if (EXPR_P (t) && code != LABEL_EXPR)
     537                 :             :     {
     538                 :  1016730429 :       if (!EXPR_HAS_LOCATION (t))
     539                 :   165565049 :         SET_EXPR_LOCATION (t, input_location);
     540                 :             : 
     541                 :             :       /* When we expand a statement-tree, we must know whether or not the
     542                 :             :          statements are full-expressions.  We record that fact here.  */
     543                 :  1016730429 :       if (STATEMENT_CODE_P (TREE_CODE (t)))
     544                 :   260282592 :         STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
     545                 :             :     }
     546                 :             : 
     547                 :  1059220430 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     548                 :     3729362 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     549                 :             : 
     550                 :             :   /* Add T to the statement-tree.  Non-side-effect statements need to be
     551                 :             :      recorded during statement expressions.  */
     552                 :  1059220430 :   gcc_checking_assert (!stmt_list_stack->is_empty ());
     553                 :  1059220430 :   append_to_statement_list_force (t, &cur_stmt_list);
     554                 :             : 
     555                 :  1059220430 :   return t;
     556                 :             : }
     557                 :             : 
     558                 :             : /* Returns the stmt_tree to which statements are currently being added.  */
     559                 :             : 
     560                 :             : stmt_tree
     561                 :  6185366185 : current_stmt_tree (void)
     562                 :             : {
     563                 :  6185366185 :   return (cfun
     564                 :  6169836442 :           ? &cfun->language->base.x_stmt_tree
     565                 :  6185366185 :           : &scope_chain->x_stmt_tree);
     566                 :             : }
     567                 :             : 
     568                 :             : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR.  */
     569                 :             : 
     570                 :             : static tree
     571                 :      338903 : maybe_cleanup_point_expr (tree expr)
     572                 :             : {
     573                 :      338903 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     574                 :      331321 :     expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
     575                 :      338903 :   return expr;
     576                 :             : }
     577                 :             : 
     578                 :             : /* Like maybe_cleanup_point_expr except have the type of the new expression be
     579                 :             :    void so we don't need to create a temporary variable to hold the inner
     580                 :             :    expression.  The reason why we do this is because the original type might be
     581                 :             :    an aggregate and we cannot create a temporary variable for that type.  */
     582                 :             : 
     583                 :             : tree
     584                 :   262678253 : maybe_cleanup_point_expr_void (tree expr)
     585                 :             : {
     586                 :   262678253 :   if (!processing_template_decl && stmts_are_full_exprs_p ())
     587                 :    92717547 :     expr = fold_build_cleanup_point_expr (void_type_node, expr);
     588                 :   262678253 :   return expr;
     589                 :             : }
     590                 :             : 
     591                 :             : 
     592                 :             : 
     593                 :             : /* Create a declaration statement for the declaration given by the DECL.  */
     594                 :             : 
     595                 :             : void
     596                 :    87271060 : add_decl_expr (tree decl)
     597                 :             : {
     598                 :    87271060 :   tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
     599                 :    87271060 :   if (DECL_INITIAL (decl)
     600                 :    87271060 :       || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
     601                 :     9580201 :     r = maybe_cleanup_point_expr_void (r);
     602                 :    87271060 :   add_stmt (r);
     603                 :    87271060 : }
     604                 :             : 
     605                 :             : /* Set EXPR_LOCATION on one cleanup T to LOC.  */
     606                 :             : 
     607                 :             : static void
     608                 :     5338148 : set_one_cleanup_loc (tree t, location_t loc)
     609                 :             : {
     610                 :     5338148 :   if (!t)
     611                 :             :     return;
     612                 :     5338148 :   if (TREE_CODE (t) != POSTCONDITION_STMT)
     613                 :     5338148 :     protected_set_expr_location (t, loc);
     614                 :             :   /* Avoid locus differences for C++ cdtor calls depending on whether
     615                 :             :      cdtor_returns_this: a conversion to void is added to discard the return
     616                 :             :      value, and this conversion ends up carrying the location, and when it
     617                 :             :      gets discarded, the location is lost.  So hold it in the call as well.  */
     618                 :     5338148 :   if (TREE_CODE (t) == NOP_EXPR
     619                 :           0 :       && TREE_TYPE (t) == void_type_node
     620                 :     5338148 :       && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
     621                 :           0 :     protected_set_expr_location (TREE_OPERAND (t, 0), loc);
     622                 :             : }
     623                 :             : 
     624                 :             : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC.  */
     625                 :             : 
     626                 :             : static void
     627                 :  1004614344 : set_cleanup_locs (tree stmts, location_t loc)
     628                 :             : {
     629                 :  1009952492 :   if (TREE_CODE (stmts) == CLEANUP_STMT)
     630                 :             :     {
     631                 :     5338148 :       set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
     632                 :     5338148 :       set_cleanup_locs (CLEANUP_BODY (stmts), loc);
     633                 :             :     }
     634                 :  1004614344 :   else if (TREE_CODE (stmts) == STATEMENT_LIST)
     635                 :   900273085 :     for (tree stmt : tsi_range (stmts))
     636                 :   694364429 :       set_cleanup_locs (stmt, loc);
     637                 :  1004614344 : }
     638                 :             : 
     639                 :             : /* True iff the innermost block scope is a try block.  */
     640                 :             : 
     641                 :             : static bool
     642                 :   310249915 : at_try_scope ()
     643                 :             : {
     644                 :   310249915 :   cp_binding_level *b = current_binding_level;
     645                 :   310250185 :   while (b && b->kind == sk_cleanup)
     646                 :         270 :     b = b->level_chain;
     647                 :   310249915 :   return b && b->kind == sk_try;
     648                 :             : }
     649                 :             : 
     650                 :             : /* Finish a scope.  */
     651                 :             : 
     652                 :             : tree
     653                 :   310249915 : do_poplevel (tree stmt_list)
     654                 :             : {
     655                 :   310249915 :   tree block = NULL;
     656                 :             : 
     657                 :   310249915 :   bool was_try = at_try_scope ();
     658                 :             : 
     659                 :   310249915 :   if (stmts_are_full_exprs_p ())
     660                 :   310228877 :     block = poplevel (kept_level_p (), 1, 0);
     661                 :             : 
     662                 :             :   /* This needs to come after poplevel merges sk_cleanup statement_lists.  */
     663                 :   310249915 :   maybe_splice_retval_cleanup (stmt_list, was_try);
     664                 :             : 
     665                 :   310249915 :   stmt_list = pop_stmt_list (stmt_list);
     666                 :             : 
     667                 :             :   /* input_location is the last token of the scope, usually a }.  */
     668                 :   310249915 :   set_cleanup_locs (stmt_list, input_location);
     669                 :             : 
     670                 :   310249915 :   if (!processing_template_decl)
     671                 :             :     {
     672                 :    96108247 :       stmt_list = c_build_bind_expr (input_location, block, stmt_list);
     673                 :             :       /* ??? See c_end_compound_stmt re statement expressions.  */
     674                 :             :     }
     675                 :             : 
     676                 :   310249915 :   return stmt_list;
     677                 :             : }
     678                 :             : 
     679                 :             : /* Begin a new scope.  */
     680                 :             : 
     681                 :             : tree
     682                 :   310240337 : do_pushlevel (scope_kind sk)
     683                 :             : {
     684                 :   310240337 :   tree ret = push_stmt_list ();
     685                 :   310240337 :   if (stmts_are_full_exprs_p ())
     686                 :   310228937 :     begin_scope (sk, NULL);
     687                 :   310240337 :   return ret;
     688                 :             : }
     689                 :             : 
     690                 :             : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
     691                 :             :    when the current scope is exited.  EH_ONLY is true when this is not
     692                 :             :    meant to apply to normal control flow transfer.  DECL is the VAR_DECL
     693                 :             :    being cleaned up, if any, or null for temporaries or subobjects.  */
     694                 :             : 
     695                 :             : void
     696                 :     5338009 : push_cleanup (tree decl, tree cleanup, bool eh_only)
     697                 :             : {
     698                 :     5338009 :   tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
     699                 :     5338009 :   CLEANUP_EH_ONLY (stmt) = eh_only;
     700                 :     5338009 :   add_stmt (stmt);
     701                 :     5338009 :   CLEANUP_BODY (stmt) = push_stmt_list ();
     702                 :     5338009 : }
     703                 :             : 
     704                 :             : /* Simple infinite loop tracking for -Wreturn-type.  We keep a stack of all
     705                 :             :    the current loops, represented by 'NULL_TREE' if we've seen a possible
     706                 :             :    exit, and 'error_mark_node' if not.  This is currently used only to
     707                 :             :    suppress the warning about a function with no return statements, and
     708                 :             :    therefore we don't bother noting returns as possible exits.  We also
     709                 :             :    don't bother with gotos.  */
     710                 :             : 
     711                 :             : static void
     712                 :    15550047 : begin_maybe_infinite_loop (tree cond)
     713                 :             : {
     714                 :             :   /* Only track this while parsing a function, not during instantiation.  */
     715                 :    15550047 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     716                 :     2253123 :                 && !processing_template_decl))
     717                 :             :     return;
     718                 :    13296393 :   bool maybe_infinite = true;
     719                 :    13296393 :   if (cond)
     720                 :             :     {
     721                 :    13074309 :       cond = fold_non_dependent_expr (cond);
     722                 :    13074309 :       maybe_infinite = integer_nonzerop (cond);
     723                 :             :     }
     724                 :    26370702 :   vec_safe_push (cp_function_chain->infinite_loops,
     725                 :    13296393 :                  maybe_infinite ? error_mark_node : NULL_TREE);
     726                 :             : 
     727                 :             : }
     728                 :             : 
     729                 :             : /* A break is a possible exit for the current loop.  */
     730                 :             : 
     731                 :             : void
     732                 :     1381376 : break_maybe_infinite_loop (void)
     733                 :             : {
     734                 :     1381376 :   if (!cfun)
     735                 :             :     return;
     736                 :     1381376 :   cp_function_chain->infinite_loops->last() = NULL_TREE;
     737                 :             : }
     738                 :             : 
     739                 :             : /* If we reach the end of the loop without seeing a possible exit, we have
     740                 :             :    an infinite loop.  */
     741                 :             : 
     742                 :             : static void
     743                 :    15550047 : end_maybe_infinite_loop (tree cond)
     744                 :             : {
     745                 :    15550047 :   if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
     746                 :     2253123 :                 && !processing_template_decl))
     747                 :             :     return;
     748                 :    13296393 :   tree current = cp_function_chain->infinite_loops->pop();
     749                 :    13296393 :   if (current != NULL_TREE)
     750                 :             :     {
     751                 :     4159665 :       cond = fold_non_dependent_expr (cond);
     752                 :     4159665 :       if (integer_nonzerop (cond))
     753                 :      215600 :         current_function_infinite_loop = 1;
     754                 :             :     }
     755                 :             : }
     756                 :             : 
     757                 :             : /* Begin a conditional that might contain a declaration.  When generating
     758                 :             :    normal code, we want the declaration to appear before the statement
     759                 :             :    containing the conditional.  When generating template code, we want the
     760                 :             :    conditional to be rendered as the raw DECL_EXPR.  */
     761                 :             : 
     762                 :             : static void
     763                 :    67557700 : begin_cond (tree *cond_p)
     764                 :             : {
     765                 :    67557700 :   if (processing_template_decl)
     766                 :    47092239 :     *cond_p = push_stmt_list ();
     767                 :    67557700 : }
     768                 :             : 
     769                 :             : /* Finish such a conditional.  */
     770                 :             : 
     771                 :             : static void
     772                 :    67557700 : finish_cond (tree *cond_p, tree expr)
     773                 :             : {
     774                 :    67557700 :   if (processing_template_decl)
     775                 :             :     {
     776                 :    47092239 :       tree cond = pop_stmt_list (*cond_p);
     777                 :             : 
     778                 :    47092239 :       if (expr == NULL_TREE)
     779                 :             :         /* Empty condition in 'for'.  */
     780                 :      215298 :         gcc_assert (empty_expr_stmt_p (cond));
     781                 :    46876941 :       else if (check_for_bare_parameter_packs (expr))
     782                 :           0 :         expr = error_mark_node;
     783                 :    46876941 :       else if (!empty_expr_stmt_p (cond))
     784                 :      620076 :         expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
     785                 :             :     }
     786                 :    67557700 :   *cond_p = expr;
     787                 :    67557700 : }
     788                 :             : 
     789                 :             : /* If loop condition specifies a conditional with a declaration,
     790                 :             :    such as
     791                 :             :             while (A x = 42) { }
     792                 :             :             for (; A x = 42;) { }
     793                 :             :    move the *BODY_P statements as a BIND_EXPR into {FOR,WHILE}_COND_PREP
     794                 :             :    and if there are any CLEANUP_STMT at the end, remember their count in
     795                 :             :    {FOR,WHILE}_COND_CLEANUP.
     796                 :             :    genericize_c_loop will then handle it appropriately.  In particular,
     797                 :             :    the {FOR,WHILE}_COND, {FOR,WHILE}_BODY, if used continue label and
     798                 :             :    FOR_EXPR will be appended into the {FOR,WHILE}_COND_PREP BIND_EXPR,
     799                 :             :    but it can't be done too early because only the actual body should
     800                 :             :    bind BREAK_STMT and CONTINUE_STMT to the inner loop.
     801                 :             :    The statement list for *BODY will be empty if the conditional did
     802                 :             :    not declare anything.  */
     803                 :             : 
     804                 :             : static void
     805                 :    10637156 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
     806                 :             : {
     807                 :    10637156 :   if (!TREE_SIDE_EFFECTS (*body_p))
     808                 :    10627075 :     return;
     809                 :             : 
     810                 :       10081 :   gcc_assert (!processing_template_decl);
     811                 :       10081 :   *prep_p = *body_p;
     812                 :       10081 :   if (*prep_p != cur_stmt_list)
     813                 :             :     {
     814                 :             :       /* There can be just one CLEANUP_STMT, or there could be multiple
     815                 :             :          nested CLEANUP_STMTs, e.g. for structured bindings used as
     816                 :             :          condition.  */
     817                 :          97 :       gcc_assert (stmt_list_stack->length () > 1);
     818                 :          97 :       for (unsigned i = stmt_list_stack->length () - 2; ; --i)
     819                 :             :         {
     820                 :         109 :           tree t = (*stmt_list_stack)[i];
     821                 :         109 :           tree_stmt_iterator last = tsi_last (t);
     822                 :         218 :           gcc_assert (tsi_one_before_end_p (last)
     823                 :             :                       && TREE_CODE (tsi_stmt (last)) == CLEANUP_STMT
     824                 :             :                       && (CLEANUP_BODY (tsi_stmt (last))
     825                 :             :                           == (*stmt_list_stack)[i + 1])
     826                 :             :                       && !CLEANUP_EH_ONLY (tsi_stmt (last)));
     827                 :         109 :           if (t == *prep_p)
     828                 :             :             {
     829                 :          97 :               *cleanup_p = build_int_cst (long_unsigned_type_node,
     830                 :          97 :                                           stmt_list_stack->length () - 1 - i);
     831                 :          97 :               break;
     832                 :             :             }
     833                 :          12 :           gcc_assert (i >= 1);
     834                 :          12 :         }
     835                 :             :     }
     836                 :       10081 :   current_binding_level->keep = true;
     837                 :       10081 :   tree_stmt_iterator iter = tsi_last (cur_stmt_list);
     838                 :             :   /* Temporarily store in {FOR,WHILE}_BODY the last statement of
     839                 :             :      the innnermost statement list or NULL if it has no statement.
     840                 :             :      This is used in finish_loop_cond_prep to find out the splitting
     841                 :             :      point and then {FOR,WHILE}_BODY will be changed to the actual
     842                 :             :      body.  */
     843                 :       10081 :   if (tsi_end_p (iter))
     844                 :          91 :     *body_p = NULL_TREE;
     845                 :             :   else
     846                 :        9990 :     *body_p = tsi_stmt (iter);
     847                 :             : }
     848                 :             : 
     849                 :             : /* Finalize {FOR,WHILE}_{BODY,COND_PREP} after the loop body.
     850                 :             :    The above function initialized *BODY_P to the last statement
     851                 :             :    in *PREP_P at that point.
     852                 :             :    Call do_poplevel on *PREP_P and move everything after that
     853                 :             :    former last statement into *BODY_P.  genericize_c_loop
     854                 :             :    will later put those parts back together.
     855                 :             :    CLEANUP is {FOR,WHILE}_COND_CLEANUP.  */
     856                 :             : 
     857                 :             : static void
     858                 :       10081 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
     859                 :             : {
     860                 :       10081 :   *prep_p = do_poplevel (*prep_p);
     861                 :       10081 :   gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
     862                 :       10081 :   if (BIND_EXPR_BODY (*prep_p) == *body_p)
     863                 :             :     {
     864                 :          18 :       gcc_assert (cleanup == NULL_TREE);
     865                 :          18 :       *body_p = build_empty_stmt (input_location);
     866                 :         109 :       return;
     867                 :             :     }
     868                 :       10063 :   tree stmt_list = BIND_EXPR_BODY (*prep_p);
     869                 :       10063 :   gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
     870                 :       10063 :   if (cleanup)
     871                 :             :     {
     872                 :          97 :       tree_stmt_iterator iter = tsi_last (stmt_list);
     873                 :          97 :       gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
     874                 :         109 :       for (unsigned depth = tree_to_uhwi (cleanup); depth > 1; --depth)
     875                 :             :         {
     876                 :          12 :           gcc_assert (TREE_CODE (CLEANUP_BODY (tsi_stmt (iter)))
     877                 :             :                       == STATEMENT_LIST);
     878                 :          12 :           iter = tsi_last (CLEANUP_BODY (tsi_stmt (iter)));
     879                 :          12 :           gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
     880                 :             :         }
     881                 :          97 :       if (*body_p == NULL_TREE)
     882                 :             :         {
     883                 :          91 :           *body_p = CLEANUP_BODY (tsi_stmt (iter));
     884                 :          91 :           CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
     885                 :          91 :           return;
     886                 :             :         }
     887                 :           6 :       stmt_list = CLEANUP_BODY (tsi_stmt (iter));
     888                 :             :     }
     889                 :        9972 :   tree_stmt_iterator iter = tsi_start (stmt_list);
     890                 :       10168 :   while (tsi_stmt (iter) != *body_p)
     891                 :         196 :     tsi_next (&iter);
     892                 :        9972 :   *body_p = tsi_split_stmt_list (input_location, iter);
     893                 :             : }
     894                 :             : 
     895                 :             : /* Finish a goto-statement.  */
     896                 :             : 
     897                 :             : tree
     898                 :        2343 : finish_goto_stmt (tree destination)
     899                 :             : {
     900                 :        2343 :   if (identifier_p (destination))
     901                 :        2209 :     destination = lookup_label (destination);
     902                 :             : 
     903                 :             :   /* We warn about unused labels with -Wunused.  That means we have to
     904                 :             :      mark the used labels as used.  */
     905                 :        2343 :   if (TREE_CODE (destination) == LABEL_DECL)
     906                 :        2209 :     TREE_USED (destination) = 1;
     907                 :             :   else
     908                 :             :     {
     909                 :         134 :       destination = mark_rvalue_use (destination);
     910                 :         134 :       if (!processing_template_decl)
     911                 :             :         {
     912                 :         114 :           destination = cp_convert (ptr_type_node, destination,
     913                 :             :                                     tf_warning_or_error);
     914                 :         114 :           if (error_operand_p (destination))
     915                 :             :             return NULL_TREE;
     916                 :         105 :           destination
     917                 :         105 :             = fold_build_cleanup_point_expr (TREE_TYPE (destination),
     918                 :             :                                              destination);
     919                 :             :         }
     920                 :             :     }
     921                 :             : 
     922                 :        2334 :   add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
     923                 :             : 
     924                 :        2334 :   tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
     925                 :        2334 :   check_goto (&TREE_OPERAND (stmt, 0));
     926                 :             : 
     927                 :        2334 :   return add_stmt (stmt);
     928                 :             : }
     929                 :             : 
     930                 :             : /* Returns true if T corresponds to an assignment operator expression.  */
     931                 :             : 
     932                 :             : static bool
     933                 :      774251 : is_assignment_op_expr_p (tree t)
     934                 :             : {
     935                 :      774251 :   if (t == NULL_TREE)
     936                 :             :     return false;
     937                 :             : 
     938                 :      774251 :   if (TREE_CODE (t) == MODIFY_EXPR
     939                 :      774251 :       || (TREE_CODE (t) == MODOP_EXPR
     940                 :         330 :           && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
     941                 :             :     return true;
     942                 :             : 
     943                 :      773564 :   tree call = extract_call_expr (t);
     944                 :      773564 :   if (call == NULL_TREE
     945                 :      119362 :       || call == error_mark_node
     946                 :      892926 :       || !CALL_EXPR_OPERATOR_SYNTAX (call))
     947                 :             :     return false;
     948                 :             : 
     949                 :        4116 :   tree fndecl = cp_get_callee_fndecl_nofold (call);
     950                 :        4116 :   return fndecl != NULL_TREE
     951                 :        4085 :     && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
     952                 :        4167 :     && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
     953                 :             : }
     954                 :             : 
     955                 :             : /* Return true if TYPE is a class type that is convertible to
     956                 :             :    and assignable from bool.  */
     957                 :             : 
     958                 :             : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
     959                 :             : 
     960                 :             : static bool
     961                 :          60 : boolish_class_type_p (tree type)
     962                 :             : {
     963                 :          60 :   type = TYPE_MAIN_VARIANT (type);
     964                 :          60 :   if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
     965                 :             :     return false;
     966                 :             : 
     967                 :          78 :   if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
     968                 :          27 :     return *r;
     969                 :             : 
     970                 :          18 :   tree ops;
     971                 :          18 :   bool has_bool_assignment = false;
     972                 :          18 :   bool has_bool_conversion = false;
     973                 :             : 
     974                 :          18 :   ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
     975                 :          55 :   for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
     976                 :             :     {
     977                 :          29 :       op = STRIP_TEMPLATE (op);
     978                 :          29 :       if (TREE_CODE (op) != FUNCTION_DECL)
     979                 :           0 :         continue;
     980                 :          29 :       tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
     981                 :          29 :       tree parm_type = non_reference (TREE_TYPE (parm));
     982                 :          29 :       if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
     983                 :             :         {
     984                 :             :           has_bool_assignment = true;
     985                 :             :           break;
     986                 :             :         }
     987                 :             :     }
     988                 :             : 
     989                 :          18 :   if (has_bool_assignment)
     990                 :             :     {
     991                 :           3 :       ops = lookup_conversions (type);
     992                 :           3 :       for (; ops; ops = TREE_CHAIN (ops))
     993                 :             :         {
     994                 :           3 :           tree op = TREE_VALUE (ops);
     995                 :           3 :           if (!DECL_NONCONVERTING_P (op)
     996                 :           3 :               && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
     997                 :             :             {
     998                 :             :               has_bool_conversion = true;
     999                 :             :               break;
    1000                 :             :             }
    1001                 :             :         }
    1002                 :             :     }
    1003                 :             : 
    1004                 :          18 :   bool boolish = has_bool_assignment && has_bool_conversion;
    1005                 :          18 :   hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
    1006                 :          18 :   return boolish;
    1007                 :             : }
    1008                 :             : 
    1009                 :             : 
    1010                 :             : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
    1011                 :             :    boolean context where 'a == b' might have been intended).
    1012                 :             :    NESTED_P is true if T is the RHS of another assignment.  */
    1013                 :             : 
    1014                 :             : void
    1015                 :    65635855 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
    1016                 :             :                                        tsubst_flags_t complain)
    1017                 :             : {
    1018                 :    65635855 :   tree type = TREE_TYPE (t);
    1019                 :    65635855 :   t = STRIP_REFERENCE_REF (t);
    1020                 :             : 
    1021                 :    65635855 :   if ((complain & tf_warning)
    1022                 :    65596582 :       && warn_parentheses
    1023                 :      774251 :       && is_assignment_op_expr_p (t)
    1024                 :             :       /* A parenthesized expression would've had this warning
    1025                 :             :          suppressed by finish_parenthesized_expr.  */
    1026                 :         738 :       && !warning_suppressed_p (t, OPT_Wparentheses)
    1027                 :             :       /* In c = a = b, don't warn if a has type bool or bool-like class.  */
    1028                 :    65636208 :       && (!nested_p
    1029                 :         182 :           || (TREE_CODE (type) != BOOLEAN_TYPE
    1030                 :          60 :               && !boolish_class_type_p (type))))
    1031                 :             :     {
    1032                 :         219 :       warning_at (cp_expr_loc_or_input_loc (t), OPT_Wparentheses,
    1033                 :             :                   "suggest parentheses around assignment used as truth value");
    1034                 :         219 :       suppress_warning (t, OPT_Wparentheses);
    1035                 :             :     }
    1036                 :    65635855 : }
    1037                 :             : 
    1038                 :             : /* Helper class for saving/restoring ANNOTATE_EXPRs.  For a tree node t, users
    1039                 :             :    can construct one of these like so:
    1040                 :             : 
    1041                 :             :      annotate_saver s (&t);
    1042                 :             : 
    1043                 :             :    and t will be updated to have any annotations removed.  The user can then
    1044                 :             :    transform t, and later restore the ANNOTATE_EXPRs with:
    1045                 :             : 
    1046                 :             :      t = s.restore (t).
    1047                 :             : 
    1048                 :             :    The intent is to ensure that any ANNOTATE_EXPRs remain the outermost
    1049                 :             :    expressions following any operations on t.  */
    1050                 :             : 
    1051                 :             : class annotate_saver {
    1052                 :             :   /* The chain of saved annotations, if there were any.  Otherwise null.  */
    1053                 :             :   tree m_annotations;
    1054                 :             : 
    1055                 :             :   /* If M_ANNOTATIONS is non-null, then M_INNER points to TREE_OPERAND (A, 0)
    1056                 :             :      for the innermost annotation A.  */
    1057                 :             :   tree *m_inner;
    1058                 :             : 
    1059                 :             : public:
    1060                 :             :   annotate_saver (tree *);
    1061                 :             :   tree restore (tree);
    1062                 :             : };
    1063                 :             : 
    1064                 :             : /* If *COND is an ANNOTATE_EXPR, walk through the chain of annotations, and set
    1065                 :             :    *COND equal to the first non-ANNOTATE_EXPR (saving a pointer to the
    1066                 :             :    original chain of annotations for later use in restore).  */
    1067                 :             : 
    1068                 :    41719620 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
    1069                 :             : {
    1070                 :    41719620 :   tree *t = cond;
    1071                 :    41722837 :   while (TREE_CODE (*t) == ANNOTATE_EXPR)
    1072                 :        3217 :     t = &TREE_OPERAND (*t, 0);
    1073                 :             : 
    1074                 :    41719620 :   if (t != cond)
    1075                 :             :     {
    1076                 :        3214 :       m_annotations = *cond;
    1077                 :        3214 :       *cond = *t;
    1078                 :        3214 :       m_inner = t;
    1079                 :             :     }
    1080                 :    41719620 : }
    1081                 :             : 
    1082                 :             : /* If we didn't strip any annotations on construction, return NEW_INNER
    1083                 :             :    unmodified.  Otherwise, wrap the saved annotations around NEW_INNER (updating
    1084                 :             :    the types and flags of the annotations if needed) and return the resulting
    1085                 :             :    expression.  */
    1086                 :             : 
    1087                 :             : tree
    1088                 :    41719620 : annotate_saver::restore (tree new_inner)
    1089                 :             : {
    1090                 :    41719620 :   if (!m_annotations)
    1091                 :             :     return new_inner;
    1092                 :             : 
    1093                 :             :   /* If the type of the inner expression changed, we need to update the types
    1094                 :             :      of all the ANNOTATE_EXPRs.  We may need to update the flags too, but we
    1095                 :             :      assume they only change if the type of the inner expression changes.
    1096                 :             :      The flag update logic assumes that the other operands to the
    1097                 :             :      ANNOTATE_EXPRs are always INTEGER_CSTs.  */
    1098                 :        3214 :   if (TREE_TYPE (new_inner) != TREE_TYPE (*m_inner))
    1099                 :             :     {
    1100                 :           6 :       const bool new_readonly
    1101                 :           6 :         = TREE_READONLY (new_inner) || CONSTANT_CLASS_P (new_inner);
    1102                 :             : 
    1103                 :          12 :       for (tree c = m_annotations; c != *m_inner; c = TREE_OPERAND (c, 0))
    1104                 :             :         {
    1105                 :           6 :           gcc_checking_assert (TREE_CODE (c) == ANNOTATE_EXPR
    1106                 :             :                                && TREE_CODE (TREE_OPERAND (c, 1)) == INTEGER_CST
    1107                 :             :                                && TREE_CODE (TREE_OPERAND (c, 2)) == INTEGER_CST);
    1108                 :           6 :           TREE_TYPE (c) = TREE_TYPE (new_inner);
    1109                 :           6 :           TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (new_inner);
    1110                 :           6 :           TREE_READONLY (c) = new_readonly;
    1111                 :             :         }
    1112                 :             :     }
    1113                 :             : 
    1114                 :        3214 :   *m_inner = new_inner;
    1115                 :        3214 :   return m_annotations;
    1116                 :             : }
    1117                 :             : 
    1118                 :             : /* COND is the condition-expression for an if, while, etc.,
    1119                 :             :    statement.  Convert it to a boolean value, if appropriate.
    1120                 :             :    In addition, verify sequence points if -Wsequence-point is enabled.  */
    1121                 :             : 
    1122                 :             : tree
    1123                 :    71742764 : maybe_convert_cond (tree cond)
    1124                 :             : {
    1125                 :             :   /* Empty conditions remain empty.  */
    1126                 :    71742764 :   if (!cond)
    1127                 :             :     return NULL_TREE;
    1128                 :             : 
    1129                 :             :   /* Wait until we instantiate templates before doing conversion.  */
    1130                 :    71464503 :   if (type_dependent_expression_p (cond))
    1131                 :    29744883 :     return cond;
    1132                 :             : 
    1133                 :             :   /* Strip any ANNOTATE_EXPRs from COND.  */
    1134                 :    41719620 :   annotate_saver annotations (&cond);
    1135                 :             : 
    1136                 :             :   /* For structured binding used in condition, the conversion needs to be
    1137                 :             :      evaluated before the individual variables are initialized in the
    1138                 :             :      std::tuple_{size,elemenet} case.  cp_finish_decomp saved the conversion
    1139                 :             :      result in a TARGET_EXPR, pick it up from there.  */
    1140                 :      348428 :   if (DECL_DECOMPOSITION_P (cond)
    1141                 :         217 :       && DECL_DECOMP_IS_BASE (cond)
    1142                 :         217 :       && DECL_DECOMP_BASE (cond)
    1143                 :    41719834 :       && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1144                 :          56 :     cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1145                 :             : 
    1146                 :    41719620 :   if (warn_sequence_point && !processing_template_decl)
    1147                 :      302562 :     verify_sequence_points (cond);
    1148                 :             : 
    1149                 :    41719620 :   maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
    1150                 :             :                                          tf_warning_or_error);
    1151                 :             : 
    1152                 :             :   /* Do the conversion.  */
    1153                 :    41719620 :   cond = convert_from_reference (cond);
    1154                 :    41719620 :   cond = condition_conversion (cond);
    1155                 :             : 
    1156                 :             :   /* Restore any ANNOTATE_EXPRs around COND.  */
    1157                 :    41719620 :   return annotations.restore (cond);
    1158                 :             : }
    1159                 :             : 
    1160                 :             : /* Finish an expression-statement, whose EXPRESSION is as indicated.  */
    1161                 :             : 
    1162                 :             : tree
    1163                 :   141700057 : finish_expr_stmt (tree expr)
    1164                 :             : {
    1165                 :   141700057 :   tree r = NULL_TREE;
    1166                 :   141700057 :   location_t loc = EXPR_LOCATION (expr);
    1167                 :             : 
    1168                 :   141496040 :   if (expr != NULL_TREE)
    1169                 :             :     {
    1170                 :             :       /* If we ran into a problem, make sure we complained.  */
    1171                 :   141699902 :       gcc_assert (expr != error_mark_node || seen_error ());
    1172                 :             : 
    1173                 :   141699902 :       if (!processing_template_decl)
    1174                 :             :         {
    1175                 :    52577323 :           if (warn_sequence_point)
    1176                 :      775713 :             verify_sequence_points (expr);
    1177                 :    52577323 :           expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1178                 :             :         }
    1179                 :    89122579 :       else if (!type_dependent_expression_p (expr))
    1180                 :    18355188 :         convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
    1181                 :             : 
    1182                 :   141699899 :       if (check_for_bare_parameter_packs (expr))
    1183                 :          24 :         expr = error_mark_node;
    1184                 :             : 
    1185                 :             :       /* Simplification of inner statement expressions, compound exprs,
    1186                 :             :          etc can result in us already having an EXPR_STMT or other statement
    1187                 :             :          tree.  Don't wrap them in EXPR_STMT.  */
    1188                 :   141699899 :       if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    1189                 :             :         {
    1190                 :   141699726 :           if (TREE_CODE (expr) != EXPR_STMT
    1191                 :   139851061 :               && !STATEMENT_CLASS_P (expr)
    1192                 :   139846910 :               && TREE_CODE (expr) != STATEMENT_LIST)
    1193                 :   139682018 :             expr = build_stmt (loc, EXPR_STMT, expr);
    1194                 :   141699726 :           expr = maybe_cleanup_point_expr_void (expr);
    1195                 :             :         }
    1196                 :             : 
    1197                 :   141699899 :       r = add_stmt (expr);
    1198                 :             :     }
    1199                 :             : 
    1200                 :   141700054 :   return r;
    1201                 :             : }
    1202                 :             : 
    1203                 :             : 
    1204                 :             : /* Begin an if-statement.  Returns a newly created IF_STMT if
    1205                 :             :    appropriate.  */
    1206                 :             : 
    1207                 :             : tree
    1208                 :    56419671 : begin_if_stmt (void)
    1209                 :             : {
    1210                 :    56419671 :   tree r, scope;
    1211                 :    56419671 :   scope = do_pushlevel (sk_cond);
    1212                 :    56419671 :   r = build_stmt (input_location, IF_STMT, NULL_TREE,
    1213                 :             :                   NULL_TREE, NULL_TREE, scope);
    1214                 :    56419671 :   current_binding_level->this_entity = r;
    1215                 :    56419671 :   begin_cond (&IF_COND (r));
    1216                 :    56419671 :   return r;
    1217                 :             : }
    1218                 :             : 
    1219                 :             : /* Returns true if FN, a CALL_EXPR, is a call to
    1220                 :             :    std::is_constant_evaluated or __builtin_is_constant_evaluated.  */
    1221                 :             : 
    1222                 :             : static bool
    1223                 :      231373 : is_std_constant_evaluated_p (tree fn)
    1224                 :             : {
    1225                 :             :   /* std::is_constant_evaluated takes no arguments.  */
    1226                 :      231373 :   if (call_expr_nargs (fn) != 0)
    1227                 :             :     return false;
    1228                 :             : 
    1229                 :       79452 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
    1230                 :       79452 :   if (fndecl == NULL_TREE)
    1231                 :             :     return false;
    1232                 :             : 
    1233                 :       21292 :   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    1234                 :             :                          BUILT_IN_FRONTEND))
    1235                 :             :     return true;
    1236                 :             : 
    1237                 :       21267 :   if (!decl_in_std_namespace_p (fndecl))
    1238                 :             :     return false;
    1239                 :             : 
    1240                 :        7569 :   tree name = DECL_NAME (fndecl);
    1241                 :        7569 :   return name && id_equal (name, "is_constant_evaluated");
    1242                 :             : }
    1243                 :             : 
    1244                 :             : /* Callback function for maybe_warn_for_constant_evaluated that looks
    1245                 :             :    for calls to std::is_constant_evaluated in TP.  */
    1246                 :             : 
    1247                 :             : static tree
    1248                 :     4311083 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
    1249                 :             : {
    1250                 :     4311083 :   tree t = *tp;
    1251                 :             : 
    1252                 :     4311083 :   if (TYPE_P (t) || TREE_CONSTANT (t))
    1253                 :             :     {
    1254                 :      744623 :       *walk_subtrees = false;
    1255                 :      744623 :       return NULL_TREE;
    1256                 :             :     }
    1257                 :             : 
    1258                 :     3566460 :   switch (TREE_CODE (t))
    1259                 :             :     {
    1260                 :      231373 :     case CALL_EXPR:
    1261                 :      231373 :       if (is_std_constant_evaluated_p (t))
    1262                 :             :         return t;
    1263                 :             :       break;
    1264                 :           6 :     case EXPR_STMT:
    1265                 :             :       /* Don't warn in statement expressions.  */
    1266                 :           6 :       *walk_subtrees = false;
    1267                 :           6 :       return NULL_TREE;
    1268                 :             :     default:
    1269                 :             :       break;
    1270                 :             :     }
    1271                 :             : 
    1272                 :             :   return NULL_TREE;
    1273                 :             : }
    1274                 :             : 
    1275                 :             : /* In certain contexts, std::is_constant_evaluated() is always true (for
    1276                 :             :    instance, in a consteval function or in a constexpr if), or always false
    1277                 :             :    (e.g., in a non-constexpr non-consteval function) so give the user a clue.  */
    1278                 :             : 
    1279                 :             : static void
    1280                 :    56498295 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
    1281                 :             :                                    bool trivial_infinite)
    1282                 :             : {
    1283                 :    56498295 :   if (!warn_tautological_compare)
    1284                 :             :     return;
    1285                 :             : 
    1286                 :             :   /* Suppress warning for std::is_constant_evaluated if the conditional
    1287                 :             :      comes from a macro.  */
    1288                 :     1304214 :   if (from_macro_expansion_at (EXPR_LOCATION (cond)))
    1289                 :             :     return;
    1290                 :             : 
    1291                 :      545702 :   cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
    1292                 :             :                                           NULL);
    1293                 :      545702 :   if (cond)
    1294                 :             :     {
    1295                 :        1080 :       if (constexpr_if)
    1296                 :          32 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1297                 :             :                     "%<std::is_constant_evaluated%> always evaluates to "
    1298                 :             :                     "true in %<if constexpr%>");
    1299                 :        1048 :       else if (trivial_infinite)
    1300                 :             :         {
    1301                 :           8 :           auto_diagnostic_group d;
    1302                 :           8 :           if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1303                 :             :                           "%<std::is_constant_evaluated%> evaluates to "
    1304                 :             :                           "true when checking if trivially empty iteration "
    1305                 :             :                           "statement is trivial infinite loop")
    1306                 :           8 :               && !maybe_constexpr_fn (current_function_decl))
    1307                 :           8 :             inform (EXPR_LOCATION (cond),
    1308                 :             :                     "and evaluates to false when actually evaluating "
    1309                 :             :                     "the condition in non-%<constexpr%> function");
    1310                 :           8 :         }
    1311                 :        1040 :       else if (!maybe_constexpr_fn (current_function_decl))
    1312                 :          22 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1313                 :             :                     "%<std::is_constant_evaluated%> always evaluates to "
    1314                 :             :                     "false in a non-%<constexpr%> function");
    1315                 :        2036 :       else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1316                 :           3 :         warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
    1317                 :             :                     "%<std::is_constant_evaluated%> always evaluates to "
    1318                 :             :                     "true in a %<consteval%> function");
    1319                 :             :     }
    1320                 :             : }
    1321                 :             : 
    1322                 :             : /* Process the COND of an if-statement, which may be given by
    1323                 :             :    IF_STMT.  */
    1324                 :             : 
    1325                 :             : tree
    1326                 :    56419671 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
    1327                 :             : {
    1328                 :    56419671 :   tree cond = maybe_convert_cond (orig_cond);
    1329                 :    56419671 :   maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
    1330                 :             :                                      /*trivial_infinite=*/false);
    1331                 :    56419671 :   if (IF_STMT_CONSTEXPR_P (if_stmt)
    1332                 :     8578903 :       && !type_dependent_expression_p (cond)
    1333                 :     5776541 :       && require_constant_expression (cond)
    1334                 :     5776513 :       && !instantiation_dependent_expression_p (cond)
    1335                 :             :       /* Wait until instantiation time, since only then COND has been
    1336                 :             :          converted to bool.  */
    1337                 :    59977806 :       && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
    1338                 :             :     {
    1339                 :     3558135 :       cond = instantiate_non_dependent_expr (cond);
    1340                 :     3558135 :       cond = cxx_constant_value (cond);
    1341                 :             :     }
    1342                 :    52861536 :   else if (processing_template_decl)
    1343                 :    38119508 :     cond = orig_cond;
    1344                 :    56419671 :   finish_cond (&IF_COND (if_stmt), cond);
    1345                 :    56419671 :   add_stmt (if_stmt);
    1346                 :    56419671 :   THEN_CLAUSE (if_stmt) = push_stmt_list ();
    1347                 :    56419671 :   return cond;
    1348                 :             : }
    1349                 :             : 
    1350                 :             : /* Finish the then-clause of an if-statement, which may be given by
    1351                 :             :    IF_STMT.  */
    1352                 :             : 
    1353                 :             : tree
    1354                 :    56411315 : finish_then_clause (tree if_stmt)
    1355                 :             : {
    1356                 :    56411315 :   THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
    1357                 :    56411315 :   return if_stmt;
    1358                 :             : }
    1359                 :             : 
    1360                 :             : /* Begin the else-clause of an if-statement.  */
    1361                 :             : 
    1362                 :             : void
    1363                 :    20241781 : begin_else_clause (tree if_stmt)
    1364                 :             : {
    1365                 :    20241781 :   ELSE_CLAUSE (if_stmt) = push_stmt_list ();
    1366                 :    20241781 : }
    1367                 :             : 
    1368                 :             : /* Finish the else-clause of an if-statement, which may be given by
    1369                 :             :    IF_STMT.  */
    1370                 :             : 
    1371                 :             : void
    1372                 :    20241743 : finish_else_clause (tree if_stmt)
    1373                 :             : {
    1374                 :    20241743 :   ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
    1375                 :    20241743 : }
    1376                 :             : 
    1377                 :             : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
    1378                 :             :    read.  */
    1379                 :             : 
    1380                 :             : static tree
    1381                 :   415238473 : maybe_mark_exp_read_r (tree *tp, int *, void *)
    1382                 :             : {
    1383                 :   415238473 :   tree t = *tp;
    1384                 :   415238473 :   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    1385                 :    26255195 :     mark_exp_read (t);
    1386                 :   415238473 :   return NULL_TREE;
    1387                 :             : }
    1388                 :             : 
    1389                 :             : /* Finish an if-statement.  */
    1390                 :             : 
    1391                 :             : void
    1392                 :    56410616 : finish_if_stmt (tree if_stmt)
    1393                 :             : {
    1394                 :    56410616 :   tree scope = IF_SCOPE (if_stmt);
    1395                 :    56410616 :   IF_SCOPE (if_stmt) = NULL;
    1396                 :    56410616 :   if (IF_STMT_CONSTEXPR_P (if_stmt))
    1397                 :             :     {
    1398                 :             :       /* Prevent various -Wunused warnings.  We might not instantiate
    1399                 :             :          either of these branches, so we would not mark the variables
    1400                 :             :          used in that branch as read.  */
    1401                 :     8570547 :       cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
    1402                 :             :                                        maybe_mark_exp_read_r, NULL);
    1403                 :     8570547 :       cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
    1404                 :             :                                        maybe_mark_exp_read_r, NULL);
    1405                 :             :     }
    1406                 :    56410616 :   add_stmt (do_poplevel (scope));
    1407                 :    56410616 : }
    1408                 :             : 
    1409                 :             : /* Determine if iteration statement with *CONDP condition and
    1410                 :             :    loop BODY is trivially empty iteration statement or even
    1411                 :             :    trivial infinite loop.  In the latter case for -ffinite-loops
    1412                 :             :    add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
    1413                 :             :    Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
    1414                 :             :    calls in the condition when needed.  */
    1415                 :             : 
    1416                 :             : static void
    1417                 :    15041568 : finish_loop_cond (tree *condp, tree body)
    1418                 :             : {
    1419                 :    15041568 :   if (TREE_CODE (*condp) == INTEGER_CST)
    1420                 :             :     return;
    1421                 :    10931790 :   bool trivially_empty = expr_first (body) == NULL_TREE;
    1422                 :    10931790 :   bool trivial_infinite = false;
    1423                 :    10931790 :   if (trivially_empty)
    1424                 :             :     {
    1425                 :       71270 :       tree c = fold_non_dependent_expr (*condp, tf_none,
    1426                 :             :                                         /*manifestly_const_eval=*/true);
    1427                 :       71270 :       trivial_infinite = c && integer_nonzerop (c);
    1428                 :             :     }
    1429                 :    10931790 :   if (warn_tautological_compare)
    1430                 :             :     {
    1431                 :       78796 :       tree cond = *condp;
    1432                 :       79151 :       while (TREE_CODE (cond) == ANNOTATE_EXPR)
    1433                 :         355 :         cond = TREE_OPERAND (cond, 0);
    1434                 :       78796 :       if (trivial_infinite
    1435                 :       78860 :           && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1436                 :          64 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1437                 :             :                                            /*trivial_infinite=*/true);
    1438                 :       78732 :       else if (!trivially_empty
    1439                 :         328 :                || !processing_template_decl
    1440                 :       79076 :                || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
    1441                 :       78560 :         maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
    1442                 :             :                                            /*trivial_infinite=*/false);
    1443                 :             :     }
    1444                 :    10931790 :   if (trivial_infinite && flag_finite_loops && !processing_template_decl)
    1445                 :          64 :     *condp = build3 (ANNOTATE_EXPR, TREE_TYPE (*condp), *condp,
    1446                 :             :                      build_int_cst (integer_type_node,
    1447                 :             :                                     annot_expr_maybe_infinite_kind),
    1448                 :             :                      integer_zero_node);
    1449                 :             : }
    1450                 :             : 
    1451                 :             : /* Begin a while-statement.  Returns a newly created WHILE_STMT if
    1452                 :             :    appropriate.  */
    1453                 :             : 
    1454                 :             : tree
    1455                 :     3938294 : begin_while_stmt (void)
    1456                 :             : {
    1457                 :     3938294 :   tree r;
    1458                 :     3938294 :   r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1459                 :             :                   NULL_TREE, NULL_TREE);
    1460                 :     3938294 :   add_stmt (r);
    1461                 :     3938294 :   WHILE_BODY (r) = do_pushlevel (sk_block);
    1462                 :     3938294 :   begin_cond (&WHILE_COND (r));
    1463                 :     3938294 :   return r;
    1464                 :             : }
    1465                 :             : 
    1466                 :             : /* Process the COND of a while-statement, which may be given by
    1467                 :             :    WHILE_STMT.  */
    1468                 :             : 
    1469                 :             : void
    1470                 :     3938294 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
    1471                 :             :                         tree unroll, bool novector)
    1472                 :             : {
    1473                 :     3938294 :   cond = maybe_convert_cond (cond);
    1474                 :     3938294 :   finish_cond (&WHILE_COND (while_stmt), cond);
    1475                 :     3938294 :   begin_maybe_infinite_loop (cond);
    1476                 :     3938294 :   if (ivdep && cond != error_mark_node)
    1477                 :          24 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1478                 :          12 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1479                 :          12 :                                       WHILE_COND (while_stmt),
    1480                 :             :                                       build_int_cst (integer_type_node,
    1481                 :             :                                                      annot_expr_ivdep_kind),
    1482                 :             :                                       integer_zero_node);
    1483                 :     3938294 :   if (unroll && cond != error_mark_node)
    1484                 :       25850 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1485                 :       12925 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1486                 :       12925 :                                       WHILE_COND (while_stmt),
    1487                 :             :                                       build_int_cst (integer_type_node,
    1488                 :             :                                                      annot_expr_unroll_kind),
    1489                 :             :                                       unroll);
    1490                 :     3938294 :   if (novector && cond != error_mark_node)
    1491                 :          42 :     WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
    1492                 :          21 :                                       TREE_TYPE (WHILE_COND (while_stmt)),
    1493                 :          21 :                                       WHILE_COND (while_stmt),
    1494                 :             :                                       build_int_cst (integer_type_node,
    1495                 :             :                                                      annot_expr_no_vector_kind),
    1496                 :             :                                       integer_zero_node);
    1497                 :     3938294 :   adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
    1498                 :             :                          &WHILE_COND_PREP (while_stmt),
    1499                 :             :                          &WHILE_COND_CLEANUP (while_stmt));
    1500                 :     3938294 : }
    1501                 :             : 
    1502                 :             : /* Finish a while-statement, which may be given by WHILE_STMT.  */
    1503                 :             : 
    1504                 :             : void
    1505                 :     3938294 : finish_while_stmt (tree while_stmt)
    1506                 :             : {
    1507                 :     3938294 :   end_maybe_infinite_loop (boolean_true_node);
    1508                 :     3938294 :   if (WHILE_COND_PREP (while_stmt))
    1509                 :        9907 :     finish_loop_cond_prep (&WHILE_BODY (while_stmt),
    1510                 :             :                            &WHILE_COND_PREP (while_stmt),
    1511                 :        9907 :                            WHILE_COND_CLEANUP (while_stmt));
    1512                 :             :   else
    1513                 :     3928387 :     WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
    1514                 :     3938294 :   finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
    1515                 :     3938294 : }
    1516                 :             : 
    1517                 :             : /* Begin a do-statement.  Returns a newly created DO_STMT if
    1518                 :             :    appropriate.  */
    1519                 :             : 
    1520                 :             : tree
    1521                 :     4682673 : begin_do_stmt (void)
    1522                 :             : {
    1523                 :     4682673 :   tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
    1524                 :             :                        NULL_TREE);
    1525                 :     4682673 :   begin_maybe_infinite_loop (boolean_true_node);
    1526                 :     4682673 :   add_stmt (r);
    1527                 :     4682673 :   DO_BODY (r) = push_stmt_list ();
    1528                 :     4682673 :   return r;
    1529                 :             : }
    1530                 :             : 
    1531                 :             : /* Finish the body of a do-statement, which may be given by DO_STMT.  */
    1532                 :             : 
    1533                 :             : void
    1534                 :     4682673 : finish_do_body (tree do_stmt)
    1535                 :             : {
    1536                 :     4682673 :   tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
    1537                 :             : 
    1538                 :     4682673 :   if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
    1539                 :      394437 :     body = STATEMENT_LIST_TAIL (body)->stmt;
    1540                 :             : 
    1541                 :     4682673 :   if (IS_EMPTY_STMT (body))
    1542                 :          28 :     warning (OPT_Wempty_body,
    1543                 :             :             "suggest explicit braces around empty body in %<do%> statement");
    1544                 :     4682673 : }
    1545                 :             : 
    1546                 :             : /* Finish a do-statement, which may be given by DO_STMT, and whose
    1547                 :             :    COND is as indicated.  */
    1548                 :             : 
    1549                 :             : void
    1550                 :     4682673 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
    1551                 :             :                 bool novector)
    1552                 :             : {
    1553                 :     4682673 :   cond = maybe_convert_cond (cond);
    1554                 :     4682673 :   end_maybe_infinite_loop (cond);
    1555                 :             :   /* Unlike other iteration statements, the condition may not contain
    1556                 :             :      a declaration, so we don't call finish_cond which checks for
    1557                 :             :      unexpanded parameter packs.  */
    1558                 :     4682673 :   if (check_for_bare_parameter_packs (cond))
    1559                 :           3 :     cond = error_mark_node;
    1560                 :     4682673 :   if (ivdep && cond != error_mark_node)
    1561                 :           3 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1562                 :             :                    build_int_cst (integer_type_node, annot_expr_ivdep_kind),
    1563                 :             :                    integer_zero_node);
    1564                 :     4682673 :   if (unroll && cond != error_mark_node)
    1565                 :           9 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1566                 :             :                    build_int_cst (integer_type_node, annot_expr_unroll_kind),
    1567                 :             :                    unroll);
    1568                 :     4682673 :   if (novector && cond != error_mark_node)
    1569                 :           0 :     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
    1570                 :             :                    build_int_cst (integer_type_node, annot_expr_no_vector_kind),
    1571                 :             :                    integer_zero_node);
    1572                 :     4682673 :   DO_COND (do_stmt) = cond;
    1573                 :     4682673 :   tree do_body = DO_BODY (do_stmt);
    1574                 :     4682645 :   if (CONVERT_EXPR_P (do_body)
    1575                 :          28 :       && integer_zerop (TREE_OPERAND (do_body, 0))
    1576                 :     4682701 :       && VOID_TYPE_P (TREE_TYPE (do_body)))
    1577                 :             :     do_body = NULL_TREE;
    1578                 :     4682673 :   finish_loop_cond (&DO_COND (do_stmt), do_body);
    1579                 :     4682673 : }
    1580                 :             : 
    1581                 :             : /* Finish a return-statement.  The EXPRESSION returned, if any, is as
    1582                 :             :    indicated.  */
    1583                 :             : 
    1584                 :             : tree
    1585                 :   105024279 : finish_return_stmt (tree expr)
    1586                 :             : {
    1587                 :   105024279 :   tree r;
    1588                 :   105024279 :   bool no_warning;
    1589                 :   105024279 :   bool dangling;
    1590                 :             : 
    1591                 :   105024279 :   expr = check_return_expr (expr, &no_warning, &dangling);
    1592                 :             : 
    1593                 :   105024279 :   if (error_operand_p (expr)
    1594                 :   105024279 :       || (flag_openmp && !check_omp_return ()))
    1595                 :             :     {
    1596                 :             :       /* Suppress -Wreturn-type for this function.  */
    1597                 :        1198 :       if (warn_return_type)
    1598                 :        1192 :         suppress_warning (current_function_decl, OPT_Wreturn_type);
    1599                 :        1198 :       return error_mark_node;
    1600                 :             :     }
    1601                 :             : 
    1602                 :   105023081 :   if (!processing_template_decl)
    1603                 :             :     {
    1604                 :    37057142 :       if (warn_sequence_point)
    1605                 :      985734 :         verify_sequence_points (expr);
    1606                 :             :     }
    1607                 :             : 
    1608                 :   105023081 :   r = build_stmt (input_location, RETURN_EXPR, expr);
    1609                 :   105023081 :   RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
    1610                 :   105023081 :   if (no_warning)
    1611                 :          35 :     suppress_warning (r, OPT_Wreturn_type);
    1612                 :   105023081 :   r = maybe_cleanup_point_expr_void (r);
    1613                 :   105023081 :   r = add_stmt (r);
    1614                 :             : 
    1615                 :   105023081 :   return r;
    1616                 :             : }
    1617                 :             : 
    1618                 :             : /* Begin the scope of a for-statement or a range-for-statement.
    1619                 :             :    Both the returned trees are to be used in a call to
    1620                 :             :    begin_for_stmt or begin_range_for_stmt.  */
    1621                 :             : 
    1622                 :             : tree
    1623                 :     6929080 : begin_for_scope (tree *init)
    1624                 :             : {
    1625                 :     6929080 :   tree scope = do_pushlevel (sk_for);
    1626                 :             : 
    1627                 :     6929080 :   if (processing_template_decl)
    1628                 :     5538732 :     *init = push_stmt_list ();
    1629                 :             :   else
    1630                 :     1390348 :     *init = NULL_TREE;
    1631                 :             : 
    1632                 :     6929080 :   return scope;
    1633                 :             : }
    1634                 :             : 
    1635                 :             : /* Begin a for-statement.  Returns a new FOR_STMT.
    1636                 :             :    SCOPE and INIT should be the return of begin_for_scope,
    1637                 :             :    or both NULL_TREE  */
    1638                 :             : 
    1639                 :             : tree
    1640                 :     6698862 : begin_for_stmt (tree scope, tree init)
    1641                 :             : {
    1642                 :     6698862 :   tree r;
    1643                 :             : 
    1644                 :     6698862 :   r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
    1645                 :             :                   NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
    1646                 :             :                   NULL_TREE, NULL_TREE);
    1647                 :             : 
    1648                 :     6698862 :   if (scope == NULL_TREE)
    1649                 :             :     {
    1650                 :     1192365 :       gcc_assert (!init);
    1651                 :     1192365 :       scope = begin_for_scope (&init);
    1652                 :             :     }
    1653                 :             : 
    1654                 :     6698862 :   FOR_INIT_STMT (r) = init;
    1655                 :     6698862 :   FOR_SCOPE (r) = scope;
    1656                 :             : 
    1657                 :     6698862 :   return r;
    1658                 :             : }
    1659                 :             : 
    1660                 :             : /* Finish the init-statement of a for-statement, which may be
    1661                 :             :    given by FOR_STMT.  */
    1662                 :             : 
    1663                 :             : void
    1664                 :     6698862 : finish_init_stmt (tree for_stmt)
    1665                 :             : {
    1666                 :     6698862 :   if (processing_template_decl)
    1667                 :     5308514 :     FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
    1668                 :     6698862 :   add_stmt (for_stmt);
    1669                 :     6698862 :   FOR_BODY (for_stmt) = do_pushlevel (sk_block);
    1670                 :     6698862 :   begin_cond (&FOR_COND (for_stmt));
    1671                 :     6698862 : }
    1672                 :             : 
    1673                 :             : /* Finish the COND of a for-statement, which may be given by
    1674                 :             :    FOR_STMT.  */
    1675                 :             : 
    1676                 :             : void
    1677                 :     6698862 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
    1678                 :             :                  bool novector)
    1679                 :             : {
    1680                 :     6698862 :   cond = maybe_convert_cond (cond);
    1681                 :     6698862 :   finish_cond (&FOR_COND (for_stmt), cond);
    1682                 :     6698862 :   begin_maybe_infinite_loop (cond);
    1683                 :     6698862 :   if (ivdep && cond != error_mark_node)
    1684                 :          68 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1685                 :          34 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1686                 :          34 :                                   FOR_COND (for_stmt),
    1687                 :             :                                   build_int_cst (integer_type_node,
    1688                 :             :                                                  annot_expr_ivdep_kind),
    1689                 :             :                                   integer_zero_node);
    1690                 :     6698862 :   if (unroll && cond != error_mark_node)
    1691                 :         408 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1692                 :         204 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1693                 :         204 :                                   FOR_COND (for_stmt),
    1694                 :             :                                   build_int_cst (integer_type_node,
    1695                 :             :                                                  annot_expr_unroll_kind),
    1696                 :             :                                   unroll);
    1697                 :     6698862 :   if (novector && cond && cond != error_mark_node)
    1698                 :         268 :     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
    1699                 :         134 :                                   TREE_TYPE (FOR_COND (for_stmt)),
    1700                 :         134 :                                   FOR_COND (for_stmt),
    1701                 :             :                                   build_int_cst (integer_type_node,
    1702                 :             :                                                  annot_expr_no_vector_kind),
    1703                 :             :                                   integer_zero_node);
    1704                 :     6698862 :   adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
    1705                 :             :                          &FOR_COND_CLEANUP (for_stmt));
    1706                 :     6698862 : }
    1707                 :             : 
    1708                 :             : /* Finish the increment-EXPRESSION in a for-statement, which may be
    1709                 :             :    given by FOR_STMT.  */
    1710                 :             : 
    1711                 :             : void
    1712                 :     6693213 : finish_for_expr (tree expr, tree for_stmt)
    1713                 :             : {
    1714                 :     6693213 :   if (!expr)
    1715                 :             :     return;
    1716                 :             :   /* If EXPR is an overloaded function, issue an error; there is no
    1717                 :             :      context available to use to perform overload resolution.  */
    1718                 :     6324737 :   if (type_unknown_p (expr))
    1719                 :             :     {
    1720                 :           6 :       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
    1721                 :           6 :       expr = error_mark_node;
    1722                 :             :     }
    1723                 :     6324737 :   if (!processing_template_decl)
    1724                 :             :     {
    1725                 :     1326771 :       if (warn_sequence_point)
    1726                 :       13841 :         verify_sequence_points (expr);
    1727                 :     1326771 :       expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
    1728                 :             :                               tf_warning_or_error);
    1729                 :             :     }
    1730                 :     4997966 :   else if (!type_dependent_expression_p (expr))
    1731                 :     1935745 :     convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
    1732                 :     6324737 :   expr = maybe_cleanup_point_expr_void (expr);
    1733                 :     6324737 :   if (check_for_bare_parameter_packs (expr))
    1734                 :           0 :     expr = error_mark_node;
    1735                 :     6324737 :   FOR_EXPR (for_stmt) = expr;
    1736                 :             : }
    1737                 :             : 
    1738                 :             : /* During parsing of the body, range for uses "__for_{range,begin,end} "
    1739                 :             :    decl names to make those unaccessible by code in the body.
    1740                 :             :    Find those decls and store into RANGE_FOR_DECL array, so that they
    1741                 :             :    can be changed later to ones with underscore instead of space, so that
    1742                 :             :    it can be inspected in the debugger.  */
    1743                 :             : 
    1744                 :             : void
    1745                 :     6929193 : find_range_for_decls (tree range_for_decl[3])
    1746                 :             : {
    1747                 :     6929193 :   gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
    1748                 :             :               && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
    1749                 :             :               && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
    1750                 :             :               && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
    1751                 :             :               && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
    1752                 :    27716772 :   for (int i = 0; i < 3; i++)
    1753                 :             :     {
    1754                 :    20787579 :       tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
    1755                 :    20787579 :       if (IDENTIFIER_BINDING (id)
    1756                 :    20787579 :           && IDENTIFIER_BINDING (id)->scope == current_binding_level)
    1757                 :             :         {
    1758                 :      203116 :           range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
    1759                 :      203116 :           gcc_assert (VAR_P (range_for_decl[i])
    1760                 :             :                       && DECL_ARTIFICIAL (range_for_decl[i]));
    1761                 :             :         }
    1762                 :             :     }
    1763                 :     6929193 : }
    1764                 :             : 
    1765                 :             : /* Finish the body of a for-statement, which may be given by
    1766                 :             :    FOR_STMT.  The increment-EXPR for the loop must be
    1767                 :             :    provided.
    1768                 :             :    It can also finish RANGE_FOR_STMT. */
    1769                 :             : 
    1770                 :             : void
    1771                 :     6929080 : finish_for_stmt (tree for_stmt)
    1772                 :             : {
    1773                 :     6929080 :   end_maybe_infinite_loop (boolean_true_node);
    1774                 :             : 
    1775                 :     6929080 :   if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
    1776                 :      230218 :     RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
    1777                 :             :   else
    1778                 :             :     {
    1779                 :     6698862 :       if (FOR_COND_PREP (for_stmt))
    1780                 :         174 :         finish_loop_cond_prep (&FOR_BODY (for_stmt),
    1781                 :             :                                &FOR_COND_PREP (for_stmt),
    1782                 :         174 :                                FOR_COND_CLEANUP (for_stmt));
    1783                 :             :       else
    1784                 :     6698688 :         FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
    1785                 :     6698862 :       if (FOR_COND (for_stmt))
    1786                 :     6420601 :         finish_loop_cond (&FOR_COND (for_stmt),
    1787                 :     6420601 :                           FOR_EXPR (for_stmt) ? integer_one_node
    1788                 :      133086 :                                               : FOR_BODY (for_stmt));
    1789                 :             :     }
    1790                 :             : 
    1791                 :             :   /* Pop the scope for the body of the loop.  */
    1792                 :     6929080 :   tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
    1793                 :     6929080 :                      ? &RANGE_FOR_SCOPE (for_stmt)
    1794                 :     6698862 :                      : &FOR_SCOPE (for_stmt));
    1795                 :     6929080 :   tree scope = *scope_ptr;
    1796                 :     6929080 :   *scope_ptr = NULL;
    1797                 :             : 
    1798                 :             :   /* During parsing of the body, range for uses "__for_{range,begin,end} "
    1799                 :             :      decl names to make those unaccessible by code in the body.
    1800                 :             :      Change it to ones with underscore instead of space, so that it can
    1801                 :             :      be inspected in the debugger.  */
    1802                 :     6929080 :   tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
    1803                 :     6929080 :   find_range_for_decls (range_for_decl);
    1804                 :             : 
    1805                 :     6929080 :   add_stmt (do_poplevel (scope));
    1806                 :             : 
    1807                 :             :   /* If we're being called from build_vec_init, don't mess with the names of
    1808                 :             :      the variables for an enclosing range-for.  */
    1809                 :     6929080 :   if (!stmts_are_full_exprs_p ())
    1810                 :        5649 :     return;
    1811                 :             : 
    1812                 :    27693724 :   for (int i = 0; i < 3; i++)
    1813                 :    20770293 :     if (range_for_decl[i])
    1814                 :      203000 :       DECL_NAME (range_for_decl[i])
    1815                 :      203000 :         = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
    1816                 :             : }
    1817                 :             : 
    1818                 :             : /* Begin a range-for-statement.  Returns a new RANGE_FOR_STMT.
    1819                 :             :    SCOPE and INIT should be the return of begin_for_scope,
    1820                 :             :    or both NULL_TREE  .
    1821                 :             :    To finish it call finish_for_stmt(). */
    1822                 :             : 
    1823                 :             : tree
    1824                 :      230218 : begin_range_for_stmt (tree scope, tree init)
    1825                 :             : {
    1826                 :      230218 :   begin_maybe_infinite_loop (boolean_false_node);
    1827                 :             : 
    1828                 :      230218 :   tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
    1829                 :             :                        NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
    1830                 :             : 
    1831                 :      230218 :   if (scope == NULL_TREE)
    1832                 :             :     {
    1833                 :           6 :       gcc_assert (!init);
    1834                 :           6 :       scope = begin_for_scope (&init);
    1835                 :             :     }
    1836                 :             : 
    1837                 :             :   /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it.  */
    1838                 :      230218 :   RANGE_FOR_INIT_STMT (r) = init;
    1839                 :      230218 :   RANGE_FOR_SCOPE (r) = scope;
    1840                 :             : 
    1841                 :      230218 :   return r;
    1842                 :             : }
    1843                 :             : 
    1844                 :             : /* Finish the head of a range-based for statement, which may
    1845                 :             :    be given by RANGE_FOR_STMT.  DECL must be the declaration
    1846                 :             :    and EXPR must be the loop expression. */
    1847                 :             : 
    1848                 :             : void
    1849                 :      230218 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
    1850                 :             : {
    1851                 :      230218 :   if (processing_template_decl)
    1852                 :      460436 :     RANGE_FOR_INIT_STMT (range_for_stmt)
    1853                 :      460436 :       = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
    1854                 :      230218 :   RANGE_FOR_DECL (range_for_stmt) = decl;
    1855                 :      230218 :   RANGE_FOR_EXPR (range_for_stmt) = expr;
    1856                 :      230218 :   add_stmt (range_for_stmt);
    1857                 :      230218 :   RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
    1858                 :      230218 : }
    1859                 :             : 
    1860                 :             : /* Begin the scope of an expansion-statement.  */
    1861                 :             : 
    1862                 :             : tree
    1863                 :        1098 : begin_template_for_scope (tree *init)
    1864                 :             : {
    1865                 :        1098 :   tree scope = do_pushlevel (sk_template_for);
    1866                 :             : 
    1867                 :        1098 :   if (processing_template_decl)
    1868                 :         351 :     *init = push_stmt_list ();
    1869                 :             :   else
    1870                 :         747 :     *init = NULL_TREE;
    1871                 :             : 
    1872                 :        1098 :   return scope;
    1873                 :             : }
    1874                 :             : 
    1875                 :             : /* Finish a break-statement.  */
    1876                 :             : 
    1877                 :             : tree
    1878                 :     3557636 : finish_break_stmt (void)
    1879                 :             : {
    1880                 :             :   /* In switch statements break is sometimes stylistically used after
    1881                 :             :      a return statement.  This can lead to spurious warnings about
    1882                 :             :      control reaching the end of a non-void function when it is
    1883                 :             :      inlined.  Note that we are calling block_may_fallthru with
    1884                 :             :      language specific tree nodes; this works because
    1885                 :             :      block_may_fallthru returns true when given something it does not
    1886                 :             :      understand.  */
    1887                 :     3557636 :   if (!block_may_fallthru (cur_stmt_list))
    1888                 :         791 :     return void_node;
    1889                 :     3556845 :   note_break_stmt ();
    1890                 :     3556845 :   return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
    1891                 :             : }
    1892                 :             : 
    1893                 :             : /* Finish a continue-statement.  */
    1894                 :             : 
    1895                 :             : tree
    1896                 :      163803 : finish_continue_stmt (void)
    1897                 :             : {
    1898                 :      163803 :   return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
    1899                 :             : }
    1900                 :             : 
    1901                 :             : /* Begin a switch-statement.  Returns a new SWITCH_STMT if
    1902                 :             :    appropriate.  */
    1903                 :             : 
    1904                 :             : tree
    1905                 :      500873 : begin_switch_stmt (void)
    1906                 :             : {
    1907                 :      500873 :   tree r, scope;
    1908                 :             : 
    1909                 :      500873 :   scope = do_pushlevel (sk_cond);
    1910                 :      500873 :   r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
    1911                 :             :                   scope, NULL_TREE);
    1912                 :             : 
    1913                 :      500873 :   begin_cond (&SWITCH_STMT_COND (r));
    1914                 :             : 
    1915                 :      500873 :   return r;
    1916                 :             : }
    1917                 :             : 
    1918                 :             : /* Finish the cond of a switch-statement.  */
    1919                 :             : 
    1920                 :             : void
    1921                 :      500873 : finish_switch_cond (tree cond, tree switch_stmt)
    1922                 :             : {
    1923                 :      500873 :   tree orig_type = NULL;
    1924                 :             : 
    1925                 :      500873 :   if (!processing_template_decl)
    1926                 :             :     {
    1927                 :             :       /* Convert the condition to an integer or enumeration type.  */
    1928                 :      316033 :       tree orig_cond = cond;
    1929                 :             :       /* For structured binding used in condition, the conversion needs to be
    1930                 :             :          evaluated before the individual variables are initialized in the
    1931                 :             :          std::tuple_{size,elemenet} case.  cp_finish_decomp saved the
    1932                 :             :          conversion result in a TARGET_EXPR, pick it up from there.  */
    1933                 :         122 :       if (DECL_DECOMPOSITION_P (cond)
    1934                 :          57 :           && DECL_DECOMP_IS_BASE (cond)
    1935                 :          57 :           && DECL_DECOMP_BASE (cond)
    1936                 :      316087 :           && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
    1937                 :          18 :         cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
    1938                 :      316033 :       cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
    1939                 :      316033 :       if (cond == NULL_TREE)
    1940                 :             :         {
    1941                 :          42 :           error_at (cp_expr_loc_or_input_loc (orig_cond),
    1942                 :             :                     "switch quantity not an integer");
    1943                 :          27 :           cond = error_mark_node;
    1944                 :             :         }
    1945                 :             :       /* We want unlowered type here to handle enum bit-fields.  */
    1946                 :      316033 :       orig_type = unlowered_expr_type (cond);
    1947                 :      316033 :       if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
    1948                 :      181091 :         orig_type = TREE_TYPE (cond);
    1949                 :      316033 :       if (cond != error_mark_node)
    1950                 :             :         {
    1951                 :             :           /* [stmt.switch]
    1952                 :             : 
    1953                 :             :              Integral promotions are performed.  */
    1954                 :      316000 :           cond = perform_integral_promotions (cond);
    1955                 :      316000 :           cond = maybe_cleanup_point_expr (cond);
    1956                 :             :         }
    1957                 :             :     }
    1958                 :      500873 :   if (check_for_bare_parameter_packs (cond))
    1959                 :           0 :     cond = error_mark_node;
    1960                 :      500873 :   else if (!processing_template_decl && warn_sequence_point)
    1961                 :        2654 :     verify_sequence_points (cond);
    1962                 :             : 
    1963                 :      500873 :   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
    1964                 :      500873 :   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
    1965                 :      500873 :   add_stmt (switch_stmt);
    1966                 :      500873 :   push_switch (switch_stmt);
    1967                 :      500873 :   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
    1968                 :      500873 : }
    1969                 :             : 
    1970                 :             : /* Finish the body of a switch-statement, which may be given by
    1971                 :             :    SWITCH_STMT.  The COND to switch on is indicated.  */
    1972                 :             : 
    1973                 :             : void
    1974                 :      500873 : finish_switch_stmt (tree switch_stmt)
    1975                 :             : {
    1976                 :      500873 :   tree scope;
    1977                 :             : 
    1978                 :     1001746 :   SWITCH_STMT_BODY (switch_stmt) =
    1979                 :      500873 :     pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
    1980                 :      500873 :   pop_switch ();
    1981                 :             : 
    1982                 :      500873 :   scope = SWITCH_STMT_SCOPE (switch_stmt);
    1983                 :      500873 :   SWITCH_STMT_SCOPE (switch_stmt) = NULL;
    1984                 :      500873 :   add_stmt (do_poplevel (scope));
    1985                 :      500873 : }
    1986                 :             : 
    1987                 :             : /* Begin a try-block.  Returns a newly-created TRY_BLOCK if
    1988                 :             :    appropriate.  */
    1989                 :             : 
    1990                 :             : tree
    1991                 :     1165952 : begin_try_block (void)
    1992                 :             : {
    1993                 :     1165952 :   tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
    1994                 :     1165952 :   add_stmt (r);
    1995                 :     1165952 :   TRY_STMTS (r) = push_stmt_list ();
    1996                 :     1165952 :   return r;
    1997                 :             : }
    1998                 :             : 
    1999                 :             : /* Likewise, for a function-try-block.  The block returned in
    2000                 :             :    *COMPOUND_STMT is an artificial outer scope, containing the
    2001                 :             :    function-try-block.  */
    2002                 :             : 
    2003                 :             : tree
    2004                 :         339 : begin_function_try_block (tree *compound_stmt)
    2005                 :             : {
    2006                 :         339 :   tree r;
    2007                 :             :   /* This outer scope does not exist in the C++ standard, but we need
    2008                 :             :      a place to put __FUNCTION__ and similar variables.  */
    2009                 :         339 :   *compound_stmt = begin_compound_stmt (0);
    2010                 :         339 :   current_binding_level->artificial = 1;
    2011                 :         339 :   r = begin_try_block ();
    2012                 :         339 :   FN_TRY_BLOCK_P (r) = 1;
    2013                 :         339 :   return r;
    2014                 :             : }
    2015                 :             : 
    2016                 :             : /* Finish a try-block, which may be given by TRY_BLOCK.  */
    2017                 :             : 
    2018                 :             : void
    2019                 :     1165952 : finish_try_block (tree try_block)
    2020                 :             : {
    2021                 :     1165952 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2022                 :     1165952 :   TRY_HANDLERS (try_block) = push_stmt_list ();
    2023                 :     1165952 : }
    2024                 :             : 
    2025                 :             : /* Finish the body of a cleanup try-block, which may be given by
    2026                 :             :    TRY_BLOCK.  */
    2027                 :             : 
    2028                 :             : void
    2029                 :           0 : finish_cleanup_try_block (tree try_block)
    2030                 :             : {
    2031                 :           0 :   TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
    2032                 :           0 : }
    2033                 :             : 
    2034                 :             : /* Finish an implicitly generated try-block, with a cleanup is given
    2035                 :             :    by CLEANUP.  */
    2036                 :             : 
    2037                 :             : void
    2038                 :           0 : finish_cleanup (tree cleanup, tree try_block)
    2039                 :             : {
    2040                 :           0 :   TRY_HANDLERS (try_block) = cleanup;
    2041                 :           0 :   CLEANUP_P (try_block) = 1;
    2042                 :           0 : }
    2043                 :             : 
    2044                 :             : /* Likewise, for a function-try-block.  */
    2045                 :             : 
    2046                 :             : void
    2047                 :         339 : finish_function_try_block (tree try_block)
    2048                 :             : {
    2049                 :         339 :   finish_try_block (try_block);
    2050                 :             :   /* FIXME : something queer about CTOR_INITIALIZER somehow following
    2051                 :             :      the try block, but moving it inside.  */
    2052                 :         339 :   in_function_try_handler = 1;
    2053                 :         339 : }
    2054                 :             : 
    2055                 :             : /* Finish a handler-sequence for a try-block, which may be given by
    2056                 :             :    TRY_BLOCK.  */
    2057                 :             : 
    2058                 :             : void
    2059                 :     1165952 : finish_handler_sequence (tree try_block)
    2060                 :             : {
    2061                 :     1165952 :   TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
    2062                 :     1165952 :   check_handlers (TRY_HANDLERS (try_block));
    2063                 :     1165952 : }
    2064                 :             : 
    2065                 :             : /* Finish the handler-seq for a function-try-block, given by
    2066                 :             :    TRY_BLOCK.  COMPOUND_STMT is the outer block created by
    2067                 :             :    begin_function_try_block.  */
    2068                 :             : 
    2069                 :             : void
    2070                 :         339 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
    2071                 :             : {
    2072                 :         339 :   in_function_try_handler = 0;
    2073                 :         339 :   finish_handler_sequence (try_block);
    2074                 :         339 :   finish_compound_stmt (compound_stmt);
    2075                 :         339 : }
    2076                 :             : 
    2077                 :             : /* Begin a handler.  Returns a HANDLER if appropriate.  */
    2078                 :             : 
    2079                 :             : tree
    2080                 :     1632960 : begin_handler (void)
    2081                 :             : {
    2082                 :     1632960 :   tree r;
    2083                 :             : 
    2084                 :     1632960 :   r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
    2085                 :     1632960 :   add_stmt (r);
    2086                 :             : 
    2087                 :             :   /* Create a binding level for the eh_info and the exception object
    2088                 :             :      cleanup.  */
    2089                 :     1632960 :   HANDLER_BODY (r) = do_pushlevel (sk_catch);
    2090                 :             : 
    2091                 :     1632960 :   return r;
    2092                 :             : }
    2093                 :             : 
    2094                 :             : /* Finish the handler-parameters for a handler, which may be given by
    2095                 :             :    HANDLER.  DECL is the declaration for the catch parameter, or NULL
    2096                 :             :    if this is a `catch (...)' clause.  */
    2097                 :             : 
    2098                 :             : void
    2099                 :     1632960 : finish_handler_parms (tree decl, tree handler)
    2100                 :             : {
    2101                 :     1632960 :   tree type = NULL_TREE;
    2102                 :     1632960 :   if (processing_template_decl)
    2103                 :             :     {
    2104                 :     1485501 :       if (decl)
    2105                 :             :         {
    2106                 :      491324 :           decl = pushdecl (decl);
    2107                 :      491324 :           decl = push_template_decl (decl);
    2108                 :      491324 :           HANDLER_PARMS (handler) = decl;
    2109                 :      491324 :           type = TREE_TYPE (decl);
    2110                 :             :         }
    2111                 :             :     }
    2112                 :             :   else
    2113                 :             :     {
    2114                 :      147459 :       type = expand_start_catch_block (decl);
    2115                 :      147459 :       if (warn_catch_value
    2116                 :        2080 :           && type != NULL_TREE
    2117                 :         709 :           && type != error_mark_node
    2118                 :      148168 :           && !TYPE_REF_P (TREE_TYPE (decl)))
    2119                 :             :         {
    2120                 :         210 :           tree orig_type = TREE_TYPE (decl);
    2121                 :         210 :           if (CLASS_TYPE_P (orig_type))
    2122                 :             :             {
    2123                 :          96 :               if (TYPE_POLYMORPHIC_P (orig_type))
    2124                 :          48 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2125                 :          48 :                             OPT_Wcatch_value_,
    2126                 :             :                             "catching polymorphic type %q#T by value",
    2127                 :             :                             orig_type);
    2128                 :          48 :               else if (warn_catch_value > 1)
    2129                 :          36 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    2130                 :          36 :                             OPT_Wcatch_value_,
    2131                 :             :                             "catching type %q#T by value", orig_type);
    2132                 :             :             }
    2133                 :         114 :           else if (warn_catch_value > 2)
    2134                 :          54 :             warning_at (DECL_SOURCE_LOCATION (decl),
    2135                 :          54 :                         OPT_Wcatch_value_,
    2136                 :             :                         "catching non-reference type %q#T", orig_type);
    2137                 :             :         }
    2138                 :             :     }
    2139                 :     1632960 :   HANDLER_TYPE (handler) = type;
    2140                 :     1632960 : }
    2141                 :             : 
    2142                 :             : /* Finish a handler, which may be given by HANDLER.  The BLOCKs are
    2143                 :             :    the return value from the matching call to finish_handler_parms.  */
    2144                 :             : 
    2145                 :             : void
    2146                 :     1632960 : finish_handler (tree handler)
    2147                 :             : {
    2148                 :     1632960 :   if (!processing_template_decl)
    2149                 :      147459 :     expand_end_catch_block ();
    2150                 :     1632960 :   HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
    2151                 :     1632960 : }
    2152                 :             : 
    2153                 :             : /* Begin a compound statement.  FLAGS contains some bits that control the
    2154                 :             :    behavior and context.  If BCS_NO_SCOPE is set, the compound statement
    2155                 :             :    does not define a scope.  If BCS_FN_BODY is set, this is the outermost
    2156                 :             :    block of a function.  If BCS_TRY_BLOCK is set, this is the block
    2157                 :             :    created on behalf of a TRY statement.  Returns a token to be passed to
    2158                 :             :    finish_compound_stmt.  */
    2159                 :             : 
    2160                 :             : tree
    2161                 :   237981491 : begin_compound_stmt (unsigned int flags)
    2162                 :             : {
    2163                 :   237981491 :   tree r;
    2164                 :             : 
    2165                 :   237981491 :   if (flags & BCS_NO_SCOPE)
    2166                 :             :     {
    2167                 :     4158441 :       r = push_stmt_list ();
    2168                 :     4158441 :       STATEMENT_LIST_NO_SCOPE (r) = 1;
    2169                 :             : 
    2170                 :             :       /* Normally, we try hard to keep the BLOCK for a statement-expression.
    2171                 :             :          But, if it's a statement-expression with a scopeless block, there's
    2172                 :             :          nothing to keep, and we don't want to accidentally keep a block
    2173                 :             :          *inside* the scopeless block.  */
    2174                 :     4158441 :       keep_next_level (false);
    2175                 :             :     }
    2176                 :             :   else
    2177                 :             :     {
    2178                 :   233823050 :       scope_kind sk = sk_block;
    2179                 :   233823050 :       if (flags & BCS_TRY_BLOCK)
    2180                 :             :         sk = sk_try;
    2181                 :   232657098 :       else if (flags & BCS_TRANSACTION)
    2182                 :             :         sk = sk_transaction;
    2183                 :   232656863 :       else if (flags & BCS_STMT_EXPR)
    2184                 :       29006 :         sk = sk_stmt_expr;
    2185                 :   233823050 :       r = do_pushlevel (sk);
    2186                 :             :     }
    2187                 :             : 
    2188                 :             :   /* When processing a template, we need to remember where the braces were,
    2189                 :             :      so that we can set up identical scopes when instantiating the template
    2190                 :             :      later.  BIND_EXPR is a handy candidate for this.
    2191                 :             :      Note that do_poplevel won't create a BIND_EXPR itself here (and thus
    2192                 :             :      result in nested BIND_EXPRs), since we don't build BLOCK nodes when
    2193                 :             :      processing templates.  */
    2194                 :   237981491 :   if (processing_template_decl)
    2195                 :             :     {
    2196                 :   159789450 :       r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
    2197                 :   159789450 :       BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
    2198                 :   159789450 :       BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
    2199                 :   159789450 :       TREE_SIDE_EFFECTS (r) = 1;
    2200                 :             :     }
    2201                 :             : 
    2202                 :   237981491 :   return r;
    2203                 :             : }
    2204                 :             : 
    2205                 :             : /* Finish a compound-statement, which is given by STMT.  */
    2206                 :             : 
    2207                 :             : void
    2208                 :   237981452 : finish_compound_stmt (tree stmt)
    2209                 :             : {
    2210                 :   237981452 :   if (TREE_CODE (stmt) == BIND_EXPR)
    2211                 :             :     {
    2212                 :   159789450 :       tree body = do_poplevel (BIND_EXPR_BODY (stmt));
    2213                 :             :       /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
    2214                 :             :          discard the BIND_EXPR so it can be merged with the containing
    2215                 :             :          STATEMENT_LIST.  */
    2216                 :   159789450 :       if (TREE_CODE (body) == STATEMENT_LIST
    2217                 :   146473693 :           && STATEMENT_LIST_HEAD (body) == NULL
    2218                 :    10704565 :           && !BIND_EXPR_BODY_BLOCK (stmt)
    2219                 :   169981805 :           && !BIND_EXPR_TRY_BLOCK (stmt))
    2220                 :             :         stmt = body;
    2221                 :             :       else
    2222                 :   149597198 :         BIND_EXPR_BODY (stmt) = body;
    2223                 :             :     }
    2224                 :    78192002 :   else if (STATEMENT_LIST_NO_SCOPE (stmt))
    2225                 :     4148803 :     stmt = pop_stmt_list (stmt);
    2226                 :             :   else
    2227                 :             :     {
    2228                 :             :       /* Destroy any ObjC "super" receivers that may have been
    2229                 :             :          created.  */
    2230                 :    74043199 :       objc_clear_super_receiver ();
    2231                 :             : 
    2232                 :    74043199 :       stmt = do_poplevel (stmt);
    2233                 :             :     }
    2234                 :             : 
    2235                 :             :   /* ??? See c_end_compound_stmt wrt statement expressions.  */
    2236                 :   237981452 :   add_stmt (stmt);
    2237                 :   237981452 : }
    2238                 :             : 
    2239                 :             : /* Finish an asm string literal, which can be a string literal
    2240                 :             :    or parenthesized constant expression.  Extract the string literal
    2241                 :             :    from the latter.  */
    2242                 :             : 
    2243                 :             : tree
    2244                 :       47340 : finish_asm_string_expression (location_t loc, tree string)
    2245                 :             : {
    2246                 :       47340 :   if (string == error_mark_node
    2247                 :       47327 :       || TREE_CODE (string) == STRING_CST
    2248                 :         871 :       || processing_template_decl)
    2249                 :             :     return string;
    2250                 :         564 :   string = cxx_constant_value (string, tf_error);
    2251                 :         564 :   if (TREE_CODE (string) == STRING_CST)
    2252                 :          10 :     string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
    2253                 :             :                          string);
    2254                 :         564 :   cexpr_str cstr (string);
    2255                 :         564 :   if (!cstr.type_check (loc))
    2256                 :         171 :     return error_mark_node;
    2257                 :         393 :   if (!cstr.extract (loc, string))
    2258                 :          62 :     string = error_mark_node;
    2259                 :         393 :   return string;
    2260                 :         564 : }
    2261                 :             : 
    2262                 :             : /* Finish an asm-statement, whose components are a STRING, some
    2263                 :             :    OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
    2264                 :             :    LABELS.  Also note whether the asm-statement should be
    2265                 :             :    considered volatile, and whether it is asm inline.  TOPLEV_P
    2266                 :             :    is true if finishing namespace scope extended asm.  */
    2267                 :             : 
    2268                 :             : tree
    2269                 :       28253 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
    2270                 :             :                  tree output_operands, tree input_operands, tree clobbers,
    2271                 :             :                  tree labels, bool inline_p, bool toplev_p)
    2272                 :             : {
    2273                 :       28253 :   tree r;
    2274                 :       28253 :   tree t;
    2275                 :       28253 :   int ninputs = list_length (input_operands);
    2276                 :       28253 :   int noutputs = list_length (output_operands);
    2277                 :             : 
    2278                 :       28253 :   if (!processing_template_decl)
    2279                 :             :     {
    2280                 :       11336 :       const char *constraint;
    2281                 :       11336 :       const char **oconstraints;
    2282                 :       11336 :       bool allows_mem, allows_reg, is_inout;
    2283                 :       11336 :       tree operand;
    2284                 :       11336 :       int i;
    2285                 :             : 
    2286                 :       11336 :       oconstraints = XALLOCAVEC (const char *, noutputs);
    2287                 :             : 
    2288                 :       22570 :       string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
    2289                 :             :                                              string);
    2290                 :       11336 :       if (string == error_mark_node)
    2291                 :         109 :         return error_mark_node;
    2292                 :       33726 :       for (int i = 0; i < 2; ++i)
    2293                 :       75535 :         for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
    2294                 :             :           {
    2295                 :       30567 :             tree s = TREE_VALUE (TREE_PURPOSE (t));
    2296                 :       61116 :             s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2297                 :       30567 :             if (s == error_mark_node)
    2298                 :             :               return error_mark_node;
    2299                 :       30537 :             TREE_VALUE (TREE_PURPOSE (t)) = s;
    2300                 :             :           }
    2301                 :       16076 :       for (t = clobbers; t; t = TREE_CHAIN (t))
    2302                 :             :         {
    2303                 :        4849 :           tree s = TREE_VALUE (t);
    2304                 :        9692 :           s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
    2305                 :        4849 :           TREE_VALUE (t) = s;
    2306                 :             :         }
    2307                 :             : 
    2308                 :       11227 :       string = resolve_asm_operand_names (string, output_operands,
    2309                 :             :                                           input_operands, labels);
    2310                 :             : 
    2311                 :       27594 :       for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
    2312                 :             :         {
    2313                 :       16367 :           operand = TREE_VALUE (t);
    2314                 :             : 
    2315                 :             :           /* ??? Really, this should not be here.  Users should be using a
    2316                 :             :              proper lvalue, dammit.  But there's a long history of using
    2317                 :             :              casts in the output operands.  In cases like longlong.h, this
    2318                 :             :              becomes a primitive form of typechecking -- if the cast can be
    2319                 :             :              removed, then the output operand had a type of the proper width;
    2320                 :             :              otherwise we'll get an error.  Gross, but ...  */
    2321                 :       16367 :           STRIP_NOPS (operand);
    2322                 :             : 
    2323                 :       16367 :           operand = mark_lvalue_use (operand);
    2324                 :             : 
    2325                 :       16367 :           if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
    2326                 :           9 :             operand = error_mark_node;
    2327                 :             : 
    2328                 :       16367 :           if (operand != error_mark_node
    2329                 :       16367 :               && (TREE_READONLY (operand)
    2330                 :       16352 :                   || CP_TYPE_CONST_P (TREE_TYPE (operand))
    2331                 :             :                   /* Functions are not modifiable, even though they are
    2332                 :             :                      lvalues.  */
    2333                 :       16352 :                   || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
    2334                 :             :                   /* If it's an aggregate and any field is const, then it is
    2335                 :             :                      effectively const.  */
    2336                 :       16352 :                   || (CLASS_TYPE_P (TREE_TYPE (operand))
    2337                 :          32 :                       && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
    2338                 :           6 :             cxx_readonly_error (loc, operand, lv_asm);
    2339                 :             : 
    2340                 :             :           tree *op = &operand;
    2341                 :       16374 :           while (TREE_CODE (*op) == COMPOUND_EXPR)
    2342                 :           7 :             op = &TREE_OPERAND (*op, 1);
    2343                 :       16367 :           switch (TREE_CODE (*op))
    2344                 :             :             {
    2345                 :          30 :             case PREINCREMENT_EXPR:
    2346                 :          30 :             case PREDECREMENT_EXPR:
    2347                 :          30 :             case MODIFY_EXPR:
    2348                 :          30 :               *op = genericize_compound_lvalue (*op);
    2349                 :          30 :               op = &TREE_OPERAND (*op, 1);
    2350                 :          30 :               break;
    2351                 :             :             default:
    2352                 :             :               break;
    2353                 :             :             }
    2354                 :             : 
    2355                 :       16367 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2356                 :       16367 :           oconstraints[i] = constraint;
    2357                 :             : 
    2358                 :       16367 :           if (parse_output_constraint (&constraint, i, ninputs, noutputs,
    2359                 :             :                                        &allows_mem, &allows_reg, &is_inout,
    2360                 :             :                                        nullptr))
    2361                 :             :             {
    2362                 :             :               /* If the operand is going to end up in memory,
    2363                 :             :                  mark it addressable.  */
    2364                 :       16358 :               if (!allows_reg && !cxx_mark_addressable (*op))
    2365                 :           0 :                 operand = error_mark_node;
    2366                 :       16358 :               if (allows_reg && toplev_p)
    2367                 :             :                 {
    2368                 :           3 :                   error_at (loc, "constraint allows registers outside of "
    2369                 :             :                                  "a function");
    2370                 :           3 :                   operand = error_mark_node;
    2371                 :             :                 }
    2372                 :             :             }
    2373                 :             :           else
    2374                 :           9 :             operand = error_mark_node;
    2375                 :             : 
    2376                 :         287 :           if (toplev_p && operand != error_mark_node)
    2377                 :             :             {
    2378                 :          21 :               if (TREE_SIDE_EFFECTS (operand))
    2379                 :             :                 {
    2380                 :           0 :                   error_at (loc, "side-effects in output operand outside "
    2381                 :             :                                  "of a function");
    2382                 :           0 :                   operand = error_mark_node;
    2383                 :             :                 }
    2384                 :             :               else
    2385                 :             :                 {
    2386                 :          21 :                   tree addr
    2387                 :          21 :                     = cp_build_addr_expr (operand, tf_warning_or_error);
    2388                 :          21 :                   if (addr == error_mark_node)
    2389                 :           0 :                     operand = error_mark_node;
    2390                 :             :                   else
    2391                 :             :                     {
    2392                 :          21 :                       addr = maybe_constant_value (addr);
    2393                 :          21 :                       if (!initializer_constant_valid_p (addr,
    2394                 :          21 :                                                          TREE_TYPE (addr)))
    2395                 :             :                         {
    2396                 :           3 :                           error_at (loc, "output operand outside of a "
    2397                 :             :                                          "function is not constant");
    2398                 :           3 :                           operand = error_mark_node;
    2399                 :             :                         }
    2400                 :             :                       else
    2401                 :          18 :                         operand = build_fold_indirect_ref (addr);
    2402                 :             :                     }
    2403                 :             :                 }
    2404                 :             :             }
    2405                 :       16346 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2406                 :             :             {
    2407                 :           3 :               error_at (loc, "%<-%> modifier used inside of a function");
    2408                 :           3 :               operand = error_mark_node;
    2409                 :             :             }
    2410                 :             : 
    2411                 :       16367 :           TREE_VALUE (t) = operand;
    2412                 :             :         }
    2413                 :             : 
    2414                 :       25392 :       for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
    2415                 :             :         {
    2416                 :       14165 :           constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
    2417                 :       14165 :           bool constraint_parsed
    2418                 :       14165 :             = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
    2419                 :             :                                       oconstraints, &allows_mem, &allows_reg,
    2420                 :             :                                       nullptr);
    2421                 :             :           /* If the operand is going to end up in memory, don't call
    2422                 :             :              decay_conversion.  */
    2423                 :       14165 :           if (constraint_parsed && !allows_reg && allows_mem)
    2424                 :         156 :             operand = mark_lvalue_use (TREE_VALUE (t));
    2425                 :             :           else
    2426                 :       14009 :             operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
    2427                 :             : 
    2428                 :             :           /* If the type of the operand hasn't been determined (e.g.,
    2429                 :             :              because it involves an overloaded function), then issue
    2430                 :             :              an error message.  There's no context available to
    2431                 :             :              resolve the overloading.  */
    2432                 :       14165 :           if (TREE_TYPE (operand) == unknown_type_node)
    2433                 :             :             {
    2434                 :           3 :               error_at (loc,
    2435                 :             :                         "type of %<asm%> operand %qE could not be determined",
    2436                 :           3 :                         TREE_VALUE (t));
    2437                 :           3 :               operand = error_mark_node;
    2438                 :             :             }
    2439                 :             : 
    2440                 :       14165 :           if (constraint_parsed)
    2441                 :             :             {
    2442                 :             :               /* If the operand is going to end up in memory,
    2443                 :             :                  mark it addressable.  */
    2444                 :       14147 :               if (!allows_reg && allows_mem)
    2445                 :             :                 {
    2446                 :             :                   /* Strip the nops as we allow this case.  FIXME, this really
    2447                 :             :                      should be rejected or made deprecated.  */
    2448                 :         156 :                   STRIP_NOPS (operand);
    2449                 :             : 
    2450                 :         156 :                   tree *op = &operand;
    2451                 :         163 :                   while (TREE_CODE (*op) == COMPOUND_EXPR)
    2452                 :           7 :                     op = &TREE_OPERAND (*op, 1);
    2453                 :         156 :                   switch (TREE_CODE (*op))
    2454                 :             :                     {
    2455                 :          27 :                     case PREINCREMENT_EXPR:
    2456                 :          27 :                     case PREDECREMENT_EXPR:
    2457                 :          27 :                     case MODIFY_EXPR:
    2458                 :          27 :                       *op = genericize_compound_lvalue (*op);
    2459                 :          27 :                       op = &TREE_OPERAND (*op, 1);
    2460                 :          27 :                       break;
    2461                 :             :                     default:
    2462                 :             :                       break;
    2463                 :             :                     }
    2464                 :             : 
    2465                 :         156 :                   if (!cxx_mark_addressable (*op))
    2466                 :           0 :                     operand = error_mark_node;
    2467                 :             :                 }
    2468                 :       13991 :               else if (!allows_reg && !allows_mem)
    2469                 :             :                 {
    2470                 :             :                   /* If constraint allows neither register nor memory,
    2471                 :             :                      try harder to get a constant.  */
    2472                 :         266 :                   tree constop = maybe_constant_value (operand);
    2473                 :         266 :                   if (TREE_CONSTANT (constop))
    2474                 :         239 :                     operand = constop;
    2475                 :             :                 }
    2476                 :       14147 :               if (allows_reg && toplev_p)
    2477                 :             :                 {
    2478                 :           3 :                   error_at (loc, "constraint allows registers outside of "
    2479                 :             :                                  "a function");
    2480                 :           3 :                   operand = error_mark_node;
    2481                 :             :                 }
    2482                 :       14147 :               if (constraint[0] == ':' && operand != error_mark_node)
    2483                 :             :                 {
    2484                 :          45 :                   tree t = operand;
    2485                 :          45 :                   STRIP_NOPS (t);
    2486                 :          45 :                   if (TREE_CODE (t) != ADDR_EXPR
    2487                 :          45 :                       || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
    2488                 :          30 :                            || (VAR_P (TREE_OPERAND (t, 0))
    2489                 :          24 :                                && is_global_var (TREE_OPERAND (t, 0)))))
    2490                 :             :                     {
    2491                 :          15 :                       error_at (loc, "%<:%> constraint operand is not address "
    2492                 :             :                                 "of a function or non-automatic variable");
    2493                 :          15 :                       operand = error_mark_node;
    2494                 :             :                     }
    2495                 :             :                 }
    2496                 :             :             }
    2497                 :             :           else
    2498                 :          18 :             operand = error_mark_node;
    2499                 :             : 
    2500                 :       14165 :           if (toplev_p && operand != error_mark_node)
    2501                 :             :             {
    2502                 :         114 :               if (TREE_SIDE_EFFECTS (operand))
    2503                 :             :                 {
    2504                 :           6 :                   error_at (loc, "side-effects in input operand outside "
    2505                 :             :                                  "of a function");
    2506                 :           6 :                   operand = error_mark_node;
    2507                 :             :                 }
    2508                 :         108 :               else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
    2509                 :             :                 {
    2510                 :          21 :                   tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
    2511                 :          21 :                   if (addr == error_mark_node)
    2512                 :           0 :                     operand = error_mark_node;
    2513                 :             :                   else
    2514                 :             :                     {
    2515                 :          21 :                       addr = maybe_constant_value (addr);
    2516                 :          21 :                       if (!initializer_constant_valid_p (addr,
    2517                 :          21 :                                                          TREE_TYPE (addr)))
    2518                 :             :                         {
    2519                 :           3 :                           error_at (loc, "input operand outside of a "
    2520                 :             :                                          "function is not constant");
    2521                 :           3 :                           operand = error_mark_node;
    2522                 :             :                         }
    2523                 :             :                       else
    2524                 :          18 :                         operand = build_fold_indirect_ref (addr);
    2525                 :             :                     }
    2526                 :             :                 }
    2527                 :             :               else
    2528                 :             :                 {
    2529                 :          87 :                   operand = maybe_constant_value (operand);
    2530                 :          87 :                   if (!initializer_constant_valid_p (operand,
    2531                 :          87 :                                                      TREE_TYPE (operand)))
    2532                 :             :                     {
    2533                 :           3 :                       error_at (loc, "input operand outside of a "
    2534                 :             :                                      "function is not constant");
    2535                 :           3 :                       operand = error_mark_node;
    2536                 :             :                     }
    2537                 :             :                 }
    2538                 :             :             }
    2539                 :       14051 :           else if (operand != error_mark_node && strstr (constraint, "-"))
    2540                 :             :             {
    2541                 :           9 :               error_at (loc, "%<-%> modifier used inside of a function");
    2542                 :           9 :               operand = error_mark_node;
    2543                 :             :             }
    2544                 :             : 
    2545                 :       14165 :           TREE_VALUE (t) = operand;
    2546                 :             :         }
    2547                 :             :     }
    2548                 :             : 
    2549                 :       28144 :   r = build_stmt (loc, ASM_EXPR, string,
    2550                 :             :                   output_operands, input_operands,
    2551                 :             :                   clobbers, labels);
    2552                 :       28144 :   ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
    2553                 :       28144 :   ASM_INLINE_P (r) = inline_p;
    2554                 :       28144 :   if (toplev_p)
    2555                 :             :     {
    2556                 :          96 :       symtab->finalize_toplevel_asm (r);
    2557                 :          96 :       return r;
    2558                 :             :     }
    2559                 :       28048 :   r = maybe_cleanup_point_expr_void (r);
    2560                 :       28048 :   return add_stmt (r);
    2561                 :             : }
    2562                 :             : 
    2563                 :             : /* Finish a label with the indicated NAME.  Returns the new label.  */
    2564                 :             : 
    2565                 :             : tree
    2566                 :        2396 : finish_label_stmt (tree name)
    2567                 :             : {
    2568                 :        2396 :   tree decl = define_label (input_location, name);
    2569                 :             : 
    2570                 :        2396 :   if (decl == error_mark_node)
    2571                 :             :     return error_mark_node;
    2572                 :             : 
    2573                 :        2390 :   add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
    2574                 :             : 
    2575                 :        2390 :   return decl;
    2576                 :             : }
    2577                 :             : 
    2578                 :             : /* Finish a series of declarations for local labels.  G++ allows users
    2579                 :             :    to declare "local" labels, i.e., labels with scope.  This extension
    2580                 :             :    is useful when writing code involving statement-expressions.  */
    2581                 :             : 
    2582                 :             : void
    2583                 :         207 : finish_label_decl (tree name)
    2584                 :             : {
    2585                 :         207 :   if (!at_function_scope_p ())
    2586                 :             :     {
    2587                 :           0 :       error ("%<__label__%> declarations are only allowed in function scopes");
    2588                 :           0 :       return;
    2589                 :             :     }
    2590                 :             : 
    2591                 :         207 :   add_decl_expr (declare_local_label (name));
    2592                 :             : }
    2593                 :             : 
    2594                 :             : /* When DECL goes out of scope, make sure that CLEANUP is executed.  */
    2595                 :             : 
    2596                 :             : void
    2597                 :     3226967 : finish_decl_cleanup (tree decl, tree cleanup)
    2598                 :             : {
    2599                 :     3226967 :   push_cleanup (decl, cleanup, false);
    2600                 :     3226967 : }
    2601                 :             : 
    2602                 :             : /* If the current scope exits with an exception, run CLEANUP.  */
    2603                 :             : 
    2604                 :             : void
    2605                 :     2098710 : finish_eh_cleanup (tree cleanup)
    2606                 :             : {
    2607                 :     2098710 :   push_cleanup (NULL, cleanup, true);
    2608                 :     2098710 : }
    2609                 :             : 
    2610                 :             : /* The MEM_INITS is a list of mem-initializers, in reverse of the
    2611                 :             :    order they were written by the user.  Each node is as for
    2612                 :             :    emit_mem_initializers.  */
    2613                 :             : 
    2614                 :             : void
    2615                 :    18616929 : finish_mem_initializers (tree mem_inits)
    2616                 :             : {
    2617                 :             :   /* Reorder the MEM_INITS so that they are in the order they appeared
    2618                 :             :      in the source program.  */
    2619                 :    18616929 :   mem_inits = nreverse (mem_inits);
    2620                 :             : 
    2621                 :    18616929 :   if (processing_template_decl)
    2622                 :             :     {
    2623                 :             :       tree mem;
    2624                 :             : 
    2625                 :    32431440 :       for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
    2626                 :             :         {
    2627                 :             :           /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
    2628                 :             :              check for bare parameter packs in the TREE_VALUE, because
    2629                 :             :              any parameter packs in the TREE_VALUE have already been
    2630                 :             :              bound as part of the TREE_PURPOSE.  See
    2631                 :             :              make_pack_expansion for more information.  */
    2632                 :    19118735 :           if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
    2633                 :    19118735 :               && check_for_bare_parameter_packs (TREE_VALUE (mem)))
    2634                 :           3 :             TREE_VALUE (mem) = error_mark_node;
    2635                 :             :         }
    2636                 :             : 
    2637                 :    13312705 :       add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
    2638                 :             :                                   CTOR_INITIALIZER, mem_inits));
    2639                 :             :     }
    2640                 :             :   else
    2641                 :     5304224 :     emit_mem_initializers (mem_inits);
    2642                 :    18616929 : }
    2643                 :             : 
    2644                 :             : /* Obfuscate EXPR if it looks like an id-expression or member access so
    2645                 :             :    that the call to finish_decltype in do_auto_deduction will give the
    2646                 :             :    right result.  If EVEN_UNEVAL, do this even in unevaluated context.  */
    2647                 :             : 
    2648                 :             : tree
    2649                 :    33845335 : force_paren_expr (tree expr, bool even_uneval /* = false */)
    2650                 :             : {
    2651                 :             :   /* This is only needed for decltype(auto) in C++14.  */
    2652                 :    33845335 :   if (cxx_dialect < cxx14)
    2653                 :             :     return expr;
    2654                 :             : 
    2655                 :             :   /* If we're in unevaluated context, we can't be deducing a
    2656                 :             :      return/initializer type, so we don't need to mess with this.  */
    2657                 :    33248134 :   if (cp_unevaluated_operand && !even_uneval)
    2658                 :             :     return expr;
    2659                 :             : 
    2660                 :    30183550 :   if (TREE_CODE (expr) == COMPONENT_REF
    2661                 :    30124013 :       || TREE_CODE (expr) == SCOPE_REF
    2662                 :    60300867 :       || REFERENCE_REF_P (expr))
    2663                 :      422374 :     REF_PARENTHESIZED_P (expr) = true;
    2664                 :    29761176 :   else if (DECL_P (tree_strip_any_location_wrapper (expr)))
    2665                 :             :     {
    2666                 :     1909603 :       location_t loc = cp_expr_location (expr);
    2667                 :     1909603 :       const tree_code code = processing_template_decl ? PAREN_EXPR
    2668                 :             :                                                       : VIEW_CONVERT_EXPR;
    2669                 :     1909603 :       expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
    2670                 :     1909603 :       REF_PARENTHESIZED_P (expr) = true;
    2671                 :             :     }
    2672                 :             :   return expr;
    2673                 :             : }
    2674                 :             : 
    2675                 :             : /* If T is an id-expression obfuscated by force_paren_expr, undo the
    2676                 :             :    obfuscation and return the underlying id-expression.  Otherwise
    2677                 :             :    return T.  */
    2678                 :             : 
    2679                 :             : tree
    2680                 :   779239849 : maybe_undo_parenthesized_ref (tree t)
    2681                 :             : {
    2682                 :   779239849 :   if (cxx_dialect < cxx14)
    2683                 :             :     return t;
    2684                 :             : 
    2685                 :   770044991 :   if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
    2686                 :   855176566 :       && REF_PARENTHESIZED_P (t))
    2687                 :      273229 :     t = TREE_OPERAND (t, 0);
    2688                 :             : 
    2689                 :             :   return t;
    2690                 :             : }
    2691                 :             : 
    2692                 :             : /* Finish a parenthesized expression EXPR.  */
    2693                 :             : 
    2694                 :             : cp_expr
    2695                 :    28855014 : finish_parenthesized_expr (cp_expr expr)
    2696                 :             : {
    2697                 :    28855014 :   if (EXPR_P (expr))
    2698                 :             :     {
    2699                 :             :       /* This inhibits warnings in maybe_warn_unparenthesized_assignment
    2700                 :             :          and c_common_truthvalue_conversion.  */
    2701                 :    57448290 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
    2702                 :             :       /* And maybe_warn_sizeof_array_div.  */
    2703                 :    57448290 :       suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
    2704                 :             :     }
    2705                 :             : 
    2706                 :    28855014 :   if (TREE_CODE (expr) == OFFSET_REF
    2707                 :    28855014 :       || TREE_CODE (expr) == SCOPE_REF)
    2708                 :             :     /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
    2709                 :             :        enclosed in parentheses.  */
    2710                 :       13557 :     PTRMEM_OK_P (expr) = 0;
    2711                 :             : 
    2712                 :    28855014 :   tree stripped_expr = tree_strip_any_location_wrapper (expr);
    2713                 :    28855014 :   if (TREE_CODE (stripped_expr) == STRING_CST)
    2714                 :      863123 :     PAREN_STRING_LITERAL_P (stripped_expr) = 1;
    2715                 :    27991891 :   else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
    2716                 :        2512 :     PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
    2717                 :             : 
    2718                 :    28855014 :   expr = cp_expr (force_paren_expr (expr), expr.get_location ());
    2719                 :             : 
    2720                 :    28855014 :   return expr;
    2721                 :             : }
    2722                 :             : 
    2723                 :             : /* Finish a reference to a non-static data member (DECL) that is not
    2724                 :             :    preceded by `.' or `->'.  */
    2725                 :             : 
    2726                 :             : tree
    2727                 :    65654670 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
    2728                 :             :                                tsubst_flags_t complain /* = tf_warning_or_error */)
    2729                 :             : {
    2730                 :    65654670 :   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
    2731                 :    65654670 :   bool try_omp_private = !object && omp_private_member_map;
    2732                 :    57025635 :   tree ret;
    2733                 :             : 
    2734                 :    57025635 :   if (!object)
    2735                 :             :     {
    2736                 :    57025635 :       tree scope = qualifying_scope;
    2737                 :    57025635 :       if (scope == NULL_TREE)
    2738                 :             :         {
    2739                 :    57013883 :           scope = context_for_name_lookup (decl);
    2740                 :    57013883 :           if (!TYPE_P (scope))
    2741                 :             :             {
    2742                 :             :               /* Can happen during error recovery (c++/85014).  */
    2743                 :           3 :               gcc_assert (seen_error ());
    2744                 :           3 :               return error_mark_node;
    2745                 :             :             }
    2746                 :             :         }
    2747                 :    57025632 :       object = maybe_dummy_object (scope, NULL);
    2748                 :             :     }
    2749                 :             : 
    2750                 :    65654667 :   object = maybe_resolve_dummy (object, true);
    2751                 :    65654667 :   if (object == error_mark_node)
    2752                 :             :     return error_mark_node;
    2753                 :             : 
    2754                 :             :   /* DR 613/850: Can use non-static data members without an associated
    2755                 :             :      object in sizeof/decltype/alignof.  */
    2756                 :    65654664 :   if (is_dummy_object (object)
    2757                 :       41488 :       && !cp_unevaluated_operand
    2758                 :    65654758 :       && (!processing_template_decl || !current_class_ref))
    2759                 :             :     {
    2760                 :          79 :       if (complain & tf_error)
    2761                 :             :         {
    2762                 :          74 :           auto_diagnostic_group d;
    2763                 :          74 :           if (current_function_decl
    2764                 :          74 :               && DECL_STATIC_FUNCTION_P (current_function_decl))
    2765                 :           3 :             error ("invalid use of member %qD in static member function", decl);
    2766                 :          71 :           else if (current_function_decl
    2767                 :          65 :                    && processing_contract_condition
    2768                 :          75 :                    && DECL_CONSTRUCTOR_P (current_function_decl))
    2769                 :           1 :             error ("invalid use of member %qD in constructor %<pre%> contract", decl);
    2770                 :          70 :           else if (current_function_decl
    2771                 :          64 :                    && processing_contract_condition
    2772                 :          72 :                    && DECL_DESTRUCTOR_P (current_function_decl))
    2773                 :           1 :             error ("invalid use of member %qD in destructor %<post%> contract", decl);
    2774                 :             :           else
    2775                 :          69 :             error ("invalid use of non-static data member %qD", decl);
    2776                 :          74 :           inform (DECL_SOURCE_LOCATION (decl), "declared here");
    2777                 :          74 :         }
    2778                 :             : 
    2779                 :          79 :       return error_mark_node;
    2780                 :             :     }
    2781                 :             : 
    2782                 :    65654585 :   if (current_class_ptr)
    2783                 :    65392059 :     TREE_USED (current_class_ptr) = 1;
    2784                 :    65654585 :   if (processing_template_decl)
    2785                 :             :     {
    2786                 :    52189243 :       tree type = TREE_TYPE (decl);
    2787                 :             : 
    2788                 :    52189243 :       if (TYPE_REF_P (type))
    2789                 :             :         /* Quals on the object don't matter.  */;
    2790                 :    50183182 :       else if (PACK_EXPANSION_P (type))
    2791                 :             :         /* Don't bother trying to represent this.  */
    2792                 :             :         type = NULL_TREE;
    2793                 :    50174152 :       else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
    2794                 :             :         /* We don't know what the eventual quals will be, so punt until
    2795                 :             :            instantiation time.
    2796                 :             : 
    2797                 :             :            This can happen when called from build_capture_proxy for an explicit
    2798                 :             :            object lambda.  It's a bit marginal to call this function in that
    2799                 :             :            case, since this function is for references to members of 'this',
    2800                 :             :            but the deduced type is required to be derived from the closure
    2801                 :             :            type, so it works.  */
    2802                 :             :         type = NULL_TREE;
    2803                 :             :       else
    2804                 :             :         {
    2805                 :             :           /* Set the cv qualifiers.  */
    2806                 :    50168783 :           int quals = cp_type_quals (TREE_TYPE (object));
    2807                 :             : 
    2808                 :    50168783 :           if (DECL_MUTABLE_P (decl))
    2809                 :      236945 :             quals &= ~TYPE_QUAL_CONST;
    2810                 :             : 
    2811                 :    50168783 :           quals |= cp_type_quals (TREE_TYPE (decl));
    2812                 :    50168783 :           type = cp_build_qualified_type (type, quals);
    2813                 :             :         }
    2814                 :             : 
    2815                 :    52189243 :       if (qualifying_scope)
    2816                 :             :         /* Wrap this in a SCOPE_REF for now.  */
    2817                 :        9828 :         ret = build_qualified_name (type, qualifying_scope, decl,
    2818                 :             :                                     /*template_p=*/false);
    2819                 :             :       else
    2820                 :    52179415 :         ret = (convert_from_reference
    2821                 :    52179415 :                (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
    2822                 :             :     }
    2823                 :             :   /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
    2824                 :             :      QUALIFYING_SCOPE is also non-null.  */
    2825                 :             :   else
    2826                 :             :     {
    2827                 :    13465342 :       tree access_type = TREE_TYPE (object);
    2828                 :             : 
    2829                 :    13465342 :       if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
    2830                 :             :                                           decl, complain))
    2831                 :           0 :         return error_mark_node;
    2832                 :             : 
    2833                 :             :       /* If the data member was named `C::M', convert `*this' to `C'
    2834                 :             :          first.  */
    2835                 :    13465342 :       if (qualifying_scope)
    2836                 :             :         {
    2837                 :        1889 :           tree binfo = NULL_TREE;
    2838                 :        1889 :           object = build_scoped_ref (object, qualifying_scope,
    2839                 :             :                                      &binfo);
    2840                 :             :         }
    2841                 :             : 
    2842                 :    13465342 :       ret = build_class_member_access_expr (object, decl,
    2843                 :             :                                             /*access_path=*/NULL_TREE,
    2844                 :             :                                             /*preserve_reference=*/false,
    2845                 :             :                                             complain);
    2846                 :             :     }
    2847                 :    65654585 :   if (try_omp_private)
    2848                 :             :     {
    2849                 :        1662 :       tree *v = omp_private_member_map->get (decl);
    2850                 :        1662 :       if (v)
    2851                 :        1234 :         ret = convert_from_reference (*v);
    2852                 :             :     }
    2853                 :             :   return ret;
    2854                 :             : }
    2855                 :             : 
    2856                 :             : /* DECL was the declaration to which a qualified-id resolved.  Issue
    2857                 :             :    an error message if it is not accessible.  If OBJECT_TYPE is
    2858                 :             :    non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
    2859                 :             :    type of `*x', or `x', respectively.  If the DECL was named as
    2860                 :             :    `A::B' then NESTED_NAME_SPECIFIER is `A'.  Return value is like
    2861                 :             :    perform_access_checks above.  */
    2862                 :             : 
    2863                 :             : bool
    2864                 :  4015471819 : check_accessibility_of_qualified_id (tree decl,
    2865                 :             :                                      tree object_type,
    2866                 :             :                                      tree nested_name_specifier,
    2867                 :             :                                      tsubst_flags_t complain)
    2868                 :             : {
    2869                 :             :   /* If we're not checking, return immediately.  */
    2870                 :  4015471819 :   if (deferred_access_no_check)
    2871                 :             :     return true;
    2872                 :             : 
    2873                 :             :   /* Determine the SCOPE of DECL.  */
    2874                 :  4007152157 :   tree scope = context_for_name_lookup (decl);
    2875                 :             :   /* If the SCOPE is not a type, then DECL is not a member.  */
    2876                 :  4007152157 :   if (!TYPE_P (scope)
    2877                 :             :       /* If SCOPE is dependent then we can't perform this access check now,
    2878                 :             :          and since we'll perform this access check again after substitution
    2879                 :             :          there's no need to explicitly defer it.  */
    2880                 :  4007152157 :       || dependent_type_p (scope))
    2881                 :  3668902602 :     return true;
    2882                 :             : 
    2883                 :   338249555 :   tree qualifying_type = NULL_TREE;
    2884                 :             :   /* Compute the scope through which DECL is being accessed.  */
    2885                 :   338249555 :   if (object_type
    2886                 :             :       /* OBJECT_TYPE might not be a class type; consider:
    2887                 :             : 
    2888                 :             :            class A { typedef int I; };
    2889                 :             :            I *p;
    2890                 :             :            p->A::I::~I();
    2891                 :             : 
    2892                 :             :          In this case, we will have "A::I" as the DECL, but "I" as the
    2893                 :             :          OBJECT_TYPE.  */
    2894                 :       78773 :       && CLASS_TYPE_P (object_type)
    2895                 :   338328311 :       && DERIVED_FROM_P (scope, object_type))
    2896                 :             :     {
    2897                 :             :       /* If we are processing a `->' or `.' expression, use the type of the
    2898                 :             :          left-hand side.  */
    2899                 :       78747 :       if (tree open = currently_open_class (object_type))
    2900                 :             :         qualifying_type = open;
    2901                 :             :       else
    2902                 :             :         qualifying_type = object_type;
    2903                 :             :     }
    2904                 :   338170808 :   else if (nested_name_specifier)
    2905                 :             :     {
    2906                 :             :       /* If the reference is to a non-static member of the
    2907                 :             :          current class, treat it as if it were referenced through
    2908                 :             :          `this'.  */
    2909                 :   437893901 :       if (DECL_NONSTATIC_MEMBER_P (decl)
    2910                 :   218999946 :           && current_class_ptr)
    2911                 :       42570 :         if (tree current = current_nonlambda_class_type ())
    2912                 :             :           {
    2913                 :       42543 :             if (dependent_type_p (current))
    2914                 :             :             /* In general we can't know whether this access goes through
    2915                 :             :                `this' until instantiation time.  Punt now, or else we might
    2916                 :             :                create a deferred access check that's not relative to `this'
    2917                 :             :                when it ought to be.  We'll check this access again after
    2918                 :             :                substitution, e.g. from tsubst_qualified_id.  */
    2919                 :             :               return true;
    2920                 :             : 
    2921                 :        3565 :             if (DERIVED_FROM_P (scope, current))
    2922                 :             :               qualifying_type = current;
    2923                 :             :           }
    2924                 :             :       /* Otherwise, use the type indicated by the
    2925                 :             :          nested-name-specifier.  */
    2926                 :             :       if (!qualifying_type)
    2927                 :             :         qualifying_type = nested_name_specifier;
    2928                 :             :     }
    2929                 :             :   else
    2930                 :             :     /* Otherwise, the name must be from the current class or one of
    2931                 :             :        its bases.  */
    2932                 :   119223856 :     qualifying_type = currently_open_derived_class (scope);
    2933                 :             : 
    2934                 :   338156492 :   if (qualifying_type
    2935                 :             :       /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
    2936                 :             :          or similar in a default argument value.  */
    2937                 :   338210577 :       && CLASS_TYPE_P (qualifying_type))
    2938                 :   327336536 :     return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
    2939                 :   327336536 :                                           decl, complain);
    2940                 :             : 
    2941                 :             :   return true;
    2942                 :             : }
    2943                 :             : 
    2944                 :             : /* EXPR is the result of a qualified-id.  The QUALIFYING_CLASS was the
    2945                 :             :    class named to the left of the "::" operator.  DONE is true if this
    2946                 :             :    expression is a complete postfix-expression; it is false if this
    2947                 :             :    expression is followed by '->', '[', '(', etc.  ADDRESS_P is true
    2948                 :             :    iff this expression is the operand of '&'.  TEMPLATE_P is true iff
    2949                 :             :    the qualified-id was of the form "A::template B".  TEMPLATE_ARG_P
    2950                 :             :    is true iff this qualified name appears as a template argument.  */
    2951                 :             : 
    2952                 :             : tree
    2953                 :    65536742 : finish_qualified_id_expr (tree qualifying_class,
    2954                 :             :                           tree expr,
    2955                 :             :                           bool done,
    2956                 :             :                           bool address_p,
    2957                 :             :                           bool template_p,
    2958                 :             :                           bool template_arg_p,
    2959                 :             :                           tsubst_flags_t complain)
    2960                 :             : {
    2961                 :    65536742 :   gcc_assert (TYPE_P (qualifying_class));
    2962                 :             : 
    2963                 :    65536742 :   if (error_operand_p (expr))
    2964                 :          18 :     return error_mark_node;
    2965                 :             : 
    2966                 :    65536724 :   if (DECL_P (expr)
    2967                 :             :       /* Functions are marked after overload resolution; avoid redundant
    2968                 :             :          warnings.  */
    2969                 :    56182203 :       && TREE_CODE (expr) != FUNCTION_DECL
    2970                 :   121718903 :       && !mark_used (expr, complain))
    2971                 :           0 :     return error_mark_node;
    2972                 :             : 
    2973                 :    65536724 :   if (template_p)
    2974                 :             :     {
    2975                 :     3097655 :       if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
    2976                 :             :         {
    2977                 :             :           /* cp_parser_lookup_name thought we were looking for a type,
    2978                 :             :              but we're actually looking for a declaration.  */
    2979                 :           9 :           qualifying_class = TYPE_CONTEXT (expr);
    2980                 :           9 :           expr = TYPE_IDENTIFIER (expr);
    2981                 :             :         }
    2982                 :             :       else
    2983                 :     3097646 :         check_template_keyword (expr);
    2984                 :             :     }
    2985                 :             : 
    2986                 :             :   /* If EXPR occurs as the operand of '&', use special handling that
    2987                 :             :      permits a pointer-to-member.  */
    2988                 :    65536724 :   if (address_p && done
    2989                 :      172140 :       && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
    2990                 :             :     {
    2991                 :      172138 :       if (TREE_CODE (expr) == SCOPE_REF)
    2992                 :           0 :         expr = TREE_OPERAND (expr, 1);
    2993                 :      172138 :       expr = build_offset_ref (qualifying_class, expr,
    2994                 :             :                                /*address_p=*/true, complain);
    2995                 :      172138 :       return expr;
    2996                 :             :     }
    2997                 :             : 
    2998                 :             :   /* No need to check access within an enum.  */
    2999                 :    65364586 :   if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
    3000                 :     1831641 :       && TREE_CODE (expr) != IDENTIFIER_NODE)
    3001                 :             :     return expr;
    3002                 :             : 
    3003                 :             :   /* Within the scope of a class, turn references to non-static
    3004                 :             :      members into expression of the form "this->...".  */
    3005                 :    63532948 :   if (template_arg_p)
    3006                 :             :     /* But, within a template argument, we do not want make the
    3007                 :             :        transformation, as there is no "this" pointer.  */
    3008                 :             :     ;
    3009                 :    63530340 :   else if (TREE_CODE (expr) == FIELD_DECL)
    3010                 :             :     {
    3011                 :       11752 :       push_deferring_access_checks (dk_no_check);
    3012                 :       11752 :       expr = finish_non_static_data_member (expr, NULL_TREE,
    3013                 :             :                                             qualifying_class, complain);
    3014                 :       11752 :       pop_deferring_access_checks ();
    3015                 :             :     }
    3016                 :    63518588 :   else if (BASELINK_P (expr))
    3017                 :             :     {
    3018                 :             :       /* See if any of the functions are non-static members.  */
    3019                 :             :       /* If so, the expression may be relative to 'this'.  */
    3020                 :     8836559 :       if (!shared_member_p (expr)
    3021                 :      270282 :           && current_class_ptr
    3022                 :     9106360 :           && DERIVED_FROM_P (qualifying_class,
    3023                 :             :                              current_nonlambda_class_type ()))
    3024                 :      269659 :         expr = (build_class_member_access_expr
    3025                 :      269659 :                 (maybe_dummy_object (qualifying_class, NULL),
    3026                 :             :                  expr,
    3027                 :      269659 :                  BASELINK_ACCESS_BINFO (expr),
    3028                 :             :                  /*preserve_reference=*/false,
    3029                 :             :                  complain));
    3030                 :     8566900 :       else if (done)
    3031                 :             :         /* The expression is a qualified name whose address is not
    3032                 :             :            being taken.  */
    3033                 :        4774 :         expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
    3034                 :             :                                  complain);
    3035                 :             :     }
    3036                 :    54682029 :   else if (!template_p
    3037                 :    54361855 :            && TREE_CODE (expr) == TEMPLATE_DECL
    3038                 :    54682146 :            && !DECL_FUNCTION_TEMPLATE_P (expr))
    3039                 :             :     {
    3040                 :         117 :       if (complain & tf_error)
    3041                 :           3 :         error ("%qE missing template arguments", expr);
    3042                 :         117 :       return error_mark_node;
    3043                 :             :     }
    3044                 :             :   else
    3045                 :             :     {
    3046                 :             :       /* In a template, return a SCOPE_REF for most qualified-ids
    3047                 :             :          so that we can check access at instantiation time.  But if
    3048                 :             :          we're looking at a member of the current instantiation, we
    3049                 :             :          know we have access and building up the SCOPE_REF confuses
    3050                 :             :          non-type template argument handling.  */
    3051                 :    54681912 :       if (processing_template_decl
    3052                 :    54681912 :           && (!currently_open_class (qualifying_class)
    3053                 :        3978 :               || TREE_CODE (expr) == IDENTIFIER_NODE
    3054                 :        3978 :               || TREE_CODE (expr) == TEMPLATE_ID_EXPR
    3055                 :          82 :               || TREE_CODE (expr) == BIT_NOT_EXPR))
    3056                 :    10274039 :         expr = build_qualified_name (TREE_TYPE (expr),
    3057                 :             :                                      qualifying_class, expr,
    3058                 :             :                                      template_p);
    3059                 :    44407873 :       else if (tree wrap = maybe_get_tls_wrapper_call (expr))
    3060                 :           9 :         expr = wrap;
    3061                 :             : 
    3062                 :    54681912 :       expr = convert_from_reference (expr);
    3063                 :             :     }
    3064                 :             : 
    3065                 :             :   return expr;
    3066                 :             : }
    3067                 :             : 
    3068                 :             : /* Begin a statement-expression.  The value returned must be passed to
    3069                 :             :    finish_stmt_expr.  */
    3070                 :             : 
    3071                 :             : tree
    3072                 :     4180202 : begin_stmt_expr (void)
    3073                 :             : {
    3074                 :     4180202 :   return push_stmt_list ();
    3075                 :             : }
    3076                 :             : 
    3077                 :             : /* Process the final expression of a statement expression. EXPR can be
    3078                 :             :    NULL, if the final expression is empty.  Return a STATEMENT_LIST
    3079                 :             :    containing all the statements in the statement-expression, or
    3080                 :             :    ERROR_MARK_NODE if there was an error.  */
    3081                 :             : 
    3082                 :             : tree
    3083                 :       23100 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
    3084                 :             : {
    3085                 :       23100 :   if (error_operand_p (expr))
    3086                 :             :     {
    3087                 :             :       /* The type of the statement-expression is the type of the last
    3088                 :             :          expression.  */
    3089                 :           3 :       TREE_TYPE (stmt_expr) = error_mark_node;
    3090                 :           3 :       return error_mark_node;
    3091                 :             :     }
    3092                 :             : 
    3093                 :             :   /* If the last statement does not have "void" type, then the value
    3094                 :             :      of the last statement is the value of the entire expression.  */
    3095                 :       23097 :   if (expr)
    3096                 :             :     {
    3097                 :       23082 :       tree type = TREE_TYPE (expr);
    3098                 :             : 
    3099                 :       23082 :       if (type && type_unknown_p (type))
    3100                 :             :         {
    3101                 :          15 :           error ("a statement expression is an insufficient context"
    3102                 :             :                  " for overload resolution");
    3103                 :          15 :           TREE_TYPE (stmt_expr) = error_mark_node;
    3104                 :          15 :           return error_mark_node;
    3105                 :             :         }
    3106                 :       23067 :       else if (processing_template_decl)
    3107                 :             :         {
    3108                 :             :           /* Not finish_expr_stmt because we don't want convert_to_void.  */
    3109                 :         133 :           expr = build_stmt (input_location, EXPR_STMT, expr);
    3110                 :         133 :           expr = add_stmt (expr);
    3111                 :             :           /* Mark the last statement so that we can recognize it as such at
    3112                 :             :              template-instantiation time.  */
    3113                 :         133 :           EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
    3114                 :             :         }
    3115                 :       22934 :       else if (VOID_TYPE_P (type))
    3116                 :             :         {
    3117                 :             :           /* Just treat this like an ordinary statement.  */
    3118                 :          31 :           expr = finish_expr_stmt (expr);
    3119                 :             :         }
    3120                 :             :       else
    3121                 :             :         {
    3122                 :             :           /* It actually has a value we need to deal with.  First, force it
    3123                 :             :              to be an rvalue so that we won't need to build up a copy
    3124                 :             :              constructor call later when we try to assign it to something.  */
    3125                 :       22903 :           expr = force_rvalue (expr, tf_warning_or_error);
    3126                 :       22903 :           if (error_operand_p (expr))
    3127                 :           0 :             return error_mark_node;
    3128                 :             : 
    3129                 :             :           /* Update for array-to-pointer decay.  */
    3130                 :       22903 :           type = TREE_TYPE (expr);
    3131                 :             : 
    3132                 :             :           /* This TARGET_EXPR will initialize the outer one added by
    3133                 :             :              finish_stmt_expr.  */
    3134                 :       22903 :           set_target_expr_eliding (expr);
    3135                 :             : 
    3136                 :             :           /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
    3137                 :             :              normal statement, but don't convert to void or actually add
    3138                 :             :              the EXPR_STMT.  */
    3139                 :       22903 :           if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
    3140                 :       22903 :             expr = maybe_cleanup_point_expr (expr);
    3141                 :       22903 :           add_stmt (expr);
    3142                 :             :         }
    3143                 :             : 
    3144                 :             :       /* The type of the statement-expression is the type of the last
    3145                 :             :          expression.  */
    3146                 :       23067 :       TREE_TYPE (stmt_expr) = type;
    3147                 :             :     }
    3148                 :             : 
    3149                 :             :   return stmt_expr;
    3150                 :             : }
    3151                 :             : 
    3152                 :             : /* Finish a statement-expression.  EXPR should be the value returned
    3153                 :             :    by the previous begin_stmt_expr.  Returns an expression
    3154                 :             :    representing the statement-expression.  */
    3155                 :             : 
    3156                 :             : tree
    3157                 :     4180202 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
    3158                 :             : {
    3159                 :     4180202 :   tree type;
    3160                 :     4180202 :   tree result;
    3161                 :             : 
    3162                 :     4180202 :   if (error_operand_p (stmt_expr))
    3163                 :             :     {
    3164                 :          18 :       pop_stmt_list (stmt_expr);
    3165                 :          18 :       return error_mark_node;
    3166                 :             :     }
    3167                 :             : 
    3168                 :     4180184 :   gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
    3169                 :             : 
    3170                 :     4180184 :   type = TREE_TYPE (stmt_expr);
    3171                 :     4180184 :   result = pop_stmt_list (stmt_expr);
    3172                 :     4180184 :   TREE_TYPE (result) = type;
    3173                 :             : 
    3174                 :     4180184 :   if (processing_template_decl)
    3175                 :             :     {
    3176                 :        9795 :       result = build_min (STMT_EXPR, type, result);
    3177                 :        9795 :       TREE_SIDE_EFFECTS (result) = 1;
    3178                 :        9795 :       STMT_EXPR_NO_SCOPE (result) = has_no_scope;
    3179                 :             :     }
    3180                 :     4170389 :   else if (CLASS_TYPE_P (type))
    3181                 :             :     {
    3182                 :             :       /* Wrap the statement-expression in a TARGET_EXPR so that the
    3183                 :             :          temporary object created by the final expression is destroyed at
    3184                 :             :          the end of the full-expression containing the
    3185                 :             :          statement-expression.  */
    3186                 :         118 :       result = force_target_expr (type, result, tf_warning_or_error);
    3187                 :             :     }
    3188                 :             : 
    3189                 :             :   return result;
    3190                 :             : }
    3191                 :             : 
    3192                 :             : /* Returns the expression which provides the value of STMT_EXPR.  */
    3193                 :             : 
    3194                 :             : tree
    3195                 :         152 : stmt_expr_value_expr (tree stmt_expr)
    3196                 :             : {
    3197                 :         152 :   tree t = STMT_EXPR_STMT (stmt_expr);
    3198                 :             : 
    3199                 :         152 :   if (TREE_CODE (t) == BIND_EXPR)
    3200                 :         152 :     t = BIND_EXPR_BODY (t);
    3201                 :             : 
    3202                 :         152 :   if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
    3203                 :         119 :     t = STATEMENT_LIST_TAIL (t)->stmt;
    3204                 :             : 
    3205                 :         152 :   if (TREE_CODE (t) == EXPR_STMT)
    3206                 :         134 :     t = EXPR_STMT_EXPR (t);
    3207                 :             : 
    3208                 :         152 :   return t;
    3209                 :             : }
    3210                 :             : 
    3211                 :             : /* Return TRUE iff EXPR_STMT is an empty list of
    3212                 :             :    expression statements.  */
    3213                 :             : 
    3214                 :             : bool
    3215                 :    47092375 : empty_expr_stmt_p (tree expr_stmt)
    3216                 :             : {
    3217                 :    47092378 :   tree body = NULL_TREE;
    3218                 :             : 
    3219                 :    47092378 :   if (expr_stmt == void_node)
    3220                 :             :     return true;
    3221                 :             : 
    3222                 :    47092375 :   if (expr_stmt)
    3223                 :             :     {
    3224                 :    47092375 :       if (TREE_CODE (expr_stmt) == EXPR_STMT)
    3225                 :           3 :         body = EXPR_STMT_EXPR (expr_stmt);
    3226                 :    47092372 :       else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
    3227                 :             :         body = expr_stmt;
    3228                 :             :     }
    3229                 :             : 
    3230                 :           3 :   if (body)
    3231                 :             :     {
    3232                 :    46472199 :       if (TREE_CODE (body) == STATEMENT_LIST)
    3233                 :    46472196 :         return tsi_end_p (tsi_start (body));
    3234                 :             :       else
    3235                 :             :         return empty_expr_stmt_p (body);
    3236                 :             :     }
    3237                 :             :   return false;
    3238                 :             : }
    3239                 :             : 
    3240                 :             : /* Perform Koenig lookup.  FN_EXPR is the postfix-expression representing
    3241                 :             :    the function (or functions) to call; ARGS are the arguments to the
    3242                 :             :    call.  Returns the functions to be considered by overload resolution.  */
    3243                 :             : 
    3244                 :             : cp_expr
    3245                 :    16661016 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
    3246                 :             :                        tsubst_flags_t complain)
    3247                 :             : {
    3248                 :    16661016 :   tree identifier = NULL_TREE;
    3249                 :    16661016 :   tree functions = NULL_TREE;
    3250                 :    16661016 :   tree tmpl_args = NULL_TREE;
    3251                 :    16661016 :   bool template_id = false;
    3252                 :    16661016 :   location_t loc = fn_expr.get_location ();
    3253                 :    16661016 :   tree fn = fn_expr.get_value ();
    3254                 :             : 
    3255                 :    16661016 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3256                 :             : 
    3257                 :    16661016 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    3258                 :             :     {
    3259                 :             :       /* Use a separate flag to handle null args.  */
    3260                 :     2279964 :       template_id = true;
    3261                 :     2279964 :       tmpl_args = TREE_OPERAND (fn, 1);
    3262                 :     2279964 :       fn = TREE_OPERAND (fn, 0);
    3263                 :             :     }
    3264                 :             : 
    3265                 :             :   /* Find the name of the overloaded function.  */
    3266                 :    16661016 :   if (identifier_p (fn))
    3267                 :             :     identifier = fn;
    3268                 :             :   else
    3269                 :             :     {
    3270                 :    23364964 :       functions = fn;
    3271                 :    16560945 :       identifier = OVL_NAME (functions);
    3272                 :             :     }
    3273                 :             : 
    3274                 :             :   /* A call to a namespace-scope function using an unqualified name.
    3275                 :             : 
    3276                 :             :      Do Koenig lookup -- unless any of the arguments are
    3277                 :             :      type-dependent.  */
    3278                 :    16661016 :   if (!any_type_dependent_arguments_p (args)
    3279                 :    16661016 :       && !any_dependent_template_arguments_p (tmpl_args))
    3280                 :             :     {
    3281                 :    15808569 :       fn = lookup_arg_dependent (identifier, functions, args);
    3282                 :    15808569 :       if (!fn)
    3283                 :             :         {
    3284                 :             :           /* The unqualified name could not be resolved.  */
    3285                 :       23403 :           if (complain & tf_error)
    3286                 :         390 :             fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
    3287                 :             :           else
    3288                 :             :             fn = identifier;
    3289                 :             :         }
    3290                 :             :     }
    3291                 :             : 
    3292                 :    16661016 :   if (fn && template_id && fn != error_mark_node)
    3293                 :     2279953 :     fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
    3294                 :             : 
    3295                 :    16661016 :   return cp_expr (fn, loc);
    3296                 :             : }
    3297                 :             : 
    3298                 :             : /* Generate an expression for `FN (ARGS)'.  This may change the
    3299                 :             :    contents of ARGS.
    3300                 :             : 
    3301                 :             :    If DISALLOW_VIRTUAL is true, the call to FN will be not generated
    3302                 :             :    as a virtual call, even if FN is virtual.  (This flag is set when
    3303                 :             :    encountering an expression where the function name is explicitly
    3304                 :             :    qualified.  For example a call to `X::f' never generates a virtual
    3305                 :             :    call.)
    3306                 :             : 
    3307                 :             :    Returns code for the call.  */
    3308                 :             : 
    3309                 :             : tree
    3310                 :   298736585 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
    3311                 :             :                   bool koenig_p, tsubst_flags_t complain)
    3312                 :             : {
    3313                 :   298736585 :   tree result;
    3314                 :   298736585 :   tree orig_fn;
    3315                 :   298736585 :   vec<tree, va_gc> *orig_args = *args;
    3316                 :             : 
    3317                 :   298736585 :   if (fn == error_mark_node)
    3318                 :             :     return error_mark_node;
    3319                 :             : 
    3320                 :   298735575 :   gcc_assert (!TYPE_P (fn));
    3321                 :             : 
    3322                 :             :   /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
    3323                 :             :      it so that we can tell this is a call to a known function.  */
    3324                 :   298735575 :   fn = maybe_undo_parenthesized_ref (fn);
    3325                 :             : 
    3326                 :   298735575 :   STRIP_ANY_LOCATION_WRAPPER (fn);
    3327                 :             : 
    3328                 :   298735575 :   orig_fn = fn;
    3329                 :             : 
    3330                 :   298735575 :   if (concept_check_p (fn))
    3331                 :             :     {
    3332                 :           6 :       error_at (EXPR_LOC_OR_LOC (fn, input_location),
    3333                 :             :                 "cannot call a concept as a function");
    3334                 :           6 :       return error_mark_node;
    3335                 :             :     }
    3336                 :             : 
    3337                 :   298735569 :   if (processing_template_decl)
    3338                 :             :     {
    3339                 :             :       /* If FN is a local extern declaration (or set thereof) in a template,
    3340                 :             :          look it up again at instantiation time.  */
    3341                 :   198397843 :       if (is_overloaded_fn (fn))
    3342                 :             :         {
    3343                 :   122495000 :           tree ifn = get_first_fn (fn);
    3344                 :   122495000 :           if (TREE_CODE (ifn) == FUNCTION_DECL
    3345                 :   122495000 :               && dependent_local_decl_p (ifn))
    3346                 :       19043 :             orig_fn = DECL_NAME (ifn);
    3347                 :             :         }
    3348                 :             : 
    3349                 :             :       /* If the call expression is dependent, build a CALL_EXPR node
    3350                 :             :          with no type; type_dependent_expression_p recognizes
    3351                 :             :          expressions with no type as being dependent.  */
    3352                 :   198397843 :       if (type_dependent_expression_p (fn)
    3353                 :   198397843 :           || any_type_dependent_arguments_p (*args))
    3354                 :             :         {
    3355                 :   178145651 :           if (koenig_p
    3356                 :     9458175 :               && TREE_CODE (orig_fn) == FUNCTION_DECL
    3357                 :   180578723 :               && !fndecl_built_in_p (orig_fn))
    3358                 :             :             /* For an ADL-enabled call where unqualified lookup found a
    3359                 :             :                single non-template function, wrap it in an OVERLOAD so that
    3360                 :             :                later substitution doesn't overeagerly mark the function as
    3361                 :             :                used.  */
    3362                 :      336268 :             orig_fn = ovl_make (orig_fn, NULL_TREE);
    3363                 :   178145651 :           result = build_min_nt_call_vec (orig_fn, *args);
    3364                 :   237252555 :           SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
    3365                 :   178145651 :           KOENIG_LOOKUP_P (result) = koenig_p;
    3366                 :             :           /* Disable the std::move warnings since this call was dependent
    3367                 :             :              (c++/89780, c++/107363).  This also suppresses the
    3368                 :             :              -Wredundant-move warning.  */
    3369                 :   178145651 :           suppress_warning (result, OPT_Wpessimizing_move);
    3370                 :             : 
    3371                 :   178145651 :           if (cfun && cp_function_chain && !cp_unevaluated_operand)
    3372                 :             :             {
    3373                 :   154663927 :               bool abnormal = true;
    3374                 :   154825095 :               for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
    3375                 :             :                 {
    3376                 :    86379485 :                   tree fndecl = STRIP_TEMPLATE (*iter);
    3377                 :    86379485 :                   if (TREE_CODE (fndecl) != FUNCTION_DECL
    3378                 :    86379407 :                       || !TREE_THIS_VOLATILE (fndecl))
    3379                 :             :                     {
    3380                 :             :                       abnormal = false;
    3381                 :             :                       break;
    3382                 :             :                     }
    3383                 :             :                 }
    3384                 :             :               /* FIXME: Stop warning about falling off end of non-void
    3385                 :             :                  function.   But this is wrong.  Even if we only see
    3386                 :             :                  no-return fns at this point, we could select a
    3387                 :             :                  future-defined return fn during instantiation.  Or
    3388                 :             :                  vice-versa.  */
    3389                 :   154663927 :               if (abnormal)
    3390                 :    68445610 :                 current_function_returns_abnormally = 1;
    3391                 :             :             }
    3392                 :   178145651 :           if (TREE_CODE (fn) == COMPONENT_REF)
    3393                 :    88097997 :             maybe_generic_this_capture (TREE_OPERAND (fn, 0),
    3394                 :    88097997 :                                         TREE_OPERAND (fn, 1));
    3395                 :   178145651 :           return result;
    3396                 :             :         }
    3397                 :    20252192 :       orig_args = make_tree_vector_copy (*args);
    3398                 :             :     }
    3399                 :             : 
    3400                 :   120589918 :   if (TREE_CODE (fn) == COMPONENT_REF)
    3401                 :             :     {
    3402                 :    24099764 :       tree member = TREE_OPERAND (fn, 1);
    3403                 :    24099764 :       if (BASELINK_P (member))
    3404                 :             :         {
    3405                 :    23920368 :           tree object = TREE_OPERAND (fn, 0);
    3406                 :    47611987 :           return build_new_method_call (object, member,
    3407                 :             :                                         args, NULL_TREE,
    3408                 :             :                                         (disallow_virtual
    3409                 :             :                                          ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
    3410                 :             :                                          : LOOKUP_NORMAL),
    3411                 :             :                                         /*fn_p=*/NULL,
    3412                 :    23920368 :                                         complain);
    3413                 :             :         }
    3414                 :             :     }
    3415                 :             : 
    3416                 :             :   /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'.  */
    3417                 :    96669550 :   if (TREE_CODE (fn) == ADDR_EXPR
    3418                 :    96669550 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
    3419                 :           9 :     fn = TREE_OPERAND (fn, 0);
    3420                 :             : 
    3421                 :    96669550 :   if (is_overloaded_fn (fn))
    3422                 :    92372448 :     fn = baselink_for_fns (fn);
    3423                 :             : 
    3424                 :    96669550 :   result = NULL_TREE;
    3425                 :    96669550 :   if (BASELINK_P (fn))
    3426                 :             :     {
    3427                 :    15494972 :       tree object;
    3428                 :             : 
    3429                 :             :       /* A call to a member function.  From [over.call.func]:
    3430                 :             : 
    3431                 :             :            If the keyword this is in scope and refers to the class of
    3432                 :             :            that member function, or a derived class thereof, then the
    3433                 :             :            function call is transformed into a qualified function call
    3434                 :             :            using (*this) as the postfix-expression to the left of the
    3435                 :             :            . operator.... [Otherwise] a contrived object of type T
    3436                 :             :            becomes the implied object argument.
    3437                 :             : 
    3438                 :             :         In this situation:
    3439                 :             : 
    3440                 :             :           struct A { void f(); };
    3441                 :             :           struct B : public A {};
    3442                 :             :           struct C : public A { void g() { B::f(); }};
    3443                 :             : 
    3444                 :             :         "the class of that member function" refers to `A'.  But 11.2
    3445                 :             :         [class.access.base] says that we need to convert 'this' to B* as
    3446                 :             :         part of the access, so we pass 'B' to maybe_dummy_object.  */
    3447                 :             : 
    3448                 :    15494972 :       if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
    3449                 :             :         {
    3450                 :             :           /* A constructor call always uses a dummy object.  (This constructor
    3451                 :             :              call which has the form A::A () is actually invalid and we are
    3452                 :             :              going to reject it later in build_new_method_call.)  */
    3453                 :          39 :           object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
    3454                 :             :         }
    3455                 :             :       else
    3456                 :    15494933 :         object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
    3457                 :             :                                      NULL);
    3458                 :             : 
    3459                 :    17103291 :       result = build_new_method_call (object, fn, args, NULL_TREE,
    3460                 :             :                                       (disallow_virtual
    3461                 :             :                                        ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
    3462                 :             :                                        : LOOKUP_NORMAL),
    3463                 :             :                                       /*fn_p=*/NULL,
    3464                 :             :                                       complain);
    3465                 :             :     }
    3466                 :    81174578 :   else if (is_overloaded_fn (fn))
    3467                 :             :     {
    3468                 :             :       /* If the function is an overloaded builtin, resolve it.  */
    3469                 :    76877476 :       if (TREE_CODE (fn) == FUNCTION_DECL
    3470                 :    76877476 :           && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
    3471                 :    15325262 :               || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
    3472                 :     8590273 :         result = resolve_overloaded_builtin (input_location, fn, *args,
    3473                 :             :                                              complain & tf_error);
    3474                 :             : 
    3475                 :     8590273 :       if (!result)
    3476                 :             :         {
    3477                 :    76638050 :           tree alloc_size_attr = NULL_TREE;
    3478                 :    76638050 :           if (warn_calloc_transposed_args
    3479                 :      629875 :               && TREE_CODE (fn) == FUNCTION_DECL
    3480                 :    76638050 :               && (alloc_size_attr
    3481                 :      410819 :                   = lookup_attribute ("alloc_size",
    3482                 :      410819 :                                       TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
    3483                 :        3429 :             if (TREE_VALUE (alloc_size_attr) == NULL_TREE
    3484                 :        3429 :                 || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
    3485                 :             :               alloc_size_attr = NULL_TREE;
    3486                 :    75007218 :           if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
    3487                 :     1630892 :               && (complain & tf_warning)
    3488                 :     1451520 :               && !vec_safe_is_empty (*args)
    3489                 :    77765649 :               && !processing_template_decl)
    3490                 :             :             {
    3491                 :             :               location_t sizeof_arg_loc[6];
    3492                 :             :               tree sizeof_arg[6];
    3493                 :             :               unsigned int i;
    3494                 :     8109372 :               for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
    3495                 :             :                 {
    3496                 :     3041217 :                   tree t;
    3497                 :             : 
    3498                 :     3041217 :                   sizeof_arg_loc[i] = UNKNOWN_LOCATION;
    3499                 :     3041217 :                   sizeof_arg[i] = NULL_TREE;
    3500                 :     3041217 :                   if (i >= (*args)->length ())
    3501                 :      630136 :                     continue;
    3502                 :     2411081 :                   t = (**args)[i];
    3503                 :     2411081 :                   if (TREE_CODE (t) != SIZEOF_EXPR)
    3504                 :     2404786 :                     continue;
    3505                 :        6295 :                   if (SIZEOF_EXPR_TYPE_P (t))
    3506                 :        2353 :                     sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
    3507                 :             :                   else
    3508                 :        3942 :                     sizeof_arg[i] = TREE_OPERAND (t, 0);
    3509                 :        6295 :                   sizeof_arg_loc[i] = EXPR_LOCATION (t);
    3510                 :             :                 }
    3511                 :     1013679 :               if (warn_sizeof_pointer_memaccess)
    3512                 :             :                 {
    3513                 :     1013619 :                   auto same_p = same_type_ignoring_top_level_qualifiers_p;
    3514                 :     1013619 :                   sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
    3515                 :             :                                                     sizeof_arg, same_p);
    3516                 :             :                 }
    3517                 :     1013679 :               if (alloc_size_attr)
    3518                 :          60 :                 warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
    3519                 :             :                                  alloc_size_attr);
    3520                 :             :             }
    3521                 :             : 
    3522                 :    76638050 :           if ((complain & tf_warning)
    3523                 :    48052377 :               && TREE_CODE (fn) == FUNCTION_DECL
    3524                 :    22529002 :               && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
    3525                 :      114852 :               && vec_safe_length (*args) == 3
    3526                 :    76752902 :               && !any_type_dependent_arguments_p (*args))
    3527                 :             :             {
    3528                 :      114852 :               tree arg0 = (*orig_args)[0];
    3529                 :      114852 :               tree arg1 = (*orig_args)[1];
    3530                 :      114852 :               tree arg2 = (*orig_args)[2];
    3531                 :      114852 :               int literal_mask = ((literal_integer_zerop (arg1) << 1)
    3532                 :      114852 :                                   | (literal_integer_zerop (arg2) << 2));
    3533                 :      114852 :               warn_for_memset (input_location, arg0, arg2, literal_mask);
    3534                 :             :             }
    3535                 :             : 
    3536                 :             :           /* A call to a namespace-scope function.  */
    3537                 :    76638050 :           result = build_new_function_call (fn, args, complain);
    3538                 :             :         }
    3539                 :             :     }
    3540                 :     4297102 :   else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
    3541                 :             :     {
    3542                 :       47842 :       if (!vec_safe_is_empty (*args))
    3543                 :           0 :         error ("arguments to destructor are not allowed");
    3544                 :             :       /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
    3545                 :             :          which case the postfix-expression is a possibly-parenthesized class
    3546                 :             :          member access), the function call destroys the object of scalar type
    3547                 :             :          denoted by the object expression of the class member access.  */
    3548                 :       47842 :       tree ob = TREE_OPERAND (fn, 0);
    3549                 :       47842 :       if (obvalue_p (ob))
    3550                 :       47824 :         result = build_trivial_dtor_call (ob, true);
    3551                 :             :       else
    3552                 :             :         /* No location to clobber.  */
    3553                 :          18 :         result = convert_to_void (ob, ICV_STATEMENT, complain);
    3554                 :             :     }
    3555                 :     4249260 :   else if (CLASS_TYPE_P (TREE_TYPE (fn)))
    3556                 :             :     /* If the "function" is really an object of class type, it might
    3557                 :             :        have an overloaded `operator ()'.  */
    3558                 :     1881959 :     result = build_op_call (fn, args, complain);
    3559                 :             : 
    3560                 :    94049305 :   if (!result)
    3561                 :             :     /* A call where the function is unknown.  */
    3562                 :     2367301 :     result = cp_build_function_call_vec (fn, args, complain);
    3563                 :             : 
    3564                 :    96656032 :   if (processing_template_decl && result != error_mark_node)
    3565                 :             :     {
    3566                 :    16053239 :       if (INDIRECT_REF_P (result))
    3567                 :     1020694 :         result = TREE_OPERAND (result, 0);
    3568                 :             : 
    3569                 :             :       /* Prune all but the selected function from the original overload
    3570                 :             :          set so that we can avoid some duplicate work at instantiation time.  */
    3571                 :    16053239 :       if (TREE_CODE (result) == CALL_EXPR
    3572                 :    16043211 :           && really_overloaded_fn (orig_fn))
    3573                 :             :         {
    3574                 :     7468096 :           tree sel_fn = CALL_EXPR_FN (result);
    3575                 :     7468096 :           if (TREE_CODE (sel_fn) == COMPONENT_REF)
    3576                 :             :             {
    3577                 :             :               /* The non-dependent result of build_new_method_call.  */
    3578                 :     2197506 :               sel_fn = TREE_OPERAND (sel_fn, 1);
    3579                 :     2197506 :               gcc_assert (BASELINK_P (sel_fn));
    3580                 :             :             }
    3581                 :     5270590 :           else if (TREE_CODE (sel_fn) == ADDR_EXPR)
    3582                 :             :             /* Our original callee wasn't wrapped in an ADDR_EXPR,
    3583                 :             :                so strip this ADDR_EXPR added by build_over_call.  */
    3584                 :     5270590 :             sel_fn = TREE_OPERAND (sel_fn, 0);
    3585                 :             :           orig_fn = sel_fn;
    3586                 :             :         }
    3587                 :             : 
    3588                 :    16053239 :       tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
    3589                 :    16053239 :       SET_EXPR_LOCATION (r, input_location);
    3590                 :    16053239 :       KOENIG_LOOKUP_P (r) = koenig_p;
    3591                 :    16053239 :       TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
    3592                 :    16053239 :       release_tree_vector (orig_args);
    3593                 :    16053239 :       result = convert_from_reference (r);
    3594                 :             :     }
    3595                 :             : 
    3596                 :             :   return result;
    3597                 :             : }
    3598                 :             : 
    3599                 :             : /* Finish a call to a postfix increment or decrement or EXPR.  (Which
    3600                 :             :    is indicated by CODE, which should be POSTINCREMENT_EXPR or
    3601                 :             :    POSTDECREMENT_EXPR.)  */
    3602                 :             : 
    3603                 :             : cp_expr
    3604                 :     2291420 : finish_increment_expr (cp_expr expr, enum tree_code code)
    3605                 :             : {
    3606                 :             :   /* input_location holds the location of the trailing operator token.
    3607                 :             :      Build a location of the form:
    3608                 :             :        expr++
    3609                 :             :        ~~~~^~
    3610                 :             :      with the caret at the operator token, ranging from the start
    3611                 :             :      of EXPR to the end of the operator token.  */
    3612                 :     2291420 :   location_t combined_loc = make_location (input_location,
    3613                 :             :                                            expr.get_start (),
    3614                 :             :                                            get_finish (input_location));
    3615                 :     2291420 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3616                 :     2291420 :                                      NULL_TREE, tf_warning_or_error);
    3617                 :             :   /* TODO: build_x_unary_op doesn't honor the location, so set it here.  */
    3618                 :     2291420 :   result.set_location (combined_loc);
    3619                 :     2291420 :   return result;
    3620                 :             : }
    3621                 :             : 
    3622                 :             : /* Finish a use of `this'.  Returns an expression for `this'.  */
    3623                 :             : 
    3624                 :             : tree
    3625                 :    32164229 : finish_this_expr (void)
    3626                 :             : {
    3627                 :    32164229 :   tree result = NULL_TREE;
    3628                 :             : 
    3629                 :    64328344 :   if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
    3630                 :    31957756 :     result = current_class_ptr;
    3631                 :      412930 :   else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
    3632                 :      206399 :     result = (lambda_expr_this_capture
    3633                 :      206399 :               (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
    3634                 :             :   else
    3635                 :          74 :     gcc_checking_assert (!current_class_ptr);
    3636                 :             : 
    3637                 :    32164155 :   if (result)
    3638                 :             :     /* The keyword 'this' is a prvalue expression.  */
    3639                 :    32164152 :     return rvalue (result);
    3640                 :             : 
    3641                 :          77 :   tree fn = current_nonlambda_function ();
    3642                 :          77 :   if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3643                 :             :     {
    3644                 :           4 :       auto_diagnostic_group d;
    3645                 :           4 :       error ("%<this%> is unavailable for explicit object member "
    3646                 :             :              "functions");
    3647                 :           4 :       tree xobj_parm = DECL_ARGUMENTS (fn);
    3648                 :           4 :       gcc_assert (xobj_parm);
    3649                 :           4 :       tree parm_name = DECL_NAME (xobj_parm);
    3650                 :             : 
    3651                 :           4 :       static tree remembered_fn = NULL_TREE;
    3652                 :             :       /* Only output this diagnostic once per function.  */
    3653                 :           4 :       if (remembered_fn == fn)
    3654                 :             :         /* Early escape.  */;
    3655                 :           4 :       else if (parm_name)
    3656                 :           4 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3657                 :             :                 "use explicit object parameter %qs instead",
    3658                 :           2 :                 IDENTIFIER_POINTER (parm_name));
    3659                 :             :       else
    3660                 :           2 :         inform (DECL_SOURCE_LOCATION (xobj_parm),
    3661                 :             :                 "name the explicit object parameter");
    3662                 :             : 
    3663                 :           4 :       remembered_fn = fn;
    3664                 :           4 :     }
    3665                 :          73 :   else if (fn && DECL_STATIC_FUNCTION_P (fn))
    3666                 :           3 :     error ("%<this%> is unavailable for static member functions");
    3667                 :          70 :   else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
    3668                 :           0 :     error ("invalid use of %<this%> before it is valid");
    3669                 :          70 :   else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
    3670                 :           0 :     error ("invalid use of %<this%> after it is valid");
    3671                 :          70 :   else if (fn)
    3672                 :          22 :     error ("invalid use of %<this%> in non-member function");
    3673                 :             :   else
    3674                 :          48 :     error ("invalid use of %<this%> at top level");
    3675                 :          77 :   return error_mark_node;
    3676                 :             : }
    3677                 :             : 
    3678                 :             : /* Finish a pseudo-destructor expression.  If SCOPE is NULL, the
    3679                 :             :    expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
    3680                 :             :    the TYPE for the type given.  If SCOPE is non-NULL, the expression
    3681                 :             :    was of the form `OBJECT.SCOPE::~DESTRUCTOR'.  */
    3682                 :             : 
    3683                 :             : tree
    3684                 :       47893 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
    3685                 :             :                                location_t loc, tsubst_flags_t complain)
    3686                 :             : {
    3687                 :       47893 :   if (object == error_mark_node || destructor == error_mark_node)
    3688                 :             :     return error_mark_node;
    3689                 :             : 
    3690                 :       47884 :   gcc_assert (TYPE_P (destructor));
    3691                 :             : 
    3692                 :       47884 :   if (!processing_template_decl)
    3693                 :             :     {
    3694                 :       47863 :       if (scope == error_mark_node)
    3695                 :             :         {
    3696                 :           0 :           if (complain & tf_error)
    3697                 :           0 :             error_at (loc, "invalid qualifying scope in pseudo-destructor name");
    3698                 :           0 :           return error_mark_node;
    3699                 :             :         }
    3700                 :       47863 :       if (is_auto (destructor))
    3701                 :           3 :         destructor = TREE_TYPE (object);
    3702                 :       47863 :       if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
    3703                 :             :         {
    3704                 :           3 :           if (complain & tf_error)
    3705                 :           3 :             error_at (loc,
    3706                 :             :                       "qualified type %qT does not match destructor name ~%qT",
    3707                 :             :                       scope, destructor);
    3708                 :           3 :           return error_mark_node;
    3709                 :             :         }
    3710                 :             : 
    3711                 :             : 
    3712                 :             :       /* [expr.pseudo] says both:
    3713                 :             : 
    3714                 :             :            The type designated by the pseudo-destructor-name shall be
    3715                 :             :            the same as the object type.
    3716                 :             : 
    3717                 :             :          and:
    3718                 :             : 
    3719                 :             :            The cv-unqualified versions of the object type and of the
    3720                 :             :            type designated by the pseudo-destructor-name shall be the
    3721                 :             :            same type.
    3722                 :             : 
    3723                 :             :          We implement the more generous second sentence, since that is
    3724                 :             :          what most other compilers do.  */
    3725                 :       47860 :       if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
    3726                 :             :                                                       destructor))
    3727                 :             :         {
    3728                 :          12 :           if (complain & tf_error)
    3729                 :           9 :             error_at (loc, "%qE is not of type %qT", object, destructor);
    3730                 :          12 :           return error_mark_node;
    3731                 :             :         }
    3732                 :             :     }
    3733                 :             : 
    3734                 :       47869 :   tree type = (type_dependent_expression_p (object)
    3735                 :       47869 :                ? NULL_TREE : void_type_node);
    3736                 :             : 
    3737                 :       47869 :   return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
    3738                 :       47869 :                      scope, destructor);
    3739                 :             : }
    3740                 :             : 
    3741                 :             : /* Finish an expression of the form CODE EXPR.  */
    3742                 :             : 
    3743                 :             : cp_expr
    3744                 :    31883991 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
    3745                 :             :                       tsubst_flags_t complain)
    3746                 :             : {
    3747                 :             :   /* Build a location of the form:
    3748                 :             :        ++expr
    3749                 :             :        ^~~~~~
    3750                 :             :      with the caret at the operator token, ranging from the start
    3751                 :             :      of the operator token to the end of EXPR.  */
    3752                 :    31883991 :   location_t combined_loc = make_location (op_loc,
    3753                 :             :                                            op_loc, expr.get_finish ());
    3754                 :    31883991 :   cp_expr result = build_x_unary_op (combined_loc, code, expr,
    3755                 :    31883991 :                                      NULL_TREE, complain);
    3756                 :             :   /* TODO: build_x_unary_op doesn't always honor the location.  */
    3757                 :    31883991 :   result.set_location (combined_loc);
    3758                 :             : 
    3759                 :    31883991 :   if (result == error_mark_node)
    3760                 :             :     return result;
    3761                 :             : 
    3762                 :    31883541 :   if (!(complain & tf_warning))
    3763                 :             :     return result;
    3764                 :             : 
    3765                 :             :   /* These will never fold into a constant, so no need to check for
    3766                 :             :      overflow for them.  */
    3767                 :    31883541 :   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
    3768                 :             :     return result;
    3769                 :             : 
    3770                 :    17436083 :   tree result_ovl = result;
    3771                 :    17436083 :   tree expr_ovl = expr;
    3772                 :             : 
    3773                 :    17436083 :   if (!processing_template_decl)
    3774                 :     1459342 :     expr_ovl = cp_fully_fold (expr_ovl);
    3775                 :             : 
    3776                 :    17436083 :   if (!CONSTANT_CLASS_P (expr_ovl)
    3777                 :    17436083 :       || TREE_OVERFLOW_P (expr_ovl))
    3778                 :             :     return result;
    3779                 :             : 
    3780                 :      204972 :   if (!processing_template_decl)
    3781                 :      195211 :     result_ovl = cp_fully_fold (result_ovl);
    3782                 :             : 
    3783                 :      204972 :   if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
    3784                 :           9 :     overflow_warning (combined_loc, result_ovl);
    3785                 :             : 
    3786                 :             :   return result;
    3787                 :             : }
    3788                 :             : 
    3789                 :             : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
    3790                 :             :    elements.  */
    3791                 :             : 
    3792                 :             : static bool
    3793                 :          12 : maybe_zero_constructor_nelts (tree expr)
    3794                 :             : {
    3795                 :          12 :   if (CONSTRUCTOR_NELTS (expr) == 0)
    3796                 :             :     return true;
    3797                 :          12 :   if (!processing_template_decl)
    3798                 :             :     return false;
    3799                 :          30 :   for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
    3800                 :          21 :     if (!PACK_EXPANSION_P (elt.value))
    3801                 :             :       return false;
    3802                 :             :   return true;
    3803                 :             : }
    3804                 :             : 
    3805                 :             : /* Finish a compound-literal expression or C++11 functional cast with aggregate
    3806                 :             :    initializer.  TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
    3807                 :             :    is being cast.  */
    3808                 :             : 
    3809                 :             : tree
    3810                 :     6965108 : finish_compound_literal (tree type, tree compound_literal,
    3811                 :             :                          tsubst_flags_t complain,
    3812                 :             :                          fcl_t fcl_context)
    3813                 :             : {
    3814                 :     6965108 :   if (type == error_mark_node)
    3815                 :             :     return error_mark_node;
    3816                 :             : 
    3817                 :     6965095 :   if (TYPE_REF_P (type))
    3818                 :             :     {
    3819                 :          12 :       compound_literal
    3820                 :          12 :         = finish_compound_literal (TREE_TYPE (type), compound_literal,
    3821                 :             :                                    complain, fcl_context);
    3822                 :             :       /* The prvalue is then used to direct-initialize the reference.  */
    3823                 :          12 :       tree r = (perform_implicit_conversion_flags
    3824                 :          12 :                 (type, compound_literal, complain, LOOKUP_NORMAL));
    3825                 :          12 :       return convert_from_reference (r);
    3826                 :             :     }
    3827                 :             : 
    3828                 :     6965083 :   if (!TYPE_OBJ_P (type))
    3829                 :             :     {
    3830                 :             :       /* DR2351 */
    3831                 :          60 :       if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
    3832                 :             :         {
    3833                 :          12 :           if (!processing_template_decl)
    3834                 :           9 :             return void_node;
    3835                 :           3 :           TREE_TYPE (compound_literal) = type;
    3836                 :           3 :           TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
    3837                 :           3 :           CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
    3838                 :           3 :           return compound_literal;
    3839                 :             :         }
    3840                 :          21 :       else if (VOID_TYPE_P (type)
    3841                 :          15 :                && processing_template_decl
    3842                 :          33 :                && maybe_zero_constructor_nelts (compound_literal))
    3843                 :             :         /* If there are only packs in compound_literal, it could
    3844                 :             :            be void{} after pack expansion.  */;
    3845                 :             :       else
    3846                 :             :         {
    3847                 :          12 :           if (complain & tf_error)
    3848                 :           9 :             error ("compound literal of non-object type %qT", type);
    3849                 :          12 :           return error_mark_node;
    3850                 :             :         }
    3851                 :             :     }
    3852                 :             : 
    3853                 :     6965059 :   if (template_placeholder_p (type))
    3854                 :             :     {
    3855                 :       54139 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3856                 :             :                                 adc_variable_type);
    3857                 :       54139 :       if (type == error_mark_node)
    3858                 :             :         return error_mark_node;
    3859                 :             :     }
    3860                 :             :   /* C++23 auto{x}.  */
    3861                 :     6910920 :   else if (is_auto (type)
    3862                 :         109 :            && !AUTO_IS_DECLTYPE (type)
    3863                 :     6911027 :            && CONSTRUCTOR_NELTS (compound_literal) == 1)
    3864                 :             :     {
    3865                 :         101 :       if (is_constrained_auto (type))
    3866                 :             :         {
    3867                 :           2 :           if (complain & tf_error)
    3868                 :           2 :             error ("%<auto{x}%> cannot be constrained");
    3869                 :           2 :           return error_mark_node;
    3870                 :             :         }
    3871                 :          99 :       else if (cxx_dialect < cxx23)
    3872                 :           1 :         pedwarn (input_location, OPT_Wc__23_extensions,
    3873                 :             :                  "%<auto{x}%> only available with "
    3874                 :             :                  "%<-std=c++23%> or %<-std=gnu++23%>");
    3875                 :          99 :       type = do_auto_deduction (type, compound_literal, type, complain,
    3876                 :             :                                 adc_variable_type);
    3877                 :          99 :       if (type == error_mark_node)
    3878                 :             :         return error_mark_node;
    3879                 :             :     }
    3880                 :             : 
    3881                 :             :   /* Used to hold a copy of the compound literal in a template.  */
    3882                 :     6964956 :   tree orig_cl = NULL_TREE;
    3883                 :             : 
    3884                 :     6964956 :   if (processing_template_decl)
    3885                 :             :     {
    3886                 :     3276214 :       const bool dependent_p
    3887                 :     3276214 :         = (instantiation_dependent_expression_p (compound_literal)
    3888                 :     3276214 :            || dependent_type_p (type));
    3889                 :      715987 :       if (dependent_p)
    3890                 :             :         /* We're about to return, no need to copy.  */
    3891                 :             :         orig_cl = compound_literal;
    3892                 :             :       else
    3893                 :             :         /* We're going to need a copy.  */
    3894                 :      715987 :         orig_cl = unshare_constructor (compound_literal);
    3895                 :     3276214 :       TREE_TYPE (orig_cl) = type;
    3896                 :             :       /* Mark the expression as a compound literal.  */
    3897                 :     3276214 :       TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
    3898                 :             :       /* And as instantiation-dependent.  */
    3899                 :     3276214 :       CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
    3900                 :     3276214 :       if (fcl_context == fcl_c99)
    3901                 :         138 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
    3902                 :             :       /* If the compound literal is dependent, we're done for now.  */
    3903                 :     3276214 :       if (dependent_p)
    3904                 :             :         return orig_cl;
    3905                 :             :       /* Otherwise, do go on to e.g. check narrowing.  */
    3906                 :             :     }
    3907                 :             : 
    3908                 :     4404729 :   type = complete_type (type);
    3909                 :             : 
    3910                 :     4404729 :   if (TYPE_NON_AGGREGATE_CLASS (type))
    3911                 :             :     {
    3912                 :             :       /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
    3913                 :             :          everywhere that deals with function arguments would be a pain, so
    3914                 :             :          just wrap it in a TREE_LIST.  The parser set a flag so we know
    3915                 :             :          that it came from T{} rather than T({}).  */
    3916                 :      562930 :       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
    3917                 :      562930 :       compound_literal = build_tree_list (NULL_TREE, compound_literal);
    3918                 :      562930 :       return build_functional_cast (input_location, type,
    3919                 :      562930 :                                     compound_literal, complain);
    3920                 :             :     }
    3921                 :             : 
    3922                 :     3841799 :   if (TREE_CODE (type) == ARRAY_TYPE
    3923                 :     3841799 :       && check_array_initializer (NULL_TREE, type, compound_literal))
    3924                 :           9 :     return error_mark_node;
    3925                 :     3841790 :   compound_literal = reshape_init (type, compound_literal, complain);
    3926                 :     3636449 :   if (SCALAR_TYPE_P (type)
    3927                 :      441329 :       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
    3928                 :     3897447 :       && !check_narrowing (type, compound_literal, complain))
    3929                 :         102 :     return error_mark_node;
    3930                 :     3841688 :   if (TREE_CODE (type) == ARRAY_TYPE
    3931                 :     3841688 :       && TYPE_DOMAIN (type) == NULL_TREE)
    3932                 :             :     {
    3933                 :        1409 :       cp_complete_array_type_or_error (&type, compound_literal,
    3934                 :             :                                        false, complain);
    3935                 :        1409 :       if (type == error_mark_node)
    3936                 :             :         return error_mark_node;
    3937                 :             :     }
    3938                 :     3841685 :   compound_literal = digest_init_flags (type, compound_literal,
    3939                 :             :                                         LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
    3940                 :             :                                         complain);
    3941                 :     3841685 :   if (compound_literal == error_mark_node)
    3942                 :             :     return error_mark_node;
    3943                 :             : 
    3944                 :             :   /* If we're in a template, return the original compound literal.  */
    3945                 :     3841086 :   if (orig_cl)
    3946                 :             :     return orig_cl;
    3947                 :             : 
    3948                 :     3170962 :   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    3949                 :             :     {
    3950                 :     2769430 :       TREE_HAS_CONSTRUCTOR (compound_literal) = true;
    3951                 :     2769430 :       if (fcl_context == fcl_c99)
    3952                 :       33262 :         CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
    3953                 :             :     }
    3954                 :             : 
    3955                 :             :   /* Put static/constant array temporaries in static variables.  */
    3956                 :             :   /* FIXME all C99 compound literals should be variables rather than C++
    3957                 :             :      temporaries, unless they are used as an aggregate initializer.  */
    3958                 :     4101766 :   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
    3959                 :     2244105 :       && fcl_context == fcl_c99
    3960                 :          80 :       && TREE_CODE (type) == ARRAY_TYPE
    3961                 :          28 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    3962                 :     3170990 :       && initializer_constant_valid_p (compound_literal, type))
    3963                 :             :     {
    3964                 :          28 :       tree decl = create_temporary_var (type);
    3965                 :          28 :       DECL_CONTEXT (decl) = NULL_TREE;
    3966                 :          28 :       DECL_INITIAL (decl) = compound_literal;
    3967                 :          28 :       TREE_STATIC (decl) = 1;
    3968                 :          28 :       if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
    3969                 :             :         {
    3970                 :             :           /* 5.19 says that a constant expression can include an
    3971                 :             :              lvalue-rvalue conversion applied to "a glvalue of literal type
    3972                 :             :              that refers to a non-volatile temporary object initialized
    3973                 :             :              with a constant expression".  Rather than try to communicate
    3974                 :             :              that this VAR_DECL is a temporary, just mark it constexpr.  */
    3975                 :          24 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3976                 :          24 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    3977                 :          24 :           TREE_CONSTANT (decl) = true;
    3978                 :             :         }
    3979                 :          28 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    3980                 :          28 :       decl = pushdecl_top_level (decl);
    3981                 :          28 :       DECL_NAME (decl) = make_anon_name ();
    3982                 :          28 :       SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
    3983                 :             :       /* Make sure the destructor is callable.  */
    3984                 :          28 :       tree clean = cxx_maybe_build_cleanup (decl, complain);
    3985                 :          28 :       if (clean == error_mark_node)
    3986                 :             :         return error_mark_node;
    3987                 :          28 :       return decl;
    3988                 :             :     }
    3989                 :             : 
    3990                 :             :   /* Represent other compound literals with TARGET_EXPR so we produce
    3991                 :             :      a prvalue, and can elide copies.  */
    3992                 :     3170934 :   if (!VECTOR_TYPE_P (type)
    3993                 :     3138937 :       && (TREE_CODE (compound_literal) == CONSTRUCTOR
    3994                 :      401526 :           || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
    3995                 :             :     {
    3996                 :             :       /* The CONSTRUCTOR is now an initializer, not a compound literal.  */
    3997                 :     2737411 :       if (TREE_CODE (compound_literal) == CONSTRUCTOR)
    3998                 :     2737411 :         TREE_HAS_CONSTRUCTOR (compound_literal) = false;
    3999                 :     2737411 :       compound_literal = get_target_expr (compound_literal, complain);
    4000                 :             :     }
    4001                 :             :   else
    4002                 :             :     /* For e.g. int{42} just make sure it's a prvalue.  */
    4003                 :      433523 :     compound_literal = rvalue (compound_literal);
    4004                 :             : 
    4005                 :             :   return compound_literal;
    4006                 :             : }
    4007                 :             : 
    4008                 :             : /* Return the declaration for the function-name variable indicated by
    4009                 :             :    ID.  */
    4010                 :             : 
    4011                 :             : tree
    4012                 :      183429 : finish_fname (tree id)
    4013                 :             : {
    4014                 :      183429 :   tree decl = fname_decl (input_location, C_RID_CODE (id), id);
    4015                 :             :   /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
    4016                 :             :      of a consteval-block-declaration, a variable __func__ is implicitly
    4017                 :             :      defined...".  We could be in a consteval block in a function, though,
    4018                 :             :      and then we shouldn't warn.  */
    4019                 :      183429 :   if (current_function_decl
    4020                 :      183429 :       && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
    4021                 :           4 :     pedwarn (input_location, 0, "%qD is not defined outside of function scope",
    4022                 :             :              decl);
    4023                 :      183429 :   if (processing_template_decl && current_function_decl
    4024                 :      110277 :       && decl != error_mark_node)
    4025                 :      110277 :     decl = DECL_NAME (decl);
    4026                 :      183429 :   return decl;
    4027                 :             : }
    4028                 :             : 
    4029                 :             : /* Finish a translation unit.  */
    4030                 :             : 
    4031                 :             : void
    4032                 :       94944 : finish_translation_unit (void)
    4033                 :             : {
    4034                 :             :   /* In case there were missing closebraces,
    4035                 :             :      get us back to the global binding level.  */
    4036                 :       94944 :   pop_everything ();
    4037                 :      189888 :   while (current_namespace != global_namespace)
    4038                 :           0 :     pop_namespace ();
    4039                 :             : 
    4040                 :             :   /* Do file scope __FUNCTION__ et al.  */
    4041                 :       94944 :   finish_fname_decls ();
    4042                 :             : 
    4043                 :       94944 :   if (vec_safe_length (scope_chain->omp_declare_target_attribute))
    4044                 :             :     {
    4045                 :          12 :       cp_omp_declare_target_attr
    4046                 :          12 :         a = scope_chain->omp_declare_target_attribute->pop ();
    4047                 :          12 :       if (!errorcount)
    4048                 :           9 :         error ("%qs without corresponding %qs",
    4049                 :             :                a.device_type >= 0 ? "#pragma omp begin declare target"
    4050                 :             :                                   : "#pragma omp declare target",
    4051                 :             :                "#pragma omp end declare target");
    4052                 :          24 :       vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
    4053                 :             :     }
    4054                 :       94944 :   if (vec_safe_length (scope_chain->omp_begin_assumes))
    4055                 :             :     {
    4056                 :           3 :       if (!errorcount)
    4057                 :           3 :         error ("%qs without corresponding %qs",
    4058                 :             :                "#pragma omp begin assumes", "#pragma omp end assumes");
    4059                 :           3 :       vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
    4060                 :             :     }
    4061                 :       94944 : }
    4062                 :             : 
    4063                 :             : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
    4064                 :             :    Returns the parameter.  */
    4065                 :             : 
    4066                 :             : tree
    4067                 :   141502525 : finish_template_type_parm (tree aggr, tree identifier)
    4068                 :             : {
    4069                 :   141502525 :   if (aggr != class_type_node)
    4070                 :             :     {
    4071                 :           0 :       permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
    4072                 :           0 :       aggr = class_type_node;
    4073                 :             :     }
    4074                 :             : 
    4075                 :   141502525 :   return build_tree_list (aggr, identifier);
    4076                 :             : }
    4077                 :             : 
    4078                 :             : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
    4079                 :             :    Returns the parameter.  */
    4080                 :             : 
    4081                 :             : tree
    4082                 :      326127 : finish_template_template_parm (tree aggr, tree identifier)
    4083                 :             : {
    4084                 :      326127 :   tree decl = build_decl (input_location,
    4085                 :             :                           TYPE_DECL, identifier, NULL_TREE);
    4086                 :             : 
    4087                 :      326127 :   tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
    4088                 :      326127 :   DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
    4089                 :      326127 :   DECL_TEMPLATE_RESULT (tmpl) = decl;
    4090                 :      326127 :   DECL_ARTIFICIAL (decl) = 1;
    4091                 :             : 
    4092                 :             :   /* Associate the constraints with the underlying declaration,
    4093                 :             :      not the template.  */
    4094                 :      326127 :   tree constr = current_template_constraints ();
    4095                 :      326127 :   set_constraints (decl, constr);
    4096                 :             : 
    4097                 :      326127 :   end_template_decl ();
    4098                 :             : 
    4099                 :      326127 :   gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
    4100                 :             : 
    4101                 :      326127 :   check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
    4102                 :             :                            /*is_primary=*/true, /*is_partial=*/false,
    4103                 :             :                            /*is_friend=*/0);
    4104                 :             : 
    4105                 :      326127 :   return finish_template_type_parm (aggr, tmpl);
    4106                 :             : }
    4107                 :             : 
    4108                 :             : /* ARGUMENT is the default-argument value for a template template
    4109                 :             :    parameter.  If ARGUMENT is invalid, issue error messages and return
    4110                 :             :    the ERROR_MARK_NODE.  Otherwise, ARGUMENT itself is returned.  */
    4111                 :             : 
    4112                 :             : tree
    4113                 :         831 : check_template_template_default_arg (tree argument)
    4114                 :             : {
    4115                 :         831 :   if (TREE_CODE (argument) != TEMPLATE_DECL
    4116                 :             :       && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
    4117                 :             :       && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
    4118                 :             :     {
    4119                 :             :       if (TREE_CODE (argument) == TYPE_DECL)
    4120                 :             :         {
    4121                 :          18 :           if (tree t = maybe_get_template_decl_from_type_decl (argument))
    4122                 :          18 :             if (TREE_CODE (t) == TEMPLATE_DECL)
    4123                 :             :               return t;
    4124                 :          15 :           error ("invalid use of type %qT as a default value for a template "
    4125                 :          15 :                  "template-parameter", TREE_TYPE (argument));
    4126                 :             :         }
    4127                 :             :       else
    4128                 :           0 :         error ("invalid default argument for a template template parameter");
    4129                 :          15 :       return error_mark_node;
    4130                 :             :     }
    4131                 :             : 
    4132                 :             :   return argument;
    4133                 :             : }
    4134                 :             : 
    4135                 :             : /* Begin a class definition, as indicated by T.  */
    4136                 :             : 
    4137                 :             : tree
    4138                 :    25735705 : begin_class_definition (tree t)
    4139                 :             : {
    4140                 :    25735705 :   if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
    4141                 :          33 :     return error_mark_node;
    4142                 :             : 
    4143                 :    25735785 :   if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
    4144                 :             :     {
    4145                 :           9 :       error ("definition of %q#T inside template parameter list", t);
    4146                 :           9 :       return error_mark_node;
    4147                 :             :     }
    4148                 :             : 
    4149                 :             :   /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
    4150                 :             :      are passed the same as decimal scalar types.  */
    4151                 :    25735663 :   if (TREE_CODE (t) == RECORD_TYPE
    4152                 :    25275842 :       && !processing_template_decl)
    4153                 :             :     {
    4154                 :     8537001 :       tree ns = TYPE_CONTEXT (t);
    4155                 :     8537001 :       if (ns && TREE_CODE (ns) == NAMESPACE_DECL
    4156                 :     6826569 :           && DECL_CONTEXT (ns) == std_node
    4157                 :      858370 :           && DECL_NAME (ns)
    4158                 :     9395351 :           && id_equal (DECL_NAME (ns), "decimal"))
    4159                 :             :         {
    4160                 :         150 :           const char *n = TYPE_NAME_STRING (t);
    4161                 :         150 :           if ((strcmp (n, "decimal32") == 0)
    4162                 :         101 :               || (strcmp (n, "decimal64") == 0)
    4163                 :          46 :               || (strcmp (n, "decimal128") == 0))
    4164                 :         147 :             TYPE_TRANSPARENT_AGGR (t) = 1;
    4165                 :             :         }
    4166                 :             :     }
    4167                 :             : 
    4168                 :             :   /* A non-implicit typename comes from code like:
    4169                 :             : 
    4170                 :             :        template <typename T> struct A {
    4171                 :             :          template <typename U> struct A<T>::B ...
    4172                 :             : 
    4173                 :             :      This is erroneous.  */
    4174                 :    17198662 :   else if (TREE_CODE (t) == TYPENAME_TYPE)
    4175                 :             :     {
    4176                 :           0 :       error ("invalid definition of qualified type %qT", t);
    4177                 :           0 :       t = error_mark_node;
    4178                 :             :     }
    4179                 :             : 
    4180                 :    25735663 :   if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
    4181                 :             :     {
    4182                 :           0 :       t = make_class_type (RECORD_TYPE);
    4183                 :           0 :       pushtag (make_anon_name (), t);
    4184                 :             :     }
    4185                 :             : 
    4186                 :    25735663 :   if (TYPE_BEING_DEFINED (t))
    4187                 :             :     {
    4188                 :           0 :       t = make_class_type (TREE_CODE (t));
    4189                 :           0 :       pushtag (TYPE_IDENTIFIER (t), t);
    4190                 :             :     }
    4191                 :             : 
    4192                 :    25735663 :   if (modules_p ())
    4193                 :             :     {
    4194                 :      104893 :       if (!module_may_redeclare (TYPE_NAME (t)))
    4195                 :           0 :         return error_mark_node;
    4196                 :      104893 :       set_instantiating_module (TYPE_NAME (t));
    4197                 :      104893 :       set_defining_module (TYPE_NAME (t));
    4198                 :             :     }
    4199                 :             : 
    4200                 :    25735663 :   maybe_process_partial_specialization (t);
    4201                 :    25735663 :   pushclass (t);
    4202                 :    25735663 :   TYPE_BEING_DEFINED (t) = 1;
    4203                 :    25735663 :   class_binding_level->defining_class_p = 1;
    4204                 :             : 
    4205                 :    25735663 :   if (flag_pack_struct)
    4206                 :             :     {
    4207                 :          99 :       tree v;
    4208                 :          99 :       TYPE_PACKED (t) = 1;
    4209                 :             :       /* Even though the type is being defined for the first time
    4210                 :             :          here, there might have been a forward declaration, so there
    4211                 :             :          might be cv-qualified variants of T.  */
    4212                 :          99 :       for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    4213                 :           0 :         TYPE_PACKED (v) = 1;
    4214                 :             :     }
    4215                 :             :   /* Reset the interface data, at the earliest possible
    4216                 :             :      moment, as it might have been set via a class foo;
    4217                 :             :      before.  */
    4218                 :    53112842 :   if (! TYPE_UNNAMED_P (t))
    4219                 :             :     {
    4220                 :    25069453 :       struct c_fileinfo *finfo = \
    4221                 :    25069453 :         get_fileinfo (LOCATION_FILE (input_location));
    4222                 :    25069453 :       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
    4223                 :    25069453 :       SET_CLASSTYPE_INTERFACE_UNKNOWN_X
    4224                 :             :         (t, finfo->interface_unknown);
    4225                 :             :     }
    4226                 :    25735663 :   reset_specialization ();
    4227                 :             : 
    4228                 :             :   /* Make a declaration for this class in its own scope.  */
    4229                 :    25735663 :   build_self_reference ();
    4230                 :             : 
    4231                 :    25735663 :   return t;
    4232                 :             : }
    4233                 :             : 
    4234                 :             : /* Finish the member declaration given by DECL.  */
    4235                 :             : 
    4236                 :             : void
    4237                 :   348735015 : finish_member_declaration (tree decl)
    4238                 :             : {
    4239                 :   348735015 :   if (decl == error_mark_node || decl == NULL_TREE)
    4240                 :             :     return;
    4241                 :             : 
    4242                 :   348734064 :   if (decl == void_type_node)
    4243                 :             :     /* The COMPONENT was a friend, not a member, and so there's
    4244                 :             :        nothing for us to do.  */
    4245                 :             :     return;
    4246                 :             : 
    4247                 :             :   /* We should see only one DECL at a time.  */
    4248                 :   348734064 :   gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
    4249                 :             : 
    4250                 :             :   /* Don't add decls after definition.  */
    4251                 :   348734085 :   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
    4252                 :             :               /* We can add lambda types when late parsing default
    4253                 :             :                  arguments.  */
    4254                 :             :               || LAMBDA_TYPE_P (TREE_TYPE (decl)));
    4255                 :             : 
    4256                 :             :   /* Set up access control for DECL.  */
    4257                 :   348734064 :   TREE_PRIVATE (decl)
    4258                 :   348734064 :     = (current_access_specifier == access_private_node);
    4259                 :   348734064 :   TREE_PROTECTED (decl)
    4260                 :   348734064 :     = (current_access_specifier == access_protected_node);
    4261                 :   348734064 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    4262                 :             :     {
    4263                 :    40594220 :       TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
    4264                 :    40594220 :       TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
    4265                 :             :     }
    4266                 :             : 
    4267                 :             :   /* Mark the DECL as a member of the current class, unless it's
    4268                 :             :      a member of an enumeration.  */
    4269                 :   348734064 :   if (TREE_CODE (decl) != CONST_DECL)
    4270                 :   346396301 :     DECL_CONTEXT (decl) = current_class_type;
    4271                 :             : 
    4272                 :             :   /* Remember the single FIELD_DECL an anonymous aggregate type is used for.  */
    4273                 :   348734064 :   if (TREE_CODE (decl) == FIELD_DECL
    4274                 :   348734064 :       && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    4275                 :             :     {
    4276                 :      170191 :       gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
    4277                 :      170191 :       ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
    4278                 :             :     }
    4279                 :             : 
    4280                 :   348734064 :   if (TREE_CODE (decl) == USING_DECL)
    4281                 :             :     /* Avoid debug info for class-scope USING_DECLS for now, we'll
    4282                 :             :        call cp_emit_debug_info_for_using later. */
    4283                 :     3011414 :     DECL_IGNORED_P (decl) = 1;
    4284                 :             : 
    4285                 :             :   /* Check for bare parameter packs in the non-static data member
    4286                 :             :      declaration.  */
    4287                 :   348734064 :   if (TREE_CODE (decl) == FIELD_DECL)
    4288                 :             :     {
    4289                 :    25199519 :       if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
    4290                 :           9 :         TREE_TYPE (decl) = error_mark_node;
    4291                 :    25199519 :       if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
    4292                 :           0 :         DECL_ATTRIBUTES (decl) = NULL_TREE;
    4293                 :             :     }
    4294                 :             : 
    4295                 :             :   /* [dcl.link]
    4296                 :             : 
    4297                 :             :      A C language linkage is ignored for the names of class members
    4298                 :             :      and the member function type of class member functions.  */
    4299                 :   348734064 :   if (DECL_LANG_SPECIFIC (decl))
    4300                 :   318125440 :     SET_DECL_LANGUAGE (decl, lang_cplusplus);
    4301                 :             : 
    4302                 :   348734064 :   bool add = false;
    4303                 :             : 
    4304                 :             :   /* Functions and non-functions are added differently.  */
    4305                 :   348734064 :   if (DECL_DECLARES_FUNCTION_P (decl))
    4306                 :   184208446 :     add = add_method (current_class_type, decl, false);
    4307                 :             :   /* Enter the DECL into the scope of the class, if the class
    4308                 :             :      isn't a closure (whose fields are supposed to be unnamed).  */
    4309                 :   164525618 :   else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
    4310                 :   162208788 :            || maybe_push_used_methods (decl)
    4311                 :   325246082 :            || pushdecl_class_level (decl))
    4312                 :             :     add = true;
    4313                 :             : 
    4314                 :   184208446 :   if (add)
    4315                 :             :     {
    4316                 :             :       /* All TYPE_DECLs go at the end of TYPE_FIELDS.  Ordinary fields
    4317                 :             :          go at the beginning.  The reason is that
    4318                 :             :          legacy_nonfn_member_lookup searches the list in order, and we
    4319                 :             :          want a field name to override a type name so that the "struct
    4320                 :             :          stat hack" will work.  In particular:
    4321                 :             : 
    4322                 :             :            struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
    4323                 :             : 
    4324                 :             :          is valid.  */
    4325                 :             : 
    4326                 :   348727651 :       if (TREE_CODE (decl) == TYPE_DECL)
    4327                 :   115816056 :         TYPE_FIELDS (current_class_type)
    4328                 :   231632112 :           = chainon (TYPE_FIELDS (current_class_type), decl);
    4329                 :             :       else
    4330                 :             :         {
    4331                 :   232911595 :           DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
    4332                 :   232911595 :           TYPE_FIELDS (current_class_type) = decl;
    4333                 :             :         }
    4334                 :             : 
    4335                 :   348727651 :       maybe_add_class_template_decl_list (current_class_type, decl,
    4336                 :             :                                           /*friend_p=*/0);
    4337                 :             :     }
    4338                 :             : }
    4339                 :             : 
    4340                 :             : /* Finish processing a complete template declaration.  The PARMS are
    4341                 :             :    the template parameters.  */
    4342                 :             : 
    4343                 :             : void
    4344                 :    80852981 : finish_template_decl (tree parms)
    4345                 :             : {
    4346                 :    80852981 :   if (parms)
    4347                 :    80852975 :     end_template_decl ();
    4348                 :             :   else
    4349                 :           6 :     end_specialization ();
    4350                 :    80852981 : }
    4351                 :             : 
    4352                 :             : // Returns the template type of the class scope being entered. If we're
    4353                 :             : // entering a constrained class scope. TYPE is the class template
    4354                 :             : // scope being entered and we may need to match the intended type with
    4355                 :             : // a constrained specialization. For example:
    4356                 :             : //
    4357                 :             : //    template<Object T>
    4358                 :             : //      struct S { void f(); }; #1
    4359                 :             : //
    4360                 :             : //    template<Object T>
    4361                 :             : //      void S<T>::f() { }      #2
    4362                 :             : //
    4363                 :             : // We check, in #2, that S<T> refers precisely to the type declared by
    4364                 :             : // #1 (i.e., that the constraints match). Note that the following should
    4365                 :             : // be an error since there is no specialization of S<T> that is
    4366                 :             : // unconstrained, but this is not diagnosed here.
    4367                 :             : //
    4368                 :             : //    template<typename T>
    4369                 :             : //      void S<T>::f() { }
    4370                 :             : //
    4371                 :             : // We cannot diagnose this problem here since this function also matches
    4372                 :             : // qualified template names that are not part of a definition. For example:
    4373                 :             : //
    4374                 :             : //    template<Integral T, Floating_point U>
    4375                 :             : //      typename pair<T, U>::first_type void f(T, U);
    4376                 :             : //
    4377                 :             : // Here, it is unlikely that there is a partial specialization of
    4378                 :             : // pair constrained for Integral and Floating_point arguments.
    4379                 :             : //
    4380                 :             : // The general rule is: if a constrained specialization with matching
    4381                 :             : // constraints is found return that type. Also note that if TYPE is not a
    4382                 :             : // class-type (e.g. a typename type), then no fixup is needed.
    4383                 :             : 
    4384                 :             : static tree
    4385                 :     4691708 : fixup_template_type (tree type)
    4386                 :             : {
    4387                 :             :   // Find the template parameter list at the a depth appropriate to
    4388                 :             :   // the scope we're trying to enter.
    4389                 :     4691708 :   tree parms = current_template_parms;
    4390                 :     4691708 :   int depth = template_class_depth (type);
    4391                 :    10493467 :   for (int n = current_template_depth; n > depth && parms; --n)
    4392                 :     1110051 :     parms = TREE_CHAIN (parms);
    4393                 :     4691708 :   if (!parms)
    4394                 :             :     return type;
    4395                 :     4691703 :   tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
    4396                 :     4691703 :   tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
    4397                 :             : 
    4398                 :             :   // Search for a specialization whose type and constraints match.
    4399                 :     4691703 :   tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
    4400                 :     4691703 :   tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
    4401                 :     9181006 :   while (specs)
    4402                 :             :     {
    4403                 :     4595540 :       tree spec_constr = get_constraints (TREE_VALUE (specs));
    4404                 :             : 
    4405                 :             :       // If the type and constraints match a specialization, then we
    4406                 :             :       // are entering that type.
    4407                 :     4595540 :       if (same_type_p (type, TREE_TYPE (specs))
    4408                 :     4595540 :           && equivalent_constraints (cur_constr, spec_constr))
    4409                 :      106237 :         return TREE_TYPE (specs);
    4410                 :     4489303 :       specs = TREE_CHAIN (specs);
    4411                 :             :     }
    4412                 :             : 
    4413                 :             :   // If no specialization matches, then must return the type
    4414                 :             :   // previously found.
    4415                 :             :   return type;
    4416                 :             : }
    4417                 :             : 
    4418                 :             : /* Finish processing a template-id (which names a type) of the form
    4419                 :             :    NAME < ARGS >.  Return the TYPE_DECL for the type named by the
    4420                 :             :    template-id.  If ENTERING_SCOPE is nonzero we are about to enter
    4421                 :             :    the scope of template-id indicated.  */
    4422                 :             : 
    4423                 :             : tree
    4424                 :   165969105 : finish_template_type (tree name, tree args, int entering_scope)
    4425                 :             : {
    4426                 :   165969105 :   tree type;
    4427                 :             : 
    4428                 :   165969105 :   type = lookup_template_class (name, args,
    4429                 :             :                                 NULL_TREE, NULL_TREE,
    4430                 :             :                                 tf_warning_or_error | tf_user);
    4431                 :   165969102 :   if (entering_scope)
    4432                 :    18937462 :     type = adjust_type_for_entering_scope (type);
    4433                 :             : 
    4434                 :             :   /* If we might be entering the scope of a partial specialization,
    4435                 :             :      find the one with the right constraints.  */
    4436                 :   165969102 :   if (flag_concepts
    4437                 :    51209854 :       && entering_scope
    4438                 :     4866711 :       && CLASS_TYPE_P (type)
    4439                 :     4817666 :       && CLASSTYPE_TEMPLATE_INFO (type)
    4440                 :     4817660 :       && dependent_type_p (type)
    4441                 :   170660810 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
    4442                 :     4691708 :     type = fixup_template_type (type);
    4443                 :             : 
    4444                 :   165969102 :   if (type == error_mark_node)
    4445                 :             :     return type;
    4446                 :   165966852 :   else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
    4447                 :   140154629 :     return TYPE_STUB_DECL (type);
    4448                 :             :   else
    4449                 :    25812223 :     return TYPE_NAME (type);
    4450                 :             : }
    4451                 :             : 
    4452                 :             : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
    4453                 :             :    Return a TREE_LIST containing the ACCESS_SPECIFIER and the
    4454                 :             :    BASE_CLASS, or NULL_TREE if an error occurred.  The
    4455                 :             :    ACCESS_SPECIFIER is one of
    4456                 :             :    access_{default,public,protected_private}_node.  For a virtual base
    4457                 :             :    we set TREE_TYPE.  */
    4458                 :             : 
    4459                 :             : tree
    4460                 :    10742152 : finish_base_specifier (tree base, tree access, bool virtual_p)
    4461                 :             : {
    4462                 :    10742152 :   tree result;
    4463                 :             : 
    4464                 :    10742152 :   if (base == error_mark_node)
    4465                 :             :     {
    4466                 :           0 :       error ("invalid base-class specification");
    4467                 :           0 :       result = NULL_TREE;
    4468                 :             :     }
    4469                 :    10742152 :   else if (! MAYBE_CLASS_TYPE_P (base))
    4470                 :             :     {
    4471                 :           3 :       error ("%qT is not a class type", base);
    4472                 :           3 :       result = NULL_TREE;
    4473                 :             :     }
    4474                 :             :   else
    4475                 :             :     {
    4476                 :    10742149 :       if (cp_type_quals (base) != 0)
    4477                 :             :         {
    4478                 :             :           /* DR 484: Can a base-specifier name a cv-qualified
    4479                 :             :              class type?  */
    4480                 :          12 :           base = TYPE_MAIN_VARIANT (base);
    4481                 :             :         }
    4482                 :    10742149 :       result = build_tree_list (access, base);
    4483                 :    10742149 :       if (virtual_p)
    4484                 :       26176 :         TREE_TYPE (result) = integer_type_node;
    4485                 :             :     }
    4486                 :             : 
    4487                 :    10742152 :   return result;
    4488                 :             : }
    4489                 :             : 
    4490                 :             : /* If FNS is a member function, a set of member functions, or a
    4491                 :             :    template-id referring to one or more member functions, return a
    4492                 :             :    BASELINK for FNS, incorporating the current access context.
    4493                 :             :    Otherwise, return FNS unchanged.  */
    4494                 :             : 
    4495                 :             : tree
    4496                 :   143931736 : baselink_for_fns (tree fns)
    4497                 :             : {
    4498                 :   143931736 :   tree scope;
    4499                 :   143931736 :   tree cl;
    4500                 :             : 
    4501                 :   143931736 :   if (BASELINK_P (fns)
    4502                 :   143931736 :       || error_operand_p (fns))
    4503                 :             :     return fns;
    4504                 :             : 
    4505                 :   128468962 :   scope = ovl_scope (fns);
    4506                 :   128468962 :   if (!CLASS_TYPE_P (scope))
    4507                 :             :     return fns;
    4508                 :             : 
    4509                 :     6453537 :   cl = currently_open_derived_class (scope);
    4510                 :     6453537 :   if (!cl)
    4511                 :     4557965 :     cl = scope;
    4512                 :     6453537 :   tree access_path = TYPE_BINFO (cl);
    4513                 :     6453537 :   tree conv_path = (cl == scope ? access_path
    4514                 :      736356 :                     : lookup_base (cl, scope, ba_any, NULL, tf_none));
    4515                 :     6453537 :   return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
    4516                 :             : }
    4517                 :             : 
    4518                 :             : /* Returns true iff we are currently parsing a lambda-declarator.  */
    4519                 :             : 
    4520                 :             : static bool
    4521                 :  1487722540 : parsing_lambda_declarator ()
    4522                 :             : {
    4523                 :  1487722540 :   cp_binding_level *b = current_binding_level;
    4524                 :  1489230366 :   while (b->kind == sk_template_parms || b->kind == sk_function_parms)
    4525                 :     1507826 :     b = b->level_chain;
    4526                 :  1487722540 :   return b->kind == sk_lambda;
    4527                 :             : }
    4528                 :             : 
    4529                 :             : /* Returns true iff DECL is a variable from a function outside
    4530                 :             :    the current one.  */
    4531                 :             : 
    4532                 :             : static bool
    4533                 :  1977782365 : outer_var_p (tree decl)
    4534                 :             : {
    4535                 :             :   /* These should have been stripped or otherwise handled by the caller.  */
    4536                 :  1977782365 :   gcc_checking_assert (!REFERENCE_REF_P (decl));
    4537                 :             : 
    4538                 :  1268979480 :   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
    4539                 :  1797323943 :           && DECL_FUNCTION_SCOPE_P (decl)
    4540                 :             :           /* Don't get confused by temporaries.  */
    4541                 :  1504271058 :           && DECL_NAME (decl)
    4542                 :  3470961643 :           && (DECL_CONTEXT (decl) != current_function_decl
    4543                 :  1486614717 :               || parsing_nsdmi ()
    4544                 :             :               /* Also consider captures as outer vars if we are in
    4545                 :             :                  decltype in a lambda declarator as in:
    4546                 :             :                    auto l = [j=0]() -> decltype((j)) { ... }
    4547                 :             :                  for the sake of finish_decltype_type.
    4548                 :             : 
    4549                 :             :                  (Similar issue also affects non-lambdas, but vexing parse
    4550                 :             :                  makes it more difficult to handle than lambdas.)  */
    4551                 :  1486614253 :               || parsing_lambda_declarator ()));
    4552                 :             : }
    4553                 :             : 
    4554                 :             : /* As above, but also checks that DECL is automatic.  */
    4555                 :             : 
    4556                 :             : bool
    4557                 :  1977782365 : outer_automatic_var_p (tree decl)
    4558                 :             : {
    4559                 :  1977782365 :   return (outer_var_p (decl)
    4560                 :  1977782365 :           && !TREE_STATIC (decl));
    4561                 :             : }
    4562                 :             : 
    4563                 :             : /* DECL satisfies outer_automatic_var_p.  Possibly complain about it or
    4564                 :             :    rewrite it for lambda capture.
    4565                 :             : 
    4566                 :             :    If ODR_USE is true, we're being called from mark_use, and we complain about
    4567                 :             :    use of constant variables.  If ODR_USE is false, we're being called for the
    4568                 :             :    id-expression, and we do lambda capture.  */
    4569                 :             : 
    4570                 :             : tree
    4571                 :     2847611 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
    4572                 :             : {
    4573                 :     2847611 :   if (cp_unevaluated_operand)
    4574                 :             :     {
    4575                 :     1739222 :       tree type = TREE_TYPE (decl);
    4576                 :     1739222 :       if (!dependent_type_p (type)
    4577                 :     1739222 :           && variably_modified_type_p (type, NULL_TREE))
    4578                 :             :         /* VLAs are used even in unevaluated context.  */;
    4579                 :             :       else
    4580                 :             :         /* It's not a use (3.2) if we're in an unevaluated context.  */
    4581                 :     1739216 :         return decl;
    4582                 :             :     }
    4583                 :     1108395 :   if (decl == error_mark_node)
    4584                 :             :     return decl;
    4585                 :             : 
    4586                 :     1108395 :   tree context = DECL_CONTEXT (decl);
    4587                 :     1108395 :   tree containing_function = current_function_decl;
    4588                 :     1108395 :   tree lambda_stack = NULL_TREE;
    4589                 :     1108395 :   tree lambda_expr = NULL_TREE;
    4590                 :     1108395 :   tree initializer = convert_from_reference (decl);
    4591                 :     1108395 :   tree var = strip_normal_capture_proxy (decl);
    4592                 :             : 
    4593                 :             :   /* Mark it as used now even if the use is ill-formed.  */
    4594                 :     1108395 :   if (!mark_used (decl, complain))
    4595                 :           3 :     return error_mark_node;
    4596                 :             : 
    4597                 :     1108392 :   if (parsing_nsdmi () || parsing_lambda_declarator ())
    4598                 :             :     containing_function = NULL_TREE;
    4599                 :             : 
    4600                 :     2216230 :   if (containing_function && LAMBDA_FUNCTION_P (containing_function))
    4601                 :             :     {
    4602                 :             :       /* Check whether we've already built a proxy.  */
    4603                 :     1108024 :       tree d = retrieve_local_specialization (var);
    4604                 :             : 
    4605                 :     1108024 :       if (d && d != decl && is_capture_proxy (d))
    4606                 :             :         {
    4607                 :      575105 :           if (DECL_CONTEXT (d) == containing_function)
    4608                 :             :             /* We already have an inner proxy.  */
    4609                 :             :             return d;
    4610                 :             :           else
    4611                 :             :             /* We need to capture an outer proxy.  */
    4612                 :        2989 :             return process_outer_var_ref (d, complain, odr_use);
    4613                 :             :         }
    4614                 :             :     }
    4615                 :             : 
    4616                 :             :   /* If we are in a lambda function, we can move out until we hit
    4617                 :             :      1. the context,
    4618                 :             :      2. a non-lambda function, or
    4619                 :             :      3. a non-default capturing lambda function.  */
    4620                 :     1068871 :   while (context != containing_function
    4621                 :             :          /* containing_function can be null with invalid generic lambdas.  */
    4622                 :     1068871 :          && containing_function
    4623                 :     1604796 :          && LAMBDA_FUNCTION_P (containing_function))
    4624                 :             :     {
    4625                 :      535925 :       tree closure = DECL_CONTEXT (containing_function);
    4626                 :      535925 :       lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
    4627                 :             : 
    4628                 :      535925 :       if (TYPE_CLASS_SCOPE_P (closure))
    4629                 :             :         /* A lambda in an NSDMI (c++/64496).  */
    4630                 :             :         break;
    4631                 :             : 
    4632                 :      535922 :       if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4633                 :             :         break;
    4634                 :             : 
    4635                 :      535584 :       lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
    4636                 :             : 
    4637                 :      535584 :       containing_function = decl_function_context (containing_function);
    4638                 :             :     }
    4639                 :             : 
    4640                 :             :   /* In a lambda within a template, wait until instantiation time to implicitly
    4641                 :             :      capture a parameter pack.  We want to wait because we don't know if we're
    4642                 :             :      capturing the whole pack or a single element, and it's OK to wait because
    4643                 :             :      find_parameter_packs_r walks into the lambda body.  */
    4644                 :      533287 :   if (context == containing_function
    4645                 :      533287 :       && DECL_PACK_P (decl))
    4646                 :             :     return decl;
    4647                 :             : 
    4648                 :      499784 :   if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
    4649                 :             :     {
    4650                 :           6 :       if (complain & tf_error)
    4651                 :           6 :         error ("cannot capture member %qD of anonymous union", decl);
    4652                 :           6 :       return error_mark_node;
    4653                 :             :     }
    4654                 :             :   /* Do lambda capture when processing the id-expression, not when
    4655                 :             :      odr-using a variable.  */
    4656                 :      499778 :   if (!odr_use && context == containing_function)
    4657                 :      998138 :     decl = add_default_capture (lambda_stack,
    4658                 :      499069 :                                 /*id=*/DECL_NAME (decl), initializer);
    4659                 :             :   /* Only an odr-use of an outer automatic variable causes an
    4660                 :             :      error, and a constant variable can decay to a prvalue
    4661                 :             :      constant without odr-use.  So don't complain yet.  */
    4662                 :         709 :   else if (!odr_use && decl_constant_var_p (var))
    4663                 :             :     return var;
    4664                 :         254 :   else if (lambda_expr)
    4665                 :             :     {
    4666                 :          43 :       if (complain & tf_error)
    4667                 :             :         {
    4668                 :          43 :           auto_diagnostic_group d;
    4669                 :          43 :           error ("%qD is not captured", decl);
    4670                 :          43 :           tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
    4671                 :          43 :           if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
    4672                 :          40 :             inform (location_of (closure),
    4673                 :             :                     "the lambda has no capture-default");
    4674                 :           3 :           else if (TYPE_CLASS_SCOPE_P (closure))
    4675                 :           3 :             inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
    4676                 :             :                     "capture variables from the enclosing context",
    4677                 :           3 :                     TYPE_CONTEXT (closure));
    4678                 :          43 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4679                 :          43 :         }
    4680                 :          43 :       return error_mark_node;
    4681                 :             :     }
    4682                 :         211 :   else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
    4683                 :             :     /* Use of a parameter in a contract condition is fine.  */
    4684                 :             :     return decl;
    4685                 :             :   else
    4686                 :             :     {
    4687                 :          39 :       if (complain & tf_error)
    4688                 :             :         {
    4689                 :          39 :           auto_diagnostic_group d;
    4690                 :          57 :           error (VAR_P (decl)
    4691                 :             :                  ? G_("use of local variable with automatic storage from "
    4692                 :             :                       "containing function")
    4693                 :             :                  : G_("use of parameter from containing function"));
    4694                 :          39 :           inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
    4695                 :          39 :         }
    4696                 :          39 :       return error_mark_node;
    4697                 :             :     }
    4698                 :      499069 :   return decl;
    4699                 :             : }
    4700                 :             : 
    4701                 :             : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
    4702                 :             :    id-expression.  (See cp_parser_id_expression for details.)  SCOPE,
    4703                 :             :    if non-NULL, is the type or namespace used to explicitly qualify
    4704                 :             :    ID_EXPRESSION.  DECL is the entity to which that name has been
    4705                 :             :    resolved.
    4706                 :             : 
    4707                 :             :    *CONSTANT_EXPRESSION_P is true if we are presently parsing a
    4708                 :             :    constant-expression.  In that case, *NON_CONSTANT_EXPRESSION_P will
    4709                 :             :    be set to true if this expression isn't permitted in a
    4710                 :             :    constant-expression, but it is otherwise not set by this function.
    4711                 :             :    *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
    4712                 :             :    constant-expression, but a non-constant expression is also
    4713                 :             :    permissible.
    4714                 :             : 
    4715                 :             :    DONE is true if this expression is a complete postfix-expression;
    4716                 :             :    it is false if this expression is followed by '->', '[', '(', etc.
    4717                 :             :    ADDRESS_P is true iff this expression is the operand of '&'.
    4718                 :             :    TEMPLATE_P is true iff the qualified-id was of the form
    4719                 :             :    "A::template B".  TEMPLATE_ARG_P is true iff this qualified name
    4720                 :             :    appears as a template argument.
    4721                 :             : 
    4722                 :             :    If an error occurs, and it is the kind of error that might cause
    4723                 :             :    the parser to abort a tentative parse, *ERROR_MSG is filled in.  It
    4724                 :             :    is the caller's responsibility to issue the message.  *ERROR_MSG
    4725                 :             :    will be a string with static storage duration, so the caller need
    4726                 :             :    not "free" it.
    4727                 :             : 
    4728                 :             :    Return an expression for the entity, after issuing appropriate
    4729                 :             :    diagnostics.  This function is also responsible for transforming a
    4730                 :             :    reference to a non-static member into a COMPONENT_REF that makes
    4731                 :             :    the use of "this" explicit.
    4732                 :             : 
    4733                 :             :    Upon return, *IDK will be filled in appropriately.  */
    4734                 :             : static cp_expr
    4735                 :   632110107 : finish_id_expression_1 (tree id_expression,
    4736                 :             :                         tree decl,
    4737                 :             :                         tree scope,
    4738                 :             :                         cp_id_kind *idk,
    4739                 :             :                         bool integral_constant_expression_p,
    4740                 :             :                         bool allow_non_integral_constant_expression_p,
    4741                 :             :                         bool *non_integral_constant_expression_p,
    4742                 :             :                         bool template_p,
    4743                 :             :                         bool done,
    4744                 :             :                         bool address_p,
    4745                 :             :                         bool template_arg_p,
    4746                 :             :                         const char **error_msg,
    4747                 :             :                         location_t location)
    4748                 :             : {
    4749                 :   632110107 :   decl = strip_using_decl (decl);
    4750                 :             : 
    4751                 :             :   /* Initialize the output parameters.  */
    4752                 :   632110107 :   *idk = CP_ID_KIND_NONE;
    4753                 :   632110107 :   *error_msg = NULL;
    4754                 :             : 
    4755                 :   632110107 :   if (id_expression == error_mark_node)
    4756                 :          12 :     return error_mark_node;
    4757                 :             :   /* If we have a template-id, then no further lookup is
    4758                 :             :      required.  If the template-id was for a template-class, we
    4759                 :             :      will sometimes have a TYPE_DECL at this point.  */
    4760                 :   632110095 :   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4761                 :   599624117 :            || TREE_CODE (decl) == TYPE_DECL)
    4762                 :             :     ;
    4763                 :             :   /* Look up the name.  */
    4764                 :             :   else
    4765                 :             :     {
    4766                 :   599623227 :       if (decl == error_mark_node)
    4767                 :             :         {
    4768                 :             :           /* Name lookup failed.  */
    4769                 :       92506 :           if (scope
    4770                 :       92506 :               && (!TYPE_P (scope)
    4771                 :         116 :                   || (!dependentish_scope_p (scope)
    4772                 :         112 :                       && !(identifier_p (id_expression)
    4773                 :          97 :                            && IDENTIFIER_CONV_OP_P (id_expression)
    4774                 :           3 :                            && dependent_type_p (TREE_TYPE (id_expression))))))
    4775                 :             :             {
    4776                 :             :               /* If the qualifying type is non-dependent (and the name
    4777                 :             :                  does not name a conversion operator to a dependent
    4778                 :             :                  type), issue an error.  */
    4779                 :         361 :               qualified_name_lookup_error (scope, id_expression, decl, location);
    4780                 :         361 :               return error_mark_node;
    4781                 :             :             }
    4782                 :       92145 :           else if (!scope)
    4783                 :             :             {
    4784                 :             :               /* It may be resolved via Koenig lookup.  */
    4785                 :       92135 :               *idk = CP_ID_KIND_UNQUALIFIED;
    4786                 :       92135 :               return id_expression;
    4787                 :             :             }
    4788                 :             :           else
    4789                 :             :             decl = id_expression;
    4790                 :             :         }
    4791                 :             : 
    4792                 :             :       /* Remember that the name was used in the definition of
    4793                 :             :          the current class so that we can check later to see if
    4794                 :             :          the meaning would have been different after the class
    4795                 :             :          was entirely defined.  */
    4796                 :   599530721 :       if (!scope && decl != error_mark_node && identifier_p (id_expression))
    4797                 :   544538875 :         maybe_note_name_used_in_class (id_expression, decl);
    4798                 :             : 
    4799                 :             :       /* A use in unevaluated operand might not be instantiated appropriately
    4800                 :             :          if tsubst_copy builds a dummy parm, or if we never instantiate a
    4801                 :             :          generic lambda, so mark it now.  */
    4802                 :   599530731 :       if (processing_template_decl && cp_unevaluated_operand)
    4803                 :     9760376 :         mark_type_use (decl);
    4804                 :             : 
    4805                 :             :       /* Disallow uses of local variables from containing functions, except
    4806                 :             :          within lambda-expressions.  */
    4807                 :   599530731 :       if (outer_automatic_var_p (decl))
    4808                 :             :         {
    4809                 :     1968678 :           decl = process_outer_var_ref (decl, tf_warning_or_error);
    4810                 :     1968678 :           if (decl == error_mark_node)
    4811                 :          85 :             return error_mark_node;
    4812                 :             :         }
    4813                 :             : 
    4814                 :             :       /* Also disallow uses of function parameters outside the function
    4815                 :             :          body, except inside an unevaluated context (i.e. decltype).  */
    4816                 :   599530646 :       if (TREE_CODE (decl) == PARM_DECL
    4817                 :   252272961 :           && DECL_CONTEXT (decl) == NULL_TREE
    4818                 :     4459225 :           && !CONSTRAINT_VAR_P (decl)
    4819                 :     3468521 :           && !cp_unevaluated_operand
    4820                 :         454 :           && !processing_contract_condition
    4821                 :   599530689 :           && !processing_omp_trait_property_expr)
    4822                 :             :         {
    4823                 :          25 :           *error_msg = G_("use of parameter outside function body");
    4824                 :          25 :           return error_mark_node;
    4825                 :             :         }
    4826                 :             :     }
    4827                 :             : 
    4828                 :             :   /* If we didn't find anything, or what we found was a type,
    4829                 :             :      then this wasn't really an id-expression.  */
    4830                 :   632017489 :   if (TREE_CODE (decl) == TEMPLATE_DECL
    4831                 :   632017489 :       && !DECL_FUNCTION_TEMPLATE_P (decl))
    4832                 :             :     {
    4833                 :          59 :       *error_msg = G_("missing template arguments");
    4834                 :          59 :       return error_mark_node;
    4835                 :             :     }
    4836                 :   632017430 :   else if (TREE_CODE (decl) == TYPE_DECL
    4837                 :   632016540 :            || TREE_CODE (decl) == NAMESPACE_DECL)
    4838                 :             :     {
    4839                 :         905 :       *error_msg = G_("expected primary-expression");
    4840                 :         905 :       return error_mark_node;
    4841                 :             :     }
    4842                 :             : 
    4843                 :             :   /* If the name resolved to a template parameter, there is no
    4844                 :             :      need to look it up again later.  */
    4845                 :    29305833 :   if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
    4846                 :   642570785 :       || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4847                 :             :     {
    4848                 :    18751573 :       tree r;
    4849                 :             : 
    4850                 :    18751573 :       *idk = CP_ID_KIND_NONE;
    4851                 :    18751573 :       if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
    4852                 :           0 :         decl = TEMPLATE_PARM_DECL (decl);
    4853                 :    18751573 :       r = DECL_INITIAL (decl);
    4854                 :    18751573 :       if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
    4855                 :             :         {
    4856                 :             :           /* If the entity is a template parameter object for a template
    4857                 :             :              parameter of type T, the type of the expression is const T.  */
    4858                 :         162 :           tree ctype = TREE_TYPE (r);
    4859                 :         162 :           ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
    4860                 :             :                                                    | TYPE_QUAL_CONST));
    4861                 :         162 :           r = build1 (VIEW_CONVERT_EXPR, ctype, r);
    4862                 :             :         }
    4863                 :    18751573 :       r = convert_from_reference (r);
    4864                 :    18751573 :       if (integral_constant_expression_p
    4865                 :     3111538 :           && !dependent_type_p (TREE_TYPE (decl))
    4866                 :    21339292 :           && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
    4867                 :             :         {
    4868                 :         102 :           if (!allow_non_integral_constant_expression_p)
    4869                 :           6 :             error ("template parameter %qD of type %qT is not allowed in "
    4870                 :             :                    "an integral constant expression because it is not of "
    4871                 :           6 :                    "integral or enumeration type", decl, TREE_TYPE (decl));
    4872                 :         102 :           *non_integral_constant_expression_p = true;
    4873                 :             :         }
    4874                 :    18751573 :       return r;
    4875                 :             :     }
    4876                 :   613264952 :   else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
    4877                 :             :     {
    4878                 :           9 :       gcc_checking_assert (scope);
    4879                 :           9 :       *idk = CP_ID_KIND_QUALIFIED;
    4880                 :           9 :       cp_warn_deprecated_use_scopes (scope);
    4881                 :           9 :       decl = finish_qualified_id_expr (scope, decl, done, address_p,
    4882                 :             :                                        template_p, template_arg_p,
    4883                 :             :                                        tf_warning_or_error);
    4884                 :             :     }
    4885                 :             :   else
    4886                 :             :     {
    4887                 :   613264943 :       if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4888                 :    32485978 :           && variable_template_p (TREE_OPERAND (decl, 0))
    4889                 :   620051211 :           && !concept_check_p (decl))
    4890                 :             :         /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
    4891                 :             :            considered type-dependent) now, so that the dependence test that
    4892                 :             :            follows gives us the right answer: if it represents a non-dependent
    4893                 :             :            variable template-id then finish_template_variable will yield the
    4894                 :             :            corresponding non-dependent VAR_DECL.  */
    4895                 :     6786268 :         decl = finish_template_variable (decl);
    4896                 :             : 
    4897                 :   613264943 :       bool dependent_p = type_dependent_expression_p (decl);
    4898                 :             : 
    4899                 :             :       /* If the declaration was explicitly qualified indicate
    4900                 :             :          that.  The semantics of `A::f(3)' are different than
    4901                 :             :          `f(3)' if `f' is virtual.  */
    4902                 :  1226529886 :       *idk = (scope
    4903                 :   613264943 :               ? CP_ID_KIND_QUALIFIED
    4904                 :   541477386 :               : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
    4905                 :   541477386 :                  ? CP_ID_KIND_TEMPLATE_ID
    4906                 :             :                  : (dependent_p
    4907                 :   525881291 :                     ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
    4908                 :             :                     : CP_ID_KIND_UNQUALIFIED)));
    4909                 :             : 
    4910                 :   613264943 :       if (dependent_p
    4911                 :   613264943 :           && !scope
    4912                 :   360507827 :           && DECL_P (decl)
    4913                 :   950355565 :           && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
    4914                 :             :         /* Dependent type attributes on the decl mean that the TREE_TYPE is
    4915                 :             :            wrong, so just return the identifier.  */
    4916                 :          39 :         return id_expression;
    4917                 :             : 
    4918                 :   613264904 :       if (DECL_CLASS_TEMPLATE_P (decl))
    4919                 :             :         {
    4920                 :           0 :           error ("use of class template %qT as expression", decl);
    4921                 :           0 :           return error_mark_node;
    4922                 :             :         }
    4923                 :             : 
    4924                 :   613264904 :       if (TREE_CODE (decl) == TREE_LIST)
    4925                 :             :         {
    4926                 :             :           /* Ambiguous reference to base members.  */
    4927                 :           0 :           auto_diagnostic_group d;
    4928                 :           0 :           error ("request for member %qD is ambiguous in "
    4929                 :             :                  "multiple inheritance lattice", id_expression);
    4930                 :           0 :           print_candidates (decl);
    4931                 :           0 :           return error_mark_node;
    4932                 :           0 :         }
    4933                 :             : 
    4934                 :             :       /* Mark variable-like entities as used.  Functions are similarly
    4935                 :             :          marked either below or after overload resolution.  */
    4936                 :   613264904 :       if ((VAR_P (decl)
    4937                 :   446339531 :            || TREE_CODE (decl) == PARM_DECL
    4938                 :   194066601 :            || TREE_CODE (decl) == CONST_DECL
    4939                 :   183512341 :            || TREE_CODE (decl) == RESULT_DECL)
    4940                 :   876092094 :           && !mark_used (decl))
    4941                 :          12 :         return error_mark_node;
    4942                 :             : 
    4943                 :             :       /* Only certain kinds of names are allowed in constant
    4944                 :             :          expression.  Template parameters have already
    4945                 :             :          been handled above.  */
    4946                 :   613264889 :       if (! error_operand_p (decl)
    4947                 :   613264604 :           && !dependent_p
    4948                 :   613264604 :           && integral_constant_expression_p
    4949                 :    58427502 :           && !decl_constant_var_p (decl)
    4950                 :    48385462 :           && TREE_CODE (decl) != CONST_DECL
    4951                 :    42014223 :           && !builtin_valid_in_constant_expr_p (decl)
    4952                 :   655243105 :           && !concept_check_p (decl))
    4953                 :             :         {
    4954                 :    41762014 :           if (!allow_non_integral_constant_expression_p)
    4955                 :             :             {
    4956                 :          30 :               error ("%qD cannot appear in a constant-expression", decl);
    4957                 :          30 :               return error_mark_node;
    4958                 :             :             }
    4959                 :    41761984 :           *non_integral_constant_expression_p = true;
    4960                 :             :         }
    4961                 :             : 
    4962                 :   613264859 :       if (tree wrap = maybe_get_tls_wrapper_call (decl))
    4963                 :             :         /* Replace an evaluated use of the thread_local variable with
    4964                 :             :            a call to its wrapper.  */
    4965                 :             :         decl = wrap;
    4966                 :   613264347 :       else if (concept_check_p (decl))
    4967                 :             :         {
    4968                 :             :           /* Nothing more to do. All of the analysis for concept checks
    4969                 :             :              is done by build_conept_id, called from the parser.  */
    4970                 :             :         }
    4971                 :   607872354 :       else if (scope)
    4972                 :             :         {
    4973                 :    71038587 :           if (TREE_CODE (decl) == SCOPE_REF)
    4974                 :             :             {
    4975                 :       26400 :               gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
    4976                 :       26400 :               decl = TREE_OPERAND (decl, 1);
    4977                 :             :             }
    4978                 :             : 
    4979                 :    71038587 :           decl = (adjust_result_of_qualified_name_lookup
    4980                 :    71038587 :                   (decl, scope, current_nonlambda_class_type()));
    4981                 :             : 
    4982                 :    71038587 :           cp_warn_deprecated_use_scopes (scope);
    4983                 :             : 
    4984                 :    71038587 :           if (TYPE_P (scope))
    4985                 :    10752392 :             decl = finish_qualified_id_expr (scope,
    4986                 :             :                                              decl,
    4987                 :             :                                              done,
    4988                 :             :                                              address_p,
    4989                 :             :                                              template_p,
    4990                 :             :                                              template_arg_p,
    4991                 :             :                                              tf_warning_or_error);
    4992                 :             :           else
    4993                 :    60286195 :             decl = convert_from_reference (decl);
    4994                 :             :         }
    4995                 :   536833767 :       else if (TREE_CODE (decl) == FIELD_DECL)
    4996                 :             :         {
    4997                 :             :           /* Since SCOPE is NULL here, this is an unqualified name.
    4998                 :             :              Access checking has been performed during name lookup
    4999                 :             :              already.  Turn off checking to avoid duplicate errors.  */
    5000                 :    57012986 :           push_deferring_access_checks (dk_no_check);
    5001                 :    57012986 :           decl = finish_non_static_data_member (decl, NULL_TREE,
    5002                 :             :                                                 /*qualifying_scope=*/NULL_TREE);
    5003                 :    57012986 :           pop_deferring_access_checks ();
    5004                 :             :         }
    5005                 :   479820781 :       else if (is_overloaded_fn (decl))
    5006                 :             :         {
    5007                 :             :           /* We only need to look at the first function,
    5008                 :             :              because all the fns share the attribute we're
    5009                 :             :              concerned with (all member fns or all non-members).  */
    5010                 :    55294513 :           tree first_fn = get_first_fn (decl);
    5011                 :    55294513 :           first_fn = STRIP_TEMPLATE (first_fn);
    5012                 :             : 
    5013                 :    55294513 :           if (!template_arg_p
    5014                 :    55294513 :               && (TREE_CODE (first_fn) == USING_DECL
    5015                 :    55292665 :                   || (TREE_CODE (first_fn) == FUNCTION_DECL
    5016                 :    55292665 :                       && DECL_FUNCTION_MEMBER_P (first_fn)
    5017                 :    32819417 :                       && !shared_member_p (decl))))
    5018                 :             :             {
    5019                 :             :               /* A set of member functions.  */
    5020                 :    26398941 :               decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
    5021                 :    26398941 :               return finish_class_member_access_expr (decl, id_expression,
    5022                 :             :                                                       /*template_p=*/false,
    5023                 :    26398941 :                                                       tf_warning_or_error);
    5024                 :             :             }
    5025                 :             : 
    5026                 :    28895572 :           decl = baselink_for_fns (decl);
    5027                 :             :         }
    5028                 :             :       else
    5029                 :             :         {
    5030                 :   418170754 :           if (DECL_P (decl) && DECL_NONLOCAL (decl)
    5031                 :   425897524 :               && DECL_CLASS_SCOPE_P (decl))
    5032                 :             :             {
    5033                 :     1371256 :               tree context = context_for_name_lookup (decl);
    5034                 :     1371256 :               if (context != current_class_type)
    5035                 :             :                 {
    5036                 :      800168 :                   tree path = currently_open_derived_class (context);
    5037                 :      800168 :                   if (!path)
    5038                 :             :                     /* PATH can be null for using an enum of an unrelated
    5039                 :             :                        class; we checked its access in lookup_using_decl.
    5040                 :             : 
    5041                 :             :                        ??? Should this case make a clone instead, like
    5042                 :             :                        handle_using_decl?  */
    5043                 :          10 :                     gcc_assert (TREE_CODE (decl) == CONST_DECL);
    5044                 :             :                   else
    5045                 :      800158 :                     perform_or_defer_access_check (TYPE_BINFO (path),
    5046                 :             :                                                    decl, decl,
    5047                 :             :                                                    tf_warning_or_error);
    5048                 :             :                 }
    5049                 :             :             }
    5050                 :             : 
    5051                 :   424526268 :           decl = convert_from_reference (decl);
    5052                 :             :         }
    5053                 :             :     }
    5054                 :             : 
    5055                 :   586865927 :   return cp_expr (decl, location);
    5056                 :             : }
    5057                 :             : 
    5058                 :             : /* As per finish_id_expression_1, but adding a wrapper node
    5059                 :             :    around the result if needed to express LOCATION.  */
    5060                 :             : 
    5061                 :             : cp_expr
    5062                 :   632110107 : finish_id_expression (tree id_expression,
    5063                 :             :                       tree decl,
    5064                 :             :                       tree scope,
    5065                 :             :                       cp_id_kind *idk,
    5066                 :             :                       bool integral_constant_expression_p,
    5067                 :             :                       bool allow_non_integral_constant_expression_p,
    5068                 :             :                       bool *non_integral_constant_expression_p,
    5069                 :             :                       bool template_p,
    5070                 :             :                       bool done,
    5071                 :             :                       bool address_p,
    5072                 :             :                       bool template_arg_p,
    5073                 :             :                       const char **error_msg,
    5074                 :             :                       location_t location)
    5075                 :             : {
    5076                 :   632110107 :   cp_expr result
    5077                 :   632110107 :     = finish_id_expression_1 (id_expression, decl, scope, idk,
    5078                 :             :                               integral_constant_expression_p,
    5079                 :             :                               allow_non_integral_constant_expression_p,
    5080                 :             :                               non_integral_constant_expression_p,
    5081                 :             :                               template_p, done, address_p, template_arg_p,
    5082                 :             :                               error_msg, location);
    5083                 :   632110104 :   return result.maybe_add_location_wrapper ();
    5084                 :             : }
    5085                 :             : 
    5086                 :             : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
    5087                 :             :    use as a type-specifier.  */
    5088                 :             : 
    5089                 :             : tree
    5090                 :    19732851 : finish_typeof (tree expr)
    5091                 :             : {
    5092                 :    19732851 :   tree type;
    5093                 :             : 
    5094                 :    19732851 :   if (type_dependent_expression_p (expr))
    5095                 :             :     {
    5096                 :    19640358 :       type = cxx_make_type (TYPEOF_TYPE);
    5097                 :    19640358 :       TYPEOF_TYPE_EXPR (type) = expr;
    5098                 :    19640358 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
    5099                 :             : 
    5100                 :    19640358 :       return type;
    5101                 :             :     }
    5102                 :             : 
    5103                 :       92493 :   expr = mark_type_use (expr);
    5104                 :             : 
    5105                 :       92493 :   type = unlowered_expr_type (expr);
    5106                 :             : 
    5107                 :       92493 :   if (!type || type == unknown_type_node)
    5108                 :             :     {
    5109                 :           3 :       error ("type of %qE is unknown", expr);
    5110                 :           3 :       return error_mark_node;
    5111                 :             :     }
    5112                 :             : 
    5113                 :             :   return type;
    5114                 :             : }
    5115                 :             : 
    5116                 :             : /* Implement the __underlying_type keyword: Return the underlying
    5117                 :             :    type of TYPE, suitable for use as a type-specifier.  */
    5118                 :             : 
    5119                 :             : tree
    5120                 :       43353 : finish_underlying_type (tree type)
    5121                 :             : {
    5122                 :       43353 :   if (!complete_type_or_else (type, NULL_TREE))
    5123                 :           3 :     return error_mark_node;
    5124                 :             : 
    5125                 :       43350 :   if (TREE_CODE (type) != ENUMERAL_TYPE)
    5126                 :             :     {
    5127                 :          24 :       error ("%qT is not an enumeration type", type);
    5128                 :          24 :       return error_mark_node;
    5129                 :             :     }
    5130                 :             : 
    5131                 :       43326 :   tree underlying_type = ENUM_UNDERLYING_TYPE (type);
    5132                 :             : 
    5133                 :             :   /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
    5134                 :             :      includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
    5135                 :             :      See finish_enum_value_list for details.  */
    5136                 :       43326 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
    5137                 :          52 :     underlying_type
    5138                 :          52 :       = c_common_type_for_mode (TYPE_MODE (underlying_type),
    5139                 :          52 :                                 TYPE_UNSIGNED (underlying_type));
    5140                 :             : 
    5141                 :             :   return underlying_type;
    5142                 :             : }
    5143                 :             : 
    5144                 :             : /* Implement the __type_pack_element keyword: Return the type
    5145                 :             :    at index IDX within TYPES.  */
    5146                 :             : 
    5147                 :             : static tree
    5148                 :       92541 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
    5149                 :             : {
    5150                 :       92541 :   idx = maybe_constant_value (idx, NULL_TREE, mce_true);
    5151                 :       92541 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
    5152                 :             :     {
    5153                 :           6 :       if (complain & tf_error)
    5154                 :           3 :         error ("pack index has non-integral type %qT", TREE_TYPE (idx));
    5155                 :           6 :       return error_mark_node;
    5156                 :             :     }
    5157                 :       92535 :   if (TREE_CODE (idx) != INTEGER_CST)
    5158                 :             :     {
    5159                 :           1 :       if (complain & tf_error)
    5160                 :             :         {
    5161                 :           1 :           error ("pack index is not an integral constant");
    5162                 :           1 :           cxx_constant_value (idx);
    5163                 :             :         }
    5164                 :           1 :       return error_mark_node;
    5165                 :             :     }
    5166                 :       92534 :   if (tree_int_cst_sgn (idx) < 0)
    5167                 :             :     {
    5168                 :           5 :       if (complain & tf_error)
    5169                 :           5 :         error ("pack index %qE is negative", idx);
    5170                 :           5 :       return error_mark_node;
    5171                 :             :     }
    5172                 :       92529 :   if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
    5173                 :             :     {
    5174                 :          25 :       if (complain & tf_error)
    5175                 :          19 :         error ("pack index %qE is out of range for pack of length %qd",
    5176                 :          19 :                idx, TREE_VEC_LENGTH (types));
    5177                 :          25 :       return error_mark_node;
    5178                 :             :     }
    5179                 :       92504 :   return TREE_VEC_ELT (types, tree_to_shwi (idx));
    5180                 :             : }
    5181                 :             : 
    5182                 :             : /* In a pack-index T...[N], return the element at index IDX within TYPES.
    5183                 :             :    PARENTHESIZED_P is true iff the pack index was wrapped in ().  */
    5184                 :             : 
    5185                 :             : tree
    5186                 :        1359 : pack_index_element (tree idx, tree types, bool parenthesized_p,
    5187                 :             :                     tsubst_flags_t complain)
    5188                 :             : {
    5189                 :        1359 :   tree r = finish_type_pack_element (idx, types, complain);
    5190                 :        1359 :   if (parenthesized_p)
    5191                 :             :     /* For the benefit of decltype(auto).  */
    5192                 :          22 :     r = force_paren_expr (r);
    5193                 :        1359 :   return r;
    5194                 :             : }
    5195                 :             : 
    5196                 :             : /* Implement the __direct_bases keyword: Return the direct base classes
    5197                 :             :    of type.  */
    5198                 :             : 
    5199                 :             : tree
    5200                 :          15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
    5201                 :             : {
    5202                 :          15 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5203                 :          15 :       || !NON_UNION_CLASS_TYPE_P (type))
    5204                 :           8 :     return make_tree_vec (0);
    5205                 :             : 
    5206                 :           7 :   releasing_vec vector;
    5207                 :           7 :   vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
    5208                 :           7 :   tree binfo;
    5209                 :           7 :   unsigned i;
    5210                 :             : 
    5211                 :             :   /* Virtual bases are initialized first */
    5212                 :          20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5213                 :          13 :     if (BINFO_VIRTUAL_P (binfo))
    5214                 :           2 :       vec_safe_push (vector, binfo);
    5215                 :             : 
    5216                 :             :   /* Now non-virtuals */
    5217                 :          20 :   for (i = 0; base_binfos->iterate (i, &binfo); i++)
    5218                 :          13 :     if (!BINFO_VIRTUAL_P (binfo))
    5219                 :          11 :       vec_safe_push (vector, binfo);
    5220                 :             : 
    5221                 :           7 :   tree bases_vec = make_tree_vec (vector->length ());
    5222                 :             : 
    5223                 :          27 :   for (i = 0; i < vector->length (); ++i)
    5224                 :          13 :     TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
    5225                 :             : 
    5226                 :           7 :   return bases_vec;
    5227                 :           7 : }
    5228                 :             : 
    5229                 :             : /* Implement the __bases keyword: Return the base classes
    5230                 :             :    of type */
    5231                 :             : 
    5232                 :             : /* Find morally non-virtual base classes by walking binfo hierarchy */
    5233                 :             : /* Virtual base classes are handled separately in finish_bases */
    5234                 :             : 
    5235                 :             : static tree
    5236                 :          73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
    5237                 :             : {
    5238                 :             :   /* Don't walk bases of virtual bases */
    5239                 :          73 :   return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
    5240                 :             : }
    5241                 :             : 
    5242                 :             : static tree
    5243                 :          73 : dfs_calculate_bases_post (tree binfo, void *data_)
    5244                 :             : {
    5245                 :          73 :   vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
    5246                 :          73 :   if (!BINFO_VIRTUAL_P (binfo))
    5247                 :          48 :     vec_safe_push (*data, BINFO_TYPE (binfo));
    5248                 :          73 :   return NULL_TREE;
    5249                 :             : }
    5250                 :             : 
    5251                 :             : /* Calculates the morally non-virtual base classes of a class */
    5252                 :             : static vec<tree, va_gc> *
    5253                 :          16 : calculate_bases_helper (tree type)
    5254                 :             : {
    5255                 :          16 :   vec<tree, va_gc> *vector = make_tree_vector ();
    5256                 :             : 
    5257                 :             :   /* Now add non-virtual base classes in order of construction */
    5258                 :          16 :   if (TYPE_BINFO (type))
    5259                 :          16 :     dfs_walk_all (TYPE_BINFO (type),
    5260                 :             :                   dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
    5261                 :          16 :   return vector;
    5262                 :             : }
    5263                 :             : 
    5264                 :             : tree
    5265                 :          12 : calculate_bases (tree type, tsubst_flags_t complain)
    5266                 :             : {
    5267                 :          12 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
    5268                 :          12 :       || !NON_UNION_CLASS_TYPE_P (type))
    5269                 :           5 :     return make_tree_vec (0);
    5270                 :             : 
    5271                 :           7 :   releasing_vec vector;
    5272                 :           7 :   tree bases_vec = NULL_TREE;
    5273                 :           7 :   unsigned i;
    5274                 :           7 :   vec<tree, va_gc> *vbases;
    5275                 :           7 :   tree binfo;
    5276                 :             : 
    5277                 :             :   /* First go through virtual base classes */
    5278                 :           7 :   for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
    5279                 :          16 :        vec_safe_iterate (vbases, i, &binfo); i++)
    5280                 :             :     {
    5281                 :           9 :       releasing_vec vbase_bases
    5282                 :           9 :         = calculate_bases_helper (BINFO_TYPE (binfo));
    5283                 :           9 :       vec_safe_splice (vector, vbase_bases);
    5284                 :           9 :     }
    5285                 :             : 
    5286                 :             :   /* Now for the non-virtual bases */
    5287                 :           7 :   releasing_vec nonvbases = calculate_bases_helper (type);
    5288                 :           7 :   vec_safe_splice (vector, nonvbases);
    5289                 :             : 
    5290                 :             :   /* Note that during error recovery vector->length can even be zero.  */
    5291                 :           7 :   if (vector->length () > 1)
    5292                 :             :     {
    5293                 :             :       /* Last element is entire class, so don't copy */
    5294                 :           6 :       bases_vec = make_tree_vec (vector->length () - 1);
    5295                 :             : 
    5296                 :          53 :       for (i = 0; i < vector->length () - 1; ++i)
    5297                 :          41 :         TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
    5298                 :             :     }
    5299                 :             :   else
    5300                 :           1 :     bases_vec = make_tree_vec (0);
    5301                 :             : 
    5302                 :           7 :   return bases_vec;
    5303                 :           7 : }
    5304                 :             : 
    5305                 :             : tree
    5306                 :          28 : finish_bases (tree type, bool direct)
    5307                 :             : {
    5308                 :          28 :   tree bases = NULL_TREE;
    5309                 :             : 
    5310                 :          28 :   if (!processing_template_decl)
    5311                 :             :     {
    5312                 :             :       /* Parameter packs can only be used in templates */
    5313                 :           0 :       error ("parameter pack %<__bases%> only valid in template declaration");
    5314                 :           0 :       return error_mark_node;
    5315                 :             :     }
    5316                 :             : 
    5317                 :          28 :   bases = cxx_make_type (BASES);
    5318                 :          28 :   BASES_TYPE (bases) = type;
    5319                 :          28 :   BASES_DIRECT (bases) = direct;
    5320                 :          28 :   SET_TYPE_STRUCTURAL_EQUALITY (bases);
    5321                 :             : 
    5322                 :          28 :   return bases;
    5323                 :             : }
    5324                 :             : 
    5325                 :             : /* Perform C++-specific checks for __builtin_offsetof before calling
    5326                 :             :    fold_offsetof.  */
    5327                 :             : 
    5328                 :             : tree
    5329                 :        2381 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
    5330                 :             : {
    5331                 :             :   /* If we're processing a template, we can't finish the semantics yet.
    5332                 :             :      Otherwise we can fold the entire expression now.  */
    5333                 :        2381 :   if (processing_template_decl)
    5334                 :             :     {
    5335                 :          60 :       expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
    5336                 :          60 :       SET_EXPR_LOCATION (expr, loc);
    5337                 :          60 :       return expr;
    5338                 :             :     }
    5339                 :             : 
    5340                 :        2321 :   if (expr == error_mark_node)
    5341                 :             :     return error_mark_node;
    5342                 :             : 
    5343                 :        2304 :   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
    5344                 :             :     {
    5345                 :           6 :       error ("cannot apply %<offsetof%> to destructor %<~%T%>",
    5346                 :           6 :               TREE_OPERAND (expr, 2));
    5347                 :           6 :       return error_mark_node;
    5348                 :             :     }
    5349                 :        4581 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
    5350                 :        4581 :       || TREE_TYPE (expr) == unknown_type_node)
    5351                 :             :     {
    5352                 :          30 :       while (TREE_CODE (expr) == COMPONENT_REF
    5353                 :          30 :              || TREE_CODE (expr) == COMPOUND_EXPR)
    5354                 :          12 :         expr = TREE_OPERAND (expr, 1);
    5355                 :             : 
    5356                 :          18 :       if (DECL_P (expr))
    5357                 :             :         {
    5358                 :           0 :           auto_diagnostic_group d;
    5359                 :           0 :           error ("cannot apply %<offsetof%> to member function %qD", expr);
    5360                 :           0 :           inform (DECL_SOURCE_LOCATION (expr), "declared here");
    5361                 :           0 :         }
    5362                 :             :       else
    5363                 :          18 :         error ("cannot apply %<offsetof%> to member function");
    5364                 :          18 :       return error_mark_node;
    5365                 :             :     }
    5366                 :        2280 :   if (TREE_CODE (expr) == CONST_DECL)
    5367                 :             :     {
    5368                 :           3 :       error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
    5369                 :           3 :       return error_mark_node;
    5370                 :             :     }
    5371                 :        2277 :   if (REFERENCE_REF_P (expr))
    5372                 :           9 :     expr = TREE_OPERAND (expr, 0);
    5373                 :        2277 :   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
    5374                 :           3 :     return error_mark_node;
    5375                 :        2274 :   if (warn_invalid_offsetof
    5376                 :        2274 :       && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
    5377                 :        2274 :       && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
    5378                 :        2319 :       && cp_unevaluated_operand == 0)
    5379                 :          45 :     warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
    5380                 :             :                 "non-standard-layout type %qT is conditionally-supported",
    5381                 :          45 :                 TREE_TYPE (TREE_TYPE (object_ptr)));
    5382                 :        2274 :   return fold_offsetof (expr);
    5383                 :             : }
    5384                 :             : 
    5385                 :             : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR.  This
    5386                 :             :    function is broken out from the above for the benefit of the tree-ssa
    5387                 :             :    project.  */
    5388                 :             : 
    5389                 :             : void
    5390                 :      380305 : simplify_aggr_init_expr (tree *tp)
    5391                 :             : {
    5392                 :      380305 :   tree aggr_init_expr = *tp;
    5393                 :             : 
    5394                 :             :   /* Form an appropriate CALL_EXPR.  */
    5395                 :      380305 :   tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
    5396                 :      380305 :   tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
    5397                 :      380305 :   tree type = TREE_TYPE (slot);
    5398                 :             : 
    5399                 :      380305 :   tree call_expr;
    5400                 :      380305 :   enum style_t { ctor, arg, pcc } style;
    5401                 :             : 
    5402                 :      380305 :   if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
    5403                 :             :     style = ctor;
    5404                 :             : #ifdef PCC_STATIC_STRUCT_RETURN
    5405                 :             :   else if (1)
    5406                 :             :     style = pcc;
    5407                 :             : #endif
    5408                 :             :   else
    5409                 :             :     {
    5410                 :       95836 :       gcc_assert (TREE_ADDRESSABLE (type));
    5411                 :             :       style = arg;
    5412                 :             :     }
    5413                 :             : 
    5414                 :      380305 :   call_expr = build_call_array_loc (input_location,
    5415                 :      380305 :                                     TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
    5416                 :             :                                     fn,
    5417                 :      380305 :                                     aggr_init_expr_nargs (aggr_init_expr),
    5418                 :      380305 :                                     AGGR_INIT_EXPR_ARGP (aggr_init_expr));
    5419                 :      380305 :   TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
    5420                 :      380305 :   CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
    5421                 :      380305 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr)
    5422                 :      380305 :     = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
    5423                 :      380305 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
    5424                 :      380305 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
    5425                 :      380305 :   CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
    5426                 :             : 
    5427                 :      380305 :   if (style == ctor)
    5428                 :             :     {
    5429                 :             :       /* Replace the first argument to the ctor with the address of the
    5430                 :             :          slot.  */
    5431                 :      284469 :       cxx_mark_addressable (slot);
    5432                 :      284469 :       CALL_EXPR_ARG (call_expr, 0) =
    5433                 :      284469 :         build1 (ADDR_EXPR, build_pointer_type (type), slot);
    5434                 :             :     }
    5435                 :       95836 :   else if (style == arg)
    5436                 :             :     {
    5437                 :             :       /* Just mark it addressable here, and leave the rest to
    5438                 :             :          expand_call{,_inline}.  */
    5439                 :       95836 :       cxx_mark_addressable (slot);
    5440                 :       95836 :       CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
    5441                 :       95836 :       call_expr = cp_build_init_expr (slot, call_expr);
    5442                 :             :     }
    5443                 :             :   else if (style == pcc)
    5444                 :             :     {
    5445                 :             :       /* If we're using the non-reentrant PCC calling convention, then we
    5446                 :             :          need to copy the returned value out of the static buffer into the
    5447                 :             :          SLOT.  */
    5448                 :             :       push_deferring_access_checks (dk_no_check);
    5449                 :             :       call_expr = build_aggr_init (slot, call_expr,
    5450                 :             :                                    DIRECT_BIND | LOOKUP_ONLYCONVERTING,
    5451                 :             :                                    tf_warning_or_error);
    5452                 :             :       pop_deferring_access_checks ();
    5453                 :             :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
    5454                 :             :     }
    5455                 :             : 
    5456                 :      380305 :   if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
    5457                 :             :     {
    5458                 :        3657 :       tree init = build_zero_init (type, NULL_TREE,
    5459                 :             :                                    /*static_storage_p=*/false);
    5460                 :        3657 :       init = cp_build_init_expr (slot, init);
    5461                 :        3657 :       call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
    5462                 :             :                           init, call_expr);
    5463                 :             :     }
    5464                 :             : 
    5465                 :      380305 :   *tp = call_expr;
    5466                 :      380305 : }
    5467                 :             : 
    5468                 :             : /* Emit all thunks to FN that should be emitted when FN is emitted.  */
    5469                 :             : 
    5470                 :             : void
    5471                 :    49827681 : emit_associated_thunks (tree fn)
    5472                 :             : {
    5473                 :             :   /* When we use vcall offsets, we emit thunks with the virtual
    5474                 :             :      functions to which they thunk. The whole point of vcall offsets
    5475                 :             :      is so that you can know statically the entire set of thunks that
    5476                 :             :      will ever be needed for a given virtual function, thereby
    5477                 :             :      enabling you to output all the thunks with the function itself.  */
    5478                 :    49827681 :   if (DECL_VIRTUAL_P (fn)
    5479                 :             :       /* Do not emit thunks for extern template instantiations.  */
    5480                 :     1028957 :       && ! DECL_REALLY_EXTERN (fn)
    5481                 :             :       /* Do not emit thunks for tentative decls, those will be processed
    5482                 :             :          again at_eof if really needed.  */
    5483                 :    50797096 :       && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
    5484                 :             :     {
    5485                 :      968552 :       tree thunk;
    5486                 :             : 
    5487                 :     1941357 :       for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
    5488                 :             :         {
    5489                 :        4253 :           if (!THUNK_ALIAS (thunk))
    5490                 :             :             {
    5491                 :        4253 :               use_thunk (thunk, /*emit_p=*/1);
    5492                 :        4253 :               if (DECL_RESULT_THUNK_P (thunk))
    5493                 :             :                 {
    5494                 :         178 :                   tree probe;
    5495                 :             : 
    5496                 :         178 :                   for (probe = DECL_THUNKS (thunk);
    5497                 :         327 :                        probe; probe = DECL_CHAIN (probe))
    5498                 :         149 :                     use_thunk (probe, /*emit_p=*/1);
    5499                 :             :                 }
    5500                 :             :             }
    5501                 :             :           else
    5502                 :           0 :             gcc_assert (!DECL_THUNKS (thunk));
    5503                 :             :         }
    5504                 :             :     }
    5505                 :    49827681 : }
    5506                 :             : 
    5507                 :             : /* Generate RTL for FN.  */
    5508                 :             : 
    5509                 :             : bool
    5510                 :   141840020 : expand_or_defer_fn_1 (tree fn)
    5511                 :             : {
    5512                 :             :   /* When the parser calls us after finishing the body of a template
    5513                 :             :      function, we don't really want to expand the body.  */
    5514                 :   141840020 :   if (processing_template_decl)
    5515                 :             :     {
    5516                 :             :       /* Normally, collection only occurs in rest_of_compilation.  So,
    5517                 :             :          if we don't collect here, we never collect junk generated
    5518                 :             :          during the processing of templates until we hit a
    5519                 :             :          non-template function.  It's not safe to do this inside a
    5520                 :             :          nested class, though, as the parser may have local state that
    5521                 :             :          is not a GC root.  */
    5522                 :    85171064 :       if (!function_depth)
    5523                 :    84789579 :         ggc_collect ();
    5524                 :    85171064 :       return false;
    5525                 :             :     }
    5526                 :             : 
    5527                 :    56668956 :   gcc_assert (DECL_SAVED_TREE (fn));
    5528                 :             : 
    5529                 :             :   /* We make a decision about linkage for these functions at the end
    5530                 :             :      of the compilation.  Until that point, we do not want the back
    5531                 :             :      end to output them -- but we do want it to see the bodies of
    5532                 :             :      these functions so that it can inline them as appropriate.  */
    5533                 :    56668956 :   if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
    5534                 :             :     {
    5535                 :    56415514 :       if (DECL_INTERFACE_KNOWN (fn))
    5536                 :             :         /* We've already made a decision as to how this function will
    5537                 :             :            be handled.  */;
    5538                 :    38947672 :       else if (!at_eof
    5539                 :    14909897 :                || DECL_IMMEDIATE_FUNCTION_P (fn)
    5540                 :    53554050 :                || DECL_OMP_DECLARE_REDUCTION_P (fn))
    5541                 :    24341294 :         tentative_decl_linkage (fn);
    5542                 :             :       else
    5543                 :    14606378 :         import_export_decl (fn);
    5544                 :             : 
    5545                 :             :       /* If the user wants us to keep all inline functions, then mark
    5546                 :             :          this function as needed so that finish_file will make sure to
    5547                 :             :          output it later.  Similarly, all dllexport'd functions must
    5548                 :             :          be emitted; there may be callers in other DLLs.  */
    5549                 :    56415514 :       if (DECL_DECLARED_INLINE_P (fn)
    5550                 :    54553497 :           && !DECL_REALLY_EXTERN (fn)
    5551                 :    51560441 :           && !DECL_IMMEDIATE_FUNCTION_P (fn)
    5552                 :    51050092 :           && !DECL_OMP_DECLARE_REDUCTION_P (fn)
    5553                 :   107465606 :           && (flag_keep_inline_functions
    5554                 :    51047745 :               || (flag_keep_inline_dllexport
    5555                 :    51047745 :                   && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
    5556                 :             :         {
    5557                 :        2347 :           mark_needed (fn);
    5558                 :        2347 :           DECL_EXTERNAL (fn) = 0;
    5559                 :             :         }
    5560                 :             :     }
    5561                 :             : 
    5562                 :             :   /* If this is a constructor or destructor body, we have to clone
    5563                 :             :      it.  */
    5564                 :    56668956 :   if (maybe_clone_body (fn))
    5565                 :             :     {
    5566                 :             :       /* We don't want to process FN again, so pretend we've written
    5567                 :             :          it out, even though we haven't.  */
    5568                 :     6814093 :       TREE_ASM_WRITTEN (fn) = 1;
    5569                 :             :       /* If this is a constexpr function we still need the body to be
    5570                 :             :          able to evaluate it.  Similarly, with modules we only stream
    5571                 :             :          the maybe-in-charge cdtor and regenerate the clones from it on
    5572                 :             :          demand, so we also need to keep the body.  Otherwise we don't
    5573                 :             :          need it anymore.  */
    5574                 :     6814093 :       if (!DECL_DECLARED_CONSTEXPR_P (fn)
    5575                 :     6814093 :           && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
    5576                 :     4494066 :         DECL_SAVED_TREE (fn) = void_node;
    5577                 :     6814093 :       return false;
    5578                 :             :     }
    5579                 :             : 
    5580                 :             :   /* There's no reason to do any of the work here if we're only doing
    5581                 :             :      semantic analysis; this code just generates RTL.  */
    5582                 :    49854863 :   if (flag_syntax_only)
    5583                 :             :     {
    5584                 :             :       /* Pretend that this function has been written out so that we don't try
    5585                 :             :          to expand it again.  */
    5586                 :       27166 :       TREE_ASM_WRITTEN (fn) = 1;
    5587                 :       27166 :       return false;
    5588                 :             :     }
    5589                 :             : 
    5590                 :    49827697 :   if (DECL_OMP_DECLARE_REDUCTION_P (fn))
    5591                 :             :     return false;
    5592                 :             : 
    5593                 :             :   return true;
    5594                 :             : }
    5595                 :             : 
    5596                 :             : void
    5597                 :   135045697 : expand_or_defer_fn (tree fn)
    5598                 :             : {
    5599                 :   135045697 :   if (expand_or_defer_fn_1 (fn))
    5600                 :             :     {
    5601                 :    43035694 :       function_depth++;
    5602                 :             : 
    5603                 :             :       /* Expand or defer, at the whim of the compilation unit manager.  */
    5604                 :    43035694 :       cgraph_node::finalize_function (fn, function_depth > 1);
    5605                 :    43035694 :       emit_associated_thunks (fn);
    5606                 :             : 
    5607                 :    43035694 :       function_depth--;
    5608                 :             : 
    5609                 :    86071388 :       if (DECL_IMMEDIATE_FUNCTION_P (fn))
    5610                 :             :         {
    5611                 :      493636 :           if (cgraph_node *node = cgraph_node::get (fn))
    5612                 :             :             {
    5613                 :      493636 :               node->body_removed = true;
    5614                 :      493636 :               node->analyzed = false;
    5615                 :      493636 :               node->definition = false;
    5616                 :      493636 :               node->force_output = false;
    5617                 :             :             }
    5618                 :             :         }
    5619                 :             :     }
    5620                 :   135045697 : }
    5621                 :             : 
    5622                 :      360266 : class nrv_data
    5623                 :             : {
    5624                 :             : public:
    5625                 :      180133 :   nrv_data () : visited (37) {}
    5626                 :             : 
    5627                 :             :   tree var;
    5628                 :             :   tree result;
    5629                 :             :   hash_set<tree> visited;
    5630                 :             :   bool simple;
    5631                 :             :   bool in_nrv_cleanup;
    5632                 :             : };
    5633                 :             : 
    5634                 :             : /* Helper function for walk_tree, used by finalize_nrv below.  */
    5635                 :             : 
    5636                 :             : static tree
    5637                 :    19505491 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
    5638                 :             : {
    5639                 :    19505491 :   class nrv_data *dp = (class nrv_data *)data;
    5640                 :             : 
    5641                 :             :   /* No need to walk into types.  There wouldn't be any need to walk into
    5642                 :             :      non-statements, except that we have to consider STMT_EXPRs.  */
    5643                 :    19505491 :   if (TYPE_P (*tp))
    5644                 :      170122 :     *walk_subtrees = 0;
    5645                 :             : 
    5646                 :             :   /* Replace all uses of the NRV with the RESULT_DECL.  */
    5647                 :    19335369 :   else if (*tp == dp->var)
    5648                 :      478616 :     *tp = dp->result;
    5649                 :             : 
    5650                 :             :   /* Avoid walking into the same tree more than once.  Unfortunately, we
    5651                 :             :      can't just use walk_tree_without duplicates because it would only call
    5652                 :             :      us for the first occurrence of dp->var in the function body.  */
    5653                 :    18856753 :   else if (dp->visited.add (*tp))
    5654                 :     4166598 :     *walk_subtrees = 0;
    5655                 :             : 
    5656                 :             :   /* If there's a label, we might need to destroy the NRV on goto (92407).  */
    5657                 :    14690155 :   else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
    5658                 :           3 :     dp->simple = false;
    5659                 :             :   /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
    5660                 :             :      but differs from using NULL_TREE in that it indicates that we care
    5661                 :             :      about the value of the RESULT_DECL.  But preserve anything appended
    5662                 :             :      by check_return_expr.  */
    5663                 :    14690152 :   else if (TREE_CODE (*tp) == RETURN_EXPR)
    5664                 :             :     {
    5665                 :      191700 :       tree *p = &TREE_OPERAND (*tp, 0);
    5666                 :      520895 :       while (TREE_CODE (*p) == COMPOUND_EXPR)
    5667                 :      137495 :         p = &TREE_OPERAND (*p, 0);
    5668                 :      191700 :       if (TREE_CODE (*p) == INIT_EXPR
    5669                 :      191700 :           && INIT_EXPR_NRV_P (*p))
    5670                 :      191351 :         *p = dp->result;
    5671                 :             :     }
    5672                 :             :   /* Change all cleanups for the NRV to only run when not returning.  */
    5673                 :    14498452 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5674                 :    14498452 :            && CLEANUP_DECL (*tp) == dp->var)
    5675                 :             :     {
    5676                 :      126804 :       dp->in_nrv_cleanup = true;
    5677                 :      126804 :       cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
    5678                 :      126804 :       dp->in_nrv_cleanup = false;
    5679                 :      126804 :       cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
    5680                 :      126804 :       *walk_subtrees = 0;
    5681                 :             : 
    5682                 :      126804 :       if (dp->simple)
    5683                 :             :         /* For a simple NRV, just run it on the EH path.  */
    5684                 :      126322 :         CLEANUP_EH_ONLY (*tp) = true;
    5685                 :             :       else
    5686                 :             :         {
    5687                 :             :           /* Not simple, we need to check current_retval_sentinel to decide
    5688                 :             :              whether to run it.  If it's set, we're returning normally and
    5689                 :             :              don't want to destroy the NRV.  If the sentinel is not set, we're
    5690                 :             :              leaving scope some other way, either by flowing off the end of its
    5691                 :             :              scope or throwing an exception.  */
    5692                 :        1446 :           tree cond = build3 (COND_EXPR, void_type_node,
    5693                 :         482 :                               current_retval_sentinel,
    5694                 :         482 :                               void_node, CLEANUP_EXPR (*tp));
    5695                 :         482 :           CLEANUP_EXPR (*tp) = cond;
    5696                 :             :         }
    5697                 :             : 
    5698                 :             :       /* If a cleanup might throw, we need to clear current_retval_sentinel on
    5699                 :             :          the exception path, both so the check above succeeds and so an outer
    5700                 :             :          cleanup added by maybe_splice_retval_cleanup doesn't run.  */
    5701                 :      126804 :       if (cp_function_chain->throwing_cleanup)
    5702                 :             :         {
    5703                 :         154 :           tree clear = build2 (MODIFY_EXPR, boolean_type_node,
    5704                 :             :                                current_retval_sentinel,
    5705                 :             :                                boolean_false_node);
    5706                 :         154 :           if (dp->simple)
    5707                 :             :             {
    5708                 :             :               /* We're already only on the EH path, just prepend it.  */
    5709                 :         144 :               tree &exp = CLEANUP_EXPR (*tp);
    5710                 :         144 :               exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
    5711                 :             :             }
    5712                 :             :           else
    5713                 :             :             {
    5714                 :             :               /* The cleanup runs on both normal and EH paths, we need another
    5715                 :             :                  CLEANUP_STMT to clear the flag only on the EH path.  */
    5716                 :          10 :               tree &bod = CLEANUP_BODY (*tp);
    5717                 :          10 :               bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
    5718                 :          10 :                                 bod, clear, current_retval_sentinel);
    5719                 :          10 :               CLEANUP_EH_ONLY (bod) = true;
    5720                 :             :             }
    5721                 :             :         }
    5722                 :             :     }
    5723                 :             :   /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
    5724                 :             :      want to destroy the retval before the variable goes out of scope.  */
    5725                 :    14371648 :   else if (TREE_CODE (*tp) == CLEANUP_STMT
    5726                 :        7531 :            && dp->in_nrv_cleanup
    5727                 :    14378100 :            && CLEANUP_DECL (*tp) == dp->result)
    5728                 :           6 :     CLEANUP_EXPR (*tp) = void_node;
    5729                 :             :   /* Replace the DECL_EXPR for the NRV with an initialization of the
    5730                 :             :      RESULT_DECL, if needed.  */
    5731                 :    14371642 :   else if (TREE_CODE (*tp) == DECL_EXPR
    5732                 :    14371642 :            && DECL_EXPR_DECL (*tp) == dp->var)
    5733                 :             :     {
    5734                 :      180135 :       tree init;
    5735                 :      180135 :       if (DECL_INITIAL (dp->var)
    5736                 :      180135 :           && DECL_INITIAL (dp->var) != error_mark_node)
    5737                 :       41976 :         init = cp_build_init_expr (dp->result,
    5738                 :       41976 :                        DECL_INITIAL (dp->var));
    5739                 :             :       else
    5740                 :      138159 :         init = build_empty_stmt (EXPR_LOCATION (*tp));
    5741                 :      180135 :       DECL_INITIAL (dp->var) = NULL_TREE;
    5742                 :      180135 :       SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
    5743                 :      180135 :       *tp = init;
    5744                 :             :     }
    5745                 :             : 
    5746                 :             :   /* Keep iterating.  */
    5747                 :    19505491 :   return NULL_TREE;
    5748                 :             : }
    5749                 :             : 
    5750                 :             : /* Called from finish_function to implement the named return value
    5751                 :             :    optimization by overriding all the RETURN_EXPRs and pertinent
    5752                 :             :    CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
    5753                 :             :    RESULT_DECL for the function.  */
    5754                 :             : 
    5755                 :             : void
    5756                 :      180133 : finalize_nrv (tree fndecl, tree var)
    5757                 :             : {
    5758                 :      180133 :   class nrv_data data;
    5759                 :      180133 :   tree result = DECL_RESULT (fndecl);
    5760                 :             : 
    5761                 :             :   /* Copy name from VAR to RESULT.  */
    5762                 :      180133 :   DECL_NAME (result) = DECL_NAME (var);
    5763                 :             :   /* Don't forget that we take its address.  */
    5764                 :      180133 :   TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
    5765                 :             :   /* Finally set DECL_VALUE_EXPR to avoid assigning
    5766                 :             :      a stack slot at -O0 for the original var and debug info
    5767                 :             :      uses RESULT location for VAR.  */
    5768                 :      180133 :   SET_DECL_VALUE_EXPR (var, result);
    5769                 :      180133 :   DECL_HAS_VALUE_EXPR_P (var) = 1;
    5770                 :             : 
    5771                 :      180133 :   data.var = var;
    5772                 :      180133 :   data.result = result;
    5773                 :      180133 :   data.in_nrv_cleanup = false;
    5774                 :             : 
    5775                 :             :   /* This is simpler for variables declared in the outer scope of
    5776                 :             :      the function so we know that their lifetime always ends with a
    5777                 :             :      return; see g++.dg/opt/nrv6.C.  */
    5778                 :      180133 :   tree outer = outer_curly_brace_block (fndecl);
    5779                 :      180133 :   data.simple = chain_member (var, BLOCK_VARS (outer));
    5780                 :             : 
    5781                 :      180133 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
    5782                 :      180133 : }
    5783                 :             : 
    5784                 :             : /* Create CP_OMP_CLAUSE_INFO for clause C.  Returns true if it is invalid.  */
    5785                 :             : 
    5786                 :             : bool
    5787                 :        2236 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
    5788                 :             :                             bool need_copy_ctor, bool need_copy_assignment,
    5789                 :             :                             bool need_dtor)
    5790                 :             : {
    5791                 :        2236 :   int save_errorcount = errorcount;
    5792                 :        2236 :   tree info, t;
    5793                 :             : 
    5794                 :             :   /* Always allocate 3 elements for simplicity.  These are the
    5795                 :             :      function decls for the ctor, dtor, and assignment op.
    5796                 :             :      This layout is known to the three lang hooks,
    5797                 :             :      cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
    5798                 :             :      and cxx_omp_clause_assign_op.  */
    5799                 :        2236 :   info = make_tree_vec (3);
    5800                 :        2236 :   CP_OMP_CLAUSE_INFO (c) = info;
    5801                 :             : 
    5802                 :        2236 :   if (need_default_ctor || need_copy_ctor)
    5803                 :             :     {
    5804                 :        1655 :       if (need_default_ctor)
    5805                 :        1254 :         t = get_default_ctor (type);
    5806                 :             :       else
    5807                 :         401 :         t = get_copy_ctor (type, tf_warning_or_error);
    5808                 :             : 
    5809                 :        1655 :       if (t && !trivial_fn_p (t))
    5810                 :        1400 :         TREE_VEC_ELT (info, 0) = t;
    5811                 :             :     }
    5812                 :             : 
    5813                 :        2236 :   if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5814                 :        1635 :     TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
    5815                 :             : 
    5816                 :        2236 :   if (need_copy_assignment)
    5817                 :             :     {
    5818                 :         397 :       t = get_copy_assign (type);
    5819                 :             : 
    5820                 :         397 :       if (t && !trivial_fn_p (t))
    5821                 :         344 :         TREE_VEC_ELT (info, 2) = t;
    5822                 :             :     }
    5823                 :             : 
    5824                 :        2236 :   return errorcount != save_errorcount;
    5825                 :             : }
    5826                 :             : 
    5827                 :             : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
    5828                 :             :    FIELD_DECL, otherwise return DECL itself.  */
    5829                 :             : 
    5830                 :             : static tree
    5831                 :       26437 : omp_clause_decl_field (tree decl)
    5832                 :             : {
    5833                 :       26437 :   if (VAR_P (decl)
    5834                 :       18404 :       && DECL_HAS_VALUE_EXPR_P (decl)
    5835                 :         359 :       && DECL_ARTIFICIAL (decl)
    5836                 :         359 :       && DECL_LANG_SPECIFIC (decl)
    5837                 :       26772 :       && DECL_OMP_PRIVATIZED_MEMBER (decl))
    5838                 :             :     {
    5839                 :         328 :       tree f = DECL_VALUE_EXPR (decl);
    5840                 :         328 :       if (INDIRECT_REF_P (f))
    5841                 :           0 :         f = TREE_OPERAND (f, 0);
    5842                 :         328 :       if (TREE_CODE (f) == COMPONENT_REF)
    5843                 :             :         {
    5844                 :         328 :           f = TREE_OPERAND (f, 1);
    5845                 :         328 :           gcc_assert (TREE_CODE (f) == FIELD_DECL);
    5846                 :             :           return f;
    5847                 :             :         }
    5848                 :             :     }
    5849                 :             :   return NULL_TREE;
    5850                 :             : }
    5851                 :             : 
    5852                 :             : /* Adjust DECL if needed for printing using %qE.  */
    5853                 :             : 
    5854                 :             : static tree
    5855                 :         187 : omp_clause_printable_decl (tree decl)
    5856                 :             : {
    5857                 :           0 :   tree t = omp_clause_decl_field (decl);
    5858                 :         187 :   if (t)
    5859                 :          45 :     return t;
    5860                 :             :   return decl;
    5861                 :             : }
    5862                 :             : 
    5863                 :             : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
    5864                 :             :    VAR_DECL T that doesn't need a DECL_EXPR added, record it for
    5865                 :             :    privatization.  */
    5866                 :             : 
    5867                 :             : static void
    5868                 :         219 : omp_note_field_privatization (tree f, tree t)
    5869                 :             : {
    5870                 :         219 :   if (!omp_private_member_map)
    5871                 :          71 :     omp_private_member_map = new hash_map<tree, tree>;
    5872                 :         219 :   tree &v = omp_private_member_map->get_or_insert (f);
    5873                 :         219 :   if (v == NULL_TREE)
    5874                 :             :     {
    5875                 :         146 :       v = t;
    5876                 :         146 :       omp_private_member_vec.safe_push (f);
    5877                 :             :       /* Signal that we don't want to create DECL_EXPR for this dummy var.  */
    5878                 :         146 :       omp_private_member_vec.safe_push (integer_zero_node);
    5879                 :             :     }
    5880                 :         219 : }
    5881                 :             : 
    5882                 :             : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
    5883                 :             :    dummy VAR_DECL.  */
    5884                 :             : 
    5885                 :             : tree
    5886                 :         861 : omp_privatize_field (tree t, bool shared)
    5887                 :             : {
    5888                 :         861 :   tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    5889                 :         861 :   if (m == error_mark_node)
    5890                 :             :     return error_mark_node;
    5891                 :         861 :   if (!omp_private_member_map && !shared)
    5892                 :         365 :     omp_private_member_map = new hash_map<tree, tree>;
    5893                 :         861 :   if (TYPE_REF_P (TREE_TYPE (t)))
    5894                 :             :     {
    5895                 :         123 :       gcc_assert (INDIRECT_REF_P (m));
    5896                 :         123 :       m = TREE_OPERAND (m, 0);
    5897                 :             :     }
    5898                 :         861 :   tree vb = NULL_TREE;
    5899                 :         861 :   tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
    5900                 :         861 :   if (v == NULL_TREE)
    5901                 :             :     {
    5902                 :         770 :       v = create_temporary_var (TREE_TYPE (m));
    5903                 :         770 :       retrofit_lang_decl (v);
    5904                 :         770 :       DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
    5905                 :         770 :       SET_DECL_VALUE_EXPR (v, m);
    5906                 :         770 :       DECL_HAS_VALUE_EXPR_P (v) = 1;
    5907                 :         770 :       if (!shared)
    5908                 :         690 :         omp_private_member_vec.safe_push (t);
    5909                 :             :     }
    5910                 :         861 :   return v;
    5911                 :             : }
    5912                 :             : 
    5913                 :             : /* C++ specialisation of the c_omp_address_inspector class.  */
    5914                 :             : 
    5915                 :             : class cp_omp_address_inspector : public c_omp_address_inspector
    5916                 :             : {
    5917                 :             : public:
    5918                 :       30808 :   cp_omp_address_inspector (location_t loc, tree t)
    5919                 :       30808 :     : c_omp_address_inspector (loc, t)
    5920                 :             :     {
    5921                 :             :     }
    5922                 :             : 
    5923                 :       30808 :   ~cp_omp_address_inspector ()
    5924                 :             :     {
    5925                 :       22514 :     }
    5926                 :             : 
    5927                 :      131512 :   bool processing_template_decl_p ()
    5928                 :             :     {
    5929                 :      131512 :       return processing_template_decl;
    5930                 :             :     }
    5931                 :             : 
    5932                 :           0 :   void emit_unmappable_type_notes (tree t)
    5933                 :             :     {
    5934                 :           0 :       if (TREE_TYPE (t) != error_mark_node
    5935                 :           0 :           && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    5936                 :           0 :         cxx_incomplete_type_inform (TREE_TYPE (t));
    5937                 :           0 :     }
    5938                 :             : 
    5939                 :        1058 :   tree convert_from_reference (tree x)
    5940                 :             :     {
    5941                 :        1058 :       return ::convert_from_reference (x);
    5942                 :             :     }
    5943                 :             : 
    5944                 :         143 :   tree build_array_ref (location_t loc, tree arr, tree idx)
    5945                 :             :     {
    5946                 :         143 :       return ::build_array_ref (loc, arr, idx);
    5947                 :             :     }
    5948                 :             : 
    5949                 :       22456 :   bool check_clause (tree clause)
    5950                 :             :     {
    5951                 :       22456 :       if (TREE_CODE (orig) == COMPONENT_REF
    5952                 :       22456 :           && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
    5953                 :             :                                         tf_warning_or_error))
    5954                 :             :         return false;
    5955                 :       22453 :       if (!c_omp_address_inspector::check_clause (clause))
    5956                 :             :         return false;
    5957                 :             :       return true;
    5958                 :             :     }
    5959                 :             : };
    5960                 :             : 
    5961                 :             : /* Helper function for handle_omp_array_sections.  Called recursively
    5962                 :             :    to handle multiple array-section-subscripts.  C is the clause,
    5963                 :             :    T current expression (initially OMP_CLAUSE_DECL), which is either
    5964                 :             :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
    5965                 :             :    expression if specified, TREE_VALUE length expression if specified,
    5966                 :             :    TREE_CHAIN is what it has been specified after, or some decl.
    5967                 :             :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
    5968                 :             :    set to true if any of the array-section-subscript could have length
    5969                 :             :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
    5970                 :             :    first array-section-subscript which is known not to have length
    5971                 :             :    of one.  Given say:
    5972                 :             :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
    5973                 :             :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
    5974                 :             :    all are or may have length of 1, array-section-subscript [:2] is the
    5975                 :             :    first one known not to have length 1.  For array-section-subscript
    5976                 :             :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
    5977                 :             :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
    5978                 :             :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
    5979                 :             :    case though, as some lengths could be zero.  */
    5980                 :             : 
    5981                 :             : static tree
    5982                 :       21205 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
    5983                 :             :                              bool &maybe_zero_len, unsigned int &first_non_one,
    5984                 :             :                              enum c_omp_region_type ort)
    5985                 :             : {
    5986                 :       21205 :   tree ret, low_bound, length, type;
    5987                 :       21205 :   bool openacc = (ort & C_ORT_ACC) != 0;
    5988                 :       21205 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
    5989                 :             :     {
    5990                 :        9568 :       if (error_operand_p (t))
    5991                 :           6 :         return error_mark_node;
    5992                 :             : 
    5993                 :        9562 :       cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    5994                 :        9562 :       tree t_refto = ai.maybe_unconvert_ref (t);
    5995                 :             : 
    5996                 :        9562 :       if (!ai.check_clause (c))
    5997                 :           0 :         return error_mark_node;
    5998                 :        9562 :       else if (ai.component_access_p ()
    5999                 :       10950 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6000                 :          64 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
    6001                 :          40 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
    6002                 :        1388 :         t = ai.get_root_term (true);
    6003                 :             :       else
    6004                 :        8174 :         t = ai.unconverted_ref_origin ();
    6005                 :        9562 :       if (t == error_mark_node)
    6006                 :             :         return error_mark_node;
    6007                 :        9562 :       ret = t_refto;
    6008                 :        9562 :       if (TREE_CODE (t) == FIELD_DECL)
    6009                 :          33 :         ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6010                 :        9529 :       else if (!VAR_P (t)
    6011                 :        2853 :                && (openacc || !EXPR_P (t))
    6012                 :        2658 :                && TREE_CODE (t) != PARM_DECL)
    6013                 :             :         {
    6014                 :          51 :           if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    6015                 :             :             return NULL_TREE;
    6016                 :          33 :           if (DECL_P (t))
    6017                 :          33 :             error_at (OMP_CLAUSE_LOCATION (c),
    6018                 :             :                       "%qD is not a variable in %qs clause", t,
    6019                 :          33 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6020                 :             :           else
    6021                 :           0 :             error_at (OMP_CLAUSE_LOCATION (c),
    6022                 :             :                       "%qE is not a variable in %qs clause", t,
    6023                 :           0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6024                 :          33 :           return error_mark_node;
    6025                 :             :         }
    6026                 :        9478 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6027                 :        9148 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6028                 :       17699 :                && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    6029                 :             :         {
    6030                 :          18 :           error_at (OMP_CLAUSE_LOCATION (c),
    6031                 :             :                     "%qD is threadprivate variable in %qs clause", t,
    6032                 :          18 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6033                 :          18 :           return error_mark_node;
    6034                 :             :         }
    6035                 :        9493 :       if (type_dependent_expression_p (ret))
    6036                 :             :         return NULL_TREE;
    6037                 :        8782 :       ret = convert_from_reference (ret);
    6038                 :        8782 :       return ret;
    6039                 :        9562 :     }
    6040                 :             : 
    6041                 :       11637 :   if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
    6042                 :        7716 :       && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6043                 :        6414 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6044                 :        5130 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6045                 :       14351 :       && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
    6046                 :          43 :     TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
    6047                 :       11637 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
    6048                 :             :                                      maybe_zero_len, first_non_one, ort);
    6049                 :       11637 :   if (ret == error_mark_node || ret == NULL_TREE)
    6050                 :             :     return ret;
    6051                 :             : 
    6052                 :       10576 :   type = TREE_TYPE (ret);
    6053                 :       10576 :   low_bound = TREE_OPERAND (t, 1);
    6054                 :       10576 :   length = TREE_OPERAND (t, 2);
    6055                 :        8506 :   if ((low_bound && type_dependent_expression_p (low_bound))
    6056                 :       18999 :       || (length && type_dependent_expression_p (length)))
    6057                 :          88 :     return NULL_TREE;
    6058                 :             : 
    6059                 :       10488 :   if (low_bound == error_mark_node || length == error_mark_node)
    6060                 :             :     return error_mark_node;
    6061                 :             : 
    6062                 :       10488 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
    6063                 :             :     {
    6064                 :          75 :       error_at (OMP_CLAUSE_LOCATION (c),
    6065                 :             :                 "low bound %qE of array section does not have integral type",
    6066                 :             :                 low_bound);
    6067                 :          75 :       return error_mark_node;
    6068                 :             :     }
    6069                 :       10413 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
    6070                 :             :     {
    6071                 :          69 :       error_at (OMP_CLAUSE_LOCATION (c),
    6072                 :             :                 "length %qE of array section does not have integral type",
    6073                 :             :                 length);
    6074                 :          69 :       return error_mark_node;
    6075                 :             :     }
    6076                 :       10344 :   if (low_bound)
    6077                 :        8334 :     low_bound = mark_rvalue_use (low_bound);
    6078                 :       10344 :   if (length)
    6079                 :        9327 :     length = mark_rvalue_use (length);
    6080                 :             :   /* We need to reduce to real constant-values for checks below.  */
    6081                 :        9327 :   if (length)
    6082                 :        9327 :     length = fold_simple (length);
    6083                 :       10344 :   if (low_bound)
    6084                 :        8334 :     low_bound = fold_simple (low_bound);
    6085                 :        8334 :   if (low_bound
    6086                 :        8334 :       && TREE_CODE (low_bound) == INTEGER_CST
    6087                 :       15737 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
    6088                 :        7403 :          > TYPE_PRECISION (sizetype))
    6089                 :           0 :     low_bound = fold_convert (sizetype, low_bound);
    6090                 :       10344 :   if (length
    6091                 :        9327 :       && TREE_CODE (length) == INTEGER_CST
    6092                 :       17652 :       && TYPE_PRECISION (TREE_TYPE (length))
    6093                 :        7308 :          > TYPE_PRECISION (sizetype))
    6094                 :           0 :     length = fold_convert (sizetype, length);
    6095                 :       10344 :   if (low_bound == NULL_TREE)
    6096                 :        2010 :     low_bound = integer_zero_node;
    6097                 :             : 
    6098                 :       10344 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    6099                 :       10344 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    6100                 :        5096 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
    6101                 :             :     {
    6102                 :          60 :       if (length != integer_one_node)
    6103                 :             :         {
    6104                 :          36 :           error_at (OMP_CLAUSE_LOCATION (c),
    6105                 :             :                     "expected single pointer in %qs clause",
    6106                 :             :                     user_omp_clause_code_name (c, openacc));
    6107                 :          36 :           return error_mark_node;
    6108                 :             :         }
    6109                 :             :     }
    6110                 :       10308 :   if (length != NULL_TREE)
    6111                 :             :     {
    6112                 :        9315 :       if (!integer_nonzerop (length))
    6113                 :             :         {
    6114                 :        2071 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6115                 :             :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6116                 :             :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6117                 :             :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6118                 :             :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6119                 :             :             {
    6120                 :         475 :               if (integer_zerop (length))
    6121                 :             :                 {
    6122                 :          36 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6123                 :             :                             "zero length array section in %qs clause",
    6124                 :          36 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6125                 :          36 :                   return error_mark_node;
    6126                 :             :                 }
    6127                 :             :             }
    6128                 :             :           else
    6129                 :        1596 :             maybe_zero_len = true;
    6130                 :             :         }
    6131                 :        9279 :       if (first_non_one == types.length ()
    6132                 :        9279 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
    6133                 :        3964 :         first_non_one++;
    6134                 :             :     }
    6135                 :       10272 :   if (TREE_CODE (type) == ARRAY_TYPE)
    6136                 :             :     {
    6137                 :        5692 :       if (length == NULL_TREE
    6138                 :        5692 :           && (TYPE_DOMAIN (type) == NULL_TREE
    6139                 :         915 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
    6140                 :             :         {
    6141                 :          33 :           error_at (OMP_CLAUSE_LOCATION (c),
    6142                 :             :                     "for unknown bound array type length expression must "
    6143                 :             :                     "be specified");
    6144                 :          33 :           return error_mark_node;
    6145                 :             :         }
    6146                 :        5659 :       if (TREE_CODE (low_bound) == INTEGER_CST
    6147                 :        5659 :           && tree_int_cst_sgn (low_bound) == -1)
    6148                 :             :         {
    6149                 :         174 :           error_at (OMP_CLAUSE_LOCATION (c),
    6150                 :             :                     "negative low bound in array section in %qs clause",
    6151                 :         174 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6152                 :         174 :           return error_mark_node;
    6153                 :             :         }
    6154                 :        5485 :       if (length != NULL_TREE
    6155                 :        4624 :           && TREE_CODE (length) == INTEGER_CST
    6156                 :        9187 :           && tree_int_cst_sgn (length) == -1)
    6157                 :             :         {
    6158                 :         174 :           error_at (OMP_CLAUSE_LOCATION (c),
    6159                 :             :                     "negative length in array section in %qs clause",
    6160                 :         174 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6161                 :         174 :           return error_mark_node;
    6162                 :             :         }
    6163                 :        5311 :       if (TYPE_DOMAIN (type)
    6164                 :        5212 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    6165                 :       10523 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
    6166                 :             :                         == INTEGER_CST)
    6167                 :             :         {
    6168                 :        4816 :           tree size
    6169                 :        4816 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
    6170                 :        4816 :           size = size_binop (PLUS_EXPR, size, size_one_node);
    6171                 :        4816 :           if (TREE_CODE (low_bound) == INTEGER_CST)
    6172                 :             :             {
    6173                 :        4045 :               if (tree_int_cst_lt (size, low_bound))
    6174                 :             :                 {
    6175                 :          60 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6176                 :             :                             "low bound %qE above array section size "
    6177                 :             :                             "in %qs clause", low_bound,
    6178                 :          60 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6179                 :          60 :                   return error_mark_node;
    6180                 :             :                 }
    6181                 :        3985 :               if (tree_int_cst_equal (size, low_bound))
    6182                 :             :                 {
    6183                 :          21 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
    6184                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6185                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6186                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6187                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6188                 :             :                     {
    6189                 :          21 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6190                 :             :                                 "zero length array section in %qs clause",
    6191                 :          21 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6192                 :          21 :                       return error_mark_node;
    6193                 :             :                     }
    6194                 :           0 :                   maybe_zero_len = true;
    6195                 :             :                 }
    6196                 :        3964 :               else if (length == NULL_TREE
    6197                 :        1514 :                        && first_non_one == types.length ()
    6198                 :        4285 :                        && tree_int_cst_equal
    6199                 :         321 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
    6200                 :             :                              low_bound))
    6201                 :         207 :                 first_non_one++;
    6202                 :             :             }
    6203                 :         771 :           else if (length == NULL_TREE)
    6204                 :             :             {
    6205                 :          22 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6206                 :             :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6207                 :             :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6208                 :             :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6209                 :             :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6210                 :          13 :                 maybe_zero_len = true;
    6211                 :          44 :               if (first_non_one == types.length ())
    6212                 :          19 :                 first_non_one++;
    6213                 :             :             }
    6214                 :        4735 :           if (length && TREE_CODE (length) == INTEGER_CST)
    6215                 :             :             {
    6216                 :        3408 :               if (tree_int_cst_lt (size, length))
    6217                 :             :                 {
    6218                 :          63 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6219                 :             :                             "length %qE above array section size "
    6220                 :             :                             "in %qs clause", length,
    6221                 :          63 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6222                 :          63 :                   return error_mark_node;
    6223                 :             :                 }
    6224                 :        3345 :               if (TREE_CODE (low_bound) == INTEGER_CST)
    6225                 :             :                 {
    6226                 :        3011 :                   tree lbpluslen
    6227                 :        3011 :                     = size_binop (PLUS_EXPR,
    6228                 :             :                                   fold_convert (sizetype, low_bound),
    6229                 :             :                                   fold_convert (sizetype, length));
    6230                 :        3011 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
    6231                 :        3011 :                       && tree_int_cst_lt (size, lbpluslen))
    6232                 :             :                     {
    6233                 :          60 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6234                 :             :                                 "high bound %qE above array section size "
    6235                 :             :                                 "in %qs clause", lbpluslen,
    6236                 :          60 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6237                 :          60 :                       return error_mark_node;
    6238                 :             :                     }
    6239                 :             :                 }
    6240                 :             :             }
    6241                 :             :         }
    6242                 :         495 :       else if (length == NULL_TREE)
    6243                 :             :         {
    6244                 :           1 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6245                 :             :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6246                 :             :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
    6247                 :             :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
    6248                 :             :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
    6249                 :           0 :             maybe_zero_len = true;
    6250                 :           2 :           if (first_non_one == types.length ())
    6251                 :           1 :             first_non_one++;
    6252                 :             :         }
    6253                 :             : 
    6254                 :             :       /* For [lb:] we will need to evaluate lb more than once.  */
    6255                 :        4066 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6256                 :             :         {
    6257                 :         699 :           tree lb = cp_save_expr (low_bound);
    6258                 :         699 :           if (lb != low_bound)
    6259                 :             :             {
    6260                 :          11 :               TREE_OPERAND (t, 1) = lb;
    6261                 :          11 :               low_bound = lb;
    6262                 :             :             }
    6263                 :             :         }
    6264                 :             :     }
    6265                 :        4580 :   else if (TYPE_PTR_P (type))
    6266                 :             :     {
    6267                 :        4520 :       if (length == NULL_TREE)
    6268                 :             :         {
    6269                 :          45 :           if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
    6270                 :          39 :             error_at (OMP_CLAUSE_LOCATION (c),
    6271                 :             :                       "for array function parameter length expression "
    6272                 :             :                       "must be specified");
    6273                 :             :           else
    6274                 :           6 :             error_at (OMP_CLAUSE_LOCATION (c),
    6275                 :             :                       "for pointer type length expression must be specified");
    6276                 :          45 :           return error_mark_node;
    6277                 :             :         }
    6278                 :        4475 :       if (length != NULL_TREE
    6279                 :        4475 :           && TREE_CODE (length) == INTEGER_CST
    6280                 :        3378 :           && tree_int_cst_sgn (length) == -1)
    6281                 :             :         {
    6282                 :          96 :           error_at (OMP_CLAUSE_LOCATION (c),
    6283                 :             :                     "negative length in array section in %qs clause",
    6284                 :          96 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6285                 :          96 :           return error_mark_node;
    6286                 :             :         }
    6287                 :             :       /* If there is a pointer type anywhere but in the very first
    6288                 :             :          array-section-subscript, the array section could be non-contiguous.  */
    6289                 :        4379 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
    6290                 :        4277 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
    6291                 :        8173 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
    6292                 :             :         {
    6293                 :             :           /* If any prior dimension has a non-one length, then deem this
    6294                 :             :              array section as non-contiguous.  */
    6295                 :         159 :           for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
    6296                 :          69 :                d = TREE_OPERAND (d, 0))
    6297                 :             :             {
    6298                 :          90 :               tree d_length = TREE_OPERAND (d, 2);
    6299                 :          90 :               if (d_length == NULL_TREE || !integer_onep (d_length))
    6300                 :             :                 {
    6301                 :          21 :                   error_at (OMP_CLAUSE_LOCATION (c),
    6302                 :             :                             "array section is not contiguous in %qs clause",
    6303                 :          21 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6304                 :          21 :                   return error_mark_node;
    6305                 :             :                 }
    6306                 :             :             }
    6307                 :             :         }
    6308                 :             :     }
    6309                 :             :   else
    6310                 :             :     {
    6311                 :          60 :       error_at (OMP_CLAUSE_LOCATION (c),
    6312                 :             :                 "%qE does not have pointer or array type", ret);
    6313                 :          60 :       return error_mark_node;
    6314                 :             :     }
    6315                 :        9465 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
    6316                 :        8562 :     types.safe_push (TREE_TYPE (ret));
    6317                 :             :   /* We will need to evaluate lb more than once.  */
    6318                 :        9465 :   tree lb = cp_save_expr (low_bound);
    6319                 :        9465 :   if (lb != low_bound)
    6320                 :             :     {
    6321                 :         720 :       TREE_OPERAND (t, 1) = lb;
    6322                 :         720 :       low_bound = lb;
    6323                 :             :     }
    6324                 :             :   /* Temporarily disable -fstrong-eval-order for array reductions.
    6325                 :             :      The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
    6326                 :             :      is something the middle-end can't cope with and more importantly,
    6327                 :             :      it needs to be the actual base variable that is privatized, not some
    6328                 :             :      temporary assigned previous value of it.  That, together with OpenMP
    6329                 :             :      saying how many times the side-effects are evaluated is unspecified,
    6330                 :             :      makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified.  */
    6331                 :        9465 :   warning_sentinel s (flag_strong_eval_order,
    6332                 :        9465 :                       OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6333                 :        8368 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6334                 :       19049 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
    6335                 :        9465 :   ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
    6336                 :             :                          tf_warning_or_error);
    6337                 :        9465 :   return ret;
    6338                 :        9465 : }
    6339                 :             : 
    6340                 :             : /* Handle array sections for clause C.  */
    6341                 :             : 
    6342                 :             : static bool
    6343                 :        9568 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
    6344                 :             : {
    6345                 :        9568 :   bool maybe_zero_len = false;
    6346                 :        9568 :   unsigned int first_non_one = 0;
    6347                 :        9568 :   auto_vec<tree, 10> types;
    6348                 :        9568 :   tree *tp = &OMP_CLAUSE_DECL (c);
    6349                 :        9568 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6350                 :        8611 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6351                 :        9916 :       && OMP_ITERATOR_DECL_P (*tp))
    6352                 :         258 :     tp = &TREE_VALUE (*tp);
    6353                 :        9568 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
    6354                 :             :                                             maybe_zero_len, first_non_one,
    6355                 :             :                                             ort);
    6356                 :        9568 :   if (first == error_mark_node)
    6357                 :             :     return true;
    6358                 :        8488 :   if (first == NULL_TREE)
    6359                 :             :     return false;
    6360                 :        7671 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    6361                 :        7671 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
    6362                 :             :     {
    6363                 :         915 :       tree t = *tp;
    6364                 :         915 :       tree tem = NULL_TREE;
    6365                 :         915 :       if (processing_template_decl)
    6366                 :             :         return false;
    6367                 :             :       /* Need to evaluate side effects in the length expressions
    6368                 :             :          if any.  */
    6369                 :         816 :       while (TREE_CODE (t) == TREE_LIST)
    6370                 :             :         {
    6371                 :           0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
    6372                 :             :             {
    6373                 :           0 :               if (tem == NULL_TREE)
    6374                 :             :                 tem = TREE_VALUE (t);
    6375                 :             :               else
    6376                 :           0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
    6377                 :           0 :                               TREE_VALUE (t), tem);
    6378                 :             :             }
    6379                 :           0 :           t = TREE_CHAIN (t);
    6380                 :             :         }
    6381                 :         816 :       if (tem)
    6382                 :           0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
    6383                 :         816 :       *tp = first;
    6384                 :             :     }
    6385                 :             :   else
    6386                 :             :     {
    6387                 :        6756 :       unsigned int num = types.length (), i;
    6388                 :        6756 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
    6389                 :        6756 :       tree condition = NULL_TREE;
    6390                 :             : 
    6391                 :        6756 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
    6392                 :           3 :         maybe_zero_len = true;
    6393                 :        6756 :       if (processing_template_decl && maybe_zero_len)
    6394                 :             :         return false;
    6395                 :             : 
    6396                 :       14220 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
    6397                 :        7542 :            t = TREE_OPERAND (t, 0))
    6398                 :             :         {
    6399                 :        7617 :           gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
    6400                 :             : 
    6401                 :        7617 :           tree low_bound = TREE_OPERAND (t, 1);
    6402                 :        7617 :           tree length = TREE_OPERAND (t, 2);
    6403                 :             : 
    6404                 :        7617 :           i--;
    6405                 :        7617 :           if (low_bound
    6406                 :        6188 :               && TREE_CODE (low_bound) == INTEGER_CST
    6407                 :       13194 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
    6408                 :        5577 :                  > TYPE_PRECISION (sizetype))
    6409                 :           0 :             low_bound = fold_convert (sizetype, low_bound);
    6410                 :        7617 :           if (length
    6411                 :        7085 :               && TREE_CODE (length) == INTEGER_CST
    6412                 :       12810 :               && TYPE_PRECISION (TREE_TYPE (length))
    6413                 :        5193 :                  > TYPE_PRECISION (sizetype))
    6414                 :           0 :             length = fold_convert (sizetype, length);
    6415                 :        7617 :           if (low_bound == NULL_TREE)
    6416                 :        1429 :             low_bound = integer_zero_node;
    6417                 :        7617 :           if (!maybe_zero_len && i > first_non_one)
    6418                 :             :             {
    6419                 :         646 :               if (integer_nonzerop (low_bound))
    6420                 :          36 :                 goto do_warn_noncontiguous;
    6421                 :         610 :               if (length != NULL_TREE
    6422                 :         282 :                   && TREE_CODE (length) == INTEGER_CST
    6423                 :         282 :                   && TYPE_DOMAIN (types[i])
    6424                 :         282 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
    6425                 :         892 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
    6426                 :             :                      == INTEGER_CST)
    6427                 :             :                 {
    6428                 :         282 :                   tree size;
    6429                 :         282 :                   size = size_binop (PLUS_EXPR,
    6430                 :             :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6431                 :             :                                      size_one_node);
    6432                 :         282 :                   if (!tree_int_cst_equal (length, size))
    6433                 :             :                     {
    6434                 :          39 :                      do_warn_noncontiguous:
    6435                 :         150 :                       error_at (OMP_CLAUSE_LOCATION (c),
    6436                 :             :                                 "array section is not contiguous in %qs "
    6437                 :             :                                 "clause",
    6438                 :          75 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    6439                 :          75 :                       return true;
    6440                 :             :                     }
    6441                 :             :                 }
    6442                 :         571 :               if (!processing_template_decl
    6443                 :         401 :                   && length != NULL_TREE
    6444                 :         742 :                   && TREE_SIDE_EFFECTS (length))
    6445                 :             :                 {
    6446                 :           0 :                   if (side_effects == NULL_TREE)
    6447                 :             :                     side_effects = length;
    6448                 :             :                   else
    6449                 :           0 :                     side_effects = build2 (COMPOUND_EXPR,
    6450                 :           0 :                                            TREE_TYPE (side_effects),
    6451                 :             :                                            length, side_effects);
    6452                 :             :                 }
    6453                 :             :             }
    6454                 :        6971 :           else if (processing_template_decl)
    6455                 :         726 :             continue;
    6456                 :             :           else
    6457                 :             :             {
    6458                 :        6245 :               tree l;
    6459                 :             : 
    6460                 :        6245 :               if (i > first_non_one
    6461                 :        6245 :                   && ((length && integer_nonzerop (length))
    6462                 :           0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6463                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6464                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
    6465                 :           0 :                 continue;
    6466                 :        6245 :               if (length)
    6467                 :        6123 :                 l = fold_convert (sizetype, length);
    6468                 :             :               else
    6469                 :             :                 {
    6470                 :         122 :                   l = size_binop (PLUS_EXPR,
    6471                 :             :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
    6472                 :             :                                   size_one_node);
    6473                 :         122 :                   l = size_binop (MINUS_EXPR, l,
    6474                 :             :                                   fold_convert (sizetype, low_bound));
    6475                 :             :                 }
    6476                 :        6245 :               if (i > first_non_one)
    6477                 :             :                 {
    6478                 :           0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
    6479                 :             :                                    size_zero_node);
    6480                 :           0 :                   if (condition == NULL_TREE)
    6481                 :             :                     condition = l;
    6482                 :             :                   else
    6483                 :           0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
    6484                 :             :                                              l, condition);
    6485                 :             :                 }
    6486                 :        6245 :               else if (size == NULL_TREE)
    6487                 :             :                 {
    6488                 :        5958 :                   size = size_in_bytes (TREE_TYPE (types[i]));
    6489                 :        5958 :                   tree eltype = TREE_TYPE (types[num - 1]);
    6490                 :        6029 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
    6491                 :          71 :                     eltype = TREE_TYPE (eltype);
    6492                 :        5958 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6493                 :        5148 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6494                 :       10353 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6495                 :        1659 :                     size = size_binop (EXACT_DIV_EXPR, size,
    6496                 :             :                                        size_in_bytes (eltype));
    6497                 :        5958 :                   size = size_binop (MULT_EXPR, size, l);
    6498                 :        5958 :                   if (condition)
    6499                 :           0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
    6500                 :             :                                         size, size_zero_node);
    6501                 :             :                 }
    6502                 :             :               else
    6503                 :         287 :                 size = size_binop (MULT_EXPR, size, l);
    6504                 :             :             }
    6505                 :             :         }
    6506                 :        6603 :       if (!processing_template_decl)
    6507                 :             :         {
    6508                 :        5958 :           if (side_effects)
    6509                 :           0 :             size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
    6510                 :        5958 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    6511                 :        5148 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    6512                 :       10353 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
    6513                 :             :             {
    6514                 :        1659 :               size = size_binop (MINUS_EXPR, size, size_one_node);
    6515                 :        1659 :               size = save_expr (size);
    6516                 :        1659 :               tree index_type = build_index_type (size);
    6517                 :        1659 :               tree eltype = TREE_TYPE (first);
    6518                 :        1688 :               while (TREE_CODE (eltype) == ARRAY_TYPE)
    6519                 :          29 :                 eltype = TREE_TYPE (eltype);
    6520                 :        1659 :               tree type = build_array_type (eltype, index_type);
    6521                 :        1659 :               tree ptype = build_pointer_type (eltype);
    6522                 :        1659 :               if (TYPE_REF_P (TREE_TYPE (t))
    6523                 :        1659 :                   && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
    6524                 :         170 :                 t = convert_from_reference (t);
    6525                 :        1489 :               else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6526                 :         641 :                 t = build_fold_addr_expr (t);
    6527                 :        1659 :               tree t2 = build_fold_addr_expr (first);
    6528                 :        1659 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6529                 :             :                                      ptrdiff_type_node, t2);
    6530                 :        1659 :               t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
    6531                 :             :                                     ptrdiff_type_node, t2,
    6532                 :        1659 :                                     fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6533                 :             :                                                       ptrdiff_type_node, t));
    6534                 :        1659 :               if (tree_fits_shwi_p (t2))
    6535                 :        1321 :                 t = build2 (MEM_REF, type, t,
    6536                 :        1321 :                             build_int_cst (ptype, tree_to_shwi (t2)));
    6537                 :             :               else
    6538                 :             :                 {
    6539                 :         338 :                   t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
    6540                 :             :                                          sizetype, t2);
    6541                 :         338 :                   t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
    6542                 :         338 :                                   TREE_TYPE (t), t, t2);
    6543                 :         338 :                   t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
    6544                 :             :                 }
    6545                 :        1659 :               OMP_CLAUSE_DECL (c) = t;
    6546                 :        7617 :               return false;
    6547                 :             :             }
    6548                 :        4299 :           OMP_CLAUSE_DECL (c) = first;
    6549                 :        4299 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
    6550                 :             :             return false;
    6551                 :        4273 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    6552                 :        4273 :               || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    6553                 :        3716 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
    6554                 :        3704 :                   && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
    6555                 :        4249 :             OMP_CLAUSE_SIZE (c) = size;
    6556                 :        4273 :           if (TREE_CODE (t) == FIELD_DECL)
    6557                 :           3 :             t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    6558                 :             : 
    6559                 :        4273 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    6560                 :             :             return false;
    6561                 :             : 
    6562                 :        3728 :           if (TREE_CODE (first) == INDIRECT_REF)
    6563                 :             :             {
    6564                 :             :               /* Detect and skip adding extra nodes for pointer-to-member
    6565                 :             :                  mappings.  These are unsupported for now.  */
    6566                 :        2403 :               tree tmp = TREE_OPERAND (first, 0);
    6567                 :             : 
    6568                 :        2403 :               if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
    6569                 :        1908 :                 tmp = TREE_OPERAND (tmp, 0);
    6570                 :             : 
    6571                 :        2403 :               if (TREE_CODE (tmp) == INDIRECT_REF)
    6572                 :         158 :                 tmp = TREE_OPERAND (tmp, 0);
    6573                 :             : 
    6574                 :        2403 :               if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
    6575                 :             :                 {
    6576                 :         465 :                   tree offset = TREE_OPERAND (tmp, 1);
    6577                 :         465 :                   STRIP_NOPS (offset);
    6578                 :         465 :                   if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
    6579                 :             :                     {
    6580                 :          36 :                       sorry_at (OMP_CLAUSE_LOCATION (c),
    6581                 :             :                                 "pointer-to-member mapping %qE not supported",
    6582                 :          18 :                                 OMP_CLAUSE_DECL (c));
    6583                 :          18 :                       return true;
    6584                 :             :                     }
    6585                 :             :                 }
    6586                 :             :             }
    6587                 :             : 
    6588                 :             :           /* FIRST represents the first item of data that we are mapping.
    6589                 :             :              E.g. if we're mapping an array, FIRST might resemble
    6590                 :             :              "foo.bar.myarray[0]".  */
    6591                 :             : 
    6592                 :        3710 :           auto_vec<omp_addr_token *, 10> addr_tokens;
    6593                 :             : 
    6594                 :        3710 :           if (!omp_parse_expr (addr_tokens, first))
    6595                 :             :             return true;
    6596                 :             : 
    6597                 :        3710 :           cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    6598                 :             : 
    6599                 :        3710 :           tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
    6600                 :        3710 :           if (nc != error_mark_node)
    6601                 :             :             {
    6602                 :        3710 :               using namespace omp_addr_tokenizer;
    6603                 :             : 
    6604                 :        3710 :               if (ai.maybe_zero_length_array_section (c))
    6605                 :        3686 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
    6606                 :             : 
    6607                 :             :               /* !!! If we're accessing a base decl via chained access
    6608                 :             :                  methods (e.g. multiple indirections), duplicate clause
    6609                 :             :                  detection won't work properly.  Skip it in that case.  */
    6610                 :        3710 :               if ((addr_tokens[0]->type == STRUCTURE_BASE
    6611                 :        2693 :                    || addr_tokens[0]->type == ARRAY_BASE)
    6612                 :        3710 :                   && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    6613                 :        3699 :                   && addr_tokens[1]->type == ACCESS_METHOD
    6614                 :        7409 :                   && omp_access_chain_p (addr_tokens, 1))
    6615                 :         218 :                 c = nc;
    6616                 :             : 
    6617                 :        3710 :               return false;
    6618                 :             :             }
    6619                 :        7420 :         }
    6620                 :             :     }
    6621                 :             :   return false;
    6622                 :        9568 : }
    6623                 :             : 
    6624                 :             : /* Return identifier to look up for omp declare reduction.  */
    6625                 :             : 
    6626                 :             : tree
    6627                 :        7069 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
    6628                 :             : {
    6629                 :        7069 :   const char *p = NULL;
    6630                 :        7069 :   const char *m = NULL;
    6631                 :        7069 :   switch (reduction_code)
    6632                 :             :     {
    6633                 :        4188 :     case PLUS_EXPR:
    6634                 :        4188 :     case MULT_EXPR:
    6635                 :        4188 :     case MINUS_EXPR:
    6636                 :        4188 :     case BIT_AND_EXPR:
    6637                 :        4188 :     case BIT_XOR_EXPR:
    6638                 :        4188 :     case BIT_IOR_EXPR:
    6639                 :        4188 :     case TRUTH_ANDIF_EXPR:
    6640                 :        4188 :     case TRUTH_ORIF_EXPR:
    6641                 :        4188 :       reduction_id = ovl_op_identifier (false, reduction_code);
    6642                 :        4188 :       break;
    6643                 :             :     case MIN_EXPR:
    6644                 :             :       p = "min";
    6645                 :             :       break;
    6646                 :             :     case MAX_EXPR:
    6647                 :             :       p = "max";
    6648                 :             :       break;
    6649                 :             :     default:
    6650                 :             :       break;
    6651                 :             :     }
    6652                 :             : 
    6653                 :        4188 :   if (p == NULL)
    6654                 :             :     {
    6655                 :        6905 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
    6656                 :           0 :         return error_mark_node;
    6657                 :        6905 :       p = IDENTIFIER_POINTER (reduction_id);
    6658                 :             :     }
    6659                 :             : 
    6660                 :        7069 :   if (type != NULL_TREE)
    6661                 :        2025 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6662                 :             : 
    6663                 :        7069 :   const char prefix[] = "omp declare reduction ";
    6664                 :        7069 :   size_t lenp = sizeof (prefix);
    6665                 :        7069 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6666                 :        2025 :     lenp = 1;
    6667                 :        7069 :   size_t len = strlen (p);
    6668                 :        7069 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6669                 :        7069 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6670                 :        7069 :   if (lenp > 1)
    6671                 :        5044 :     memcpy (name, prefix, lenp - 1);
    6672                 :        7069 :   memcpy (name + lenp - 1, p, len + 1);
    6673                 :        7069 :   if (m)
    6674                 :             :     {
    6675                 :        2025 :       name[lenp + len - 1] = '~';
    6676                 :        2025 :       memcpy (name + lenp + len, m, lenm);
    6677                 :             :     }
    6678                 :        7069 :   return get_identifier (name);
    6679                 :             : }
    6680                 :             : 
    6681                 :             : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
    6682                 :             :    FUNCTION_DECL or NULL_TREE if not found.  */
    6683                 :             : 
    6684                 :             : static tree
    6685                 :        1284 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
    6686                 :             :                       vec<tree> *ambiguousp)
    6687                 :             : {
    6688                 :        1284 :   tree orig_id = id;
    6689                 :        1284 :   tree baselink = NULL_TREE;
    6690                 :        1284 :   if (identifier_p (id))
    6691                 :             :     {
    6692                 :        1256 :       cp_id_kind idk;
    6693                 :        1256 :       bool nonint_cst_expression_p;
    6694                 :        1256 :       const char *error_msg;
    6695                 :        1256 :       id = omp_reduction_id (ERROR_MARK, id, type);
    6696                 :        1256 :       tree decl = lookup_name (id);
    6697                 :        1256 :       if (decl == NULL_TREE)
    6698                 :          80 :         decl = error_mark_node;
    6699                 :        1256 :       id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
    6700                 :             :                                  &nonint_cst_expression_p, false, true, false,
    6701                 :             :                                  false, &error_msg, loc);
    6702                 :        1256 :       if (idk == CP_ID_KIND_UNQUALIFIED
    6703                 :        1336 :           && identifier_p (id))
    6704                 :             :         {
    6705                 :          80 :           vec<tree, va_gc> *args = NULL;
    6706                 :          80 :           vec_safe_push (args, build_reference_type (type));
    6707                 :          80 :           id = perform_koenig_lookup (id, args, tf_none);
    6708                 :             :         }
    6709                 :             :     }
    6710                 :          28 :   else if (TREE_CODE (id) == SCOPE_REF)
    6711                 :          28 :     id = lookup_qualified_name (TREE_OPERAND (id, 0),
    6712                 :             :                                 omp_reduction_id (ERROR_MARK,
    6713                 :          28 :                                                   TREE_OPERAND (id, 1),
    6714                 :             :                                                   type),
    6715                 :             :                                 LOOK_want::NORMAL, false);
    6716                 :        1284 :   tree fns = id;
    6717                 :        1284 :   id = NULL_TREE;
    6718                 :        1284 :   if (fns && is_overloaded_fn (fns))
    6719                 :             :     {
    6720                 :        1210 :       for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
    6721                 :             :         {
    6722                 :        1210 :           tree fndecl = *iter;
    6723                 :        1210 :           if (TREE_CODE (fndecl) == FUNCTION_DECL)
    6724                 :             :             {
    6725                 :        1210 :               tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
    6726                 :        1210 :               if (same_type_p (TREE_TYPE (argtype), type))
    6727                 :             :                 {
    6728                 :        1210 :                   id = fndecl;
    6729                 :        1210 :                   break;
    6730                 :             :                 }
    6731                 :             :             }
    6732                 :             :         }
    6733                 :             : 
    6734                 :        1210 :       if (id && BASELINK_P (fns))
    6735                 :             :         {
    6736                 :          74 :           if (baselinkp)
    6737                 :           0 :             *baselinkp = fns;
    6738                 :             :           else
    6739                 :          74 :             baselink = fns;
    6740                 :             :         }
    6741                 :             :     }
    6742                 :             : 
    6743                 :        1284 :   if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
    6744                 :             :     {
    6745                 :          35 :       auto_vec<tree> ambiguous;
    6746                 :          35 :       tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
    6747                 :          35 :       unsigned int ix;
    6748                 :          35 :       if (ambiguousp == NULL)
    6749                 :          19 :         ambiguousp = &ambiguous;
    6750                 :          73 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    6751                 :             :         {
    6752                 :          52 :           id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
    6753                 :             :                                      baselinkp ? baselinkp : &baselink,
    6754                 :             :                                      ambiguousp);
    6755                 :          38 :           if (id == NULL_TREE)
    6756                 :          14 :             continue;
    6757                 :          24 :           if (!ambiguousp->is_empty ())
    6758                 :           3 :             ambiguousp->safe_push (id);
    6759                 :          21 :           else if (ret != NULL_TREE)
    6760                 :             :             {
    6761                 :           6 :               ambiguousp->safe_push (ret);
    6762                 :           6 :               ambiguousp->safe_push (id);
    6763                 :           6 :               ret = NULL_TREE;
    6764                 :             :             }
    6765                 :             :           else
    6766                 :          15 :             ret = id;
    6767                 :             :         }
    6768                 :          35 :       if (ambiguousp != &ambiguous)
    6769                 :          16 :         return ret;
    6770                 :          19 :       if (!ambiguous.is_empty ())
    6771                 :             :         {
    6772                 :           6 :           auto_diagnostic_group d;
    6773                 :           6 :           const char *str = _("candidates are:");
    6774                 :           6 :           unsigned int idx;
    6775                 :           6 :           tree udr;
    6776                 :           6 :           error_at (loc, "user defined reduction lookup is ambiguous");
    6777                 :          27 :           FOR_EACH_VEC_ELT (ambiguous, idx, udr)
    6778                 :             :             {
    6779                 :          15 :               inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
    6780                 :          15 :               if (idx == 0)
    6781                 :           6 :                 str = get_spaces (str);
    6782                 :             :             }
    6783                 :           6 :           ret = error_mark_node;
    6784                 :           6 :           baselink = NULL_TREE;
    6785                 :           6 :         }
    6786                 :          19 :       id = ret;
    6787                 :          35 :     }
    6788                 :        1268 :   if (id && baselink)
    6789                 :          74 :     perform_or_defer_access_check (BASELINK_BINFO (baselink),
    6790                 :             :                                    id, id, tf_warning_or_error);
    6791                 :             :   return id;
    6792                 :             : }
    6793                 :             : 
    6794                 :             : /* Return identifier to look up for omp declare mapper.  */
    6795                 :             : 
    6796                 :             : tree
    6797                 :        3905 : omp_mapper_id (tree mapper_id, tree type)
    6798                 :             : {
    6799                 :        3905 :   const char *p = NULL;
    6800                 :        3905 :   const char *m = NULL;
    6801                 :             : 
    6802                 :        3905 :   if (mapper_id == NULL_TREE)
    6803                 :             :     p = "";
    6804                 :          68 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
    6805                 :          68 :     p = IDENTIFIER_POINTER (mapper_id);
    6806                 :             :   else
    6807                 :           0 :     return error_mark_node;
    6808                 :             : 
    6809                 :        3905 :   if (type != NULL_TREE)
    6810                 :        3903 :     m = mangle_type_string (TYPE_MAIN_VARIANT (type));
    6811                 :             : 
    6812                 :        3905 :   const char prefix[] = "omp declare mapper ";
    6813                 :        3905 :   size_t lenp = sizeof (prefix);
    6814                 :        3905 :   if (strncmp (p, prefix, lenp - 1) == 0)
    6815                 :           2 :     lenp = 1;
    6816                 :        3905 :   size_t len = strlen (p);
    6817                 :        3905 :   size_t lenm = m ? strlen (m) + 1 : 0;
    6818                 :        3905 :   char *name = XALLOCAVEC (char, lenp + len + lenm);
    6819                 :        3905 :   memcpy (name, prefix, lenp - 1);
    6820                 :        3905 :   memcpy (name + lenp - 1, p, len + 1);
    6821                 :        3905 :   if (m)
    6822                 :             :     {
    6823                 :        3903 :       name[lenp + len - 1] = '~';
    6824                 :        3903 :       memcpy (name + lenp + len, m, lenm);
    6825                 :             :     }
    6826                 :        3905 :   return get_identifier (name);
    6827                 :             : }
    6828                 :             : 
    6829                 :             : tree
    6830                 :        6952 : cxx_omp_mapper_lookup (tree id, tree type)
    6831                 :             : {
    6832                 :        6952 :   if (!RECORD_OR_UNION_TYPE_P (type))
    6833                 :             :     return NULL_TREE;
    6834                 :        3692 :   id = omp_mapper_id (id, type);
    6835                 :        3692 :   return lookup_name (id);
    6836                 :             : }
    6837                 :             : 
    6838                 :             : tree
    6839                 :         273 : cxx_omp_extract_mapper_directive (tree vardecl)
    6840                 :             : {
    6841                 :         273 :   gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
    6842                 :             : 
    6843                 :             :   /* Instantiate the decl if we haven't already.  */
    6844                 :         273 :   mark_used (vardecl);
    6845                 :         273 :   tree body = DECL_INITIAL (vardecl);
    6846                 :             : 
    6847                 :         273 :   if (TREE_CODE (body) == STATEMENT_LIST)
    6848                 :             :     {
    6849                 :           0 :       tree_stmt_iterator tsi = tsi_start (body);
    6850                 :           0 :       gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
    6851                 :           0 :       tsi_next (&tsi);
    6852                 :           0 :       body = tsi_stmt (tsi);
    6853                 :             :     }
    6854                 :             : 
    6855                 :         273 :   gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
    6856                 :             : 
    6857                 :         273 :   return body;
    6858                 :             : }
    6859                 :             : 
    6860                 :             : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
    6861                 :             :    nothing more complicated.  */
    6862                 :             : 
    6863                 :             : tree
    6864                 :        1510 : cxx_omp_map_array_section (location_t loc, tree t)
    6865                 :             : {
    6866                 :        1510 :   tree low = TREE_OPERAND (t, 1);
    6867                 :        1510 :   tree len = TREE_OPERAND (t, 2);
    6868                 :             : 
    6869                 :        1510 :   if (len && integer_onep (len))
    6870                 :             :     {
    6871                 :         237 :       t = TREE_OPERAND (t, 0);
    6872                 :             : 
    6873                 :         237 :       if (!low)
    6874                 :           9 :         low = integer_zero_node;
    6875                 :             : 
    6876                 :         237 :       if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
    6877                 :           5 :         t = convert_from_reference (t);
    6878                 :             : 
    6879                 :         237 :       t = build_array_ref (loc, t, low);
    6880                 :             :     }
    6881                 :             : 
    6882                 :        1510 :   return t;
    6883                 :             : }
    6884                 :             : 
    6885                 :             : /* Helper function for cp_parser_omp_declare_reduction_exprs
    6886                 :             :    and tsubst_omp_udr.
    6887                 :             :    Remove CLEANUP_STMT for data (omp_priv variable).
    6888                 :             :    Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
    6889                 :             :    DECL_EXPR.  */
    6890                 :             : 
    6891                 :             : tree
    6892                 :        4347 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
    6893                 :             : {
    6894                 :        4347 :   if (TYPE_P (*tp))
    6895                 :         221 :     *walk_subtrees = 0;
    6896                 :        4126 :   else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
    6897                 :          52 :     *tp = CLEANUP_BODY (*tp);
    6898                 :        4074 :   else if (TREE_CODE (*tp) == DECL_EXPR)
    6899                 :             :     {
    6900                 :         298 :       tree decl = DECL_EXPR_DECL (*tp);
    6901                 :         298 :       if (!processing_template_decl
    6902                 :         252 :           && decl == (tree) data
    6903                 :         252 :           && DECL_INITIAL (decl)
    6904                 :         387 :           && DECL_INITIAL (decl) != error_mark_node)
    6905                 :             :         {
    6906                 :          89 :           tree list = NULL_TREE;
    6907                 :          89 :           append_to_statement_list_force (*tp, &list);
    6908                 :          89 :           tree init_expr = build2 (INIT_EXPR, void_type_node,
    6909                 :          89 :                                    decl, DECL_INITIAL (decl));
    6910                 :          89 :           DECL_INITIAL (decl) = NULL_TREE;
    6911                 :          89 :           append_to_statement_list_force (init_expr, &list);
    6912                 :          89 :           *tp = list;
    6913                 :             :         }
    6914                 :             :     }
    6915                 :        4347 :   return NULL_TREE;
    6916                 :             : }
    6917                 :             : 
    6918                 :             : /* Data passed from cp_check_omp_declare_reduction to
    6919                 :             :    cp_check_omp_declare_reduction_r.  */
    6920                 :             : 
    6921                 :             : struct cp_check_omp_declare_reduction_data
    6922                 :             : {
    6923                 :             :   location_t loc;
    6924                 :             :   tree stmts[7];
    6925                 :             :   bool combiner_p;
    6926                 :             : };
    6927                 :             : 
    6928                 :             : /* Helper function for cp_check_omp_declare_reduction, called via
    6929                 :             :    cp_walk_tree.  */
    6930                 :             : 
    6931                 :             : static tree
    6932                 :       14814 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
    6933                 :             : {
    6934                 :       14814 :   struct cp_check_omp_declare_reduction_data *udr_data
    6935                 :             :     = (struct cp_check_omp_declare_reduction_data *) data;
    6936                 :       14814 :   if (SSA_VAR_P (*tp)
    6937                 :        2666 :       && !DECL_ARTIFICIAL (*tp)
    6938                 :         225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
    6939                 :         225 :       && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
    6940                 :             :     {
    6941                 :         135 :       location_t loc = udr_data->loc;
    6942                 :         135 :       if (udr_data->combiner_p)
    6943                 :          45 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
    6944                 :             :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
    6945                 :             :                   *tp);
    6946                 :             :       else
    6947                 :          90 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
    6948                 :             :                        "to variable %qD which is not %<omp_priv%> nor "
    6949                 :             :                        "%<omp_orig%>",
    6950                 :             :                   *tp);
    6951                 :         135 :       return *tp;
    6952                 :             :     }
    6953                 :             :   return NULL_TREE;
    6954                 :             : }
    6955                 :             : 
    6956                 :             : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions.  */
    6957                 :             : 
    6958                 :             : bool
    6959                 :        1090 : cp_check_omp_declare_reduction (tree udr)
    6960                 :             : {
    6961                 :        1090 :   tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
    6962                 :        1090 :   gcc_assert (TYPE_REF_P (type));
    6963                 :        1090 :   type = TREE_TYPE (type);
    6964                 :        1090 :   int i;
    6965                 :        1090 :   location_t loc = DECL_SOURCE_LOCATION (udr);
    6966                 :             : 
    6967                 :        1090 :   if (type == error_mark_node)
    6968                 :             :     return false;
    6969                 :        1090 :   if (ARITHMETIC_TYPE_P (type))
    6970                 :             :     {
    6971                 :             :       static enum tree_code predef_codes[]
    6972                 :             :         = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
    6973                 :             :             BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
    6974                 :        3276 :       for (i = 0; i < 8; i++)
    6975                 :             :         {
    6976                 :        2918 :           tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
    6977                 :        2918 :           const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
    6978                 :        2918 :           const char *n2 = IDENTIFIER_POINTER (id);
    6979                 :        2918 :           if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
    6980                 :        2918 :               && (n1[IDENTIFIER_LENGTH (id)] == '~'
    6981                 :           0 :                   || n1[IDENTIFIER_LENGTH (id)] == '\0'))
    6982                 :             :             break;
    6983                 :             :         }
    6984                 :             : 
    6985                 :         376 :       if (i == 8
    6986                 :         358 :           && TREE_CODE (type) != COMPLEX_EXPR)
    6987                 :             :         {
    6988                 :         358 :           const char prefix_minmax[] = "omp declare reduction m";
    6989                 :         358 :           size_t prefix_size = sizeof (prefix_minmax) - 1;
    6990                 :         358 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
    6991                 :         358 :           if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
    6992                 :             :                        prefix_minmax, prefix_size) == 0
    6993                 :          10 :               && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
    6994                 :           4 :                   || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
    6995                 :         368 :               && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
    6996                 :           6 :             i = 0;
    6997                 :             :         }
    6998                 :         376 :       if (i < 8)
    6999                 :             :         {
    7000                 :          24 :           error_at (loc, "predeclared arithmetic type %qT in "
    7001                 :             :                          "%<#pragma omp declare reduction%>", type);
    7002                 :          24 :           return false;
    7003                 :             :         }
    7004                 :             :     }
    7005                 :             :   else if (FUNC_OR_METHOD_TYPE_P (type)
    7006                 :             :            || TREE_CODE (type) == ARRAY_TYPE)
    7007                 :             :     {
    7008                 :          24 :       error_at (loc, "function or array type %qT in "
    7009                 :             :                      "%<#pragma omp declare reduction%>", type);
    7010                 :          24 :       return false;
    7011                 :             :     }
    7012                 :             :   else if (TYPE_REF_P (type))
    7013                 :             :     {
    7014                 :           0 :       error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
    7015                 :             :                 type);
    7016                 :           0 :       return false;
    7017                 :             :     }
    7018                 :         690 :   else if (TYPE_QUALS_NO_ADDR_SPACE (type))
    7019                 :             :     {
    7020                 :          24 :       error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
    7021                 :             :                 "type %qT in %<#pragma omp declare reduction%>", type);
    7022                 :          24 :       return false;
    7023                 :             :     }
    7024                 :             : 
    7025                 :        1018 :   tree body = DECL_SAVED_TREE (udr);
    7026                 :        1018 :   if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
    7027                 :             :     return true;
    7028                 :             : 
    7029                 :         835 :   tree_stmt_iterator tsi;
    7030                 :         835 :   struct cp_check_omp_declare_reduction_data data;
    7031                 :         835 :   memset (data.stmts, 0, sizeof data.stmts);
    7032                 :         835 :   for (i = 0, tsi = tsi_start (body);
    7033                 :        4627 :        i < 7 && !tsi_end_p (tsi);
    7034                 :        3792 :        i++, tsi_next (&tsi))
    7035                 :        3792 :     data.stmts[i] = tsi_stmt (tsi);
    7036                 :         835 :   data.loc = loc;
    7037                 :         835 :   gcc_assert (tsi_end_p (tsi));
    7038                 :         835 :   if (i >= 3)
    7039                 :             :     {
    7040                 :         835 :       gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
    7041                 :             :                   && TREE_CODE (data.stmts[1]) == DECL_EXPR);
    7042                 :         835 :       if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
    7043                 :             :         return true;
    7044                 :         790 :       data.combiner_p = true;
    7045                 :         790 :       if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
    7046                 :             :                         &data, NULL))
    7047                 :          45 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
    7048                 :             :     }
    7049                 :         790 :   if (i >= 6)
    7050                 :             :     {
    7051                 :         330 :       gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
    7052                 :             :                   && TREE_CODE (data.stmts[4]) == DECL_EXPR);
    7053                 :         330 :       data.combiner_p = false;
    7054                 :         330 :       if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
    7055                 :             :                         &data, NULL)
    7056                 :         330 :           || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
    7057                 :             :                            cp_check_omp_declare_reduction_r, &data, NULL))
    7058                 :          90 :         suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /* Wat warning? */);
    7059                 :         330 :       if (i == 7)
    7060                 :         192 :         gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
    7061                 :             :     }
    7062                 :             :   return true;
    7063                 :             : }
    7064                 :             : 
    7065                 :             : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
    7066                 :             :    an inline call.  But, remap
    7067                 :             :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
    7068                 :             :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
    7069                 :             : 
    7070                 :             : static tree
    7071                 :        2191 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
    7072                 :             :                tree decl, tree placeholder)
    7073                 :             : {
    7074                 :        2191 :   copy_body_data id;
    7075                 :        2191 :   hash_map<tree, tree> decl_map;
    7076                 :             : 
    7077                 :        2191 :   decl_map.put (omp_decl1, placeholder);
    7078                 :        2191 :   decl_map.put (omp_decl2, decl);
    7079                 :        2191 :   memset (&id, 0, sizeof (id));
    7080                 :        2191 :   id.src_fn = DECL_CONTEXT (omp_decl1);
    7081                 :        2191 :   id.dst_fn = current_function_decl;
    7082                 :        2191 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    7083                 :        2191 :   id.decl_map = &decl_map;
    7084                 :             : 
    7085                 :        2191 :   id.copy_decl = copy_decl_no_change;
    7086                 :        2191 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    7087                 :        2191 :   id.transform_new_cfg = true;
    7088                 :        2191 :   id.transform_return_to_modify = false;
    7089                 :        2191 :   id.eh_lp_nr = 0;
    7090                 :        2191 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
    7091                 :        2191 :   return stmt;
    7092                 :        2191 : }
    7093                 :             : 
    7094                 :             : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
    7095                 :             :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
    7096                 :             : 
    7097                 :             : static tree
    7098                 :       15411 : find_omp_placeholder_r (tree *tp, int *, void *data)
    7099                 :             : {
    7100                 :       15411 :   if (*tp == (tree) data)
    7101                 :         265 :     return *tp;
    7102                 :             :   return NULL_TREE;
    7103                 :             : }
    7104                 :             : 
    7105                 :             : /* Helper function of finish_omp_clauses.  Handle OMP_CLAUSE_REDUCTION C.
    7106                 :             :    Return true if there is some error and the clause should be removed.  */
    7107                 :             : 
    7108                 :             : static bool
    7109                 :        8948 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
    7110                 :             : {
    7111                 :        8948 :   tree t = OMP_CLAUSE_DECL (c);
    7112                 :        8948 :   bool predefined = false;
    7113                 :        8948 :   if (TREE_CODE (t) == TREE_LIST)
    7114                 :             :     {
    7115                 :           0 :       gcc_assert (processing_template_decl);
    7116                 :             :       return false;
    7117                 :             :     }
    7118                 :        8948 :   tree type = TREE_TYPE (t);
    7119                 :        8948 :   if (TREE_CODE (t) == MEM_REF)
    7120                 :        1656 :     type = TREE_TYPE (type);
    7121                 :        8948 :   if (TYPE_REF_P (type))
    7122                 :         557 :     type = TREE_TYPE (type);
    7123                 :        8948 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7124                 :             :     {
    7125                 :         377 :       tree oatype = type;
    7126                 :         377 :       gcc_assert (TREE_CODE (t) != MEM_REF);
    7127                 :         757 :       while (TREE_CODE (type) == ARRAY_TYPE)
    7128                 :         380 :         type = TREE_TYPE (type);
    7129                 :         377 :       if (!processing_template_decl)
    7130                 :             :         {
    7131                 :         270 :           t = require_complete_type (t);
    7132                 :         270 :           if (t == error_mark_node
    7133                 :         270 :               || !complete_type_or_else (oatype, NULL_TREE))
    7134                 :           9 :             return true;
    7135                 :         261 :           tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
    7136                 :             :                                   TYPE_SIZE_UNIT (type));
    7137                 :         261 :           if (integer_zerop (size))
    7138                 :             :             {
    7139                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7140                 :             :                         "%qE in %<reduction%> clause is a zero size array",
    7141                 :             :                         omp_clause_printable_decl (t));
    7142                 :           3 :               return true;
    7143                 :             :             }
    7144                 :         258 :           size = size_binop (MINUS_EXPR, size, size_one_node);
    7145                 :         258 :           size = save_expr (size);
    7146                 :         258 :           tree index_type = build_index_type (size);
    7147                 :         258 :           tree atype = build_array_type (type, index_type);
    7148                 :         258 :           tree ptype = build_pointer_type (type);
    7149                 :         258 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    7150                 :         152 :             t = build_fold_addr_expr (t);
    7151                 :         258 :           t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
    7152                 :         258 :           OMP_CLAUSE_DECL (c) = t;
    7153                 :             :         }
    7154                 :             :     }
    7155                 :        8936 :   if (type == error_mark_node)
    7156                 :             :     return true;
    7157                 :        8933 :   else if (ARITHMETIC_TYPE_P (type))
    7158                 :        7681 :     switch (OMP_CLAUSE_REDUCTION_CODE (c))
    7159                 :             :       {
    7160                 :             :       case PLUS_EXPR:
    7161                 :             :       case MULT_EXPR:
    7162                 :             :       case MINUS_EXPR:
    7163                 :             :       case TRUTH_ANDIF_EXPR:
    7164                 :             :       case TRUTH_ORIF_EXPR:
    7165                 :             :         predefined = true;
    7166                 :             :         break;
    7167                 :         246 :       case MIN_EXPR:
    7168                 :         246 :       case MAX_EXPR:
    7169                 :         246 :         if (TREE_CODE (type) == COMPLEX_TYPE)
    7170                 :             :           break;
    7171                 :             :         predefined = true;
    7172                 :             :         break;
    7173                 :         111 :       case BIT_AND_EXPR:
    7174                 :         111 :       case BIT_IOR_EXPR:
    7175                 :         111 :       case BIT_XOR_EXPR:
    7176                 :         111 :         if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
    7177                 :             :           break;
    7178                 :             :         predefined = true;
    7179                 :             :         break;
    7180                 :             :       default:
    7181                 :             :         break;
    7182                 :             :       }
    7183                 :        1252 :   else if (TYPE_READONLY (type))
    7184                 :             :     {
    7185                 :          18 :       error_at (OMP_CLAUSE_LOCATION (c),
    7186                 :             :                 "%qE has const type for %<reduction%>",
    7187                 :             :                 omp_clause_printable_decl (t));
    7188                 :           9 :       return true;
    7189                 :             :     }
    7190                 :        1243 :   else if (!processing_template_decl)
    7191                 :             :     {
    7192                 :        1033 :       t = require_complete_type (t);
    7193                 :        1033 :       if (t == error_mark_node)
    7194                 :             :         return true;
    7195                 :        1033 :       OMP_CLAUSE_DECL (c) = t;
    7196                 :             :     }
    7197                 :             : 
    7198                 :        1033 :   if (predefined)
    7199                 :             :     {
    7200                 :        7459 :       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7201                 :        7459 :       return false;
    7202                 :             :     }
    7203                 :        1465 :   else if (processing_template_decl)
    7204                 :             :     {
    7205                 :         219 :       if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
    7206                 :             :         return true;
    7207                 :             :       return false;
    7208                 :             :     }
    7209                 :             : 
    7210                 :        1246 :   tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
    7211                 :             : 
    7212                 :        1246 :   type = TYPE_MAIN_VARIANT (type);
    7213                 :        1246 :   OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
    7214                 :        1246 :   if (id == NULL_TREE)
    7215                 :         924 :     id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
    7216                 :             :                            NULL_TREE, NULL_TREE);
    7217                 :        1246 :   id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
    7218                 :        1246 :   if (id)
    7219                 :             :     {
    7220                 :        1201 :       if (id == error_mark_node)
    7221                 :             :         return true;
    7222                 :        1195 :       mark_used (id);
    7223                 :        1195 :       tree body = DECL_SAVED_TREE (id);
    7224                 :        1195 :       if (!body)
    7225                 :             :         return true;
    7226                 :        1192 :       if (TREE_CODE (body) == STATEMENT_LIST)
    7227                 :             :         {
    7228                 :        1192 :           tree_stmt_iterator tsi;
    7229                 :        1192 :           tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
    7230                 :        1192 :           int i;
    7231                 :        1192 :           tree stmts[7];
    7232                 :        1192 :           tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
    7233                 :        1192 :           atype = TREE_TYPE (atype);
    7234                 :        1192 :           bool need_static_cast = !same_type_p (type, atype);
    7235                 :        1192 :           memset (stmts, 0, sizeof stmts);
    7236                 :        1192 :           for (i = 0, tsi = tsi_start (body);
    7237                 :        8490 :                i < 7 && !tsi_end_p (tsi);
    7238                 :        7298 :                i++, tsi_next (&tsi))
    7239                 :        7298 :             stmts[i] = tsi_stmt (tsi);
    7240                 :        1192 :           gcc_assert (tsi_end_p (tsi));
    7241                 :             : 
    7242                 :        1192 :           if (i >= 3)
    7243                 :             :             {
    7244                 :        1192 :               gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
    7245                 :             :                           && TREE_CODE (stmts[1]) == DECL_EXPR);
    7246                 :        1192 :               placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
    7247                 :        1192 :               DECL_ARTIFICIAL (placeholder) = 1;
    7248                 :        1192 :               DECL_IGNORED_P (placeholder) = 1;
    7249                 :        1192 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
    7250                 :        1192 :               if (TREE_CODE (t) == MEM_REF)
    7251                 :             :                 {
    7252                 :         600 :                   decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
    7253                 :             :                                                       type);
    7254                 :         600 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
    7255                 :         600 :                   DECL_IGNORED_P (decl_placeholder) = 1;
    7256                 :         600 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
    7257                 :             :                 }
    7258                 :        1192 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
    7259                 :         282 :                 cxx_mark_addressable (placeholder);
    7260                 :        1192 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
    7261                 :        1192 :                   && (decl_placeholder
    7262                 :         146 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7263                 :         366 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7264                 :         115 :                                       : OMP_CLAUSE_DECL (c));
    7265                 :        1192 :               tree omp_out = placeholder;
    7266                 :        1192 :               tree omp_in = decl_placeholder ? decl_placeholder
    7267                 :         592 :                             : convert_from_reference (OMP_CLAUSE_DECL (c));
    7268                 :        1192 :               if (need_static_cast)
    7269                 :             :                 {
    7270                 :           7 :                   tree rtype = build_reference_type (atype);
    7271                 :           7 :                   omp_out = build_static_cast (input_location,
    7272                 :             :                                                rtype, omp_out,
    7273                 :             :                                                tf_warning_or_error);
    7274                 :           7 :                   omp_in = build_static_cast (input_location,
    7275                 :             :                                               rtype, omp_in,
    7276                 :             :                                               tf_warning_or_error);
    7277                 :           7 :                   if (omp_out == error_mark_node || omp_in == error_mark_node)
    7278                 :           3 :                     return true;
    7279                 :           7 :                   omp_out = convert_from_reference (omp_out);
    7280                 :           7 :                   omp_in = convert_from_reference (omp_in);
    7281                 :             :                 }
    7282                 :        1192 :               OMP_CLAUSE_REDUCTION_MERGE (c)
    7283                 :        1192 :                 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
    7284                 :        1192 :                                  DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
    7285                 :             :             }
    7286                 :        1192 :           if (i >= 6)
    7287                 :             :             {
    7288                 :        1002 :               gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
    7289                 :             :                           && TREE_CODE (stmts[4]) == DECL_EXPR);
    7290                 :        1002 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
    7291                 :        1002 :                   && (decl_placeholder
    7292                 :         232 :                       || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
    7293                 :         844 :                 cxx_mark_addressable (decl_placeholder ? decl_placeholder
    7294                 :         170 :                                       : OMP_CLAUSE_DECL (c));
    7295                 :        1002 :               if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
    7296                 :         216 :                 cxx_mark_addressable (placeholder);
    7297                 :        1002 :               tree omp_priv = decl_placeholder ? decl_placeholder
    7298                 :         426 :                               : convert_from_reference (OMP_CLAUSE_DECL (c));
    7299                 :        1002 :               tree omp_orig = placeholder;
    7300                 :        1002 :               if (need_static_cast)
    7301                 :             :                 {
    7302                 :           5 :                   if (i == 7)
    7303                 :             :                     {
    7304                 :           3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    7305                 :             :                                 "user defined reduction with constructor "
    7306                 :             :                                 "initializer for base class %qT", atype);
    7307                 :           3 :                       return true;
    7308                 :             :                     }
    7309                 :           2 :                   tree rtype = build_reference_type (atype);
    7310                 :           2 :                   omp_priv = build_static_cast (input_location,
    7311                 :             :                                                 rtype, omp_priv,
    7312                 :             :                                                 tf_warning_or_error);
    7313                 :           2 :                   omp_orig = build_static_cast (input_location,
    7314                 :             :                                                 rtype, omp_orig,
    7315                 :             :                                                 tf_warning_or_error);
    7316                 :           2 :                   if (omp_priv == error_mark_node
    7317                 :           2 :                       || omp_orig == error_mark_node)
    7318                 :             :                     return true;
    7319                 :           2 :                   omp_priv = convert_from_reference (omp_priv);
    7320                 :           2 :                   omp_orig = convert_from_reference (omp_orig);
    7321                 :             :                 }
    7322                 :         999 :               if (i == 6)
    7323                 :         286 :                 *need_default_ctor = true;
    7324                 :         999 :               OMP_CLAUSE_REDUCTION_INIT (c)
    7325                 :         999 :                 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
    7326                 :         999 :                                  DECL_EXPR_DECL (stmts[3]),
    7327                 :             :                                  omp_priv, omp_orig);
    7328                 :         999 :               if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
    7329                 :             :                                 find_omp_placeholder_r, placeholder, NULL))
    7330                 :         238 :                 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
    7331                 :             :             }
    7332                 :         190 :           else if (i >= 3)
    7333                 :             :             {
    7334                 :         190 :               if (CLASS_TYPE_P (type) && !pod_type_p (type))
    7335                 :         175 :                 *need_default_ctor = true;
    7336                 :             :               else
    7337                 :             :                 {
    7338                 :          15 :                   tree init;
    7339                 :          15 :                   tree v = decl_placeholder ? decl_placeholder
    7340                 :          15 :                            : convert_from_reference (t);
    7341                 :          15 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
    7342                 :           6 :                     init = build_constructor (TREE_TYPE (v), NULL);
    7343                 :             :                   else
    7344                 :           9 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
    7345                 :          30 :                   OMP_CLAUSE_REDUCTION_INIT (c)
    7346                 :          30 :                     = cp_build_init_expr (v, init);
    7347                 :             :                 }
    7348                 :             :             }
    7349                 :             :         }
    7350                 :             :     }
    7351                 :        1234 :   if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
    7352                 :        1189 :     *need_dtor = true;
    7353                 :             :   else
    7354                 :             :     {
    7355                 :          90 :       error_at (OMP_CLAUSE_LOCATION (c),
    7356                 :             :                 "user defined reduction not found for %qE",
    7357                 :             :                 omp_clause_printable_decl (t));
    7358                 :          45 :       return true;
    7359                 :             :     }
    7360                 :        1189 :   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
    7361                 :         600 :     gcc_assert (TYPE_SIZE_UNIT (type)
    7362                 :             :                 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
    7363                 :             :   return false;
    7364                 :             : }
    7365                 :             : 
    7366                 :             : /* Check an instance of an "omp declare mapper" function.  */
    7367                 :             : 
    7368                 :             : bool
    7369                 :         179 : cp_check_omp_declare_mapper (tree udm)
    7370                 :             : {
    7371                 :         179 :   tree type = TREE_TYPE (udm);
    7372                 :         179 :   location_t loc = DECL_SOURCE_LOCATION (udm);
    7373                 :             : 
    7374                 :         179 :   if (type == error_mark_node)
    7375                 :             :     return false;
    7376                 :             : 
    7377                 :         179 :   if (!processing_template_decl && !RECORD_OR_UNION_TYPE_P (type))
    7378                 :             :     {
    7379                 :          15 :       error_at (loc, "%qT is not a struct, union or class type in "
    7380                 :             :                 "%<#pragma omp declare mapper%>", type);
    7381                 :          15 :       return false;
    7382                 :             :     }
    7383                 :         164 :   if (!processing_template_decl && CLASSTYPE_VBASECLASSES (type))
    7384                 :             :     {
    7385                 :           3 :       error_at (loc, "%qT must not be a virtual base class in "
    7386                 :             :                 "%<#pragma omp declare mapper%>", type);
    7387                 :           3 :       return false;
    7388                 :             :     }
    7389                 :             : 
    7390                 :             :   return true;
    7391                 :             : }
    7392                 :             : 
    7393                 :             : /* Called from finish_struct_1.  linear(this) or linear(this:step)
    7394                 :             :    clauses might not be finalized yet because the class has been incomplete
    7395                 :             :    when parsing #pragma omp declare simd methods.  Fix those up now.  */
    7396                 :             : 
    7397                 :             : void
    7398                 :       97524 : finish_omp_declare_simd_methods (tree t)
    7399                 :             : {
    7400                 :       97524 :   if (processing_template_decl)
    7401                 :             :     return;
    7402                 :             : 
    7403                 :      667681 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7404                 :             :     {
    7405                 :      932863 :       if (TREE_CODE (x) == USING_DECL
    7406                 :      570157 :           || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
    7407                 :      362706 :         continue;
    7408                 :      207451 :       tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
    7409                 :      207559 :       if (!ods || !TREE_VALUE (ods))
    7410                 :      207343 :         continue;
    7411                 :         366 :       for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
    7412                 :         258 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
    7413                 :          66 :             && integer_zerop (OMP_CLAUSE_DECL (c))
    7414                 :          18 :             && OMP_CLAUSE_LINEAR_STEP (c)
    7415                 :         276 :             && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
    7416                 :             :           {
    7417                 :          18 :             tree s = OMP_CLAUSE_LINEAR_STEP (c);
    7418                 :          18 :             s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
    7419                 :          18 :             s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
    7420                 :          18 :                                  sizetype, s, TYPE_SIZE_UNIT (t));
    7421                 :          18 :             OMP_CLAUSE_LINEAR_STEP (c) = s;
    7422                 :             :           }
    7423                 :             :     }
    7424                 :             : }
    7425                 :             : 
    7426                 :             : /* Adjust sink depend/doacross clause to take into account pointer offsets.
    7427                 :             : 
    7428                 :             :    Return TRUE if there was a problem processing the offset, and the
    7429                 :             :    whole clause should be removed.  */
    7430                 :             : 
    7431                 :             : static bool
    7432                 :         295 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
    7433                 :             : {
    7434                 :         295 :   tree t = OMP_CLAUSE_DECL (sink_clause);
    7435                 :         295 :   gcc_assert (TREE_CODE (t) == TREE_LIST);
    7436                 :             : 
    7437                 :             :   /* Make sure we don't adjust things twice for templates.  */
    7438                 :         295 :   if (processing_template_decl)
    7439                 :             :     return false;
    7440                 :             : 
    7441                 :         665 :   for (; t; t = TREE_CHAIN (t))
    7442                 :             :     {
    7443                 :         388 :       tree decl = TREE_VALUE (t);
    7444                 :         388 :       if (TYPE_PTR_P (TREE_TYPE (decl)))
    7445                 :             :         {
    7446                 :           6 :           tree offset = TREE_PURPOSE (t);
    7447                 :           6 :           bool neg = wi::neg_p (wi::to_wide (offset));
    7448                 :           6 :           offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
    7449                 :           6 :           decl = mark_rvalue_use (decl);
    7450                 :           6 :           decl = convert_from_reference (decl);
    7451                 :          12 :           tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
    7452                 :             :                                      neg ? MINUS_EXPR : PLUS_EXPR,
    7453                 :             :                                      decl, offset);
    7454                 :           6 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
    7455                 :             :                                 MINUS_EXPR, sizetype,
    7456                 :             :                                 fold_convert (sizetype, t2),
    7457                 :             :                                 fold_convert (sizetype, decl));
    7458                 :           6 :           if (t2 == error_mark_node)
    7459                 :             :             return true;
    7460                 :           6 :           TREE_PURPOSE (t) = t2;
    7461                 :             :         }
    7462                 :             :     }
    7463                 :             :   return false;
    7464                 :             : }
    7465                 :             : 
    7466                 :             : /* Finish OpenMP iterators ITER.  Return true if they are errorneous
    7467                 :             :    and clauses containing them should be removed.  */
    7468                 :             : 
    7469                 :             : static bool
    7470                 :         610 : cp_omp_finish_iterators (tree iter)
    7471                 :             : {
    7472                 :         610 :   bool ret = false;
    7473                 :        1385 :   for (tree it = iter; it; it = TREE_CHAIN (it))
    7474                 :             :     {
    7475                 :         775 :       tree var = TREE_VEC_ELT (it, 0);
    7476                 :         775 :       tree begin = TREE_VEC_ELT (it, 1);
    7477                 :         775 :       tree end = TREE_VEC_ELT (it, 2);
    7478                 :         775 :       tree step = TREE_VEC_ELT (it, 3);
    7479                 :         775 :       tree orig_step;
    7480                 :         775 :       tree type = TREE_TYPE (var);
    7481                 :         775 :       location_t loc = DECL_SOURCE_LOCATION (var);
    7482                 :         775 :       if (type == error_mark_node)
    7483                 :             :         {
    7484                 :           0 :           ret = true;
    7485                 :         218 :           continue;
    7486                 :             :         }
    7487                 :         775 :       if (type_dependent_expression_p (var))
    7488                 :          59 :         continue;
    7489                 :         716 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7490                 :             :         {
    7491                 :          27 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
    7492                 :             :                     var);
    7493                 :          27 :           ret = true;
    7494                 :          27 :           continue;
    7495                 :             :         }
    7496                 :         689 :       else if (TYPE_READONLY (type))
    7497                 :             :         {
    7498                 :          24 :           error_at (loc, "iterator %qD has const qualified type", var);
    7499                 :          24 :           ret = true;
    7500                 :          24 :           continue;
    7501                 :             :         }
    7502                 :         665 :       if (type_dependent_expression_p (begin)
    7503                 :         656 :           || type_dependent_expression_p (end)
    7504                 :        1321 :           || type_dependent_expression_p (step))
    7505                 :          15 :         continue;
    7506                 :         650 :       else if (error_operand_p (step))
    7507                 :             :         {
    7508                 :           0 :           ret = true;
    7509                 :           0 :           continue;
    7510                 :             :         }
    7511                 :         650 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
    7512                 :             :         {
    7513                 :          33 :           error_at (EXPR_LOC_OR_LOC (step, loc),
    7514                 :             :                     "iterator step with non-integral type");
    7515                 :          21 :           ret = true;
    7516                 :          21 :           continue;
    7517                 :             :         }
    7518                 :             : 
    7519                 :         629 :       begin = mark_rvalue_use (begin);
    7520                 :         629 :       end = mark_rvalue_use (end);
    7521                 :         629 :       step = mark_rvalue_use (step);
    7522                 :         629 :       begin = cp_build_c_cast (input_location, type, begin,
    7523                 :             :                                tf_warning_or_error);
    7524                 :         629 :       end = cp_build_c_cast (input_location, type, end,
    7525                 :             :                              tf_warning_or_error);
    7526                 :         629 :       orig_step = step;
    7527                 :         629 :       if (!processing_template_decl)
    7528                 :         552 :         step = orig_step = save_expr (step);
    7529                 :         629 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
    7530                 :         629 :       step = cp_build_c_cast (input_location, stype, step,
    7531                 :             :                               tf_warning_or_error);
    7532                 :         629 :       if (POINTER_TYPE_P (type) && !processing_template_decl)
    7533                 :             :         {
    7534                 :          66 :           begin = save_expr (begin);
    7535                 :          66 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
    7536                 :          66 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
    7537                 :             :                                   fold_convert (sizetype, step),
    7538                 :             :                                   fold_convert (sizetype, begin));
    7539                 :          66 :           step = fold_convert (ssizetype, step);
    7540                 :             :         }
    7541                 :         629 :       if (!processing_template_decl)
    7542                 :             :         {
    7543                 :         552 :           begin = maybe_constant_value (begin);
    7544                 :         552 :           end = maybe_constant_value (end);
    7545                 :         552 :           step = maybe_constant_value (step);
    7546                 :         552 :           orig_step = maybe_constant_value (orig_step);
    7547                 :             :         }
    7548                 :         629 :       if (integer_zerop (step))
    7549                 :             :         {
    7550                 :          27 :           error_at (loc, "iterator %qD has zero step", var);
    7551                 :          27 :           ret = true;
    7552                 :          27 :           continue;
    7553                 :             :         }
    7554                 :             : 
    7555                 :         602 :       if (begin == error_mark_node
    7556                 :         593 :           || end == error_mark_node
    7557                 :         584 :           || step == error_mark_node
    7558                 :         584 :           || orig_step == error_mark_node)
    7559                 :             :         {
    7560                 :          18 :           ret = true;
    7561                 :          18 :           continue;
    7562                 :             :         }
    7563                 :             : 
    7564                 :         584 :       if (!processing_template_decl)
    7565                 :             :         {
    7566                 :         507 :           begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
    7567                 :         507 :           end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
    7568                 :         507 :           step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
    7569                 :         507 :           orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
    7570                 :             :                                                      orig_step);
    7571                 :             :         }
    7572                 :         584 :       hash_set<tree> pset;
    7573                 :         584 :       tree it2;
    7574                 :         740 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
    7575                 :             :         {
    7576                 :         183 :           tree var2 = TREE_VEC_ELT (it2, 0);
    7577                 :         183 :           tree begin2 = TREE_VEC_ELT (it2, 1);
    7578                 :         183 :           tree end2 = TREE_VEC_ELT (it2, 2);
    7579                 :         183 :           tree step2 = TREE_VEC_ELT (it2, 3);
    7580                 :         183 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
    7581                 :         183 :           if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
    7582                 :             :             {
    7583                 :           9 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
    7584                 :             :                         "begin expression refers to outer iterator %qD", var);
    7585                 :          36 :               break;
    7586                 :             :             }
    7587                 :         174 :           else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
    7588                 :             :             {
    7589                 :           9 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
    7590                 :             :                         "end expression refers to outer iterator %qD", var);
    7591                 :           9 :               break;
    7592                 :             :             }
    7593                 :         165 :           else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
    7594                 :             :             {
    7595                 :           9 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
    7596                 :             :                         "step expression refers to outer iterator %qD", var);
    7597                 :           9 :               break;
    7598                 :             :             }
    7599                 :             :         }
    7600                 :         584 :       if (it2)
    7601                 :             :         {
    7602                 :          27 :           ret = true;
    7603                 :          27 :           continue;
    7604                 :             :         }
    7605                 :         557 :       TREE_VEC_ELT (it, 1) = begin;
    7606                 :         557 :       TREE_VEC_ELT (it, 2) = end;
    7607                 :         557 :       if (processing_template_decl)
    7608                 :          71 :         TREE_VEC_ELT (it, 3) = orig_step;
    7609                 :             :       else
    7610                 :             :         {
    7611                 :         486 :           TREE_VEC_ELT (it, 3) = step;
    7612                 :         486 :           TREE_VEC_ELT (it, 4) = orig_step;
    7613                 :             :         }
    7614                 :         584 :     }
    7615                 :         610 :   return ret;
    7616                 :             : }
    7617                 :             : 
    7618                 :             : /* Ensure that pointers are used in OpenACC attach and detach clauses.
    7619                 :             :    Return true if an error has been detected.  */
    7620                 :             : 
    7621                 :             : static bool
    7622                 :       18306 : cp_oacc_check_attachments (tree c)
    7623                 :             : {
    7624                 :       18306 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    7625                 :             :     return false;
    7626                 :             : 
    7627                 :             :   /* OpenACC attach / detach clauses must be pointers.  */
    7628                 :       14370 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    7629                 :       14370 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    7630                 :             :     {
    7631                 :         196 :       tree t = OMP_CLAUSE_DECL (c);
    7632                 :         196 :       tree type;
    7633                 :             : 
    7634                 :         232 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7635                 :          36 :         t = TREE_OPERAND (t, 0);
    7636                 :             : 
    7637                 :         196 :       type = TREE_TYPE (t);
    7638                 :             : 
    7639                 :         196 :       if (TREE_CODE (type) == REFERENCE_TYPE)
    7640                 :          36 :         type = TREE_TYPE (type);
    7641                 :             : 
    7642                 :         196 :       if (TREE_CODE (type) != POINTER_TYPE)
    7643                 :             :         {
    7644                 :          36 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
    7645                 :             :                     user_omp_clause_code_name (c, true));
    7646                 :          36 :           return true;
    7647                 :             :         }
    7648                 :             :     }
    7649                 :             : 
    7650                 :             :   return false;
    7651                 :             : }
    7652                 :             : 
    7653                 :             : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
    7654                 :             :    happened.  */
    7655                 :             : 
    7656                 :             : tree
    7657                 :         813 : cp_finish_omp_init_prefer_type (tree pref_type)
    7658                 :             : {
    7659                 :         813 :   if (processing_template_decl
    7660                 :         741 :       || pref_type == NULL_TREE
    7661                 :         356 :       || TREE_CODE (pref_type) != TREE_LIST)
    7662                 :             :     return pref_type;
    7663                 :             : 
    7664                 :          81 :   tree t = TREE_PURPOSE (pref_type);
    7665                 :          81 :   char *str = const_cast<char *> (TREE_STRING_POINTER (t));
    7666                 :          81 :   tree fr_list = TREE_VALUE (pref_type);
    7667                 :          81 :   int len = TREE_VEC_LENGTH (fr_list);
    7668                 :          81 :   int cnt = 0;
    7669                 :             : 
    7670                 :         270 :   while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
    7671                 :             :     {
    7672                 :         270 :       str++;
    7673                 :         270 :       if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
    7674                 :             :         {
    7675                 :             :           /* Assume a no or a single 'fr'.  */
    7676                 :         150 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7677                 :         150 :           location_t loc = UNKNOWN_LOCATION;
    7678                 :         150 :           tree value = TREE_VEC_ELT (fr_list, cnt);
    7679                 :         150 :           if (value != NULL_TREE && value != error_mark_node)
    7680                 :             :             {
    7681                 :         126 :               loc = EXPR_LOCATION (value);
    7682                 :         126 :               if (value && TREE_CODE (value) == NOP_EXPR)
    7683                 :          39 :                 value = TREE_OPERAND (value, 0);
    7684                 :         126 :               value = cp_fully_fold (value);
    7685                 :             :             }
    7686                 :         126 :           if (value != NULL_TREE && value != error_mark_node)
    7687                 :             :             {
    7688                 :         126 :               if (TREE_CODE (value) != INTEGER_CST
    7689                 :         126 :                   || !tree_fits_shwi_p (value))
    7690                 :           0 :                 error_at (loc,
    7691                 :             :                           "expected string literal or "
    7692                 :             :                           "constant integer expression instead of %qE", value);
    7693                 :             :               else
    7694                 :             :                 {
    7695                 :         126 :                   HOST_WIDE_INT n = tree_to_shwi (value);
    7696                 :         126 :                   if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
    7697                 :             :                     {
    7698                 :          48 :                       warning_at (loc, OPT_Wopenmp,
    7699                 :             :                                   "unknown foreign runtime identifier %qwd", n);
    7700                 :          48 :                       n = GOMP_INTEROP_IFR_UNKNOWN;
    7701                 :             :                     }
    7702                 :         126 :                   str[0] = (char) n;
    7703                 :             :                 }
    7704                 :             :             }
    7705                 :         150 :           str++;
    7706                 :             :         }
    7707                 :         120 :       else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
    7708                 :             :         {
    7709                 :             :           /* Assume a no or a single 'fr'.  */
    7710                 :         120 :           gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
    7711                 :         120 :           str++;
    7712                 :             :         }
    7713                 :         270 :       str++;
    7714                 :         294 :       while (str[0] != '\0')
    7715                 :          24 :         str += strlen (str) + 1;
    7716                 :         270 :       str++;
    7717                 :         270 :       cnt++;
    7718                 :         270 :       if (cnt >= len)
    7719                 :             :         break;
    7720                 :             :     }
    7721                 :             :   return t;
    7722                 :             : }
    7723                 :             : 
    7724                 :             : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    7725                 :             :    Remove any elements from the list that are invalid.  */
    7726                 :             : 
    7727                 :             : tree
    7728                 :       62565 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
    7729                 :             : {
    7730                 :       62565 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
    7731                 :       62565 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
    7732                 :       62565 :   bitmap_head oacc_reduction_head, is_on_device_head;
    7733                 :       62565 :   tree c, t, *pc;
    7734                 :       62565 :   tree safelen = NULL_TREE;
    7735                 :       62565 :   bool openacc = (ort & C_ORT_ACC) != 0;
    7736                 :       62565 :   bool branch_seen = false;
    7737                 :       62565 :   bool copyprivate_seen = false;
    7738                 :       62565 :   bool ordered_seen = false;
    7739                 :       62565 :   bool order_seen = false;
    7740                 :       62565 :   bool schedule_seen = false;
    7741                 :       62565 :   bool oacc_async = false;
    7742                 :       62565 :   bool indir_component_ref_p = false;
    7743                 :       62565 :   tree last_iterators = NULL_TREE;
    7744                 :       62565 :   bool last_iterators_remove = false;
    7745                 :             :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
    7746                 :             :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
    7747                 :       62565 :   int reduction_seen = 0;
    7748                 :       62565 :   bool allocate_seen = false;
    7749                 :       62565 :   tree detach_seen = NULL_TREE;
    7750                 :       62565 :   bool mergeable_seen = false;
    7751                 :       62565 :   bool implicit_moved = false;
    7752                 :       62565 :   bool target_in_reduction_seen = false;
    7753                 :       62565 :   bool num_tasks_seen = false;
    7754                 :       62565 :   bool partial_seen = false;
    7755                 :       62565 :   bool init_seen = false;
    7756                 :       62565 :   bool init_use_destroy_seen = false;
    7757                 :       62565 :   tree init_no_targetsync_clause = NULL_TREE;
    7758                 :       62565 :   tree depend_clause = NULL_TREE;
    7759                 :             : 
    7760                 :       62565 :   bitmap_obstack_initialize (NULL);
    7761                 :       62565 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
    7762                 :       62565 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
    7763                 :       62565 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
    7764                 :       62565 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
    7765                 :             :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
    7766                 :       62565 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
    7767                 :       62565 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
    7768                 :       62565 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
    7769                 :             :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
    7770                 :             :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
    7771                 :       62565 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
    7772                 :       62565 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
    7773                 :             : 
    7774                 :       62565 :   if (openacc)
    7775                 :       28415 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
    7776                 :       15990 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
    7777                 :             :         {
    7778                 :             :           oacc_async = true;
    7779                 :             :           break;
    7780                 :             :         }
    7781                 :             : 
    7782                 :       62565 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
    7783                 :             : 
    7784                 :      160255 :   for (pc = &clauses, c = clauses; c ; c = *pc)
    7785                 :             :     {
    7786                 :       97690 :       bool remove = false;
    7787                 :       97690 :       bool field_ok = false;
    7788                 :             : 
    7789                 :             :       /* We've reached the end of a list of expanded nodes.  Reset the group
    7790                 :             :          start pointer.  */
    7791                 :       97690 :       if (c == grp_sentinel)
    7792                 :             :         {
    7793                 :        5485 :           if (grp_start_p
    7794                 :        5485 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
    7795                 :          96 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
    7796                 :          66 :                  gc = OMP_CLAUSE_CHAIN (gc))
    7797                 :          66 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
    7798                 :             :           grp_start_p = NULL;
    7799                 :             :         }
    7800                 :             : 
    7801                 :       97690 :       switch (OMP_CLAUSE_CODE (c))
    7802                 :             :         {
    7803                 :        2094 :         case OMP_CLAUSE_SHARED:
    7804                 :        2094 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7805                 :        2094 :           goto check_dup_generic;
    7806                 :        2535 :         case OMP_CLAUSE_PRIVATE:
    7807                 :        2535 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7808                 :        2535 :           goto check_dup_generic;
    7809                 :        7481 :         case OMP_CLAUSE_REDUCTION:
    7810                 :        7481 :           if (reduction_seen == 0)
    7811                 :        6377 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
    7812                 :        1104 :           else if (reduction_seen != -2
    7813                 :        2208 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
    7814                 :        1104 :                                          ? -1 : 1))
    7815                 :             :             {
    7816                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7817                 :             :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
    7818                 :             :                         "on the same construct");
    7819                 :           6 :               reduction_seen = -2;
    7820                 :             :             }
    7821                 :             :           /* FALLTHRU */
    7822                 :        9623 :         case OMP_CLAUSE_IN_REDUCTION:
    7823                 :        9623 :         case OMP_CLAUSE_TASK_REDUCTION:
    7824                 :        9623 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7825                 :        9623 :           t = OMP_CLAUSE_DECL (c);
    7826                 :        9623 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7827                 :             :             {
    7828                 :        2315 :               if (handle_omp_array_sections (c, ort))
    7829                 :             :                 {
    7830                 :             :                   remove = true;
    7831                 :             :                   break;
    7832                 :             :                 }
    7833                 :        2273 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
    7834                 :        2273 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
    7835                 :             :                 {
    7836                 :           3 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7837                 :             :                             "%<inscan%> %<reduction%> clause with array "
    7838                 :             :                             "section");
    7839                 :           3 :                   remove = true;
    7840                 :           3 :                   break;
    7841                 :             :                 }
    7842                 :        2270 :               if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7843                 :             :                 {
    7844                 :        4888 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    7845                 :        2618 :                     t = TREE_OPERAND (t, 0);
    7846                 :             :                 }
    7847                 :             :               else
    7848                 :             :                 {
    7849                 :           0 :                   gcc_assert (TREE_CODE (t) == MEM_REF);
    7850                 :           0 :                   t = TREE_OPERAND (t, 0);
    7851                 :           0 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
    7852                 :           0 :                     t = TREE_OPERAND (t, 0);
    7853                 :           0 :                   if (TREE_CODE (t) == ADDR_EXPR
    7854                 :           0 :                       || INDIRECT_REF_P (t))
    7855                 :           0 :                     t = TREE_OPERAND (t, 0);
    7856                 :             :                 }
    7857                 :        2270 :               tree n = omp_clause_decl_field (t);
    7858                 :        2270 :               if (n)
    7859                 :          59 :                 t = n;
    7860                 :        2270 :               goto check_dup_generic_t;
    7861                 :             :             }
    7862                 :        7308 :           if (oacc_async)
    7863                 :           7 :             cxx_mark_addressable (t);
    7864                 :        7308 :           goto check_dup_generic;
    7865                 :          98 :         case OMP_CLAUSE_COPYPRIVATE:
    7866                 :          98 :           copyprivate_seen = true;
    7867                 :          98 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7868                 :          98 :           goto check_dup_generic;
    7869                 :         277 :         case OMP_CLAUSE_COPYIN:
    7870                 :         277 :           goto check_dup_generic;
    7871                 :        1613 :         case OMP_CLAUSE_LINEAR:
    7872                 :        1613 :           field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
    7873                 :        1613 :           t = OMP_CLAUSE_DECL (c);
    7874                 :        1613 :           if (ort != C_ORT_OMP_DECLARE_SIMD
    7875                 :        1613 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
    7876                 :             :             {
    7877                 :          84 :               if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
    7878                 :             :                 {
    7879                 :          42 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7880                 :             :                             "modifier should not be specified in %<linear%> "
    7881                 :             :                             "clause on %<simd%> or %<for%> constructs when "
    7882                 :             :                             "not using OpenMP 5.2 modifiers");
    7883                 :          42 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    7884                 :             :                 }
    7885                 :          42 :               else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
    7886                 :             :                 {
    7887                 :          18 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7888                 :             :                             "modifier other than %<val%> specified in "
    7889                 :             :                             "%<linear%> clause on %<simd%> or %<for%> "
    7890                 :             :                             "constructs when using OpenMP 5.2 modifiers");
    7891                 :          18 :                   OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
    7892                 :             :                 }
    7893                 :             :             }
    7894                 :         993 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    7895                 :        2535 :               && !type_dependent_expression_p (t))
    7896                 :             :             {
    7897                 :        1511 :               tree type = TREE_TYPE (t);
    7898                 :        1511 :               if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    7899                 :        1436 :                    || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
    7900                 :        1574 :                   && !TYPE_REF_P (type))
    7901                 :             :                 {
    7902                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    7903                 :             :                             "linear clause with %qs modifier applied to "
    7904                 :             :                             "non-reference variable with %qT type",
    7905                 :          12 :                             OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
    7906                 :          12 :                             ? "ref" : "uval", TREE_TYPE (t));
    7907                 :          12 :                   remove = true;
    7908                 :          12 :                   break;
    7909                 :             :                 }
    7910                 :        1499 :               if (TYPE_REF_P (type))
    7911                 :         269 :                 type = TREE_TYPE (type);
    7912                 :        1499 :               if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
    7913                 :             :                 {
    7914                 :        1430 :                   if (!INTEGRAL_TYPE_P (type)
    7915                 :          85 :                       && !TYPE_PTR_P (type))
    7916                 :             :                     {
    7917                 :          18 :                       error_at (OMP_CLAUSE_LOCATION (c),
    7918                 :             :                                 "linear clause applied to non-integral "
    7919                 :             :                                 "non-pointer variable with %qT type",
    7920                 :          18 :                                 TREE_TYPE (t));
    7921                 :          18 :                       remove = true;
    7922                 :          18 :                       break;
    7923                 :             :                     }
    7924                 :             :                 }
    7925                 :             :             }
    7926                 :        1583 :           t = OMP_CLAUSE_LINEAR_STEP (c);
    7927                 :        1583 :           if (t == NULL_TREE)
    7928                 :           6 :             t = integer_one_node;
    7929                 :        1583 :           if (t == error_mark_node)
    7930                 :             :             {
    7931                 :             :               remove = true;
    7932                 :             :               break;
    7933                 :             :             }
    7934                 :        1583 :           else if (!type_dependent_expression_p (t)
    7935                 :        1581 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t))
    7936                 :        1595 :                    && (ort != C_ORT_OMP_DECLARE_SIMD
    7937                 :           9 :                        || TREE_CODE (t) != PARM_DECL
    7938                 :           6 :                        || !TYPE_REF_P (TREE_TYPE (t))
    7939                 :           6 :                        || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
    7940                 :             :             {
    7941                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    7942                 :             :                         "linear step expression must be integral");
    7943                 :           6 :               remove = true;
    7944                 :           6 :               break;
    7945                 :             :             }
    7946                 :             :           else
    7947                 :             :             {
    7948                 :        1577 :               t = mark_rvalue_use (t);
    7949                 :        1577 :               if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
    7950                 :             :                 {
    7951                 :          42 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
    7952                 :          42 :                   goto check_dup_generic;
    7953                 :             :                 }
    7954                 :        1535 :               if (!processing_template_decl
    7955                 :        1535 :                   && (VAR_P (OMP_CLAUSE_DECL (c))
    7956                 :         817 :                       || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
    7957                 :             :                 {
    7958                 :        1354 :                   if (ort == C_ORT_OMP_DECLARE_SIMD)
    7959                 :             :                     {
    7960                 :         571 :                       t = maybe_constant_value (t);
    7961                 :         571 :                       if (TREE_CODE (t) != INTEGER_CST)
    7962                 :             :                         {
    7963                 :           6 :                           error_at (OMP_CLAUSE_LOCATION (c),
    7964                 :             :                                     "%<linear%> clause step %qE is neither "
    7965                 :             :                                      "constant nor a parameter", t);
    7966                 :           6 :                           remove = true;
    7967                 :           6 :                           break;
    7968                 :             :                         }
    7969                 :             :                     }
    7970                 :        1348 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    7971                 :        1348 :                   tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
    7972                 :        1348 :                   if (TYPE_REF_P (type))
    7973                 :         245 :                     type = TREE_TYPE (type);
    7974                 :        1348 :                   if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
    7975                 :             :                     {
    7976                 :          60 :                       type = build_pointer_type (type);
    7977                 :          60 :                       tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
    7978                 :          60 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    7979                 :             :                                            d, t);
    7980                 :          60 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    7981                 :             :                                            MINUS_EXPR, sizetype,
    7982                 :             :                                            fold_convert (sizetype, t),
    7983                 :             :                                            fold_convert (sizetype, d));
    7984                 :          60 :                       if (t == error_mark_node)
    7985                 :             :                         {
    7986                 :             :                           remove = true;
    7987                 :             :                           break;
    7988                 :             :                         }
    7989                 :             :                     }
    7990                 :        1288 :                   else if (TYPE_PTR_P (type)
    7991                 :             :                            /* Can't multiply the step yet if *this
    7992                 :             :                               is still incomplete type.  */
    7993                 :        1288 :                            && (ort != C_ORT_OMP_DECLARE_SIMD
    7994                 :          45 :                                || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
    7995                 :          45 :                                || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
    7996                 :          30 :                                || DECL_NAME (OMP_CLAUSE_DECL (c))
    7997                 :          30 :                                   != this_identifier
    7998                 :          30 :                                || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
    7999                 :             :                     {
    8000                 :          37 :                       tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
    8001                 :          37 :                       t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
    8002                 :             :                                            d, t);
    8003                 :          37 :                       t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
    8004                 :             :                                            MINUS_EXPR, sizetype,
    8005                 :             :                                            fold_convert (sizetype, t),
    8006                 :             :                                            fold_convert (sizetype, d));
    8007                 :          37 :                       if (t == error_mark_node)
    8008                 :             :                         {
    8009                 :             :                           remove = true;
    8010                 :             :                           break;
    8011                 :             :                         }
    8012                 :             :                     }
    8013                 :             :                   else
    8014                 :        1251 :                     t = fold_convert (type, t);
    8015                 :             :                 }
    8016                 :        1529 :               OMP_CLAUSE_LINEAR_STEP (c) = t;
    8017                 :             :             }
    8018                 :        1529 :           goto check_dup_generic;
    8019                 :       14848 :         check_dup_generic:
    8020                 :       14848 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8021                 :       14848 :           if (t)
    8022                 :             :             {
    8023                 :         101 :               if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
    8024                 :         101 :                 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8025                 :             :             }
    8026                 :             :           else
    8027                 :       14747 :             t = OMP_CLAUSE_DECL (c);
    8028                 :       17384 :         check_dup_generic_t:
    8029                 :       17384 :           if (t == current_class_ptr
    8030                 :       17384 :               && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
    8031                 :         102 :                   || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
    8032                 :          72 :                       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
    8033                 :             :             {
    8034                 :          24 :               error_at (OMP_CLAUSE_LOCATION (c),
    8035                 :             :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8036                 :             :                         " clauses");
    8037                 :          24 :               remove = true;
    8038                 :          24 :               break;
    8039                 :             :             }
    8040                 :       17360 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8041                 :         586 :               && (!field_ok || TREE_CODE (t) != FIELD_DECL))
    8042                 :             :             {
    8043                 :          59 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8044                 :             :                 break;
    8045                 :          39 :               if (DECL_P (t))
    8046                 :          30 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8047                 :             :                           "%qD is not a variable in clause %qs", t,
    8048                 :          15 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8049                 :             :               else
    8050                 :          48 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8051                 :             :                           "%qE is not a variable in clause %qs", t,
    8052                 :          24 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8053                 :             :               remove = true;
    8054                 :             :             }
    8055                 :       17301 :           else if ((openacc
    8056                 :        2707 :                     && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
    8057                 :       14832 :                    || (ort == C_ORT_OMP
    8058                 :       12553 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    8059                 :       12522 :                            || (OMP_CLAUSE_CODE (c)
    8060                 :             :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
    8061                 :       32026 :                    || (ort == C_ORT_OMP_TARGET
    8062                 :         902 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
    8063                 :             :             {
    8064                 :        2854 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
    8065                 :        2854 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
    8066                 :         275 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
    8067                 :             :                 {
    8068                 :           6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8069                 :             :                             "%qD appears more than once in data-sharing "
    8070                 :             :                             "clauses", t);
    8071                 :           6 :                   remove = true;
    8072                 :           6 :                   break;
    8073                 :             :                 }
    8074                 :        2848 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
    8075                 :         272 :                 target_in_reduction_seen = true;
    8076                 :        2848 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8077                 :             :                 {
    8078                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8079                 :             :                             openacc
    8080                 :             :                             ? "%qD appears more than once in reduction clauses"
    8081                 :             :                             : "%qD appears more than once in data clauses",
    8082                 :             :                             t);
    8083                 :           6 :                   remove = true;
    8084                 :             :                 }
    8085                 :             :               else
    8086                 :        2842 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8087                 :             :             }
    8088                 :       14447 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8089                 :       14375 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8090                 :       14372 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
    8091                 :       28819 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8092                 :             :             {
    8093                 :          75 :               error_at (OMP_CLAUSE_LOCATION (c),
    8094                 :             :                         "%qD appears more than once in data clauses", t);
    8095                 :          75 :               remove = true;
    8096                 :             :             }
    8097                 :       14372 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    8098                 :             :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
    8099                 :             :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    8100                 :        3075 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
    8101                 :             :             {
    8102                 :           9 :               if (openacc)
    8103                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8104                 :             :                           "%qD appears more than once in data clauses", t);
    8105                 :             :               else
    8106                 :           9 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8107                 :             :                           "%qD appears both in data and map clauses", t);
    8108                 :             :               remove = true;
    8109                 :             :             }
    8110                 :             :           else
    8111                 :       14363 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    8112                 :       17334 :           if (!field_ok)
    8113                 :             :             break;
    8114                 :       12945 :         handle_field_decl:
    8115                 :       21578 :           if (!remove
    8116                 :       21384 :               && TREE_CODE (t) == FIELD_DECL
    8117                 :       16741 :               && t == OMP_CLAUSE_DECL (c))
    8118                 :             :             {
    8119                 :         795 :               OMP_CLAUSE_DECL (c)
    8120                 :         795 :                 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
    8121                 :             :                                            == OMP_CLAUSE_SHARED));
    8122                 :         795 :               if (OMP_CLAUSE_DECL (c) == error_mark_node)
    8123                 :       97238 :                 remove = true;
    8124                 :             :             }
    8125                 :             :           break;
    8126                 :             : 
    8127                 :        3441 :         case OMP_CLAUSE_FIRSTPRIVATE:
    8128                 :        3441 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
    8129                 :             :             {
    8130                 :         452 :             move_implicit:
    8131                 :         452 :               implicit_moved = true;
    8132                 :             :               /* Move firstprivate and map clauses with
    8133                 :             :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
    8134                 :             :                  clauses chain.  */
    8135                 :         452 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
    8136                 :         452 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
    8137                 :        2814 :               while (*pc1)
    8138                 :        2362 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
    8139                 :        2362 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
    8140                 :             :                   {
    8141                 :         275 :                     *pc3 = *pc1;
    8142                 :         275 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
    8143                 :         275 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8144                 :             :                   }
    8145                 :        2087 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
    8146                 :        2087 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
    8147                 :             :                   {
    8148                 :         408 :                     *pc2 = *pc1;
    8149                 :         408 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
    8150                 :         408 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
    8151                 :             :                   }
    8152                 :             :                 else
    8153                 :        1679 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
    8154                 :         452 :               *pc3 = NULL;
    8155                 :         452 :               *pc2 = cl2;
    8156                 :         452 :               *pc1 = cl1;
    8157                 :         452 :               continue;
    8158                 :         452 :             }
    8159                 :        3184 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8160                 :        3184 :           if (t)
    8161                 :          69 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8162                 :             :           else
    8163                 :        3115 :             t = OMP_CLAUSE_DECL (c);
    8164                 :        3184 :           if (!openacc && t == current_class_ptr)
    8165                 :             :             {
    8166                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8167                 :             :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8168                 :             :                         " clauses");
    8169                 :           6 :               remove = true;
    8170                 :           6 :               break;
    8171                 :             :             }
    8172                 :        3178 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8173                 :         333 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8174                 :         333 :                   || TREE_CODE (t) != FIELD_DECL))
    8175                 :             :             {
    8176                 :          41 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8177                 :             :                 break;
    8178                 :          18 :               if (DECL_P (t))
    8179                 :          12 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8180                 :             :                           "%qD is not a variable in clause %<firstprivate%>",
    8181                 :             :                           t);
    8182                 :             :               else
    8183                 :           6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8184                 :             :                           "%qE is not a variable in clause %<firstprivate%>",
    8185                 :             :                           t);
    8186                 :          18 :               remove = true;
    8187                 :             :             }
    8188                 :        3137 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8189                 :         275 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
    8190                 :        3391 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8191                 :             :             remove = true;
    8192                 :        3137 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8193                 :        3128 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    8194                 :        6262 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    8195                 :             :             {
    8196                 :          15 :               error_at (OMP_CLAUSE_LOCATION (c),
    8197                 :             :                         "%qD appears more than once in data clauses", t);
    8198                 :          15 :               remove = true;
    8199                 :             :             }
    8200                 :        3122 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
    8201                 :        3122 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
    8202                 :             :             {
    8203                 :          21 :               if (openacc)
    8204                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8205                 :             :                           "%qD appears more than once in data clauses", t);
    8206                 :          21 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
    8207                 :          21 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
    8208                 :             :                 /* Silently drop the clause.  */;
    8209                 :             :               else
    8210                 :          18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8211                 :             :                           "%qD appears both in data and map clauses", t);
    8212                 :          21 :               remove = true;
    8213                 :             :             }
    8214                 :             :           else
    8215                 :        3101 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
    8216                 :        3155 :           goto handle_field_decl;
    8217                 :             : 
    8218                 :        2787 :         case OMP_CLAUSE_LASTPRIVATE:
    8219                 :        2787 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8220                 :        2787 :           if (t)
    8221                 :          35 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8222                 :             :           else
    8223                 :        2752 :             t = OMP_CLAUSE_DECL (c);
    8224                 :        2787 :           if (!openacc && t == current_class_ptr)
    8225                 :             :             {
    8226                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8227                 :             :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8228                 :             :                         " clauses");
    8229                 :           6 :               remove = true;
    8230                 :           6 :               break;
    8231                 :             :             }
    8232                 :        2781 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
    8233                 :         259 :               && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
    8234                 :         259 :                   || TREE_CODE (t) != FIELD_DECL))
    8235                 :             :             {
    8236                 :          35 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8237                 :             :                 break;
    8238                 :           9 :               if (DECL_P (t))
    8239                 :           3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8240                 :             :                           "%qD is not a variable in clause %<lastprivate%>",
    8241                 :             :                           t);
    8242                 :             :               else
    8243                 :           6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8244                 :             :                           "%qE is not a variable in clause %<lastprivate%>",
    8245                 :             :                           t);
    8246                 :           9 :               remove = true;
    8247                 :             :             }
    8248                 :        2746 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
    8249                 :        2746 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
    8250                 :             :             {
    8251                 :          12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8252                 :             :                         "%qD appears more than once in data clauses", t);
    8253                 :          12 :               remove = true;
    8254                 :             :             }
    8255                 :             :           else
    8256                 :        2734 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
    8257                 :        2755 :           goto handle_field_decl;
    8258                 :             : 
    8259                 :        2212 :         case OMP_CLAUSE_IF:
    8260                 :        2212 :         case OMP_CLAUSE_SELF:
    8261                 :        2212 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8262                 :        2212 :           t = maybe_convert_cond (t);
    8263                 :        2212 :           if (t == error_mark_node)
    8264                 :             :             remove = true;
    8265                 :        2197 :           else if (!processing_template_decl)
    8266                 :        2136 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8267                 :        2212 :           OMP_CLAUSE_OPERAND (c, 0) = t;
    8268                 :        2212 :           break;
    8269                 :             : 
    8270                 :         286 :         case OMP_CLAUSE_FINAL:
    8271                 :         286 :           t = OMP_CLAUSE_FINAL_EXPR (c);
    8272                 :         286 :           t = maybe_convert_cond (t);
    8273                 :         286 :           if (t == error_mark_node)
    8274                 :             :             remove = true;
    8275                 :         286 :           else if (!processing_template_decl)
    8276                 :         280 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8277                 :         286 :           OMP_CLAUSE_FINAL_EXPR (c) = t;
    8278                 :         286 :           break;
    8279                 :             : 
    8280                 :          92 :         case OMP_CLAUSE_NOCONTEXT:
    8281                 :          92 :           t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
    8282                 :          92 :           t = maybe_convert_cond (t);
    8283                 :          92 :           if (t == error_mark_node)
    8284                 :             :             remove = true;
    8285                 :          89 :           else if (!processing_template_decl)
    8286                 :          83 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8287                 :          92 :           OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
    8288                 :          92 :           break;
    8289                 :             : 
    8290                 :          77 :         case OMP_CLAUSE_NOVARIANTS:
    8291                 :          77 :           t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
    8292                 :          77 :           t = maybe_convert_cond (t);
    8293                 :          77 :           if (t == error_mark_node)
    8294                 :             :             remove = true;
    8295                 :          74 :           else if (!processing_template_decl)
    8296                 :          68 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8297                 :          77 :           OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
    8298                 :          77 :           break;
    8299                 :             : 
    8300                 :        1249 :         case OMP_CLAUSE_GANG:
    8301                 :             :           /* Operand 1 is the gang static: argument.  */
    8302                 :        1249 :           t = OMP_CLAUSE_OPERAND (c, 1);
    8303                 :        1249 :           if (t != NULL_TREE)
    8304                 :             :             {
    8305                 :         129 :               if (t == error_mark_node)
    8306                 :             :                 remove = true;
    8307                 :         129 :               else if (!type_dependent_expression_p (t)
    8308                 :         129 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8309                 :             :                 {
    8310                 :           6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8311                 :             :                             "%<gang%> static expression must be integral");
    8312                 :           6 :                   remove = true;
    8313                 :             :                 }
    8314                 :             :               else
    8315                 :             :                 {
    8316                 :         123 :                   t = mark_rvalue_use (t);
    8317                 :         123 :                   if (!processing_template_decl)
    8318                 :             :                     {
    8319                 :         123 :                       t = maybe_constant_value (t);
    8320                 :         123 :                       if (TREE_CODE (t) == INTEGER_CST
    8321                 :         109 :                           && tree_int_cst_sgn (t) != 1
    8322                 :         176 :                           && t != integer_minus_one_node)
    8323                 :             :                         {
    8324                 :           0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8325                 :             :                                       "%<gang%> static value must be "
    8326                 :             :                                       "positive");
    8327                 :           0 :                           t = integer_one_node;
    8328                 :             :                         }
    8329                 :         123 :                       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8330                 :             :                     }
    8331                 :             :                 }
    8332                 :         129 :               OMP_CLAUSE_OPERAND (c, 1) = t;
    8333                 :             :             }
    8334                 :             :           /* Check operand 0, the num argument.  */
    8335                 :             :           /* FALLTHRU */
    8336                 :             : 
    8337                 :        3480 :         case OMP_CLAUSE_WORKER:
    8338                 :        3480 :         case OMP_CLAUSE_VECTOR:
    8339                 :        3480 :           if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
    8340                 :             :             break;
    8341                 :             :           /* FALLTHRU */
    8342                 :             : 
    8343                 :         481 :         case OMP_CLAUSE_NUM_TASKS:
    8344                 :         481 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
    8345                 :         133 :             num_tasks_seen = true;
    8346                 :             :           /* FALLTHRU */
    8347                 :             : 
    8348                 :        3002 :         case OMP_CLAUSE_NUM_TEAMS:
    8349                 :        3002 :         case OMP_CLAUSE_NUM_THREADS:
    8350                 :        3002 :         case OMP_CLAUSE_NUM_GANGS:
    8351                 :        3002 :         case OMP_CLAUSE_NUM_WORKERS:
    8352                 :        3002 :         case OMP_CLAUSE_VECTOR_LENGTH:
    8353                 :        3002 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8354                 :        3002 :           if (t == error_mark_node)
    8355                 :             :             remove = true;
    8356                 :        3002 :           else if (!type_dependent_expression_p (t)
    8357                 :        3002 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8358                 :             :             {
    8359                 :          93 :              switch (OMP_CLAUSE_CODE (c))
    8360                 :             :                 {
    8361                 :          12 :                 case OMP_CLAUSE_GANG:
    8362                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8363                 :          12 :                             "%<gang%> num expression must be integral"); break;
    8364                 :          12 :                 case OMP_CLAUSE_VECTOR:
    8365                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8366                 :             :                             "%<vector%> length expression must be integral");
    8367                 :          12 :                   break;
    8368                 :          12 :                 case OMP_CLAUSE_WORKER:
    8369                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8370                 :             :                             "%<worker%> num expression must be integral");
    8371                 :          12 :                   break;
    8372                 :          57 :                 default:
    8373                 :          57 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8374                 :             :                             "%qs expression must be integral",
    8375                 :          57 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8376                 :             :                 }
    8377                 :             :               remove = true;
    8378                 :             :             }
    8379                 :             :           else
    8380                 :             :             {
    8381                 :        2909 :               t = mark_rvalue_use (t);
    8382                 :        2909 :               if (!processing_template_decl)
    8383                 :             :                 {
    8384                 :        2661 :                   t = maybe_constant_value (t);
    8385                 :        2661 :                   if (TREE_CODE (t) == INTEGER_CST
    8386                 :        2661 :                       && tree_int_cst_sgn (t) != 1)
    8387                 :             :                     {
    8388                 :          85 :                       switch (OMP_CLAUSE_CODE (c))
    8389                 :             :                         {
    8390                 :           3 :                         case OMP_CLAUSE_GANG:
    8391                 :           3 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8392                 :             :                                       "%<gang%> num value must be positive");
    8393                 :           3 :                           break;
    8394                 :           0 :                         case OMP_CLAUSE_VECTOR:
    8395                 :           0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8396                 :             :                                       "%<vector%> length value must be "
    8397                 :             :                                       "positive");
    8398                 :           0 :                           break;
    8399                 :           0 :                         case OMP_CLAUSE_WORKER:
    8400                 :           0 :                           warning_at (OMP_CLAUSE_LOCATION (c), 0,
    8401                 :             :                                       "%<worker%> num value must be "
    8402                 :             :                                       "positive");
    8403                 :           0 :                           break;
    8404                 :          82 :                         default:
    8405                 :          82 :                           warning_at (OMP_CLAUSE_LOCATION (c),
    8406                 :          46 :                                       (flag_openmp || flag_openmp_simd)
    8407                 :          82 :                                       ? OPT_Wopenmp : 0,
    8408                 :             :                                       "%qs value must be positive",
    8409                 :             :                                       omp_clause_code_name
    8410                 :          82 :                                       [OMP_CLAUSE_CODE (c)]);
    8411                 :             :                         }
    8412                 :          85 :                       t = integer_one_node;
    8413                 :             :                     }
    8414                 :        2661 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8415                 :             :                 }
    8416                 :        2909 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8417                 :             :             }
    8418                 :        3002 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
    8419                 :         764 :               && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
    8420                 :        3281 :               && !remove)
    8421                 :             :             {
    8422                 :         279 :               t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
    8423                 :         279 :               if (t == error_mark_node)
    8424                 :             :                 remove = true;
    8425                 :         279 :               else if (!type_dependent_expression_p (t)
    8426                 :         279 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8427                 :             :                 {
    8428                 :           0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8429                 :             :                             "%qs expression must be integral",
    8430                 :           0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8431                 :           0 :                   remove = true;
    8432                 :             :                 }
    8433                 :             :               else
    8434                 :             :                 {
    8435                 :         279 :                   t = mark_rvalue_use (t);
    8436                 :         279 :                   if (!processing_template_decl)
    8437                 :             :                     {
    8438                 :         213 :                       t = maybe_constant_value (t);
    8439                 :         213 :                       if (TREE_CODE (t) == INTEGER_CST
    8440                 :         213 :                           && tree_int_cst_sgn (t) != 1)
    8441                 :             :                         {
    8442                 :          18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8443                 :             :                                       "%qs value must be positive",
    8444                 :             :                                       omp_clause_code_name
    8445                 :          18 :                                       [OMP_CLAUSE_CODE (c)]);
    8446                 :          18 :                           t = NULL_TREE;
    8447                 :             :                         }
    8448                 :             :                       else
    8449                 :         195 :                         t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8450                 :         213 :                       tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
    8451                 :         213 :                       if (t
    8452                 :         195 :                           && TREE_CODE (t) == INTEGER_CST
    8453                 :          43 :                           && TREE_CODE (upper) == INTEGER_CST
    8454                 :         250 :                           && tree_int_cst_lt (upper, t))
    8455                 :             :                         {
    8456                 :          18 :                           warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8457                 :             :                                       "%<num_teams%> lower bound %qE bigger "
    8458                 :             :                                       "than upper bound %qE", t, upper);
    8459                 :          18 :                           t = NULL_TREE;
    8460                 :             :                         }
    8461                 :             :                     }
    8462                 :         279 :                   OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
    8463                 :             :                 }
    8464                 :             :             }
    8465                 :             :           break;
    8466                 :             : 
    8467                 :        3856 :         case OMP_CLAUSE_SCHEDULE:
    8468                 :        3856 :           t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
    8469                 :        3856 :           if (t == NULL)
    8470                 :             :             ;
    8471                 :        2072 :           else if (t == error_mark_node)
    8472                 :             :             remove = true;
    8473                 :        2072 :           else if (!type_dependent_expression_p (t)
    8474                 :        2072 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8475                 :             :             {
    8476                 :           9 :               error_at (OMP_CLAUSE_LOCATION (c),
    8477                 :             :                         "schedule chunk size expression must be integral");
    8478                 :           9 :               remove = true;
    8479                 :             :             }
    8480                 :             :           else
    8481                 :             :             {
    8482                 :        2063 :               t = mark_rvalue_use (t);
    8483                 :        2063 :               if (!processing_template_decl)
    8484                 :             :                 {
    8485                 :        2023 :                   t = maybe_constant_value (t);
    8486                 :        2023 :                   if (TREE_CODE (t) == INTEGER_CST
    8487                 :        2023 :                       && tree_int_cst_sgn (t) != 1)
    8488                 :             :                   {
    8489                 :           6 :                     warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8490                 :             :                               "chunk size value must be positive");
    8491                 :           6 :                     t = integer_one_node;
    8492                 :             :                   }
    8493                 :        2023 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8494                 :             :                 }
    8495                 :        2063 :               OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
    8496                 :             :             }
    8497                 :        2072 :           if (!remove)
    8498                 :             :             schedule_seen = true;
    8499                 :             :           break;
    8500                 :             : 
    8501                 :        1268 :         case OMP_CLAUSE_SIMDLEN:
    8502                 :        1268 :         case OMP_CLAUSE_SAFELEN:
    8503                 :        1268 :           t = OMP_CLAUSE_OPERAND (c, 0);
    8504                 :        1268 :           if (t == error_mark_node)
    8505                 :             :             remove = true;
    8506                 :        1268 :           else if (!type_dependent_expression_p (t)
    8507                 :        1268 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8508                 :             :             {
    8509                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8510                 :             :                         "%qs length expression must be integral",
    8511                 :           0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8512                 :           0 :               remove = true;
    8513                 :             :             }
    8514                 :             :           else
    8515                 :             :             {
    8516                 :        1268 :               t = mark_rvalue_use (t);
    8517                 :        1268 :               if (!processing_template_decl)
    8518                 :             :                 {
    8519                 :        1219 :                   t = maybe_constant_value (t);
    8520                 :        1219 :                   if (TREE_CODE (t) != INTEGER_CST
    8521                 :        1219 :                       || tree_int_cst_sgn (t) != 1)
    8522                 :             :                     {
    8523                 :           0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8524                 :             :                                 "%qs length expression must be positive "
    8525                 :             :                                 "constant integer expression",
    8526                 :           0 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8527                 :           0 :                       remove = true;
    8528                 :             :                     }
    8529                 :             :                 }
    8530                 :        1268 :               OMP_CLAUSE_OPERAND (c, 0) = t;
    8531                 :        1268 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
    8532                 :         470 :                 safelen = c;
    8533                 :             :             }
    8534                 :             :           break;
    8535                 :             : 
    8536                 :         388 :         case OMP_CLAUSE_ASYNC:
    8537                 :         388 :           t = OMP_CLAUSE_ASYNC_EXPR (c);
    8538                 :         388 :           if (t == error_mark_node)
    8539                 :             :             remove = true;
    8540                 :         373 :           else if (!type_dependent_expression_p (t)
    8541                 :         373 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8542                 :             :             {
    8543                 :          12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8544                 :             :                         "%<async%> expression must be integral");
    8545                 :          12 :               remove = true;
    8546                 :             :             }
    8547                 :             :           else
    8548                 :             :             {
    8549                 :         361 :               t = mark_rvalue_use (t);
    8550                 :         361 :               if (!processing_template_decl)
    8551                 :         352 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8552                 :         361 :               OMP_CLAUSE_ASYNC_EXPR (c) = t;
    8553                 :             :             }
    8554                 :             :           break;
    8555                 :             : 
    8556                 :         196 :         case OMP_CLAUSE_WAIT:
    8557                 :         196 :           t = OMP_CLAUSE_WAIT_EXPR (c);
    8558                 :         196 :           if (t == error_mark_node)
    8559                 :             :             remove = true;
    8560                 :         196 :           else if (!processing_template_decl)
    8561                 :         188 :             t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8562                 :         196 :           OMP_CLAUSE_WAIT_EXPR (c) = t;
    8563                 :         196 :           break;
    8564                 :             : 
    8565                 :         637 :         case OMP_CLAUSE_THREAD_LIMIT:
    8566                 :         637 :           t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
    8567                 :         637 :           if (t == error_mark_node)
    8568                 :             :             remove = true;
    8569                 :         637 :           else if (!type_dependent_expression_p (t)
    8570                 :         637 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8571                 :             :             {
    8572                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8573                 :             :                         "%<thread_limit%> expression must be integral");
    8574                 :           0 :               remove = true;
    8575                 :             :             }
    8576                 :             :           else
    8577                 :             :             {
    8578                 :         637 :               t = mark_rvalue_use (t);
    8579                 :         637 :               if (!processing_template_decl)
    8580                 :             :                 {
    8581                 :         583 :                   t = maybe_constant_value (t);
    8582                 :         583 :                   if (TREE_CODE (t) == INTEGER_CST
    8583                 :         583 :                       && tree_int_cst_sgn (t) != 1)
    8584                 :             :                     {
    8585                 :           0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8586                 :             :                                   "%<thread_limit%> value must be positive");
    8587                 :           0 :                       t = integer_one_node;
    8588                 :             :                     }
    8589                 :         583 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8590                 :             :                 }
    8591                 :         637 :               OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
    8592                 :             :             }
    8593                 :             :           break;
    8594                 :             : 
    8595                 :         769 :         case OMP_CLAUSE_DEVICE:
    8596                 :         769 :           t = OMP_CLAUSE_DEVICE_ID (c);
    8597                 :         769 :           if (t == error_mark_node)
    8598                 :             :             remove = true;
    8599                 :         769 :           else if (!type_dependent_expression_p (t)
    8600                 :         769 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8601                 :             :             {
    8602                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8603                 :             :                         "%<device%> id must be integral");
    8604                 :           6 :               remove = true;
    8605                 :             :             }
    8606                 :         763 :           else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
    8607                 :          66 :                    && TREE_CODE (t) == INTEGER_CST
    8608                 :         823 :                    && !integer_onep (t))
    8609                 :             :             {
    8610                 :           3 :               error_at (OMP_CLAUSE_LOCATION (c),
    8611                 :             :                         "the %<device%> clause expression must evaluate to "
    8612                 :             :                         "%<1%>");
    8613                 :           3 :               remove = true;
    8614                 :             :             }
    8615                 :             :           else
    8616                 :             :             {
    8617                 :         760 :               t = mark_rvalue_use (t);
    8618                 :         760 :               if (!processing_template_decl)
    8619                 :         749 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8620                 :         760 :               OMP_CLAUSE_DEVICE_ID (c) = t;
    8621                 :             :             }
    8622                 :             :           break;
    8623                 :             : 
    8624                 :        1836 :         case OMP_CLAUSE_DIST_SCHEDULE:
    8625                 :        1836 :           t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
    8626                 :        1836 :           if (t == NULL)
    8627                 :             :             ;
    8628                 :        1815 :           else if (t == error_mark_node)
    8629                 :             :             remove = true;
    8630                 :        1815 :           else if (!type_dependent_expression_p (t)
    8631                 :        1815 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8632                 :             :             {
    8633                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8634                 :             :                         "%<dist_schedule%> chunk size expression must be "
    8635                 :             :                         "integral");
    8636                 :           0 :               remove = true;
    8637                 :             :             }
    8638                 :             :           else
    8639                 :             :             {
    8640                 :        1815 :               t = mark_rvalue_use (t);
    8641                 :        1815 :               if (!processing_template_decl)
    8642                 :        1815 :                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    8643                 :        1815 :               OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
    8644                 :             :             }
    8645                 :             :           break;
    8646                 :             : 
    8647                 :         807 :         case OMP_CLAUSE_ALIGNED:
    8648                 :         807 :           t = OMP_CLAUSE_DECL (c);
    8649                 :         807 :           if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
    8650                 :             :             {
    8651                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8652                 :             :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    8653                 :             :                         " clauses");
    8654                 :           0 :               remove = true;
    8655                 :           0 :               break;
    8656                 :             :             }
    8657                 :         807 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8658                 :             :             {
    8659                 :           0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8660                 :             :                 break;
    8661                 :           0 :               if (DECL_P (t))
    8662                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8663                 :             :                           "%qD is not a variable in %<aligned%> clause", t);
    8664                 :             :               else
    8665                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8666                 :             :                           "%qE is not a variable in %<aligned%> clause", t);
    8667                 :             :               remove = true;
    8668                 :             :             }
    8669                 :         807 :           else if (!type_dependent_expression_p (t)
    8670                 :         789 :                    && !TYPE_PTR_P (TREE_TYPE (t))
    8671                 :         111 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    8672                 :         864 :                    && (!TYPE_REF_P (TREE_TYPE (t))
    8673                 :          39 :                        || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
    8674                 :          30 :                            && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
    8675                 :             :                                != ARRAY_TYPE))))
    8676                 :             :             {
    8677                 :          33 :               error_at (OMP_CLAUSE_LOCATION (c),
    8678                 :             :                         "%qE in %<aligned%> clause is neither a pointer nor "
    8679                 :             :                         "an array nor a reference to pointer or array", t);
    8680                 :          33 :               remove = true;
    8681                 :             :             }
    8682                 :         774 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8683                 :             :             {
    8684                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8685                 :             :                         "%qD appears more than once in %<aligned%> clauses",
    8686                 :             :                         t);
    8687                 :           0 :               remove = true;
    8688                 :             :             }
    8689                 :             :           else
    8690                 :         774 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
    8691                 :         807 :           t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
    8692                 :         807 :           if (t == error_mark_node)
    8693                 :             :             remove = true;
    8694                 :         807 :           else if (t == NULL_TREE)
    8695                 :             :             break;
    8696                 :         744 :           else if (!type_dependent_expression_p (t)
    8697                 :         744 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    8698                 :             :             {
    8699                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8700                 :             :                         "%<aligned%> clause alignment expression must "
    8701                 :             :                         "be integral");
    8702                 :           0 :               remove = true;
    8703                 :             :             }
    8704                 :             :           else
    8705                 :             :             {
    8706                 :         744 :               t = mark_rvalue_use (t);
    8707                 :         744 :               if (!processing_template_decl)
    8708                 :             :                 {
    8709                 :         690 :                   t = maybe_constant_value (t);
    8710                 :         690 :                   if (TREE_CODE (t) != INTEGER_CST
    8711                 :         690 :                       || tree_int_cst_sgn (t) != 1)
    8712                 :             :                     {
    8713                 :           0 :                       error_at (OMP_CLAUSE_LOCATION (c),
    8714                 :             :                                 "%<aligned%> clause alignment expression must "
    8715                 :             :                                 "be positive constant integer expression");
    8716                 :           0 :                       remove = true;
    8717                 :             :                     }
    8718                 :             :                 }
    8719                 :         744 :               OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
    8720                 :             :             }
    8721                 :             :           break;
    8722                 :             : 
    8723                 :         369 :         case OMP_CLAUSE_NONTEMPORAL:
    8724                 :         369 :           t = OMP_CLAUSE_DECL (c);
    8725                 :         369 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    8726                 :             :             {
    8727                 :           0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8728                 :             :                 break;
    8729                 :           0 :               if (DECL_P (t))
    8730                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8731                 :             :                           "%qD is not a variable in %<nontemporal%> clause",
    8732                 :             :                           t);
    8733                 :             :               else
    8734                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8735                 :             :                           "%qE is not a variable in %<nontemporal%> clause",
    8736                 :             :                           t);
    8737                 :             :               remove = true;
    8738                 :             :             }
    8739                 :         369 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
    8740                 :             :             {
    8741                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    8742                 :             :                         "%qD appears more than once in %<nontemporal%> "
    8743                 :             :                         "clauses", t);
    8744                 :           6 :               remove = true;
    8745                 :             :             }
    8746                 :             :           else
    8747                 :         363 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
    8748                 :             :           break;
    8749                 :             : 
    8750                 :        2739 :         case OMP_CLAUSE_ALLOCATE:
    8751                 :        2739 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    8752                 :        2739 :           if (t)
    8753                 :          14 :             omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
    8754                 :             :           else
    8755                 :        2725 :             t = OMP_CLAUSE_DECL (c);
    8756                 :        2739 :           if (t == current_class_ptr)
    8757                 :             :             {
    8758                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    8759                 :             :                         "%<this%> not allowed in %<allocate%> clause");
    8760                 :           0 :               remove = true;
    8761                 :           0 :               break;
    8762                 :             :             }
    8763                 :        2739 :           if (!VAR_P (t)
    8764                 :         678 :               && TREE_CODE (t) != PARM_DECL
    8765                 :          45 :               && TREE_CODE (t) != FIELD_DECL)
    8766                 :             :             {
    8767                 :           3 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8768                 :             :                 break;
    8769                 :           3 :               if (DECL_P (t))
    8770                 :           3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8771                 :             :                           "%qD is not a variable in %<allocate%> clause", t);
    8772                 :             :               else
    8773                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8774                 :             :                           "%qE is not a variable in %<allocate%> clause", t);
    8775                 :             :               remove = true;
    8776                 :             :             }
    8777                 :        2736 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
    8778                 :             :             {
    8779                 :          12 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    8780                 :             :                         "%qD appears more than once in %<allocate%> clauses",
    8781                 :             :                         t);
    8782                 :          12 :               remove = true;
    8783                 :             :             }
    8784                 :             :           else
    8785                 :             :             {
    8786                 :        2724 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
    8787                 :        2724 :               allocate_seen = true;
    8788                 :             :             }
    8789                 :        2739 :           tree allocator, align;
    8790                 :        2739 :           align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
    8791                 :        2739 :           if (error_operand_p (align))
    8792                 :             :             {
    8793                 :             :               remove = true;
    8794                 :             :               break;
    8795                 :             :             }
    8796                 :        2739 :           if (align)
    8797                 :             :             {
    8798                 :         171 :               if (!type_dependent_expression_p (align)
    8799                 :         171 :                   && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    8800                 :             :                 {
    8801                 :           4 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8802                 :             :                             "%<allocate%> clause %<align%> modifier "
    8803                 :             :                             "argument needs to be positive constant "
    8804                 :             :                             "power of two integer expression");
    8805                 :           4 :                   remove = true;
    8806                 :             :                 }
    8807                 :             :               else
    8808                 :             :                 {
    8809                 :         167 :                   align = mark_rvalue_use (align);
    8810                 :         167 :                   if (!processing_template_decl)
    8811                 :             :                     {
    8812                 :         152 :                       align = maybe_constant_value (align);
    8813                 :         152 :                       if (TREE_CODE (align) != INTEGER_CST
    8814                 :         149 :                           || !tree_fits_uhwi_p (align)
    8815                 :         301 :                           || !integer_pow2p (align))
    8816                 :             :                         {
    8817                 :          10 :                           error_at (OMP_CLAUSE_LOCATION (c),
    8818                 :             :                                     "%<allocate%> clause %<align%> modifier "
    8819                 :             :                                     "argument needs to be positive constant "
    8820                 :             :                                     "power of two integer expression");
    8821                 :          10 :                           remove = true;
    8822                 :             :                         }
    8823                 :             :                     }
    8824                 :             :                 }
    8825                 :         171 :               OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
    8826                 :             :             }
    8827                 :        2739 :           allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
    8828                 :        2739 :           if (error_operand_p (allocator))
    8829                 :             :             {
    8830                 :             :               remove = true;
    8831                 :             :               break;
    8832                 :             :             }
    8833                 :        2739 :           if (allocator == NULL_TREE)
    8834                 :        1745 :             goto handle_field_decl;
    8835                 :         994 :           tree allocatort;
    8836                 :         994 :           allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
    8837                 :         994 :           if (!type_dependent_expression_p (allocator)
    8838                 :         994 :               && (TREE_CODE (allocatort) != ENUMERAL_TYPE
    8839                 :         975 :                   || TYPE_NAME (allocatort) == NULL_TREE
    8840                 :         975 :                   || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
    8841                 :        1950 :                   || (DECL_NAME (TYPE_NAME (allocatort))
    8842                 :         975 :                       != get_identifier ("omp_allocator_handle_t"))
    8843                 :         975 :                   || (TYPE_CONTEXT (allocatort)
    8844                 :         975 :                       != DECL_CONTEXT (global_namespace))))
    8845                 :             :             {
    8846                 :          16 :               error_at (OMP_CLAUSE_LOCATION (c),
    8847                 :             :                         "%<allocate%> clause allocator expression has "
    8848                 :             :                         "type %qT rather than %<omp_allocator_handle_t%>",
    8849                 :          16 :                         TREE_TYPE (allocator));
    8850                 :          16 :               remove = true;
    8851                 :          16 :               break;
    8852                 :             :             }
    8853                 :             :           else
    8854                 :             :             {
    8855                 :         978 :               allocator = mark_rvalue_use (allocator);
    8856                 :         978 :               if (!processing_template_decl)
    8857                 :         959 :                 allocator = maybe_constant_value (allocator);
    8858                 :         978 :               OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
    8859                 :             :             }
    8860                 :         978 :           goto handle_field_decl;
    8861                 :             : 
    8862                 :         648 :         case OMP_CLAUSE_DOACROSS:
    8863                 :         648 :           t = OMP_CLAUSE_DECL (c);
    8864                 :         648 :           if (t == NULL_TREE)
    8865                 :             :             break;
    8866                 :         295 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
    8867                 :             :             {
    8868                 :         295 :               if (cp_finish_omp_clause_doacross_sink (c))
    8869                 :           9 :                 remove = true;
    8870                 :             :               break;
    8871                 :             :             }
    8872                 :           0 :           gcc_unreachable ();
    8873                 :        1803 :         case OMP_CLAUSE_DEPEND:
    8874                 :        1803 :           depend_clause = c;
    8875                 :             :           /* FALLTHRU */
    8876                 :        2343 :         case OMP_CLAUSE_AFFINITY:
    8877                 :        2343 :           t = OMP_CLAUSE_DECL (c);
    8878                 :        2343 :           if (OMP_ITERATOR_DECL_P (t))
    8879                 :             :             {
    8880                 :         621 :               if (TREE_PURPOSE (t) != last_iterators)
    8881                 :         523 :                 last_iterators_remove
    8882                 :         523 :                   = cp_omp_finish_iterators (TREE_PURPOSE (t));
    8883                 :         621 :               last_iterators = TREE_PURPOSE (t);
    8884                 :         621 :               t = TREE_VALUE (t);
    8885                 :         621 :               if (last_iterators_remove)
    8886                 :         144 :                 t = error_mark_node;
    8887                 :             :             }
    8888                 :             :           else
    8889                 :             :             last_iterators = NULL_TREE;
    8890                 :             : 
    8891                 :        2343 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    8892                 :             :             {
    8893                 :        1305 :               if (handle_omp_array_sections (c, ort))
    8894                 :             :                 remove = true;
    8895                 :         978 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    8896                 :         978 :                        && (OMP_CLAUSE_DEPEND_KIND (c)
    8897                 :             :                            == OMP_CLAUSE_DEPEND_DEPOBJ))
    8898                 :             :                 {
    8899                 :           6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8900                 :             :                             "%<depend%> clause with %<depobj%> dependence "
    8901                 :             :                             "type on array section");
    8902                 :           6 :                   remove = true;
    8903                 :             :                 }
    8904                 :             :               break;
    8905                 :             :             }
    8906                 :        1038 :           if (t == error_mark_node)
    8907                 :             :             remove = true;
    8908                 :         876 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    8909                 :         876 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
    8910                 :             :             {
    8911                 :          33 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
    8912                 :          33 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
    8913                 :             :                 {
    8914                 :           9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8915                 :             :                             "%<omp_all_memory%> used with %<depend%> kind "
    8916                 :             :                             "other than %<out%> or %<inout%>");
    8917                 :           9 :                   remove = true;
    8918                 :             :                 }
    8919                 :          33 :               if (processing_template_decl)
    8920                 :             :                 break;
    8921                 :             :             }
    8922                 :         843 :           else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    8923                 :             :             break;
    8924                 :         651 :           else if (!lvalue_p (t))
    8925                 :             :             {
    8926                 :          21 :               if (DECL_P (t))
    8927                 :          24 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8928                 :             :                           "%qD is not lvalue expression nor array section "
    8929                 :             :                           "in %qs clause", t,
    8930                 :          12 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8931                 :             :               else
    8932                 :          18 :                 error_at (OMP_CLAUSE_LOCATION (c),
    8933                 :             :                           "%qE is not lvalue expression nor array section "
    8934                 :             :                           "in %qs clause", t,
    8935                 :           9 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8936                 :             :               remove = true;
    8937                 :             :             }
    8938                 :         630 :           else if (TREE_CODE (t) == COMPONENT_REF
    8939                 :          36 :                    && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
    8940                 :         666 :                    && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
    8941                 :             :             {
    8942                 :          12 :               error_at (OMP_CLAUSE_LOCATION (c),
    8943                 :             :                         "bit-field %qE in %qs clause", t,
    8944                 :           6 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    8945                 :           6 :               remove = true;
    8946                 :             :             }
    8947                 :         624 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    8948                 :         624 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
    8949                 :             :             {
    8950                 :         130 :               if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    8951                 :           8 :                                      ? TREE_TYPE (TREE_TYPE (t))
    8952                 :          57 :                                      : TREE_TYPE (t)))
    8953                 :             :                 {
    8954                 :          12 :                   error_at (OMP_CLAUSE_LOCATION (c),
    8955                 :             :                             "%qE does not have %<omp_depend_t%> type in "
    8956                 :             :                             "%<depend%> clause with %<depobj%> dependence "
    8957                 :             :                             "type", t);
    8958                 :          12 :                   remove = true;
    8959                 :             :                 }
    8960                 :             :             }
    8961                 :         559 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
    8962                 :         998 :                    && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
    8963                 :           4 :                                         ? TREE_TYPE (TREE_TYPE (t))
    8964                 :         435 :                                         : TREE_TYPE (t)))
    8965                 :             :             {
    8966                 :          15 :               error_at (OMP_CLAUSE_LOCATION (c),
    8967                 :             :                         "%qE should not have %<omp_depend_t%> type in "
    8968                 :             :                         "%<depend%> clause with dependence type other than "
    8969                 :             :                         "%<depobj%>", t);
    8970                 :          15 :               remove = true;
    8971                 :             :             }
    8972                 :          66 :           if (!remove)
    8973                 :             :             {
    8974                 :         621 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
    8975                 :          24 :                 t = null_pointer_node;
    8976                 :             :               else
    8977                 :             :                 {
    8978                 :         597 :                   tree addr = cp_build_addr_expr (t, tf_warning_or_error);
    8979                 :         597 :                   if (addr == error_mark_node)
    8980                 :             :                     {
    8981                 :             :                       remove = true;
    8982                 :             :                       break;
    8983                 :             :                     }
    8984                 :         597 :                   t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
    8985                 :             :                                              addr, RO_UNARY_STAR,
    8986                 :             :                                              tf_warning_or_error);
    8987                 :         597 :                   if (t == error_mark_node)
    8988                 :             :                     {
    8989                 :             :                       remove = true;
    8990                 :             :                       break;
    8991                 :             :                     }
    8992                 :             :                 }
    8993                 :         621 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
    8994                 :         135 :                   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
    8995                 :         756 :                   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
    8996                 :             :                       == TREE_VEC))
    8997                 :         135 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
    8998                 :             :               else
    8999                 :         486 :                 OMP_CLAUSE_DECL (c) = t;
    9000                 :             :             }
    9001                 :             :           break;
    9002                 :          69 :         case OMP_CLAUSE_DETACH:
    9003                 :          69 :           t = OMP_CLAUSE_DECL (c);
    9004                 :          69 :           if (detach_seen)
    9005                 :             :             {
    9006                 :           3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9007                 :             :                         "too many %qs clauses on a task construct",
    9008                 :             :                         "detach");
    9009                 :           3 :               remove = true;
    9010                 :           3 :               break;
    9011                 :             :             }
    9012                 :          66 :           else if (error_operand_p (t))
    9013                 :             :             {
    9014                 :             :               remove = true;
    9015                 :             :               break;
    9016                 :             :             }
    9017                 :             :           else
    9018                 :             :             {
    9019                 :          63 :               tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
    9020                 :          63 :               if (!type_dependent_expression_p (t)
    9021                 :          63 :                   && (!INTEGRAL_TYPE_P (type)
    9022                 :             :                       || TREE_CODE (type) != ENUMERAL_TYPE
    9023                 :          51 :                       || TYPE_NAME (type) == NULL_TREE
    9024                 :         102 :                       || (DECL_NAME (TYPE_NAME (type))
    9025                 :          51 :                           != get_identifier ("omp_event_handle_t"))))
    9026                 :             :                 {
    9027                 :           6 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9028                 :             :                             "%<detach%> clause event handle "
    9029                 :             :                             "has type %qT rather than "
    9030                 :             :                             "%<omp_event_handle_t%>",
    9031                 :             :                             type);
    9032                 :           6 :                   remove = true;
    9033                 :             :                 }
    9034                 :          63 :               detach_seen = c;
    9035                 :          63 :               cxx_mark_addressable (t);
    9036                 :             :             }
    9037                 :          63 :           break;
    9038                 :             : 
    9039                 :       15879 :         case OMP_CLAUSE_MAP:
    9040                 :       15879 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
    9041                 :         195 :             goto move_implicit;
    9042                 :       15684 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
    9043                 :       15684 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
    9044                 :             :             {
    9045                 :             :               remove = true;
    9046                 :             :               break;
    9047                 :             :             }
    9048                 :             :           /* FALLTHRU */
    9049                 :       18802 :         case OMP_CLAUSE_TO:
    9050                 :       18802 :         case OMP_CLAUSE_FROM:
    9051                 :       18802 :           if (OMP_CLAUSE_ITERATORS (c)
    9052                 :       18802 :               && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
    9053                 :             :             {
    9054                 :       97238 :               t = error_mark_node;
    9055                 :             :               break;
    9056                 :             :             }
    9057                 :             :           /* FALLTHRU */
    9058                 :       19681 :         case OMP_CLAUSE__CACHE_:
    9059                 :       19681 :           {
    9060                 :       19681 :             using namespace omp_addr_tokenizer;
    9061                 :       19681 :             auto_vec<omp_addr_token *, 10> addr_tokens;
    9062                 :             : 
    9063                 :       19681 :             t = OMP_CLAUSE_DECL (c);
    9064                 :       19681 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9065                 :             :               {
    9066                 :        5920 :                 grp_start_p = pc;
    9067                 :        5920 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9068                 :             : 
    9069                 :        5920 :                 if (handle_omp_array_sections (c, ort))
    9070                 :             :                   remove = true;
    9071                 :             :                 else
    9072                 :             :                   {
    9073                 :        5116 :                     t = OMP_CLAUSE_DECL (c);
    9074                 :        5116 :                     if (TREE_CODE (t) != OMP_ARRAY_SECTION
    9075                 :        4255 :                         && !type_dependent_expression_p (t)
    9076                 :        9371 :                         && !omp_mappable_type (TREE_TYPE (t)))
    9077                 :             :                       {
    9078                 :           3 :                         auto_diagnostic_group d;
    9079                 :           6 :                         error_at (OMP_CLAUSE_LOCATION (c),
    9080                 :             :                                   "array section does not have mappable type "
    9081                 :             :                                   "in %qs clause",
    9082                 :           3 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9083                 :           3 :                         if (TREE_TYPE (t) != error_mark_node
    9084                 :           3 :                             && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9085                 :           3 :                           cxx_incomplete_type_inform (TREE_TYPE (t));
    9086                 :           3 :                         remove = true;
    9087                 :           3 :                       }
    9088                 :        6980 :                     while (TREE_CODE (t) == ARRAY_REF)
    9089                 :        1864 :                       t = TREE_OPERAND (t, 0);
    9090                 :             : 
    9091                 :        5116 :                     if (type_dependent_expression_p (t))
    9092                 :             :                       break;
    9093                 :             : 
    9094                 :        4642 :                     cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9095                 :             : 
    9096                 :        4642 :                     if (!ai.map_supported_p ()
    9097                 :        4642 :                         || !omp_parse_expr (addr_tokens, t))
    9098                 :             :                       {
    9099                 :          18 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
    9100                 :             :                                   "unsupported map expression %qE",
    9101                 :           9 :                                   OMP_CLAUSE_DECL (c));
    9102                 :           9 :                         remove = true;
    9103                 :           9 :                         break;
    9104                 :             :                       }
    9105                 :             : 
    9106                 :             :                     /* This check is to determine if this will be the only map
    9107                 :             :                        node created for this clause.  Otherwise, we'll check
    9108                 :             :                        the following FIRSTPRIVATE_POINTER,
    9109                 :             :                        FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
    9110                 :             :                        iteration(s) of the loop.   */
    9111                 :        9217 :                     if (addr_tokens.length () >= 4
    9112                 :        1063 :                         && addr_tokens[0]->type == STRUCTURE_BASE
    9113                 :        1057 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
    9114                 :        1057 :                         && addr_tokens[1]->type == ACCESS_METHOD
    9115                 :        1057 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
    9116                 :         977 :                         && addr_tokens[3]->type == ACCESS_METHOD
    9117                 :        5347 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
    9118                 :         551 :                             || (addr_tokens[3]->u.access_kind
    9119                 :             :                                 == ACCESS_INDEXED_ARRAY)))
    9120                 :             :                       {
    9121                 :         165 :                         tree rt = addr_tokens[1]->expr;
    9122                 :             : 
    9123                 :         165 :                         gcc_assert (DECL_P (rt));
    9124                 :             : 
    9125                 :         165 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9126                 :         154 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
    9127                 :         165 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
    9128                 :           0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
    9129                 :           0 :                                 || bitmap_bit_p (&map_firstprivate_head,
    9130                 :           0 :                                                  DECL_UID (rt))))
    9131                 :             :                           {
    9132                 :             :                             remove = true;
    9133                 :             :                             break;
    9134                 :             :                           }
    9135                 :         165 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
    9136                 :             :                           break;
    9137                 :         116 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
    9138                 :             :                           {
    9139                 :           0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9140                 :           0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9141                 :             :                                         "%qD appears more than once in motion"
    9142                 :             :                                         " clauses", rt);
    9143                 :           0 :                             else if (openacc)
    9144                 :           0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9145                 :             :                                         "%qD appears more than once in data"
    9146                 :             :                                         " clauses", rt);
    9147                 :             :                             else
    9148                 :           0 :                               error_at (OMP_CLAUSE_LOCATION (c),
    9149                 :             :                                         "%qD appears more than once in map"
    9150                 :             :                                         " clauses", rt);
    9151                 :             :                             remove = true;
    9152                 :             :                           }
    9153                 :             :                         else
    9154                 :             :                           {
    9155                 :         116 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
    9156                 :         116 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
    9157                 :             :                           }
    9158                 :             :                       }
    9159                 :        4642 :                   }
    9160                 :        5388 :                 if (cp_oacc_check_attachments (c))
    9161                 :          12 :                   remove = true;
    9162                 :        5388 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9163                 :        4413 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9164                 :        4349 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9165                 :        5486 :                     && !OMP_CLAUSE_SIZE (c))
    9166                 :             :                   /* In this case, we have a single array element which is a
    9167                 :             :                      pointer, and we already set OMP_CLAUSE_SIZE in
    9168                 :             :                      handle_omp_array_sections above.  For attach/detach
    9169                 :             :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
    9170                 :             :                      to zero here.  */
    9171                 :          60 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
    9172                 :             :                 break;
    9173                 :             :               }
    9174                 :       13761 :             else if (type_dependent_expression_p (t))
    9175                 :             :               break;
    9176                 :       12987 :             else if (!omp_parse_expr (addr_tokens, t))
    9177                 :             :               {
    9178                 :           0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9179                 :             :                           "unsupported map expression %qE",
    9180                 :           0 :                           OMP_CLAUSE_DECL (c));
    9181                 :           0 :                 remove = true;
    9182                 :           0 :                 break;
    9183                 :             :               }
    9184                 :       12987 :             if (t == error_mark_node)
    9185                 :             :               {
    9186                 :             :                 remove = true;
    9187                 :             :                 break;
    9188                 :             :               }
    9189                 :             :             /* OpenACC attach / detach clauses must be pointers.  */
    9190                 :       12918 :             if (cp_oacc_check_attachments (c))
    9191                 :             :               {
    9192                 :             :                 remove = true;
    9193                 :             :                 break;
    9194                 :             :               }
    9195                 :       12894 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9196                 :        9933 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
    9197                 :        9884 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
    9198                 :       12968 :                 && !OMP_CLAUSE_SIZE (c))
    9199                 :             :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
    9200                 :             :                  bias) to zero here, so it is not set erroneously to the
    9201                 :             :                  pointer size later on in gimplify.cc.  */
    9202                 :          66 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
    9203                 :             : 
    9204                 :       12894 :             cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
    9205                 :             : 
    9206                 :       12894 :             if (!ai.check_clause (c))
    9207                 :             :               {
    9208                 :             :                 remove = true;
    9209                 :             :                 break;
    9210                 :             :               }
    9211                 :             : 
    9212                 :       12873 :             if (!ai.map_supported_p ())
    9213                 :             :               {
    9214                 :          88 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
    9215                 :             :                           "unsupported map expression %qE",
    9216                 :          44 :                           OMP_CLAUSE_DECL (c));
    9217                 :          44 :                 remove = true;
    9218                 :          44 :                 break;
    9219                 :             :               }
    9220                 :             : 
    9221                 :       25658 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
    9222                 :             :                          || addr_tokens[0]->type == STRUCTURE_BASE)
    9223                 :             :                         && addr_tokens[1]->type == ACCESS_METHOD);
    9224                 :             : 
    9225                 :       12829 :             t = addr_tokens[1]->expr;
    9226                 :             : 
    9227                 :             :             /* This is used to prevent cxx_mark_addressable from being called
    9228                 :             :                on 'this' for expressions like 'this->a', i.e. typical member
    9229                 :             :                accesses.  */
    9230                 :       12829 :             indir_component_ref_p
    9231                 :       25658 :               = (addr_tokens[0]->type == STRUCTURE_BASE
    9232                 :       12829 :                  && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
    9233                 :             : 
    9234                 :       12829 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
    9235                 :           1 :               goto skip_decl_checks;
    9236                 :             : 
    9237                 :             :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
    9238                 :             :                mapping.  OpenACC allows multiple fields of the same structure
    9239                 :             :                to be written.  */
    9240                 :       12828 :             if (addr_tokens[0]->type == STRUCTURE_BASE
    9241                 :       12828 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
    9242                 :        1197 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
    9243                 :        1168 :               goto skip_decl_checks;
    9244                 :             : 
    9245                 :       11660 :             if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
    9246                 :             :               {
    9247                 :           0 :                 OMP_CLAUSE_DECL (c)
    9248                 :           0 :                   = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
    9249                 :           0 :                 break;
    9250                 :             :               }
    9251                 :       11660 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
    9252                 :             :               {
    9253                 :           0 :                 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9254                 :             :                   break;
    9255                 :           0 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9256                 :           0 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9257                 :           0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
    9258                 :           0 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
    9259                 :           0 :                         || (!openacc && EXPR_P (t))))
    9260                 :             :                   break;
    9261                 :           0 :                 if (DECL_P (t))
    9262                 :           0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9263                 :             :                             "%qD is not a variable in %qs clause", t,
    9264                 :           0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9265                 :             :                 else
    9266                 :           0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9267                 :             :                             "%qE is not a variable in %qs clause", t,
    9268                 :           0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9269                 :             :                 remove = true;
    9270                 :             :               }
    9271                 :       11660 :             else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
    9272                 :             :               {
    9273                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9274                 :             :                           "%qD is threadprivate variable in %qs clause", t,
    9275                 :           0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9276                 :           0 :                 remove = true;
    9277                 :             :               }
    9278                 :       11660 :             else if (!processing_template_decl
    9279                 :       11484 :                      && !TYPE_REF_P (TREE_TYPE (t))
    9280                 :       10811 :                      && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9281                 :        7900 :                          || (OMP_CLAUSE_MAP_KIND (c)
    9282                 :             :                              != GOMP_MAP_FIRSTPRIVATE_POINTER))
    9283                 :        8878 :                      && !indir_component_ref_p
    9284                 :        8514 :                      && (t != current_class_ptr
    9285                 :          18 :                          || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9286                 :           6 :                          || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
    9287                 :       20174 :                      && !cxx_mark_addressable (t))
    9288                 :             :               remove = true;
    9289                 :       11660 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9290                 :        8731 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
    9291                 :        8731 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9292                 :             :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
    9293                 :        6798 :                            || (OMP_CLAUSE_MAP_KIND (c)
    9294                 :             :                                == GOMP_MAP_ATTACH_DETACH)))
    9295                 :        9075 :                      && t == OMP_CLAUSE_DECL (c)
    9296                 :        8443 :                      && !type_dependent_expression_p (t)
    9297                 :       28546 :                      && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
    9298                 :         274 :                                             ? TREE_TYPE (TREE_TYPE (t))
    9299                 :        8169 :                                             : TREE_TYPE (t)))
    9300                 :             :               {
    9301                 :          42 :                 auto_diagnostic_group d;
    9302                 :          84 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9303                 :             :                           "%qD does not have a mappable type in %qs clause", t,
    9304                 :          42 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9305                 :          42 :                 if (TREE_TYPE (t) != error_mark_node
    9306                 :          42 :                     && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9307                 :          39 :                   cxx_incomplete_type_inform (TREE_TYPE (t));
    9308                 :          42 :                 remove = true;
    9309                 :          42 :               }
    9310                 :       11618 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9311                 :        8695 :                      && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
    9312                 :          93 :                      && !type_dependent_expression_p (t)
    9313                 :       11711 :                      && !INDIRECT_TYPE_P (TREE_TYPE (t)))
    9314                 :             :               {
    9315                 :           6 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9316                 :             :                           "%qD is not a pointer variable", t);
    9317                 :           6 :                 remove = true;
    9318                 :             :               }
    9319                 :       11612 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9320                 :        8689 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
    9321                 :       12020 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
    9322                 :         372 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
    9323                 :         372 :                          || bitmap_bit_p (&map_firstprivate_head,
    9324                 :         372 :                                           DECL_UID (t))))
    9325                 :             :               remove = true;
    9326                 :       11573 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9327                 :       11573 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9328                 :             :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
    9329                 :             :               {
    9330                 :        1927 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
    9331                 :        1927 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9332                 :        3851 :                     || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
    9333                 :             :                   {
    9334                 :          15 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9335                 :             :                               "%qD appears more than once in data clauses", t);
    9336                 :          15 :                     remove = true;
    9337                 :             :                   }
    9338                 :        1912 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9339                 :          12 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9340                 :        1920 :                          && openacc)
    9341                 :             :                   {
    9342                 :           3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9343                 :             :                               "%qD appears more than once in data clauses", t);
    9344                 :           3 :                     remove = true;
    9345                 :             :                   }
    9346                 :             :                 else
    9347                 :        1909 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9348                 :             :               }
    9349                 :        9646 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
    9350                 :        9646 :                      && (OMP_CLAUSE_MAP_KIND (c)
    9351                 :             :                          == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
    9352                 :         115 :               bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
    9353                 :        9531 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
    9354                 :         171 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
    9355                 :          28 :                      && ort != C_ORT_OMP
    9356                 :        9559 :                      && ort != C_ORT_OMP_EXIT_DATA)
    9357                 :             :               {
    9358                 :          18 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
    9359                 :           0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9360                 :             :                             "%qD appears more than once in motion clauses", t);
    9361                 :          18 :                 else if (openacc)
    9362                 :           9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9363                 :             :                             "%qD appears more than once in data clauses", t);
    9364                 :             :                 else
    9365                 :           9 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9366                 :             :                             "%qD appears more than once in map clauses", t);
    9367                 :             :                 remove = true;
    9368                 :             :               }
    9369                 :        9513 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
    9370                 :             :               {
    9371                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9372                 :             :                           "%qD appears more than once in data clauses", t);
    9373                 :           0 :                 remove = true;
    9374                 :             :               }
    9375                 :        9513 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
    9376                 :        9513 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
    9377                 :             :               {
    9378                 :          27 :                 if (openacc)
    9379                 :           0 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9380                 :             :                             "%qD appears more than once in data clauses", t);
    9381                 :             :                 else
    9382                 :          27 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9383                 :             :                             "%qD appears both in data and map clauses", t);
    9384                 :             :                 remove = true;
    9385                 :             :               }
    9386                 :        9486 :             else if (!omp_access_chain_p (addr_tokens, 1))
    9387                 :             :               {
    9388                 :        9406 :                 bitmap_set_bit (&map_head, DECL_UID (t));
    9389                 :             : 
    9390                 :        9406 :                 tree decl = OMP_CLAUSE_DECL (c);
    9391                 :        9406 :                 if (t != decl
    9392                 :        9406 :                     && (TREE_CODE (decl) == COMPONENT_REF
    9393                 :         162 :                         || (INDIRECT_REF_P (decl)
    9394                 :         162 :                             && (TREE_CODE (TREE_OPERAND (decl, 0))
    9395                 :             :                                 == COMPONENT_REF)
    9396                 :         150 :                             && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
    9397                 :             :                                                                     0))))))
    9398                 :        1099 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
    9399                 :             :               }
    9400                 :             : 
    9401                 :        4358 :           skip_decl_checks:
    9402                 :             :             /* If we call ai.expand_map_clause in handle_omp_array_sections,
    9403                 :             :                the containing loop (here) iterates through the new nodes
    9404                 :             :                created by that expansion.  Avoid expanding those again (just
    9405                 :             :                by checking the node type).  */
    9406                 :        4358 :             if (!remove
    9407                 :       12679 :                 && !processing_template_decl
    9408                 :       12506 :                 && ort != C_ORT_DECLARE_SIMD
    9409                 :       12506 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
    9410                 :        9563 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
    9411                 :        7654 :                         && (OMP_CLAUSE_MAP_KIND (c)
    9412                 :             :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
    9413                 :        7539 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
    9414                 :        7539 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
    9415                 :        6548 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
    9416                 :        6499 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
    9417                 :             :               {
    9418                 :        9417 :                 grp_start_p = pc;
    9419                 :        9417 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
    9420                 :        9417 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
    9421                 :             :                                                 addr_tokens, ort);
    9422                 :        9417 :                 if (nc != error_mark_node)
    9423                 :        9417 :                   c = nc;
    9424                 :             :               }
    9425                 :       19746 :           }
    9426                 :       12829 :           break;
    9427                 :             : 
    9428                 :         591 :         case OMP_CLAUSE_ENTER:
    9429                 :         591 :         case OMP_CLAUSE_LINK:
    9430                 :         591 :           t = OMP_CLAUSE_DECL (c);
    9431                 :         591 :           const char *cname;
    9432                 :         591 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
    9433                 :         591 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
    9434                 :         591 :               && OMP_CLAUSE_ENTER_TO (c))
    9435                 :             :             cname = "to";
    9436                 :         591 :           if (TREE_CODE (t) == FUNCTION_DECL
    9437                 :         591 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9438                 :             :             ;
    9439                 :         377 :           else if (!VAR_P (t))
    9440                 :             :             {
    9441                 :          12 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
    9442                 :             :                 {
    9443                 :           9 :                   if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
    9444                 :           6 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9445                 :             :                               "template %qE in clause %qs", t, cname);
    9446                 :           3 :                   else if (really_overloaded_fn (t))
    9447                 :           3 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9448                 :             :                               "overloaded function name %qE in clause %qs", t,
    9449                 :             :                               cname);
    9450                 :             :                   else
    9451                 :           0 :                     error_at (OMP_CLAUSE_LOCATION (c),
    9452                 :             :                               "%qE is neither a variable nor a function name "
    9453                 :             :                               "in clause %qs", t, cname);
    9454                 :             :                 }
    9455                 :             :               else
    9456                 :           3 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9457                 :             :                           "%qE is not a variable in clause %qs", t, cname);
    9458                 :             :               remove = true;
    9459                 :             :             }
    9460                 :         365 :           else if (DECL_THREAD_LOCAL_P (t))
    9461                 :             :             {
    9462                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9463                 :             :                         "%qD is threadprivate variable in %qs clause", t,
    9464                 :             :                         cname);
    9465                 :           6 :               remove = true;
    9466                 :             :             }
    9467                 :         359 :           else if (!omp_mappable_type (TREE_TYPE (t)))
    9468                 :             :             {
    9469                 :          18 :               auto_diagnostic_group d;
    9470                 :          18 :               error_at (OMP_CLAUSE_LOCATION (c),
    9471                 :             :                         "%qD does not have a mappable type in %qs clause", t,
    9472                 :             :                         cname);
    9473                 :          18 :               if (TREE_TYPE (t) != error_mark_node
    9474                 :          18 :                   && !COMPLETE_TYPE_P (TREE_TYPE (t)))
    9475                 :          18 :                 cxx_incomplete_type_inform (TREE_TYPE (t));
    9476                 :          18 :               remove = true;
    9477                 :          18 :             }
    9478                 :          24 :           if (remove)
    9479                 :             :             break;
    9480                 :         555 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
    9481                 :             :             {
    9482                 :          24 :               error_at (OMP_CLAUSE_LOCATION (c),
    9483                 :             :                         "%qE appears more than once on the same "
    9484                 :             :                         "%<declare target%> directive", t);
    9485                 :          24 :               remove = true;
    9486                 :             :             }
    9487                 :             :           else
    9488                 :         531 :             bitmap_set_bit (&generic_head, DECL_UID (t));
    9489                 :             :           break;
    9490                 :             : 
    9491                 :         457 :         case OMP_CLAUSE_UNIFORM:
    9492                 :         457 :           t = OMP_CLAUSE_DECL (c);
    9493                 :         457 :           if (TREE_CODE (t) != PARM_DECL)
    9494                 :             :             {
    9495                 :           0 :               if (processing_template_decl)
    9496                 :             :                 break;
    9497                 :           0 :               if (DECL_P (t))
    9498                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9499                 :             :                           "%qD is not an argument in %<uniform%> clause", t);
    9500                 :             :               else
    9501                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9502                 :             :                           "%qE is not an argument in %<uniform%> clause", t);
    9503                 :             :               remove = true;
    9504                 :             :               break;
    9505                 :             :             }
    9506                 :             :           /* map_head bitmap is used as uniform_head if declare_simd.  */
    9507                 :         457 :           bitmap_set_bit (&map_head, DECL_UID (t));
    9508                 :         457 :           goto check_dup_generic;
    9509                 :             : 
    9510                 :         165 :         case OMP_CLAUSE_GRAINSIZE:
    9511                 :         165 :           t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
    9512                 :         165 :           if (t == error_mark_node)
    9513                 :             :             remove = true;
    9514                 :         165 :           else if (!type_dependent_expression_p (t)
    9515                 :         165 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9516                 :             :             {
    9517                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9518                 :             :                         "%<grainsize%> expression must be integral");
    9519                 :           0 :               remove = true;
    9520                 :             :             }
    9521                 :             :           else
    9522                 :             :             {
    9523                 :         165 :               t = mark_rvalue_use (t);
    9524                 :         165 :               if (!processing_template_decl)
    9525                 :             :                 {
    9526                 :         164 :                   t = maybe_constant_value (t);
    9527                 :         164 :                   if (TREE_CODE (t) == INTEGER_CST
    9528                 :         164 :                       && tree_int_cst_sgn (t) != 1)
    9529                 :             :                     {
    9530                 :           0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9531                 :             :                                   "%<grainsize%> value must be positive");
    9532                 :           0 :                       t = integer_one_node;
    9533                 :             :                     }
    9534                 :         164 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9535                 :             :                 }
    9536                 :         165 :               OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
    9537                 :             :             }
    9538                 :             :           break;
    9539                 :             : 
    9540                 :         273 :         case OMP_CLAUSE_PRIORITY:
    9541                 :         273 :           t = OMP_CLAUSE_PRIORITY_EXPR (c);
    9542                 :         273 :           if (t == error_mark_node)
    9543                 :             :             remove = true;
    9544                 :         273 :           else if (!type_dependent_expression_p (t)
    9545                 :         273 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9546                 :             :             {
    9547                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9548                 :             :                         "%<priority%> expression must be integral");
    9549                 :           0 :               remove = true;
    9550                 :             :             }
    9551                 :             :           else
    9552                 :             :             {
    9553                 :         273 :               t = mark_rvalue_use (t);
    9554                 :         273 :               if (!processing_template_decl)
    9555                 :             :                 {
    9556                 :         273 :                   t = maybe_constant_value (t);
    9557                 :         273 :                   if (TREE_CODE (t) == INTEGER_CST
    9558                 :         273 :                       && tree_int_cst_sgn (t) == -1)
    9559                 :             :                     {
    9560                 :           0 :                       warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
    9561                 :             :                                   "%<priority%> value must be non-negative");
    9562                 :           0 :                       t = integer_one_node;
    9563                 :             :                     }
    9564                 :         273 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9565                 :             :                 }
    9566                 :         273 :               OMP_CLAUSE_PRIORITY_EXPR (c) = t;
    9567                 :             :             }
    9568                 :             :           break;
    9569                 :             : 
    9570                 :         228 :         case OMP_CLAUSE_HINT:
    9571                 :         228 :           t = OMP_CLAUSE_HINT_EXPR (c);
    9572                 :         228 :           if (t == error_mark_node)
    9573                 :             :             remove = true;
    9574                 :         228 :           else if (!type_dependent_expression_p (t)
    9575                 :         228 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9576                 :             :             {
    9577                 :           9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9578                 :             :                         "%<hint%> expression must be integral");
    9579                 :           9 :               remove = true;
    9580                 :             :             }
    9581                 :             :           else
    9582                 :             :             {
    9583                 :         219 :               t = mark_rvalue_use (t);
    9584                 :         219 :               if (!processing_template_decl)
    9585                 :             :                 {
    9586                 :         171 :                   t = maybe_constant_value (t);
    9587                 :         171 :                   if (TREE_CODE (t) != INTEGER_CST)
    9588                 :             :                     {
    9589                 :          16 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9590                 :             :                                 "%<hint%> expression must be constant integer "
    9591                 :             :                                 "expression");
    9592                 :          16 :                       remove = true;
    9593                 :             :                     }
    9594                 :             :                 }
    9595                 :         219 :               OMP_CLAUSE_HINT_EXPR (c) = t;
    9596                 :             :             }
    9597                 :             :           break;
    9598                 :             : 
    9599                 :         183 :         case OMP_CLAUSE_FILTER:
    9600                 :         183 :           t = OMP_CLAUSE_FILTER_EXPR (c);
    9601                 :         183 :           if (t == error_mark_node)
    9602                 :             :             remove = true;
    9603                 :         183 :           else if (!type_dependent_expression_p (t)
    9604                 :         183 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9605                 :             :             {
    9606                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
    9607                 :             :                         "%<filter%> expression must be integral");
    9608                 :           6 :               remove = true;
    9609                 :             :             }
    9610                 :             :           else
    9611                 :             :             {
    9612                 :         177 :               t = mark_rvalue_use (t);
    9613                 :         177 :               if (!processing_template_decl)
    9614                 :             :                 {
    9615                 :         174 :                   t = maybe_constant_value (t);
    9616                 :         174 :                   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    9617                 :             :                 }
    9618                 :         177 :               OMP_CLAUSE_FILTER_EXPR (c) = t;
    9619                 :             :             }
    9620                 :             :           break;
    9621                 :             : 
    9622                 :         432 :         case OMP_CLAUSE_IS_DEVICE_PTR:
    9623                 :         432 :         case OMP_CLAUSE_USE_DEVICE_PTR:
    9624                 :         432 :           field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
    9625                 :         432 :           t = OMP_CLAUSE_DECL (c);
    9626                 :         432 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
    9627                 :         328 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9628                 :         432 :           if (!type_dependent_expression_p (t))
    9629                 :             :             {
    9630                 :         430 :               tree type = TREE_TYPE (t);
    9631                 :         430 :               if (!TYPE_PTR_P (type)
    9632                 :         430 :                   && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
    9633                 :             :                 {
    9634                 :          57 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
    9635                 :          57 :                       && ort == C_ORT_OMP)
    9636                 :             :                     {
    9637                 :           3 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9638                 :             :                                 "%qs variable is neither a pointer "
    9639                 :             :                                 "nor reference to pointer",
    9640                 :           3 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9641                 :           3 :                       remove = true;
    9642                 :             :                     }
    9643                 :          54 :                   else if (TREE_CODE (type) != ARRAY_TYPE
    9644                 :          54 :                            && (!TYPE_REF_P (type)
    9645                 :           2 :                                || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
    9646                 :             :                     {
    9647                 :          12 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9648                 :             :                                 "%qs variable is neither a pointer, nor an "
    9649                 :             :                                 "array nor reference to pointer or array",
    9650                 :          12 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9651                 :          12 :                       remove = true;
    9652                 :             :                     }
    9653                 :             :                 }
    9654                 :             :             }
    9655                 :         432 :           goto check_dup_generic;
    9656                 :             : 
    9657                 :         266 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
    9658                 :         266 :           t = OMP_CLAUSE_DECL (c);
    9659                 :         266 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9660                 :             :             {
    9661                 :          28 :               if (handle_omp_array_sections (c, ort))
    9662                 :             :                 remove = true;
    9663                 :             :               else
    9664                 :             :                 {
    9665                 :          28 :                   t = OMP_CLAUSE_DECL (c);
    9666                 :          30 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
    9667                 :           2 :                     t = TREE_OPERAND (t, 0);
    9668                 :          64 :                   while (INDIRECT_REF_P (t)
    9669                 :          64 :                          || TREE_CODE (t) == ARRAY_REF)
    9670                 :          36 :                     t = TREE_OPERAND (t, 0);
    9671                 :             :                 }
    9672                 :             :             }
    9673                 :         266 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9674                 :             :             {
    9675                 :         266 :               bitmap_set_bit (&is_on_device_head, DECL_UID (t));
    9676                 :         266 :               if (!processing_template_decl
    9677                 :         266 :                   && !cxx_mark_addressable (t))
    9678                 :             :                 remove = true;
    9679                 :             :             }
    9680                 :         266 :           goto check_dup_generic_t;
    9681                 :             : 
    9682                 :          76 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
    9683                 :          76 :           field_ok = true;
    9684                 :          76 :           t = OMP_CLAUSE_DECL (c);
    9685                 :          76 :           if (!processing_template_decl
    9686                 :          74 :               && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
    9687                 :          74 :               && !TYPE_REF_P (TREE_TYPE (t))
    9688                 :         143 :               && !cxx_mark_addressable (t))
    9689                 :             :             remove = true;
    9690                 :          76 :           goto check_dup_generic;
    9691                 :             : 
    9692                 :             :         case OMP_CLAUSE_NOWAIT:
    9693                 :             :         case OMP_CLAUSE_DEFAULT:
    9694                 :             :         case OMP_CLAUSE_UNTIED:
    9695                 :             :         case OMP_CLAUSE_COLLAPSE:
    9696                 :             :         case OMP_CLAUSE_PARALLEL:
    9697                 :             :         case OMP_CLAUSE_FOR:
    9698                 :             :         case OMP_CLAUSE_SECTIONS:
    9699                 :             :         case OMP_CLAUSE_TASKGROUP:
    9700                 :             :         case OMP_CLAUSE_PROC_BIND:
    9701                 :             :         case OMP_CLAUSE_DEVICE_TYPE:
    9702                 :             :         case OMP_CLAUSE_NOGROUP:
    9703                 :             :         case OMP_CLAUSE_THREADS:
    9704                 :             :         case OMP_CLAUSE_SIMD:
    9705                 :             :         case OMP_CLAUSE_DEFAULTMAP:
    9706                 :             :         case OMP_CLAUSE_BIND:
    9707                 :             :         case OMP_CLAUSE_AUTO:
    9708                 :             :         case OMP_CLAUSE_INDEPENDENT:
    9709                 :             :         case OMP_CLAUSE_SEQ:
    9710                 :             :         case OMP_CLAUSE_IF_PRESENT:
    9711                 :             :         case OMP_CLAUSE_FINALIZE:
    9712                 :             :         case OMP_CLAUSE_NOHOST:
    9713                 :             :         case OMP_CLAUSE_INDIRECT:
    9714                 :             :           break;
    9715                 :             : 
    9716                 :         228 :         case OMP_CLAUSE_MERGEABLE:
    9717                 :         228 :           mergeable_seen = true;
    9718                 :         228 :           break;
    9719                 :             : 
    9720                 :         322 :         case OMP_CLAUSE_TILE:
    9721                 :         754 :           for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
    9722                 :         432 :                list = TREE_CHAIN (list))
    9723                 :             :             {
    9724                 :         432 :               t = TREE_VALUE (list);
    9725                 :             : 
    9726                 :         432 :               if (t == error_mark_node)
    9727                 :             :                 remove = true;
    9728                 :         403 :               else if (!type_dependent_expression_p (t)
    9729                 :         403 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9730                 :             :                 {
    9731                 :           3 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9732                 :             :                             "%<tile%> argument needs integral type");
    9733                 :           3 :                   remove = true;
    9734                 :             :                 }
    9735                 :             :               else
    9736                 :             :                 {
    9737                 :         400 :                   t = mark_rvalue_use (t);
    9738                 :         400 :                   if (!processing_template_decl)
    9739                 :             :                     {
    9740                 :             :                       /* Zero is used to indicate '*', we permit you
    9741                 :             :                          to get there via an ICE of value zero.  */
    9742                 :         385 :                       t = maybe_constant_value (t);
    9743                 :         385 :                       if (!tree_fits_shwi_p (t)
    9744                 :         369 :                           || tree_to_shwi (t) < 0)
    9745                 :             :                         {
    9746                 :          40 :                           error_at (OMP_CLAUSE_LOCATION (c),
    9747                 :             :                                     "%<tile%> argument needs positive "
    9748                 :             :                                     "integral constant");
    9749                 :          40 :                           remove = true;
    9750                 :             :                         }
    9751                 :             :                     }
    9752                 :             :                 }
    9753                 :             : 
    9754                 :             :                 /* Update list item.  */
    9755                 :         432 :               TREE_VALUE (list) = t;
    9756                 :             :             }
    9757                 :             :           break;
    9758                 :             : 
    9759                 :        1027 :         case OMP_CLAUSE_SIZES:
    9760                 :        1027 :           for (tree list = OMP_CLAUSE_SIZES_LIST (c);
    9761                 :        2688 :                !remove && list; list = TREE_CHAIN (list))
    9762                 :             :             {
    9763                 :        1661 :               t = TREE_VALUE (list);
    9764                 :             : 
    9765                 :        1661 :               if (t == error_mark_node)
    9766                 :           0 :                 t = integer_one_node;
    9767                 :        1661 :               else if (!type_dependent_expression_p (t)
    9768                 :        1661 :                        && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9769                 :             :                 {
    9770                 :           8 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9771                 :             :                             "%<sizes%> argument needs positive integral "
    9772                 :             :                             "constant");
    9773                 :           8 :                   t = integer_one_node;
    9774                 :             :                 }
    9775                 :             :               else
    9776                 :             :                 {
    9777                 :        1653 :                   t = mark_rvalue_use (t);
    9778                 :        1653 :                   if (!processing_template_decl)
    9779                 :             :                     {
    9780                 :        1636 :                       t = maybe_constant_value (t);
    9781                 :        1636 :                       HOST_WIDE_INT n;
    9782                 :        1636 :                       if (!tree_fits_shwi_p (t)
    9783                 :        1632 :                           || !INTEGRAL_TYPE_P (TREE_TYPE (t))
    9784                 :        1632 :                           || (n = tree_to_shwi (t)) <= 0
    9785                 :        3240 :                           || (int)n != n)
    9786                 :             :                         {
    9787                 :          32 :                           error_at (OMP_CLAUSE_LOCATION (c),
    9788                 :             :                                     "%<sizes%> argument needs positive "
    9789                 :             :                                     "integral constant");
    9790                 :          32 :                           t = integer_one_node;
    9791                 :             :                         }
    9792                 :             :                     }
    9793                 :             :                 }
    9794                 :             : 
    9795                 :             :               /* Update list item.  */
    9796                 :        1661 :               TREE_VALUE (list) = t;
    9797                 :             :             }
    9798                 :             :           break;
    9799                 :             : 
    9800                 :         627 :         case OMP_CLAUSE_ORDERED:
    9801                 :         627 :           ordered_seen = true;
    9802                 :         627 :           break;
    9803                 :             : 
    9804                 :        1546 :         case OMP_CLAUSE_ORDER:
    9805                 :        1546 :           if (order_seen)
    9806                 :             :             remove = true;
    9807                 :             :           else
    9808                 :             :             order_seen = true;
    9809                 :             :           break;
    9810                 :             : 
    9811                 :         638 :         case OMP_CLAUSE_INBRANCH:
    9812                 :         638 :         case OMP_CLAUSE_NOTINBRANCH:
    9813                 :         638 :           if (branch_seen)
    9814                 :             :             {
    9815                 :           3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9816                 :             :                         "%<inbranch%> clause is incompatible with "
    9817                 :             :                         "%<notinbranch%>");
    9818                 :           3 :               remove = true;
    9819                 :             :             }
    9820                 :             :           branch_seen = true;
    9821                 :             :           break;
    9822                 :             : 
    9823                 :         297 :         case OMP_CLAUSE_INCLUSIVE:
    9824                 :         297 :         case OMP_CLAUSE_EXCLUSIVE:
    9825                 :         297 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
    9826                 :         297 :           if (!t)
    9827                 :         297 :             t = OMP_CLAUSE_DECL (c);
    9828                 :         297 :           if (t == current_class_ptr)
    9829                 :             :             {
    9830                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
    9831                 :             :                         "%<this%> allowed in OpenMP only in %<declare simd%>"
    9832                 :             :                         " clauses");
    9833                 :           0 :               remove = true;
    9834                 :           0 :               break;
    9835                 :             :             }
    9836                 :         297 :           if (!VAR_P (t)
    9837                 :             :               && TREE_CODE (t) != PARM_DECL
    9838                 :             :               && TREE_CODE (t) != FIELD_DECL)
    9839                 :             :             {
    9840                 :           0 :               if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
    9841                 :             :                 break;
    9842                 :           0 :               if (DECL_P (t))
    9843                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9844                 :             :                           "%qD is not a variable in clause %qs", t,
    9845                 :           0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9846                 :             :               else
    9847                 :           0 :                 error_at (OMP_CLAUSE_LOCATION (c),
    9848                 :             :                           "%qE is not a variable in clause %qs", t,
    9849                 :           0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
    9850                 :             :               remove = true;
    9851                 :             :             }
    9852                 :             :           break;
    9853                 :             : 
    9854                 :             :         case OMP_CLAUSE_FULL:
    9855                 :             :           break;
    9856                 :             : 
    9857                 :         470 :         case OMP_CLAUSE_PARTIAL:
    9858                 :         470 :           partial_seen = true;
    9859                 :         470 :           t = OMP_CLAUSE_PARTIAL_EXPR (c);
    9860                 :         470 :           if (!t)
    9861                 :             :             break;
    9862                 :             : 
    9863                 :         313 :           if (t == error_mark_node)
    9864                 :             :             t = NULL_TREE;
    9865                 :         313 :           else if (!type_dependent_expression_p (t)
    9866                 :         313 :                    && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    9867                 :             :             {
    9868                 :           3 :               error_at (OMP_CLAUSE_LOCATION (c),
    9869                 :             :                         "%<partial%> argument needs positive constant "
    9870                 :             :                         "integer expression");
    9871                 :           3 :               t = NULL_TREE;
    9872                 :             :             }
    9873                 :             :           else
    9874                 :             :             {
    9875                 :         310 :               t = mark_rvalue_use (t);
    9876                 :         310 :               if (!processing_template_decl)
    9877                 :             :                 {
    9878                 :         292 :                   t = maybe_constant_value (t);
    9879                 :             : 
    9880                 :         292 :                   HOST_WIDE_INT n;
    9881                 :         584 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
    9882                 :         292 :                       || !tree_fits_shwi_p (t)
    9883                 :         286 :                       || (n = tree_to_shwi (t)) <= 0
    9884                 :         560 :                       || (int)n != n)
    9885                 :             :                     {
    9886                 :          24 :                       error_at (OMP_CLAUSE_LOCATION (c),
    9887                 :             :                                 "%<partial%> argument needs positive "
    9888                 :             :                                 "constant integer expression");
    9889                 :          24 :                       t = NULL_TREE;
    9890                 :             :                     }
    9891                 :             :                 }
    9892                 :             :             }
    9893                 :             : 
    9894                 :         313 :           OMP_CLAUSE_PARTIAL_EXPR (c) = t;
    9895                 :         313 :           break;
    9896                 :         549 :         case OMP_CLAUSE_INIT:
    9897                 :         549 :           init_seen = true;
    9898                 :         549 :           OMP_CLAUSE_INIT_PREFER_TYPE (c)
    9899                 :         549 :             = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
    9900                 :         549 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
    9901                 :         271 :             init_no_targetsync_clause = c;
    9902                 :             :           /* FALLTHRU */
    9903                 :         844 :         case OMP_CLAUSE_DESTROY:
    9904                 :         844 :         case OMP_CLAUSE_USE:
    9905                 :         844 :           init_use_destroy_seen = true;
    9906                 :         844 :           t = OMP_CLAUSE_DECL (c);
    9907                 :         844 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
    9908                 :             :             {
    9909                 :           9 :               error_at (OMP_CLAUSE_LOCATION (c),
    9910                 :             :                         "%qD appears more than once in action clauses", t);
    9911                 :           9 :               remove = true;
    9912                 :           9 :               break;
    9913                 :             :             }
    9914                 :         835 :           bitmap_set_bit (&generic_head, DECL_UID (t));
    9915                 :             :           /* FALLTHRU */
    9916                 :        1099 :         case OMP_CLAUSE_INTEROP:
    9917                 :        1099 :           if (!processing_template_decl)
    9918                 :             :             {
    9919                 :        1003 :               if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
    9920                 :             :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) &&  */
    9921                 :        1003 :                   !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
    9922                 :             :                 {
    9923                 :         126 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9924                 :             :                             "%qD must be of %<omp_interop_t%>",
    9925                 :          63 :                             OMP_CLAUSE_DECL (c));
    9926                 :          63 :                   remove = true;
    9927                 :             :                 }
    9928                 :         940 :               else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
    9929                 :         481 :                         || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
    9930                 :        1058 :                        && TREE_READONLY (OMP_CLAUSE_DECL (c)))
    9931                 :             :                 {
    9932                 :          36 :                   error_at (OMP_CLAUSE_LOCATION (c),
    9933                 :          18 :                             "%qD shall not be const", OMP_CLAUSE_DECL (c));
    9934                 :          18 :                   remove = true;
    9935                 :             :                 }
    9936                 :             :             }
    9937                 :        1099 :           pc = &OMP_CLAUSE_CHAIN (c);
    9938                 :        1099 :           break;
    9939                 :           0 :         default:
    9940                 :           0 :           gcc_unreachable ();
    9941                 :             :         }
    9942                 :             : 
    9943                 :       97238 :       if (remove)
    9944                 :             :         {
    9945                 :        2613 :           if (grp_start_p)
    9946                 :             :             {
    9947                 :             :               /* If we found a clause to remove, we want to remove the whole
    9948                 :             :                  expanded group, otherwise gimplify
    9949                 :             :                  (omp_resolve_clause_dependencies) can get confused.  */
    9950                 :         858 :               *grp_start_p = grp_sentinel;
    9951                 :         858 :               pc = grp_start_p;
    9952                 :         858 :               grp_start_p = NULL;
    9953                 :             :             }
    9954                 :             :           else
    9955                 :        1755 :             *pc = OMP_CLAUSE_CHAIN (c);
    9956                 :             :         }
    9957                 :             :       else
    9958                 :       94625 :         pc = &OMP_CLAUSE_CHAIN (c);
    9959                 :             :     }
    9960                 :             : 
    9961                 :       62565 :   if (grp_start_p
    9962                 :       62565 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
    9963                 :         131 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
    9964                 :          80 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
    9965                 :             : 
    9966                 :       62565 :   if (reduction_seen < 0 && (ordered_seen || schedule_seen))
    9967                 :       62565 :     reduction_seen = -2;
    9968                 :             : 
    9969                 :      158095 :   for (pc = &clauses, c = clauses; c ; c = *pc)
    9970                 :             :     {
    9971                 :       95530 :       enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
    9972                 :       95530 :       bool remove = false;
    9973                 :       95530 :       bool need_complete_type = false;
    9974                 :       95530 :       bool need_default_ctor = false;
    9975                 :       95530 :       bool need_copy_ctor = false;
    9976                 :       95530 :       bool need_copy_assignment = false;
    9977                 :       95530 :       bool need_implicitly_determined = false;
    9978                 :       95530 :       bool need_dtor = false;
    9979                 :       95530 :       tree type, inner_type;
    9980                 :             : 
    9981                 :       95530 :       switch (c_kind)
    9982                 :             :         {
    9983                 :             :         case OMP_CLAUSE_SHARED:
    9984                 :             :           need_implicitly_determined = true;
    9985                 :             :           break;
    9986                 :        2502 :         case OMP_CLAUSE_PRIVATE:
    9987                 :        2502 :           need_complete_type = true;
    9988                 :        2502 :           need_default_ctor = true;
    9989                 :        2502 :           need_dtor = true;
    9990                 :        2502 :           need_implicitly_determined = true;
    9991                 :        2502 :           break;
    9992                 :        3124 :         case OMP_CLAUSE_FIRSTPRIVATE:
    9993                 :        3124 :           need_complete_type = true;
    9994                 :        3124 :           need_copy_ctor = true;
    9995                 :        3124 :           need_dtor = true;
    9996                 :        3124 :           need_implicitly_determined = true;
    9997                 :        3124 :           break;
    9998                 :        2760 :         case OMP_CLAUSE_LASTPRIVATE:
    9999                 :        2760 :           need_complete_type = true;
   10000                 :        2760 :           need_copy_assignment = true;
   10001                 :        2760 :           need_implicitly_determined = true;
   10002                 :        2760 :           break;
   10003                 :        7430 :         case OMP_CLAUSE_REDUCTION:
   10004                 :        7430 :           if (reduction_seen == -2)
   10005                 :          27 :             OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   10006                 :        7430 :           if (OMP_CLAUSE_REDUCTION_INSCAN (c))
   10007                 :         421 :             need_copy_assignment = true;
   10008                 :             :           need_implicitly_determined = true;
   10009                 :             :           break;
   10010                 :             :         case OMP_CLAUSE_IN_REDUCTION:
   10011                 :             :         case OMP_CLAUSE_TASK_REDUCTION:
   10012                 :             :         case OMP_CLAUSE_INCLUSIVE:
   10013                 :             :         case OMP_CLAUSE_EXCLUSIVE:
   10014                 :             :           need_implicitly_determined = true;
   10015                 :             :           break;
   10016                 :        1532 :         case OMP_CLAUSE_LINEAR:
   10017                 :        1532 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   10018                 :             :             need_implicitly_determined = true;
   10019                 :         661 :           else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   10020                 :         703 :                    && !bitmap_bit_p (&map_head,
   10021                 :          42 :                                      DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   10022                 :             :             {
   10023                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10024                 :             :                         "%<linear%> clause step is a parameter %qD not "
   10025                 :             :                         "specified in %<uniform%> clause",
   10026                 :           6 :                         OMP_CLAUSE_LINEAR_STEP (c));
   10027                 :           6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10028                 :       74008 :               continue;
   10029                 :             :             }
   10030                 :             :           break;
   10031                 :             :         case OMP_CLAUSE_COPYPRIVATE:
   10032                 :         366 :           need_copy_assignment = true;
   10033                 :             :           break;
   10034                 :             :         case OMP_CLAUSE_COPYIN:
   10035                 :         366 :           need_copy_assignment = true;
   10036                 :             :           break;
   10037                 :         798 :         case OMP_CLAUSE_SIMDLEN:
   10038                 :         798 :           if (safelen
   10039                 :         345 :               && !processing_template_decl
   10040                 :        1143 :               && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   10041                 :         345 :                                   OMP_CLAUSE_SIMDLEN_EXPR (c)))
   10042                 :             :             {
   10043                 :           0 :               error_at (OMP_CLAUSE_LOCATION (c),
   10044                 :             :                         "%<simdlen%> clause value is bigger than "
   10045                 :             :                         "%<safelen%> clause value");
   10046                 :           0 :               OMP_CLAUSE_SIMDLEN_EXPR (c)
   10047                 :           0 :                 = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   10048                 :             :             }
   10049                 :         798 :           pc = &OMP_CLAUSE_CHAIN (c);
   10050                 :         798 :           continue;
   10051                 :        3847 :         case OMP_CLAUSE_SCHEDULE:
   10052                 :        3847 :           if (ordered_seen
   10053                 :        3847 :               && (OMP_CLAUSE_SCHEDULE_KIND (c)
   10054                 :             :                   & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   10055                 :             :             {
   10056                 :          21 :               error_at (OMP_CLAUSE_LOCATION (c),
   10057                 :             :                         "%<nonmonotonic%> schedule modifier specified "
   10058                 :             :                         "together with %<ordered%> clause");
   10059                 :          42 :               OMP_CLAUSE_SCHEDULE_KIND (c)
   10060                 :          21 :                 = (enum omp_clause_schedule_kind)
   10061                 :          21 :                   (OMP_CLAUSE_SCHEDULE_KIND (c)
   10062                 :             :                    & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   10063                 :             :             }
   10064                 :        3847 :           if (reduction_seen == -2)
   10065                 :           9 :             error_at (OMP_CLAUSE_LOCATION (c),
   10066                 :             :                       "%qs clause specified together with %<inscan%> "
   10067                 :             :                       "%<reduction%> clause", "schedule");
   10068                 :        3847 :           pc = &OMP_CLAUSE_CHAIN (c);
   10069                 :        3847 :           continue;
   10070                 :          51 :         case OMP_CLAUSE_NOGROUP:
   10071                 :          51 :           if (reduction_seen)
   10072                 :             :             {
   10073                 :           3 :               error_at (OMP_CLAUSE_LOCATION (c),
   10074                 :             :                         "%<nogroup%> clause must not be used together with "
   10075                 :             :                         "%<reduction%> clause");
   10076                 :           3 :               *pc = OMP_CLAUSE_CHAIN (c);
   10077                 :           3 :               continue;
   10078                 :             :             }
   10079                 :          48 :           pc = &OMP_CLAUSE_CHAIN (c);
   10080                 :          48 :           continue;
   10081                 :         165 :         case OMP_CLAUSE_GRAINSIZE:
   10082                 :         165 :           if (num_tasks_seen)
   10083                 :             :             {
   10084                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10085                 :             :                         "%<grainsize%> clause must not be used together with "
   10086                 :             :                         "%<num_tasks%> clause");
   10087                 :           6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10088                 :           6 :               continue;
   10089                 :             :             }
   10090                 :         159 :           pc = &OMP_CLAUSE_CHAIN (c);
   10091                 :         159 :           continue;
   10092                 :         627 :         case OMP_CLAUSE_ORDERED:
   10093                 :         627 :           if (reduction_seen == -2)
   10094                 :           6 :             error_at (OMP_CLAUSE_LOCATION (c),
   10095                 :             :                       "%qs clause specified together with %<inscan%> "
   10096                 :             :                       "%<reduction%> clause", "ordered");
   10097                 :         627 :           pc = &OMP_CLAUSE_CHAIN (c);
   10098                 :         627 :           continue;
   10099                 :        1522 :         case OMP_CLAUSE_ORDER:
   10100                 :        1522 :           if (ordered_seen)
   10101                 :             :             {
   10102                 :          12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10103                 :             :                         "%<order%> clause must not be used together "
   10104                 :             :                         "with %<ordered%> clause");
   10105                 :          12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10106                 :          12 :               continue;
   10107                 :             :             }
   10108                 :        1510 :           pc = &OMP_CLAUSE_CHAIN (c);
   10109                 :        1510 :           continue;
   10110                 :          57 :         case OMP_CLAUSE_DETACH:
   10111                 :          57 :           if (mergeable_seen)
   10112                 :             :             {
   10113                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10114                 :             :                         "%<detach%> clause must not be used together with "
   10115                 :             :                         "%<mergeable%> clause");
   10116                 :           6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10117                 :           6 :               continue;
   10118                 :             :             }
   10119                 :          51 :           pc = &OMP_CLAUSE_CHAIN (c);
   10120                 :          51 :           continue;
   10121                 :       15597 :         case OMP_CLAUSE_MAP:
   10122                 :       15597 :           if (target_in_reduction_seen && !processing_template_decl)
   10123                 :             :             {
   10124                 :         684 :               t = OMP_CLAUSE_DECL (c);
   10125                 :         684 :               while (handled_component_p (t)
   10126                 :             :                      || INDIRECT_REF_P (t)
   10127                 :             :                      || TREE_CODE (t) == ADDR_EXPR
   10128                 :             :                      || TREE_CODE (t) == MEM_REF
   10129                 :         804 :                      || TREE_CODE (t) == NON_LVALUE_EXPR)
   10130                 :         120 :                 t = TREE_OPERAND (t, 0);
   10131                 :         684 :               if (DECL_P (t)
   10132                 :         684 :                   && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   10133                 :         342 :                 OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   10134                 :             :             }
   10135                 :       15597 :           pc = &OMP_CLAUSE_CHAIN (c);
   10136                 :       15597 :           continue;
   10137                 :         225 :         case OMP_CLAUSE_FULL:
   10138                 :         225 :           if (partial_seen)
   10139                 :             :             {
   10140                 :          12 :               error_at (OMP_CLAUSE_LOCATION (c),
   10141                 :             :                         "%<full%> clause must not be used together "
   10142                 :             :                         "with %<partial%> clause");
   10143                 :          12 :               *pc = OMP_CLAUSE_CHAIN (c);
   10144                 :          12 :               continue;
   10145                 :             :             }
   10146                 :         213 :           pc = &OMP_CLAUSE_CHAIN (c);
   10147                 :         213 :           continue;
   10148                 :        6942 :         case OMP_CLAUSE_NOWAIT:
   10149                 :        6942 :           if (copyprivate_seen)
   10150                 :             :             {
   10151                 :           6 :               error_at (OMP_CLAUSE_LOCATION (c),
   10152                 :             :                         "%<nowait%> clause must not be used together "
   10153                 :             :                         "with %<copyprivate%> clause");
   10154                 :           6 :               *pc = OMP_CLAUSE_CHAIN (c);
   10155                 :           6 :               continue;
   10156                 :             :             }
   10157                 :             :           /* FALLTHRU */
   10158                 :       50421 :         default:
   10159                 :       50421 :           pc = &OMP_CLAUSE_CHAIN (c);
   10160                 :       50421 :           continue;
   10161                 :             :         }
   10162                 :             : 
   10163                 :       22208 :       t = OMP_CLAUSE_DECL (c);
   10164                 :       22208 :       switch (c_kind)
   10165                 :             :         {
   10166                 :        2760 :         case OMP_CLAUSE_LASTPRIVATE:
   10167                 :        2760 :           if (DECL_P (t)
   10168                 :        2760 :               && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
   10169                 :             :             {
   10170                 :        2663 :               need_default_ctor = true;
   10171                 :        2663 :               need_dtor = true;
   10172                 :             :             }
   10173                 :             :           break;
   10174                 :             : 
   10175                 :        9566 :         case OMP_CLAUSE_REDUCTION:
   10176                 :        9566 :         case OMP_CLAUSE_IN_REDUCTION:
   10177                 :        9566 :         case OMP_CLAUSE_TASK_REDUCTION:
   10178                 :        9566 :           if (allocate_seen)
   10179                 :             :             {
   10180                 :        1711 :               if (TREE_CODE (t) == MEM_REF)
   10181                 :             :                 {
   10182                 :         222 :                   t = TREE_OPERAND (t, 0);
   10183                 :         222 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   10184                 :           0 :                     t = TREE_OPERAND (t, 0);
   10185                 :         222 :                   if (TREE_CODE (t) == ADDR_EXPR
   10186                 :         168 :                       || INDIRECT_REF_P (t))
   10187                 :         110 :                     t = TREE_OPERAND (t, 0);
   10188                 :         222 :                   if (DECL_P (t))
   10189                 :         222 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10190                 :             :                 }
   10191                 :        1489 :               else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10192                 :             :                 {
   10193                 :         288 :                   while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   10194                 :         144 :                     t = TREE_OPERAND (t, 0);
   10195                 :         144 :                   if (DECL_P (t))
   10196                 :         144 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10197                 :         144 :                   t = OMP_CLAUSE_DECL (c);
   10198                 :             :                 }
   10199                 :        1345 :               else if (DECL_P (t))
   10200                 :        1345 :                 bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10201                 :        1711 :               t = OMP_CLAUSE_DECL (c);
   10202                 :             :             }
   10203                 :        9566 :           if (processing_template_decl
   10204                 :         926 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10205                 :             :             break;
   10206                 :        8948 :           if (finish_omp_reduction_clause (c, &need_default_ctor,
   10207                 :             :                                            &need_dtor))
   10208                 :             :             remove = true;
   10209                 :             :           else
   10210                 :        8864 :             t = OMP_CLAUSE_DECL (c);
   10211                 :             :           break;
   10212                 :             : 
   10213                 :         274 :         case OMP_CLAUSE_COPYIN:
   10214                 :         274 :           if (processing_template_decl
   10215                 :           0 :               && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10216                 :             :             break;
   10217                 :         274 :           if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
   10218                 :             :             {
   10219                 :          15 :               error_at (OMP_CLAUSE_LOCATION (c),
   10220                 :             :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   10221                 :          15 :               remove = true;
   10222                 :             :             }
   10223                 :             :           break;
   10224                 :             : 
   10225                 :             :         default:
   10226                 :             :           break;
   10227                 :             :         }
   10228                 :             : 
   10229                 :       22208 :       if (processing_template_decl
   10230                 :        1607 :           && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   10231                 :             :         {
   10232                 :         680 :           pc = &OMP_CLAUSE_CHAIN (c);
   10233                 :         680 :           continue;
   10234                 :             :         }
   10235                 :             : 
   10236                 :       21528 :       if (need_complete_type || need_copy_assignment)
   10237                 :             :         {
   10238                 :        9117 :           t = require_complete_type (t);
   10239                 :        9117 :           if (t == error_mark_node)
   10240                 :             :             remove = true;
   10241                 :        9093 :           else if (!processing_template_decl
   10242                 :        8710 :                    && TYPE_REF_P (TREE_TYPE (t))
   10243                 :        9621 :                    && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
   10244                 :             :             remove = true;
   10245                 :             :         }
   10246                 :       21528 :       if (need_implicitly_determined)
   10247                 :             :         {
   10248                 :       20508 :           const char *share_name = NULL;
   10249                 :             : 
   10250                 :       20508 :           if (allocate_seen
   10251                 :        5047 :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10252                 :       24676 :               && DECL_P (t))
   10253                 :        3883 :             bitmap_clear_bit (&aligned_head, DECL_UID (t));
   10254                 :             : 
   10255                 :       20508 :           if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
   10256                 :             :             share_name = "threadprivate";
   10257                 :       20466 :           else switch (cxx_omp_predetermined_sharing_1 (t))
   10258                 :             :             {
   10259                 :             :             case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   10260                 :             :               break;
   10261                 :          47 :             case OMP_CLAUSE_DEFAULT_SHARED:
   10262                 :          47 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10263                 :          30 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   10264                 :          64 :                   && c_omp_predefined_variable (t))
   10265                 :             :                 /* The __func__ variable and similar function-local predefined
   10266                 :             :                    variables may be listed in a shared or firstprivate
   10267                 :             :                    clause.  */
   10268                 :             :                 break;
   10269                 :          31 :               if (VAR_P (t)
   10270                 :          31 :                   && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10271                 :           9 :                   && TREE_STATIC (t)
   10272                 :          40 :                   && cxx_omp_const_qual_no_mutable (t))
   10273                 :             :                 {
   10274                 :           6 :                   tree ctx = CP_DECL_CONTEXT (t);
   10275                 :             :                   /* const qualified static data members without mutable
   10276                 :             :                      member may be specified in firstprivate clause.  */
   10277                 :           6 :                   if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
   10278                 :             :                     break;
   10279                 :             :                 }
   10280                 :             :               share_name = "shared";
   10281                 :             :               break;
   10282                 :             :             case OMP_CLAUSE_DEFAULT_PRIVATE:
   10283                 :             :               share_name = "private";
   10284                 :             :               break;
   10285                 :           0 :             default:
   10286                 :           0 :               gcc_unreachable ();
   10287                 :             :             }
   10288                 :             :           if (share_name)
   10289                 :             :             {
   10290                 :          67 :               error_at (OMP_CLAUSE_LOCATION (c),
   10291                 :             :                         "%qE is predetermined %qs for %qs",
   10292                 :             :                         omp_clause_printable_decl (t), share_name,
   10293                 :          67 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   10294                 :          67 :               remove = true;
   10295                 :             :             }
   10296                 :       20441 :           else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   10297                 :       18388 :                    && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
   10298                 :       35734 :                    && cxx_omp_const_qual_no_mutable (t))
   10299                 :             :             {
   10300                 :         126 :               error_at (OMP_CLAUSE_LOCATION (c),
   10301                 :             :                         "%<const%> qualified %qE without %<mutable%> member "
   10302                 :             :                         "may appear only in %<shared%> or %<firstprivate%> "
   10303                 :             :                         "clauses", omp_clause_printable_decl (t));
   10304                 :          63 :               remove = true;
   10305                 :             :             }
   10306                 :             :         }
   10307                 :             : 
   10308                 :       21528 :       if (detach_seen
   10309                 :          16 :           && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   10310                 :          10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   10311                 :          10 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   10312                 :           0 :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   10313                 :       21544 :           && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
   10314                 :             :         {
   10315                 :           6 :           error_at (OMP_CLAUSE_LOCATION (c),
   10316                 :             :                     "the event handle of a %<detach%> clause "
   10317                 :             :                     "should not be in a data-sharing clause");
   10318                 :           6 :           remove = true;
   10319                 :             :         }
   10320                 :             : 
   10321                 :             :       /* We're interested in the base element, not arrays.  */
   10322                 :       21528 :       inner_type = type = TREE_TYPE (t);
   10323                 :       21528 :       if ((need_complete_type
   10324                 :             :            || need_copy_assignment
   10325                 :       12411 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   10326                 :        5681 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   10327                 :        4211 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   10328                 :       30055 :           && TYPE_REF_P (inner_type))
   10329                 :         871 :         inner_type = TREE_TYPE (inner_type);
   10330                 :       24150 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   10331                 :        2622 :         inner_type = TREE_TYPE (inner_type);
   10332                 :             : 
   10333                 :             :       /* Check for special function availability by building a call to one.
   10334                 :             :          Save the results, because later we won't be in the right context
   10335                 :             :          for making these queries.  */
   10336                 :        2378 :       if (CLASS_TYPE_P (inner_type)
   10337                 :        2378 :           && COMPLETE_TYPE_P (inner_type)
   10338                 :        2312 :           && (need_default_ctor || need_copy_ctor
   10339                 :        1076 :               || need_copy_assignment || need_dtor)
   10340                 :        1988 :           && !type_dependent_expression_p (t)
   10341                 :       23516 :           && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
   10342                 :             :                                          need_copy_ctor, need_copy_assignment,
   10343                 :             :                                          need_dtor))
   10344                 :             :         remove = true;
   10345                 :             : 
   10346                 :       21528 :       if (!remove
   10347                 :       21528 :           && c_kind == OMP_CLAUSE_SHARED
   10348                 :        2050 :           && processing_template_decl)
   10349                 :             :         {
   10350                 :         125 :           t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
   10351                 :         125 :           if (t)
   10352                 :           5 :             OMP_CLAUSE_DECL (c) = t;
   10353                 :             :         }
   10354                 :             : 
   10355                 :       21528 :       if (remove)
   10356                 :         292 :         *pc = OMP_CLAUSE_CHAIN (c);
   10357                 :             :       else
   10358                 :       21236 :         pc = &OMP_CLAUSE_CHAIN (c);
   10359                 :             :     }
   10360                 :             : 
   10361                 :       62565 :   if (allocate_seen)
   10362                 :       17255 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   10363                 :             :       {
   10364                 :       14799 :         bool remove = false;
   10365                 :       14799 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   10366                 :        2694 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   10367                 :        2245 :             && DECL_P (OMP_CLAUSE_DECL (c))
   10368                 :       17044 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   10369                 :             :           {
   10370                 :          15 :             error_at (OMP_CLAUSE_LOCATION (c),
   10371                 :             :                       "%qD specified in %<allocate%> clause but not in "
   10372                 :          15 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   10373                 :          15 :             remove = true;
   10374                 :             :           }
   10375                 :       14799 :         if (remove)
   10376                 :          15 :           *pc = OMP_CLAUSE_CHAIN (c);
   10377                 :             :         else
   10378                 :       14784 :           pc = &OMP_CLAUSE_CHAIN (c);
   10379                 :             :       }
   10380                 :             : 
   10381                 :       62565 :   if (ort == C_ORT_OMP_INTEROP
   10382                 :       62565 :       && depend_clause
   10383                 :          60 :       && (!init_use_destroy_seen
   10384                 :          57 :           || (init_seen && init_no_targetsync_clause)))
   10385                 :             :     {
   10386                 :           9 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   10387                 :             :                 "%<depend%> clause requires action clauses with "
   10388                 :             :                 "%<targetsync%> interop-type");
   10389                 :           9 :       if (init_no_targetsync_clause)
   10390                 :           6 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   10391                 :             :                 "%<init%> clause lacks the %<targetsync%> modifier");
   10392                 :             :     }
   10393                 :             : 
   10394                 :       62565 :   bitmap_obstack_release (NULL);
   10395                 :       62565 :   return clauses;
   10396                 :             : }
   10397                 :             : 
   10398                 :             : /* Start processing OpenMP clauses that can include any
   10399                 :             :    privatization clauses for non-static data members.  */
   10400                 :             : 
   10401                 :             : tree
   10402                 :       48431 : push_omp_privatization_clauses (bool ignore_next)
   10403                 :             : {
   10404                 :       48431 :   if (omp_private_member_ignore_next)
   10405                 :             :     {
   10406                 :         710 :       omp_private_member_ignore_next = ignore_next;
   10407                 :         710 :       return NULL_TREE;
   10408                 :             :     }
   10409                 :       47721 :   omp_private_member_ignore_next = ignore_next;
   10410                 :       47721 :   if (omp_private_member_map)
   10411                 :          24 :     omp_private_member_vec.safe_push (error_mark_node);
   10412                 :       47721 :   return push_stmt_list ();
   10413                 :             : }
   10414                 :             : 
   10415                 :             : /* Revert remapping of any non-static data members since
   10416                 :             :    the last push_omp_privatization_clauses () call.  */
   10417                 :             : 
   10418                 :             : void
   10419                 :       48425 : pop_omp_privatization_clauses (tree stmt)
   10420                 :             : {
   10421                 :       48425 :   if (stmt == NULL_TREE)
   10422                 :             :     return;
   10423                 :       47715 :   stmt = pop_stmt_list (stmt);
   10424                 :       47715 :   if (omp_private_member_map)
   10425                 :             :     {
   10426                 :        1280 :       while (!omp_private_member_vec.is_empty ())
   10427                 :             :         {
   10428                 :         850 :           tree t = omp_private_member_vec.pop ();
   10429                 :         850 :           if (t == error_mark_node)
   10430                 :             :             {
   10431                 :          24 :               add_stmt (stmt);
   10432                 :          24 :               return;
   10433                 :             :             }
   10434                 :         826 :           bool no_decl_expr = t == integer_zero_node;
   10435                 :         826 :           if (no_decl_expr)
   10436                 :         136 :             t = omp_private_member_vec.pop ();
   10437                 :         826 :           tree *v = omp_private_member_map->get (t);
   10438                 :         826 :           gcc_assert (v);
   10439                 :         826 :           if (!no_decl_expr)
   10440                 :         690 :             add_decl_expr (*v);
   10441                 :         826 :           omp_private_member_map->remove (t);
   10442                 :             :         }
   10443                 :         860 :       delete omp_private_member_map;
   10444                 :         430 :       omp_private_member_map = NULL;
   10445                 :             :     }
   10446                 :       47691 :   add_stmt (stmt);
   10447                 :             : }
   10448                 :             : 
   10449                 :             : /* Remember OpenMP privatization clauses mapping and clear it.
   10450                 :             :    Used for lambdas.  */
   10451                 :             : 
   10452                 :             : void
   10453                 :     8186254 : save_omp_privatization_clauses (vec<tree> &save)
   10454                 :             : {
   10455                 :     8186254 :   save = vNULL;
   10456                 :     8186254 :   if (omp_private_member_ignore_next)
   10457                 :           2 :     save.safe_push (integer_one_node);
   10458                 :     8186254 :   omp_private_member_ignore_next = false;
   10459                 :     8186254 :   if (!omp_private_member_map)
   10460                 :             :     return;
   10461                 :             : 
   10462                 :           0 :   while (!omp_private_member_vec.is_empty ())
   10463                 :             :     {
   10464                 :           0 :       tree t = omp_private_member_vec.pop ();
   10465                 :           0 :       if (t == error_mark_node)
   10466                 :             :         {
   10467                 :           0 :           save.safe_push (t);
   10468                 :           0 :           continue;
   10469                 :             :         }
   10470                 :           0 :       tree n = t;
   10471                 :           0 :       if (t == integer_zero_node)
   10472                 :           0 :         t = omp_private_member_vec.pop ();
   10473                 :           0 :       tree *v = omp_private_member_map->get (t);
   10474                 :           0 :       gcc_assert (v);
   10475                 :           0 :       save.safe_push (*v);
   10476                 :           0 :       save.safe_push (t);
   10477                 :           0 :       if (n != t)
   10478                 :           0 :         save.safe_push (n);
   10479                 :             :     }
   10480                 :           0 :   delete omp_private_member_map;
   10481                 :           0 :   omp_private_member_map = NULL;
   10482                 :             : }
   10483                 :             : 
   10484                 :             : /* Restore OpenMP privatization clauses mapping saved by the
   10485                 :             :    above function.  */
   10486                 :             : 
   10487                 :             : void
   10488                 :     8186254 : restore_omp_privatization_clauses (vec<tree> &save)
   10489                 :             : {
   10490                 :     8186254 :   gcc_assert (omp_private_member_vec.is_empty ());
   10491                 :     8186254 :   omp_private_member_ignore_next = false;
   10492                 :     8186254 :   if (save.is_empty ())
   10493                 :             :     return;
   10494                 :           4 :   if (save.length () == 1 && save[0] == integer_one_node)
   10495                 :             :     {
   10496                 :           2 :       omp_private_member_ignore_next = true;
   10497                 :           2 :       save.release ();
   10498                 :           2 :       return;
   10499                 :             :     }
   10500                 :             : 
   10501                 :           0 :   omp_private_member_map = new hash_map <tree, tree>;
   10502                 :           0 :   while (!save.is_empty ())
   10503                 :             :     {
   10504                 :           0 :       tree t = save.pop ();
   10505                 :           0 :       tree n = t;
   10506                 :           0 :       if (t != error_mark_node)
   10507                 :             :         {
   10508                 :           0 :           if (t == integer_one_node)
   10509                 :             :             {
   10510                 :           0 :               omp_private_member_ignore_next = true;
   10511                 :           0 :               gcc_assert (save.is_empty ());
   10512                 :           0 :               break;
   10513                 :             :             }
   10514                 :           0 :           if (t == integer_zero_node)
   10515                 :           0 :             t = save.pop ();
   10516                 :           0 :           tree &v = omp_private_member_map->get_or_insert (t);
   10517                 :           0 :           v = save.pop ();
   10518                 :             :         }
   10519                 :           0 :       omp_private_member_vec.safe_push (t);
   10520                 :           0 :       if (n != t)
   10521                 :           0 :         omp_private_member_vec.safe_push (n);
   10522                 :             :     }
   10523                 :           0 :   save.release ();
   10524                 :             : }
   10525                 :             : 
   10526                 :             : /* For all variables in the tree_list VARS, mark them as thread local.  */
   10527                 :             : 
   10528                 :             : void
   10529                 :         241 : finish_omp_threadprivate (tree vars)
   10530                 :             : {
   10531                 :         241 :   tree t;
   10532                 :             : 
   10533                 :             :   /* Mark every variable in VARS to be assigned thread local storage.  */
   10534                 :         515 :   for (t = vars; t; t = TREE_CHAIN (t))
   10535                 :             :     {
   10536                 :         274 :       tree v = TREE_PURPOSE (t);
   10537                 :         274 :       location_t loc = EXPR_LOCATION (TREE_VALUE (t));
   10538                 :             : 
   10539                 :         274 :       if (error_operand_p (v))
   10540                 :             :         ;
   10541                 :         274 :       else if (!VAR_P (v))
   10542                 :           6 :         error_at (loc, "%<threadprivate%> %qD is not file, namespace "
   10543                 :             :                        "or block scope variable", v);
   10544                 :             :       /* If V had already been marked threadprivate, it doesn't matter
   10545                 :             :          whether it had been used prior to this point.  */
   10546                 :         268 :       else if (TREE_USED (v)
   10547                 :         268 :           && (DECL_LANG_SPECIFIC (v) == NULL
   10548                 :           3 :               || !CP_DECL_THREADPRIVATE_P (v)))
   10549                 :           6 :         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
   10550                 :         262 :       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
   10551                 :           6 :         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
   10552                 :         256 :       else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
   10553                 :           3 :         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
   10554                 :         204 :       else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
   10555                 :         276 :                && CP_DECL_CONTEXT (v) != current_class_type)
   10556                 :           6 :         error_at (loc, "%<threadprivate%> %qE directive not "
   10557                 :           6 :                        "in %qT definition", v, CP_DECL_CONTEXT (v));
   10558                 :             :       else
   10559                 :             :         {
   10560                 :             :           /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
   10561                 :         247 :           if (DECL_LANG_SPECIFIC (v) == NULL)
   10562                 :         203 :             retrofit_lang_decl (v);
   10563                 :             : 
   10564                 :         247 :           if (! CP_DECL_THREAD_LOCAL_P (v))
   10565                 :             :             {
   10566                 :         247 :               CP_DECL_THREAD_LOCAL_P (v) = true;
   10567                 :         247 :               set_decl_tls_model (v, decl_default_tls_model (v));
   10568                 :             :               /* If rtl has been already set for this var, call
   10569                 :             :                  make_decl_rtl once again, so that encode_section_info
   10570                 :             :                  has a chance to look at the new decl flags.  */
   10571                 :         247 :               if (DECL_RTL_SET_P (v))
   10572                 :           0 :                 make_decl_rtl (v);
   10573                 :             :             }
   10574                 :         247 :           CP_DECL_THREADPRIVATE_P (v) = 1;
   10575                 :             :         }
   10576                 :             :     }
   10577                 :         241 : }
   10578                 :             : 
   10579                 :             : /* Build an OpenMP structured block.  */
   10580                 :             : 
   10581                 :             : tree
   10582                 :       64019 : begin_omp_structured_block (void)
   10583                 :             : {
   10584                 :       64019 :   return do_pushlevel (sk_omp);
   10585                 :             : }
   10586                 :             : 
   10587                 :             : tree
   10588                 :       63998 : finish_omp_structured_block (tree block)
   10589                 :             : {
   10590                 :       63998 :   return do_poplevel (block);
   10591                 :             : }
   10592                 :             : 
   10593                 :             : /* Similarly, except force the retention of the BLOCK.  */
   10594                 :             : 
   10595                 :             : tree
   10596                 :       14912 : begin_omp_parallel (void)
   10597                 :             : {
   10598                 :       14912 :   keep_next_level (true);
   10599                 :       14912 :   return begin_omp_structured_block ();
   10600                 :             : }
   10601                 :             : 
   10602                 :             : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   10603                 :             :    statement.  */
   10604                 :             : 
   10605                 :             : tree
   10606                 :         768 : finish_oacc_data (tree clauses, tree block)
   10607                 :             : {
   10608                 :         768 :   tree stmt;
   10609                 :             : 
   10610                 :         768 :   block = finish_omp_structured_block (block);
   10611                 :             : 
   10612                 :         768 :   stmt = make_node (OACC_DATA);
   10613                 :         768 :   TREE_TYPE (stmt) = void_type_node;
   10614                 :         768 :   OACC_DATA_CLAUSES (stmt) = clauses;
   10615                 :         768 :   OACC_DATA_BODY (stmt) = block;
   10616                 :             : 
   10617                 :         768 :   return add_stmt (stmt);
   10618                 :             : }
   10619                 :             : 
   10620                 :             : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   10621                 :             :    statement.  */
   10622                 :             : 
   10623                 :             : tree
   10624                 :          55 : finish_oacc_host_data (tree clauses, tree block)
   10625                 :             : {
   10626                 :          55 :   tree stmt;
   10627                 :             : 
   10628                 :          55 :   block = finish_omp_structured_block (block);
   10629                 :             : 
   10630                 :          55 :   stmt = make_node (OACC_HOST_DATA);
   10631                 :          55 :   TREE_TYPE (stmt) = void_type_node;
   10632                 :          55 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   10633                 :          55 :   OACC_HOST_DATA_BODY (stmt) = block;
   10634                 :             : 
   10635                 :          55 :   return add_stmt (stmt);
   10636                 :             : }
   10637                 :             : 
   10638                 :             : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   10639                 :             :    statement.  */
   10640                 :             : 
   10641                 :             : tree
   10642                 :        4690 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
   10643                 :             : {
   10644                 :        4690 :   body = finish_omp_structured_block (body);
   10645                 :             : 
   10646                 :        4690 :   tree stmt = make_node (code);
   10647                 :        4690 :   TREE_TYPE (stmt) = void_type_node;
   10648                 :        4690 :   OMP_BODY (stmt) = body;
   10649                 :        4690 :   OMP_CLAUSES (stmt) = clauses;
   10650                 :             : 
   10651                 :        4690 :   return add_stmt (stmt);
   10652                 :             : }
   10653                 :             : 
   10654                 :             : /* Used to walk OpenMP target directive body.  */
   10655                 :             : 
   10656                 :             : struct omp_target_walk_data
   10657                 :             : {
   10658                 :             :   /* Holds the 'this' expression found in current function.  */
   10659                 :             :   tree current_object;
   10660                 :             : 
   10661                 :             :   /* True if the 'this' expression was accessed in the target body.  */
   10662                 :             :   bool this_expr_accessed;
   10663                 :             : 
   10664                 :             :   /* For non-static functions, record which pointer-typed members were
   10665                 :             :      accessed, and the whole expression.  */
   10666                 :             :   hash_map<tree, tree> ptr_members_accessed;
   10667                 :             : 
   10668                 :             :   /* Record which lambda objects were accessed in target body.  */
   10669                 :             :   hash_set<tree> lambda_objects_accessed;
   10670                 :             : 
   10671                 :             :   /* For lambda functions, the __closure object expression of the current
   10672                 :             :      function, and the set of captured variables accessed in target body.  */
   10673                 :             :   tree current_closure;
   10674                 :             :   hash_set<tree> closure_vars_accessed;
   10675                 :             : 
   10676                 :             :   /* Local variables declared inside a BIND_EXPR, used to filter out such
   10677                 :             :      variables when recording lambda_objects_accessed.  */
   10678                 :             :   hash_set<tree> local_decls;
   10679                 :             : 
   10680                 :             :   omp_mapper_list<tree> *mappers;
   10681                 :             : };
   10682                 :             : 
   10683                 :             : /* Helper function of finish_omp_target_clauses, called via
   10684                 :             :    cp_walk_tree_without_duplicates.  Traverse body of OpenMP target
   10685                 :             :    directive *TP, and fill out omp_target_walk_data passed in *PTR.  */
   10686                 :             : 
   10687                 :             : static tree
   10688                 :      225176 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
   10689                 :             : {
   10690                 :      225176 :   tree t = *tp;
   10691                 :      225176 :   struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
   10692                 :      225176 :   tree current_object = data->current_object;
   10693                 :      225176 :   tree current_closure = data->current_closure;
   10694                 :      225176 :   omp_mapper_list<tree> *mlist = data->mappers;
   10695                 :             : 
   10696                 :             :   /* References inside of these expression codes shouldn't incur any
   10697                 :             :      form of mapping, so return early.  */
   10698                 :      225176 :   if (TREE_CODE (t) == SIZEOF_EXPR
   10699                 :      225168 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   10700                 :             :     {
   10701                 :           8 :       *walk_subtrees = 0;
   10702                 :           8 :       return NULL_TREE;
   10703                 :             :     }
   10704                 :             : 
   10705                 :      225168 :   if (TREE_CODE (t) == OMP_CLAUSE)
   10706                 :             :     return NULL_TREE;
   10707                 :             : 
   10708                 :      212590 :   if (!processing_template_decl)
   10709                 :             :     {
   10710                 :      212590 :       tree aggr_type = NULL_TREE;
   10711                 :             : 
   10712                 :      212590 :       if (TREE_CODE (t) == COMPONENT_REF
   10713                 :      212590 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   10714                 :        2231 :         aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   10715                 :      210359 :       else if ((TREE_CODE (t) == VAR_DECL
   10716                 :             :                 || TREE_CODE (t) == PARM_DECL
   10717                 :             :                 || TREE_CODE (t) == RESULT_DECL)
   10718                 :       16803 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   10719                 :        1247 :         aggr_type = TREE_TYPE (t);
   10720                 :             : 
   10721                 :        3478 :       if (aggr_type)
   10722                 :             :         {
   10723                 :        3478 :           tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
   10724                 :        3478 :           if (mapper_fn)
   10725                 :         167 :             mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   10726                 :             :         }
   10727                 :             :     }
   10728                 :             : 
   10729                 :      212590 :   if (current_object)
   10730                 :             :     {
   10731                 :        2472 :       tree this_expr = TREE_OPERAND (current_object, 0);
   10732                 :             : 
   10733                 :        2472 :       if (operand_equal_p (t, this_expr))
   10734                 :             :         {
   10735                 :          35 :           data->this_expr_accessed = true;
   10736                 :          35 :           *walk_subtrees = 0;
   10737                 :          35 :           return NULL_TREE;
   10738                 :             :         }
   10739                 :             : 
   10740                 :        2437 :       if (TREE_CODE (t) == COMPONENT_REF
   10741                 :         115 :           && POINTER_TYPE_P (TREE_TYPE (t))
   10742                 :          36 :           && operand_equal_p (TREE_OPERAND (t, 0), current_object)
   10743                 :        2471 :           && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
   10744                 :             :         {
   10745                 :          34 :           data->this_expr_accessed = true;
   10746                 :          34 :           tree fld = TREE_OPERAND (t, 1);
   10747                 :          34 :           if (data->ptr_members_accessed.get (fld) == NULL)
   10748                 :             :             {
   10749                 :          14 :               if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
   10750                 :           4 :                 t = convert_from_reference (t);
   10751                 :          14 :               data->ptr_members_accessed.put (fld, t);
   10752                 :             :             }
   10753                 :          34 :           *walk_subtrees = 0;
   10754                 :          34 :           return NULL_TREE;
   10755                 :             :         }
   10756                 :             :     }
   10757                 :             : 
   10758                 :             :   /* When the current_function_decl is a lambda function, the closure object
   10759                 :             :      argument's type seems to not yet have fields layed out, so a recording
   10760                 :             :      of DECL_VALUE_EXPRs during the target body walk seems the only way to
   10761                 :             :      find them.  */
   10762                 :      212521 :   if (current_closure
   10763                 :         300 :       && (VAR_P (t)
   10764                 :             :           || TREE_CODE (t) == PARM_DECL
   10765                 :             :           || TREE_CODE (t) == RESULT_DECL)
   10766                 :          24 :       && DECL_HAS_VALUE_EXPR_P (t)
   10767                 :          10 :       && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
   10768                 :      212531 :       && operand_equal_p (current_closure,
   10769                 :          10 :                           TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
   10770                 :             :     {
   10771                 :           9 :       if (!data->closure_vars_accessed.contains (t))
   10772                 :           9 :         data->closure_vars_accessed.add (t);
   10773                 :           9 :       *walk_subtrees = 0;
   10774                 :           9 :       return NULL_TREE;
   10775                 :             :     }
   10776                 :             : 
   10777                 :      212512 :   if (TREE_CODE (t) == BIND_EXPR)
   10778                 :             :     {
   10779                 :       19650 :       if (tree block = BIND_EXPR_BLOCK (t))
   10780                 :       22052 :         for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
   10781                 :        2406 :           if (!data->local_decls.contains (var))
   10782                 :        2406 :             data->local_decls.add (var);
   10783                 :       19650 :       return NULL_TREE;
   10784                 :             :     }
   10785                 :             : 
   10786                 :      197464 :   if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
   10787                 :             :     {
   10788                 :          39 :       tree lt = TREE_TYPE (t);
   10789                 :          39 :       gcc_assert (CLASS_TYPE_P (lt));
   10790                 :             : 
   10791                 :          39 :       if (!data->lambda_objects_accessed.contains (t)
   10792                 :             :           /* Do not prepare to create target maps for locally declared
   10793                 :             :              lambdas or anonymous ones.  */
   10794                 :          39 :           && !data->local_decls.contains (t)
   10795                 :          72 :           && TREE_CODE (t) != TARGET_EXPR)
   10796                 :          13 :         data->lambda_objects_accessed.add (t);
   10797                 :          39 :       *walk_subtrees = 0;
   10798                 :          39 :       return NULL_TREE;
   10799                 :             :     }
   10800                 :             : 
   10801                 :             :   return NULL_TREE;
   10802                 :             : }
   10803                 :             : 
   10804                 :             : /* Helper function for finish_omp_target, and also from tsubst_expr.
   10805                 :             :    Create additional clauses for mapping of non-static members, lambda objects,
   10806                 :             :    etc.  */
   10807                 :             : 
   10808                 :             : void
   10809                 :        6663 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
   10810                 :             : {
   10811                 :        6663 :   omp_target_walk_data data;
   10812                 :        6663 :   data.this_expr_accessed = false;
   10813                 :        6663 :   data.current_object = NULL_TREE;
   10814                 :             : 
   10815                 :        6663 :   if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
   10816                 :          96 :     if (tree ct = current_nonlambda_class_type ())
   10817                 :             :       {
   10818                 :          95 :         tree object = maybe_dummy_object (ct, NULL);
   10819                 :          95 :         object = maybe_resolve_dummy (object, true);
   10820                 :          95 :         data.current_object = object;
   10821                 :             :       }
   10822                 :             : 
   10823                 :        6663 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   10824                 :             :     {
   10825                 :           8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   10826                 :           8 :       data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   10827                 :             :     }
   10828                 :             :   else
   10829                 :        6655 :     data.current_closure = NULL_TREE;
   10830                 :             : 
   10831                 :        6663 :   auto_vec<tree, 16> new_clauses;
   10832                 :             : 
   10833                 :        6663 :   if (!processing_template_decl)
   10834                 :             :     {
   10835                 :        6663 :       hash_set<omp_name_type<tree> > seen_types;
   10836                 :        6663 :       auto_vec<tree> mapper_fns;
   10837                 :        6663 :       omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
   10838                 :        6663 :       data.mappers = &mlist;
   10839                 :             : 
   10840                 :        6663 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   10841                 :             :                                        &data);
   10842                 :             : 
   10843                 :        6663 :       unsigned int i;
   10844                 :        6663 :       tree mapper_fn;
   10845                 :       13412 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   10846                 :          86 :         c_omp_find_nested_mappers (&mlist, mapper_fn);
   10847                 :             : 
   10848                 :        6812 :       FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
   10849                 :             :         {
   10850                 :          86 :           tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
   10851                 :          86 :           if (mapper == error_mark_node)
   10852                 :           0 :             continue;
   10853                 :          86 :           tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   10854                 :          86 :           tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   10855                 :          86 :           if (BASELINK_P (mapper_fn))
   10856                 :           0 :             mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
   10857                 :             : 
   10858                 :          86 :           tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   10859                 :          86 :           OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   10860                 :          86 :           OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   10861                 :          86 :           OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
   10862                 :             : 
   10863                 :          86 :           new_clauses.safe_push (c);
   10864                 :             :         }
   10865                 :        6663 :     }
   10866                 :             :   else
   10867                 :             :     {
   10868                 :           0 :       data.mappers = NULL;
   10869                 :           0 :       cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
   10870                 :             :                                        &data);
   10871                 :             :     }
   10872                 :             : 
   10873                 :        6663 :   tree omp_target_this_expr = NULL_TREE;
   10874                 :        6663 :   tree *explicit_this_deref_map = NULL;
   10875                 :        6663 :   if (data.this_expr_accessed)
   10876                 :             :     {
   10877                 :          31 :       omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
   10878                 :             : 
   10879                 :             :       /* See if explicit user-specified map(this[:]) clause already exists.
   10880                 :             :          If not, we create an implicit map(tofrom:this[:1]) clause.  */
   10881                 :          80 :       for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
   10882                 :          50 :         if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
   10883                 :          47 :             && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
   10884                 :          40 :                 || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
   10885                 :          57 :             && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
   10886                 :             :                                 omp_target_this_expr))
   10887                 :             :           {
   10888                 :             :             explicit_this_deref_map = cp;
   10889                 :             :             break;
   10890                 :             :           }
   10891                 :             :     }
   10892                 :             : 
   10893                 :        6663 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   10894                 :        6663 :       && (data.this_expr_accessed
   10895                 :           1 :           || !data.closure_vars_accessed.is_empty ()))
   10896                 :             :     {
   10897                 :             :       /* For lambda functions, we need to first create a copy of the
   10898                 :             :          __closure object.  */
   10899                 :           8 :       tree closure = DECL_ARGUMENTS (current_function_decl);
   10900                 :           8 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   10901                 :           8 :       OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
   10902                 :           8 :       OMP_CLAUSE_DECL (c)
   10903                 :           8 :         = build_indirect_ref (loc, closure, RO_UNARY_STAR);
   10904                 :           8 :       OMP_CLAUSE_SIZE (c)
   10905                 :           8 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
   10906                 :           8 :       new_clauses.safe_push (c);
   10907                 :             : 
   10908                 :           8 :       tree closure_obj = OMP_CLAUSE_DECL (c);
   10909                 :           8 :       tree closure_type = TREE_TYPE (closure_obj);
   10910                 :             : 
   10911                 :          16 :       gcc_assert (LAMBDA_TYPE_P (closure_type)
   10912                 :             :                   && CLASS_TYPE_P (closure_type));
   10913                 :             : 
   10914                 :           8 :       tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   10915                 :           8 :       OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
   10916                 :           8 :       OMP_CLAUSE_DECL (c2) = closure;
   10917                 :           8 :       OMP_CLAUSE_SIZE (c2) = size_zero_node;
   10918                 :           8 :       new_clauses.safe_push (c2);
   10919                 :             :     }
   10920                 :             : 
   10921                 :        6663 :   if (data.this_expr_accessed)
   10922                 :             :     {
   10923                 :             :       /* If the this-expr was accessed, create a map(*this) clause.  */
   10924                 :          31 :       enum gomp_map_kind kind = GOMP_MAP_TOFROM;
   10925                 :          31 :       if (explicit_this_deref_map)
   10926                 :             :         {
   10927                 :           1 :           tree this_map = *explicit_this_deref_map;
   10928                 :           1 :           tree nc = OMP_CLAUSE_CHAIN (this_map);
   10929                 :           2 :           gcc_assert (nc != NULL_TREE
   10930                 :             :                       && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   10931                 :             :                       && (OMP_CLAUSE_MAP_KIND (nc)
   10932                 :             :                           == GOMP_MAP_FIRSTPRIVATE_POINTER));
   10933                 :           1 :           kind = OMP_CLAUSE_MAP_KIND (this_map);
   10934                 :             :           /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
   10935                 :             :              two-map sequence away from the chain.  */
   10936                 :           1 :           *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
   10937                 :             :         }
   10938                 :          31 :       tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   10939                 :          31 :       OMP_CLAUSE_SET_MAP_KIND (c, kind);
   10940                 :          31 :       OMP_CLAUSE_DECL (c)
   10941                 :          31 :         = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
   10942                 :          31 :       OMP_CLAUSE_SIZE (c)
   10943                 :          31 :         = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
   10944                 :          31 :       new_clauses.safe_push (c);
   10945                 :             : 
   10946                 :             :       /* If we're in a lambda function, the this-pointer will actually be
   10947                 :             :          '__closure->this', a mapped member of __closure, hence always_pointer.
   10948                 :             :          Otherwise it's a firstprivate pointer.  */
   10949                 :          31 :       enum gomp_map_kind ptr_kind
   10950                 :          31 :         = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
   10951                 :          31 :            ? GOMP_MAP_ALWAYS_POINTER
   10952                 :          24 :            : GOMP_MAP_FIRSTPRIVATE_POINTER);
   10953                 :          31 :       c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   10954                 :          31 :       OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   10955                 :          31 :       OMP_CLAUSE_DECL (c) = omp_target_this_expr;
   10956                 :          31 :       OMP_CLAUSE_SIZE (c) = size_zero_node;
   10957                 :          31 :       new_clauses.safe_push (c);
   10958                 :             :     }
   10959                 :             : 
   10960                 :        6663 :   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
   10961                 :             :     {
   10962                 :           8 :       if (omp_target_this_expr)
   10963                 :             :         {
   10964                 :           7 :           STRIP_NOPS (omp_target_this_expr);
   10965                 :           7 :           gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
   10966                 :           7 :           omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
   10967                 :             :         }
   10968                 :             : 
   10969                 :          17 :       for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
   10970                 :          34 :            i != data.closure_vars_accessed.end (); ++i)
   10971                 :             :         {
   10972                 :           9 :           tree orig_decl = *i;
   10973                 :           9 :           tree closure_expr = DECL_VALUE_EXPR (orig_decl);
   10974                 :             : 
   10975                 :           9 :           if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
   10976                 :           9 :               || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
   10977                 :             :             {
   10978                 :             :               /* this-pointer is processed above, outside this loop.  */
   10979                 :           3 :               if (omp_target_this_expr
   10980                 :           3 :                   && operand_equal_p (closure_expr, omp_target_this_expr))
   10981                 :           0 :                 continue;
   10982                 :             : 
   10983                 :           3 :               bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
   10984                 :           3 :               enum gomp_map_kind kind, ptr_kind, nc_kind;
   10985                 :           3 :               tree size;
   10986                 :             : 
   10987                 :           3 :               if (ptr_p)
   10988                 :             :                 {
   10989                 :             :                   /* For pointers, default mapped as zero-length array
   10990                 :             :                      section.  */
   10991                 :           2 :                   kind = GOMP_MAP_ALLOC;
   10992                 :           2 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
   10993                 :           2 :                   ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
   10994                 :           2 :                   size = size_zero_node;
   10995                 :             :                 }
   10996                 :             :               else
   10997                 :             :                 {
   10998                 :             :                   /* For references, default mapped as appearing on map
   10999                 :             :                      clause.  */
   11000                 :           1 :                   kind = GOMP_MAP_TOFROM;
   11001                 :           1 :                   nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
   11002                 :           1 :                   ptr_kind = GOMP_MAP_ALWAYS_POINTER;
   11003                 :           1 :                   size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
   11004                 :             :                 }
   11005                 :             : 
   11006                 :           6 :               for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
   11007                 :           3 :                 if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
   11008                 :           1 :                     && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
   11009                 :           1 :                         || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
   11010                 :           3 :                     && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
   11011                 :             :                                         orig_decl))
   11012                 :             :                   {
   11013                 :             :                     /* If this was already specified by user as a map,
   11014                 :             :                        save the user specified map kind, delete the
   11015                 :             :                        "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
   11016                 :             :                        and insert our own sequence:
   11017                 :             :                        "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
   11018                 :             :                     */
   11019                 :           0 :                     tree nc = OMP_CLAUSE_CHAIN (*p);
   11020                 :           0 :                     gcc_assert (nc != NULL_TREE
   11021                 :             :                                 && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
   11022                 :             :                                 && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
   11023                 :             :                     /* Update with user specified kind and size.  */
   11024                 :           0 :                     kind = OMP_CLAUSE_MAP_KIND (*p);
   11025                 :           0 :                     size = OMP_CLAUSE_SIZE (*p);
   11026                 :           0 :                     *p = OMP_CLAUSE_CHAIN (nc);
   11027                 :           0 :                     break;
   11028                 :             :                   }
   11029                 :             : 
   11030                 :           3 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11031                 :           3 :               OMP_CLAUSE_SET_MAP_KIND (c, kind);
   11032                 :           3 :               OMP_CLAUSE_DECL (c)
   11033                 :           3 :                 = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
   11034                 :           3 :               OMP_CLAUSE_SIZE (c) = size;
   11035                 :           3 :               if (ptr_p)
   11036                 :           2 :                 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11037                 :           3 :               new_clauses.safe_push (c);
   11038                 :             : 
   11039                 :           3 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11040                 :           3 :               OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
   11041                 :           3 :               OMP_CLAUSE_DECL (c) = closure_expr;
   11042                 :           3 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11043                 :           3 :               new_clauses.safe_push (c);
   11044                 :             :             }
   11045                 :             :         }
   11046                 :             :     }
   11047                 :             : 
   11048                 :        6663 :   if (!data.ptr_members_accessed.is_empty ())
   11049                 :          14 :     for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
   11050                 :          56 :          i != data.ptr_members_accessed.end (); ++i)
   11051                 :             :       {
   11052                 :             :         /* For each referenced member that is of pointer or reference-to-pointer
   11053                 :             :            type, create the equivalent of map(alloc:this->ptr[:0]).  */
   11054                 :          14 :         tree field_decl = (*i).first;
   11055                 :          14 :         tree ptr_member = (*i).second;
   11056                 :             : 
   11057                 :          26 :         for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
   11058                 :             :           {
   11059                 :          16 :             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   11060                 :           2 :               continue;
   11061                 :             :             /* If map(this->ptr[:N]) already exists, avoid creating another
   11062                 :             :                such map.  */
   11063                 :          14 :             tree decl = OMP_CLAUSE_DECL (c);
   11064                 :          14 :             if ((TREE_CODE (decl) == INDIRECT_REF
   11065                 :          10 :                  || TREE_CODE (decl) == MEM_REF)
   11066                 :          14 :                 && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
   11067                 :           4 :               goto next_ptr_member;
   11068                 :             :           }
   11069                 :             : 
   11070                 :          10 :         if (!cxx_mark_addressable (ptr_member))
   11071                 :           0 :           gcc_unreachable ();
   11072                 :             : 
   11073                 :          10 :         if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
   11074                 :             :           {
   11075                 :             :             /* For reference to pointers, we need to map the referenced
   11076                 :             :                pointer first for things to be correct.  */
   11077                 :           4 :             tree ptr_member_type = TREE_TYPE (ptr_member);
   11078                 :             : 
   11079                 :             :             /* Map pointer target as zero-length array section.  */
   11080                 :           4 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11081                 :           4 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11082                 :           4 :             OMP_CLAUSE_DECL (c)
   11083                 :           4 :               = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
   11084                 :           4 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11085                 :           4 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11086                 :             : 
   11087                 :             :             /* Map pointer to zero-length array section.  */
   11088                 :           4 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11089                 :           4 :             OMP_CLAUSE_SET_MAP_KIND
   11090                 :             :               (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
   11091                 :           4 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11092                 :           4 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11093                 :             : 
   11094                 :             :             /* Attach reference-to-pointer field to pointer.  */
   11095                 :           4 :             tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11096                 :           4 :             OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
   11097                 :           4 :             OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
   11098                 :           4 :             OMP_CLAUSE_SIZE (c3) = size_zero_node;
   11099                 :             : 
   11100                 :           4 :             new_clauses.safe_push (c);
   11101                 :           4 :             new_clauses.safe_push (c2);
   11102                 :           4 :             new_clauses.safe_push (c3);
   11103                 :             :           }
   11104                 :           6 :         else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
   11105                 :             :           {
   11106                 :             :             /* Map pointer target as zero-length array section.  */
   11107                 :           6 :             tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11108                 :           6 :             OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11109                 :           6 :             OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
   11110                 :             :                                                       RO_UNARY_STAR);
   11111                 :           6 :             OMP_CLAUSE_SIZE (c) = size_zero_node;
   11112                 :           6 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11113                 :             : 
   11114                 :             :             /* Attach zero-length array section to pointer.  */
   11115                 :           6 :             tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11116                 :           6 :             OMP_CLAUSE_SET_MAP_KIND
   11117                 :             :               (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11118                 :           6 :             OMP_CLAUSE_DECL (c2) = ptr_member;
   11119                 :           6 :             OMP_CLAUSE_SIZE (c2) = size_zero_node;
   11120                 :             : 
   11121                 :           6 :             new_clauses.safe_push (c);
   11122                 :           6 :             new_clauses.safe_push (c2);
   11123                 :             :           }
   11124                 :             :         else
   11125                 :           0 :           gcc_unreachable ();
   11126                 :             : 
   11127                 :          14 :       next_ptr_member:
   11128                 :          14 :         ;
   11129                 :             :       }
   11130                 :             : 
   11131                 :        6676 :   for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
   11132                 :        6689 :        i != data.lambda_objects_accessed.end (); ++i)
   11133                 :             :     {
   11134                 :          13 :       tree lobj = *i;
   11135                 :          13 :       if (TREE_CODE (lobj) == TARGET_EXPR)
   11136                 :           0 :         lobj = TARGET_EXPR_SLOT (lobj);
   11137                 :             : 
   11138                 :          13 :       tree lt = TREE_TYPE (lobj);
   11139                 :          26 :       gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
   11140                 :             : 
   11141                 :          13 :       tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11142                 :          13 :       OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
   11143                 :          13 :       OMP_CLAUSE_DECL (lc) = lobj;
   11144                 :          13 :       OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
   11145                 :          13 :       new_clauses.safe_push (lc);
   11146                 :             : 
   11147                 :         180 :       for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
   11148                 :             :         {
   11149                 :         167 :           if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
   11150                 :             :             {
   11151                 :           4 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11152                 :             :                                  lobj, fld, NULL_TREE);
   11153                 :           4 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11154                 :           4 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
   11155                 :           4 :               OMP_CLAUSE_DECL (c)
   11156                 :           4 :                 = build_indirect_ref (loc, exp, RO_UNARY_STAR);
   11157                 :           4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11158                 :           4 :               OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   11159                 :           4 :               new_clauses.safe_push (c);
   11160                 :             : 
   11161                 :           4 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11162                 :           4 :               OMP_CLAUSE_SET_MAP_KIND
   11163                 :             :                 (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
   11164                 :           4 :               OMP_CLAUSE_DECL (c) = exp;
   11165                 :           4 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11166                 :           4 :               new_clauses.safe_push (c);
   11167                 :             :             }
   11168                 :         163 :           else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
   11169                 :             :             {
   11170                 :           0 :               tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
   11171                 :             :                                  lobj, fld, NULL_TREE);
   11172                 :           0 :               tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11173                 :           0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
   11174                 :           0 :               OMP_CLAUSE_DECL (c)
   11175                 :           0 :                 = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
   11176                 :           0 :               OMP_CLAUSE_SIZE (c)
   11177                 :           0 :                 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
   11178                 :           0 :               new_clauses.safe_push (c);
   11179                 :             : 
   11180                 :           0 :               c = build_omp_clause (loc, OMP_CLAUSE_MAP);
   11181                 :           0 :               OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
   11182                 :           0 :               OMP_CLAUSE_DECL (c) = exp;
   11183                 :           0 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   11184                 :           0 :               new_clauses.safe_push (c);
   11185                 :             :             }
   11186                 :             :         }
   11187                 :             :     }
   11188                 :             : 
   11189                 :        6663 :   tree c = *clauses_ptr;
   11190                 :       13541 :   for (int i = new_clauses.length () - 1; i >= 0; i--)
   11191                 :             :     {
   11192                 :         215 :       OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
   11193                 :         215 :       c = new_clauses[i];
   11194                 :             :     }
   11195                 :        6663 :   *clauses_ptr = c;
   11196                 :        6663 : }
   11197                 :             : 
   11198                 :             : /* Called from cp_parser_omp_target.  Create additional implicit clauses for
   11199                 :             :    OpenMP target directives, and do sanity checks.  */
   11200                 :             : 
   11201                 :             : tree
   11202                 :        6654 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
   11203                 :             : {
   11204                 :        6654 :   if (!processing_template_decl)
   11205                 :        5856 :     finish_omp_target_clauses (loc, body, &clauses);
   11206                 :             : 
   11207                 :        6654 :   tree stmt = make_node (OMP_TARGET);
   11208                 :        6654 :   TREE_TYPE (stmt) = void_type_node;
   11209                 :        6654 :   OMP_TARGET_CLAUSES (stmt) = clauses;
   11210                 :        6654 :   OMP_TARGET_BODY (stmt) = body;
   11211                 :        6654 :   OMP_TARGET_COMBINED (stmt) = combined_p;
   11212                 :        6654 :   SET_EXPR_LOCATION (stmt, loc);
   11213                 :             : 
   11214                 :        6654 :   tree c = clauses;
   11215                 :       15957 :   while (c)
   11216                 :             :     {
   11217                 :        9303 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   11218                 :        5445 :         switch (OMP_CLAUSE_MAP_KIND (c))
   11219                 :             :           {
   11220                 :             :           case GOMP_MAP_TO:
   11221                 :             :           case GOMP_MAP_ALWAYS_TO:
   11222                 :             :           case GOMP_MAP_PRESENT_TO:
   11223                 :             :           case GOMP_MAP_ALWAYS_PRESENT_TO:
   11224                 :             :           case GOMP_MAP_FROM:
   11225                 :             :           case GOMP_MAP_ALWAYS_FROM:
   11226                 :             :           case GOMP_MAP_PRESENT_FROM:
   11227                 :             :           case GOMP_MAP_ALWAYS_PRESENT_FROM:
   11228                 :             :           case GOMP_MAP_TOFROM:
   11229                 :             :           case GOMP_MAP_ALWAYS_TOFROM:
   11230                 :             :           case GOMP_MAP_PRESENT_TOFROM:
   11231                 :             :           case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
   11232                 :             :           case GOMP_MAP_ALLOC:
   11233                 :             :           case GOMP_MAP_PRESENT_ALLOC:
   11234                 :             :           case GOMP_MAP_FIRSTPRIVATE_POINTER:
   11235                 :             :           case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
   11236                 :             :           case GOMP_MAP_ALWAYS_POINTER:
   11237                 :             :           case GOMP_MAP_ATTACH_DETACH:
   11238                 :             :           case GOMP_MAP_ATTACH:
   11239                 :             :           case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
   11240                 :             :           case GOMP_MAP_POINTER:
   11241                 :             :           case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
   11242                 :             :             break;
   11243                 :           3 :           default:
   11244                 :           3 :             error_at (OMP_CLAUSE_LOCATION (c),
   11245                 :             :                       "%<#pragma omp target%> with map-type other "
   11246                 :             :                       "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
   11247                 :             :                       "on %<map%> clause");
   11248                 :           3 :             break;
   11249                 :             :           }
   11250                 :        9303 :       c = OMP_CLAUSE_CHAIN (c);
   11251                 :             :     }
   11252                 :        6654 :   return add_stmt (stmt);
   11253                 :             : }
   11254                 :             : 
   11255                 :             : tree
   11256                 :        9399 : finish_omp_parallel (tree clauses, tree body)
   11257                 :             : {
   11258                 :        9399 :   tree stmt;
   11259                 :             : 
   11260                 :        9399 :   body = finish_omp_structured_block (body);
   11261                 :             : 
   11262                 :        9399 :   stmt = make_node (OMP_PARALLEL);
   11263                 :        9399 :   TREE_TYPE (stmt) = void_type_node;
   11264                 :        9399 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   11265                 :        9399 :   OMP_PARALLEL_BODY (stmt) = body;
   11266                 :             : 
   11267                 :        9399 :   return add_stmt (stmt);
   11268                 :             : }
   11269                 :             : 
   11270                 :             : tree
   11271                 :        2330 : begin_omp_task (void)
   11272                 :             : {
   11273                 :        2330 :   keep_next_level (true);
   11274                 :        2330 :   return begin_omp_structured_block ();
   11275                 :             : }
   11276                 :             : 
   11277                 :             : tree
   11278                 :        2330 : finish_omp_task (tree clauses, tree body)
   11279                 :             : {
   11280                 :        2330 :   tree stmt;
   11281                 :             : 
   11282                 :        2330 :   body = finish_omp_structured_block (body);
   11283                 :             : 
   11284                 :        2330 :   stmt = make_node (OMP_TASK);
   11285                 :        2330 :   TREE_TYPE (stmt) = void_type_node;
   11286                 :        2330 :   OMP_TASK_CLAUSES (stmt) = clauses;
   11287                 :        2330 :   OMP_TASK_BODY (stmt) = body;
   11288                 :             : 
   11289                 :        2330 :   return add_stmt (stmt);
   11290                 :             : }
   11291                 :             : 
   11292                 :             : /* Helper function for finish_omp_for.  Convert Ith random access iterator
   11293                 :             :    into integral iterator.  Return FALSE if successful.  */
   11294                 :             : 
   11295                 :             : static bool
   11296                 :         813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
   11297                 :             :                                tree declv, tree orig_declv, tree initv,
   11298                 :             :                                tree condv, tree incrv, tree *body,
   11299                 :             :                                tree *pre_body, tree &clauses,
   11300                 :             :                                int collapse, int ordered)
   11301                 :             : {
   11302                 :         813 :   tree diff, iter_init, iter_incr = NULL, last;
   11303                 :         813 :   tree incr_var = NULL, orig_pre_body, orig_body, c;
   11304                 :         813 :   tree decl = TREE_VEC_ELT (declv, i);
   11305                 :         813 :   tree init = TREE_VEC_ELT (initv, i);
   11306                 :         813 :   tree cond = TREE_VEC_ELT (condv, i);
   11307                 :         813 :   tree incr = TREE_VEC_ELT (incrv, i);
   11308                 :         813 :   tree iter = decl;
   11309                 :         813 :   location_t elocus = locus;
   11310                 :             : 
   11311                 :         813 :   if (init && EXPR_HAS_LOCATION (init))
   11312                 :          12 :     elocus = EXPR_LOCATION (init);
   11313                 :             : 
   11314                 :         813 :   switch (TREE_CODE (cond))
   11315                 :             :     {
   11316                 :         810 :     case GT_EXPR:
   11317                 :         810 :     case GE_EXPR:
   11318                 :         810 :     case LT_EXPR:
   11319                 :         810 :     case LE_EXPR:
   11320                 :         810 :     case NE_EXPR:
   11321                 :         810 :       if (TREE_OPERAND (cond, 1) == iter)
   11322                 :          42 :         cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
   11323                 :          42 :                        TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
   11324                 :         810 :       if (TREE_OPERAND (cond, 0) != iter)
   11325                 :           0 :         cond = error_mark_node;
   11326                 :             :       else
   11327                 :             :         {
   11328                 :         810 :           tree tem = build_x_binary_op (EXPR_LOCATION (cond),
   11329                 :         810 :                                         TREE_CODE (cond),
   11330                 :             :                                         iter, ERROR_MARK,
   11331                 :         810 :                                         TREE_OPERAND (cond, 1), ERROR_MARK,
   11332                 :             :                                         NULL_TREE, NULL, tf_warning_or_error);
   11333                 :         810 :           if (error_operand_p (tem))
   11334                 :             :             return true;
   11335                 :             :         }
   11336                 :             :       break;
   11337                 :           3 :     default:
   11338                 :           3 :       cond = error_mark_node;
   11339                 :           3 :       break;
   11340                 :             :     }
   11341                 :         810 :   if (cond == error_mark_node)
   11342                 :             :     {
   11343                 :           3 :       error_at (elocus, "invalid controlling predicate");
   11344                 :           3 :       return true;
   11345                 :             :     }
   11346                 :         807 :   diff = build_x_binary_op (elocus, MINUS_EXPR,
   11347                 :         807 :                             TREE_OPERAND (cond, 1), ERROR_MARK,
   11348                 :             :                             iter, ERROR_MARK,
   11349                 :             :                             NULL_TREE, NULL, tf_warning_or_error);
   11350                 :         807 :   diff = cp_fully_fold (diff);
   11351                 :         807 :   if (error_operand_p (diff))
   11352                 :             :     return true;
   11353                 :         807 :   if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
   11354                 :             :     {
   11355                 :           0 :       error_at (elocus, "difference between %qE and %qD does not have integer type",
   11356                 :           0 :                 TREE_OPERAND (cond, 1), iter);
   11357                 :           0 :       return true;
   11358                 :             :     }
   11359                 :         807 :   if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
   11360                 :         807 :                                   TREE_VEC_ELT (declv, i), NULL_TREE,
   11361                 :             :                                   cond, cp_walk_subtrees))
   11362                 :             :     return true;
   11363                 :             : 
   11364                 :         762 :   switch (TREE_CODE (incr))
   11365                 :             :     {
   11366                 :         370 :     case PREINCREMENT_EXPR:
   11367                 :         370 :     case PREDECREMENT_EXPR:
   11368                 :         370 :     case POSTINCREMENT_EXPR:
   11369                 :         370 :     case POSTDECREMENT_EXPR:
   11370                 :         370 :       if (TREE_OPERAND (incr, 0) != iter)
   11371                 :             :         {
   11372                 :           0 :           incr = error_mark_node;
   11373                 :           0 :           break;
   11374                 :             :         }
   11375                 :         370 :       iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
   11376                 :         370 :                                     TREE_CODE (incr), iter,
   11377                 :             :                                     NULL_TREE, tf_warning_or_error);
   11378                 :         370 :       if (error_operand_p (iter_incr))
   11379                 :             :         return true;
   11380                 :         370 :       else if (TREE_CODE (incr) == PREINCREMENT_EXPR
   11381                 :         219 :                || TREE_CODE (incr) == POSTINCREMENT_EXPR)
   11382                 :         299 :         incr = integer_one_node;
   11383                 :             :       else
   11384                 :          71 :         incr = integer_minus_one_node;
   11385                 :             :       break;
   11386                 :         392 :     case MODIFY_EXPR:
   11387                 :         392 :       if (TREE_OPERAND (incr, 0) != iter)
   11388                 :           0 :         incr = error_mark_node;
   11389                 :         392 :       else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
   11390                 :         392 :                || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
   11391                 :             :         {
   11392                 :         392 :           tree rhs = TREE_OPERAND (incr, 1);
   11393                 :         392 :           if (TREE_OPERAND (rhs, 0) == iter)
   11394                 :             :             {
   11395                 :         299 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
   11396                 :             :                   != INTEGER_TYPE)
   11397                 :           0 :                 incr = error_mark_node;
   11398                 :             :               else
   11399                 :             :                 {
   11400                 :         299 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11401                 :         299 :                                                    iter, TREE_CODE (rhs),
   11402                 :         299 :                                                    TREE_OPERAND (rhs, 1),
   11403                 :             :                                                    NULL_TREE,
   11404                 :             :                                                    tf_warning_or_error);
   11405                 :         299 :                   if (error_operand_p (iter_incr))
   11406                 :             :                     return true;
   11407                 :         299 :                   incr = TREE_OPERAND (rhs, 1);
   11408                 :         299 :                   incr = cp_convert (TREE_TYPE (diff), incr,
   11409                 :             :                                      tf_warning_or_error);
   11410                 :         299 :                   if (TREE_CODE (rhs) == MINUS_EXPR)
   11411                 :             :                     {
   11412                 :          16 :                       incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
   11413                 :          16 :                       incr = fold_simple (incr);
   11414                 :             :                     }
   11415                 :         299 :                   if (TREE_CODE (incr) != INTEGER_CST
   11416                 :         299 :                       && (TREE_CODE (incr) != NOP_EXPR
   11417                 :          66 :                           || (TREE_CODE (TREE_OPERAND (incr, 0))
   11418                 :             :                               != INTEGER_CST)))
   11419                 :             :                     iter_incr = NULL;
   11420                 :             :                 }
   11421                 :             :             }
   11422                 :          93 :           else if (TREE_OPERAND (rhs, 1) == iter)
   11423                 :             :             {
   11424                 :          93 :               if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
   11425                 :          93 :                   || TREE_CODE (rhs) != PLUS_EXPR)
   11426                 :           0 :                 incr = error_mark_node;
   11427                 :             :               else
   11428                 :             :                 {
   11429                 :          93 :                   iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
   11430                 :             :                                                  PLUS_EXPR,
   11431                 :          93 :                                                  TREE_OPERAND (rhs, 0),
   11432                 :             :                                                  ERROR_MARK, iter,
   11433                 :             :                                                  ERROR_MARK, NULL_TREE, NULL,
   11434                 :             :                                                  tf_warning_or_error);
   11435                 :          93 :                   if (error_operand_p (iter_incr))
   11436                 :             :                     return true;
   11437                 :          93 :                   iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
   11438                 :             :                                                    iter, NOP_EXPR,
   11439                 :             :                                                    iter_incr, NULL_TREE,
   11440                 :             :                                                    tf_warning_or_error);
   11441                 :          93 :                   if (error_operand_p (iter_incr))
   11442                 :             :                     return true;
   11443                 :          93 :                   incr = TREE_OPERAND (rhs, 0);
   11444                 :          93 :                   iter_incr = NULL;
   11445                 :             :                 }
   11446                 :             :             }
   11447                 :             :           else
   11448                 :           0 :             incr = error_mark_node;
   11449                 :             :         }
   11450                 :             :       else
   11451                 :           0 :         incr = error_mark_node;
   11452                 :             :       break;
   11453                 :           0 :     default:
   11454                 :           0 :       incr = error_mark_node;
   11455                 :           0 :       break;
   11456                 :             :     }
   11457                 :             : 
   11458                 :         762 :   if (incr == error_mark_node)
   11459                 :             :     {
   11460                 :           0 :       error_at (elocus, "invalid increment expression");
   11461                 :           0 :       return true;
   11462                 :             :     }
   11463                 :             : 
   11464                 :         762 :   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
   11465                 :         762 :   incr = cp_fully_fold (incr);
   11466                 :         762 :   tree loop_iv_seen = NULL_TREE;
   11467                 :        1735 :   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
   11468                 :        1093 :     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   11469                 :        1093 :         && OMP_CLAUSE_DECL (c) == iter)
   11470                 :             :       {
   11471                 :         120 :         if (code == OMP_TASKLOOP || code == OMP_LOOP)
   11472                 :             :           {
   11473                 :          60 :             loop_iv_seen = c;
   11474                 :          60 :             OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
   11475                 :             :           }
   11476                 :             :         break;
   11477                 :             :       }
   11478                 :         973 :     else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
   11479                 :         113 :              && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   11480                 :        1007 :              && OMP_CLAUSE_DECL (c) == iter)
   11481                 :             :       {
   11482                 :          30 :         loop_iv_seen = c;
   11483                 :          30 :         if (code == OMP_TASKLOOP)
   11484                 :          25 :           OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
   11485                 :             :       }
   11486                 :             : 
   11487                 :         762 :   decl = create_temporary_var (TREE_TYPE (diff));
   11488                 :         762 :   pushdecl (decl);
   11489                 :         762 :   add_decl_expr (decl);
   11490                 :         762 :   last = create_temporary_var (TREE_TYPE (diff));
   11491                 :         762 :   pushdecl (last);
   11492                 :         762 :   add_decl_expr (last);
   11493                 :         762 :   if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
   11494                 :          10 :       && (!ordered || (i < collapse && collapse > 1)))
   11495                 :             :     {
   11496                 :          10 :       incr_var = create_temporary_var (TREE_TYPE (diff));
   11497                 :          10 :       pushdecl (incr_var);
   11498                 :          10 :       add_decl_expr (incr_var);
   11499                 :             :     }
   11500                 :         762 :   gcc_assert (stmts_are_full_exprs_p ());
   11501                 :         762 :   tree diffvar = NULL_TREE;
   11502                 :         762 :   if (code == OMP_TASKLOOP)
   11503                 :             :     {
   11504                 :         101 :       if (!loop_iv_seen)
   11505                 :             :         {
   11506                 :          38 :           tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11507                 :          38 :           OMP_CLAUSE_DECL (ivc) = iter;
   11508                 :          38 :           cxx_omp_finish_clause (ivc, NULL, false);
   11509                 :          38 :           OMP_CLAUSE_CHAIN (ivc) = clauses;
   11510                 :          38 :           clauses = ivc;
   11511                 :             :         }
   11512                 :         101 :       tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11513                 :         101 :       OMP_CLAUSE_DECL (lvc) = last;
   11514                 :         101 :       OMP_CLAUSE_CHAIN (lvc) = clauses;
   11515                 :         101 :       clauses = lvc;
   11516                 :         101 :       diffvar = create_temporary_var (TREE_TYPE (diff));
   11517                 :         101 :       pushdecl (diffvar);
   11518                 :         101 :       add_decl_expr (diffvar);
   11519                 :             :     }
   11520                 :         661 :   else if (code == OMP_LOOP)
   11521                 :             :     {
   11522                 :          43 :       if (!loop_iv_seen)
   11523                 :             :         {
   11524                 :             :           /* While iterators on the loop construct are predetermined
   11525                 :             :              lastprivate, if the decl is not declared inside of the
   11526                 :             :              loop, OMP_CLAUSE_LASTPRIVATE should have been added
   11527                 :             :              already.  */
   11528                 :          16 :           loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
   11529                 :          16 :           OMP_CLAUSE_DECL (loop_iv_seen) = iter;
   11530                 :          16 :           OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
   11531                 :          16 :           clauses = loop_iv_seen;
   11532                 :             :         }
   11533                 :          27 :       else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
   11534                 :             :         {
   11535                 :           5 :           OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
   11536                 :           5 :           OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
   11537                 :           5 :           OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
   11538                 :             :         }
   11539                 :          43 :       if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
   11540                 :          21 :         cxx_omp_finish_clause (loop_iv_seen, NULL, false);
   11541                 :             :     }
   11542                 :             : 
   11543                 :         762 :   orig_pre_body = *pre_body;
   11544                 :         762 :   *pre_body = push_stmt_list ();
   11545                 :         762 :   if (orig_pre_body)
   11546                 :         610 :     add_stmt (orig_pre_body);
   11547                 :         762 :   if (init != NULL)
   11548                 :          61 :     finish_expr_stmt (build_x_modify_expr (elocus,
   11549                 :             :                                            iter, NOP_EXPR, init,
   11550                 :             :                                            NULL_TREE, tf_warning_or_error));
   11551                 :         762 :   init = build_int_cst (TREE_TYPE (diff), 0);
   11552                 :         762 :   if (c && iter_incr == NULL
   11553                 :          28 :       && (!ordered || (i < collapse && collapse > 1)))
   11554                 :             :     {
   11555                 :          28 :       if (incr_var)
   11556                 :             :         {
   11557                 :          10 :           finish_expr_stmt (build_x_modify_expr (elocus,
   11558                 :             :                                                  incr_var, NOP_EXPR,
   11559                 :             :                                                  incr, NULL_TREE,
   11560                 :             :                                                  tf_warning_or_error));
   11561                 :          10 :           incr = incr_var;
   11562                 :             :         }
   11563                 :          28 :       iter_incr = build_x_modify_expr (elocus,
   11564                 :             :                                        iter, PLUS_EXPR, incr,
   11565                 :             :                                        NULL_TREE, tf_warning_or_error);
   11566                 :             :     }
   11567                 :         762 :   if (c && ordered && i < collapse && collapse > 1)
   11568                 :         762 :     iter_incr = incr;
   11569                 :         762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11570                 :             :                                          last, NOP_EXPR, init,
   11571                 :             :                                          NULL_TREE, tf_warning_or_error));
   11572                 :         762 :   if (diffvar)
   11573                 :             :     {
   11574                 :         101 :       finish_expr_stmt (build_x_modify_expr (elocus,
   11575                 :             :                                              diffvar, NOP_EXPR,
   11576                 :             :                                              diff, NULL_TREE, tf_warning_or_error));
   11577                 :         101 :       diff = diffvar;
   11578                 :             :     }
   11579                 :         762 :   *pre_body = pop_stmt_list (*pre_body);
   11580                 :             : 
   11581                 :        1524 :   cond = cp_build_binary_op (elocus,
   11582                 :         762 :                              TREE_CODE (cond), decl, diff,
   11583                 :             :                              tf_warning_or_error);
   11584                 :         762 :   incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
   11585                 :             :                             elocus, incr, NULL_TREE);
   11586                 :             : 
   11587                 :         762 :   orig_body = *body;
   11588                 :         762 :   *body = push_stmt_list ();
   11589                 :         762 :   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
   11590                 :         762 :   iter_init = build_x_modify_expr (elocus,
   11591                 :             :                                    iter, PLUS_EXPR, iter_init,
   11592                 :             :                                    NULL_TREE, tf_warning_or_error);
   11593                 :         762 :   if (iter_init != error_mark_node)
   11594                 :         759 :     iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11595                 :         762 :   finish_expr_stmt (iter_init);
   11596                 :         762 :   finish_expr_stmt (build_x_modify_expr (elocus,
   11597                 :             :                                          last, NOP_EXPR, decl,
   11598                 :             :                                          NULL_TREE, tf_warning_or_error));
   11599                 :         762 :   add_stmt (orig_body);
   11600                 :         762 :   *body = pop_stmt_list (*body);
   11601                 :             : 
   11602                 :         762 :   if (c)
   11603                 :             :     {
   11604                 :         120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
   11605                 :         120 :       if (!ordered)
   11606                 :         114 :         finish_expr_stmt (iter_incr);
   11607                 :             :       else
   11608                 :             :         {
   11609                 :           6 :           iter_init = decl;
   11610                 :           6 :           if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
   11611                 :           2 :             iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
   11612                 :             :                                 iter_init, iter_incr);
   11613                 :           6 :           iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
   11614                 :           6 :           iter_init = build_x_modify_expr (elocus,
   11615                 :             :                                            iter, PLUS_EXPR, iter_init,
   11616                 :             :                                            NULL_TREE, tf_warning_or_error);
   11617                 :           6 :           if (iter_init != error_mark_node)
   11618                 :           6 :             iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   11619                 :           6 :           finish_expr_stmt (iter_init);
   11620                 :             :         }
   11621                 :         120 :       OMP_CLAUSE_LASTPRIVATE_STMT (c)
   11622                 :         240 :         = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
   11623                 :             :     }
   11624                 :             : 
   11625                 :         762 :   if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
   11626                 :             :     {
   11627                 :         116 :       tree t = TREE_VEC_ELT (orig_declv, i);
   11628                 :         116 :       gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   11629                 :             :                   && TREE_VALUE (t) == NULL_TREE
   11630                 :             :                   && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
   11631                 :         116 :       TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
   11632                 :         116 :       TREE_VALUE (t) = last;
   11633                 :             :     }
   11634                 :             :   else
   11635                 :         646 :     TREE_VEC_ELT (orig_declv, i)
   11636                 :        1292 :       = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   11637                 :         762 :   TREE_VEC_ELT (declv, i) = decl;
   11638                 :         762 :   TREE_VEC_ELT (initv, i) = init;
   11639                 :         762 :   TREE_VEC_ELT (condv, i) = cond;
   11640                 :         762 :   TREE_VEC_ELT (incrv, i) = incr;
   11641                 :             : 
   11642                 :         762 :   return false;
   11643                 :             : }
   11644                 :             : 
   11645                 :             : /* Build and validate an OMP_FOR statement.  CLAUSES, BODY, COND, INCR
   11646                 :             :    are directly for their associated operands in the statement.  DECL
   11647                 :             :    and INIT are a combo; if DECL is NULL then INIT ought to be a
   11648                 :             :    MODIFY_EXPR, and the DECL should be extracted.  PRE_BODY are
   11649                 :             :    optional statements that need to go before the loop into its
   11650                 :             :    sk_omp scope.  */
   11651                 :             : 
   11652                 :             : tree
   11653                 :       21159 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
   11654                 :             :                 tree orig_declv, tree initv, tree condv, tree incrv,
   11655                 :             :                 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
   11656                 :             : {
   11657                 :       21159 :   tree omp_for = NULL, orig_incr = NULL;
   11658                 :       21159 :   tree decl = NULL, init, cond, incr;
   11659                 :       21159 :   location_t elocus;
   11660                 :       21159 :   int i;
   11661                 :       21159 :   int collapse = 1;
   11662                 :       21159 :   int ordered = 0;
   11663                 :       21159 :   auto_vec<location_t> init_locv;
   11664                 :             : 
   11665                 :       21159 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
   11666                 :       21159 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
   11667                 :       21159 :   gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
   11668                 :       21159 :   if (TREE_VEC_LENGTH (declv) > 1)
   11669                 :             :     {
   11670                 :        4026 :       if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
   11671                 :          83 :         collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
   11672                 :             :       else
   11673                 :             :         {
   11674                 :        3943 :           if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
   11675                 :        3473 :             collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
   11676                 :         470 :           else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
   11677                 :         394 :             collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
   11678                 :        3943 :           if (collapse != TREE_VEC_LENGTH (declv))
   11679                 :         100 :             ordered = TREE_VEC_LENGTH (declv);
   11680                 :             :         }
   11681                 :             :     }
   11682                 :       48632 :   for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   11683                 :             :     {
   11684                 :       27509 :       decl = TREE_VEC_ELT (declv, i);
   11685                 :       27509 :       init = TREE_VEC_ELT (initv, i);
   11686                 :       27509 :       cond = TREE_VEC_ELT (condv, i);
   11687                 :       27509 :       incr = TREE_VEC_ELT (incrv, i);
   11688                 :       27509 :       elocus = locus;
   11689                 :             : 
   11690                 :       27509 :       if (decl == global_namespace)
   11691                 :             :         {
   11692                 :        1101 :           gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
   11693                 :        1101 :           TREE_VEC_ELT (declv, i) = NULL_TREE;
   11694                 :        1101 :           init_locv.safe_push (UNKNOWN_LOCATION);
   11695                 :        1101 :           continue;
   11696                 :             :         }
   11697                 :             :       /* We are going to throw out the init's original MODIFY_EXPR or
   11698                 :             :          MODOP_EXPR below.  Save its location so we can use it when
   11699                 :             :          reconstructing the expression farther down.  Alternatively, if the
   11700                 :             :          initializer is a binding of the iteration variable, save
   11701                 :             :          that location.  Any of these locations in the initialization clause
   11702                 :             :          for the current nested loop are better than using the argument locus,
   11703                 :             :          that points to the "for" of the outermost loop in the nest.  */
   11704                 :       26408 :       if (init && EXPR_HAS_LOCATION (init))
   11705                 :       17879 :         elocus = EXPR_LOCATION (init);
   11706                 :        8529 :       else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
   11707                 :             :         /* This can happen for class iterators.  */
   11708                 :           0 :         elocus = EXPR_LOCATION (decl);
   11709                 :        8529 :       else if (decl && DECL_P (decl))
   11710                 :             :         {
   11711                 :        8502 :           if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
   11712                 :        8502 :             elocus = DECL_SOURCE_LOCATION (decl);
   11713                 :           0 :           else if (DECL_INITIAL (decl)
   11714                 :           0 :                    && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
   11715                 :           0 :             elocus = EXPR_LOCATION (DECL_INITIAL (decl));
   11716                 :             :         }
   11717                 :       26408 :       init_locv.safe_push (elocus);
   11718                 :             : 
   11719                 :       26408 :       if (decl == NULL)
   11720                 :             :         {
   11721                 :       16568 :           if (init != NULL)
   11722                 :       16565 :             switch (TREE_CODE (init))
   11723                 :             :               {
   11724                 :       16158 :               case MODIFY_EXPR:
   11725                 :       16158 :                 decl = TREE_OPERAND (init, 0);
   11726                 :       16158 :                 init = TREE_OPERAND (init, 1);
   11727                 :       16158 :                 break;
   11728                 :         389 :               case MODOP_EXPR:
   11729                 :         389 :                 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
   11730                 :             :                   {
   11731                 :         389 :                     decl = TREE_OPERAND (init, 0);
   11732                 :         389 :                     init = TREE_OPERAND (init, 2);
   11733                 :             :                   }
   11734                 :             :                 break;
   11735                 :             :               default:
   11736                 :             :                 break;
   11737                 :             :               }
   11738                 :             : 
   11739                 :       16568 :           if (decl == NULL)
   11740                 :             :             {
   11741                 :          21 :               error_at (locus,
   11742                 :             :                         "expected iteration declaration or initialization");
   11743                 :          21 :               return NULL;
   11744                 :             :             }
   11745                 :             :         }
   11746                 :             : 
   11747                 :       26387 :       if (cond == global_namespace)
   11748                 :         170 :         continue;
   11749                 :             : 
   11750                 :       26217 :       if (cond == NULL)
   11751                 :             :         {
   11752                 :           9 :           error_at (elocus, "missing controlling predicate");
   11753                 :           9 :           return NULL;
   11754                 :             :         }
   11755                 :             : 
   11756                 :       26208 :       if (incr == NULL)
   11757                 :             :         {
   11758                 :           6 :           error_at (elocus, "missing increment expression");
   11759                 :           6 :           return NULL;
   11760                 :             :         }
   11761                 :             : 
   11762                 :       26202 :       TREE_VEC_ELT (declv, i) = decl;
   11763                 :       26202 :       TREE_VEC_ELT (initv, i) = init;
   11764                 :             :     }
   11765                 :             : 
   11766                 :       21123 :   if (orig_inits)
   11767                 :             :     {
   11768                 :             :       bool fail = false;
   11769                 :             :       tree orig_init;
   11770                 :       21229 :       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
   11771                 :        1181 :         if (orig_init
   11772                 :        3396 :             && !c_omp_check_loop_iv_exprs (locus, code,
   11773                 :             :                                            orig_declv ? orig_declv : declv, i,
   11774                 :        1164 :                                            TREE_VEC_ELT (declv, i), orig_init,
   11775                 :             :                                            NULL_TREE, cp_walk_subtrees))
   11776                 :             :           fail = true;
   11777                 :       20048 :       if (fail)
   11778                 :         887 :         return NULL;
   11779                 :             :     }
   11780                 :             : 
   11781                 :       21066 :   if (dependent_omp_for_p (declv, initv, condv, incrv, body))
   11782                 :             :     {
   11783                 :         453 :       tree stmt;
   11784                 :             : 
   11785                 :         453 :       stmt = make_node (code);
   11786                 :             : 
   11787                 :        1499 :       for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
   11788                 :             :         {
   11789                 :         593 :           if (TREE_VEC_ELT (declv, i) == NULL_TREE)
   11790                 :           9 :             continue;
   11791                 :             :           /* This is really just a place-holder.  We'll be decomposing this
   11792                 :             :              again and going through the cp_build_modify_expr path below when
   11793                 :             :              we instantiate the thing.  */
   11794                 :         584 :           TREE_VEC_ELT (initv, i)
   11795                 :        1168 :             = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
   11796                 :         584 :                           TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
   11797                 :             :         }
   11798                 :             : 
   11799                 :         453 :       TREE_TYPE (stmt) = void_type_node;
   11800                 :         453 :       OMP_FOR_INIT (stmt) = initv;
   11801                 :         453 :       OMP_FOR_COND (stmt) = condv;
   11802                 :         453 :       OMP_FOR_INCR (stmt) = incrv;
   11803                 :         453 :       OMP_FOR_BODY (stmt) = body;
   11804                 :         453 :       OMP_FOR_PRE_BODY (stmt) = pre_body;
   11805                 :         453 :       OMP_FOR_CLAUSES (stmt) = clauses;
   11806                 :             : 
   11807                 :         453 :       SET_EXPR_LOCATION (stmt, locus);
   11808                 :         453 :       return add_stmt (stmt);
   11809                 :             :     }
   11810                 :             : 
   11811                 :       20613 :   if (!orig_declv)
   11812                 :       19810 :     orig_declv = copy_node (declv);
   11813                 :             : 
   11814                 :       20613 :   if (processing_template_decl)
   11815                 :         628 :     orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
   11816                 :             : 
   11817                 :       48061 :   for (i = 0; i < TREE_VEC_LENGTH (declv); )
   11818                 :             :     {
   11819                 :       27540 :       decl = TREE_VEC_ELT (declv, i);
   11820                 :       27540 :       init = TREE_VEC_ELT (initv, i);
   11821                 :       27540 :       cond = TREE_VEC_ELT (condv, i);
   11822                 :       27540 :       incr = TREE_VEC_ELT (incrv, i);
   11823                 :       27540 :       if (orig_incr)
   11824                 :         857 :         TREE_VEC_ELT (orig_incr, i) = incr;
   11825                 :       27540 :       elocus = init_locv[i];
   11826                 :             : 
   11827                 :       27540 :       if (decl == NULL_TREE)
   11828                 :             :         {
   11829                 :        1092 :           i++;
   11830                 :        1092 :           continue;
   11831                 :             :         }
   11832                 :             : 
   11833                 :       26448 :       if (!DECL_P (decl))
   11834                 :             :         {
   11835                 :           6 :           error_at (elocus, "expected iteration declaration or initialization");
   11836                 :           6 :           return NULL;
   11837                 :             :         }
   11838                 :             : 
   11839                 :       26442 :       if (incr && TREE_CODE (incr) == MODOP_EXPR)
   11840                 :             :         {
   11841                 :           1 :           if (orig_incr)
   11842                 :           1 :             TREE_VEC_ELT (orig_incr, i) = incr;
   11843                 :           1 :           incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
   11844                 :           1 :                                        TREE_CODE (TREE_OPERAND (incr, 1)),
   11845                 :           1 :                                        TREE_OPERAND (incr, 2),
   11846                 :             :                                        tf_warning_or_error);
   11847                 :             :         }
   11848                 :             : 
   11849                 :       26442 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
   11850                 :             :         {
   11851                 :         825 :           if (code == OMP_SIMD)
   11852                 :             :             {
   11853                 :          12 :               error_at (elocus, "%<#pragma omp simd%> used with class "
   11854                 :             :                                 "iteration variable %qE", decl);
   11855                 :          12 :               return NULL;
   11856                 :             :             }
   11857                 :         813 :           if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
   11858                 :             :                                              initv, condv, incrv, &body,
   11859                 :             :                                              &pre_body, clauses,
   11860                 :             :                                              collapse, ordered))
   11861                 :             :             return NULL;
   11862                 :         762 :           continue;
   11863                 :             :         }
   11864                 :             : 
   11865                 :       51234 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
   11866                 :       27200 :           && !TYPE_PTR_P (TREE_TYPE (decl)))
   11867                 :             :         {
   11868                 :          14 :           error_at (elocus, "invalid type for iteration variable %qE", decl);
   11869                 :          14 :           return NULL;
   11870                 :             :         }
   11871                 :             : 
   11872                 :       25603 :       if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
   11873                 :       24829 :         init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
   11874                 :             :                                      tf_warning_or_error);
   11875                 :             :       else
   11876                 :         774 :         init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
   11877                 :       25603 :       if (decl == error_mark_node || init == error_mark_node)
   11878                 :             :         return NULL;
   11879                 :             : 
   11880                 :       25594 :       TREE_VEC_ELT (declv, i) = decl;
   11881                 :       25594 :       TREE_VEC_ELT (initv, i) = init;
   11882                 :       25594 :       TREE_VEC_ELT (condv, i) = cond;
   11883                 :       25594 :       TREE_VEC_ELT (incrv, i) = incr;
   11884                 :       25594 :       i++;
   11885                 :             :     }
   11886                 :             : 
   11887                 :       20521 :   if (pre_body && IS_EMPTY_STMT (pre_body))
   11888                 :           0 :     pre_body = NULL;
   11889                 :             : 
   11890                 :       41042 :   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
   11891                 :             :                               incrv, body, pre_body,
   11892                 :       20521 :                               !processing_template_decl);
   11893                 :             : 
   11894                 :             :   /* Check for iterators appearing in lb, b or incr expressions.  */
   11895                 :       20521 :   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
   11896                 :             :     omp_for = NULL_TREE;
   11897                 :             : 
   11898                 :       20035 :   if (omp_for == NULL)
   11899                 :         702 :     return NULL;
   11900                 :             : 
   11901                 :       19819 :   add_stmt (omp_for);
   11902                 :             : 
   11903                 :       45479 :   for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
   11904                 :             :     {
   11905                 :       25660 :       init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
   11906                 :       25660 :       if (init == NULL_TREE)
   11907                 :        1032 :         continue;
   11908                 :       24628 :       decl = TREE_OPERAND (init, 0);
   11909                 :       24628 :       cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
   11910                 :       24628 :       incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
   11911                 :             : 
   11912                 :       24628 :       if (!processing_template_decl)
   11913                 :             :         {
   11914                 :       24094 :           if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
   11915                 :             :             {
   11916                 :         106 :               tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
   11917                 :         106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
   11918                 :         106 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11919                 :         106 :               t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
   11920                 :         106 :               TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
   11921                 :         212 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11922                 :             :             }
   11923                 :             :           else
   11924                 :             :             {
   11925                 :       23988 :               tree t = TREE_OPERAND (init, 1);
   11926                 :       23988 :               TREE_OPERAND (init, 1)
   11927                 :       47976 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11928                 :             :             }
   11929                 :       24094 :           if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
   11930                 :             :             {
   11931                 :         121 :               tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
   11932                 :         121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
   11933                 :         121 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11934                 :         121 :               t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
   11935                 :         121 :               TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
   11936                 :         242 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11937                 :             :             }
   11938                 :             :           else
   11939                 :             :             {
   11940                 :       23973 :               tree t = TREE_OPERAND (cond, 1);
   11941                 :       23973 :               TREE_OPERAND (cond, 1)
   11942                 :       47946 :                 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11943                 :             :             }
   11944                 :             :         }
   11945                 :             : 
   11946                 :       24628 :       if (TREE_CODE (incr) != MODIFY_EXPR)
   11947                 :       18435 :         continue;
   11948                 :             : 
   11949                 :        6193 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
   11950                 :          70 :           && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
   11951                 :        6263 :           && !processing_template_decl)
   11952                 :             :         {
   11953                 :          64 :           tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
   11954                 :          64 :           if (TREE_SIDE_EFFECTS (t)
   11955                 :           8 :               && t != decl
   11956                 :          70 :               && (TREE_CODE (t) != NOP_EXPR
   11957                 :           0 :                   || TREE_OPERAND (t, 0) != decl))
   11958                 :           6 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
   11959                 :          12 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11960                 :             : 
   11961                 :          64 :           t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
   11962                 :          64 :           if (TREE_SIDE_EFFECTS (t)
   11963                 :          56 :               && t != decl
   11964                 :         120 :               && (TREE_CODE (t) != NOP_EXPR
   11965                 :           5 :                   || TREE_OPERAND (t, 0) != decl))
   11966                 :          56 :             TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
   11967                 :         112 :               = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   11968                 :             :         }
   11969                 :             : 
   11970                 :        6193 :       if (orig_incr)
   11971                 :         177 :         TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
   11972                 :             :     }
   11973                 :       19819 :   OMP_FOR_CLAUSES (omp_for) = clauses;
   11974                 :             : 
   11975                 :             :   /* For simd loops with non-static data member iterators, we could have added
   11976                 :             :      OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP.  As we know the
   11977                 :             :      step at this point, fill it in.  */
   11978                 :        4732 :   if (code == OMP_SIMD && !processing_template_decl
   11979                 :       24507 :       && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
   11980                 :        4619 :     for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
   11981                 :         561 :          c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
   11982                 :         561 :       if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
   11983                 :             :         {
   11984                 :           4 :           decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
   11985                 :           4 :           gcc_assert (decl == OMP_CLAUSE_DECL (c));
   11986                 :           4 :           incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
   11987                 :           4 :           tree step, stept;
   11988                 :           4 :           switch (TREE_CODE (incr))
   11989                 :             :             {
   11990                 :           0 :             case PREINCREMENT_EXPR:
   11991                 :           0 :             case POSTINCREMENT_EXPR:
   11992                 :             :               /* c_omp_for_incr_canonicalize_ptr() should have been
   11993                 :             :                  called to massage things appropriately.  */
   11994                 :           0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   11995                 :           0 :               OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
   11996                 :           0 :               break;
   11997                 :           0 :             case PREDECREMENT_EXPR:
   11998                 :           0 :             case POSTDECREMENT_EXPR:
   11999                 :             :               /* c_omp_for_incr_canonicalize_ptr() should have been
   12000                 :             :                  called to massage things appropriately.  */
   12001                 :           0 :               gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
   12002                 :           0 :               OMP_CLAUSE_LINEAR_STEP (c)
   12003                 :           0 :                 = build_int_cst (TREE_TYPE (decl), -1);
   12004                 :           0 :               break;
   12005                 :           4 :             case MODIFY_EXPR:
   12006                 :           4 :               gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12007                 :           4 :               incr = TREE_OPERAND (incr, 1);
   12008                 :           4 :               switch (TREE_CODE (incr))
   12009                 :             :                 {
   12010                 :           4 :                 case PLUS_EXPR:
   12011                 :           4 :                   if (TREE_OPERAND (incr, 1) == decl)
   12012                 :           0 :                     step = TREE_OPERAND (incr, 0);
   12013                 :             :                   else
   12014                 :           4 :                     step = TREE_OPERAND (incr, 1);
   12015                 :             :                   break;
   12016                 :           0 :                 case MINUS_EXPR:
   12017                 :           0 :                 case POINTER_PLUS_EXPR:
   12018                 :           0 :                   gcc_assert (TREE_OPERAND (incr, 0) == decl);
   12019                 :           0 :                   step = TREE_OPERAND (incr, 1);
   12020                 :           0 :                   break;
   12021                 :           0 :                 default:
   12022                 :           0 :                   gcc_unreachable ();
   12023                 :             :                 }
   12024                 :           4 :               stept = TREE_TYPE (decl);
   12025                 :           4 :               if (INDIRECT_TYPE_P (stept))
   12026                 :           0 :                 stept = sizetype;
   12027                 :           4 :               step = fold_convert (stept, step);
   12028                 :           4 :               if (TREE_CODE (incr) == MINUS_EXPR)
   12029                 :           0 :                 step = fold_build1 (NEGATE_EXPR, stept, step);
   12030                 :           4 :               OMP_CLAUSE_LINEAR_STEP (c) = step;
   12031                 :           4 :               break;
   12032                 :           0 :             default:
   12033                 :           0 :               gcc_unreachable ();
   12034                 :             :             }
   12035                 :             :         }
   12036                 :             :   /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
   12037                 :             :      clauses, we need copy ctor for those rather than default ctor,
   12038                 :             :      plus as for other lastprivates assignment op and dtor.  */
   12039                 :       19819 :   if (code == OMP_LOOP && !processing_template_decl)
   12040                 :        1979 :     for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   12041                 :        1270 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
   12042                 :         204 :           && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
   12043                 :        1292 :           && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
   12044                 :             :                                          false, true, true, true))
   12045                 :           0 :         CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
   12046                 :             : 
   12047                 :             :   return omp_for;
   12048                 :       21159 : }
   12049                 :             : 
   12050                 :             : /* Code walker for finish_omp_for_block: extract binding of DP->var
   12051                 :             :    from its current block and move it to a new BIND_EXPR DP->b
   12052                 :             :    surrounding the body of DP->omp_for.  */
   12053                 :             : 
   12054                 :             : struct fofb_data {
   12055                 :             :   tree var;
   12056                 :             :   tree b;
   12057                 :             :   tree omp_for;
   12058                 :             : };
   12059                 :             : 
   12060                 :             : static tree
   12061                 :         389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
   12062                 :             : {
   12063                 :         389 :   struct fofb_data *fofb = (struct fofb_data *)dp;
   12064                 :         389 :   if (TREE_CODE (*tp) == BIND_EXPR)
   12065                 :         578 :     for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
   12066                 :             :       {
   12067                 :         576 :         if (*p == fofb->var)
   12068                 :             :           {
   12069                 :         363 :             *p = DECL_CHAIN (*p);
   12070                 :         363 :             if (fofb->b == NULL_TREE)
   12071                 :             :               {
   12072                 :         214 :                 fofb->b = make_node (BLOCK);
   12073                 :         214 :                 fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
   12074                 :         214 :                             OMP_FOR_BODY (fofb->omp_for), fofb->b);
   12075                 :         214 :                 TREE_SIDE_EFFECTS (fofb->b) = 1;
   12076                 :         214 :                 OMP_FOR_BODY (fofb->omp_for) = fofb->b;
   12077                 :             :               }
   12078                 :         363 :             DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
   12079                 :         363 :             BIND_EXPR_VARS (fofb->b) = fofb->var;
   12080                 :         363 :             BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
   12081                 :         363 :             BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
   12082                 :         363 :             return *tp;
   12083                 :             :           }
   12084                 :             :       }
   12085                 :          26 :   if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
   12086                 :          22 :     *walk_subtrees = false;
   12087                 :             :   return NULL_TREE;
   12088                 :             : }
   12089                 :             : 
   12090                 :             : /* Fix up range for decls.  Those decls were pushed into BIND's
   12091                 :             :    BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
   12092                 :             :    and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
   12093                 :             :    so that processing of combined loop directives can find them.  */
   12094                 :             : tree
   12095                 :       14575 : finish_omp_for_block (tree bind, tree omp_for)
   12096                 :             : {
   12097                 :       14575 :   if (omp_for == NULL_TREE
   12098                 :       14528 :       || !OMP_FOR_ORIG_DECLS (omp_for)
   12099                 :       28516 :       || bind == NULL_TREE)
   12100                 :         634 :     return bind;
   12101                 :       13941 :   struct fofb_data fofb;
   12102                 :       13941 :   fofb.b = NULL_TREE;
   12103                 :       13941 :   fofb.omp_for = omp_for;
   12104                 :       33378 :   for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
   12105                 :       19437 :     if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
   12106                 :       19215 :         && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
   12107                 :             :             == TREE_LIST)
   12108                 :       20268 :         && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
   12109                 :             :       {
   12110                 :         237 :         tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
   12111                 :         602 :         for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
   12112                 :             :           {
   12113                 :         365 :             fofb.var = TREE_VEC_ELT (v, j);
   12114                 :         365 :             cp_walk_tree (&bind, finish_omp_for_block_walker,
   12115                 :             :                           (void *)&fofb, NULL);
   12116                 :             :           }
   12117                 :             :       }
   12118                 :       13941 :   return bind;
   12119                 :             : }
   12120                 :             : 
   12121                 :             : void
   12122                 :        3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
   12123                 :             :                    tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
   12124                 :             :                    tree clauses, enum omp_memory_order mo, bool weak)
   12125                 :             : {
   12126                 :        3342 :   tree orig_lhs;
   12127                 :        3342 :   tree orig_rhs;
   12128                 :        3342 :   tree orig_v;
   12129                 :        3342 :   tree orig_lhs1;
   12130                 :        3342 :   tree orig_rhs1;
   12131                 :        3342 :   tree orig_r;
   12132                 :        3342 :   bool dependent_p;
   12133                 :        3342 :   tree stmt;
   12134                 :             : 
   12135                 :        3342 :   orig_lhs = lhs;
   12136                 :        3342 :   orig_rhs = rhs;
   12137                 :        3342 :   orig_v = v;
   12138                 :        3342 :   orig_lhs1 = lhs1;
   12139                 :        3342 :   orig_rhs1 = rhs1;
   12140                 :        3342 :   orig_r = r;
   12141                 :        3342 :   dependent_p = false;
   12142                 :        3342 :   stmt = NULL_TREE;
   12143                 :             : 
   12144                 :             :   /* Even in a template, we can detect invalid uses of the atomic
   12145                 :             :      pragma if neither LHS nor RHS is type-dependent.  */
   12146                 :        3342 :   if (processing_template_decl)
   12147                 :             :     {
   12148                 :         600 :       dependent_p = (type_dependent_expression_p (lhs)
   12149                 :         237 :                      || (rhs && type_dependent_expression_p (rhs))
   12150                 :         234 :                      || (v && type_dependent_expression_p (v))
   12151                 :         234 :                      || (lhs1 && type_dependent_expression_p (lhs1))
   12152                 :         234 :                      || (rhs1 && type_dependent_expression_p (rhs1))
   12153                 :         834 :                      || (r
   12154                 :          25 :                          && r != void_list_node
   12155                 :          16 :                          && type_dependent_expression_p (r)));
   12156                 :         600 :       if (clauses)
   12157                 :             :         {
   12158                 :          30 :           gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
   12159                 :             :                       && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
   12160                 :             :                       && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
   12161                 :          30 :           if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
   12162                 :          30 :               || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
   12163                 :             :             dependent_p = true;
   12164                 :             :         }
   12165                 :             :     }
   12166                 :         576 :   if (!dependent_p)
   12167                 :             :     {
   12168                 :        2958 :       bool swapped = false;
   12169                 :        2958 :       if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
   12170                 :             :         {
   12171                 :         143 :           std::swap (rhs, rhs1);
   12172                 :         143 :           swapped = !commutative_tree_code (opcode);
   12173                 :             :         }
   12174                 :        2958 :       if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
   12175                 :             :         {
   12176                 :           0 :           if (code == OMP_ATOMIC)
   12177                 :           0 :             error ("%<#pragma omp atomic update%> uses two different "
   12178                 :             :                    "expressions for memory");
   12179                 :             :           else
   12180                 :           0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12181                 :             :                    "expressions for memory");
   12182                 :           0 :           return;
   12183                 :             :         }
   12184                 :        2958 :       if (lhs1 && !cp_tree_equal (lhs, lhs1))
   12185                 :             :         {
   12186                 :           0 :           if (code == OMP_ATOMIC)
   12187                 :           0 :             error ("%<#pragma omp atomic update%> uses two different "
   12188                 :             :                    "expressions for memory");
   12189                 :             :           else
   12190                 :           0 :             error ("%<#pragma omp atomic capture%> uses two different "
   12191                 :             :                    "expressions for memory");
   12192                 :           0 :           return;
   12193                 :             :         }
   12194                 :        5916 :       stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
   12195                 :             :                                   v, lhs1, rhs1, r, swapped, mo, weak,
   12196                 :        2958 :                                   processing_template_decl != 0);
   12197                 :        2958 :       if (stmt == error_mark_node)
   12198                 :             :         return;
   12199                 :             :     }
   12200                 :        3312 :   if (processing_template_decl)
   12201                 :             :     {
   12202                 :         591 :       if (code == OMP_ATOMIC_READ)
   12203                 :             :         {
   12204                 :         167 :           stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
   12205                 :         167 :           OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12206                 :         167 :           stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12207                 :             :         }
   12208                 :             :       else
   12209                 :             :         {
   12210                 :         424 :           if (opcode == NOP_EXPR)
   12211                 :          35 :             stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
   12212                 :         389 :           else if (opcode == COND_EXPR)
   12213                 :             :             {
   12214                 :         124 :               stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
   12215                 :         124 :               if (orig_r)
   12216                 :          50 :                 stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
   12217                 :             :                                stmt);
   12218                 :         124 :               stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
   12219                 :             :                              orig_lhs);
   12220                 :         124 :               orig_rhs1 = NULL_TREE;
   12221                 :             :             }
   12222                 :             :           else
   12223                 :         265 :             stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
   12224                 :         424 :           if (orig_rhs1)
   12225                 :         182 :             stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
   12226                 :             :                                      COMPOUND_EXPR, orig_rhs1, stmt);
   12227                 :         424 :           if (code != OMP_ATOMIC)
   12228                 :             :             {
   12229                 :         233 :               stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
   12230                 :         233 :               OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12231                 :         233 :               OMP_ATOMIC_WEAK (stmt) = weak;
   12232                 :         233 :               stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
   12233                 :             :             }
   12234                 :             :         }
   12235                 :         591 :       stmt = build2 (OMP_ATOMIC, void_type_node,
   12236                 :             :                      clauses ? clauses : integer_zero_node, stmt);
   12237                 :         591 :       OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
   12238                 :         591 :       OMP_ATOMIC_WEAK (stmt) = weak;
   12239                 :         591 :       SET_EXPR_LOCATION (stmt, loc);
   12240                 :             :     }
   12241                 :             : 
   12242                 :             :   /* Avoid -Wunused-value warnings here, the whole construct has side-effects
   12243                 :             :      and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
   12244                 :             :      in some tree that appears to be unused, the value is not unused.  */
   12245                 :        3312 :   warning_sentinel w (warn_unused_value);
   12246                 :        3312 :   finish_expr_stmt (stmt);
   12247                 :        3312 : }
   12248                 :             : 
   12249                 :             : void
   12250                 :         371 : finish_omp_barrier (void)
   12251                 :             : {
   12252                 :         371 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
   12253                 :         371 :   releasing_vec vec;
   12254                 :         371 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12255                 :         371 :   finish_expr_stmt (stmt);
   12256                 :         371 : }
   12257                 :             : 
   12258                 :             : void
   12259                 :         397 : finish_omp_depobj (location_t loc, tree depobj,
   12260                 :             :                    enum omp_clause_depend_kind kind, tree clause)
   12261                 :             : {
   12262                 :         397 :   if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
   12263                 :             :     {
   12264                 :         343 :       if (!lvalue_p (depobj))
   12265                 :             :         {
   12266                 :           6 :           error_at (EXPR_LOC_OR_LOC (depobj, loc),
   12267                 :             :                     "%<depobj%> expression is not lvalue expression");
   12268                 :           6 :           depobj = error_mark_node;
   12269                 :             :         }
   12270                 :             :     }
   12271                 :             : 
   12272                 :         397 :   if (processing_template_decl)
   12273                 :             :     {
   12274                 :         114 :       if (clause == NULL_TREE)
   12275                 :          47 :         clause = build_int_cst (integer_type_node, kind);
   12276                 :         114 :       add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
   12277                 :         114 :       return;
   12278                 :             :     }
   12279                 :             : 
   12280                 :         283 :   if (!error_operand_p (depobj))
   12281                 :             :     {
   12282                 :         274 :       tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
   12283                 :         274 :       if (addr == error_mark_node)
   12284                 :             :         depobj = error_mark_node;
   12285                 :             :       else
   12286                 :         274 :         depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
   12287                 :             :                                         tf_warning_or_error);
   12288                 :             :     }
   12289                 :             : 
   12290                 :         283 :   c_finish_omp_depobj (loc, depobj, kind, clause);
   12291                 :             : }
   12292                 :             : 
   12293                 :             : void
   12294                 :         168 : finish_omp_flush (int mo)
   12295                 :             : {
   12296                 :         168 :   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   12297                 :         168 :   releasing_vec vec;
   12298                 :         168 :   if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
   12299                 :             :     {
   12300                 :          54 :       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
   12301                 :          54 :       vec->quick_push (build_int_cst (integer_type_node, mo));
   12302                 :             :     }
   12303                 :         168 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12304                 :         168 :   finish_expr_stmt (stmt);
   12305                 :         168 : }
   12306                 :             : 
   12307                 :             : void
   12308                 :         111 : finish_omp_taskwait (void)
   12309                 :             : {
   12310                 :         111 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
   12311                 :         111 :   releasing_vec vec;
   12312                 :         111 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12313                 :         111 :   finish_expr_stmt (stmt);
   12314                 :         111 : }
   12315                 :             : 
   12316                 :             : void
   12317                 :          16 : finish_omp_taskyield (void)
   12318                 :             : {
   12319                 :          16 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
   12320                 :          16 :   releasing_vec vec;
   12321                 :          16 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12322                 :          16 :   finish_expr_stmt (stmt);
   12323                 :          16 : }
   12324                 :             : 
   12325                 :             : void
   12326                 :         596 : finish_omp_cancel (tree clauses)
   12327                 :             : {
   12328                 :         596 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   12329                 :         596 :   int mask = 0;
   12330                 :         596 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12331                 :             :     mask = 1;
   12332                 :         414 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12333                 :             :     mask = 2;
   12334                 :         285 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12335                 :             :     mask = 4;
   12336                 :         164 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12337                 :             :     mask = 8;
   12338                 :             :   else
   12339                 :             :     {
   12340                 :           0 :       error ("%<#pragma omp cancel%> must specify one of "
   12341                 :             :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12342                 :           0 :       return;
   12343                 :             :     }
   12344                 :         596 :   releasing_vec vec;
   12345                 :         596 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   12346                 :         596 :   if (ifc != NULL_TREE)
   12347                 :             :     {
   12348                 :          70 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   12349                 :          70 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   12350                 :           6 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   12351                 :             :                   "expected %<cancel%> %<if%> clause modifier");
   12352                 :             :       else
   12353                 :             :         {
   12354                 :          64 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   12355                 :          64 :           if (ifc2 != NULL_TREE)
   12356                 :             :             {
   12357                 :           3 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   12358                 :             :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   12359                 :             :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   12360                 :           3 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   12361                 :             :                         "expected %<cancel%> %<if%> clause modifier");
   12362                 :             :             }
   12363                 :             :         }
   12364                 :             : 
   12365                 :          70 :       if (!processing_template_decl)
   12366                 :          61 :         ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
   12367                 :             :       else
   12368                 :           9 :         ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   12369                 :           9 :                                  OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
   12370                 :             :                                  integer_zero_node, ERROR_MARK,
   12371                 :             :                                  NULL_TREE, NULL, tf_warning_or_error);
   12372                 :             :     }
   12373                 :             :   else
   12374                 :         526 :     ifc = boolean_true_node;
   12375                 :         596 :   vec->quick_push (build_int_cst (integer_type_node, mask));
   12376                 :         596 :   vec->quick_push (ifc);
   12377                 :         596 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12378                 :         596 :   finish_expr_stmt (stmt);
   12379                 :         596 : }
   12380                 :             : 
   12381                 :             : void
   12382                 :         494 : finish_omp_cancellation_point (tree clauses)
   12383                 :             : {
   12384                 :         494 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   12385                 :         494 :   int mask = 0;
   12386                 :         494 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   12387                 :             :     mask = 1;
   12388                 :         366 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   12389                 :             :     mask = 2;
   12390                 :         261 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   12391                 :             :     mask = 4;
   12392                 :         156 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   12393                 :             :     mask = 8;
   12394                 :             :   else
   12395                 :             :     {
   12396                 :           3 :       error ("%<#pragma omp cancellation point%> must specify one of "
   12397                 :             :              "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
   12398                 :           3 :       return;
   12399                 :             :     }
   12400                 :         491 :   releasing_vec vec
   12401                 :         491 :     = make_tree_vector_single (build_int_cst (integer_type_node, mask));
   12402                 :         491 :   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   12403                 :         491 :   finish_expr_stmt (stmt);
   12404                 :         491 : }
   12405                 :             : 
   12406                 :             : /* Begin a __transaction_atomic or __transaction_relaxed statement.
   12407                 :             :    If PCOMPOUND is non-null, this is for a function-transaction-block, and we
   12408                 :             :    should create an extra compound stmt.  */
   12409                 :             : 
   12410                 :             : tree
   12411                 :         303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
   12412                 :             : {
   12413                 :         303 :   tree r;
   12414                 :             : 
   12415                 :         303 :   if (pcompound)
   12416                 :          21 :     *pcompound = begin_compound_stmt (0);
   12417                 :             : 
   12418                 :         303 :   r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
   12419                 :             : 
   12420                 :             :   /* Only add the statement to the function if support enabled.  */
   12421                 :         303 :   if (flag_tm)
   12422                 :         297 :     add_stmt (r);
   12423                 :             :   else
   12424                 :          12 :     error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
   12425                 :             :                     ? G_("%<__transaction_relaxed%> without "
   12426                 :             :                          "transactional memory support enabled")
   12427                 :             :                     : G_("%<__transaction_atomic%> without "
   12428                 :             :                          "transactional memory support enabled")));
   12429                 :             : 
   12430                 :         303 :   TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
   12431                 :         303 :   TREE_SIDE_EFFECTS (r) = 1;
   12432                 :         303 :   return r;
   12433                 :             : }
   12434                 :             : 
   12435                 :             : /* End a __transaction_atomic or __transaction_relaxed statement.
   12436                 :             :    If COMPOUND_STMT is non-null, this is for a function-transaction-block,
   12437                 :             :    and we should end the compound.  If NOEX is non-NULL, we wrap the body in
   12438                 :             :    a MUST_NOT_THROW_EXPR with NOEX as condition.  */
   12439                 :             : 
   12440                 :             : void
   12441                 :         303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
   12442                 :             : {
   12443                 :         303 :   TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
   12444                 :         303 :   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   12445                 :         303 :   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
   12446                 :         303 :   TRANSACTION_EXPR_IS_STMT (stmt) = 1;
   12447                 :             : 
   12448                 :             :   /* noexcept specifications are not allowed for function transactions.  */
   12449                 :         303 :   gcc_assert (!(noex && compound_stmt));
   12450                 :         303 :   if (noex)
   12451                 :             :     {
   12452                 :          51 :       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
   12453                 :             :                                              noex);
   12454                 :          51 :       protected_set_expr_location
   12455                 :          51 :         (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
   12456                 :          51 :       TREE_SIDE_EFFECTS (body) = 1;
   12457                 :          51 :       TRANSACTION_EXPR_BODY (stmt) = body;
   12458                 :             :     }
   12459                 :             : 
   12460                 :         303 :   if (compound_stmt)
   12461                 :          21 :     finish_compound_stmt (compound_stmt);
   12462                 :         303 : }
   12463                 :             : 
   12464                 :             : /* Build a __transaction_atomic or __transaction_relaxed expression.  If
   12465                 :             :    NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
   12466                 :             :    condition.  */
   12467                 :             : 
   12468                 :             : tree
   12469                 :         116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
   12470                 :             : {
   12471                 :         116 :   tree ret;
   12472                 :         116 :   if (noex)
   12473                 :             :     {
   12474                 :          57 :       expr = build_must_not_throw_expr (expr, noex);
   12475                 :          57 :       protected_set_expr_location (expr, loc);
   12476                 :          57 :       TREE_SIDE_EFFECTS (expr) = 1;
   12477                 :             :     }
   12478                 :         116 :   ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
   12479                 :         116 :   if (flags & TM_STMT_ATTR_RELAXED)
   12480                 :           4 :         TRANSACTION_EXPR_RELAXED (ret) = 1;
   12481                 :         116 :   TREE_SIDE_EFFECTS (ret) = 1;
   12482                 :         116 :   SET_EXPR_LOCATION (ret, loc);
   12483                 :         116 :   return ret;
   12484                 :             : }
   12485                 :             : 
   12486                 :             : void
   12487                 :       96471 : init_cp_semantics (void)
   12488                 :             : {
   12489                 :       96471 : }
   12490                 :             : 
   12491                 :             : 
   12492                 :             : /* Get constant string at LOCATION. Returns true if successful,
   12493                 :             :    otherwise false.  */
   12494                 :             : 
   12495                 :             : bool
   12496                 :     9031903 : cexpr_str::type_check (location_t location)
   12497                 :             : {
   12498                 :     9031903 :   tsubst_flags_t complain = tf_warning_or_error;
   12499                 :             : 
   12500                 :     9031903 :   if (message == NULL_TREE
   12501                 :     9031903 :       || message == error_mark_node
   12502                 :    18063803 :       || check_for_bare_parameter_packs (message))
   12503                 :           3 :     return false;
   12504                 :             : 
   12505                 :     9031900 :   if (TREE_CODE (message) != STRING_CST
   12506                 :     9031900 :       && !type_dependent_expression_p (message))
   12507                 :             :     {
   12508                 :         887 :       message_sz
   12509                 :         887 :         = finish_class_member_access_expr (message,
   12510                 :             :                                            get_identifier ("size"),
   12511                 :             :                                            false, complain);
   12512                 :         887 :       if (message_sz != error_mark_node)
   12513                 :         814 :         message_data
   12514                 :         814 :           = finish_class_member_access_expr (message,
   12515                 :             :                                              get_identifier ("data"),
   12516                 :             :                                              false, complain);
   12517                 :         887 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12518                 :             :         {
   12519                 :         103 :           error_at (location, "constexpr string must be a string "
   12520                 :             :                     "literal or object with %<size%> and "
   12521                 :             :                     "%<data%> members");
   12522                 :         262 :           return false;
   12523                 :             :         }
   12524                 :         784 :       releasing_vec size_args, data_args;
   12525                 :         784 :       message_sz = finish_call_expr (message_sz, &size_args, false, false,
   12526                 :             :                                      complain);
   12527                 :         784 :       message_data = finish_call_expr (message_data, &data_args, false, false,
   12528                 :             :                                        complain);
   12529                 :         784 :       if (message_sz == error_mark_node || message_data == error_mark_node)
   12530                 :             :         return false;
   12531                 :         670 :       message_sz = build_converted_constant_expr (size_type_node, message_sz,
   12532                 :             :                                                        complain);
   12533                 :         670 :       if (message_sz == error_mark_node)
   12534                 :             :         {
   12535                 :          15 :           error_at (location, "constexpr string %<size()%> "
   12536                 :             :                     "must be implicitly convertible to "
   12537                 :             :                     "%<std::size_t%>");
   12538                 :          15 :           return false;
   12539                 :             :         }
   12540                 :         655 :       message_data = build_converted_constant_expr (const_string_type_node,
   12541                 :             :                                                          message_data, complain);
   12542                 :         655 :       if (message_data == error_mark_node)
   12543                 :             :         {
   12544                 :          30 :           error_at (location, "constexpr string %<data()%> "
   12545                 :             :                     "must be implicitly convertible to "
   12546                 :             :                     "%<const char*%>");
   12547                 :          30 :           return false;
   12548                 :             :         }
   12549                 :         784 :     }
   12550                 :             :   return true;
   12551                 :             : }
   12552                 :             : 
   12553                 :             : /* Extract constant string at LOCATON into output string STR.
   12554                 :             :    Returns true if successful, otherwise false.  */
   12555                 :             : 
   12556                 :             : bool
   12557                 :         393 : cexpr_str::extract (location_t location, tree &str)
   12558                 :             : {
   12559                 :         393 :   const char *msg;
   12560                 :         393 :   int len;
   12561                 :         393 :   if (!extract (location, msg, len))
   12562                 :             :     return false;
   12563                 :         331 :   str = build_string (len, msg);
   12564                 :         331 :   return true;
   12565                 :             : }
   12566                 :             : 
   12567                 :             : /* Extract constant string at LOCATION into output string MSG with LEN.
   12568                 :             :    Returns true if successful, otherwise false.  */
   12569                 :             : 
   12570                 :             : bool
   12571                 :        2013 : cexpr_str::extract (location_t location, const char * & msg, int &len)
   12572                 :             : {
   12573                 :        2013 :   tsubst_flags_t complain = tf_warning_or_error;
   12574                 :             : 
   12575                 :        2013 :   msg = NULL;
   12576                 :        2013 :   if (message_sz && message_data)
   12577                 :             :     {
   12578                 :         551 :       tree msz = cxx_constant_value (message_sz, NULL_TREE, complain);
   12579                 :         551 :       if (!tree_fits_uhwi_p (msz))
   12580                 :             :         {
   12581                 :          35 :           error_at (location,
   12582                 :             :                     "constexpr string %<size()%> "
   12583                 :             :                     "must be a constant expression");
   12584                 :          35 :           return false;
   12585                 :             :         }
   12586                 :         516 :       else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
   12587                 :             :                != tree_to_uhwi (msz))
   12588                 :             :         {
   12589                 :           0 :           error_at (location,
   12590                 :             :                     "constexpr string message %<size()%> "
   12591                 :             :                     "%qE too large", msz);
   12592                 :           0 :           return false;
   12593                 :             :         }
   12594                 :         516 :       len = tree_to_uhwi (msz);
   12595                 :         516 :       tree data = maybe_constant_value (message_data, NULL_TREE,
   12596                 :             :                                         mce_true);
   12597                 :         516 :       if (!reduced_constant_expression_p (data))
   12598                 :          96 :         data = NULL_TREE;
   12599                 :         516 :       if (len)
   12600                 :             :         {
   12601                 :         439 :           if (data)
   12602                 :         365 :             msg = c_getstr (data);
   12603                 :         439 :           if (msg == NULL)
   12604                 :         119 :             buf = XNEWVEC (char, len);
   12605                 :        1413 :           for (int i = 0; i < len; ++i)
   12606                 :             :             {
   12607                 :        1004 :               tree t = message_data;
   12608                 :        1004 :               if (i)
   12609                 :        1130 :                 t = build2 (POINTER_PLUS_EXPR,
   12610                 :         565 :                             TREE_TYPE (message_data), message_data,
   12611                 :         565 :                             size_int (i));
   12612                 :        1004 :               t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
   12613                 :        1004 :               tree t2 = cxx_constant_value (t, NULL_TREE, complain);
   12614                 :        1004 :               if (!tree_fits_shwi_p (t2))
   12615                 :             :                 {
   12616                 :          30 :                   error_at (location,
   12617                 :             :                             "constexpr string %<data()[%d]%> "
   12618                 :             :                             "must be a constant expression", i);
   12619                 :          30 :                   return false;
   12620                 :             :                 }
   12621                 :         974 :               if (msg == NULL)
   12622                 :         362 :                 buf[i] = tree_to_shwi (t2);
   12623                 :             :               /* If c_getstr worked, just verify the first and
   12624                 :             :                  last characters using constant evaluation.  */
   12625                 :         612 :               else if (len > 2 && i == 0)
   12626                 :         258 :                 i = len - 2;
   12627                 :             :             }
   12628                 :         409 :           if (msg == NULL)
   12629                 :         104 :             msg = buf;
   12630                 :             :         }
   12631                 :          77 :       else if (!data)
   12632                 :             :         {
   12633                 :             :           /* We don't have any function to test whether some
   12634                 :             :              expression is a core constant expression.  So, instead
   12635                 :             :              test whether (message.data (), 0) is a constant
   12636                 :             :              expression.  */
   12637                 :          22 :           data = build2 (COMPOUND_EXPR, integer_type_node,
   12638                 :             :                          message_data, integer_zero_node);
   12639                 :          22 :           tree t = cxx_constant_value (data, NULL_TREE, complain);
   12640                 :          22 :           if (!integer_zerop (t))
   12641                 :             :             {
   12642                 :          22 :               error_at (location,
   12643                 :             :                         "constexpr string %<data()%> "
   12644                 :             :                         "must be a core constant expression");
   12645                 :          22 :               return false;
   12646                 :             :             }
   12647                 :             :         }
   12648                 :             :     }
   12649                 :             :   else
   12650                 :             :     {
   12651                 :        1462 :       tree eltype = TREE_TYPE (TREE_TYPE (message));
   12652                 :        1462 :       int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
   12653                 :        1462 :       msg = TREE_STRING_POINTER (message);
   12654                 :        1462 :       len = TREE_STRING_LENGTH (message) / sz - 1;
   12655                 :             :     }
   12656                 :             : 
   12657                 :             :   return true;
   12658                 :             : }
   12659                 :             : 
   12660                 :             : /* Build a STATIC_ASSERT for a static assertion with the condition
   12661                 :             :    CONDITION and the message text MESSAGE.  LOCATION is the location
   12662                 :             :    of the static assertion in the source code.  When MEMBER_P, this
   12663                 :             :    static assertion is a member of a class.  If SHOW_EXPR_P is true,
   12664                 :             :    print the condition (because it was instantiation-dependent).
   12665                 :             :    If CONSTEVAL_BLOCK_P is true, this static assertion represents
   12666                 :             :    a consteval block.  */
   12667                 :             : 
   12668                 :             : void
   12669                 :     9031495 : finish_static_assert (tree condition, tree message, location_t location,
   12670                 :             :                       bool member_p, bool show_expr_p,
   12671                 :             :                       bool consteval_block_p/*=false*/)
   12672                 :             : {
   12673                 :     9031495 :   tsubst_flags_t complain = tf_warning_or_error;
   12674                 :             : 
   12675                 :     9031495 :   if (condition == NULL_TREE
   12676                 :     9031495 :       || condition == error_mark_node)
   12677                 :     4079957 :     return;
   12678                 :             : 
   12679                 :     9031342 :   if (check_for_bare_parameter_packs (condition))
   12680                 :             :     return;
   12681                 :             : 
   12682                 :     9031339 :   cexpr_str cstr(message);
   12683                 :     9031339 :   if (!cstr.type_check (location))
   12684                 :             :     return;
   12685                 :             : 
   12686                 :             :   /* Save the condition in case it was a concept check.  */
   12687                 :     9031245 :   tree orig_condition = condition;
   12688                 :             : 
   12689                 :     9031245 :   if (instantiation_dependent_expression_p (condition)
   12690                 :     9031245 :       || instantiation_dependent_expression_p (message))
   12691                 :             :     {
   12692                 :             :       /* We're in a template; build a STATIC_ASSERT and put it in
   12693                 :             :          the right place. */
   12694                 :     4079631 :     defer:
   12695                 :     4079631 :       tree assertion = make_node (STATIC_ASSERT);
   12696                 :     4079631 :       STATIC_ASSERT_CONDITION (assertion) = orig_condition;
   12697                 :     4079631 :       STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
   12698                 :     4079631 :       STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
   12699                 :     4079631 :       CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
   12700                 :             : 
   12701                 :     4079631 :       if (member_p)
   12702                 :     2215773 :         maybe_add_class_template_decl_list (current_class_type,
   12703                 :             :                                             assertion,
   12704                 :             :                                             /*friend_p=*/0);
   12705                 :             :       else
   12706                 :     1863858 :         add_stmt (assertion);
   12707                 :             : 
   12708                 :     4079631 :       return;
   12709                 :             :     }
   12710                 :             : 
   12711                 :             :   /* Evaluate the consteval { }.  This must be done only once.  */
   12712                 :     4954941 :   if (consteval_block_p)
   12713                 :             :     {
   12714                 :          51 :       cxx_constant_value (condition);
   12715                 :          51 :       return;
   12716                 :             :     }
   12717                 :             : 
   12718                 :             :   /* Fold the expression and convert it to a boolean value. */
   12719                 :     4954890 :   condition = contextual_conv_bool (condition, complain);
   12720                 :     4954890 :   condition = fold_non_dependent_expr (condition, complain,
   12721                 :             :                                        /*manifestly_const_eval=*/true);
   12722                 :             : 
   12723                 :     4954889 :   if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
   12724                 :             :     /* Do nothing; the condition is satisfied. */
   12725                 :             :     ;
   12726                 :             :   else
   12727                 :             :     {
   12728                 :        5244 :       iloc_sentinel ils (location);
   12729                 :             : 
   12730                 :        5244 :       if (integer_zerop (condition))
   12731                 :             :         {
   12732                 :             :           /* CWG2518: static_assert failure in a template is not IFNDR.  */
   12733                 :        4947 :           if (processing_template_decl)
   12734                 :        3327 :             goto defer;
   12735                 :             : 
   12736                 :        1620 :           int len;
   12737                 :        1620 :           const char *msg = NULL;
   12738                 :        1620 :           if (!cstr.extract (location, msg, len))
   12739                 :          25 :             return;
   12740                 :             : 
   12741                 :             :           /* See if we can find which clause was failing (for logical AND).  */
   12742                 :        1595 :           tree bad = find_failing_clause (NULL, orig_condition);
   12743                 :             :           /* If not, or its location is unusable, fall back to the previous
   12744                 :             :              location.  */
   12745                 :        1595 :           location_t cloc = cp_expr_loc_or_loc (bad, location);
   12746                 :             : 
   12747                 :        1595 :           auto_diagnostic_group d;
   12748                 :             : 
   12749                 :             :           /* Report the error. */
   12750                 :        1595 :           if (len == 0)
   12751                 :         948 :             error_at (cloc, "static assertion failed");
   12752                 :             :           else
   12753                 :         647 :             error_at (cloc, "static assertion failed: %.*s", len, msg);
   12754                 :             : 
   12755                 :        1595 :           diagnose_failing_condition (bad, cloc, show_expr_p);
   12756                 :        1595 :         }
   12757                 :         297 :       else if (condition && condition != error_mark_node)
   12758                 :             :         {
   12759                 :         294 :           error ("non-constant condition for static assertion");
   12760                 :         294 :           if (require_rvalue_constant_expression (condition))
   12761                 :         238 :             cxx_constant_value (condition);
   12762                 :             :         }
   12763                 :        5244 :     }
   12764                 :     9031338 : }
   12765                 :             : 
   12766                 :             : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
   12767                 :             :    suitable for use as a type-specifier.
   12768                 :             : 
   12769                 :             :    ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
   12770                 :             :    id-expression or a class member access, FALSE when it was parsed as
   12771                 :             :    a full expression.  */
   12772                 :             : 
   12773                 :             : tree
   12774                 :    26949289 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
   12775                 :             :                       tsubst_flags_t complain)
   12776                 :             : {
   12777                 :    26949289 :   tree type = NULL_TREE;
   12778                 :             : 
   12779                 :    26949289 :   if (!expr || error_operand_p (expr))
   12780                 :      122780 :     return error_mark_node;
   12781                 :             : 
   12782                 :    26826509 :   if (TYPE_P (expr)
   12783                 :    26826509 :       || TREE_CODE (expr) == TYPE_DECL
   12784                 :    53653000 :       || (TREE_CODE (expr) == BIT_NOT_EXPR
   12785                 :       13345 :           && TYPE_P (TREE_OPERAND (expr, 0))))
   12786                 :             :     {
   12787                 :          27 :       if (complain & tf_error)
   12788                 :          27 :         error ("argument to %<decltype%> must be an expression");
   12789                 :          27 :       return error_mark_node;
   12790                 :             :     }
   12791                 :             : 
   12792                 :             :   /* decltype is an unevaluated context.  */
   12793                 :    26826482 :   cp_unevaluated u;
   12794                 :             : 
   12795                 :    26826482 :   processing_template_decl_sentinel ptds (/*reset=*/false);
   12796                 :             : 
   12797                 :             :   /* Depending on the resolution of DR 1172, we may later need to distinguish
   12798                 :             :      instantiation-dependent but not type-dependent expressions so that, say,
   12799                 :             :      A<decltype(sizeof(T))>::U doesn't require 'typename'.  */
   12800                 :    26826482 :   if (instantiation_dependent_uneval_expression_p (expr))
   12801                 :             :     {
   12802                 :     4724372 :     dependent:
   12803                 :     4724756 :       type = cxx_make_type (DECLTYPE_TYPE);
   12804                 :     4724756 :       DECLTYPE_TYPE_EXPR (type) = expr;
   12805                 :     9449512 :       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
   12806                 :     4724756 :         = id_expression_or_member_access_p;
   12807                 :     4724756 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   12808                 :             : 
   12809                 :     4724756 :       return type;
   12810                 :             :     }
   12811                 :    22102110 :   else if (processing_template_decl)
   12812                 :             :     {
   12813                 :        4887 :       expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
   12814                 :        4887 :       if (expr == error_mark_node)
   12815                 :             :         return error_mark_node;
   12816                 :             :       /* Keep processing_template_decl cleared for the rest of the function
   12817                 :             :          (for sake of the call to lvalue_kind below, which handles templated
   12818                 :             :          and non-templated COND_EXPR differently).  */
   12819                 :        4849 :       processing_template_decl = 0;
   12820                 :             :     }
   12821                 :             : 
   12822                 :             :   /* The type denoted by decltype(e) is defined as follows:  */
   12823                 :             : 
   12824                 :    22102072 :   expr = resolve_nondeduced_context (expr, complain);
   12825                 :    22102072 :   if (!mark_single_function (expr, complain))
   12826                 :           0 :     return error_mark_node;
   12827                 :             : 
   12828                 :    22102072 :   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
   12829                 :          18 :     return error_mark_node;
   12830                 :             : 
   12831                 :    22102054 :   if (type_unknown_p (expr))
   12832                 :             :     {
   12833                 :          18 :       if (complain & tf_error)
   12834                 :           6 :         error ("%<decltype%> cannot resolve address of overloaded function");
   12835                 :          18 :       return error_mark_node;
   12836                 :             :     }
   12837                 :             : 
   12838                 :    22102036 :   if (id_expression_or_member_access_p)
   12839                 :             :     {
   12840                 :             :       /* If e is an id-expression or a class member access (5.2.5
   12841                 :             :          [expr.ref]), decltype(e) is defined as the type of the entity
   12842                 :             :          named by e. If there is no such entity, or e names a set of
   12843                 :             :          overloaded functions, the program is ill-formed.  */
   12844                 :      903258 :       if (identifier_p (expr))
   12845                 :           0 :         expr = lookup_name (expr);
   12846                 :             : 
   12847                 :      903258 :       if (INDIRECT_REF_P (expr)
   12848                 :      903258 :           || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
   12849                 :             :         /* This can happen when the expression is, e.g., "a.b". Just
   12850                 :             :            look at the underlying operand.  */
   12851                 :      772356 :         expr = TREE_OPERAND (expr, 0);
   12852                 :             : 
   12853                 :      903258 :       if (TREE_CODE (expr) == OFFSET_REF
   12854                 :      903258 :           || TREE_CODE (expr) == MEMBER_REF
   12855                 :      903258 :           || TREE_CODE (expr) == SCOPE_REF)
   12856                 :             :         /* We're only interested in the field itself. If it is a
   12857                 :             :            BASELINK, we will need to see through it in the next
   12858                 :             :            step.  */
   12859                 :           0 :         expr = TREE_OPERAND (expr, 1);
   12860                 :             : 
   12861                 :      903258 :       if (BASELINK_P (expr))
   12862                 :             :         /* See through BASELINK nodes to the underlying function.  */
   12863                 :           3 :         expr = BASELINK_FUNCTIONS (expr);
   12864                 :             : 
   12865                 :             :       /* decltype of a decomposition name drops references in the tuple case
   12866                 :             :          (unlike decltype of a normal variable) and keeps cv-qualifiers from
   12867                 :             :          the containing object in the other cases (unlike decltype of a member
   12868                 :             :          access expression).  */
   12869                 :      903258 :       if (DECL_DECOMPOSITION_P (expr))
   12870                 :             :         {
   12871                 :        1368 :           if (ptds.saved)
   12872                 :             :             {
   12873                 :         266 :               gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
   12874                 :             :               /* DECL_HAS_VALUE_EXPR_P is always set if
   12875                 :             :                  processing_template_decl.  If lookup_decomp_type
   12876                 :             :                  returns non-NULL, it is the tuple case.  */
   12877                 :         266 :               if (tree ret = lookup_decomp_type (expr))
   12878                 :             :                 return ret;
   12879                 :             :             }
   12880                 :        1293 :           if (DECL_HAS_VALUE_EXPR_P (expr))
   12881                 :             :             /* Expr is an array or struct subobject proxy, handle
   12882                 :             :                bit-fields properly.  */
   12883                 :        1013 :             return unlowered_expr_type (expr);
   12884                 :             :           else
   12885                 :             :             /* Expr is a reference variable for the tuple case.  */
   12886                 :         280 :             return lookup_decomp_type (expr);
   12887                 :             :         }
   12888                 :             : 
   12889                 :      901890 :       switch (TREE_CODE (expr))
   12890                 :             :         {
   12891                 :          30 :         case FIELD_DECL:
   12892                 :          30 :           if (DECL_BIT_FIELD_TYPE (expr))
   12893                 :             :             {
   12894                 :             :               type = DECL_BIT_FIELD_TYPE (expr);
   12895                 :             :               break;
   12896                 :             :             }
   12897                 :             :           /* Fall through for fields that aren't bitfields.  */
   12898                 :      114137 :           gcc_fallthrough ();
   12899                 :             : 
   12900                 :      114137 :         case VAR_DECL:
   12901                 :      114137 :           if (is_capture_proxy (expr))
   12902                 :             :             {
   12903                 :          85 :               if (is_normal_capture_proxy (expr))
   12904                 :             :                 {
   12905                 :          21 :                   expr = DECL_CAPTURED_VARIABLE (expr);
   12906                 :          21 :                   type = TREE_TYPE (expr);
   12907                 :             :                 }
   12908                 :             :               else
   12909                 :             :                 {
   12910                 :          64 :                   expr = DECL_VALUE_EXPR (expr);
   12911                 :          64 :                   gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
   12912                 :          64 :                   expr = TREE_OPERAND (expr, 1);
   12913                 :          64 :                   type = TREE_TYPE (expr);
   12914                 :             :                 }
   12915                 :             :               break;
   12916                 :             :             }
   12917                 :             :           /* Fall through for variables that aren't capture proxies.  */
   12918                 :      898454 :           gcc_fallthrough ();
   12919                 :             : 
   12920                 :      898454 :         case FUNCTION_DECL:
   12921                 :      898454 :         case CONST_DECL:
   12922                 :      898454 :         case PARM_DECL:
   12923                 :      898454 :         case RESULT_DECL:
   12924                 :      898454 :         case TEMPLATE_PARM_INDEX:
   12925                 :      898454 :           expr = mark_type_use (expr);
   12926                 :      898454 :           type = TREE_TYPE (expr);
   12927                 :      898454 :           if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
   12928                 :             :             {
   12929                 :             :               /* decltype of an NTTP object is the type of the template
   12930                 :             :                  parameter, which is the object type modulo cv-quals.  */
   12931                 :         495 :               int quals = cp_type_quals (type);
   12932                 :         495 :               gcc_checking_assert (quals & TYPE_QUAL_CONST);
   12933                 :         495 :               type = cv_unqualified (type);
   12934                 :             :             }
   12935                 :             :           break;
   12936                 :             : 
   12937                 :           0 :         case ERROR_MARK:
   12938                 :           0 :           type = error_mark_node;
   12939                 :           0 :           break;
   12940                 :             : 
   12941                 :        2838 :         case COMPONENT_REF:
   12942                 :        2838 :         case COMPOUND_EXPR:
   12943                 :        2838 :           mark_type_use (expr);
   12944                 :        2838 :           type = is_bitfield_expr_with_lowered_type (expr);
   12945                 :        2838 :           if (!type)
   12946                 :        2805 :             type = TREE_TYPE (TREE_OPERAND (expr, 1));
   12947                 :             :           break;
   12948                 :             : 
   12949                 :           0 :         case BIT_FIELD_REF:
   12950                 :           0 :           gcc_unreachable ();
   12951                 :             : 
   12952                 :         273 :         case INTEGER_CST:
   12953                 :         273 :         case PTRMEM_CST:
   12954                 :             :           /* We can get here when the id-expression refers to an
   12955                 :             :              enumerator or non-type template parameter.  */
   12956                 :         273 :           type = TREE_TYPE (expr);
   12957                 :         273 :           break;
   12958                 :             : 
   12959                 :         240 :         default:
   12960                 :             :           /* Handle instantiated template non-type arguments.  */
   12961                 :         240 :           type = TREE_TYPE (expr);
   12962                 :         240 :           break;
   12963                 :             :         }
   12964                 :             :     }
   12965                 :             :   else
   12966                 :             :     {
   12967                 :    21198778 :       tree decl = STRIP_REFERENCE_REF (expr);
   12968                 :    21198778 :       tree lam = current_lambda_expr ();
   12969                 :    21198778 :       if (lam && outer_automatic_var_p (decl))
   12970                 :             :         {
   12971                 :             :           /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
   12972                 :             :              unevaluated operand within S would refer to an entity captured by
   12973                 :             :              copy in some intervening lambda-expression, then let E be the
   12974                 :             :              innermost such lambda-expression.
   12975                 :             : 
   12976                 :             :              If there is such a lambda-expression and if P is in E's function
   12977                 :             :              parameter scope but not its parameter-declaration-clause, then the
   12978                 :             :              type of the expression is the type of a class member access
   12979                 :             :              expression naming the non-static data member that would be declared
   12980                 :             :              for such a capture in the object parameter of the function call
   12981                 :             :              operator of E."  */
   12982                 :             :           /* FIXME: This transformation needs to happen for all uses of an outer
   12983                 :             :              local variable inside decltype, not just decltype((x)) (PR83167).
   12984                 :             :              And we don't handle nested lambdas properly, where we need to
   12985                 :             :              consider the outer lambdas as well (PR112926). */
   12986                 :         940 :           tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
   12987                 :             :                                   LOOK_want::HIDDEN_LAMBDA);
   12988                 :             : 
   12989                 :         940 :           if (cap && is_capture_proxy (cap))
   12990                 :         319 :             type = TREE_TYPE (cap);
   12991                 :         621 :           else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
   12992                 :             :             {
   12993                 :         500 :               type = TREE_TYPE (decl);
   12994                 :         500 :               if (TYPE_REF_P (type)
   12995                 :         500 :                   && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
   12996                 :          25 :                 type = TREE_TYPE (type);
   12997                 :             :             }
   12998                 :             : 
   12999                 :         819 :           if (type && !TYPE_REF_P (type))
   13000                 :             :             {
   13001                 :         761 :               int quals;
   13002                 :         761 :               if (current_function_decl
   13003                 :        1428 :                   && LAMBDA_FUNCTION_P (current_function_decl)
   13004                 :        1428 :                   && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
   13005                 :             :                 {
   13006                 :         600 :                   tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
   13007                 :         600 :                   if (WILDCARD_TYPE_P (non_reference (obtype)))
   13008                 :             :                     /* We don't know what the eventual obtype quals will be.  */
   13009                 :         384 :                     goto dependent;
   13010                 :         432 :                   auto direct_type = [](tree t){
   13011                 :         216 :                       if (INDIRECT_TYPE_P (t))
   13012                 :         108 :                         return TREE_TYPE (t);
   13013                 :             :                       return t;
   13014                 :             :                    };
   13015                 :         432 :                   quals = (cp_type_quals (type)
   13016                 :         216 :                            | cp_type_quals (direct_type (obtype)));
   13017                 :             :                 }
   13018                 :             :               else
   13019                 :             :                 /* We are in the parameter clause, trailing return type, or
   13020                 :             :                    the requires clause and have no relevant c_f_decl yet.  */
   13021                 :         251 :                 quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
   13022                 :         161 :                          ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
   13023                 :         377 :               type = cp_build_qualified_type (type, quals);
   13024                 :         377 :               type = build_reference_type (type);
   13025                 :             :             }
   13026                 :             :         }
   13027                 :    21197838 :       else if (error_operand_p (expr))
   13028                 :           0 :         type = error_mark_node;
   13029                 :    21197838 :       else if (expr == current_class_ptr)
   13030                 :             :         /* If the expression is just "this", we want the
   13031                 :             :            cv-unqualified pointer for the "this" type.  */
   13032                 :           0 :         type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
   13033                 :             : 
   13034                 :         377 :       if (!type)
   13035                 :             :         {
   13036                 :             :           /* Otherwise, where T is the type of e, if e is an lvalue,
   13037                 :             :              decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
   13038                 :    21197959 :           cp_lvalue_kind clk = lvalue_kind (expr);
   13039                 :    21197959 :           type = unlowered_expr_type (expr);
   13040                 :    21197959 :           gcc_assert (!TYPE_REF_P (type));
   13041                 :             : 
   13042                 :             :           /* For vector types, pick a non-opaque variant.  */
   13043                 :    21197959 :           if (VECTOR_TYPE_P (type))
   13044                 :         127 :             type = strip_typedefs (type);
   13045                 :             : 
   13046                 :    21197959 :           if (clk != clk_none && !(clk & clk_class))
   13047                 :     3818608 :             type = cp_build_reference_type (type, (clk & clk_rvalueref));
   13048                 :             :         }
   13049                 :             :     }
   13050                 :             : 
   13051                 :             :   return type;
   13052                 :    26826482 : }
   13053                 :             : 
   13054                 :             : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
   13055                 :             :    __has_nothrow_copy, depending on assign_p.  Returns true iff all
   13056                 :             :    the copy {ctor,assign} fns are nothrow.  */
   13057                 :             : 
   13058                 :             : static bool
   13059                 :         279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
   13060                 :             : {
   13061                 :         279 :   tree fns = NULL_TREE;
   13062                 :             : 
   13063                 :         279 :   if (assign_p || TYPE_HAS_COPY_CTOR (type))
   13064                 :         276 :     fns = get_class_binding (type, assign_p ? assign_op_identifier
   13065                 :             :                              : ctor_identifier);
   13066                 :             : 
   13067                 :         279 :   bool saw_copy = false;
   13068                 :         696 :   for (ovl_iterator iter (fns); iter; ++iter)
   13069                 :             :     {
   13070                 :         441 :       tree fn = *iter;
   13071                 :             : 
   13072                 :         441 :       if (copy_fn_p (fn) > 0)
   13073                 :             :         {
   13074                 :         423 :           saw_copy = true;
   13075                 :         423 :           if (!maybe_instantiate_noexcept (fn)
   13076                 :         423 :               || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
   13077                 :         192 :             return false;
   13078                 :             :         }
   13079                 :             :     }
   13080                 :             : 
   13081                 :          87 :   return saw_copy;
   13082                 :             : }
   13083                 :             : 
   13084                 :             : /* Return true if DERIVED is pointer interconvertible base of BASE.  */
   13085                 :             : 
   13086                 :             : static bool
   13087                 :         130 : pointer_interconvertible_base_of_p (tree base, tree derived)
   13088                 :             : {
   13089                 :         130 :   if (base == error_mark_node || derived == error_mark_node)
   13090                 :             :     return false;
   13091                 :         130 :   base = TYPE_MAIN_VARIANT (base);
   13092                 :         130 :   derived = TYPE_MAIN_VARIANT (derived);
   13093                 :         119 :   if (!NON_UNION_CLASS_TYPE_P (base)
   13094                 :         249 :       || !NON_UNION_CLASS_TYPE_P (derived))
   13095                 :             :     return false;
   13096                 :             : 
   13097                 :         119 :   if (same_type_p (base, derived))
   13098                 :             :     return true;
   13099                 :             : 
   13100                 :          88 :   if (!std_layout_type_p (derived))
   13101                 :             :     return false;
   13102                 :             : 
   13103                 :          83 :   return uniquely_derived_from_p (base, derived);
   13104                 :             : }
   13105                 :             : 
   13106                 :             : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
   13107                 :             :    return true if MEMBERTYPE is the type of the first non-static data member
   13108                 :             :    of TYPE or for unions of any members.  */
   13109                 :             : static bool
   13110                 :         647 : first_nonstatic_data_member_p (tree type, tree membertype)
   13111                 :             : {
   13112                 :        1307 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   13113                 :             :     {
   13114                 :        1232 :       if (TREE_CODE (field) != FIELD_DECL)
   13115                 :         135 :         continue;
   13116                 :        1097 :       if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
   13117                 :          60 :         continue;
   13118                 :        1037 :       if (DECL_FIELD_IS_BASE (field))
   13119                 :          45 :         return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
   13120                 :         992 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13121                 :             :         {
   13122                 :         216 :           if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
   13123                 :         138 :                || std_layout_type_p (TREE_TYPE (field)))
   13124                 :         294 :               && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
   13125                 :             :             return true;
   13126                 :             :         }
   13127                 :         776 :       else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13128                 :             :                                                           membertype))
   13129                 :             :         return true;
   13130                 :         540 :       if (TREE_CODE (type) != UNION_TYPE)
   13131                 :             :         return false;
   13132                 :             :     }
   13133                 :             :   return false;
   13134                 :             : }
   13135                 :             : 
   13136                 :             : /* Fold __builtin_is_pointer_interconvertible_with_class call.  */
   13137                 :             : 
   13138                 :             : tree
   13139                 :         553 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
   13140                 :             :                                                      tree *args)
   13141                 :             : {
   13142                 :             :   /* Unless users call the builtin directly, the following 3 checks should be
   13143                 :             :      ensured from std::is_pointer_interconvertible_with_class function
   13144                 :             :      template.  */
   13145                 :         553 :   if (nargs != 1)
   13146                 :             :     {
   13147                 :           6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13148                 :             :                      "needs a single argument");
   13149                 :           6 :       return boolean_false_node;
   13150                 :             :     }
   13151                 :         547 :   tree arg = args[0];
   13152                 :         547 :   if (error_operand_p (arg))
   13153                 :           0 :     return boolean_false_node;
   13154                 :         547 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
   13155                 :             :     {
   13156                 :           6 :       error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
   13157                 :             :                      "argument is not pointer to member");
   13158                 :           6 :       return boolean_false_node;
   13159                 :             :     }
   13160                 :             : 
   13161                 :         541 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
   13162                 :          21 :     return boolean_false_node;
   13163                 :             : 
   13164                 :         520 :   tree membertype = TREE_TYPE (TREE_TYPE (arg));
   13165                 :         520 :   tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
   13166                 :         520 :   if (!complete_type_or_else (basetype, NULL_TREE))
   13167                 :           3 :     return boolean_false_node;
   13168                 :             : 
   13169                 :         517 :   if (TREE_CODE (basetype) != UNION_TYPE
   13170                 :         517 :       && !std_layout_type_p (basetype))
   13171                 :          26 :     return boolean_false_node;
   13172                 :             : 
   13173                 :         491 :   if (!first_nonstatic_data_member_p (basetype, membertype))
   13174                 :         135 :     return boolean_false_node;
   13175                 :             : 
   13176                 :         356 :   if (TREE_CODE (arg) == PTRMEM_CST)
   13177                 :          70 :     arg = cplus_expand_constant (arg);
   13178                 :             : 
   13179                 :         356 :   if (integer_nonzerop (arg))
   13180                 :          11 :     return boolean_false_node;
   13181                 :         345 :   if (integer_zerop (arg))
   13182                 :          73 :     return boolean_true_node;
   13183                 :             : 
   13184                 :         272 :   return fold_build2 (EQ_EXPR, boolean_type_node, arg,
   13185                 :             :                       build_zero_cst (TREE_TYPE (arg)));
   13186                 :             : }
   13187                 :             : 
   13188                 :             : /* Helper function for is_corresponding_member_aggr.  Return true if
   13189                 :             :    MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
   13190                 :             :    union or structure BASETYPE.  */
   13191                 :             : 
   13192                 :             : static bool
   13193                 :          90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
   13194                 :             : {
   13195                 :         222 :   for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
   13196                 :         192 :     if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
   13197                 :          36 :       continue;
   13198                 :         156 :     else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
   13199                 :             :                                                         membertype))
   13200                 :             :       {
   13201                 :          48 :         if (TREE_CODE (arg) != INTEGER_CST
   13202                 :          48 :             || tree_int_cst_equal (arg, byte_position (field)))
   13203                 :          48 :           return true;
   13204                 :             :       }
   13205                 :         108 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   13206                 :             :       {
   13207                 :          18 :         tree narg = arg;
   13208                 :          18 :         if (TREE_CODE (basetype) != UNION_TYPE
   13209                 :           0 :             && TREE_CODE (narg) == INTEGER_CST)
   13210                 :           0 :           narg = size_binop (MINUS_EXPR, arg, byte_position (field));
   13211                 :          18 :         if (is_corresponding_member_union (TREE_TYPE (field),
   13212                 :             :                                            membertype, narg))
   13213                 :             :           return true;
   13214                 :             :       }
   13215                 :             :   return false;
   13216                 :             : }
   13217                 :             : 
   13218                 :             : /* Helper function for fold_builtin_is_corresponding_member call.
   13219                 :             :    Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
   13220                 :             :    MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
   13221                 :             :    boolean_true_node if they are corresponding members, or for
   13222                 :             :    non-constant ARG2 the highest member offset for corresponding
   13223                 :             :    members.  */
   13224                 :             : 
   13225                 :             : static tree
   13226                 :         521 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
   13227                 :             :                               tree arg1, tree basetype2, tree membertype2,
   13228                 :             :                               tree arg2)
   13229                 :             : {
   13230                 :         521 :   tree field1 = TYPE_FIELDS (basetype1);
   13231                 :         521 :   tree field2 = TYPE_FIELDS (basetype2);
   13232                 :         521 :   tree ret = boolean_false_node;
   13233                 :        2259 :   while (1)
   13234                 :             :     {
   13235                 :        1390 :       bool r = next_common_initial_sequence (field1, field2);
   13236                 :        1390 :       if (field1 == NULL_TREE || field2 == NULL_TREE)
   13237                 :             :         break;
   13238                 :        1264 :       if (r
   13239                 :         990 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
   13240                 :             :                                                         membertype1)
   13241                 :        1762 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
   13242                 :             :                                                         membertype2))
   13243                 :             :         {
   13244                 :         492 :           tree pos = byte_position (field1);
   13245                 :         492 :           if (TREE_CODE (arg1) == INTEGER_CST
   13246                 :         492 :               && tree_int_cst_equal (arg1, pos))
   13247                 :             :             {
   13248                 :          88 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13249                 :          88 :                 return boolean_true_node;
   13250                 :             :               return pos;
   13251                 :             :             }
   13252                 :         404 :           else if (TREE_CODE (arg1) != INTEGER_CST)
   13253                 :        1125 :             ret = pos;
   13254                 :             :         }
   13255                 :        1544 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
   13256                 :         889 :                && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
   13257                 :             :         {
   13258                 :         117 :           if ((!lookup_attribute ("no_unique_address",
   13259                 :         117 :                                   DECL_ATTRIBUTES (field1)))
   13260                 :         117 :               != !lookup_attribute ("no_unique_address",
   13261                 :         117 :                                     DECL_ATTRIBUTES (field2)))
   13262                 :             :             break;
   13263                 :         117 :           if (!tree_int_cst_equal (bit_position (field1),
   13264                 :         117 :                                    bit_position (field2)))
   13265                 :             :             break;
   13266                 :          99 :           bool overlap = true;
   13267                 :          99 :           tree pos = byte_position (field1);
   13268                 :          99 :           if (TREE_CODE (arg1) == INTEGER_CST)
   13269                 :             :             {
   13270                 :          27 :               tree off1 = fold_convert (sizetype, arg1);
   13271                 :          27 :               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
   13272                 :          27 :               if (tree_int_cst_lt (off1, pos)
   13273                 :          27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
   13274                 :             :                 overlap = false;
   13275                 :             :             }
   13276                 :          99 :           if (TREE_CODE (arg2) == INTEGER_CST)
   13277                 :             :             {
   13278                 :          27 :               tree off2 = fold_convert (sizetype, arg2);
   13279                 :          27 :               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
   13280                 :          27 :               if (tree_int_cst_lt (off2, pos)
   13281                 :          27 :                   || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
   13282                 :             :                 overlap = false;
   13283                 :             :             }
   13284                 :          87 :           if (overlap
   13285                 :          87 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
   13286                 :         126 :               && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
   13287                 :             :             {
   13288                 :          39 :               tree narg1 = arg1;
   13289                 :          39 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13290                 :           9 :                 narg1 = size_binop (MINUS_EXPR,
   13291                 :             :                                     fold_convert (sizetype, arg1), pos);
   13292                 :          39 :               tree narg2 = arg2;
   13293                 :          39 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13294                 :           9 :                 narg2 = size_binop (MINUS_EXPR,
   13295                 :             :                                     fold_convert (sizetype, arg2), pos);
   13296                 :          39 :               tree t1 = TREE_TYPE (field1);
   13297                 :          39 :               tree t2 = TREE_TYPE (field2);
   13298                 :          39 :               tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
   13299                 :             :                                                         narg1, t2, membertype2,
   13300                 :             :                                                         narg2);
   13301                 :          39 :               if (nret != boolean_false_node)
   13302                 :             :                 {
   13303                 :          39 :                   if (nret == boolean_true_node)
   13304                 :             :                     return nret;
   13305                 :          30 :                   if (TREE_CODE (arg1) == INTEGER_CST)
   13306                 :           0 :                     return size_binop (PLUS_EXPR, nret, pos);
   13307                 :          30 :                   ret = size_binop (PLUS_EXPR, nret, pos);
   13308                 :             :                 }
   13309                 :             :             }
   13310                 :          60 :           else if (overlap
   13311                 :          48 :                    && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
   13312                 :         108 :                    && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
   13313                 :             :             {
   13314                 :          48 :               tree narg1 = arg1;
   13315                 :          48 :               if (TREE_CODE (arg1) == INTEGER_CST)
   13316                 :           6 :                 narg1 = size_binop (MINUS_EXPR,
   13317                 :             :                                     fold_convert (sizetype, arg1), pos);
   13318                 :          48 :               tree narg2 = arg2;
   13319                 :          48 :               if (TREE_CODE (arg2) == INTEGER_CST)
   13320                 :           6 :                 narg2 = size_binop (MINUS_EXPR,
   13321                 :             :                                     fold_convert (sizetype, arg2), pos);
   13322                 :          48 :               if (is_corresponding_member_union (TREE_TYPE (field1),
   13323                 :             :                                                  membertype1, narg1)
   13324                 :          48 :                   && is_corresponding_member_union (TREE_TYPE (field2),
   13325                 :             :                                                     membertype2, narg2))
   13326                 :             :                 {
   13327                 :          24 :                   sorry_at (loc, "%<__builtin_is_corresponding_member%> "
   13328                 :             :                                  "not well defined for anonymous unions");
   13329                 :          24 :                   return boolean_false_node;
   13330                 :             :                 }
   13331                 :             :             }
   13332                 :             :         }
   13333                 :        1125 :       if (!r)
   13334                 :             :         break;
   13335                 :         869 :       field1 = DECL_CHAIN (field1);
   13336                 :         869 :       field2 = DECL_CHAIN (field2);
   13337                 :         869 :     }
   13338                 :             :   return ret;
   13339                 :             : }
   13340                 :             : 
   13341                 :             : /* Fold __builtin_is_corresponding_member call.  */
   13342                 :             : 
   13343                 :             : tree
   13344                 :         681 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
   13345                 :             :                                       tree *args)
   13346                 :             : {
   13347                 :             :   /* Unless users call the builtin directly, the following 3 checks should be
   13348                 :             :      ensured from std::is_corresponding_member function template.  */
   13349                 :         681 :   if (nargs != 2)
   13350                 :             :     {
   13351                 :           9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13352                 :             :                      "needs two arguments");
   13353                 :           9 :       return boolean_false_node;
   13354                 :             :     }
   13355                 :         672 :   tree arg1 = args[0];
   13356                 :         672 :   tree arg2 = args[1];
   13357                 :         672 :   if (error_operand_p (arg1) || error_operand_p (arg2))
   13358                 :           0 :     return boolean_false_node;
   13359                 :         693 :   if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
   13360                 :         687 :       || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
   13361                 :             :     {
   13362                 :           9 :       error_at (loc, "%<__builtin_is_corresponding_member%> "
   13363                 :             :                      "argument is not pointer to member");
   13364                 :           9 :       return boolean_false_node;
   13365                 :             :     }
   13366                 :             : 
   13367                 :         663 :   if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
   13368                 :         663 :       || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
   13369                 :          15 :     return boolean_false_node;
   13370                 :             : 
   13371                 :         648 :   tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
   13372                 :         648 :   tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
   13373                 :         648 :   if (!complete_type_or_else (basetype1, NULL_TREE))
   13374                 :          12 :     return boolean_false_node;
   13375                 :             : 
   13376                 :         636 :   tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
   13377                 :         636 :   tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
   13378                 :         636 :   if (!complete_type_or_else (basetype2, NULL_TREE))
   13379                 :          12 :     return boolean_false_node;
   13380                 :             : 
   13381                 :         609 :   if (!NON_UNION_CLASS_TYPE_P (basetype1)
   13382                 :         609 :       || !NON_UNION_CLASS_TYPE_P (basetype2)
   13383                 :         609 :       || !std_layout_type_p (basetype1)
   13384                 :        1194 :       || !std_layout_type_p (basetype2))
   13385                 :          54 :     return boolean_false_node;
   13386                 :             : 
   13387                 :             :   /* If the member types aren't layout compatible, then they
   13388                 :             :      can't be corresponding members.  */
   13389                 :         570 :   if (!layout_compatible_type_p (membertype1, membertype2))
   13390                 :          27 :     return boolean_false_node;
   13391                 :             : 
   13392                 :         543 :   if (TREE_CODE (arg1) == PTRMEM_CST)
   13393                 :         166 :     arg1 = cplus_expand_constant (arg1);
   13394                 :         543 :   if (TREE_CODE (arg2) == PTRMEM_CST)
   13395                 :         172 :     arg2 = cplus_expand_constant (arg2);
   13396                 :             : 
   13397                 :         543 :   if (null_member_pointer_value_p (arg1)
   13398                 :         543 :       || null_member_pointer_value_p (arg2))
   13399                 :           9 :     return boolean_false_node;
   13400                 :             : 
   13401                 :         534 :   if (TREE_CODE (arg1) == INTEGER_CST
   13402                 :         172 :       && TREE_CODE (arg2) == INTEGER_CST
   13403                 :         706 :       && !tree_int_cst_equal (arg1, arg2))
   13404                 :          52 :     return boolean_false_node;
   13405                 :             : 
   13406                 :         482 :   if (TREE_CODE (arg2) == INTEGER_CST
   13407                 :         120 :       && TREE_CODE (arg1) != INTEGER_CST)
   13408                 :             :     {
   13409                 :             :       std::swap (arg1, arg2);
   13410                 :             :       std::swap (membertype1, membertype2);
   13411                 :             :       std::swap (basetype1, basetype2);
   13412                 :             :     }
   13413                 :             : 
   13414                 :         482 :   tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
   13415                 :             :                                            basetype2, membertype2, arg2);
   13416                 :         482 :   if (TREE_TYPE (ret) == boolean_type_node)
   13417                 :             :     return ret;
   13418                 :             :   /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
   13419                 :             :      already returns boolean_{true,false}_node whether those particular
   13420                 :             :      members are corresponding members or not.  Otherwise, if only
   13421                 :             :      one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
   13422                 :             :      above), it returns boolean_false_node if it is certainly not a
   13423                 :             :      corresponding member and otherwise we need to do a runtime check that
   13424                 :             :      those two OFFSET_TYPE offsets are equal.
   13425                 :             :      If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
   13426                 :             :      returns the largest offset at which the members would be corresponding
   13427                 :             :      members, so perform arg1 <= ret && arg1 == arg2 runtime check.  */
   13428                 :         296 :   gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
   13429                 :         296 :   if (TREE_CODE (arg1) == INTEGER_CST)
   13430                 :           0 :     return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13431                 :             :                         fold_convert (TREE_TYPE (arg1), arg2));
   13432                 :         296 :   ret = fold_build2 (LE_EXPR, boolean_type_node,
   13433                 :             :                      fold_convert (pointer_sized_int_node, arg1),
   13434                 :             :                      fold_convert (pointer_sized_int_node, ret));
   13435                 :         296 :   return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
   13436                 :             :                       fold_build2 (EQ_EXPR, boolean_type_node, arg1,
   13437                 :             :                                    fold_convert (TREE_TYPE (arg1), arg2)));
   13438                 :             : }
   13439                 :             : 
   13440                 :             : /* [basic.types] 8.  True iff TYPE is an object type.  */
   13441                 :             : 
   13442                 :             : static bool
   13443                 :     2144620 : object_type_p (const_tree type)
   13444                 :             : {
   13445                 :     2144620 :   return (TREE_CODE (type) != FUNCTION_TYPE
   13446                 :           0 :           && !TYPE_REF_P (type)
   13447                 :     2144620 :           && !VOID_TYPE_P (type));
   13448                 :             : }
   13449                 :             : 
   13450                 :             : /* [defns.referenceable] True iff TYPE is a referenceable type.  */
   13451                 :             : 
   13452                 :             : static bool
   13453                 :     2188368 : referenceable_type_p (const_tree type)
   13454                 :             : {
   13455                 :     2188368 :   return (TYPE_REF_P (type)
   13456                 :     2188724 :           || object_type_p (type)
   13457                 :     2188724 :           || (FUNC_OR_METHOD_TYPE_P (type)
   13458                 :         297 :               && type_memfn_quals (type) == TYPE_UNQUALIFIED
   13459                 :         241 :               && type_memfn_rqual (type) == REF_QUAL_NONE));
   13460                 :             : }
   13461                 :             : 
   13462                 :             : /* Actually evaluates the trait.  */
   13463                 :             : 
   13464                 :             : static bool
   13465                 :    10986321 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
   13466                 :             : {
   13467                 :    10986321 :   enum tree_code type_code1;
   13468                 :    10986321 :   tree t;
   13469                 :             : 
   13470                 :    10986321 :   type_code1 = TREE_CODE (type1);
   13471                 :             : 
   13472                 :    10986321 :   switch (kind)
   13473                 :             :     {
   13474                 :         317 :     case CPTK_HAS_NOTHROW_ASSIGN:
   13475                 :         317 :       type1 = strip_array_types (type1);
   13476                 :         601 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   13477                 :         601 :               && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
   13478                 :         173 :                   || (CLASS_TYPE_P (type1)
   13479                 :         129 :                       && classtype_has_nothrow_assign_or_copy_p (type1,
   13480                 :             :                                                                  true))));
   13481                 :             : 
   13482                 :         215 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   13483                 :         215 :       type1 = strip_array_types (type1);
   13484                 :         215 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
   13485                 :         215 :               || (CLASS_TYPE_P (type1)
   13486                 :          93 :                   && (t = locate_ctor (type1))
   13487                 :          60 :                   && maybe_instantiate_noexcept (t)
   13488                 :          58 :                   && TYPE_NOTHROW_P (TREE_TYPE (t))));
   13489                 :             : 
   13490                 :         305 :     case CPTK_HAS_NOTHROW_COPY:
   13491                 :         305 :       type1 = strip_array_types (type1);
   13492                 :         305 :       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
   13493                 :         305 :               || (CLASS_TYPE_P (type1)
   13494                 :         150 :                   && classtype_has_nothrow_assign_or_copy_p (type1, false)));
   13495                 :             : 
   13496                 :         517 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   13497                 :             :       /* ??? The standard seems to be missing the "or array of such a class
   13498                 :             :          type" wording for this trait.  */
   13499                 :         517 :       type1 = strip_array_types (type1);
   13500                 :        1016 :       return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
   13501                 :        1001 :               && (trivial_type_p (type1)
   13502                 :         307 :                     || (CLASS_TYPE_P (type1)
   13503                 :         222 :                         && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
   13504                 :             : 
   13505                 :         512 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   13506                 :         512 :       type1 = strip_array_types (type1);
   13507                 :         512 :       return (trivial_type_p (type1)
   13508                 :         512 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
   13509                 :             : 
   13510                 :         526 :     case CPTK_HAS_TRIVIAL_COPY:
   13511                 :             :       /* ??? The standard seems to be missing the "or array of such a class
   13512                 :             :          type" wording for this trait.  */
   13513                 :         526 :       type1 = strip_array_types (type1);
   13514                 :         878 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   13515                 :         863 :               || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
   13516                 :             : 
   13517                 :         783 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   13518                 :         783 :       type1 = strip_array_types (type1);
   13519                 :         783 :       if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
   13520                 :             :         {
   13521                 :         123 :           deferring_access_check_sentinel dacs (dk_no_check);
   13522                 :         123 :           cp_unevaluated un;
   13523                 :         123 :           tree fn = get_dtor (type1, tf_none);
   13524                 :         123 :           if (!fn && !seen_error ())
   13525                 :           3 :             warning (0, "checking %qs for type %qT with a destructor that "
   13526                 :             :                      "cannot be called", "__has_trivial_destructor", type1);
   13527                 :         123 :         }
   13528                 :        1120 :       return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
   13529                 :        1117 :               || (CLASS_TYPE_P (type1)
   13530                 :         290 :                   && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
   13531                 :             : 
   13532                 :       21915 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   13533                 :       21915 :       return type_has_unique_obj_representations (type1);
   13534                 :             : 
   13535                 :         279 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   13536                 :         279 :       return type_has_virtual_destructor (type1);
   13537                 :             : 
   13538                 :       58524 :     case CPTK_IS_ABSTRACT:
   13539                 :       58524 :       return ABSTRACT_CLASS_TYPE_P (type1);
   13540                 :             : 
   13541                 :         813 :     case CPTK_IS_AGGREGATE:
   13542                 :         813 :       return CP_AGGREGATE_TYPE_P (type1);
   13543                 :             : 
   13544                 :      259891 :     case CPTK_IS_ARRAY:
   13545                 :      259891 :       return (type_code1 == ARRAY_TYPE
   13546                 :             :               /* We don't want to report T[0] as being an array type.
   13547                 :             :                  This is for compatibility with an implementation of
   13548                 :             :                  std::is_array by template argument deduction, because
   13549                 :             :                  compute_array_index_type_loc rejects a zero-size array
   13550                 :             :                  in SFINAE context.  */
   13551                 :      259891 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   13552                 :             : 
   13553                 :      689715 :     case CPTK_IS_ASSIGNABLE:
   13554                 :      689715 :       return is_xible (MODIFY_EXPR, type1, type2);
   13555                 :             : 
   13556                 :      212927 :     case CPTK_IS_BASE_OF:
   13557                 :      212830 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   13558                 :      405587 :               && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
   13559                 :      181308 :                   || DERIVED_FROM_P (type1, type2)));
   13560                 :             : 
   13561                 :       32241 :     case CPTK_IS_BOUNDED_ARRAY:
   13562                 :       32241 :       return (type_code1 == ARRAY_TYPE
   13563                 :        3904 :               && TYPE_DOMAIN (type1)
   13564                 :             :               /* We don't want to report T[0] as being a bounded array type.
   13565                 :             :                  This is for compatibility with an implementation of
   13566                 :             :                  std::is_bounded_array by template argument deduction, because
   13567                 :             :                  compute_array_index_type_loc rejects a zero-size array
   13568                 :             :                  in SFINAE context.  */
   13569                 :       36009 :               && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
   13570                 :             : 
   13571                 :      290714 :     case CPTK_IS_CLASS:
   13572                 :      290714 :       return NON_UNION_CLASS_TYPE_P (type1);
   13573                 :             : 
   13574                 :      285670 :     case CPTK_IS_CONST:
   13575                 :      285670 :       return CP_TYPE_CONST_P (type1);
   13576                 :             : 
   13577                 :     1403259 :     case CPTK_IS_CONSTRUCTIBLE:
   13578                 :     1403259 :       return is_xible (INIT_EXPR, type1, type2);
   13579                 :             : 
   13580                 :     1307733 :     case CPTK_IS_CONVERTIBLE:
   13581                 :     1307733 :       return is_convertible (type1, type2);
   13582                 :             : 
   13583                 :         533 :     case CPTK_IS_DESTRUCTIBLE:
   13584                 :         533 :       return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   13585                 :             : 
   13586                 :      227168 :     case CPTK_IS_EMPTY:
   13587                 :      227168 :       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
   13588                 :             : 
   13589                 :      433440 :     case CPTK_IS_ENUM:
   13590                 :      433440 :       return type_code1 == ENUMERAL_TYPE;
   13591                 :             : 
   13592                 :      407792 :     case CPTK_IS_FINAL:
   13593                 :      407792 :       return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
   13594                 :             : 
   13595                 :       34986 :     case CPTK_IS_FUNCTION:
   13596                 :       34986 :       return type_code1 == FUNCTION_TYPE;
   13597                 :             : 
   13598                 :       50280 :     case CPTK_IS_INVOCABLE:
   13599                 :       50280 :       return !error_operand_p (build_invoke (type1, type2, tf_none));
   13600                 :             : 
   13601                 :         189 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   13602                 :         189 :       return layout_compatible_type_p (type1, type2);
   13603                 :             : 
   13604                 :         209 :     case CPTK_IS_LITERAL_TYPE:
   13605                 :         209 :       return literal_type_p (type1);
   13606                 :             : 
   13607                 :       49680 :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   13608                 :       49680 :       return TYPE_PTRMEMFUNC_P (type1);
   13609                 :             : 
   13610                 :       49568 :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   13611                 :       49568 :       return TYPE_PTRDATAMEM_P (type1);
   13612                 :             : 
   13613                 :       10739 :     case CPTK_IS_MEMBER_POINTER:
   13614                 :       10739 :       return TYPE_PTRMEM_P (type1);
   13615                 :             : 
   13616                 :      303265 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   13617                 :      303265 :       return is_nothrow_xible (MODIFY_EXPR, type1, type2);
   13618                 :             : 
   13619                 :      629045 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   13620                 :      629045 :       return is_nothrow_xible (INIT_EXPR, type1, type2);
   13621                 :             : 
   13622                 :         750 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   13623                 :         750 :       return is_nothrow_convertible (type1, type2);
   13624                 :             : 
   13625                 :       24093 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   13626                 :       24093 :       return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   13627                 :             : 
   13628                 :       42764 :     case CPTK_IS_NOTHROW_INVOCABLE:
   13629                 :       42764 :       return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
   13630                 :             : 
   13631                 :         114 :     case CPTK_IS_NOTHROW_RELOCATABLE:
   13632                 :         114 :       if (trivially_relocatable_type_p (type1))
   13633                 :             :         return true;
   13634                 :             :       else
   13635                 :             :         {
   13636                 :          69 :           type1 = strip_array_types (type1);
   13637                 :          69 :           if (!referenceable_type_p (type1))
   13638                 :             :             return false;
   13639                 :          69 :           tree arg = make_tree_vec (1);
   13640                 :          69 :           TREE_VEC_ELT (arg, 0)
   13641                 :          69 :             = cp_build_reference_type (type1, /*rval=*/true);
   13642                 :          69 :           return (is_nothrow_xible (INIT_EXPR, type1, arg)
   13643                 :          69 :                   && is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE));
   13644                 :             :         }
   13645                 :             : 
   13646                 :      824974 :     case CPTK_IS_OBJECT:
   13647                 :      824974 :       return object_type_p (type1);
   13648                 :             : 
   13649                 :         130 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   13650                 :         130 :       return pointer_interconvertible_base_of_p (type1, type2);
   13651                 :             : 
   13652                 :       11706 :     case CPTK_IS_POD:
   13653                 :       11706 :       return pod_type_p (type1);
   13654                 :             : 
   13655                 :      107531 :     case CPTK_IS_POINTER:
   13656                 :      107531 :       return TYPE_PTR_P (type1);
   13657                 :             : 
   13658                 :         267 :     case CPTK_IS_POLYMORPHIC:
   13659                 :         267 :       return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
   13660                 :             : 
   13661                 :      228444 :     case CPTK_IS_REFERENCE:
   13662                 :      228444 :       return type_code1 == REFERENCE_TYPE;
   13663                 :             : 
   13664                 :         533 :     case CPTK_IS_REPLACEABLE:
   13665                 :         533 :       return replaceable_type_p (type1);
   13666                 :             : 
   13667                 :     2217679 :     case CPTK_IS_SAME:
   13668                 :     2217679 :       return same_type_p (type1, type2);
   13669                 :             : 
   13670                 :         373 :     case CPTK_IS_SCOPED_ENUM:
   13671                 :         373 :       return SCOPED_ENUM_P (type1);
   13672                 :             : 
   13673                 :       49244 :     case CPTK_IS_STD_LAYOUT:
   13674                 :       49244 :       return std_layout_type_p (type1);
   13675                 :             : 
   13676                 :       30485 :     case CPTK_IS_TRIVIAL:
   13677                 :       30485 :       return trivial_type_p (type1);
   13678                 :             : 
   13679                 :        7218 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   13680                 :        7218 :       return is_trivially_xible (MODIFY_EXPR, type1, type2);
   13681                 :             : 
   13682                 :       56519 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   13683                 :       56519 :       return is_trivially_xible (INIT_EXPR, type1, type2);
   13684                 :             : 
   13685                 :       67008 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   13686                 :       67008 :       return trivially_copyable_p (type1);
   13687                 :             : 
   13688                 :       24894 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   13689                 :       24894 :       return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
   13690                 :             : 
   13691                 :         509 :     case CPTK_IS_TRIVIALLY_RELOCATABLE:
   13692                 :         509 :       return trivially_relocatable_type_p (type1);
   13693                 :             : 
   13694                 :       24610 :     case CPTK_IS_UNBOUNDED_ARRAY:
   13695                 :       24610 :       return array_of_unknown_bound_p (type1);
   13696                 :             : 
   13697                 :       98093 :     case CPTK_IS_UNION:
   13698                 :       98093 :       return type_code1 == UNION_TYPE;
   13699                 :             : 
   13700                 :         693 :     case CPTK_IS_VIRTUAL_BASE_OF:
   13701                 :         627 :       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   13702                 :        1305 :               && lookup_base (type2, type1, ba_require_virtual,
   13703                 :             :                               NULL, tf_none) != NULL_TREE);
   13704                 :             : 
   13705                 :      284847 :     case CPTK_IS_VOLATILE:
   13706                 :      284847 :       return CP_TYPE_VOLATILE_P (type1);
   13707                 :             : 
   13708                 :       63853 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   13709                 :       63853 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
   13710                 :             : 
   13711                 :       55161 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   13712                 :       55161 :       return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
   13713                 :             : 
   13714                 :          79 :     case CPTK_IS_DEDUCIBLE:
   13715                 :          79 :       return type_targs_deducible_from (type1, type2);
   13716                 :             : 
   13717                 :             :     /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
   13718                 :             :        are handled in finish_trait_expr.  */
   13719                 :           0 :     case CPTK_RANK:
   13720                 :           0 :     case CPTK_TYPE_ORDER:
   13721                 :           0 :     case CPTK_STRUCTURED_BINDING_SIZE:
   13722                 :           0 :       gcc_unreachable ();
   13723                 :             : 
   13724                 :             : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   13725                 :             :     case CPTK_##CODE:
   13726                 :             : #include "cp-trait.def"
   13727                 :             : #undef DEFTRAIT_TYPE
   13728                 :             :       /* Type-yielding traits are handled in finish_trait_type.  */
   13729                 :             :       break;
   13730                 :             :     }
   13731                 :             : 
   13732                 :           0 :   gcc_unreachable ();
   13733                 :             : }
   13734                 :             : 
   13735                 :             : /* Returns true if TYPE meets the requirements for the specified KIND,
   13736                 :             :    false otherwise.
   13737                 :             : 
   13738                 :             :    When KIND == 1, TYPE must be an array of unknown bound,
   13739                 :             :    or (possibly cv-qualified) void, or a complete type.
   13740                 :             : 
   13741                 :             :    When KIND == 2, TYPE must be a complete type, or array of complete type,
   13742                 :             :    or (possibly cv-qualified) void.
   13743                 :             : 
   13744                 :             :    When KIND == 3:
   13745                 :             :    If TYPE is a non-union class type, it must be complete.
   13746                 :             : 
   13747                 :             :    When KIND == 4:
   13748                 :             :    If TYPE is a class type, it must be complete.  */
   13749                 :             : 
   13750                 :             : static bool
   13751                 :    11158965 : check_trait_type (tree type, int kind = 1)
   13752                 :             : {
   13753                 :    11158965 :   if (type == NULL_TREE)
   13754                 :             :     return true;
   13755                 :             : 
   13756                 :    11158965 :   if (TREE_CODE (type) == TREE_VEC)
   13757                 :             :     {
   13758                 :     3779197 :       for (tree arg : tree_vec_range (type))
   13759                 :     1600257 :         if (!check_trait_type (arg, kind))
   13760                 :          21 :           return false;
   13761                 :     2178940 :       return true;
   13762                 :             :     }
   13763                 :             : 
   13764                 :     8980004 :   if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   13765                 :             :     return true; // Array of unknown bound. Don't care about completeness.
   13766                 :             : 
   13767                 :     8979492 :   if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
   13768                 :             :     return true; // Not a non-union class type. Don't care about completeness.
   13769                 :             : 
   13770                 :     8874950 :   if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
   13771                 :             :     return true; // Not a class type. Don't care about completeness.
   13772                 :             : 
   13773                 :     8874525 :   if (VOID_TYPE_P (type))
   13774                 :             :     return true;
   13775                 :             : 
   13776                 :     8873432 :   type = complete_type (strip_array_types (type));
   13777                 :     8873432 :   if (!COMPLETE_TYPE_P (type)
   13778                 :         158 :       && cxx_incomplete_type_diagnostic (NULL_TREE, type,
   13779                 :             :                                          diagnostics::kind::permerror)
   13780                 :     8873590 :       && !flag_permissive)
   13781                 :             :     return false;
   13782                 :             :   return true;
   13783                 :             : }
   13784                 :             : 
   13785                 :             : /* True iff the conversion (if any) would be a direct reference
   13786                 :             :    binding, not requiring complete types.  This is LWG2939.  */
   13787                 :             : 
   13788                 :             : static bool
   13789                 :     3609424 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
   13790                 :             : {
   13791                 :     3609424 :   tree from, to;
   13792                 :     3609424 :   switch (kind)
   13793                 :             :     {
   13794                 :             :       /* These put the target type first.  */
   13795                 :             :     case CPTK_IS_CONSTRUCTIBLE:
   13796                 :             :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   13797                 :             :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   13798                 :             :     case CPTK_IS_INVOCABLE:
   13799                 :             :     case CPTK_IS_NOTHROW_INVOCABLE:
   13800                 :             :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   13801                 :             :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   13802                 :             :       to = type1;
   13803                 :             :       from = type2;
   13804                 :             :       break;
   13805                 :             : 
   13806                 :             :       /* These put it second.  */
   13807                 :     1308483 :     case CPTK_IS_CONVERTIBLE:
   13808                 :     1308483 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   13809                 :     1308483 :       to = type2;
   13810                 :     1308483 :       from = type1;
   13811                 :     1308483 :       break;
   13812                 :             : 
   13813                 :           0 :     default:
   13814                 :           0 :       gcc_unreachable ();
   13815                 :             :     }
   13816                 :             : 
   13817                 :     3609424 :   if (TREE_CODE (to) != REFERENCE_TYPE || !from)
   13818                 :             :     return false;
   13819                 :      363831 :   if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
   13820                 :       62515 :     from = TREE_VEC_ELT (from, 0);
   13821                 :      363831 :   return (TYPE_P (from)
   13822                 :      718978 :           && (same_type_ignoring_top_level_qualifiers_p
   13823                 :      355147 :               (non_reference (to), non_reference (from))));
   13824                 :             : }
   13825                 :             : 
   13826                 :             : /* Helper for finish_trait_expr and tsubst_expr.  Handle
   13827                 :             :    CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
   13828                 :             :    way.  */
   13829                 :             : 
   13830                 :             : tree
   13831                 :         261 : finish_structured_binding_size (location_t loc, tree type,
   13832                 :             :                                 tsubst_flags_t complain)
   13833                 :             : {
   13834                 :         261 :   if (TYPE_REF_P (type))
   13835                 :             :     {
   13836                 :         105 :       if (complain & tf_error)
   13837                 :          99 :         error_at (loc, "%qs argument %qT is a reference",
   13838                 :             :                   "__builtin_structured_binding_size", type);
   13839                 :         105 :       return error_mark_node;
   13840                 :             :     }
   13841                 :         156 :   HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
   13842                 :         156 :   if (ret == -1)
   13843                 :          57 :     return error_mark_node;
   13844                 :          99 :   return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
   13845                 :             : }
   13846                 :             : 
   13847                 :             : /* Process a trait expression.  */
   13848                 :             : 
   13849                 :             : tree
   13850                 :    14079971 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
   13851                 :             : {
   13852                 :    14079971 :   if (type1 == error_mark_node
   13853                 :    14079968 :       || type2 == error_mark_node)
   13854                 :             :     return error_mark_node;
   13855                 :             : 
   13856                 :    14079968 :   if (processing_template_decl)
   13857                 :             :     {
   13858                 :     3093979 :       tree trait_expr = make_node (TRAIT_EXPR);
   13859                 :     3093979 :       if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
   13860                 :       29784 :         TREE_TYPE (trait_expr) = size_type_node;
   13861                 :     3064195 :       else if (kind == CPTK_TYPE_ORDER)
   13862                 :             :         {
   13863                 :        3940 :           tree val = type_order_value (type1, type1);
   13864                 :        3940 :           if (val != error_mark_node)
   13865                 :        3940 :             TREE_TYPE (trait_expr) = TREE_TYPE (val);
   13866                 :             :         }
   13867                 :             :       else
   13868                 :     3060255 :         TREE_TYPE (trait_expr) = boolean_type_node;
   13869                 :     3093979 :       TRAIT_EXPR_TYPE1 (trait_expr) = type1;
   13870                 :     3093979 :       TRAIT_EXPR_TYPE2 (trait_expr) = type2;
   13871                 :     3093979 :       TRAIT_EXPR_KIND (trait_expr) = kind;
   13872                 :     3093979 :       TRAIT_EXPR_LOCATION (trait_expr) = loc;
   13873                 :     3093979 :       return trait_expr;
   13874                 :             :     }
   13875                 :             : 
   13876                 :    10985989 :   switch (kind)
   13877                 :             :     {
   13878                 :       51912 :     case CPTK_HAS_NOTHROW_ASSIGN:
   13879                 :       51912 :     case CPTK_HAS_TRIVIAL_ASSIGN:
   13880                 :       51912 :     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
   13881                 :       51912 :     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
   13882                 :       51912 :     case CPTK_HAS_NOTHROW_COPY:
   13883                 :       51912 :     case CPTK_HAS_TRIVIAL_COPY:
   13884                 :       51912 :     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
   13885                 :       51912 :     case CPTK_IS_DESTRUCTIBLE:
   13886                 :       51912 :     case CPTK_IS_NOTHROW_DESTRUCTIBLE:
   13887                 :       51912 :     case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
   13888                 :       51912 :       if (!check_trait_type (type1))
   13889                 :          21 :         return error_mark_node;
   13890                 :             :       break;
   13891                 :             : 
   13892                 :      181765 :     case CPTK_IS_LITERAL_TYPE:
   13893                 :      181765 :     case CPTK_IS_POD:
   13894                 :      181765 :     case CPTK_IS_STD_LAYOUT:
   13895                 :      181765 :     case CPTK_IS_REPLACEABLE:
   13896                 :      181765 :     case CPTK_IS_NOTHROW_RELOCATABLE:
   13897                 :      181765 :     case CPTK_IS_TRIVIAL:
   13898                 :      181765 :     case CPTK_IS_TRIVIALLY_COPYABLE:
   13899                 :      181765 :     case CPTK_IS_TRIVIALLY_RELOCATABLE:
   13900                 :      181765 :     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   13901                 :      181765 :       if (!check_trait_type (type1, /* kind = */ 2))
   13902                 :          42 :         return error_mark_node;
   13903                 :             :       break;
   13904                 :             : 
   13905                 :      286253 :     case CPTK_IS_ABSTRACT:
   13906                 :      286253 :     case CPTK_IS_EMPTY:
   13907                 :      286253 :     case CPTK_IS_POLYMORPHIC:
   13908                 :      286253 :     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   13909                 :      286253 :       if (!check_trait_type (type1, /* kind = */ 3))
   13910                 :          15 :         return error_mark_node;
   13911                 :             :       break;
   13912                 :             : 
   13913                 :             :     /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
   13914                 :             :        type to know whether an array is an aggregate, so use kind=4 here.  */
   13915                 :      408619 :     case CPTK_IS_AGGREGATE:
   13916                 :      408619 :     case CPTK_IS_FINAL:
   13917                 :      408619 :       if (!check_trait_type (type1, /* kind = */ 4))
   13918                 :          14 :         return error_mark_node;
   13919                 :             :       break;
   13920                 :             : 
   13921                 :     3609424 :     case CPTK_IS_CONSTRUCTIBLE:
   13922                 :     3609424 :     case CPTK_IS_CONVERTIBLE:
   13923                 :     3609424 :     case CPTK_IS_INVOCABLE:
   13924                 :     3609424 :     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
   13925                 :     3609424 :     case CPTK_IS_NOTHROW_CONVERTIBLE:
   13926                 :     3609424 :     case CPTK_IS_NOTHROW_INVOCABLE:
   13927                 :     3609424 :     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
   13928                 :     3609424 :     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
   13929                 :     3609424 :     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
   13930                 :     3609424 :       /* Don't check completeness for direct reference binding.  */;
   13931                 :     3609424 :       if (same_type_ref_bind_p (kind, type1, type2))
   13932                 :             :         break;
   13933                 :     4315099 :       gcc_fallthrough ();
   13934                 :             : 
   13935                 :     4315099 :     case CPTK_IS_ASSIGNABLE:
   13936                 :     4315099 :     case CPTK_IS_NOTHROW_ASSIGNABLE:
   13937                 :     4315099 :     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
   13938                 :     4315099 :       if (!check_trait_type (type1)
   13939                 :     4315099 :           || !check_trait_type (type2))
   13940                 :          63 :         return error_mark_node;
   13941                 :             :       break;
   13942                 :             : 
   13943                 :      213060 :     case CPTK_IS_BASE_OF:
   13944                 :      213060 :     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
   13945                 :      212952 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   13946                 :      192782 :           && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
   13947                 :      394459 :           && !complete_type_or_else (type2, NULL_TREE))
   13948                 :             :         /* We already issued an error.  */
   13949                 :           3 :         return error_mark_node;
   13950                 :             :       break;
   13951                 :             : 
   13952                 :         696 :     case CPTK_IS_VIRTUAL_BASE_OF:
   13953                 :         630 :       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
   13954                 :        1311 :           && !complete_type_or_else (type2, NULL_TREE))
   13955                 :             :         /* We already issued an error.  */
   13956                 :           3 :         return error_mark_node;
   13957                 :             :       break;
   13958                 :             : 
   13959                 :             :     case CPTK_IS_ARRAY:
   13960                 :             :     case CPTK_IS_BOUNDED_ARRAY:
   13961                 :             :     case CPTK_IS_CLASS:
   13962                 :             :     case CPTK_IS_CONST:
   13963                 :             :     case CPTK_IS_ENUM:
   13964                 :             :     case CPTK_IS_FUNCTION:
   13965                 :             :     case CPTK_IS_MEMBER_FUNCTION_POINTER:
   13966                 :             :     case CPTK_IS_MEMBER_OBJECT_POINTER:
   13967                 :             :     case CPTK_IS_MEMBER_POINTER:
   13968                 :             :     case CPTK_IS_OBJECT:
   13969                 :             :     case CPTK_IS_POINTER:
   13970                 :             :     case CPTK_IS_REFERENCE:
   13971                 :             :     case CPTK_IS_SAME:
   13972                 :             :     case CPTK_IS_SCOPED_ENUM:
   13973                 :             :     case CPTK_IS_UNBOUNDED_ARRAY:
   13974                 :             :     case CPTK_IS_UNION:
   13975                 :             :     case CPTK_IS_VOLATILE:
   13976                 :             :       break;
   13977                 :             : 
   13978                 :             :     case CPTK_RANK:
   13979                 :             :       {
   13980                 :             :         size_t rank = 0;
   13981                 :         122 :         for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
   13982                 :          80 :           ++rank;
   13983                 :          42 :         return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
   13984                 :             :                                          loc);
   13985                 :             :       }
   13986                 :             : 
   13987                 :         122 :     case CPTK_TYPE_ORDER:
   13988                 :         122 :       return maybe_wrap_with_location (type_order_value (type1, type2), loc);
   13989                 :             : 
   13990                 :         138 :     case CPTK_STRUCTURED_BINDING_SIZE:
   13991                 :         138 :       return finish_structured_binding_size (loc, type1, tf_warning_or_error);
   13992                 :             : 
   13993                 :         198 :     case CPTK_IS_LAYOUT_COMPATIBLE:
   13994                 :         198 :       if (!array_of_unknown_bound_p (type1)
   13995                 :         181 :           && TREE_CODE (type1) != VOID_TYPE
   13996                 :         372 :           && !complete_type_or_else (type1, NULL_TREE))
   13997                 :             :         /* We already issued an error.  */
   13998                 :           6 :         return error_mark_node;
   13999                 :         192 :       if (!array_of_unknown_bound_p (type2)
   14000                 :         167 :           && TREE_CODE (type2) != VOID_TYPE
   14001                 :         352 :           && !complete_type_or_else (type2, NULL_TREE))
   14002                 :             :         /* We already issued an error.  */
   14003                 :           3 :         return error_mark_node;
   14004                 :             :       break;
   14005                 :             : 
   14006                 :          79 :     case CPTK_IS_DEDUCIBLE:
   14007                 :          79 :       if (!DECL_TYPE_TEMPLATE_P (type1))
   14008                 :             :         {
   14009                 :           0 :           error ("%qD is not a class or alias template", type1);
   14010                 :           0 :           return error_mark_node;
   14011                 :             :         }
   14012                 :             :       break;
   14013                 :             : 
   14014                 :             : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
   14015                 :             :     case CPTK_##CODE:
   14016                 :             : #include "cp-trait.def"
   14017                 :             : #undef DEFTRAIT_TYPE
   14018                 :             :       /* Type-yielding traits are handled in finish_trait_type.  */
   14019                 :           0 :       gcc_unreachable ();
   14020                 :             :     }
   14021                 :             : 
   14022                 :    10985517 :   tree val = (trait_expr_value (kind, type1, type2)
   14023                 :    10985517 :               ? boolean_true_node : boolean_false_node);
   14024                 :    10985517 :   return maybe_wrap_with_location (val, loc);
   14025                 :             : }
   14026                 :             : 
   14027                 :             : /* Process a trait type.  */
   14028                 :             : 
   14029                 :             : tree
   14030                 :     5044756 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
   14031                 :             :                    tsubst_flags_t complain)
   14032                 :             : {
   14033                 :     5044756 :   if (type1 == error_mark_node
   14034                 :     5044753 :       || type2 == error_mark_node)
   14035                 :             :     return error_mark_node;
   14036                 :             : 
   14037                 :     5044753 :   if (processing_template_decl)
   14038                 :             :     {
   14039                 :      209039 :       tree type = cxx_make_type (TRAIT_TYPE);
   14040                 :      209039 :       TRAIT_TYPE_TYPE1 (type) = type1;
   14041                 :      209039 :       TRAIT_TYPE_TYPE2 (type) = type2;
   14042                 :      209039 :       TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
   14043                 :             :       /* These traits are intended to be used in the definition of the ::type
   14044                 :             :          member of the corresponding standard library type trait and aren't
   14045                 :             :          mangleable (and thus won't appear directly in template signatures),
   14046                 :             :          so structural equality should suffice.  */
   14047                 :      209039 :       SET_TYPE_STRUCTURAL_EQUALITY (type);
   14048                 :      209039 :       return type;
   14049                 :             :     }
   14050                 :             : 
   14051                 :     4835714 :   switch (kind)
   14052                 :             :     {
   14053                 :      965944 :     case CPTK_ADD_LVALUE_REFERENCE:
   14054                 :             :       /* [meta.trans.ref].  */
   14055                 :      965944 :       if (referenceable_type_p (type1))
   14056                 :      965871 :         return cp_build_reference_type (type1, /*rval=*/false);
   14057                 :             :       return type1;
   14058                 :             : 
   14059                 :       44131 :     case CPTK_ADD_POINTER:
   14060                 :             :       /* [meta.trans.ptr].  */
   14061                 :       44131 :       if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
   14062                 :             :         {
   14063                 :       44099 :           if (TYPE_REF_P (type1))
   14064                 :       42989 :             type1 = TREE_TYPE (type1);
   14065                 :       44099 :           return build_pointer_type (type1);
   14066                 :             :         }
   14067                 :             :       return type1;
   14068                 :             : 
   14069                 :     1178240 :     case CPTK_ADD_RVALUE_REFERENCE:
   14070                 :             :       /* [meta.trans.ref].  */
   14071                 :     1178240 :       if (referenceable_type_p (type1))
   14072                 :     1178194 :         return cp_build_reference_type (type1, /*rval=*/true);
   14073                 :             :       return type1;
   14074                 :             : 
   14075                 :      160966 :     case CPTK_DECAY:
   14076                 :      160966 :       if (TYPE_REF_P (type1))
   14077                 :       29362 :         type1 = TREE_TYPE (type1);
   14078                 :             : 
   14079                 :      160966 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14080                 :         710 :         return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
   14081                 :         710 :                                   complain);
   14082                 :      160256 :       else if (TREE_CODE (type1) == FUNCTION_TYPE)
   14083                 :         159 :         return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
   14084                 :             :       else
   14085                 :      160097 :         return cv_unqualified (type1);
   14086                 :             : 
   14087                 :         262 :     case CPTK_REMOVE_ALL_EXTENTS:
   14088                 :         262 :       return strip_array_types (type1);
   14089                 :             : 
   14090                 :      670763 :     case CPTK_REMOVE_CV:
   14091                 :      670763 :       return cv_unqualified (type1);
   14092                 :             : 
   14093                 :      225709 :     case CPTK_REMOVE_CVREF:
   14094                 :      225709 :       if (TYPE_REF_P (type1))
   14095                 :      101593 :         type1 = TREE_TYPE (type1);
   14096                 :      225709 :       return cv_unqualified (type1);
   14097                 :             : 
   14098                 :       54437 :     case CPTK_REMOVE_EXTENT:
   14099                 :       54437 :       if (TREE_CODE (type1) == ARRAY_TYPE)
   14100                 :        2551 :         type1 = TREE_TYPE (type1);
   14101                 :             :       return type1;
   14102                 :             : 
   14103                 :       17008 :     case CPTK_REMOVE_POINTER:
   14104                 :       17008 :       if (TYPE_PTR_P (type1))
   14105                 :       14162 :         type1 = TREE_TYPE (type1);
   14106                 :             :       return type1;
   14107                 :             : 
   14108                 :     1383777 :     case CPTK_REMOVE_REFERENCE:
   14109                 :     1383777 :       if (TYPE_REF_P (type1))
   14110                 :      837128 :         type1 = TREE_TYPE (type1);
   14111                 :             :       return type1;
   14112                 :             : 
   14113                 :       91182 :     case CPTK_TYPE_PACK_ELEMENT:
   14114                 :       91182 :       return finish_type_pack_element (type1, type2, complain);
   14115                 :             : 
   14116                 :       43295 :     case CPTK_UNDERLYING_TYPE:
   14117                 :       43295 :       return finish_underlying_type (type1);
   14118                 :             : 
   14119                 :             : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
   14120                 :             :     case CPTK_##CODE:
   14121                 :             : #include "cp-trait.def"
   14122                 :             : #undef DEFTRAIT_EXPR
   14123                 :             :       /* Expression-yielding traits are handled in finish_trait_expr.  */
   14124                 :             :     case CPTK_BASES:
   14125                 :             :     case CPTK_DIRECT_BASES:
   14126                 :             :       /* BASES and DIRECT_BASES are handled in finish_bases.  */
   14127                 :             :       break;
   14128                 :             :     }
   14129                 :             : 
   14130                 :           0 :   gcc_unreachable ();
   14131                 :             : }
   14132                 :             : 
   14133                 :             : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
   14134                 :             :    which is ignored for C++.  */
   14135                 :             : 
   14136                 :             : void
   14137                 :           0 : set_float_const_decimal64 (void)
   14138                 :             : {
   14139                 :           0 : }
   14140                 :             : 
   14141                 :             : void
   14142                 :           0 : clear_float_const_decimal64 (void)
   14143                 :             : {
   14144                 :           0 : }
   14145                 :             : 
   14146                 :             : bool
   14147                 :     1959420 : float_const_decimal64_p (void)
   14148                 :             : {
   14149                 :     1959420 :   return 0;
   14150                 :             : }
   14151                 :             : 
   14152                 :             : 
   14153                 :             : /* Return true if T designates the implied `this' parameter.  */
   14154                 :             : 
   14155                 :             : bool
   14156                 :     4229824 : is_this_parameter (tree t)
   14157                 :             : {
   14158                 :     4229824 :   if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
   14159                 :             :     return false;
   14160                 :     2822979 :   gcc_assert (TREE_CODE (t) == PARM_DECL
   14161                 :             :               || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
   14162                 :             :               || (cp_binding_oracle && VAR_P (t)));
   14163                 :             :   return true;
   14164                 :             : }
   14165                 :             : 
   14166                 :             : /* As above, or a C++23 explicit object parameter.  */
   14167                 :             : 
   14168                 :             : bool
   14169                 :         456 : is_object_parameter (tree t)
   14170                 :             : {
   14171                 :         456 :   if (is_this_parameter (t))
   14172                 :             :     return true;
   14173                 :          91 :   if (TREE_CODE (t) != PARM_DECL)
   14174                 :             :     return false;
   14175                 :          34 :   tree ctx = DECL_CONTEXT (t);
   14176                 :          34 :   return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
   14177                 :          62 :           && t == DECL_ARGUMENTS (ctx));
   14178                 :             : }
   14179                 :             : 
   14180                 :             : /* Insert the deduced return type for an auto function.  */
   14181                 :             : 
   14182                 :             : void
   14183                 :      839789 : apply_deduced_return_type (tree fco, tree return_type)
   14184                 :             : {
   14185                 :      839789 :   tree result;
   14186                 :             : 
   14187                 :      839789 :   if (return_type == error_mark_node)
   14188                 :             :     return;
   14189                 :             : 
   14190                 :      839786 :   if (DECL_CONV_FN_P (fco))
   14191                 :         194 :     DECL_NAME (fco) = make_conv_op_name (return_type);
   14192                 :             : 
   14193                 :      839786 :   TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
   14194                 :             : 
   14195                 :      839786 :   maybe_update_postconditions (fco);
   14196                 :             : 
   14197                 :             :   /* Apply the type to the result object.  */
   14198                 :             : 
   14199                 :      839786 :   result = DECL_RESULT (fco);
   14200                 :      839786 :   if (result == NULL_TREE)
   14201                 :             :     return;
   14202                 :      837275 :   if (TREE_TYPE (result) == return_type)
   14203                 :             :     return;
   14204                 :             : 
   14205                 :      837269 :   if (!processing_template_decl && !VOID_TYPE_P (return_type)
   14206                 :     1422932 :       && !complete_type_or_else (return_type, NULL_TREE))
   14207                 :             :     return;
   14208                 :             : 
   14209                 :             :   /* We already have a DECL_RESULT from start_preparsed_function.
   14210                 :             :      Now we need to redo the work it and allocate_struct_function
   14211                 :             :      did to reflect the new type.  */
   14212                 :      837272 :   result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
   14213                 :      837272 :                        TYPE_MAIN_VARIANT (return_type));
   14214                 :      837272 :   DECL_ARTIFICIAL (result) = 1;
   14215                 :      837272 :   DECL_IGNORED_P (result) = 1;
   14216                 :      837272 :   cp_apply_type_quals_to_decl (cp_type_quals (return_type),
   14217                 :             :                                result);
   14218                 :      837272 :   DECL_RESULT (fco) = result;
   14219                 :             : 
   14220                 :      837272 :   if (!uses_template_parms (fco))
   14221                 :      837272 :     if (function *fun = DECL_STRUCT_FUNCTION (fco))
   14222                 :             :       {
   14223                 :      837143 :         bool aggr = aggregate_value_p (result, fco);
   14224                 :             : #ifdef PCC_STATIC_STRUCT_RETURN
   14225                 :             :         fun->returns_pcc_struct = aggr;
   14226                 :             : #endif
   14227                 :      837143 :         fun->returns_struct = aggr;
   14228                 :             :       }
   14229                 :             : }
   14230                 :             : 
   14231                 :             : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
   14232                 :             :    this is a right unary fold. Otherwise it is a left unary fold. */
   14233                 :             : 
   14234                 :             : static tree
   14235                 :      651650 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
   14236                 :             : {
   14237                 :             :   /* Build a pack expansion (assuming expr has pack type).  */
   14238                 :      651650 :   if (!uses_parameter_packs (expr))
   14239                 :             :     {
   14240                 :           3 :       error_at (location_of (expr), "operand of fold expression has no "
   14241                 :             :                 "unexpanded parameter packs");
   14242                 :           3 :       return error_mark_node;
   14243                 :             :     }
   14244                 :      651647 :   tree pack = make_pack_expansion (expr);
   14245                 :             : 
   14246                 :             :   /* Build the fold expression.  */
   14247                 :      651647 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14248                 :      651647 :   tree fold = build_min_nt_loc (loc, dir, code, pack);
   14249                 :      651647 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14250                 :      651647 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14251                 :      651647 :                                                     FOLD_EXPR_OP (fold),
   14252                 :      651647 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14253                 :      651647 :   return fold;
   14254                 :             : }
   14255                 :             : 
   14256                 :             : tree
   14257                 :       37017 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
   14258                 :             : {
   14259                 :       37017 :   return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
   14260                 :             : }
   14261                 :             : 
   14262                 :             : tree
   14263                 :      614633 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
   14264                 :             : {
   14265                 :      614633 :   return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
   14266                 :             : }
   14267                 :             : 
   14268                 :             : /* Build a binary fold expression over EXPR1 and EXPR2. The
   14269                 :             :    associativity of the fold is determined by EXPR1 and EXPR2 (whichever
   14270                 :             :    has an unexpanded parameter pack). */
   14271                 :             : 
   14272                 :             : static tree
   14273                 :       17129 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
   14274                 :             :                          int op, tree_code dir)
   14275                 :             : {
   14276                 :       17129 :   pack = make_pack_expansion (pack);
   14277                 :       17129 :   tree code = build_int_cstu (integer_type_node, abs (op));
   14278                 :       17129 :   tree fold = build_min_nt_loc (loc, dir, code, pack, init);
   14279                 :       17129 :   FOLD_EXPR_MODIFY_P (fold) = (op < 0);
   14280                 :       17129 :   TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
   14281                 :       17129 :                                                     FOLD_EXPR_OP (fold),
   14282                 :       17129 :                                                     FOLD_EXPR_MODIFY_P (fold));
   14283                 :       17129 :   return fold;
   14284                 :             : }
   14285                 :             : 
   14286                 :             : tree
   14287                 :       17129 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
   14288                 :             : {
   14289                 :             :   // Determine which expr has an unexpanded parameter pack and
   14290                 :             :   // set the pack and initial term.
   14291                 :       17129 :   bool pack1 = uses_parameter_packs (expr1);
   14292                 :       17129 :   bool pack2 = uses_parameter_packs (expr2);
   14293                 :       17129 :   if (pack1 && !pack2)
   14294                 :         344 :     return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
   14295                 :       16785 :   else if (pack2 && !pack1)
   14296                 :       16785 :     return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
   14297                 :             :   else
   14298                 :             :     {
   14299                 :           0 :       if (pack1)
   14300                 :           0 :         error ("both arguments in binary fold have unexpanded parameter packs");
   14301                 :             :       else
   14302                 :           0 :         error ("no unexpanded parameter packs in binary fold");
   14303                 :             :     }
   14304                 :           0 :   return error_mark_node;
   14305                 :             : }
   14306                 :             : 
   14307                 :             : /* Finish __builtin_launder (arg).  */
   14308                 :             : 
   14309                 :             : tree
   14310                 :       12890 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
   14311                 :             : {
   14312                 :       12890 :   tree orig_arg = arg;
   14313                 :       12890 :   if (!type_dependent_expression_p (arg))
   14314                 :          84 :     arg = decay_conversion (arg, complain);
   14315                 :       12890 :   if (error_operand_p (arg))
   14316                 :           0 :     return error_mark_node;
   14317                 :       12890 :   if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
   14318                 :             :     {
   14319                 :          24 :       error_at (loc, "type %qT of argument to %<__builtin_launder%> "
   14320                 :          24 :                 "is not a pointer to object type", TREE_TYPE (arg));
   14321                 :          24 :       return error_mark_node;
   14322                 :             :     }
   14323                 :       12866 :   if (processing_template_decl)
   14324                 :       12806 :     arg = orig_arg;
   14325                 :       12866 :   return build_call_expr_internal_loc (loc, IFN_LAUNDER,
   14326                 :       25732 :                                        TREE_TYPE (arg), 1, arg);
   14327                 :             : }
   14328                 :             : 
   14329                 :             : /* Finish __builtin_convertvector (arg, type).  */
   14330                 :             : 
   14331                 :             : tree
   14332                 :         185 : cp_build_vec_convert (tree arg, location_t loc, tree type,
   14333                 :             :                       tsubst_flags_t complain)
   14334                 :             : {
   14335                 :         185 :   if (error_operand_p (type))
   14336                 :           9 :     return error_mark_node;
   14337                 :         176 :   if (error_operand_p (arg))
   14338                 :           0 :     return error_mark_node;
   14339                 :             : 
   14340                 :         176 :   tree ret = NULL_TREE;
   14341                 :         176 :   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
   14342                 :         194 :     ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
   14343                 :             :                                decay_conversion (arg, complain),
   14344                 :             :                                loc, type, (complain & tf_error) != 0);
   14345                 :             : 
   14346                 :         176 :   if (!processing_template_decl)
   14347                 :             :     return ret;
   14348                 :             : 
   14349                 :          24 :   return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
   14350                 :             : }
   14351                 :             : 
   14352                 :             : /* Finish __builtin_bit_cast (type, arg).  */
   14353                 :             : 
   14354                 :             : tree
   14355                 :       47496 : cp_build_bit_cast (location_t loc, tree type, tree arg,
   14356                 :             :                    tsubst_flags_t complain)
   14357                 :             : {
   14358                 :       47496 :   if (error_operand_p (type))
   14359                 :           0 :     return error_mark_node;
   14360                 :       47496 :   if (!dependent_type_p (type))
   14361                 :             :     {
   14362                 :       34237 :       if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
   14363                 :           9 :         return error_mark_node;
   14364                 :       34228 :       if (TREE_CODE (type) == ARRAY_TYPE)
   14365                 :             :         {
   14366                 :             :           /* std::bit_cast for destination ARRAY_TYPE is not possible,
   14367                 :             :              as functions may not return an array, so don't bother trying
   14368                 :             :              to support this (and then deal with VLAs etc.).  */
   14369                 :           9 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14370                 :             :                          "is an array type", type);
   14371                 :           9 :           return error_mark_node;
   14372                 :             :         }
   14373                 :       34219 :       if (!trivially_copyable_p (type))
   14374                 :             :         {
   14375                 :          18 :           error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
   14376                 :             :                          "is not trivially copyable", type);
   14377                 :          18 :           return error_mark_node;
   14378                 :             :         }
   14379                 :             :     }
   14380                 :             : 
   14381                 :       47460 :   if (error_operand_p (arg))
   14382                 :           0 :     return error_mark_node;
   14383                 :             : 
   14384                 :       47460 :   if (!type_dependent_expression_p (arg))
   14385                 :             :     {
   14386                 :        7681 :       if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
   14387                 :             :         {
   14388                 :             :           /* Don't perform array-to-pointer conversion.  */
   14389                 :          26 :           arg = mark_rvalue_use (arg, loc, true);
   14390                 :          26 :           if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
   14391                 :           0 :             return error_mark_node;
   14392                 :             :         }
   14393                 :             :       else
   14394                 :        7655 :         arg = decay_conversion (arg, complain);
   14395                 :             : 
   14396                 :        7681 :       if (error_operand_p (arg))
   14397                 :          12 :         return error_mark_node;
   14398                 :             : 
   14399                 :        7669 :       if (!trivially_copyable_p (TREE_TYPE (arg)))
   14400                 :             :         {
   14401                 :           9 :           error_at (cp_expr_loc_or_loc (arg, loc),
   14402                 :             :                     "%<__builtin_bit_cast%> source type %qT "
   14403                 :           9 :                     "is not trivially copyable", TREE_TYPE (arg));
   14404                 :           9 :           return error_mark_node;
   14405                 :             :         }
   14406                 :        7660 :       if (!dependent_type_p (type)
   14407                 :       12843 :           && !cp_tree_equal (TYPE_SIZE_UNIT (type),
   14408                 :        5183 :                              TYPE_SIZE_UNIT (TREE_TYPE (arg))))
   14409                 :             :         {
   14410                 :          18 :           error_at (loc, "%<__builtin_bit_cast%> source size %qE "
   14411                 :             :                          "not equal to destination type size %qE",
   14412                 :          18 :                          TYPE_SIZE_UNIT (TREE_TYPE (arg)),
   14413                 :          18 :                          TYPE_SIZE_UNIT (type));
   14414                 :          18 :           return error_mark_node;
   14415                 :             :         }
   14416                 :             :     }
   14417                 :             : 
   14418                 :       47421 :   tree ret = build_min (BIT_CAST_EXPR, type, arg);
   14419                 :       47421 :   SET_EXPR_LOCATION (ret, loc);
   14420                 :             : 
   14421                 :       47421 :   if (!processing_template_decl && CLASS_TYPE_P (type))
   14422                 :         224 :     ret = get_target_expr (ret, complain);
   14423                 :             : 
   14424                 :             :   return ret;
   14425                 :             : }
   14426                 :             : 
   14427                 :             : /* Diagnose invalid #pragma GCC unroll argument and adjust
   14428                 :             :    it if needed.  */
   14429                 :             : 
   14430                 :             : tree
   14431                 :       16397 : cp_check_pragma_unroll (location_t loc, tree unroll)
   14432                 :             : {
   14433                 :       16397 :   HOST_WIDE_INT lunroll = 0;
   14434                 :       16397 :   if (type_dependent_expression_p (unroll))
   14435                 :             :     ;
   14436                 :       32722 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
   14437                 :       32676 :            || (!value_dependent_expression_p (unroll)
   14438                 :       16285 :                && (!tree_fits_shwi_p (unroll)
   14439                 :       16259 :                    || (lunroll = tree_to_shwi (unroll)) < 0
   14440                 :       16244 :                    || lunroll >= USHRT_MAX)))
   14441                 :             :     {
   14442                 :          90 :       error_at (loc, "%<#pragma GCC unroll%> requires an"
   14443                 :             :                 " assignment-expression that evaluates to a non-negative"
   14444                 :             :                 " integral constant less than %u", USHRT_MAX);
   14445                 :          90 :       unroll = integer_one_node;
   14446                 :             :     }
   14447                 :       16271 :   else if (TREE_CODE (unroll) == INTEGER_CST)
   14448                 :             :     {
   14449                 :       16241 :       unroll = fold_convert (integer_type_node, unroll);
   14450                 :       16241 :       if (integer_zerop (unroll))
   14451                 :          12 :         unroll = integer_one_node;
   14452                 :             :     }
   14453                 :       16397 :   return unroll;
   14454                 :             : }
   14455                 :             : 
   14456                 :             : #include "gt-cp-semantics.h"
        

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