LCOV - code coverage report
Current view: top level - gcc/fortran - openmp.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.4 % 8154 7618
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 236 236
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* OpenMP directive matching and resolving.
       2              :    Copyright (C) 2005-2026 Free Software Foundation, Inc.
       3              :    Contributed by Jakub Jelinek
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify it under
       8              : the terms of the GNU General Public License as published by the Free
       9              : Software Foundation; either version 3, or (at your option) any later
      10              : version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15              : for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #define INCLUDE_VECTOR
      22              : #define INCLUDE_STRING
      23              : #include "config.h"
      24              : #include "system.h"
      25              : #include "coretypes.h"
      26              : #include "options.h"
      27              : #include "gfortran.h"
      28              : #include "arith.h"
      29              : #include "match.h"
      30              : #include "parse.h"
      31              : #include "constructor.h"
      32              : #include "diagnostic.h"
      33              : #include "gomp-constants.h"
      34              : #include "target-memory.h"  /* For gfc_encode_character.  */
      35              : #include "bitmap.h"
      36              : #include "omp-api.h"  /* For omp_runtime_api_procname.  */
      37              : 
      38              : location_t gfc_get_location (locus *);
      39              : 
      40              : static gfc_statement omp_code_to_statement (gfc_code *);
      41              : 
      42              : enum gfc_omp_directive_kind {
      43              :   GFC_OMP_DIR_DECLARATIVE,
      44              :   GFC_OMP_DIR_EXECUTABLE,
      45              :   GFC_OMP_DIR_INFORMATIONAL,
      46              :   GFC_OMP_DIR_META,
      47              :   GFC_OMP_DIR_SUBSIDIARY,
      48              :   GFC_OMP_DIR_UTILITY
      49              : };
      50              : 
      51              : struct gfc_omp_directive {
      52              :   const char *name;
      53              :   enum gfc_omp_directive_kind kind;
      54              :   gfc_statement st;
      55              : };
      56              : 
      57              : /* Alphabetically sorted OpenMP clauses, except that longer strings are before
      58              :    substrings; excludes combined/composite directives. See note for "ordered"
      59              :    and "nothing".  */
      60              : 
      61              : static const struct gfc_omp_directive gfc_omp_directives[] = {
      62              :   /* allocate as alias for allocators is also executive. */
      63              :   {"allocate", GFC_OMP_DIR_DECLARATIVE, ST_OMP_ALLOCATE},
      64              :   {"allocators", GFC_OMP_DIR_EXECUTABLE, ST_OMP_ALLOCATORS},
      65              :   {"assumes", GFC_OMP_DIR_INFORMATIONAL, ST_OMP_ASSUMES},
      66              :   {"assume", GFC_OMP_DIR_INFORMATIONAL, ST_OMP_ASSUME},
      67              :   {"atomic", GFC_OMP_DIR_EXECUTABLE, ST_OMP_ATOMIC},
      68              :   {"barrier", GFC_OMP_DIR_EXECUTABLE, ST_OMP_BARRIER},
      69              :   {"cancellation point", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCELLATION_POINT},
      70              :   {"cancellation_point", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCELLATION_POINT},
      71              :   {"cancel", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCEL},
      72              :   {"critical", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CRITICAL},
      73              :   /* {"declare induction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_INDUCTION}, */
      74              :   /* {"declare_induction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_INDUCTION}, */
      75              :   {"declare mapper", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_MAPPER},
      76              :   {"declare_mapper", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_MAPPER},
      77              :   {"declare reduction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_REDUCTION},
      78              :   {"declare_reduction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_REDUCTION},
      79              :   {"declare simd", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_SIMD},
      80              :   {"declare_simd", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_SIMD},
      81              :   {"declare target", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_TARGET},
      82              :   {"declare_target", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_TARGET},
      83              :   {"declare variant", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_VARIANT},
      84              :   {"declare_variant", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_VARIANT},
      85              :   {"depobj", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DEPOBJ},
      86              :   {"dispatch", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DISPATCH},
      87              :   {"distribute", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DISTRIBUTE},
      88              :   {"do", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DO},
      89              :   /* "error" becomes GFC_OMP_DIR_EXECUTABLE with at(execution) */
      90              :   {"error", GFC_OMP_DIR_UTILITY, ST_OMP_ERROR},
      91              :   /* {"flatten", GFC_OMP_DIR_EXECUTABLE, ST_OMP_FLATTEN}, */
      92              :   {"flush", GFC_OMP_DIR_EXECUTABLE, ST_OMP_FLUSH},
      93              :   /* {"fuse", GFC_OMP_DIR_EXECUTABLE, ST_OMP_FLUSE}, */
      94              :   {"groupprivate", GFC_OMP_DIR_DECLARATIVE, ST_OMP_GROUPPRIVATE},
      95              :   /* {"interchange", GFC_OMP_DIR_EXECUTABLE, ST_OMP_INTERCHANGE}, */
      96              :   {"interop", GFC_OMP_DIR_EXECUTABLE, ST_OMP_INTEROP},
      97              :   {"loop", GFC_OMP_DIR_EXECUTABLE, ST_OMP_LOOP},
      98              :   {"masked", GFC_OMP_DIR_EXECUTABLE, ST_OMP_MASKED},
      99              :   {"metadirective", GFC_OMP_DIR_META, ST_OMP_METADIRECTIVE},
     100              :   /* Note: gfc_match_omp_nothing returns ST_NONE.  */
     101              :   {"nothing", GFC_OMP_DIR_UTILITY, ST_OMP_NOTHING},
     102              :   /* Special case; for now map to the first one.
     103              :      ordered-blockassoc = ST_OMP_ORDERED
     104              :      ordered-standalone = ST_OMP_ORDERED_DEPEND + depend/doacross.  */
     105              :   {"ordered", GFC_OMP_DIR_EXECUTABLE, ST_OMP_ORDERED},
     106              :   {"parallel", GFC_OMP_DIR_EXECUTABLE, ST_OMP_PARALLEL},
     107              :   {"requires", GFC_OMP_DIR_INFORMATIONAL, ST_OMP_REQUIRES},
     108              :   {"scan", GFC_OMP_DIR_SUBSIDIARY, ST_OMP_SCAN},
     109              :   {"scope", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SCOPE},
     110              :   {"sections", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SECTIONS},
     111              :   {"section", GFC_OMP_DIR_SUBSIDIARY, ST_OMP_SECTION},
     112              :   {"simd", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SIMD},
     113              :   {"single", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SINGLE},
     114              :   /* {"split", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SPLIT}, */
     115              :   /* {"strip", GFC_OMP_DIR_EXECUTABLE, ST_OMP_STRIP}, */
     116              :   {"target data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_DATA},
     117              :   {"target_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_DATA},
     118              :   {"target enter data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_ENTER_DATA},
     119              :   {"target_enter_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_ENTER_DATA},
     120              :   {"target exit data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_EXIT_DATA},
     121              :   {"target_exit_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_EXIT_DATA},
     122              :   {"target update", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_UPDATE},
     123              :   {"target_update", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_UPDATE},
     124              :   {"target", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET},
     125              :   /* {"taskgraph", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASKGRAPH}, */
     126              :   /* {"task iteration", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASK_ITERATION}, */
     127              :   {"taskloop", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASKLOOP},
     128              :   {"taskwait", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASKWAIT},
     129              :   {"taskyield", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASKYIELD},
     130              :   {"task", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASK},
     131              :   {"teams", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TEAMS},
     132              :   {"threadprivate", GFC_OMP_DIR_DECLARATIVE, ST_OMP_THREADPRIVATE},
     133              :   {"tile", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TILE},
     134              :   {"unroll", GFC_OMP_DIR_EXECUTABLE, ST_OMP_UNROLL},
     135              :   /* {"workdistribute", GFC_OMP_DIR_EXECUTABLE, ST_OMP_WORKDISTRIBUTE}, */
     136              :   {"workshare", GFC_OMP_DIR_EXECUTABLE, ST_OMP_WORKSHARE},
     137              : };
     138              : 
     139              : 
     140              : /* Match an end of OpenMP directive.  End of OpenMP directive is optional
     141              :    whitespace, followed by '\n' or comment '!'.  In the special case where a
     142              :    context selector is being matched, match against ')' instead.  */
     143              : 
     144              : static match
     145        56831 : gfc_match_omp_eos (void)
     146              : {
     147        56831 :   locus old_loc;
     148        56831 :   char c;
     149              : 
     150        56831 :   old_loc = gfc_current_locus;
     151        56831 :   gfc_gobble_whitespace ();
     152              : 
     153        56831 :   if (gfc_matching_omp_context_selector)
     154              :     {
     155          287 :       if (gfc_peek_ascii_char () == ')')
     156              :         return MATCH_YES;
     157              :     }
     158              :   else
     159              :     {
     160        56544 :       c = gfc_next_ascii_char ();
     161        56544 :       switch (c)
     162              :         {
     163            0 :         case '!':
     164            0 :           do
     165            0 :             c = gfc_next_ascii_char ();
     166            0 :           while (c != '\n');
     167              :           /* Fall through */
     168              : 
     169              :         case '\n':
     170              :           return MATCH_YES;
     171              :         }
     172              :     }
     173              : 
     174         1798 :   gfc_current_locus = old_loc;
     175         1798 :   return MATCH_NO;
     176              : }
     177              : 
     178              : match
     179        13267 : gfc_match_omp_eos_error (void)
     180              : {
     181        13267 :   if (gfc_match_omp_eos() == MATCH_YES)
     182              :     return MATCH_YES;
     183              : 
     184           35 :   gfc_error ("Unexpected junk at %C");
     185           35 :   return MATCH_ERROR;
     186              : }
     187              : 
     188              : 
     189              : /* Free an omp_clauses structure.  */
     190              : 
     191              : void
     192        84916 : gfc_free_omp_clauses (gfc_omp_clauses *c)
     193              : {
     194        84916 :   if (c == NULL)
     195              :     return;
     196              : 
     197        57579 :   gfc_free_expr (c->if_expr);
     198       690948 :   for (int i = 0; i < OMP_IF_LAST; i++)
     199       575790 :     gfc_free_expr (c->if_exprs[i]);
     200        57579 :   gfc_free_expr (c->self_expr);
     201        57579 :   gfc_free_expr (c->final_expr);
     202        57579 :   gfc_free_expr (c->chunk_size);
     203        57579 :   gfc_free_expr (c->safelen_expr);
     204        57579 :   gfc_free_expr (c->simdlen_expr);
     205        57579 :   gfc_free_expr (c->simdlen_divisor);
     206        57579 :   gfc_free_expr (c->device);
     207        57579 :   gfc_free_expr (c->dyn_groupprivate);
     208        57579 :   gfc_free_expr (c->dist_chunk_size);
     209        57579 :   gfc_free_expr (c->grainsize);
     210        57579 :   gfc_free_expr (c->hint);
     211        57579 :   gfc_free_expr (c->num_tasks);
     212        57579 :   gfc_free_expr (c->priority);
     213        57579 :   gfc_free_expr (c->detach);
     214        57579 :   gfc_free_expr (c->novariants);
     215        57579 :   gfc_free_expr (c->nocontext);
     216        57579 :   gfc_free_expr (c->async_expr);
     217        57579 :   gfc_free_expr (c->gang_num_expr);
     218        57579 :   gfc_free_expr (c->gang_static_expr);
     219        57579 :   gfc_free_expr (c->worker_expr);
     220        57579 :   gfc_free_expr (c->vector_expr);
     221        57579 :   gfc_free_expr (c->num_gangs_expr);
     222        57579 :   gfc_free_expr (c->num_workers_expr);
     223        57579 :   gfc_free_expr (c->vector_length_expr);
     224        57579 :   gfc_free_expr (c->device_num_expr);
     225      2360739 :   for (enum gfc_omp_list_type t = OMP_LIST_FIRST; t < OMP_LIST_NUM;
     226      2245581 :        t = gfc_omp_list_type (t + 1))
     227      2245581 :     gfc_free_omp_namelist (c->lists[t], t);
     228        57579 :   gfc_free_expr_list (c->num_teams_list);
     229        57579 :   gfc_free_expr_list (c->thread_limit_list);
     230        57579 :   gfc_free_expr_list (c->num_threads_list);
     231        57579 :   gfc_free_expr_list (c->wait_list);
     232        57579 :   gfc_free_expr_list (c->tile_list);
     233        57579 :   gfc_free_expr_list (c->sizes_list);
     234        57579 :   free (const_cast<char *> (c->critical_name));
     235        57579 :   if (c->assume)
     236              :     {
     237           33 :       free (c->assume->absent);
     238           33 :       free (c->assume->contains);
     239           33 :       gfc_free_expr_list (c->assume->holds);
     240           33 :       free (c->assume);
     241              :     }
     242        57579 :   free (c);
     243              : }
     244              : 
     245              : /* Free oacc_declare structures.  */
     246              : 
     247              : void
     248           76 : gfc_free_oacc_declare_clauses (struct gfc_oacc_declare *oc)
     249              : {
     250           76 :   struct gfc_oacc_declare *decl = oc;
     251              : 
     252           76 :   do
     253              :     {
     254           76 :       struct gfc_oacc_declare *next;
     255              : 
     256           76 :       next = decl->next;
     257           76 :       gfc_free_omp_clauses (decl->clauses);
     258           76 :       free (decl);
     259           76 :       decl = next;
     260              :     }
     261           76 :   while (decl);
     262           76 : }
     263              : 
     264              : /* Free expression list. */
     265              : void
     266       347363 : gfc_free_expr_list (gfc_expr_list *list)
     267              : {
     268       347363 :   gfc_expr_list *n;
     269              : 
     270       350386 :   for (; list; list = n)
     271              :     {
     272         3023 :       n = list->next;
     273         3023 :       free (list);
     274              :     }
     275       347363 : }
     276              : 
     277              : /* Free an !$omp declare simd construct list.  */
     278              : 
     279              : void
     280          252 : gfc_free_omp_declare_simd (gfc_omp_declare_simd *ods)
     281              : {
     282          252 :   if (ods)
     283              :     {
     284          252 :       gfc_free_omp_clauses (ods->clauses);
     285          252 :       free (ods);
     286              :     }
     287          252 : }
     288              : 
     289              : void
     290       563954 : gfc_free_omp_declare_simd_list (gfc_omp_declare_simd *list)
     291              : {
     292       564206 :   while (list)
     293              :     {
     294          252 :       gfc_omp_declare_simd *current = list;
     295          252 :       list = list->next;
     296          252 :       gfc_free_omp_declare_simd (current);
     297              :     }
     298       563954 : }
     299              : 
     300              : static void
     301          762 : gfc_free_omp_trait_property_list (gfc_omp_trait_property *list)
     302              : {
     303         1194 :   while (list)
     304              :     {
     305          432 :       gfc_omp_trait_property *current = list;
     306          432 :       list = list->next;
     307          432 :       switch (current->property_kind)
     308              :         {
     309           24 :         case OMP_TRAIT_PROPERTY_ID:
     310           24 :           free (current->name);
     311           24 :           break;
     312          265 :         case OMP_TRAIT_PROPERTY_NAME_LIST:
     313          265 :           if (current->is_name)
     314          170 :             free (current->name);
     315              :           break;
     316           31 :         case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
     317           31 :           gfc_free_omp_clauses (current->clauses);
     318           31 :           break;
     319              :         default:
     320              :           break;
     321              :         }
     322          432 :       free (current);
     323              :     }
     324          762 : }
     325              : 
     326              : static void
     327          629 : gfc_free_omp_selector_list (gfc_omp_selector *list)
     328              : {
     329         1391 :   while (list)
     330              :     {
     331          762 :       gfc_omp_selector *current = list;
     332          762 :       list = list->next;
     333          762 :       gfc_free_omp_trait_property_list (current->properties);
     334          762 :       free (current);
     335              :     }
     336          629 : }
     337              : 
     338              : static void
     339          700 : gfc_free_omp_set_selector_list (gfc_omp_set_selector *list)
     340              : {
     341         1329 :   while (list)
     342              :     {
     343          629 :       gfc_omp_set_selector *current = list;
     344          629 :       list = list->next;
     345          629 :       gfc_free_omp_selector_list (current->trait_selectors);
     346          629 :       free (current);
     347              :     }
     348          700 : }
     349              : 
     350              : /* Free an !$omp declare variant construct list.  */
     351              : 
     352              : void
     353       563954 : gfc_free_omp_declare_variant_list (gfc_omp_declare_variant *list)
     354              : {
     355       564431 :   while (list)
     356              :     {
     357          477 :       gfc_omp_declare_variant *current = list;
     358          477 :       list = list->next;
     359          477 :       gfc_free_omp_set_selector_list (current->set_selectors);
     360          477 :       gfc_free_omp_namelist (current->adjust_args_list, OMP_LIST_NONE);
     361          477 :       free (current);
     362              :     }
     363       563954 : }
     364              : 
     365              : /* Free an !$omp declare reduction.  */
     366              : 
     367              : void
     368         1285 : gfc_free_omp_udr (gfc_omp_udr *omp_udr)
     369              : {
     370         1285 :   if (omp_udr)
     371              :     {
     372          692 :       gfc_free_omp_udr (omp_udr->next);
     373          692 :       gfc_free_namespace (omp_udr->combiner_ns);
     374          692 :       if (omp_udr->initializer_ns)
     375          392 :         gfc_free_namespace (omp_udr->initializer_ns);
     376          692 :       free (omp_udr);
     377              :     }
     378         1285 : }
     379              : 
     380              : /* Free variants of an !$omp metadirective construct.  */
     381              : 
     382              : void
     383           97 : gfc_free_omp_variants (gfc_omp_variant *variant)
     384              : {
     385          297 :   while (variant)
     386              :     {
     387          200 :       gfc_omp_variant *next_variant = variant->next;
     388          200 :       gfc_free_omp_set_selector_list (variant->selectors);
     389          200 :       free (variant);
     390          200 :       variant = next_variant;
     391              :     }
     392           97 : }
     393              : 
     394              : /* Free an !$omp declare mapper.  */
     395              : 
     396              : void
     397           60 : gfc_free_omp_udm (gfc_omp_udm *omp_udm)
     398              : {
     399           60 :   if (omp_udm)
     400              :     {
     401           30 :       gfc_free_omp_udm (omp_udm->next);
     402           30 :       gfc_free_namespace (omp_udm->mapper_ns);
     403           30 :       free (omp_udm);
     404              :     }
     405           60 : }
     406              : 
     407              : static gfc_omp_udr *
     408         4725 : gfc_find_omp_udr (gfc_namespace *ns, const char *name, gfc_typespec *ts)
     409              : {
     410         4725 :   gfc_symtree *st;
     411              : 
     412         4725 :   if (ns == NULL)
     413          471 :     ns = gfc_current_ns;
     414         5681 :   do
     415              :     {
     416         5681 :       gfc_omp_udr *omp_udr;
     417              : 
     418         5681 :       st = gfc_find_symtree (ns->omp_udr_root, name);
     419         5681 :       if (st != NULL)
     420              :         {
     421          943 :           for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
     422          943 :             if (ts == NULL)
     423              :               return omp_udr;
     424          572 :             else if (gfc_compare_types (&omp_udr->ts, ts))
     425              :               {
     426          483 :                 if (ts->type == BT_CHARACTER)
     427              :                   {
     428           60 :                     if (omp_udr->ts.u.cl->length == NULL)
     429              :                       return omp_udr;
     430           36 :                     if (ts->u.cl->length == NULL)
     431            0 :                       continue;
     432           36 :                     if (gfc_compare_expr (omp_udr->ts.u.cl->length,
     433              :                                           ts->u.cl->length,
     434              :                                           INTRINSIC_EQ) != 0)
     435           12 :                       continue;
     436              :                   }
     437              :                 return omp_udr;
     438              :               }
     439              :         }
     440              : 
     441              :       /* Don't escape an interface block.  */
     442         4839 :       if (ns && !ns->has_import_set
     443         4839 :           && ns->proc_name && ns->proc_name->attr.if_source == IFSRC_IFBODY)
     444              :         break;
     445              : 
     446         4839 :       ns = ns->parent;
     447              :     }
     448         4839 :   while (ns != NULL);
     449              : 
     450              :   return NULL;
     451              : }
     452              : 
     453              : 
     454              : /* Match a variable/common block list and construct a namelist from it;
     455              :    if has_all_memory != NULL, *has_all_memory is set and omp_all_memory
     456              :    yields a list->sym NULL entry. */
     457              : 
     458              : static match
     459        32026 : gfc_match_omp_variable_list (const char *str, gfc_omp_namelist **list,
     460              :                              bool allow_common, bool *end_colon = NULL,
     461              :                              gfc_omp_namelist ***headp = NULL,
     462              :                              bool allow_sections = false,
     463              :                              bool allow_derived = false,
     464              :                              bool *has_all_memory = NULL,
     465              :                              bool reject_common_vars = false,
     466              :                              bool reverse_order = false)
     467              : {
     468        32026 :   gfc_omp_namelist *head, *tail, *p;
     469        32026 :   locus old_loc, cur_loc;
     470        32026 :   char n[GFC_MAX_SYMBOL_LEN+1];
     471        32026 :   gfc_symbol *sym;
     472        32026 :   match m;
     473        32026 :   gfc_symtree *st;
     474              : 
     475        32026 :   head = tail = NULL;
     476              : 
     477        32026 :   old_loc = gfc_current_locus;
     478        32026 :   if (has_all_memory)
     479          709 :     *has_all_memory = false;
     480        32026 :   m = gfc_match (str);
     481        32026 :   if (m != MATCH_YES)
     482              :     return m;
     483              : 
     484        38893 :   for (;;)
     485              :     {
     486        38893 :       gfc_gobble_whitespace ();
     487        38893 :       cur_loc = gfc_current_locus;
     488              : 
     489        38893 :       m = gfc_match_name (n);
     490        38893 :       if (m == MATCH_YES && strcmp (n, "omp_all_memory") == 0)
     491              :         {
     492           23 :           locus loc = gfc_get_location_range (NULL, 0, &cur_loc, 1,
     493              :                                               &gfc_current_locus);
     494           23 :           if (!has_all_memory)
     495              :             {
     496            2 :               gfc_error ("%<omp_all_memory%> at %L not permitted in this "
     497              :                          "clause", &loc);
     498            2 :               goto cleanup;
     499              :             }
     500           21 :           *has_all_memory = true;
     501           21 :           p = gfc_get_omp_namelist ();
     502           21 :           if (head == NULL)
     503              :             head = tail = p;
     504              :           else
     505              :             {
     506            3 :               tail->next = p;
     507            3 :               tail = tail->next;
     508              :             }
     509           21 :           tail->where = loc;
     510           21 :           goto next_item;
     511              :         }
     512        38614 :       if (m == MATCH_YES)
     513              :         {
     514        38614 :           gfc_symtree *st;
     515        38614 :           if ((m = gfc_get_ha_sym_tree (n, &st) ? MATCH_ERROR : MATCH_YES)
     516              :               == MATCH_YES)
     517        38614 :             sym = st->n.sym;
     518              :         }
     519        38870 :       switch (m)
     520              :         {
     521        38614 :         case MATCH_YES:
     522        38614 :           gfc_expr *expr;
     523        38614 :           expr = NULL;
     524        38614 :           gfc_gobble_whitespace ();
     525        23796 :           if ((allow_sections && gfc_peek_ascii_char () == '(')
     526        58048 :               || (allow_derived && gfc_peek_ascii_char () == '%'))
     527              :             {
     528         6609 :               gfc_current_locus = cur_loc;
     529         6609 :               m = gfc_match_variable (&expr, 0);
     530         6609 :               switch (m)
     531              :                 {
     532            4 :                 case MATCH_ERROR:
     533           12 :                   goto cleanup;
     534            0 :                 case MATCH_NO:
     535            0 :                   goto syntax;
     536         6605 :                 default:
     537         6605 :                   break;
     538              :                 }
     539         6605 :               if (gfc_is_coindexed (expr))
     540              :                 {
     541            5 :                   gfc_error ("List item shall not be coindexed at %L",
     542            5 :                              &expr->where);
     543            5 :                   goto cleanup;
     544              :                 }
     545              :             }
     546        38605 :           gfc_set_sym_referenced (sym);
     547        38605 :           p = gfc_get_omp_namelist ();
     548        38605 :           if (head == NULL)
     549              :             head = tail = p;
     550        10367 :           else if (reverse_order)
     551              :             {
     552           57 :               p->next = head;
     553           57 :               head = p;
     554              :             }
     555              :           else
     556              :             {
     557        10310 :               tail->next = p;
     558        10310 :               tail = tail->next;
     559              :             }
     560        38605 :           p->sym = sym;
     561        38605 :           p->expr = expr;
     562        38605 :           p->where = gfc_get_location_range (NULL, 0, &cur_loc, 1,
     563              :                                              &gfc_current_locus);
     564        38605 :           if (reject_common_vars && sym->attr.in_common)
     565              :             {
     566            3 :               gcc_assert (allow_common);
     567            3 :               gfc_error ("%qs at %L is part of the common block %</%s/%> and "
     568              :                          "may only be specified implicitly via the named "
     569              :                          "common block", sym->name, &cur_loc,
     570            3 :                          sym->common_head->name);
     571            3 :               goto cleanup;
     572              :             }
     573        38602 :           goto next_item;
     574          256 :         case MATCH_NO:
     575          256 :           break;
     576            0 :         case MATCH_ERROR:
     577            0 :           goto cleanup;
     578              :         }
     579              : 
     580          256 :       if (!allow_common)
     581           12 :         goto syntax;
     582              : 
     583          244 :       m = gfc_match ("/ %n /", n);
     584          244 :       if (m == MATCH_ERROR)
     585            0 :         goto cleanup;
     586          244 :       if (m == MATCH_NO)
     587           19 :         goto syntax;
     588              : 
     589          225 :       cur_loc = gfc_get_location_range (NULL, 0, &cur_loc, 1,
     590              :                                         &gfc_current_locus);
     591          225 :       st = gfc_find_symtree (gfc_current_ns->common_root, n);
     592          225 :       if (st == NULL)
     593              :         {
     594            2 :           gfc_error ("COMMON block %</%s/%> not found at %L", n, &cur_loc);
     595            2 :           goto cleanup;
     596              :         }
     597          724 :       for (sym = st->n.common->head; sym; sym = sym->common_next)
     598              :         {
     599          501 :           gfc_set_sym_referenced (sym);
     600          501 :           p = gfc_get_omp_namelist ();
     601          501 :           if (head == NULL)
     602              :             head = tail = p;
     603          325 :           else if (reverse_order)
     604              :             {
     605            0 :               p->next = head;
     606            0 :               head = p;
     607              :             }
     608              :           else
     609              :             {
     610          325 :               tail->next = p;
     611          325 :               tail = tail->next;
     612              :             }
     613          501 :           p->sym = sym;
     614          501 :           p->where = cur_loc;
     615              :         }
     616              : 
     617          223 :     next_item:
     618        38846 :       if (end_colon && gfc_match_char (':') == MATCH_YES)
     619              :         {
     620          806 :           *end_colon = true;
     621          806 :           break;
     622              :         }
     623        38040 :       if (gfc_match_char (')') == MATCH_YES)
     624              :         break;
     625        10438 :       if (gfc_match_char (',') != MATCH_YES)
     626           21 :         goto syntax;
     627              :     }
     628              : 
     629        38470 :   while (*list)
     630        10062 :     list = &(*list)->next;
     631              : 
     632        28408 :   *list = head;
     633        28408 :   if (headp)
     634        22492 :     *headp = list;
     635              :   return MATCH_YES;
     636              : 
     637           52 : syntax:
     638           52 :   gfc_error ("Syntax error in OpenMP variable list at %C");
     639              : 
     640           68 : cleanup:
     641           68 :   gfc_free_omp_namelist (head, OMP_LIST_NONE);
     642           68 :   gfc_current_locus = old_loc;
     643           68 :   return MATCH_ERROR;
     644              : }
     645              : 
     646              : /* Match a variable/procedure/common block list and construct a namelist
     647              :    from it.  */
     648              : 
     649              : static match
     650          397 : gfc_match_omp_to_link (const char *str, gfc_omp_namelist **list)
     651              : {
     652          397 :   gfc_omp_namelist *head, *tail, *p;
     653          397 :   locus old_loc, cur_loc;
     654          397 :   char n[GFC_MAX_SYMBOL_LEN+1];
     655          397 :   gfc_symbol *sym;
     656          397 :   match m;
     657          397 :   gfc_symtree *st;
     658              : 
     659          397 :   head = tail = NULL;
     660              : 
     661          397 :   old_loc = gfc_current_locus;
     662              : 
     663          397 :   m = gfc_match (str);
     664          397 :   if (m != MATCH_YES)
     665              :     return m;
     666              : 
     667          602 :   for (;;)
     668              :     {
     669          602 :       cur_loc = gfc_current_locus;
     670          602 :       m = gfc_match_symbol (&sym, 1);
     671          602 :       switch (m)
     672              :         {
     673          560 :         case MATCH_YES:
     674          560 :           p = gfc_get_omp_namelist ();
     675          560 :           if (head == NULL)
     676              :             head = tail = p;
     677              :           else
     678              :             {
     679          222 :               tail->next = p;
     680          222 :               tail = tail->next;
     681              :             }
     682          560 :           tail->sym = sym;
     683          560 :           tail->where = cur_loc;
     684          560 :           goto next_item;
     685              :         case MATCH_NO:
     686              :           break;
     687            0 :         case MATCH_ERROR:
     688            0 :           goto cleanup;
     689              :         }
     690              : 
     691           42 :       m = gfc_match (" / %n /", n);
     692           42 :       if (m == MATCH_ERROR)
     693            0 :         goto cleanup;
     694           42 :       if (m == MATCH_NO)
     695            0 :         goto syntax;
     696              : 
     697           42 :       st = gfc_find_symtree (gfc_current_ns->common_root, n);
     698           42 :       if (st == NULL)
     699              :         {
     700            0 :           gfc_error ("COMMON block /%s/ not found at %C", n);
     701            0 :           goto cleanup;
     702              :         }
     703           42 :       p = gfc_get_omp_namelist ();
     704           42 :       if (head == NULL)
     705              :         head = tail = p;
     706              :       else
     707              :         {
     708            4 :           tail->next = p;
     709            4 :           tail = tail->next;
     710              :         }
     711           42 :       tail->u.common = st->n.common;
     712           42 :       tail->where = cur_loc;
     713              : 
     714          602 :     next_item:
     715          602 :       if (gfc_match_char (')') == MATCH_YES)
     716              :         break;
     717          226 :       if (gfc_match_char (',') != MATCH_YES)
     718            0 :         goto syntax;
     719              :     }
     720              : 
     721          388 :   while (*list)
     722           12 :     list = &(*list)->next;
     723              : 
     724          376 :   *list = head;
     725          376 :   return MATCH_YES;
     726              : 
     727            0 : syntax:
     728            0 :   gfc_error ("Syntax error in OpenMP variable list at %C");
     729              : 
     730            0 : cleanup:
     731            0 :   gfc_free_omp_namelist (head, OMP_LIST_NONE);
     732            0 :   gfc_current_locus = old_loc;
     733            0 :   return MATCH_ERROR;
     734              : }
     735              : 
     736              : /* Match detach(event-handle).  */
     737              : 
     738              : static match
     739          126 : gfc_match_omp_detach (gfc_expr **expr)
     740              : {
     741          126 :   locus old_loc = gfc_current_locus;
     742              : 
     743          126 :   if (gfc_match ("detach ( ") != MATCH_YES)
     744            0 :     goto syntax_error;
     745              : 
     746          126 :   if (gfc_match_variable (expr, 0) != MATCH_YES)
     747            0 :     goto syntax_error;
     748              : 
     749          126 :   if (gfc_match_char (')') != MATCH_YES)
     750            0 :     goto syntax_error;
     751              : 
     752              :   return MATCH_YES;
     753              : 
     754            0 : syntax_error:
     755            0 :    gfc_error ("Syntax error in OpenMP detach clause at %C");
     756            0 :    gfc_current_locus = old_loc;
     757            0 :    return MATCH_ERROR;
     758              : 
     759              : }
     760              : 
     761              : /* Match doacross(sink : ...) construct a namelist from it;
     762              :    if depend is true, match legacy 'depend(sink : ...)'.  */
     763              : 
     764              : static match
     765          241 : gfc_match_omp_doacross_sink (gfc_omp_namelist **list, bool depend)
     766              : {
     767          241 :   char n[GFC_MAX_SYMBOL_LEN+1];
     768          241 :   gfc_omp_namelist *head, *tail, *p;
     769          241 :   locus old_loc, cur_loc;
     770          241 :   gfc_symbol *sym;
     771              : 
     772          241 :   head = tail = NULL;
     773              : 
     774          241 :   old_loc = gfc_current_locus;
     775              : 
     776         2231 :   for (;;)
     777              :     {
     778         1236 :       gfc_gobble_whitespace ();
     779         1236 :       cur_loc = gfc_current_locus;
     780              : 
     781         1236 :       if (gfc_match_name (n) != MATCH_YES)
     782            1 :         goto syntax;
     783         1235 :       locus loc = gfc_get_location_range (NULL, 0, &cur_loc, 1,
     784              :                                           &gfc_current_locus);
     785         1235 :       if (UNLIKELY (strcmp (n, "omp_all_memory") == 0))
     786              :         {
     787            1 :           gfc_error ("%<omp_all_memory%> used with dependence-type "
     788              :                      "other than OUT or INOUT at %L", &loc);
     789            1 :           goto cleanup;
     790              :         }
     791         1234 :       sym = NULL;
     792         1234 :       if (!(strcmp (n, "omp_cur_iteration") == 0))
     793              :         {
     794         1229 :           gfc_symtree *st;
     795         1229 :           if (gfc_get_ha_sym_tree (n, &st))
     796            0 :             goto syntax;
     797         1229 :           sym = st->n.sym;
     798         1229 :           gfc_set_sym_referenced (sym);
     799              :         }
     800         1234 :       p = gfc_get_omp_namelist ();
     801         1234 :       if (head == NULL)
     802              :         {
     803          239 :           head = tail = p;
     804          253 :           head->u.depend_doacross_op = (depend ? OMP_DEPEND_SINK_FIRST
     805              :                                                : OMP_DOACROSS_SINK_FIRST);
     806              :         }
     807              :       else
     808              :         {
     809          995 :           tail->next = p;
     810          995 :           tail = tail->next;
     811          995 :           tail->u.depend_doacross_op = OMP_DOACROSS_SINK;
     812              :         }
     813         1234 :       tail->sym = sym;
     814         1234 :       tail->expr = NULL;
     815         1234 :       tail->where = loc;
     816         1234 :       if (gfc_match_char ('+') == MATCH_YES)
     817              :         {
     818          154 :           if (gfc_match_literal_constant (&tail->expr, 0) != MATCH_YES)
     819            0 :             goto syntax;
     820              :         }
     821         1080 :       else if (gfc_match_char ('-') == MATCH_YES)
     822              :         {
     823          418 :           if (gfc_match_literal_constant (&tail->expr, 0) != MATCH_YES)
     824            1 :             goto syntax;
     825          417 :           tail->expr = gfc_uminus (tail->expr);
     826              :         }
     827         1233 :       if (gfc_match_char (')') == MATCH_YES)
     828              :         break;
     829          995 :       if (gfc_match_char (',') != MATCH_YES)
     830            0 :         goto syntax;
     831          995 :     }
     832              : 
     833         1030 :   while (*list)
     834          792 :     list = &(*list)->next;
     835              : 
     836          238 :   *list = head;
     837          238 :   return MATCH_YES;
     838              : 
     839            2 : syntax:
     840            2 :   gfc_error ("Syntax error in OpenMP SINK dependence-type list at %C");
     841              : 
     842            3 : cleanup:
     843            3 :   gfc_free_omp_namelist (head, OMP_LIST_DEPEND);
     844            3 :   gfc_current_locus = old_loc;
     845            3 :   return MATCH_ERROR;
     846              : }
     847              : 
     848              : static int
     849          332 : match_oacc_device_type_kind (void)
     850              : {
     851          332 :   char name[GFC_MAX_SYMBOL_LEN + 1];
     852              : 
     853              :   /* Since device_type arg accept * as all,
     854              :      we need to check first the case when
     855              :      the user inputs * as the parameter.  */
     856          332 :   gfc_gobble_whitespace ();
     857          332 :   name[0] = (char) gfc_next_char ();
     858              : 
     859          332 :   if (name[0] == '*')
     860              :     return GOMP_DEVICE_NONE;
     861              : 
     862              :   /* If is not *, we try to match the
     863              :      pre-defined names.  */
     864              : 
     865          332 :   match m = gfc_match (" %n ", name + 1);
     866              : 
     867          332 :   if (m != MATCH_YES)
     868              :     return -1;
     869              : 
     870          332 :   if (strcmp (name ,"host") == 0)
     871              :     return GOMP_DEVICE_HOST;
     872          144 :   if (strcmp (name, "nvidia") == 0)
     873              :     return GOMP_DEVICE_NVIDIA_PTX;
     874           72 :   if (strcmp (name, "radeon") == 0)
     875           69 :     return GOMP_DEVICE_GCN;
     876              : 
     877              :   return -1;
     878              : }
     879              : 
     880              : static match
     881          332 : match_oacc_device_type (gfc_omp_clauses *c)
     882              : {
     883          332 :   locus old_loc = gfc_current_locus;
     884              : 
     885          332 :   int result = match_oacc_device_type_kind ();
     886          332 :   match m;
     887              : 
     888          332 :   if (result == -1)
     889            3 :     goto syntax;
     890              : 
     891          329 :   m = gfc_match_char (')', true);
     892              : 
     893          329 :   if (m != MATCH_YES)
     894            3 :     goto single_argument;
     895              : 
     896          326 :   c->oacc_device_type = (unsigned) result;
     897          326 :   c->oacc_device_type_present = 1;
     898              : 
     899          326 :   return MATCH_YES;
     900              : 
     901            3 : single_argument:
     902            3 :   gfc_error ("OpenACC %<DEVICE_TYPE%> clause only accepts one argument, "
     903              :              "unexpected char at %C");
     904            3 :   goto cleanup;
     905              : 
     906            3 : syntax:
     907            3 :   gfc_error ("Syntax error in OpenACC %<DEVICE_TYPE%> argument at %C.  Expected "
     908              :              "host, radeon, nvidia or * as argument.");
     909              : 
     910            6 : cleanup:
     911            6 :   gfc_current_locus = old_loc;
     912            6 :   return MATCH_ERROR;
     913              : }
     914              : 
     915              : static match
     916         2005 : match_omp_oacc_expr_list (const char *str, gfc_expr_list **list,
     917              :                           bool allow_asterisk, bool is_omp)
     918              : {
     919         2005 :   gfc_expr_list *head, *tail, *p;
     920         2005 :   locus old_loc;
     921         2005 :   gfc_expr *expr;
     922         2005 :   match m;
     923              : 
     924         2005 :   head = tail = NULL;
     925              : 
     926         2005 :   old_loc = gfc_current_locus;
     927              : 
     928         2005 :   if (str && (m = gfc_match (str)) != MATCH_YES)
     929              :     return m;
     930              : 
     931         2297 :   for (;;)
     932              :     {
     933         2297 :       m = gfc_match_expr (&expr);
     934         2297 :       if (m == MATCH_YES || allow_asterisk)
     935              :         {
     936         2280 :           p = gfc_get_expr_list ();
     937         2280 :           if (head == NULL)
     938              :             head = tail = p;
     939              :           else
     940              :             {
     941          415 :               tail->next = p;
     942          415 :               tail = tail->next;
     943              :             }
     944         2280 :           if (m == MATCH_YES)
     945         2147 :             tail->expr = expr;
     946          133 :           else if (gfc_match (" *") != MATCH_YES)
     947           18 :             goto syntax;
     948         2262 :           goto next_item;
     949              :         }
     950           17 :       if (m == MATCH_ERROR)
     951            0 :         goto cleanup;
     952           17 :       goto syntax;
     953              : 
     954         2262 :     next_item:
     955         2262 :       if (gfc_match_char (')') == MATCH_YES)
     956              :         break;
     957          437 :       if (gfc_match_char (',') != MATCH_YES)
     958           17 :         goto syntax;
     959              :     }
     960              : 
     961         1831 :   while (*list)
     962            6 :     list = &(*list)->next;
     963              : 
     964         1825 :   *list = head;
     965         1825 :   return MATCH_YES;
     966              : 
     967           52 : syntax:
     968           52 :   if (is_omp)
     969           23 :     gfc_error ("Syntax error in OpenMP expression list at %C");
     970              :   else
     971           29 :     gfc_error ("Syntax error in OpenACC expression list at %C");
     972              : 
     973           52 : cleanup:
     974           52 :   gfc_free_expr_list (head);
     975           52 :   gfc_current_locus = old_loc;
     976           52 :   return MATCH_ERROR;
     977              : }
     978              : 
     979              : static match
     980         3056 : match_oacc_clause_gwv (gfc_omp_clauses *cp, unsigned gwv)
     981              : {
     982         3056 :   match ret = MATCH_YES;
     983              : 
     984         3056 :   if (gfc_match (" ( ") != MATCH_YES)
     985              :     return MATCH_NO;
     986              : 
     987          470 :   if (gwv == GOMP_DIM_GANG)
     988              :     {
     989              :         /* The gang clause accepts two optional arguments, num and static.
     990              :          The num argument may either be explicit (num: <val>) or
     991              :          implicit without (<val> without num:).  */
     992              : 
     993          457 :       while (ret == MATCH_YES)
     994              :         {
     995          236 :           if (gfc_match (" static :") == MATCH_YES)
     996              :             {
     997          114 :               if (cp->gang_static)
     998              :                 return MATCH_ERROR;
     999              :               else
    1000          113 :                 cp->gang_static = true;
    1001          113 :               if (gfc_match_char ('*') == MATCH_YES)
    1002           18 :                 cp->gang_static_expr = NULL;
    1003           95 :               else if (gfc_match (" %e ", &cp->gang_static_expr) != MATCH_YES)
    1004              :                 return MATCH_ERROR;
    1005              :             }
    1006              :           else
    1007              :             {
    1008          122 :               if (cp->gang_num_expr)
    1009              :                 return MATCH_ERROR;
    1010              : 
    1011              :               /* The 'num' argument is optional.  */
    1012          121 :               gfc_match (" num :");
    1013              : 
    1014          121 :               if (gfc_match (" %e ", &cp->gang_num_expr) != MATCH_YES)
    1015              :                 return MATCH_ERROR;
    1016              :             }
    1017              : 
    1018          231 :           ret = gfc_match (" , ");
    1019              :         }
    1020              :     }
    1021          244 :   else if (gwv == GOMP_DIM_WORKER)
    1022              :     {
    1023              :       /* The 'num' argument is optional.  */
    1024          107 :       gfc_match (" num :");
    1025              : 
    1026          107 :       if (gfc_match (" %e ", &cp->worker_expr) != MATCH_YES)
    1027              :         return MATCH_ERROR;
    1028              :     }
    1029          137 :   else if (gwv == GOMP_DIM_VECTOR)
    1030              :     {
    1031              :       /* The 'length' argument is optional.  */
    1032          137 :       gfc_match (" length :");
    1033              : 
    1034          137 :       if (gfc_match (" %e ", &cp->vector_expr) != MATCH_YES)
    1035              :         return MATCH_ERROR;
    1036              :     }
    1037              :   else
    1038            0 :     gfc_fatal_error ("Unexpected OpenACC parallelism.");
    1039              : 
    1040          459 :   return gfc_match (" )");
    1041              : }
    1042              : 
    1043              : static match
    1044            8 : gfc_match_oacc_clause_link (const char *str, gfc_omp_namelist **list)
    1045              : {
    1046            8 :   gfc_omp_namelist *head = NULL;
    1047            8 :   gfc_omp_namelist *tail, *p;
    1048            8 :   locus old_loc;
    1049            8 :   char n[GFC_MAX_SYMBOL_LEN+1];
    1050            8 :   gfc_symbol *sym;
    1051            8 :   match m;
    1052            8 :   gfc_symtree *st;
    1053              : 
    1054            8 :   old_loc = gfc_current_locus;
    1055              : 
    1056            8 :   m = gfc_match (str);
    1057            8 :   if (m != MATCH_YES)
    1058              :     return m;
    1059              : 
    1060            8 :   m = gfc_match (" (");
    1061              : 
    1062           14 :   for (;;)
    1063              :     {
    1064           14 :       m = gfc_match_symbol (&sym, 0);
    1065           14 :       switch (m)
    1066              :         {
    1067            8 :         case MATCH_YES:
    1068            8 :           if (sym->attr.in_common)
    1069              :             {
    1070            2 :               gfc_error_now ("Variable at %C is an element of a COMMON block");
    1071            2 :               goto cleanup;
    1072              :             }
    1073            6 :           gfc_set_sym_referenced (sym);
    1074            6 :           p = gfc_get_omp_namelist ();
    1075            6 :           if (head == NULL)
    1076              :             head = tail = p;
    1077              :           else
    1078              :             {
    1079            4 :               tail->next = p;
    1080            4 :               tail = tail->next;
    1081              :             }
    1082            6 :           tail->sym = sym;
    1083            6 :           tail->expr = NULL;
    1084            6 :           tail->where = gfc_current_locus;
    1085            6 :           goto next_item;
    1086              :         case MATCH_NO:
    1087              :           break;
    1088              : 
    1089            0 :         case MATCH_ERROR:
    1090            0 :           goto cleanup;
    1091              :         }
    1092              : 
    1093            6 :       m = gfc_match (" / %n /", n);
    1094            6 :       if (m == MATCH_ERROR)
    1095            0 :         goto cleanup;
    1096            6 :       if (m == MATCH_NO || n[0] == '\0')
    1097            0 :         goto syntax;
    1098              : 
    1099            6 :       st = gfc_find_symtree (gfc_current_ns->common_root, n);
    1100            6 :       if (st == NULL)
    1101              :         {
    1102            1 :           gfc_error ("COMMON block /%s/ not found at %C", n);
    1103            1 :           goto cleanup;
    1104              :         }
    1105              : 
    1106           20 :       for (sym = st->n.common->head; sym; sym = sym->common_next)
    1107              :         {
    1108           15 :           gfc_set_sym_referenced (sym);
    1109           15 :           p = gfc_get_omp_namelist ();
    1110           15 :           if (head == NULL)
    1111              :             head = tail = p;
    1112              :           else
    1113              :             {
    1114           12 :               tail->next = p;
    1115           12 :               tail = tail->next;
    1116              :             }
    1117           15 :           tail->sym = sym;
    1118           15 :           tail->where = gfc_current_locus;
    1119              :         }
    1120              : 
    1121            5 :     next_item:
    1122           11 :       if (gfc_match_char (')') == MATCH_YES)
    1123              :         break;
    1124            6 :       if (gfc_match_char (',') != MATCH_YES)
    1125            0 :         goto syntax;
    1126              :     }
    1127              : 
    1128            5 :   if (gfc_match_omp_eos () != MATCH_YES)
    1129              :     {
    1130            1 :       gfc_error ("Unexpected junk after !$ACC DECLARE at %C");
    1131            1 :       goto cleanup;
    1132              :     }
    1133              : 
    1134            4 :   while (*list)
    1135            0 :     list = &(*list)->next;
    1136            4 :   *list = head;
    1137            4 :   return MATCH_YES;
    1138              : 
    1139            0 : syntax:
    1140            0 :   gfc_error ("Syntax error in !$ACC DECLARE list at %C");
    1141              : 
    1142            4 : cleanup:
    1143            4 :   gfc_current_locus = old_loc;
    1144            4 :   return MATCH_ERROR;
    1145              : }
    1146              : 
    1147              : /* OpenMP clauses.  */
    1148              : enum omp_mask1
    1149              : {
    1150              :   OMP_CLAUSE_PRIVATE,
    1151              :   OMP_CLAUSE_FIRSTPRIVATE,
    1152              :   OMP_CLAUSE_LASTPRIVATE,
    1153              :   OMP_CLAUSE_COPYPRIVATE,
    1154              :   OMP_CLAUSE_SHARED,
    1155              :   OMP_CLAUSE_COPYIN,
    1156              :   OMP_CLAUSE_REDUCTION,
    1157              :   OMP_CLAUSE_IN_REDUCTION,
    1158              :   OMP_CLAUSE_TASK_REDUCTION,
    1159              :   OMP_CLAUSE_IF,
    1160              :   OMP_CLAUSE_NUM_THREADS,
    1161              :   OMP_CLAUSE_SCHEDULE,
    1162              :   OMP_CLAUSE_DEFAULT,
    1163              :   OMP_CLAUSE_ORDER,
    1164              :   OMP_CLAUSE_ORDERED,
    1165              :   OMP_CLAUSE_COLLAPSE,
    1166              :   OMP_CLAUSE_UNTIED,
    1167              :   OMP_CLAUSE_FINAL,
    1168              :   OMP_CLAUSE_MERGEABLE,
    1169              :   OMP_CLAUSE_ALIGNED,
    1170              :   OMP_CLAUSE_DEPEND,
    1171              :   OMP_CLAUSE_INBRANCH,
    1172              :   OMP_CLAUSE_LINEAR,
    1173              :   OMP_CLAUSE_NOTINBRANCH,
    1174              :   OMP_CLAUSE_PROC_BIND,
    1175              :   OMP_CLAUSE_SAFELEN,
    1176              :   OMP_CLAUSE_SIMDLEN,
    1177              :   OMP_CLAUSE_UNIFORM,
    1178              :   OMP_CLAUSE_DEVICE,
    1179              :   OMP_CLAUSE_MAP,
    1180              :   OMP_CLAUSE_TO,
    1181              :   OMP_CLAUSE_FROM,
    1182              :   OMP_CLAUSE_NUM_TEAMS,
    1183              :   OMP_CLAUSE_THREAD_LIMIT,
    1184              :   OMP_CLAUSE_DIST_SCHEDULE,
    1185              :   OMP_CLAUSE_DEFAULTMAP,
    1186              :   OMP_CLAUSE_GRAINSIZE,
    1187              :   OMP_CLAUSE_HINT,
    1188              :   OMP_CLAUSE_IS_DEVICE_PTR,
    1189              :   OMP_CLAUSE_LINK,
    1190              :   OMP_CLAUSE_NOGROUP,
    1191              :   OMP_CLAUSE_NOTEMPORAL,
    1192              :   OMP_CLAUSE_NUM_TASKS,
    1193              :   OMP_CLAUSE_PRIORITY,
    1194              :   OMP_CLAUSE_SIMD,
    1195              :   OMP_CLAUSE_THREADS,
    1196              :   OMP_CLAUSE_USE_DEVICE_PTR,
    1197              :   OMP_CLAUSE_USE_DEVICE_ADDR,  /* OpenMP 5.0.  */
    1198              :   OMP_CLAUSE_DEVICE_TYPE,  /* OpenMP 5.0.  */
    1199              :   OMP_CLAUSE_ATOMIC,  /* OpenMP 5.0.  */
    1200              :   OMP_CLAUSE_CAPTURE,  /* OpenMP 5.0.  */
    1201              :   OMP_CLAUSE_MEMORDER,  /* OpenMP 5.0.  */
    1202              :   OMP_CLAUSE_DETACH,  /* OpenMP 5.0.  */
    1203              :   OMP_CLAUSE_AFFINITY,  /* OpenMP 5.0.  */
    1204              :   OMP_CLAUSE_ALLOCATE,  /* OpenMP 5.0.  */
    1205              :   OMP_CLAUSE_BIND,  /* OpenMP 5.0.  */
    1206              :   OMP_CLAUSE_FILTER,  /* OpenMP 5.1.  */
    1207              :   OMP_CLAUSE_AT,  /* OpenMP 5.1.  */
    1208              :   OMP_CLAUSE_MESSAGE,  /* OpenMP 5.1.  */
    1209              :   OMP_CLAUSE_SEVERITY,  /* OpenMP 5.1.  */
    1210              :   OMP_CLAUSE_COMPARE,  /* OpenMP 5.1.  */
    1211              :   OMP_CLAUSE_FAIL,  /* OpenMP 5.1.  */
    1212              :   OMP_CLAUSE_WEAK,  /* OpenMP 5.1.  */
    1213              :   OMP_CLAUSE_NOWAIT,
    1214              :   /* This must come last.  */
    1215              :   OMP_MASK1_LAST
    1216              : };
    1217              : 
    1218              : /* More OpenMP clauses and OpenACC 2.0+ specific clauses. */
    1219              : enum omp_mask2
    1220              : {
    1221              :   OMP_CLAUSE_ASYNC,
    1222              :   OMP_CLAUSE_NUM_GANGS,
    1223              :   OMP_CLAUSE_NUM_WORKERS,
    1224              :   OMP_CLAUSE_VECTOR_LENGTH,
    1225              :   OMP_CLAUSE_COPY,
    1226              :   OMP_CLAUSE_COPYOUT,
    1227              :   OMP_CLAUSE_CREATE,
    1228              :   OMP_CLAUSE_NO_CREATE,
    1229              :   OMP_CLAUSE_PRESENT,
    1230              :   OMP_CLAUSE_DEVICEPTR,
    1231              :   OMP_CLAUSE_GANG,
    1232              :   OMP_CLAUSE_WORKER,
    1233              :   OMP_CLAUSE_VECTOR,
    1234              :   OMP_CLAUSE_SEQ,
    1235              :   OMP_CLAUSE_INDEPENDENT,
    1236              :   OMP_CLAUSE_USE_DEVICE,
    1237              :   OMP_CLAUSE_DEVICE_RESIDENT,
    1238              :   OMP_CLAUSE_SELF,
    1239              :   OMP_CLAUSE_HOST,
    1240              :   OMP_CLAUSE_WAIT,
    1241              :   OMP_CLAUSE_DELETE,
    1242              :   OMP_CLAUSE_AUTO,
    1243              :   OMP_CLAUSE_TILE,
    1244              :   OMP_CLAUSE_IF_PRESENT,
    1245              :   OMP_CLAUSE_FINALIZE,
    1246              :   OMP_CLAUSE_ATTACH,
    1247              :   OMP_CLAUSE_NOHOST,
    1248              :   OMP_CLAUSE_HAS_DEVICE_ADDR,  /* OpenMP 5.1  */
    1249              :   OMP_CLAUSE_ENTER, /* OpenMP 5.2 */
    1250              :   OMP_CLAUSE_DOACROSS, /* OpenMP 5.2 */
    1251              :   OMP_CLAUSE_ASSUMPTIONS, /* OpenMP 5.1. */
    1252              :   OMP_CLAUSE_USES_ALLOCATORS, /* OpenMP 5.0  */
    1253              :   OMP_CLAUSE_INDIRECT, /* OpenMP 5.1  */
    1254              :   OMP_CLAUSE_FULL,  /* OpenMP 5.1.  */
    1255              :   OMP_CLAUSE_PARTIAL,  /* OpenMP 5.1.  */
    1256              :   OMP_CLAUSE_SIZES,  /* OpenMP 5.1.  */
    1257              :   OMP_CLAUSE_INIT,  /* OpenMP 5.1.  */
    1258              :   OMP_CLAUSE_DESTROY,  /* OpenMP 5.1.  */
    1259              :   OMP_CLAUSE_USE,  /* OpenMP 5.1.  */
    1260              :   OMP_CLAUSE_NOVARIANTS, /* OpenMP 5.1  */
    1261              :   OMP_CLAUSE_NOCONTEXT, /* OpenMP 5.1  */
    1262              :   OMP_CLAUSE_INTEROP, /* OpenMP 5.1  */
    1263              :   OMP_CLAUSE_LOCAL, /* OpenMP 6.0 */
    1264              :   OMP_CLAUSE_DYN_GROUPPRIVATE, /* OpenMP 6.1 */
    1265              :   OMP_CLAUSE_DEVICE_NUM,
    1266              :   /* This must come last.  */
    1267              :   OMP_MASK2_LAST
    1268              : };
    1269              : 
    1270              : struct omp_inv_mask;
    1271              : 
    1272              : /* Customized bitset for up to 128-bits.
    1273              :    The two enums above provide bit numbers to use, and which of the
    1274              :    two enums it is determines which of the two mask fields is used.
    1275              :    Supported operations are defining a mask, like:
    1276              :    #define XXX_CLAUSES \
    1277              :      (omp_mask (OMP_CLAUSE_XXX) | OMP_CLAUSE_YYY | OMP_CLAUSE_ZZZ)
    1278              :    oring such bitsets together or removing selected bits:
    1279              :    (XXX_CLAUSES | YYY_CLAUSES) & ~(omp_mask (OMP_CLAUSE_VVV))
    1280              :    and testing individual bits:
    1281              :    if (mask & OMP_CLAUSE_UUU)  */
    1282              : 
    1283              : struct omp_mask {
    1284              :   const uint64_t mask1;
    1285              :   const uint64_t mask2;
    1286              :   inline omp_mask ();
    1287              :   inline omp_mask (omp_mask1);
    1288              :   inline omp_mask (omp_mask2);
    1289              :   inline omp_mask (uint64_t, uint64_t);
    1290              :   inline omp_mask operator| (omp_mask1) const;
    1291              :   inline omp_mask operator| (omp_mask2) const;
    1292              :   inline omp_mask operator| (omp_mask) const;
    1293              :   inline omp_mask operator& (const omp_inv_mask &) const;
    1294              :   inline bool operator& (omp_mask1) const;
    1295              :   inline bool operator& (omp_mask2) const;
    1296              :   inline omp_inv_mask operator~ () const;
    1297              : };
    1298              : 
    1299              : struct omp_inv_mask : public omp_mask {
    1300              :   inline omp_inv_mask (const omp_mask &);
    1301              : };
    1302              : 
    1303              : omp_mask::omp_mask () : mask1 (0), mask2 (0)
    1304              : {
    1305              : }
    1306              : 
    1307        33397 : omp_mask::omp_mask (omp_mask1 m) : mask1 (((uint64_t) 1) << m), mask2 (0)
    1308              : {
    1309              : }
    1310              : 
    1311         2247 : omp_mask::omp_mask (omp_mask2 m) : mask1 (0), mask2 (((uint64_t) 1) << m)
    1312              : {
    1313              : }
    1314              : 
    1315        34285 : omp_mask::omp_mask (uint64_t m1, uint64_t m2) : mask1 (m1), mask2 (m2)
    1316              : {
    1317              : }
    1318              : 
    1319              : omp_mask
    1320        33324 : omp_mask::operator| (omp_mask1 m) const
    1321              : {
    1322        33324 :   return omp_mask (mask1 | (((uint64_t) 1) << m), mask2);
    1323              : }
    1324              : 
    1325              : omp_mask
    1326        17865 : omp_mask::operator| (omp_mask2 m) const
    1327              : {
    1328        17865 :   return omp_mask (mask1, mask2 | (((uint64_t) 1) << m));
    1329              : }
    1330              : 
    1331              : omp_mask
    1332         4504 : omp_mask::operator| (omp_mask m) const
    1333              : {
    1334         4504 :   return omp_mask (mask1 | m.mask1, mask2 | m.mask2);
    1335              : }
    1336              : 
    1337              : omp_mask
    1338         2119 : omp_mask::operator& (const omp_inv_mask &m) const
    1339              : {
    1340         2119 :   return omp_mask (mask1 & ~m.mask1, mask2 & ~m.mask2);
    1341              : }
    1342              : 
    1343              : bool
    1344       131730 : omp_mask::operator& (omp_mask1 m) const
    1345              : {
    1346       131730 :   return (mask1 & (((uint64_t) 1) << m)) != 0;
    1347              : }
    1348              : 
    1349              : bool
    1350        93282 : omp_mask::operator& (omp_mask2 m) const
    1351              : {
    1352        93282 :   return (mask2 & (((uint64_t) 1) << m)) != 0;
    1353              : }
    1354              : 
    1355              : omp_inv_mask
    1356         2119 : omp_mask::operator~ () const
    1357              : {
    1358         2119 :   return omp_inv_mask (*this);
    1359              : }
    1360              : 
    1361         2119 : omp_inv_mask::omp_inv_mask (const omp_mask &m) : omp_mask (m)
    1362              : {
    1363              : }
    1364              : 
    1365              : /* Helper function for OpenACC and OpenMP clauses involving memory
    1366              :    mapping.  */
    1367              : 
    1368              : static bool
    1369         5544 : gfc_match_omp_map_clause (gfc_omp_namelist **list, gfc_omp_map_op map_op,
    1370              :                           bool allow_common, bool allow_derived)
    1371              : {
    1372         5544 :   gfc_omp_namelist **head = NULL;
    1373         5544 :   if (gfc_match_omp_variable_list ("", list, allow_common, NULL, &head, true,
    1374              :                                    allow_derived)
    1375              :       == MATCH_YES)
    1376              :     {
    1377         5535 :       gfc_omp_namelist *n;
    1378        13409 :       for (n = *head; n; n = n->next)
    1379         7874 :         n->u.map.op = map_op;
    1380              :       return true;
    1381              :     }
    1382              : 
    1383              :   return false;
    1384              : }
    1385              : 
    1386              : static match
    1387         8848 : gfc_match_iterator (gfc_namespace **ns, bool permit_var)
    1388              : {
    1389         8848 :   locus old_loc = gfc_current_locus;
    1390              : 
    1391         8848 :   if (gfc_match ("iterator ( ") != MATCH_YES)
    1392              :     return MATCH_NO;
    1393              : 
    1394          142 :   gfc_typespec ts;
    1395          142 :   gfc_symbol *last = NULL;
    1396          142 :   gfc_expr *begin, *end, *step;
    1397          142 :   *ns = gfc_build_block_ns (gfc_current_ns);
    1398          161 :   char name[GFC_MAX_SYMBOL_LEN + 1];
    1399          180 :   while (true)
    1400              :     {
    1401          161 :       locus prev_loc = gfc_current_locus;
    1402          161 :       if (gfc_match_type_spec (&ts) == MATCH_YES
    1403          161 :           && gfc_match (" :: ") == MATCH_YES)
    1404              :         {
    1405            5 :           if (ts.type != BT_INTEGER)
    1406              :             {
    1407            2 :               gfc_error ("Expected INTEGER type at %L", &prev_loc);
    1408            5 :               return MATCH_ERROR;
    1409              :             }
    1410              :           permit_var = false;
    1411              :         }
    1412              :       else
    1413              :         {
    1414          156 :           ts.type = BT_INTEGER;
    1415          156 :           ts.kind = gfc_default_integer_kind;
    1416          156 :           gfc_current_locus = prev_loc;
    1417              :         }
    1418          159 :       prev_loc = gfc_current_locus;
    1419          159 :       if (gfc_match_name (name) != MATCH_YES)
    1420              :         {
    1421            4 :           gfc_error ("Expected identifier at %C");
    1422            4 :           goto failed;
    1423              :         }
    1424          155 :       if (gfc_find_symtree ((*ns)->sym_root, name))
    1425              :         {
    1426            2 :           gfc_error ("Same identifier %qs specified again at %C", name);
    1427            2 :           goto failed;
    1428              :         }
    1429              : 
    1430          153 :       gfc_symbol *sym = gfc_new_symbol (name, *ns);
    1431          153 :       if (last)
    1432           17 :         last->tlink = sym;
    1433              :       else
    1434          136 :         (*ns)->omp_affinity_iterators = sym;
    1435          153 :       last = sym;
    1436          153 :       sym->declared_at = prev_loc;
    1437          153 :       sym->ts = ts;
    1438          153 :       sym->attr.flavor = FL_VARIABLE;
    1439          153 :       sym->attr.artificial = 1;
    1440          153 :       sym->attr.referenced = 1;
    1441          153 :       sym->refs++;
    1442          153 :       gfc_symtree *st = gfc_new_symtree (&(*ns)->sym_root, name);
    1443          153 :       st->n.sym = sym;
    1444              : 
    1445          153 :       prev_loc = gfc_current_locus;
    1446          153 :       if (gfc_match (" = ") != MATCH_YES)
    1447            3 :         goto failed;
    1448          150 :       permit_var = false;
    1449          150 :       begin = end = step = NULL;
    1450          150 :       if (gfc_match ("%e : ", &begin) != MATCH_YES
    1451          150 :           || gfc_match ("%e ", &end) != MATCH_YES)
    1452              :         {
    1453            3 :           gfc_error ("Expected range-specification at %C");
    1454            3 :           gfc_free_expr (begin);
    1455            3 :           gfc_free_expr (end);
    1456            3 :           return MATCH_ERROR;
    1457              :         }
    1458          147 :       if (':' == gfc_peek_ascii_char ())
    1459              :         {
    1460           23 :           if (gfc_match (": %e ", &step) != MATCH_YES)
    1461              :             {
    1462            5 :               gfc_free_expr (begin);
    1463            5 :               gfc_free_expr (end);
    1464            5 :               gfc_free_expr (step);
    1465            5 :               goto failed;
    1466              :             }
    1467              :         }
    1468              : 
    1469          142 :       gfc_expr *e = gfc_get_expr ();
    1470          142 :       e->where = prev_loc;
    1471          142 :       e->expr_type = EXPR_ARRAY;
    1472          142 :       e->ts = ts;
    1473          142 :       e->rank = 1;
    1474          142 :       e->shape = gfc_get_shape (1);
    1475          266 :       mpz_init_set_ui (e->shape[0], step ? 3 : 2);
    1476          142 :       gfc_constructor_append_expr (&e->value.constructor, begin, &begin->where);
    1477          142 :       gfc_constructor_append_expr (&e->value.constructor, end, &end->where);
    1478          142 :       if (step)
    1479           18 :         gfc_constructor_append_expr (&e->value.constructor, step, &step->where);
    1480          142 :       sym->value = e;
    1481              : 
    1482          142 :       if (gfc_match (") ") == MATCH_YES)
    1483              :         break;
    1484           19 :       if (gfc_match (", ") != MATCH_YES)
    1485            0 :         goto failed;
    1486           19 :     }
    1487          123 :   return MATCH_YES;
    1488              : 
    1489           14 : failed:
    1490           14 :   gfc_namespace *prev_ns = NULL;
    1491           14 :   for (gfc_namespace *it = gfc_current_ns->contained; it; it = it->sibling)
    1492              :     {
    1493            0 :       if (it == *ns)
    1494              :         {
    1495            0 :           if (prev_ns)
    1496            0 :             prev_ns->sibling = it->sibling;
    1497              :           else
    1498            0 :             gfc_current_ns->contained = it->sibling;
    1499            0 :           gfc_free_namespace (it);
    1500            0 :           break;
    1501              :         }
    1502            0 :       prev_ns = it;
    1503              :     }
    1504           14 :   *ns = NULL;
    1505           14 :   if (!permit_var)
    1506              :     return MATCH_ERROR;
    1507            4 :   gfc_current_locus = old_loc;
    1508            4 :   return MATCH_NO;
    1509              : }
    1510              : 
    1511              : /* Match target update's to/from( [present:] var-list).  */
    1512              : 
    1513              : static match
    1514         1806 : gfc_match_motion_var_list (const char *str, gfc_omp_namelist **list,
    1515              :                            gfc_omp_namelist ***headp)
    1516              : {
    1517         1806 :   match m = gfc_match (str);
    1518         1806 :   if (m != MATCH_YES)
    1519              :     return m;
    1520              : 
    1521         1806 :   gfc_namespace *ns_iter = NULL, *ns_curr = gfc_current_ns;
    1522         1806 :   locus old_loc = gfc_current_locus;
    1523         1806 :   int present_modifier = 0;
    1524         1806 :   int iterator_modifier = 0;
    1525         1806 :   locus second_present_locus = old_loc;
    1526         1806 :   locus second_iterator_locus = old_loc;
    1527         1806 :   bool saw_modifier = false;
    1528              : 
    1529         1818 :   for (;;)
    1530              :     {
    1531         1812 :       locus current_locus = gfc_current_locus;
    1532         1812 :       if (gfc_match ("present ") == MATCH_YES)
    1533              :         {
    1534            8 :           if (present_modifier++ == 1)
    1535            0 :             second_present_locus = current_locus;
    1536              :         }
    1537         1804 :       else if (gfc_match_iterator (&ns_iter, true) == MATCH_YES)
    1538              :         {
    1539           20 :           if (iterator_modifier++ == 1)
    1540            1 :             second_iterator_locus = current_locus;
    1541              :         }
    1542         1784 :       else if (!saw_modifier)
    1543              :         break;
    1544              :       else
    1545              :         {
    1546            2 :           gfc_error ("Expected clause modifier at %C");
    1547            4 :           return MATCH_ERROR;
    1548              :         }
    1549              : 
    1550              :       /* OpenMP 5.1 syntax mistakenly allowed commas to be optional
    1551              :          between and after modifiers in a clause.  This was corrected
    1552              :          in 5.2 and later specifications: they're now required between
    1553              :          modifiers and a trailing comma is not permitted.  We implement
    1554              :          the 5.2 syntax here.  */
    1555           28 :       saw_modifier = true;
    1556           28 :       if (gfc_match (" : ") == MATCH_YES)
    1557              :         break;
    1558            8 :       else if (gfc_match (", ") == MATCH_YES)
    1559            6 :         continue;
    1560              :       else
    1561              :         {
    1562            2 :           gfc_error ("Expected %<,%> or %<:%> after clause modifier at %C");
    1563            2 :           return MATCH_ERROR;
    1564              :         }
    1565            6 :     }
    1566              : 
    1567         1802 :   if (!saw_modifier)
    1568              :     {
    1569         1782 :       gfc_current_locus = old_loc;
    1570         1782 :       present_modifier = 0;
    1571         1782 :       iterator_modifier = 0;
    1572              :     }
    1573              : 
    1574         1802 :   if (present_modifier > 1)
    1575              :     {
    1576            0 :       gfc_error ("Too many %<present%> modifiers at %L", &second_present_locus);
    1577            0 :       return MATCH_ERROR;
    1578              :     }
    1579         1802 :   if (iterator_modifier > 1)
    1580              :     {
    1581            1 :       gfc_error ("Too many %<iterator%> modifiers at %L",
    1582              :                  &second_iterator_locus);
    1583            1 :       return MATCH_ERROR;
    1584              :     }
    1585              : 
    1586         1801 :   if (ns_iter)
    1587           14 :     gfc_current_ns = ns_iter;
    1588              : 
    1589         1801 :   m = gfc_match_omp_variable_list ("", list, false, NULL, headp, true, true);
    1590         1801 :   gfc_current_ns = ns_curr;
    1591         1801 :   if (m != MATCH_YES)
    1592              :     return m;
    1593         1799 :   gfc_omp_namelist *n;
    1594         3796 :   for (n = **headp; n; n = n->next)
    1595              :     {
    1596         1997 :       if (present_modifier)
    1597            6 :         n->u.present_modifier = true;
    1598         1997 :       if (iterator_modifier)
    1599              :         {
    1600           18 :           n->u2.ns = ns_iter;
    1601           18 :           ns_iter->refs++;
    1602              :         }
    1603              :     }
    1604              :   return MATCH_YES;
    1605              : }
    1606              : 
    1607              : /* reduction ( reduction-modifier, reduction-operator : variable-list )
    1608              :    in_reduction ( reduction-operator : variable-list )
    1609              :    task_reduction ( reduction-operator : variable-list )  */
    1610              : 
    1611              : static match
    1612         4368 : gfc_match_omp_clause_reduction (char pc, gfc_omp_clauses *c, bool openacc,
    1613              :                                 bool allow_derived, bool openmp_target = false)
    1614              : {
    1615         4368 :   if (pc == 'r' && gfc_match ("reduction ( ") != MATCH_YES)
    1616              :     return MATCH_NO;
    1617         4368 :   else if (pc == 'i' && gfc_match ("in_reduction ( ") != MATCH_YES)
    1618              :     return MATCH_NO;
    1619         4256 :   else if (pc == 't' && gfc_match ("task_reduction ( ") != MATCH_YES)
    1620              :     return MATCH_NO;
    1621              : 
    1622         4256 :   locus old_loc = gfc_current_locus;
    1623         4256 :   enum gfc_omp_list_type list_idx = OMP_LIST_NONE;
    1624              : 
    1625         4256 :   if (pc == 'r' && !openacc)
    1626              :     {
    1627         2129 :       if (gfc_match ("inscan") == MATCH_YES)
    1628              :         list_idx = OMP_LIST_REDUCTION_INSCAN;
    1629         2059 :       else if (gfc_match ("task") == MATCH_YES)
    1630              :         list_idx = OMP_LIST_REDUCTION_TASK;
    1631         1954 :       else if (gfc_match ("default") == MATCH_YES)
    1632              :         list_idx = OMP_LIST_REDUCTION;
    1633          231 :       if (list_idx != OMP_LIST_NONE && gfc_match (", ") != MATCH_YES)
    1634              :         {
    1635            1 :           gfc_error ("Comma expected at %C");
    1636            1 :           gfc_current_locus = old_loc;
    1637            1 :           return MATCH_NO;
    1638              :         }
    1639         2128 :       if (list_idx == OMP_LIST_NONE)
    1640         3842 :         list_idx = OMP_LIST_REDUCTION;
    1641              :     }
    1642         2127 :   else if (pc == 'i')
    1643              :     list_idx = OMP_LIST_IN_REDUCTION;
    1644         2009 :   else if (pc == 't')
    1645              :     list_idx = OMP_LIST_TASK_REDUCTION;
    1646              :   else
    1647         3842 :     list_idx = OMP_LIST_REDUCTION;
    1648              : 
    1649         4255 :   gfc_omp_reduction_op rop = OMP_REDUCTION_NONE;
    1650         4255 :   char buffer[GFC_MAX_SYMBOL_LEN + 3];
    1651         4255 :   if (gfc_match_char ('+') == MATCH_YES)
    1652              :     rop = OMP_REDUCTION_PLUS;
    1653         2224 :   else if (gfc_match_char ('*') == MATCH_YES)
    1654              :     rop = OMP_REDUCTION_TIMES;
    1655         1992 :   else if (gfc_match_char ('-') == MATCH_YES)
    1656              :     {
    1657          171 :       if (!openacc)
    1658           16 :         gfc_warning (OPT_Wdeprecated_openmp,
    1659              :                      "%<-%> operator at %C for reductions deprecated in "
    1660              :                      "OpenMP 5.2");
    1661              :       rop = OMP_REDUCTION_MINUS;
    1662              :     }
    1663         1821 :   else if (gfc_match (".and.") == MATCH_YES)
    1664              :     rop = OMP_REDUCTION_AND;
    1665         1715 :   else if (gfc_match (".or.") == MATCH_YES)
    1666              :     rop = OMP_REDUCTION_OR;
    1667          930 :   else if (gfc_match (".eqv.") == MATCH_YES)
    1668              :     rop = OMP_REDUCTION_EQV;
    1669          832 :   else if (gfc_match (".neqv.") == MATCH_YES)
    1670              :     rop = OMP_REDUCTION_NEQV;
    1671           16 :   if (rop != OMP_REDUCTION_NONE)
    1672         3518 :     snprintf (buffer, sizeof buffer, "operator %s",
    1673              :               gfc_op2string ((gfc_intrinsic_op) rop));
    1674          737 :   else if (gfc_match_defined_op_name (buffer + 1, 1) == MATCH_YES)
    1675              :     {
    1676           38 :       buffer[0] = '.';
    1677           38 :       strcat (buffer, ".");
    1678              :     }
    1679          699 :   else if (gfc_match_name (buffer) == MATCH_YES)
    1680              :     {
    1681          698 :       gfc_symbol *sym;
    1682          698 :       const char *n = buffer;
    1683              : 
    1684          698 :       gfc_find_symbol (buffer, NULL, 1, &sym);
    1685          698 :       if (sym != NULL)
    1686              :         {
    1687          217 :           if (sym->attr.intrinsic)
    1688          139 :             n = sym->name;
    1689           78 :           else if ((sym->attr.flavor != FL_UNKNOWN
    1690           76 :                     && sym->attr.flavor != FL_PROCEDURE)
    1691           76 :                    || sym->attr.external
    1692           65 :                    || sym->attr.generic
    1693           65 :                    || sym->attr.entry
    1694           65 :                    || sym->attr.result
    1695           65 :                    || sym->attr.dummy
    1696           65 :                    || sym->attr.subroutine
    1697           64 :                    || sym->attr.pointer
    1698           64 :                    || sym->attr.target
    1699           64 :                    || sym->attr.cray_pointer
    1700           64 :                    || sym->attr.cray_pointee
    1701           64 :                    || (sym->attr.proc != PROC_UNKNOWN
    1702            2 :                        && sym->attr.proc != PROC_INTRINSIC)
    1703           62 :                    || sym->attr.if_source != IFSRC_UNKNOWN
    1704           62 :                    || sym == sym->ns->proc_name)
    1705              :                 {
    1706              :                   sym = NULL;
    1707              :                   n = NULL;
    1708              :                 }
    1709              :               else
    1710           62 :                 n = sym->name;
    1711              :             }
    1712          201 :           if (n == NULL)
    1713              :             rop = OMP_REDUCTION_NONE;
    1714          682 :           else if (strcmp (n, "max") == 0)
    1715              :             rop = OMP_REDUCTION_MAX;
    1716          517 :           else if (strcmp (n, "min") == 0)
    1717              :             rop = OMP_REDUCTION_MIN;
    1718          376 :           else if (strcmp (n, "iand") == 0)
    1719              :             rop = OMP_REDUCTION_IAND;
    1720          321 :           else if (strcmp (n, "ior") == 0)
    1721              :             rop = OMP_REDUCTION_IOR;
    1722          255 :           else if (strcmp (n, "ieor") == 0)
    1723              :             rop = OMP_REDUCTION_IEOR;
    1724              :           if (rop != OMP_REDUCTION_NONE
    1725          477 :               && sym != NULL
    1726          200 :               && ! sym->attr.intrinsic
    1727           61 :               && ! sym->attr.use_assoc
    1728           61 :               && ((sym->attr.flavor == FL_UNKNOWN
    1729            2 :                    && !gfc_add_flavor (&sym->attr, FL_PROCEDURE,
    1730              :                                               sym->name, NULL))
    1731           61 :                   || !gfc_add_intrinsic (&sym->attr, NULL)))
    1732              :             rop = OMP_REDUCTION_NONE;
    1733              :     }
    1734              :   else
    1735            1 :     buffer[0] = '\0';
    1736         4255 :   gfc_omp_udr *udr = (buffer[0] ? gfc_find_omp_udr (gfc_current_ns, buffer, NULL)
    1737              :                                 : NULL);
    1738         4255 :   gfc_omp_namelist **head = NULL;
    1739         4255 :   if (rop == OMP_REDUCTION_NONE && udr)
    1740          251 :     rop = OMP_REDUCTION_USER;
    1741              : 
    1742         4255 :   if (gfc_match_omp_variable_list (" :", &c->lists[list_idx], false, NULL,
    1743              :                                    &head, openacc, allow_derived) != MATCH_YES)
    1744              :     {
    1745            9 :       gfc_current_locus = old_loc;
    1746            9 :       return MATCH_NO;
    1747              :     }
    1748         4246 :   gfc_omp_namelist *n;
    1749         4246 :   if (rop == OMP_REDUCTION_NONE)
    1750              :     {
    1751            6 :       n = *head;
    1752            6 :       *head = NULL;
    1753            6 :       gfc_error_now ("!$OMP DECLARE REDUCTION %s not found at %L",
    1754              :                      buffer, &old_loc);
    1755            6 :       gfc_free_omp_namelist (n, OMP_LIST_NONE);
    1756              :     }
    1757              :   else
    1758         9132 :     for (n = *head; n; n = n->next)
    1759              :       {
    1760         4892 :         n->u.reduction_op = rop;
    1761         4892 :         if (udr)
    1762              :           {
    1763          477 :             n->u2.udr = gfc_get_omp_namelist_udr ();
    1764          477 :             n->u2.udr->udr = udr;
    1765              :           }
    1766         4892 :         if (openmp_target && list_idx == OMP_LIST_IN_REDUCTION)
    1767              :           {
    1768           40 :             gfc_omp_namelist *p = gfc_get_omp_namelist (), **tl;
    1769           40 :             p->sym = n->sym;
    1770           40 :             p->where = n->where;
    1771           40 :             p->u.map.op = OMP_MAP_ALWAYS_TOFROM;
    1772              : 
    1773           40 :             tl = &c->lists[OMP_LIST_MAP];
    1774           52 :             while (*tl)
    1775           12 :               tl = &((*tl)->next);
    1776           40 :             *tl = p;
    1777           40 :             p->next = NULL;
    1778              :           }
    1779              :      }
    1780              :   return MATCH_YES;
    1781              : }
    1782              : 
    1783              : static match
    1784           47 : gfc_omp_absent_contains_clause (gfc_omp_assumptions **assume, bool is_absent)
    1785              : {
    1786           47 :   if (*assume == NULL)
    1787           22 :     *assume = gfc_get_omp_assumptions ();
    1788           77 :   do
    1789              :     {
    1790           62 :       gfc_statement st = ST_NONE;
    1791           62 :       gfc_gobble_whitespace ();
    1792           62 :       locus old_loc = gfc_current_locus;
    1793           62 :       char c = gfc_peek_ascii_char ();
    1794           62 :       enum gfc_omp_directive_kind kind
    1795              :         = GFC_OMP_DIR_DECLARATIVE; /* Silence warning. */
    1796         2369 :       for (size_t i = 0; i < ARRAY_SIZE (gfc_omp_directives); i++)
    1797              :         {
    1798         2307 :           if (gfc_omp_directives[i].name[0] > c)
    1799              :             break;
    1800         2245 :           if (gfc_omp_directives[i].name[0] != c)
    1801         1668 :             continue;
    1802          577 :           if (gfc_match (gfc_omp_directives[i].name) == MATCH_YES)
    1803              :             {
    1804           62 :               st = gfc_omp_directives[i].st;
    1805           62 :               kind = gfc_omp_directives[i].kind;
    1806              :             }
    1807              :         }
    1808           62 :       gfc_gobble_whitespace ();
    1809           62 :       c = gfc_peek_ascii_char ();
    1810           62 :       if (st == ST_NONE || (c != ',' && c != ')'))
    1811              :         {
    1812            0 :           if (st == ST_NONE)
    1813            0 :             gfc_error ("Unknown directive at %L", &old_loc);
    1814              :           else
    1815            0 :             gfc_error ("Invalid combined or composite directive at %L",
    1816              :                        &old_loc);
    1817            9 :           return MATCH_ERROR;
    1818              :         }
    1819           62 :       if (kind == GFC_OMP_DIR_DECLARATIVE
    1820           62 :           || kind == GFC_OMP_DIR_INFORMATIONAL
    1821              :           || kind == GFC_OMP_DIR_META)
    1822              :         {
    1823           15 :           gfc_error ("Invalid %qs directive at %L in %s clause: declarative, "
    1824              :                      "informational, and meta directives not permitted",
    1825              :                      gfc_ascii_statement (st, true), &old_loc,
    1826              :                      is_absent ? "ABSENT" : "CONTAINS");
    1827            9 :           return MATCH_ERROR;
    1828              :         }
    1829           53 :       if (is_absent)
    1830              :         {
    1831              :           /* Use exponential allocation; equivalent to pow2p(x). */
    1832           38 :           int i = (*assume)->n_absent;
    1833           38 :           int size = ((i == 0) ? 4
    1834           14 :                       : pow2p_hwi (i) == 1 ? i*2 : 0);
    1835           11 :           if (size != 0)
    1836           35 :             (*assume)->absent = XRESIZEVEC (gfc_statement,
    1837              :                                             (*assume)->absent, size);
    1838           38 :           (*assume)->absent[(*assume)->n_absent++] = st;
    1839              :         }
    1840              :       else
    1841              :         {
    1842           15 :           int i = (*assume)->n_contains;
    1843           15 :           int size = ((i == 0) ? 4
    1844            4 :                       : pow2p_hwi (i) == 1 ? i*2 : 0);
    1845            4 :           if (size != 0)
    1846           15 :             (*assume)->contains = XRESIZEVEC (gfc_statement,
    1847              :                                               (*assume)->contains, size);
    1848           15 :           (*assume)->contains[(*assume)->n_contains++] = st;
    1849              :         }
    1850           53 :       gfc_gobble_whitespace ();
    1851           53 :       if (gfc_match(",") == MATCH_YES)
    1852           15 :         continue;
    1853           38 :       if (gfc_match(")") == MATCH_YES)
    1854              :         break;
    1855            0 :       gfc_error ("Expected %<,%> or %<)%> at %C");
    1856            0 :       return MATCH_ERROR;
    1857           15 :     }
    1858              :   while (true);
    1859              : 
    1860           38 :   return MATCH_YES;
    1861              : }
    1862              : 
    1863              : /* Check 'check' argument for duplicated statements in absent and/or contains
    1864              :    clauses. If 'merge', merge them from check to 'merge'.  */
    1865              : 
    1866              : static match
    1867           50 : omp_verify_merge_absent_contains (gfc_statement st, gfc_omp_assumptions *check,
    1868              :                                   gfc_omp_assumptions *merge, locus *loc)
    1869              : {
    1870           50 :   if (check == NULL)
    1871              :     return MATCH_YES;
    1872           49 :   bitmap_head absent_head, contains_head;
    1873           49 :   bitmap_obstack_initialize (NULL);
    1874           49 :   bitmap_initialize (&absent_head, &bitmap_default_obstack);
    1875           49 :   bitmap_initialize (&contains_head, &bitmap_default_obstack);
    1876              : 
    1877           49 :   match m = MATCH_YES;
    1878           87 :   for (int i = 0; i < check->n_absent; i++)
    1879           38 :     if (!bitmap_set_bit (&absent_head, check->absent[i]))
    1880              :       {
    1881            2 :         gfc_error ("%qs directive mentioned multiple times in %s clause in %s "
    1882              :                    "directive at %L",
    1883            2 :                    gfc_ascii_statement (check->absent[i], true),
    1884              :                    "ABSENT", gfc_ascii_statement (st), loc);
    1885            2 :         m = MATCH_ERROR;
    1886              :       }
    1887           64 :   for (int i = 0; i < check->n_contains; i++)
    1888              :     {
    1889           15 :       if (!bitmap_set_bit (&contains_head, check->contains[i]))
    1890              :         {
    1891            2 :           gfc_error ("%qs directive mentioned multiple times in %s clause in %s "
    1892              :                      "directive at %L",
    1893            2 :                      gfc_ascii_statement (check->contains[i], true),
    1894              :                      "CONTAINS", gfc_ascii_statement (st), loc);
    1895            2 :           m = MATCH_ERROR;
    1896              :         }
    1897           15 :       if (bitmap_bit_p (&absent_head, check->contains[i]))
    1898              :         {
    1899            2 :           gfc_error ("%qs directive mentioned both times in ABSENT and CONTAINS "
    1900              :                      "clauses in %s directive at %L",
    1901            2 :                      gfc_ascii_statement (check->absent[i], true),
    1902              :                      gfc_ascii_statement (st), loc);
    1903            2 :           m = MATCH_ERROR;
    1904              :         }
    1905              :     }
    1906              : 
    1907           49 :   if (m == MATCH_ERROR)
    1908              :     return MATCH_ERROR;
    1909           43 :   if (merge == NULL)
    1910              :     return MATCH_YES;
    1911            3 :   if (merge->absent == NULL && check->absent)
    1912              :     {
    1913            1 :       merge->n_absent = check->n_absent;
    1914            1 :       merge->absent = check->absent;
    1915            1 :       check->absent = NULL;
    1916              :     }
    1917            2 :   else if (merge->absent && check->absent)
    1918              :     {
    1919            0 :       check->absent = XRESIZEVEC (gfc_statement, check->absent,
    1920              :                                   merge->n_absent + check->n_absent);
    1921            0 :       for (int i = 0; i < merge->n_absent; i++)
    1922            0 :         if (!bitmap_bit_p (&absent_head, merge->absent[i]))
    1923            0 :           check->absent[check->n_absent++] = merge->absent[i];
    1924            0 :       free (merge->absent);
    1925            0 :       merge->absent = check->absent;
    1926            0 :       merge->n_absent = check->n_absent;
    1927            0 :       check->absent = NULL;
    1928              :     }
    1929            3 :   if (merge->contains == NULL && check->contains)
    1930              :     {
    1931            0 :       merge->n_contains = check->n_contains;
    1932            0 :       merge->contains = check->contains;
    1933            0 :       check->contains = NULL;
    1934              :     }
    1935            3 :   else if (merge->contains && check->contains)
    1936              :     {
    1937            0 :       check->contains = XRESIZEVEC (gfc_statement, check->contains,
    1938              :                                     merge->n_contains + check->n_contains);
    1939            0 :       for (int i = 0; i < merge->n_contains; i++)
    1940            0 :         if (!bitmap_bit_p (&contains_head, merge->contains[i]))
    1941            0 :           check->contains[check->n_contains++] = merge->contains[i];
    1942            0 :       free (merge->contains);
    1943            0 :       merge->contains = check->contains;
    1944            0 :       merge->n_contains = check->n_contains;
    1945            0 :       check->contains = NULL;
    1946              :     }
    1947              :   return MATCH_YES;
    1948              : }
    1949              : 
    1950              : /* OpenMP 5.0
    1951              :    uses_allocators ( allocator-list )
    1952              : 
    1953              :    allocator:
    1954              :      predefined-allocator
    1955              :      variable ( traits-array )
    1956              : 
    1957              :    OpenMP 5.2 deprecated, 6.0 deleted: 'variable ( traits-array )'
    1958              : 
    1959              :    OpenMP 5.2:
    1960              :    uses_allocators ( [modifier-list :] allocator-list )
    1961              : 
    1962              :    OpenMP 6.0:
    1963              :    uses_allocators ( [modifier-list :] allocator-list [; ...])
    1964              : 
    1965              :    allocator:
    1966              :      variable or predefined-allocator
    1967              :    modifier:
    1968              :      traits ( traits-array )
    1969              :      memspace ( mem-space-handle )  */
    1970              : 
    1971              : static match
    1972           78 : gfc_match_omp_clause_uses_allocators (gfc_omp_clauses *c)
    1973              : {
    1974           82 : parse_next:
    1975           82 :   gfc_symbol *memspace_sym = NULL;
    1976           82 :   gfc_symbol *traits_sym = NULL;
    1977           82 :   gfc_omp_namelist *head = NULL;
    1978           82 :   gfc_omp_namelist *p, *tail, **list;
    1979           82 :   int ntraits, nmemspace;
    1980           82 :   bool has_modifiers;
    1981           82 :   locus old_loc, cur_loc;
    1982              : 
    1983           82 :   gfc_gobble_whitespace ();
    1984           82 :   old_loc = gfc_current_locus;
    1985           82 :   ntraits = nmemspace = 0;
    1986          126 :   do
    1987              :     {
    1988          104 :       cur_loc = gfc_current_locus;
    1989          104 :       if (gfc_match ("traits ( %S ) ", &traits_sym) == MATCH_YES)
    1990           34 :         ntraits++;
    1991           70 :       else if (gfc_match ("memspace ( %S ) ", &memspace_sym) == MATCH_YES)
    1992           33 :         nmemspace++;
    1993          104 :       if (ntraits > 1 || nmemspace > 1)
    1994              :         {
    1995            5 :           gfc_error ("Duplicate %s modifier at %L in USES_ALLOCATORS clause",
    1996              :                      ntraits > 1 ? "TRAITS" : "MEMSPACE", &cur_loc);
    1997            5 :           return MATCH_ERROR;
    1998              :         }
    1999           99 :       if (gfc_match (", ") == MATCH_YES)
    2000           22 :         continue;
    2001           77 :       if (gfc_match (": ") != MATCH_YES)
    2002              :         {
    2003              :           /* Assume no modifier. */
    2004           39 :           memspace_sym = traits_sym = NULL;
    2005           39 :           gfc_current_locus = old_loc;
    2006           39 :           break;
    2007              :         }
    2008              :       break;
    2009              :     } while (true);
    2010              : 
    2011          115 :   has_modifiers = traits_sym != NULL || memspace_sym != NULL;
    2012          179 :   do
    2013              :     {
    2014          128 :       p = gfc_get_omp_namelist ();
    2015          128 :       p->where = gfc_current_locus;
    2016          128 :       if (head == NULL)
    2017              :         head = tail = p;
    2018              :       else
    2019              :         {
    2020           51 :           tail->next = p;
    2021           51 :           tail = tail->next;
    2022              :         }
    2023          128 :       if (gfc_match ("%S ", &p->sym) != MATCH_YES)
    2024            1 :         goto error;
    2025          127 :       if (!has_modifiers)
    2026              :         {
    2027           83 :           if (gfc_match ("( %S ) ", &p->u2.traits_sym) == MATCH_YES)
    2028           22 :             gfc_warning (OPT_Wdeprecated_openmp,
    2029              :                          "The specification of arguments to "
    2030              :                          "%<uses_allocators%> at %L where each item is of "
    2031              :                          "the form %<allocator(traits)%> is deprecated since "
    2032              :                          "OpenMP 5.2; instead use %<uses_allocators(traits(%s"
    2033           22 :                          "): %s)%>", &p->where, p->u2.traits_sym->name,
    2034           22 :                          p->sym->name);
    2035              :         }
    2036           44 :       else if (gfc_peek_ascii_char () == '(')
    2037              :         {
    2038            1 :           gfc_error ("Unexpected %<(%> at %C");
    2039            1 :           goto error;
    2040              :         }
    2041              :       else
    2042              :         {
    2043           43 :           p->u.memspace_sym = memspace_sym;
    2044           43 :           p->u2.traits_sym = traits_sym;
    2045              :         }
    2046          126 :       gfc_gobble_whitespace ();
    2047          126 :       const char c = gfc_peek_ascii_char ();
    2048          126 :       if (c == ';' || c == ')')
    2049              :         break;
    2050           53 :       if (c != ',')
    2051              :         {
    2052            2 :           gfc_error ("Expected %<,%>, %<)%> or %<;%> at %C");
    2053            2 :           goto error;
    2054              :         }
    2055           51 :       gfc_match_char (',');
    2056           51 :       gfc_gobble_whitespace ();
    2057           51 :     } while (true);
    2058              : 
    2059           73 :   list = &c->lists[OMP_LIST_USES_ALLOCATORS];
    2060           91 :   while (*list)
    2061           18 :     list = &(*list)->next;
    2062           73 :   *list = head;
    2063              : 
    2064           73 :   if (gfc_match_char (';') == MATCH_YES)
    2065            4 :     goto parse_next;
    2066              : 
    2067           69 :   gfc_match_char (')');
    2068           69 :   return MATCH_YES;
    2069              : 
    2070            4 : error:
    2071            4 :   gfc_free_omp_namelist (head, OMP_LIST_USES_ALLOCATORS);
    2072            4 :   return MATCH_ERROR;
    2073              : }
    2074              : 
    2075              : 
    2076              : /* Match the 'prefer_type' modifier of the interop 'init' clause:
    2077              :    with either OpenMP 5.1's
    2078              :      prefer_type ( <const-int-expr|string literal> [, ...]
    2079              :    or
    2080              :      prefer_type ( '{' <fr(...) | attr (...)>, ...] '}' [, '{' ... '}' ] )
    2081              :    where 'fr' takes a constant expression or a string literal
    2082              :    and 'attr takes a list of string literals, starting with 'ompx_')
    2083              : 
    2084              :    For the foreign runtime identifiers, string values are converted to
    2085              :    their integer value; unknown string or integer values are set to
    2086              :    GOMP_INTEROP_IFR_KNOWN.
    2087              : 
    2088              :    Data format:
    2089              :     For the foreign runtime identifiers, string values are converted to
    2090              :     their integer value; unknown string or integer values are set to 0.
    2091              : 
    2092              :     Each item (a) GOMP_INTEROP_IFR_SEPARATOR
    2093              :               (b) for any 'fr', its integer value.
    2094              :                   Note: Spec only permits 1 'fr' entry (6.0; changed after TR13)
    2095              :               (c) GOMP_INTEROP_IFR_SEPARATOR
    2096              :               (d) list of \0-terminated non-empty strings for 'attr'
    2097              :               (e) '\0'
    2098              :     Tailing '\0'.  */
    2099              : 
    2100              : static match
    2101           82 : gfc_match_omp_prefer_type (char **type_str, int *type_str_len)
    2102              : {
    2103           82 :   gfc_expr *e;
    2104           82 :   std::string type_string, attr_string;
    2105              :   /* New syntax.  */
    2106           82 :   if (gfc_peek_ascii_char () == '{')
    2107          115 :     do
    2108              :       {
    2109           85 :         attr_string.clear ();
    2110           85 :         type_string += (char) GOMP_INTEROP_IFR_SEPARATOR;
    2111           85 :         if (gfc_match ("{ ") != MATCH_YES)
    2112              :           {
    2113            1 :             gfc_error ("Expected %<{%> at %C");
    2114            1 :             return MATCH_ERROR;
    2115              :           }
    2116              :         bool fr_found = false;
    2117          148 :         do
    2118              :           {
    2119          116 :             if (gfc_match ("fr ( ") == MATCH_YES)
    2120              :               {
    2121           62 :                 if (fr_found)
    2122              :                   {
    2123            1 :                     gfc_error ("Duplicated %<fr%> preference-selector-name "
    2124              :                                "at %C");
    2125            1 :                     return MATCH_ERROR;
    2126              :                   }
    2127           61 :                 fr_found = true;
    2128           61 :                 do
    2129              :                   {
    2130           61 :                     bool found_literal = false;
    2131           61 :                     match m = MATCH_YES;
    2132           61 :                     if (gfc_match_literal_constant (&e, false) == MATCH_YES)
    2133              :                       found_literal = true;
    2134              :                     else
    2135           12 :                       m = gfc_match_expr (&e);
    2136           12 :                     if (m != MATCH_YES
    2137           61 :                         || !gfc_resolve_expr (e)
    2138           61 :                         || e->rank != 0
    2139           60 :                         || e->expr_type != EXPR_CONSTANT
    2140           59 :                         || (e->ts.type != BT_INTEGER
    2141           43 :                             && (!found_literal || e->ts.type != BT_CHARACTER))
    2142           58 :                         || (e->ts.type == BT_INTEGER
    2143           16 :                             && !mpz_fits_sint_p (e->value.integer))
    2144           70 :                         || (e->ts.type == BT_CHARACTER
    2145           42 :                             && (e->ts.kind != gfc_default_character_kind
    2146           41 :                         || e->value.character.length == 0)))
    2147              :                       {
    2148            5 :                         gfc_error ("Expected constant scalar integer expression"
    2149              :                                    " or non-empty default-kind character "
    2150            5 :                                    "literal at %L", &e->where);
    2151            5 :                         gfc_free_expr (e);
    2152            5 :                         return MATCH_ERROR;
    2153              :                       }
    2154           56 :                     gfc_gobble_whitespace ();
    2155           56 :                     int val;
    2156           56 :                     if (e->ts.type == BT_INTEGER)
    2157              :                       {
    2158           16 :                         val = mpz_get_si (e->value.integer);
    2159           16 :                         if (val < 1 || val > GOMP_INTEROP_IFR_LAST)
    2160              :                           {
    2161            0 :                             gfc_warning_now (OPT_Wopenmp,
    2162              :                                              "Unknown foreign runtime "
    2163              :                                              "identifier %qd at %L",
    2164              :                                              val, &e->where);
    2165            0 :                             val = GOMP_INTEROP_IFR_UNKNOWN;
    2166              :                           }
    2167              :                       }
    2168              :                     else
    2169              :                       {
    2170           40 :                         char *str = XALLOCAVEC (char,
    2171              :                                                 e->value.character.length+1);
    2172          229 :                         for (int i = 0; i < e->value.character.length + 1; i++)
    2173          189 :                           str[i] = e->value.character.string[i];
    2174           40 :                         if (memchr (str, '\0', e->value.character.length) != 0)
    2175              :                           {
    2176            0 :                             gfc_error ("Unexpected null character in character "
    2177              :                                        "literal at %L", &e->where);
    2178            0 :                             return MATCH_ERROR;
    2179              :                           }
    2180           40 :                         val = omp_get_fr_id_from_name (str);
    2181           40 :                         if (val == GOMP_INTEROP_IFR_UNKNOWN)
    2182            2 :                           gfc_warning_now (OPT_Wopenmp,
    2183              :                                            "Unknown foreign runtime identifier "
    2184            2 :                                            "%qs at %L", str, &e->where);
    2185              :                       }
    2186              : 
    2187           56 :                     type_string += (char) val;
    2188           56 :                     if (gfc_match (") ") == MATCH_YES)
    2189              :                       break;
    2190            4 :                     gfc_error ("Expected %<)%> at %C");
    2191            4 :                     return MATCH_ERROR;
    2192              :                   }
    2193              :                 while (true);
    2194              :               }
    2195           54 :             else if (gfc_match ("attr ( ") == MATCH_YES)
    2196              :               {
    2197           60 :                 do
    2198              :                   {
    2199           57 :                     if (gfc_match_literal_constant (&e, false) != MATCH_YES
    2200           56 :                         || !gfc_resolve_expr (e)
    2201           56 :                         || e->expr_type != EXPR_CONSTANT
    2202           56 :                         || e->rank != 0
    2203           56 :                         || e->ts.type != BT_CHARACTER
    2204          113 :                         || e->ts.kind != gfc_default_character_kind)
    2205              :                       {
    2206            1 :                         gfc_error ("Expected default-kind character literal "
    2207            1 :                                    "at %L", &e->where);
    2208            1 :                         gfc_free_expr (e);
    2209            1 :                         return MATCH_ERROR;
    2210              :                       }
    2211           56 :                     gfc_gobble_whitespace ();
    2212           56 :                     char *str = XALLOCAVEC (char, e->value.character.length+1);
    2213          564 :                     for (int i = 0; i < e->value.character.length + 1; i++)
    2214          508 :                       str[i] = e->value.character.string[i];
    2215           56 :                     if (!startswith (str, "ompx_"))
    2216              :                       {
    2217            1 :                         gfc_error ("Character literal at %L must start with "
    2218              :                                    "%<ompx_%>", &e->where);
    2219            1 :                         gfc_free_expr (e);
    2220            1 :                         return MATCH_ERROR;
    2221              :                       }
    2222           55 :                     if (memchr (str, '\0', e->value.character.length) != 0
    2223           55 :                         || memchr (str, ',', e->value.character.length) != 0)
    2224              :                       {
    2225            1 :                         gfc_error ("Unexpected null or %<,%> character in "
    2226              :                                    "character literal at %L", &e->where);
    2227            1 :                         return MATCH_ERROR;
    2228              :                       }
    2229           54 :                     attr_string += str;
    2230           54 :                     attr_string += '\0';
    2231           54 :                     if (gfc_match (", ") == MATCH_YES)
    2232            3 :                       continue;
    2233           51 :                     if (gfc_match (") ") == MATCH_YES)
    2234              :                       break;
    2235            0 :                     gfc_error ("Expected %<,%> or %<)%> at %C");
    2236            0 :                     return MATCH_ERROR;
    2237            3 :                   }
    2238              :                 while (true);
    2239              :               }
    2240              :             else
    2241              :               {
    2242            0 :                 gfc_error ("Expected %<fr(%> or %<attr(%> at %C");
    2243            0 :                 return MATCH_ERROR;
    2244              :               }
    2245          103 :             if (gfc_match (", ") == MATCH_YES)
    2246           32 :               continue;
    2247           71 :             if (gfc_match ("} ") == MATCH_YES)
    2248              :               break;
    2249            2 :             gfc_error ("Expected %<,%> or %<}%> at %C");
    2250            2 :             return MATCH_ERROR;
    2251           32 :           }
    2252              :         while (true);
    2253           69 :         type_string += (char) GOMP_INTEROP_IFR_SEPARATOR;
    2254           69 :         type_string += attr_string;
    2255           69 :         type_string += '\0';
    2256           69 :         if (gfc_match (", ") == MATCH_YES)
    2257           30 :           continue;
    2258           39 :         if (gfc_match (") ") == MATCH_YES)
    2259              :           break;
    2260            1 :         gfc_error ("Expected %<,%> or %<)%> at %C");
    2261            1 :         return MATCH_ERROR;
    2262           30 :       }
    2263              :     while (true);
    2264              :   else
    2265           75 :     do
    2266              :       {
    2267           51 :         type_string += (char) GOMP_INTEROP_IFR_SEPARATOR;
    2268           51 :         bool found_literal = false;
    2269           51 :         match m = MATCH_YES;
    2270           51 :         if (gfc_match_literal_constant (&e, false) == MATCH_YES)
    2271              :           found_literal = true;
    2272              :         else
    2273           19 :           m = gfc_match_expr (&e);
    2274           19 :         if (m != MATCH_YES
    2275           51 :             || !gfc_resolve_expr (e)
    2276           51 :             || e->rank != 0
    2277           50 :             || e->expr_type != EXPR_CONSTANT
    2278           49 :             || (e->ts.type != BT_INTEGER
    2279           28 :                 && (!found_literal || e->ts.type != BT_CHARACTER))
    2280           48 :             || (e->ts.type == BT_INTEGER
    2281           21 :                 && !mpz_fits_sint_p (e->value.integer))
    2282           67 :             || (e->ts.type == BT_CHARACTER
    2283           27 :                 && (e->ts.kind != gfc_default_character_kind
    2284           27 :                     || e->value.character.length == 0)))
    2285              :           {
    2286            3 :             gfc_error ("Expected constant scalar integer expression or "
    2287            3 :                        "non-empty default-kind character literal at %L", &e->where);
    2288            3 :             gfc_free_expr (e);
    2289            3 :             return MATCH_ERROR;
    2290              :           }
    2291           48 :         gfc_gobble_whitespace ();
    2292           48 :         int val;
    2293           48 :         if (e->ts.type == BT_INTEGER)
    2294              :           {
    2295           21 :             val = mpz_get_si (e->value.integer);
    2296           21 :             if (val < 1 || val > GOMP_INTEROP_IFR_LAST)
    2297              :               {
    2298            3 :                 gfc_warning_now (OPT_Wopenmp,
    2299              :                                  "Unknown foreign runtime identifier %qd at %L",
    2300              :                                  val, &e->where);
    2301            3 :                 val = 0;
    2302              :               }
    2303              :           }
    2304              :         else
    2305              :           {
    2306           27 :             char *str = XALLOCAVEC (char, e->value.character.length+1);
    2307          169 :             for (int i = 0; i < e->value.character.length + 1; i++)
    2308          142 :               str[i] = e->value.character.string[i];
    2309           27 :             if (memchr (str, '\0', e->value.character.length) != 0)
    2310              :               {
    2311            0 :                 gfc_error ("Unexpected null character in character "
    2312              :                            "literal at %L", &e->where);
    2313            0 :                 return MATCH_ERROR;
    2314              :               }
    2315           27 :             val = omp_get_fr_id_from_name (str);
    2316           27 :             if (val == GOMP_INTEROP_IFR_UNKNOWN)
    2317            5 :               gfc_warning_now (OPT_Wopenmp,
    2318              :                                "Unknown foreign runtime identifier %qs at %L",
    2319            5 :                                str, &e->where);
    2320              :           }
    2321           48 :         type_string += (char) val;
    2322           48 :         type_string += (char) GOMP_INTEROP_IFR_SEPARATOR;
    2323           48 :         type_string += '\0';
    2324           48 :         gfc_free_expr (e);
    2325           48 :         if (gfc_match (", ") == MATCH_YES)
    2326           24 :           continue;
    2327           24 :         if (gfc_match (") ") == MATCH_YES)
    2328              :           break;
    2329            2 :         gfc_error ("Expected %<,%> or %<)%> at %C");
    2330            2 :         return MATCH_ERROR;
    2331           24 :       }
    2332              :     while (true);
    2333           60 :   type_string += '\0';
    2334           60 :   *type_str_len = type_string.length();
    2335           60 :   *type_str = XNEWVEC (char, type_string.length ());
    2336           60 :   memcpy (*type_str, type_string.data (), type_string.length ());
    2337           60 :   return MATCH_YES;
    2338           82 : }
    2339              : 
    2340              : 
    2341              : /* Match OpenMP 5.1's 'init'-clause modifiers, used by the 'init' clause of
    2342              :    the 'interop' directive and the 'append_args' directive of 'declare variant'.
    2343              :      [prefer_type(...)][,][<target|targetsync>, ...])
    2344              : 
    2345              :    If is_init_clause, the modifier parsing ends with a ':'.
    2346              :    If not is_init_clause (i.e. append_args), the parsing ends with ')'.  */
    2347              : 
    2348              : static match
    2349          164 : gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync,
    2350              :                                       char **type_str, int &type_str_len,
    2351              :                                       bool is_init_clause)
    2352              : {
    2353          164 :   target = false;
    2354          164 :   targetsync = false;
    2355          164 :   *type_str = NULL;
    2356          164 :   type_str_len = 0;
    2357          286 :   match m;
    2358              : 
    2359          286 :   do
    2360              :     {
    2361          286 :       if (gfc_match ("prefer_type ( ") == MATCH_YES)
    2362              :         {
    2363           83 :           if (*type_str)
    2364              :             {
    2365            1 :               gfc_error ("Duplicate %<prefer_type%> modifier at %C");
    2366            1 :               return MATCH_ERROR;
    2367              :             }
    2368           82 :           m = gfc_match_omp_prefer_type (type_str, &type_str_len);
    2369           82 :           if (m != MATCH_YES)
    2370              :             return m;
    2371           60 :           if (gfc_match (", ") == MATCH_YES)
    2372           14 :             continue;
    2373           46 :           if (is_init_clause)
    2374              :             {
    2375           24 :               if (gfc_match (": ") == MATCH_YES)
    2376              :                 break;
    2377            0 :               gfc_error ("Expected %<,%> or %<:%> at %C");
    2378              :             }
    2379              :           else
    2380              :             {
    2381           22 :               if (gfc_match (") ") == MATCH_YES)
    2382              :                 break;
    2383            0 :               gfc_error ("Expected %<,%> or %<)%> at %C");
    2384              :             }
    2385              :           return MATCH_ERROR;
    2386              :         }
    2387              : 
    2388          203 :       if (gfc_match ("prefer_type ") == MATCH_YES)
    2389              :         {
    2390            2 :           gfc_error ("Expected %<(%> after %<prefer_type%> at %C");
    2391            2 :           return MATCH_ERROR;
    2392              :         }
    2393              : 
    2394          201 :       if (gfc_match ("targetsync ") == MATCH_YES)
    2395              :         {
    2396           57 :           if (targetsync)
    2397              :             {
    2398            3 :               gfc_error ("Duplicate %<targetsync%> at %C");
    2399            3 :               return MATCH_ERROR;
    2400              :             }
    2401           54 :           targetsync = true;
    2402           54 :           if (gfc_match (", ") == MATCH_YES)
    2403           13 :             continue;
    2404           41 :           if (!is_init_clause)
    2405              :             {
    2406           23 :               if (gfc_match (") ") == MATCH_YES)
    2407              :                 break;
    2408            0 :               gfc_error ("Expected %<,%> or %<)%> at %C");
    2409            0 :               return MATCH_ERROR;
    2410              :             }
    2411           18 :           if (gfc_match (": ") == MATCH_YES)
    2412              :             break;
    2413            1 :           gfc_error ("Expected %<,%> or %<:%> at %C");
    2414            1 :           return MATCH_ERROR;
    2415              :         }
    2416          144 :       if (gfc_match ("target ") == MATCH_YES)
    2417              :         {
    2418          135 :           if (target)
    2419              :             {
    2420            3 :               gfc_error ("Duplicate %<target%> at %C");
    2421            3 :               return MATCH_ERROR;
    2422              :             }
    2423          132 :           target = true;
    2424          132 :           if (gfc_match (", ") == MATCH_YES)
    2425           95 :             continue;
    2426           37 :           if (!is_init_clause)
    2427              :             {
    2428           11 :               if (gfc_match (") ") == MATCH_YES)
    2429              :                 break;
    2430            0 :               gfc_error ("Expected %<,%> or %<)%> at %C");
    2431            0 :               return MATCH_ERROR;
    2432              :             }
    2433           26 :           if (gfc_match (": ") == MATCH_YES)
    2434              :             break;
    2435            1 :           gfc_error ("Expected %<,%> or %<:%> at %C");
    2436            1 :           return MATCH_ERROR;
    2437              :         }
    2438            9 :       gfc_error ("Expected %<prefer_type%>, %<target%>, or %<targetsync%> "
    2439              :                  "at %C");
    2440            9 :       return MATCH_ERROR;
    2441              :     }
    2442              :   while (true);
    2443              : 
    2444          122 :   if (!target && !targetsync)
    2445              :     {
    2446            4 :       gfc_error ("Missing required %<target%> and/or %<targetsync%> "
    2447              :                  "modifier at %C");
    2448            4 :       return MATCH_ERROR;
    2449              :     }
    2450              :   return MATCH_YES;
    2451              : }
    2452              : 
    2453              : /* Match OpenMP 5.1's 'init' clause for 'interop' objects:
    2454              :    init([prefer_type(...)][,][<target|targetsync>, ...] :] interop-obj-list)  */
    2455              : 
    2456              : static match
    2457          108 : gfc_match_omp_init (gfc_omp_namelist **list)
    2458              : {
    2459          108 :   bool target, targetsync;
    2460          108 :   char *type_str = NULL;
    2461          108 :   int type_str_len;
    2462          108 :   if (gfc_parser_omp_clause_init_modifiers (target, targetsync, &type_str,
    2463              :                                             type_str_len, true) == MATCH_ERROR)
    2464              :     return MATCH_ERROR;
    2465              : 
    2466           64 :   gfc_omp_namelist **head = NULL;
    2467           64 :   if (gfc_match_omp_variable_list ("", list, false, NULL, &head) != MATCH_YES)
    2468              :     return MATCH_ERROR;
    2469          147 :   for (gfc_omp_namelist *n = *head; n; n = n->next)
    2470              :     {
    2471           84 :       n->u.init.target = target;
    2472           84 :       n->u.init.targetsync = targetsync;
    2473           84 :       n->u.init.len = type_str_len;
    2474           84 :       n->u2.init_interop = type_str;
    2475              :     }
    2476              :   return MATCH_YES;
    2477              : }
    2478              : 
    2479              : /* Match boolean-type clause with duplicate check. Matches 'name' then matches
    2480              :    an optional '(const-logical-expr)'; already_set is used for the duplicate
    2481              :    check.  If the clause is not matched NO is returned, if an error occurs ERROR
    2482              :    and otherwise YES.  In the no-error case RES contains the value of the
    2483              :    expression or true if no expression exists.
    2484              :    If FALSE_OK, 'false' implies an absent clause, which can be repeated without
    2485              :    printing an error; that is the case for clause groups.
    2486              :    If DUPL_MSG is nonnull, the string is used as error message and must contain
    2487              :    %qs and %L in that order.  */
    2488              : 
    2489              : static match
    2490         3748 : gfc_match_boolean_clause (bool *res, const char *name, bool already_set,
    2491              :                           bool false_ok = false, const char *dupl_msg = NULL)
    2492              : {
    2493         3748 :   gfc_expr *expr = NULL;
    2494         3748 :   match m;
    2495         3748 :   char c;
    2496         3748 :   locus old_loc = gfc_current_locus;
    2497         3748 :   locus old_loc2;
    2498         3748 :   if ((m = gfc_match (name)) != MATCH_YES)
    2499              :     return m;
    2500              :   /* Ensure that no partial string is matched.  */
    2501         2506 :   if (gfc_current_form == FORM_FREE
    2502         2506 :       && gfc_match_eos () != MATCH_YES
    2503         3254 :       && ((c = gfc_peek_ascii_char ()) == '_' || ISALNUM (c)))
    2504              :     {
    2505            1 :       gfc_current_locus = old_loc;
    2506            1 :       return MATCH_NO;
    2507              :     }
    2508         2505 :   if (already_set && !false_ok)
    2509           22 :     goto dupl;
    2510         2483 :   if (gfc_match (" (") == MATCH_NO)
    2511              :     {
    2512         2289 :       if (already_set)
    2513            3 :         goto dupl;
    2514         2286 :       *res = true;  /* Implicit boolean true.  */
    2515         2286 :       return MATCH_YES;
    2516              :     }
    2517          194 :   old_loc2 = gfc_current_locus;
    2518          194 :   m = gfc_match_expr (&expr);
    2519          194 :   if (m != MATCH_YES
    2520          193 :       || gfc_match (" )") != MATCH_YES
    2521          188 :       || !gfc_resolve_expr (expr)
    2522          188 :       || expr->rank != 0
    2523          187 :       || expr->expr_type != EXPR_CONSTANT
    2524          379 :       || expr->ts.type != BT_LOGICAL)
    2525              :     {
    2526           13 :       gfc_free_expr (expr);
    2527           13 :       gfc_error ("Expected %<( const-logical-expr )%> at %L", &old_loc2);
    2528           13 :       return MATCH_ERROR;
    2529              :     }
    2530          181 :   if (already_set && expr->value.logical)
    2531            4 :     goto dupl;
    2532          177 :   *res = expr->value.logical;
    2533          177 :   gfc_free_expr (expr);
    2534          177 :   return MATCH_YES;
    2535              : 
    2536           29 : dupl:
    2537           29 :   if (dupl_msg)
    2538           12 :     gfc_error (dupl_msg, name, &old_loc);
    2539              :   else
    2540           17 :     gfc_error ("Duplicated %qs clause at %L", name, &old_loc);
    2541              :   return MATCH_ERROR;
    2542              : }
    2543              : 
    2544              : 
    2545              : /* Match a clause from the atomic clauses set.  */
    2546              : 
    2547              : static match
    2548         1231 : gfc_match_dupl_atomic (bool *res, const char *name, bool already_set)
    2549              : {
    2550         1231 :   const char *msg = G_("Duplicated atomic clause: unexpected %qs clause at %L");
    2551            0 :   return gfc_match_boolean_clause (res, name, already_set, true, msg);
    2552              : }
    2553              : 
    2554              : 
    2555              : /* Match a clause from the memory-order clauses set.  */
    2556              : 
    2557              : static match
    2558          451 : gfc_match_dupl_memorder (bool *res, const char *name, bool already_set)
    2559              : {
    2560          451 :   const char *msg = G_("Duplicated memory-order clause: unexpected %qs clause "
    2561              :                        "at %L");
    2562            0 :   return gfc_match_boolean_clause (res, name, already_set, true, msg);
    2563              : }
    2564              : 
    2565              : 
    2566              : /* Match a clause from the branch clauses set; interestingly, here
    2567              :    inbranch(false) branch(false/true) is not permitted!  */
    2568              : 
    2569              : static match
    2570           62 : gfc_match_dupl_branch_clause (bool *res, const char *name, bool already_set)
    2571              : {
    2572           62 :   const char *msg = G_("Duplicated branch clause: unexpected %qs clause "
    2573              :                        "at %L");
    2574           62 :   return gfc_match_boolean_clause (res, name, already_set, false, msg);
    2575              : }
    2576              : 
    2577              : 
    2578              : /* Match with duplicate check. Matches 'name'. If expr != NULL, it
    2579              :    then matches '(expr)', otherwise, if open_parens is true,
    2580              :    it matches a ' ( ' after 'name'.  */
    2581              : 
    2582              : static match
    2583        20800 : gfc_match_dupl_check (bool not_dupl, const char *name, bool open_parens = false,
    2584              :                       gfc_expr **expr = NULL)
    2585              : {
    2586        20800 :   match m;
    2587        20800 :   char c;
    2588        20800 :   locus old_loc = gfc_current_locus;
    2589        20800 :   if ((m = gfc_match (name)) != MATCH_YES)
    2590              :     return m;
    2591              :   /* Ensure that no partial string is matched.  */
    2592        16301 :   if (gfc_current_form == FORM_FREE
    2593        15803 :       && gfc_match_eos () != MATCH_YES
    2594        29640 :       && ((c = gfc_peek_ascii_char ()) == '_' || ISALNUM (c)))
    2595              :     {
    2596           12 :       gfc_current_locus = old_loc;
    2597           12 :       return MATCH_NO;
    2598              :     }
    2599        16289 :   if (!not_dupl)
    2600              :     {
    2601           46 :       gfc_error ("Duplicated %qs clause at %L", name, &old_loc);
    2602           46 :       return MATCH_ERROR;
    2603              :     }
    2604        16243 :   if (open_parens || expr)
    2605              :     {
    2606        10444 :       if (gfc_match (" ( ") != MATCH_YES)
    2607              :         {
    2608           25 :           gfc_error ("Expected %<(%> after %qs at %C", name);
    2609           25 :           return MATCH_ERROR;
    2610              :         }
    2611        10419 :       if (expr)
    2612              :         {
    2613         3423 :           if (gfc_match ("%e )", expr) != MATCH_YES)
    2614              :             {
    2615            9 :               gfc_error ("Invalid expression after %<%s(%> at %C", name);
    2616            9 :               return MATCH_ERROR;
    2617              :             }
    2618              :         }
    2619              :     }
    2620              :   return MATCH_YES;
    2621              : }
    2622              : 
    2623              : /* Search upwards though namespace NS and its parents to find an
    2624              :    !$omp declare mapper named MAPPER_ID, for typespec TS.  The default
    2625              :    mapper has mapper_id == "".  */
    2626              : 
    2627              : gfc_omp_udm *
    2628         1003 : gfc_find_omp_udm (gfc_namespace *ns, const char *mapper_id, gfc_typespec *ts)
    2629              : {
    2630         1003 :   gfc_symtree *st;
    2631              : 
    2632         1003 :   if (ns == NULL)
    2633            0 :     ns = gfc_current_ns;
    2634              : 
    2635         1182 :   do
    2636              :     {
    2637         1182 :       gfc_omp_udm *omp_udm;
    2638              : 
    2639         1182 :       st = gfc_find_symtree (ns->omp_udm_root, mapper_id);
    2640              : 
    2641         1182 :       if (st != NULL)
    2642              :         {
    2643           29 :           for (omp_udm = st->n.omp_udm; omp_udm; omp_udm = omp_udm->next)
    2644           29 :             if (gfc_compare_types (&omp_udm->ts, ts))
    2645              :               return omp_udm;
    2646              :         }
    2647              : 
    2648              :       /* Don't escape an interface block.  */
    2649         1155 :       if (ns && !ns->has_import_set
    2650         1155 :           && ns->proc_name && ns->proc_name->attr.if_source == IFSRC_IFBODY)
    2651              :         break;
    2652              : 
    2653         1155 :       ns = ns->parent;
    2654              :     }
    2655         1155 :   while (ns != NULL);
    2656              : 
    2657              :   return NULL;
    2658              : }
    2659              : 
    2660              : 
    2661              : /* Match OpenMP and OpenACC directive clauses. MASK is a bitmask of
    2662              :    clauses that are allowed for a particular directive.  */
    2663              : 
    2664              : static match
    2665        35644 : gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
    2666              :                        bool first_no_comma = true, bool needs_space = true,
    2667              :                        bool openacc = false, bool openmp_target = false,
    2668              :                        gfc_omp_map_op default_map_op = OMP_MAP_TOFROM)
    2669              : {
    2670        35644 :   bool error = false;
    2671        35644 :   bool bval;
    2672        35644 :   gfc_omp_clauses *c = gfc_get_omp_clauses ();
    2673        35644 :   gfc_omp_clauses *cfalse = openacc ? NULL : gfc_get_omp_clauses ();
    2674        21776 :   locus old_loc;
    2675              :   /* Determine whether we're dealing with an OpenACC directive that permits
    2676              :      derived type member accesses.  This in particular disallows
    2677              :      "!$acc declare" from using such accesses, because it's not clear if/how
    2678              :      that should work.  */
    2679        21776 :   bool allow_derived = (openacc
    2680        13868 :                         && ((mask & OMP_CLAUSE_ATTACH)
    2681         6326 :                             || (mask & OMP_CLAUSE_DETACH)));
    2682              : 
    2683        35644 :   gcc_checking_assert (OMP_MASK1_LAST <= 64 && OMP_MASK2_LAST <= 64);
    2684        35644 :   *cp = NULL;
    2685       130786 :   while (1)
    2686              :     {
    2687        83215 :       match m = MATCH_NO;
    2688        83122 :       if ((first_no_comma || (m = gfc_match_char (',')) != MATCH_YES)
    2689       165892 :           && (needs_space && gfc_match_space () != MATCH_YES))
    2690              :         break;
    2691        78601 :       needs_space = false;
    2692        78601 :       first_no_comma = false;
    2693        78601 :       gfc_gobble_whitespace ();
    2694        78601 :       bool end_colon;
    2695        78601 :       gfc_omp_namelist **head;
    2696        78601 :       old_loc = gfc_current_locus;
    2697        78601 :       char pc = gfc_peek_ascii_char ();
    2698        78601 :       if (pc == '\n' && m == MATCH_YES)
    2699              :         {
    2700            1 :           gfc_error ("Clause expected at %C after trailing comma");
    2701            1 :           goto error;
    2702              :         }
    2703        78600 :       switch (pc)
    2704              :         {
    2705         1339 :         case 'a':
    2706         1339 :           end_colon = false;
    2707         1339 :           head = NULL;
    2708         1364 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    2709         1339 :               && gfc_match ("absent ( ") == MATCH_YES)
    2710              :             {
    2711           28 :               if (gfc_omp_absent_contains_clause (&c->assume, true)
    2712              :                   != MATCH_YES)
    2713            3 :                 goto error;
    2714           25 :               continue;
    2715              :             }
    2716         1311 :           if ((mask & OMP_CLAUSE_ALIGNED)
    2717         1311 :               && gfc_match_omp_variable_list ("aligned (",
    2718              :                                               &c->lists[OMP_LIST_ALIGNED],
    2719              :                                               false, &end_colon,
    2720              :                                               &head) == MATCH_YES)
    2721              :             {
    2722          112 :               gfc_expr *alignment = NULL;
    2723          112 :               gfc_omp_namelist *n;
    2724              : 
    2725          112 :               if (end_colon && gfc_match (" %e )", &alignment) != MATCH_YES)
    2726              :                 {
    2727            0 :                   gfc_free_omp_namelist (*head, OMP_LIST_ALIGNED);
    2728            0 :                   gfc_current_locus = old_loc;
    2729            0 :                   *head = NULL;
    2730            0 :                   break;
    2731              :                 }
    2732          268 :               for (n = *head; n; n = n->next)
    2733          156 :                 if (n->next && alignment)
    2734           42 :                   n->expr = gfc_copy_expr (alignment);
    2735              :                 else
    2736          114 :                   n->expr = alignment;
    2737          112 :               continue;
    2738          112 :             }
    2739         1218 :           if ((mask & OMP_CLAUSE_MEMORDER)
    2740         1234 :               && (m = gfc_match_dupl_memorder (&bval, "acq_rel",
    2741           35 :                         c->memorder != OMP_MEMORDER_UNSET)) != MATCH_NO)
    2742              :             {
    2743           19 :               if (m == MATCH_ERROR)
    2744            0 :                 goto error;
    2745           19 :               if (bval)
    2746           12 :                 c->memorder = OMP_MEMORDER_ACQ_REL;
    2747           19 :               continue;
    2748              :             }
    2749         1196 :           if ((mask & OMP_CLAUSE_MEMORDER)
    2750         1196 :               && (m = gfc_match_dupl_memorder (&bval, "acquire",
    2751           16 :                         c->memorder != OMP_MEMORDER_UNSET)) != MATCH_NO)
    2752              :             {
    2753           16 :               if (m == MATCH_ERROR)
    2754            0 :                 goto error;
    2755           16 :               if (bval)
    2756            9 :                 c->memorder = OMP_MEMORDER_ACQUIRE;
    2757           16 :               continue;
    2758              :             }
    2759         1164 :           if ((mask & OMP_CLAUSE_AFFINITY)
    2760         1164 :               && gfc_match ("affinity ( ") == MATCH_YES)
    2761              :             {
    2762           41 :               gfc_namespace *ns_iter = NULL, *ns_curr = gfc_current_ns;
    2763           41 :               m = gfc_match_iterator (&ns_iter, true);
    2764           41 :               if (m == MATCH_ERROR)
    2765              :                 break;
    2766           31 :               if (m == MATCH_YES && gfc_match (" : ") != MATCH_YES)
    2767              :                 {
    2768            1 :                   gfc_error ("Expected %<:%> at %C");
    2769            1 :                   break;
    2770              :                 }
    2771           30 :               if (ns_iter)
    2772           18 :                 gfc_current_ns = ns_iter;
    2773           30 :               head = NULL;
    2774           30 :               m = gfc_match_omp_variable_list ("", &c->lists[OMP_LIST_AFFINITY],
    2775              :                                                false, NULL, &head, true);
    2776           30 :               gfc_current_ns = ns_curr;
    2777           30 :               if (m == MATCH_ERROR)
    2778              :                 break;
    2779           27 :               if (ns_iter)
    2780              :                 {
    2781           45 :                   for (gfc_omp_namelist *n = *head; n; n = n->next)
    2782              :                     {
    2783           27 :                       n->u2.ns = ns_iter;
    2784           27 :                       ns_iter->refs++;
    2785              :                     }
    2786              :                 }
    2787           27 :               continue;
    2788           27 :             }
    2789         1123 :           if ((mask & OMP_CLAUSE_ALLOCATE)
    2790         1123 :               && gfc_match ("allocate ( ") == MATCH_YES)
    2791              :             {
    2792          281 :               gfc_expr *allocator = NULL;
    2793          281 :               gfc_expr *align = NULL;
    2794          281 :               old_loc = gfc_current_locus;
    2795          281 :               if ((m = gfc_match ("allocator ( %e )", &allocator)) == MATCH_YES)
    2796           50 :                 gfc_match (" , align ( %e )", &align);
    2797          231 :               else if ((m = gfc_match ("align ( %e )", &align)) == MATCH_YES)
    2798           29 :                 gfc_match (" , allocator ( %e )", &allocator);
    2799              : 
    2800           79 :               if (m == MATCH_YES)
    2801              :                 {
    2802           79 :                   if (gfc_match (" : ") != MATCH_YES)
    2803              :                     {
    2804            5 :                       gfc_error ("Expected %<:%> at %C");
    2805            8 :                       goto error;
    2806              :                     }
    2807              :                 }
    2808              :               else
    2809              :                 {
    2810          202 :                   m = gfc_match_expr (&allocator);
    2811          202 :                   if (m == MATCH_YES && gfc_match (" : ") != MATCH_YES)
    2812              :                     {
    2813              :                        /* If no ":" then there is no allocator, we backtrack
    2814              :                           and read the variable list.  */
    2815          101 :                       gfc_free_expr (allocator);
    2816          101 :                       allocator = NULL;
    2817          101 :                       gfc_current_locus = old_loc;
    2818              :                     }
    2819              :                 }
    2820          276 :               gfc_omp_namelist **head = NULL;
    2821          276 :               m = gfc_match_omp_variable_list ("", &c->lists[OMP_LIST_ALLOCATE],
    2822              :                                                true, NULL, &head);
    2823              : 
    2824          276 :               if (m != MATCH_YES)
    2825              :                 {
    2826            3 :                   gfc_free_expr (allocator);
    2827            3 :                   gfc_free_expr (align);
    2828            3 :                   gfc_error ("Expected variable list at %C");
    2829            3 :                   goto error;
    2830              :                 }
    2831              : 
    2832          729 :               for (gfc_omp_namelist *n = *head; n; n = n->next)
    2833              :                 {
    2834          456 :                   n->u2.allocator = allocator;
    2835          456 :                   n->u.align = (align) ? gfc_copy_expr (align) : NULL;
    2836              :                 }
    2837          273 :               gfc_free_expr (align);
    2838          273 :               continue;
    2839          273 :             }
    2840          905 :           if ((mask & OMP_CLAUSE_AT)
    2841          842 :               && (m = gfc_match_dupl_check (c->at == OMP_AT_UNSET, "at", true))
    2842              :                  != MATCH_NO)
    2843              :             {
    2844           69 :               if (m == MATCH_ERROR)
    2845            2 :                 goto error;
    2846           67 :               if (gfc_match ("compilation )") == MATCH_YES)
    2847           15 :                 c->at = OMP_AT_COMPILATION;
    2848           52 :               else if (gfc_match ("execution )") == MATCH_YES)
    2849           48 :                 c->at = OMP_AT_EXECUTION;
    2850              :               else
    2851              :                 {
    2852            4 :                   gfc_error ("Expected COMPILATION or EXECUTION in AT clause "
    2853              :                              "at %C");
    2854            4 :                   goto error;
    2855              :                 }
    2856           63 :               continue;
    2857              :             }
    2858         1416 :           if ((mask & OMP_CLAUSE_ASYNC)
    2859          773 :               && (m = gfc_match_dupl_check (!c->async, "async")) != MATCH_NO)
    2860              :             {
    2861          643 :               if (m == MATCH_ERROR)
    2862            0 :                 goto error;
    2863          643 :               c->async = true;
    2864          643 :               m = gfc_match (" ( %e )", &c->async_expr);
    2865          643 :               if (m == MATCH_ERROR)
    2866              :                 {
    2867            0 :                   gfc_current_locus = old_loc;
    2868            0 :                   break;
    2869              :                 }
    2870          643 :               else if (m == MATCH_NO)
    2871              :                 {
    2872          133 :                   c->async_expr
    2873          133 :                     = gfc_get_constant_expr (BT_INTEGER,
    2874              :                                              gfc_default_integer_kind,
    2875              :                                              &gfc_current_locus);
    2876          133 :                   mpz_set_si (c->async_expr->value.integer, GOMP_ASYNC_NOVAL);
    2877              :                 }
    2878          643 :               continue;
    2879              :             }
    2880          193 :           if ((mask & OMP_CLAUSE_AUTO)
    2881          130 :               && (m = gfc_match_dupl_check (!c->par_auto, "auto"))
    2882              :                  != MATCH_NO)
    2883              :             {
    2884           63 :               if (m == MATCH_ERROR)
    2885            0 :                 goto error;
    2886           63 :               c->par_auto = true;
    2887           63 :               continue;
    2888              :             }
    2889          128 :           if ((mask & OMP_CLAUSE_ATTACH)
    2890           62 :               && gfc_match ("attach ( ") == MATCH_YES
    2891          128 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    2892              :                                            OMP_MAP_ATTACH, false,
    2893              :                                            allow_derived))
    2894           61 :             continue;
    2895              :           break;
    2896           37 :         case 'b':
    2897           72 :           if ((mask & OMP_CLAUSE_BIND)
    2898           37 :               && (m = gfc_match_dupl_check (c->bind == OMP_BIND_UNSET, "bind",
    2899              :                                             true)) != MATCH_NO)
    2900              :             {
    2901           37 :               if (m == MATCH_ERROR)
    2902            1 :                 goto error;
    2903           36 :               if (gfc_match ("teams )") == MATCH_YES)
    2904           11 :                 c->bind = OMP_BIND_TEAMS;
    2905           25 :               else if (gfc_match ("parallel )") == MATCH_YES)
    2906           15 :                 c->bind = OMP_BIND_PARALLEL;
    2907           10 :               else if (gfc_match ("thread )") == MATCH_YES)
    2908            9 :                 c->bind = OMP_BIND_THREAD;
    2909              :               else
    2910              :                 {
    2911            1 :                   gfc_error ("Expected TEAMS, PARALLEL or THREAD as binding in "
    2912              :                              "BIND at %C");
    2913            1 :                   break;
    2914              :                 }
    2915           35 :               continue;
    2916              :             }
    2917              :           break;
    2918         7230 :         case 'c':
    2919         7506 :           if ((mask & OMP_CLAUSE_CAPTURE)
    2920         7678 :               && (m = gfc_match_boolean_clause (&bval, "capture",
    2921          448 :                          c->capture || cfalse->capture)) != MATCH_NO)
    2922              :             {
    2923          277 :               if (m == MATCH_ERROR)
    2924            1 :                 goto error;
    2925          276 :               if (bval)
    2926          273 :                 c->capture = true;
    2927              :               else
    2928            3 :                 cfalse->capture = true;
    2929          276 :               continue;
    2930              :             }
    2931         6953 :           if (mask & OMP_CLAUSE_COLLAPSE)
    2932              :             {
    2933         2103 :               gfc_expr *cexpr = NULL;
    2934         2103 :               if ((m = gfc_match_dupl_check (!c->collapse, "collapse", true,
    2935              :                                              &cexpr)) != MATCH_NO)
    2936              :               {
    2937         1613 :                 int collapse;
    2938         1613 :                 if (m == MATCH_ERROR)
    2939            0 :                   goto error;
    2940         1613 :                 if (gfc_extract_int (cexpr, &collapse, -1))
    2941            4 :                   collapse = 1;
    2942         1609 :                 else if (collapse <= 0)
    2943              :                   {
    2944            8 :                     gfc_error_now ("COLLAPSE clause argument not constant "
    2945              :                                    "positive integer at %C");
    2946            8 :                     collapse = 1;
    2947              :                   }
    2948         1613 :                 gfc_free_expr (cexpr);
    2949         1613 :                 c->collapse = collapse;
    2950         1613 :                 continue;
    2951         1613 :               }
    2952              :             }
    2953         5510 :           if ((mask & OMP_CLAUSE_COMPARE)
    2954         5511 :               && (m = gfc_match_boolean_clause (&bval, "compare",
    2955          171 :                          c->compare || cfalse->compare)) != MATCH_NO)
    2956              :             {
    2957          171 :               if (m == MATCH_ERROR)
    2958            1 :                 goto error;
    2959          170 :               if (bval)
    2960          167 :                 c->compare = true;
    2961              :               else
    2962            3 :                 cfalse->compare = true;
    2963          170 :               continue;
    2964              :             }
    2965         5182 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    2966         5169 :               && gfc_match ("contains ( ") == MATCH_YES)
    2967              :             {
    2968           19 :               if (gfc_omp_absent_contains_clause (&c->assume, false)
    2969              :                   != MATCH_YES)
    2970            6 :                 goto error;
    2971           13 :               continue;
    2972              :             }
    2973         7266 :           if ((mask & OMP_CLAUSE_COPY)
    2974         3723 :               && gfc_match ("copy ( ") == MATCH_YES
    2975         7267 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    2976              :                                            OMP_MAP_TOFROM, true,
    2977              :                                            allow_derived))
    2978         2116 :             continue;
    2979         3034 :           if (mask & OMP_CLAUSE_COPYIN)
    2980              :             {
    2981         2628 :               if (openacc)
    2982              :                 {
    2983         2529 :                   if (gfc_match ("copyin ( ") == MATCH_YES)
    2984              :                     {
    2985         1458 :                       bool readonly = gfc_match ("readonly : ") == MATCH_YES;
    2986         1458 :                       head = NULL;
    2987         1458 :                       if (gfc_match_omp_variable_list ("",
    2988              :                                                        &c->lists[OMP_LIST_MAP],
    2989              :                                                        true, NULL, &head, true,
    2990              :                                                        allow_derived)
    2991              :                           == MATCH_YES)
    2992              :                         {
    2993         1452 :                           gfc_omp_namelist *n;
    2994         3349 :                           for (n = *head; n; n = n->next)
    2995              :                             {
    2996         1897 :                               n->u.map.op = OMP_MAP_TO;
    2997         1897 :                               n->u.map.readonly = readonly;
    2998              :                             }
    2999         1452 :                           continue;
    3000         1452 :                         }
    3001              :                     }
    3002              :                 }
    3003           99 :               else if (gfc_match_omp_variable_list ("copyin (",
    3004              :                                                     &c->lists[OMP_LIST_COPYIN],
    3005              :                                                     true) == MATCH_YES)
    3006           97 :                 continue;
    3007              :             }
    3008         2556 :           if ((mask & OMP_CLAUSE_COPYOUT)
    3009         1216 :               && gfc_match ("copyout ( ") == MATCH_YES
    3010         2556 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3011              :                                            OMP_MAP_FROM, true, allow_derived))
    3012         1071 :             continue;
    3013          498 :           if ((mask & OMP_CLAUSE_COPYPRIVATE)
    3014          414 :               && gfc_match_omp_variable_list ("copyprivate (",
    3015              :                                               &c->lists[OMP_LIST_COPYPRIVATE],
    3016              :                                               true) == MATCH_YES)
    3017           84 :             continue;
    3018          651 :           if ((mask & OMP_CLAUSE_CREATE)
    3019          328 :               && gfc_match ("create ( ") == MATCH_YES
    3020          651 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3021              :                                            OMP_MAP_ALLOC, true, allow_derived))
    3022          321 :             continue;
    3023              :           break;
    3024         4274 :         case 'd':
    3025         4274 :           if ((mask & OMP_CLAUSE_DEFAULTMAP)
    3026         4274 :               && gfc_match ("defaultmap ( ") == MATCH_YES)
    3027              :             {
    3028          218 :               enum gfc_omp_defaultmap behavior;
    3029          218 :               gfc_omp_defaultmap_category category
    3030              :                 = OMP_DEFAULTMAP_CAT_UNCATEGORIZED;
    3031          218 :               bool optional = false;
    3032          218 :               if (gfc_match ("alloc ") == MATCH_YES)
    3033              :                 behavior = OMP_DEFAULTMAP_ALLOC;
    3034          206 :               else if (gfc_match ("tofrom ") == MATCH_YES)
    3035              :                 behavior = OMP_DEFAULTMAP_TOFROM;
    3036          162 :               else if (gfc_match ("to ") == MATCH_YES)
    3037              :                 behavior = OMP_DEFAULTMAP_TO;
    3038          151 :               else if (gfc_match ("from ") == MATCH_YES)
    3039              :                 behavior = OMP_DEFAULTMAP_FROM;
    3040          142 :               else if (gfc_match ("firstprivate ") == MATCH_YES)
    3041              :                 behavior = OMP_DEFAULTMAP_FIRSTPRIVATE;
    3042          101 :               else if (gfc_match ("present ") == MATCH_YES)
    3043              :                 behavior = OMP_DEFAULTMAP_PRESENT;
    3044           91 :               else if (gfc_match ("none ") == MATCH_YES)
    3045              :                 behavior = OMP_DEFAULTMAP_NONE;
    3046           10 :               else if (gfc_match ("default ") == MATCH_YES)
    3047              :                 behavior = OMP_DEFAULTMAP_DEFAULT;
    3048              :               else
    3049              :                 {
    3050            1 :                   gfc_error ("Expected ALLOC, TO, FROM, TOFROM, FIRSTPRIVATE, "
    3051              :                              "PRESENT, NONE or DEFAULT at %C");
    3052            1 :                   goto error;
    3053              :                 }
    3054          217 :               if (')' == gfc_peek_ascii_char ())
    3055              :                 ;
    3056          139 :               else if (gfc_match (": ") != MATCH_YES)
    3057              :                 {
    3058            1 :                   gfc_error ("Expected %<)%> or %<:%> at %C");
    3059            1 :                   goto error;
    3060              :                 }
    3061              :               else
    3062              :                 {
    3063          138 :                   if (gfc_match ("optional ") == MATCH_YES)
    3064              :                     {
    3065            7 :                       optional = true;
    3066            7 :                       if (')' == gfc_peek_ascii_char ())
    3067              :                         category = OMP_DEFAULTMAP_CAT_ALL;
    3068            5 :                       else if (gfc_match (", ") != MATCH_YES)
    3069              :                         {
    3070            1 :                           gfc_error ("Expected %<)%> or %<,%> at %C");
    3071            1 :                           goto error;
    3072              :                         }
    3073              :                     }
    3074              :                   if (category == OMP_DEFAULTMAP_CAT_ALL)
    3075              :                     ;
    3076          135 :                   else if (gfc_match ("scalar ") == MATCH_YES)
    3077              :                     category = OMP_DEFAULTMAP_CAT_SCALAR;
    3078           88 :                   else if (gfc_match ("aggregate ") == MATCH_YES)
    3079              :                     category = OMP_DEFAULTMAP_CAT_AGGREGATE;
    3080           56 :                   else if (gfc_match ("allocatable ") == MATCH_YES)
    3081              :                     category = OMP_DEFAULTMAP_CAT_ALLOCATABLE;
    3082           40 :                   else if (gfc_match ("pointer ") == MATCH_YES)
    3083              :                     category = OMP_DEFAULTMAP_CAT_POINTER;
    3084           18 :                   else if (gfc_match ("all ") == MATCH_YES)
    3085              :                     category = OMP_DEFAULTMAP_CAT_ALL;
    3086              :                   else
    3087              :                     {
    3088            4 :                       if (!optional)
    3089            2 :                         gfc_error ("Expected SCALAR, AGGREGATE, ALLOCATABLE, "
    3090              :                                    "POINTER, ALL, or OPTIONAL at %C");
    3091              :                       else
    3092            2 :                         gfc_error ("Expected SCALAR, AGGREGATE, ALLOCATABLE, "
    3093              :                                    "POINTER, or ALL at %C");
    3094            4 :                       goto error;
    3095              :                     }
    3096          133 :                   if (!optional && gfc_match (", ") == MATCH_YES)
    3097              :                     {
    3098            3 :                       if (gfc_match ("optional ") == MATCH_YES)
    3099              :                         optional = true;
    3100              :                       else
    3101              :                         {
    3102            1 :                           gfc_error ("Expected OPTIONAL at %C");
    3103            1 :                           goto error;
    3104              :                         }
    3105              :                     }
    3106              :                 }
    3107         1417 :               for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; ++i)
    3108              :                 {
    3109         1220 :                   if (i != category
    3110         1220 :                       && category != OMP_DEFAULTMAP_CAT_UNCATEGORIZED
    3111          641 :                       && category != OMP_DEFAULTMAP_CAT_ALL
    3112          641 :                       && i != OMP_DEFAULTMAP_CAT_UNCATEGORIZED
    3113          453 :                       && i != OMP_DEFAULTMAP_CAT_ALL)
    3114          338 :                     continue;
    3115          882 :                   if (c->defaultmap[i] != OMP_DEFAULTMAP_UNSET)
    3116              :                     {
    3117           13 :                       const char *pcategory = NULL;
    3118           13 :                       switch (i)
    3119              :                         {
    3120              :                         case OMP_DEFAULTMAP_CAT_UNCATEGORIZED: break;
    3121            3 :                         case OMP_DEFAULTMAP_CAT_ALL: pcategory = "ALL"; break;
    3122            1 :                         case OMP_DEFAULTMAP_CAT_SCALAR: pcategory = "SCALAR"; break;
    3123            2 :                         case OMP_DEFAULTMAP_CAT_AGGREGATE:
    3124            2 :                           pcategory = "AGGREGATE";
    3125            2 :                           break;
    3126            1 :                         case OMP_DEFAULTMAP_CAT_ALLOCATABLE:
    3127            1 :                           pcategory = "ALLOCATABLE";
    3128            1 :                           break;
    3129              :                         case OMP_DEFAULTMAP_CAT_POINTER:
    3130              :                           pcategory = "POINTER";
    3131              :                           break;
    3132            0 :                         default: gcc_unreachable ();
    3133              :                         }
    3134            7 :                      if (i == OMP_DEFAULTMAP_CAT_UNCATEGORIZED)
    3135            4 :                       gfc_error ("DEFAULTMAP at %C but prior DEFAULTMAP with "
    3136              :                                  "unspecified category");
    3137              :                      else
    3138            9 :                       gfc_error ("DEFAULTMAP at %C but prior DEFAULTMAP for "
    3139              :                                  "category %s", pcategory);
    3140           13 :                      goto error;
    3141              :                     }
    3142              :                 }
    3143          197 :               c->defaultmap[category] = behavior;
    3144          197 :               if (gfc_match (")") != MATCH_YES)
    3145              :                 {
    3146            1 :                   gfc_error ("Expected %<)%> at %C");
    3147            1 :                   goto error;
    3148              :                 }
    3149          196 :               if (optional)
    3150            6 :                 sorry_at (gfc_get_location (&gfc_current_locus),
    3151              :                            "%<optional%> modifier is not supported yet");
    3152          196 :               continue;
    3153          196 :             }
    3154         5029 :           if ((mask & OMP_CLAUSE_DEFAULT)
    3155         4056 :               && (m = gfc_match_dupl_check (c->default_sharing
    3156              :                                             == OMP_DEFAULT_UNKNOWN, "default",
    3157              :                                             true)) != MATCH_NO)
    3158              :             {
    3159         1018 :               if (m == MATCH_ERROR)
    3160            6 :                 goto error;
    3161         1012 :               if (gfc_match ("none") == MATCH_YES)
    3162          602 :                 c->default_sharing = OMP_DEFAULT_NONE;
    3163          410 :               else if (openacc)
    3164              :                 {
    3165          225 :                   if (gfc_match ("present") == MATCH_YES)
    3166          195 :                     c->default_sharing = OMP_DEFAULT_PRESENT;
    3167              :                 }
    3168              :               else
    3169              :                 {
    3170          185 :                   if (gfc_match ("firstprivate") == MATCH_YES)
    3171            8 :                     c->default_sharing = OMP_DEFAULT_FIRSTPRIVATE;
    3172          177 :                   else if (gfc_match ("private") == MATCH_YES)
    3173           24 :                     c->default_sharing = OMP_DEFAULT_PRIVATE;
    3174          153 :                   else if (gfc_match ("shared") == MATCH_YES)
    3175          153 :                     c->default_sharing = OMP_DEFAULT_SHARED;
    3176              :                 }
    3177         1012 :               if (c->default_sharing == OMP_DEFAULT_UNKNOWN)
    3178              :                 {
    3179           30 :                   if (openacc)
    3180           30 :                     gfc_error ("Expected NONE or PRESENT in DEFAULT clause "
    3181              :                                "at %C");
    3182              :                   else
    3183            0 :                     gfc_error ("Expected NONE, FIRSTPRIVATE, PRIVATE or SHARED "
    3184              :                                "in DEFAULT clause at %C");
    3185           30 :                   goto error;
    3186              :                 }
    3187          982 :               if (gfc_match (" )") != MATCH_YES)
    3188            9 :                 goto error;
    3189          973 :               continue;
    3190              :             }
    3191         3346 :           if ((mask & OMP_CLAUSE_DELETE)
    3192          345 :               && gfc_match ("delete ( ") == MATCH_YES
    3193         3346 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3194              :                                            OMP_MAP_RELEASE, true,
    3195              :                                            allow_derived))
    3196          308 :             continue;
    3197              :           /* DOACROSS: match 'doacross' and 'depend' with sink/source.
    3198              :              DEPEND: match 'depend' but not sink/source.  */
    3199         2730 :           m = MATCH_NO;
    3200         2730 :           if (((mask & OMP_CLAUSE_DOACROSS)
    3201          383 :                && gfc_match ("doacross ( ") == MATCH_YES)
    3202         3086 :               || (((mask & OMP_CLAUSE_DEPEND) || (mask & OMP_CLAUSE_DOACROSS))
    3203         1629 :                   && (m = gfc_match ("depend ( ")) == MATCH_YES))
    3204              :             {
    3205         1101 :               bool has_omp_all_memory;
    3206         1101 :               bool is_depend = m == MATCH_YES;
    3207         1101 :               gfc_namespace *ns_iter = NULL, *ns_curr = gfc_current_ns;
    3208         1101 :               match m_it = MATCH_NO;
    3209         1101 :               if (is_depend)
    3210         1074 :                 m_it = gfc_match_iterator (&ns_iter, false);
    3211         1074 :               if (m_it == MATCH_ERROR)
    3212              :                 break;
    3213         1096 :               if (m_it == MATCH_YES && gfc_match (" , ") != MATCH_YES)
    3214              :                 break;
    3215         1096 :               m = MATCH_YES;
    3216         1096 :               gfc_omp_depend_doacross_op depend_op = OMP_DEPEND_OUT;
    3217         1096 :               if (gfc_match ("inoutset") == MATCH_YES)
    3218              :                 depend_op = OMP_DEPEND_INOUTSET;
    3219         1084 :               else if (gfc_match ("inout") == MATCH_YES)
    3220              :                 depend_op = OMP_DEPEND_INOUT;
    3221          992 :               else if (gfc_match ("in") == MATCH_YES)
    3222              :                 depend_op = OMP_DEPEND_IN;
    3223          704 :               else if (gfc_match ("out") == MATCH_YES)
    3224              :                 depend_op = OMP_DEPEND_OUT;
    3225          442 :               else if (gfc_match ("mutexinoutset") == MATCH_YES)
    3226              :                 depend_op = OMP_DEPEND_MUTEXINOUTSET;
    3227          424 :               else if (gfc_match ("depobj") == MATCH_YES)
    3228              :                 depend_op = OMP_DEPEND_DEPOBJ;
    3229          387 :               else if (gfc_match ("source") == MATCH_YES)
    3230              :                 {
    3231          143 :                   if (m_it == MATCH_YES)
    3232              :                     {
    3233            1 :                       gfc_error ("ITERATOR may not be combined with SOURCE "
    3234              :                                  "at %C");
    3235           17 :                       goto error;
    3236              :                     }
    3237          142 :                   if (!(mask & OMP_CLAUSE_DOACROSS))
    3238              :                     {
    3239            1 :                       gfc_error ("SOURCE at %C not permitted as dependence-type"
    3240              :                                  " for this directive");
    3241            1 :                       goto error;
    3242              :                     }
    3243          141 :                   if (c->doacross_source)
    3244              :                     {
    3245            0 :                       gfc_error ("Duplicated clause with SOURCE dependence-type"
    3246              :                                  " at %C");
    3247            0 :                       goto error;
    3248              :                     }
    3249          141 :                   gfc_gobble_whitespace ();
    3250          141 :                   m = gfc_match (": ");
    3251          141 :                   if (m != MATCH_YES && !is_depend)
    3252              :                     {
    3253            1 :                       gfc_error ("Expected %<:%> at %C");
    3254            1 :                       goto error;
    3255              :                     }
    3256          140 :                   if (gfc_match (")") != MATCH_YES
    3257          146 :                       && !(m == MATCH_YES
    3258            6 :                            && gfc_match ("omp_cur_iteration )") == MATCH_YES))
    3259              :                     {
    3260            2 :                       gfc_error ("Expected %<)%> or %<omp_cur_iteration)%> "
    3261              :                                  "at %C");
    3262            2 :                       goto error;
    3263              :                     }
    3264          138 :                   if (is_depend)
    3265          130 :                     gfc_warning (OPT_Wdeprecated_openmp,
    3266              :                                  "%<source%> modifier with %<depend%> clause "
    3267              :                                  "at %L deprecated since OpenMP 5.2, use with "
    3268              :                                  "%<doacross%>", &old_loc);
    3269          138 :                   c->doacross_source = true;
    3270          138 :                   c->depend_source = is_depend;
    3271         1079 :                   continue;
    3272              :                 }
    3273          244 :               else if (gfc_match ("sink ") == MATCH_YES)
    3274              :                 {
    3275          244 :                   if (!(mask & OMP_CLAUSE_DOACROSS))
    3276              :                     {
    3277            2 :                       gfc_error ("SINK at %C not permitted as dependence-type "
    3278              :                                  "for this directive");
    3279            2 :                       goto error;
    3280              :                     }
    3281          242 :                   if (gfc_match (": ") != MATCH_YES)
    3282              :                     {
    3283            1 :                       gfc_error ("Expected %<:%> at %C");
    3284            1 :                       goto error;
    3285              :                     }
    3286          241 :                   if (m_it == MATCH_YES)
    3287              :                     {
    3288            0 :                       gfc_error ("ITERATOR may not be combined with SINK "
    3289              :                                  "at %C");
    3290            0 :                       goto error;
    3291              :                     }
    3292          241 :                   if (is_depend)
    3293          226 :                     gfc_warning (OPT_Wdeprecated_openmp,
    3294              :                                  "%<sink%> modifier with %<depend%> clause at "
    3295              :                                  "%L deprecated since OpenMP 5.2, use with "
    3296              :                                  "%<doacross%>", &old_loc);
    3297          241 :                   m = gfc_match_omp_doacross_sink (&c->lists[OMP_LIST_DEPEND],
    3298              :                                                    is_depend);
    3299          241 :                   if (m == MATCH_YES)
    3300          238 :                     continue;
    3301            3 :                   goto error;
    3302              :                 }
    3303              :               else
    3304              :                 m = MATCH_NO;
    3305          709 :               if (!(mask & OMP_CLAUSE_DEPEND))
    3306              :                 {
    3307            0 :                   gfc_error ("Expected dependence-type SINK or SOURCE at %C");
    3308            0 :                   goto error;
    3309              :                 }
    3310          709 :               head = NULL;
    3311          709 :               if (ns_iter)
    3312           40 :                 gfc_current_ns = ns_iter;
    3313          709 :               if (m == MATCH_YES)
    3314          709 :                 m = gfc_match_omp_variable_list (" : ",
    3315              :                                                  &c->lists[OMP_LIST_DEPEND],
    3316              :                                                  false, NULL, &head, true,
    3317              :                                                  false, &has_omp_all_memory);
    3318          709 :               if (m != MATCH_YES)
    3319            2 :                 goto error;
    3320          707 :               gfc_current_ns = ns_curr;
    3321          707 :               if (has_omp_all_memory && depend_op != OMP_DEPEND_INOUT
    3322           21 :                   && depend_op != OMP_DEPEND_OUT)
    3323              :                 {
    3324            4 :                   gfc_error ("%<omp_all_memory%> used with DEPEND kind "
    3325              :                              "other than OUT or INOUT at %C");
    3326            4 :                   goto error;
    3327              :                 }
    3328          703 :               gfc_omp_namelist *n;
    3329         1437 :               for (n = *head; n; n = n->next)
    3330              :                 {
    3331          734 :                   n->u.depend_doacross_op = depend_op;
    3332          734 :                   n->u2.ns = ns_iter;
    3333          734 :                   if (ns_iter)
    3334           39 :                     ns_iter->refs++;
    3335              :                 }
    3336          703 :               continue;
    3337          703 :             }
    3338         1650 :           if ((mask & OMP_CLAUSE_DESTROY)
    3339         1629 :               && gfc_match_omp_variable_list ("destroy (",
    3340              :                                               &c->lists[OMP_LIST_DESTROY],
    3341              :                                               true) == MATCH_YES)
    3342           21 :             continue;
    3343         1734 :           if ((mask & OMP_CLAUSE_DETACH)
    3344          164 :               && !openacc
    3345          127 :               && !c->detach
    3346         1734 :               && gfc_match_omp_detach (&c->detach) == MATCH_YES)
    3347          126 :             continue;
    3348         1519 :           if ((mask & OMP_CLAUSE_DETACH)
    3349           38 :               && openacc
    3350           37 :               && gfc_match ("detach ( ") == MATCH_YES
    3351         1519 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3352              :                                            OMP_MAP_DETACH, false,
    3353              :                                            allow_derived))
    3354           37 :             continue;
    3355         1481 :           if ((mask & OMP_CLAUSE_DEVICEPTR)
    3356           87 :               && gfc_match ("deviceptr ( ") == MATCH_YES
    3357         1483 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3358              :                                            OMP_MAP_FORCE_DEVICEPTR, false,
    3359              :                                            allow_derived))
    3360           36 :             continue;
    3361          851 :           if ((mask & OMP_CLAUSE_DEVICE_TYPE) && openacc
    3362          444 :               && gfc_match_dupl_check (!c->oacc_device_type_present,
    3363              :                                        "device_type", true) == MATCH_YES
    3364         1741 :               && match_oacc_device_type (c) == MATCH_YES)
    3365          326 :             continue;
    3366          525 :           if ((mask & OMP_CLAUSE_DEVICE_TYPE) && !openacc
    3367         1490 :               && gfc_match_dupl_check (c->device_type == OMP_DEVICE_TYPE_UNSET,
    3368              :                                        "device_type", true) == MATCH_YES)
    3369              :             {
    3370           95 :               if (gfc_match ("host") == MATCH_YES)
    3371           32 :                 c->device_type = OMP_DEVICE_TYPE_HOST;
    3372           63 :               else if (gfc_match ("nohost") == MATCH_YES)
    3373           24 :                 c->device_type = OMP_DEVICE_TYPE_NOHOST;
    3374           39 :               else if (gfc_match ("any") == MATCH_YES)
    3375           38 :                 c->device_type = OMP_DEVICE_TYPE_ANY;
    3376              :               else
    3377              :                 {
    3378            1 :                   gfc_error ("Expected HOST, NOHOST or ANY at %C");
    3379            1 :                   break;
    3380              :                 }
    3381           94 :               if (gfc_match (" )") != MATCH_YES)
    3382              :                 break;
    3383           94 :               continue;
    3384              :             }
    3385         1095 :           if ((mask & OMP_CLAUSE_DEVICE_NUM)
    3386          988 :               && (m = gfc_match_dupl_check (!c->device_num_expr,
    3387              :                                             "device_num")) != MATCH_NO)
    3388              :             {
    3389          109 :               if (m == MATCH_ERROR)
    3390            2 :                 goto error;
    3391          107 :               if (gfc_match ("( %e )", &c->device_num_expr) != MATCH_YES)
    3392            0 :                 goto error;
    3393          107 :               continue;
    3394              :             }
    3395          927 :           if ((mask & OMP_CLAUSE_DEVICE_RESIDENT)
    3396          928 :               && gfc_match_omp_variable_list
    3397           49 :                    ("device_resident (",
    3398              :                     &c->lists[OMP_LIST_DEVICE_RESIDENT], true) == MATCH_YES)
    3399           48 :             continue;
    3400         1143 :           if ((mask & OMP_CLAUSE_DEVICE)
    3401          733 :               && openacc
    3402          314 :               && gfc_match ("device ( ") == MATCH_YES
    3403         1144 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3404              :                                            OMP_MAP_FORCE_TO, true,
    3405              :                                            /* allow_derived = */ true))
    3406          312 :             continue;
    3407          519 :           if ((mask & OMP_CLAUSE_DEVICE)
    3408          421 :               && !openacc
    3409          938 :               && ((m = gfc_match_dupl_check (!c->device, "device", true))
    3410              :                   != MATCH_NO))
    3411              :             {
    3412          355 :               if (m == MATCH_ERROR)
    3413            0 :                 goto error;
    3414          355 :               c->ancestor = false;
    3415          355 :               if (gfc_match ("device_num : ") == MATCH_YES)
    3416              :                 {
    3417           18 :                   if (gfc_match ("%e )", &c->device) != MATCH_YES)
    3418              :                     {
    3419            1 :                       gfc_error ("Expected integer expression at %C");
    3420            1 :                       break;
    3421              :                     }
    3422              :                 }
    3423          337 :               else if (gfc_match ("ancestor : ") == MATCH_YES)
    3424              :                 {
    3425           45 :                   bool has_requires = false;
    3426           45 :                   c->ancestor = true;
    3427           82 :                   for (gfc_namespace *ns = gfc_current_ns; ns; ns = ns->parent)
    3428           80 :                     if (ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD)
    3429              :                       {
    3430              :                         has_requires = true;
    3431              :                         break;
    3432              :                       }
    3433           45 :                   if (!has_requires)
    3434              :                     {
    3435            2 :                       gfc_error ("%<ancestor%> device modifier not "
    3436              :                                  "preceded by %<requires%> directive "
    3437              :                                  "with %<reverse_offload%> clause at %C");
    3438            5 :                       break;
    3439              :                     }
    3440           43 :                   locus old_loc2 = gfc_current_locus;
    3441           43 :                   if (gfc_match ("%e )", &c->device) == MATCH_YES)
    3442              :                     {
    3443           43 :                       int device = 0;
    3444           43 :                       if (!gfc_extract_int (c->device, &device) && device != 1)
    3445              :                       {
    3446            1 :                         gfc_current_locus = old_loc2;
    3447            1 :                         gfc_error ("the %<device%> clause expression must "
    3448              :                                    "evaluate to %<1%> at %C");
    3449            1 :                         break;
    3450              :                       }
    3451              :                     }
    3452              :                   else
    3453              :                     {
    3454            0 :                       gfc_error ("Expected integer expression at %C");
    3455            0 :                       break;
    3456              :                     }
    3457              :                 }
    3458          292 :               else if (gfc_match ("%e )", &c->device) != MATCH_YES)
    3459              :                 {
    3460           13 :                   gfc_error ("Expected integer expression or a single device-"
    3461              :                               "modifier %<device_num%> or %<ancestor%> at %C");
    3462           13 :                   break;
    3463              :                 }
    3464          338 :               continue;
    3465          338 :             }
    3466          164 :           if ((mask & OMP_CLAUSE_DIST_SCHEDULE)
    3467          109 :               && c->dist_sched_kind == OMP_SCHED_NONE
    3468          273 :               && gfc_match ("dist_schedule ( static") == MATCH_YES)
    3469              :             {
    3470           97 :               m = MATCH_NO;
    3471           97 :               c->dist_sched_kind = OMP_SCHED_STATIC;
    3472           97 :               m = gfc_match (" , %e )", &c->dist_chunk_size);
    3473           97 :               if (m != MATCH_YES)
    3474           14 :                 m = gfc_match_char (')');
    3475           14 :               if (m != MATCH_YES)
    3476              :                 {
    3477            0 :                   c->dist_sched_kind = OMP_SCHED_NONE;
    3478            0 :                   gfc_current_locus = old_loc;
    3479              :                 }
    3480              :               else
    3481           97 :                 continue;
    3482              :             }
    3483           67 :           if ((mask & OMP_CLAUSE_DYN_GROUPPRIVATE)
    3484           67 :               && gfc_match_dupl_check (!c->dyn_groupprivate,
    3485              :                                        "dyn_groupprivate", true) == MATCH_YES)
    3486              :             {
    3487              :               bool cgroup = false;
    3488              :               bool first = true;
    3489           72 :               bool error_p = false;
    3490           95 :               do
    3491              :                 {
    3492           72 :                   old_loc = gfc_current_locus;
    3493           72 :                   if (gfc_match ("cgroup ") == MATCH_YES)
    3494              :                     {
    3495           24 :                       if (cgroup)
    3496              :                         {
    3497            1 :                           gfc_error ("Duplicated %<cgroup%> modifier at %L",
    3498              :                                      &old_loc);
    3499            1 :                           goto error;
    3500              :                         }
    3501              :                       cgroup = true;
    3502              :                     }
    3503           48 :                   else if (gfc_match ("fallback ( ") == MATCH_YES)
    3504              :                     {
    3505           30 :                       if (c->fallback != OMP_FALLBACK_NONE)
    3506              :                         {
    3507            1 :                           gfc_error ("Duplicated %<fallback%> modifier at %L",
    3508              :                                      &old_loc);
    3509            1 :                           goto error;
    3510              :                         }
    3511           29 :                       old_loc = gfc_current_locus;
    3512           29 :                       if (gfc_match ("abort ) ") == MATCH_YES)
    3513            6 :                         c->fallback = OMP_FALLBACK_ABORT;
    3514           23 :                       else if (gfc_match ("default_mem ) ") == MATCH_YES)
    3515            8 :                         c->fallback = OMP_FALLBACK_DEFAULT_MEM;
    3516           15 :                       else if (gfc_match ("null ) ") == MATCH_YES)
    3517           14 :                         c->fallback = OMP_FALLBACK_NULL;
    3518              :                       else
    3519              :                         {
    3520            1 :                           gfc_error ("Expected %<abort%>, %<default_mem%> or "
    3521              :                                      "%<null%> followed by %<)%> at %L",
    3522              :                                      &old_loc);
    3523            1 :                           goto error;
    3524              :                         }
    3525              :                     }
    3526           18 :                   else if (!first)
    3527              :                     {
    3528            1 :                       gfc_error ("Expected %<cgroup%> or %<fallback%> clause at %C");
    3529            1 :                       goto error;
    3530              :                     }
    3531           68 :                   if (gfc_match (", ") == MATCH_YES)
    3532              :                     {
    3533           23 :                       first = false;
    3534           23 :                       continue;
    3535              :                     }
    3536           45 :                   if (gfc_match (": ") == MATCH_YES)
    3537              :                     {
    3538           27 :                       old_loc = gfc_current_locus;
    3539           27 :                       break;
    3540              :                     }
    3541           18 :                   if (!first)
    3542              :                     {
    3543            0 :                       gfc_error ("Expected %<:%> at %C");
    3544            0 :                       goto error;
    3545              :                     }
    3546              :                   error_p = true;
    3547              :                   break;
    3548              :                 }
    3549              :               while (true);
    3550           45 :               if (gfc_match_expr (&c->dyn_groupprivate) != MATCH_YES)
    3551              :                 {
    3552            0 :                   gfc_error ("Expected numeric expression at %L, optionally preceeded by "
    3553              :                              "the %<cgroup%> and %<fallback%> modifier", &old_loc);
    3554            0 :                   goto error;
    3555              :                 }
    3556           45 :               if (error_p)
    3557           18 :                 c->fallback = OMP_FALLBACK_NONE;
    3558           45 :               if (gfc_match (" )") != MATCH_YES)
    3559              :                 {
    3560            1 :                   gfc_error ("Expected %<)%> at %C");
    3561            1 :                   goto error;
    3562              :                 }
    3563           44 :               continue;
    3564           44 :             }
    3565              :           break;
    3566           98 :         case 'e':
    3567           98 :           if ((mask & OMP_CLAUSE_ENTER))
    3568              :             {
    3569           98 :               m = gfc_match_omp_to_link ("enter (", &c->lists[OMP_LIST_ENTER]);
    3570           98 :               if (m == MATCH_ERROR)
    3571            0 :                 goto error;
    3572           98 :               if (m == MATCH_YES)
    3573           98 :                 continue;
    3574              :             }
    3575              :           break;
    3576         2359 :         case 'f':
    3577         2408 :           if ((mask & OMP_CLAUSE_FAIL)
    3578         2359 :               && (m = gfc_match_dupl_check (c->fail == OMP_MEMORDER_UNSET,
    3579              :                                             "fail", true)) != MATCH_NO)
    3580              :             {
    3581           58 :               if (m == MATCH_ERROR)
    3582            3 :                 goto error;
    3583           55 :               if (gfc_match ("seq_cst") == MATCH_YES)
    3584            6 :                 c->fail = OMP_MEMORDER_SEQ_CST;
    3585           49 :               else if (gfc_match ("acquire") == MATCH_YES)
    3586           14 :                 c->fail = OMP_MEMORDER_ACQUIRE;
    3587           35 :               else if (gfc_match ("relaxed") == MATCH_YES)
    3588           30 :                 c->fail = OMP_MEMORDER_RELAXED;
    3589              :               else
    3590              :                 {
    3591            5 :                   gfc_error ("Expected SEQ_CST, ACQUIRE or RELAXED at %C");
    3592            5 :                   break;
    3593              :                 }
    3594           50 :               if (gfc_match (" )") != MATCH_YES)
    3595            1 :                 goto error;
    3596           49 :               continue;
    3597              :             }
    3598         2344 :           if ((mask & OMP_CLAUSE_FILTER)
    3599         2301 :               && (m = gfc_match_dupl_check (!c->filter, "filter", true,
    3600              :                                             &c->filter)) != MATCH_NO)
    3601              :             {
    3602           44 :               if (m == MATCH_ERROR)
    3603            1 :                 goto error;
    3604           43 :               continue;
    3605              :             }
    3606         2321 :           if ((mask & OMP_CLAUSE_FINAL)
    3607         2257 :               && (m = gfc_match_dupl_check (!c->final_expr, "final", true,
    3608              :                                             &c->final_expr)) != MATCH_NO)
    3609              :             {
    3610           64 :               if (m == MATCH_ERROR)
    3611            0 :                 goto error;
    3612           64 :               continue;
    3613              :             }
    3614         2219 :           if ((mask & OMP_CLAUSE_FINALIZE)
    3615         2193 :               && (m = gfc_match_dupl_check (!c->finalize, "finalize"))
    3616              :                  != MATCH_NO)
    3617              :             {
    3618           26 :               if (m == MATCH_ERROR)
    3619            0 :                 goto error;
    3620           26 :               c->finalize = true;
    3621           26 :               continue;
    3622              :             }
    3623         3210 :           if ((mask & OMP_CLAUSE_FIRSTPRIVATE)
    3624         2167 :               && gfc_match_omp_variable_list ("firstprivate (",
    3625              :                                               &c->lists[OMP_LIST_FIRSTPRIVATE],
    3626              :                                               true) == MATCH_YES)
    3627         1043 :             continue;
    3628         2159 :           if ((mask & OMP_CLAUSE_FROM)
    3629         1124 :               && gfc_match_motion_var_list ("from (", &c->lists[OMP_LIST_FROM],
    3630              :                                              &head) == MATCH_YES)
    3631         1035 :             continue;
    3632          158 :           if ((mask & OMP_CLAUSE_FULL)
    3633          165 :               && (m = gfc_match_boolean_clause (&bval, "full",
    3634           76 :                          c->full || cfalse->full)) != MATCH_NO)
    3635              :             {
    3636           76 :               if (m == MATCH_ERROR)
    3637            7 :                 goto error;
    3638           69 :               if (bval)
    3639           68 :                 c->full = true;
    3640              :               else
    3641            1 :                 cfalse->full = true;
    3642           69 :               continue;
    3643              :             }
    3644              :           break;
    3645         1231 :         case 'g':
    3646         2423 :           if ((mask & OMP_CLAUSE_GANG)
    3647         1231 :               && (m = gfc_match_dupl_check (!c->gang, "gang")) != MATCH_NO)
    3648              :             {
    3649         1197 :               if (m == MATCH_ERROR)
    3650            0 :                 goto error;
    3651         1197 :               c->gang = true;
    3652         1197 :               m = match_oacc_clause_gwv (c, GOMP_DIM_GANG);
    3653         1197 :               if (m == MATCH_ERROR)
    3654              :                 {
    3655            5 :                   gfc_current_locus = old_loc;
    3656            5 :                   break;
    3657              :                 }
    3658         1192 :               continue;
    3659              :             }
    3660           68 :           if ((mask & OMP_CLAUSE_GRAINSIZE)
    3661           34 :               && (m = gfc_match_dupl_check (!c->grainsize, "grainsize", true))
    3662              :                  != MATCH_NO)
    3663              :             {
    3664           34 :               if (m == MATCH_ERROR)
    3665            0 :                 goto error;
    3666           34 :               if (gfc_match ("strict : ") == MATCH_YES)
    3667            1 :                 c->grainsize_strict = true;
    3668           34 :               if (gfc_match (" %e )", &c->grainsize) != MATCH_YES)
    3669            0 :                 goto error;
    3670           34 :               continue;
    3671              :             }
    3672              :           break;
    3673          474 :         case 'h':
    3674          523 :           if ((mask & OMP_CLAUSE_HAS_DEVICE_ADDR)
    3675          523 :               && gfc_match_omp_variable_list
    3676           49 :                    ("has_device_addr (", &c->lists[OMP_LIST_HAS_DEVICE_ADDR],
    3677              :                     false, NULL, NULL, true) == MATCH_YES)
    3678           49 :             continue;
    3679          473 :           if ((mask & OMP_CLAUSE_HINT)
    3680          425 :               && (m = gfc_match_dupl_check (!c->hint, "hint", true, &c->hint))
    3681              :                  != MATCH_NO)
    3682              :             {
    3683           48 :               if (m == MATCH_ERROR)
    3684            0 :                 goto error;
    3685           48 :               continue;
    3686              :             }
    3687          377 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    3688          377 :               && gfc_match ("holds ( ") == MATCH_YES)
    3689              :             {
    3690           22 :               gfc_expr *e;
    3691           22 :               if (gfc_match ("%e )", &e) != MATCH_YES)
    3692            0 :                 goto error;
    3693           22 :               if (c->assume == NULL)
    3694           15 :                 c->assume = gfc_get_omp_assumptions ();
    3695           22 :               gfc_expr_list *el = XCNEW (gfc_expr_list);
    3696           22 :               el->expr = e;
    3697           22 :               el->next = c->assume->holds;
    3698           22 :               c->assume->holds = el;
    3699           22 :               continue;
    3700           22 :             }
    3701          709 :           if ((mask & OMP_CLAUSE_HOST)
    3702          355 :               && gfc_match ("host ( ") == MATCH_YES
    3703          710 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    3704              :                                            OMP_MAP_FORCE_FROM, true,
    3705              :                                            /* allow_derived = */ true))
    3706          354 :             continue;
    3707              :           break;
    3708         2253 :         case 'i':
    3709         2276 :           if ((mask & OMP_CLAUSE_IF_PRESENT)
    3710         2253 :               && (m = gfc_match_dupl_check (!c->if_present, "if_present"))
    3711              :                  != MATCH_NO)
    3712              :             {
    3713           23 :               if (m == MATCH_ERROR)
    3714            0 :                 goto error;
    3715           23 :               c->if_present = true;
    3716           23 :               continue;
    3717              :             }
    3718         2230 :           if ((mask & OMP_CLAUSE_IF)
    3719         2230 :               && (m = gfc_match_dupl_check (!c->if_expr, "if", true))
    3720              :                  != MATCH_NO)
    3721              :             {
    3722         1472 :               if (m == MATCH_ERROR)
    3723           14 :                 goto error;
    3724         1458 :               if (!openacc)
    3725              :                 {
    3726              :                   /* This should match the enum gfc_omp_if_kind order.  */
    3727              :                   static const char *ifs[OMP_IF_LAST] = {
    3728              :                     "cancel : %e )",
    3729              :                     "parallel : %e )",
    3730              :                     "simd : %e )",
    3731              :                     "task : %e )",
    3732              :                     "taskloop : %e )",
    3733              :                     "target : %e )",
    3734              :                     "target data : %e )",
    3735              :                     "target update : %e )",
    3736              :                     "target enter data : %e )",
    3737              :                     "target exit data : %e )" };
    3738              :                   static const char *ifs2[] = {
    3739              :                     "target_data : %e )",
    3740              :                     "target_update : %e )",
    3741              :                     "target_enter_data : %e )",
    3742              :                     "target_exit_data : %e )" };
    3743              :                   int i;
    3744         4973 :                   for (i = 0; i < OMP_IF_LAST; i++)
    3745         4563 :                     if (c->if_exprs[i] == NULL
    3746         4563 :                         && gfc_match (ifs[i], &c->if_exprs[i]) == MATCH_YES)
    3747              :                       break;
    3748          548 :                   if (i < OMP_IF_LAST)
    3749          138 :                     continue;
    3750         2040 :                   for (i = 0; i < (int) ARRAY_SIZE (ifs2); i++)
    3751         1634 :                     if (c->if_exprs[OMP_IF_TARGET_DATA + i] == NULL
    3752         1634 :                         && (gfc_match (ifs2[i],
    3753              :                                       &c->if_exprs[OMP_IF_TARGET_DATA + i])
    3754              :                             == MATCH_YES))
    3755              :                       break;
    3756          410 :                   if (i < (int) ARRAY_SIZE (ifs2))
    3757            4 :                     continue;
    3758              :                 }
    3759         1316 :               if (gfc_match (" %e )", &c->if_expr) == MATCH_YES)
    3760         1311 :                 continue;
    3761            5 :               goto error;
    3762              :             }
    3763          875 :           if ((mask & OMP_CLAUSE_IN_REDUCTION)
    3764          758 :               && gfc_match_omp_clause_reduction (pc, c, openacc, allow_derived,
    3765              :                                                  openmp_target) == MATCH_YES)
    3766          117 :             continue;
    3767          668 :           if ((mask & OMP_CLAUSE_INBRANCH)
    3768          670 :               && (m = gfc_match_dupl_branch_clause (&bval, "inbranch",
    3769           29 :                         c->notinbranch || cfalse->notinbranch
    3770           27 :                         || c->inbranch || cfalse->inbranch)) != MATCH_NO)
    3771              :             {
    3772           29 :               if (m == MATCH_ERROR)
    3773            2 :                 goto error;
    3774           27 :               if (bval)
    3775           25 :                 c->inbranch = true;
    3776              :               else
    3777            2 :                 cfalse->inbranch = true;
    3778           27 :               continue;
    3779              :             }
    3780          854 :           if ((mask & OMP_CLAUSE_INDEPENDENT)
    3781          612 :               && (m = gfc_match_dupl_check (!c->independent, "independent"))
    3782              :                  != MATCH_NO)
    3783              :             {
    3784          242 :               if (m == MATCH_ERROR)
    3785            0 :                 goto error;
    3786          242 :               c->independent = true;
    3787          242 :               continue;
    3788              :             }
    3789          426 :           if ((mask & OMP_CLAUSE_INDIRECT)
    3790          431 :               && (m = gfc_match_boolean_clause (&bval, "indirect",
    3791           61 :                          c->indirect || cfalse->indirect)) != MATCH_NO)
    3792              :             {
    3793           61 :               if (m == MATCH_ERROR)
    3794            5 :                 goto error;
    3795           56 :               if (bval)
    3796           51 :                 c->indirect = true;
    3797              :               else
    3798            5 :                 cfalse->indirect = true;
    3799           56 :               continue;
    3800              :             }
    3801          309 :           if ((mask & OMP_CLAUSE_INIT)
    3802          309 :               && gfc_match ("init ( ") == MATCH_YES)
    3803              :             {
    3804          108 :               m = gfc_match_omp_init (&c->lists[OMP_LIST_INIT]);
    3805          108 :               if (m == MATCH_YES)
    3806           63 :                 continue;
    3807           45 :               goto error;
    3808              :             }
    3809          201 :           if ((mask & OMP_CLAUSE_INTEROP)
    3810          201 :               && (m = gfc_match_dupl_check (!c->lists[OMP_LIST_INTEROP],
    3811              :                                             "interop", true)) != MATCH_NO)
    3812              :             {
    3813              :               /* Note: the interop objects are saved in reverse order to match
    3814              :                  the order in C/C++.  */
    3815          125 :               if (m == MATCH_YES
    3816           63 :                   && (gfc_match_omp_variable_list ("",
    3817              :                                                    &c->lists[OMP_LIST_INTEROP],
    3818              :                                                    false, NULL, NULL, false,
    3819              :                                                    false, NULL, false, true)
    3820              :                       == MATCH_YES))
    3821           62 :                 continue;
    3822            1 :               goto error;
    3823              :             }
    3824          258 :           if ((mask & OMP_CLAUSE_IS_DEVICE_PTR)
    3825          258 :               && gfc_match_omp_variable_list
    3826          120 :                    ("is_device_ptr (",
    3827              :                     &c->lists[OMP_LIST_IS_DEVICE_PTR], false) == MATCH_YES)
    3828          120 :             continue;
    3829              :           break;
    3830         2395 :         case 'l':
    3831         2395 :           if ((mask & OMP_CLAUSE_LASTPRIVATE)
    3832         2395 :               && gfc_match ("lastprivate ( ") == MATCH_YES)
    3833              :             {
    3834         1468 :               bool conditional = gfc_match ("conditional : ") == MATCH_YES;
    3835         1468 :               head = NULL;
    3836         1468 :               if (gfc_match_omp_variable_list ("",
    3837              :                                                &c->lists[OMP_LIST_LASTPRIVATE],
    3838              :                                                false, NULL, &head) == MATCH_YES)
    3839              :                 {
    3840         1468 :                   gfc_omp_namelist *n;
    3841         3813 :                   for (n = *head; n; n = n->next)
    3842         2345 :                     n->u.lastprivate_conditional = conditional;
    3843         1468 :                   continue;
    3844         1468 :                 }
    3845            0 :               gfc_current_locus = old_loc;
    3846            0 :               break;
    3847              :             }
    3848          927 :           end_colon = false;
    3849          927 :           head = NULL;
    3850          927 :           if ((mask & OMP_CLAUSE_LINEAR)
    3851          927 :               && gfc_match ("linear (") == MATCH_YES)
    3852              :             {
    3853          849 :               bool old_linear_modifier = false;
    3854          849 :               gfc_omp_linear_op linear_op = OMP_LINEAR_DEFAULT;
    3855          849 :               gfc_expr *step = NULL;
    3856          849 :               locus saved_loc = gfc_current_locus;
    3857              : 
    3858          849 :               if (gfc_match_omp_variable_list (" ref (",
    3859              :                                                &c->lists[OMP_LIST_LINEAR],
    3860              :                                                false, NULL, &head)
    3861              :                   == MATCH_YES)
    3862              :                 {
    3863              :                   linear_op = OMP_LINEAR_REF;
    3864              :                   old_linear_modifier = true;
    3865              :                 }
    3866          821 :               else if (gfc_match_omp_variable_list (" val (",
    3867              :                                                     &c->lists[OMP_LIST_LINEAR],
    3868              :                                                     false, NULL, &head)
    3869              :                        == MATCH_YES)
    3870              :                 {
    3871              :                   linear_op = OMP_LINEAR_VAL;
    3872              :                   old_linear_modifier = true;
    3873              :                 }
    3874          810 :               else if (gfc_match_omp_variable_list (" uval (",
    3875              :                                                     &c->lists[OMP_LIST_LINEAR],
    3876              :                                                     false, NULL, &head)
    3877              :                        == MATCH_YES)
    3878              :                 {
    3879              :                   linear_op = OMP_LINEAR_UVAL;
    3880              :                   old_linear_modifier = true;
    3881              :                 }
    3882          801 :               else if (gfc_match_omp_variable_list ("",
    3883              :                                                     &c->lists[OMP_LIST_LINEAR],
    3884              :                                                     false, &end_colon, &head)
    3885              :                        == MATCH_YES)
    3886              :                 linear_op = OMP_LINEAR_DEFAULT;
    3887              :               else
    3888              :                 {
    3889            2 :                   gfc_current_locus = old_loc;
    3890            2 :                   break;
    3891              :                 }
    3892              :               if (linear_op != OMP_LINEAR_DEFAULT)
    3893              :                 {
    3894           48 :                   if (gfc_match (" :") == MATCH_YES)
    3895           31 :                     end_colon = true;
    3896           17 :                   else if (gfc_match (" )") != MATCH_YES)
    3897              :                     {
    3898            0 :                       gfc_free_omp_namelist (*head, OMP_LIST_LINEAR);
    3899            0 :                       gfc_current_locus = old_loc;
    3900            0 :                       *head = NULL;
    3901            0 :                       break;
    3902              :                     }
    3903              :                 }
    3904          847 :               gfc_gobble_whitespace ();
    3905          847 :               if (old_linear_modifier && end_colon)
    3906              :                 {
    3907           31 :                   if (gfc_match (" %e )", &step) != MATCH_YES)
    3908              :                     {
    3909            1 :                       gfc_free_omp_namelist (*head, OMP_LIST_LINEAR);
    3910            1 :                       gfc_current_locus = old_loc;
    3911            1 :                       *head = NULL;
    3912            5 :                       goto error;
    3913              :                     }
    3914              :                 }
    3915           47 :               if (old_linear_modifier)
    3916              :                 {
    3917           47 :                   char var_names[512]{};
    3918           47 :                   int count, offset = 0;
    3919          106 :                   for (gfc_omp_namelist *n = *head; n; n = n->next)
    3920              :                     {
    3921           59 :                       if (!n->next)
    3922           47 :                         count = snprintf (var_names + offset,
    3923           47 :                                           sizeof (var_names) - offset,
    3924           47 :                                           "%s", n->sym->name);
    3925              :                       else
    3926           12 :                         count = snprintf (var_names + offset,
    3927           12 :                                           sizeof (var_names) - offset,
    3928           12 :                                           "%s, ", n->sym->name);
    3929           59 :                       if (count < 0 || count >= ((int)sizeof (var_names))
    3930           59 :                                                 - offset)
    3931              :                         {
    3932            0 :                           snprintf (var_names, 512, "%s, ..., ",
    3933            0 :                                     (*head)->sym->name);
    3934            0 :                           while (n->next)
    3935              :                             n = n->next;
    3936            0 :                           offset = strlen (var_names);
    3937            0 :                           snprintf (var_names + offset,
    3938            0 :                                     sizeof (var_names) - offset,
    3939            0 :                                     "%s", n->sym->name);
    3940            0 :                           break;
    3941              :                         }
    3942           59 :                       offset += count;
    3943              :                     }
    3944           47 :                   char *var_names_for_warn = var_names;
    3945           47 :                   const char *op_name;
    3946           47 :                   switch (linear_op)
    3947              :                     {
    3948              :                       case OMP_LINEAR_REF: op_name = "ref"; break;
    3949           10 :                       case OMP_LINEAR_VAL: op_name = "val"; break;
    3950            9 :                       case OMP_LINEAR_UVAL: op_name = "uval"; break;
    3951            0 :                       default: gcc_unreachable ();
    3952              :                     }
    3953           47 :                   gfc_warning (OPT_Wdeprecated_openmp,
    3954              :                                "Specification of the list items as "
    3955              :                                "arguments to the modifiers at %L is "
    3956              :                                "deprecated; since OpenMP 5.2, use "
    3957              :                                "%<linear(%s : %s%s)%>", &saved_loc,
    3958              :                                var_names_for_warn, op_name,
    3959           47 :                                step == nullptr ? "" : ", step(...)");
    3960              :                 }
    3961          799 :               else if (end_colon)
    3962              :                 {
    3963          732 :                   bool has_error = false;
    3964              :                   bool has_modifiers = false;
    3965              :                   bool has_step = false;
    3966          732 :                   bool duplicate_step = false;
    3967          732 :                   bool duplicate_mod = false;
    3968          732 :                   while (true)
    3969              :                     {
    3970          732 :                       old_loc = gfc_current_locus;
    3971          732 :                       bool close_paren = gfc_match ("val )") == MATCH_YES;
    3972          732 :                       if (close_paren || gfc_match ("val , ") == MATCH_YES)
    3973              :                         {
    3974           23 :                           if (linear_op != OMP_LINEAR_DEFAULT)
    3975              :                             {
    3976              :                               duplicate_mod = true;
    3977              :                               break;
    3978              :                             }
    3979           22 :                           linear_op = OMP_LINEAR_VAL;
    3980           22 :                           has_modifiers = true;
    3981           22 :                           if (close_paren)
    3982              :                             break;
    3983           16 :                           continue;
    3984              :                         }
    3985          709 :                       close_paren = gfc_match ("uval )") == MATCH_YES;
    3986          709 :                       if (close_paren || gfc_match ("uval , ") == MATCH_YES)
    3987              :                         {
    3988            7 :                           if (linear_op != OMP_LINEAR_DEFAULT)
    3989              :                             {
    3990              :                               duplicate_mod = true;
    3991              :                               break;
    3992              :                             }
    3993            7 :                           linear_op = OMP_LINEAR_UVAL;
    3994            7 :                           has_modifiers = true;
    3995            7 :                           if (close_paren)
    3996              :                             break;
    3997            2 :                           continue;
    3998              :                         }
    3999          702 :                       close_paren = gfc_match ("ref )") == MATCH_YES;
    4000          702 :                       if (close_paren || gfc_match ("ref , ") == MATCH_YES)
    4001              :                         {
    4002           16 :                           if (linear_op != OMP_LINEAR_DEFAULT)
    4003              :                             {
    4004              :                               duplicate_mod = true;
    4005              :                               break;
    4006              :                             }
    4007           15 :                           linear_op = OMP_LINEAR_REF;
    4008           15 :                           has_modifiers = true;
    4009           15 :                           if (close_paren)
    4010              :                             break;
    4011            7 :                           continue;
    4012              :                         }
    4013          686 :                       close_paren = (gfc_match ("step ( %e ) )", &step)
    4014              :                                      == MATCH_YES);
    4015          697 :                       if (close_paren
    4016          686 :                           || gfc_match ("step ( %e ) , ", &step) == MATCH_YES)
    4017              :                         {
    4018           50 :                           if (has_step)
    4019              :                             {
    4020              :                               duplicate_step = true;
    4021              :                               break;
    4022              :                             }
    4023           49 :                           has_modifiers = has_step = true;
    4024           49 :                           if (close_paren)
    4025              :                             break;
    4026           11 :                           continue;
    4027              :                         }
    4028          636 :                       if (!has_modifiers
    4029          636 :                           && gfc_match ("%e )", &step) == MATCH_YES)
    4030              :                         {
    4031          636 :                           if ((step->expr_type == EXPR_FUNCTION
    4032          635 :                                 || step->expr_type == EXPR_VARIABLE)
    4033           31 :                               && strcmp (step->symtree->name, "step") == 0)
    4034              :                             {
    4035            1 :                               gfc_current_locus = old_loc;
    4036            1 :                               gfc_match ("step (");
    4037            1 :                               has_error = true;
    4038              :                             }
    4039              :                           break;
    4040              :                         }
    4041              :                       has_error = true;
    4042              :                       break;
    4043              :                     }
    4044           61 :                   if (duplicate_mod || duplicate_step)
    4045              :                     {
    4046            3 :                       gfc_error ("Multiple %qs modifiers specified at %C",
    4047              :                                  duplicate_mod ? "linear" : "step");
    4048            3 :                       has_error = true;
    4049              :                     }
    4050          696 :                   if (has_error)
    4051              :                     {
    4052            4 :                       gfc_free_omp_namelist (*head, OMP_LIST_LINEAR);
    4053            4 :                       *head = NULL;
    4054            4 :                       goto error;
    4055              :                     }
    4056              :                 }
    4057          842 :               if (step == NULL)
    4058              :                 {
    4059          130 :                   step = gfc_get_constant_expr (BT_INTEGER,
    4060              :                                                 gfc_default_integer_kind,
    4061              :                                                 &old_loc);
    4062          130 :                   mpz_set_si (step->value.integer, 1);
    4063              :                 }
    4064          842 :               (*head)->expr = step;
    4065          842 :               if (linear_op != OMP_LINEAR_DEFAULT || old_linear_modifier)
    4066          188 :                 for (gfc_omp_namelist *n = *head; n; n = n->next)
    4067              :                   {
    4068          100 :                     n->u.linear.op = linear_op;
    4069          100 :                     n->u.linear.old_modifier = old_linear_modifier;
    4070              :                   }
    4071          842 :               continue;
    4072          842 :             }
    4073           82 :           if ((mask & OMP_CLAUSE_LINK)
    4074           78 :               && openacc
    4075           86 :               && (gfc_match_oacc_clause_link ("link (",
    4076              :                                               &c->lists[OMP_LIST_LINK])
    4077              :                   == MATCH_YES))
    4078            4 :             continue;
    4079          123 :           else if ((mask & OMP_CLAUSE_LINK)
    4080           74 :                    && !openacc
    4081          144 :                    && (gfc_match_omp_to_link ("link (",
    4082              :                                               &c->lists[OMP_LIST_LINK])
    4083              :                        == MATCH_YES))
    4084           49 :             continue;
    4085           46 :           if ((mask & OMP_CLAUSE_LOCAL)
    4086           25 :               && (gfc_match_omp_to_link ("local (", &c->lists[OMP_LIST_LOCAL])
    4087              :                   == MATCH_YES))
    4088           21 :             continue;
    4089              :           break;
    4090         6020 :         case 'm':
    4091         6020 :           if ((mask & OMP_CLAUSE_MAP)
    4092         6020 :               && gfc_match ("map ( ") == MATCH_YES)
    4093              :             {
    4094         5887 :               locus old_loc2 = gfc_current_locus;
    4095         5887 :               int always_modifier = 0;
    4096         5887 :               int close_modifier = 0;
    4097         5887 :               int present_modifier = 0;
    4098         5887 :               int mapper_modifier = 0;
    4099         5887 :               int iterator_modifier = 0;
    4100         5887 :               gfc_namespace *ns_iter = NULL, *ns_curr = gfc_current_ns;
    4101         5887 :               locus second_always_locus = old_loc2;
    4102         5887 :               locus second_close_locus = old_loc2;
    4103         5887 :               locus second_mapper_locus = old_loc2;
    4104         5887 :               locus second_present_locus = old_loc2;
    4105         5887 :               char mapper_id[GFC_MAX_SYMBOL_LEN + 1] = { '\0' };
    4106         5887 :               locus second_iterator_locus = old_loc2;
    4107              : 
    4108         6557 :               for (;;)
    4109              :                 {
    4110         6222 :                   locus current_locus = gfc_current_locus;
    4111         6222 :                   if (gfc_match ("always ") == MATCH_YES)
    4112              :                     {
    4113          149 :                       if (always_modifier++ == 1)
    4114            5 :                         second_always_locus = current_locus;
    4115              :                     }
    4116         6073 :                   else if (gfc_match ("close ") == MATCH_YES)
    4117              :                     {
    4118           69 :                       if (close_modifier++ == 1)
    4119            5 :                         second_close_locus = current_locus;
    4120              :                     }
    4121         6004 :                   else if (gfc_match ("present ") == MATCH_YES)
    4122              :                     {
    4123           67 :                       if (present_modifier++ == 1)
    4124            4 :                         second_present_locus = current_locus;
    4125              :                     }
    4126         5937 :                   else if (gfc_match ("mapper ( ") == MATCH_YES)
    4127              :                     {
    4128            8 :                       if (mapper_modifier++ == 1)
    4129            0 :                         second_mapper_locus = current_locus;
    4130            8 :                       m = gfc_match (" %n ) ", mapper_id);
    4131            8 :                       if (m != MATCH_YES)
    4132            0 :                         goto error;
    4133            8 :                       if (strcmp (mapper_id, "default") == 0)
    4134            3 :                         mapper_id[0] = '\0';
    4135              :                     }
    4136         5929 :                   else if (gfc_match_iterator (&ns_iter, true) == MATCH_YES)
    4137              :                     {
    4138           42 :                       if (iterator_modifier++ == 1)
    4139            1 :                       second_iterator_locus = current_locus;
    4140              :                     }
    4141              :                   else
    4142              :                     break;
    4143          335 :                   if (gfc_match (", ") != MATCH_YES)
    4144           62 :                     gfc_warning (OPT_Wdeprecated_openmp,
    4145              :                                  "The specification of modifiers without "
    4146              :                                  "comma separators for the %<map%> clause "
    4147              :                                  "at %C has been deprecated since "
    4148              :                                  "OpenMP 5.2");
    4149          335 :                 }
    4150              : 
    4151         5887 :               gfc_omp_map_op map_op = default_map_op;
    4152         5887 :               int always_present_modifier
    4153         5887 :                 = always_modifier && present_modifier;
    4154              : 
    4155         5887 :               if (gfc_match ("alloc : ") == MATCH_YES)
    4156          799 :                 map_op = (present_modifier ? OMP_MAP_PRESENT_ALLOC
    4157              :                           : OMP_MAP_ALLOC);
    4158         5088 :               else if (gfc_match ("tofrom : ") == MATCH_YES)
    4159          979 :                 map_op = (always_present_modifier ? OMP_MAP_ALWAYS_PRESENT_TOFROM
    4160          975 :                           : present_modifier ? OMP_MAP_PRESENT_TOFROM
    4161          970 :                           : always_modifier ? OMP_MAP_ALWAYS_TOFROM
    4162              :                           : OMP_MAP_TOFROM);
    4163         4109 :               else if (gfc_match ("to : ") == MATCH_YES)
    4164         1821 :                 map_op = (always_present_modifier ? OMP_MAP_ALWAYS_PRESENT_TO
    4165         1815 :                           : present_modifier ? OMP_MAP_PRESENT_TO
    4166         1803 :                           : always_modifier ? OMP_MAP_ALWAYS_TO
    4167              :                           : OMP_MAP_TO);
    4168         2288 :               else if (gfc_match ("from : ") == MATCH_YES)
    4169         1656 :                 map_op = (always_present_modifier ? OMP_MAP_ALWAYS_PRESENT_FROM
    4170         1652 :                           : present_modifier ? OMP_MAP_PRESENT_FROM
    4171         1647 :                           : always_modifier ? OMP_MAP_ALWAYS_FROM
    4172              :                           : OMP_MAP_FROM);
    4173          632 :               else if (gfc_match ("release : ") == MATCH_YES)
    4174              :                 map_op = OMP_MAP_RELEASE;
    4175          578 :               else if (gfc_match ("delete : ") == MATCH_YES)
    4176              :                 map_op = OMP_MAP_DELETE;
    4177              :               else
    4178              :                 {
    4179          501 :                   gfc_current_locus = old_loc2;
    4180          501 :                   always_modifier = 0;
    4181          501 :                   close_modifier = 0;
    4182          501 :                   mapper_modifier = 0;
    4183              :                 }
    4184              : 
    4185         1580 :               if (always_modifier > 1)
    4186              :                 {
    4187            5 :                   gfc_error ("too many %<always%> modifiers at %L",
    4188              :                              &second_always_locus);
    4189           24 :                   break;
    4190              :                 }
    4191         5882 :               if (close_modifier > 1)
    4192              :                 {
    4193            4 :                   gfc_error ("too many %<close%> modifiers at %L",
    4194              :                              &second_close_locus);
    4195            4 :                   break;
    4196              :                 }
    4197         5878 :               if (present_modifier > 1)
    4198              :                 {
    4199            4 :                   gfc_error ("too many %<present%> modifiers at %L",
    4200              :                              &second_present_locus);
    4201            4 :                   break;
    4202              :                 }
    4203         5874 :               if (mapper_modifier > 1)
    4204              :                 {
    4205            0 :                   gfc_error ("too many %<mapper%> modifiers at %L",
    4206              :                              &second_mapper_locus);
    4207            0 :                   break;
    4208              :                 }
    4209         5874 :               if (iterator_modifier > 1)
    4210              :                 {
    4211            1 :                   gfc_error ("too many %<iterator%> modifiers at %L",
    4212              :                              &second_iterator_locus);
    4213            1 :                   break;
    4214              :                 }
    4215              : 
    4216         5873 :               head = NULL;
    4217         5873 :               if (ns_iter)
    4218           40 :                 gfc_current_ns = ns_iter;
    4219         5873 :               m = gfc_match_omp_variable_list ("", &c->lists[OMP_LIST_MAP],
    4220              :                                                false, NULL, &head, true, true);
    4221         5873 :               gfc_current_ns = ns_curr;
    4222         5873 :               if (m == MATCH_YES)
    4223              :                 {
    4224         5868 :                   gfc_omp_namelist *n;
    4225        13344 :                   for (n = *head; n; n = n->next)
    4226              :                     {
    4227         7476 :                       n->u.map.op = map_op;
    4228         7476 :                       if (mapper_id[0] != '\0')
    4229              :                         {
    4230            5 :                           n->u3.udm = gfc_get_omp_namelist_udm ();
    4231            5 :                           n->u3.udm->requested_mapper_id
    4232            5 :                             = gfc_get_string ("%s", mapper_id);
    4233              :                         }
    4234         7476 :                       n->u2.ns = ns_iter;
    4235         7476 :                       if (ns_iter)
    4236           42 :                         ns_iter->refs++;
    4237              :                     }
    4238         5868 :                   continue;
    4239         5868 :                 }
    4240            5 :               gfc_current_locus = old_loc;
    4241            5 :               break;
    4242              :             }
    4243          167 :           if ((mask & OMP_CLAUSE_MERGEABLE)
    4244          167 :               && (m = gfc_match_boolean_clause (&bval, "mergeable",
    4245           34 :                          c->mergeable || cfalse->mergeable)) != MATCH_NO)
    4246              :             {
    4247           34 :               if (m == MATCH_ERROR)
    4248            0 :                 goto error;
    4249           34 :               if (bval)
    4250           34 :                 c->mergeable = true;
    4251              :               else
    4252            0 :                 cfalse->mergeable = true;
    4253           34 :               continue;
    4254              :             }
    4255          193 :           if ((mask & OMP_CLAUSE_MESSAGE)
    4256           99 :               && (m = gfc_match_dupl_check (!c->message, "message", true,
    4257              :                  &c->message)) != MATCH_NO)
    4258              :             {
    4259           99 :               if (m == MATCH_ERROR)
    4260            5 :                 goto error;
    4261           94 :               continue;
    4262              :             }
    4263              :           break;
    4264         3062 :         case 'n':
    4265         3114 :           if ((mask & OMP_CLAUSE_NO_CREATE)
    4266         1343 :               && gfc_match ("no_create ( ") == MATCH_YES
    4267         3114 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4268              :                                            OMP_MAP_IF_PRESENT, true,
    4269              :                                            allow_derived))
    4270           52 :             continue;
    4271         3013 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    4272         3044 :               && ((m = gfc_match_boolean_clause (&bval, "no_openmp_constructs",
    4273           34 :                          (c->assume && c->assume->no_openmp_constructs)
    4274           31 :                          || (cfalse->assume && cfalse->assume->no_openmp_constructs)))
    4275              :                   != MATCH_NO))
    4276              :             {
    4277            4 :               if (m == MATCH_ERROR)
    4278            1 :                 goto error;
    4279            3 :               if (bval)
    4280              :                 {
    4281            2 :                   if (c->assume == NULL)
    4282            0 :                     c->assume = gfc_get_omp_assumptions ();
    4283            2 :                   c->assume->no_openmp_constructs = true;
    4284              :                 }
    4285              :               else
    4286              :                 {
    4287            1 :                   if (cfalse->assume == NULL)
    4288            0 :                     cfalse->assume = gfc_get_omp_assumptions ();
    4289            1 :                   cfalse->assume->no_openmp_constructs = true;
    4290              :                 }
    4291            3 :               continue;
    4292              :             }
    4293         3021 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    4294         3036 :               && ((m = gfc_match_boolean_clause (&bval, "no_openmp_routines",
    4295           30 :                          (c->assume && c->assume->no_openmp_routines)
    4296           29 :                          || (cfalse->assume && cfalse->assume->no_openmp_routines)))
    4297              :                   != MATCH_NO))
    4298              :             {
    4299           15 :               if (m == MATCH_ERROR)
    4300            0 :                 goto error;
    4301           15 :               if (bval)
    4302              :                 {
    4303           14 :                   if (c->assume == NULL)
    4304           12 :                     c->assume = gfc_get_omp_assumptions ();
    4305           14 :                   c->assume->no_openmp_routines = true;
    4306              :                 }
    4307              :               else
    4308              :                 {
    4309            1 :                   if (cfalse->assume == NULL)
    4310            0 :                     cfalse->assume = gfc_get_omp_assumptions ();
    4311            1 :                   cfalse->assume->no_openmp_routines = true;
    4312              :                 }
    4313           15 :               continue;
    4314              :             }
    4315         2997 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    4316         3006 :               && ((m = gfc_match_boolean_clause (&bval, "no_openmp",
    4317           15 :                          (c->assume && c->assume->no_openmp)
    4318           13 :                          || (cfalse->assume && cfalse->assume->no_openmp)))
    4319              :                   != MATCH_NO))
    4320              :             {
    4321            6 :               if (m == MATCH_ERROR)
    4322            0 :                 goto error;
    4323            6 :               if (bval)
    4324              :                 {
    4325            5 :                   if (c->assume == NULL)
    4326            5 :                     c->assume = gfc_get_omp_assumptions ();
    4327            5 :                   c->assume->no_openmp = true;
    4328              :                 }
    4329              :               else
    4330              :                 {
    4331            1 :                   if (cfalse->assume == NULL)
    4332            1 :                     cfalse->assume = gfc_get_omp_assumptions ();
    4333            1 :                   cfalse->assume->no_openmp = true;
    4334              :                 }
    4335            6 :               continue;
    4336              :             }
    4337         2993 :           if ((mask & OMP_CLAUSE_ASSUMPTIONS)
    4338         2994 :               && ((m = gfc_match_boolean_clause (&bval, "no_parallelism",
    4339            9 :                          (c->assume && c->assume->no_parallelism)
    4340            9 :                          || (cfalse->assume && cfalse->assume->no_parallelism)))
    4341              :                   != MATCH_NO))
    4342              :             {
    4343            8 :               if (m == MATCH_ERROR)
    4344            0 :                 goto error;
    4345            8 :               if (bval)
    4346              :                 {
    4347            7 :                   if (c->assume == NULL)
    4348            6 :                     c->assume = gfc_get_omp_assumptions ();
    4349            7 :                   c->assume->no_parallelism = true;
    4350              :                 }
    4351              :               else
    4352              :                 {
    4353            1 :                   if (cfalse->assume == NULL)
    4354            0 :                     cfalse->assume = gfc_get_omp_assumptions ();
    4355            1 :                   cfalse->assume->no_parallelism = true;
    4356              :                 }
    4357            8 :               continue;
    4358              :             }
    4359              : 
    4360         2987 :           if ((mask & OMP_CLAUSE_NOVARIANTS)
    4361         2977 :               && (m = gfc_match_dupl_check (!c->novariants, "novariants", true,
    4362              :                                             &c->novariants))
    4363              :                    != MATCH_NO)
    4364              :             {
    4365           12 :               if (m == MATCH_ERROR)
    4366            2 :                 goto error;
    4367           10 :               continue;
    4368              :             }
    4369         2978 :           if ((mask & OMP_CLAUSE_NOCONTEXT)
    4370         2965 :               && (m = gfc_match_dupl_check (!c->nocontext, "nocontext", true,
    4371              :                                             &c->nocontext))
    4372              :                    != MATCH_NO)
    4373              :             {
    4374           15 :               if (m == MATCH_ERROR)
    4375            2 :                 goto error;
    4376           13 :               continue;
    4377              :             }
    4378         2964 :           if ((mask & OMP_CLAUSE_NOGROUP)
    4379         3034 :               && ((m = gfc_match_boolean_clause (&bval, "nogroup",
    4380           84 :                                                  c->nogroup || cfalse->nogroup))
    4381              :                   != MATCH_NO))
    4382              :             {
    4383           14 :               if (m == MATCH_ERROR)
    4384            0 :                 goto error;
    4385           14 :               if (bval)
    4386           14 :                 c->nogroup = true;
    4387              :               else
    4388            0 :                 cfalse->nogroup = true;
    4389           14 :               continue;
    4390              :             }
    4391         3086 :           if ((mask & OMP_CLAUSE_NOHOST)
    4392         2936 :               && (m = gfc_match_dupl_check (!c->nohost, "nohost")) != MATCH_NO)
    4393              :             {
    4394          151 :               if (m == MATCH_ERROR)
    4395            1 :                 goto error;
    4396          150 :               c->nohost = true;
    4397          150 :               continue;
    4398              :             }
    4399         2827 :           if ((mask & OMP_CLAUSE_NOTEMPORAL)
    4400         2785 :               && gfc_match_omp_variable_list ("nontemporal (",
    4401              :                                               &c->lists[OMP_LIST_NONTEMPORAL],
    4402              :                                               true) == MATCH_YES)
    4403           42 :             continue;
    4404         2773 :           if ((mask & OMP_CLAUSE_NOTINBRANCH)
    4405         2776 :               && (m = gfc_match_dupl_branch_clause (&bval, "notinbranch",
    4406           33 :                         c->notinbranch || cfalse->notinbranch
    4407           33 :                         || c->inbranch || cfalse->inbranch)) != MATCH_NO)
    4408              :             {
    4409           33 :               if (m == MATCH_ERROR)
    4410            3 :                 goto error;
    4411           30 :               if (bval)
    4412           27 :                 c->notinbranch = true;
    4413              :               else
    4414            3 :                 cfalse->notinbranch = true;
    4415           30 :               continue;
    4416              :             }
    4417         2843 :           if ((mask & OMP_CLAUSE_NOWAIT)
    4418         2710 :               && (m = gfc_match_dupl_check (!c->nowait, "nowait")) != MATCH_NO)
    4419              :             {
    4420          136 :               if (m == MATCH_ERROR)
    4421            3 :                 goto error;
    4422          133 :               c->nowait = true;
    4423          133 :               continue;
    4424              :             }
    4425         3256 :           if ((mask & OMP_CLAUSE_NUM_GANGS)
    4426         2574 :               && (m = gfc_match_dupl_check (!c->num_gangs_expr, "num_gangs",
    4427              :                                             true)) != MATCH_NO)
    4428              :             {
    4429          686 :               if (m == MATCH_ERROR)
    4430            2 :                 goto error;
    4431          684 :               if (gfc_match (" %e )", &c->num_gangs_expr) != MATCH_YES)
    4432            2 :                 goto error;
    4433          682 :               continue;
    4434              :             }
    4435         1914 :           if ((mask & OMP_CLAUSE_NUM_TASKS)
    4436         1888 :               && (m = gfc_match_dupl_check (!c->num_tasks, "num_tasks", true))
    4437              :                  != MATCH_NO)
    4438              :             {
    4439           26 :               if (m == MATCH_ERROR)
    4440            0 :                 goto error;
    4441           26 :               if (gfc_match ("strict : ") == MATCH_YES)
    4442            1 :                 c->num_tasks_strict = true;
    4443           26 :               if (gfc_match (" %e )", &c->num_tasks) != MATCH_YES)
    4444            0 :                 goto error;
    4445           26 :               continue;
    4446              :             }
    4447         1862 :           if ((mask & OMP_CLAUSE_NUM_TEAMS)
    4448         1862 :               && (m = gfc_match_dupl_check (!c->num_teams_list,
    4449              :                                             "num_teams", true)) != MATCH_NO)
    4450              :             {
    4451          203 :               if (m == MATCH_ERROR)
    4452           20 :                 goto error;
    4453          201 :               gfc_expr *expr;
    4454          201 :               if (gfc_match ("dims ( %e ) : ", &expr) == MATCH_YES
    4455          201 :                   && match_omp_oacc_expr_list (NULL, &c->num_teams_list,
    4456              :                                                false, true) == MATCH_YES)
    4457              :                 {
    4458           29 :                   int num = 0;
    4459           29 :                   gfc_expr_list *el;
    4460           82 :                   for (el = c->num_teams_list; el; el = el->next)
    4461           53 :                     ++num;
    4462           29 :                   if (!gfc_resolve_expr (expr)
    4463           29 :                       || expr->ts.type != BT_INTEGER
    4464           28 :                       || expr->rank != 0
    4465           27 :                       || expr->expr_type != EXPR_CONSTANT
    4466           54 :                       || mpz_sgn (expr->value.integer) <= 0)
    4467              :                     {
    4468            5 :                       gfc_error ("DIMS must be a constant positive integer "
    4469            5 :                                  "at %L", &expr->where);
    4470            5 :                       goto error;
    4471              :                     }
    4472           24 :                   if (mpz_cmp_si (expr->value.integer, num) != 0)
    4473              :                     {
    4474            1 :                       gfc_error ("The number of arguments (%d) must be the same"
    4475              :                                  " as specified for DIMS at %L", num,
    4476              :                                  &expr->where);
    4477            1 :                       goto error;
    4478              :                     }
    4479           23 :                   c->num_teams_dims = true;
    4480          183 :                   continue;
    4481           23 :                 }
    4482          172 :               else if (gfc_match ("%e ", &expr) == MATCH_YES)
    4483              :                 {
    4484          169 :                   c->num_teams_list = gfc_get_expr_list();
    4485          169 :                   c->num_teams_list->expr = expr;
    4486          169 :                   if (gfc_peek_ascii_char () == ':')
    4487              :                     {
    4488           39 :                       expr = NULL;
    4489           39 :                       if (gfc_match (": %e ", &expr) == MATCH_YES)
    4490              :                         {
    4491           38 :                           c->num_teams_list->next = gfc_get_expr_list();
    4492           38 :                           c->num_teams_list->next->expr = expr;
    4493           38 :                           if (gfc_match (") ") == MATCH_YES)
    4494           36 :                             continue;
    4495              :                         }
    4496              :                     }
    4497          130 :                   else if (gfc_match (") ") == MATCH_YES)
    4498          124 :                     continue;
    4499              :                 }
    4500           12 :               gfc_error ("Expected either %<[lower-expr : ] upper-expr%> or "
    4501              :                              "%<dims(N): expr-list%> at %C");
    4502           12 :               goto error;
    4503              :             }
    4504         1659 :           if ((mask & OMP_CLAUSE_NUM_THREADS)
    4505         1659 :               && (m = gfc_match_dupl_check (!c->num_threads_list,
    4506              :                                             "num_threads", true, NULL))
    4507              :                   != MATCH_NO)
    4508              :             {
    4509         1018 :               int nstrict = 0, nrelaxed = 0, ndims = 0;
    4510         1018 :               bool fail = false;
    4511         1018 :               gfc_expr *dims = NULL;
    4512         1018 :               locus old_loc = gfc_current_locus;
    4513              : 
    4514         1018 :               if (m == MATCH_ERROR)
    4515           27 :                 goto error;
    4516         1068 :               while (true)
    4517              :                 {
    4518         1042 :                   if (gfc_match ("strict ") == MATCH_YES)
    4519           16 :                     nstrict++;
    4520         1026 :                   else if (gfc_match ("relaxed ") == MATCH_YES)
    4521           21 :                     nrelaxed++;
    4522         1005 :                   else if (gfc_match ("dims ") == MATCH_YES)
    4523              :                     {
    4524           32 :                       ndims++;
    4525           32 :                       if (dims)
    4526            3 :                         gfc_free_expr (dims);
    4527           32 :                       if (gfc_match ("( %e ) ", &dims) != MATCH_YES)
    4528              :                         break;
    4529              :                     }
    4530              :                   else
    4531              :                     {
    4532              :                       fail = true;
    4533              :                       break;
    4534              :                     }
    4535           68 :                   if (gfc_match (", ") == MATCH_YES)
    4536           26 :                     continue;
    4537              :                   break;
    4538              :                 }
    4539         1016 :               if (gfc_match (" : ") == MATCH_YES)
    4540              :                 {
    4541           40 :                   if (nstrict + nrelaxed + ndims == 0 || fail)
    4542              :                     {
    4543            1 :                       gfc_error ("Expected STRICT, RELAXED or DIMS modifier at "
    4544              :                                  "%C");
    4545            1 :                       goto error;
    4546              :                     }
    4547           39 :                   else if (nstrict + nrelaxed > 1)
    4548              :                     {
    4549            8 :                       gfc_error ("Only one STRICT or RELAXED modifier permitted"
    4550              :                                  " at %L", &old_loc);
    4551            8 :                       goto error;
    4552              :                     }
    4553           31 :                   if (ndims > 1)
    4554              :                     {
    4555            3 :                       gfc_error ("Duplicated DIMS expression at %L",
    4556            3 :                                  &dims->where);
    4557            3 :                       goto error;
    4558              :                     }
    4559           28 :                   if (nstrict || (dims && !nrelaxed))
    4560           17 :                     c->num_threads_strict = true;
    4561              :                 }
    4562              :               else
    4563              :                 {
    4564          976 :                   gfc_free_expr (dims);
    4565          976 :                   dims = NULL;
    4566          976 :                   gfc_current_locus = old_loc;
    4567              :                 }
    4568              : 
    4569         1004 :               m = match_omp_oacc_expr_list (NULL, &c->num_threads_list, false,
    4570              :                                             true);
    4571         1004 :               if (m != MATCH_YES)
    4572              :                 {
    4573            7 :                   gfc_error ("Expected a list of integer expressions followed "
    4574              :                              "by a %<)%> and optionally preceded by the STRICT,"
    4575              :                              " RELAXED, or DIMS as modifiers and a colon at %C");
    4576            7 :                   goto error;
    4577              :                 }
    4578          997 :               if (dims)
    4579              :                 {
    4580           17 :                   int num = 0;
    4581           17 :                   gfc_expr_list *el;
    4582           46 :                   for (el = c->num_threads_list; el; el = el->next)
    4583           29 :                     ++num;
    4584           17 :                   if (!gfc_resolve_expr (dims)
    4585           17 :                       || dims->ts.type != BT_INTEGER
    4586           16 :                       || dims->rank != 0
    4587           15 :                       || dims->expr_type != EXPR_CONSTANT
    4588           30 :                       || mpz_sgn (dims->value.integer) <= 0)
    4589              :                     {
    4590            5 :                       gfc_error ("DIMS must be a constant positive integer "
    4591            5 :                                  "at %L", &dims->where);
    4592            5 :                       goto error;
    4593              :                     }
    4594           12 :                   if (mpz_cmp_si (dims->value.integer, num) != 0)
    4595              :                     {
    4596            1 :                       gfc_error ("The number of arguments (%d) must be the same"
    4597              :                                  " as specified for DIMS at %L", num,
    4598              :                                  &dims->where);
    4599            1 :                       goto error;
    4600              :                     }
    4601           11 :                   c->num_threads_dims = true;
    4602              :                 }
    4603          991 :               continue;
    4604          991 :             }
    4605         1240 :           if ((mask & OMP_CLAUSE_NUM_WORKERS)
    4606          641 :               && (m = gfc_match_dupl_check (!c->num_workers_expr, "num_workers",
    4607              :                                             true, &c->num_workers_expr))
    4608              :                  != MATCH_NO)
    4609              :             {
    4610          603 :               if (m == MATCH_ERROR)
    4611            4 :                 goto error;
    4612          599 :               continue;
    4613              :             }
    4614              :           break;
    4615          591 :         case 'o':
    4616          591 :           if ((mask & OMP_CLAUSE_ORDERED)
    4617          591 :               && (m = gfc_match_dupl_check (!c->ordered, "ordered"))
    4618              :                  != MATCH_NO)
    4619              :             {
    4620          343 :               if (m == MATCH_ERROR)
    4621            0 :                 goto error;
    4622          343 :               gfc_expr *cexpr = NULL;
    4623          343 :               m = gfc_match (" ( %e )", &cexpr);
    4624              : 
    4625          343 :               c->ordered = true;
    4626          343 :               if (m == MATCH_YES)
    4627              :                 {
    4628          144 :                   int ordered = 0;
    4629          144 :                   if (gfc_extract_int (cexpr, &ordered, -1))
    4630            0 :                     ordered = 0;
    4631          144 :                   else if (ordered <= 0)
    4632              :                     {
    4633            0 :                       gfc_error_now ("ORDERED clause argument not"
    4634              :                                      " constant positive integer at %C");
    4635            0 :                       ordered = 0;
    4636              :                     }
    4637          144 :                   c->orderedc = ordered;
    4638          144 :                   gfc_free_expr (cexpr);
    4639          144 :                   continue;
    4640          144 :                 }
    4641              : 
    4642          199 :               continue;
    4643          199 :             }
    4644          482 :           if ((mask & OMP_CLAUSE_ORDER)
    4645          248 :               && (m = gfc_match_dupl_check (!c->order_concurrent, "order", true))
    4646              :                  != MATCH_NO)
    4647              :             {
    4648          247 :               if (m == MATCH_ERROR)
    4649           10 :                 goto error;
    4650          237 :               if (gfc_match (" reproducible : concurrent )") == MATCH_YES)
    4651           55 :                 c->order_reproducible = true;
    4652          182 :               else if (gfc_match (" concurrent )") == MATCH_YES)
    4653              :                 ;
    4654           50 :               else if (gfc_match (" unconstrained : concurrent )") == MATCH_YES)
    4655           47 :                 c->order_unconstrained = true;
    4656              :               else
    4657              :                 {
    4658            3 :                   gfc_error ("Expected ORDER(CONCURRENT) at %C "
    4659              :                              "with optional %<reproducible%> or "
    4660              :                              "%<unconstrained%> modifier");
    4661            3 :                   goto error;
    4662              :                 }
    4663          234 :               c->order_concurrent = true;
    4664          234 :               continue;
    4665              :             }
    4666              :           break;
    4667         3116 :         case 'p':
    4668         3116 :           if (mask & OMP_CLAUSE_PARTIAL)
    4669              :             {
    4670          277 :               if ((m = gfc_match_dupl_check (!c->partial, "partial"))
    4671              :                   != MATCH_NO)
    4672              :                 {
    4673          277 :                   int expr;
    4674          277 :                   if (m == MATCH_ERROR)
    4675            0 :                     goto error;
    4676              : 
    4677          277 :                   c->partial = -1;
    4678              : 
    4679          277 :                   gfc_expr *cexpr = NULL;
    4680          277 :                   m = gfc_match (" ( %e )", &cexpr);
    4681          277 :                   if (m == MATCH_NO)
    4682              :                     ;
    4683          252 :                   else if (m == MATCH_YES
    4684          252 :                            && !gfc_extract_int (cexpr, &expr, -1)
    4685          504 :                            && expr > 0)
    4686          248 :                     c->partial = expr;
    4687              :                   else
    4688            4 :                     gfc_error_now ("PARTIAL clause argument not constant "
    4689              :                                    "positive integer at %C");
    4690          277 :                   gfc_free_expr (cexpr);
    4691          277 :                   continue;
    4692          277 :                 }
    4693              :             }
    4694         2908 :           if ((mask & OMP_CLAUSE_COPY)
    4695          877 :               && gfc_match ("pcopy ( ") == MATCH_YES
    4696         2909 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4697              :                                            OMP_MAP_TOFROM, true, allow_derived))
    4698           69 :             continue;
    4699         2844 :           if ((mask & OMP_CLAUSE_COPYIN)
    4700         1918 :               && gfc_match ("pcopyin ( ") == MATCH_YES
    4701         2844 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4702              :                                            OMP_MAP_TO, true, allow_derived))
    4703           74 :             continue;
    4704         2769 :           if ((mask & OMP_CLAUSE_COPYOUT)
    4705          735 :               && gfc_match ("pcopyout ( ") == MATCH_YES
    4706         2769 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4707              :                                            OMP_MAP_FROM, true, allow_derived))
    4708           73 :             continue;
    4709         2638 :           if ((mask & OMP_CLAUSE_CREATE)
    4710          672 :               && gfc_match ("pcreate ( ") == MATCH_YES
    4711         2638 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4712              :                                            OMP_MAP_ALLOC, true, allow_derived))
    4713           15 :             continue;
    4714         3024 :           if ((mask & OMP_CLAUSE_PRESENT)
    4715          647 :               && gfc_match ("present ( ") == MATCH_YES
    4716         3026 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4717              :                                            OMP_MAP_FORCE_PRESENT, false,
    4718              :                                            allow_derived))
    4719          416 :             continue;
    4720         2215 :           if ((mask & OMP_CLAUSE_COPY)
    4721          231 :               && gfc_match ("present_or_copy ( ") == MATCH_YES
    4722         2215 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4723              :                                            OMP_MAP_TOFROM, true,
    4724              :                                            allow_derived))
    4725           23 :             continue;
    4726         2209 :           if ((mask & OMP_CLAUSE_COPYIN)
    4727         1317 :               && gfc_match ("present_or_copyin ( ") == MATCH_YES
    4728         2209 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4729              :                                            OMP_MAP_TO, true, allow_derived))
    4730           40 :             continue;
    4731         2164 :           if ((mask & OMP_CLAUSE_COPYOUT)
    4732          173 :               && gfc_match ("present_or_copyout ( ") == MATCH_YES
    4733         2164 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4734              :                                            OMP_MAP_FROM, true, allow_derived))
    4735           35 :             continue;
    4736         2122 :           if ((mask & OMP_CLAUSE_CREATE)
    4737          143 :               && gfc_match ("present_or_create ( ") == MATCH_YES
    4738         2122 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4739              :                                            OMP_MAP_ALLOC, true, allow_derived))
    4740           28 :             continue;
    4741         2101 :           if ((mask & OMP_CLAUSE_PRIORITY)
    4742         2066 :               && (m = gfc_match_dupl_check (!c->priority, "priority", true,
    4743              :                                             &c->priority)) != MATCH_NO)
    4744              :             {
    4745           35 :               if (m == MATCH_ERROR)
    4746            0 :                 goto error;
    4747           35 :               continue;
    4748              :             }
    4749         3985 :           if ((mask & OMP_CLAUSE_PRIVATE)
    4750         2031 :               && gfc_match_omp_variable_list ("private (",
    4751              :                                               &c->lists[OMP_LIST_PRIVATE],
    4752              :                                               true) == MATCH_YES)
    4753         1954 :             continue;
    4754          141 :           if ((mask & OMP_CLAUSE_PROC_BIND)
    4755          141 :               && (m = gfc_match_dupl_check ((c->proc_bind
    4756           64 :                                              == OMP_PROC_BIND_UNKNOWN),
    4757              :                                             "proc_bind", true)) != MATCH_NO)
    4758              :             {
    4759           64 :               if (m == MATCH_ERROR)
    4760            0 :                 goto error;
    4761           64 :               if (gfc_match ("primary )") == MATCH_YES)
    4762            1 :                 c->proc_bind = OMP_PROC_BIND_PRIMARY;
    4763           63 :               else if (gfc_match ("master )") == MATCH_YES)
    4764              :                 {
    4765            9 :                   gfc_warning (OPT_Wdeprecated_openmp,
    4766              :                                "%<master%> affinity policy at %C deprecated "
    4767              :                                "since OpenMP 5.1, use %<primary%>");
    4768            9 :                   c->proc_bind = OMP_PROC_BIND_MASTER;
    4769              :                 }
    4770           54 :               else if (gfc_match ("spread )") == MATCH_YES)
    4771           53 :                 c->proc_bind = OMP_PROC_BIND_SPREAD;
    4772            1 :               else if (gfc_match ("close )") == MATCH_YES)
    4773            1 :                 c->proc_bind = OMP_PROC_BIND_CLOSE;
    4774              :               else
    4775            0 :                 goto error;
    4776           64 :               continue;
    4777              :             }
    4778              :           break;
    4779         4620 :         case 'r':
    4780         5121 :           if ((mask & OMP_CLAUSE_ATOMIC)
    4781         5167 :               && (m = gfc_match_dupl_atomic (&bval, "read",
    4782          547 :                         c->atomic_op != GFC_OMP_ATOMIC_UNSET)) != MATCH_NO)
    4783              :             {
    4784          501 :               if (m == MATCH_ERROR)
    4785            0 :                 goto error;
    4786          501 :               if (bval)
    4787          493 :                 c->atomic_op = GFC_OMP_ATOMIC_READ;
    4788          501 :               continue;
    4789              :             }
    4790         8183 :           if ((mask & OMP_CLAUSE_REDUCTION)
    4791         4119 :               && gfc_match_omp_clause_reduction (pc, c, openacc,
    4792              :                                                  allow_derived) == MATCH_YES)
    4793         4064 :             continue;
    4794           74 :           if ((mask & OMP_CLAUSE_MEMORDER)
    4795          101 :               && (m = gfc_match_dupl_memorder (&bval, "relaxed",
    4796           46 :                         c->memorder != OMP_MEMORDER_UNSET)) != MATCH_NO)
    4797              :             {
    4798           19 :               if (m == MATCH_ERROR)
    4799            0 :                 goto error;
    4800           19 :               if (bval)
    4801           12 :                 c->memorder = OMP_MEMORDER_RELAXED;
    4802           19 :               continue;
    4803              :             }
    4804           61 :           if ((mask & OMP_CLAUSE_MEMORDER)
    4805           63 :               && (m = gfc_match_dupl_memorder (&bval, "release",
    4806           27 :                         c->memorder != OMP_MEMORDER_UNSET)) != MATCH_NO)
    4807              :             {
    4808           27 :               if (m == MATCH_ERROR)
    4809            2 :                 goto error;
    4810           25 :               if (bval)
    4811           17 :                 c->memorder = OMP_MEMORDER_RELEASE;
    4812           25 :               continue;
    4813              :             }
    4814              :           break;
    4815         3114 :         case 's':
    4816         3209 :           if ((mask & OMP_CLAUSE_SAFELEN)
    4817         3114 :               && (m = gfc_match_dupl_check (!c->safelen_expr, "safelen",
    4818              :                                             true, &c->safelen_expr))
    4819              :                  != MATCH_NO)
    4820              :             {
    4821           95 :               if (m == MATCH_ERROR)
    4822            0 :                 goto error;
    4823           95 :               continue;
    4824              :             }
    4825         3019 :           if ((mask & OMP_CLAUSE_SCHEDULE)
    4826         3019 :               && (m = gfc_match_dupl_check (c->sched_kind == OMP_SCHED_NONE,
    4827              :                                             "schedule", true)) != MATCH_NO)
    4828              :             {
    4829          809 :               if (m == MATCH_ERROR)
    4830            0 :                 goto error;
    4831          809 :               int nmodifiers = 0;
    4832          809 :               locus old_loc2 = gfc_current_locus;
    4833          827 :               do
    4834              :                 {
    4835          818 :                   if (gfc_match ("simd") == MATCH_YES)
    4836              :                     {
    4837           18 :                       c->sched_simd = true;
    4838           18 :                       nmodifiers++;
    4839              :                     }
    4840          800 :                   else if (gfc_match ("monotonic") == MATCH_YES)
    4841              :                     {
    4842           30 :                       c->sched_monotonic = true;
    4843           30 :                       nmodifiers++;
    4844              :                     }
    4845          770 :                   else if (gfc_match ("nonmonotonic") == MATCH_YES)
    4846              :                     {
    4847           35 :                       c->sched_nonmonotonic = true;
    4848           35 :                       nmodifiers++;
    4849              :                     }
    4850              :                   else
    4851              :                     {
    4852          735 :                       if (nmodifiers)
    4853            0 :                         gfc_current_locus = old_loc2;
    4854              :                       break;
    4855              :                     }
    4856           92 :                   if (nmodifiers == 1
    4857           83 :                       && gfc_match (" , ") == MATCH_YES)
    4858            9 :                     continue;
    4859           74 :                   else if (gfc_match (" : ") == MATCH_YES)
    4860              :                     break;
    4861            0 :                   gfc_current_locus = old_loc2;
    4862            0 :                   break;
    4863              :                 }
    4864              :               while (1);
    4865          809 :               if (gfc_match ("static") == MATCH_YES)
    4866          425 :                 c->sched_kind = OMP_SCHED_STATIC;
    4867          384 :               else if (gfc_match ("dynamic") == MATCH_YES)
    4868          164 :                 c->sched_kind = OMP_SCHED_DYNAMIC;
    4869          220 :               else if (gfc_match ("guided") == MATCH_YES)
    4870          127 :                 c->sched_kind = OMP_SCHED_GUIDED;
    4871           93 :               else if (gfc_match ("runtime") == MATCH_YES)
    4872           85 :                 c->sched_kind = OMP_SCHED_RUNTIME;
    4873            8 :               else if (gfc_match ("auto") == MATCH_YES)
    4874            8 :                 c->sched_kind = OMP_SCHED_AUTO;
    4875          809 :               if (c->sched_kind != OMP_SCHED_NONE)
    4876              :                 {
    4877          809 :                   m = MATCH_NO;
    4878          809 :                   if (c->sched_kind != OMP_SCHED_RUNTIME
    4879          724 :                       && c->sched_kind != OMP_SCHED_AUTO)
    4880          716 :                     m = gfc_match (" , %e )", &c->chunk_size);
    4881          716 :                   if (m != MATCH_YES)
    4882          299 :                     m = gfc_match_char (')');
    4883          299 :                   if (m != MATCH_YES)
    4884            0 :                     c->sched_kind = OMP_SCHED_NONE;
    4885              :                 }
    4886          809 :               if (c->sched_kind != OMP_SCHED_NONE)
    4887          809 :                 continue;
    4888              :               else
    4889            0 :                 gfc_current_locus = old_loc;
    4890              :             }
    4891         2393 :           if ((mask & OMP_CLAUSE_SELF)
    4892          335 :               && !(mask & OMP_CLAUSE_HOST) /* OpenACC compute construct */
    4893         2450 :               && (m = gfc_match_dupl_check (!c->self_expr, "self"))
    4894              :                   != MATCH_NO)
    4895              :             {
    4896          186 :               if (m == MATCH_ERROR)
    4897            3 :                 goto error;
    4898          183 :               m = gfc_match (" ( %e )", &c->self_expr);
    4899          183 :               if (m == MATCH_ERROR)
    4900              :                 {
    4901            0 :                   gfc_current_locus = old_loc;
    4902            0 :                   break;
    4903              :                 }
    4904          183 :               else if (m == MATCH_NO)
    4905            9 :                 c->self_expr = gfc_get_logical_expr (gfc_default_logical_kind,
    4906              :                                                      NULL, true);
    4907          183 :               continue;
    4908              :             }
    4909         2118 :           if ((mask & OMP_CLAUSE_SELF)
    4910          149 :               && (mask & OMP_CLAUSE_HOST) /* OpenACC 'update' directive */
    4911           95 :               && gfc_match ("self ( ") == MATCH_YES
    4912         2119 :               && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
    4913              :                                            OMP_MAP_FORCE_FROM, true,
    4914              :                                            /* allow_derived = */ true))
    4915           94 :             continue;
    4916         2278 :           if ((mask & OMP_CLAUSE_SEQ)
    4917         1930 :               && (m = gfc_match_dupl_check (!c->seq, "seq")) != MATCH_NO)
    4918              :             {
    4919          348 :               if (m == MATCH_ERROR)
    4920            0 :                 goto error;
    4921          348 :               c->seq = true;
    4922          348 :               continue;
    4923              :             }
    4924         1731 :           if ((mask & OMP_CLAUSE_MEMORDER)
    4925         1731 :               && (m = gfc_match_dupl_memorder (&bval, "seq_cst",
    4926          149 :                         c->memorder != OMP_MEMORDER_UNSET)) != MATCH_NO)
    4927              :             {
    4928          149 :               if (m == MATCH_ERROR)
    4929            0 :                 goto error;
    4930          149 :               if (bval)
    4931          143 :                 c->memorder = OMP_MEMORDER_SEQ_CST;
    4932          149 :               continue;
    4933              :             }
    4934         2415 :           if ((mask & OMP_CLAUSE_SHARED)
    4935         1433 :               && gfc_match_omp_variable_list ("shared (",
    4936              :                                               &c->lists[OMP_LIST_SHARED],
    4937              :                                               true) == MATCH_YES)
    4938          982 :             continue;
    4939          451 :           if ((mask & OMP_CLAUSE_SIMDLEN)
    4940          451 :               && (m = gfc_match_dupl_check (!c->simdlen_expr, "simdlen",
    4941              :                                             true)) != MATCH_NO)
    4942              :             {
    4943          151 :               if (m == MATCH_ERROR)
    4944            0 :                 goto error;
    4945          151 :               if (gfc_match ("scaled ( ") == MATCH_YES)
    4946              :                 {
    4947           27 :                   old_loc = gfc_current_locus;
    4948           27 :                   gfc_typespec ts;
    4949              :                   /* This does not match 'type(integer)'; should it?  */
    4950           27 :                   if (gfc_match_type_spec (&ts) != MATCH_YES
    4951           27 :                       || (ts.type != BT_INTEGER && ts.type != BT_UNSIGNED
    4952              :                           && ts.type != BT_REAL && ts.type != BT_COMPLEX))
    4953              :                     {
    4954            2 :                       gfc_error ("Expected numerical type name at %L",
    4955              :                                  &old_loc);
    4956            5 :                       goto error;
    4957              :                     }
    4958           25 :                   c->simdlen_type.type = ts.type;
    4959           25 :                   c->simdlen_type.kind = ts.kind;
    4960           25 :                   if (gfc_match (" , ") == MATCH_YES)
    4961              :                     {
    4962           17 :                       if (gfc_match_expr (&c->simdlen_divisor) != MATCH_YES)
    4963              :                         {
    4964            0 :                           gfc_error ("Expected divisor expression at %C");
    4965            0 :                           goto error;
    4966              :                         }
    4967              :                     }
    4968           25 :                   if (gfc_match (" ) ") != MATCH_YES)
    4969              :                     {
    4970            2 :                       gfc_error ("Expected %<)%> at %C");
    4971            2 :                       goto error;
    4972              :                     }
    4973           23 :                   if (gfc_match (" : ") != MATCH_YES)
    4974              :                     {
    4975            1 :                       gfc_error ("Expected %<:%> at %C");
    4976            1 :                       goto error;
    4977              :                     }
    4978              :                 }
    4979          146 :               if (gfc_match_expr (&c->simdlen_expr) != MATCH_YES)
    4980              :                 {
    4981            0 :                   gfc_error ("Expected length expression at %C");
    4982            0 :                   goto error;
    4983              :                 }
    4984          146 :               if (gfc_match (" ) ") != MATCH_YES)
    4985              :                 {
    4986            0 :                   gfc_error ("Expected %<)%> at %C");
    4987            0 :                   goto error;
    4988              :                 }
    4989          146 :               continue;
    4990          146 :             }
    4991          326 :           if ((mask & OMP_CLAUSE_SIMD)
    4992          326 :               && ((m = gfc_match_boolean_clause (&bval, "simd",
    4993           26 :                                                  c->simd || cfalse->simd))
    4994              :                   != MATCH_NO))
    4995              :             {
    4996           26 :               if (m == MATCH_ERROR)
    4997            0 :                 goto error;
    4998           26 :               if (bval)
    4999           24 :                 c->simd = true;
    5000              :               else
    5001            2 :                 cfalse->simd = false;
    5002           26 :               continue;
    5003              :             }
    5004          331 :           if ((mask & OMP_CLAUSE_SEVERITY)
    5005          274 :               && (m = gfc_match_dupl_check (!c->severity, "severity", true))
    5006              :                  != MATCH_NO)
    5007              :             {
    5008           63 :               if (m == MATCH_ERROR)
    5009            2 :                 goto error;
    5010           61 :               if (gfc_match ("fatal )") == MATCH_YES)
    5011           12 :                 c->severity = OMP_SEVERITY_FATAL;
    5012           49 :               else if (gfc_match ("warning )") == MATCH_YES)
    5013           45 :                 c->severity = OMP_SEVERITY_WARNING;
    5014              :               else
    5015              :                 {
    5016            4 :                   gfc_error ("Expected FATAL or WARNING in SEVERITY clause "
    5017              :                              "at %C");
    5018            4 :                   goto error;
    5019              :                 }
    5020           57 :               continue;
    5021              :             }
    5022          211 :           if ((mask & OMP_CLAUSE_SIZES)
    5023          211 :               && ((m = gfc_match_dupl_check (!c->sizes_list, "sizes"))
    5024              :                   != MATCH_NO))
    5025              :             {
    5026          205 :               if (m == MATCH_ERROR)
    5027            0 :                 goto error;
    5028          205 :               m = match_omp_oacc_expr_list (" (", &c->sizes_list, false, true);
    5029          205 :               if (m == MATCH_ERROR)
    5030            7 :                 goto error;
    5031          198 :               if (m == MATCH_YES)
    5032          197 :                 continue;
    5033            1 :               gfc_error ("Expected %<(%> after %qs at %C", "sizes");
    5034            1 :               goto error;
    5035              :             }
    5036              :           break;
    5037         1355 :         case 't':
    5038         1420 :           if ((mask & OMP_CLAUSE_TASK_REDUCTION)
    5039         1355 :               && gfc_match_omp_clause_reduction (pc, c, openacc,
    5040              :                                                  allow_derived) == MATCH_YES)
    5041           65 :             continue;
    5042         1290 :           if ((mask & OMP_CLAUSE_THREAD_LIMIT)
    5043         1290 :               && (m = gfc_match_dupl_check (!c->thread_limit_list, "thread_limit",
    5044              :                                             true, NULL)) != MATCH_NO)
    5045              :             {
    5046          164 :               int nstrict = 0, nrelaxed = 0, ndims = 0;
    5047          164 :               bool fail = false;
    5048          164 :               gfc_expr *dims = NULL;
    5049          164 :               locus old_loc = gfc_current_locus;
    5050              : 
    5051          164 :               if (m == MATCH_ERROR)
    5052           28 :                 goto error;
    5053          220 :               while (true)
    5054              :                 {
    5055          191 :                   if (gfc_match ("strict ") == MATCH_YES)
    5056           29 :                     nstrict++;
    5057          162 :                   else if (gfc_match ("relaxed ") == MATCH_YES)
    5058           31 :                     nrelaxed++;
    5059          131 :                   else if (gfc_match ("dims ") == MATCH_YES)
    5060              :                     {
    5061           37 :                       ndims++;
    5062           37 :                       if (dims)
    5063            3 :                         gfc_free_expr (dims);
    5064           37 :                       if (gfc_match ("( %e ) ", &dims) != MATCH_YES)
    5065              :                         break;
    5066              :                     }
    5067              :                   else
    5068              :                     {
    5069              :                       fail = true;
    5070              :                       break;
    5071              :                     }
    5072           96 :                   if (gfc_match (", ") == MATCH_YES)
    5073           29 :                     continue;
    5074              :                   break;
    5075              :                 }
    5076          162 :               if (gfc_match (" : ") == MATCH_YES)
    5077              :                 {
    5078           65 :                   if (nstrict + nrelaxed + ndims == 0 || fail)
    5079              :                     {
    5080            1 :                       gfc_error ("Expected STRICT, RELAXED or DIMS modifier at "
    5081              :                                  "%C");
    5082            1 :                       goto error;
    5083              :                     }
    5084           64 :                   else if (nstrict + nrelaxed > 1)
    5085              :                     {
    5086            8 :                       gfc_error ("Only one STRICT or RELAXED modifier permitted"
    5087              :                                  " at %L", &old_loc);
    5088            8 :                       goto error;
    5089              :                     }
    5090           56 :                   if (ndims > 1)
    5091              :                     {
    5092            3 :                       gfc_error ("Duplicated DIMS expression at %L",
    5093            3 :                                  &dims->where);
    5094            3 :                       goto error;
    5095              :                     }
    5096              :                 }
    5097              :               else
    5098              :                 {
    5099           97 :                   gfc_free_expr (dims);
    5100           97 :                   dims = NULL;
    5101           97 :                   gfc_current_locus = old_loc;
    5102              :                 }
    5103              : 
    5104          150 :               m = match_omp_oacc_expr_list (NULL, &c->thread_limit_list,
    5105              :                                             false, true);
    5106          150 :               if (m != MATCH_YES)
    5107              :                 {
    5108            7 :                   gfc_error ("Expected a list of integer expressions followed "
    5109              :                              "by a %<)%> and optionally preceded by the STRICT,"
    5110              :                              " RELAXED, or DIMS as modifiers and a colon at %C");
    5111            7 :                   goto error;
    5112              :                 }
    5113          143 :               c->thread_limit_strict = (nstrict != 0) || (dims && !nrelaxed);
    5114              : 
    5115          143 :               if (!dims && c->thread_limit_list->next)
    5116              :                 {
    5117            1 :                   gfc_error ("Without the DIM modifier, only a single integer "
    5118              :                              "expression may be specified at %L",
    5119            1 :                              &c->thread_limit_list->next->expr->where);
    5120            1 :                   goto error;
    5121              :                 }
    5122          142 :               else if (dims)
    5123              :                 {
    5124           22 :                   int num = 0;
    5125           22 :                   gfc_expr_list *el;
    5126           73 :                   for (el = c->thread_limit_list; el; el = el->next)
    5127           51 :                     ++num;
    5128           22 :                   if (!gfc_resolve_expr (dims)
    5129           22 :                       || dims->ts.type != BT_INTEGER
    5130           21 :                       || dims->rank != 0
    5131           20 :                       || dims->expr_type != EXPR_CONSTANT
    5132           40 :                       || mpz_sgn (dims->value.integer) <= 0)
    5133              :                     {
    5134            5 :                       gfc_error ("DIMS must be a constant positive integer "
    5135            5 :                                  "at %L", &dims->where);
    5136            5 :                       goto error;
    5137              :                     }
    5138           17 :                   if (mpz_cmp_si (dims->value.integer, num) != 0)
    5139              :                     {
    5140            1 :                       gfc_error ("The number of arguments (%d) must be the same"
    5141              :                                  " as specified for DIMS at %L", num,
    5142              :                                  &dims->where);
    5143            1 :                       goto error;
    5144              :                     }
    5145           16 :                   c->thread_limit_dims = true;
    5146              :                 }
    5147          136 :               continue;
    5148          136 :             }
    5149         1143 :           if ((mask & OMP_CLAUSE_THREADS)
    5150         1143 :               && ((m = gfc_match_boolean_clause (&bval, "threads",
    5151           17 :                                                  c->threads || cfalse->threads))
    5152              :                   != MATCH_NO))
    5153              :             {
    5154           17 :               if (m == MATCH_ERROR)
    5155            0 :                 goto error;
    5156           17 :               if (bval)
    5157           15 :                 c->threads = true;
    5158              :               else
    5159            2 :                 cfalse->threads = false;
    5160           17 :               continue;
    5161              :             }
    5162         1306 :           if ((mask & OMP_CLAUSE_TILE)
    5163          221 :               && !c->tile_list
    5164         1330 :               && match_omp_oacc_expr_list ("tile (", &c->tile_list,
    5165              :                                            true, false) == MATCH_YES)
    5166          197 :             continue;
    5167          912 :           if ((mask & OMP_CLAUSE_TO) && (mask & OMP_CLAUSE_LINK))
    5168              :             {
    5169              :               /* Declare target: 'to' is an alias for 'enter';
    5170              :                  'to' is deprecated since 5.2.  */
    5171          117 :               m = gfc_match_omp_to_link ("to (", &c->lists[OMP_LIST_TO]);
    5172          117 :               if (m == MATCH_ERROR)
    5173            0 :                 goto error;
    5174          117 :               if (m == MATCH_YES)
    5175              :                 {
    5176          117 :                   gfc_warning (OPT_Wdeprecated_openmp,
    5177              :                                "%<to%> clause with %<declare target%> at %L "
    5178              :                                "deprecated since OpenMP 5.2, use %<enter%>",
    5179              :                                &old_loc);
    5180          117 :                   continue;
    5181              :                 }
    5182              :             }
    5183         1559 :           else if ((mask & OMP_CLAUSE_TO)
    5184          795 :                    && gfc_match_motion_var_list ("to (", &c->lists[OMP_LIST_TO],
    5185              :                                                  &head) == MATCH_YES)
    5186          764 :             continue;
    5187              :           break;
    5188         1551 :         case 'u':
    5189         1609 :           if ((mask & OMP_CLAUSE_UNIFORM)
    5190         1551 :               && gfc_match_omp_variable_list ("uniform (",
    5191              :                                               &c->lists[OMP_LIST_UNIFORM],
    5192              :                                               false) == MATCH_YES)
    5193           58 :             continue;
    5194         1636 :           if ((mask & OMP_CLAUSE_UNTIED)
    5195         1636 :               && ((m = gfc_match_boolean_clause (&bval, "untied",
    5196          143 :                                                  c->untied || cfalse->untied))
    5197              :                   != MATCH_NO))
    5198              :             {
    5199          143 :               if (m == MATCH_ERROR)
    5200            0 :                 goto error;
    5201          143 :               if (bval)
    5202          142 :                 c->untied = true;
    5203              :               else
    5204            1 :                 cfalse->untied = true;
    5205          143 :               continue;
    5206              :             }
    5207         1605 :           if ((mask & OMP_CLAUSE_ATOMIC)
    5208         1606 :               && (m = gfc_match_dupl_atomic (&bval, "update",
    5209          256 :                         c->atomic_op != GFC_OMP_ATOMIC_UNSET)) != MATCH_NO)
    5210              :             {
    5211          256 :               if (m == MATCH_ERROR)
    5212            1 :                 goto error;
    5213          255 :               if (bval)
    5214          249 :                 c->atomic_op = GFC_OMP_ATOMIC_UPDATE;
    5215          255 :               continue;
    5216              :             }
    5217         1116 :           if ((mask & OMP_CLAUSE_USE)
    5218         1094 :               && gfc_match_omp_variable_list ("use (",
    5219              :                                               &c->lists[OMP_LIST_USE],
    5220              :                                               true) == MATCH_YES)
    5221           22 :             continue;
    5222         1132 :           if ((mask & OMP_CLAUSE_USE_DEVICE)
    5223         1072 :               && gfc_match_omp_variable_list ("use_device (",
    5224              :                                               &c->lists[OMP_LIST_USE_DEVICE],
    5225              :                                               true) == MATCH_YES)
    5226           60 :             continue;
    5227         1175 :           if ((mask & OMP_CLAUSE_USE_DEVICE_PTR)
    5228         1940 :               && gfc_match_omp_variable_list
    5229          928 :                    ("use_device_ptr (",
    5230              :                     &c->lists[OMP_LIST_USE_DEVICE_PTR], false) == MATCH_YES)
    5231          163 :             continue;
    5232         1614 :           if ((mask & OMP_CLAUSE_USE_DEVICE_ADDR)
    5233         1614 :               && gfc_match_omp_variable_list
    5234          765 :                    ("use_device_addr (", &c->lists[OMP_LIST_USE_DEVICE_ADDR],
    5235              :                     false, NULL, NULL, true) == MATCH_YES)
    5236          765 :             continue;
    5237          153 :           if ((mask & OMP_CLAUSE_USES_ALLOCATORS)
    5238           84 :               && (gfc_match ("uses_allocators ( ") == MATCH_YES))
    5239              :             {
    5240           78 :               if (gfc_match_omp_clause_uses_allocators (c) != MATCH_YES)
    5241            9 :                 goto error;
    5242           69 :               continue;
    5243              :             }
    5244              :           break;
    5245         1570 :         case 'v':
    5246              :           /* VECTOR_LENGTH must be matched before VECTOR, because the latter
    5247              :              doesn't unconditionally match '('.  */
    5248         2139 :           if ((mask & OMP_CLAUSE_VECTOR_LENGTH)
    5249         1570 :               && (m = gfc_match_dupl_check (!c->vector_length_expr,
    5250              :                                             "vector_length", true,
    5251              :                                             &c->vector_length_expr))
    5252              :                  != MATCH_NO)
    5253              :             {
    5254          573 :               if (m == MATCH_ERROR)
    5255            4 :                 goto error;
    5256          569 :               continue;
    5257              :             }
    5258         1989 :           if ((mask & OMP_CLAUSE_VECTOR)
    5259          997 :               && (m = gfc_match_dupl_check (!c->vector, "vector")) != MATCH_NO)
    5260              :             {
    5261          995 :               if (m == MATCH_ERROR)
    5262            0 :                 goto error;
    5263          995 :               c->vector = true;
    5264          995 :               m = match_oacc_clause_gwv (c, GOMP_DIM_VECTOR);
    5265          995 :               if (m == MATCH_ERROR)
    5266            3 :                 goto error;
    5267          992 :               continue;
    5268              :             }
    5269              :           break;
    5270         1505 :         case 'w':
    5271         1505 :           if ((mask & OMP_CLAUSE_WAIT)
    5272         1505 :               && gfc_match ("wait") == MATCH_YES)
    5273              :             {
    5274          192 :               m = match_omp_oacc_expr_list (" (", &c->wait_list, false, false);
    5275          192 :               if (m == MATCH_ERROR)
    5276            9 :                 goto error;
    5277          183 :               else if (m == MATCH_NO)
    5278              :                 {
    5279           47 :                   gfc_expr *expr
    5280           47 :                     = gfc_get_constant_expr (BT_INTEGER,
    5281              :                                              gfc_default_integer_kind,
    5282              :                                              &gfc_current_locus);
    5283           47 :                   mpz_set_si (expr->value.integer, GOMP_ASYNC_NOVAL);
    5284           47 :                   gfc_expr_list **expr_list = &c->wait_list;
    5285           56 :                   while (*expr_list)
    5286            9 :                     expr_list = &(*expr_list)->next;
    5287           47 :                   *expr_list = gfc_get_expr_list ();
    5288           47 :                   (*expr_list)->expr = expr;
    5289           47 :                   needs_space = true;
    5290              :                 }
    5291          183 :               continue;
    5292          183 :             }
    5293         1330 :           if ((mask & OMP_CLAUSE_WEAK)
    5294         1759 :               && ((m = gfc_match_boolean_clause (&bval, "weak",
    5295          446 :                                                 c->weak || cfalse->weak))
    5296              :                   != MATCH_NO))
    5297              :             {
    5298           18 :               if (m == MATCH_ERROR)
    5299            1 :                 goto error;
    5300           17 :               if (bval)
    5301           14 :                 c->weak = true;
    5302              :               else
    5303            3 :                 cfalse->weak = true;
    5304           17 :               continue;
    5305              :             }
    5306         2156 :           if ((mask & OMP_CLAUSE_WORKER)
    5307         1295 :               && (m = gfc_match_dupl_check (!c->worker, "worker")) != MATCH_NO)
    5308              :             {
    5309          864 :               if (m == MATCH_ERROR)
    5310            0 :                 goto error;
    5311          864 :               c->worker = true;
    5312          864 :               m = match_oacc_clause_gwv (c, GOMP_DIM_WORKER);
    5313          864 :               if (m == MATCH_ERROR)
    5314            3 :                 goto error;
    5315          861 :               continue;
    5316              :             }
    5317          856 :           if ((mask & OMP_CLAUSE_ATOMIC)
    5318          859 :               && (m = gfc_match_dupl_atomic (&bval, "write",
    5319          428 :                         c->atomic_op != GFC_OMP_ATOMIC_UNSET)) != MATCH_NO)
    5320              :             {
    5321          428 :               if (m == MATCH_ERROR)
    5322            3 :                 goto error;
    5323          425 :               if (bval)
    5324          418 :                 c->atomic_op = GFC_OMP_ATOMIC_WRITE;
    5325          425 :               continue;
    5326              :             }
    5327              :           break;
    5328              :         }
    5329              :       break;
    5330        47571 :     }
    5331              : 
    5332        35644 : end:
    5333        35644 :   if (cfalse)
    5334        21776 :     gfc_free_omp_clauses (cfalse);
    5335        35644 :   if (error || gfc_match_omp_eos () != MATCH_YES)
    5336              :     {
    5337          676 :       if (!gfc_error_flag_test ())
    5338          152 :         gfc_error ("Failed to match clause at %C");
    5339          676 :       gfc_free_omp_clauses (c);
    5340          676 :       return MATCH_ERROR;
    5341              :     }
    5342              : 
    5343        34968 :   *cp = c;
    5344        34968 :   return MATCH_YES;
    5345              : 
    5346          377 : error:
    5347          377 :   error = true;
    5348          377 :   goto end;
    5349              : }
    5350              : 
    5351              : 
    5352              : #define OACC_PARALLEL_CLAUSES \
    5353              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_NUM_GANGS         \
    5354              :    | OMP_CLAUSE_NUM_WORKERS | OMP_CLAUSE_VECTOR_LENGTH | OMP_CLAUSE_REDUCTION \
    5355              :    | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT                 \
    5356              :    | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT            \
    5357              :    | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE      \
    5358              :    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH                 \
    5359              :    | OMP_CLAUSE_SELF)
    5360              : #define OACC_KERNELS_CLAUSES \
    5361              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_NUM_GANGS         \
    5362              :    | OMP_CLAUSE_NUM_WORKERS | OMP_CLAUSE_VECTOR_LENGTH | OMP_CLAUSE_DEVICEPTR \
    5363              :    | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT                 \
    5364              :    | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT            \
    5365              :    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH                 \
    5366              :    | OMP_CLAUSE_SELF)
    5367              : #define OACC_SERIAL_CLAUSES \
    5368              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_REDUCTION         \
    5369              :    | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT                 \
    5370              :    | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT            \
    5371              :    | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE      \
    5372              :    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH                 \
    5373              :    | OMP_CLAUSE_SELF)
    5374              : #define OACC_DATA_CLAUSES \
    5375              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_DEVICEPTR  | OMP_CLAUSE_COPY         \
    5376              :    | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT | OMP_CLAUSE_CREATE               \
    5377              :    | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT | OMP_CLAUSE_ATTACH            \
    5378              :    | OMP_CLAUSE_DEFAULT)
    5379              : #define OACC_LOOP_CLAUSES \
    5380              :   (omp_mask (OMP_CLAUSE_COLLAPSE) | OMP_CLAUSE_GANG | OMP_CLAUSE_WORKER       \
    5381              :    | OMP_CLAUSE_VECTOR | OMP_CLAUSE_SEQ | OMP_CLAUSE_INDEPENDENT              \
    5382              :    | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_AUTO              \
    5383              :    | OMP_CLAUSE_TILE)
    5384              : #define OACC_PARALLEL_LOOP_CLAUSES \
    5385              :   (OACC_LOOP_CLAUSES | OACC_PARALLEL_CLAUSES)
    5386              : #define OACC_KERNELS_LOOP_CLAUSES \
    5387              :   (OACC_LOOP_CLAUSES | OACC_KERNELS_CLAUSES)
    5388              : #define OACC_SERIAL_LOOP_CLAUSES \
    5389              :   (OACC_LOOP_CLAUSES | OACC_SERIAL_CLAUSES)
    5390              : #define OACC_HOST_DATA_CLAUSES \
    5391              :   (omp_mask (OMP_CLAUSE_USE_DEVICE)                                           \
    5392              :    | OMP_CLAUSE_IF                                                            \
    5393              :    | OMP_CLAUSE_IF_PRESENT)
    5394              : #define OACC_DECLARE_CLAUSES \
    5395              :   (omp_mask (OMP_CLAUSE_COPY) | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT        \
    5396              :    | OMP_CLAUSE_CREATE | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_DEVICE_RESIDENT    \
    5397              :    | OMP_CLAUSE_PRESENT                       \
    5398              :    | OMP_CLAUSE_LINK)
    5399              : #define OACC_UPDATE_CLAUSES                                             \
    5400              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_HOST              \
    5401              :    | OMP_CLAUSE_DEVICE | OMP_CLAUSE_WAIT | OMP_CLAUSE_IF_PRESENT              \
    5402              :    | OMP_CLAUSE_SELF)
    5403              : #define OACC_ENTER_DATA_CLAUSES \
    5404              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_WAIT              \
    5405              :    | OMP_CLAUSE_COPYIN | OMP_CLAUSE_CREATE | OMP_CLAUSE_ATTACH)
    5406              : #define OACC_EXIT_DATA_CLAUSES \
    5407              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_WAIT              \
    5408              :    | OMP_CLAUSE_COPYOUT | OMP_CLAUSE_DELETE | OMP_CLAUSE_FINALIZE             \
    5409              :    | OMP_CLAUSE_DETACH)
    5410              : #define OACC_WAIT_CLAUSES \
    5411              :   omp_mask (OMP_CLAUSE_ASYNC) | OMP_CLAUSE_IF
    5412              : #define OACC_ROUTINE_CLAUSES \
    5413              :   (omp_mask (OMP_CLAUSE_GANG) | OMP_CLAUSE_WORKER | OMP_CLAUSE_VECTOR         \
    5414              :    | OMP_CLAUSE_SEQ                                                           \
    5415              :    | OMP_CLAUSE_NOHOST)
    5416              : #define OACC_INIT_CLAUSES                                                      \
    5417              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_DEVICE_NUM | OMP_CLAUSE_DEVICE_TYPE)
    5418              : #define OACC_SHUTDOWN_CLAUSES                                                  \
    5419              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_DEVICE_NUM | OMP_CLAUSE_DEVICE_TYPE)
    5420              : #define OACC_SET_CLAUSES                                                       \
    5421              :   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_DEVICE_NUM | OMP_CLAUSE_DEVICE_TYPE)
    5422              : 
    5423              : 
    5424              : static match
    5425        12198 : match_acc (gfc_exec_op op, const omp_mask mask)
    5426              : {
    5427        12198 :   gfc_omp_clauses *c;
    5428        12198 :   if (gfc_match_omp_clauses (&c, mask, false, false, true) != MATCH_YES)
    5429              :     return MATCH_ERROR;
    5430        11969 :   new_st.op = op;
    5431        11969 :   new_st.ext.omp_clauses = c;
    5432        11969 :   return MATCH_YES;
    5433              : }
    5434              : 
    5435              : match
    5436         1378 : gfc_match_oacc_parallel_loop (void)
    5437              : {
    5438         1378 :   return match_acc (EXEC_OACC_PARALLEL_LOOP, OACC_PARALLEL_LOOP_CLAUSES);
    5439              : }
    5440              : 
    5441              : 
    5442              : match
    5443         2974 : gfc_match_oacc_parallel (void)
    5444              : {
    5445         2974 :   return match_acc (EXEC_OACC_PARALLEL, OACC_PARALLEL_CLAUSES);
    5446              : }
    5447              : 
    5448              : 
    5449              : match
    5450          129 : gfc_match_oacc_kernels_loop (void)
    5451              : {
    5452          129 :   return match_acc (EXEC_OACC_KERNELS_LOOP, OACC_KERNELS_LOOP_CLAUSES);
    5453              : }
    5454              : 
    5455              : 
    5456              : match
    5457          906 : gfc_match_oacc_kernels (void)
    5458              : {
    5459          906 :   return match_acc (EXEC_OACC_KERNELS, OACC_KERNELS_CLAUSES);
    5460              : }
    5461              : 
    5462              : 
    5463              : match
    5464          230 : gfc_match_oacc_serial_loop (void)
    5465              : {
    5466          230 :   return match_acc (EXEC_OACC_SERIAL_LOOP, OACC_SERIAL_LOOP_CLAUSES);
    5467              : }
    5468              : 
    5469              : 
    5470              : match
    5471          359 : gfc_match_oacc_serial (void)
    5472              : {
    5473          359 :   return match_acc (EXEC_OACC_SERIAL, OACC_SERIAL_CLAUSES);
    5474              : }
    5475              : 
    5476              : 
    5477              : match
    5478          689 : gfc_match_oacc_data (void)
    5479              : {
    5480          689 :   return match_acc (EXEC_OACC_DATA, OACC_DATA_CLAUSES);
    5481              : }
    5482              : 
    5483              : 
    5484              : match
    5485           65 : gfc_match_oacc_host_data (void)
    5486              : {
    5487           65 :   return match_acc (EXEC_OACC_HOST_DATA, OACC_HOST_DATA_CLAUSES);
    5488              : }
    5489              : 
    5490              : 
    5491              : match
    5492         3585 : gfc_match_oacc_loop (void)
    5493              : {
    5494         3585 :   return match_acc (EXEC_OACC_LOOP, OACC_LOOP_CLAUSES);
    5495              : }
    5496              : 
    5497              : 
    5498              : match
    5499          178 : gfc_match_oacc_declare (void)
    5500              : {
    5501          178 :   gfc_omp_clauses *c;
    5502          178 :   gfc_omp_namelist *n;
    5503          178 :   gfc_namespace *ns = gfc_current_ns;
    5504          178 :   gfc_oacc_declare *new_oc;
    5505          178 :   bool module_var = false;
    5506          178 :   locus where = gfc_current_locus;
    5507              : 
    5508          178 :   if (gfc_match_omp_clauses (&c, OACC_DECLARE_CLAUSES, false, false, true)
    5509              :       != MATCH_YES)
    5510              :     return MATCH_ERROR;
    5511              : 
    5512          262 :   for (n = c->lists[OMP_LIST_DEVICE_RESIDENT]; n != NULL; n = n->next)
    5513           90 :     n->sym->attr.oacc_declare_device_resident = 1;
    5514              : 
    5515          192 :   for (n = c->lists[OMP_LIST_LINK]; n != NULL; n = n->next)
    5516           20 :     n->sym->attr.oacc_declare_link = 1;
    5517              : 
    5518          318 :   for (n = c->lists[OMP_LIST_MAP]; n != NULL; n = n->next)
    5519              :     {
    5520          156 :       gfc_symbol *s = n->sym;
    5521              : 
    5522          156 :       if (gfc_current_ns->proc_name
    5523          156 :           && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
    5524              :         {
    5525           52 :           if (n->u.map.op != OMP_MAP_ALLOC && n->u.map.op != OMP_MAP_TO)
    5526              :             {
    5527            6 :               gfc_error ("Invalid clause in module with !$ACC DECLARE at %L",
    5528              :                          &where);
    5529            6 :               return MATCH_ERROR;
    5530              :             }
    5531              : 
    5532              :           module_var = true;
    5533              :         }
    5534              : 
    5535          150 :       if (s->attr.use_assoc)
    5536              :         {
    5537            0 :           gfc_error ("Variable is USE-associated with !$ACC DECLARE at %L",
    5538              :                      &where);
    5539            0 :           return MATCH_ERROR;
    5540              :         }
    5541              : 
    5542          150 :       if ((s->result == s && s->ns->contained != gfc_current_ns)
    5543          150 :           || ((s->attr.flavor == FL_UNKNOWN || s->attr.flavor == FL_VARIABLE)
    5544          135 :               && s->ns != gfc_current_ns))
    5545              :         {
    5546            2 :           gfc_error ("Variable %qs shall be declared in the same scoping unit "
    5547              :                      "as !$ACC DECLARE at %L", s->name, &where);
    5548            2 :           return MATCH_ERROR;
    5549              :         }
    5550              : 
    5551          148 :       if ((s->attr.dimension || s->attr.codimension)
    5552           76 :           && s->attr.dummy && s->as->type != AS_EXPLICIT)
    5553              :         {
    5554            2 :           gfc_error ("Assumed-size dummy array with !$ACC DECLARE at %L",
    5555              :                      &where);
    5556            2 :           return MATCH_ERROR;
    5557              :         }
    5558              : 
    5559          146 :       switch (n->u.map.op)
    5560              :         {
    5561           49 :           case OMP_MAP_FORCE_ALLOC:
    5562           49 :           case OMP_MAP_ALLOC:
    5563           49 :             s->attr.oacc_declare_create = 1;
    5564           49 :             break;
    5565              : 
    5566           63 :           case OMP_MAP_FORCE_TO:
    5567           63 :           case OMP_MAP_TO:
    5568           63 :             s->attr.oacc_declare_copyin = 1;
    5569           63 :             break;
    5570              : 
    5571            1 :           case OMP_MAP_FORCE_DEVICEPTR:
    5572            1 :             s->attr.oacc_declare_deviceptr = 1;
    5573            1 :             break;
    5574              : 
    5575              :           default:
    5576              :             break;
    5577              :         }
    5578              :     }
    5579              : 
    5580          162 :   new_oc = gfc_get_oacc_declare ();
    5581          162 :   new_oc->next = ns->oacc_declare;
    5582          162 :   new_oc->module_var = module_var;
    5583          162 :   new_oc->clauses = c;
    5584          162 :   new_oc->loc = gfc_current_locus;
    5585          162 :   ns->oacc_declare = new_oc;
    5586              : 
    5587          162 :   return MATCH_YES;
    5588              : }
    5589              : 
    5590              : 
    5591              : match
    5592          760 : gfc_match_oacc_update (void)
    5593              : {
    5594          760 :   gfc_omp_clauses *c;
    5595          760 :   locus here = gfc_current_locus;
    5596              : 
    5597          760 :   if (gfc_match_omp_clauses (&c, OACC_UPDATE_CLAUSES, false, false, true)
    5598              :       != MATCH_YES)
    5599              :     return MATCH_ERROR;
    5600              : 
    5601          756 :   if (!c->lists[OMP_LIST_MAP])
    5602              :     {
    5603            1 :       gfc_error ("%<acc update%> must contain at least one "
    5604              :                  "%<device%> or %<host%> or %<self%> clause at %L", &here);
    5605            1 :       return MATCH_ERROR;
    5606              :     }
    5607              : 
    5608          755 :   new_st.op = EXEC_OACC_UPDATE;
    5609          755 :   new_st.ext.omp_clauses = c;
    5610          755 :   return MATCH_YES;
    5611              : }
    5612              : 
    5613              : 
    5614              : match
    5615          877 : gfc_match_oacc_enter_data (void)
    5616              : {
    5617          877 :   return match_acc (EXEC_OACC_ENTER_DATA, OACC_ENTER_DATA_CLAUSES);
    5618              : }
    5619              : 
    5620              : 
    5621              : match
    5622          612 : gfc_match_oacc_exit_data (void)
    5623              : {
    5624          612 :   return match_acc (EXEC_OACC_EXIT_DATA, OACC_EXIT_DATA_CLAUSES);
    5625              : }
    5626              : 
    5627              : 
    5628              : match
    5629          202 : gfc_match_oacc_wait (void)
    5630              : {
    5631          202 :   gfc_omp_clauses *c = gfc_get_omp_clauses ();
    5632          202 :   gfc_expr_list *wait_list = NULL, *el;
    5633          202 :   bool space = true;
    5634          202 :   match m;
    5635              : 
    5636          202 :   m = match_omp_oacc_expr_list (" (", &wait_list, true, false);
    5637          202 :   if (m == MATCH_ERROR)
    5638              :     return m;
    5639          196 :   else if (m == MATCH_YES)
    5640          126 :     space = false;
    5641              : 
    5642          196 :   if (gfc_match_omp_clauses (&c, OACC_WAIT_CLAUSES, space, space, true)
    5643              :       == MATCH_ERROR)
    5644              :     return MATCH_ERROR;
    5645              : 
    5646          184 :   if (wait_list)
    5647          261 :     for (el = wait_list; el; el = el->next)
    5648              :       {
    5649          140 :         if (el->expr == NULL)
    5650              :           {
    5651            2 :             gfc_error ("Invalid argument to !$ACC WAIT at %C");
    5652            2 :             return MATCH_ERROR;
    5653              :           }
    5654              : 
    5655          138 :         if (!gfc_resolve_expr (el->expr)
    5656          138 :             || el->expr->ts.type != BT_INTEGER || el->expr->rank != 0)
    5657              :           {
    5658            3 :             gfc_error ("WAIT clause at %L requires a scalar INTEGER expression",
    5659            3 :                        &el->expr->where);
    5660              : 
    5661            3 :             return MATCH_ERROR;
    5662              :           }
    5663              :       }
    5664          179 :   c->wait_list = wait_list;
    5665          179 :   new_st.op = EXEC_OACC_WAIT;
    5666          179 :   new_st.ext.omp_clauses = c;
    5667          179 :   return MATCH_YES;
    5668              : }
    5669              : 
    5670              : 
    5671              : match
    5672           97 : gfc_match_oacc_cache (void)
    5673              : {
    5674           97 :   bool readonly = false;
    5675           97 :   gfc_omp_clauses *c = gfc_get_omp_clauses ();
    5676              :   /* The OpenACC cache directive explicitly only allows "array elements or
    5677              :      subarrays", which we're currently not checking here.  Either check this
    5678              :      after the call of gfc_match_omp_variable_list, or add something like a
    5679              :      only_sections variant next to its allow_sections parameter.  */
    5680           97 :   match m = gfc_match (" ( ");
    5681           97 :   if (m != MATCH_YES)
    5682              :     {
    5683            0 :       gfc_free_omp_clauses(c);
    5684            0 :       return m;
    5685              :     }
    5686              : 
    5687           97 :   if (gfc_match ("readonly : ") == MATCH_YES)
    5688            8 :     readonly = true;
    5689              : 
    5690           97 :   gfc_omp_namelist **head = NULL;
    5691           97 :   m = gfc_match_omp_variable_list ("", &c->lists[OMP_LIST_CACHE], true,
    5692              :                                    NULL, &head, true);
    5693           97 :   if (m != MATCH_YES)
    5694              :     {
    5695            2 :       gfc_free_omp_clauses(c);
    5696            2 :       return m;
    5697              :     }
    5698              : 
    5699           95 :   if (readonly)
    5700           24 :     for (gfc_omp_namelist *n = *head; n; n = n->next)
    5701           16 :       n->u.map.readonly = true;
    5702              : 
    5703           95 :   if (gfc_current_state() != COMP_DO
    5704           56 :       && gfc_current_state() != COMP_DO_CONCURRENT)
    5705              :     {
    5706            2 :       gfc_error ("ACC CACHE directive must be inside of loop %C");
    5707            2 :       gfc_free_omp_clauses(c);
    5708            2 :       return MATCH_ERROR;
    5709              :     }
    5710              : 
    5711           93 :   new_st.op = EXEC_OACC_CACHE;
    5712           93 :   new_st.ext.omp_clauses = c;
    5713           93 :   return MATCH_YES;
    5714              : }
    5715              : 
    5716              : match
    5717          134 : gfc_match_oacc_init (void)
    5718              : {
    5719          134 :   return match_acc (EXEC_OACC_INIT, OACC_INIT_CLAUSES);
    5720              : }
    5721              : 
    5722              : match
    5723          130 : gfc_match_oacc_shutdown (void)
    5724              : {
    5725          130 :   return match_acc (EXEC_OACC_SHUTDOWN, OACC_SHUTDOWN_CLAUSES);
    5726              : }
    5727              : 
    5728              : match
    5729          130 : gfc_match_oacc_set (void)
    5730              : {
    5731          130 :   return match_acc (EXEC_OACC_SET, OACC_SET_CLAUSES);
    5732              : }
    5733              : 
    5734              : /* Determine the OpenACC 'routine' directive's level of parallelism.  */
    5735              : 
    5736              : static oacc_routine_lop
    5737          734 : gfc_oacc_routine_lop (gfc_omp_clauses *clauses)
    5738              : {
    5739          734 :   oacc_routine_lop ret = OACC_ROUTINE_LOP_SEQ;
    5740              : 
    5741          734 :   if (clauses)
    5742              :     {
    5743          584 :       unsigned n_lop_clauses = 0;
    5744              : 
    5745          584 :       if (clauses->gang)
    5746              :         {
    5747          164 :           ++n_lop_clauses;
    5748          164 :           ret = OACC_ROUTINE_LOP_GANG;
    5749              :         }
    5750          584 :       if (clauses->worker)
    5751              :         {
    5752          114 :           ++n_lop_clauses;
    5753          114 :           ret = OACC_ROUTINE_LOP_WORKER;
    5754              :         }
    5755          584 :       if (clauses->vector)
    5756              :         {
    5757          116 :           ++n_lop_clauses;
    5758          116 :           ret = OACC_ROUTINE_LOP_VECTOR;
    5759              :         }
    5760          584 :       if (clauses->seq)
    5761              :         {
    5762          206 :           ++n_lop_clauses;
    5763          206 :           ret = OACC_ROUTINE_LOP_SEQ;
    5764              :         }
    5765              : 
    5766          584 :       if (n_lop_clauses > 1)
    5767           47 :         ret = OACC_ROUTINE_LOP_ERROR;
    5768              :     }
    5769              : 
    5770          734 :   return ret;
    5771              : }
    5772              : 
    5773              : match
    5774          698 : gfc_match_oacc_routine (void)
    5775              : {
    5776          698 :   locus old_loc;
    5777          698 :   match m;
    5778          698 :   gfc_intrinsic_sym *isym = NULL;
    5779          698 :   gfc_symbol *sym = NULL;
    5780          698 :   gfc_omp_clauses *c = NULL;
    5781          698 :   gfc_oacc_routine_name *n = NULL;
    5782          698 :   oacc_routine_lop lop = OACC_ROUTINE_LOP_NONE;
    5783          698 :   bool nohost;
    5784              : 
    5785          698 :   old_loc = gfc_current_locus;
    5786              : 
    5787          698 :   m = gfc_match (" (");
    5788              : 
    5789          698 :   if (gfc_current_ns->proc_name
    5790          696 :       && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY
    5791           90 :       && m == MATCH_YES)
    5792              :     {
    5793            3 :       gfc_error ("Only the !$ACC ROUTINE form without "
    5794              :                  "list is allowed in interface block at %C");
    5795            3 :       goto cleanup;
    5796              :     }
    5797              : 
    5798          608 :   if (m == MATCH_YES)
    5799              :     {
    5800          295 :       char buffer[GFC_MAX_SYMBOL_LEN + 1];
    5801              : 
    5802          295 :       m = gfc_match_name (buffer);
    5803          295 :       if (m == MATCH_YES)
    5804              :         {
    5805          294 :           gfc_symtree *st = NULL;
    5806              : 
    5807              :           /* First look for an intrinsic symbol.  */
    5808          294 :           isym = gfc_find_function (buffer);
    5809          294 :           if (!isym)
    5810          294 :             isym = gfc_find_subroutine (buffer);
    5811              :           /* If no intrinsic symbol found, search the current namespace.  */
    5812          294 :           if (!isym)
    5813          276 :             st = gfc_find_symtree (gfc_current_ns->sym_root, buffer);
    5814          276 :           if (st)
    5815              :             {
    5816          270 :               sym = st->n.sym;
    5817              :               /* If the name in a 'routine' directive refers to the containing
    5818              :                  subroutine or function, then make sure that we'll later handle
    5819              :                  this accordingly.  */
    5820          270 :               if (gfc_current_ns->proc_name != NULL
    5821          270 :                   && strcmp (sym->name, gfc_current_ns->proc_name->name) == 0)
    5822          294 :                 sym = NULL;
    5823              :             }
    5824              : 
    5825          294 :           if (isym == NULL && st == NULL)
    5826              :             {
    5827            6 :               gfc_error ("Invalid NAME %qs in !$ACC ROUTINE ( NAME ) at %C",
    5828              :                          buffer);
    5829            6 :               gfc_current_locus = old_loc;
    5830            9 :               return MATCH_ERROR;
    5831              :             }
    5832              :         }
    5833              :       else
    5834              :         {
    5835            1 :           gfc_error ("Syntax error in !$ACC ROUTINE ( NAME ) at %C");
    5836            1 :           gfc_current_locus = old_loc;
    5837            1 :           return MATCH_ERROR;
    5838              :         }
    5839              : 
    5840          288 :       if (gfc_match_char (')') != MATCH_YES)
    5841              :         {
    5842            2 :           gfc_error ("Syntax error in !$ACC ROUTINE ( NAME ) at %C, expecting"
    5843              :                      " %<)%> after NAME");
    5844            2 :           gfc_current_locus = old_loc;
    5845            2 :           return MATCH_ERROR;
    5846              :         }
    5847              :     }
    5848              : 
    5849          686 :   if (gfc_match_omp_eos () != MATCH_YES
    5850          686 :       && (gfc_match_omp_clauses (&c, OACC_ROUTINE_CLAUSES, false, false, true)
    5851              :           != MATCH_YES))
    5852              :     return MATCH_ERROR;
    5853              : 
    5854          683 :   lop = gfc_oacc_routine_lop (c);
    5855          683 :   if (lop == OACC_ROUTINE_LOP_ERROR)
    5856              :     {
    5857           47 :       gfc_error ("Multiple loop axes specified for routine at %C");
    5858           47 :       goto cleanup;
    5859              :     }
    5860          636 :   nohost = c ? c->nohost : false;
    5861              : 
    5862          636 :   if (isym != NULL)
    5863              :     {
    5864              :       /* Diagnose any OpenACC 'routine' directive that doesn't match the
    5865              :          (implicit) one with a 'seq' clause.  */
    5866           16 :       if (c && (c->gang || c->worker || c->vector))
    5867              :         {
    5868           10 :           gfc_error ("Intrinsic symbol specified in !$ACC ROUTINE ( NAME )"
    5869              :                      " at %C marked with incompatible GANG, WORKER, or VECTOR"
    5870              :                      " clause");
    5871           10 :           goto cleanup;
    5872              :         }
    5873              :       /* ..., and no 'nohost' clause.  */
    5874            6 :       if (nohost)
    5875              :         {
    5876            2 :           gfc_error ("Intrinsic symbol specified in !$ACC ROUTINE ( NAME )"
    5877              :                      " at %C marked with incompatible NOHOST clause");
    5878            2 :           goto cleanup;
    5879              :         }
    5880              :     }
    5881          620 :   else if (sym != NULL)
    5882              :     {
    5883          151 :       bool add = true;
    5884              : 
    5885              :       /* For a repeated OpenACC 'routine' directive, diagnose if it doesn't
    5886              :          match the first one.  */
    5887          151 :       for (gfc_oacc_routine_name *n_p = gfc_current_ns->oacc_routine_names;
    5888          346 :            n_p;
    5889          195 :            n_p = n_p->next)
    5890          235 :         if (n_p->sym == sym)
    5891              :           {
    5892           51 :             add = false;
    5893           51 :             bool nohost_p = n_p->clauses ? n_p->clauses->nohost : false;
    5894           51 :             if (lop != gfc_oacc_routine_lop (n_p->clauses)
    5895           51 :                 || nohost != nohost_p)
    5896              :               {
    5897           40 :                 gfc_error ("!$ACC ROUTINE already applied at %C");
    5898           40 :                 goto cleanup;
    5899              :               }
    5900              :           }
    5901              : 
    5902          111 :       if (add)
    5903              :         {
    5904          100 :           sym->attr.oacc_routine_lop = lop;
    5905          100 :           sym->attr.oacc_routine_nohost = nohost;
    5906              : 
    5907          100 :           n = gfc_get_oacc_routine_name ();
    5908          100 :           n->sym = sym;
    5909          100 :           n->clauses = c;
    5910          100 :           n->next = gfc_current_ns->oacc_routine_names;
    5911          100 :           n->loc = old_loc;
    5912          100 :           gfc_current_ns->oacc_routine_names = n;
    5913              :         }
    5914              :     }
    5915          469 :   else if (gfc_current_ns->proc_name)
    5916              :     {
    5917              :       /* For a repeated OpenACC 'routine' directive, diagnose if it doesn't
    5918              :          match the first one.  */
    5919          468 :       oacc_routine_lop lop_p = gfc_current_ns->proc_name->attr.oacc_routine_lop;
    5920          468 :       bool nohost_p = gfc_current_ns->proc_name->attr.oacc_routine_nohost;
    5921          468 :       if (lop_p != OACC_ROUTINE_LOP_NONE
    5922           86 :           && (lop != lop_p
    5923           86 :               || nohost != nohost_p))
    5924              :         {
    5925           56 :           gfc_error ("!$ACC ROUTINE already applied at %C");
    5926           56 :           goto cleanup;
    5927              :         }
    5928              : 
    5929          412 :       if (!gfc_add_omp_declare_target (&gfc_current_ns->proc_name->attr,
    5930              :                                        gfc_current_ns->proc_name->name,
    5931              :                                        &old_loc))
    5932            1 :         goto cleanup;
    5933          411 :       gfc_current_ns->proc_name->attr.oacc_routine_lop = lop;
    5934          411 :       gfc_current_ns->proc_name->attr.oacc_routine_nohost = nohost;
    5935              :     }
    5936              :   else
    5937              :     /* Something has gone wrong, possibly a syntax error.  */
    5938            1 :     goto cleanup;
    5939              : 
    5940          526 :   if (gfc_pure (NULL) && c && (c->gang || c->worker || c->vector))
    5941              :     {
    5942            6 :       gfc_error ("!$ACC ROUTINE with GANG, WORKER, or VECTOR clause is not "
    5943              :                  "permitted in PURE procedure at %C");
    5944            6 :       goto cleanup;
    5945              :     }
    5946              : 
    5947              : 
    5948          520 :   if (n)
    5949          100 :     n->clauses = c;
    5950          420 :   else if (gfc_current_ns->oacc_routine)
    5951            0 :     gfc_current_ns->oacc_routine_clauses = c;
    5952              : 
    5953          520 :   new_st.op = EXEC_OACC_ROUTINE;
    5954          520 :   new_st.ext.omp_clauses = c;
    5955          520 :   return MATCH_YES;
    5956              : 
    5957          166 : cleanup:
    5958          166 :   gfc_current_locus = old_loc;
    5959          166 :   return MATCH_ERROR;
    5960              : }
    5961              : 
    5962              : 
    5963              : #define OMP_PARALLEL_CLAUSES \
    5964              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    5965              :    | OMP_CLAUSE_SHARED | OMP_CLAUSE_COPYIN | OMP_CLAUSE_REDUCTION       \
    5966              :    | OMP_CLAUSE_IF | OMP_CLAUSE_NUM_THREADS | OMP_CLAUSE_DEFAULT        \
    5967              :    | OMP_CLAUSE_PROC_BIND | OMP_CLAUSE_ALLOCATE | OMP_CLAUSE_MESSAGE    \
    5968              :    | OMP_CLAUSE_SEVERITY)
    5969              : #define OMP_DECLARE_SIMD_CLAUSES \
    5970              :   (omp_mask (OMP_CLAUSE_SIMDLEN) | OMP_CLAUSE_LINEAR                    \
    5971              :    | OMP_CLAUSE_UNIFORM | OMP_CLAUSE_ALIGNED | OMP_CLAUSE_INBRANCH      \
    5972              :    | OMP_CLAUSE_NOTINBRANCH)
    5973              : #define OMP_DO_CLAUSES \
    5974              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    5975              :    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION                      \
    5976              :    | OMP_CLAUSE_SCHEDULE | OMP_CLAUSE_ORDERED | OMP_CLAUSE_COLLAPSE     \
    5977              :    | OMP_CLAUSE_LINEAR | OMP_CLAUSE_ORDER | OMP_CLAUSE_ALLOCATE         \
    5978              :    | OMP_CLAUSE_NOWAIT)
    5979              : #define OMP_LOOP_CLAUSES \
    5980              :   (omp_mask (OMP_CLAUSE_BIND) | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_ORDER  \
    5981              :    | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION)
    5982              : 
    5983              : #define OMP_SCOPE_CLAUSES \
    5984              :   (omp_mask (OMP_CLAUSE_PRIVATE) |OMP_CLAUSE_FIRSTPRIVATE               \
    5985              :    | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE | OMP_CLAUSE_NOWAIT)
    5986              : #define OMP_SECTIONS_CLAUSES \
    5987              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    5988              :    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION                      \
    5989              :    | OMP_CLAUSE_ALLOCATE | OMP_CLAUSE_NOWAIT)
    5990              : #define OMP_SIMD_CLAUSES \
    5991              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_LASTPRIVATE               \
    5992              :    | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_SAFELEN    \
    5993              :    | OMP_CLAUSE_LINEAR | OMP_CLAUSE_ALIGNED | OMP_CLAUSE_SIMDLEN        \
    5994              :    | OMP_CLAUSE_IF | OMP_CLAUSE_ORDER | OMP_CLAUSE_NOTEMPORAL)
    5995              : #define OMP_TASK_CLAUSES \
    5996              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    5997              :    | OMP_CLAUSE_SHARED | OMP_CLAUSE_IF | OMP_CLAUSE_DEFAULT             \
    5998              :    | OMP_CLAUSE_UNTIED | OMP_CLAUSE_FINAL | OMP_CLAUSE_MERGEABLE        \
    5999              :    | OMP_CLAUSE_DEPEND | OMP_CLAUSE_PRIORITY | OMP_CLAUSE_IN_REDUCTION  \
    6000              :    | OMP_CLAUSE_DETACH | OMP_CLAUSE_AFFINITY | OMP_CLAUSE_ALLOCATE)
    6001              : #define OMP_TASKLOOP_CLAUSES \
    6002              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    6003              :    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_SHARED | OMP_CLAUSE_IF         \
    6004              :    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_UNTIED | OMP_CLAUSE_FINAL          \
    6005              :    | OMP_CLAUSE_MERGEABLE | OMP_CLAUSE_PRIORITY | OMP_CLAUSE_GRAINSIZE  \
    6006              :    | OMP_CLAUSE_NUM_TASKS | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_NOGROUP    \
    6007              :    | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_IN_REDUCTION | OMP_CLAUSE_ALLOCATE)
    6008              : #define OMP_TASKGROUP_CLAUSES \
    6009              :   (omp_mask (OMP_CLAUSE_TASK_REDUCTION) | OMP_CLAUSE_ALLOCATE)
    6010              : #define OMP_TARGET_CLAUSES \
    6011              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF        \
    6012              :    | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOWAIT | OMP_CLAUSE_PRIVATE         \
    6013              :    | OMP_CLAUSE_FIRSTPRIVATE | OMP_CLAUSE_DEFAULTMAP                    \
    6014              :    | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_IN_REDUCTION                 \
    6015              :    | OMP_CLAUSE_THREAD_LIMIT | OMP_CLAUSE_ALLOCATE                      \
    6016              :    | OMP_CLAUSE_HAS_DEVICE_ADDR | OMP_CLAUSE_USES_ALLOCATORS            \
    6017              :    | OMP_CLAUSE_DYN_GROUPPRIVATE | OMP_CLAUSE_DEVICE_TYPE               \
    6018              :    | OMP_CLAUSE_MESSAGE)
    6019              : #define OMP_TARGET_DATA_CLAUSES \
    6020              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF        \
    6021              :    | OMP_CLAUSE_USE_DEVICE_PTR | OMP_CLAUSE_USE_DEVICE_ADDR)
    6022              : #define OMP_TARGET_ENTER_DATA_CLAUSES \
    6023              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF        \
    6024              :    | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOWAIT)
    6025              : #define OMP_TARGET_EXIT_DATA_CLAUSES \
    6026              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF        \
    6027              :    | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOWAIT)
    6028              : #define OMP_TARGET_UPDATE_CLAUSES \
    6029              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_IF | OMP_CLAUSE_TO         \
    6030              :    | OMP_CLAUSE_FROM | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOWAIT)
    6031              : #define OMP_TEAMS_CLAUSES \
    6032              :   (omp_mask (OMP_CLAUSE_NUM_TEAMS) | OMP_CLAUSE_THREAD_LIMIT            \
    6033              :    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE  \
    6034              :    | OMP_CLAUSE_SHARED | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE     \
    6035              :    | OMP_CLAUSE_MESSAGE | OMP_CLAUSE_DYN_GROUPPRIVATE)
    6036              : #define OMP_DISTRIBUTE_CLAUSES \
    6037              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    6038              :    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_DIST_SCHEDULE \
    6039              :    | OMP_CLAUSE_ORDER | OMP_CLAUSE_ALLOCATE)
    6040              : #define OMP_SINGLE_CLAUSES \
    6041              :   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE              \
    6042              :    | OMP_CLAUSE_ALLOCATE | OMP_CLAUSE_NOWAIT | OMP_CLAUSE_COPYPRIVATE)
    6043              : #define OMP_ORDERED_CLAUSES \
    6044              :   (omp_mask (OMP_CLAUSE_THREADS) | OMP_CLAUSE_SIMD)
    6045              : #define OMP_DECLARE_TARGET_CLAUSES \
    6046              :   (omp_mask (OMP_CLAUSE_ENTER) | OMP_CLAUSE_LINK | OMP_CLAUSE_DEVICE_TYPE \
    6047              :    | OMP_CLAUSE_TO | OMP_CLAUSE_INDIRECT | OMP_CLAUSE_LOCAL)
    6048              : #define OMP_ATOMIC_CLAUSES \
    6049              :   (omp_mask (OMP_CLAUSE_ATOMIC) | OMP_CLAUSE_CAPTURE | OMP_CLAUSE_HINT  \
    6050              :    | OMP_CLAUSE_MEMORDER | OMP_CLAUSE_COMPARE | OMP_CLAUSE_FAIL         \
    6051              :    | OMP_CLAUSE_WEAK)
    6052              : #define OMP_MASKED_CLAUSES \
    6053              :   (omp_mask (OMP_CLAUSE_FILTER))
    6054              : #define OMP_ERROR_CLAUSES \
    6055              :   (omp_mask (OMP_CLAUSE_AT) | OMP_CLAUSE_MESSAGE | OMP_CLAUSE_SEVERITY)
    6056              : #define OMP_WORKSHARE_CLAUSES \
    6057              :   omp_mask (OMP_CLAUSE_NOWAIT)
    6058              : #define OMP_UNROLL_CLAUSES \
    6059              :   (omp_mask (OMP_CLAUSE_FULL) | OMP_CLAUSE_PARTIAL)
    6060              : #define OMP_TILE_CLAUSES \
    6061              :   (omp_mask (OMP_CLAUSE_SIZES))
    6062              : #define OMP_ALLOCATORS_CLAUSES \
    6063              :   omp_mask (OMP_CLAUSE_ALLOCATE)
    6064              : #define OMP_INTEROP_CLAUSES \
    6065              :   (omp_mask (OMP_CLAUSE_DEPEND) | OMP_CLAUSE_NOWAIT | OMP_CLAUSE_DEVICE \
    6066              :    | OMP_CLAUSE_INIT | OMP_CLAUSE_DESTROY | OMP_CLAUSE_USE)
    6067              : #define OMP_DISPATCH_CLAUSES                                                   \
    6068              :   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOVARIANTS    \
    6069              :    | OMP_CLAUSE_NOCONTEXT | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_NOWAIT       \
    6070              :    | OMP_CLAUSE_HAS_DEVICE_ADDR | OMP_CLAUSE_INTEROP)
    6071              : 
    6072              : 
    6073              : static match
    6074        17806 : match_omp (gfc_exec_op op, const omp_mask mask)
    6075              : {
    6076        17806 :   gfc_omp_clauses *c;
    6077        17806 :   if (gfc_match_omp_clauses (&c, mask, false, true, false,
    6078              :                              op == EXEC_OMP_TARGET) != MATCH_YES)
    6079              :     return MATCH_ERROR;
    6080        17441 :   new_st.op = op;
    6081        17441 :   new_st.ext.omp_clauses = c;
    6082        17441 :   return MATCH_YES;
    6083              : }
    6084              : 
    6085              : /* Handles both declarative and (deprecated) executable ALLOCATE directive;
    6086              :    accepts optional list (for executable) and common blocks.
    6087              :    If no variables have been provided, the single omp namelist has sym == NULL.
    6088              : 
    6089              :    Note that the executable ALLOCATE directive permits structure elements only
    6090              :    in OpenMP 5.0 and 5.1 but not longer in 5.2.  See also the comment on the
    6091              :    'omp allocators' directive below. The accidental change was reverted for
    6092              :    OpenMP TR12, permitting them again. See also gfc_match_omp_allocators.
    6093              : 
    6094              :    Hence, structure elements are rejected for now, also to make resolving
    6095              :    OMP_LIST_ALLOCATE simpler (check for duplicates, same symbol in
    6096              :    Fortran allocate stmt).  TODO: Permit structure elements.  */
    6097              : 
    6098              : match
    6099          274 : gfc_match_omp_allocate (void)
    6100              : {
    6101          274 :   match m;
    6102          274 :   gfc_omp_namelist *vars = NULL;
    6103          274 :   gfc_expr *align = NULL;
    6104          274 :   gfc_expr *allocator = NULL;
    6105          274 :   locus loc = gfc_current_locus;
    6106              : 
    6107          274 :   m = gfc_match_omp_variable_list (" (", &vars, true, NULL, NULL, true, true,
    6108              :                                    NULL, true);
    6109              : 
    6110          274 :   if (m == MATCH_ERROR)
    6111              :     return m;
    6112              : 
    6113          502 :   while (true)
    6114              :     {
    6115          502 :       gfc_gobble_whitespace ();
    6116          502 :       if (gfc_match_omp_eos () == MATCH_YES)
    6117              :         break;
    6118          234 :       gfc_match (", ");  /* optionally  */
    6119          234 :       if ((m = gfc_match_dupl_check (!align, "align", true, &align))
    6120              :           != MATCH_NO)
    6121              :         {
    6122           62 :           if (m == MATCH_ERROR)
    6123            1 :             goto error;
    6124           61 :           continue;
    6125              :         }
    6126          172 :       if ((m = gfc_match_dupl_check (!allocator, "allocator",
    6127              :                                      true, &allocator)) != MATCH_NO)
    6128              :         {
    6129          171 :           if (m == MATCH_ERROR)
    6130            1 :             goto error;
    6131          170 :           continue;
    6132              :         }
    6133            1 :       gfc_error ("Expected ALIGN or ALLOCATOR clause at %C");
    6134            1 :       return MATCH_ERROR;
    6135              :     }
    6136          541 :   for (gfc_omp_namelist *n = vars; n; n = n->next)
    6137          276 :     if (n->expr)
    6138              :       {
    6139            3 :         if ((n->expr->ref && n->expr->ref->type == REF_COMPONENT)
    6140            3 :             || (n->expr->ref->next && n->expr->ref->type == REF_COMPONENT))
    6141            1 :           gfc_error ("Sorry, structure-element list item at %L in ALLOCATE "
    6142              :                      "directive is not yet supported", &n->expr->where);
    6143              :         else
    6144            2 :           gfc_error ("Unexpected expression as list item at %L in ALLOCATE "
    6145              :                      "directive", &n->expr->where);
    6146              : 
    6147            3 :         gfc_free_omp_namelist (vars, OMP_LIST_ALLOCATE);
    6148            3 :         goto error;
    6149              :       }
    6150              : 
    6151          265 :   new_st.op = EXEC_OMP_ALLOCATE;
    6152          265 :   new_st.ext.omp_clauses = gfc_get_omp_clauses ();
    6153          265 :   if (vars == NULL)
    6154              :     {
    6155           27 :       vars = gfc_get_omp_namelist ();
    6156           27 :       vars->where = loc;
    6157           27 :       vars->u.align = align;
    6158           27 :       vars->u2.allocator = allocator;
    6159           27 :       new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = vars;
    6160              :     }
    6161              :   else
    6162              :     {
    6163          238 :       new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = vars;
    6164          511 :       for (; vars; vars = vars->next)
    6165              :         {
    6166          273 :           vars->u.align = (align) ? gfc_copy_expr (align) : NULL;
    6167          273 :           vars->u2.allocator = allocator;
    6168              :         }
    6169          238 :       gfc_free_expr (align);
    6170              :     }
    6171              :   return MATCH_YES;
    6172              : 
    6173            5 : error:
    6174            5 :   gfc_free_expr (align);
    6175            5 :   gfc_free_expr (allocator);
    6176            5 :   return MATCH_ERROR;
    6177              : }
    6178              : 
    6179              : /* In line with OpenMP 5.2 derived-type components are rejected.
    6180              :    See also comment before gfc_match_omp_allocate.  */
    6181              : 
    6182              : match
    6183           26 : gfc_match_omp_allocators (void)
    6184              : {
    6185           26 :   return match_omp (EXEC_OMP_ALLOCATORS, OMP_ALLOCATORS_CLAUSES);
    6186              : }
    6187              : 
    6188              : 
    6189              : match
    6190           25 : gfc_match_omp_assume (void)
    6191              : {
    6192           25 :   gfc_omp_clauses *c;
    6193           25 :   locus loc = gfc_current_locus;
    6194           32 :   if ((gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_ASSUMPTIONS), false)
    6195              :        != MATCH_YES)
    6196           25 :       || (omp_verify_merge_absent_contains (ST_OMP_ASSUME, c->assume, NULL,
    6197              :                                             &loc) != MATCH_YES))
    6198              :     return MATCH_ERROR;
    6199           18 :   new_st.op = EXEC_OMP_ASSUME;
    6200           18 :   new_st.ext.omp_clauses = c;
    6201           18 :   return MATCH_YES;
    6202              : }
    6203              : 
    6204              : 
    6205              : match
    6206           38 : gfc_match_omp_assumes (void)
    6207              : {
    6208           38 :   gfc_omp_clauses *c;
    6209           38 :   locus loc = gfc_current_locus;
    6210           38 :   if (!gfc_current_ns->proc_name
    6211           37 :       || (gfc_current_ns->proc_name->attr.flavor != FL_MODULE
    6212           23 :           && !gfc_current_ns->proc_name->attr.subroutine
    6213           10 :           && !gfc_current_ns->proc_name->attr.function))
    6214              :     {
    6215            2 :       gfc_error ("!$OMP ASSUMES at %C must be in the specification part of a "
    6216              :                  "subprogram or module");
    6217            2 :       return MATCH_ERROR;
    6218              :     }
    6219           46 :   if ((gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_ASSUMPTIONS), false)
    6220              :        != MATCH_YES)
    6221           65 :       || (omp_verify_merge_absent_contains (ST_OMP_ASSUMES, c->assume,
    6222           29 :                                             gfc_current_ns->omp_assumes, &loc)
    6223              :           != MATCH_YES))
    6224              :     return MATCH_ERROR;
    6225           26 :   if (gfc_current_ns->omp_assumes == NULL)
    6226              :     {
    6227           23 :       gfc_current_ns->omp_assumes = c->assume;
    6228           23 :       c->assume = NULL;
    6229              :     }
    6230            3 :   else if (gfc_current_ns->omp_assumes && c->assume)
    6231              :     {
    6232            3 :       gfc_current_ns->omp_assumes->no_openmp |= c->assume->no_openmp;
    6233            3 :       gfc_current_ns->omp_assumes->no_openmp_routines
    6234            3 :         |= c->assume->no_openmp_routines;
    6235            3 :       gfc_current_ns->omp_assumes->no_openmp_constructs
    6236            3 :         |= c->assume->no_openmp_constructs;
    6237            3 :       gfc_current_ns->omp_assumes->no_parallelism |= c->assume->no_parallelism;
    6238            3 :       if (gfc_current_ns->omp_assumes->holds && c->assume->holds)
    6239              :         {
    6240              :           gfc_expr_list *el = gfc_current_ns->omp_assumes->holds;
    6241            1 :           for ( ; el->next ; el = el->next)
    6242              :             ;
    6243            1 :           el->next = c->assume->holds;
    6244            1 :         }
    6245            2 :       else if (c->assume->holds)
    6246            1 :         gfc_current_ns->omp_assumes->holds = c->assume->holds;
    6247            3 :       c->assume->holds = NULL;
    6248              :     }
    6249           26 :   gfc_free_omp_clauses (c);
    6250           26 :   return MATCH_YES;
    6251              : }
    6252              : 
    6253              : 
    6254              : match
    6255          168 : gfc_match_omp_critical (void)
    6256              : {
    6257          168 :   char n[GFC_MAX_SYMBOL_LEN+1];
    6258          168 :   gfc_omp_clauses *c = NULL;
    6259              : 
    6260          168 :   if (gfc_match (" ( %n )", n) != MATCH_YES)
    6261          117 :     n[0] = '\0';
    6262              : 
    6263          168 :   if (gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_HINT), false,
    6264          168 :                              /* needs_space = */ n[0] == '\0') != MATCH_YES)
    6265              :     return MATCH_ERROR;
    6266              : 
    6267          166 :   new_st.op = EXEC_OMP_CRITICAL;
    6268          166 :   new_st.ext.omp_clauses = c;
    6269          166 :   if (n[0])
    6270           51 :     c->critical_name = xstrdup (n);
    6271              :   return MATCH_YES;
    6272              : }
    6273              : 
    6274              : 
    6275              : match
    6276          166 : gfc_match_omp_end_critical (void)
    6277              : {
    6278          166 :   char n[GFC_MAX_SYMBOL_LEN+1];
    6279              : 
    6280          166 :   if (gfc_match (" ( %n )", n) != MATCH_YES)
    6281          115 :     n[0] = '\0';
    6282          166 :   if (gfc_match_omp_eos () != MATCH_YES)
    6283              :     {
    6284            1 :       gfc_error ("Unexpected junk after $OMP CRITICAL statement at %C");
    6285            1 :       return MATCH_ERROR;
    6286              :     }
    6287              : 
    6288          165 :   new_st.op = EXEC_OMP_END_CRITICAL;
    6289          165 :   new_st.ext.omp_name = n[0] ? xstrdup (n) : NULL;
    6290          165 :   return MATCH_YES;
    6291              : }
    6292              : 
    6293              : /* depobj(depobj) depend(dep-type:loc)|destroy|update(dep-type)
    6294              :    dep-type = in/out/inout/mutexinoutset/depobj/source/sink
    6295              :    depend: !source, !sink
    6296              :    update: !source, !sink, !depobj
    6297              :    locator = exactly one list item  .*/
    6298              : match
    6299          128 : gfc_match_omp_depobj (void)
    6300              : {
    6301          128 :   gfc_omp_clauses *c = NULL;
    6302          128 :   gfc_expr *depobj;
    6303              : 
    6304          128 :   if (gfc_match (" ( %v ) ", &depobj) != MATCH_YES)
    6305              :     {
    6306            2 :       gfc_error ("Expected %<( depobj )%> at %C");
    6307            2 :       return MATCH_ERROR;
    6308              :     }
    6309          126 :   gfc_match (", ");  /* optionally */
    6310          126 :   if (gfc_match ("update ( ") == MATCH_YES)
    6311              :     {
    6312           12 :       c = gfc_get_omp_clauses ();
    6313           12 :       if (gfc_match ("inoutset )") == MATCH_YES)
    6314            2 :         c->depobj_update = OMP_DEPEND_INOUTSET;
    6315           10 :       else if (gfc_match ("inout )") == MATCH_YES)
    6316            1 :         c->depobj_update = OMP_DEPEND_INOUT;
    6317            9 :       else if (gfc_match ("in )") == MATCH_YES)
    6318            2 :         c->depobj_update = OMP_DEPEND_IN;
    6319            7 :       else if (gfc_match ("out )") == MATCH_YES)
    6320            2 :         c->depobj_update = OMP_DEPEND_OUT;
    6321            5 :       else if (gfc_match ("mutexinoutset )") == MATCH_YES)
    6322            2 :         c->depobj_update = OMP_DEPEND_MUTEXINOUTSET;
    6323              :       else
    6324              :         {
    6325            3 :           gfc_error ("Expected IN, OUT, INOUT, INOUTSET or MUTEXINOUTSET "
    6326              :                      "followed by %<)%> at %C");
    6327            3 :           goto error;
    6328              :         }
    6329              :     }
    6330          114 :   else if (gfc_match ("destroy ") == MATCH_YES)
    6331              :     {
    6332           18 :       gfc_expr *destroyobj = NULL;
    6333           18 :       c = gfc_get_omp_clauses ();
    6334           18 :       c->destroy = true;
    6335              : 
    6336           18 :       if (gfc_match (" ( %v ) ", &destroyobj) == MATCH_YES)
    6337              :         {
    6338            3 :           if (destroyobj->symtree != depobj->symtree)
    6339            2 :             gfc_warning (OPT_Wopenmp, "The same depend object should be used as"
    6340              :                          " DEPOBJ argument at %L and as DESTROY argument at %L",
    6341              :                          &depobj->where, &destroyobj->where);
    6342            3 :           gfc_free_expr (destroyobj);
    6343              :         }
    6344              :     }
    6345           96 :   else if (gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_DEPEND), false, false)
    6346              :            != MATCH_YES)
    6347            2 :     goto error;
    6348              : 
    6349          121 :   if (c->depobj_update == OMP_DEPEND_UNSET && !c->destroy)
    6350              :     {
    6351           94 :       if (!c->doacross_source && !c->lists[OMP_LIST_DEPEND])
    6352              :         {
    6353            1 :           gfc_error ("Expected DEPEND, UPDATE, or DESTROY clause at %C");
    6354            1 :           goto error;
    6355              :         }
    6356           93 :       if (c->lists[OMP_LIST_DEPEND]->u.depend_doacross_op == OMP_DEPEND_DEPOBJ)
    6357              :         {
    6358            1 :           gfc_error ("DEPEND clause at %L of OMP DEPOBJ construct shall not "
    6359              :                      "have dependence-type DEPOBJ",
    6360              :                      c->lists[OMP_LIST_DEPEND]
    6361              :                      ? &c->lists[OMP_LIST_DEPEND]->where : &gfc_current_locus);
    6362            1 :           goto error;
    6363              :         }
    6364           92 :       if (c->lists[OMP_LIST_DEPEND]->next)
    6365              :         {
    6366            1 :           gfc_error ("DEPEND clause at %L of OMP DEPOBJ construct shall have "
    6367              :                      "only a single locator",
    6368              :                      &c->lists[OMP_LIST_DEPEND]->next->where);
    6369            1 :           goto error;
    6370              :         }
    6371              :     }
    6372              : 
    6373          118 :   c->depobj = depobj;
    6374          118 :   new_st.op = EXEC_OMP_DEPOBJ;
    6375          118 :   new_st.ext.omp_clauses = c;
    6376          118 :   return MATCH_YES;
    6377              : 
    6378            8 : error:
    6379            8 :   gfc_free_expr (depobj);
    6380            8 :   gfc_free_omp_clauses (c);
    6381            8 :   return MATCH_ERROR;
    6382              : }
    6383              : 
    6384              : match
    6385          160 : gfc_match_omp_dispatch (void)
    6386              : {
    6387          160 :   return match_omp (EXEC_OMP_DISPATCH, OMP_DISPATCH_CLAUSES);
    6388              : }
    6389              : 
    6390              : match
    6391           57 : gfc_match_omp_distribute (void)
    6392              : {
    6393           57 :   return match_omp (EXEC_OMP_DISTRIBUTE, OMP_DISTRIBUTE_CLAUSES);
    6394              : }
    6395              : 
    6396              : 
    6397              : match
    6398           47 : gfc_match_omp_distribute_parallel_do (void)
    6399              : {
    6400           47 :   return match_omp (EXEC_OMP_DISTRIBUTE_PARALLEL_DO,
    6401           47 :                     (OMP_DISTRIBUTE_CLAUSES | OMP_PARALLEL_CLAUSES
    6402           47 :                      | OMP_DO_CLAUSES)
    6403           47 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED)
    6404           47 :                         | OMP_CLAUSE_LINEAR | OMP_CLAUSE_NOWAIT));
    6405              : }
    6406              : 
    6407              : 
    6408              : match
    6409           34 : gfc_match_omp_distribute_parallel_do_simd (void)
    6410              : {
    6411           34 :   return match_omp (EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD,
    6412           34 :                     (OMP_DISTRIBUTE_CLAUSES | OMP_PARALLEL_CLAUSES
    6413           34 :                      | OMP_DO_CLAUSES | OMP_SIMD_CLAUSES)
    6414           34 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED) | OMP_CLAUSE_NOWAIT));
    6415              : }
    6416              : 
    6417              : 
    6418              : match
    6419           52 : gfc_match_omp_distribute_simd (void)
    6420              : {
    6421           52 :   return match_omp (EXEC_OMP_DISTRIBUTE_SIMD,
    6422           52 :                     OMP_DISTRIBUTE_CLAUSES | OMP_SIMD_CLAUSES);
    6423              : }
    6424              : 
    6425              : 
    6426              : match
    6427         1256 : gfc_match_omp_do (void)
    6428              : {
    6429         1256 :   return match_omp (EXEC_OMP_DO, OMP_DO_CLAUSES);
    6430              : }
    6431              : 
    6432              : 
    6433              : match
    6434          157 : gfc_match_omp_do_simd (void)
    6435              : {
    6436          157 :   return match_omp (EXEC_OMP_DO_SIMD, OMP_DO_CLAUSES | OMP_SIMD_CLAUSES);
    6437              : }
    6438              : 
    6439              : 
    6440              : match
    6441           71 : gfc_match_omp_loop (void)
    6442              : {
    6443           71 :   return match_omp (EXEC_OMP_LOOP, OMP_LOOP_CLAUSES);
    6444              : }
    6445              : 
    6446              : 
    6447              : match
    6448           38 : gfc_match_omp_teams_loop (void)
    6449              : {
    6450           38 :   return match_omp (EXEC_OMP_TEAMS_LOOP, OMP_TEAMS_CLAUSES | OMP_LOOP_CLAUSES);
    6451              : }
    6452              : 
    6453              : 
    6454              : match
    6455           19 : gfc_match_omp_target_teams_loop (void)
    6456              : {
    6457           19 :   return match_omp (EXEC_OMP_TARGET_TEAMS_LOOP,
    6458           19 :                     OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES | OMP_LOOP_CLAUSES);
    6459              : }
    6460              : 
    6461              : 
    6462              : match
    6463           31 : gfc_match_omp_parallel_loop (void)
    6464              : {
    6465           31 :   return match_omp (EXEC_OMP_PARALLEL_LOOP,
    6466           31 :                     OMP_PARALLEL_CLAUSES | OMP_LOOP_CLAUSES);
    6467              : }
    6468              : 
    6469              : 
    6470              : match
    6471           17 : gfc_match_omp_target_parallel_loop (void)
    6472              : {
    6473           17 :   return match_omp (EXEC_OMP_TARGET_PARALLEL_LOOP,
    6474           17 :                     (OMP_TARGET_CLAUSES | OMP_PARALLEL_CLAUSES
    6475           17 :                      | OMP_LOOP_CLAUSES));
    6476              : }
    6477              : 
    6478              : 
    6479              : match
    6480          104 : gfc_match_omp_error (void)
    6481              : {
    6482          104 :   locus loc = gfc_current_locus;
    6483          104 :   match m = match_omp (EXEC_OMP_ERROR, OMP_ERROR_CLAUSES);
    6484          104 :   if (m != MATCH_YES)
    6485              :     return m;
    6486              : 
    6487           85 :   gfc_omp_clauses *c = new_st.ext.omp_clauses;
    6488           85 :   if (c->severity == OMP_SEVERITY_UNSET)
    6489           48 :     c->severity = OMP_SEVERITY_FATAL;
    6490           85 :   if (new_st.ext.omp_clauses->at == OMP_AT_EXECUTION)
    6491              :     return MATCH_YES;
    6492           37 :   if (c->message
    6493           37 :       && (!gfc_resolve_expr (c->message)
    6494           16 :           || c->message->ts.type != BT_CHARACTER
    6495           14 :           || c->message->ts.kind != gfc_default_character_kind
    6496           13 :           || c->message->rank != 0))
    6497              :     {
    6498            4 :       gfc_error ("MESSAGE clause at %L requires a scalar default-kind "
    6499              :                    "CHARACTER expression",
    6500            4 :                  &new_st.ext.omp_clauses->message->where);
    6501            4 :       return MATCH_ERROR;
    6502              :     }
    6503           33 :   if (c->message && !gfc_is_constant_expr (c->message))
    6504              :     {
    6505            2 :       gfc_error ("Constant character expression required in MESSAGE clause "
    6506            2 :                  "at %L", &new_st.ext.omp_clauses->message->where);
    6507            2 :       return MATCH_ERROR;
    6508              :     }
    6509           31 :   if (c->message)
    6510              :     {
    6511           10 :       const char *msg = G_("$OMP ERROR encountered at %L: %s");
    6512           10 :       gcc_assert (c->message->expr_type == EXPR_CONSTANT);
    6513           10 :       gfc_charlen_t slen = c->message->value.character.length;
    6514           10 :       int i = gfc_validate_kind (BT_CHARACTER, gfc_default_character_kind,
    6515              :                                  false);
    6516           10 :       size_t size = slen * gfc_character_kinds[i].bit_size / 8;
    6517           10 :       unsigned char *s = XCNEWVAR (unsigned char, size + 1);
    6518           10 :       gfc_encode_character (gfc_default_character_kind, slen,
    6519           10 :                             c->message->value.character.string,
    6520              :                             (unsigned char *) s, size);
    6521           10 :       s[size] = '\0';
    6522           10 :       if (c->severity == OMP_SEVERITY_WARNING)
    6523            6 :         gfc_warning_now (0, msg, &loc, s);
    6524              :       else
    6525            4 :         gfc_error_now (msg, &loc, s);
    6526           10 :       free (s);
    6527              :     }
    6528              :   else
    6529              :     {
    6530           21 :       const char *msg = G_("$OMP ERROR encountered at %L");
    6531           21 :       if (c->severity == OMP_SEVERITY_WARNING)
    6532            7 :         gfc_warning_now (0, msg, &loc);
    6533              :       else
    6534           14 :         gfc_error_now (msg, &loc);
    6535              :     }
    6536              :   return MATCH_YES;
    6537              : }
    6538              : 
    6539              : match
    6540          100 : gfc_match_omp_flush (void)
    6541              : {
    6542          100 :   gfc_omp_namelist *list = NULL;
    6543          100 :   gfc_omp_clauses *c = NULL;
    6544          100 :   gfc_gobble_whitespace ();
    6545          100 :   enum gfc_omp_memorder mo = OMP_MEMORDER_UNSET;
    6546          100 :   if (gfc_match_omp_variable_list (" (", &list, true) == MATCH_ERROR)
    6547              :     return MATCH_ERROR;
    6548              :   match m = MATCH_YES;
    6549          150 :   while (gfc_match_omp_eos () != MATCH_YES)
    6550              :     {
    6551           59 :       gfc_gobble_whitespace ();
    6552           59 :       gfc_match (", ");  /* optionally  */
    6553           59 :       enum gfc_omp_memorder mo2 = OMP_MEMORDER_UNSET;
    6554           59 :       bool bval = false;
    6555           59 :       locus loc = gfc_current_locus;
    6556           59 :       if ((m = gfc_match_dupl_memorder (&bval, "seq_cst",
    6557              :                                         mo != OMP_MEMORDER_UNSET)) != MATCH_NO)
    6558              :         mo2 = OMP_MEMORDER_SEQ_CST;
    6559           48 :       else if ((m = gfc_match_dupl_memorder (&bval, "acq_rel",
    6560              :                                              mo != OMP_MEMORDER_UNSET))
    6561              :               != MATCH_NO)
    6562              :         mo2 = OMP_MEMORDER_ACQ_REL;
    6563           35 :       else if ((m = gfc_match_dupl_memorder (&bval, "release",
    6564              :                                              mo != OMP_MEMORDER_UNSET))
    6565              :               != MATCH_NO)
    6566              :         mo2 = OMP_MEMORDER_RELEASE;
    6567           24 :       else if ((m = gfc_match_dupl_memorder (&bval, "acquire",
    6568              :                                              mo != OMP_MEMORDER_UNSET))
    6569              :               != MATCH_NO)
    6570              :         mo2 = OMP_MEMORDER_ACQUIRE;
    6571           12 :       else if ((m = gfc_match_dupl_memorder (&bval, "relaxed",
    6572              :                                              mo != OMP_MEMORDER_UNSET))
    6573              :               != MATCH_NO)
    6574              :         {
    6575           10 :           if (m == MATCH_YES && bval)
    6576              :             {
    6577              :               /* relaxed only permitted with 'false'.  */
    6578            2 :               gfc_current_locus = loc;
    6579            2 :               m = MATCH_NO;
    6580            2 :               break;
    6581              :             }
    6582              :         }
    6583              :       else
    6584              :         break;
    6585           55 :       if (m == MATCH_ERROR)
    6586            5 :         return MATCH_ERROR;
    6587           50 :       if (bval)
    6588           18 :         mo = mo2;
    6589              :     }
    6590           95 :   if (m == MATCH_NO)
    6591              :     {
    6592            4 :       gfc_error ("Expected SEQ_CST, AQC_REL, RELEASE, or ACQUIRE at %C");
    6593            4 :       gfc_free_omp_namelist (list, OMP_LIST_NONE);
    6594            4 :       return MATCH_ERROR;
    6595              :     }
    6596           91 :   if (list && mo != OMP_MEMORDER_UNSET)
    6597              :     {
    6598            1 :       gfc_error ("List specified together with memory order clause in FLUSH "
    6599              :                  "directive at %C");
    6600            1 :       gfc_free_omp_namelist (list, OMP_LIST_NONE);
    6601            1 :       return MATCH_ERROR;
    6602              :     }
    6603           90 :   if (gfc_match_omp_eos () != MATCH_YES)
    6604              :     {
    6605            0 :       gfc_error ("Unexpected junk after $OMP FLUSH statement at %C");
    6606            0 :       gfc_free_omp_namelist (list, OMP_LIST_NONE);
    6607            0 :       return MATCH_ERROR;
    6608              :     }
    6609           90 :   if (mo != OMP_MEMORDER_UNSET)
    6610              :     {
    6611           16 :       c = gfc_get_omp_clauses ();
    6612           16 :       c->memorder = mo;
    6613              :     }
    6614           90 :   new_st.op = EXEC_OMP_FLUSH;
    6615           90 :   new_st.ext.omp_namelist = list;
    6616           90 :   new_st.ext.omp_clauses = c;
    6617           90 :   return MATCH_YES;
    6618              : }
    6619              : 
    6620              : 
    6621              : match
    6622          208 : gfc_match_omp_declare_simd (void)
    6623              : {
    6624          208 :   locus where = gfc_current_locus;
    6625          208 :   gfc_symbol *proc_name;
    6626          208 :   gfc_omp_clauses *c;
    6627          208 :   gfc_omp_declare_simd *ods;
    6628          208 :   bool needs_space = false;
    6629              : 
    6630          208 :   switch (gfc_match (" ( "))
    6631              :     {
    6632          145 :     case MATCH_YES:
    6633          145 :       if (gfc_match_symbol (&proc_name, /* host assoc = */ true) != MATCH_YES
    6634          145 :           || gfc_match (" ) ") != MATCH_YES)
    6635              :         return MATCH_ERROR;
    6636              :       break;
    6637           63 :     case MATCH_NO: proc_name = NULL; needs_space = true; break;
    6638              :     case MATCH_ERROR: return MATCH_ERROR;
    6639              :     }
    6640              : 
    6641          208 :   if (gfc_match_omp_clauses (&c, OMP_DECLARE_SIMD_CLAUSES, false,
    6642              :                              needs_space) != MATCH_YES)
    6643              :     return MATCH_ERROR;
    6644              : 
    6645          199 :   if (gfc_current_ns->is_block_data)
    6646              :     {
    6647            1 :       gfc_free_omp_clauses (c);
    6648            1 :       return MATCH_YES;
    6649              :     }
    6650              : 
    6651          198 :   ods = gfc_get_omp_declare_simd ();
    6652          198 :   ods->where = where;
    6653          198 :   ods->proc_name = proc_name;
    6654          198 :   ods->clauses = c;
    6655          198 :   ods->next = gfc_current_ns->omp_declare_simd;
    6656          198 :   gfc_current_ns->omp_declare_simd = ods;
    6657          198 :   return MATCH_YES;
    6658              : }
    6659              : 
    6660              : 
    6661              : /* Find a matching "!$omp declare mapper" for typespec TS in symtree ST.  */
    6662              : 
    6663              : gfc_omp_udm *
    6664           37 : gfc_omp_udm_find (gfc_symtree *st, gfc_typespec *ts)
    6665              : {
    6666           37 :   gfc_omp_udm *omp_udm;
    6667              : 
    6668           37 :   if (st == NULL)
    6669              :     return NULL;
    6670              : 
    6671           14 :   gfc_symbol *dt = (ts->type == BT_CLASS
    6672            0 :                     ? CLASS_DATA (ts->u.derived)->ts.u.derived
    6673              :                     : ts->u.derived);
    6674           15 :   for (omp_udm = st->n.omp_udm; omp_udm; omp_udm = omp_udm->next)
    6675              :     {
    6676            5 :       if (dt == omp_udm->ts.u.derived)
    6677              :         return omp_udm;
    6678              :       /* Special case for comparing derived types across namespaces.  If the
    6679              :          true names and module names are the same and the module name is
    6680              :          nonnull, then they are equal.  */
    6681            1 :       if (dt->module && omp_udm->ts.u.derived->module
    6682            1 :           && strcmp (dt->name, omp_udm->ts.u.derived->name) == 0
    6683            1 :           && strcmp (dt->module, omp_udm->ts.u.derived->module) == 0)
    6684              :         return omp_udm;
    6685              :     }
    6686              : 
    6687              :   return NULL;
    6688              : }
    6689              : 
    6690              : 
    6691              : /* Match !$omp declare mapper([ mapper-identifier : ] type :: var) clauses-list  */
    6692              : 
    6693              : match
    6694           35 : gfc_match_omp_declare_mapper (void)
    6695              : {
    6696           35 :   match m;
    6697           35 :   gfc_typespec ts;
    6698           35 :   char mapper_id[GFC_MAX_SYMBOL_LEN + 1];
    6699           35 :   char var[GFC_MAX_SYMBOL_LEN + 1];
    6700           35 :   gfc_namespace *mapper_ns = NULL;
    6701           35 :   gfc_symtree *var_st;
    6702           35 :   gfc_symtree *st;
    6703           35 :   gfc_omp_udm *omp_udm = NULL, *prev_udm = NULL;
    6704           35 :   locus where = gfc_current_locus;
    6705              : 
    6706           35 :   if (gfc_match_char ('(') != MATCH_YES)
    6707              :     {
    6708            1 :       gfc_error ("Expected %<(%> at %C");
    6709            1 :       return MATCH_ERROR;
    6710              :     }
    6711              : 
    6712           34 :   locus old_locus = gfc_current_locus;
    6713              : 
    6714           34 :   m = gfc_match (" %n : ", mapper_id);
    6715              : 
    6716           34 :   if (m == MATCH_ERROR)
    6717              :     return MATCH_ERROR;
    6718              : 
    6719              :   /* As a special case, a mapper named "default" and an unnamed mapper are
    6720              :      both the default mapper for a given type.  */
    6721           34 :   if (strcmp (mapper_id, "default") == 0)
    6722            0 :     mapper_id[0] = '\0';
    6723              : 
    6724           34 :   if (gfc_peek_ascii_char () == ':')
    6725              :    {
    6726              :      /* If we see '::', the user did not name the mapper, and instead we just
    6727              :         saw the type.  So backtrack and try parsing as a type instead.  */
    6728           15 :      mapper_id[0] = '\0';
    6729           15 :      gfc_current_locus = old_locus;
    6730              :    }
    6731           34 :   old_locus = gfc_current_locus;
    6732              : 
    6733           34 :   m = gfc_match_type_spec (&ts);
    6734           34 :   if (m != MATCH_YES)
    6735              :     {
    6736            4 :       gfc_error ("Expected either a type name at %L or a map-type "
    6737              :                  "identifier, a colon, or a type name", &old_locus);
    6738            4 :       return MATCH_ERROR;
    6739              :     }
    6740              : 
    6741           30 :   if (ts.type != BT_DERIVED)
    6742              :     {
    6743            1 :       gfc_error ("!$OMP DECLARE MAPPER with non-derived type at %L", &old_locus);
    6744            1 :       return MATCH_ERROR;
    6745              :     }
    6746              : 
    6747           29 :   if (gfc_match (" :: ") != MATCH_YES)
    6748              :     {
    6749            0 :       gfc_error ("Expected %<::%> at %C");
    6750            0 :       return MATCH_ERROR;
    6751              :     }
    6752              : 
    6753           29 :   if (gfc_match_name (var) != MATCH_YES)
    6754              :     {
    6755            1 :       gfc_error ("Expected variable name at %C");
    6756            1 :       return MATCH_ERROR;
    6757              :     }
    6758              : 
    6759           28 :   if (gfc_match_char (')') != MATCH_YES)
    6760              :     {
    6761            2 :       gfc_error ("Expected %<)%> at %C");
    6762            2 :       return MATCH_ERROR;
    6763              :     }
    6764              : 
    6765           26 :   st = gfc_find_symtree (gfc_current_ns->omp_udm_root, mapper_id);
    6766              : 
    6767              :   /* Now we need to set up a new namespace, and create a new sym_tree for our
    6768              :      dummy variable so we can use it in the following list of mapping
    6769              :      clauses.  */
    6770              : 
    6771           26 :   gfc_current_ns = mapper_ns = gfc_get_namespace (gfc_current_ns, 1);
    6772           26 :   mapper_ns->proc_name = mapper_ns->parent->proc_name;
    6773           26 :   mapper_ns->omp_udm_ns = 1;
    6774              : 
    6775           26 :   gfc_get_sym_tree (var, mapper_ns, &var_st, false);
    6776           26 :   var_st->n.sym->ts = ts;
    6777           26 :   var_st->n.sym->attr.omp_udm_artificial_var = 1;
    6778           26 :   var_st->n.sym->attr.flavor = FL_VARIABLE;
    6779           26 :   gfc_commit_symbols ();
    6780              : 
    6781           26 :   gfc_omp_clauses *clauses = NULL;
    6782              : 
    6783           26 :   m = gfc_match_omp_clauses (&clauses, omp_mask (OMP_CLAUSE_MAP), false, false,
    6784              :                              false, false, OMP_MAP_UNSET);
    6785           26 :   if (m != MATCH_YES)
    6786            1 :     goto failure;
    6787              : 
    6788           25 :   omp_udm = gfc_get_omp_udm ();
    6789           25 :   omp_udm->next = NULL;
    6790           25 :   omp_udm->where = where;
    6791           25 :   omp_udm->mapper_id = gfc_get_string ("%s", mapper_id);
    6792           25 :   omp_udm->ts = ts;
    6793           25 :   omp_udm->var_sym = var_st->n.sym;
    6794           25 :   omp_udm->mapper_ns = mapper_ns;
    6795           25 :   omp_udm->clauses = clauses;
    6796              : 
    6797           25 :   gfc_current_ns = mapper_ns->parent;
    6798              : 
    6799           25 :   prev_udm = gfc_omp_udm_find (st, &ts);
    6800           25 :   if (prev_udm)
    6801              :     {
    6802            2 :       if (mapper_id[0])
    6803            1 :         gfc_error ("Redefinition of !$OMP DECLARE MAPPER at %L for type %qs with id %qs",
    6804              :                    &where, gfc_typename (&ts), mapper_id);
    6805              :       else
    6806            1 :         gfc_error ("Redefinition of !$OMP DECLARE MAPPER at %L for type %qs",
    6807              :                    &where, gfc_typename (&ts));
    6808            2 :       inform (gfc_get_location (&prev_udm->where),
    6809              :               "Previous !$OMP DECLARE MAPPER here");
    6810            2 :       return MATCH_ERROR;
    6811              :     }
    6812           23 :   else if (st)
    6813              :     {
    6814            0 :       omp_udm->next = st->n.omp_udm;
    6815            0 :       st->n.omp_udm = omp_udm;
    6816              :     }
    6817              :   else
    6818              :     {
    6819           23 :       st = gfc_new_symtree (&gfc_current_ns->omp_udm_root, mapper_id);
    6820           23 :       st->n.omp_udm = omp_udm;
    6821              :     }
    6822              : 
    6823              :   return MATCH_YES;
    6824              : 
    6825            1 : failure:
    6826            1 :   if (mapper_ns)
    6827            1 :     gfc_current_ns = mapper_ns->parent;
    6828            1 :   gfc_free_omp_udm (omp_udm);
    6829              : 
    6830            1 :   return MATCH_ERROR;
    6831              : }
    6832              : 
    6833              : /* For 'declare reduction', matches either the combiner or initializer
    6834              :    expression, either can be an assignment of 'omp_sym1 = ...'
    6835              :    or a subroutine call, i.e. 'subroutine-name(argument-list)'.  */
    6836              : 
    6837              : static bool
    6838          935 : match_udr_expr (gfc_symtree *omp_sym1, gfc_symtree *omp_sym2)
    6839              : {
    6840          935 :   match m;
    6841          935 :   locus old_loc = gfc_current_locus;
    6842          935 :   char sname[GFC_MAX_SYMBOL_LEN + 1];
    6843          935 :   gfc_symbol *sym;
    6844          935 :   gfc_namespace *ns = gfc_current_ns;
    6845          935 :   gfc_expr *lvalue = NULL, *rvalue = NULL;
    6846          935 :   gfc_symtree *st;
    6847          935 :   gfc_actual_arglist *arglist;
    6848              : 
    6849          935 :   m = gfc_match (" %v =", &lvalue);
    6850          935 :   if (m != MATCH_YES)
    6851          210 :     gfc_current_locus = old_loc;
    6852              :   else
    6853              :     {
    6854          725 :       m = gfc_match (" %e )", &rvalue);
    6855          725 :       if (m == MATCH_YES)
    6856              :         {
    6857          715 :           ns->code = gfc_get_code (EXEC_ASSIGN);
    6858          715 :           ns->code->expr1 = lvalue;
    6859          715 :           ns->code->expr2 = rvalue;
    6860          715 :           ns->code->loc = old_loc;
    6861          715 :           return true;
    6862              :         }
    6863              : 
    6864           10 :       gfc_current_locus = old_loc;
    6865           10 :       gfc_free_expr (lvalue);
    6866              :     }
    6867              : 
    6868          220 :   m = gfc_match (" %n", sname);
    6869          220 :   if (m != MATCH_YES)
    6870            4 :     goto syntax;
    6871              : 
    6872          216 :   if (strcmp (sname, omp_sym1->name) == 0
    6873          203 :       || strcmp (sname, omp_sym2->name) == 0)
    6874           14 :     goto syntax;
    6875              : 
    6876          202 :   gfc_current_ns = ns->parent;
    6877          202 :   if (gfc_get_ha_sym_tree (sname, &st))
    6878            0 :     goto syntax;
    6879              : 
    6880          202 :   sym = st->n.sym;
    6881          202 :   if (sym->attr.flavor != FL_PROCEDURE
    6882           74 :       && sym->attr.flavor != FL_UNKNOWN)
    6883            1 :     goto syntax;
    6884              : 
    6885          201 :   if (!sym->attr.generic
    6886          191 :       && !sym->attr.subroutine
    6887           73 :       && !sym->attr.function)
    6888              :     {
    6889           73 :       if (!(sym->attr.external && !sym->attr.referenced))
    6890              :         {
    6891              :           /* ...create a symbol in this scope...  */
    6892           73 :           if (sym->ns != gfc_current_ns
    6893           73 :               && gfc_get_sym_tree (sname, NULL, &st, false) == 1)
    6894            0 :             goto syntax;
    6895              : 
    6896           73 :           if (sym != st->n.sym)
    6897           73 :             sym = st->n.sym;
    6898              :         }
    6899              : 
    6900              :       /* ...and then to try to make the symbol into a subroutine.  */
    6901           73 :       if (!gfc_add_subroutine (&sym->attr, sym->name, NULL))
    6902            0 :         goto syntax;
    6903              :     }
    6904              : 
    6905          201 :   gfc_set_sym_referenced (sym);
    6906          201 :   gfc_gobble_whitespace ();
    6907          201 :   if (gfc_peek_ascii_char () != '(')
    6908            6 :     goto syntax;
    6909              : 
    6910          195 :   gfc_current_ns = ns;
    6911          195 :   m = gfc_match_actual_arglist (1, &arglist);
    6912          195 :   if (m != MATCH_YES)
    6913            0 :     goto syntax;
    6914              : 
    6915          195 :   if (gfc_match_char (')') != MATCH_YES)
    6916            0 :     goto syntax;
    6917              : 
    6918          195 :   gfc_clear_error ();
    6919          195 :   ns->code = gfc_get_code (EXEC_CALL);
    6920          195 :   ns->code->symtree = st;
    6921          195 :   ns->code->ext.actual = arglist;
    6922          195 :   ns->code->loc = old_loc;
    6923          195 :   return true;
    6924           25 : syntax:
    6925           25 :   gfc_clear_error ();
    6926           25 :   gfc_error ("Expected either %<%s = expr%> or %<subroutine-name(argument-list)"
    6927              :              "%> followed by %<)%> at %L", omp_sym1->name, &old_loc);
    6928           25 :   return false;
    6929              : }
    6930              : 
    6931              : static bool
    6932         1217 : gfc_omp_udr_predef (gfc_omp_reduction_op rop, const char *name,
    6933              :                     gfc_typespec *ts, const char **n)
    6934              : {
    6935         1217 :   if (!gfc_numeric_ts (ts) && ts->type != BT_LOGICAL)
    6936              :     return false;
    6937              : 
    6938          675 :   switch (rop)
    6939              :     {
    6940           19 :     case OMP_REDUCTION_PLUS:
    6941           19 :     case OMP_REDUCTION_MINUS:
    6942           19 :     case OMP_REDUCTION_TIMES:
    6943           19 :       return ts->type != BT_LOGICAL;
    6944           12 :     case OMP_REDUCTION_AND:
    6945           12 :     case OMP_REDUCTION_OR:
    6946           12 :     case OMP_REDUCTION_EQV:
    6947           12 :     case OMP_REDUCTION_NEQV:
    6948           12 :       return ts->type == BT_LOGICAL;
    6949          643 :     case OMP_REDUCTION_USER:
    6950          643 :       if (name[0] != '.' && (ts->type == BT_INTEGER || ts->type == BT_REAL))
    6951              :         {
    6952          571 :           gfc_symbol *sym;
    6953              : 
    6954          571 :           gfc_find_symbol (name, NULL, 1, &sym);
    6955          571 :           if (sym != NULL)
    6956              :             {
    6957           94 :               if (sym->attr.intrinsic)
    6958            0 :                 *n = sym->name;
    6959           94 :               else if ((sym->attr.flavor != FL_UNKNOWN
    6960           82 :                         && sym->attr.flavor != FL_PROCEDURE)
    6961           70 :                        || sym->attr.external
    6962           55 :                        || sym->attr.generic
    6963           55 :                        || sym->attr.entry
    6964           55 :                        || sym->attr.result
    6965           55 :                        || sym->attr.dummy
    6966           55 :                        || sym->attr.subroutine
    6967           51 :                        || sym->attr.pointer
    6968           51 :                        || sym->attr.target
    6969           51 :                        || sym->attr.cray_pointer
    6970           51 :                        || sym->attr.cray_pointee
    6971           51 :                        || (sym->attr.proc != PROC_UNKNOWN
    6972            1 :                            && sym->attr.proc != PROC_INTRINSIC)
    6973           50 :                        || sym->attr.if_source != IFSRC_UNKNOWN
    6974           50 :                        || sym == sym->ns->proc_name)
    6975           44 :                 *n = NULL;
    6976              :               else
    6977           50 :                 *n = sym->name;
    6978              :             }
    6979              :           else
    6980          477 :             *n = name;
    6981          571 :           if (*n
    6982          527 :               && (strcmp (*n, "max") == 0 || strcmp (*n, "min") == 0))
    6983           56 :             return true;
    6984          533 :           else if (*n
    6985          489 :                    && ts->type == BT_INTEGER
    6986          403 :                    && (strcmp (*n, "iand") == 0
    6987          397 :                        || strcmp (*n, "ior") == 0
    6988          391 :                        || strcmp (*n, "ieor") == 0))
    6989              :             return true;
    6990              :         }
    6991              :       break;
    6992              :     default:
    6993              :       break;
    6994              :     }
    6995              :   return false;
    6996              : }
    6997              : 
    6998              : gfc_omp_udr *
    6999          673 : gfc_omp_udr_find (gfc_symtree *st, gfc_typespec *ts)
    7000              : {
    7001          673 :   gfc_omp_udr *omp_udr;
    7002              : 
    7003          673 :   if (st == NULL)
    7004              :     return NULL;
    7005              : 
    7006          112 :   gfc_symbol *dt = NULL;
    7007          112 :   if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
    7008           25 :     dt = (ts->type == BT_CLASS
    7009            0 :           ? CLASS_DATA (ts->u.derived)->ts.u.derived : ts->u.derived);
    7010          260 :   for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
    7011          161 :     if (omp_udr->ts.type == ts->type
    7012           91 :         || (dt && omp_udr->ts.type == BT_DERIVED))
    7013              :       {
    7014           70 :         if (dt && omp_udr->ts.type == BT_DERIVED)
    7015              :           {
    7016           15 :             gfc_symbol *dtu = omp_udr->ts.u.derived;
    7017           15 :             if (dt == dtu)
    7018              :               return omp_udr;
    7019              :             /* Special case for comparing derived types across namespaces.  If
    7020              :                the true names and module names are the same and the module name
    7021              :                is nonnull, then they are equal.  */
    7022            7 :             if (dt->module && dtu->module
    7023            1 :                 && strcmp (dt->name, dtu->name) == 0
    7024            1 :                 && strcmp (dt->module, dtu->module) == 0)
    7025              :               return omp_udr;
    7026              :           }
    7027           55 :         else if (omp_udr->ts.kind == ts->kind)
    7028              :           {
    7029           20 :             if (omp_udr->ts.type == BT_CHARACTER)
    7030              :               {
    7031           17 :                 if (omp_udr->ts.u.cl->length == NULL
    7032           15 :                     || ts->u.cl->length == NULL)
    7033              :                   return omp_udr;
    7034           15 :                 if (omp_udr->ts.u.cl->length->expr_type != EXPR_CONSTANT)
    7035              :                   return omp_udr;
    7036           15 :                 if (ts->u.cl->length->expr_type != EXPR_CONSTANT)
    7037              :                   return omp_udr;
    7038           15 :                 if (omp_udr->ts.u.cl->length->ts.type != BT_INTEGER)
    7039              :                   return omp_udr;
    7040           15 :                 if (ts->u.cl->length->ts.type != BT_INTEGER)
    7041              :                   return omp_udr;
    7042           15 :                 if (gfc_compare_expr (omp_udr->ts.u.cl->length,
    7043              :                                       ts->u.cl->length, INTRINSIC_EQ) != 0)
    7044           15 :                   continue;
    7045              :               }
    7046              :             return omp_udr;
    7047              :           }
    7048              :       }
    7049              :   return NULL;
    7050              : }
    7051              : 
    7052              : match
    7053          594 : gfc_match_omp_declare_reduction (void)
    7054              : {
    7055          594 :   match m;
    7056          594 :   gfc_intrinsic_op op;
    7057          594 :   char name[GFC_MAX_SYMBOL_LEN + 3];
    7058          594 :   auto_vec<gfc_typespec, 5> tss;
    7059          594 :   gfc_typespec ts;
    7060          594 :   unsigned int i;
    7061          594 :   gfc_symtree *st;
    7062          594 :   locus where = gfc_current_locus;
    7063          594 :   locus end_loc = gfc_current_locus;
    7064          594 :   bool end_loc_set = false;
    7065          594 :   gfc_omp_reduction_op rop = OMP_REDUCTION_NONE;
    7066              : 
    7067          594 :   if (gfc_match_char ('(') != MATCH_YES)
    7068              :     {
    7069            4 :       gfc_error ("Expected %<(%> at %C");
    7070            4 :       return MATCH_ERROR;
    7071              :     }
    7072              : 
    7073          590 :   m = gfc_match (" %o : ", &op);
    7074          590 :   if (m == MATCH_ERROR)
    7075              :     return MATCH_ERROR;
    7076          590 :   if (m == MATCH_YES)
    7077              :     {
    7078          142 :       snprintf (name, sizeof name, "operator %s", gfc_op2string (op));
    7079          142 :       rop = (gfc_omp_reduction_op) op;
    7080              :     }
    7081              :   else
    7082              :     {
    7083          448 :       m = gfc_match_defined_op_name (name + 1, 1);
    7084          448 :       if (m == MATCH_ERROR)
    7085              :         return MATCH_ERROR;
    7086          447 :       if (m == MATCH_YES)
    7087              :         {
    7088           41 :           name[0] = '.';
    7089           41 :           strcat (name, ".");
    7090           41 :           if (gfc_match (" : ") != MATCH_YES)
    7091              :             {
    7092            0 :               gfc_error ("Expected %<:%> at %C");
    7093            0 :               return MATCH_ERROR;
    7094              :             }
    7095              :         }
    7096              :       else
    7097              :         {
    7098          406 :           if (gfc_match (" %n : ", name) != MATCH_YES)
    7099              :             {
    7100            4 :               gfc_error ("Expected an identfifier or operator as reduction "
    7101              :                          "identifier followed by a colon at %C");
    7102            4 :               return MATCH_ERROR;
    7103              :             }
    7104              :         }
    7105              :       rop = OMP_REDUCTION_USER;
    7106              :     }
    7107              : 
    7108          585 :   m = gfc_match_type_spec (&ts);
    7109          585 :   if (m != MATCH_YES)
    7110              :     {
    7111            4 :       gfc_error ("Expected type spec at %C");
    7112            4 :       return MATCH_ERROR;
    7113              :     }
    7114              :   /* Treat len=: the same as len=*.  */
    7115          581 :   if (ts.type == BT_CHARACTER)
    7116           61 :     ts.deferred = false;
    7117          581 :   tss.safe_push (ts);
    7118              : 
    7119         1203 :   while (gfc_match_char (',') == MATCH_YES)
    7120              :     {
    7121           42 :       m = gfc_match_type_spec (&ts);
    7122           42 :       if (m != MATCH_YES)
    7123              :         {
    7124            1 :           gfc_error ("Expected type spec at %C");
    7125            1 :           return MATCH_ERROR;
    7126              :         }
    7127           41 :       tss.safe_push (ts);
    7128              :     }
    7129          580 :   if (gfc_match_char (':') != MATCH_YES)
    7130              :     {
    7131            6 :       gfc_error ("Expected %<:%> or %<,%> at %C");
    7132            6 :       return MATCH_ERROR;
    7133              :     }
    7134              : 
    7135          574 :   st = gfc_find_symtree (gfc_current_ns->omp_udr_root, name);
    7136         1699 :   for (i = 0; i < tss.length (); i++)
    7137              :     {
    7138          610 :       gfc_symtree *omp_out, *omp_in;
    7139          610 :       gfc_symtree *omp_priv = NULL, *omp_orig = NULL;
    7140          610 :       gfc_namespace *combiner_ns, *initializer_ns = NULL;
    7141          610 :       gfc_omp_udr *prev_udr, *omp_udr;
    7142          610 :       const char *predef_name = NULL;
    7143              : 
    7144          610 :       omp_udr = gfc_get_omp_udr ();
    7145          610 :       omp_udr->name = gfc_get_string ("%s", name);
    7146          610 :       omp_udr->rop = rop;
    7147          610 :       omp_udr->ts = tss[i];
    7148          610 :       omp_udr->where = where;
    7149              : 
    7150          610 :       gfc_current_ns = combiner_ns = gfc_get_namespace (gfc_current_ns, 1);
    7151          610 :       combiner_ns->proc_name = combiner_ns->parent->proc_name;
    7152              : 
    7153          610 :       gfc_get_sym_tree ("omp_out", combiner_ns, &omp_out, false);
    7154          610 :       gfc_get_sym_tree ("omp_in", combiner_ns, &omp_in, false);
    7155          610 :       combiner_ns->omp_udr_ns = 1;
    7156          610 :       omp_out->n.sym->ts = tss[i];
    7157          610 :       omp_in->n.sym->ts = tss[i];
    7158          610 :       omp_out->n.sym->attr.omp_udr_artificial_var = 1;
    7159          610 :       omp_in->n.sym->attr.omp_udr_artificial_var = 1;
    7160          610 :       omp_out->n.sym->attr.flavor = FL_VARIABLE;
    7161          610 :       omp_in->n.sym->attr.flavor = FL_VARIABLE;
    7162          610 :       gfc_commit_symbols ();
    7163          610 :       omp_udr->combiner_ns = combiner_ns;
    7164          610 :       omp_udr->omp_out = omp_out->n.sym;
    7165          610 :       omp_udr->omp_in = omp_in->n.sym;
    7166              : 
    7167          610 :       locus old_loc = gfc_current_locus;
    7168              : 
    7169          610 :       if (!match_udr_expr (omp_out, omp_in))
    7170              :         {
    7171           19 :          syntax:
    7172           59 :           gfc_current_ns = combiner_ns->parent;
    7173           59 :           gfc_undo_symbols ();
    7174           59 :           gfc_free_omp_udr (omp_udr);
    7175           59 :           return MATCH_ERROR;
    7176              :         }
    7177          591 :       gfc_match_char (',');  /* optionally  */
    7178          591 :       if (gfc_match (" initializer ( ") == MATCH_YES)
    7179              :         {
    7180          325 :           gfc_current_ns = combiner_ns->parent;
    7181          325 :           initializer_ns = gfc_get_namespace (gfc_current_ns, 1);
    7182          325 :           gfc_current_ns = initializer_ns;
    7183          325 :           initializer_ns->proc_name = initializer_ns->parent->proc_name;
    7184              : 
    7185          325 :           gfc_get_sym_tree ("omp_priv", initializer_ns, &omp_priv, false);
    7186          325 :           gfc_get_sym_tree ("omp_orig", initializer_ns, &omp_orig, false);
    7187          325 :           initializer_ns->omp_udr_ns = 1;
    7188          325 :           omp_priv->n.sym->ts = tss[i];
    7189          325 :           omp_orig->n.sym->ts = tss[i];
    7190          325 :           omp_priv->n.sym->attr.omp_udr_artificial_var = 1;
    7191          325 :           omp_orig->n.sym->attr.omp_udr_artificial_var = 1;
    7192          325 :           omp_priv->n.sym->attr.flavor = FL_VARIABLE;
    7193          325 :           omp_orig->n.sym->attr.flavor = FL_VARIABLE;
    7194          325 :           gfc_commit_symbols ();
    7195          325 :           omp_udr->initializer_ns = initializer_ns;
    7196          325 :           omp_udr->omp_priv = omp_priv->n.sym;
    7197          325 :           omp_udr->omp_orig = omp_orig->n.sym;
    7198              : 
    7199          325 :           if (!match_udr_expr (omp_priv, omp_orig))
    7200            6 :             goto syntax;
    7201              :         }
    7202              : 
    7203          585 :       gfc_current_ns = combiner_ns->parent;
    7204          585 :       if (!end_loc_set)
    7205              :         {
    7206          549 :           end_loc_set = true;
    7207          549 :           end_loc = gfc_current_locus;
    7208              :         }
    7209          585 :       gfc_current_locus = old_loc;
    7210              : 
    7211          585 :       prev_udr = gfc_omp_udr_find (st, &tss[i]);
    7212          585 :       if (gfc_omp_udr_predef (rop, name, &tss[i], &predef_name)
    7213              :           /* Don't error on !$omp declare reduction (min : integer : ...)
    7214              :              just yet, there could be integer :: min afterwards,
    7215              :              making it valid.  When the UDR is resolved, we'll get
    7216              :              to it again.  */
    7217          585 :           && (rop != OMP_REDUCTION_USER || name[0] == '.'))
    7218              :         {
    7219           27 :           if (predef_name)
    7220            0 :             gfc_error_now ("Redefinition of predefined %qs in "
    7221              :                            "!$OMP DECLARE REDUCTION at %L",
    7222              :                            predef_name, &where);
    7223              :           else
    7224           27 :             gfc_error_now ("Redefinition of predefined %qs in "
    7225              :                            "!$OMP DECLARE REDUCTION at %L", name, &where);
    7226           27 :           goto syntax;
    7227              :         }
    7228          558 :       else if (prev_udr)
    7229              :         {
    7230            7 :           gfc_error_now ("Redefinition of %qs in !$OMP DECLARE REDUCTION at %L",
    7231              :                          name, &where);
    7232            7 :           inform (gfc_get_location (&prev_udr->where),
    7233              :                   "Previous !$OMP DECLARE REDUCTION");
    7234            7 :           goto syntax;
    7235              :         }
    7236          551 :       else if (st)
    7237              :         {
    7238           98 :           omp_udr->next = st->n.omp_udr;
    7239           98 :           st->n.omp_udr = omp_udr;
    7240              :         }
    7241              :       else
    7242              :         {
    7243          453 :           st = gfc_new_symtree (&gfc_current_ns->omp_udr_root, name);
    7244          453 :           st->n.omp_udr = omp_udr;
    7245              :         }
    7246              :     }
    7247              : 
    7248          515 :   if (end_loc_set)
    7249              :     {
    7250          515 :       gfc_current_locus = end_loc;
    7251          515 :       if (gfc_match_omp_eos () != MATCH_YES)
    7252              :         {
    7253            4 :           gfc_error ("Unexpected junk at %C");
    7254            4 :           return MATCH_ERROR;
    7255              :         }
    7256              :       return MATCH_YES;
    7257              :     }
    7258              :   return MATCH_ERROR;
    7259          594 : }
    7260              : 
    7261              : 
    7262              : match
    7263          504 : gfc_match_omp_declare_target (void)
    7264              : {
    7265          504 :   locus old_loc;
    7266          504 :   match m;
    7267          504 :   gfc_omp_clauses *c = NULL;
    7268          504 :   enum gfc_omp_list_type list;
    7269          504 :   gfc_omp_namelist *n;
    7270          504 :   gfc_symbol *s;
    7271              : 
    7272          504 :   old_loc = gfc_current_locus;
    7273              : 
    7274          504 :   if (gfc_current_ns->proc_name
    7275          504 :       && gfc_match_omp_eos () == MATCH_YES)
    7276              :     {
    7277          147 :       if (!gfc_add_omp_declare_target (&gfc_current_ns->proc_name->attr,
    7278          147 :                                        gfc_current_ns->proc_name->name,
    7279              :                                        &old_loc))
    7280            0 :         goto cleanup;
    7281              :       return MATCH_YES;
    7282              :     }
    7283              : 
    7284          357 :   if (gfc_current_ns->proc_name
    7285          357 :       && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY)
    7286              :     {
    7287            2 :       gfc_error ("Only the !$OMP DECLARE TARGET form without "
    7288              :                  "clauses is allowed in interface block at %C");
    7289            2 :       goto cleanup;
    7290              :     }
    7291              : 
    7292          355 :   m = gfc_match (" (");
    7293          355 :   if (m == MATCH_YES)
    7294              :     {
    7295           91 :       c = gfc_get_omp_clauses ();
    7296           91 :       gfc_current_locus = old_loc;
    7297           91 :       m = gfc_match_omp_to_link (" (", &c->lists[OMP_LIST_ENTER]);
    7298           91 :       if (m != MATCH_YES)
    7299            0 :         goto syntax;
    7300           91 :       if (gfc_match_omp_eos () != MATCH_YES)
    7301              :         {
    7302            0 :           gfc_error ("Unexpected junk after !$OMP DECLARE TARGET at %C");
    7303            0 :           goto cleanup;
    7304              :         }
    7305              :     }
    7306          264 :   else if (gfc_match_omp_clauses (&c, OMP_DECLARE_TARGET_CLAUSES, false)
    7307              :            != MATCH_YES)
    7308              :     return MATCH_ERROR;
    7309              : 
    7310          349 :   gfc_buffer_error (false);
    7311              : 
    7312          349 :   static const enum gfc_omp_list_type to_enter_link_lists[]
    7313              :     = { OMP_LIST_TO, OMP_LIST_ENTER, OMP_LIST_LINK, OMP_LIST_LOCAL };
    7314         1745 :   for (size_t listn = 0; listn < ARRAY_SIZE (to_enter_link_lists)
    7315         1745 :                          && (list = to_enter_link_lists[listn], true); ++listn)
    7316         1994 :     for (n = c->lists[list]; n; n = n->next)
    7317          598 :       if (n->sym)
    7318          556 :         n->sym->mark = 0;
    7319           42 :       else if (n->u.common->head)
    7320           42 :         n->u.common->head->mark = 0;
    7321              : 
    7322          349 :   if (c->device_type == OMP_DEVICE_TYPE_UNSET)
    7323          281 :     c->device_type = OMP_DEVICE_TYPE_ANY;
    7324         1745 :   for (size_t listn = 0; listn < ARRAY_SIZE (to_enter_link_lists)
    7325         1745 :                          && (list = to_enter_link_lists[listn], true); ++listn)
    7326         1994 :     for (n = c->lists[list]; n; n = n->next)
    7327          598 :       if (n->sym)
    7328              :         {
    7329          556 :           if (n->sym->attr.in_common)
    7330            1 :             gfc_error_now ("OMP DECLARE TARGET variable at %L is an "
    7331              :                            "element of a COMMON block", &n->where);
    7332          555 :           else if (n->sym->attr.omp_groupprivate && list != OMP_LIST_LOCAL)
    7333           12 :             gfc_error_now ("List item %qs at %L should not appear in the %qs "
    7334              :                            "clause, as it was previously specified in a "
    7335              :                            "GROUPPRIVATE directive", n->sym->name, &n->where,
    7336              :                            list == OMP_LIST_LINK
    7337            5 :                            ? "link" : list == OMP_LIST_TO ? "to" : "enter");
    7338          548 :           else if (n->sym->mark)
    7339           11 :             gfc_error_now ("Variable at %L mentioned multiple times in "
    7340              :                            "clauses of the same OMP DECLARE TARGET directive",
    7341              :                            &n->where);
    7342          537 :           else if ((list != OMP_LIST_LINK
    7343          504 :                     && n->sym->attr.omp_declare_target_link)
    7344          502 :                    || (list != OMP_LIST_LOCAL
    7345          521 :                        && n->sym->attr.omp_declare_target_local))
    7346           10 :             gfc_error_now ("OMP DECLARE TARGET variable at %L previously "
    7347              :                            "mentioned in %s clause and later in %s clause",
    7348              :                            &n->where,
    7349            5 :                            n->sym->attr.omp_declare_target_link ? "LINK"
    7350              :                                                                 : "LOCAL",
    7351              :                            (list == OMP_LIST_LOCAL ? "LOCAL"
    7352              :                             : list == OMP_LIST_LINK ? "LINK"
    7353              :                             : list == OMP_LIST_TO ? "TO" : "ENTER"));
    7354          532 :           else if (n->sym->attr.omp_declare_target
    7355           15 :                    && (list == OMP_LIST_LINK || list == OMP_LIST_LOCAL))
    7356            3 :             gfc_error_now ("OMP DECLARE TARGET variable at %L previously "
    7357              :                            "mentioned in TO or ENTER clause and later in "
    7358              :                            "%s clause", &n->where,
    7359              :                            list == OMP_LIST_LINK ? "LINK" : "LOCAL");
    7360              :           else
    7361              :             {
    7362          530 :               if (list == OMP_LIST_TO || list == OMP_LIST_ENTER)
    7363          486 :                 gfc_add_omp_declare_target (&n->sym->attr, n->sym->name,
    7364              :                                             &n->sym->declared_at);
    7365          530 :               if (list == OMP_LIST_LINK)
    7366           31 :                 gfc_add_omp_declare_target_link (&n->sym->attr, n->sym->name,
    7367           31 :                                                  &n->sym->declared_at);
    7368          530 :               if (list == OMP_LIST_LOCAL)
    7369           13 :                 gfc_add_omp_declare_target_local (&n->sym->attr, n->sym->name,
    7370           13 :                                                   &n->sym->declared_at);
    7371              :             }
    7372          556 :           if (n->sym->attr.omp_device_type != OMP_DEVICE_TYPE_UNSET
    7373           43 :               && n->sym->attr.omp_device_type != c->device_type)
    7374              :             {
    7375           12 :               const char *dt = "any";
    7376           12 :               if (n->sym->attr.omp_device_type == OMP_DEVICE_TYPE_NOHOST)
    7377              :                 dt = "nohost";
    7378            8 :               else if (n->sym->attr.omp_device_type == OMP_DEVICE_TYPE_HOST)
    7379            4 :                 dt = "host";
    7380           12 :               if (n->sym->attr.omp_groupprivate)
    7381            1 :                 gfc_error_now ("List item %qs at %L set in previous OMP "
    7382              :                                "GROUPPRIVATE directive to the different "
    7383              :                                "DEVICE_TYPE %qs", n->sym->name, &n->where, dt);
    7384              :               else
    7385           11 :                 gfc_error_now ("List item %qs at %L set in previous OMP "
    7386              :                                "DECLARE TARGET directive to the different "
    7387              :                                "DEVICE_TYPE %qs", n->sym->name, &n->where, dt);
    7388              :             }
    7389          556 :           n->sym->attr.omp_device_type = c->device_type;
    7390          556 :           if (c->indirect && c->device_type != OMP_DEVICE_TYPE_ANY)
    7391              :             {
    7392            1 :               gfc_error_now ("DEVICE_TYPE must be ANY when used with INDIRECT "
    7393              :                              "at %L", &n->where);
    7394            1 :               c->indirect = 0;
    7395              :             }
    7396          556 :           n->sym->attr.omp_declare_target_indirect = c->indirect;
    7397          556 :           if (list == OMP_LIST_LINK && c->device_type == OMP_DEVICE_TYPE_NOHOST)
    7398            3 :             gfc_error_now ("List item %qs at %L set with NOHOST specified may "
    7399              :                            "not appear in a LINK clause", n->sym->name,
    7400              :                            &n->where);
    7401          556 :           n->sym->mark = 1;
    7402              :         }
    7403              :       else  /* common block  */
    7404              :         {
    7405           42 :           if (n->u.common->omp_groupprivate && list != OMP_LIST_LOCAL)
    7406            7 :             gfc_error_now ("Common block %</%s/%> at %L not appear in the %qs "
    7407              :                            "clause as it was previously specified in a "
    7408              :                            "GROUPPRIVATE directive",
    7409            7 :                            n->u.common->name, &n->where,
    7410              :                            list == OMP_LIST_LINK
    7411            5 :                            ? "link" : list == OMP_LIST_TO ? "to" : "enter");
    7412           35 :           else if (n->u.common->head && n->u.common->head->mark)
    7413            4 :             gfc_error_now ("Common block %</%s/%> at %L mentioned multiple "
    7414              :                            "times in clauses of the same OMP DECLARE TARGET "
    7415            4 :                            "directive", n->u.common->name, &n->where);
    7416           31 :           else if ((n->u.common->omp_declare_target_link
    7417           27 :                     || n->u.common->omp_declare_target_local)
    7418              :                    && list != OMP_LIST_LINK
    7419            6 :                    && list != OMP_LIST_LOCAL)
    7420            2 :             gfc_error_now ("Common block %</%s/%> at %L previously mentioned "
    7421              :                            "in %s clause and later in %s clause",
    7422            1 :                            n->u.common->name, &n->where,
    7423              :                            n->u.common->omp_declare_target_link ? "LINK"
    7424              :                                                                 : "LOCAL",
    7425              :                            list == OMP_LIST_TO ? "TO" : "ENTER");
    7426           30 :           else if (n->u.common->omp_declare_target
    7427            4 :                    && (list == OMP_LIST_LINK || list == OMP_LIST_LOCAL))
    7428            1 :             gfc_error_now ("Common block %</%s/%> at %L previously mentioned "
    7429              :                            "in TO or ENTER clause and later in %s clause",
    7430            1 :                            n->u.common->name, &n->where,
    7431              :                            list == OMP_LIST_LINK ? "LINK" : "LOCAL");
    7432           42 :           if (n->u.common->omp_device_type != OMP_DEVICE_TYPE_UNSET
    7433           21 :               && n->u.common->omp_device_type != c->device_type)
    7434              :             {
    7435            1 :               const char *dt = "any";
    7436            1 :               if (n->u.common->omp_device_type == OMP_DEVICE_TYPE_NOHOST)
    7437              :                 dt = "nohost";
    7438            0 :               else if (n->u.common->omp_device_type == OMP_DEVICE_TYPE_HOST)
    7439            0 :                 dt = "host";
    7440            1 :               if (n->u.common->omp_groupprivate)
    7441            1 :                 gfc_error_now ("Common block %</%s/%> at %L set in previous OMP "
    7442              :                                "GROUPPRIVATE directive to the different "
    7443            1 :                                "DEVICE_TYPE %qs", n->u.common->name, &n->where,
    7444              :                                 dt);
    7445              :               else
    7446            0 :                 gfc_error_now ("Common block %</%s/%> at %L set in previous OMP "
    7447              :                                "DECLARE TARGET directive to the different "
    7448            0 :                                "DEVICE_TYPE %qs", n->u.common->name, &n->where,
    7449              :                                 dt);
    7450              :             }
    7451           42 :           n->u.common->omp_device_type = c->device_type;
    7452              : 
    7453           42 :           if (c->indirect && c->device_type != OMP_DEVICE_TYPE_ANY)
    7454              :             {
    7455            0 :               gfc_error_now ("DEVICE_TYPE must be ANY when used with INDIRECT "
    7456              :                              "at %L", &n->where);
    7457            0 :               c->indirect = 0;
    7458              :             }
    7459           42 :           if (list == OMP_LIST_LINK && c->device_type == OMP_DEVICE_TYPE_NOHOST)
    7460            1 :             gfc_error_now ("Common block %</%s/%> at %L set with NOHOST "
    7461              :                            "specified may not appear in a LINK clause",
    7462            1 :                            n->u.common->name, &n->where);
    7463              : 
    7464           42 :           if (list == OMP_LIST_TO || list == OMP_LIST_ENTER)
    7465           21 :             n->u.common->omp_declare_target = 1;
    7466           42 :           if (list == OMP_LIST_LINK)
    7467           15 :             n->u.common->omp_declare_target_link = 1;
    7468           42 :           if (list == OMP_LIST_LOCAL)
    7469            6 :             n->u.common->omp_declare_target_local = 1;
    7470              : 
    7471          112 :           for (s = n->u.common->head; s; s = s->common_next)
    7472              :             {
    7473           70 :               s->mark = 1;
    7474           70 :               if (list == OMP_LIST_TO || list == OMP_LIST_ENTER)
    7475           33 :                 gfc_add_omp_declare_target (&s->attr, s->name, &n->where);
    7476           70 :               if (list == OMP_LIST_LINK)
    7477           31 :                 gfc_add_omp_declare_target_link (&s->attr, s->name, &n->where);
    7478           70 :               if (list == OMP_LIST_LOCAL)
    7479            6 :                 gfc_add_omp_declare_target_local (&s->attr, s->name, &n->where);
    7480           70 :               s->attr.omp_device_type = c->device_type;
    7481           70 :               s->attr.omp_declare_target_indirect = c->indirect;
    7482              :             }
    7483              :         }
    7484          349 :   if ((c->device_type || c->indirect)
    7485          349 :       && !c->lists[OMP_LIST_ENTER]
    7486          161 :       && !c->lists[OMP_LIST_TO]
    7487           56 :       && !c->lists[OMP_LIST_LINK]
    7488           17 :       && !c->lists[OMP_LIST_LOCAL])
    7489            2 :     gfc_warning_now (OPT_Wopenmp,
    7490              :                      "OMP DECLARE TARGET directive at %L with only "
    7491              :                      "DEVICE_TYPE or INDIRECT clauses is ignored",
    7492              :                      &old_loc);
    7493              : 
    7494          349 :   gfc_buffer_error (true);
    7495              : 
    7496          349 :   if (c)
    7497          349 :     gfc_free_omp_clauses (c);
    7498              :   return MATCH_YES;
    7499              : 
    7500            0 : syntax:
    7501            0 :   gfc_error ("Syntax error in !$OMP DECLARE TARGET list at %C");
    7502              : 
    7503            2 : cleanup:
    7504            2 :   gfc_current_locus = old_loc;
    7505            2 :   if (c)
    7506            0 :     gfc_free_omp_clauses (c);
    7507              :   return MATCH_ERROR;
    7508              : }
    7509              : 
    7510              : /* Skip over and ignore trait-property-extensions.
    7511              : 
    7512              :    trait-property-extension :
    7513              :      trait-property-name
    7514              :      identifier (trait-property-extension[, trait-property-extension[, ...]])
    7515              :      constant integer expression
    7516              :  */
    7517              : 
    7518              : static match gfc_ignore_trait_property_extension_list (void);
    7519              : 
    7520              : static match
    7521            7 : gfc_ignore_trait_property_extension (void)
    7522              : {
    7523            7 :   char buf[GFC_MAX_SYMBOL_LEN + 1];
    7524            7 :   gfc_expr *expr;
    7525              : 
    7526              :   /* Identifier form of trait-property name, possibly followed by
    7527              :      a list of (recursive) trait-property-extensions.  */
    7528            7 :   if (gfc_match_name (buf) == MATCH_YES)
    7529              :     {
    7530            0 :       if (gfc_match (" (") == MATCH_YES)
    7531            0 :         return gfc_ignore_trait_property_extension_list ();
    7532              :       return MATCH_YES;
    7533              :     }
    7534              : 
    7535              :   /* Literal constant.  */
    7536            7 :   if (gfc_match_literal_constant (&expr, 0) == MATCH_YES)
    7537              :     return MATCH_YES;
    7538              : 
    7539              :   /* FIXME: constant integer expressions.  */
    7540            0 :   gfc_error ("Expected trait-property-extension at %C");
    7541            0 :   return MATCH_ERROR;
    7542              : }
    7543              : 
    7544              : static match
    7545            5 : gfc_ignore_trait_property_extension_list (void)
    7546              : {
    7547            9 :   while (1)
    7548              :     {
    7549            7 :       if (gfc_ignore_trait_property_extension () != MATCH_YES)
    7550              :         return MATCH_ERROR;
    7551            7 :       if (gfc_match (" ,") == MATCH_YES)
    7552            2 :         continue;
    7553            5 :       if (gfc_match (" )") == MATCH_YES)
    7554              :         return MATCH_YES;
    7555            0 :       gfc_error ("expected %<)%> at %C");
    7556            0 :       return MATCH_ERROR;
    7557              :     }
    7558              : }
    7559              : 
    7560              : 
    7561              : match
    7562          110 : gfc_match_omp_interop (void)
    7563              : {
    7564          110 :   return match_omp (EXEC_OMP_INTEROP, OMP_INTEROP_CLAUSES);
    7565              : }
    7566              : 
    7567              : 
    7568              : /* OpenMP 5.0:
    7569              : 
    7570              :    trait-selector:
    7571              :      trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])]
    7572              : 
    7573              :    trait-score:
    7574              :      score(score-expression)  */
    7575              : 
    7576              : static match
    7577          662 : gfc_match_omp_context_selector (gfc_omp_set_selector *oss)
    7578              : {
    7579          803 :   do
    7580              :     {
    7581          803 :       char selector[GFC_MAX_SYMBOL_LEN + 1];
    7582              : 
    7583          803 :       if (gfc_match_name (selector) != MATCH_YES)
    7584              :         {
    7585            2 :           gfc_error ("expected trait selector name at %C");
    7586           39 :           return MATCH_ERROR;
    7587              :         }
    7588              : 
    7589          801 :       gfc_omp_selector *os = gfc_get_omp_selector ();
    7590          801 :       if (oss->code == OMP_TRAIT_SET_CONSTRUCT
    7591          351 :           && !strcmp (selector, "do"))
    7592           48 :         os->code = OMP_TRAIT_CONSTRUCT_FOR;
    7593          753 :       else if (oss->code == OMP_TRAIT_SET_CONSTRUCT
    7594          303 :                && !strcmp (selector, "for"))
    7595            1 :         os->code = OMP_TRAIT_INVALID;
    7596              :       else
    7597          752 :         os->code = omp_lookup_ts_code (oss->code, selector);
    7598          801 :       os->next = oss->trait_selectors;
    7599          801 :       oss->trait_selectors = os;
    7600              : 
    7601          801 :       if (os->code == OMP_TRAIT_INVALID)
    7602              :         {
    7603           18 :           gfc_warning (OPT_Wopenmp,
    7604              :                        "unknown selector %qs for context selector set %qs "
    7605              :                        "at %C",
    7606           18 :                        selector, omp_tss_map[oss->code]);
    7607           18 :           if (gfc_match (" (") == MATCH_YES
    7608           18 :               && gfc_ignore_trait_property_extension_list () != MATCH_YES)
    7609              :             return MATCH_ERROR;
    7610           18 :           if (gfc_match (" ,") == MATCH_YES)
    7611            1 :             continue;
    7612          623 :           break;
    7613              :         }
    7614              : 
    7615          783 :       enum omp_tp_type property_kind = omp_ts_map[os->code].tp_type;
    7616          783 :       bool allow_score = omp_ts_map[os->code].allow_score;
    7617              : 
    7618          783 :       if (gfc_match (" (") == MATCH_YES)
    7619              :         {
    7620          451 :           if (property_kind == OMP_TRAIT_PROPERTY_NONE)
    7621              :             {
    7622            6 :               gfc_error ("selector %qs does not accept any properties at %C",
    7623              :                          selector);
    7624            6 :               return MATCH_ERROR;
    7625              :             }
    7626              : 
    7627          445 :           if (gfc_match (" score") == MATCH_YES)
    7628              :             {
    7629           63 :               if (!allow_score)
    7630              :                 {
    7631           10 :                   gfc_error ("%<score%> cannot be specified in traits "
    7632              :                              "in the %qs trait-selector-set at %C",
    7633           10 :                              omp_tss_map[oss->code]);
    7634           10 :                   return MATCH_ERROR;
    7635              :                 }
    7636           53 :               if (gfc_match (" (") != MATCH_YES)
    7637              :                 {
    7638            0 :                   gfc_error ("expected %<(%> at %C");
    7639            0 :                   return MATCH_ERROR;
    7640              :                 }
    7641           53 :               if (gfc_match_expr (&os->score) != MATCH_YES)
    7642              :                 return MATCH_ERROR;
    7643              : 
    7644           52 :               if (gfc_match (" )") != MATCH_YES)
    7645              :                 {
    7646            0 :                   gfc_error ("expected %<)%> at %C");
    7647            0 :                   return MATCH_ERROR;
    7648              :                 }
    7649              : 
    7650           52 :               if (gfc_match (" :") != MATCH_YES)
    7651              :                 {
    7652            0 :                   gfc_error ("expected : at %C");
    7653            0 :                   return MATCH_ERROR;
    7654              :                 }
    7655              :             }
    7656              : 
    7657          434 :           gfc_omp_trait_property *otp = gfc_get_omp_trait_property ();
    7658          434 :           otp->property_kind = property_kind;
    7659          434 :           otp->next = os->properties;
    7660          434 :           os->properties = otp;
    7661              : 
    7662          434 :           switch (property_kind)
    7663              :             {
    7664           25 :             case OMP_TRAIT_PROPERTY_ID:
    7665           25 :               {
    7666           25 :                 char buf[GFC_MAX_SYMBOL_LEN + 1];
    7667           25 :                 if (gfc_match_name (buf) == MATCH_YES)
    7668              :                   {
    7669           24 :                     otp->name = XNEWVEC (char, strlen (buf) + 1);
    7670           24 :                     strcpy (otp->name, buf);
    7671              :                   }
    7672              :                 else
    7673              :                   {
    7674            1 :                     gfc_error ("expected identifier at %C");
    7675            1 :                     free (otp);
    7676            1 :                     os->properties = nullptr;
    7677            1 :                     return MATCH_ERROR;
    7678              :                   }
    7679              :               }
    7680           24 :               break;
    7681          294 :             case OMP_TRAIT_PROPERTY_NAME_LIST:
    7682          347 :               do
    7683              :                 {
    7684          294 :                   char buf[GFC_MAX_SYMBOL_LEN + 1];
    7685          294 :                   if (gfc_match_name (buf) == MATCH_YES)
    7686              :                     {
    7687          172 :                       otp->name = XNEWVEC (char, strlen (buf) + 1);
    7688          172 :                       strcpy (otp->name, buf);
    7689          172 :                       otp->is_name = true;
    7690              :                     }
    7691          122 :                   else if (gfc_match_literal_constant (&otp->expr, 0)
    7692              :                            != MATCH_YES
    7693          122 :                            || otp->expr->ts.type != BT_CHARACTER)
    7694              :                     {
    7695            5 :                       gfc_error ("expected identifier or string literal "
    7696              :                                  "at %C");
    7697            5 :                       free (otp);
    7698            5 :                       os->properties = nullptr;
    7699            5 :                       return MATCH_ERROR;
    7700              :                     }
    7701              : 
    7702          289 :                   if (gfc_match (" ,") == MATCH_YES)
    7703              :                     {
    7704           53 :                       otp = gfc_get_omp_trait_property ();
    7705           53 :                       otp->property_kind = property_kind;
    7706           53 :                       otp->next = os->properties;
    7707           53 :                       os->properties = otp;
    7708              :                     }
    7709              :                   else
    7710              :                     break;
    7711           53 :                 }
    7712              :               while (1);
    7713          236 :               break;
    7714          145 :             case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
    7715          145 :             case OMP_TRAIT_PROPERTY_BOOL_EXPR:
    7716          145 :               if (gfc_match_expr (&otp->expr) != MATCH_YES)
    7717              :                 {
    7718            3 :                   gfc_error ("expected expression at %C");
    7719            3 :                   free (otp);
    7720            3 :                   os->properties = nullptr;
    7721            3 :                   return MATCH_ERROR;
    7722              :                 }
    7723              :               break;
    7724           23 :             case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
    7725           23 :               {
    7726           23 :                 if (os->code == OMP_TRAIT_CONSTRUCT_SIMD)
    7727              :                   {
    7728           23 :                     gfc_matching_omp_context_selector = true;
    7729           23 :                     if (gfc_match_omp_clauses (&otp->clauses,
    7730           23 :                                                OMP_DECLARE_SIMD_CLAUSES,
    7731              :                                                true, false, false)
    7732              :                         != MATCH_YES)
    7733              :                       {
    7734            1 :                         gfc_matching_omp_context_selector = false;
    7735            1 :                         gfc_error ("expected simd clause at %C");
    7736            1 :                         return MATCH_ERROR;
    7737              :                       }
    7738           22 :                     gfc_matching_omp_context_selector = false;
    7739              :                   }
    7740            0 :                 else if (os->code == OMP_TRAIT_IMPLEMENTATION_REQUIRES)
    7741              :                   {
    7742              :                     /* FIXME: The "requires" selector was added in OpenMP 5.1.
    7743              :                        Currently only the now-deprecated syntax
    7744              :                        from OpenMP 5.0 is supported.
    7745              :                        TODO: When implementing, update modules.cc as well.  */
    7746            0 :                     sorry_at (gfc_get_location (&gfc_current_locus),
    7747              :                               "%<requires%> selector is not supported yet");
    7748            0 :                     return MATCH_ERROR;
    7749              :                   }
    7750              :                 else
    7751            0 :                   gcc_unreachable ();
    7752           22 :                 break;
    7753              :               }
    7754            0 :             default:
    7755            0 :               gcc_unreachable ();
    7756              :             }
    7757              : 
    7758          424 :           if (gfc_match (" )") != MATCH_YES)
    7759              :             {
    7760            2 :               gfc_error ("expected %<)%> at %C");
    7761            2 :               return MATCH_ERROR;
    7762              :             }
    7763              :         }
    7764          332 :       else if (property_kind != OMP_TRAIT_PROPERTY_NONE
    7765          332 :                && property_kind != OMP_TRAIT_PROPERTY_CLAUSE_LIST
    7766            8 :                && property_kind != OMP_TRAIT_PROPERTY_EXTENSION)
    7767              :         {
    7768            8 :           if (gfc_match (" (") != MATCH_YES)
    7769              :             {
    7770            8 :               gfc_error ("expected %<(%> at %C");
    7771            8 :               return MATCH_ERROR;
    7772              :             }
    7773              :         }
    7774              : 
    7775          746 :       if (gfc_match (" ,") != MATCH_YES)
    7776              :         break;
    7777              :     }
    7778              :   while (1);
    7779              : 
    7780          623 :   return MATCH_YES;
    7781              : }
    7782              : 
    7783              : /* OpenMP 5.0:
    7784              : 
    7785              :    trait-set-selector[,trait-set-selector[,...]]
    7786              : 
    7787              :    trait-set-selector:
    7788              :      trait-set-selector-name = { trait-selector[, trait-selector[, ...]] }
    7789              : 
    7790              :    trait-set-selector-name:
    7791              :      constructor
    7792              :      device
    7793              :      implementation
    7794              :      user  */
    7795              : 
    7796              : static match
    7797          600 : gfc_match_omp_context_selector_specification (gfc_omp_set_selector **oss_head)
    7798              : {
    7799          740 :   do
    7800              :     {
    7801          670 :       match m;
    7802          670 :       char buf[GFC_MAX_SYMBOL_LEN + 1];
    7803          670 :       enum omp_tss_code set = OMP_TRAIT_SET_INVALID;
    7804              : 
    7805          670 :       m = gfc_match_name (buf);
    7806          670 :       if (m == MATCH_YES)
    7807          668 :         set = omp_lookup_tss_code (buf);
    7808              : 
    7809          668 :       if (set == OMP_TRAIT_SET_INVALID)
    7810              :         {
    7811            5 :           gfc_error ("expected context selector set name at %C");
    7812           47 :           return MATCH_ERROR;
    7813              :         }
    7814              : 
    7815          665 :       m = gfc_match (" =");
    7816          665 :       if (m != MATCH_YES)
    7817              :         {
    7818            1 :           gfc_error ("expected %<=%> at %C");
    7819            1 :           return MATCH_ERROR;
    7820              :         }
    7821              : 
    7822          664 :       m = gfc_match (" {");
    7823          664 :       if (m != MATCH_YES)
    7824              :         {
    7825            2 :           gfc_error ("expected %<{%> at %C");
    7826            2 :           return MATCH_ERROR;
    7827              :         }
    7828              : 
    7829          662 :       gfc_omp_set_selector *oss = gfc_get_omp_set_selector ();
    7830          662 :       oss->next = *oss_head;
    7831          662 :       oss->code = set;
    7832          662 :       *oss_head = oss;
    7833              : 
    7834          662 :       if (gfc_match_omp_context_selector (oss) != MATCH_YES)
    7835              :         return MATCH_ERROR;
    7836              : 
    7837          623 :       m = gfc_match (" }");
    7838          623 :       if (m != MATCH_YES)
    7839              :         {
    7840            0 :           gfc_error ("expected %<}%> at %C");
    7841            0 :           return MATCH_ERROR;
    7842              :         }
    7843              : 
    7844          623 :       m = gfc_match (" ,");
    7845          623 :       if (m != MATCH_YES)
    7846              :         break;
    7847           70 :     }
    7848              :   while (1);
    7849              : 
    7850          553 :   return MATCH_YES;
    7851              : }
    7852              : 
    7853              : 
    7854              : match
    7855          434 : gfc_match_omp_declare_variant (void)
    7856              : {
    7857          434 :   char buf[GFC_MAX_SYMBOL_LEN + 1];
    7858              : 
    7859          434 :   if (gfc_match (" (") != MATCH_YES)
    7860              :     {
    7861            2 :       gfc_error ("expected %<(%> at %C");
    7862            2 :       return MATCH_ERROR;
    7863              :     }
    7864              : 
    7865          432 :   gfc_symtree *base_proc_st, *variant_proc_st;
    7866          432 :   if (gfc_match_name (buf) != MATCH_YES)
    7867              :     {
    7868            2 :       gfc_error ("expected name at %C");
    7869            2 :       return MATCH_ERROR;
    7870              :     }
    7871              : 
    7872          430 :   if (gfc_get_ha_sym_tree (buf, &base_proc_st))
    7873              :     return MATCH_ERROR;
    7874              : 
    7875          430 :   if (gfc_match (" :") == MATCH_YES)
    7876              :     {
    7877           16 :       if (gfc_match_name (buf) != MATCH_YES)
    7878              :         {
    7879            0 :           gfc_error ("expected variant name at %C");
    7880            0 :           return MATCH_ERROR;
    7881              :         }
    7882              : 
    7883           16 :       if (gfc_get_ha_sym_tree (buf, &variant_proc_st))
    7884              :         return MATCH_ERROR;
    7885              :     }
    7886              :   else
    7887              :     {
    7888              :       /* Base procedure not specified.  */
    7889          414 :       variant_proc_st = base_proc_st;
    7890          414 :       base_proc_st = NULL;
    7891              :     }
    7892              : 
    7893          430 :   gfc_omp_declare_variant *odv;
    7894          430 :   odv = gfc_get_omp_declare_variant ();
    7895          430 :   odv->where = gfc_current_locus;
    7896          430 :   odv->variant_proc_symtree = variant_proc_st;
    7897          430 :   odv->adjust_args_list = NULL;
    7898          430 :   odv->base_proc_symtree = base_proc_st;
    7899          430 :   odv->next = NULL;
    7900          430 :   odv->error_p = false;
    7901              : 
    7902              :   /* Add the new declare variant to the end of the list.  */
    7903          430 :   gfc_omp_declare_variant **prev_next = &gfc_current_ns->omp_declare_variant;
    7904          597 :   while (*prev_next)
    7905          167 :     prev_next = &((*prev_next)->next);
    7906          430 :   *prev_next = odv;
    7907              : 
    7908          430 :   if (gfc_match (" )") != MATCH_YES)
    7909              :     {
    7910            1 :       gfc_error ("expected %<)%> at %C");
    7911            1 :       return MATCH_ERROR;
    7912              :     }
    7913              : 
    7914          429 :   bool has_match = false, has_adjust_args = false, has_append_args = false;
    7915          429 :   bool error_p = false;
    7916          429 :   locus adjust_args_loc;
    7917          429 :   locus append_args_loc;
    7918              : 
    7919          429 :   gfc_gobble_whitespace ();
    7920          429 :   gfc_match_char (',');
    7921          647 :   for (;;)
    7922              :     {
    7923          538 :       gfc_gobble_whitespace ();
    7924              : 
    7925          538 :       enum clause
    7926              :       {
    7927              :         clause_match,
    7928              :         clause_adjust_args,
    7929              :         clause_append_args
    7930              :       } ccode;
    7931              : 
    7932          538 :       if (gfc_match ("match") == MATCH_YES)
    7933              :         ccode = clause_match;
    7934          119 :       else if (gfc_match ("adjust_args") == MATCH_YES)
    7935              :         {
    7936          532 :           ccode = clause_adjust_args;
    7937              :           adjust_args_loc = gfc_current_locus;
    7938              :         }
    7939           38 :       else if (gfc_match ("append_args") == MATCH_YES)
    7940              :         {
    7941          532 :           ccode = clause_append_args;
    7942              :           append_args_loc = gfc_current_locus;
    7943              :         }
    7944              :       else
    7945              :         {
    7946              :           error_p = true;
    7947              :           break;
    7948              :         }
    7949              : 
    7950          532 :       if (gfc_match (" ( ") != MATCH_YES)
    7951              :         {
    7952            1 :           gfc_error ("expected %<(%> at %C");
    7953            1 :           return MATCH_ERROR;
    7954              :         }
    7955              : 
    7956          531 :       if (ccode == clause_match)
    7957              :         {
    7958          418 :           if (has_match)
    7959              :             {
    7960            1 :               gfc_error ("%qs clause at %L specified more than once",
    7961              :                          "match", &gfc_current_locus);
    7962            1 :               return MATCH_ERROR;
    7963              :             }
    7964          417 :           has_match = true;
    7965          417 :           if (gfc_match_omp_context_selector_specification (&odv->set_selectors)
    7966              :               != MATCH_YES)
    7967              :             return MATCH_ERROR;
    7968          377 :           if (gfc_match (" )") != MATCH_YES)
    7969              :             {
    7970            0 :               gfc_error ("expected %<)%> at %C");
    7971            0 :               return MATCH_ERROR;
    7972              :             }
    7973              :         }
    7974          113 :       else if (ccode == clause_adjust_args)
    7975              :         {
    7976           81 :           has_adjust_args = true;
    7977           81 :           bool need_device_ptr_p = false;
    7978           81 :           bool need_device_addr_p = false;
    7979           81 :           if (gfc_match ("nothing ") == MATCH_YES)
    7980              :             ;
    7981           58 :           else if (gfc_match ("need_device_ptr ") == MATCH_YES)
    7982              :             need_device_ptr_p = true;
    7983            9 :           else if (gfc_match ("need_device_addr ") == MATCH_YES)
    7984              :             need_device_addr_p = true;
    7985              :           else
    7986              :             {
    7987            2 :               gfc_error ("expected %<nothing%>, %<need_device_ptr%> or "
    7988              :                          "%<need_device_addr%> at %C");
    7989            2 :               return MATCH_ERROR;
    7990              :             }
    7991           79 :           if (gfc_match (": ") != MATCH_YES)
    7992              :             {
    7993            1 :               gfc_error ("expected %<:%> at %C");
    7994            1 :               return MATCH_ERROR;
    7995              :             }
    7996              :           gfc_omp_namelist *tail = NULL;
    7997              :           bool need_range = false, have_range = false;
    7998          125 :           while (true)
    7999              :             {
    8000          125 :               gfc_omp_namelist *p = gfc_get_omp_namelist ();
    8001          125 :               p->where = gfc_current_locus;
    8002          125 :               p->u.adj_args.need_ptr = need_device_ptr_p;
    8003          125 :               p->u.adj_args.need_addr = need_device_addr_p;
    8004          125 :               if (tail)
    8005              :                 {
    8006           47 :                   tail->next = p;
    8007           47 :                   tail = tail->next;
    8008              :                 }
    8009              :               else
    8010              :                 {
    8011           78 :                   gfc_omp_namelist **q = &odv->adjust_args_list;
    8012           78 :                   if (*q)
    8013              :                     {
    8014           50 :                       for (; (*q)->next; q = &(*q)->next)
    8015              :                         ;
    8016           28 :                       (*q)->next = p;
    8017              :                     }
    8018              :                   else
    8019           50 :                     *q = p;
    8020              :                   tail = p;
    8021              :                 }
    8022          125 :               if (gfc_match (": ") == MATCH_YES)
    8023              :                 {
    8024            2 :                   if (have_range)
    8025              :                     {
    8026            0 :                       gfc_error ("unexpected %<:%> at %C");
    8027            2 :                       return MATCH_ERROR;
    8028              :                     }
    8029            2 :                   p->u.adj_args.range_start = have_range = true;
    8030            2 :                   need_range = false;
    8031           47 :                   continue;
    8032              :                 }
    8033          123 :               if (have_range && gfc_match (", ") == MATCH_YES)
    8034              :                 {
    8035            1 :                  have_range = false;
    8036            1 :                  continue;
    8037              :                 }
    8038          122 :               if (have_range && gfc_match (") ") == MATCH_YES)
    8039              :                 break;
    8040          121 :               locus saved_loc = gfc_current_locus;
    8041              : 
    8042              :               /* Without ranges, only arg names or integer literals permitted;
    8043              :                  handle literals here as gfc_match_expr simplifies the expr.  */
    8044          121 :               if (gfc_match_literal_constant (&p->expr, true) == MATCH_YES)
    8045              :                 {
    8046           17 :                   gfc_gobble_whitespace ();
    8047           17 :                   char c = gfc_peek_ascii_char ();
    8048           17 :                   if (c != ')' && c != ',' && c != ':')
    8049              :                     {
    8050            1 :                       gfc_free_expr (p->expr);
    8051            1 :                       p->expr = NULL;
    8052            1 :                       gfc_current_locus = saved_loc;
    8053              :                     }
    8054              :                 }
    8055          121 :               if (!p->expr && gfc_match ("omp_num_args") == MATCH_YES)
    8056              :                 {
    8057            6 :                   if (!have_range)
    8058            3 :                     p->u.adj_args.range_start = need_range = true;
    8059              :                   else
    8060              :                     need_range = false;
    8061              : 
    8062            6 :                   locus saved_loc2 = gfc_current_locus;
    8063            6 :                   gfc_gobble_whitespace ();
    8064            6 :                   char c = gfc_peek_ascii_char ();
    8065            6 :                   if (c == '+' || c == '-')
    8066              :                     {
    8067            5 :                       if (gfc_match ("+ %e", &p->expr) == MATCH_YES)
    8068            1 :                         p->u.adj_args.omp_num_args_plus = true;
    8069            4 :                       else if (gfc_match ("- %e", &p->expr) == MATCH_YES)
    8070            4 :                         p->u.adj_args.omp_num_args_minus = true;
    8071            0 :                       else if (!gfc_error_check ())
    8072              :                         {
    8073            0 :                           gfc_error ("expected constant integer expression "
    8074              :                                      "at %C");
    8075            0 :                           p->u.adj_args.error_p = true;
    8076            0 :                           return MATCH_ERROR;
    8077              :                         }
    8078            5 :                       p->where = gfc_get_location_range (&saved_loc, 1,
    8079              :                                                          &saved_loc, 1,
    8080              :                                                          &gfc_current_locus);
    8081              :                     }
    8082              :                   else
    8083              :                     {
    8084            1 :                       p->where = gfc_get_location_range (&saved_loc, 1,
    8085              :                                                          &saved_loc, 1,
    8086              :                                                          &saved_loc2);
    8087            1 :                       p->u.adj_args.omp_num_args_plus = true;
    8088              :                     }
    8089              :                 }
    8090          115 :               else if (!p->expr)
    8091              :                 {
    8092           99 :                   match m = gfc_match_expr (&p->expr);
    8093           99 :                   if (m != MATCH_YES)
    8094              :                     {
    8095            1 :                       gfc_error ("expected dummy parameter name, "
    8096              :                                  "%<omp_num_args%> or constant positive integer"
    8097              :                                  " at %C");
    8098            1 :                       p->u.adj_args.error_p = true;
    8099            1 :                       return MATCH_ERROR;
    8100              :                     }
    8101           98 :                   if (p->expr->expr_type == EXPR_CONSTANT && !have_range)
    8102           98 :                     need_range = true;  /* Constant expr but not literal.  */
    8103           98 :                   p->where = p->expr->where;
    8104              :                 }
    8105              :               else
    8106           16 :                 p->where = p->expr->where;
    8107          120 :               gfc_gobble_whitespace ();
    8108          120 :               match m = gfc_match (": ");
    8109          120 :               if (need_range && m != MATCH_YES)
    8110              :                 {
    8111            1 :                   gfc_error ("expected %<:%> at %C");
    8112            1 :                   return MATCH_ERROR;
    8113              :                 }
    8114          119 :               if (m == MATCH_YES)
    8115              :                 {
    8116            6 :                   p->u.adj_args.range_start = have_range = true;
    8117            6 :                   need_range = false;
    8118            6 :                   continue;
    8119              :                 }
    8120          113 :               need_range = have_range = false;
    8121          113 :               if (gfc_match (", ") == MATCH_YES)
    8122           38 :                 continue;
    8123           75 :               if (gfc_match (") ") == MATCH_YES)
    8124              :                 break;
    8125              :             }
    8126              :         }
    8127           32 :       else if (ccode == clause_append_args)
    8128              :         {
    8129           32 :           if (has_append_args)
    8130              :             {
    8131            1 :               gfc_error ("%qs clause at %L specified more than once",
    8132              :                          "append_args", &gfc_current_locus);
    8133            1 :               return MATCH_ERROR;
    8134              :             }
    8135           56 :           has_append_args = true;
    8136              :           gfc_omp_namelist *append_args_last = NULL;
    8137           81 :           do
    8138              :             {
    8139           56 :               gfc_gobble_whitespace ();
    8140           56 :               if (gfc_match ("interop ") != MATCH_YES)
    8141              :                 {
    8142            0 :                   gfc_error ("expected %<interop%> at %C");
    8143            3 :                   return MATCH_ERROR;
    8144              :                 }
    8145           56 :               if (gfc_match ("( ") != MATCH_YES)
    8146              :                 {
    8147            0 :                   gfc_error ("expected %<(%> at %C");
    8148            0 :                   return MATCH_ERROR;
    8149              :                 }
    8150              : 
    8151           56 :               bool target, targetsync;
    8152           56 :               char *type_str = NULL;
    8153           56 :               int type_str_len;
    8154           56 :               locus loc = gfc_current_locus;
    8155           56 :               if (gfc_parser_omp_clause_init_modifiers (target, targetsync,
    8156              :                                                         &type_str, type_str_len,
    8157              :                                                         false) == MATCH_ERROR)
    8158              :                 return MATCH_ERROR;
    8159              : 
    8160           54 :               gfc_omp_namelist *n = gfc_get_omp_namelist();
    8161           54 :               n->where = loc;
    8162           54 :               n->u.init.target = target;
    8163           54 :               n->u.init.targetsync = targetsync;
    8164           54 :               n->u.init.len = type_str_len;
    8165           54 :               n->u2.init_interop = type_str;
    8166           54 :               if (odv->append_args_list)
    8167              :                 {
    8168           25 :                   append_args_last->next = n;
    8169           25 :                   append_args_last = n;
    8170              :                 }
    8171              :               else
    8172           29 :                 append_args_last = odv->append_args_list = n;
    8173              : 
    8174           54 :               gfc_gobble_whitespace ();
    8175           54 :               if (gfc_match_char (',') == MATCH_YES)
    8176           25 :                 continue;
    8177           29 :               if (gfc_match_char (')') == MATCH_YES)
    8178              :                 break;
    8179            1 :               gfc_error ("Expected %<,%> or %<)%> at %C");
    8180            1 :               return MATCH_ERROR;
    8181           25 :             }
    8182              :           while (true);
    8183              :         }
    8184          481 :       gfc_gobble_whitespace ();
    8185          481 :       if (gfc_match_omp_eos () == MATCH_YES)
    8186              :         break;
    8187          109 :       gfc_match_char (',');
    8188          109 :     }
    8189              : 
    8190          378 :   if (error_p || (!has_match && !has_adjust_args && !has_append_args))
    8191              :     {
    8192            6 :       gfc_error ("expected %<match%>, %<adjust_args%> or %<append_args%> at %C");
    8193            6 :       return MATCH_ERROR;
    8194              :     }
    8195              : 
    8196          372 :   if (!has_match)
    8197              :     {
    8198            3 :       gfc_error ("expected %<match%> clause at %C");
    8199            3 :       return MATCH_ERROR;
    8200              :     }
    8201              : 
    8202              :   return MATCH_YES;
    8203              : }
    8204              : 
    8205              : 
    8206              : static match
    8207          167 : match_omp_metadirective (bool begin_p)
    8208              : {
    8209          167 :   locus old_loc = gfc_current_locus;
    8210          167 :   gfc_omp_variant *variants_head;
    8211          167 :   gfc_omp_variant **next_variant = &variants_head;
    8212          167 :   bool default_seen = false;
    8213              : 
    8214              :   /* Parse the context selectors.  */
    8215          681 :   for (;;)
    8216              :     {
    8217          424 :       bool default_p = false;
    8218          424 :       gfc_omp_set_selector *selectors = NULL;
    8219              : 
    8220          424 :       gfc_gobble_whitespace ();
    8221          424 :       if (gfc_match_eos () == MATCH_YES)
    8222              :         break;
    8223          275 :       gfc_match_char (',');
    8224          275 :       gfc_gobble_whitespace ();
    8225              : 
    8226          275 :       locus variant_locus = gfc_current_locus;
    8227              : 
    8228          275 :       if (gfc_match ("default ( ") == MATCH_YES)
    8229              :         {
    8230           82 :           default_p = true;
    8231           82 :           gfc_warning (OPT_Wdeprecated_openmp,
    8232              :                        "%<default%> clause with metadirective at %L "
    8233              :                        "deprecated since OpenMP 5.2", &variant_locus);
    8234              :         }
    8235          193 :       else if (gfc_match ("otherwise ( ") == MATCH_YES)
    8236              :         default_p = true;
    8237          185 :       else if (gfc_match ("when ( ") != MATCH_YES)
    8238              :         {
    8239            1 :           gfc_error ("expected %<when%>, %<otherwise%>, or %<default%> at %C");
    8240            1 :           gfc_current_locus = old_loc;
    8241           18 :           return MATCH_ERROR;
    8242              :         }
    8243           90 :       if (default_p && default_seen)
    8244              :         {
    8245            3 :           gfc_error ("too many %<otherwise%> or %<default%> clauses "
    8246              :                      "in %<metadirective%> at %C");
    8247            3 :           gfc_current_locus = old_loc;
    8248            3 :           return MATCH_ERROR;
    8249              :         }
    8250          271 :       else if (default_seen)
    8251              :         {
    8252            1 :           gfc_error ("%<otherwise%> or %<default%> clause "
    8253              :                      "must appear last in %<metadirective%> at %C");
    8254            1 :           gfc_current_locus = old_loc;
    8255            1 :           return MATCH_ERROR;
    8256              :         }
    8257              : 
    8258          270 :       if (!default_p)
    8259              :         {
    8260          183 :           if (gfc_match_omp_context_selector_specification (&selectors)
    8261              :               != MATCH_YES)
    8262              :             return MATCH_ERROR;
    8263              : 
    8264          176 :           if (gfc_match (" : ") != MATCH_YES)
    8265              :             {
    8266            1 :               gfc_error ("expected %<:%> at %C");
    8267            1 :               gfc_current_locus = old_loc;
    8268            1 :               return MATCH_ERROR;
    8269              :             }
    8270              : 
    8271          175 :           gfc_commit_symbols ();
    8272              :         }
    8273              : 
    8274          262 :       gfc_matching_omp_context_selector = true;
    8275          262 :       gfc_statement directive = match_omp_directive ();
    8276          262 :       gfc_matching_omp_context_selector = false;
    8277              : 
    8278          262 :       if (is_omp_declarative_stmt (directive))
    8279            0 :         sorry_at (gfc_get_location (&gfc_current_locus),
    8280              :                   "declarative directive variants are not supported");
    8281              : 
    8282          262 :       if (gfc_error_flag_test ())
    8283              :         {
    8284            2 :           gfc_current_locus = old_loc;
    8285            2 :           return MATCH_ERROR;
    8286              :         }
    8287              : 
    8288          260 :       if (gfc_match (" )") != MATCH_YES)
    8289              :         {
    8290            0 :           gfc_error ("Expected %<)%> at %C");
    8291            0 :           gfc_current_locus = old_loc;
    8292            0 :           return MATCH_ERROR;
    8293              :         }
    8294              : 
    8295          260 :       gfc_commit_symbols ();
    8296              : 
    8297          260 :       if (begin_p
    8298          260 :           && directive != ST_NONE
    8299          260 :           && gfc_omp_end_stmt (directive) == ST_NONE)
    8300              :         {
    8301            3 :           gfc_error ("variant directive used in OMP BEGIN METADIRECTIVE "
    8302              :                      "at %C must have a corresponding end directive");
    8303            3 :           gfc_current_locus = old_loc;
    8304            3 :           return MATCH_ERROR;
    8305              :         }
    8306              : 
    8307          257 :       if (default_p)
    8308              :         default_seen = true;
    8309              : 
    8310          257 :       gfc_omp_variant *omv = gfc_get_omp_variant ();
    8311          257 :       omv->selectors = selectors;
    8312          257 :       omv->stmt = directive;
    8313          257 :       omv->where = variant_locus;
    8314              : 
    8315          257 :       if (directive == ST_NONE)
    8316              :         {
    8317              :           /* The directive was a 'nothing' directive.  */
    8318           15 :           omv->code = gfc_get_code (EXEC_CONTINUE);
    8319           15 :           omv->code->ext.omp_clauses = NULL;
    8320              :         }
    8321              :       else
    8322              :         {
    8323          242 :           omv->code = gfc_get_code (new_st.op);
    8324          242 :           omv->code->ext.omp_clauses = new_st.ext.omp_clauses;
    8325              :           /* Prevent the OpenMP clauses from being freed via NEW_ST.  */
    8326          242 :           new_st.ext.omp_clauses = NULL;
    8327              :         }
    8328              : 
    8329          257 :       *next_variant = omv;
    8330          257 :       next_variant = &omv->next;
    8331          257 :     }
    8332              : 
    8333          149 :   if (gfc_match_omp_eos () != MATCH_YES)
    8334              :     {
    8335            0 :       gfc_error ("Unexpected junk after OMP METADIRECTIVE at %C");
    8336            0 :       gfc_current_locus = old_loc;
    8337            0 :       return MATCH_ERROR;
    8338              :     }
    8339              : 
    8340              :   /* Add a 'default (nothing)' clause if no default is explicitly given.  */
    8341          149 :   if (!default_seen)
    8342              :     {
    8343           71 :       gfc_omp_variant *omv = gfc_get_omp_variant ();
    8344           71 :       omv->stmt = ST_NONE;
    8345           71 :       omv->code = gfc_get_code (EXEC_CONTINUE);
    8346           71 :       omv->code->ext.omp_clauses = NULL;
    8347           71 :       omv->where = old_loc;
    8348           71 :       omv->selectors = NULL;
    8349              : 
    8350           71 :       *next_variant = omv;
    8351           71 :       next_variant = &omv->next;
    8352              :     }
    8353              : 
    8354          149 :   new_st.op = EXEC_OMP_METADIRECTIVE;
    8355          149 :   new_st.ext.omp_variants = variants_head;
    8356              : 
    8357          149 :   return MATCH_YES;
    8358              : }
    8359              : 
    8360              : match
    8361           47 : gfc_match_omp_begin_metadirective (void)
    8362              : {
    8363           47 :   return match_omp_metadirective (true);
    8364              : }
    8365              : 
    8366              : match
    8367          120 : gfc_match_omp_metadirective (void)
    8368              : {
    8369          120 :   return match_omp_metadirective (false);
    8370              : }
    8371              : 
    8372              : /* Match 'omp threadprivate' or 'omp groupprivate'.  */
    8373              : static match
    8374          262 : gfc_match_omp_thread_group_private (bool is_groupprivate)
    8375              : {
    8376          262 :   locus old_loc;
    8377          262 :   char n[GFC_MAX_SYMBOL_LEN+1];
    8378          262 :   gfc_symbol *sym;
    8379          262 :   match m;
    8380          262 :   gfc_symtree *st;
    8381          262 :   struct sym_loc_t { gfc_symbol *sym; gfc_common_head *com; locus loc; };
    8382          262 :   auto_vec<sym_loc_t> syms;
    8383              : 
    8384          262 :   old_loc = gfc_current_locus;
    8385              : 
    8386          262 :   m = gfc_match (" ( ");
    8387          262 :   if (m != MATCH_YES)
    8388              :     return m;
    8389              : 
    8390          372 :   for (;;)
    8391              :     {
    8392          317 :       locus sym_loc = gfc_current_locus;
    8393          317 :       m = gfc_match_symbol (&sym, 0);
    8394          317 :       switch (m)
    8395              :         {
    8396          212 :         case MATCH_YES:
    8397          212 :           if (sym->attr.in_common)
    8398            0 :             gfc_error_now ("%qs variable at %L is an element of a COMMON block",
    8399              :                            is_groupprivate ? "groupprivate" : "threadprivate",
    8400              :                            &sym_loc);
    8401          212 :           else if (!is_groupprivate
    8402          212 :                    && !gfc_add_threadprivate (&sym->attr, sym->name, &sym_loc))
    8403           16 :             goto cleanup;
    8404          210 :           else if (is_groupprivate)
    8405              :             {
    8406           33 :               if (!gfc_add_omp_groupprivate (&sym->attr, sym->name, &sym_loc))
    8407            4 :                 goto cleanup;
    8408           29 :               syms.safe_push ({sym, nullptr, sym_loc});
    8409              :             }
    8410          206 :           goto next_item;
    8411              :         case MATCH_NO:
    8412              :           break;
    8413            0 :         case MATCH_ERROR:
    8414            0 :           goto cleanup;
    8415              :         }
    8416              : 
    8417          105 :       m = gfc_match (" / %n /", n);
    8418          105 :       if (m == MATCH_ERROR)
    8419            0 :         goto cleanup;
    8420          105 :       if (m == MATCH_NO || n[0] == '\0')
    8421            0 :         goto syntax;
    8422              : 
    8423          105 :       st = gfc_find_symtree (gfc_current_ns->common_root, n);
    8424          105 :       if (st == NULL)
    8425              :         {
    8426            2 :           gfc_error ("COMMON block /%s/ not found at %L", n, &sym_loc);
    8427            2 :           goto cleanup;
    8428              :         }
    8429          103 :       syms.safe_push ({nullptr, st->n.common, sym_loc});
    8430          103 :       if (is_groupprivate)
    8431           30 :         st->n.common->omp_groupprivate = 1;
    8432              :       else
    8433           73 :         st->n.common->threadprivate = 1;
    8434          236 :       for (sym = st->n.common->head; sym; sym = sym->common_next)
    8435          141 :         if (!is_groupprivate
    8436          141 :             && !gfc_add_threadprivate (&sym->attr, sym->name, &sym_loc))
    8437            3 :           goto cleanup;
    8438          138 :         else if (is_groupprivate
    8439          138 :                  && !gfc_add_omp_groupprivate (&sym->attr, sym->name, &sym_loc))
    8440            5 :           goto cleanup;
    8441              : 
    8442           95 :     next_item:
    8443          301 :       if (gfc_match_char (')') == MATCH_YES)
    8444              :         break;
    8445           55 :       if (gfc_match_char (',') != MATCH_YES)
    8446            0 :         goto syntax;
    8447           55 :     }
    8448              : 
    8449          246 :   if (is_groupprivate)
    8450              :     {
    8451           42 :       gfc_omp_clauses *c;
    8452           42 :       m = gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_DEVICE_TYPE), false, false);
    8453           42 :       if (m == MATCH_ERROR)
    8454            0 :         return MATCH_ERROR;
    8455              : 
    8456           42 :       if (c->device_type == OMP_DEVICE_TYPE_UNSET)
    8457           19 :         c->device_type = OMP_DEVICE_TYPE_ANY;
    8458              : 
    8459           92 :       for (size_t i = 0; i < syms.length (); i++)
    8460           50 :         if (syms[i].sym)
    8461              :           {
    8462           27 :             sym_loc_t &n = syms[i];
    8463           27 :             if (n.sym->attr.in_common)
    8464            0 :               gfc_error_now ("Variable %qs at %L is an element of a COMMON "
    8465              :                              "block", n.sym->name, &n.loc);
    8466           27 :             else if (n.sym->attr.omp_declare_target
    8467           26 :                      || n.sym->attr.omp_declare_target_link)
    8468            2 :               gfc_error_now ("List item %qs at %L implies OMP DECLARE TARGET "
    8469              :                              "with the LOCAL clause, but it has been specified"
    8470              :                              " with a different clause before",
    8471              :                              n.sym->name, &n.loc);
    8472           27 :             if (n.sym->attr.omp_device_type != OMP_DEVICE_TYPE_UNSET
    8473            5 :                 && n.sym->attr.omp_device_type != c->device_type)
    8474              :               {
    8475            2 :               const char *dt = "any";
    8476            2 :               if (n.sym->attr.omp_device_type == OMP_DEVICE_TYPE_HOST)
    8477              :                 dt = "host";
    8478            0 :               else if (n.sym->attr.omp_device_type == OMP_DEVICE_TYPE_NOHOST)
    8479            0 :                 dt = "nohost";
    8480            2 :               gfc_error_now ("List item %qs at %L set in previous OMP DECLARE "
    8481              :                              "TARGET directive to the different DEVICE_TYPE %qs",
    8482              :                              n.sym->name, &n.loc, dt);
    8483              :               }
    8484           27 :             gfc_add_omp_declare_target_local (&n.sym->attr, n.sym->name,
    8485              :                                               &n.loc);
    8486           27 :             n.sym->attr.omp_device_type = c->device_type;
    8487              :           }
    8488              :         else  /* Common block.  */
    8489              :           {
    8490           23 :             sym_loc_t &n = syms[i];
    8491           23 :             if (n.com->omp_declare_target
    8492           22 :                 || n.com->omp_declare_target_link)
    8493            2 :               gfc_error_now ("List item %</%s/%> at %L implies OMP DECLARE "
    8494              :                              "TARGET with the LOCAL clause, but it has been "
    8495              :                              "specified with a different clause before",
    8496            2 :                              n.com->name, &n.loc);
    8497           23 :             if (n.com->omp_device_type != OMP_DEVICE_TYPE_UNSET
    8498            5 :                 && n.com->omp_device_type != c->device_type)
    8499              :               {
    8500            2 :                 const char *dt = "any";
    8501            2 :                 if (n.com->omp_device_type == OMP_DEVICE_TYPE_HOST)
    8502              :                   dt = "host";
    8503            0 :                 else if (n.com->omp_device_type == OMP_DEVICE_TYPE_NOHOST)
    8504            0 :                   dt = "nohost";
    8505            2 :                 gfc_error_now ("List item %qs at %L set in previous OMP DECLARE"
    8506              :                                " TARGET directive to the different DEVICE_TYPE "
    8507            2 :                                "%qs", n.com->name, &n.loc, dt);
    8508              :               }
    8509           23 :             n.com->omp_declare_target_local = 1;
    8510           23 :             n.com->omp_device_type = c->device_type;
    8511           46 :             for (gfc_symbol *s = n.com->head; s; s = s->common_next)
    8512              :               {
    8513           23 :                 gfc_add_omp_declare_target_local (&s->attr, s->name, &n.loc);
    8514           23 :                 s->attr.omp_device_type = c->device_type;
    8515              :               }
    8516              :           }
    8517           42 :       free (c);
    8518              :     }
    8519              : 
    8520          246 :   if (gfc_match_omp_eos () != MATCH_YES)
    8521              :     {
    8522            0 :       gfc_error ("Unexpected junk after OMP %s at %C",
    8523              :                  is_groupprivate ? "GROUPPRIVATE" : "THREADPRIVATE");
    8524            0 :       goto cleanup;
    8525              :     }
    8526              : 
    8527              :   return MATCH_YES;
    8528              : 
    8529            0 : syntax:
    8530            0 :   gfc_error ("Syntax error in !$OMP %s list at %C",
    8531              :              is_groupprivate ? "GROUPPRIVATE" : "THREADPRIVATE");
    8532              : 
    8533           16 : cleanup:
    8534           16 :   gfc_current_locus = old_loc;
    8535           16 :   return MATCH_ERROR;
    8536          262 : }
    8537              : 
    8538              : 
    8539              : match
    8540           51 : gfc_match_omp_groupprivate (void)
    8541              : {
    8542           51 :   return gfc_match_omp_thread_group_private (true);
    8543              : }
    8544              : 
    8545              : 
    8546              : match
    8547          211 : gfc_match_omp_threadprivate (void)
    8548              : {
    8549          211 :   return gfc_match_omp_thread_group_private (false);
    8550              : }
    8551              : 
    8552              : 
    8553              : match
    8554         2244 : gfc_match_omp_parallel (void)
    8555              : {
    8556         2244 :   return match_omp (EXEC_OMP_PARALLEL, OMP_PARALLEL_CLAUSES);
    8557              : }
    8558              : 
    8559              : 
    8560              : match
    8561         1207 : gfc_match_omp_parallel_do (void)
    8562              : {
    8563         1207 :   return match_omp (EXEC_OMP_PARALLEL_DO,
    8564         1207 :                     (OMP_PARALLEL_CLAUSES | OMP_DO_CLAUSES)
    8565         1207 :                     & ~(omp_mask (OMP_CLAUSE_NOWAIT)));
    8566              : }
    8567              : 
    8568              : 
    8569              : match
    8570          345 : gfc_match_omp_parallel_do_simd (void)
    8571              : {
    8572          345 :   return match_omp (EXEC_OMP_PARALLEL_DO_SIMD,
    8573          345 :                     (OMP_PARALLEL_CLAUSES | OMP_DO_CLAUSES | OMP_SIMD_CLAUSES)
    8574          345 :                     & ~(omp_mask (OMP_CLAUSE_NOWAIT)));
    8575              : }
    8576              : 
    8577              : 
    8578              : match
    8579           14 : gfc_match_omp_parallel_masked (void)
    8580              : {
    8581           14 :   return match_omp (EXEC_OMP_PARALLEL_MASKED,
    8582           14 :                     OMP_PARALLEL_CLAUSES | OMP_MASKED_CLAUSES);
    8583              : }
    8584              : 
    8585              : match
    8586           10 : gfc_match_omp_parallel_masked_taskloop (void)
    8587              : {
    8588           10 :   return match_omp (EXEC_OMP_PARALLEL_MASKED_TASKLOOP,
    8589           10 :                     (OMP_PARALLEL_CLAUSES | OMP_MASKED_CLAUSES
    8590           10 :                      | OMP_TASKLOOP_CLAUSES)
    8591           10 :                     & ~(omp_mask (OMP_CLAUSE_IN_REDUCTION)));
    8592              : }
    8593              : 
    8594              : match
    8595           13 : gfc_match_omp_parallel_masked_taskloop_simd (void)
    8596              : {
    8597           13 :   return match_omp (EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD,
    8598           13 :                     (OMP_PARALLEL_CLAUSES | OMP_MASKED_CLAUSES
    8599           13 :                      | OMP_TASKLOOP_CLAUSES | OMP_SIMD_CLAUSES)
    8600           13 :                     & ~(omp_mask (OMP_CLAUSE_IN_REDUCTION)));
    8601              : }
    8602              : 
    8603              : match
    8604           14 : gfc_match_omp_parallel_master (void)
    8605              : {
    8606           14 :   gfc_warning (OPT_Wdeprecated_openmp,
    8607              :                "%<master%> construct at %C deprecated since OpenMP 5.1, use "
    8608              :                "%<masked%>");
    8609           14 :   return match_omp (EXEC_OMP_PARALLEL_MASTER, OMP_PARALLEL_CLAUSES);
    8610              : }
    8611              : 
    8612              : match
    8613           16 : gfc_match_omp_parallel_master_taskloop (void)
    8614              : {
    8615           16 :   gfc_warning (OPT_Wdeprecated_openmp,
    8616              :                "%<master%> construct at %C deprecated since OpenMP 5.1, "
    8617              :                "use %<masked%>");
    8618           16 :   return match_omp (EXEC_OMP_PARALLEL_MASTER_TASKLOOP,
    8619           16 :                     (OMP_PARALLEL_CLAUSES | OMP_TASKLOOP_CLAUSES)
    8620           16 :                     & ~(omp_mask (OMP_CLAUSE_IN_REDUCTION)));
    8621              : }
    8622              : 
    8623              : match
    8624           21 : gfc_match_omp_parallel_master_taskloop_simd (void)
    8625              : {
    8626           21 :   gfc_warning (OPT_Wdeprecated_openmp,
    8627              :                "%<master%> construct at %C deprecated since OpenMP 5.1, "
    8628              :                "use %<masked%>");
    8629           21 :   return match_omp (EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD,
    8630           21 :                     (OMP_PARALLEL_CLAUSES | OMP_TASKLOOP_CLAUSES
    8631           21 :                      | OMP_SIMD_CLAUSES)
    8632           21 :                     & ~(omp_mask (OMP_CLAUSE_IN_REDUCTION)));
    8633              : }
    8634              : 
    8635              : match
    8636           59 : gfc_match_omp_parallel_sections (void)
    8637              : {
    8638           59 :   return match_omp (EXEC_OMP_PARALLEL_SECTIONS,
    8639           59 :                     (OMP_PARALLEL_CLAUSES | OMP_SECTIONS_CLAUSES)
    8640           59 :                     & ~(omp_mask (OMP_CLAUSE_NOWAIT)));
    8641              : }
    8642              : 
    8643              : 
    8644              : match
    8645           56 : gfc_match_omp_parallel_workshare (void)
    8646              : {
    8647           56 :   return match_omp (EXEC_OMP_PARALLEL_WORKSHARE, OMP_PARALLEL_CLAUSES);
    8648              : }
    8649              : 
    8650              : void
    8651        51443 : gfc_check_omp_requires (gfc_namespace *ns, int ref_omp_requires)
    8652              : {
    8653        51443 :   const char *msg = G_("Program unit at %L has OpenMP device "
    8654              :                        "constructs/routines but does not set !$OMP REQUIRES %s "
    8655              :                        "but other program units do");
    8656        51443 :   if (ns->omp_target_seen
    8657         1332 :       && (ns->omp_requires & OMP_REQ_TARGET_MASK)
    8658         1332 :          != (ref_omp_requires & OMP_REQ_TARGET_MASK))
    8659              :     {
    8660            6 :       gcc_assert (ns->proc_name);
    8661            6 :       if ((ref_omp_requires & OMP_REQ_REVERSE_OFFLOAD)
    8662            5 :           && !(ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD))
    8663            4 :         gfc_error (msg, &ns->proc_name->declared_at, "REVERSE_OFFLOAD");
    8664            6 :       if ((ref_omp_requires & OMP_REQ_UNIFIED_ADDRESS)
    8665            1 :           && !(ns->omp_requires & OMP_REQ_UNIFIED_ADDRESS))
    8666            1 :         gfc_error (msg, &ns->proc_name->declared_at, "UNIFIED_ADDRESS");
    8667            6 :       if ((ref_omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
    8668            4 :           && !(ns->omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY))
    8669            2 :         gfc_error (msg, &ns->proc_name->declared_at, "UNIFIED_SHARED_MEMORY");
    8670            6 :       if ((ref_omp_requires & OMP_REQ_SELF_MAPS)
    8671            1 :           && !(ns->omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY))
    8672            1 :         gfc_error (msg, &ns->proc_name->declared_at, "SELF_MAPS");
    8673              :     }
    8674        51443 : }
    8675              : 
    8676              : bool
    8677          138 : gfc_omp_requires_add_clause (gfc_omp_requires_kind clause,
    8678              :                              const char *clause_name, locus *loc,
    8679              :                              const char *module_name)
    8680              : {
    8681          138 :   gfc_namespace *prog_unit = gfc_current_ns;
    8682          162 :   while (prog_unit->parent)
    8683              :     {
    8684           26 :       if (gfc_state_stack->previous
    8685           26 :           && gfc_state_stack->previous->state == COMP_INTERFACE)
    8686              :         break;
    8687              :       /* A submodule namespace may have its parent set to the ancestor module
    8688              :          for host-association purposes.  Do not escape the submodule boundary:
    8689              :          the submodule itself is the program unit for OMP REQUIRES purposes.  */
    8690           25 :       if (prog_unit->proc_name
    8691           25 :           && prog_unit->proc_name->attr.flavor == FL_MODULE)
    8692              :         break;
    8693           24 :       prog_unit = prog_unit->parent;
    8694              :     }
    8695              : 
    8696              :   /* Requires added after use.  */
    8697          138 :   if (prog_unit->omp_target_seen
    8698           24 :       && (clause & OMP_REQ_TARGET_MASK)
    8699           24 :       && !(prog_unit->omp_requires & clause))
    8700              :     {
    8701            0 :       if (module_name)
    8702            0 :         gfc_error ("!$OMP REQUIRES clause %qs specified via module %qs use "
    8703              :                    "at %L comes after using a device construct/routine",
    8704              :                    clause_name, module_name, loc);
    8705              :       else
    8706            0 :         gfc_error ("!$OMP REQUIRES clause %qs specified at %L comes after "
    8707              :                    "using a device construct/routine", clause_name, loc);
    8708              :       return false;
    8709              :     }
    8710              : 
    8711              :   /* Overriding atomic_default_mem_order clause value.  */
    8712          138 :   if ((clause & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8713           34 :       && (prog_unit->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8714            6 :       && (prog_unit->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8715            6 :          != (int) clause)
    8716              :     {
    8717            3 :       const char *other;
    8718            3 :       switch (prog_unit->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8719              :         {
    8720              :         case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST: other = "seq_cst"; break;
    8721            0 :         case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL: other = "acq_rel"; break;
    8722            1 :         case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE: other = "acquire"; break;
    8723            1 :         case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED: other = "relaxed"; break;
    8724            0 :         case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE: other = "release"; break;
    8725            0 :         default: gcc_unreachable ();
    8726              :         }
    8727              : 
    8728            3 :       if (module_name)
    8729            0 :         gfc_error ("!$OMP REQUIRES clause %<atomic_default_mem_order(%s)%> "
    8730              :                    "specified via module %qs use at %L overrides a previous "
    8731              :                    "%<atomic_default_mem_order(%s)%> (which might be through "
    8732              :                    "using a module)", clause_name, module_name, loc, other);
    8733              :       else
    8734            3 :         gfc_error ("!$OMP REQUIRES clause %<atomic_default_mem_order(%s)%> "
    8735              :                    "specified at %L overrides a previous "
    8736              :                    "%<atomic_default_mem_order(%s)%> (which might be through "
    8737              :                    "using a module)", clause_name, loc, other);
    8738              :       return false;
    8739              :     }
    8740              : 
    8741              :   /* Requires via module not at program-unit level and not repeating clause.  */
    8742          135 :   if (prog_unit != gfc_current_ns && !(prog_unit->omp_requires & clause))
    8743              :     {
    8744            0 :       if (clause & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8745            0 :         gfc_error ("!$OMP REQUIRES clause %<atomic_default_mem_order(%s)%> "
    8746              :                    "specified via module %qs use at %L but same clause is "
    8747              :                    "not specified for the program unit", clause_name,
    8748              :                    module_name, loc);
    8749              :       else
    8750            0 :         gfc_error ("!$OMP REQUIRES clause %qs specified via module %qs use at "
    8751              :                    "%L but same clause is not specified for the program unit",
    8752              :                    clause_name, module_name, loc);
    8753              :       return false;
    8754              :     }
    8755              : 
    8756          135 :   if (!gfc_state_stack->previous
    8757          127 :       || gfc_state_stack->previous->state != COMP_INTERFACE)
    8758          134 :     prog_unit->omp_requires |= clause;
    8759              :   return true;
    8760              : }
    8761              : 
    8762              : match
    8763          110 : gfc_match_omp_requires (void)
    8764              : {
    8765          110 :   static const char *clauses[] = {"reverse_offload",
    8766              :                                   "unified_address",
    8767              :                                   "unified_shared_memory",
    8768              :                                   "self_maps",
    8769              :                                   "dynamic_allocators",
    8770              :                                   "atomic_default_mem_order"};
    8771          110 :   const char *clause = NULL;
    8772          110 :   int requires_clauses = 0;
    8773          110 :   int seen_clauses = 0;
    8774          110 :   bool first = true;
    8775          110 :   locus old_loc;
    8776              : 
    8777              :   /* A submodule's namespace may have its parent pointer set to the ancestor
    8778              :      module namespace for host-association purposes.  The submodule spec part
    8779              :      is still a valid program-unit spec part for OMP REQUIRES.  Only reject
    8780              :      the directive when we are genuinely nested inside a procedure.  */
    8781          110 :   if (gfc_current_ns->parent
    8782            8 :       && !(gfc_current_ns->proc_name
    8783            8 :            && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
    8784            7 :       && (!gfc_state_stack->previous
    8785            7 :           || gfc_state_stack->previous->state != COMP_INTERFACE))
    8786              :     {
    8787            6 :       gfc_error ("!$OMP REQUIRES at %C must appear in the specification part "
    8788              :                  "of a program unit");
    8789            6 :       return MATCH_ERROR;
    8790              :     }
    8791              : 
    8792              :   /* Specifying '<clause>(.false.)' in this directive does not affect requirements
    8793              :      set in another 'requires' directive in the same compilation unit; however,
    8794              :      specifying it multiple times in the same directive is disallowed.  */
    8795          336 :   while (true)
    8796              :     {
    8797          220 :       bool bval;
    8798          220 :       match m;
    8799          220 :       old_loc = gfc_current_locus;
    8800          220 :       gfc_omp_requires_kind requires_clause = OMP_REQ_NONE;
    8801          220 :       if (gfc_match_char (',') != MATCH_YES
    8802          220 :           && (first && gfc_match_space () != MATCH_YES))
    8803           17 :         goto error;
    8804          220 :       first = false;
    8805          220 :       gfc_gobble_whitespace ();
    8806          220 :       old_loc = gfc_current_locus;
    8807              : 
    8808          220 :       if (gfc_match_omp_eos () != MATCH_NO)
    8809              :         break;
    8810          133 :       if ((m = gfc_match_boolean_clause (&bval, clauses[0],
    8811          133 :                  seen_clauses & OMP_REQ_REVERSE_OFFLOAD)) != MATCH_NO)
    8812              :         {
    8813           40 :           if (m == MATCH_ERROR)
    8814            2 :             goto error;
    8815           38 :           clause = clauses[0];
    8816           38 :           seen_clauses |= OMP_REQ_REVERSE_OFFLOAD;
    8817           38 :           if (bval)
    8818              :             requires_clause = OMP_REQ_REVERSE_OFFLOAD;
    8819              :         }
    8820           93 :       else if ((m = gfc_match_boolean_clause (&bval, clauses[1],
    8821           93 :                       seen_clauses & OMP_REQ_UNIFIED_ADDRESS)) != MATCH_NO)
    8822              :         {
    8823           14 :           if (m == MATCH_ERROR)
    8824            2 :             goto error;
    8825           12 :           clause = clauses[1];
    8826           12 :           seen_clauses |= OMP_REQ_UNIFIED_ADDRESS;
    8827           12 :           if (bval)
    8828              :             requires_clause = OMP_REQ_UNIFIED_ADDRESS;
    8829              :         }
    8830           79 :       else if ((m = gfc_match_boolean_clause (&bval, clauses[2],
    8831           79 :                       seen_clauses & OMP_REQ_UNIFIED_SHARED_MEMORY))
    8832              :                != MATCH_NO)
    8833              :         {
    8834           17 :           if (m == MATCH_ERROR)
    8835            1 :             goto error;
    8836           16 :           clause = clauses[2];
    8837           16 :           seen_clauses |= OMP_REQ_UNIFIED_SHARED_MEMORY;
    8838           16 :           if (bval)
    8839              :             requires_clause = OMP_REQ_UNIFIED_SHARED_MEMORY;
    8840              :         }
    8841           62 :       else if ((m = gfc_match_boolean_clause (&bval, clauses[3],
    8842           62 :                       seen_clauses & OMP_REQ_SELF_MAPS)) != MATCH_NO)
    8843              :         {
    8844           19 :           if (m == MATCH_ERROR)
    8845            4 :             goto error;
    8846           15 :           clause = clauses[3];
    8847           15 :           seen_clauses |= OMP_REQ_SELF_MAPS;
    8848           15 :           if (bval)
    8849              :             requires_clause = OMP_REQ_SELF_MAPS;
    8850              :         }
    8851           43 :       else if ((m = gfc_match_boolean_clause (&bval, clauses[4],
    8852           43 :                       seen_clauses & OMP_REQ_DYNAMIC_ALLOCATORS)) != MATCH_NO)
    8853              :         {
    8854           11 :           if (m == MATCH_ERROR)
    8855            1 :             goto error;
    8856           10 :           clause = clauses[4];
    8857           10 :           seen_clauses |= OMP_REQ_DYNAMIC_ALLOCATORS;
    8858           10 :           if (bval)
    8859              :             requires_clause = OMP_REQ_DYNAMIC_ALLOCATORS;
    8860              :         }
    8861           32 :       else if ((m = gfc_match_dupl_check (
    8862           32 :                       !(seen_clauses & OMP_REQ_ATOMIC_MEM_ORDER_MASK),
    8863              :                       clauses[5], true)) != MATCH_NO)
    8864              :         {
    8865           31 :           if (m == MATCH_ERROR)
    8866            1 :             goto error;
    8867           30 :           seen_clauses |= OMP_REQ_ATOMIC_MEM_ORDER_MASK;
    8868           30 :           if (gfc_match (" seq_cst )") == MATCH_YES)
    8869              :             {
    8870              :               clause = "seq_cst";
    8871              :               requires_clause = OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST;
    8872              :             }
    8873           18 :           else if (gfc_match (" acq_rel )") == MATCH_YES)
    8874              :             {
    8875              :               clause = "acq_rel";
    8876              :               requires_clause = OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL;
    8877              :             }
    8878           12 :           else if (gfc_match (" acquire )") == MATCH_YES)
    8879              :             {
    8880              :               clause = "acquire";
    8881              :               requires_clause = OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE;
    8882              :             }
    8883            9 :           else if (gfc_match (" relaxed )") == MATCH_YES)
    8884              :             {
    8885              :               clause = "relaxed";
    8886              :               requires_clause = OMP_REQ_ATOMIC_MEM_ORDER_RELAXED;
    8887              :             }
    8888            5 :           else if (gfc_match (" release )") == MATCH_YES)
    8889              :             {
    8890              :               clause = "release";
    8891              :               requires_clause = OMP_REQ_ATOMIC_MEM_ORDER_RELEASE;
    8892              :             }
    8893              :           else
    8894              :             {
    8895            2 :               gfc_error ("Expected ACQ_REL, ACQUIRE, RELAXED, RELEASE or "
    8896              :                          "SEQ_CST for ATOMIC_DEFAULT_MEM_ORDER clause at %C");
    8897            2 :               goto error;
    8898              :             }
    8899              :         }
    8900              :       else
    8901            1 :         goto error;
    8902              : 
    8903              :       if (requires_clause != OMP_REQ_NONE
    8904          107 :           && !gfc_omp_requires_add_clause (requires_clause, clause, &old_loc, NULL))
    8905            3 :         goto error;
    8906          116 :       requires_clauses |= requires_clause;
    8907          116 :     }
    8908              : 
    8909           87 :   if (requires_clauses == 0)
    8910            2 :     goto error;
    8911              :   return MATCH_YES;
    8912              : 
    8913           19 : error:
    8914           19 :   if (!gfc_error_flag_test ())
    8915            3 :     gfc_error ("Expected UNIFIED_ADDRESS, UNIFIED_SHARED_MEMORY, SELF_MAPS, "
    8916              :                "DYNAMIC_ALLOCATORS, REVERSE_OFFLOAD, or "
    8917              :                "ATOMIC_DEFAULT_MEM_ORDER clause at %L", &old_loc);
    8918              :   return MATCH_ERROR;
    8919              : }
    8920              : 
    8921              : 
    8922              : match
    8923           51 : gfc_match_omp_scan (void)
    8924              : {
    8925           51 :   bool incl;
    8926           51 :   gfc_omp_clauses *c = gfc_get_omp_clauses ();
    8927           51 :   gfc_gobble_whitespace ();
    8928           51 :   gfc_match (", ");  /* optionally  */
    8929           51 :   if ((incl = (gfc_match ("inclusive") == MATCH_YES))
    8930           51 :       || gfc_match ("exclusive") == MATCH_YES)
    8931              :     {
    8932           70 :       if (gfc_match_omp_variable_list (" (", &c->lists[incl ? OMP_LIST_SCAN_IN
    8933              :                                                             : OMP_LIST_SCAN_EX],
    8934              :                                        false) != MATCH_YES)
    8935              :         {
    8936            0 :           gfc_free_omp_clauses (c);
    8937            0 :           return MATCH_ERROR;
    8938              :         }
    8939              :     }
    8940              :   else
    8941              :     {
    8942            1 :       gfc_error ("Expected INCLUSIVE or EXCLUSIVE clause at %C");
    8943            1 :       gfc_free_omp_clauses (c);
    8944            1 :       return MATCH_ERROR;
    8945              :     }
    8946           50 :   if (gfc_match_omp_eos () != MATCH_YES)
    8947              :     {
    8948            1 :       gfc_error ("Unexpected junk after !$OMP SCAN at %C");
    8949            1 :       gfc_free_omp_clauses (c);
    8950            1 :       return MATCH_ERROR;
    8951              :     }
    8952              : 
    8953           49 :   new_st.op = EXEC_OMP_SCAN;
    8954           49 :   new_st.ext.omp_clauses = c;
    8955           49 :   return MATCH_YES;
    8956              : }
    8957              : 
    8958              : 
    8959              : match
    8960           58 : gfc_match_omp_scope (void)
    8961              : {
    8962           58 :   return match_omp (EXEC_OMP_SCOPE, OMP_SCOPE_CLAUSES);
    8963              : }
    8964              : 
    8965              : 
    8966              : match
    8967           82 : gfc_match_omp_sections (void)
    8968              : {
    8969           82 :   return match_omp (EXEC_OMP_SECTIONS, OMP_SECTIONS_CLAUSES);
    8970              : }
    8971              : 
    8972              : 
    8973              : match
    8974          877 : gfc_match_omp_simd (void)
    8975              : {
    8976          877 :   return match_omp (EXEC_OMP_SIMD, OMP_SIMD_CLAUSES);
    8977              : }
    8978              : 
    8979              : 
    8980              : match
    8981          574 : gfc_match_omp_single (void)
    8982              : {
    8983          574 :   return match_omp (EXEC_OMP_SINGLE, OMP_SINGLE_CLAUSES);
    8984              : }
    8985              : 
    8986              : 
    8987              : match
    8988         2327 : gfc_match_omp_target (void)
    8989              : {
    8990         2327 :   return match_omp (EXEC_OMP_TARGET, OMP_TARGET_CLAUSES);
    8991              : }
    8992              : 
    8993              : 
    8994              : match
    8995         1401 : gfc_match_omp_target_data (void)
    8996              : {
    8997         1401 :   return match_omp (EXEC_OMP_TARGET_DATA, OMP_TARGET_DATA_CLAUSES);
    8998              : }
    8999              : 
    9000              : 
    9001              : match
    9002          472 : gfc_match_omp_target_enter_data (void)
    9003              : {
    9004          472 :   return match_omp (EXEC_OMP_TARGET_ENTER_DATA, OMP_TARGET_ENTER_DATA_CLAUSES);
    9005              : }
    9006              : 
    9007              : 
    9008              : match
    9009          367 : gfc_match_omp_target_exit_data (void)
    9010              : {
    9011          367 :   return match_omp (EXEC_OMP_TARGET_EXIT_DATA, OMP_TARGET_EXIT_DATA_CLAUSES);
    9012              : }
    9013              : 
    9014              : 
    9015              : match
    9016           30 : gfc_match_omp_target_parallel (void)
    9017              : {
    9018           30 :   return match_omp (EXEC_OMP_TARGET_PARALLEL,
    9019           30 :                     (OMP_TARGET_CLAUSES | OMP_PARALLEL_CLAUSES)
    9020           30 :                     & ~(omp_mask (OMP_CLAUSE_COPYIN)));
    9021              : }
    9022              : 
    9023              : 
    9024              : match
    9025           82 : gfc_match_omp_target_parallel_do (void)
    9026              : {
    9027           82 :   return match_omp (EXEC_OMP_TARGET_PARALLEL_DO,
    9028           82 :                     (OMP_TARGET_CLAUSES | OMP_PARALLEL_CLAUSES
    9029           82 :                      | OMP_DO_CLAUSES) & ~(omp_mask (OMP_CLAUSE_COPYIN)));
    9030              : }
    9031              : 
    9032              : 
    9033              : match
    9034           21 : gfc_match_omp_target_parallel_do_simd (void)
    9035              : {
    9036           21 :   return match_omp (EXEC_OMP_TARGET_PARALLEL_DO_SIMD,
    9037           21 :                     (OMP_TARGET_CLAUSES | OMP_PARALLEL_CLAUSES | OMP_DO_CLAUSES
    9038           21 :                      | OMP_SIMD_CLAUSES) & ~(omp_mask (OMP_CLAUSE_COPYIN)));
    9039              : }
    9040              : 
    9041              : 
    9042              : match
    9043           35 : gfc_match_omp_target_simd (void)
    9044              : {
    9045           35 :   return match_omp (EXEC_OMP_TARGET_SIMD,
    9046           35 :                     OMP_TARGET_CLAUSES | OMP_SIMD_CLAUSES);
    9047              : }
    9048              : 
    9049              : 
    9050              : match
    9051           83 : gfc_match_omp_target_teams (void)
    9052              : {
    9053           83 :   return match_omp (EXEC_OMP_TARGET_TEAMS,
    9054           83 :                     OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES);
    9055              : }
    9056              : 
    9057              : 
    9058              : match
    9059           20 : gfc_match_omp_target_teams_distribute (void)
    9060              : {
    9061           20 :   return match_omp (EXEC_OMP_TARGET_TEAMS_DISTRIBUTE,
    9062           20 :                     OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES
    9063           20 :                     | OMP_DISTRIBUTE_CLAUSES);
    9064              : }
    9065              : 
    9066              : 
    9067              : match
    9068           68 : gfc_match_omp_target_teams_distribute_parallel_do (void)
    9069              : {
    9070           68 :   return match_omp (EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO,
    9071           68 :                     (OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES
    9072           68 :                      | OMP_DISTRIBUTE_CLAUSES | OMP_PARALLEL_CLAUSES
    9073           68 :                      | OMP_DO_CLAUSES)
    9074           68 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED))
    9075           68 :                     & ~(omp_mask (OMP_CLAUSE_LINEAR)));
    9076              : }
    9077              : 
    9078              : 
    9079              : match
    9080           54 : gfc_match_omp_target_teams_distribute_parallel_do_simd (void)
    9081              : {
    9082           54 :   return match_omp (EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD,
    9083           54 :                     (OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES
    9084           54 :                      | OMP_DISTRIBUTE_CLAUSES | OMP_PARALLEL_CLAUSES
    9085           54 :                      | OMP_DO_CLAUSES | OMP_SIMD_CLAUSES)
    9086           54 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED)));
    9087              : }
    9088              : 
    9089              : 
    9090              : match
    9091           22 : gfc_match_omp_target_teams_distribute_simd (void)
    9092              : {
    9093           22 :   return match_omp (EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD,
    9094           22 :                     OMP_TARGET_CLAUSES | OMP_TEAMS_CLAUSES
    9095           22 :                     | OMP_DISTRIBUTE_CLAUSES | OMP_SIMD_CLAUSES);
    9096              : }
    9097              : 
    9098              : 
    9099              : match
    9100         1795 : gfc_match_omp_target_update (void)
    9101              : {
    9102         1795 :   return match_omp (EXEC_OMP_TARGET_UPDATE, OMP_TARGET_UPDATE_CLAUSES);
    9103              : }
    9104              : 
    9105              : 
    9106              : match
    9107         1184 : gfc_match_omp_task (void)
    9108              : {
    9109         1184 :   return match_omp (EXEC_OMP_TASK, OMP_TASK_CLAUSES);
    9110              : }
    9111              : 
    9112              : 
    9113              : match
    9114           73 : gfc_match_omp_taskloop (void)
    9115              : {
    9116           73 :   return match_omp (EXEC_OMP_TASKLOOP, OMP_TASKLOOP_CLAUSES);
    9117              : }
    9118              : 
    9119              : 
    9120              : match
    9121           40 : gfc_match_omp_taskloop_simd (void)
    9122              : {
    9123           40 :   return match_omp (EXEC_OMP_TASKLOOP_SIMD,
    9124           40 :                     OMP_TASKLOOP_CLAUSES | OMP_SIMD_CLAUSES);
    9125              : }
    9126              : 
    9127              : 
    9128              : match
    9129          149 : gfc_match_omp_taskwait (void)
    9130              : {
    9131          149 :   if (gfc_match_omp_eos () == MATCH_YES)
    9132              :     {
    9133          135 :       new_st.op = EXEC_OMP_TASKWAIT;
    9134          135 :       new_st.ext.omp_clauses = NULL;
    9135          135 :       return MATCH_YES;
    9136              :     }
    9137           14 :   return match_omp (EXEC_OMP_TASKWAIT,
    9138           14 :                     omp_mask (OMP_CLAUSE_DEPEND) | OMP_CLAUSE_NOWAIT);
    9139              : }
    9140              : 
    9141              : 
    9142              : match
    9143           10 : gfc_match_omp_taskyield (void)
    9144              : {
    9145           10 :   if (gfc_match_omp_eos () != MATCH_YES)
    9146              :     {
    9147            0 :       gfc_error ("Unexpected junk after TASKYIELD clause at %C");
    9148            0 :       return MATCH_ERROR;
    9149              :     }
    9150           10 :   new_st.op = EXEC_OMP_TASKYIELD;
    9151           10 :   new_st.ext.omp_clauses = NULL;
    9152           10 :   return MATCH_YES;
    9153              : }
    9154              : 
    9155              : 
    9156              : match
    9157          233 : gfc_match_omp_teams (void)
    9158              : {
    9159          233 :   return match_omp (EXEC_OMP_TEAMS, OMP_TEAMS_CLAUSES);
    9160              : }
    9161              : 
    9162              : 
    9163              : match
    9164           26 : gfc_match_omp_teams_distribute (void)
    9165              : {
    9166           26 :   return match_omp (EXEC_OMP_TEAMS_DISTRIBUTE,
    9167           26 :                     OMP_TEAMS_CLAUSES | OMP_DISTRIBUTE_CLAUSES);
    9168              : }
    9169              : 
    9170              : 
    9171              : match
    9172           44 : gfc_match_omp_teams_distribute_parallel_do (void)
    9173              : {
    9174           44 :   return match_omp (EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO,
    9175           44 :                     (OMP_TEAMS_CLAUSES | OMP_DISTRIBUTE_CLAUSES
    9176           44 :                      | OMP_PARALLEL_CLAUSES | OMP_DO_CLAUSES)
    9177           44 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED)
    9178           44 :                         | OMP_CLAUSE_LINEAR | OMP_CLAUSE_NOWAIT));
    9179              : }
    9180              : 
    9181              : 
    9182              : match
    9183           68 : gfc_match_omp_teams_distribute_parallel_do_simd (void)
    9184              : {
    9185           68 :   return match_omp (EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD,
    9186           68 :                     (OMP_TEAMS_CLAUSES | OMP_DISTRIBUTE_CLAUSES
    9187           68 :                      | OMP_PARALLEL_CLAUSES | OMP_DO_CLAUSES
    9188           68 :                      | OMP_SIMD_CLAUSES)
    9189           68 :                     & ~(omp_mask (OMP_CLAUSE_ORDERED) | OMP_CLAUSE_NOWAIT));
    9190              : }
    9191              : 
    9192              : 
    9193              : match
    9194           47 : gfc_match_omp_teams_distribute_simd (void)
    9195              : {
    9196           47 :   return match_omp (EXEC_OMP_TEAMS_DISTRIBUTE_SIMD,
    9197           47 :                     OMP_TEAMS_CLAUSES | OMP_DISTRIBUTE_CLAUSES
    9198           47 :                     | OMP_SIMD_CLAUSES);
    9199              : }
    9200              : 
    9201              : match
    9202          205 : gfc_match_omp_tile (void)
    9203              : {
    9204          205 :   return match_omp (EXEC_OMP_TILE, OMP_TILE_CLAUSES);
    9205              : }
    9206              : 
    9207              : match
    9208          425 : gfc_match_omp_unroll (void)
    9209              : {
    9210          425 :   return match_omp (EXEC_OMP_UNROLL, OMP_UNROLL_CLAUSES);
    9211              : }
    9212              : 
    9213              : match
    9214           39 : gfc_match_omp_workshare (void)
    9215              : {
    9216           39 :   return match_omp (EXEC_OMP_WORKSHARE, OMP_WORKSHARE_CLAUSES);
    9217              : }
    9218              : 
    9219              : 
    9220              : match
    9221           55 : gfc_match_omp_masked (void)
    9222              : {
    9223           55 :   return match_omp (EXEC_OMP_MASKED, OMP_MASKED_CLAUSES);
    9224              : }
    9225              : 
    9226              : match
    9227           10 : gfc_match_omp_masked_taskloop (void)
    9228              : {
    9229           10 :   return match_omp (EXEC_OMP_MASKED_TASKLOOP,
    9230           10 :                     OMP_MASKED_CLAUSES | OMP_TASKLOOP_CLAUSES);
    9231              : }
    9232              : 
    9233              : match
    9234           16 : gfc_match_omp_masked_taskloop_simd (void)
    9235              : {
    9236           16 :   return match_omp (EXEC_OMP_MASKED_TASKLOOP_SIMD,
    9237           16 :                     (OMP_MASKED_CLAUSES | OMP_TASKLOOP_CLAUSES
    9238           16 :                      | OMP_SIMD_CLAUSES));
    9239              : }
    9240              : 
    9241              : match
    9242          111 : gfc_match_omp_master (void)
    9243              : {
    9244          111 :   gfc_warning (OPT_Wdeprecated_openmp,
    9245              :                "%<master%> construct at %C deprecated since OpenMP 5.1, "
    9246              :                "use %<masked%>");
    9247          111 :   if (gfc_match_omp_eos () != MATCH_YES)
    9248              :     {
    9249            1 :       gfc_error ("Unexpected junk after $OMP MASTER statement at %C");
    9250            1 :       return MATCH_ERROR;
    9251              :     }
    9252          110 :   new_st.op = EXEC_OMP_MASTER;
    9253          110 :   new_st.ext.omp_clauses = NULL;
    9254          110 :   return MATCH_YES;
    9255              : }
    9256              : 
    9257              : match
    9258           16 : gfc_match_omp_master_taskloop (void)
    9259              : {
    9260           16 :   gfc_warning (OPT_Wdeprecated_openmp,
    9261              :                "%<master%> construct at %C deprecated since OpenMP 5.1, "
    9262              :                "use %<masked%>");
    9263           16 :   return match_omp (EXEC_OMP_MASTER_TASKLOOP, OMP_TASKLOOP_CLAUSES);
    9264              : }
    9265              : 
    9266              : match
    9267           21 : gfc_match_omp_master_taskloop_simd (void)
    9268              : {
    9269           21 :   gfc_warning (OPT_Wdeprecated_openmp,
    9270              :                "%<master%> construct at %C deprecated since OpenMP 5.1, use "
    9271              :                "%<masked%>");
    9272           21 :   return match_omp (EXEC_OMP_MASTER_TASKLOOP_SIMD,
    9273           21 :                     OMP_TASKLOOP_CLAUSES | OMP_SIMD_CLAUSES);
    9274              : }
    9275              : 
    9276              : match
    9277          239 : gfc_match_omp_ordered (void)
    9278              : {
    9279          239 :   return match_omp (EXEC_OMP_ORDERED, OMP_ORDERED_CLAUSES);
    9280              : }
    9281              : 
    9282              : match
    9283           24 : gfc_match_omp_nothing (void)
    9284              : {
    9285           24 :   if (gfc_match_omp_eos () != MATCH_YES)
    9286              :     {
    9287            1 :       gfc_error ("Unexpected junk after $OMP NOTHING statement at %C");
    9288            1 :       return MATCH_ERROR;
    9289              :     }
    9290              :   /* Will use ST_NONE; therefore, no EXEC_OMP_ is needed.  */
    9291              :   return MATCH_YES;
    9292              : }
    9293              : 
    9294              : match
    9295          317 : gfc_match_omp_ordered_depend (void)
    9296              : {
    9297          317 :   return match_omp (EXEC_OMP_ORDERED, omp_mask (OMP_CLAUSE_DOACROSS));
    9298              : }
    9299              : 
    9300              : 
    9301              : /* omp atomic [clause-list]
    9302              :    - atomic-clause:  read | write | update
    9303              :    - capture
    9304              :    - memory-order-clause: seq_cst | acq_rel | release | acquire | relaxed
    9305              :    - hint(hint-expr)
    9306              :    - OpenMP 5.1: compare | fail (seq_cst | acquire | relaxed ) | weak
    9307              : */
    9308              : 
    9309              : match
    9310         2188 : gfc_match_omp_atomic (void)
    9311              : {
    9312         2188 :   gfc_omp_clauses *c;
    9313         2188 :   locus loc = gfc_current_locus;
    9314              : 
    9315         2188 :   if (gfc_match_omp_clauses (&c, OMP_ATOMIC_CLAUSES, false, true) != MATCH_YES)
    9316              :     return MATCH_ERROR;
    9317              : 
    9318         2166 :   if (c->atomic_op == GFC_OMP_ATOMIC_UNSET)
    9319         1013 :     c->atomic_op = GFC_OMP_ATOMIC_UPDATE;
    9320              : 
    9321         2166 :   if (c->capture && c->atomic_op != GFC_OMP_ATOMIC_UPDATE)
    9322            3 :     gfc_error ("!$OMP ATOMIC at %L with %s clause is incompatible with "
    9323              :                "READ or WRITE", &loc, "CAPTURE");
    9324         2166 :   if (c->compare && c->atomic_op != GFC_OMP_ATOMIC_UPDATE)
    9325            3 :     gfc_error ("!$OMP ATOMIC at %L with %s clause is incompatible with "
    9326              :                "READ or WRITE", &loc, "COMPARE");
    9327         2166 :   if (c->fail != OMP_MEMORDER_UNSET && c->atomic_op != GFC_OMP_ATOMIC_UPDATE)
    9328            2 :     gfc_error ("!$OMP ATOMIC at %L with %s clause is incompatible with "
    9329              :                "READ or WRITE", &loc, "FAIL");
    9330         2166 :   if (c->weak && !c->compare)
    9331              :     {
    9332            5 :       gfc_error ("!$OMP ATOMIC at %L with %s clause requires %s clause", &loc,
    9333              :                  "WEAK", "COMPARE");
    9334            5 :       c->weak = false;
    9335              :     }
    9336              : 
    9337         2166 :   if (c->memorder == OMP_MEMORDER_UNSET)
    9338              :     {
    9339         1975 :       gfc_namespace *prog_unit = gfc_current_ns;
    9340         1975 :       while (prog_unit->parent
    9341         2537 :              && !(prog_unit->proc_name
    9342          562 :                   && prog_unit->proc_name->attr.flavor == FL_MODULE))
    9343          562 :         prog_unit = prog_unit->parent;
    9344         1975 :       switch (prog_unit->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    9345              :         {
    9346         1942 :         case 0:
    9347         1942 :         case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED:
    9348         1942 :           c->memorder = OMP_MEMORDER_RELAXED;
    9349         1942 :           break;
    9350            7 :         case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST:
    9351            7 :           c->memorder = OMP_MEMORDER_SEQ_CST;
    9352            7 :           break;
    9353           16 :         case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL:
    9354           16 :           if (c->capture)
    9355            5 :             c->memorder = OMP_MEMORDER_ACQ_REL;
    9356           11 :           else if (c->atomic_op == GFC_OMP_ATOMIC_READ)
    9357            3 :             c->memorder = OMP_MEMORDER_ACQUIRE;
    9358              :           else
    9359            8 :             c->memorder = OMP_MEMORDER_RELEASE;
    9360              :           break;
    9361            5 :         case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE:
    9362            5 :           if (c->atomic_op == GFC_OMP_ATOMIC_WRITE)
    9363              :             {
    9364            1 :               gfc_error ("!$OMP ATOMIC WRITE at %L incompatible with "
    9365              :                          "ACQUIRES clause implicitly provided by a "
    9366              :                          "REQUIRES directive", &loc);
    9367            1 :               c->memorder = OMP_MEMORDER_SEQ_CST;
    9368              :             }
    9369              :           else
    9370            4 :             c->memorder = OMP_MEMORDER_ACQUIRE;
    9371              :           break;
    9372            5 :         case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE:
    9373            5 :           if (c->atomic_op == GFC_OMP_ATOMIC_READ)
    9374              :             {
    9375            1 :               gfc_error ("!$OMP ATOMIC READ at %L incompatible with "
    9376              :                          "RELEASE clause implicitly provided by a "
    9377              :                          "REQUIRES directive", &loc);
    9378            1 :               c->memorder = OMP_MEMORDER_SEQ_CST;
    9379              :             }
    9380              :           else
    9381            4 :             c->memorder = OMP_MEMORDER_RELEASE;
    9382              :           break;
    9383            0 :         default:
    9384            0 :           gcc_unreachable ();
    9385              :         }
    9386              :     }
    9387              :   else
    9388          191 :     switch (c->atomic_op)
    9389              :       {
    9390           31 :       case GFC_OMP_ATOMIC_READ:
    9391           31 :         if (c->memorder == OMP_MEMORDER_RELEASE)
    9392              :           {
    9393            1 :             gfc_error ("!$OMP ATOMIC READ at %L incompatible with "
    9394              :                        "RELEASE clause", &loc);
    9395            1 :             c->memorder = OMP_MEMORDER_SEQ_CST;
    9396              :           }
    9397           30 :         else if (c->memorder == OMP_MEMORDER_ACQ_REL)
    9398            1 :           c->memorder = OMP_MEMORDER_ACQUIRE;
    9399              :         break;
    9400           37 :       case GFC_OMP_ATOMIC_WRITE:
    9401           37 :         if (c->memorder == OMP_MEMORDER_ACQUIRE)
    9402              :           {
    9403            1 :             gfc_error ("!$OMP ATOMIC WRITE at %L incompatible with "
    9404              :                        "ACQUIRE clause", &loc);
    9405            1 :             c->memorder = OMP_MEMORDER_SEQ_CST;
    9406              :           }
    9407           36 :         else if (c->memorder == OMP_MEMORDER_ACQ_REL)
    9408            3 :           c->memorder = OMP_MEMORDER_RELEASE;
    9409              :         break;
    9410              :       default:
    9411              :         break;
    9412              :       }
    9413         2166 :   gfc_error_check ();
    9414         2166 :   new_st.ext.omp_clauses = c;
    9415         2166 :   new_st.op = EXEC_OMP_ATOMIC;
    9416         2166 :   return MATCH_YES;
    9417              : }
    9418              : 
    9419              : 
    9420              : /* acc atomic [ read | write | update | capture]  */
    9421              : 
    9422              : match
    9423          552 : gfc_match_oacc_atomic (void)
    9424              : {
    9425          552 :   gfc_omp_clauses *c = gfc_get_omp_clauses ();
    9426          552 :   c->atomic_op = GFC_OMP_ATOMIC_UPDATE;
    9427          552 :   c->memorder = OMP_MEMORDER_RELAXED;
    9428          552 :   gfc_gobble_whitespace ();
    9429          552 :   if (gfc_match ("update") == MATCH_YES)
    9430              :     ;
    9431          373 :   else if (gfc_match ("read") == MATCH_YES)
    9432           17 :     c->atomic_op = GFC_OMP_ATOMIC_READ;
    9433          356 :   else if (gfc_match ("write") == MATCH_YES)
    9434           13 :     c->atomic_op = GFC_OMP_ATOMIC_WRITE;
    9435          343 :   else if (gfc_match ("capture") == MATCH_YES)
    9436          319 :     c->capture = true;
    9437          552 :   gfc_gobble_whitespace ();
    9438          552 :   if (gfc_match_omp_eos () != MATCH_YES)
    9439              :     {
    9440            9 :       gfc_error ("Unexpected junk after !$ACC ATOMIC statement at %C");
    9441            9 :       gfc_free_omp_clauses (c);
    9442            9 :       return MATCH_ERROR;
    9443              :     }
    9444          543 :   new_st.ext.omp_clauses = c;
    9445          543 :   new_st.op = EXEC_OACC_ATOMIC;
    9446          543 :   return MATCH_YES;
    9447              : }
    9448              : 
    9449              : 
    9450              : match
    9451          614 : gfc_match_omp_barrier (void)
    9452              : {
    9453          614 :   if (gfc_match_omp_eos () != MATCH_YES)
    9454              :     {
    9455            0 :       gfc_error ("Unexpected junk after $OMP BARRIER statement at %C");
    9456            0 :       return MATCH_ERROR;
    9457              :     }
    9458          614 :   new_st.op = EXEC_OMP_BARRIER;
    9459          614 :   new_st.ext.omp_clauses = NULL;
    9460          614 :   return MATCH_YES;
    9461              : }
    9462              : 
    9463              : 
    9464              : match
    9465          188 : gfc_match_omp_taskgroup (void)
    9466              : {
    9467          188 :   return match_omp (EXEC_OMP_TASKGROUP, OMP_TASKGROUP_CLAUSES);
    9468              : }
    9469              : 
    9470              : 
    9471              : static enum gfc_omp_cancel_kind
    9472          502 : gfc_match_omp_cancel_kind (void)
    9473              : {
    9474          502 :   if (gfc_match (" , ") != MATCH_YES
    9475          502 :       && gfc_match_space () != MATCH_YES)
    9476              :     return OMP_CANCEL_UNKNOWN;
    9477          502 :   if (gfc_match ("parallel") == MATCH_YES)
    9478              :     return OMP_CANCEL_PARALLEL;
    9479          352 :   if (gfc_match ("sections") == MATCH_YES)
    9480              :     return OMP_CANCEL_SECTIONS;
    9481          253 :   if (gfc_match ("do") == MATCH_YES)
    9482              :     return OMP_CANCEL_DO;
    9483          123 :   if (gfc_match ("taskgroup") == MATCH_YES)
    9484          121 :     return OMP_CANCEL_TASKGROUP;
    9485              :   return OMP_CANCEL_UNKNOWN;
    9486              : }
    9487              : 
    9488              : 
    9489              : match
    9490          324 : gfc_match_omp_cancel (void)
    9491              : {
    9492          324 :   gfc_omp_clauses *c;
    9493          324 :   enum gfc_omp_cancel_kind kind = gfc_match_omp_cancel_kind ();
    9494          324 :   if (kind == OMP_CANCEL_UNKNOWN)
    9495              :     return MATCH_ERROR;
    9496          324 :   if (gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_IF), false) != MATCH_YES)
    9497              :     return MATCH_ERROR;
    9498          321 :   c->cancel = kind;
    9499          321 :   new_st.op = EXEC_OMP_CANCEL;
    9500          321 :   new_st.ext.omp_clauses = c;
    9501          321 :   return MATCH_YES;
    9502              : }
    9503              : 
    9504              : 
    9505              : match
    9506          178 : gfc_match_omp_cancellation_point (void)
    9507              : {
    9508          178 :   gfc_omp_clauses *c;
    9509          178 :   enum gfc_omp_cancel_kind kind = gfc_match_omp_cancel_kind ();
    9510          178 :   if (kind == OMP_CANCEL_UNKNOWN)
    9511              :     {
    9512            2 :       gfc_error ("Expected construct-type PARALLEL, SECTIONS, DO or TASKGROUP "
    9513              :                  "in $OMP CANCELLATION POINT statement at %C");
    9514            2 :       return MATCH_ERROR;
    9515              :     }
    9516          176 :   if (gfc_match_omp_eos () != MATCH_YES)
    9517              :     {
    9518            0 :       gfc_error ("Unexpected junk after $OMP CANCELLATION POINT statement "
    9519              :                  "at %C");
    9520            0 :       return MATCH_ERROR;
    9521              :     }
    9522          176 :   c = gfc_get_omp_clauses ();
    9523          176 :   c->cancel = kind;
    9524          176 :   new_st.op = EXEC_OMP_CANCELLATION_POINT;
    9525          176 :   new_st.ext.omp_clauses = c;
    9526          176 :   return MATCH_YES;
    9527              : }
    9528              : 
    9529              : 
    9530              : match
    9531         2806 : gfc_match_omp_end_nowait (void)
    9532              : {
    9533         2806 :   bool nowait = false;
    9534         2806 :   if (gfc_match ("% nowait ") == MATCH_YES
    9535         2806 :       || gfc_match (" , nowait ") == MATCH_YES)
    9536              :     nowait = true;
    9537         2806 :   if (gfc_match_omp_eos () != MATCH_YES)
    9538              :     {
    9539            4 :       if (nowait)
    9540            3 :         gfc_error ("Unexpected junk after NOWAIT clause at %C");
    9541              :       else
    9542            1 :         gfc_error ("Unexpected junk at %C");
    9543              :       return MATCH_ERROR;
    9544              :     }
    9545         2802 :   new_st.op = EXEC_OMP_END_NOWAIT;
    9546         2802 :   new_st.ext.omp_bool = nowait;
    9547         2802 :   return MATCH_YES;
    9548              : }
    9549              : 
    9550              : 
    9551              : match
    9552          570 : gfc_match_omp_end_single (void)
    9553              : {
    9554          570 :   gfc_omp_clauses *c;
    9555          570 :   if (gfc_match_omp_clauses (&c, omp_mask (OMP_CLAUSE_COPYPRIVATE)
    9556              :                                            | OMP_CLAUSE_NOWAIT, false)
    9557              :       != MATCH_YES)
    9558              :     return MATCH_ERROR;
    9559          570 :   new_st.op = EXEC_OMP_END_SINGLE;
    9560          570 :   new_st.ext.omp_clauses = c;
    9561          570 :   return MATCH_YES;
    9562              : }
    9563              : 
    9564              : 
    9565              : static bool
    9566        37256 : oacc_is_loop (gfc_code *code)
    9567              : {
    9568        37256 :   return code->op == EXEC_OACC_PARALLEL_LOOP
    9569              :          || code->op == EXEC_OACC_KERNELS_LOOP
    9570        20201 :          || code->op == EXEC_OACC_SERIAL_LOOP
    9571        13457 :          || code->op == EXEC_OACC_LOOP;
    9572              : }
    9573              : 
    9574              : static bool
    9575         6089 : resolve_scalar_int_expr (gfc_expr *expr, const char *clause)
    9576              : {
    9577         6089 :   if (!gfc_resolve_expr (expr)
    9578         6089 :       || expr->ts.type != BT_INTEGER
    9579        12109 :       || expr->rank != 0)
    9580              :     {
    9581           87 :       gfc_error ("%s clause at %L requires a scalar INTEGER expression",
    9582              :                  clause, &expr->where);
    9583           87 :       return false;
    9584              :     }
    9585              :   return true;
    9586              : }
    9587              : 
    9588              : /* Require that EXPR is a scalar constant integer expression; it shall be a
    9589              :    positive number: If WARN is true, a warning is printed if constant and
    9590              :    not positive. If WARN is false, an error is printed if it is either not
    9591              :    constant or not positive.  CLAUSE is used in the diagnostic output.  */
    9592              : 
    9593              : static void
    9594         4578 : resolve_positive_int_expr (gfc_expr *expr, const char *clause, bool warn)
    9595              : {
    9596         4578 :   if (!resolve_scalar_int_expr (expr, clause))
    9597              :     return;
    9598         4543 :   if (warn
    9599         3743 :       && expr->expr_type == EXPR_CONSTANT
    9600         3343 :       && mpz_sgn (expr->value.integer) <= 0)
    9601           30 :     gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
    9602              :                  "INTEGER expression of %s clause at %L must be positive",
    9603              :                  clause, &expr->where);
    9604              :   else if (!warn
    9605          800 :            && (expr->expr_type != EXPR_CONSTANT
    9606          785 :                || mpz_sgn (expr->value.integer) <= 0))
    9607           36 :     gfc_error ("INTEGER expression of %s clause at %L must be positive and "
    9608              :                "constant", clause, &expr->where);
    9609              : }
    9610              : 
    9611              : /* Require that EXPR is a scalar constant integer expression; it shall be a
    9612              :    nonnegative number: If WARN is true, a warning is printed if constant and
    9613              :    negative. If WARN is false, an error is printed if it is either not constant
    9614              :    or negative.  CLAUSE is used in the diagnostic output.  */
    9615              : 
    9616              : static void
    9617          120 : resolve_nonnegative_int_expr (gfc_expr *expr, const char *clause, bool warn)
    9618              : {
    9619          120 :   if (!resolve_scalar_int_expr (expr, clause))
    9620              :     return;
    9621          113 :   if (warn
    9622          113 :       && expr->expr_type == EXPR_CONSTANT
    9623           61 :       && mpz_sgn (expr->value.integer) < 0)
    9624            8 :     gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
    9625              :                  "INTEGER expression of %s clause at %L must be non-negative",
    9626              :                  clause, &expr->where);
    9627              :   else if (!warn
    9628            0 :            && (expr->expr_type != EXPR_CONSTANT
    9629            0 :                || mpz_sgn (expr->value.integer) < 0))
    9630            0 :     gfc_error ("INTEGER expression of %s clause at %L must be non-negtive and "
    9631              :                "constant", clause, &expr->where);
    9632              : }
    9633              : 
    9634              : /* Emits error when symbol is pointer, cray pointer or cray pointee
    9635              :    of derived of polymorphic type.  */
    9636              : 
    9637              : static void
    9638           98 : check_symbol_not_pointer (gfc_symbol *sym, locus loc, const char *name)
    9639              : {
    9640           98 :   if (sym->ts.type == BT_DERIVED && sym->attr.cray_pointer)
    9641            0 :     gfc_error ("Cray pointer object %qs of derived type in %s clause at %L",
    9642              :                sym->name, name, &loc);
    9643           98 :   if (sym->ts.type == BT_DERIVED && sym->attr.cray_pointee)
    9644            0 :     gfc_error ("Cray pointee object %qs of derived type in %s clause at %L",
    9645              :                sym->name, name, &loc);
    9646              : 
    9647           98 :   if ((sym->ts.type == BT_ASSUMED && sym->attr.pointer)
    9648           98 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9649            0 :           && CLASS_DATA (sym)->attr.pointer))
    9650            0 :     gfc_error ("POINTER object %qs of polymorphic type in %s clause at %L",
    9651              :                sym->name, name, &loc);
    9652           98 :   if ((sym->ts.type == BT_ASSUMED && sym->attr.cray_pointer)
    9653           98 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9654            0 :           && CLASS_DATA (sym)->attr.cray_pointer))
    9655            0 :     gfc_error ("Cray pointer object %qs of polymorphic type in %s clause at %L",
    9656              :                sym->name, name, &loc);
    9657           98 :   if ((sym->ts.type == BT_ASSUMED && sym->attr.cray_pointee)
    9658           98 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9659            0 :           && CLASS_DATA (sym)->attr.cray_pointee))
    9660            0 :     gfc_error ("Cray pointee object %qs of polymorphic type in %s clause at %L",
    9661              :                sym->name, name, &loc);
    9662           98 : }
    9663              : 
    9664              : /* Emits error when symbol represents assumed size/rank array.  */
    9665              : 
    9666              : static void
    9667        14844 : check_array_not_assumed (gfc_symbol *sym, locus loc, const char *name)
    9668              : {
    9669        14844 :   if (sym->as && sym->as->type == AS_ASSUMED_SIZE)
    9670           13 :     gfc_error ("Assumed size array %qs in %s clause at %L",
    9671              :                sym->name, name, &loc);
    9672        14844 :   if (sym->as && sym->as->type == AS_ASSUMED_RANK)
    9673           11 :     gfc_error ("Assumed rank array %qs in %s clause at %L",
    9674              :                sym->name, name, &loc);
    9675        14844 : }
    9676              : 
    9677              : static void
    9678         5850 : resolve_oacc_data_clauses (gfc_symbol *sym, locus loc, const char *name)
    9679              : {
    9680            0 :   check_array_not_assumed (sym, loc, name);
    9681            0 : }
    9682              : 
    9683              : static void
    9684           65 : resolve_oacc_deviceptr_clause (gfc_symbol *sym, locus loc, const char *name)
    9685              : {
    9686           65 :   if (sym->attr.pointer
    9687           64 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9688            0 :           && CLASS_DATA (sym)->attr.class_pointer))
    9689            1 :     gfc_error ("POINTER object %qs in %s clause at %L",
    9690              :                sym->name, name, &loc);
    9691           65 :   if (sym->attr.cray_pointer
    9692           63 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9693            0 :           && CLASS_DATA (sym)->attr.cray_pointer))
    9694            2 :     gfc_error ("Cray pointer object %qs in %s clause at %L",
    9695              :                sym->name, name, &loc);
    9696           65 :   if (sym->attr.cray_pointee
    9697           63 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9698            0 :           && CLASS_DATA (sym)->attr.cray_pointee))
    9699            2 :     gfc_error ("Cray pointee object %qs in %s clause at %L",
    9700              :                sym->name, name, &loc);
    9701           65 :   if (sym->attr.allocatable
    9702           64 :       || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
    9703            0 :           && CLASS_DATA (sym)->attr.allocatable))
    9704            1 :     gfc_error ("ALLOCATABLE object %qs in %s clause at %L",
    9705              :                sym->name, name, &loc);
    9706           65 :   if (sym->attr.value)
    9707            1 :     gfc_error ("VALUE object %qs in %s clause at %L",
    9708              :                sym->name, name, &loc);
    9709           65 :   check_array_not_assumed (sym, loc, name);
    9710           65 : }
    9711              : 
    9712              : 
    9713              : struct resolve_omp_udr_callback_data
    9714              : {
    9715              :   gfc_symbol *sym1, *sym2;
    9716              : };
    9717              : 
    9718              : 
    9719              : static int
    9720         1413 : resolve_omp_udr_callback (gfc_expr **e, int *, void *data)
    9721              : {
    9722         1413 :   struct resolve_omp_udr_callback_data *rcd
    9723              :     = (struct resolve_omp_udr_callback_data *) data;
    9724         1413 :   if ((*e)->expr_type == EXPR_VARIABLE
    9725          801 :       && ((*e)->symtree->n.sym == rcd->sym1
    9726          255 :           || (*e)->symtree->n.sym == rcd->sym2))
    9727              :     {
    9728          801 :       gfc_ref *ref = gfc_get_ref ();
    9729          801 :       ref->type = REF_ARRAY;
    9730          801 :       ref->u.ar.where = (*e)->where;
    9731          801 :       ref->u.ar.as = (*e)->symtree->n.sym->as;
    9732          801 :       ref->u.ar.type = AR_FULL;
    9733          801 :       ref->u.ar.dimen = 0;
    9734          801 :       ref->next = (*e)->ref;
    9735          801 :       (*e)->ref = ref;
    9736              :     }
    9737         1413 :   return 0;
    9738              : }
    9739              : 
    9740              : 
    9741              : static int
    9742         3008 : resolve_omp_udr_callback2 (gfc_expr **e, int *, void *)
    9743              : {
    9744         3008 :   if ((*e)->expr_type == EXPR_FUNCTION
    9745          360 :       && (*e)->value.function.isym == NULL)
    9746              :     {
    9747          174 :       gfc_symbol *sym = (*e)->symtree->n.sym;
    9748          174 :       if (!sym->attr.intrinsic
    9749          174 :           && sym->attr.if_source == IFSRC_UNKNOWN)
    9750            4 :         gfc_error ("Implicitly declared function %s used in "
    9751              :                    "!$OMP DECLARE REDUCTION at %L", sym->name, &(*e)->where);
    9752              :     }
    9753         3008 :   return 0;
    9754              : }
    9755              : 
    9756              : 
    9757              : static gfc_code *
    9758          802 : resolve_omp_udr_clause (gfc_omp_namelist *n, gfc_namespace *ns,
    9759              :                         gfc_symbol *sym1, gfc_symbol *sym2)
    9760              : {
    9761          802 :   gfc_code *copy;
    9762          802 :   gfc_symbol sym1_copy, sym2_copy;
    9763              : 
    9764          802 :   if (ns->code->op == EXEC_ASSIGN)
    9765              :     {
    9766          630 :       copy = gfc_get_code (EXEC_ASSIGN);
    9767          630 :       copy->expr1 = gfc_copy_expr (ns->code->expr1);
    9768          630 :       copy->expr2 = gfc_copy_expr (ns->code->expr2);
    9769              :     }
    9770              :   else
    9771              :     {
    9772          172 :       copy = gfc_get_code (EXEC_CALL);
    9773          172 :       copy->symtree = ns->code->symtree;
    9774          172 :       copy->ext.actual = gfc_copy_actual_arglist (ns->code->ext.actual);
    9775              :     }
    9776          802 :   copy->loc = ns->code->loc;
    9777          802 :   sym1_copy = *sym1;
    9778          802 :   sym2_copy = *sym2;
    9779          802 :   *sym1 = *n->sym;
    9780          802 :   *sym2 = *n->sym;
    9781          802 :   sym1->name = sym1_copy.name;
    9782          802 :   sym2->name = sym2_copy.name;
    9783          802 :   ns->proc_name = ns->parent->proc_name;
    9784          802 :   if (n->sym->attr.dimension)
    9785              :     {
    9786          348 :       struct resolve_omp_udr_callback_data rcd;
    9787          348 :       rcd.sym1 = sym1;
    9788          348 :       rcd.sym2 = sym2;
    9789          348 :       gfc_code_walker (&copy, gfc_dummy_code_callback,
    9790              :                        resolve_omp_udr_callback, &rcd);
    9791              :     }
    9792          802 :   gfc_resolve_code (copy, gfc_current_ns);
    9793          802 :   if (copy->op == EXEC_CALL && copy->resolved_isym == NULL)
    9794              :     {
    9795          172 :       gfc_symbol *sym = copy->resolved_sym;
    9796          172 :       if (sym
    9797          170 :           && !sym->attr.intrinsic
    9798          170 :           && sym->attr.if_source == IFSRC_UNKNOWN)
    9799            4 :         gfc_error ("Implicitly declared subroutine %s used in "
    9800              :                    "!$OMP DECLARE REDUCTION at %L", sym->name,
    9801              :                    &copy->loc);
    9802              :     }
    9803          802 :   gfc_code_walker (&copy, gfc_dummy_code_callback,
    9804              :                    resolve_omp_udr_callback2, NULL);
    9805          802 :   *sym1 = sym1_copy;
    9806          802 :   *sym2 = sym2_copy;
    9807          802 :   return copy;
    9808              : }
    9809              : 
    9810              : /* Assume that a constant expression in the range 1 (omp_default_mem_alloc)
    9811              :    to GOMP_OMP_PREDEF_ALLOC_MAX, or GOMP_OMPX_PREDEF_ALLOC_MIN to
    9812              :    GOMP_OMPX_PREDEF_ALLOC_MAX is fine.  The original symbol name is already
    9813              :    lost during matching via gfc_match_expr.  */
    9814              : static bool
    9815          130 : is_predefined_allocator (gfc_expr *expr)
    9816              : {
    9817          130 :   return (gfc_resolve_expr (expr)
    9818          129 :           && expr->rank == 0
    9819          124 :           && expr->ts.type == BT_INTEGER
    9820          119 :           && expr->ts.kind == gfc_c_intptr_kind
    9821          114 :           && expr->expr_type == EXPR_CONSTANT
    9822          239 :           && ((mpz_sgn (expr->value.integer) > 0
    9823          107 :                && mpz_cmp_si (expr->value.integer,
    9824              :                               GOMP_OMP_PREDEF_ALLOC_MAX) <= 0)
    9825            4 :               || (mpz_cmp_si (expr->value.integer,
    9826              :                               GOMP_OMPX_PREDEF_ALLOC_MIN) >= 0
    9827            1 :                   && mpz_cmp_si (expr->value.integer,
    9828          130 :                                  GOMP_OMPX_PREDEF_ALLOC_MAX) <= 0)));
    9829              : }
    9830              : 
    9831              : /* Resolve declarative ALLOCATE statement. Note: Common block vars only appear
    9832              :    as /block/ not individual, which is ensured during parsing.  */
    9833              : 
    9834              : void
    9835           62 : gfc_resolve_omp_allocate (gfc_namespace *ns, gfc_omp_namelist *list)
    9836              : {
    9837          278 :   for (gfc_omp_namelist *n = list; n; n = n->next)
    9838              :     {
    9839          216 :       if (n->sym->attr.result || n->sym->result == n->sym)
    9840              :         {
    9841            1 :           gfc_error ("Unexpected function-result variable %qs at %L in "
    9842              :                      "declarative !$OMP ALLOCATE", n->sym->name, &n->where);
    9843           30 :           continue;
    9844              :         }
    9845          215 :       if (ns->omp_allocate->sym->attr.proc_pointer)
    9846              :         {
    9847            0 :           gfc_error ("Procedure pointer %qs not supported with !$OMP "
    9848              :                      "ALLOCATE at %L", n->sym->name, &n->where);
    9849            0 :           continue;
    9850              :         }
    9851          215 :       if (n->sym->attr.flavor != FL_VARIABLE)
    9852              :         {
    9853            3 :           gfc_error ("Argument %qs at %L to declarative !$OMP ALLOCATE "
    9854              :                      "directive must be a variable", n->sym->name,
    9855              :                      &n->where);
    9856            3 :           continue;
    9857              :         }
    9858          212 :       if (ns != n->sym->ns || n->sym->attr.use_assoc || n->sym->attr.imported)
    9859              :         {
    9860            8 :           gfc_error ("Argument %qs at %L to declarative !$OMP ALLOCATE shall be"
    9861              :                      " in the same scope as the variable declaration",
    9862              :                      n->sym->name, &n->where);
    9863            8 :           continue;
    9864              :         }
    9865          204 :       if (n->sym->attr.dummy)
    9866              :         {
    9867            3 :           gfc_error ("Unexpected dummy argument %qs as argument at %L to "
    9868              :                      "declarative !$OMP ALLOCATE", n->sym->name, &n->where);
    9869            3 :           continue;
    9870              :         }
    9871          201 :       if (n->sym->attr.codimension)
    9872              :         {
    9873            0 :           gfc_error ("Unexpected coarray argument %qs as argument at %L to "
    9874              :                      "declarative !$OMP ALLOCATE", n->sym->name, &n->where);
    9875            0 :           continue;
    9876              :         }
    9877          201 :       if (n->sym->attr.omp_allocate)
    9878              :         {
    9879            5 :           if (n->sym->attr.in_common)
    9880              :             {
    9881            1 :               gfc_error ("Duplicated common block %</%s/%> in !$OMP ALLOCATE "
    9882            1 :                          "at %L", n->sym->common_head->name, &n->where);
    9883            3 :               while (n->next && n->next->sym
    9884            3 :                      && n->sym->common_head == n->next->sym->common_head)
    9885              :                 n = n->next;
    9886              :             }
    9887              :           else
    9888            4 :             gfc_error ("Duplicated variable %qs in !$OMP ALLOCATE at %L",
    9889              :                        n->sym->name, &n->where);
    9890            5 :           continue;
    9891              :         }
    9892              :       /* For 'equivalence(a,b)', a 'union_type {<type> a,b} equiv.0' is created
    9893              :          with a value expression for 'a' as 'equiv.0.a' (likewise for b); while
    9894              :          this can be handled, EQUIVALENCE is marked as obsolescent since Fortran
    9895              :          2018 and also not widely used.  However, it could be supported,
    9896              :          if needed. */
    9897          196 :       if (n->sym->attr.in_equivalence)
    9898              :         {
    9899            2 :           gfc_error ("Sorry, EQUIVALENCE object %qs not supported with !$OMP "
    9900              :                      "ALLOCATE at %L", n->sym->name, &n->where);
    9901            2 :           continue;
    9902              :         }
    9903              :       /* Similar for Cray pointer/pointee - they could be implemented but as
    9904              :          common vendor extension but nowadays rarely used and requiring
    9905              :          -fcray-pointer, there is no need to support them.  */
    9906          194 :       if (n->sym->attr.cray_pointer || n->sym->attr.cray_pointee)
    9907              :         {
    9908            2 :           gfc_error ("Sorry, Cray pointers and pointees such as %qs are not "
    9909              :                      "supported with !$OMP ALLOCATE at %L",
    9910              :                      n->sym->name, &n->where);
    9911            2 :           continue;
    9912              :         }
    9913          192 :       n->sym->attr.omp_allocate = 1;
    9914          192 :       if ((n->sym->ts.type == BT_CLASS && n->sym->attr.class_ok
    9915            0 :            && CLASS_DATA (n->sym)->attr.allocatable)
    9916          192 :           || (n->sym->ts.type != BT_CLASS && n->sym->attr.allocatable))
    9917            1 :         gfc_error ("Unexpected allocatable variable %qs at %L in declarative "
    9918              :                    "!$OMP ALLOCATE directive", n->sym->name, &n->where);
    9919          191 :       else if ((n->sym->ts.type == BT_CLASS && n->sym->attr.class_ok
    9920            0 :                 && CLASS_DATA (n->sym)->attr.class_pointer)
    9921          191 :                || (n->sym->ts.type != BT_CLASS && n->sym->attr.pointer))
    9922            1 :         gfc_error ("Unexpected pointer variable %qs at %L in declarative "
    9923              :                    "!$OMP ALLOCATE directive", n->sym->name, &n->where);
    9924          192 :       HOST_WIDE_INT alignment = 0;
    9925          198 :       if (n->u.align
    9926          192 :           && (!gfc_resolve_expr (n->u.align)
    9927           27 :               || n->u.align->ts.type != BT_INTEGER
    9928           26 :               || n->u.align->rank != 0
    9929           24 :               || n->u.align->expr_type != EXPR_CONSTANT
    9930           23 :               || gfc_extract_hwi (n->u.align, &alignment)
    9931           23 :               || !pow2p_hwi (alignment)))
    9932              :         {
    9933            6 :           gfc_error ("ALIGN requires a scalar positive constant integer "
    9934              :                      "alignment expression at %L that is a power of two",
    9935            6 :                      &n->u.align->where);
    9936            6 :           while (n->sym->attr.in_common && n->next && n->next->sym
    9937            6 :                  && n->sym->common_head == n->next->sym->common_head)
    9938              :             n = n->next;
    9939            6 :           continue;
    9940              :         }
    9941          186 :       if (n->sym->attr.in_common || n->sym->attr.save || n->sym->ns->save_all
    9942           63 :           || (n->sym->ns->proc_name
    9943           63 :               && (n->sym->ns->proc_name->attr.flavor == FL_PROGRAM
    9944           55 :                   || n->sym->ns->proc_name->attr.flavor == FL_MODULE
    9945           55 :                   || n->sym->ns->proc_name->attr.flavor == FL_BLOCK_DATA)))
    9946              :         {
    9947          131 :           bool com = n->sym->attr.in_common;
    9948          131 :           if (!n->u2.allocator)
    9949            1 :             gfc_error ("An ALLOCATOR clause is required as the list item "
    9950              :                        "%<%s%s%s%> at %L has the SAVE attribute", com ? "/" : "",
    9951            0 :                        com ? n->sym->common_head->name : n->sym->name,
    9952              :                        com ? "/" : "", &n->where);
    9953          130 :           else if (!is_predefined_allocator (n->u2.allocator))
    9954           24 :             gfc_error ("Predefined allocator required in ALLOCATOR clause at %L"
    9955              :                        " as the list item %<%s%s%s%> at %L has the SAVE attribute",
    9956           24 :                        &n->u2.allocator->where, com ? "/" : "",
    9957           24 :                        com ? n->sym->common_head->name : n->sym->name,
    9958              :                        com ? "/" : "", &n->where);
    9959              :           /* Static variables may not use omp_cgroup_mem_alloc (6),
    9960              :              omp_pteam_mem_alloc (7), or omp_thread_mem_alloc (8).  */
    9961          106 :           else if (mpz_cmp_si (n->u2.allocator->value.integer,
    9962              :                                   6 /* cgroup */) >= 0
    9963           34 :                    && mpz_cmp_si (n->u2.allocator->value.integer,
    9964              :                                   8 /* thread */) <= 0)
    9965              :             {
    9966           33 :               STATIC_ASSERT (GOMP_OMP_PREDEF_ALLOC_CGROUP == 6);
    9967           33 :               STATIC_ASSERT (GOMP_OMP_PREDEF_ALLOC_PTEAM == 7);
    9968           33 :               STATIC_ASSERT (GOMP_OMP_PREDEF_ALLOC_THREAD == 8);
    9969           33 :               const char *alloc_name[] = {"omp_cgroup_mem_alloc",
    9970              :                                           "omp_pteam_mem_alloc",
    9971              :                                           "omp_thread_mem_alloc" };
    9972           33 :               gfc_error ("Predefined allocator %qs in ALLOCATOR clause at %L, "
    9973              :                          "used for list item %<%s%s%s%> at %L, may not be used"
    9974              :                          " for static variables",
    9975           33 :                          alloc_name[mpz_get_ui (n->u2.allocator->value.integer)
    9976           33 :                                     - 6 /* cgroup */], &n->u2.allocator->where,
    9977              :                          com ? "/" : "",
    9978           33 :                          com ? n->sym->common_head->name : n->sym->name,
    9979              :                          com ? "/" : "", &n->where);
    9980              :             }
    9981           67 :           while (n->sym->attr.in_common && n->next && n->next->sym
    9982          186 :                  && n->sym->common_head == n->next->sym->common_head)
    9983              :             n = n->next;
    9984              :         }
    9985           55 :       else if (n->u2.allocator
    9986           55 :           && (!gfc_resolve_expr (n->u2.allocator)
    9987           20 :               || n->u2.allocator->ts.type != BT_INTEGER
    9988           19 :               || n->u2.allocator->rank != 0
    9989           18 :               || n->u2.allocator->ts.kind != gfc_c_intptr_kind))
    9990            3 :         gfc_error ("Expected integer expression of the "
    9991              :                    "%<omp_allocator_handle_kind%> kind at %L",
    9992            3 :                    &n->u2.allocator->where);
    9993              :     }
    9994           62 : }
    9995              : 
    9996              : /* Resolve ASSUME's and ASSUMES' assumption clauses.  Note that absent/contains
    9997              :    is handled during parse time in omp_verify_merge_absent_contains.   */
    9998              : 
    9999              : void
   10000           34 : gfc_resolve_omp_assumptions (gfc_omp_assumptions *assume)
   10001              : {
   10002           54 :   for (gfc_expr_list *el = assume->holds; el; el = el->next)
   10003           20 :     if (!gfc_resolve_expr (el->expr)
   10004           20 :         || el->expr->ts.type != BT_LOGICAL
   10005           38 :         || el->expr->rank != 0)
   10006            4 :       gfc_error ("HOLDS expression at %L must be a scalar logical expression",
   10007            4 :                  &el->expr->where);
   10008           34 : }
   10009              : 
   10010              : 
   10011              : /* Resolve the OpenMP ALLOCATE clauses.  */
   10012              : 
   10013              : static void
   10014        33556 : resolve_omp_allocate_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
   10015              :                               gfc_namespace *ns)
   10016              : {
   10017        33556 :   gfc_omp_namelist *n;
   10018        33556 :   enum gfc_omp_list_type list;
   10019              : 
   10020        33556 :   if (!omp_clauses->lists[OMP_LIST_ALLOCATE])
   10021              :     return;
   10022          795 :   for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
   10023              :     {
   10024          515 :       if (n->u2.allocator
   10025          515 :           && (!gfc_resolve_expr (n->u2.allocator)
   10026          290 :               || n->u2.allocator->ts.type != BT_INTEGER
   10027          288 :               || n->u2.allocator->rank != 0
   10028          287 :               || n->u2.allocator->ts.kind != gfc_c_intptr_kind))
   10029              :         {
   10030            8 :           gfc_error ("Expected integer expression of the "
   10031              :                      "%<omp_allocator_handle_kind%> kind at %L",
   10032            8 :                      &n->u2.allocator->where);
   10033           28 :           break;
   10034              :         }
   10035          507 :       if (!n->u.align)
   10036          399 :         continue;
   10037          108 :       HOST_WIDE_INT alignment = 0;
   10038          108 :       if (!gfc_resolve_expr (n->u.align)
   10039          108 :           || n->u.align->ts.type != BT_INTEGER
   10040          105 :           || n->u.align->rank != 0
   10041          102 :           || n->u.align->expr_type != EXPR_CONSTANT
   10042           99 :           || gfc_extract_hwi (n->u.align, &alignment)
   10043           99 :           || alignment <= 0
   10044          207 :           || !pow2p_hwi (alignment))
   10045              :         {
   10046           12 :           gfc_error ("ALIGN requires a scalar positive constant integer "
   10047              :                      "alignment expression at %L that is a power of two",
   10048           12 :                      &n->u.align->where);
   10049           12 :           break;
   10050              :         }
   10051              :     }
   10052              : 
   10053              :   /* Check for 2 things here.
   10054              :       1.  There is no duplication of variable in allocate clause.
   10055              :       2.  Variable in allocate clause are also present in some
   10056              :           privatization clase (non-composite case).  */
   10057          815 :   for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
   10058          515 :     if (n->sym)
   10059          489 :       n->sym->mark = 0;
   10060              : 
   10061              :   gfc_omp_namelist *prev = NULL;
   10062          815 :   for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; )
   10063              :     {
   10064          515 :       if (n->sym == NULL)
   10065              :         {
   10066           26 :           n = n->next;
   10067           26 :           continue;
   10068              :         }
   10069          489 :       if (n->sym->mark == 1)
   10070              :         {
   10071            3 :           gfc_warning (OPT_Wopenmp, "%qs appears more than once in "
   10072              :                        "%<allocate%> at %L" , n->sym->name, &n->where);
   10073              :           /* We have already seen this variable so it is a duplicate.
   10074              :              Remove it.  */
   10075            3 :           if (prev != NULL && prev->next == n)
   10076              :             {
   10077            3 :               prev->next = n->next;
   10078            3 :               n->next = NULL;
   10079            3 :               gfc_free_omp_namelist (n, OMP_LIST_ALLOCATE);
   10080            3 :               n = prev->next;
   10081              :             }
   10082            3 :           continue;
   10083              :         }
   10084          486 :       n->sym->mark = 1;
   10085          486 :       prev = n;
   10086          486 :       n = n->next;
   10087              :     }
   10088              : 
   10089              :   /* Non-composite constructs.  */
   10090          300 :   if (code && code->op < EXEC_OMP_DO_SIMD)
   10091              :     {
   10092         4760 :       for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   10093         4641 :            list = gfc_omp_list_type (list + 1))
   10094         4641 :         switch (list)
   10095              :           {
   10096         1071 :           case OMP_LIST_PRIVATE:
   10097         1071 :           case OMP_LIST_FIRSTPRIVATE:
   10098         1071 :           case OMP_LIST_LASTPRIVATE:
   10099         1071 :           case OMP_LIST_REDUCTION:
   10100         1071 :           case OMP_LIST_REDUCTION_INSCAN:
   10101         1071 :           case OMP_LIST_REDUCTION_TASK:
   10102         1071 :           case OMP_LIST_IN_REDUCTION:
   10103         1071 :           case OMP_LIST_TASK_REDUCTION:
   10104         1071 :           case OMP_LIST_LINEAR:
   10105         1370 :             for (n = omp_clauses->lists[list]; n; n = n->next)
   10106          299 :                  n->sym->mark = 0;
   10107              :             break;
   10108              :           default:
   10109              :             break;
   10110              :           }
   10111              : 
   10112          410 :       for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
   10113          291 :         if (n->sym->mark == 1)
   10114            4 :           gfc_error ("%qs specified in %<allocate%> clause at %L but not "
   10115              :                      "in an explicit privatization clause",
   10116              :                      n->sym->name, &n->where);
   10117              :     }
   10118           71 :   if (!(code
   10119          300 :         && (code->op == EXEC_OMP_ALLOCATORS || code->op == EXEC_OMP_ALLOCATE)
   10120           73 :         && code->block
   10121           72 :         && code->block->next
   10122           71 :         && code->block->next->op == EXEC_ALLOCATE))
   10123              :     return;
   10124              : 
   10125           68 :   if (code->op == EXEC_OMP_ALLOCATE)
   10126           49 :     gfc_warning (OPT_Wdeprecated_openmp,
   10127              :                  "The use of one or more %<allocate%> directives with "
   10128              :                  "an associated %<allocate%> statement at %L is "
   10129              :                  "deprecated since OpenMP 5.2, use an %<allocators%> "
   10130              :                  "directive", &code->loc);
   10131           68 :   gfc_alloc *a;
   10132           68 :   gfc_omp_namelist *n_null = NULL;
   10133           68 :   bool missing_allocator = false;
   10134           68 :   gfc_symbol *missing_allocator_sym = NULL;
   10135          161 :   for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
   10136              :     {
   10137           93 :       if (n->u2.allocator == NULL)
   10138              :         {
   10139           77 :           if (!missing_allocator_sym)
   10140           59 :             missing_allocator_sym = n->sym;
   10141              :           missing_allocator = true;
   10142              :         }
   10143           93 :       if (n->sym == NULL)
   10144              :         {
   10145           26 :           n_null = n;
   10146           26 :           continue;
   10147              :         }
   10148           67 :       if (n->sym->attr.codimension)
   10149            2 :         gfc_error ("Unexpected coarray %qs in %<allocate%> at %L",
   10150              :                            n->sym->name, &n->where);
   10151          103 :       for (a = code->block->next->ext.alloc.list; a; a = a->next)
   10152          101 :         if (a->expr->expr_type == EXPR_VARIABLE
   10153          101 :             && a->expr->symtree->n.sym == n->sym)
   10154              :           {
   10155           65 :             gfc_ref *ref;
   10156           82 :             for (ref = a->expr->ref; ref; ref = ref->next)
   10157           17 :               if (ref->type == REF_COMPONENT)
   10158              :                 break;
   10159              :             if (ref == NULL)
   10160              :               break;
   10161              :           }
   10162           67 :       if (a == NULL)
   10163            2 :         gfc_error ("%qs specified in %<allocate%> at %L but not "
   10164              :                    "in the associated ALLOCATE statement",
   10165            2 :                    n->sym->name, &n->where);
   10166              :     }
   10167              :   /* If there is an ALLOCATE directive without list argument, a
   10168              :      namelist with its allocator/align clauses and n->sym = NULL is
   10169              :      created during parsing; here, we add all not otherwise specified
   10170              :      items from the Fortran allocate to that list.
   10171              :      For an ALLOCATORS directive, not listed items use the normal
   10172              :      Fortran way.
   10173              :      The behavior of an ALLOCATE directive that does not list all
   10174              :      arguments but there is no directive without list argument is not
   10175              :      well specified.  Thus, we reject such code below. In OpenMP 5.2
   10176              :      the executable ALLOCATE directive is deprecated and in 6.0
   10177              :      deleted such that no spec clarification is to be expected.  */
   10178          125 :   for (a = code->block->next->ext.alloc.list; a; a = a->next)
   10179           89 :     if (a->expr->expr_type == EXPR_VARIABLE)
   10180              :       {
   10181          154 :         for (n = omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
   10182          122 :           if (a->expr->symtree->n.sym == n->sym)
   10183              :             {
   10184           57 :               gfc_ref *ref;
   10185           72 :               for (ref = a->expr->ref; ref; ref = ref->next)
   10186           15 :                 if (ref->type == REF_COMPONENT)
   10187              :                   break;
   10188              :               if (ref == NULL)
   10189              :                 break;
   10190              :             }
   10191           89 :         if (n == NULL && n_null == NULL)
   10192              :           {
   10193              :             /* OK for ALLOCATORS but for ALLOCATE: Unspecified whether
   10194              :                    that should use the default allocator of OpenMP or the
   10195              :                    Fortran allocator. Thus, just reject it.  */
   10196            7 :             if (code->op == EXEC_OMP_ALLOCATE)
   10197            1 :               gfc_error ("%qs listed in %<allocate%> statement at %L "
   10198              :                          "but it is neither explicitly in listed in "
   10199              :                          "the %<!$OMP ALLOCATE%> directive nor exists"
   10200              :                          " a directive without argument list",
   10201            1 :                          a->expr->symtree->n.sym->name,
   10202              :                          &a->expr->where);
   10203              :             break;
   10204              :           }
   10205           82 :         if (n == NULL)
   10206              :           {
   10207           25 :             if (a->expr->symtree->n.sym->attr.codimension)
   10208            1 :               gfc_error ("Unexpected coarray %qs in %<allocate%> at "
   10209              :                          "%L, implicitly listed in %<!$OMP ALLOCATE%>"
   10210              :                          " at %L", a->expr->symtree->n.sym->name,
   10211              :                          &a->expr->where, &n_null->where);
   10212              :             break;
   10213              :           }
   10214              :       }
   10215           68 :   gfc_namespace *prog_unit = ns;
   10216           87 :   while (prog_unit->parent)
   10217              :     prog_unit = prog_unit->parent;
   10218              :   gfc_namespace *fn_ns = ns;
   10219           72 :   while (fn_ns)
   10220              :     {
   10221           70 :       if (ns->proc_name
   10222           70 :           && (ns->proc_name->attr.subroutine
   10223            6 :               || ns->proc_name->attr.function))
   10224              :         break;
   10225            4 :       fn_ns = fn_ns->parent;
   10226              :     }
   10227           68 :   if (missing_allocator
   10228           58 :       && !(prog_unit->omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
   10229           58 :       && ((fn_ns && fn_ns->proc_name->attr.omp_declare_target)
   10230           55 :           || omp_clauses->contained_in_target_construct))
   10231              :     {
   10232            6 :       if (code->op == EXEC_OMP_ALLOCATORS)
   10233            2 :         gfc_error ("ALLOCATORS directive at %L inside a target region "
   10234              :                    "must specify an ALLOCATOR modifier for %qs",
   10235              :                    &code->loc, missing_allocator_sym->name);
   10236            4 :       else if (missing_allocator_sym)
   10237            2 :         gfc_error ("ALLOCATE directive at %L inside a target region "
   10238              :                    "must specify an ALLOCATOR clause for %qs",
   10239              :                    &code->loc, missing_allocator_sym->name);
   10240              :       else
   10241            2 :         gfc_error ("ALLOCATE directive at %L inside a target region "
   10242              :                    "must specify an ALLOCATOR clause", &code->loc);
   10243              :     }
   10244              : }
   10245              : 
   10246              : 
   10247              : /* Diagnose list items that appear multiple times in OpenMP or OpenACC clauses,
   10248              :    unless permitted by the specification.  */
   10249              : 
   10250              : static void
   10251        33556 : check_omp_clauses_dupl_syms (gfc_code *code, gfc_omp_clauses *omp_clauses,
   10252              :                             bool openacc)
   10253              : {
   10254        33556 :   gfc_omp_namelist *n;
   10255        33556 :   enum gfc_omp_list_type list;
   10256              : 
   10257              :   /* Check that no symbol appears on multiple clauses, except that
   10258              :      a symbol can appear on both firstprivate and lastprivate.  */
   10259      1342240 :   for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   10260      1308684 :        list = gfc_omp_list_type (list + 1))
   10261      1354928 :     for (n = omp_clauses->lists[list]; n; n = n->next)
   10262              :       {
   10263        46244 :         if (!n->sym)  /* omp_all_memory.  */
   10264           47 :           continue;
   10265        46197 :         n->sym->mark = 0;
   10266        46197 :         n->sym->comp_mark = 0;
   10267        46197 :         n->sym->data_mark = 0;
   10268        46197 :         n->sym->dev_mark = 0;
   10269        46197 :         n->sym->gen_mark = 0;
   10270        46197 :         n->sym->reduc_mark = 0;
   10271              :       }
   10272      1342240 :   for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   10273      1308684 :        list = gfc_omp_list_type (list + 1))
   10274      1308684 :     if (list != OMP_LIST_FIRSTPRIVATE
   10275      1308684 :         && list != OMP_LIST_LASTPRIVATE
   10276      1308684 :         && list != OMP_LIST_ALIGNED
   10277      1208016 :         && list != OMP_LIST_DEPEND
   10278      1208016 :         && list != OMP_LIST_FROM
   10279      1140904 :         && list != OMP_LIST_TO
   10280      1140904 :         && list != OMP_LIST_INTEROP
   10281      1073792 :         && (list != OMP_LIST_REDUCTION || !openacc)
   10282      1060797 :         && list != OMP_LIST_ALLOCATE)
   10283      1062339 :       for (n = omp_clauses->lists[list]; n; n = n->next)
   10284              :         {
   10285        35098 :           bool component_ref_p = false;
   10286              : 
   10287              :           /* Allow multiple components of the same (e.g. derived-type)
   10288              :              variable here.  Duplicate components are detected elsewhere.  */
   10289        35098 :           if (n->expr && n->expr->expr_type == EXPR_VARIABLE)
   10290        16021 :             for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
   10291         9744 :               if (ref->type == REF_COMPONENT)
   10292         3197 :                 component_ref_p = true;
   10293        35098 :           if ((list == OMP_LIST_IS_DEVICE_PTR
   10294        35098 :                || list == OMP_LIST_HAS_DEVICE_ADDR)
   10295          314 :               && !component_ref_p)
   10296              :             {
   10297          314 :               if (n->sym->gen_mark
   10298          312 :                   || n->sym->dev_mark
   10299          311 :                   || n->sym->reduc_mark
   10300          311 :                   || n->sym->mark)
   10301            5 :                 gfc_error ("Symbol %qs present on multiple clauses at %L",
   10302              :                            n->sym->name, &n->where);
   10303              :               else
   10304          309 :                 n->sym->dev_mark = 1;
   10305              :             }
   10306        34784 :           else if ((list == OMP_LIST_USE_DEVICE_PTR
   10307        34784 :                     || list == OMP_LIST_USE_DEVICE_ADDR
   10308        34784 :                     || list == OMP_LIST_PRIVATE
   10309              :                     || list == OMP_LIST_SHARED)
   10310        12931 :                    && !component_ref_p)
   10311              :             {
   10312        12931 :               if (n->sym->gen_mark || n->sym->dev_mark || n->sym->reduc_mark)
   10313           13 :                 gfc_error ("Symbol %qs present on multiple clauses at %L",
   10314              :                            n->sym->name, &n->where);
   10315              :               else
   10316              :                 {
   10317        12918 :                   n->sym->gen_mark = 1;
   10318              :                   /* Set both generic and device bits if we have
   10319              :                      use_device_*(x) or shared(x).  This allows us to diagnose
   10320              :                      "map(x) private(x)" below.  */
   10321        12918 :                   if (list != OMP_LIST_PRIVATE)
   10322         3469 :                     n->sym->dev_mark = 1;
   10323              :                 }
   10324              :             }
   10325        21853 :           else if ((list == OMP_LIST_REDUCTION
   10326        21853 :                     || list == OMP_LIST_REDUCTION_TASK
   10327        19385 :                     || list == OMP_LIST_REDUCTION_INSCAN
   10328        19385 :                     || list == OMP_LIST_IN_REDUCTION
   10329        19172 :                     || list == OMP_LIST_TASK_REDUCTION)
   10330         2681 :                    && !component_ref_p)
   10331              :             {
   10332              :               /* Attempts to mix reduction types are diagnosed below.  */
   10333         2681 :               if (n->sym->gen_mark || n->sym->dev_mark)
   10334            2 :                 gfc_error ("Symbol %qs present on multiple clauses at %L",
   10335              :                            n->sym->name, &n->where);
   10336         2681 :               n->sym->reduc_mark = 1;
   10337              :             }
   10338        19172 :           else if ((!component_ref_p && n->sym->comp_mark)
   10339        19171 :                    || (component_ref_p && n->sym->mark))
   10340              :             {
   10341           42 :               if (openacc)
   10342            3 :                 gfc_error ("Symbol %qs has mixed component and non-component "
   10343            3 :                            "accesses at %L", n->sym->name, &n->where);
   10344              :             }
   10345        19130 :           else if ((openacc || list != OMP_LIST_MAP) && n->sym->mark)
   10346           88 :             gfc_error ("Symbol %qs present on multiple clauses at %L",
   10347              :                        n->sym->name, &n->where);
   10348              :           else
   10349              :             {
   10350        19042 :               if (component_ref_p)
   10351         2473 :                 n->sym->comp_mark = 1;
   10352              :               else
   10353        16569 :                 n->sym->mark = 1;
   10354              :             }
   10355              :         }
   10356              : 
   10357              :   /* Detect specifically the case where we have "map(x) private(x)" and raise
   10358              :      an error.  If we have "...simd" combined directives though, the "private"
   10359              :      applies to the simd part, so this is permitted though.  */
   10360        43013 :   for (n = omp_clauses->lists[OMP_LIST_PRIVATE]; n; n = n->next)
   10361         9457 :     if (n->sym->mark
   10362            6 :         && n->sym->gen_mark
   10363            6 :         && !n->sym->dev_mark
   10364            6 :         && !n->sym->reduc_mark
   10365            5 :         && code->op != EXEC_OMP_TARGET_SIMD
   10366              :         && code->op != EXEC_OMP_TARGET_PARALLEL_DO_SIMD
   10367              :         && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
   10368              :         && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD)
   10369            1 :       gfc_error ("Symbol %qs present on multiple clauses at %L",
   10370              :                  n->sym->name, &n->where);
   10371              : 
   10372              :   gcc_assert (OMP_LIST_LASTPRIVATE == OMP_LIST_FIRSTPRIVATE + 1);
   10373       100668 :   for (list = OMP_LIST_FIRSTPRIVATE; list <= OMP_LIST_LASTPRIVATE;
   10374        67112 :        list = gfc_omp_list_type (list + 1))
   10375        71378 :     for (n = omp_clauses->lists[list]; n; n = n->next)
   10376         4266 :       if (n->sym->data_mark || n->sym->gen_mark || n->sym->dev_mark)
   10377              :         {
   10378            9 :           gfc_error ("Symbol %qs present on multiple clauses at %L",
   10379              :                      n->sym->name, &n->where);
   10380            9 :           n->sym->data_mark = n->sym->gen_mark = n->sym->dev_mark = 0;
   10381              :         }
   10382         4257 :       else if (n->sym->mark
   10383           18 :                && code->op != EXEC_OMP_TARGET_TEAMS
   10384              :                && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
   10385              :                && code->op != EXEC_OMP_TARGET_TEAMS_LOOP
   10386              :                && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
   10387              :                && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
   10388              :                && code->op != EXEC_OMP_TARGET_PARALLEL
   10389              :                && code->op != EXEC_OMP_TARGET_PARALLEL_DO
   10390              :                && code->op != EXEC_OMP_TARGET_PARALLEL_LOOP
   10391              :                && code->op != EXEC_OMP_TARGET_PARALLEL_DO_SIMD
   10392              :                && code->op != EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD)
   10393            7 :         gfc_error ("Symbol %qs present on both data and map clauses "
   10394              :                    "at %L", n->sym->name, &n->where);
   10395              : 
   10396        35477 :   for (n = omp_clauses->lists[OMP_LIST_FIRSTPRIVATE]; n; n = n->next)
   10397              :     {
   10398         1921 :       if (n->sym->data_mark || n->sym->gen_mark || n->sym->dev_mark)
   10399            7 :         gfc_error ("Symbol %qs present on multiple clauses at %L",
   10400              :                    n->sym->name, &n->where);
   10401              :       else
   10402         1914 :         n->sym->data_mark = 1;
   10403              :     }
   10404              : 
   10405              :   /* LASTPRIVATE clauses.  */
   10406        35901 :   for (n = omp_clauses->lists[OMP_LIST_LASTPRIVATE]; n; n = n->next)
   10407         2345 :     n->sym->data_mark = 0;
   10408        35901 :   for (n = omp_clauses->lists[OMP_LIST_LASTPRIVATE]; n; n = n->next)
   10409              :     {
   10410         2345 :       if (n->sym->data_mark || n->sym->gen_mark || n->sym->dev_mark)
   10411            0 :         gfc_error ("Symbol %qs present on multiple clauses at %L",
   10412              :                    n->sym->name, &n->where);
   10413              :       else
   10414         2345 :         n->sym->data_mark = 1;
   10415              :     }
   10416              : 
   10417              :   /* ALIGNED clauses.  */
   10418        33706 :   for (n = omp_clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next)
   10419          150 :     n->sym->mark = 0;
   10420              : 
   10421        33706 :   for (n = omp_clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next)
   10422              :     {
   10423          150 :       if (n->sym->mark)
   10424            0 :         gfc_error ("Symbol %qs present on multiple clauses at %L",
   10425              :                    n->sym->name, &n->where);
   10426              :       else
   10427          150 :         n->sym->mark = 1;
   10428              :     }
   10429              : 
   10430              :   /* FROM and TO clauses.  */
   10431        34426 :   for (n = omp_clauses->lists[OMP_LIST_TO]; n; n = n->next)
   10432          870 :     n->sym->mark = 0;
   10433        34683 :   for (n = omp_clauses->lists[OMP_LIST_FROM]; n; n = n->next)
   10434         1127 :     if (n->expr == NULL)
   10435         1109 :       n->sym->mark = 1;
   10436        34426 :   for (n = omp_clauses->lists[OMP_LIST_TO]; n; n = n->next)
   10437              :     {
   10438          870 :       if (n->expr == NULL && n->sym->mark)
   10439            0 :         gfc_error ("Symbol %qs present on both FROM and TO clauses at %L",
   10440              :                    n->sym->name, &n->where);
   10441              :       else
   10442          870 :         n->sym->mark = 1;
   10443              :     }
   10444              : 
   10445              :   /* OpenACC reductions.  */
   10446        33556 :   if (openacc)
   10447              :     {
   10448        15131 :       for (n = omp_clauses->lists[OMP_LIST_REDUCTION]; n; n = n->next)
   10449         2136 :         n->sym->mark = 0;
   10450        15131 :       for (n = omp_clauses->lists[OMP_LIST_REDUCTION]; n; n = n->next)
   10451              :         {
   10452         2136 :           if (n->sym->mark)
   10453            0 :             gfc_error ("Symbol %qs present on multiple clauses at %L",
   10454              :                        n->sym->name, &n->where);
   10455              :           else
   10456         2136 :             n->sym->mark = 1;
   10457              : 
   10458              :           /* OpenACC does not support reductions on arrays.  */
   10459         2136 :           if (n->sym->as)
   10460           71 :             gfc_error ("Array %qs is not permitted in reduction at %L",
   10461              :                        n->sym->name, &n->where);
   10462              :         }
   10463              :     }
   10464        33556 : }
   10465              : 
   10466              : /* OpenMP/OpenACC: Resolve the list item of a MAP, TO, FROM, CACHE, AFFINITY
   10467              :    or DEPEND clause.  */
   10468              : 
   10469              : static void
   10470        21211 : resolve_omp_clauses_aff_dep_map_cache (gfc_code *code,
   10471              :                                        gfc_omp_namelist *n,
   10472              :                                        const char *name,
   10473              :                                        enum gfc_omp_list_type list,
   10474              :                                        gfc_omp_clauses *omp_clauses,
   10475              :                                        bool openacc)
   10476              : {
   10477        21211 :   gcc_checking_assert (list == OMP_LIST_AFFINITY || list == OMP_LIST_DEPEND
   10478              :                        || list == OMP_LIST_MAP || list == OMP_LIST_TO
   10479              :                        || list == OMP_LIST_FROM || list == OMP_LIST_CACHE);
   10480              : 
   10481        21211 :   if (list != OMP_LIST_CACHE && n->u2.ns && !n->u2.ns->resolved)
   10482              :     {
   10483          109 :       n->u2.ns->resolved = 1;
   10484          109 :       for (gfc_symbol *sym = n->u2.ns->omp_affinity_iterators;
   10485          235 :            sym; sym = sym->tlink)
   10486              :         {
   10487          126 :           gfc_constructor *c;
   10488          126 :           c = gfc_constructor_first (sym->value->value.constructor);
   10489          126 :           if (!gfc_resolve_expr (c->expr)
   10490          126 :               || c->expr->ts.type != BT_INTEGER
   10491          250 :               || c->expr->rank != 0)
   10492            2 :             gfc_error ("Scalar integer expression for range begin expected "
   10493            2 :                        "at %L", &c->expr->where);
   10494          126 :           c = gfc_constructor_next (c);
   10495          126 :           if (!gfc_resolve_expr (c->expr)
   10496          126 :               || c->expr->ts.type != BT_INTEGER
   10497          250 :               || c->expr->rank != 0)
   10498            2 :             gfc_error ("Scalar integer expression for range end expected at %L",
   10499            2 :                        &c->expr->where);
   10500          126 :           c = gfc_constructor_next (c);
   10501          126 :           if (c && (!gfc_resolve_expr (c->expr)
   10502           16 :                     || c->expr->ts.type != BT_INTEGER
   10503           14 :                     || c->expr->rank != 0))
   10504            2 :             gfc_error ("Scalar integer expression for range step expected "
   10505            2 :                        "at %L", &c->expr->where);
   10506          124 :           else if (c
   10507           14 :                    && c->expr->expr_type == EXPR_CONSTANT
   10508           12 :                    && mpz_cmp_si (c->expr->value.integer, 0) == 0)
   10509            2 :             gfc_error ("Nonzero range step expected at %L", &c->expr->where);
   10510              :         }
   10511              :     }
   10512        21110 :   if (list == OMP_LIST_DEPEND)
   10513              :     {
   10514         1964 :       if (n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST
   10515              :           || n->u.depend_doacross_op == OMP_DOACROSS_SINK_FIRST
   10516         1964 :           || n->u.depend_doacross_op == OMP_DOACROSS_SINK)
   10517              :         {
   10518         1233 :           if (omp_clauses->doacross_source)
   10519              :             {
   10520            0 :               gfc_error ("Dependence-type SINK used together with SOURCE on "
   10521              :                          "the same construct at %L", &n->where);
   10522            0 :               omp_clauses->doacross_source = false;
   10523              :             }
   10524         1233 :           else if (n->expr)
   10525              :             {
   10526          571 :               if (!gfc_resolve_expr (n->expr)
   10527          571 :                   || n->expr->ts.type != BT_INTEGER
   10528         1142 :                   || n->expr->rank != 0)
   10529            0 :                 gfc_error ("SINK addend not a constant integer at %L",
   10530              :                            &n->where);
   10531              :             }
   10532         1233 :           if (n->sym == NULL
   10533            4 :               && (n->expr == NULL
   10534            3 :                   || mpz_cmp_si (n->expr->value.integer, -1) != 0))
   10535            2 :             gfc_error ("omp_cur_iteration at %L requires %<-1%> as "
   10536              :                        "logical offset", &n->where);
   10537              :           return;
   10538              :         }
   10539          731 :       if (n->u.depend_doacross_op == OMP_DEPEND_DEPOBJ
   10540           38 :           && !n->expr
   10541           22 :           && (n->sym->ts.type != BT_INTEGER
   10542           22 :               || n->sym->ts.kind != 2 * gfc_index_integer_kind
   10543           22 :               || n->sym->attr.dimension))
   10544            0 :         gfc_error ("Locator %qs at %L in DEPEND clause of depobj type shall be "
   10545              :                    "a scalar integer of OMP_DEPEND_KIND kind",
   10546              :                    n->sym->name, &n->where);
   10547          731 :       else if (n->u.depend_doacross_op == OMP_DEPEND_DEPOBJ
   10548           38 :                && n->expr
   10549          747 :                && (!gfc_resolve_expr (n->expr)
   10550           16 :                    || n->expr->ts.type != BT_INTEGER
   10551           16 :                    || n->expr->ts.kind != 2 * gfc_index_integer_kind
   10552           16 :                    || n->expr->rank != 0))
   10553            0 :         gfc_error ("Locator at %L in DEPEND clause of depobj type shall be a "
   10554            0 :                    "scalar integer of OMP_DEPEND_KIND kind", &n->expr->where);
   10555              :     }
   10556        19978 :   gfc_ref *lastref = NULL, *lastslice = NULL;
   10557        19978 :   bool resolved = false;
   10558        19978 :   if (n->expr)
   10559              :     {
   10560         6546 :       lastref = n->expr->ref;
   10561         6546 :       resolved = gfc_resolve_expr (n->expr);
   10562              : 
   10563              :       /* Look through component refs to find last array reference.  */
   10564         6546 :       if (resolved)
   10565              :         {
   10566        16585 :           for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
   10567        10057 :             if (ref->type == REF_COMPONENT
   10568              :                 || ref->type == REF_SUBSTRING
   10569        10057 :                 || ref->type == REF_INQUIRY)
   10570              :               lastref = ref;
   10571         6799 :             else if (ref->type == REF_ARRAY)
   10572              :               {
   10573        14290 :                 for (int i = 0; i < ref->u.ar.dimen; i++)
   10574         7491 :                   if (ref->u.ar.dimen_type[i] == DIMEN_RANGE)
   10575         6277 :                     lastslice = ref;
   10576              :                 lastref = ref;
   10577              :               }
   10578              : 
   10579              :           /* The "!$acc cache" directive allows rectangular subarrays to be
   10580              :               specified, with some restrictions on the form of bounds (not
   10581              :               implemented).  Only raise an error here if we're really sure the
   10582              :               array isn't contiguous.  An expression such as arr(-n:n,-n:n)
   10583              :               could be contiguous even if it looks like it may not be.  */
   10584         6528 :           if (code
   10585         6502 :               && code->op != EXEC_OACC_UPDATE
   10586         5720 :               && list != OMP_LIST_CACHE
   10587         5720 :               && list != OMP_LIST_DEPEND
   10588         5398 :               && !gfc_is_simply_contiguous (n->expr, false, true)
   10589         1517 :               && gfc_is_not_contiguous (n->expr)
   10590         6541 :               && !(lastslice && (lastslice->next
   10591            3 :                                  || lastslice->type != REF_ARRAY)))
   10592            3 :             gfc_error ("Array is not contiguous at %L", &n->where);
   10593              :         }
   10594              :     }
   10595        19978 :   if (list == OMP_LIST_MAP
   10596        17114 :       && (n->sym->attr.omp_groupprivate
   10597        17113 :           || n->sym->attr.omp_declare_target_local))
   10598            2 :     gfc_error ("%qs argument to MAP clause at %L must not be a device-local "
   10599              :                "variable, including GROUPPRIVATE", n->sym->name, &n->where);
   10600        19978 :   if (openacc
   10601        19978 :       && list == OMP_LIST_MAP
   10602         9571 :       && (n->u.map.op == OMP_MAP_ATTACH || n->u.map.op == OMP_MAP_DETACH))
   10603              :     {
   10604          117 :       symbol_attribute attr;
   10605          117 :       if (n->expr)
   10606           99 :         attr = gfc_expr_attr (n->expr);
   10607              :       else
   10608           18 :         attr = n->sym->attr;
   10609          117 :       if (!attr.pointer && !attr.allocatable)
   10610            7 :         gfc_error ("%qs clause argument must be ALLOCATABLE or a POINTER at %L",
   10611            7 :                    (n->u.map.op == OMP_MAP_ATTACH) ? "attach" : "detach",
   10612              :                    &n->where);
   10613              :     }
   10614        19978 :   if (lastref
   10615        13444 :       || (n->expr && (!resolved || n->expr->expr_type != EXPR_VARIABLE)))
   10616              :     {
   10617         6546 :       if (!lastslice && lastref && lastref->type == REF_SUBSTRING)
   10618           11 :         gfc_error ("Unexpected substring reference in %s clause at %L",
   10619              :                    name, &n->where);
   10620         6535 :       else if (!lastslice && lastref && lastref->type == REF_INQUIRY)
   10621              :         {
   10622           12 :           gcc_assert (lastref->u.i == INQUIRY_RE || lastref->u.i == INQUIRY_IM);
   10623           12 :           gfc_error ("Unexpected complex-parts designator reference in %s "
   10624              :                      "clause at %L", name, &n->where);
   10625              :         }
   10626         6523 :       else if (!resolved
   10627         6505 :                || n->expr->expr_type != EXPR_VARIABLE
   10628         6493 :                || (lastslice
   10629         5615 :                    && (lastslice->next || lastslice->type != REF_ARRAY)))
   10630           46 :         gfc_error ("%qs in %s clause at %L is not a proper array section",
   10631           46 :                        n->sym->name, name, &n->where);
   10632              :       else if (lastslice)
   10633              :         {
   10634              :           int i;
   10635              :           gfc_array_ref *ar = &lastslice->u.ar;
   10636        11873 :           for (i = 0; i < ar->dimen; i++)
   10637         6275 :             if (ar->stride[i] && code && code->op != EXEC_OACC_UPDATE)
   10638              :               {
   10639            1 :                 gfc_error ("Stride should not be specified for array section "
   10640              :                            "in %s clause at %L", name, &n->where);
   10641            1 :                 break;
   10642              :               }
   10643         6274 :             else if (ar->dimen_type[i] != DIMEN_ELEMENT
   10644         6274 :                          && ar->dimen_type[i] != DIMEN_RANGE)
   10645              :               {
   10646            0 :                 gfc_error ("%qs in %s clause at %L is not a proper array "
   10647            0 :                            "section", n->sym->name, name, &n->where);
   10648            0 :                 break;
   10649              :               }
   10650         6274 :             else if ((list == OMP_LIST_DEPEND || list == OMP_LIST_AFFINITY)
   10651          161 :                      && ar->start[i]
   10652          133 :                      && ar->start[i]->expr_type == EXPR_CONSTANT
   10653           97 :                      && ar->end[i]
   10654           72 :                      && ar->end[i]->expr_type == EXPR_CONSTANT
   10655           72 :                      && mpz_cmp (ar->start[i]->value.integer,
   10656           72 :                                  ar->end[i]->value.integer) > 0)
   10657              :               {
   10658            0 :                 gfc_error ("%qs in %s clause at %L is a zero size array "
   10659            0 :                            "section", n->sym->name,
   10660              :                            list == OMP_LIST_DEPEND ? "DEPEND" : "AFFINITY",
   10661              :                            &n->where);
   10662            0 :                 break;
   10663              :               }
   10664              :         }
   10665              :     }
   10666        13432 :   else if (openacc)
   10667              :     {
   10668         5915 :       if (list == OMP_LIST_MAP && n->u.map.op == OMP_MAP_FORCE_DEVICEPTR)
   10669           65 :         resolve_oacc_deviceptr_clause (n->sym, n->where, name);
   10670              :       else
   10671         5850 :         resolve_oacc_data_clauses (n->sym, n->where, name);
   10672              :     }
   10673         7517 :   else if (list != OMP_LIST_DEPEND
   10674         7023 :                && n->sym->as
   10675         3443 :                && n->sym->as->type == AS_ASSUMED_SIZE)
   10676            5 :     gfc_error ("Assumed size array %qs in %s clause at %L",
   10677              :                    n->sym->name, name, &n->where);
   10678        19978 :   if (code && list == OMP_LIST_MAP && !openacc)
   10679         7498 :     switch (code->op)
   10680              :       {
   10681         6217 :       case EXEC_OMP_TARGET:
   10682         6217 :       case EXEC_OMP_TARGET_PARALLEL:
   10683         6217 :       case EXEC_OMP_TARGET_PARALLEL_DO:
   10684         6217 :       case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   10685         6217 :       case EXEC_OMP_TARGET_PARALLEL_LOOP:
   10686         6217 :       case EXEC_OMP_TARGET_SIMD:
   10687         6217 :       case EXEC_OMP_TARGET_TEAMS:
   10688         6217 :       case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   10689         6217 :       case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   10690         6217 :       case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   10691         6217 :       case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   10692         6217 :       case EXEC_OMP_TARGET_TEAMS_LOOP:
   10693         6217 :       case EXEC_OMP_TARGET_DATA:
   10694         6217 :         switch (n->u.map.op)
   10695              :           {
   10696              :           case OMP_MAP_TO:
   10697              :           case OMP_MAP_ALWAYS_TO:
   10698              :           case OMP_MAP_PRESENT_TO:
   10699              :           case OMP_MAP_ALWAYS_PRESENT_TO:
   10700              :           case OMP_MAP_FROM:
   10701              :           case OMP_MAP_ALWAYS_FROM:
   10702              :           case OMP_MAP_PRESENT_FROM:
   10703              :           case OMP_MAP_ALWAYS_PRESENT_FROM:
   10704              :           case OMP_MAP_TOFROM:
   10705              :           case OMP_MAP_ALWAYS_TOFROM:
   10706              :           case OMP_MAP_PRESENT_TOFROM:
   10707              :           case OMP_MAP_ALWAYS_PRESENT_TOFROM:
   10708              :           case OMP_MAP_ALLOC:
   10709              :           case OMP_MAP_PRESENT_ALLOC:
   10710              :             break;
   10711            2 :           default:
   10712            2 :             gfc_error ("TARGET%s with map-type other than TO, "
   10713              :                        "FROM, TOFROM, or ALLOC on MAP clause "
   10714              :                        "at %L",
   10715              :                        code->op == EXEC_OMP_TARGET_DATA
   10716              :                        ? " DATA" : "", &n->where);
   10717            2 :             break;
   10718              :           }
   10719              :         break;
   10720          701 :       case EXEC_OMP_TARGET_ENTER_DATA:
   10721          701 :         switch (n->u.map.op)
   10722              :           {
   10723              :           case OMP_MAP_TO:
   10724              :           case OMP_MAP_ALWAYS_TO:
   10725              :           case OMP_MAP_PRESENT_TO:
   10726              :           case OMP_MAP_ALWAYS_PRESENT_TO:
   10727              :           case OMP_MAP_ALLOC:
   10728              :           case OMP_MAP_PRESENT_ALLOC:
   10729              :             break;
   10730          181 :           case OMP_MAP_TOFROM:
   10731          181 :             n->u.map.op = OMP_MAP_TO;
   10732          181 :             break;
   10733            3 :           case OMP_MAP_ALWAYS_TOFROM:
   10734            3 :             n->u.map.op = OMP_MAP_ALWAYS_TO;
   10735            3 :             break;
   10736            2 :           case OMP_MAP_PRESENT_TOFROM:
   10737            2 :             n->u.map.op = OMP_MAP_PRESENT_TO;
   10738            2 :             break;
   10739            2 :           case OMP_MAP_ALWAYS_PRESENT_TOFROM:
   10740            2 :             n->u.map.op = OMP_MAP_ALWAYS_PRESENT_TO;
   10741            2 :             break;
   10742            2 :           default:
   10743            2 :             gfc_error ("TARGET ENTER DATA with map-type other "
   10744              :                        "than TO, TOFROM or ALLOC on MAP clause "
   10745              :                        "at %L", &n->where);
   10746            2 :             break;
   10747              :           }
   10748              :         break;
   10749          580 :       case EXEC_OMP_TARGET_EXIT_DATA:
   10750          580 :         switch (n->u.map.op)
   10751              :           {
   10752              :           case OMP_MAP_FROM:
   10753              :           case OMP_MAP_ALWAYS_FROM:
   10754              :           case OMP_MAP_PRESENT_FROM:
   10755              :           case OMP_MAP_ALWAYS_PRESENT_FROM:
   10756              :           case OMP_MAP_RELEASE:
   10757              :           case OMP_MAP_DELETE:
   10758              :             break;
   10759          134 :           case OMP_MAP_TOFROM:
   10760          134 :             n->u.map.op = OMP_MAP_FROM;
   10761          134 :             break;
   10762            1 :           case OMP_MAP_ALWAYS_TOFROM:
   10763            1 :             n->u.map.op = OMP_MAP_ALWAYS_FROM;
   10764            1 :             break;
   10765            0 :           case OMP_MAP_PRESENT_TOFROM:
   10766            0 :             n->u.map.op = OMP_MAP_PRESENT_FROM;
   10767            0 :             break;
   10768            0 :           case OMP_MAP_ALWAYS_PRESENT_TOFROM:
   10769            0 :             n->u.map.op = OMP_MAP_ALWAYS_PRESENT_FROM;
   10770            0 :             break;
   10771            2 :           default:
   10772            2 :             gfc_error ("TARGET EXIT DATA with map-type other "
   10773              :                        "than FROM, TOFROM, RELEASE, or DELETE on "
   10774              :                        "MAP clause at %L", &n->where);
   10775            2 :             break;
   10776              :           }
   10777              :         break;
   10778              :       default:
   10779              :         break;
   10780              :       }
   10781        19978 :   if (list == OMP_LIST_MAP || list == OMP_LIST_TO || list == OMP_LIST_FROM)
   10782              :     {
   10783        19111 :       gfc_typespec *ts = n->expr ? &n->expr->ts : &n->sym->ts;
   10784              : 
   10785        19111 :       if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
   10786              :         {
   10787           10 :           const char *mapper_id = (n->u3.udm
   10788         1003 :                                    ? n->u3.udm->requested_mapper_id : "");
   10789         1003 :           gfc_omp_udm *udm = gfc_find_omp_udm (gfc_current_ns, mapper_id, ts);
   10790         1003 :           if (mapper_id[0] != '\0' && !udm)
   10791            1 :             gfc_error ("User-defined mapper %qs not found at %L",
   10792              :                        mapper_id, &n->where);
   10793          998 :           else if (udm)
   10794              :             {
   10795           27 :               if (!n->u3.udm)
   10796              :                 {
   10797           18 :                   gcc_assert (mapper_id[0] == '\0');
   10798           18 :                   n->u3.udm = gfc_get_omp_namelist_udm ();
   10799           18 :                   n->u3.udm->requested_mapper_id = mapper_id;
   10800              :                 }
   10801           27 :               n->u3.udm->resolved_udm = udm;
   10802              :             }
   10803              :         }
   10804              :     }
   10805              : 
   10806        19978 :   if (list != OMP_LIST_DEPEND)
   10807              :     {
   10808        19247 :       n->sym->attr.referenced = 1;
   10809        19247 :       if (n->sym->attr.threadprivate)
   10810            1 :         gfc_error ("THREADPRIVATE object %qs in %s clause at %L",
   10811              :                    n->sym->name, name, &n->where);
   10812        19247 :       if (n->sym->attr.cray_pointee)
   10813           14 :         gfc_error ("Cray pointee %qs in %s clause at %L",
   10814              :                    n->sym->name, name, &n->where);
   10815              :     }
   10816              : }
   10817              : 
   10818              : /* OpenMP directive resolving routines.  */
   10819              : 
   10820              : static void
   10821        33556 : resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
   10822              :                      gfc_namespace *ns, bool openacc = false)
   10823              : {
   10824        33556 :   gfc_omp_namelist *n, *last;
   10825        33556 :   gfc_expr_list *el;
   10826        33556 :   enum gfc_omp_list_type list;
   10827        33556 :   int ifc;
   10828        33556 :   bool if_without_mod = false;
   10829        33556 :   gfc_omp_linear_op linear_op = OMP_LINEAR_DEFAULT;
   10830        33556 :   static const char *clause_names[]
   10831              :     = { "PRIVATE", "FIRSTPRIVATE", "LASTPRIVATE", "COPYPRIVATE", "SHARED",
   10832              :         "COPYIN", "UNIFORM", "AFFINITY", "ALIGNED", "LINEAR", "DEPEND", "MAP",
   10833              :         "TO", "FROM", "INCLUSIVE", "EXCLUSIVE",
   10834              :         "REDUCTION", "REDUCTION" /*inscan*/, "REDUCTION" /*task*/,
   10835              :         "IN_REDUCTION", "TASK_REDUCTION",
   10836              :         "DEVICE_RESIDENT", "LINK", "LOCAL", "USE_DEVICE",
   10837              :         "CACHE", "IS_DEVICE_PTR", "USE_DEVICE_PTR", "USE_DEVICE_ADDR",
   10838              :         "NONTEMPORAL", "ALLOCATE", "HAS_DEVICE_ADDR", "ENTER",
   10839              :         "USES_ALLOCATORS", "INIT", "USE", "DESTROY", "INTEROP", "ADJUST_ARGS" };
   10840        33556 :   STATIC_ASSERT (ARRAY_SIZE (clause_names) == OMP_LIST_NUM);
   10841              : 
   10842        33556 :   if (omp_clauses == NULL)
   10843              :     return;
   10844              : 
   10845        33556 :   if (ns == NULL)
   10846        33071 :     ns = gfc_current_ns;
   10847              : 
   10848        33556 :   check_omp_clauses_dupl_syms (code, omp_clauses, openacc);
   10849              : 
   10850        33556 :   if (omp_clauses->orderedc && omp_clauses->orderedc < omp_clauses->collapse)
   10851            0 :     gfc_error ("ORDERED clause parameter is less than COLLAPSE at %L",
   10852              :                &code->loc);
   10853        33556 :   if (omp_clauses->order_concurrent && omp_clauses->ordered)
   10854            4 :     gfc_error ("ORDER clause must not be used together with ORDERED at %L",
   10855              :                &code->loc);
   10856        33556 :   if (omp_clauses->if_expr)
   10857              :     {
   10858         1301 :       gfc_expr *expr = omp_clauses->if_expr;
   10859         1301 :       if (!gfc_resolve_expr (expr)
   10860         1301 :           || expr->ts.type != BT_LOGICAL || expr->rank != 0)
   10861           16 :         gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
   10862              :                    &expr->where);
   10863              :       if_without_mod = true;
   10864              :     }
   10865       369116 :   for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
   10866       335560 :     if (omp_clauses->if_exprs[ifc])
   10867              :       {
   10868          141 :         gfc_expr *expr = omp_clauses->if_exprs[ifc];
   10869          141 :         bool ok = true;
   10870          141 :         if (!gfc_resolve_expr (expr)
   10871          141 :             || expr->ts.type != BT_LOGICAL || expr->rank != 0)
   10872            0 :           gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
   10873              :                      &expr->where);
   10874          141 :         else if (if_without_mod)
   10875              :           {
   10876            1 :             gfc_error ("IF clause without modifier at %L used together with "
   10877              :                        "IF clauses with modifiers",
   10878            1 :                        &omp_clauses->if_expr->where);
   10879            1 :             if_without_mod = false;
   10880              :           }
   10881              :         else
   10882          140 :           switch (code->op)
   10883              :             {
   10884           13 :             case EXEC_OMP_CANCEL:
   10885           13 :               ok = ifc == OMP_IF_CANCEL;
   10886           13 :               break;
   10887              : 
   10888           16 :             case EXEC_OMP_PARALLEL:
   10889           16 :             case EXEC_OMP_PARALLEL_DO:
   10890           16 :             case EXEC_OMP_PARALLEL_LOOP:
   10891           16 :             case EXEC_OMP_PARALLEL_MASKED:
   10892           16 :             case EXEC_OMP_PARALLEL_MASTER:
   10893           16 :             case EXEC_OMP_PARALLEL_SECTIONS:
   10894           16 :             case EXEC_OMP_PARALLEL_WORKSHARE:
   10895           16 :             case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   10896           16 :             case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   10897           16 :               ok = ifc == OMP_IF_PARALLEL;
   10898           16 :               break;
   10899              : 
   10900           28 :             case EXEC_OMP_PARALLEL_DO_SIMD:
   10901           28 :             case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
   10902           28 :             case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   10903           28 :               ok = ifc == OMP_IF_PARALLEL || ifc == OMP_IF_SIMD;
   10904           28 :               break;
   10905              : 
   10906            8 :             case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
   10907            8 :             case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
   10908            8 :               ok = ifc == OMP_IF_PARALLEL || ifc == OMP_IF_TASKLOOP;
   10909            8 :               break;
   10910              : 
   10911           12 :             case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
   10912           12 :             case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
   10913           12 :               ok = (ifc == OMP_IF_PARALLEL
   10914           12 :                     || ifc == OMP_IF_TASKLOOP
   10915              :                     || ifc == OMP_IF_SIMD);
   10916              :               break;
   10917              : 
   10918            0 :             case EXEC_OMP_SIMD:
   10919            0 :             case EXEC_OMP_DO_SIMD:
   10920            0 :             case EXEC_OMP_DISTRIBUTE_SIMD:
   10921            0 :             case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
   10922            0 :               ok = ifc == OMP_IF_SIMD;
   10923            0 :               break;
   10924              : 
   10925            1 :             case EXEC_OMP_TASK:
   10926            1 :               ok = ifc == OMP_IF_TASK;
   10927            1 :               break;
   10928              : 
   10929            5 :             case EXEC_OMP_TASKLOOP:
   10930            5 :             case EXEC_OMP_MASKED_TASKLOOP:
   10931            5 :             case EXEC_OMP_MASTER_TASKLOOP:
   10932            5 :               ok = ifc == OMP_IF_TASKLOOP;
   10933            5 :               break;
   10934              : 
   10935           20 :             case EXEC_OMP_TASKLOOP_SIMD:
   10936           20 :             case EXEC_OMP_MASKED_TASKLOOP_SIMD:
   10937           20 :             case EXEC_OMP_MASTER_TASKLOOP_SIMD:
   10938           20 :               ok = ifc == OMP_IF_TASKLOOP || ifc == OMP_IF_SIMD;
   10939           20 :               break;
   10940              : 
   10941            5 :             case EXEC_OMP_TARGET:
   10942            5 :             case EXEC_OMP_TARGET_TEAMS:
   10943            5 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   10944            5 :             case EXEC_OMP_TARGET_TEAMS_LOOP:
   10945            5 :               ok = ifc == OMP_IF_TARGET;
   10946            5 :               break;
   10947              : 
   10948            4 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   10949            4 :             case EXEC_OMP_TARGET_SIMD:
   10950            4 :               ok = ifc == OMP_IF_TARGET || ifc == OMP_IF_SIMD;
   10951            4 :               break;
   10952              : 
   10953            2 :             case EXEC_OMP_TARGET_DATA:
   10954            2 :               ok = ifc == OMP_IF_TARGET_DATA;
   10955            2 :               break;
   10956              : 
   10957            2 :             case EXEC_OMP_TARGET_UPDATE:
   10958            2 :               ok = ifc == OMP_IF_TARGET_UPDATE;
   10959            2 :               break;
   10960              : 
   10961            2 :             case EXEC_OMP_TARGET_ENTER_DATA:
   10962            2 :               ok = ifc == OMP_IF_TARGET_ENTER_DATA;
   10963            2 :               break;
   10964              : 
   10965            2 :             case EXEC_OMP_TARGET_EXIT_DATA:
   10966            2 :               ok = ifc == OMP_IF_TARGET_EXIT_DATA;
   10967            2 :               break;
   10968              : 
   10969           10 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   10970           10 :             case EXEC_OMP_TARGET_PARALLEL:
   10971           10 :             case EXEC_OMP_TARGET_PARALLEL_DO:
   10972           10 :             case EXEC_OMP_TARGET_PARALLEL_LOOP:
   10973           10 :               ok = ifc == OMP_IF_TARGET || ifc == OMP_IF_PARALLEL;
   10974           10 :               break;
   10975              : 
   10976           10 :             case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   10977           10 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   10978           10 :               ok = (ifc == OMP_IF_TARGET
   10979           10 :                     || ifc == OMP_IF_PARALLEL
   10980              :                     || ifc == OMP_IF_SIMD);
   10981              :               break;
   10982              : 
   10983              :             default:
   10984              :               ok = false;
   10985              :               break;
   10986              :           }
   10987          119 :         if (!ok)
   10988              :           {
   10989            2 :             static const char *ifs[] = {
   10990              :               "CANCEL",
   10991              :               "PARALLEL",
   10992              :               "SIMD",
   10993              :               "TASK",
   10994              :               "TASKLOOP",
   10995              :               "TARGET",
   10996              :               "TARGET DATA",
   10997              :               "TARGET UPDATE",
   10998              :               "TARGET ENTER DATA",
   10999              :               "TARGET EXIT DATA"
   11000              :             };
   11001            2 :             gfc_error ("IF clause modifier %s at %L not appropriate for "
   11002              :                        "the current OpenMP construct", ifs[ifc], &expr->where);
   11003              :           }
   11004              :       }
   11005              : 
   11006        33556 :   if (omp_clauses->self_expr)
   11007              :     {
   11008          177 :       gfc_expr *expr = omp_clauses->self_expr;
   11009          177 :       if (!gfc_resolve_expr (expr)
   11010          177 :           || expr->ts.type != BT_LOGICAL || expr->rank != 0)
   11011            6 :         gfc_error ("SELF clause at %L requires a scalar LOGICAL expression",
   11012              :                    &expr->where);
   11013              :     }
   11014              : 
   11015        33556 :   if (omp_clauses->final_expr)
   11016              :     {
   11017           64 :       gfc_expr *expr = omp_clauses->final_expr;
   11018           64 :       if (!gfc_resolve_expr (expr)
   11019           64 :           || expr->ts.type != BT_LOGICAL || expr->rank != 0)
   11020            0 :         gfc_error ("FINAL clause at %L requires a scalar LOGICAL expression",
   11021              :                    &expr->where);
   11022              :     }
   11023        33556 :   if (omp_clauses->novariants)
   11024              :     {
   11025            9 :       gfc_expr *expr = omp_clauses->novariants;
   11026           18 :       if (!gfc_resolve_expr (expr) || expr->ts.type != BT_LOGICAL
   11027           17 :           || expr->rank != 0)
   11028            1 :         gfc_error (
   11029              :           "NOVARIANTS clause at %L requires a scalar LOGICAL expression",
   11030              :           &expr->where);
   11031        33556 :       if_without_mod = true;
   11032              :     }
   11033        33556 :   if (omp_clauses->nocontext)
   11034              :     {
   11035           12 :       gfc_expr *expr = omp_clauses->nocontext;
   11036           24 :       if (!gfc_resolve_expr (expr) || expr->ts.type != BT_LOGICAL
   11037           23 :           || expr->rank != 0)
   11038            1 :         gfc_error (
   11039              :           "NOCONTEXT clause at %L requires a scalar LOGICAL expression",
   11040              :           &expr->where);
   11041        33556 :       if_without_mod = true;
   11042              :     }
   11043              : 
   11044        34572 :   for (el = omp_clauses->num_threads_list; el; el = el->next)
   11045         1016 :     resolve_positive_int_expr (el->expr, "NUM_THREADS", true);
   11046              : 
   11047        33556 :   if (omp_clauses->dyn_groupprivate)
   11048           43 :     resolve_nonnegative_int_expr (omp_clauses->dyn_groupprivate,
   11049              :                                   "DYN_GROUPPRIVATE", true);
   11050        33556 :   if (omp_clauses->chunk_size)
   11051              :     {
   11052          510 :       gfc_expr *expr = omp_clauses->chunk_size;
   11053          510 :       if (!gfc_resolve_expr (expr)
   11054          510 :           || expr->ts.type != BT_INTEGER || expr->rank != 0)
   11055            0 :         gfc_error ("SCHEDULE clause's chunk_size at %L requires "
   11056              :                    "a scalar INTEGER expression", &expr->where);
   11057          510 :       else if (expr->expr_type == EXPR_CONSTANT
   11058              :                && expr->ts.type == BT_INTEGER
   11059          485 :                && mpz_sgn (expr->value.integer) <= 0)
   11060            2 :         gfc_warning (OPT_Wopenmp, "INTEGER expression of SCHEDULE clause's "
   11061              :                      "chunk_size at %L must be positive", &expr->where);
   11062              :     }
   11063        33556 :   if (omp_clauses->sched_kind != OMP_SCHED_NONE
   11064          891 :       && omp_clauses->sched_nonmonotonic)
   11065              :     {
   11066           34 :       if (omp_clauses->sched_monotonic)
   11067            2 :         gfc_error ("Both MONOTONIC and NONMONOTONIC schedule modifiers "
   11068              :                    "specified at %L", &code->loc);
   11069           32 :       else if (omp_clauses->ordered)
   11070            4 :         gfc_error ("NONMONOTONIC schedule modifier specified with ORDERED "
   11071              :                    "clause at %L", &code->loc);
   11072              :     }
   11073              : 
   11074        33556 :   if (omp_clauses->depobj
   11075        33556 :       && (!gfc_resolve_expr (omp_clauses->depobj)
   11076          118 :           || omp_clauses->depobj->ts.type != BT_INTEGER
   11077          117 :           || omp_clauses->depobj->ts.kind != 2 * gfc_index_integer_kind
   11078          116 :           || omp_clauses->depobj->rank != 0))
   11079            4 :     gfc_error ("DEPOBJ in DEPOBJ construct at %L shall be a scalar integer "
   11080            4 :                "of OMP_DEPEND_KIND kind", &omp_clauses->depobj->where);
   11081              : 
   11082              :   /* Check that list items are variables.  */
   11083      1342240 :   for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   11084      1308684 :        list = gfc_omp_list_type (list + 1))
   11085      1354928 :     for (n = omp_clauses->lists[list]; n; n = n->next)
   11086              :       {
   11087        46244 :         if (!n->sym)  /* omp_all_memory.  */
   11088           47 :           continue;
   11089        46197 :         if (n->sym->attr.flavor == FL_VARIABLE
   11090          277 :             || n->sym->attr.proc_pointer
   11091          236 :             || (!code
   11092            0 :                 && !ns->omp_udm_ns
   11093            0 :                 && (!n->sym->attr.dummy || n->sym->ns != ns)))
   11094              :           {
   11095        45961 :             if (!code
   11096          322 :                 && !ns->omp_udm_ns
   11097          277 :                 && (!n->sym->attr.dummy || n->sym->ns != ns))
   11098            0 :               gfc_error ("Variable %qs is not a dummy argument at %L",
   11099              :                          n->sym->name, &n->where);
   11100        45961 :             continue;
   11101              :           }
   11102          236 :         if (n->sym->attr.flavor == FL_PROCEDURE
   11103          153 :             && n->sym->result == n->sym
   11104          138 :             && n->sym->attr.function)
   11105              :           {
   11106          138 :             if (ns->proc_name == n->sym
   11107           44 :                 || (ns->parent && ns->parent->proc_name == n->sym))
   11108          101 :               continue;
   11109           37 :             if (ns->proc_name->attr.entry_master)
   11110              :               {
   11111           32 :                 gfc_entry_list *el = ns->entries;
   11112           51 :                 for (; el; el = el->next)
   11113           51 :                   if (el->sym == n->sym)
   11114              :                     break;
   11115           32 :                 if (el)
   11116           32 :                   continue;
   11117              :               }
   11118            5 :             if (ns->parent
   11119            3 :                 && ns->parent->proc_name->attr.entry_master)
   11120              :               {
   11121            2 :                 gfc_entry_list *el = ns->parent->entries;
   11122            3 :                 for (; el; el = el->next)
   11123            3 :                   if (el->sym == n->sym)
   11124              :                     break;
   11125            2 :                 if (el)
   11126            2 :                   continue;
   11127              :               }
   11128              :           }
   11129          101 :         if (list == OMP_LIST_MAP
   11130           18 :             && n->sym->attr.flavor == FL_PARAMETER)
   11131              :           {
   11132              :             /* OpenACC since 3.4 permits for Fortran named constants, but
   11133              :                permits removing then as optimization is not needed and such
   11134              :                ignore them. Likewise below for FIRSTPRIVATE.  */
   11135           12 :             if (openacc)
   11136           10 :               gfc_warning (OPT_Wsurprising, "Clause for object %qs at %L is "
   11137              :                            "ignored as parameters need not be copied",
   11138              :                            n->sym->name, &n->where);
   11139              :             else
   11140            2 :               gfc_error ("Object %qs is not a variable at %L; parameters"
   11141              :                          " cannot be and need not be mapped", n->sym->name,
   11142              :                          &n->where);
   11143              :           }
   11144           89 :         else if (openacc && n->sym->attr.flavor == FL_PARAMETER)
   11145            9 :           gfc_warning (OPT_Wsurprising, "Clause for object %qs at %L is ignored"
   11146              :                        " as it is a parameter", n->sym->name, &n->where);
   11147           80 :         else if (list != OMP_LIST_USES_ALLOCATORS)
   11148           30 :           gfc_error ("Object %qs is not a variable at %L", n->sym->name,
   11149              :                      &n->where);
   11150              :       }
   11151              : 
   11152        33556 :   if (omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN])
   11153              :     {
   11154           69 :       locus *loc = &omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]->where;
   11155           69 :       if (code->op != EXEC_OMP_DO
   11156              :           && code->op != EXEC_OMP_SIMD
   11157              :           && code->op != EXEC_OMP_DO_SIMD
   11158              :           && code->op != EXEC_OMP_PARALLEL_DO
   11159              :           && code->op != EXEC_OMP_PARALLEL_DO_SIMD)
   11160           23 :         gfc_error ("%<inscan%> REDUCTION clause on construct other than DO, "
   11161              :                    "SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD at %L",
   11162              :                    loc);
   11163           69 :       if (omp_clauses->ordered)
   11164            2 :         gfc_error ("ORDERED clause specified together with %<inscan%> "
   11165              :                    "REDUCTION clause at %L", loc);
   11166           69 :       if (omp_clauses->sched_kind != OMP_SCHED_NONE)
   11167            3 :         gfc_error ("SCHEDULE clause specified together with %<inscan%> "
   11168              :                    "REDUCTION clause at %L", loc);
   11169              :     }
   11170              : 
   11171        33556 :   if (code
   11172        33274 :       && code->op == EXEC_OMP_INTEROP
   11173           63 :       && omp_clauses->lists[OMP_LIST_DEPEND])
   11174              :     {
   11175           12 :       if (!omp_clauses->lists[OMP_LIST_INIT]
   11176            5 :           && !omp_clauses->lists[OMP_LIST_USE]
   11177            1 :           && !omp_clauses->lists[OMP_LIST_DESTROY])
   11178              :         {
   11179            1 :           gfc_error ("DEPEND clause at %L requires action clause with "
   11180              :                      "%<targetsync%> interop-type",
   11181              :                      &omp_clauses->lists[OMP_LIST_DEPEND]->where);
   11182              :         }
   11183           22 :       for (n = omp_clauses->lists[OMP_LIST_INIT]; n; n = n->next)
   11184           12 :         if (!n->u.init.targetsync)
   11185              :           {
   11186            2 :             gfc_error ("DEPEND clause at %L requires %<targetsync%> "
   11187              :                        "interop-type, lacking it for %qs at %L",
   11188            2 :                        &omp_clauses->lists[OMP_LIST_DEPEND]->where,
   11189            2 :                        n->sym->name, &n->where);
   11190            2 :             break;
   11191              :           }
   11192              :     }
   11193        33274 :   if (code && (code->op == EXEC_OMP_INTEROP || code->op == EXEC_OMP_DISPATCH))
   11194         1085 :     for (list = OMP_LIST_INIT; list <= OMP_LIST_INTEROP;
   11195          868 :          list = gfc_omp_list_type (list + 1))
   11196         1123 :       for (n = omp_clauses->lists[list]; n; n = n->next)
   11197              :         {
   11198          255 :           if (n->sym->ts.type != BT_INTEGER
   11199          252 :               || n->sym->ts.kind != gfc_index_integer_kind
   11200          248 :               || n->sym->attr.dimension
   11201          243 :               || n->sym->attr.flavor != FL_VARIABLE)
   11202           16 :             gfc_error ("%qs at %L in %qs clause must be a scalar integer "
   11203              :                        "variable of %<omp_interop_kind%> kind", n->sym->name,
   11204              :                        &n->where, clause_names[list]);
   11205          255 :           if (list != OMP_LIST_USE && list != OMP_LIST_INTEROP
   11206          109 :               && n->sym->attr.intent == INTENT_IN)
   11207            2 :             gfc_error ("%qs at %L in %qs clause must be definable",
   11208              :                        n->sym->name, &n->where, clause_names[list]);
   11209              :         }
   11210              : 
   11211        33556 :   resolve_omp_allocate_clauses (code, omp_clauses, ns);
   11212              : 
   11213        33556 :   bool has_inscan = false, has_notinscan = false;
   11214      1375796 :   for (enum gfc_omp_list_type list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   11215      1308684 :        list = gfc_omp_list_type (list + 1))
   11216      1308684 :     if ((n = omp_clauses->lists[list]) != NULL)
   11217              :       {
   11218        29489 :         const char *name = clause_names[list];
   11219              : 
   11220        29489 :         switch (list)
   11221              :           {
   11222              :           case OMP_LIST_COPYIN:
   11223          267 :             for (; n != NULL; n = n->next)
   11224              :               {
   11225          170 :                 if (!n->sym->attr.threadprivate)
   11226            0 :                   gfc_error ("Non-THREADPRIVATE object %qs in COPYIN clause"
   11227              :                              " at %L", n->sym->name, &n->where);
   11228              :               }
   11229              :             break;
   11230           83 :           case OMP_LIST_COPYPRIVATE:
   11231           83 :             if (omp_clauses->nowait)
   11232            6 :               gfc_error ("NOWAIT clause must not be used with COPYPRIVATE "
   11233              :                          "clause at %L", &n->where);
   11234          376 :             for (; n != NULL; n = n->next)
   11235              :               {
   11236          293 :                 if (n->sym->as && n->sym->as->type == AS_ASSUMED_SIZE)
   11237            0 :                   gfc_error ("Assumed size array %qs in COPYPRIVATE clause "
   11238              :                              "at %L", n->sym->name, &n->where);
   11239          293 :                 if (n->sym->attr.pointer && n->sym->attr.intent == INTENT_IN)
   11240            1 :                   gfc_error ("INTENT(IN) POINTER %qs in COPYPRIVATE clause "
   11241              :                              "at %L", n->sym->name, &n->where);
   11242              :               }
   11243              :             break;
   11244              :           case OMP_LIST_SHARED:
   11245         2624 :             for (; n != NULL; n = n->next)
   11246              :               {
   11247         1655 :                 if (n->sym->attr.threadprivate)
   11248            0 :                   gfc_error ("THREADPRIVATE object %qs in SHARED clause at "
   11249              :                              "%L", n->sym->name, &n->where);
   11250         1655 :                 if (n->sym->attr.cray_pointee)
   11251            1 :                   gfc_error ("Cray pointee %qs in SHARED clause at %L",
   11252              :                             n->sym->name, &n->where);
   11253         1655 :                 if (n->sym->attr.associate_var)
   11254            8 :                   gfc_error ("Associate name %qs in SHARED clause at %L",
   11255            8 :                              n->sym->attr.select_type_temporary
   11256            4 :                              ? n->sym->assoc->target->symtree->n.sym->name
   11257              :                              : n->sym->name, &n->where);
   11258         1655 :                 if (omp_clauses->detach
   11259            1 :                     && n->sym == omp_clauses->detach->symtree->n.sym)
   11260            1 :                   gfc_error ("DETACH event handle %qs in SHARED clause at %L",
   11261              :                              n->sym->name, &n->where);
   11262              :               }
   11263              :             break;
   11264              :           case OMP_LIST_ALIGNED:
   11265          256 :             for (; n != NULL; n = n->next)
   11266              :               {
   11267          150 :                 if (!n->sym->attr.pointer
   11268           45 :                     && !n->sym->attr.allocatable
   11269           30 :                     && !n->sym->attr.cray_pointer
   11270           18 :                     && (n->sym->ts.type != BT_DERIVED
   11271           18 :                         || (n->sym->ts.u.derived->from_intmod
   11272              :                             != INTMOD_ISO_C_BINDING)
   11273           18 :                         || (n->sym->ts.u.derived->intmod_sym_id
   11274              :                             != ISOCBINDING_PTR)))
   11275            0 :                   gfc_error ("%qs in ALIGNED clause must be POINTER, "
   11276              :                              "ALLOCATABLE, Cray pointer or C_PTR at %L",
   11277              :                              n->sym->name, &n->where);
   11278          150 :                 else if (n->expr)
   11279              :                   {
   11280          147 :                     if (!gfc_resolve_expr (n->expr)
   11281          147 :                         || n->expr->ts.type != BT_INTEGER
   11282          146 :                         || n->expr->rank != 0
   11283          146 :                         || n->expr->expr_type != EXPR_CONSTANT
   11284          292 :                         || mpz_sgn (n->expr->value.integer) <= 0)
   11285            4 :                       gfc_error ("%qs in ALIGNED clause at %L requires a scalar"
   11286              :                                  " positive constant integer alignment "
   11287            4 :                                  "expression", n->sym->name, &n->where);
   11288              :                   }
   11289              :               }
   11290              :             break;
   11291              :           case OMP_LIST_AFFINITY:
   11292              :           case OMP_LIST_DEPEND:
   11293              :           case OMP_LIST_MAP:
   11294              :           case OMP_LIST_TO:
   11295              :           case OMP_LIST_FROM:
   11296              :           case OMP_LIST_CACHE:
   11297        33576 :             for (; n != NULL; n = n->next)
   11298        21211 :               resolve_omp_clauses_aff_dep_map_cache (code, n, name, list,
   11299              :                                                      omp_clauses, openacc);
   11300              :             break;
   11301              :           case OMP_LIST_IS_DEVICE_PTR:
   11302              :             last = NULL;
   11303          377 :             for (n = omp_clauses->lists[list]; n != NULL; )
   11304              :               {
   11305          257 :                 if ((n->sym->ts.type != BT_DERIVED
   11306           71 :                      || !n->sym->ts.u.derived->ts.is_iso_c
   11307           71 :                      || (n->sym->ts.u.derived->intmod_sym_id
   11308              :                          != ISOCBINDING_PTR))
   11309          187 :                     && code->op == EXEC_OMP_DISPATCH)
   11310              :                   /* Non-TARGET (i.e. DISPATCH) requires a C_PTR.  */
   11311            3 :                   gfc_error ("List item %qs in %s clause at %L must be of "
   11312              :                              "TYPE(C_PTR)", n->sym->name, name, &n->where);
   11313          254 :                 else if (n->sym->ts.type != BT_DERIVED
   11314           70 :                          || !n->sym->ts.u.derived->ts.is_iso_c
   11315           70 :                          || (n->sym->ts.u.derived->intmod_sym_id
   11316              :                              != ISOCBINDING_PTR))
   11317              :                   {
   11318              :                     /* For TARGET, non-C_PTR are deprecated and handled as
   11319              :                        has_device_addr.  */
   11320          184 :                     gfc_warning (OPT_Wdeprecated_openmp,
   11321              :                                  "Non-C_PTR type argument at %L is deprecated, "
   11322              :                                  "use HAS_DEVICE_ADDR", &n->where);
   11323          184 :                     gfc_omp_namelist *n2 = n;
   11324          184 :                     n = n->next;
   11325          184 :                     if (last)
   11326            0 :                       last->next = n;
   11327              :                     else
   11328          184 :                       omp_clauses->lists[list] = n;
   11329          184 :                     n2->next = omp_clauses->lists[OMP_LIST_HAS_DEVICE_ADDR];
   11330          184 :                     omp_clauses->lists[OMP_LIST_HAS_DEVICE_ADDR] = n2;
   11331          184 :                     continue;
   11332          184 :                   }
   11333           73 :                 last = n;
   11334           73 :                 n = n->next;
   11335              :               }
   11336              :             break;
   11337              :           case OMP_LIST_HAS_DEVICE_ADDR:
   11338              :           case OMP_LIST_USE_DEVICE_ADDR:
   11339              :             break;
   11340              :           case OMP_LIST_USE_DEVICE_PTR:
   11341              :             /* Non-C_PTR are deprecated and handled as use_device_ADDR.  */
   11342              :             last = NULL;
   11343          475 :             for (n = omp_clauses->lists[list]; n != NULL; )
   11344              :               {
   11345          312 :                 gfc_omp_namelist *n2 = n;
   11346          312 :                 if (n->sym->ts.type != BT_DERIVED
   11347           18 :                     || !n->sym->ts.u.derived->ts.is_iso_c)
   11348              :                   {
   11349          294 :                     gfc_warning (OPT_Wdeprecated_openmp,
   11350              :                                  "Non-C_PTR type argument at %L is "
   11351              :                                  "deprecated, use USE_DEVICE_ADDR", &n->where);
   11352          294 :                     n = n->next;
   11353          294 :                     if (last)
   11354            0 :                       last->next = n;
   11355              :                     else
   11356          294 :                       omp_clauses->lists[list] = n;
   11357          294 :                     n2->next = omp_clauses->lists[OMP_LIST_USE_DEVICE_ADDR];
   11358          294 :                     omp_clauses->lists[OMP_LIST_USE_DEVICE_ADDR] = n2;
   11359          294 :                     continue;
   11360              :                   }
   11361           18 :                 last = n;
   11362           18 :                 n = n->next;
   11363              :               }
   11364              :             break;
   11365           65 :           case OMP_LIST_USES_ALLOCATORS:
   11366           65 :             {
   11367           65 :               if (n != NULL
   11368           65 :                   && n->u.memspace_sym
   11369           20 :                   && (n->u.memspace_sym->attr.flavor != FL_PARAMETER
   11370           18 :                       || n->u.memspace_sym->ts.type != BT_INTEGER
   11371           18 :                       || n->u.memspace_sym->ts.kind != gfc_c_intptr_kind
   11372           18 :                       || n->u.memspace_sym->attr.dimension
   11373           18 :                       || (!startswith (n->u.memspace_sym->name, "omp_")
   11374            0 :                           && !startswith (n->u.memspace_sym->name, "ompx_"))
   11375           18 :                       || !endswith (n->u.memspace_sym->name, "_mem_space")))
   11376            3 :                 gfc_error ("Memspace %qs at %L in USES_ALLOCATORS must be "
   11377              :                            "a predefined memory space",
   11378              :                            n->u.memspace_sym->name, &n->where);
   11379          180 :               for (; n != NULL; n = n->next)
   11380              :                 {
   11381          122 :                   if (n->sym->ts.type != BT_INTEGER
   11382          121 :                       || n->sym->ts.kind != gfc_c_intptr_kind
   11383          120 :                       || n->sym->attr.dimension)
   11384            3 :                     gfc_error ("Allocator %qs at %L in USES_ALLOCATORS must "
   11385              :                                "be a scalar integer of kind "
   11386              :                                "%<omp_allocator_handle_kind%>", n->sym->name,
   11387              :                                &n->where);
   11388          119 :                   else if (n->sym->attr.flavor != FL_VARIABLE
   11389           50 :                            && strcmp (n->sym->name, "omp_null_allocator") != 0
   11390          165 :                            && ((!startswith (n->sym->name, "omp_")
   11391            1 :                                 && !startswith (n->sym->name, "ompx_"))
   11392           45 :                                || !endswith (n->sym->name, "_mem_alloc")))
   11393            2 :                     gfc_error ("Allocator %qs at %L in USES_ALLOCATORS must "
   11394              :                                "either a variable or a predefined allocator",
   11395              :                                n->sym->name, &n->where);
   11396          117 :                   else if ((n->u.memspace_sym || n->u2.traits_sym)
   11397           61 :                            && n->sym->attr.flavor != FL_VARIABLE)
   11398            3 :                     gfc_error ("A memory space or traits array may not be "
   11399              :                                "specified for predefined allocator %qs at %L",
   11400              :                                n->sym->name, &n->where);
   11401          122 :                   if (n->u2.traits_sym
   11402           50 :                       && (n->u2.traits_sym->attr.flavor != FL_PARAMETER
   11403           47 :                           || !n->u2.traits_sym->attr.dimension
   11404           45 :                           || n->u2.traits_sym->as->rank != 1
   11405           45 :                           || n->u2.traits_sym->ts.type != BT_DERIVED
   11406           43 :                           || strcmp (n->u2.traits_sym->ts.u.derived->name,
   11407              :                                      "omp_alloctrait") != 0))
   11408              :                     {
   11409            7 :                       gfc_error ("Traits array %qs in USES_ALLOCATORS %L must "
   11410              :                                  "be a one-dimensional named constant array of "
   11411              :                                  "type %<omp_alloctrait%>",
   11412              :                                  n->u2.traits_sym->name, &n->where);
   11413            7 :                       break;
   11414              :                     }
   11415              :                 }
   11416              :               break;
   11417              :             }
   11418              :           default:
   11419        34973 :             for (; n != NULL; n = n->next)
   11420              :               {
   11421        20507 :                 if (n->sym == NULL)
   11422              :                   {
   11423           26 :                     gcc_assert (code->op == EXEC_OMP_ALLOCATORS
   11424              :                                 || code->op == EXEC_OMP_ALLOCATE);
   11425           26 :                     continue;
   11426              :                   }
   11427        20481 :                 bool bad = false;
   11428        20481 :                 bool is_reduction = (list == OMP_LIST_REDUCTION
   11429              :                                      || list == OMP_LIST_REDUCTION_INSCAN
   11430              :                                      || list == OMP_LIST_REDUCTION_TASK
   11431              :                                      || list == OMP_LIST_IN_REDUCTION
   11432        20481 :                                      || list == OMP_LIST_TASK_REDUCTION);
   11433        20481 :                 if (list == OMP_LIST_REDUCTION_INSCAN)
   11434              :                   has_inscan = true;
   11435        20409 :                 else if (is_reduction)
   11436         4745 :                   has_notinscan = true;
   11437        20481 :                 if (has_inscan && has_notinscan && is_reduction)
   11438              :                   {
   11439            3 :                     gfc_error ("%<inscan%> and non-%<inscan%> %<reduction%> "
   11440              :                                "clauses on the same construct at %L",
   11441              :                                &n->where);
   11442            3 :                     break;
   11443              :                   }
   11444        20478 :                 if (n->sym->attr.threadprivate)
   11445            1 :                   gfc_error ("THREADPRIVATE object %qs in %s clause at %L",
   11446              :                              n->sym->name, name, &n->where);
   11447        20478 :                 if (n->sym->attr.cray_pointee)
   11448           14 :                   gfc_error ("Cray pointee %qs in %s clause at %L",
   11449              :                             n->sym->name, name, &n->where);
   11450        20478 :                 if (n->sym->attr.associate_var)
   11451           22 :                   gfc_error ("Associate name %qs in %s clause at %L",
   11452           22 :                              n->sym->attr.select_type_temporary
   11453            4 :                              ? n->sym->assoc->target->symtree->n.sym->name
   11454              :                              : n->sym->name, name, &n->where);
   11455        20478 :                 if (list != OMP_LIST_PRIVATE && is_reduction)
   11456              :                   {
   11457         4814 :                     if (n->sym->attr.proc_pointer)
   11458            1 :                       gfc_error ("Procedure pointer %qs in %s clause at %L",
   11459              :                                  n->sym->name, name, &n->where);
   11460         4814 :                     if (n->sym->attr.pointer)
   11461            3 :                       gfc_error ("POINTER object %qs in %s clause at %L",
   11462              :                                  n->sym->name, name, &n->where);
   11463         4814 :                     if (n->sym->attr.cray_pointer)
   11464            5 :                       gfc_error ("Cray pointer %qs in %s clause at %L",
   11465              :                                  n->sym->name, name, &n->where);
   11466              :                   }
   11467        20478 :                 if (code
   11468        20478 :                     && (oacc_is_loop (code)
   11469              :                         || code->op == EXEC_OACC_PARALLEL
   11470              :                         || code->op == EXEC_OACC_SERIAL))
   11471         8741 :                   check_array_not_assumed (n->sym, n->where, name);
   11472        11737 :                 else if (list != OMP_LIST_UNIFORM
   11473        11620 :                          && n->sym->as && n->sym->as->type == AS_ASSUMED_SIZE)
   11474            2 :                   gfc_error ("Assumed size array %qs in %s clause at %L",
   11475              :                              n->sym->name, name, &n->where);
   11476        20478 :                 if (n->sym->attr.in_namelist && !is_reduction)
   11477            0 :                   gfc_error ("Variable %qs in %s clause is used in "
   11478              :                              "NAMELIST statement at %L",
   11479              :                              n->sym->name, name, &n->where);
   11480        20478 :                 if (n->sym->attr.pointer && n->sym->attr.intent == INTENT_IN)
   11481            3 :                   switch (list)
   11482              :                     {
   11483            3 :                     case OMP_LIST_PRIVATE:
   11484            3 :                     case OMP_LIST_LASTPRIVATE:
   11485            3 :                     case OMP_LIST_LINEAR:
   11486              :                     /* case OMP_LIST_REDUCTION: */
   11487            3 :                       gfc_error ("INTENT(IN) POINTER %qs in %s clause at %L",
   11488              :                                  n->sym->name, name, &n->where);
   11489            3 :                       break;
   11490              :                     default:
   11491              :                       break;
   11492              :                     }
   11493        20478 :                 if (omp_clauses->detach
   11494            3 :                     && (list == OMP_LIST_PRIVATE
   11495              :                         || list == OMP_LIST_FIRSTPRIVATE
   11496              :                         || list == OMP_LIST_LASTPRIVATE)
   11497            3 :                     && n->sym == omp_clauses->detach->symtree->n.sym)
   11498            1 :                   gfc_error ("DETACH event handle %qs in %s clause at %L",
   11499              :                              n->sym->name, name, &n->where);
   11500              : 
   11501        20478 :                 if (!openacc
   11502        20478 :                     && (list == OMP_LIST_PRIVATE
   11503        20478 :                         || list == OMP_LIST_FIRSTPRIVATE)
   11504         4773 :                     && ((n->sym->ts.type == BT_DERIVED
   11505          158 :                          && n->sym->ts.u.derived->attr.alloc_comp)
   11506         4663 :                         || n->sym->ts.type == BT_CLASS))
   11507          170 :                   switch (code->op)
   11508              :                     {
   11509            8 :                     case EXEC_OMP_TARGET:
   11510            8 :                     case EXEC_OMP_TARGET_PARALLEL:
   11511            8 :                     case EXEC_OMP_TARGET_PARALLEL_DO:
   11512            8 :                     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   11513            8 :                     case EXEC_OMP_TARGET_PARALLEL_LOOP:
   11514            8 :                     case EXEC_OMP_TARGET_SIMD:
   11515            8 :                     case EXEC_OMP_TARGET_TEAMS:
   11516            8 :                     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   11517            8 :                     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   11518            8 :                     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   11519            8 :                     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   11520            8 :                     case EXEC_OMP_TARGET_TEAMS_LOOP:
   11521            8 :                       if (n->sym->ts.type == BT_DERIVED
   11522            2 :                           && n->sym->ts.u.derived->attr.alloc_comp)
   11523            3 :                         gfc_error ("Sorry, list item %qs at %L with allocatable"
   11524              :                                    " components is not yet supported in %s "
   11525              :                                    "clause", n->sym->name, &n->where,
   11526              :                                    list == OMP_LIST_PRIVATE ? "PRIVATE"
   11527              :                                                             : "FIRSTPRIVATE");
   11528              :                       else
   11529            9 :                         gfc_error ("Polymorphic list item %qs at %L in %s "
   11530              :                                    "clause has unspecified behavior and "
   11531              :                                    "unsupported", n->sym->name, &n->where,
   11532              :                                    list == OMP_LIST_PRIVATE ? "PRIVATE"
   11533              :                                                             : "FIRSTPRIVATE");
   11534              :                       break;
   11535              :                     default:
   11536              :                       break;
   11537              :                     }
   11538              : 
   11539        20478 :                 switch (list)
   11540              :                   {
   11541          104 :                   case OMP_LIST_REDUCTION_TASK:
   11542          104 :                     if (code
   11543          104 :                         && (code->op == EXEC_OMP_LOOP
   11544              :                             || code->op == EXEC_OMP_TASKLOOP
   11545              :                             || code->op == EXEC_OMP_TASKLOOP_SIMD
   11546              :                             || code->op == EXEC_OMP_MASKED_TASKLOOP
   11547              :                             || code->op == EXEC_OMP_MASKED_TASKLOOP_SIMD
   11548              :                             || code->op == EXEC_OMP_MASTER_TASKLOOP
   11549              :                             || code->op == EXEC_OMP_MASTER_TASKLOOP_SIMD
   11550              :                             || code->op == EXEC_OMP_PARALLEL_LOOP
   11551              :                             || code->op == EXEC_OMP_PARALLEL_MASKED_TASKLOOP
   11552              :                             || code->op == EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
   11553              :                             || code->op == EXEC_OMP_PARALLEL_MASTER_TASKLOOP
   11554              :                             || code->op == EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
   11555              :                             || code->op == EXEC_OMP_TARGET_PARALLEL_LOOP
   11556              :                             || code->op == EXEC_OMP_TARGET_TEAMS_LOOP
   11557              :                             || code->op == EXEC_OMP_TEAMS
   11558              :                             || code->op == EXEC_OMP_TEAMS_DISTRIBUTE
   11559              :                             || code->op == EXEC_OMP_TEAMS_LOOP))
   11560              :                       {
   11561           17 :                         gfc_error ("Only DEFAULT permitted as reduction-"
   11562              :                                    "modifier in REDUCTION clause at %L",
   11563              :                                    &n->where);
   11564           17 :                         break;
   11565              :                       }
   11566         4797 :                     gcc_fallthrough ();
   11567         4797 :                   case OMP_LIST_REDUCTION:
   11568         4797 :                   case OMP_LIST_IN_REDUCTION:
   11569         4797 :                   case OMP_LIST_TASK_REDUCTION:
   11570         4797 :                   case OMP_LIST_REDUCTION_INSCAN:
   11571         4797 :                     switch (n->u.reduction_op)
   11572              :                       {
   11573         2662 :                       case OMP_REDUCTION_PLUS:
   11574         2662 :                       case OMP_REDUCTION_TIMES:
   11575         2662 :                       case OMP_REDUCTION_MINUS:
   11576         2662 :                         if (!gfc_numeric_ts (&n->sym->ts))
   11577              :                           bad = true;
   11578              :                         break;
   11579         1112 :                       case OMP_REDUCTION_AND:
   11580         1112 :                       case OMP_REDUCTION_OR:
   11581         1112 :                       case OMP_REDUCTION_EQV:
   11582         1112 :                       case OMP_REDUCTION_NEQV:
   11583         1112 :                         if (n->sym->ts.type != BT_LOGICAL)
   11584              :                           bad = true;
   11585              :                         break;
   11586          480 :                       case OMP_REDUCTION_MAX:
   11587          480 :                       case OMP_REDUCTION_MIN:
   11588          480 :                         if (n->sym->ts.type != BT_INTEGER
   11589          212 :                             && n->sym->ts.type != BT_REAL)
   11590              :                           bad = true;
   11591              :                         break;
   11592          192 :                       case OMP_REDUCTION_IAND:
   11593          192 :                       case OMP_REDUCTION_IOR:
   11594          192 :                       case OMP_REDUCTION_IEOR:
   11595          192 :                         if (n->sym->ts.type != BT_INTEGER)
   11596              :                           bad = true;
   11597              :                         break;
   11598              :                       case OMP_REDUCTION_USER:
   11599              :                         bad = true;
   11600              :                         break;
   11601              :                       default:
   11602              :                         break;
   11603              :                       }
   11604              :                     if (!bad)
   11605         4222 :                       n->u2.udr = NULL;
   11606              :                     else
   11607              :                       {
   11608          575 :                         const char *udr_name = NULL;
   11609          575 :                         if (n->u2.udr)
   11610              :                           {
   11611          471 :                             udr_name = n->u2.udr->udr->name;
   11612          471 :                             n->u2.udr->udr
   11613          942 :                               = gfc_find_omp_udr (NULL, udr_name,
   11614          471 :                                                   &n->sym->ts);
   11615          471 :                             if (n->u2.udr->udr == NULL)
   11616              :                               {
   11617            0 :                                 free (n->u2.udr);
   11618            0 :                                 n->u2.udr = NULL;
   11619              :                               }
   11620              :                           }
   11621          575 :                         if (n->u2.udr == NULL)
   11622              :                           {
   11623          104 :                             if (udr_name == NULL)
   11624          104 :                               switch (n->u.reduction_op)
   11625              :                                 {
   11626           50 :                                 case OMP_REDUCTION_PLUS:
   11627           50 :                                 case OMP_REDUCTION_TIMES:
   11628           50 :                                 case OMP_REDUCTION_MINUS:
   11629           50 :                                 case OMP_REDUCTION_AND:
   11630           50 :                                 case OMP_REDUCTION_OR:
   11631           50 :                                 case OMP_REDUCTION_EQV:
   11632           50 :                                 case OMP_REDUCTION_NEQV:
   11633           50 :                                   udr_name = gfc_op2string ((gfc_intrinsic_op)
   11634              :                                                             n->u.reduction_op);
   11635           50 :                                   break;
   11636              :                                 case OMP_REDUCTION_MAX:
   11637              :                                   udr_name = "max";
   11638              :                                   break;
   11639            9 :                                 case OMP_REDUCTION_MIN:
   11640            9 :                                   udr_name = "min";
   11641            9 :                                   break;
   11642           12 :                                 case OMP_REDUCTION_IAND:
   11643           12 :                                   udr_name = "iand";
   11644           12 :                                   break;
   11645           12 :                                 case OMP_REDUCTION_IOR:
   11646           12 :                                   udr_name = "ior";
   11647           12 :                                   break;
   11648            9 :                                 case OMP_REDUCTION_IEOR:
   11649            9 :                                   udr_name = "ieor";
   11650            9 :                                   break;
   11651            0 :                                 default:
   11652            0 :                                   gcc_unreachable ();
   11653              :                                 }
   11654          104 :                             gfc_error ("!$OMP DECLARE REDUCTION %s not found "
   11655              :                                        "for type %s at %L", udr_name,
   11656          104 :                                        gfc_typename (&n->sym->ts), &n->where);
   11657              :                           }
   11658              :                         else
   11659              :                           {
   11660          471 :                             gfc_omp_udr *udr = n->u2.udr->udr;
   11661          471 :                             n->u.reduction_op = OMP_REDUCTION_USER;
   11662          471 :                             n->u2.udr->combiner
   11663          942 :                               = resolve_omp_udr_clause (n, udr->combiner_ns,
   11664          471 :                                                         udr->omp_out,
   11665          471 :                                                         udr->omp_in);
   11666          471 :                             if (udr->initializer_ns)
   11667          331 :                               n->u2.udr->initializer
   11668          331 :                                 = resolve_omp_udr_clause (n,
   11669              :                                                           udr->initializer_ns,
   11670          331 :                                                           udr->omp_priv,
   11671          331 :                                                           udr->omp_orig);
   11672              :                           }
   11673              :                       }
   11674              :                     break;
   11675          887 :                   case OMP_LIST_LINEAR:
   11676          887 :                     if (code)
   11677              :                       {
   11678          727 :                         bool is_worksharing_for = false;
   11679          727 :                         switch (code->op)
   11680              :                           {
   11681           54 :                           case EXEC_OMP_DO:
   11682           54 :                           case EXEC_OMP_PARALLEL_DO:
   11683           54 :                           case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   11684           54 :                           case EXEC_OMP_TARGET_PARALLEL_DO:
   11685           54 :                           case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   11686           54 :                           case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   11687           54 :                             is_worksharing_for = true;
   11688           54 :                             break;
   11689              :                           default:
   11690              :                             break;
   11691              :                           }
   11692              : 
   11693           54 :                         if (is_worksharing_for
   11694           54 :                             && (n->sym->attr.dimension
   11695           53 :                                 || n->sym->attr.allocatable))
   11696              :                           {
   11697            1 :                             if (n->sym->attr.allocatable)
   11698            0 :                               gfc_error ("Sorry, ALLOCATABLE object %qs in "
   11699              :                                          "LINEAR clause on worksharing-loop "
   11700              :                                          "construct at %L is not yet supported",
   11701              :                                          n->sym->name, &n->where);
   11702              :                             else
   11703            1 :                               gfc_error ("Sorry, array %qs in LINEAR clause "
   11704              :                                          "on worksharing-loop construct at %L "
   11705              :                                          "is not yet supported",
   11706              :                                          n->sym->name, &n->where);
   11707              :                             break;
   11708              :                           }
   11709              :                       }
   11710              : 
   11711          726 :                     if (code
   11712          726 :                         && n->u.linear.op != OMP_LINEAR_DEFAULT
   11713           23 :                         && n->u.linear.op != linear_op)
   11714              :                       {
   11715           23 :                         if (n->u.linear.old_modifier)
   11716              :                           {
   11717            9 :                             gfc_error ("LINEAR clause modifier used on DO or "
   11718              :                                        "SIMD construct at %L", &n->where);
   11719            9 :                             linear_op = n->u.linear.op;
   11720              :                           }
   11721           14 :                         else if (n->u.linear.op != OMP_LINEAR_VAL)
   11722              :                           {
   11723            6 :                             gfc_error ("LINEAR clause modifier other than VAL "
   11724              :                                        "used on DO or SIMD construct at %L",
   11725              :                                        &n->where);
   11726            6 :                             linear_op = n->u.linear.op;
   11727              :                           }
   11728              :                       }
   11729          863 :                     else if (n->u.linear.op != OMP_LINEAR_REF
   11730          813 :                              && n->sym->ts.type != BT_INTEGER)
   11731            1 :                       gfc_error ("LINEAR variable %qs must be INTEGER "
   11732              :                                  "at %L", n->sym->name, &n->where);
   11733          862 :                     else if ((n->u.linear.op == OMP_LINEAR_REF
   11734          812 :                               || n->u.linear.op == OMP_LINEAR_UVAL)
   11735           61 :                              && n->sym->attr.value)
   11736            0 :                       gfc_error ("LINEAR dummy argument %qs with VALUE "
   11737              :                                  "attribute with %s modifier at %L",
   11738              :                                  n->sym->name,
   11739              :                                  n->u.linear.op == OMP_LINEAR_REF
   11740              :                                  ? "REF" : "UVAL", &n->where);
   11741          862 :                     else if (n->expr)
   11742              :                       {
   11743          843 :                         gfc_expr *expr = n->expr;
   11744          843 :                         if (!gfc_resolve_expr (expr)
   11745          843 :                             || expr->ts.type != BT_INTEGER
   11746         1686 :                             || expr->rank != 0)
   11747            0 :                           gfc_error ("%qs in LINEAR clause at %L requires "
   11748              :                                      "a scalar integer linear-step expression",
   11749            0 :                                      n->sym->name, &n->where);
   11750          843 :                         else if (!code && expr->expr_type != EXPR_CONSTANT)
   11751              :                           {
   11752           11 :                             if (expr->expr_type == EXPR_VARIABLE
   11753            7 :                                 && expr->symtree->n.sym->attr.dummy
   11754            6 :                                 && expr->symtree->n.sym->ns == ns)
   11755              :                               {
   11756            6 :                                 gfc_omp_namelist *n2;
   11757            6 :                                 for (n2 = omp_clauses->lists[OMP_LIST_UNIFORM];
   11758            6 :                                      n2; n2 = n2->next)
   11759            6 :                                   if (n2->sym == expr->symtree->n.sym)
   11760              :                                     break;
   11761            6 :                                 if (n2)
   11762              :                                   break;
   11763              :                               }
   11764            5 :                             gfc_error ("%qs in LINEAR clause at %L requires "
   11765              :                                        "a constant integer linear-step "
   11766              :                                        "expression or dummy argument "
   11767              :                                        "specified in UNIFORM clause",
   11768            5 :                                        n->sym->name, &n->where);
   11769              :                           }
   11770              :                       }
   11771              :                     break;
   11772              :                   /* Workaround for PR middle-end/26316, nothing really needs
   11773              :                      to be done here for OMP_LIST_PRIVATE.  */
   11774         9457 :                   case OMP_LIST_PRIVATE:
   11775         9457 :                     gcc_assert (code && code->op != EXEC_NOP);
   11776              :                     break;
   11777           98 :                   case OMP_LIST_USE_DEVICE:
   11778           98 :                       if (n->sym->attr.allocatable
   11779           98 :                           || (n->sym->ts.type == BT_CLASS && CLASS_DATA (n->sym)
   11780            0 :                               && CLASS_DATA (n->sym)->attr.allocatable))
   11781            0 :                         gfc_error ("ALLOCATABLE object %qs in %s clause at %L",
   11782              :                                    n->sym->name, name, &n->where);
   11783           98 :                       if (n->sym->ts.type == BT_CLASS
   11784            0 :                           && CLASS_DATA (n->sym)
   11785            0 :                           && CLASS_DATA (n->sym)->attr.class_pointer)
   11786            0 :                         gfc_error ("POINTER object %qs of polymorphic type in "
   11787              :                                    "%s clause at %L", n->sym->name, name,
   11788              :                                    &n->where);
   11789           98 :                       if (n->sym->attr.cray_pointer)
   11790            2 :                         gfc_error ("Cray pointer object %qs in %s clause at %L",
   11791              :                                    n->sym->name, name, &n->where);
   11792           96 :                       else if (n->sym->attr.cray_pointee)
   11793            2 :                         gfc_error ("Cray pointee object %qs in %s clause at %L",
   11794              :                                    n->sym->name, name, &n->where);
   11795           94 :                       else if (n->sym->attr.flavor == FL_VARIABLE
   11796           93 :                                && !n->sym->as
   11797           54 :                                && !n->sym->attr.pointer)
   11798           13 :                         gfc_error ("%s clause variable %qs at %L is neither "
   11799              :                                    "a POINTER nor an array", name,
   11800              :                                    n->sym->name, &n->where);
   11801              :                       /* FALLTHRU */
   11802           98 :                   case OMP_LIST_DEVICE_RESIDENT:
   11803           98 :                     check_symbol_not_pointer (n->sym, n->where, name);
   11804           98 :                     check_array_not_assumed (n->sym, n->where, name);
   11805           98 :                     break;
   11806              :                   default:
   11807              :                     break;
   11808              :                   }
   11809              :               }
   11810              :             break;
   11811              :           }
   11812              :       }
   11813              :   /* OpenMP 5.1: use_device_ptr acts like use_device_addr, except for
   11814              :      type(c_ptr).  */
   11815        33556 :   if (omp_clauses->lists[OMP_LIST_USE_DEVICE_PTR])
   11816              :     {
   11817            9 :       gfc_omp_namelist *n_prev, *n_next, *n_addr;
   11818            9 :       n_addr = omp_clauses->lists[OMP_LIST_USE_DEVICE_ADDR];
   11819           28 :       for (; n_addr && n_addr->next; n_addr = n_addr->next)
   11820              :         ;
   11821              :       n_prev = NULL;
   11822              :       n = omp_clauses->lists[OMP_LIST_USE_DEVICE_PTR];
   11823           27 :       while (n)
   11824              :         {
   11825           18 :           n_next = n->next;
   11826           18 :           if (n->sym->ts.type != BT_DERIVED
   11827           18 :               || n->sym->ts.u.derived->ts.f90_type != BT_VOID)
   11828              :             {
   11829            0 :               n->next = NULL;
   11830            0 :               if (n_addr)
   11831            0 :                 n_addr->next = n;
   11832              :               else
   11833            0 :                 omp_clauses->lists[OMP_LIST_USE_DEVICE_ADDR] = n;
   11834            0 :               n_addr = n;
   11835            0 :               if (n_prev)
   11836            0 :                 n_prev->next = n_next;
   11837              :               else
   11838            0 :                 omp_clauses->lists[OMP_LIST_USE_DEVICE_PTR] = n_next;
   11839              :             }
   11840              :           else
   11841              :             n_prev = n;
   11842           18 :           n = n_next;
   11843              :         }
   11844              :     }
   11845        33556 :   if (omp_clauses->safelen_expr)
   11846           95 :     resolve_positive_int_expr (omp_clauses->safelen_expr, "SAFELEN", false);
   11847        33556 :   if (omp_clauses->simdlen_expr)
   11848          143 :     resolve_positive_int_expr (omp_clauses->simdlen_expr, "SIMDLEN", false);
   11849        33556 :   if (omp_clauses->simdlen_divisor
   11850        33556 :       && (!gfc_resolve_expr (omp_clauses->simdlen_divisor)
   11851           11 :           || omp_clauses->simdlen_divisor->ts.type != BT_INTEGER
   11852           11 :           || omp_clauses->simdlen_divisor->rank != 0
   11853           11 :           || omp_clauses->simdlen_divisor->expr_type != EXPR_CONSTANT
   11854           10 :           || mpz_sgn (omp_clauses->simdlen_divisor->value.integer) <= 0))
   11855            2 :     gfc_error ("Divisor expression at %L of the SCALED modifier to SIMDLEN must"
   11856              :                " be a positive scalar constant integer expression",
   11857            2 :                &omp_clauses->simdlen_divisor->where);
   11858              :   /* Check that safelen >= simdlen * scaled; however, scaled is
   11859              :      unknown, hence, assume scaled == 1 as conservative estimate.
   11860              :      we need to repeat some const check as the program still continues
   11861              :      after the error diagnostic above.  */
   11862        33556 :   if (omp_clauses->safelen_expr && omp_clauses->simdlen_expr
   11863           36 :       && omp_clauses->safelen_expr->expr_type == EXPR_CONSTANT
   11864           36 :       && omp_clauses->simdlen_expr->expr_type == EXPR_CONSTANT
   11865           36 :       && omp_clauses->safelen_expr->rank == 0
   11866           36 :       && omp_clauses->simdlen_expr->rank == 0
   11867           36 :       && omp_clauses->safelen_expr->ts.type == BT_INTEGER
   11868           36 :       && omp_clauses->simdlen_expr->ts.type == BT_INTEGER
   11869           36 :       && mpz_cmp (omp_clauses->safelen_expr->value.integer,
   11870           36 :                   omp_clauses->simdlen_expr->value.integer) < 0)
   11871            0 :     gfc_error ("SIMDLEN at %L must be smaller or equal to SAFELEN at %L",
   11872              :                &omp_clauses->simdlen_expr->where,
   11873              :                &omp_clauses->safelen_expr->where);
   11874        33794 :   for (el = omp_clauses->num_teams_list; el; el = el->next)
   11875          238 :     resolve_positive_int_expr (el->expr, "NUM_TEAMS", true);
   11876        33556 :   if (omp_clauses->num_teams_list
   11877          182 :       && omp_clauses->num_teams_list->next
   11878           49 :       && !omp_clauses->num_teams_dims
   11879           35 :       && omp_clauses->num_teams_list->expr->expr_type == EXPR_CONSTANT
   11880           21 :       && omp_clauses->num_teams_list->next->expr->expr_type == EXPR_CONSTANT
   11881           21 :       && mpz_cmp (omp_clauses->num_teams_list->expr->value.integer,
   11882           21 :                   omp_clauses->num_teams_list->next->expr->value.integer) > 0)
   11883            2 :     gfc_warning (OPT_Wopenmp, "NUM_TEAMS lower bound at %L larger than upper "
   11884              :                  "bound at %L", &omp_clauses->num_teams_list->expr->where,
   11885              :                  &omp_clauses->num_teams_list->next->expr->where);
   11886        33556 :   if (omp_clauses->device)
   11887          337 :     resolve_scalar_int_expr (omp_clauses->device, "DEVICE");
   11888        33556 :   if (omp_clauses->filter)
   11889           42 :     resolve_nonnegative_int_expr (omp_clauses->filter, "FILTER", true);
   11890        33556 :   if (omp_clauses->hint)
   11891              :     {
   11892           47 :       if (!gfc_resolve_expr (omp_clauses->hint)
   11893           47 :           || omp_clauses->hint->rank != 0
   11894           47 :           || omp_clauses->hint->ts.type != BT_INTEGER
   11895           45 :           || omp_clauses->hint->expr_type != EXPR_CONSTANT
   11896           90 :           || mpz_sgn (omp_clauses->hint->value.integer) < 0)
   11897            5 :       gfc_error ("Value of HINT clause at %L shall be a valid "
   11898            5 :                  "constant hint expression", &omp_clauses->hint->where);
   11899              :     }
   11900        33556 :   if (omp_clauses->priority)
   11901           35 :     resolve_nonnegative_int_expr (omp_clauses->priority, "PRIORITY", true);
   11902        33556 :   if (omp_clauses->dist_chunk_size)
   11903              :     {
   11904           83 :       gfc_expr *expr = omp_clauses->dist_chunk_size;
   11905           83 :       if (!gfc_resolve_expr (expr)
   11906           83 :           || expr->ts.type != BT_INTEGER || expr->rank != 0)
   11907            0 :         gfc_error ("DIST_SCHEDULE clause's chunk_size at %L requires "
   11908              :                    "a scalar INTEGER expression", &expr->where);
   11909              :     }
   11910        33721 :   for (el = omp_clauses->thread_limit_list; el; el = el->next)
   11911          165 :     resolve_positive_int_expr (el->expr, "THREAD_LIMIT", true);
   11912        33556 :   if (omp_clauses->grainsize)
   11913           34 :     resolve_positive_int_expr (omp_clauses->grainsize, "GRAINSIZE", true);
   11914        33556 :   if (omp_clauses->num_tasks)
   11915           26 :     resolve_positive_int_expr (omp_clauses->num_tasks, "NUM_TASKS", true);
   11916        33556 :   if (omp_clauses->grainsize && omp_clauses->num_tasks)
   11917            1 :     gfc_error ("%<GRAINSIZE%> clause at %L must not be used together with "
   11918              :                "%<NUM_TASKS%> clause", &omp_clauses->grainsize->where);
   11919        33556 :   if (omp_clauses->lists[OMP_LIST_REDUCTION] && omp_clauses->nogroup)
   11920            1 :     gfc_error ("%<REDUCTION%> clause at %L must not be used together with "
   11921              :                "%<NOGROUP%> clause",
   11922              :                &omp_clauses->lists[OMP_LIST_REDUCTION]->where);
   11923        33556 :   if (omp_clauses->full && omp_clauses->partial)
   11924            0 :     gfc_error ("%<FULL%> clause at %C must not be used together with "
   11925              :                "%<PARTIAL%> clause");
   11926        33556 :   if (omp_clauses->async)
   11927          610 :     if (omp_clauses->async_expr)
   11928          610 :       resolve_scalar_int_expr (omp_clauses->async_expr, "ASYNC");
   11929        33556 :   if (omp_clauses->device_num_expr)
   11930          105 :     resolve_scalar_int_expr (omp_clauses->device_num_expr, "DEVICE_NUM");
   11931        33556 :   if (code && code->op == EXEC_OACC_SET
   11932          121 :       && !omp_clauses->device_num_expr
   11933           52 :       && !omp_clauses->oacc_device_type_present)
   11934            2 :     gfc_error ("At least one of the clauses %<DEVICE_TYPE%> and %<DEVICE_NUM%> "
   11935              :                "should be present in %<SET%> directive at %L", &code->loc);
   11936        33556 :   if (omp_clauses->num_gangs_expr)
   11937          682 :     resolve_positive_int_expr (omp_clauses->num_gangs_expr, "NUM_GANGS", true);
   11938        33556 :   if (omp_clauses->num_workers_expr)
   11939          599 :     resolve_positive_int_expr (omp_clauses->num_workers_expr, "NUM_WORKERS",
   11940              :                                true);
   11941        33556 :   if (omp_clauses->vector_length_expr)
   11942          569 :     resolve_positive_int_expr (omp_clauses->vector_length_expr,
   11943              :                                "VECTOR_LENGTH", true);
   11944        33556 :   if (omp_clauses->gang_num_expr)
   11945          114 :     resolve_positive_int_expr (omp_clauses->gang_num_expr, "GANG", true);
   11946        33556 :   if (omp_clauses->gang_static_expr)
   11947           94 :     resolve_positive_int_expr (omp_clauses->gang_static_expr, "GANG", true);
   11948        33556 :   if (omp_clauses->worker_expr)
   11949          101 :     resolve_positive_int_expr (omp_clauses->worker_expr, "WORKER", true);
   11950        33556 :   if (omp_clauses->vector_expr)
   11951          132 :     resolve_positive_int_expr (omp_clauses->vector_expr, "VECTOR", true);
   11952        33895 :   for (el = omp_clauses->wait_list; el; el = el->next)
   11953          339 :     resolve_scalar_int_expr (el->expr, "WAIT");
   11954        33556 :   if (omp_clauses->collapse && omp_clauses->tile_list)
   11955            4 :     gfc_error ("Incompatible use of TILE and COLLAPSE at %L", &code->loc);
   11956        33556 :   if (omp_clauses->message)
   11957              :     {
   11958           83 :       gfc_expr *expr = omp_clauses->message;
   11959           83 :       if (!gfc_resolve_expr (expr)
   11960           83 :           || expr->ts.kind != gfc_default_character_kind
   11961          163 :           || expr->ts.type != BT_CHARACTER || expr->rank != 0)
   11962            4 :         gfc_error ("MESSAGE clause at %L requires a scalar default-kind "
   11963              :                    "CHARACTER expression", &expr->where);
   11964              :     }
   11965        33556 :   if (!openacc
   11966        33556 :       && code
   11967        20279 :       && omp_clauses->lists[OMP_LIST_MAP] == NULL
   11968        16458 :       && omp_clauses->lists[OMP_LIST_USE_DEVICE_PTR] == NULL
   11969        16455 :       && omp_clauses->lists[OMP_LIST_USE_DEVICE_ADDR] == NULL)
   11970              :     {
   11971        16432 :       const char *p = NULL;
   11972        16432 :       switch (code->op)
   11973              :         {
   11974            1 :         case EXEC_OMP_TARGET_ENTER_DATA: p = "TARGET ENTER DATA"; break;
   11975            1 :         case EXEC_OMP_TARGET_EXIT_DATA: p = "TARGET EXIT DATA"; break;
   11976              :         default: break;
   11977              :         }
   11978        16432 :       if (code->op == EXEC_OMP_TARGET_DATA)
   11979            1 :         gfc_error ("TARGET DATA must contain at least one MAP, USE_DEVICE_PTR, "
   11980              :                    "or USE_DEVICE_ADDR clause at %L", &code->loc);
   11981        16431 :       else if (p)
   11982            2 :         gfc_error ("%s must contain at least one MAP clause at %L",
   11983              :                    p, &code->loc);
   11984              :     }
   11985        33556 :   if (omp_clauses->sizes_list)
   11986              :     {
   11987              :       gfc_expr_list *el;
   11988          576 :       for (el = omp_clauses->sizes_list; el; el = el->next)
   11989          379 :         resolve_positive_int_expr (el->expr, "SIZES", false);
   11990              :     }
   11991              : 
   11992        33556 :   if (!openacc && omp_clauses->detach)
   11993              :     {
   11994          125 :       if (!gfc_resolve_expr (omp_clauses->detach)
   11995          125 :           || omp_clauses->detach->ts.type != BT_INTEGER
   11996          124 :           || omp_clauses->detach->ts.kind != gfc_c_intptr_kind
   11997          248 :           || omp_clauses->detach->rank != 0)
   11998            3 :         gfc_error ("%qs at %L should be a scalar of type "
   11999              :                    "integer(kind=omp_event_handle_kind)",
   12000            3 :                    omp_clauses->detach->symtree->n.sym->name,
   12001            3 :                    &omp_clauses->detach->where);
   12002          122 :       else if (omp_clauses->detach->symtree->n.sym->attr.dimension > 0)
   12003            1 :         gfc_error ("The event handle at %L must not be an array element",
   12004              :                    &omp_clauses->detach->where);
   12005          121 :       else if (omp_clauses->detach->symtree->n.sym->ts.type == BT_DERIVED
   12006          120 :                || omp_clauses->detach->symtree->n.sym->ts.type == BT_CLASS)
   12007            1 :         gfc_error ("The event handle at %L must not be part of "
   12008              :                    "a derived type or class", &omp_clauses->detach->where);
   12009              : 
   12010          125 :       if (omp_clauses->mergeable)
   12011            2 :         gfc_error ("%<DETACH%> clause at %L must not be used together with "
   12012            2 :                    "%<MERGEABLE%> clause", &omp_clauses->detach->where);
   12013              :     }
   12014              : 
   12015              :   if (openacc
   12016        12995 :       && code->op == EXEC_OACC_HOST_DATA
   12017           60 :       && omp_clauses->lists[OMP_LIST_USE_DEVICE] == NULL)
   12018            1 :     gfc_error ("%<host_data%> construct at %L requires %<use_device%> clause",
   12019              :                &code->loc);
   12020              : 
   12021        33556 :   if (omp_clauses->assume)
   12022           18 :     gfc_resolve_omp_assumptions (omp_clauses->assume);
   12023              : }
   12024              : 
   12025              : 
   12026              : /* Return true if SYM is ever referenced in EXPR except in the SE node.  */
   12027              : 
   12028              : static bool
   12029         5008 : expr_references_sym (gfc_expr *e, gfc_symbol *s, gfc_expr *se)
   12030              : {
   12031         6641 :   gfc_actual_arglist *arg;
   12032         6641 :   if (e == NULL || e == se)
   12033              :     return false;
   12034         5386 :   switch (e->expr_type)
   12035              :     {
   12036         3133 :     case EXPR_CONSTANT:
   12037         3133 :     case EXPR_NULL:
   12038         3133 :     case EXPR_VARIABLE:
   12039         3133 :     case EXPR_STRUCTURE:
   12040         3133 :     case EXPR_ARRAY:
   12041         3133 :       if (e->symtree != NULL
   12042         1157 :           && e->symtree->n.sym == s)
   12043          470 :         return true;
   12044              :       return false;
   12045            0 :     case EXPR_SUBSTRING:
   12046            0 :       if (e->ref != NULL
   12047            0 :           && (expr_references_sym (e->ref->u.ss.start, s, se)
   12048            0 :               || expr_references_sym (e->ref->u.ss.end, s, se)))
   12049            0 :         return true;
   12050              :       return false;
   12051         1742 :     case EXPR_OP:
   12052         1742 :       if (expr_references_sym (e->value.op.op2, s, se))
   12053              :         return true;
   12054         1633 :       return expr_references_sym (e->value.op.op1, s, se);
   12055          511 :     case EXPR_FUNCTION:
   12056          896 :       for (arg = e->value.function.actual; arg; arg = arg->next)
   12057          586 :         if (expr_references_sym (arg->expr, s, se))
   12058              :           return true;
   12059              :       return false;
   12060            0 :     default:
   12061            0 :       gcc_unreachable ();
   12062              :     }
   12063              : }
   12064              : 
   12065              : 
   12066              : /* If EXPR is a conversion function that widens the type
   12067              :    if WIDENING is true or narrows the type if NARROW is true,
   12068              :    return the inner expression, otherwise return NULL.  */
   12069              : 
   12070              : static gfc_expr *
   12071         5928 : is_conversion (gfc_expr *expr, bool narrowing, bool widening)
   12072              : {
   12073         5928 :   gfc_typespec *ts1, *ts2;
   12074              : 
   12075         5928 :   if (expr->expr_type != EXPR_FUNCTION
   12076          917 :       || expr->value.function.isym == NULL
   12077          894 :       || expr->value.function.esym != NULL
   12078          894 :       || expr->value.function.isym->id != GFC_ISYM_CONVERSION
   12079          388 :       || (!narrowing && !widening))
   12080              :     return NULL;
   12081              : 
   12082          388 :   if (narrowing && widening)
   12083          267 :     return expr->value.function.actual->expr;
   12084              : 
   12085          121 :   if (widening)
   12086              :     {
   12087          121 :       ts1 = &expr->ts;
   12088          121 :       ts2 = &expr->value.function.actual->expr->ts;
   12089              :     }
   12090              :   else
   12091              :     {
   12092            0 :       ts1 = &expr->value.function.actual->expr->ts;
   12093            0 :       ts2 = &expr->ts;
   12094              :     }
   12095              : 
   12096          121 :   if (ts1->type > ts2->type
   12097           49 :       || (ts1->type == ts2->type && ts1->kind > ts2->kind))
   12098          121 :     return expr->value.function.actual->expr;
   12099              : 
   12100              :   return NULL;
   12101              : }
   12102              : 
   12103              : static bool
   12104         6883 : is_scalar_intrinsic_expr (gfc_expr *expr, bool must_be_var, bool conv_ok)
   12105              : {
   12106         6883 :   if (must_be_var
   12107         4034 :       && (expr->expr_type != EXPR_VARIABLE || !expr->symtree))
   12108              :     {
   12109           37 :       if (!conv_ok)
   12110              :         return false;
   12111           37 :       gfc_expr *conv = is_conversion (expr, true, true);
   12112           37 :       if (!conv)
   12113              :         return false;
   12114           36 :       if (conv->expr_type != EXPR_VARIABLE || !conv->symtree)
   12115              :         return false;
   12116              :     }
   12117         6880 :   return (expr->rank == 0
   12118         6876 :           && !gfc_is_coindexed (expr)
   12119        13756 :           && (expr->ts.type == BT_INTEGER
   12120         1522 :               || expr->ts.type == BT_REAL
   12121          590 :               || expr->ts.type == BT_COMPLEX
   12122          572 :               || expr->ts.type == BT_LOGICAL));
   12123              : }
   12124              : 
   12125              : static void
   12126         2710 : resolve_omp_atomic (gfc_code *code)
   12127              : {
   12128         2710 :   gfc_code *atomic_code = code->block;
   12129         2710 :   gfc_symbol *var;
   12130         2710 :   gfc_expr *stmt_expr2, *capt_expr2;
   12131         2710 :   gfc_omp_atomic_op aop
   12132         2710 :     = (gfc_omp_atomic_op) (atomic_code->ext.omp_clauses->atomic_op
   12133              :                            & GFC_OMP_ATOMIC_MASK);
   12134         2710 :   gfc_code *stmt = NULL, *capture_stmt = NULL, *tailing_stmt = NULL;
   12135         2710 :   gfc_expr *comp_cond = NULL;
   12136         2710 :   locus *loc = NULL;
   12137              : 
   12138         2710 :   code = code->block->next;
   12139              :   /* resolve_blocks asserts this is initially EXEC_ASSIGN or EXEC_IF
   12140              :      If it changed to EXEC_NOP, assume an error has been emitted already.  */
   12141         2710 :   if (code->op == EXEC_NOP)
   12142              :     return;
   12143              : 
   12144         2709 :   if (atomic_code->ext.omp_clauses->compare
   12145          157 :       && atomic_code->ext.omp_clauses->capture)
   12146              :     {
   12147              :       /* Must be either "if (x == e) then; x = d; else; v = x; end if"
   12148              :          or "v = expr" followed/preceded by
   12149              :          "if (x == e) then; x = d; end if" or "if (x == e) x = d".  */
   12150          103 :       gfc_code *next = code;
   12151          103 :       if (code->op == EXEC_ASSIGN)
   12152              :         {
   12153           19 :           capture_stmt = code;
   12154           19 :           next = code->next;
   12155              :         }
   12156          103 :       if (next->op == EXEC_IF
   12157          103 :           && next->block
   12158          103 :           && next->block->op == EXEC_IF
   12159          103 :           && next->block->next
   12160          102 :           && next->block->next->op == EXEC_ASSIGN)
   12161              :         {
   12162          102 :           comp_cond = next->block->expr1;
   12163          102 :           stmt = next->block->next;
   12164          102 :           if (stmt->next)
   12165              :             {
   12166            0 :               loc = &stmt->loc;
   12167            0 :               goto unexpected;
   12168              :             }
   12169              :         }
   12170            1 :       else if (capture_stmt)
   12171              :         {
   12172            0 :           gfc_error ("Expected IF at %L in atomic compare capture",
   12173              :                      &next->loc);
   12174            0 :           return;
   12175              :         }
   12176          103 :       if (stmt && !capture_stmt && next->block->block)
   12177              :         {
   12178           64 :           if (next->block->block->expr1)
   12179              :             {
   12180            0 :               gfc_error ("Expected ELSE at %L in atomic compare capture",
   12181              :                          &next->block->block->expr1->where);
   12182            0 :               return;
   12183              :             }
   12184           64 :           if (!code->block->block->next
   12185           64 :               || code->block->block->next->op != EXEC_ASSIGN)
   12186              :             {
   12187            0 :               loc = (code->block->block->next ? &code->block->block->next->loc
   12188              :                                               : &code->block->block->loc);
   12189            0 :               goto unexpected;
   12190              :             }
   12191           64 :           capture_stmt = code->block->block->next;
   12192           64 :           if (capture_stmt->next)
   12193              :             {
   12194            0 :               loc = &capture_stmt->next->loc;
   12195            0 :               goto unexpected;
   12196              :             }
   12197              :         }
   12198          103 :       if (stmt && !capture_stmt && next->next->op == EXEC_ASSIGN)
   12199              :         capture_stmt = next->next;
   12200           84 :       else if (!capture_stmt)
   12201              :         {
   12202            1 :           loc = &code->loc;
   12203            1 :           goto unexpected;
   12204              :         }
   12205              :     }
   12206         2606 :   else if (atomic_code->ext.omp_clauses->compare)
   12207              :     {
   12208              :       /* Must be: "if (x == e) then; x = d; end if" or "if (x == e) x = d".  */
   12209           54 :       if (code->op == EXEC_IF
   12210           54 :           && code->block
   12211           54 :           && code->block->op == EXEC_IF
   12212           54 :           && code->block->next
   12213           52 :           && code->block->next->op == EXEC_ASSIGN)
   12214              :         {
   12215           52 :           comp_cond = code->block->expr1;
   12216           52 :           stmt = code->block->next;
   12217           52 :           if (stmt->next || code->block->block)
   12218              :             {
   12219            0 :               loc = stmt->next ? &stmt->next->loc : &code->block->block->loc;
   12220            0 :               goto unexpected;
   12221              :             }
   12222              :         }
   12223              :       else
   12224              :         {
   12225            2 :           loc = &code->loc;
   12226            2 :           goto unexpected;
   12227              :         }
   12228              :     }
   12229         2552 :   else if (atomic_code->ext.omp_clauses->capture)
   12230              :     {
   12231              :       /* Must be: "v = x" followed/preceded by "x = ...". */
   12232          489 :       if (code->op != EXEC_ASSIGN)
   12233            0 :         goto unexpected;
   12234          489 :       if (code->next->op != EXEC_ASSIGN)
   12235              :         {
   12236            0 :           loc = &code->next->loc;
   12237            0 :           goto unexpected;
   12238              :         }
   12239          489 :       gfc_expr *expr2, *expr2_next;
   12240          489 :       expr2 = is_conversion (code->expr2, true, true);
   12241          489 :       if (expr2 == NULL)
   12242          447 :         expr2 = code->expr2;
   12243          489 :       expr2_next = is_conversion (code->next->expr2, true, true);
   12244          489 :       if (expr2_next == NULL)
   12245          478 :         expr2_next = code->next->expr2;
   12246          489 :       if (code->expr1->expr_type == EXPR_VARIABLE
   12247          489 :           && code->next->expr1->expr_type == EXPR_VARIABLE
   12248          489 :           && expr2->expr_type == EXPR_VARIABLE
   12249          243 :           && expr2_next->expr_type == EXPR_VARIABLE)
   12250              :         {
   12251            1 :           if (code->expr1->symtree->n.sym == expr2_next->symtree->n.sym)
   12252              :             {
   12253              :               stmt = code;
   12254              :               capture_stmt = code->next;
   12255              :             }
   12256              :           else
   12257              :             {
   12258          489 :               capture_stmt = code;
   12259          489 :               stmt = code->next;
   12260              :             }
   12261              :         }
   12262          488 :       else if (expr2->expr_type == EXPR_VARIABLE)
   12263              :         {
   12264              :           capture_stmt = code;
   12265              :           stmt = code->next;
   12266              :         }
   12267              :       else
   12268              :         {
   12269          247 :           stmt = code;
   12270          247 :           capture_stmt = code->next;
   12271              :         }
   12272              :       /* Shall be NULL but can happen for invalid code. */
   12273          489 :       tailing_stmt = code->next->next;
   12274              :     }
   12275              :   else
   12276              :     {
   12277              :       /* x = ... */
   12278         2063 :       stmt = code;
   12279         2063 :       if (!atomic_code->ext.omp_clauses->compare && stmt->op != EXEC_ASSIGN)
   12280            1 :         goto unexpected;
   12281              :       /* Shall be NULL but can happen for invalid code. */
   12282         2062 :       tailing_stmt = code->next;
   12283              :     }
   12284              : 
   12285         2705 :   if (comp_cond)
   12286              :     {
   12287          154 :       if (comp_cond->expr_type != EXPR_OP
   12288          154 :           || (comp_cond->value.op.op != INTRINSIC_EQ
   12289              :               && comp_cond->value.op.op != INTRINSIC_EQ_OS
   12290              :               && comp_cond->value.op.op != INTRINSIC_EQV))
   12291              :         {
   12292            0 :           gfc_error ("Expected %<==%>, %<.EQ.%> or %<.EQV.%> atomic comparison "
   12293              :                      "expression at %L", &comp_cond->where);
   12294            0 :           return;
   12295              :         }
   12296          154 :       if (!is_scalar_intrinsic_expr (comp_cond->value.op.op1, true, true))
   12297              :         {
   12298            1 :           gfc_error ("Expected scalar intrinsic variable at %L in atomic "
   12299            1 :                      "comparison", &comp_cond->value.op.op1->where);
   12300            1 :           return;
   12301              :         }
   12302          153 :       if (!gfc_resolve_expr (comp_cond->value.op.op2))
   12303              :         return;
   12304          153 :       if (!is_scalar_intrinsic_expr (comp_cond->value.op.op2, false, false))
   12305              :         {
   12306            0 :           gfc_error ("Expected scalar intrinsic expression at %L in atomic "
   12307            0 :                      "comparison", &comp_cond->value.op.op1->where);
   12308            0 :           return;
   12309              :         }
   12310              :     }
   12311              : 
   12312         2704 :   if (!is_scalar_intrinsic_expr (stmt->expr1, true, false))
   12313              :     {
   12314            4 :       gfc_error ("!$OMP ATOMIC statement must set a scalar variable of "
   12315            4 :                  "intrinsic type at %L", &stmt->expr1->where);
   12316            4 :       return;
   12317              :     }
   12318              : 
   12319         2700 :   if (!gfc_resolve_expr (stmt->expr2))
   12320              :     return;
   12321         2696 :   if (!is_scalar_intrinsic_expr (stmt->expr2, false, false))
   12322              :     {
   12323            0 :       gfc_error ("!$OMP ATOMIC statement must assign an expression of "
   12324            0 :                  "intrinsic type at %L", &stmt->expr2->where);
   12325            0 :       return;
   12326              :     }
   12327              : 
   12328         2696 :   if (gfc_expr_attr (stmt->expr1).allocatable)
   12329              :     {
   12330            0 :       gfc_error ("!$OMP ATOMIC with ALLOCATABLE variable at %L",
   12331            0 :                  &stmt->expr1->where);
   12332            0 :       return;
   12333              :     }
   12334              : 
   12335              :   /* Should be diagnosed above already. */
   12336         2696 :   gcc_assert (tailing_stmt == NULL);
   12337              : 
   12338         2696 :   var = stmt->expr1->symtree->n.sym;
   12339         2696 :   stmt_expr2 = is_conversion (stmt->expr2, true, true);
   12340         2696 :   if (stmt_expr2 == NULL)
   12341         2540 :     stmt_expr2 = stmt->expr2;
   12342              : 
   12343         2696 :   switch (aop)
   12344              :     {
   12345          506 :     case GFC_OMP_ATOMIC_READ:
   12346          506 :       if (stmt_expr2->expr_type != EXPR_VARIABLE)
   12347            0 :         gfc_error ("!$OMP ATOMIC READ statement must read from a scalar "
   12348              :                    "variable of intrinsic type at %L", &stmt_expr2->where);
   12349              :       return;
   12350          426 :     case GFC_OMP_ATOMIC_WRITE:
   12351          426 :       if (expr_references_sym (stmt_expr2, var, NULL))
   12352            0 :         gfc_error ("expr in !$OMP ATOMIC WRITE assignment var = expr "
   12353              :                    "must be scalar and cannot reference var at %L",
   12354              :                    &stmt_expr2->where);
   12355              :       return;
   12356         1764 :     default:
   12357         1764 :       break;
   12358              :     }
   12359              : 
   12360         1764 :   if (atomic_code->ext.omp_clauses->capture)
   12361              :     {
   12362          588 :       if (!is_scalar_intrinsic_expr (capture_stmt->expr1, true, false))
   12363              :         {
   12364            0 :           gfc_error ("!$OMP ATOMIC capture-statement must set a scalar "
   12365              :                      "variable of intrinsic type at %L",
   12366            0 :                      &capture_stmt->expr1->where);
   12367            0 :           return;
   12368              :         }
   12369              : 
   12370          588 :       if (!is_scalar_intrinsic_expr (capture_stmt->expr2, true, true))
   12371              :         {
   12372            2 :           gfc_error ("!$OMP ATOMIC capture-statement requires a scalar variable"
   12373            2 :                      " of intrinsic type at %L", &capture_stmt->expr2->where);
   12374            2 :           return;
   12375              :         }
   12376          586 :       capt_expr2 = is_conversion (capture_stmt->expr2, true, true);
   12377          586 :       if (capt_expr2 == NULL)
   12378          564 :         capt_expr2 = capture_stmt->expr2;
   12379              : 
   12380          586 :       if (capt_expr2->symtree->n.sym != var)
   12381              :         {
   12382            1 :           gfc_error ("!$OMP ATOMIC CAPTURE capture statement reads from "
   12383              :                      "different variable than update statement writes "
   12384              :                      "into at %L", &capture_stmt->expr2->where);
   12385            1 :               return;
   12386              :         }
   12387              :     }
   12388              : 
   12389         1761 :   if (atomic_code->ext.omp_clauses->compare)
   12390              :     {
   12391          150 :       gfc_expr *var_expr;
   12392          150 :       if (comp_cond->value.op.op1->expr_type == EXPR_VARIABLE)
   12393              :         var_expr = comp_cond->value.op.op1;
   12394              :       else
   12395           12 :         var_expr = comp_cond->value.op.op1->value.function.actual->expr;
   12396          150 :       if (var_expr->symtree->n.sym != var)
   12397              :         {
   12398            2 :           gfc_error ("For !$OMP ATOMIC COMPARE, the first operand in comparison"
   12399              :                      " at %L must be the variable %qs that the update statement"
   12400              :                      " writes into at %L", &var_expr->where, var->name,
   12401            2 :                      &stmt->expr1->where);
   12402            2 :           return;
   12403              :         }
   12404          148 :       if (stmt_expr2->rank != 0 || expr_references_sym (stmt_expr2, var, NULL))
   12405              :         {
   12406            1 :           gfc_error ("expr in !$OMP ATOMIC COMPARE assignment var = expr "
   12407              :                      "must be scalar and cannot reference var at %L",
   12408              :                      &stmt_expr2->where);
   12409            1 :           return;
   12410              :         }
   12411              :     }
   12412         1611 :   else if (atomic_code->ext.omp_clauses->capture
   12413         1611 :            && !expr_references_sym (stmt_expr2, var, NULL))
   12414           22 :     atomic_code->ext.omp_clauses->atomic_op
   12415           22 :       = (gfc_omp_atomic_op) (atomic_code->ext.omp_clauses->atomic_op
   12416              :                              | GFC_OMP_ATOMIC_SWAP);
   12417         1589 :   else if (stmt_expr2->expr_type == EXPR_OP)
   12418              :     {
   12419         1233 :       gfc_expr *v = NULL, *e, *c;
   12420         1233 :       gfc_intrinsic_op op = stmt_expr2->value.op.op;
   12421         1233 :       gfc_intrinsic_op alt_op = INTRINSIC_NONE;
   12422              : 
   12423         1233 :       if (atomic_code->ext.omp_clauses->fail != OMP_MEMORDER_UNSET)
   12424            3 :         gfc_error ("!$OMP ATOMIC UPDATE at %L with FAIL clause requires either"
   12425              :                    " the COMPARE clause or using the intrinsic MIN/MAX "
   12426              :                    "procedure", &atomic_code->loc);
   12427         1233 :       switch (op)
   12428              :         {
   12429          746 :         case INTRINSIC_PLUS:
   12430          746 :           alt_op = INTRINSIC_MINUS;
   12431          746 :           break;
   12432           94 :         case INTRINSIC_TIMES:
   12433           94 :           alt_op = INTRINSIC_DIVIDE;
   12434           94 :           break;
   12435          120 :         case INTRINSIC_MINUS:
   12436          120 :           alt_op = INTRINSIC_PLUS;
   12437          120 :           break;
   12438           94 :         case INTRINSIC_DIVIDE:
   12439           94 :           alt_op = INTRINSIC_TIMES;
   12440           94 :           break;
   12441              :         case INTRINSIC_AND:
   12442              :         case INTRINSIC_OR:
   12443              :           break;
   12444           43 :         case INTRINSIC_EQV:
   12445           43 :           alt_op = INTRINSIC_NEQV;
   12446           43 :           break;
   12447           43 :         case INTRINSIC_NEQV:
   12448           43 :           alt_op = INTRINSIC_EQV;
   12449           43 :           break;
   12450            1 :         default:
   12451            1 :           gfc_error ("!$OMP ATOMIC assignment operator must be binary "
   12452              :                      "+, *, -, /, .AND., .OR., .EQV. or .NEQV. at %L",
   12453              :                      &stmt_expr2->where);
   12454            1 :           return;
   12455              :         }
   12456              : 
   12457              :       /* Check for var = var op expr resp. var = expr op var where
   12458              :          expr doesn't reference var and var op expr is mathematically
   12459              :          equivalent to var op (expr) resp. expr op var equivalent to
   12460              :          (expr) op var.  We rely here on the fact that the matcher
   12461              :          for x op1 y op2 z where op1 and op2 have equal precedence
   12462              :          returns (x op1 y) op2 z.  */
   12463         1232 :       e = stmt_expr2->value.op.op2;
   12464         1232 :       if (e->expr_type == EXPR_VARIABLE
   12465          288 :           && e->symtree != NULL
   12466          288 :           && e->symtree->n.sym == var)
   12467              :         v = e;
   12468         1003 :       else if ((c = is_conversion (e, false, true)) != NULL
   12469           48 :                && c->expr_type == EXPR_VARIABLE
   12470           48 :                && c->symtree != NULL
   12471         1051 :                && c->symtree->n.sym == var)
   12472              :         v = c;
   12473              :       else
   12474              :         {
   12475          955 :           gfc_expr **p = NULL, **q;
   12476         1053 :           for (q = &stmt_expr2->value.op.op1; (e = *q) != NULL; )
   12477         1053 :             if (e->expr_type == EXPR_VARIABLE
   12478          952 :                 && e->symtree != NULL
   12479          952 :                 && e->symtree->n.sym == var)
   12480              :               {
   12481              :                 v = e;
   12482              :                 break;
   12483              :               }
   12484          101 :             else if ((c = is_conversion (e, false, true)) != NULL)
   12485           60 :               q = &e->value.function.actual->expr;
   12486           41 :             else if (e->expr_type != EXPR_OP
   12487           41 :                      || (e->value.op.op != op
   12488           15 :                          && e->value.op.op != alt_op)
   12489           38 :                      || e->rank != 0)
   12490              :               break;
   12491              :             else
   12492              :               {
   12493           38 :                 p = q;
   12494           38 :                 q = &e->value.op.op1;
   12495              :               }
   12496              : 
   12497          955 :           if (v == NULL)
   12498              :             {
   12499            3 :               gfc_error ("!$OMP ATOMIC assignment must be var = var op expr "
   12500              :                          "or var = expr op var at %L", &stmt_expr2->where);
   12501            3 :               return;
   12502              :             }
   12503              : 
   12504          952 :           if (p != NULL)
   12505              :             {
   12506           38 :               e = *p;
   12507           38 :               switch (e->value.op.op)
   12508              :                 {
   12509            8 :                 case INTRINSIC_MINUS:
   12510            8 :                 case INTRINSIC_DIVIDE:
   12511            8 :                 case INTRINSIC_EQV:
   12512            8 :                 case INTRINSIC_NEQV:
   12513            8 :                   gfc_error ("!$OMP ATOMIC var = var op expr not "
   12514              :                              "mathematically equivalent to var = var op "
   12515              :                              "(expr) at %L", &stmt_expr2->where);
   12516            8 :                   break;
   12517              :                 default:
   12518              :                   break;
   12519              :                 }
   12520              : 
   12521              :               /* Canonicalize into var = var op (expr).  */
   12522           38 :               *p = e->value.op.op2;
   12523           38 :               e->value.op.op2 = stmt_expr2;
   12524           38 :               e->ts = stmt_expr2->ts;
   12525           38 :               if (stmt->expr2 == stmt_expr2)
   12526           26 :                 stmt->expr2 = stmt_expr2 = e;
   12527              :               else
   12528           12 :                 stmt->expr2->value.function.actual->expr = stmt_expr2 = e;
   12529              : 
   12530           38 :               if (!gfc_compare_types (&stmt_expr2->value.op.op1->ts,
   12531              :                                       &stmt_expr2->ts))
   12532              :                 {
   12533           24 :                   for (p = &stmt_expr2->value.op.op1; *p != v;
   12534           12 :                        p = &(*p)->value.function.actual->expr)
   12535              :                     ;
   12536           12 :                   *p = NULL;
   12537           12 :                   gfc_free_expr (stmt_expr2->value.op.op1);
   12538           12 :                   stmt_expr2->value.op.op1 = v;
   12539           12 :                   gfc_convert_type (v, &stmt_expr2->ts, 2);
   12540              :                 }
   12541              :             }
   12542              :         }
   12543              : 
   12544         1229 :       if (e->rank != 0 || expr_references_sym (stmt->expr2, var, v))
   12545              :         {
   12546            1 :           gfc_error ("expr in !$OMP ATOMIC assignment var = var op expr "
   12547              :                      "must be scalar and cannot reference var at %L",
   12548              :                      &stmt_expr2->where);
   12549            1 :           return;
   12550              :         }
   12551              :     }
   12552          356 :   else if (stmt_expr2->expr_type == EXPR_FUNCTION
   12553          355 :            && stmt_expr2->value.function.isym != NULL
   12554          355 :            && stmt_expr2->value.function.esym == NULL
   12555          355 :            && stmt_expr2->value.function.actual != NULL
   12556          355 :            && stmt_expr2->value.function.actual->next != NULL)
   12557              :     {
   12558          355 :       gfc_actual_arglist *arg, *var_arg;
   12559              : 
   12560          355 :       switch (stmt_expr2->value.function.isym->id)
   12561              :         {
   12562              :         case GFC_ISYM_MIN:
   12563              :         case GFC_ISYM_MAX:
   12564              :           break;
   12565          147 :         case GFC_ISYM_IAND:
   12566          147 :         case GFC_ISYM_IOR:
   12567          147 :         case GFC_ISYM_IEOR:
   12568          147 :           if (stmt_expr2->value.function.actual->next->next != NULL)
   12569              :             {
   12570            0 :               gfc_error ("!$OMP ATOMIC assignment intrinsic IAND, IOR "
   12571              :                          "or IEOR must have two arguments at %L",
   12572              :                          &stmt_expr2->where);
   12573            0 :               return;
   12574              :             }
   12575              :           break;
   12576            1 :         default:
   12577            1 :           gfc_error ("!$OMP ATOMIC assignment intrinsic must be "
   12578              :                      "MIN, MAX, IAND, IOR or IEOR at %L",
   12579              :                      &stmt_expr2->where);
   12580            1 :           return;
   12581              :         }
   12582              : 
   12583              :       var_arg = NULL;
   12584         1088 :       for (arg = stmt_expr2->value.function.actual; arg; arg = arg->next)
   12585              :         {
   12586          741 :           gfc_expr *e = NULL;
   12587          741 :           if (arg == stmt_expr2->value.function.actual
   12588          387 :               || (var_arg == NULL && arg->next == NULL))
   12589              :             {
   12590          527 :               e = is_conversion (arg->expr, false, true);
   12591          527 :               if (!e)
   12592          514 :                 e = arg->expr;
   12593          527 :               if (e->expr_type == EXPR_VARIABLE
   12594          453 :                   && e->symtree != NULL
   12595          453 :                   && e->symtree->n.sym == var)
   12596          741 :                 var_arg = arg;
   12597              :             }
   12598          741 :           if ((!var_arg || !e) && expr_references_sym (arg->expr, var, NULL))
   12599              :             {
   12600            7 :               gfc_error ("!$OMP ATOMIC intrinsic arguments except one must "
   12601              :                          "not reference %qs at %L",
   12602              :                          var->name, &arg->expr->where);
   12603            7 :               return;
   12604              :             }
   12605          734 :           if (arg->expr->rank != 0)
   12606              :             {
   12607            0 :               gfc_error ("!$OMP ATOMIC intrinsic arguments must be scalar "
   12608              :                          "at %L", &arg->expr->where);
   12609            0 :               return;
   12610              :             }
   12611              :         }
   12612              : 
   12613          347 :       if (var_arg == NULL)
   12614              :         {
   12615            1 :           gfc_error ("First or last !$OMP ATOMIC intrinsic argument must "
   12616              :                      "be %qs at %L", var->name, &stmt_expr2->where);
   12617            1 :           return;
   12618              :         }
   12619              : 
   12620          346 :       if (var_arg != stmt_expr2->value.function.actual)
   12621              :         {
   12622              :           /* Canonicalize, so that var comes first.  */
   12623          172 :           gcc_assert (var_arg->next == NULL);
   12624              :           for (arg = stmt_expr2->value.function.actual;
   12625          185 :                arg->next != var_arg; arg = arg->next)
   12626              :             ;
   12627          172 :           var_arg->next = stmt_expr2->value.function.actual;
   12628          172 :           stmt_expr2->value.function.actual = var_arg;
   12629          172 :           arg->next = NULL;
   12630              :         }
   12631              :     }
   12632              :   else
   12633            1 :     gfc_error ("!$OMP ATOMIC assignment must have an operator or "
   12634              :                "intrinsic on right hand side at %L", &stmt_expr2->where);
   12635              :   return;
   12636              : 
   12637            4 : unexpected:
   12638            4 :   gfc_error ("unexpected !$OMP ATOMIC expression at %L",
   12639              :              loc ? loc : &code->loc);
   12640            4 :   return;
   12641              : }
   12642              : 
   12643              : 
   12644              : static struct fortran_omp_context
   12645              : {
   12646              :   gfc_code *code;
   12647              :   hash_set<gfc_symbol *> *sharing_clauses;
   12648              :   hash_set<gfc_symbol *> *private_iterators;
   12649              :   struct fortran_omp_context *previous;
   12650              :   bool is_openmp;
   12651              : } *omp_current_ctx;
   12652              : static gfc_code *omp_current_do_code;
   12653              : static int omp_current_do_collapse;
   12654              : 
   12655              : /* Forward declaration for mutually recursive functions.  */
   12656              : static gfc_code *
   12657              : find_nested_loop_in_block (gfc_code *block);
   12658              : 
   12659              : /* Return the first nested DO loop in CHAIN, or NULL if there
   12660              :    isn't one.  Does no error checking on intervening code.  */
   12661              : 
   12662              : static gfc_code *
   12663        28283 : find_nested_loop_in_chain (gfc_code *chain)
   12664              : {
   12665        28283 :   gfc_code *code;
   12666              : 
   12667        28283 :   if (!chain)
   12668              :     return NULL;
   12669              : 
   12670        32444 :   for (code = chain; code; code = code->next)
   12671        32023 :     switch (code->op)
   12672              :       {
   12673              :       case EXEC_DO:
   12674              :       case EXEC_OMP_TILE:
   12675              :       case EXEC_OMP_UNROLL:
   12676              :         return code;
   12677          621 :       case EXEC_BLOCK:
   12678          621 :         if (gfc_code *c = find_nested_loop_in_block (code))
   12679              :           return c;
   12680              :         break;
   12681              :       default:
   12682              :         break;
   12683              :       }
   12684              :   return NULL;
   12685              : }
   12686              : 
   12687              : /* Return the first nested DO loop in BLOCK, or NULL if there
   12688              :    isn't one.  Does no error checking on intervening code.  */
   12689              : static gfc_code *
   12690          939 : find_nested_loop_in_block (gfc_code *block)
   12691              : {
   12692          939 :   gfc_namespace *ns;
   12693          939 :   gcc_assert (block->op == EXEC_BLOCK);
   12694          939 :   ns = block->ext.block.ns;
   12695          939 :   gcc_assert (ns);
   12696          939 :   return find_nested_loop_in_chain (ns->code);
   12697              : }
   12698              : 
   12699              : void
   12700         5655 : gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns)
   12701              : {
   12702         5655 :   if (code->block->next && code->block->next->op == EXEC_DO)
   12703              :     {
   12704         5301 :       int i;
   12705              : 
   12706         5301 :       omp_current_do_code = code->block->next;
   12707         5301 :       if (code->ext.omp_clauses->orderedc)
   12708          142 :         omp_current_do_collapse = code->ext.omp_clauses->orderedc;
   12709         5159 :       else if (code->ext.omp_clauses->collapse)
   12710         1228 :         omp_current_do_collapse = code->ext.omp_clauses->collapse;
   12711         3931 :       else if (code->ext.omp_clauses->sizes_list)
   12712          177 :         omp_current_do_collapse
   12713          177 :           = gfc_expr_list_len (code->ext.omp_clauses->sizes_list);
   12714              :       else
   12715         3754 :         omp_current_do_collapse = 1;
   12716         5301 :       if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN])
   12717              :         {
   12718              :           /* Checking that there is a matching EXEC_OMP_SCAN in the
   12719              :              innermost body cannot be deferred to resolve_omp_do because
   12720              :              we process directives nested in the loop before we get
   12721              :              there.  */
   12722           60 :           locus *loc
   12723              :             = &code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]->where;
   12724           60 :           gfc_code *c;
   12725              : 
   12726           80 :           for (i = 1, c = omp_current_do_code;
   12727           80 :                i < omp_current_do_collapse; i++)
   12728              :             {
   12729           22 :               c = find_nested_loop_in_chain (c->block->next);
   12730           22 :               if (!c || c->op != EXEC_DO || c->block == NULL)
   12731              :                 break;
   12732              :             }
   12733              : 
   12734              :           /* Skip this if we don't have enough nested loops.  That
   12735              :              problem will be diagnosed elsewhere.  */
   12736           60 :           if (c && c->op == EXEC_DO)
   12737              :             {
   12738           58 :               gfc_code *block = c->block ? c->block->next : NULL;
   12739           58 :               if (block && block->op != EXEC_OMP_SCAN)
   12740           54 :                 while (block && block->next
   12741           54 :                        && block->next->op != EXEC_OMP_SCAN)
   12742              :                   block = block->next;
   12743           43 :               if (!block
   12744           46 :                   || (block->op != EXEC_OMP_SCAN
   12745           43 :                       && (!block->next || block->next->op != EXEC_OMP_SCAN)))
   12746           19 :                 gfc_error ("With INSCAN at %L, expected loop body with "
   12747              :                            "!$OMP SCAN between two "
   12748              :                            "structured block sequences", loc);
   12749              :               else
   12750              :                 {
   12751           39 :                   if (block->op == EXEC_OMP_SCAN)
   12752            3 :                     gfc_warning (OPT_Wopenmp,
   12753              :                                  "!$OMP SCAN at %L with zero executable "
   12754              :                                  "statements in preceding structured block "
   12755              :                                  "sequence", &block->loc);
   12756           39 :                   if ((block->op == EXEC_OMP_SCAN && !block->next)
   12757           38 :                       || (block->next && block->next->op == EXEC_OMP_SCAN
   12758           36 :                           && !block->next->next))
   12759            3 :                     gfc_warning (OPT_Wopenmp,
   12760              :                                  "!$OMP SCAN at %L with zero executable "
   12761              :                                  "statements in succeeding structured block "
   12762              :                                  "sequence", block->op == EXEC_OMP_SCAN
   12763            1 :                                  ? &block->loc : &block->next->loc);
   12764              :                 }
   12765           58 :               if (block && block->op != EXEC_OMP_SCAN)
   12766           43 :                 block = block->next;
   12767           46 :               if (block && block->op == EXEC_OMP_SCAN)
   12768              :                 /* Mark 'omp scan' as checked; flag will be unset later.  */
   12769           39 :                 block->ext.omp_clauses->if_present = true;
   12770              :             }
   12771              :         }
   12772              :     }
   12773         5655 :   gfc_resolve_blocks (code->block, ns);
   12774         5655 :   omp_current_do_collapse = 0;
   12775         5655 :   omp_current_do_code = NULL;
   12776         5655 : }
   12777              : 
   12778              : 
   12779              : void
   12780         6271 : gfc_resolve_omp_parallel_blocks (gfc_code *code, gfc_namespace *ns)
   12781              : {
   12782         6271 :   struct fortran_omp_context ctx;
   12783         6271 :   gfc_omp_clauses *omp_clauses = code->ext.omp_clauses;
   12784         6271 :   gfc_omp_namelist *n;
   12785              : 
   12786         6271 :   ctx.code = code;
   12787         6271 :   ctx.sharing_clauses = new hash_set<gfc_symbol *>;
   12788         6271 :   ctx.private_iterators = new hash_set<gfc_symbol *>;
   12789         6271 :   ctx.previous = omp_current_ctx;
   12790         6271 :   ctx.is_openmp = true;
   12791         6271 :   omp_current_ctx = &ctx;
   12792              : 
   12793       250840 :   for (enum gfc_omp_list_type list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   12794       244569 :        list = gfc_omp_list_type (list + 1))
   12795       244569 :     switch (list)
   12796              :       {
   12797        62710 :       case OMP_LIST_SHARED:
   12798        62710 :       case OMP_LIST_PRIVATE:
   12799        62710 :       case OMP_LIST_FIRSTPRIVATE:
   12800        62710 :       case OMP_LIST_LASTPRIVATE:
   12801        62710 :       case OMP_LIST_REDUCTION:
   12802        62710 :       case OMP_LIST_REDUCTION_INSCAN:
   12803        62710 :       case OMP_LIST_REDUCTION_TASK:
   12804        62710 :       case OMP_LIST_IN_REDUCTION:
   12805        62710 :       case OMP_LIST_TASK_REDUCTION:
   12806        62710 :       case OMP_LIST_LINEAR:
   12807        71780 :         for (n = omp_clauses->lists[list]; n; n = n->next)
   12808         9070 :           ctx.sharing_clauses->add (n->sym);
   12809              :         break;
   12810              :       default:
   12811              :         break;
   12812              :       }
   12813              : 
   12814         6271 :   switch (code->op)
   12815              :     {
   12816         2471 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   12817         2471 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
   12818         2471 :     case EXEC_OMP_MASKED_TASKLOOP:
   12819         2471 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
   12820         2471 :     case EXEC_OMP_MASTER_TASKLOOP:
   12821         2471 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
   12822         2471 :     case EXEC_OMP_PARALLEL_DO:
   12823         2471 :     case EXEC_OMP_PARALLEL_DO_SIMD:
   12824         2471 :     case EXEC_OMP_PARALLEL_LOOP:
   12825         2471 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
   12826         2471 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
   12827         2471 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
   12828         2471 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
   12829         2471 :     case EXEC_OMP_TARGET_PARALLEL_DO:
   12830         2471 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   12831         2471 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
   12832         2471 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   12833         2471 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   12834         2471 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   12835         2471 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   12836         2471 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
   12837         2471 :     case EXEC_OMP_TASKLOOP:
   12838         2471 :     case EXEC_OMP_TASKLOOP_SIMD:
   12839         2471 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
   12840         2471 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   12841         2471 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   12842         2471 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
   12843         2471 :     case EXEC_OMP_TEAMS_LOOP:
   12844         2471 :       gfc_resolve_omp_do_blocks (code, ns);
   12845         2471 :       break;
   12846         3800 :     default:
   12847         3800 :       gfc_resolve_blocks (code->block, ns);
   12848              :     }
   12849              : 
   12850         6271 :   omp_current_ctx = ctx.previous;
   12851        12542 :   delete ctx.sharing_clauses;
   12852        12542 :   delete ctx.private_iterators;
   12853         6271 : }
   12854              : 
   12855              : 
   12856              : /* Save and clear openmp.cc private state.  */
   12857              : 
   12858              : void
   12859       309956 : gfc_omp_save_and_clear_state (struct gfc_omp_saved_state *state)
   12860              : {
   12861       309956 :   state->ptrs[0] = omp_current_ctx;
   12862       309956 :   state->ptrs[1] = omp_current_do_code;
   12863       309956 :   state->ints[0] = omp_current_do_collapse;
   12864       309956 :   omp_current_ctx = NULL;
   12865       309956 :   omp_current_do_code = NULL;
   12866       309956 :   omp_current_do_collapse = 0;
   12867       309956 : }
   12868              : 
   12869              : 
   12870              : /* Restore openmp.cc private state from the saved state.  */
   12871              : 
   12872              : void
   12873       309955 : gfc_omp_restore_state (struct gfc_omp_saved_state *state)
   12874              : {
   12875       309955 :   omp_current_ctx = (struct fortran_omp_context *) state->ptrs[0];
   12876       309955 :   omp_current_do_code = (gfc_code *) state->ptrs[1];
   12877       309955 :   omp_current_do_collapse = state->ints[0];
   12878       309955 : }
   12879              : 
   12880              : 
   12881              : /* Note a DO iterator variable.  This is special in !$omp parallel
   12882              :    construct, where they are predetermined private.  */
   12883              : 
   12884              : void
   12885        34106 : gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause)
   12886              : {
   12887        34106 :   if (omp_current_ctx == NULL)
   12888              :     return;
   12889              : 
   12890        13333 :   int i = omp_current_do_collapse;
   12891        13333 :   gfc_code *c = omp_current_do_code;
   12892              : 
   12893        13333 :   if (sym->attr.threadprivate)
   12894              :     return;
   12895              : 
   12896              :   /* !$omp do and !$omp parallel do iteration variable is predetermined
   12897              :      private just in the !$omp do resp. !$omp parallel do construct,
   12898              :      with no implications for the outer parallel constructs.  */
   12899              : 
   12900        18272 :   while (i-- >= 1 && c)
   12901              :     {
   12902         9817 :       if (code == c)
   12903              :         return;
   12904         4939 :       c = find_nested_loop_in_chain (c->block->next);
   12905         4939 :       if (c && (c->op == EXEC_OMP_TILE || c->op == EXEC_OMP_UNROLL))
   12906              :         return;
   12907              :     }
   12908              : 
   12909              :   /* An openacc context may represent a data clause.  Abort if so.  */
   12910         8455 :   if (!omp_current_ctx->is_openmp && !oacc_is_loop (omp_current_ctx->code))
   12911              :     return;
   12912              : 
   12913         7477 :   if (omp_current_ctx->sharing_clauses->contains (sym))
   12914              :     return;
   12915              : 
   12916         6468 :   if (! omp_current_ctx->private_iterators->add (sym) && add_clause)
   12917              :     {
   12918         6278 :       gfc_omp_clauses *omp_clauses = omp_current_ctx->code->ext.omp_clauses;
   12919         6278 :       gfc_omp_namelist *p;
   12920              : 
   12921         6278 :       if (sym->attr.pointer && omp_current_ctx->is_openmp)
   12922            2 :         gfc_warning (OPT_Wopenmp,
   12923              :                      "DO iteration variable %qs at %L has the POINTER "
   12924              :                      "attribute, but the association status of its private "
   12925              :                      "copy in the enclosing OpenMP construct is undefined",
   12926            2 :                      sym->name, &code->ext.iterator->var->where);
   12927              : 
   12928         6278 :       p = gfc_get_omp_namelist ();
   12929         6278 :       p->sym = sym;
   12930         6278 :       p->where = omp_current_ctx->code->loc;
   12931         6278 :       p->next = omp_clauses->lists[OMP_LIST_PRIVATE];
   12932         6278 :       omp_clauses->lists[OMP_LIST_PRIVATE] = p;
   12933              :     }
   12934              : }
   12935              : 
   12936              : static void
   12937          808 : handle_local_var (gfc_symbol *sym)
   12938              : {
   12939          808 :   if (sym->attr.flavor != FL_VARIABLE
   12940          198 :       || sym->as != NULL
   12941          151 :       || (sym->ts.type != BT_INTEGER && sym->ts.type != BT_REAL))
   12942              :     return;
   12943           72 :   gfc_resolve_do_iterator (sym->ns->code, sym, false);
   12944              : }
   12945              : 
   12946              : void
   12947       359709 : gfc_resolve_omp_local_vars (gfc_namespace *ns)
   12948              : {
   12949       359709 :   if (omp_current_ctx)
   12950          478 :     gfc_traverse_ns (ns, handle_local_var);
   12951       359709 : }
   12952              : 
   12953              : 
   12954              : /* Error checking on intervening code uses a code walker.  */
   12955              : 
   12956              : struct icode_error_state
   12957              : {
   12958              :   const char *name;
   12959              :   bool errorp;
   12960              :   gfc_code *nested;
   12961              :   gfc_code *next;
   12962              : };
   12963              : 
   12964              : static int
   12965          944 : icode_code_error_callback (gfc_code **codep,
   12966              :                            int *walk_subtrees ATTRIBUTE_UNUSED, void *opaque)
   12967              : {
   12968          944 :   gfc_code *code = *codep;
   12969          944 :   icode_error_state *state = (icode_error_state *)opaque;
   12970              : 
   12971              :   /* gfc_code_walker walks down CODE's next chain as well as
   12972              :      walking things that are actually nested in CODE.  We need to
   12973              :      special-case traversal of outer blocks, so stop immediately if we
   12974              :      are heading down such a next chain.  */
   12975          944 :   if (code == state->next)
   12976              :     return 1;
   12977              : 
   12978          647 :   switch (code->op)
   12979              :     {
   12980            1 :     case EXEC_DO:
   12981            1 :     case EXEC_DO_WHILE:
   12982            1 :     case EXEC_DO_CONCURRENT:
   12983            1 :       gfc_error ("%s cannot contain loop in intervening code at %L",
   12984              :                  state->name, &code->loc);
   12985            1 :       state->errorp = true;
   12986            1 :       break;
   12987            0 :     case EXEC_CYCLE:
   12988            0 :     case EXEC_EXIT:
   12989              :       /* Errors have already been diagnosed in match_exit_cycle.  */
   12990            0 :       state->errorp = true;
   12991            0 :       break;
   12992              :     case EXEC_OMP_ASSUME:
   12993              :     case EXEC_OMP_METADIRECTIVE:
   12994              :       /* Per OpenMP 6.0, some non-executable directives are allowed in
   12995              :          intervening code.  */
   12996              :       break;
   12997          477 :     case EXEC_CALL:
   12998              :       /* Per OpenMP 5.2, the "omp_" prefix is reserved, so we don't have to
   12999              :          consider the possibility that some locally-bound definition
   13000              :          overrides the runtime routine.  */
   13001          477 :       if (code->resolved_sym
   13002          477 :           && omp_runtime_api_procname (code->resolved_sym->name))
   13003              :         {
   13004            1 :           gfc_error ("%s cannot contain OpenMP API call in intervening code "
   13005              :                      "at %L",
   13006              :                  state->name, &code->loc);
   13007            1 :           state->errorp = true;
   13008              :         }
   13009              :       break;
   13010          168 :     default:
   13011          168 :       if (code->op >= EXEC_OMP_FIRST_OPENMP_EXEC
   13012          168 :           && code->op <= EXEC_OMP_LAST_OPENMP_EXEC)
   13013              :         {
   13014            2 :           gfc_error ("%s cannot contain OpenMP directive in intervening code "
   13015              :                      "at %L",
   13016              :                      state->name, &code->loc);
   13017            2 :           state->errorp = true;
   13018              :         }
   13019              :     }
   13020              :   return 0;
   13021              : }
   13022              : 
   13023              : static int
   13024         1081 : icode_expr_error_callback (gfc_expr **expr,
   13025              :                            int *walk_subtrees ATTRIBUTE_UNUSED, void *opaque)
   13026              : {
   13027         1081 :   icode_error_state *state = (icode_error_state *)opaque;
   13028              : 
   13029         1081 :   switch ((*expr)->expr_type)
   13030              :     {
   13031              :       /* As for EXPR_CALL with "omp_"-prefixed symbols.  */
   13032            2 :     case EXPR_FUNCTION:
   13033            2 :       {
   13034            2 :         gfc_symbol *sym = (*expr)->value.function.esym;
   13035            2 :         if (sym && omp_runtime_api_procname (sym->name))
   13036              :           {
   13037            1 :             gfc_error ("%s cannot contain OpenMP API call in intervening code "
   13038              :                        "at %L",
   13039            1 :                        state->name, &((*expr)->where));
   13040            1 :             state->errorp = true;
   13041              :           }
   13042              :         }
   13043              : 
   13044              :       break;
   13045              :     default:
   13046              :       break;
   13047              :     }
   13048              : 
   13049              :   /* FIXME: The description of canonical loop form in the OpenMP standard
   13050              :      also says "array expressions" are not permitted in intervening code.
   13051              :      That term is not defined in either the OpenMP spec or the Fortran
   13052              :      standard, although the latter uses it informally to refer to any
   13053              :      expression that is not scalar-valued.  It is also apparently not the
   13054              :      thing GCC internally calls EXPR_ARRAY.  It seems the intent of the
   13055              :      OpenMP restriction is to disallow elemental operations/intrinsics
   13056              :      (including things that are not expressions, like assignment
   13057              :      statements) that generate implicit loops over array operands
   13058              :      (even if the result is a scalar), but even if the spec said
   13059              :      that there is no list of all the cases that would be forbidden.
   13060              :      This is OpenMP issue 3326.  */
   13061              : 
   13062         1081 :   return 0;
   13063              : }
   13064              : 
   13065              : static void
   13066          267 : diagnose_intervening_code_errors_1 (gfc_code *chain,
   13067              :                                     struct icode_error_state *state)
   13068              : {
   13069          267 :   gfc_code *code;
   13070         1080 :   for (code = chain; code; code = code->next)
   13071              :     {
   13072          813 :       if (code == state->nested)
   13073              :         /* Do not walk the nested loop or its body, we are only
   13074              :            interested in intervening code.  */
   13075              :         ;
   13076          636 :       else if (code->op == EXEC_BLOCK
   13077          636 :                && find_nested_loop_in_block (code) == state->nested)
   13078              :         /* This block contains the nested loop, recurse on its
   13079              :            statements.  */
   13080              :         {
   13081           90 :           gfc_namespace* ns = code->ext.block.ns;
   13082           90 :           diagnose_intervening_code_errors_1 (ns->code, state);
   13083              :         }
   13084              :       else
   13085              :         /* Treat the whole statement as a unit.  */
   13086              :         {
   13087          546 :           gfc_code *temp = state->next;
   13088          546 :           state->next = code->next;
   13089          546 :           gfc_code_walker (&code, icode_code_error_callback,
   13090              :                            icode_expr_error_callback, state);
   13091          546 :           state->next = temp;
   13092              :         }
   13093              :     }
   13094          267 : }
   13095              : 
   13096              : /* Diagnose intervening code errors in BLOCK with nested loop NESTED.
   13097              :    NAME is the user-friendly name of the OMP directive, used for error
   13098              :    messages.  Returns true if any error was found.  */
   13099              : static bool
   13100          177 : diagnose_intervening_code_errors (gfc_code *chain, const char *name,
   13101              :                                   gfc_code *nested)
   13102              : {
   13103          177 :   struct icode_error_state state;
   13104          177 :   state.name = name;
   13105          177 :   state.errorp = false;
   13106          177 :   state.nested = nested;
   13107          177 :   state.next = NULL;
   13108            0 :   diagnose_intervening_code_errors_1 (chain, &state);
   13109          177 :   return state.errorp;
   13110              : }
   13111              : 
   13112              : /* Helper function for restructure_intervening_code:  wrap CHAIN in
   13113              :    a marker to indicate that it is a structured block sequence.  That
   13114              :    information will be used later on (in omp-low.cc) for error checking.  */
   13115              : static gfc_code *
   13116          461 : make_structured_block (gfc_code *chain)
   13117              : {
   13118          461 :   gcc_assert (chain);
   13119          461 :   gfc_namespace *ns = gfc_build_block_ns (gfc_current_ns);
   13120          461 :   gfc_code *result = gfc_get_code (EXEC_BLOCK);
   13121          461 :   result->op = EXEC_BLOCK;
   13122          461 :   result->ext.block.ns = ns;
   13123          461 :   result->ext.block.assoc = NULL;
   13124          461 :   result->loc = chain->loc;
   13125          461 :   ns->omp_structured_block = 1;
   13126          461 :   ns->code = chain;
   13127          461 :   return result;
   13128              : }
   13129              : 
   13130              : /* Push intervening code surrounding a loop, including nested scopes,
   13131              :    into the body of the loop.  CHAINP is the pointer to the head of
   13132              :    the next-chain to scan, OUTER_LOOP is the EXEC_DO for the next outer
   13133              :    loop level, and COLLAPSE is the number of nested loops we need to
   13134              :    process.
   13135              :    Note that CHAINP may point at outer_loop->block->next when we
   13136              :    are scanning the body of a loop, but if there is an intervening block
   13137              :    CHAINP points into the block's chain rather than its enclosing outer
   13138              :    loop.  This is why OUTER_LOOP is passed separately.  */
   13139              : static gfc_code *
   13140         7529 : restructure_intervening_code (gfc_code **chainp, gfc_code *outer_loop,
   13141              :                               int count)
   13142              : {
   13143         7529 :   gfc_code *code;
   13144         7529 :   gfc_code *head = *chainp;
   13145         7529 :   gfc_code *tail = NULL;
   13146         7529 :   gfc_code *innermost_loop = NULL;
   13147              : 
   13148         7793 :   for (code = *chainp; code; code = code->next, chainp = &(*chainp)->next)
   13149              :     {
   13150         7793 :       if (code->op == EXEC_DO)
   13151              :         {
   13152              :           /* Cut CODE free from its chain, leaving the ends dangling.  */
   13153         7445 :           *chainp = NULL;
   13154         7445 :           tail = code->next;
   13155         7445 :           code->next = NULL;
   13156              : 
   13157         7445 :           if (count == 1)
   13158              :             innermost_loop = code;
   13159              :           else
   13160         2215 :             innermost_loop
   13161         2215 :               = restructure_intervening_code (&code->block->next,
   13162              :                                               code, count - 1);
   13163              :           break;
   13164              :         }
   13165          348 :       else if (code->op == EXEC_BLOCK
   13166          348 :                && find_nested_loop_in_block (code))
   13167              :         {
   13168           84 :           gfc_namespace *ns = code->ext.block.ns;
   13169              : 
   13170              :           /* Cut CODE free from its chain, leaving the ends dangling.  */
   13171           84 :           *chainp = NULL;
   13172           84 :           tail = code->next;
   13173           84 :           code->next = NULL;
   13174              : 
   13175           84 :           innermost_loop
   13176           84 :             = restructure_intervening_code (&ns->code, outer_loop,
   13177              :                                             count);
   13178              : 
   13179              :           /* At this point we have already pulled out the nested loop and
   13180              :              pointed outer_loop at it, and moved the intervening code that
   13181              :              was previously in the block into the body of innermost_loop.
   13182              :              Now we want to move the BLOCK itself so it wraps the entire
   13183              :              current body of innermost_loop.  */
   13184           84 :           ns->code = innermost_loop->block->next;
   13185           84 :           innermost_loop->block->next = code;
   13186           84 :           break;
   13187              :         }
   13188              :     }
   13189              : 
   13190         2299 :   gcc_assert (innermost_loop);
   13191              : 
   13192              :   /* Now we have split the intervening code into two parts:
   13193              :      head is the start of the part before the loop/block, terminating
   13194              :      at *chainp, and tail is the part after it.  Mark each part as
   13195              :      a structured block sequence, and splice the two parts around the
   13196              :      existing body of the innermost loop.  */
   13197         7529 :   if (head != code)
   13198              :     {
   13199          222 :       gfc_code *block = make_structured_block (head);
   13200          222 :       if (innermost_loop->block->next)
   13201          221 :         gfc_append_code (block, innermost_loop->block->next);
   13202          222 :       innermost_loop->block->next = block;
   13203              :     }
   13204         7529 :   if (tail)
   13205              :     {
   13206          239 :       gfc_code *block = make_structured_block (tail);
   13207          239 :       if (innermost_loop->block->next)
   13208          237 :         gfc_append_code (innermost_loop->block->next, block);
   13209              :       else
   13210            2 :         innermost_loop->block->next = block;
   13211              :     }
   13212              : 
   13213              :   /* For loops, finally splice CODE into OUTER_LOOP.  We already handled
   13214              :      relinking EXEC_BLOCK above.  */
   13215         7529 :   if (code->op == EXEC_DO && outer_loop)
   13216         7445 :     outer_loop->block->next = code;
   13217              : 
   13218         7529 :   return innermost_loop;
   13219              : }
   13220              : 
   13221              : /* CODE is an OMP loop construct.  Return true if VAR matches an iteration
   13222              :    variable outer to level DEPTH.  */
   13223              : static bool
   13224         8443 : is_outer_iteration_variable (gfc_code *code, int depth, gfc_symbol *var)
   13225              : {
   13226         8443 :   int i;
   13227         8443 :   gfc_code *do_code = code;
   13228              : 
   13229        13113 :   for (i = 1; i < depth; i++)
   13230              :     {
   13231         5171 :       do_code = find_nested_loop_in_chain (do_code->block->next);
   13232         5171 :       gcc_assert (do_code);
   13233         5171 :       if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
   13234              :         {
   13235           51 :           --i;
   13236           51 :           continue;
   13237              :         }
   13238         5120 :       gfc_symbol *ivar = do_code->ext.iterator->var->symtree->n.sym;
   13239         5120 :       if (var == ivar)
   13240              :         return true;
   13241              :     }
   13242              :   return false;
   13243              : }
   13244              : 
   13245              : /* Forward declaration for recursive functions.  */
   13246              : static gfc_code *
   13247              : check_nested_loop_in_block (gfc_code *block, gfc_expr *expr, gfc_symbol *sym,
   13248              :                             bool *bad);
   13249              : 
   13250              : /* Like find_nested_loop_in_chain, but additionally check that EXPR
   13251              :    does not reference any variables bound in intervening EXEC_BLOCKs
   13252              :    and that SYM is not bound in such intervening blocks.  Either EXPR or SYM
   13253              :    may be null.  Sets *BAD to true if either test fails.  */
   13254              : static gfc_code *
   13255        50177 : check_nested_loop_in_chain (gfc_code *chain, gfc_expr *expr, gfc_symbol *sym,
   13256              :                             bool *bad)
   13257              : {
   13258        53785 :   for (gfc_code *code = chain; code; code = code->next)
   13259              :     {
   13260        53497 :       if (code->op == EXEC_DO)
   13261              :         return code;
   13262         4127 :       else if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
   13263         1686 :         return check_nested_loop_in_chain (code->block->next, expr, sym, bad);
   13264         2441 :       else if (code->op == EXEC_BLOCK)
   13265              :         {
   13266          807 :           gfc_code *c = check_nested_loop_in_block (code, expr, sym, bad);
   13267          807 :           if (c)
   13268              :             return c;
   13269              :         }
   13270              :     }
   13271              :   return NULL;
   13272              : }
   13273              : 
   13274              : /* Code walker for block symtrees.  It doesn't take any kind of state
   13275              :    argument, so use a static variable.  */
   13276              : static struct check_nested_loop_in_block_state_t {
   13277              :   gfc_expr *expr;
   13278              :   gfc_symbol *sym;
   13279              :   bool *bad;
   13280              : } check_nested_loop_in_block_state;
   13281              : 
   13282              : static void
   13283          766 : check_nested_loop_in_block_symbol (gfc_symbol *sym)
   13284              : {
   13285          766 :   if (sym == check_nested_loop_in_block_state.sym
   13286          766 :       || (check_nested_loop_in_block_state.expr
   13287          567 :           && gfc_find_sym_in_expr (sym,
   13288              :                                    check_nested_loop_in_block_state.expr)))
   13289            5 :     *check_nested_loop_in_block_state.bad = true;
   13290          766 : }
   13291              : 
   13292              : /* Return the first nested DO loop in BLOCK, or NULL if there
   13293              :    isn't one.  Set *BAD to true if EXPR references any variables in BLOCK, or
   13294              :    SYM is bound in BLOCK.  Either EXPR or SYM may be null.  */
   13295              : static gfc_code *
   13296          807 : check_nested_loop_in_block (gfc_code *block, gfc_expr *expr,
   13297              :                             gfc_symbol *sym, bool *bad)
   13298              : {
   13299          807 :   gfc_namespace *ns;
   13300          807 :   gcc_assert (block->op == EXEC_BLOCK);
   13301          807 :   ns = block->ext.block.ns;
   13302          807 :   gcc_assert (ns);
   13303              : 
   13304              :   /* Skip the check if this block doesn't contain the nested loop, or
   13305              :      if we already know it's bad.  */
   13306          807 :   gfc_code *result = check_nested_loop_in_chain (ns->code, expr, sym, bad);
   13307          807 :   if (result && !*bad)
   13308              :     {
   13309          519 :       check_nested_loop_in_block_state.expr = expr;
   13310          519 :       check_nested_loop_in_block_state.sym = sym;
   13311          519 :       check_nested_loop_in_block_state.bad = bad;
   13312          519 :       gfc_traverse_ns (ns, check_nested_loop_in_block_symbol);
   13313          519 :       check_nested_loop_in_block_state.expr = NULL;
   13314          519 :       check_nested_loop_in_block_state.sym = NULL;
   13315          519 :       check_nested_loop_in_block_state.bad = NULL;
   13316              :     }
   13317          807 :   return result;
   13318              : }
   13319              : 
   13320              : /* CODE is an OMP loop construct.  Return true if EXPR references
   13321              :    any variables bound in intervening code, to level DEPTH.  */
   13322              : static bool
   13323        23797 : expr_uses_intervening_var (gfc_code *code, int depth, gfc_expr *expr)
   13324              : {
   13325        23797 :   int i;
   13326        23797 :   gfc_code *do_code = code;
   13327              : 
   13328        60802 :   for (i = 0; i < depth; i++)
   13329              :     {
   13330        37008 :       bool bad = false;
   13331        37008 :       do_code = check_nested_loop_in_chain (do_code->block->next,
   13332              :                                             expr, NULL, &bad);
   13333        37008 :       if (bad)
   13334            3 :         return true;
   13335              :     }
   13336              :   return false;
   13337              : }
   13338              : 
   13339              : /* CODE is an OMP loop construct.  Return true if SYM is bound in
   13340              :    intervening code, to level DEPTH.  */
   13341              : static bool
   13342         7942 : is_intervening_var (gfc_code *code, int depth, gfc_symbol *sym)
   13343              : {
   13344         7942 :   int i;
   13345         7942 :   gfc_code *do_code = code;
   13346              : 
   13347        20302 :   for (i = 0; i < depth; i++)
   13348              :     {
   13349        12362 :       bool bad = false;
   13350        12362 :       do_code = check_nested_loop_in_chain (do_code->block->next,
   13351              :                                             NULL, sym, &bad);
   13352        12362 :       if (bad)
   13353            2 :         return true;
   13354              :     }
   13355              :   return false;
   13356              : }
   13357              : 
   13358              : /* CODE is an OMP loop construct.  Return true if EXPR does not reference
   13359              :    any iteration variables outer to level DEPTH.  */
   13360              : static bool
   13361        24876 : expr_is_invariant (gfc_code *code, int depth, gfc_expr *expr)
   13362              : {
   13363        24876 :   int i;
   13364        24876 :   gfc_code *do_code = code;
   13365              : 
   13366        38627 :   for (i = 1; i < depth; i++)
   13367              :     {
   13368        14817 :       do_code = find_nested_loop_in_chain (do_code->block->next);
   13369        14817 :       gcc_assert (do_code);
   13370        14817 :       if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
   13371              :         {
   13372          136 :           --i;
   13373          136 :           continue;
   13374              :         }
   13375        14681 :       gfc_symbol *ivar = do_code->ext.iterator->var->symtree->n.sym;
   13376        14681 :       if (gfc_find_sym_in_expr (ivar, expr))
   13377              :         return false;
   13378              :     }
   13379              :   return true;
   13380              : }
   13381              : 
   13382              : /* CODE is an OMP loop construct.  Return true if EXPR matches one of the
   13383              :    canonical forms for a bound expression.  It may include references to
   13384              :    an iteration variable outer to level DEPTH; set OUTER_VARP if so.  */
   13385              : static bool
   13386        15875 : bound_expr_is_canonical (gfc_code *code, int depth, gfc_expr *expr,
   13387              :                          gfc_symbol **outer_varp)
   13388              : {
   13389        15875 :   gfc_expr *expr2 = NULL;
   13390              : 
   13391              :   /* Rectangular case.  */
   13392        15875 :   if (depth == 0 || expr_is_invariant (code, depth, expr))
   13393              :     return true;
   13394              : 
   13395              :   /* Any simple variable that didn't pass expr_is_invariant must be
   13396              :      an outer_var.  */
   13397          568 :   if (expr->expr_type == EXPR_VARIABLE && expr->rank == 0)
   13398              :     {
   13399           63 :       *outer_varp = expr->symtree->n.sym;
   13400           63 :       return true;
   13401              :     }
   13402              : 
   13403              :   /* All other permitted forms are binary operators.  */
   13404          505 :   if (expr->expr_type != EXPR_OP)
   13405              :     return false;
   13406              : 
   13407              :   /* Check for plus/minus a loop invariant expr.  */
   13408          503 :   if (expr->value.op.op == INTRINSIC_PLUS
   13409          503 :       || expr->value.op.op == INTRINSIC_MINUS)
   13410              :     {
   13411          483 :       if (expr_is_invariant (code, depth, expr->value.op.op1))
   13412           48 :         expr2 = expr->value.op.op2;
   13413          435 :       else if (expr_is_invariant (code, depth, expr->value.op.op2))
   13414          434 :         expr2 = expr->value.op.op1;
   13415              :       else
   13416              :         return false;
   13417              :     }
   13418              :   else
   13419              :     expr2 = expr;
   13420              : 
   13421              :   /* Check for a product with a loop-invariant expr.  */
   13422          502 :   if (expr2->expr_type == EXPR_OP
   13423           96 :       && expr2->value.op.op == INTRINSIC_TIMES)
   13424              :     {
   13425           96 :       if (expr_is_invariant (code, depth, expr2->value.op.op1))
   13426           40 :         expr2 = expr2->value.op.op2;
   13427           56 :       else if (expr_is_invariant (code, depth, expr2->value.op.op2))
   13428           53 :         expr2 = expr2->value.op.op1;
   13429              :       else
   13430              :         return false;
   13431              :     }
   13432              : 
   13433              :   /* What's left must be a reference to an outer loop variable.  */
   13434          499 :   if (expr2->expr_type == EXPR_VARIABLE
   13435          499 :       && expr2->rank == 0
   13436          998 :       && is_outer_iteration_variable (code, depth, expr2->symtree->n.sym))
   13437              :     {
   13438          499 :       *outer_varp = expr2->symtree->n.sym;
   13439          499 :       return true;
   13440              :     }
   13441              : 
   13442              :   return false;
   13443              : }
   13444              : 
   13445              : static void
   13446         5655 : resolve_omp_do (gfc_code *code)
   13447              : {
   13448         5655 :   gfc_code *do_code, *next;
   13449         5655 :   int i, count, non_generated_count;
   13450         5655 :   gfc_omp_namelist *n;
   13451         5655 :   gfc_symbol *dovar;
   13452         5655 :   const char *name;
   13453         5655 :   bool is_simd = false;
   13454         5655 :   bool errorp = false;
   13455         5655 :   bool perfect_nesting_errorp = false;
   13456         5655 :   bool imperfect = false;
   13457              : 
   13458         5655 :   switch (code->op)
   13459              :     {
   13460              :     case EXEC_OMP_DISTRIBUTE: name = "!$OMP DISTRIBUTE"; break;
   13461           55 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   13462           55 :       name = "!$OMP DISTRIBUTE PARALLEL DO";
   13463           55 :       break;
   13464           32 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
   13465           32 :       name = "!$OMP DISTRIBUTE PARALLEL DO SIMD";
   13466           32 :       is_simd = true;
   13467           32 :       break;
   13468           50 :     case EXEC_OMP_DISTRIBUTE_SIMD:
   13469           50 :       name = "!$OMP DISTRIBUTE SIMD";
   13470           50 :       is_simd = true;
   13471           50 :       break;
   13472         1339 :     case EXEC_OMP_DO: name = "!$OMP DO"; break;
   13473          154 :     case EXEC_OMP_DO_SIMD: name = "!$OMP DO SIMD"; is_simd = true; break;
   13474           65 :     case EXEC_OMP_LOOP: name = "!$OMP LOOP"; break;
   13475         1224 :     case EXEC_OMP_PARALLEL_DO: name = "!$OMP PARALLEL DO"; break;
   13476          351 :     case EXEC_OMP_PARALLEL_DO_SIMD:
   13477          351 :       name = "!$OMP PARALLEL DO SIMD";
   13478          351 :       is_simd = true;
   13479          351 :       break;
   13480           46 :     case EXEC_OMP_PARALLEL_LOOP: name = "!$OMP PARALLEL LOOP"; break;
   13481            7 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
   13482            7 :       name = "!$OMP PARALLEL MASKED TASKLOOP";
   13483            7 :       break;
   13484           10 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
   13485           10 :       name = "!$OMP PARALLEL MASKED TASKLOOP SIMD";
   13486           10 :       is_simd = true;
   13487           10 :       break;
   13488           13 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
   13489           13 :       name = "!$OMP PARALLEL MASTER TASKLOOP";
   13490           13 :       break;
   13491           18 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
   13492           18 :       name = "!$OMP PARALLEL MASTER TASKLOOP SIMD";
   13493           18 :       is_simd = true;
   13494           18 :       break;
   13495            8 :     case EXEC_OMP_MASKED_TASKLOOP: name = "!$OMP MASKED TASKLOOP"; break;
   13496           14 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
   13497           14 :       name = "!$OMP MASKED TASKLOOP SIMD";
   13498           14 :       is_simd = true;
   13499           14 :       break;
   13500           14 :     case EXEC_OMP_MASTER_TASKLOOP: name = "!$OMP MASTER TASKLOOP"; break;
   13501           19 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
   13502           19 :       name = "!$OMP MASTER TASKLOOP SIMD";
   13503           19 :       is_simd = true;
   13504           19 :       break;
   13505          873 :     case EXEC_OMP_SIMD: name = "!$OMP SIMD"; is_simd = true; break;
   13506           89 :     case EXEC_OMP_TARGET_PARALLEL_DO: name = "!$OMP TARGET PARALLEL DO"; break;
   13507           21 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   13508           21 :       name = "!$OMP TARGET PARALLEL DO SIMD";
   13509           21 :       is_simd = true;
   13510           21 :       break;
   13511           17 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
   13512           17 :       name = "!$OMP TARGET PARALLEL LOOP";
   13513           17 :       break;
   13514           34 :     case EXEC_OMP_TARGET_SIMD:
   13515           34 :       name = "!$OMP TARGET SIMD";
   13516           34 :       is_simd = true;
   13517           34 :       break;
   13518           21 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   13519           21 :       name = "!$OMP TARGET TEAMS DISTRIBUTE";
   13520           21 :       break;
   13521           79 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   13522           79 :       name = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
   13523           79 :       break;
   13524           56 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   13525           56 :       name = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
   13526           56 :       is_simd = true;
   13527           56 :       break;
   13528           21 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   13529           21 :       name = "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
   13530           21 :       is_simd = true;
   13531           21 :       break;
   13532           20 :     case EXEC_OMP_TARGET_TEAMS_LOOP: name = "!$OMP TARGET TEAMS LOOP"; break;
   13533           70 :     case EXEC_OMP_TASKLOOP: name = "!$OMP TASKLOOP"; break;
   13534           38 :     case EXEC_OMP_TASKLOOP_SIMD:
   13535           38 :       name = "!$OMP TASKLOOP SIMD";
   13536           38 :       is_simd = true;
   13537           38 :       break;
   13538           24 :     case EXEC_OMP_TEAMS_DISTRIBUTE: name = "!$OMP TEAMS DISTRIBUTE"; break;
   13539           42 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   13540           42 :       name = "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
   13541           42 :       break;
   13542           66 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   13543           66 :       name = "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
   13544           66 :       is_simd = true;
   13545           66 :       break;
   13546           45 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
   13547           45 :       name = "!$OMP TEAMS DISTRIBUTE SIMD";
   13548           45 :       is_simd = true;
   13549           45 :       break;
   13550           51 :     case EXEC_OMP_TEAMS_LOOP: name = "!$OMP TEAMS LOOP"; break;
   13551          197 :     case EXEC_OMP_TILE: name = "!$OMP TILE"; break;
   13552          418 :     case EXEC_OMP_UNROLL: name = "!$OMP UNROLL"; break;
   13553            0 :     default: gcc_unreachable ();
   13554              :     }
   13555              : 
   13556         5655 :   if (code->ext.omp_clauses)
   13557         5655 :     resolve_omp_clauses (code, code->ext.omp_clauses, NULL);
   13558              : 
   13559         5655 :   if (code->op == EXEC_OMP_TILE && code->ext.omp_clauses->sizes_list == NULL)
   13560            0 :     gfc_error ("SIZES clause is required on !$OMP TILE construct at %L",
   13561              :                &code->loc);
   13562              : 
   13563         5655 :   do_code = code->block->next;
   13564         5655 :   if (code->ext.omp_clauses->orderedc)
   13565              :     count = code->ext.omp_clauses->orderedc;
   13566         5511 :   else if (code->ext.omp_clauses->sizes_list)
   13567          197 :     count = gfc_expr_list_len (code->ext.omp_clauses->sizes_list);
   13568              :   else
   13569              :     {
   13570         5314 :       count = code->ext.omp_clauses->collapse;
   13571         5314 :       if (count <= 0)
   13572              :         count = 1;
   13573              :     }
   13574              : 
   13575         5655 :   non_generated_count = count;
   13576              :   /* While the spec defines the loop nest depth independently of the COLLAPSE
   13577              :      clause, in practice the middle end only pays attention to the COLLAPSE
   13578              :      depth and treats any further inner loops as the final-loop-body.  So
   13579              :      here we also check canonical loop nest form only for the number of
   13580              :      outer loops specified by the COLLAPSE clause too.  */
   13581         8421 :   for (i = 1; i <= count; i++)
   13582              :     {
   13583         8421 :       gfc_symbol *start_var = NULL, *end_var = NULL;
   13584              :       /* Parse errors are not recoverable.  */
   13585         8421 :       if (do_code->op == EXEC_DO_WHILE)
   13586              :         {
   13587            6 :           gfc_error ("%s cannot be a DO WHILE or DO without loop control "
   13588              :                      "at %L", name, &do_code->loc);
   13589          106 :           goto fail;
   13590              :         }
   13591         8415 :       if (do_code->op == EXEC_DO_CONCURRENT)
   13592              :         {
   13593            4 :           gfc_error ("%s cannot be a DO CONCURRENT loop at %L", name,
   13594              :                      &do_code->loc);
   13595            4 :           goto fail;
   13596              :         }
   13597         8411 :       if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
   13598              :         {
   13599          467 :           if (do_code->op == EXEC_OMP_UNROLL)
   13600              :             {
   13601          308 :               if (!do_code->ext.omp_clauses->partial)
   13602              :                 {
   13603           53 :                   gfc_error ("Generated loop of UNROLL construct at %L "
   13604              :                              "without PARTIAL clause does not have "
   13605              :                              "canonical form", &do_code->loc);
   13606           53 :                   goto fail;
   13607              :                 }
   13608          255 :               else if (i != count)
   13609              :                 {
   13610            5 :                   gfc_error ("UNROLL construct at %L with PARTIAL clause "
   13611              :                              "generates just one loop with canonical form "
   13612              :                              "but %d loops are needed",
   13613            5 :                              &do_code->loc, count - i + 1);
   13614            5 :                   goto fail;
   13615              :                 }
   13616              :             }
   13617          159 :           else if (do_code->op == EXEC_OMP_TILE)
   13618              :             {
   13619          159 :               if (do_code->ext.omp_clauses->sizes_list == NULL)
   13620              :                 /* This should have been diagnosed earlier already.  */
   13621            0 :                 return;
   13622          159 :               int l = gfc_expr_list_len (do_code->ext.omp_clauses->sizes_list);
   13623          159 :               if (count - i + 1 > l)
   13624              :                 {
   13625           14 :                   gfc_error ("TILE construct at %L generates %d loops "
   13626              :                              "with canonical form but %d loops are needed",
   13627              :                              &do_code->loc, l, count - i + 1);
   13628           14 :                   goto fail;
   13629              :                 }
   13630              :             }
   13631          395 :           if (do_code->ext.omp_clauses && do_code->ext.omp_clauses->erroneous)
   13632           17 :             goto fail;
   13633          378 :           if (imperfect && !perfect_nesting_errorp)
   13634              :             {
   13635            4 :               sorry_at (gfc_get_location (&do_code->loc),
   13636              :                         "Imperfectly nested loop using generated loops");
   13637            4 :               errorp = true;
   13638              :             }
   13639          378 :           if (non_generated_count == count)
   13640          330 :             non_generated_count = i - 1;
   13641          378 :           --i;
   13642          378 :           do_code = do_code->block->next;
   13643          378 :           continue;
   13644          378 :         }
   13645         7944 :       gcc_assert (do_code->op == EXEC_DO);
   13646         7944 :       if (do_code->ext.iterator->var->ts.type != BT_INTEGER)
   13647              :         {
   13648            3 :           gfc_error ("%s iteration variable must be of type integer at %L",
   13649              :                      name, &do_code->loc);
   13650            3 :           errorp = true;
   13651              :         }
   13652         7944 :       dovar = do_code->ext.iterator->var->symtree->n.sym;
   13653         7944 :       if (dovar->attr.threadprivate)
   13654              :         {
   13655            0 :           gfc_error ("%s iteration variable must not be THREADPRIVATE "
   13656              :                      "at %L", name, &do_code->loc);
   13657            0 :           errorp = true;
   13658              :         }
   13659              :       /* The private copy of a pointer has undefined association status, so
   13660              :          the DO statement cannot define it.  TILE and UNROLL do not privatize
   13661              :          their iteration variables.  */
   13662         7944 :       if (dovar->attr.pointer
   13663           23 :           && i <= non_generated_count
   13664           22 :           && code->op != EXEC_OMP_TILE
   13665           20 :           && code->op != EXEC_OMP_UNROLL)
   13666           19 :         gfc_warning (OPT_Wopenmp,
   13667              :                      "%s iteration variable %qs at %L has the POINTER "
   13668              :                      "attribute, but the association status of its private "
   13669              :                      "copy is undefined",
   13670           19 :                      name, dovar->name, &do_code->ext.iterator->var->where);
   13671         7944 :       if (code->ext.omp_clauses)
   13672       317760 :         for (enum gfc_omp_list_type list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   13673       309816 :              list = gfc_omp_list_type (list + 1))
   13674       109707 :           if (!is_simd || code->ext.omp_clauses->collapse > 1
   13675       309816 :               ? (list != OMP_LIST_PRIVATE && list != OMP_LIST_LASTPRIVATE
   13676       265512 :                   && list != OMP_LIST_ALLOCATE)
   13677        44304 :               : (list != OMP_LIST_PRIVATE && list != OMP_LIST_LASTPRIVATE
   13678        44304 :                  && list != OMP_LIST_ALLOCATE && list != OMP_LIST_LINEAR))
   13679       289314 :             for (n = code->ext.omp_clauses->lists[list]; n; n = n->next)
   13680         4466 :               if (dovar == n->sym)
   13681              :                 {
   13682            5 :                   if (!is_simd || code->ext.omp_clauses->collapse > 1)
   13683            4 :                     gfc_error ("%s iteration variable present on clause "
   13684              :                                "other than PRIVATE, LASTPRIVATE or "
   13685              :                                "ALLOCATE at %L", name, &do_code->loc);
   13686              :                   else
   13687            1 :                     gfc_error ("%s iteration variable present on clause "
   13688              :                                "other than PRIVATE, LASTPRIVATE, ALLOCATE or "
   13689              :                                "LINEAR at %L", name, &do_code->loc);
   13690              :                   errorp = true;
   13691              :                 }
   13692         7944 :       if (is_outer_iteration_variable (code, i, dovar))
   13693              :         {
   13694            2 :           gfc_error ("%s iteration variable used in more than one loop at %L",
   13695              :                      name, &do_code->loc);
   13696            2 :           errorp = true;
   13697              :         }
   13698         7942 :       else if (is_intervening_var (code, i, dovar))
   13699              :         {
   13700            2 :           gfc_error ("%s iteration variable at %L is bound in "
   13701              :                      "intervening code",
   13702              :                      name, &do_code->loc);
   13703            2 :           errorp = true;
   13704              :         }
   13705         7940 :       else if (!bound_expr_is_canonical (code, i,
   13706         7940 :                                          do_code->ext.iterator->start,
   13707              :                                          &start_var))
   13708              :         {
   13709            4 :           gfc_error ("%s loop start expression not in canonical form at %L",
   13710              :                      name, &do_code->loc);
   13711            4 :           errorp = true;
   13712              :         }
   13713         7936 :       else if (expr_uses_intervening_var (code, i,
   13714         7936 :                                           do_code->ext.iterator->start))
   13715              :         {
   13716            1 :           gfc_error ("%s loop start expression at %L uses variable bound in "
   13717              :                      "intervening code",
   13718              :                      name, &do_code->loc);
   13719            1 :           errorp = true;
   13720              :         }
   13721         7935 :       else if (!bound_expr_is_canonical (code, i,
   13722         7935 :                                          do_code->ext.iterator->end,
   13723              :                                          &end_var))
   13724              :         {
   13725            2 :           gfc_error ("%s loop end expression not in canonical form at %L",
   13726              :                      name, &do_code->loc);
   13727            2 :           errorp = true;
   13728              :         }
   13729         7933 :       else if (expr_uses_intervening_var (code, i,
   13730         7933 :                                           do_code->ext.iterator->end))
   13731              :         {
   13732            1 :           gfc_error ("%s loop end expression at %L uses variable bound in "
   13733              :                      "intervening code",
   13734              :                      name, &do_code->loc);
   13735            1 :           errorp = true;
   13736              :         }
   13737         7932 :       else if (start_var && end_var && start_var != end_var)
   13738              :         {
   13739            1 :           gfc_error ("%s loop bounds reference different "
   13740              :                      "iteration variables at %L", name, &do_code->loc);
   13741            1 :           errorp = true;
   13742              :         }
   13743         7931 :       else if (!expr_is_invariant (code, i, do_code->ext.iterator->step))
   13744              :         {
   13745            3 :           gfc_error ("%s loop increment not in canonical form at %L",
   13746              :                      name, &do_code->loc);
   13747            3 :           errorp = true;
   13748              :         }
   13749         7928 :       else if (expr_uses_intervening_var (code, i,
   13750         7928 :                                           do_code->ext.iterator->step))
   13751              :         {
   13752            1 :           gfc_error ("%s loop increment expression at %L uses variable "
   13753              :                      "bound in intervening code",
   13754              :                      name, &do_code->loc);
   13755            1 :           errorp = true;
   13756              :         }
   13757         7944 :       if (start_var || end_var)
   13758              :         {
   13759          528 :           code->ext.omp_clauses->non_rectangular = 1;
   13760          528 :           if (i > non_generated_count)
   13761              :             {
   13762            3 :               sorry_at (gfc_get_location (&do_code->loc),
   13763              :                         "Non-rectangular loops from generated loops "
   13764              :                         "unsupported");
   13765            3 :               errorp = true;
   13766              :             }
   13767              :         }
   13768              : 
   13769              :       /* Only parse loop body into nested loop and intervening code if
   13770              :          there are supposed to be more loops in the nest to collapse.  */
   13771         7944 :       if (i == count)
   13772              :         break;
   13773              : 
   13774         2395 :       next = find_nested_loop_in_chain (do_code->block->next);
   13775              : 
   13776         2395 :       if (!next)
   13777              :         {
   13778              :           /* Parse error, can't recover from this.  */
   13779            7 :           gfc_error ("not enough DO loops for collapsed %s (level %d) at %L",
   13780              :                      name, i, &code->loc);
   13781            7 :           goto fail;
   13782              :         }
   13783         2388 :       else if (next != do_code->block->next
   13784         2228 :                || (next->next && next->next->op != EXEC_CONTINUE))
   13785              :         /* Imperfectly nested loop found.  */
   13786              :         {
   13787              :           /* Only diagnose violation of imperfect nesting constraints once.  */
   13788          177 :           if (!perfect_nesting_errorp)
   13789              :             {
   13790          176 :               if (code->ext.omp_clauses->orderedc)
   13791              :                 {
   13792            3 :                   gfc_error ("%s inner loops must be perfectly nested with "
   13793              :                              "ORDERED clause at %L",
   13794              :                              name, &code->loc);
   13795            3 :                   perfect_nesting_errorp = true;
   13796              :                 }
   13797          173 :               else if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN])
   13798              :                 {
   13799            2 :                   gfc_error ("%s inner loops must be perfectly nested with "
   13800              :                              "REDUCTION INSCAN clause at %L",
   13801              :                              name, &code->loc);
   13802            2 :                   perfect_nesting_errorp = true;
   13803              :                 }
   13804          171 :               else if (code->op == EXEC_OMP_TILE)
   13805              :                 {
   13806            8 :                   gfc_error ("%s inner loops must be perfectly nested at %L",
   13807              :                              name, &code->loc);
   13808            8 :                   perfect_nesting_errorp = true;
   13809              :                 }
   13810           13 :               if (perfect_nesting_errorp)
   13811              :                 errorp = true;
   13812              :             }
   13813          177 :           if (diagnose_intervening_code_errors (do_code->block->next,
   13814              :                                                 name, next))
   13815            5 :             errorp = true;
   13816              :           imperfect = true;
   13817              :         }
   13818         2388 :       do_code = next;
   13819              :     }
   13820              : 
   13821              :   /* Give up now if we found any constraint violations.  */
   13822         5549 :   if (errorp)
   13823              :     {
   13824           48 :     fail:
   13825          154 :       if (code->ext.omp_clauses)
   13826          154 :         code->ext.omp_clauses->erroneous = 1;
   13827              :       return;
   13828              :     }
   13829              : 
   13830         5501 :   if (non_generated_count)
   13831         5230 :     restructure_intervening_code (&code->block->next, code,
   13832              :                                   non_generated_count);
   13833              : }
   13834              : 
   13835              : /* Resolve the context selector. In particular, SKIP_P is set to true,
   13836              :    the context can never be matched.  */
   13837              : 
   13838              : static void
   13839          804 : gfc_resolve_omp_context_selector (gfc_omp_set_selector *oss,
   13840              :                                   bool is_metadirective, bool *skip_p)
   13841              : {
   13842          804 :   if (skip_p)
   13843          327 :     *skip_p = false;
   13844         1527 :   for (gfc_omp_set_selector *set_selector = oss; set_selector;
   13845          723 :        set_selector = set_selector->next)
   13846         1558 :     for (gfc_omp_selector *os = set_selector->trait_selectors; os; os = os->next)
   13847              :       {
   13848          853 :         if (os->score)
   13849              :           {
   13850           52 :             if (!gfc_resolve_expr (os->score)
   13851           52 :                 || os->score->ts.type != BT_INTEGER
   13852          104 :                 || os->score->rank != 0)
   13853              :               {
   13854            0 :                 gfc_error ("%<score%> argument must be constant integer "
   13855            0 :                            "expression at %L", &os->score->where);
   13856            0 :                 gfc_free_expr (os->score);
   13857            0 :                 os->score = nullptr;
   13858              :               }
   13859           52 :             else if (os->score->expr_type == EXPR_CONSTANT
   13860           52 :                      && mpz_sgn (os->score->value.integer) < 0)
   13861              :               {
   13862            1 :                 gfc_error ("%<score%> argument must be non-negative at %L",
   13863              :                            &os->score->where);
   13864            1 :                 gfc_free_expr (os->score);
   13865            1 :                 os->score = nullptr;
   13866              :               }
   13867              :           }
   13868              : 
   13869          853 :         if (os->code == OMP_TRAIT_INVALID)
   13870              :           break;
   13871          835 :         enum omp_tp_type property_kind = omp_ts_map[os->code].tp_type;
   13872          835 :         gfc_omp_trait_property *otp = os->properties;
   13873              : 
   13874          835 :         if (!otp)
   13875          419 :           continue;
   13876          416 :         switch (property_kind)
   13877              :           {
   13878          148 :           case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
   13879          148 :           case OMP_TRAIT_PROPERTY_BOOL_EXPR:
   13880          148 :             if (!gfc_resolve_expr (otp->expr)
   13881          147 :                 || (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR
   13882          133 :                     && otp->expr->ts.type != BT_LOGICAL)
   13883          146 :                 || (property_kind == OMP_TRAIT_PROPERTY_DEV_NUM_EXPR
   13884           14 :                     && otp->expr->ts.type != BT_INTEGER)
   13885          146 :                 || otp->expr->rank != 0
   13886          294 :                 || (!is_metadirective && otp->expr->expr_type != EXPR_CONSTANT))
   13887              :               {
   13888            3 :                 if (is_metadirective)
   13889              :                   {
   13890            0 :                     if (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR)
   13891            0 :                       gfc_error ("property must be a "
   13892              :                                  "logical expression at %L",
   13893            0 :                                  &otp->expr->where);
   13894              :                     else
   13895            0 :                       gfc_error ("property must be an "
   13896              :                                  "integer expression at %L",
   13897            0 :                                  &otp->expr->where);
   13898              :                   }
   13899              :                 else
   13900              :                   {
   13901            3 :                     if (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR)
   13902            2 :                       gfc_error ("property must be a constant "
   13903              :                                  "logical expression at %L",
   13904            2 :                                  &otp->expr->where);
   13905              :                     else
   13906            1 :                       gfc_error ("property must be a constant "
   13907              :                                  "integer expression at %L",
   13908            1 :                                  &otp->expr->where);
   13909              :                   }
   13910              :                 /* Prevent later ICEs. */
   13911            3 :                 gfc_expr *e;
   13912            3 :                 if (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR)
   13913            2 :                   e = gfc_get_logical_expr (gfc_default_logical_kind,
   13914            2 :                                             &otp->expr->where, true);
   13915              :                 else
   13916            1 :                   e = gfc_get_int_expr (gfc_default_integer_kind,
   13917            1 :                                         &otp->expr->where, 0);
   13918            3 :                 gfc_free_expr (otp->expr);
   13919            3 :                 otp->expr = e;
   13920            3 :                 continue;
   13921            3 :               }
   13922              :             /* Device number must be conforming, which includes
   13923              :                omp_initial_device (-1), omp_invalid_device (-4),
   13924              :                and omp_default_device (-5).  */
   13925          145 :             if (property_kind == OMP_TRAIT_PROPERTY_DEV_NUM_EXPR
   13926           14 :                 && otp->expr->expr_type == EXPR_CONSTANT
   13927            5 :                 && mpz_sgn (otp->expr->value.integer) < 0
   13928            3 :                 && mpz_cmp_si (otp->expr->value.integer, -1) != 0
   13929            2 :                 && mpz_cmp_si (otp->expr->value.integer, -4) != 0
   13930            1 :                 && mpz_cmp_si (otp->expr->value.integer, -5) != 0)
   13931            1 :               gfc_error ("property must be a conforming device number at %L",
   13932              :                          &otp->expr->where);
   13933              :             break;
   13934              :           default:
   13935              :             break;
   13936              :           }
   13937              :         /* This only handles one specific case: User condition.
   13938              :            FIXME: Handle more cases by calling omp_context_selector_matches;
   13939              :            unfortunately, we cannot generate the tree here as, e.g., PARM_DECL
   13940              :            backend decl are not available at this stage - but might be used in,
   13941              :            e.g. user conditions. See PR122361.  */
   13942          413 :         if (skip_p && otp
   13943          149 :             && os->code == OMP_TRAIT_USER_CONDITION
   13944           88 :             && otp->expr->expr_type == EXPR_CONSTANT
   13945           14 :             && otp->expr->value.logical == false)
   13946           12 :           *skip_p = true;
   13947              :       }
   13948          804 : }
   13949              : 
   13950              : 
   13951              : static void
   13952          146 : resolve_omp_metadirective (gfc_code *code, gfc_namespace *ns)
   13953              : {
   13954          146 :   gfc_omp_variant *variant = code->ext.omp_variants;
   13955          146 :   gfc_omp_variant *prev_variant = variant;
   13956              : 
   13957          473 :   while (variant)
   13958              :     {
   13959          327 :       bool skip;
   13960          327 :       gfc_resolve_omp_context_selector (variant->selectors, true, &skip);
   13961          327 :       gfc_code *variant_code = variant->code;
   13962          327 :       gfc_resolve_code (variant_code, ns);
   13963          327 :       if (skip)
   13964              :         {
   13965              :           /* The following should only be true if an error occurred
   13966              :              as the 'otherwise' clause should always match.  */
   13967           12 :           if (variant == code->ext.omp_variants && !variant->next)
   13968              :             break;
   13969           12 :           gfc_omp_variant *tmp = variant;
   13970           12 :           if (variant == code->ext.omp_variants)
   13971           11 :             variant = prev_variant = code->ext.omp_variants = variant->next;
   13972              :           else
   13973            1 :             variant = prev_variant->next = variant->next;
   13974           12 :           gfc_free_omp_set_selector_list (tmp->selectors);
   13975           12 :           free (tmp);
   13976              :         }
   13977              :       else
   13978              :         {
   13979          315 :           prev_variant = variant;
   13980          315 :           variant = variant->next;
   13981              :         }
   13982              :     }
   13983              :   /* Replace metadirective by its body if only 'nothing' remains.  */
   13984          146 :   if (!code->ext.omp_variants->next && code->ext.omp_variants->stmt == ST_NONE)
   13985              :     {
   13986           11 :       gfc_code *next = code->next;
   13987           11 :       gfc_code *inner = code->ext.omp_variants->code;
   13988           11 :       gfc_free_omp_set_selector_list (code->ext.omp_variants->selectors);
   13989           11 :       free (code->ext.omp_variants);
   13990           11 :       *code = *inner;
   13991           11 :       free (inner);
   13992           11 :       while (code->next)
   13993              :         code = code->next;
   13994           11 :       code->next = next;
   13995              :     }
   13996          146 : }
   13997              : 
   13998              : 
   13999              : static gfc_statement
   14000           63 : omp_code_to_statement (gfc_code *code)
   14001              : {
   14002           63 :   switch (code->op)
   14003              :     {
   14004              :     case EXEC_OMP_PARALLEL:
   14005              :       return ST_OMP_PARALLEL;
   14006            0 :     case EXEC_OMP_PARALLEL_MASKED:
   14007            0 :       return ST_OMP_PARALLEL_MASKED;
   14008            0 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
   14009            0 :       return ST_OMP_PARALLEL_MASKED_TASKLOOP;
   14010            0 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
   14011            0 :       return ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD;
   14012            0 :     case EXEC_OMP_PARALLEL_MASTER:
   14013            0 :       return ST_OMP_PARALLEL_MASTER;
   14014            0 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
   14015            0 :       return ST_OMP_PARALLEL_MASTER_TASKLOOP;
   14016            0 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
   14017            0 :       return ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD;
   14018            1 :     case EXEC_OMP_PARALLEL_SECTIONS:
   14019            1 :       return ST_OMP_PARALLEL_SECTIONS;
   14020            1 :     case EXEC_OMP_SECTIONS:
   14021            1 :       return ST_OMP_SECTIONS;
   14022            1 :     case EXEC_OMP_ORDERED:
   14023            1 :       return ST_OMP_ORDERED;
   14024            1 :     case EXEC_OMP_CRITICAL:
   14025            1 :       return ST_OMP_CRITICAL;
   14026            0 :     case EXEC_OMP_MASKED:
   14027            0 :       return ST_OMP_MASKED;
   14028            0 :     case EXEC_OMP_MASKED_TASKLOOP:
   14029            0 :       return ST_OMP_MASKED_TASKLOOP;
   14030            0 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
   14031            0 :       return ST_OMP_MASKED_TASKLOOP_SIMD;
   14032            1 :     case EXEC_OMP_MASTER:
   14033            1 :       return ST_OMP_MASTER;
   14034            0 :     case EXEC_OMP_MASTER_TASKLOOP:
   14035            0 :       return ST_OMP_MASTER_TASKLOOP;
   14036            0 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
   14037            0 :       return ST_OMP_MASTER_TASKLOOP_SIMD;
   14038            1 :     case EXEC_OMP_SINGLE:
   14039            1 :       return ST_OMP_SINGLE;
   14040            1 :     case EXEC_OMP_TASK:
   14041            1 :       return ST_OMP_TASK;
   14042            1 :     case EXEC_OMP_WORKSHARE:
   14043            1 :       return ST_OMP_WORKSHARE;
   14044            1 :     case EXEC_OMP_PARALLEL_WORKSHARE:
   14045            1 :       return ST_OMP_PARALLEL_WORKSHARE;
   14046            3 :     case EXEC_OMP_DO:
   14047            3 :       return ST_OMP_DO;
   14048            0 :     case EXEC_OMP_LOOP:
   14049            0 :       return ST_OMP_LOOP;
   14050            0 :     case EXEC_OMP_ALLOCATE:
   14051            0 :       return ST_OMP_ALLOCATE_EXEC;
   14052            0 :     case EXEC_OMP_ALLOCATORS:
   14053            0 :       return ST_OMP_ALLOCATORS;
   14054            0 :     case EXEC_OMP_ASSUME:
   14055            0 :       return ST_OMP_ASSUME;
   14056            1 :     case EXEC_OMP_ATOMIC:
   14057            1 :       return ST_OMP_ATOMIC;
   14058            1 :     case EXEC_OMP_BARRIER:
   14059            1 :       return ST_OMP_BARRIER;
   14060            1 :     case EXEC_OMP_CANCEL:
   14061            1 :       return ST_OMP_CANCEL;
   14062            1 :     case EXEC_OMP_CANCELLATION_POINT:
   14063            1 :       return ST_OMP_CANCELLATION_POINT;
   14064            0 :     case EXEC_OMP_ERROR:
   14065            0 :       return ST_OMP_ERROR;
   14066            1 :     case EXEC_OMP_FLUSH:
   14067            1 :       return ST_OMP_FLUSH;
   14068            0 :     case EXEC_OMP_INTEROP:
   14069            0 :       return ST_OMP_INTEROP;
   14070            1 :     case EXEC_OMP_DISTRIBUTE:
   14071            1 :       return ST_OMP_DISTRIBUTE;
   14072            1 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   14073            1 :       return ST_OMP_DISTRIBUTE_PARALLEL_DO;
   14074            1 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
   14075            1 :       return ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD;
   14076            1 :     case EXEC_OMP_DISTRIBUTE_SIMD:
   14077            1 :       return ST_OMP_DISTRIBUTE_SIMD;
   14078            1 :     case EXEC_OMP_DO_SIMD:
   14079            1 :       return ST_OMP_DO_SIMD;
   14080            0 :     case EXEC_OMP_SCAN:
   14081            0 :       return ST_OMP_SCAN;
   14082            0 :     case EXEC_OMP_SCOPE:
   14083            0 :       return ST_OMP_SCOPE;
   14084            1 :     case EXEC_OMP_SIMD:
   14085            1 :       return ST_OMP_SIMD;
   14086            1 :     case EXEC_OMP_TARGET:
   14087            1 :       return ST_OMP_TARGET;
   14088            1 :     case EXEC_OMP_TARGET_DATA:
   14089            1 :       return ST_OMP_TARGET_DATA;
   14090            1 :     case EXEC_OMP_TARGET_ENTER_DATA:
   14091            1 :       return ST_OMP_TARGET_ENTER_DATA;
   14092            1 :     case EXEC_OMP_TARGET_EXIT_DATA:
   14093            1 :       return ST_OMP_TARGET_EXIT_DATA;
   14094            1 :     case EXEC_OMP_TARGET_PARALLEL:
   14095            1 :       return ST_OMP_TARGET_PARALLEL;
   14096            1 :     case EXEC_OMP_TARGET_PARALLEL_DO:
   14097            1 :       return ST_OMP_TARGET_PARALLEL_DO;
   14098            1 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   14099            1 :       return ST_OMP_TARGET_PARALLEL_DO_SIMD;
   14100            0 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
   14101            0 :       return ST_OMP_TARGET_PARALLEL_LOOP;
   14102            1 :     case EXEC_OMP_TARGET_SIMD:
   14103            1 :       return ST_OMP_TARGET_SIMD;
   14104            1 :     case EXEC_OMP_TARGET_TEAMS:
   14105            1 :       return ST_OMP_TARGET_TEAMS;
   14106            1 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   14107            1 :       return ST_OMP_TARGET_TEAMS_DISTRIBUTE;
   14108            1 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   14109            1 :       return ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO;
   14110            1 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   14111            1 :       return ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
   14112            1 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   14113            1 :       return ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD;
   14114            0 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
   14115            0 :       return ST_OMP_TARGET_TEAMS_LOOP;
   14116            1 :     case EXEC_OMP_TARGET_UPDATE:
   14117            1 :       return ST_OMP_TARGET_UPDATE;
   14118            1 :     case EXEC_OMP_TASKGROUP:
   14119            1 :       return ST_OMP_TASKGROUP;
   14120            1 :     case EXEC_OMP_TASKLOOP:
   14121            1 :       return ST_OMP_TASKLOOP;
   14122            1 :     case EXEC_OMP_TASKLOOP_SIMD:
   14123            1 :       return ST_OMP_TASKLOOP_SIMD;
   14124            1 :     case EXEC_OMP_TASKWAIT:
   14125            1 :       return ST_OMP_TASKWAIT;
   14126            1 :     case EXEC_OMP_TASKYIELD:
   14127            1 :       return ST_OMP_TASKYIELD;
   14128            1 :     case EXEC_OMP_TEAMS:
   14129            1 :       return ST_OMP_TEAMS;
   14130            1 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
   14131            1 :       return ST_OMP_TEAMS_DISTRIBUTE;
   14132            1 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   14133            1 :       return ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO;
   14134            1 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   14135            1 :       return ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
   14136            1 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
   14137            1 :       return ST_OMP_TEAMS_DISTRIBUTE_SIMD;
   14138            0 :     case EXEC_OMP_TEAMS_LOOP:
   14139            0 :       return ST_OMP_TEAMS_LOOP;
   14140            6 :     case EXEC_OMP_PARALLEL_DO:
   14141            6 :       return ST_OMP_PARALLEL_DO;
   14142            1 :     case EXEC_OMP_PARALLEL_DO_SIMD:
   14143            1 :       return ST_OMP_PARALLEL_DO_SIMD;
   14144            0 :     case EXEC_OMP_PARALLEL_LOOP:
   14145            0 :       return ST_OMP_PARALLEL_LOOP;
   14146            1 :     case EXEC_OMP_DEPOBJ:
   14147            1 :       return ST_OMP_DEPOBJ;
   14148            0 :     case EXEC_OMP_TILE:
   14149            0 :       return ST_OMP_TILE;
   14150            0 :     case EXEC_OMP_UNROLL:
   14151            0 :       return ST_OMP_UNROLL;
   14152            0 :     case EXEC_OMP_DISPATCH:
   14153            0 :       return ST_OMP_DISPATCH;
   14154            0 :     default:
   14155            0 :       gcc_unreachable ();
   14156              :     }
   14157              : }
   14158              : 
   14159              : static gfc_statement
   14160           63 : oacc_code_to_statement (gfc_code *code)
   14161              : {
   14162           63 :   switch (code->op)
   14163              :     {
   14164              :     case EXEC_OACC_PARALLEL:
   14165              :       return ST_OACC_PARALLEL;
   14166              :     case EXEC_OACC_KERNELS:
   14167              :       return ST_OACC_KERNELS;
   14168              :     case EXEC_OACC_SERIAL:
   14169              :       return ST_OACC_SERIAL;
   14170              :     case EXEC_OACC_DATA:
   14171              :       return ST_OACC_DATA;
   14172              :     case EXEC_OACC_HOST_DATA:
   14173              :       return ST_OACC_HOST_DATA;
   14174              :     case EXEC_OACC_PARALLEL_LOOP:
   14175              :       return ST_OACC_PARALLEL_LOOP;
   14176              :     case EXEC_OACC_KERNELS_LOOP:
   14177              :       return ST_OACC_KERNELS_LOOP;
   14178              :     case EXEC_OACC_SERIAL_LOOP:
   14179              :       return ST_OACC_SERIAL_LOOP;
   14180              :     case EXEC_OACC_LOOP:
   14181              :       return ST_OACC_LOOP;
   14182              :     case EXEC_OACC_ATOMIC:
   14183              :       return ST_OACC_ATOMIC;
   14184              :     case EXEC_OACC_ROUTINE:
   14185              :       return ST_OACC_ROUTINE;
   14186              :     case EXEC_OACC_UPDATE:
   14187              :       return ST_OACC_UPDATE;
   14188              :     case EXEC_OACC_WAIT:
   14189              :       return ST_OACC_WAIT;
   14190              :     case EXEC_OACC_CACHE:
   14191              :       return ST_OACC_CACHE;
   14192              :     case EXEC_OACC_ENTER_DATA:
   14193              :       return ST_OACC_ENTER_DATA;
   14194              :     case EXEC_OACC_EXIT_DATA:
   14195              :       return ST_OACC_EXIT_DATA;
   14196              :     case EXEC_OACC_DECLARE:
   14197              :       return ST_OACC_DECLARE;
   14198              :     case EXEC_OACC_INIT:
   14199              :       return ST_OACC_INIT;
   14200              :     case EXEC_OACC_SHUTDOWN:
   14201              :       return ST_OACC_SHUTDOWN;
   14202              :     case EXEC_OACC_SET:
   14203              :       return ST_OACC_SET;
   14204            0 :     default:
   14205            0 :       gcc_unreachable ();
   14206              :     }
   14207              : }
   14208              : 
   14209              : static void
   14210        13538 : resolve_oacc_directive_inside_omp_region (gfc_code *code)
   14211              : {
   14212        13538 :   if (omp_current_ctx != NULL && omp_current_ctx->is_openmp)
   14213              :     {
   14214           11 :       gfc_statement st = omp_code_to_statement (omp_current_ctx->code);
   14215           11 :       gfc_statement oacc_st = oacc_code_to_statement (code);
   14216           11 :       gfc_error ("The %s directive cannot be specified within "
   14217              :                  "a %s region at %L", gfc_ascii_statement (oacc_st),
   14218              :                  gfc_ascii_statement (st), &code->loc);
   14219              :     }
   14220        13538 : }
   14221              : 
   14222              : static void
   14223        21751 : resolve_omp_directive_inside_oacc_region (gfc_code *code)
   14224              : {
   14225        21751 :   if (omp_current_ctx != NULL && !omp_current_ctx->is_openmp)
   14226              :     {
   14227           52 :       gfc_statement st = oacc_code_to_statement (omp_current_ctx->code);
   14228           52 :       gfc_statement omp_st = omp_code_to_statement (code);
   14229           52 :       gfc_error ("The %s directive cannot be specified within "
   14230              :                  "a %s region at %L", gfc_ascii_statement (omp_st),
   14231              :                  gfc_ascii_statement (st), &code->loc);
   14232              :     }
   14233        21751 : }
   14234              : 
   14235              : 
   14236              : static void
   14237         5272 : resolve_oacc_nested_loops (gfc_code *code, gfc_code* do_code, int collapse,
   14238              :                           const char *clause)
   14239              : {
   14240         5272 :   gfc_symbol *dovar;
   14241         5272 :   gfc_code *c;
   14242         5272 :   int i;
   14243              : 
   14244         5792 :   for (i = 1; i <= collapse; i++)
   14245              :     {
   14246         5792 :       if (do_code->op == EXEC_DO_WHILE)
   14247              :         {
   14248           10 :           gfc_error ("!$ACC LOOP cannot be a DO WHILE or DO without loop control "
   14249              :                      "at %L", &do_code->loc);
   14250           10 :           break;
   14251              :         }
   14252         5782 :       if (do_code->op == EXEC_DO_CONCURRENT)
   14253              :         {
   14254            3 :           gfc_error ("!$ACC LOOP cannot be a DO CONCURRENT loop at %L",
   14255              :                      &do_code->loc);
   14256            3 :           break;
   14257              :         }
   14258         5779 :       gcc_assert (do_code->op == EXEC_DO);
   14259         5779 :       if (do_code->ext.iterator->var->ts.type != BT_INTEGER)
   14260            6 :         gfc_error ("!$ACC LOOP iteration variable must be of type integer at %L",
   14261              :                    &do_code->loc);
   14262         5779 :       dovar = do_code->ext.iterator->var->symtree->n.sym;
   14263         5779 :       if (i > 1)
   14264              :         {
   14265          518 :           gfc_code *do_code2 = code->block->next;
   14266          518 :           int j;
   14267              : 
   14268         1218 :           for (j = 1; j < i; j++)
   14269              :             {
   14270          710 :               gfc_symbol *ivar = do_code2->ext.iterator->var->symtree->n.sym;
   14271          710 :               if (dovar == ivar
   14272          710 :                   || gfc_find_sym_in_expr (ivar, do_code->ext.iterator->start)
   14273          701 :                   || gfc_find_sym_in_expr (ivar, do_code->ext.iterator->end)
   14274         1410 :                   || gfc_find_sym_in_expr (ivar, do_code->ext.iterator->step))
   14275              :                 {
   14276           10 :                   gfc_error ("!$ACC LOOP %s loops don't form rectangular "
   14277              :                              "iteration space at %L", clause, &do_code->loc);
   14278           10 :                   break;
   14279              :                 }
   14280          700 :               do_code2 = do_code2->block->next;
   14281              :             }
   14282              :         }
   14283         5779 :       if (i == collapse)
   14284              :         break;
   14285          577 :       for (c = do_code->next; c; c = c->next)
   14286           48 :         if (c->op != EXEC_NOP && c->op != EXEC_CONTINUE)
   14287              :           {
   14288            0 :             gfc_error ("%s !$ACC LOOP loops not perfectly nested at %L",
   14289              :                        clause, &c->loc);
   14290            0 :             break;
   14291              :           }
   14292          529 :       if (c)
   14293              :         break;
   14294          529 :       do_code = do_code->block;
   14295          529 :       if (do_code->op != EXEC_DO && do_code->op != EXEC_DO_WHILE
   14296            0 :           && do_code->op != EXEC_DO_CONCURRENT)
   14297              :         {
   14298            0 :           gfc_error ("not enough DO loops for %s !$ACC LOOP at %L",
   14299              :                      clause, &code->loc);
   14300            0 :           break;
   14301              :         }
   14302          529 :       do_code = do_code->next;
   14303          529 :       if (do_code == NULL
   14304          522 :           || (do_code->op != EXEC_DO && do_code->op != EXEC_DO_WHILE
   14305            2 :               && do_code->op != EXEC_DO_CONCURRENT))
   14306              :         {
   14307            9 :           gfc_error ("not enough DO loops for %s !$ACC LOOP at %L",
   14308              :                      clause, &code->loc);
   14309            9 :           break;
   14310              :         }
   14311              :     }
   14312         5272 : }
   14313              : 
   14314              : 
   14315              : static void
   14316        10119 : resolve_oacc_loop_blocks (gfc_code *code)
   14317              : {
   14318        10119 :   if (!oacc_is_loop (code))
   14319              :     return;
   14320              : 
   14321         5272 :   if (code->ext.omp_clauses->tile_list && code->ext.omp_clauses->gang
   14322           24 :       && code->ext.omp_clauses->worker && code->ext.omp_clauses->vector)
   14323            0 :     gfc_error ("Tiled loop cannot be parallelized across gangs, workers and "
   14324              :                "vectors at the same time at %L", &code->loc);
   14325              : 
   14326         5272 :   if (code->ext.omp_clauses->tile_list)
   14327              :     {
   14328              :       gfc_expr_list *el;
   14329          501 :       for (el = code->ext.omp_clauses->tile_list; el; el = el->next)
   14330              :         {
   14331          304 :           if (el->expr == NULL)
   14332              :             {
   14333              :               /* NULL expressions are used to represent '*' arguments.
   14334              :                  Convert those to a 0 expressions.  */
   14335          113 :               el->expr = gfc_get_constant_expr (BT_INTEGER,
   14336              :                                                 gfc_default_integer_kind,
   14337              :                                                 &code->loc);
   14338          113 :               mpz_set_si (el->expr->value.integer, 0);
   14339              :             }
   14340              :           else
   14341          191 :             resolve_positive_int_expr (el->expr, "TILE", false);
   14342              :         }
   14343              :     }
   14344              : }
   14345              : 
   14346              : 
   14347              : void
   14348        10119 : gfc_resolve_oacc_blocks (gfc_code *code, gfc_namespace *ns)
   14349              : {
   14350        10119 :   fortran_omp_context ctx;
   14351        10119 :   gfc_omp_clauses *omp_clauses = code->ext.omp_clauses;
   14352        10119 :   gfc_omp_namelist *n;
   14353              : 
   14354        10119 :   resolve_oacc_loop_blocks (code);
   14355              : 
   14356        10119 :   ctx.code = code;
   14357        10119 :   ctx.sharing_clauses = new hash_set<gfc_symbol *>;
   14358        10119 :   ctx.private_iterators = new hash_set<gfc_symbol *>;
   14359        10119 :   ctx.previous = omp_current_ctx;
   14360        10119 :   ctx.is_openmp = false;
   14361        10119 :   omp_current_ctx = &ctx;
   14362              : 
   14363       404760 :   for (enum gfc_omp_list_type list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   14364       394641 :        list = gfc_omp_list_type (list + 1))
   14365       394641 :     switch (list)
   14366              :       {
   14367        10119 :       case OMP_LIST_PRIVATE:
   14368        10710 :         for (n = omp_clauses->lists[list]; n; n = n->next)
   14369          591 :           ctx.sharing_clauses->add (n->sym);
   14370              :         break;
   14371              :       default:
   14372              :         break;
   14373              :       }
   14374              : 
   14375        10119 :   gfc_resolve_blocks (code->block, ns);
   14376              : 
   14377        10119 :   omp_current_ctx = ctx.previous;
   14378        20238 :   delete ctx.sharing_clauses;
   14379        20238 :   delete ctx.private_iterators;
   14380        10119 : }
   14381              : 
   14382              : 
   14383              : static void
   14384         5272 : resolve_oacc_loop (gfc_code *code)
   14385              : {
   14386         5272 :   gfc_code *do_code;
   14387         5272 :   int collapse;
   14388              : 
   14389         5272 :   if (code->ext.omp_clauses)
   14390         5272 :     resolve_omp_clauses (code, code->ext.omp_clauses, NULL, true);
   14391              : 
   14392         5272 :   do_code = code->block->next;
   14393         5272 :   collapse = code->ext.omp_clauses->collapse;
   14394              : 
   14395              :   /* Both collapsed and tiled loops are lowered the same way, but are not
   14396              :      compatible.  In gfc_trans_omp_do, the tile is prioritized.  */
   14397         5272 :   if (code->ext.omp_clauses->tile_list)
   14398              :     {
   14399              :       int num = 0;
   14400              :       gfc_expr_list *el;
   14401          501 :       for (el = code->ext.omp_clauses->tile_list; el; el = el->next)
   14402          304 :         ++num;
   14403          197 :       resolve_oacc_nested_loops (code, code->block->next, num, "tiled");
   14404          197 :       return;
   14405              :     }
   14406              : 
   14407         5075 :   if (collapse <= 0)
   14408              :     collapse = 1;
   14409         5075 :   resolve_oacc_nested_loops (code, do_code, collapse, "collapsed");
   14410              : }
   14411              : 
   14412              : void
   14413       359709 : gfc_resolve_oacc_declare (gfc_namespace *ns)
   14414              : {
   14415       359709 :   enum gfc_omp_list_type list;
   14416       359709 :   gfc_omp_namelist *n;
   14417       359709 :   gfc_oacc_declare *oc;
   14418              : 
   14419       359709 :   if (ns->oacc_declare == NULL)
   14420              :     return;
   14421              : 
   14422          290 :   for (oc = ns->oacc_declare; oc; oc = oc->next)
   14423              :     {
   14424         6480 :       for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   14425         6318 :            list = gfc_omp_list_type (list + 1))
   14426         6574 :         for (n = oc->clauses->lists[list]; n; n = n->next)
   14427              :           {
   14428          256 :             n->sym->mark = 0;
   14429          256 :             if (n->sym->attr.flavor != FL_VARIABLE
   14430           16 :                 && (n->sym->attr.flavor != FL_PROCEDURE
   14431            8 :                     || n->sym->result != n->sym))
   14432              :               {
   14433           14 :                 if (n->sym->attr.flavor != FL_PARAMETER)
   14434              :                   {
   14435            8 :                     gfc_error ("Object %qs is not a variable at %L",
   14436              :                                n->sym->name, &oc->loc);
   14437            8 :                     continue;
   14438              :                   }
   14439              :                 /* Note that OpenACC 3.4 permits name constants, but the
   14440              :                    implementation is permitted to ignore the clause;
   14441              :                    as semantically, device_resident kind of makes sense
   14442              :                    (and the wording with it is a bit odd), the warning
   14443              :                    is suppressed.  */
   14444            6 :                 if (list != OMP_LIST_DEVICE_RESIDENT)
   14445            5 :                   gfc_warning (OPT_Wsurprising, "Object %qs at %L is ignored as"
   14446              :                                " parameters need not be copied", n->sym->name,
   14447              :                                &oc->loc);
   14448              :               }
   14449              : 
   14450          248 :             if (n->expr && n->expr->ref->type == REF_ARRAY)
   14451              :               {
   14452            1 :                 gfc_error ("Array sections: %qs not allowed in"
   14453            1 :                            " !$ACC DECLARE at %L", n->sym->name, &oc->loc);
   14454            1 :                 continue;
   14455              :               }
   14456              :           }
   14457              : 
   14458          252 :       for (n = oc->clauses->lists[OMP_LIST_DEVICE_RESIDENT]; n; n = n->next)
   14459           90 :         check_array_not_assumed (n->sym, oc->loc, "DEVICE_RESIDENT");
   14460              :     }
   14461              : 
   14462          290 :   for (oc = ns->oacc_declare; oc; oc = oc->next)
   14463              :     {
   14464         6480 :       for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   14465         6318 :            list = gfc_omp_list_type (list + 1))
   14466         6574 :         for (n = oc->clauses->lists[list]; n; n = n->next)
   14467              :           {
   14468          256 :             if (n->sym->mark)
   14469              :               {
   14470            9 :                 gfc_error ("Symbol %qs present on multiple clauses at %L",
   14471              :                            n->sym->name, &oc->loc);
   14472            9 :                 continue;
   14473              :               }
   14474              :             else
   14475          247 :               n->sym->mark = 1;
   14476              :           }
   14477              :     }
   14478              : 
   14479          290 :   for (oc = ns->oacc_declare; oc; oc = oc->next)
   14480              :     {
   14481         6480 :       for (list = OMP_LIST_FIRST; list < OMP_LIST_NUM;
   14482         6318 :            list = gfc_omp_list_type (list + 1))
   14483         6574 :         for (n = oc->clauses->lists[list]; n; n = n->next)
   14484          256 :           n->sym->mark = 0;
   14485              :     }
   14486              : }
   14487              : 
   14488              : 
   14489              : void
   14490       359709 : gfc_resolve_oacc_routines (gfc_namespace *ns)
   14491              : {
   14492       359709 :   for (gfc_oacc_routine_name *orn = ns->oacc_routine_names;
   14493       359809 :        orn;
   14494          100 :        orn = orn->next)
   14495              :     {
   14496          100 :       gfc_symbol *sym = orn->sym;
   14497          100 :       if (!sym->attr.external
   14498           29 :           && !sym->attr.function
   14499           27 :           && !sym->attr.subroutine)
   14500              :         {
   14501            7 :           gfc_error ("NAME %qs does not refer to a subroutine or function"
   14502              :                      " in !$ACC ROUTINE ( NAME ) at %L", sym->name, &orn->loc);
   14503            7 :           continue;
   14504              :         }
   14505           93 :       if (!gfc_add_omp_declare_target (&sym->attr, sym->name, &orn->loc))
   14506              :         {
   14507           20 :           gfc_error ("NAME %qs invalid"
   14508              :                      " in !$ACC ROUTINE ( NAME ) at %L", sym->name, &orn->loc);
   14509           20 :           continue;
   14510              :         }
   14511              :     }
   14512       359709 : }
   14513              : 
   14514              : 
   14515              : void
   14516        13538 : gfc_resolve_oacc_directive (gfc_code *code, gfc_namespace *ns ATTRIBUTE_UNUSED)
   14517              : {
   14518        13538 :   resolve_oacc_directive_inside_omp_region (code);
   14519              : 
   14520        13538 :   switch (code->op)
   14521              :     {
   14522         7723 :     case EXEC_OACC_PARALLEL:
   14523         7723 :     case EXEC_OACC_KERNELS:
   14524         7723 :     case EXEC_OACC_SERIAL:
   14525         7723 :     case EXEC_OACC_DATA:
   14526         7723 :     case EXEC_OACC_HOST_DATA:
   14527         7723 :     case EXEC_OACC_UPDATE:
   14528         7723 :     case EXEC_OACC_ENTER_DATA:
   14529         7723 :     case EXEC_OACC_EXIT_DATA:
   14530         7723 :     case EXEC_OACC_WAIT:
   14531         7723 :     case EXEC_OACC_CACHE:
   14532         7723 :     case EXEC_OACC_INIT:
   14533         7723 :     case EXEC_OACC_SHUTDOWN:
   14534         7723 :     case EXEC_OACC_SET:
   14535         7723 :       resolve_omp_clauses (code, code->ext.omp_clauses, NULL, true);
   14536         7723 :       break;
   14537         5272 :     case EXEC_OACC_PARALLEL_LOOP:
   14538         5272 :     case EXEC_OACC_KERNELS_LOOP:
   14539         5272 :     case EXEC_OACC_SERIAL_LOOP:
   14540         5272 :     case EXEC_OACC_LOOP:
   14541         5272 :       resolve_oacc_loop (code);
   14542         5272 :       break;
   14543          543 :     case EXEC_OACC_ATOMIC:
   14544          543 :       resolve_omp_atomic (code);
   14545          543 :       break;
   14546              :     default:
   14547              :       break;
   14548              :     }
   14549        13538 : }
   14550              : 
   14551              : 
   14552              : static void
   14553         2250 : resolve_omp_target (gfc_code *code)
   14554              : {
   14555              : #define GFC_IS_TEAMS_CONSTRUCT(op)                      \
   14556              :   (op == EXEC_OMP_TEAMS                                 \
   14557              :    || op == EXEC_OMP_TEAMS_DISTRIBUTE                   \
   14558              :    || op == EXEC_OMP_TEAMS_DISTRIBUTE_SIMD              \
   14559              :    || op == EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO       \
   14560              :    || op == EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD  \
   14561              :    || op == EXEC_OMP_TEAMS_LOOP)
   14562              : 
   14563         2250 :   if (!code->ext.omp_clauses->contains_teams_construct)
   14564              :     return;
   14565          221 :   gfc_code *c = code->block->next;
   14566          221 :   if (c->op == EXEC_BLOCK)
   14567           30 :     c = c->ext.block.ns->code;
   14568          221 :   if (code->ext.omp_clauses->target_first_st_is_teams_or_meta)
   14569              :     {
   14570          210 :       if (c->op == EXEC_OMP_METADIRECTIVE)
   14571              :         {
   14572           16 :           struct gfc_omp_variant *mc
   14573              :             = c->ext.omp_variants;
   14574              :           /* All mc->(next...->)code should be identical with regards
   14575              :              to the diagnostic below.  */
   14576           17 :           do
   14577              :             {
   14578           17 :               if (mc->stmt != ST_NONE
   14579           16 :                   && GFC_IS_TEAMS_CONSTRUCT (mc->code->op))
   14580              :                 {
   14581           15 :                   if (c->next == NULL && mc->code->next == NULL)
   14582              :                     return;
   14583           23 :                   c = mc->code;
   14584              :                   break;
   14585              :                 }
   14586            2 :               mc = mc->next;
   14587              :             }
   14588            2 :           while (mc);
   14589              :         }
   14590          194 :       else if (GFC_IS_TEAMS_CONSTRUCT (c->op) && c->next == NULL)
   14591              :         return;
   14592              :     }
   14593              : 
   14594           31 :   while (c && !GFC_IS_TEAMS_CONSTRUCT (c->op))
   14595            8 :     c = c->next;
   14596           23 :   if (c)
   14597           19 :     gfc_error ("!$OMP TARGET region at %L with a nested TEAMS at %L may not "
   14598              :                "contain any other statement, declaration or directive outside "
   14599              :                "of the single TEAMS construct", &c->loc, &code->loc);
   14600              :   else
   14601            4 :     gfc_error ("!$OMP TARGET region at %L with a nested TEAMS may not "
   14602              :                "contain any other statement, declaration or directive outside "
   14603              :                "of the single TEAMS construct", &code->loc);
   14604              : #undef GFC_IS_TEAMS_CONSTRUCT
   14605              : }
   14606              : 
   14607              : static void
   14608          154 : resolve_omp_dispatch (gfc_code *code)
   14609              : {
   14610          154 :   gfc_code *next = code->block->next;
   14611          154 :   if (next == NULL)
   14612              :     return;
   14613              : 
   14614          151 :   gfc_exec_op op = next->op;
   14615          151 :   gcc_assert (op == EXEC_CALL || op == EXEC_ASSIGN);
   14616          151 :   if (op != EXEC_CALL
   14617           74 :       && (op != EXEC_ASSIGN || next->expr2->expr_type != EXPR_FUNCTION))
   14618            3 :     gfc_error (
   14619              :       "%<OMP DISPATCH%> directive at %L must be followed by a procedure "
   14620              :       "call with optional assignment",
   14621              :       &code->loc);
   14622              : 
   14623           77 :   if ((op == EXEC_CALL && next->resolved_sym != NULL
   14624           76 :        && next->resolved_sym->attr.proc_pointer)
   14625          151 :       || (op == EXEC_ASSIGN && gfc_expr_attr (next->expr2).proc_pointer))
   14626            1 :     gfc_error ("%<OMP DISPATCH%> directive at %L cannot be followed by a "
   14627              :                "procedure pointer",
   14628              :                &code->loc);
   14629              : }
   14630              : 
   14631              : /* Resolve OpenMP directive clauses and check various requirements
   14632              :    of each directive.  */
   14633              : 
   14634              : void
   14635        21751 : gfc_resolve_omp_directive (gfc_code *code, gfc_namespace *ns)
   14636              : {
   14637        21751 :   resolve_omp_directive_inside_oacc_region (code);
   14638              : 
   14639        21751 :   if (code->op != EXEC_OMP_ATOMIC)
   14640        19584 :     gfc_maybe_initialize_eh ();
   14641              : 
   14642        21751 :   switch (code->op)
   14643              :     {
   14644         5655 :     case EXEC_OMP_DISTRIBUTE:
   14645         5655 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
   14646         5655 :     case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
   14647         5655 :     case EXEC_OMP_DISTRIBUTE_SIMD:
   14648         5655 :     case EXEC_OMP_DO:
   14649         5655 :     case EXEC_OMP_DO_SIMD:
   14650         5655 :     case EXEC_OMP_LOOP:
   14651         5655 :     case EXEC_OMP_PARALLEL_DO:
   14652         5655 :     case EXEC_OMP_PARALLEL_DO_SIMD:
   14653         5655 :     case EXEC_OMP_PARALLEL_LOOP:
   14654         5655 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
   14655         5655 :     case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
   14656         5655 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
   14657         5655 :     case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
   14658         5655 :     case EXEC_OMP_MASKED_TASKLOOP:
   14659         5655 :     case EXEC_OMP_MASKED_TASKLOOP_SIMD:
   14660         5655 :     case EXEC_OMP_MASTER_TASKLOOP:
   14661         5655 :     case EXEC_OMP_MASTER_TASKLOOP_SIMD:
   14662         5655 :     case EXEC_OMP_SIMD:
   14663         5655 :     case EXEC_OMP_TARGET_PARALLEL_DO:
   14664         5655 :     case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
   14665         5655 :     case EXEC_OMP_TARGET_PARALLEL_LOOP:
   14666         5655 :     case EXEC_OMP_TARGET_SIMD:
   14667         5655 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
   14668         5655 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
   14669         5655 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   14670         5655 :     case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
   14671         5655 :     case EXEC_OMP_TARGET_TEAMS_LOOP:
   14672         5655 :     case EXEC_OMP_TASKLOOP:
   14673         5655 :     case EXEC_OMP_TASKLOOP_SIMD:
   14674         5655 :     case EXEC_OMP_TEAMS_DISTRIBUTE:
   14675         5655 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
   14676         5655 :     case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
   14677         5655 :     case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
   14678         5655 :     case EXEC_OMP_TEAMS_LOOP:
   14679         5655 :     case EXEC_OMP_TILE:
   14680         5655 :     case EXEC_OMP_UNROLL:
   14681         5655 :       resolve_omp_do (code);
   14682         5655 :       break;
   14683         2250 :     case EXEC_OMP_TARGET:
   14684         2250 :       resolve_omp_target (code);
   14685        10442 :       gcc_fallthrough ();
   14686        10442 :     case EXEC_OMP_ALLOCATE:
   14687        10442 :     case EXEC_OMP_ALLOCATORS:
   14688        10442 :     case EXEC_OMP_ASSUME:
   14689        10442 :     case EXEC_OMP_CANCEL:
   14690        10442 :     case EXEC_OMP_ERROR:
   14691        10442 :     case EXEC_OMP_INTEROP:
   14692        10442 :     case EXEC_OMP_MASKED:
   14693        10442 :     case EXEC_OMP_ORDERED:
   14694        10442 :     case EXEC_OMP_PARALLEL_WORKSHARE:
   14695        10442 :     case EXEC_OMP_PARALLEL:
   14696        10442 :     case EXEC_OMP_PARALLEL_MASKED:
   14697        10442 :     case EXEC_OMP_PARALLEL_MASTER:
   14698        10442 :     case EXEC_OMP_PARALLEL_SECTIONS:
   14699        10442 :     case EXEC_OMP_SCOPE:
   14700        10442 :     case EXEC_OMP_SECTIONS:
   14701        10442 :     case EXEC_OMP_SINGLE:
   14702        10442 :     case EXEC_OMP_TARGET_DATA:
   14703        10442 :     case EXEC_OMP_TARGET_ENTER_DATA:
   14704        10442 :     case EXEC_OMP_TARGET_EXIT_DATA:
   14705        10442 :     case EXEC_OMP_TARGET_PARALLEL:
   14706        10442 :     case EXEC_OMP_TARGET_TEAMS:
   14707        10442 :     case EXEC_OMP_TASK:
   14708        10442 :     case EXEC_OMP_TASKWAIT:
   14709        10442 :     case EXEC_OMP_TEAMS:
   14710        10442 :     case EXEC_OMP_WORKSHARE:
   14711        10442 :     case EXEC_OMP_DEPOBJ:
   14712        10442 :       if (code->ext.omp_clauses)
   14713        10301 :         resolve_omp_clauses (code, code->ext.omp_clauses, NULL);
   14714              :       break;
   14715         1788 :     case EXEC_OMP_TARGET_UPDATE:
   14716         1788 :       if (code->ext.omp_clauses)
   14717         1788 :         resolve_omp_clauses (code, code->ext.omp_clauses, NULL);
   14718         1788 :       if (code->ext.omp_clauses == NULL
   14719         1788 :           || (code->ext.omp_clauses->lists[OMP_LIST_TO] == NULL
   14720         1028 :               && code->ext.omp_clauses->lists[OMP_LIST_FROM] == NULL))
   14721            0 :         gfc_error ("OMP TARGET UPDATE at %L requires at least one TO or "
   14722              :                    "FROM clause", &code->loc);
   14723              :       break;
   14724         2167 :     case EXEC_OMP_ATOMIC:
   14725         2167 :       resolve_omp_clauses (code, code->block->ext.omp_clauses, NULL);
   14726         2167 :       resolve_omp_atomic (code);
   14727         2167 :       break;
   14728          165 :     case EXEC_OMP_CRITICAL:
   14729          165 :       resolve_omp_clauses (code, code->ext.omp_clauses, NULL);
   14730          165 :       if (!code->ext.omp_clauses->critical_name
   14731          114 :           && code->ext.omp_clauses->hint
   14732            5 :           && code->ext.omp_clauses->hint->ts.type == BT_INTEGER
   14733            5 :           && code->ext.omp_clauses->hint->expr_type == EXPR_CONSTANT
   14734            5 :           && mpz_sgn (code->ext.omp_clauses->hint->value.integer) != 0)
   14735            1 :         gfc_error ("OMP CRITICAL at %L with HINT clause requires a NAME, "
   14736              :                    "except when omp_sync_hint_none is used", &code->loc);
   14737              :       break;
   14738           49 :     case EXEC_OMP_SCAN:
   14739              :       /* Flag is only used to checking, hence, it is unset afterwards.  */
   14740           49 :       if (!code->ext.omp_clauses->if_present)
   14741           10 :         gfc_error ("Unexpected !$OMP SCAN at %L outside loop construct with "
   14742              :                    "%<inscan%> REDUCTION clause", &code->loc);
   14743           49 :       code->ext.omp_clauses->if_present = false;
   14744           49 :       resolve_omp_clauses (code, code->ext.omp_clauses, ns);
   14745           49 :       break;
   14746          154 :     case EXEC_OMP_DISPATCH:
   14747          154 :       if (code->ext.omp_clauses)
   14748          154 :         resolve_omp_clauses (code, code->ext.omp_clauses, ns);
   14749          154 :       resolve_omp_dispatch (code);
   14750          154 :       break;
   14751          146 :     case EXEC_OMP_METADIRECTIVE:
   14752          146 :       resolve_omp_metadirective (code, ns);
   14753          146 :       break;
   14754              :     default:
   14755              :       break;
   14756              :     }
   14757        21751 : }
   14758              : 
   14759              : /* Resolve !$omp declare {variant|simd} constructs in NS.
   14760              :    Note that !$omp declare target is resolved in resolve_symbol.  */
   14761              : 
   14762              : void
   14763       372899 : gfc_resolve_omp_declare (gfc_namespace *ns)
   14764              : {
   14765       372899 :   gfc_omp_declare_simd *ods;
   14766       373151 :   for (ods = ns->omp_declare_simd; ods; ods = ods->next)
   14767              :     {
   14768          252 :       if (ods->proc_name != NULL
   14769          197 :           && ods->proc_name != ns->proc_name)
   14770            6 :         gfc_error ("!$OMP DECLARE SIMD should refer to containing procedure "
   14771              :                    "%qs at %L", ns->proc_name->name, &ods->where);
   14772          252 :       if (ods->clauses)
   14773          252 :         resolve_omp_clauses (NULL, ods->clauses, ns);
   14774              :     }
   14775              : 
   14776       372899 :   gfc_omp_declare_variant *odv;
   14777       372899 :   gfc_omp_namelist *range_begin = NULL;
   14778              : 
   14779       373376 :   for (odv = ns->omp_declare_variant; odv; odv = odv->next)
   14780          477 :     gfc_resolve_omp_context_selector (odv->set_selectors, false, nullptr);
   14781       373376 :   for (odv = ns->omp_declare_variant; odv; odv = odv->next)
   14782          680 :     for (gfc_omp_namelist *n = odv->adjust_args_list; n != NULL; n = n->next)
   14783              :       {
   14784          203 :         if ((n->expr == NULL
   14785            6 :              && (range_begin
   14786            4 :                  || n->u.adj_args.range_start
   14787            1 :                  || n->u.adj_args.omp_num_args_plus
   14788            1 :                  || n->u.adj_args.omp_num_args_minus))
   14789          198 :             || n->u.adj_args.error_p)
   14790              :           {
   14791              :           }
   14792          197 :         else if (range_begin
   14793          191 :                  || n->u.adj_args.range_start
   14794          186 :                  || n->u.adj_args.omp_num_args_plus
   14795          186 :                  || n->u.adj_args.omp_num_args_minus)
   14796              :           {
   14797           11 :             if (!n->expr
   14798           11 :                 || !gfc_resolve_expr (n->expr)
   14799           11 :                 || n->expr->expr_type != EXPR_CONSTANT
   14800           10 :                 || n->expr->ts.type != BT_INTEGER
   14801           10 :                 || n->expr->rank != 0
   14802           10 :                 || mpz_sgn (n->expr->value.integer) < 0
   14803           20 :                 || ((n->u.adj_args.omp_num_args_plus
   14804            8 :                      || n->u.adj_args.omp_num_args_minus)
   14805            5 :                     && mpz_sgn (n->expr->value.integer) == 0))
   14806              :               {
   14807            2 :                 if (n->u.adj_args.omp_num_args_plus
   14808            2 :                     || n->u.adj_args.omp_num_args_minus)
   14809            0 :                   gfc_error ("Expected constant non-negative scalar integer "
   14810              :                              "offset expression at %L", &n->where);
   14811              :                 else
   14812            2 :                   gfc_error ("For range-based %<adjust_args%>, a constant "
   14813              :                              "positive scalar integer expression is required "
   14814              :                              "at %L", &n->where);
   14815              :               }
   14816              :           }
   14817          186 :         else if (n->expr
   14818          186 :                  && n->expr->expr_type == EXPR_CONSTANT
   14819           21 :                  && n->expr->ts.type == BT_INTEGER
   14820           20 :                  && mpz_sgn (n->expr->value.integer) > 0)
   14821              :           {
   14822              :           }
   14823          166 :         else if (!n->expr
   14824          166 :                  || !gfc_resolve_expr (n->expr)
   14825          331 :                  || n->expr->expr_type != EXPR_VARIABLE)
   14826            2 :           gfc_error ("Expected dummy parameter name or a positive integer "
   14827              :                      "at %L", &n->where);
   14828          164 :         else if (n->expr->expr_type == EXPR_VARIABLE)
   14829          164 :           n->sym = n->expr->symtree->n.sym;
   14830              : 
   14831          203 :         range_begin = n->u.adj_args.range_start ? n : NULL;
   14832              :       }
   14833       372899 : }
   14834              : 
   14835              : struct omp_udr_callback_data
   14836              : {
   14837              :   gfc_omp_udr *omp_udr;
   14838              :   bool is_initializer;
   14839              : };
   14840              : 
   14841              : static int
   14842         3746 : omp_udr_callback (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
   14843              :                   void *data)
   14844              : {
   14845         3746 :   struct omp_udr_callback_data *cd = (struct omp_udr_callback_data *) data;
   14846         3746 :   if ((*e)->expr_type == EXPR_VARIABLE)
   14847              :     {
   14848         2303 :       if (cd->is_initializer)
   14849              :         {
   14850          545 :           if ((*e)->symtree->n.sym != cd->omp_udr->omp_priv
   14851          140 :               && (*e)->symtree->n.sym != cd->omp_udr->omp_orig)
   14852            4 :             gfc_error ("Variable other than OMP_PRIV or OMP_ORIG used in "
   14853              :                        "INITIALIZER clause of !$OMP DECLARE REDUCTION at %L",
   14854              :                        &(*e)->where);
   14855              :         }
   14856              :       else
   14857              :         {
   14858         1758 :           if ((*e)->symtree->n.sym != cd->omp_udr->omp_out
   14859          626 :               && (*e)->symtree->n.sym != cd->omp_udr->omp_in)
   14860            6 :             gfc_error ("Variable other than OMP_OUT or OMP_IN used in "
   14861              :                        "combiner of !$OMP DECLARE REDUCTION at %L",
   14862              :                        &(*e)->where);
   14863              :         }
   14864              :     }
   14865         3746 :   return 0;
   14866              : }
   14867              : 
   14868              : /* Resolve !$omp declare reduction constructs.  */
   14869              : 
   14870              : static void
   14871          633 : gfc_resolve_omp_udr (gfc_omp_udr *omp_udr)
   14872              : {
   14873          633 :   gfc_actual_arglist *a;
   14874          633 :   const char *predef_name = NULL;
   14875              : 
   14876          633 :   switch (omp_udr->rop)
   14877              :     {
   14878          632 :     case OMP_REDUCTION_PLUS:
   14879          632 :     case OMP_REDUCTION_TIMES:
   14880          632 :     case OMP_REDUCTION_MINUS:
   14881          632 :     case OMP_REDUCTION_AND:
   14882          632 :     case OMP_REDUCTION_OR:
   14883          632 :     case OMP_REDUCTION_EQV:
   14884          632 :     case OMP_REDUCTION_NEQV:
   14885          632 :     case OMP_REDUCTION_MAX:
   14886          632 :     case OMP_REDUCTION_USER:
   14887          632 :       break;
   14888            1 :     default:
   14889            1 :       gfc_error ("Invalid operator for !$OMP DECLARE REDUCTION %s at %L",
   14890              :                  omp_udr->name, &omp_udr->where);
   14891           26 :       return;
   14892              :     }
   14893              : 
   14894          632 :   if (gfc_omp_udr_predef (omp_udr->rop, omp_udr->name,
   14895              :                           &omp_udr->ts, &predef_name))
   14896              :     {
   14897           19 :       if (predef_name)
   14898           19 :         gfc_error ("Redefinition of predefined %qs in "
   14899              :                    "!$OMP DECLARE REDUCTION at %L",
   14900              :                    predef_name, &omp_udr->where);
   14901              :       else
   14902            0 :         gfc_error ("Redefinition of predefined %qs in "
   14903              :                    "!$OMP DECLARE REDUCTION at %L", omp_udr->name,
   14904              :                    &omp_udr->where);
   14905              :       return;
   14906              :     }
   14907              : 
   14908          613 :   if (omp_udr->ts.type == BT_CHARACTER
   14909           62 :       && omp_udr->ts.u.cl->length
   14910           32 :       && omp_udr->ts.u.cl->length->expr_type != EXPR_CONSTANT)
   14911              :     {
   14912            1 :       gfc_error ("CHARACTER length in !$OMP DECLARE REDUCTION %qs not "
   14913              :                  "constant at %L", omp_udr->name, &omp_udr->where);
   14914            1 :       return;
   14915              :     }
   14916              : 
   14917          612 :   struct omp_udr_callback_data cd;
   14918          612 :   cd.omp_udr = omp_udr;
   14919          612 :   cd.is_initializer = false;
   14920          612 :   gfc_code_walker (&omp_udr->combiner_ns->code, gfc_dummy_code_callback,
   14921              :                    omp_udr_callback, &cd);
   14922          612 :   if (omp_udr->combiner_ns->code->op == EXEC_CALL)
   14923              :     {
   14924          346 :       for (a = omp_udr->combiner_ns->code->ext.actual; a; a = a->next)
   14925          237 :         if (a->expr == NULL)
   14926              :           break;
   14927          110 :       if (a)
   14928            1 :         gfc_error ("Subroutine call with alternate returns in combiner "
   14929              :                    "of !$OMP DECLARE REDUCTION at %L",
   14930              :                    &omp_udr->combiner_ns->code->loc);
   14931              :     }
   14932          612 :   if (omp_udr->initializer_ns)
   14933              :     {
   14934          383 :       cd.is_initializer = true;
   14935          383 :       gfc_code_walker (&omp_udr->initializer_ns->code, gfc_dummy_code_callback,
   14936              :                        omp_udr_callback, &cd);
   14937          383 :       if (omp_udr->initializer_ns->code->op == EXEC_CALL)
   14938              :         {
   14939          377 :           for (a = omp_udr->initializer_ns->code->ext.actual; a; a = a->next)
   14940          243 :             if (a->expr == NULL)
   14941              :               break;
   14942          135 :           if (a)
   14943            1 :             gfc_error ("Subroutine call with alternate returns in "
   14944              :                        "INITIALIZER clause of !$OMP DECLARE REDUCTION "
   14945              :                        "at %L", &omp_udr->initializer_ns->code->loc);
   14946          136 :           for (a = omp_udr->initializer_ns->code->ext.actual; a; a = a->next)
   14947          135 :             if (a->expr
   14948          135 :                 && a->expr->expr_type == EXPR_VARIABLE
   14949          135 :                 && a->expr->symtree->n.sym == omp_udr->omp_priv
   14950          134 :                 && a->expr->ref == NULL)
   14951              :               break;
   14952          135 :           if (a == NULL)
   14953            1 :             gfc_error ("One of actual subroutine arguments in INITIALIZER "
   14954              :                        "clause of !$OMP DECLARE REDUCTION must be OMP_PRIV "
   14955              :                        "at %L", &omp_udr->initializer_ns->code->loc);
   14956              :         }
   14957              :     }
   14958          229 :   else if (omp_udr->ts.type == BT_DERIVED
   14959          229 :            && !gfc_has_default_initializer (omp_udr->ts.u.derived))
   14960              :     {
   14961            4 :       gfc_error ("Missing INITIALIZER clause for !$OMP DECLARE REDUCTION "
   14962              :                  "of derived type without default initializer at %L",
   14963              :                  &omp_udr->where);
   14964            4 :       return;
   14965              :     }
   14966              : }
   14967              : 
   14968              : void
   14969       373967 : gfc_resolve_omp_udrs (gfc_symtree *st)
   14970              : {
   14971       373967 :   gfc_omp_udr *omp_udr;
   14972              : 
   14973       373967 :   if (st == NULL)
   14974              :     return;
   14975          534 :   gfc_resolve_omp_udrs (st->left);
   14976          534 :   gfc_resolve_omp_udrs (st->right);
   14977         1167 :   for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
   14978          633 :     gfc_resolve_omp_udr (omp_udr);
   14979              : }
   14980              : 
   14981              : /* Resolve !$omp declare mapper constructs.  */
   14982              : 
   14983              : static void
   14984           30 : gfc_resolve_omp_udm (gfc_omp_udm *omp_udm)
   14985              : {
   14986           30 :   resolve_omp_clauses (NULL, omp_udm->clauses, omp_udm->mapper_ns);
   14987              : 
   14988           30 :   gfc_omp_namelist *n;
   14989           32 :   for (n = omp_udm->clauses->lists[OMP_LIST_MAP]; n; n = n->next)
   14990           30 :     if (n->sym == omp_udm->var_sym)
   14991              :       break;
   14992           30 :   if (!n)
   14993            2 :     gfc_error ("At least one %<map%> clause in !$OMP DECLARE MAPPER at %L must "
   14994              :                "map %qs or an element of it",
   14995            2 :                &omp_udm->where, omp_udm->var_sym->name);
   14996           30 : }
   14997              : 
   14998              : void
   14999       372957 : gfc_resolve_omp_udms (gfc_symtree *st)
   15000              : {
   15001       372957 :   gfc_omp_udm *omp_udm;
   15002              : 
   15003       372957 :   if (st == NULL)
   15004              :     return;
   15005           29 :   gfc_resolve_omp_udms (st->left);
   15006           29 :   gfc_resolve_omp_udms (st->right);
   15007           59 :   for (omp_udm = st->n.omp_udm; omp_udm; omp_udm = omp_udm->next)
   15008           30 :     gfc_resolve_omp_udm (omp_udm);
   15009              : }
        

Generated by: LCOV version 2.6-beta

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