LCOV - code coverage report
Current view: top level - gcc/fortran - parse.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 89.6 % 4661 4176
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 87 87
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Main parser.
       2              :    Copyright (C) 2000-2026 Free Software Foundation, Inc.
       3              :    Contributed by Andy Vaught
       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              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "options.h"
      25              : #include "gfortran.h"
      26              : #include <setjmp.h>
      27              : #include "match.h"
      28              : #include "parse.h"
      29              : #include "tree-core.h"
      30              : #include "tree.h"
      31              : #include "fold-const.h"
      32              : #include "tree-hash-traits.h"
      33              : #include "omp-general.h"
      34              : 
      35              : /* Current statement label.  Zero means no statement label.  Because new_st
      36              :    can get wiped during statement matching, we have to keep it separate.  */
      37              : 
      38              : gfc_st_label *gfc_statement_label;
      39              : 
      40              : static locus label_locus;
      41              : static jmp_buf eof_buf;
      42              : 
      43              : /* Respectively pointer and content of the current interface body being parsed
      44              :    as they were at the beginning of decode_statement.  Used to restore the
      45              :    interface to its previous state in case a parsed statement is rejected after
      46              :    some symbols have been added to the interface.  */
      47              : static gfc_interface **current_interface_ptr = nullptr;
      48              : static gfc_interface *previous_interface_head = nullptr;
      49              : 
      50              : gfc_state_data *gfc_state_stack;
      51              : static bool last_was_use_stmt = false;
      52              : bool in_exec_part;
      53              : 
      54              : /* True when matching an OpenMP context selector.  */
      55              : bool gfc_matching_omp_context_selector;
      56              : 
      57              : /* True when parsing the body of an OpenMP metadirective.  */
      58              : bool gfc_in_omp_metadirective_body;
      59              : 
      60              : /* Each metadirective body in the translation unit is given a unique
      61              :    number, used to ensure that labels in the body have unique names.  */
      62              : int gfc_omp_metadirective_region_count;
      63              : vec<int> gfc_omp_metadirective_region_stack;
      64              : 
      65              : /* TODO: Re-order functions to kill these forward decls.  */
      66              : static void check_statement_label (gfc_statement);
      67              : static void undo_new_statement (void);
      68              : static void reject_statement (void);
      69              : 
      70              : 
      71              : /* A sort of half-matching function.  We try to match the word on the
      72              :    input with the passed string.  If this succeeds, we call the
      73              :    keyword-dependent matching function that will match the rest of the
      74              :    statement.  For single keywords, the matching subroutine is
      75              :    gfc_match_eos().
      76              : 
      77              :    If NO_SUBSTRING, the keyword must be followed by a character not
      78              :    permitted in a name (for free form); EOF is not handled here. Due
      79              :    to fixed-form Fortran, longer keywords still need to be matched
      80              :    before shorter substrings.
      81              : 
      82              :    If REJECT_STMT_ON_ERROR is false, it is assumed that no error
      83              :    recovery handling is needed.  */
      84              : 
      85              : static match
      86     24908887 : match_word (const char *str, match (*subr) (void), locus *old_locus,
      87              :             bool no_substring = false, bool reject_stmt_on_error = true)
      88              : {
      89     24908887 :   match m;
      90     24908887 :   char c;
      91              : 
      92     24908887 :   if (str != NULL)
      93              :     {
      94     14916589 :       m = gfc_match (str);
      95     14916589 :       if (m != MATCH_YES)
      96              :         return m;
      97        51824 :       if (no_substring && gfc_current_form == FORM_FREE
      98      4041047 :           && ((c = gfc_peek_ascii_char ()) == '_' || c == '$' || ISALNUM (c)))
      99              :         {
     100            3 :           gfc_current_locus = *old_locus;
     101            3 :           return MATCH_NO;
     102              :         }
     103              :     }
     104              : 
     105     13982844 :   m = (*subr) ();
     106              : 
     107     13982840 :   if (m == MATCH_NO || (reject_stmt_on_error && m == MATCH_ERROR))
     108              :     {
     109      9460629 :       gfc_current_locus = *old_locus;
     110      9460629 :       reject_statement ();
     111              :     }
     112              : 
     113              :   return m;
     114              : }
     115              : 
     116              : 
     117              : /* Like match_word, but if str is matched, set a flag that it
     118              :    was matched. Note that reject_statement() is not called if
     119              :    SUBR returned a match error - and no substring matching is
     120              :    assumed.  */
     121              : static match
     122       180020 : match_word_omp_simd (const char *str, match (*subr) (void), locus *old_locus,
     123              :                      bool *simd_matched)
     124              : {
     125       180020 :   match m;
     126       180020 :   char c;
     127              : 
     128       180020 :   if (str != NULL)
     129              :     {
     130       180020 :       m = gfc_match (str);
     131       180020 :       if (m != MATCH_YES)
     132              :         return m;
     133         4161 :       if (gfc_current_form == FORM_FREE
     134         4161 :           && ((c = gfc_peek_ascii_char ()) == '_' || c == '$' || ISALNUM (c)))
     135              :         {
     136            0 :           gfc_current_locus = *old_locus;
     137            0 :           return MATCH_NO;
     138              :         }
     139         4161 :       *simd_matched = true;
     140              :     }
     141              : 
     142         4161 :   m = (*subr) ();
     143              : 
     144         4161 :   if (m == MATCH_NO)
     145              :     {
     146            0 :       gfc_current_locus = *old_locus;
     147            0 :       reject_statement ();
     148              :     }
     149              : 
     150              :   return m;
     151              : }
     152              : 
     153              : 
     154              : /* Load symbols from all USE statements encountered in this scoping unit.  */
     155              : 
     156              : static void
     157        22067 : use_modules (void)
     158              : {
     159        22067 :   gfc_error_buffer old_error;
     160              : 
     161        22067 :   gfc_push_error (&old_error);
     162        22067 :   gfc_buffer_error (false);
     163        22067 :   gfc_use_modules ();
     164        22063 :   gfc_buffer_error (true);
     165        22063 :   gfc_pop_error (&old_error);
     166        22063 :   gfc_commit_symbols ();
     167        22063 :   gfc_warning_check ();
     168        22063 :   gfc_current_ns->old_equiv = gfc_current_ns->equiv;
     169        22063 :   gfc_current_ns->old_data = gfc_current_ns->data;
     170        22063 :   last_was_use_stmt = false;
     171        22063 : }
     172              : 
     173              : 
     174              : /* Figure out what the next statement is, (mostly) regardless of
     175              :    proper ordering.  The do...while(0) is there to prevent if/else
     176              :    ambiguity.  */
     177              : 
     178              : #define match(keyword, subr, st)                                \
     179              :     do {                                                        \
     180              :       if (match_word (keyword, subr, &old_locus) == MATCH_YES)      \
     181              :         return st;                                              \
     182              :       else                                                      \
     183              :         undo_new_statement ();                                  \
     184              :     } while (0)
     185              : 
     186              : 
     187              : /* This is a specialist version of decode_statement that is used
     188              :    for the specification statements in a function, whose
     189              :    characteristics are deferred into the specification statements.
     190              :    eg.:  INTEGER (king = mykind) foo ()
     191              :          USE mymodule, ONLY mykind.....
     192              :    The KIND parameter needs a return after USE or IMPORT, whereas
     193              :    derived type declarations can occur anywhere, up the executable
     194              :    block.  ST_GET_FCN_CHARACTERISTICS is returned when we have run
     195              :    out of the correct kind of specification statements.  */
     196              : static gfc_statement
     197        11225 : decode_specification_statement (void)
     198              : {
     199        11225 :   gfc_statement st;
     200        11225 :   locus old_locus;
     201        11225 :   char c;
     202              : 
     203        11225 :   if (gfc_match_eos () == MATCH_YES)
     204              :     return ST_NONE;
     205              : 
     206        11225 :   old_locus = gfc_current_locus;
     207              : 
     208        11225 :   if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES)
     209              :     {
     210         1213 :       last_was_use_stmt = true;
     211         1213 :       return ST_USE;
     212              :     }
     213              :   else
     214              :     {
     215        10012 :       undo_new_statement ();
     216        10012 :       if (last_was_use_stmt)
     217         1034 :         use_modules ();
     218              :     }
     219              : 
     220        10012 :   match ("import", gfc_match_import, ST_IMPORT);
     221              : 
     222         9442 :   if (gfc_current_block ()->result->ts.type != BT_DERIVED)
     223         6122 :     goto end_of_block;
     224              : 
     225         3320 :   match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION);
     226         3320 :   match (NULL, gfc_match_data_decl, ST_DATA_DECL);
     227         1280 :   match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR);
     228              : 
     229              :   /* General statement matching: Instead of testing every possible
     230              :      statement, we eliminate most possibilities by peeking at the
     231              :      first character.  */
     232              : 
     233         1280 :   c = gfc_peek_ascii_char ();
     234              : 
     235         1280 :   switch (c)
     236              :     {
     237           67 :     case 'a':
     238           67 :       match ("abstract% interface", gfc_match_abstract_interface,
     239              :              ST_INTERFACE);
     240           67 :       match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL);
     241           60 :       match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL);
     242           59 :       match ("automatic", gfc_match_automatic, ST_ATTR_DECL);
     243           59 :       break;
     244              : 
     245           14 :     case 'b':
     246           14 :       match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL);
     247           14 :       break;
     248              : 
     249          117 :     case 'c':
     250          117 :       match ("codimension", gfc_match_codimension, ST_ATTR_DECL);
     251          116 :       match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL);
     252           44 :       break;
     253              : 
     254            6 :     case 'd':
     255            6 :       match ("data", gfc_match_data, ST_DATA);
     256            6 :       match ("dimension", gfc_match_dimension, ST_ATTR_DECL);
     257            5 :       break;
     258              : 
     259          552 :     case 'e':
     260          552 :       match ("enum , bind ( c )", gfc_match_enum, ST_ENUM);
     261          552 :       match ("entry% ", gfc_match_entry, ST_ENTRY);
     262          552 :       match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE);
     263          552 :       match ("external", gfc_match_external, ST_ATTR_DECL);
     264          552 :       break;
     265              : 
     266           57 :     case 'f':
     267           57 :       match ("format", gfc_match_format, ST_FORMAT);
     268           57 :       break;
     269              : 
     270            3 :     case 'g':
     271            3 :       match ("generic", gfc_match_generic, ST_GENERIC);
     272            3 :       break;
     273              : 
     274          263 :     case 'i':
     275          263 :       match ("implicit", gfc_match_implicit, ST_IMPLICIT);
     276          263 :       match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE);
     277          237 :       match ("interface", gfc_match_interface, ST_INTERFACE);
     278          237 :       match ("intent", gfc_match_intent, ST_ATTR_DECL);
     279          129 :       match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL);
     280          129 :       break;
     281              : 
     282              :     case 'm':
     283              :       break;
     284              : 
     285           16 :     case 'n':
     286           16 :       match ("namelist", gfc_match_namelist, ST_NAMELIST);
     287           16 :       break;
     288              : 
     289            1 :     case 'o':
     290            1 :       match ("optional", gfc_match_optional, ST_ATTR_DECL);
     291            1 :       break;
     292              : 
     293          105 :     case 'p':
     294          105 :       match ("parameter", gfc_match_parameter, ST_PARAMETER);
     295          105 :       match ("pointer", gfc_match_pointer, ST_ATTR_DECL);
     296          105 :       if (gfc_match_private (&st) == MATCH_YES)
     297            0 :         return st;
     298          105 :       match ("procedure", gfc_match_procedure, ST_PROCEDURE);
     299          102 :       if (gfc_match_public (&st) == MATCH_YES)
     300            0 :         return st;
     301          102 :       match ("protected", gfc_match_protected, ST_ATTR_DECL);
     302          102 :       break;
     303              : 
     304              :     case 'r':
     305              :       break;
     306              : 
     307           12 :     case 's':
     308           12 :       match ("save", gfc_match_save, ST_ATTR_DECL);
     309           12 :       match ("static", gfc_match_static, ST_ATTR_DECL);
     310           12 :       match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL);
     311           12 :       break;
     312              : 
     313           42 :     case 't':
     314           42 :       match ("target", gfc_match_target, ST_ATTR_DECL);
     315           42 :       match ("type", gfc_match_derived_decl, ST_DERIVED_DECL);
     316           26 :       break;
     317              : 
     318              :     case 'u':
     319              :       break;
     320              : 
     321            1 :     case 'v':
     322            1 :       match ("value", gfc_match_value, ST_ATTR_DECL);
     323            1 :       match ("volatile", gfc_match_volatile, ST_ATTR_DECL);
     324            0 :       break;
     325              : 
     326              :     case 'w':
     327              :       break;
     328              :     }
     329              : 
     330              :   /* This is not a specification statement.  See if any of the matchers
     331              :      has stored an error message of some sort.  */
     332              : 
     333         7166 : end_of_block:
     334         7166 :   gfc_clear_error ();
     335         7166 :   gfc_buffer_error (false);
     336         7166 :   gfc_current_locus = old_locus;
     337              : 
     338         7166 :   return ST_GET_FCN_CHARACTERISTICS;
     339              : }
     340              : 
     341              : 
     342              : /* Tells whether gfc_get_current_interface_head can be used safely.  */
     343              : 
     344              : static bool
     345      1421738 : current_interface_valid_p ()
     346              : {
     347      1421738 :   switch (current_interface.type)
     348              :     {
     349        11642 :     case INTERFACE_INTRINSIC_OP:
     350        11642 :       return current_interface.ns != nullptr;
     351              : 
     352        79418 :     case INTERFACE_GENERIC:
     353        79418 :     case INTERFACE_DTIO:
     354        79418 :       return current_interface.sym != nullptr;
     355              : 
     356         2742 :     case INTERFACE_USER_OP:
     357         2742 :       return current_interface.uop != nullptr;
     358              : 
     359              :     default:
     360              :       return false;
     361              :     }
     362              : }
     363              : 
     364              : 
     365              : /* Return a pointer to the interface currently being parsed, or nullptr if
     366              :    we are not currently parsing an interface body.  */
     367              : 
     368              : static gfc_interface **
     369      1421738 : get_current_interface_ptr ()
     370              : {
     371      1421738 :   if (current_interface_valid_p ())
     372              :     {
     373        93801 :       gfc_interface *& ifc_ptr = gfc_current_interface_head ();
     374        93801 :       return &ifc_ptr;
     375              :     }
     376              :   else
     377              :     return nullptr;
     378              : }
     379              : 
     380              : 
     381              : static bool in_specification_block;
     382              : 
     383              : /* This is the primary 'decode_statement'.  */
     384              : static gfc_statement
     385      1421738 : decode_statement (void)
     386              : {
     387      1421738 :   gfc_statement st;
     388      1421738 :   locus old_locus;
     389      1421738 :   match m = MATCH_NO;
     390      1421738 :   char c;
     391              : 
     392      1421738 :   gfc_enforce_clean_symbol_state ();
     393              : 
     394      1421738 :   gfc_clear_error ();   /* Clear any pending errors.  */
     395      1421738 :   gfc_clear_warning (); /* Clear any pending warnings.  */
     396              : 
     397      1421738 :   current_interface_ptr = get_current_interface_ptr ();
     398      2843476 :   previous_interface_head = current_interface_ptr == nullptr
     399      1421738 :                             ? nullptr
     400              :                             : *current_interface_ptr;
     401              : 
     402      1421738 :   gfc_matching_function = false;
     403              : 
     404      1421738 :   if (gfc_match_eos () == MATCH_YES)
     405              :     return ST_NONE;
     406              : 
     407      1421725 :   if (gfc_current_state () == COMP_FUNCTION
     408       102638 :         && gfc_current_block ()->result->ts.kind == -1)
     409        11225 :     return decode_specification_statement ();
     410              : 
     411      1410500 :   old_locus = gfc_current_locus;
     412              : 
     413      1410500 :   c = gfc_peek_ascii_char ();
     414              : 
     415      1410500 :   if (c == 'u')
     416              :     {
     417        28610 :       if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES)
     418              :         {
     419        23974 :           last_was_use_stmt = true;
     420        23974 :           return ST_USE;
     421              :         }
     422              :       else
     423         4636 :         undo_new_statement ();
     424              :     }
     425              : 
     426      1386526 :   if (last_was_use_stmt)
     427        20665 :     use_modules ();
     428              : 
     429              :   /* Try matching a data declaration or function declaration. The
     430              :       input "REALFUNCTIONA(N)" can mean several things in different
     431              :       contexts, so it (and its relatives) get special treatment.  */
     432              : 
     433      1386523 :   if (gfc_current_state () == COMP_NONE
     434              :       || gfc_current_state () == COMP_INTERFACE
     435              :       || gfc_current_state () == COMP_CONTAINS)
     436              :     {
     437       134750 :       gfc_matching_function = true;
     438       134750 :       m = gfc_match_function_decl ();
     439       134750 :       if (m == MATCH_YES)
     440              :         return ST_FUNCTION;
     441       113863 :       else if (m == MATCH_ERROR)
     442        10495 :         reject_statement ();
     443              :       else
     444       103368 :         gfc_undo_symbols ();
     445       113863 :       gfc_current_locus = old_locus;
     446              :     }
     447      1365636 :   gfc_matching_function = false;
     448              : 
     449              :   /* Legacy parameter statements are ambiguous with assignments so try parameter
     450              :      first.  */
     451      1365636 :   match ("parameter", gfc_match_parameter, ST_PARAMETER);
     452              : 
     453              :   /* Match statements whose error messages are meant to be overwritten
     454              :      by something better.  */
     455              : 
     456      1357583 :   match (NULL, gfc_match_assignment, ST_ASSIGNMENT);
     457      1071530 :   match (NULL, gfc_match_pointer_assignment, ST_POINTER_ASSIGNMENT);
     458              : 
     459      1061925 :   if (in_specification_block)
     460              :     {
     461       438730 :       m = match_word (NULL, gfc_match_st_function, &old_locus);
     462       438730 :       if (m == MATCH_YES)
     463              :         return ST_STATEMENT_FUNCTION;
     464              :     }
     465              : 
     466      1061698 :   if (!(in_specification_block && m == MATCH_ERROR))
     467              :     {
     468      1061677 :       match (NULL, gfc_match_ptr_fcn_assign, ST_ASSIGNMENT);
     469              :     }
     470              : 
     471      1061541 :   match (NULL, gfc_match_data_decl, ST_DATA_DECL);
     472       838633 :   match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR);
     473              : 
     474              :   /* Try to match a subroutine statement, which has the same optional
     475              :      prefixes that functions can have.  */
     476              : 
     477       838377 :   if (gfc_match_subroutine () == MATCH_YES)
     478              :     return ST_SUBROUTINE;
     479       793378 :   gfc_undo_symbols ();
     480       793378 :   gfc_current_locus = old_locus;
     481              : 
     482       793378 :   if (gfc_match_submod_proc () == MATCH_YES)
     483              :     {
     484          282 :       if (gfc_new_block->attr.subroutine)
     485              :         return ST_SUBROUTINE;
     486          134 :       else if (gfc_new_block->attr.function)
     487              :         return ST_FUNCTION;
     488              :     }
     489       793096 :   gfc_undo_symbols ();
     490       793096 :   gfc_current_locus = old_locus;
     491              : 
     492              :   /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
     493              :      statements, which might begin with a block label.  The match functions for
     494              :      these statements are unusual in that their keyword is not seen before
     495              :      the matcher is called.  */
     496              : 
     497       793096 :   if (gfc_match_if (&st) == MATCH_YES)
     498       238580 :     return st;
     499       554516 :   gfc_undo_symbols ();
     500       554516 :   gfc_current_locus = old_locus;
     501              : 
     502       554516 :   if (gfc_match_where (&st) == MATCH_YES)
     503          452 :     return st;
     504       554064 :   gfc_undo_symbols ();
     505       554064 :   gfc_current_locus = old_locus;
     506              : 
     507       554064 :   if (gfc_match_forall (&st) == MATCH_YES)
     508         1987 :     return st;
     509       552077 :   gfc_undo_symbols ();
     510       552077 :   gfc_current_locus = old_locus;
     511              : 
     512              :   /* Try to match TYPE as an alias for PRINT.  */
     513       552077 :   if (gfc_match_type (&st) == MATCH_YES)
     514           19 :     return st;
     515       552058 :   gfc_undo_symbols ();
     516       552058 :   gfc_current_locus = old_locus;
     517              : 
     518       552058 :   match (NULL, gfc_match_do, ST_DO);
     519       518001 :   match (NULL, gfc_match_block, ST_BLOCK);
     520       516450 :   match (NULL, gfc_match_associate, ST_ASSOCIATE);
     521       514636 :   match (NULL, gfc_match_change_team, ST_CHANGE_TEAM);
     522       514505 :   match (NULL, gfc_match_critical, ST_CRITICAL);
     523       514451 :   match (NULL, gfc_match_select, ST_SELECT_CASE);
     524       513893 :   match (NULL, gfc_match_select_type, ST_SELECT_TYPE);
     525       510550 :   match (NULL, gfc_match_select_rank, ST_SELECT_RANK);
     526              : 
     527              :   /* General statement matching: Instead of testing every possible
     528              :      statement, we eliminate most possibilities by peeking at the
     529              :      first character.  */
     530              : 
     531       509490 :   switch (c)
     532              :     {
     533        16147 :     case 'a':
     534        16147 :       match ("abstract% interface", gfc_match_abstract_interface,
     535              :              ST_INTERFACE);
     536        15648 :       match ("allocate", gfc_match_allocate, ST_ALLOCATE);
     537          456 :       match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL);
     538          297 :       match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT);
     539          173 :       match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL);
     540          167 :       match ("automatic", gfc_match_automatic, ST_ATTR_DECL);
     541          165 :       break;
     542              : 
     543          616 :     case 'b':
     544          616 :       match ("backspace", gfc_match_backspace, ST_BACKSPACE);
     545          214 :       match ("block data", gfc_match_block_data, ST_BLOCK_DATA);
     546          126 :       match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL);
     547           25 :       break;
     548              : 
     549       113439 :     case 'c':
     550       113439 :       match ("call", gfc_match_call, ST_CALL);
     551        30621 :       match ("close", gfc_match_close, ST_CLOSE);
     552        27407 :       match ("continue", gfc_match_continue, ST_CONTINUE);
     553        24588 :       match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL);
     554        24584 :       match ("cycle", gfc_match_cycle, ST_CYCLE);
     555        24553 :       match ("case", gfc_match_case, ST_CASE);
     556        22903 :       match ("common", gfc_match_common, ST_COMMON);
     557        20886 :       match ("contains", gfc_match_eos, ST_CONTAINS);
     558         2467 :       match ("class", gfc_match_class_is, ST_CLASS_IS);
     559          281 :       match ("codimension", gfc_match_codimension, ST_ATTR_DECL);
     560          269 :       break;
     561              : 
     562         9011 :     case 'd':
     563         9011 :       match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE);
     564         3113 :       match ("data", gfc_match_data, ST_DATA);
     565          731 :       match ("dimension", gfc_match_dimension, ST_ATTR_DECL);
     566           96 :       break;
     567              : 
     568       202559 :     case 'e':
     569       202559 :       match ("end file", gfc_match_endfile, ST_END_FILE);
     570       202488 :       match ("exit", gfc_match_exit, ST_EXIT);
     571       202190 :       match ("else", gfc_match_else, ST_ELSE);
     572       198037 :       match ("else where", gfc_match_elsewhere, ST_ELSEWHERE);
     573       197725 :       match ("else if", gfc_match_elseif, ST_ELSEIF);
     574       195757 :       match ("error% stop", gfc_match_error_stop, ST_ERROR_STOP);
     575       194743 :       match ("enum , bind ( c )", gfc_match_enum, ST_ENUM);
     576              : 
     577       194585 :       if (gfc_match_end (&st) == MATCH_YES)
     578       189211 :         return st;
     579              : 
     580         5374 :       match ("entry% ", gfc_match_entry, ST_ENTRY);
     581         4580 :       match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE);
     582         3573 :       match ("external", gfc_match_external, ST_ATTR_DECL);
     583          362 :       match ("event% post", gfc_match_event_post, ST_EVENT_POST);
     584          328 :       match ("event% wait", gfc_match_event_wait, ST_EVENT_WAIT);
     585          307 :       break;
     586              : 
     587         1885 :     case 'f':
     588         1885 :       match ("fail% image", gfc_match_fail_image, ST_FAIL_IMAGE);
     589         1873 :       match ("final", gfc_match_final_decl, ST_FINAL);
     590         1366 :       match ("flush", gfc_match_flush, ST_FLUSH);
     591         1271 :       match ("form% team", gfc_match_form_team, ST_FORM_TEAM);
     592         1089 :       match ("format", gfc_match_format, ST_FORMAT);
     593           55 :       break;
     594              : 
     595         1753 :     case 'g':
     596         1753 :       match ("generic", gfc_match_generic, ST_GENERIC);
     597          701 :       match ("go to", gfc_match_goto, ST_GOTO);
     598           23 :       break;
     599              : 
     600        43201 :     case 'i':
     601        43201 :       match ("inquire", gfc_match_inquire, ST_INQUIRE);
     602        42235 :       match ("implicit", gfc_match_implicit, ST_IMPLICIT);
     603        41820 :       match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE);
     604        16788 :       match ("import", gfc_match_import, ST_IMPORT);
     605        13275 :       match ("interface", gfc_match_interface, ST_INTERFACE);
     606         2090 :       match ("intent", gfc_match_intent, ST_ATTR_DECL);
     607         1992 :       match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL);
     608          514 :       break;
     609              : 
     610           92 :     case 'l':
     611           92 :       match ("lock", gfc_match_lock, ST_LOCK);
     612           18 :       break;
     613              : 
     614        12324 :     case 'm':
     615        12324 :       match ("map", gfc_match_map, ST_MAP);
     616        12066 :       match ("module% procedure", gfc_match_modproc, ST_MODULE_PROC);
     617        10461 :       match ("module", gfc_match_module, ST_MODULE);
     618           28 :       break;
     619              : 
     620         1642 :     case 'n':
     621         1642 :       match ("nullify", gfc_match_nullify, ST_NULLIFY);
     622         1064 :       match ("namelist", gfc_match_namelist, ST_NAMELIST);
     623           17 :       break;
     624              : 
     625         4270 :     case 'o':
     626         4270 :       match ("open", gfc_match_open, ST_OPEN);
     627          249 :       match ("optional", gfc_match_optional, ST_ATTR_DECL);
     628           25 :       break;
     629              : 
     630        38441 :     case 'p':
     631        38441 :       match ("print", gfc_match_print, ST_WRITE);
     632        31060 :       match ("pause", gfc_match_pause, ST_PAUSE);
     633        31030 :       match ("pointer", gfc_match_pointer, ST_ATTR_DECL);
     634        30137 :       if (gfc_match_private (&st) == MATCH_YES)
     635         1635 :         return st;
     636        28502 :       match ("procedure", gfc_match_procedure, ST_PROCEDURE);
     637        22015 :       match ("program", gfc_match_program, ST_PROGRAM);
     638         1786 :       if (gfc_match_public (&st) == MATCH_YES)
     639         1527 :         return st;
     640          259 :       match ("protected", gfc_match_protected, ST_ATTR_DECL);
     641          242 :       break;
     642              : 
     643        14444 :     case 'r':
     644        14444 :       match ("rank", gfc_match_rank_is, ST_RANK);
     645        12052 :       match ("read", gfc_match_read, ST_READ);
     646         5339 :       match ("return", gfc_match_return, ST_RETURN);
     647         2517 :       match ("rewind", gfc_match_rewind, ST_REWIND);
     648          156 :       break;
     649              : 
     650        11710 :     case 's':
     651        11710 :       match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL);
     652        11412 :       match ("sequence", gfc_match_eos, ST_SEQUENCE);
     653        11172 :       match ("stop", gfc_match_stop, ST_STOP);
     654         2156 :       match ("save", gfc_match_save, ST_ATTR_DECL);
     655         1889 :       match ("static", gfc_match_static, ST_ATTR_DECL);
     656         1888 :       match ("submodule", gfc_match_submodule, ST_SUBMODULE);
     657         1615 :       match ("sync% all", gfc_match_sync_all, ST_SYNC_ALL);
     658          385 :       match ("sync% images", gfc_match_sync_images, ST_SYNC_IMAGES);
     659          242 :       match ("sync% memory", gfc_match_sync_memory, ST_SYNC_MEMORY);
     660          168 :       match ("sync% team", gfc_match_sync_team, ST_SYNC_TEAM);
     661          120 :       break;
     662              : 
     663        18260 :     case 't':
     664        18260 :       match ("target", gfc_match_target, ST_ATTR_DECL);
     665        18165 :       match ("type", gfc_match_derived_decl, ST_DERIVED_DECL);
     666         3885 :       match ("type% is", gfc_match_type_is, ST_TYPE_IS);
     667          153 :       break;
     668              : 
     669          223 :     case 'u':
     670          223 :       match ("union", gfc_match_union, ST_UNION);
     671           91 :       match ("unlock", gfc_match_unlock, ST_UNLOCK);
     672           29 :       break;
     673              : 
     674          143 :     case 'v':
     675          143 :       match ("value", gfc_match_value, ST_ATTR_DECL);
     676           56 :       match ("volatile", gfc_match_volatile, ST_ATTR_DECL);
     677           18 :       break;
     678              : 
     679        19284 :     case 'w':
     680        19284 :       match ("wait", gfc_match_wait, ST_WAIT);
     681        19195 :       match ("write", gfc_match_write, ST_WRITE);
     682           32 :       break;
     683              :     }
     684              : 
     685              :   /* All else has failed, so give up.  See if any of the matchers has
     686              :      stored an error message of some sort.  Suppress the "Unclassifiable
     687              :      statement" if a previous error message was emitted, e.g., by
     688              :      gfc_error_now ().  */
     689         2338 :   if (!gfc_error_check ())
     690              :     {
     691           63 :       int ecnt;
     692           63 :       gfc_get_errors (NULL, &ecnt);
     693           63 :       if (ecnt <= 0)
     694           19 :         gfc_error_now ("Unclassifiable statement at %C");
     695              :     }
     696              : 
     697         2336 :   reject_statement ();
     698              : 
     699         2336 :   gfc_error_recovery ();
     700              : 
     701         2336 :   return ST_NONE;
     702              : }
     703              : 
     704              : /* Like match and if spec_only, goto do_spec_only without actually
     705              :    matching.  If the directive matched but the parsing then failed,
     706              :    do not start matching the next directive in the same switch statement.  */
     707              : #define matcha(keyword, subr, st)                                       \
     708              :     do {                                                                \
     709              :       match m2;                                                         \
     710              :       if (spec_only && gfc_match (keyword) == MATCH_YES)                \
     711              :         goto do_spec_only;                                              \
     712              :       else if ((m2 = match_word (keyword, subr, &old_locus, true,   \
     713              :                                  false)) == MATCH_YES)                  \
     714              :         return st;                                                      \
     715              :       else if (m2 == MATCH_ERROR)                                       \
     716              :         goto error_handling;                                            \
     717              :       else                                                              \
     718              :         undo_new_statement ();                                          \
     719              :     } while (0)
     720              : 
     721              : static gfc_statement
     722        21280 : decode_oacc_directive (void)
     723              : {
     724        21280 :   locus old_locus;
     725        21280 :   char c;
     726        21280 :   bool spec_only = false;
     727              : 
     728        21280 :   gfc_enforce_clean_symbol_state ();
     729              : 
     730        21280 :   gfc_clear_error ();   /* Clear any pending errors.  */
     731        21280 :   gfc_clear_warning (); /* Clear any pending warnings.  */
     732              : 
     733        21280 :   gfc_matching_function = false;
     734              : 
     735        21280 :   if (gfc_current_state () == COMP_FUNCTION
     736          263 :       && gfc_current_block ()->result->ts.kind == -1)
     737        21280 :     spec_only = true;
     738              : 
     739        21280 :   old_locus = gfc_current_locus;
     740              : 
     741              :   /* General OpenACC directive matching: Instead of testing every possible
     742              :      statement, we eliminate most possibilities by peeking at the
     743              :      first character.  */
     744              : 
     745        21280 :   c = gfc_peek_ascii_char ();
     746              : 
     747        21280 :   switch (c)
     748              :     {
     749          718 :     case 'r':
     750          718 :       matcha ("routine", gfc_match_oacc_routine, ST_OACC_ROUTINE);
     751            0 :       break;
     752              :     }
     753              : 
     754        20562 :   gfc_unset_implicit_pure (NULL);
     755        20562 :   if (gfc_pure (NULL))
     756              :     {
     757            8 :       gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE "
     758              :                      "procedures at %C");
     759            8 :       goto error_handling;
     760              :     }
     761              : 
     762        20554 :   switch (c)
     763              :     {
     764          552 :     case 'a':
     765          552 :       matcha ("atomic", gfc_match_oacc_atomic, ST_OACC_ATOMIC);
     766            0 :       break;
     767           97 :     case 'c':
     768           97 :       matcha ("cache", gfc_match_oacc_cache, ST_OACC_CACHE);
     769            0 :       break;
     770          872 :     case 'd':
     771          872 :       matcha ("data", gfc_match_oacc_data, ST_OACC_DATA);
     772          182 :       matcha ("declare", gfc_match_oacc_declare, ST_OACC_DECLARE);
     773            0 :       break;
     774         8044 :     case 'e':
     775         8044 :       matcha ("end atomic", gfc_match_omp_eos_error, ST_OACC_END_ATOMIC);
     776         7532 :       matcha ("end data", gfc_match_omp_eos_error, ST_OACC_END_DATA);
     777         6845 :       matcha ("end host_data", gfc_match_omp_eos_error, ST_OACC_END_HOST_DATA);
     778         6783 :       matcha ("end kernels loop", gfc_match_omp_eos_error, ST_OACC_END_KERNELS_LOOP);
     779         6758 :       matcha ("end kernels", gfc_match_omp_eos_error, ST_OACC_END_KERNELS);
     780         5870 :       matcha ("end loop", gfc_match_omp_eos_error, ST_OACC_END_LOOP);
     781         5861 :       matcha ("end parallel loop", gfc_match_omp_eos_error,
     782              :               ST_OACC_END_PARALLEL_LOOP);
     783         4931 :       matcha ("end parallel", gfc_match_omp_eos_error, ST_OACC_END_PARALLEL);
     784         1981 :       matcha ("end serial loop", gfc_match_omp_eos_error,
     785              :               ST_OACC_END_SERIAL_LOOP);
     786         1829 :       matcha ("end serial", gfc_match_omp_eos_error, ST_OACC_END_SERIAL);
     787         1490 :       matcha ("enter data", gfc_match_oacc_enter_data, ST_OACC_ENTER_DATA);
     788          613 :       matcha ("exit data", gfc_match_oacc_exit_data, ST_OACC_EXIT_DATA);
     789            1 :       break;
     790           65 :     case 'h':
     791           65 :       matcha ("host_data", gfc_match_oacc_host_data, ST_OACC_HOST_DATA);
     792            0 :       break;
     793          134 :     case 'i':
     794          134 :       matcha ("init", gfc_match_oacc_init, ST_OACC_INIT);
     795            0 :       break;
     796         4354 :     case 'p':
     797         4354 :       matcha ("parallel loop", gfc_match_oacc_parallel_loop,
     798              :               ST_OACC_PARALLEL_LOOP);
     799         2975 :       matcha ("parallel", gfc_match_oacc_parallel, ST_OACC_PARALLEL);
     800            0 :       break;
     801         1036 :     case 'k':
     802         1036 :       matcha ("kernels loop", gfc_match_oacc_kernels_loop,
     803              :               ST_OACC_KERNELS_LOOP);
     804          907 :       matcha ("kernels", gfc_match_oacc_kernels, ST_OACC_KERNELS);
     805            0 :       break;
     806         3585 :     case 'l':
     807         3585 :       matcha ("loop", gfc_match_oacc_loop, ST_OACC_LOOP);
     808            0 :       break;
     809          850 :     case 's':
     810          850 :       matcha ("serial loop", gfc_match_oacc_serial_loop, ST_OACC_SERIAL_LOOP);
     811          620 :       matcha ("serial", gfc_match_oacc_serial, ST_OACC_SERIAL);
     812          260 :       matcha ("set", gfc_match_oacc_set, ST_OACC_SET);
     813          130 :       matcha ("shutdown", gfc_match_oacc_shutdown, ST_OACC_SHUTDOWN);
     814            0 :       break;
     815          760 :     case 'u':
     816          760 :       matcha ("update", gfc_match_oacc_update, ST_OACC_UPDATE);
     817            0 :       break;
     818          204 :     case 'w':
     819          204 :       matcha ("wait", gfc_match_oacc_wait, ST_OACC_WAIT);
     820            1 :       break;
     821              :     }
     822              : 
     823              :   /* Directive not found. */
     824            3 :   gfc_error_now ("Unclassifiable OpenACC directive at %C");
     825            3 :   goto recover;
     826              : 
     827              :   /* Directive found but failed with an error, possibly with
     828              :      a stored an error message.  */
     829          473 :  error_handling:
     830          473 :   if (gfc_error_check () == 0)
     831            1 :     gfc_error_now ("Syntax error in statement at %C");
     832              : 
     833          472 :  recover:
     834          476 :   reject_statement ();
     835          476 :   gfc_error_recovery ();
     836          476 :   return ST_NONE;
     837              : 
     838           30 :  do_spec_only:
     839           30 :   reject_statement ();
     840           30 :   gfc_clear_error ();
     841           30 :   gfc_buffer_error (false);
     842           30 :   gfc_current_locus = old_locus;
     843           30 :   return ST_GET_FCN_CHARACTERISTICS;
     844              : }
     845              : 
     846              : #undef matcha
     847              : 
     848              : /* Checks for the ST_OMP_ALLOCATE. First, check whether all list items
     849              :    are allocatables/pointers - and if so, assume it is associated with a Fortran
     850              :    ALLOCATE stmt.  If not, do some initial parsing-related checks and append
     851              :    namelist to namespace.
     852              :    The check follows OpenMP 5.1 by requiring an executable stmt or OpenMP
     853              :    construct before a directive associated with an allocate statement
     854              :    (-> ST_OMP_ALLOCATE_EXEC); instead of showing an error, conversion of
     855              :    ST_OMP_ALLOCATE -> ST_OMP_ALLOCATE_EXEC would be an alternative.  */
     856              : 
     857              : bool
     858          202 : check_omp_allocate_stmt (locus *loc)
     859              : {
     860          202 :   gfc_omp_namelist *n;
     861              : 
     862          202 :   if (new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL)
     863              :     {
     864            1 :       gfc_error ("%qs directive at %L must either have a variable argument or, "
     865              :                  "if associated with an ALLOCATE stmt, must be preceded by an "
     866              :                  "executable statement or OpenMP construct",
     867              :                  gfc_ascii_statement (ST_OMP_ALLOCATE), loc);
     868            1 :       return false;
     869              :     }
     870              :   bool has_allocatable = false;
     871              :   bool has_non_allocatable = false;
     872          429 :   for (n = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next)
     873              :     {
     874          228 :       if (n->expr)
     875              :         {
     876            0 :           gfc_error ("Structure-component expression at %L in %qs directive not"
     877              :                      " permitted in declarative directive; as directive "
     878              :                      "associated with an ALLOCATE stmt it must be preceded by "
     879              :                      "an executable statement or OpenMP construct",
     880            0 :                       &n->expr->where, gfc_ascii_statement (ST_OMP_ALLOCATE));
     881            0 :           return false;
     882              :         }
     883              :       /* Procedure pointers are not allocatable; hence, we do not regard them as
     884              :          pointers here - and reject them later in gfc_resolve_omp_allocate.  */
     885          228 :       bool alloc_ptr;
     886          228 :       if (n->sym->ts.type == BT_CLASS && n->sym->attr.class_ok)
     887            0 :         alloc_ptr = (CLASS_DATA (n->sym)->attr.allocatable
     888            0 :                      || CLASS_DATA (n->sym)->attr.class_pointer);
     889              :       else
     890          228 :         alloc_ptr = n->sym->attr.allocatable || n->sym->attr.pointer;
     891              :       if (alloc_ptr
     892          223 :           || (n->sym->ns && n->sym->ns->proc_name
     893          215 :               && (n->sym->ns->proc_name->attr.allocatable
     894          215 :                   || n->sym->ns->proc_name->attr.pointer)))
     895              :         has_allocatable = true;
     896              :       else
     897          228 :         has_non_allocatable = true;
     898              :     }
     899              :   /* All allocatables - assume it is allocated with an ALLOCATE stmt.  */
     900          201 :   if (has_allocatable && !has_non_allocatable)
     901              :     {
     902            3 :       gfc_error ("%qs directive at %L associated with an ALLOCATE stmt must be "
     903              :                  "preceded by an executable statement or OpenMP construct; "
     904              :                  "note the variables in the list all have the allocatable or "
     905              :                  "pointer attribute", gfc_ascii_statement (ST_OMP_ALLOCATE),
     906              :                  loc);
     907            3 :       return false;
     908              :     }
     909          198 :   if (!gfc_current_ns->omp_allocate)
     910           62 :     gfc_current_ns->omp_allocate
     911           62 :       = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
     912              :   else
     913              :     {
     914          737 :       for (n = gfc_current_ns->omp_allocate; n->next; n = n->next)
     915              :         ;
     916          136 :       n->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
     917              :     }
     918          198 :   new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL;
     919          198 :   gfc_free_omp_clauses (new_st.ext.omp_clauses);
     920          198 :   return true;
     921              : }
     922              : 
     923              : 
     924              : /* Like match, but set a flag simd_matched if keyword matched
     925              :    and if spec_only, goto do_spec_only without actually matching.  */
     926              : #define matchs(keyword, subr, st)                               \
     927              :     do {                                                        \
     928              :       match m2;                                                 \
     929              :       if (spec_only && gfc_match (keyword) == MATCH_YES)        \
     930              :         goto do_spec_only;                                      \
     931              :       if ((m2 = match_word_omp_simd (keyword, subr, &old_locus,     \
     932              :                                &simd_matched)) == MATCH_YES)        \
     933              :         {                                                       \
     934              :           ret = st;                                             \
     935              :           goto finish;                                          \
     936              :         }                                                       \
     937              :       else if (m2 == MATCH_ERROR)                               \
     938              :         goto error_handling;                                    \
     939              :       else                                                      \
     940              :         undo_new_statement ();                                  \
     941              :     } while (0)
     942              : 
     943              : /* Like match, but don't match anything if not -fopenmp
     944              :    and if spec_only, goto do_spec_only without actually matching.  */
     945              : /* If the directive matched but the clauses failed, do not start
     946              :    matching the next directive in the same switch statement. */
     947              : #define matcho(keyword, subr, st)                                       \
     948              :     do {                                                                \
     949              :       match m2;                                                         \
     950              :       if (!flag_openmp)                                                 \
     951              :         ;                                                               \
     952              :       else if (spec_only && gfc_match (keyword) == MATCH_YES)           \
     953              :         goto do_spec_only;                                              \
     954              :       else if ((m2 = match_word (keyword, subr, &old_locus, true,   \
     955              :                                  false)) == MATCH_YES)                  \
     956              :         {                                                               \
     957              :           ret = st;                                                     \
     958              :           goto finish;                                                  \
     959              :         }                                                               \
     960              :       else if (m2 == MATCH_ERROR)                                       \
     961              :         goto error_handling;                                            \
     962              :       else                                                              \
     963              :         undo_new_statement ();                                          \
     964              :     } while (0)
     965              : 
     966              : /* Like match, but set a flag simd_matched if keyword matched.  */
     967              : #define matchds(keyword, subr, st)                              \
     968              :     do {                                                        \
     969              :       match m2;                                                 \
     970              :       if ((m2 = match_word_omp_simd (keyword, subr, &old_locus,     \
     971              :                                &simd_matched)) == MATCH_YES)        \
     972              :         {                                                       \
     973              :           ret = st;                                             \
     974              :           goto finish;                                          \
     975              :         }                                                       \
     976              :       else if (m2 == MATCH_ERROR)                               \
     977              :         goto error_handling;                                    \
     978              :       else                                                      \
     979              :         undo_new_statement ();                                  \
     980              :     } while (0)
     981              : 
     982              : /* Like match, but don't match anything if not -fopenmp.  */
     983              : #define matchdo(keyword, subr, st)                                      \
     984              :     do {                                                                \
     985              :       match m2;                                                         \
     986              :       if (!flag_openmp)                                                 \
     987              :         ;                                                               \
     988              :       else if ((m2 = match_word (keyword, subr, &old_locus, true,   \
     989              :                                  false)) == MATCH_YES)                  \
     990              :         {                                                               \
     991              :           ret = st;                                                     \
     992              :           goto finish;                                                  \
     993              :         }                                                               \
     994              :       else if (m2 == MATCH_ERROR)                                       \
     995              :         goto error_handling;                                            \
     996              :       else                                                              \
     997              :         undo_new_statement ();                                          \
     998              :     } while (0)
     999              : 
    1000              : static gfc_statement
    1001        34853 : decode_omp_directive (void)
    1002              : {
    1003        34853 :   locus old_locus;
    1004        34853 :   char c;
    1005        34853 :   bool simd_matched = false;
    1006        34853 :   bool spec_only = false;
    1007        34853 :   gfc_statement ret = ST_NONE;
    1008        34853 :   bool pure_ok = true;
    1009              : 
    1010        34853 :   gfc_enforce_clean_symbol_state ();
    1011              : 
    1012        34853 :   gfc_clear_error ();   /* Clear any pending errors.  */
    1013        34853 :   gfc_clear_warning (); /* Clear any pending warnings.  */
    1014              : 
    1015        34853 :   gfc_matching_function = false;
    1016              : 
    1017        34853 :   if (gfc_current_state () == COMP_FUNCTION
    1018         1504 :       && gfc_current_block ()->result->ts.kind == -1)
    1019        34853 :     spec_only = true;
    1020              : 
    1021        34853 :   old_locus = gfc_current_locus;
    1022              : 
    1023              :   /* General OpenMP directive matching: Instead of testing every possible
    1024              :      statement, we eliminate most possibilities by peeking at the
    1025              :      first character.  */
    1026              : 
    1027        34853 :   c = gfc_peek_ascii_char ();
    1028              : 
    1029              :   /* match is for directives that should be recognized only if
    1030              :      -fopenmp, matchs for directives that should be recognized
    1031              :      if either -fopenmp or -fopenmp-simd.
    1032              :      Handle only the directives allowed in PURE procedures
    1033              :      first (those also shall not turn off implicit pure).  */
    1034        34853 :   switch (c)
    1035              :     {
    1036         2564 :     case 'a':
    1037              :       /* For -fopenmp-simd, ignore 'assumes'; note no clause starts with 's'. */
    1038         2564 :       if (!flag_openmp && gfc_match ("assumes") == MATCH_YES)
    1039              :         break;
    1040         2562 :       matcho ("assumes", gfc_match_omp_assumes, ST_OMP_ASSUMES);
    1041         2517 :       matchs ("assume", gfc_match_omp_assume, ST_OMP_ASSUME);
    1042         2492 :       break;
    1043              : 
    1044          665 :     case 'b':
    1045          665 :       matcho ("begin metadirective", gfc_match_omp_begin_metadirective,
    1046              :               ST_OMP_BEGIN_METADIRECTIVE);
    1047              :       break;
    1048              : 
    1049         3671 :     case 'd':
    1050         3671 :       matchdo ("declare mapper", gfc_match_omp_declare_mapper,
    1051              :                ST_OMP_DECLARE_MAPPER);
    1052         3639 :       matchdo ("declare_mapper", gfc_match_omp_declare_mapper,
    1053              :                ST_OMP_DECLARE_MAPPER);
    1054         3636 :       matchds ("declare reduction", gfc_match_omp_declare_reduction,
    1055              :                ST_OMP_DECLARE_REDUCTION);
    1056         3046 :       matchds ("declare_reduction", gfc_match_omp_declare_reduction,
    1057              :                ST_OMP_DECLARE_REDUCTION);
    1058         3042 :       matchds ("declare simd", gfc_match_omp_declare_simd,
    1059              :                ST_OMP_DECLARE_SIMD);
    1060         2838 :       matchds ("declare_simd", gfc_match_omp_declare_simd,
    1061              :                ST_OMP_DECLARE_SIMD);
    1062         2834 :       matchdo ("declare target", gfc_match_omp_declare_target,
    1063              :                ST_OMP_DECLARE_TARGET);
    1064         2333 :       matchdo ("declare_target", gfc_match_omp_declare_target,
    1065              :                ST_OMP_DECLARE_TARGET);
    1066         2330 :       matchdo ("declare variant", gfc_match_omp_declare_variant,
    1067              :                ST_OMP_DECLARE_VARIANT);
    1068         1908 :       matchdo ("declare_variant", gfc_match_omp_declare_variant,
    1069              :                ST_OMP_DECLARE_VARIANT);
    1070              :       break;
    1071        10132 :     case 'e':
    1072        10132 :       matchs ("end assume", gfc_match_omp_eos_error, ST_OMP_END_ASSUME);
    1073        10120 :       matcho ("end metadirective", gfc_match_omp_eos_error,
    1074              :               ST_OMP_END_METADIRECTIVE);
    1075        10022 :       matchs ("end simd", gfc_match_omp_eos_error, ST_OMP_END_SIMD);
    1076         9970 :       matchs ("end tile", gfc_match_omp_eos_error, ST_OMP_END_TILE);
    1077         9924 :       matchs ("end unroll", gfc_match_omp_eos_error, ST_OMP_END_UNROLL);
    1078         9883 :       matcho ("error", gfc_match_omp_error, ST_OMP_ERROR);
    1079              :       break;
    1080              : 
    1081          350 :     case 'm':
    1082          350 :       matcho ("metadirective", gfc_match_omp_metadirective,
    1083              :               ST_OMP_METADIRECTIVE);
    1084              :       break;
    1085              : 
    1086           24 :     case 'n':
    1087           24 :       matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
    1088              :       break;
    1089         1909 :     case 's':
    1090         1909 :       matchs ("scan", gfc_match_omp_scan, ST_OMP_SCAN);
    1091         1858 :       matchs ("simd", gfc_match_omp_simd, ST_OMP_SIMD);
    1092          981 :       break;
    1093         9349 :     case 't':
    1094         9349 :       matchs ("tile", gfc_match_omp_tile, ST_OMP_TILE);
    1095         9144 :       break;
    1096          425 :     case 'u':
    1097          425 :       matchs ("unroll", gfc_match_omp_unroll, ST_OMP_UNROLL);
    1098            0 :       break;
    1099              :     }
    1100              : 
    1101        30906 :   pure_ok = false;
    1102        30906 :   if (flag_openmp && gfc_pure (NULL))
    1103              :     {
    1104           16 :       gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
    1105              :                      "appear in a PURE procedure");
    1106           16 :       gfc_error_recovery ();
    1107           16 :       return ST_NONE;
    1108              :     }
    1109              : 
    1110              :   /* match is for directives that should be recognized only if
    1111              :      -fopenmp, matchs for directives that should be recognized
    1112              :      if either -fopenmp or -fopenmp-simd.  */
    1113        30890 :   switch (c)
    1114              :     {
    1115         2494 :     case 'a':
    1116         2494 :       if (in_exec_part)
    1117         2049 :         matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE_EXEC);
    1118              :       else
    1119          445 :         matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE);
    1120         2218 :       matcho ("allocators", gfc_match_omp_allocators, ST_OMP_ALLOCATORS);
    1121         2192 :       matcho ("atomic", gfc_match_omp_atomic, ST_OMP_ATOMIC);
    1122              :       break;
    1123          618 :     case 'b':
    1124          618 :       matcho ("barrier", gfc_match_omp_barrier, ST_OMP_BARRIER);
    1125              :       break;
    1126          677 :     case 'c':
    1127          677 :       matcho ("cancellation% point", gfc_match_omp_cancellation_point,
    1128              :               ST_OMP_CANCELLATION_POINT);
    1129          501 :       matcho ("cancellation_point", gfc_match_omp_cancellation_point,
    1130              :               ST_OMP_CANCELLATION_POINT);
    1131          499 :       matcho ("cancel", gfc_match_omp_cancel, ST_OMP_CANCEL);
    1132          175 :       matcho ("critical", gfc_match_omp_critical, ST_OMP_CRITICAL);
    1133              :       break;
    1134         1893 :     case 'd':
    1135         1893 :       matcho ("depobj", gfc_match_omp_depobj, ST_OMP_DEPOBJ);
    1136         1765 :       matcho ("dispatch", gfc_match_omp_dispatch, ST_OMP_DISPATCH);
    1137         1605 :       matchs ("distribute parallel do simd",
    1138              :               gfc_match_omp_distribute_parallel_do_simd,
    1139              :               ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD);
    1140         1571 :       matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do,
    1141              :               ST_OMP_DISTRIBUTE_PARALLEL_DO);
    1142         1524 :       matchs ("distribute simd", gfc_match_omp_distribute_simd,
    1143              :               ST_OMP_DISTRIBUTE_SIMD);
    1144         1472 :       matcho ("distribute", gfc_match_omp_distribute, ST_OMP_DISTRIBUTE);
    1145         1415 :       matchs ("do simd", gfc_match_omp_do_simd, ST_OMP_DO_SIMD);
    1146         1258 :       matcho ("do", gfc_match_omp_do, ST_OMP_DO);
    1147              :       break;
    1148         9773 :     case 'e':
    1149         9773 :       matcho ("end allocators", gfc_match_omp_eos_error, ST_OMP_END_ALLOCATORS);
    1150         9768 :       matcho ("end atomic", gfc_match_omp_eos_error, ST_OMP_END_ATOMIC);
    1151         9550 :       matcho ("end critical", gfc_match_omp_end_critical, ST_OMP_END_CRITICAL);
    1152         9384 :       matcho ("end dispatch", gfc_match_omp_end_nowait, ST_OMP_END_DISPATCH);
    1153         9378 :       matchs ("end distribute parallel do simd", gfc_match_omp_eos_error,
    1154              :               ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD);
    1155         9371 :       matcho ("end distribute parallel do", gfc_match_omp_eos_error,
    1156              :               ST_OMP_END_DISTRIBUTE_PARALLEL_DO);
    1157         9364 :       matchs ("end distribute simd", gfc_match_omp_eos_error,
    1158              :               ST_OMP_END_DISTRIBUTE_SIMD);
    1159         9357 :       matcho ("end distribute", gfc_match_omp_eos_error, ST_OMP_END_DISTRIBUTE);
    1160         9342 :       matchs ("end do simd", gfc_match_omp_end_nowait, ST_OMP_END_DO_SIMD);
    1161         9309 :       matcho ("end do", gfc_match_omp_end_nowait, ST_OMP_END_DO);
    1162         9048 :       matchs ("end loop", gfc_match_omp_eos_error, ST_OMP_END_LOOP);
    1163         9044 :       matcho ("end masked taskloop simd", gfc_match_omp_eos_error,
    1164              :               ST_OMP_END_MASKED_TASKLOOP_SIMD);
    1165         9033 :       matcho ("end masked taskloop", gfc_match_omp_eos_error,
    1166              :               ST_OMP_END_MASKED_TASKLOOP);
    1167         9026 :       matcho ("end masked", gfc_match_omp_eos_error, ST_OMP_END_MASKED);
    1168         8972 :       matcho ("end master taskloop simd", gfc_match_omp_eos_error,
    1169              :               ST_OMP_END_MASTER_TASKLOOP_SIMD);
    1170         8967 :       matcho ("end master taskloop", gfc_match_omp_eos_error,
    1171              :               ST_OMP_END_MASTER_TASKLOOP);
    1172         8962 :       matcho ("end master", gfc_match_omp_eos_error, ST_OMP_END_MASTER);
    1173         8851 :       matchs ("end ordered", gfc_match_omp_eos_error, ST_OMP_END_ORDERED);
    1174         8612 :       matchs ("end parallel do simd", gfc_match_omp_eos_error,
    1175              :               ST_OMP_END_PARALLEL_DO_SIMD);
    1176         8570 :       matcho ("end parallel do", gfc_match_omp_eos_error,
    1177              :               ST_OMP_END_PARALLEL_DO);
    1178         8367 :       matcho ("end parallel loop", gfc_match_omp_eos_error,
    1179              :               ST_OMP_END_PARALLEL_LOOP);
    1180         8366 :       matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error,
    1181              :               ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD);
    1182         8358 :       matcho ("end parallel masked taskloop", gfc_match_omp_eos_error,
    1183              :               ST_OMP_END_PARALLEL_MASKED_TASKLOOP);
    1184         8351 :       matcho ("end parallel masked", gfc_match_omp_eos_error,
    1185              :               ST_OMP_END_PARALLEL_MASKED);
    1186         8337 :       matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error,
    1187              :               ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD);
    1188         8331 :       matcho ("end parallel master taskloop", gfc_match_omp_eos_error,
    1189              :               ST_OMP_END_PARALLEL_MASTER_TASKLOOP);
    1190         8326 :       matcho ("end parallel master", gfc_match_omp_eos_error,
    1191              :               ST_OMP_END_PARALLEL_MASTER);
    1192         8312 :       matcho ("end parallel sections", gfc_match_omp_eos_error,
    1193              :               ST_OMP_END_PARALLEL_SECTIONS);
    1194         8252 :       matcho ("end parallel workshare", gfc_match_omp_eos_error,
    1195              :               ST_OMP_END_PARALLEL_WORKSHARE);
    1196         8196 :       matcho ("end parallel", gfc_match_omp_eos_error, ST_OMP_END_PARALLEL);
    1197         6046 :       matcho ("end scope", gfc_match_omp_end_nowait, ST_OMP_END_SCOPE);
    1198         5986 :       matcho ("end sections", gfc_match_omp_end_nowait, ST_OMP_END_SECTIONS);
    1199         5905 :       matcho ("end single", gfc_match_omp_end_single, ST_OMP_END_SINGLE);
    1200         5335 :       matcho ("end target data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA);
    1201         3944 :       matcho ("end target_data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA);
    1202         3942 :       matchs ("end target parallel do simd", gfc_match_omp_end_nowait,
    1203              :               ST_OMP_END_TARGET_PARALLEL_DO_SIMD);
    1204         3933 :       matcho ("end target parallel do", gfc_match_omp_end_nowait,
    1205              :               ST_OMP_END_TARGET_PARALLEL_DO);
    1206         3924 :       matcho ("end target parallel loop", gfc_match_omp_end_nowait,
    1207              :               ST_OMP_END_TARGET_PARALLEL_LOOP);
    1208         3917 :       matcho ("end target parallel", gfc_match_omp_end_nowait,
    1209              :               ST_OMP_END_TARGET_PARALLEL);
    1210         3894 :       matchs ("end target simd", gfc_match_omp_end_nowait, ST_OMP_END_TARGET_SIMD);
    1211         3875 :       matchs ("end target teams distribute parallel do simd",
    1212              :               gfc_match_omp_end_nowait,
    1213              :               ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
    1214         3855 :       matcho ("end target teams distribute parallel do", gfc_match_omp_end_nowait,
    1215              :               ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO);
    1216         3840 :       matchs ("end target teams distribute simd", gfc_match_omp_end_nowait,
    1217              :               ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD);
    1218         3831 :       matcho ("end target teams distribute", gfc_match_omp_end_nowait,
    1219              :               ST_OMP_END_TARGET_TEAMS_DISTRIBUTE);
    1220         3822 :       matcho ("end target teams loop", gfc_match_omp_end_nowait,
    1221              :               ST_OMP_END_TARGET_TEAMS_LOOP);
    1222         3814 :       matcho ("end target teams", gfc_match_omp_end_nowait,
    1223              :               ST_OMP_END_TARGET_TEAMS);
    1224         3734 :       matcho ("end target", gfc_match_omp_end_nowait, ST_OMP_END_TARGET);
    1225         1615 :       matcho ("end taskgroup", gfc_match_omp_eos_error, ST_OMP_END_TASKGROUP);
    1226         1428 :       matchs ("end taskloop simd", gfc_match_omp_eos_error,
    1227              :               ST_OMP_END_TASKLOOP_SIMD);
    1228         1416 :       matcho ("end taskloop", gfc_match_omp_eos_error, ST_OMP_END_TASKLOOP);
    1229         1398 :       matcho ("end task", gfc_match_omp_eos_error, ST_OMP_END_TASK);
    1230          296 :       matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error,
    1231              :               ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
    1232          288 :       matcho ("end teams distribute parallel do", gfc_match_omp_eos_error,
    1233              :               ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO);
    1234          279 :       matchs ("end teams distribute simd", gfc_match_omp_eos_error,
    1235              :               ST_OMP_END_TEAMS_DISTRIBUTE_SIMD);
    1236          248 :       matcho ("end teams distribute", gfc_match_omp_eos_error,
    1237              :               ST_OMP_END_TEAMS_DISTRIBUTE);
    1238          239 :       matcho ("end teams loop", gfc_match_omp_eos_error, ST_OMP_END_TEAMS_LOOP);
    1239          238 :       matcho ("end teams", gfc_match_omp_eos_error, ST_OMP_END_TEAMS);
    1240           63 :       matcho ("end workshare", gfc_match_omp_end_nowait,
    1241              :               ST_OMP_END_WORKSHARE);
    1242              :       break;
    1243          101 :     case 'f':
    1244          101 :       matcho ("flush", gfc_match_omp_flush, ST_OMP_FLUSH);
    1245              :       break;
    1246           51 :     case 'g':
    1247           51 :       matchdo ("groupprivate", gfc_match_omp_groupprivate, ST_OMP_GROUPPRIVATE);
    1248              :       break;
    1249          111 :     case 'i':
    1250          111 :       matcho ("interop", gfc_match_omp_interop, ST_OMP_INTEROP);
    1251              :       break;
    1252          230 :     case 'm':
    1253          230 :       matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd,
    1254              :               ST_OMP_MASKED_TASKLOOP_SIMD);
    1255          214 :       matcho ("masked taskloop", gfc_match_omp_masked_taskloop,
    1256              :               ST_OMP_MASKED_TASKLOOP);
    1257          204 :       matcho ("masked", gfc_match_omp_masked, ST_OMP_MASKED);
    1258          149 :       matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd,
    1259              :               ST_OMP_MASTER_TASKLOOP_SIMD);
    1260          128 :       matcho ("master taskloop", gfc_match_omp_master_taskloop,
    1261              :               ST_OMP_MASTER_TASKLOOP);
    1262          112 :       matcho ("master", gfc_match_omp_master, ST_OMP_MASTER);
    1263              :       break;
    1264            0 :     case 'n':
    1265            0 :       matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
    1266              :       break;
    1267           71 :     case 'l':
    1268           71 :       matchs ("loop", gfc_match_omp_loop, ST_OMP_LOOP);
    1269            0 :       break;
    1270          558 :     case 'o':
    1271          558 :       if (gfc_match ("ordered depend (") == MATCH_YES
    1272          558 :           || gfc_match ("ordered doacross (") == MATCH_YES)
    1273              :         {
    1274          319 :           gfc_current_locus = old_locus;
    1275          319 :           if (!flag_openmp)
    1276              :             break;
    1277          317 :           matcho ("ordered", gfc_match_omp_ordered_depend,
    1278              :                   ST_OMP_ORDERED_DEPEND);
    1279              :         }
    1280              :       else
    1281          239 :         matchs ("ordered", gfc_match_omp_ordered, ST_OMP_ORDERED);
    1282              :       break;
    1283         4041 :     case 'p':
    1284         4041 :       matchs ("parallel do simd", gfc_match_omp_parallel_do_simd,
    1285              :               ST_OMP_PARALLEL_DO_SIMD);
    1286         3696 :       matcho ("parallel do", gfc_match_omp_parallel_do, ST_OMP_PARALLEL_DO);
    1287         2489 :       matcho ("parallel loop", gfc_match_omp_parallel_loop,
    1288              :               ST_OMP_PARALLEL_LOOP);
    1289         2458 :       matcho ("parallel masked taskloop simd",
    1290              :               gfc_match_omp_parallel_masked_taskloop_simd,
    1291              :               ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD);
    1292         2445 :       matcho ("parallel masked taskloop",
    1293              :               gfc_match_omp_parallel_masked_taskloop,
    1294              :               ST_OMP_PARALLEL_MASKED_TASKLOOP);
    1295         2435 :       matcho ("parallel masked", gfc_match_omp_parallel_masked,
    1296              :               ST_OMP_PARALLEL_MASKED);
    1297         2421 :       matcho ("parallel master taskloop simd",
    1298              :               gfc_match_omp_parallel_master_taskloop_simd,
    1299              :               ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD);
    1300         2400 :       matcho ("parallel master taskloop",
    1301              :               gfc_match_omp_parallel_master_taskloop,
    1302              :               ST_OMP_PARALLEL_MASTER_TASKLOOP);
    1303         2384 :       matcho ("parallel master", gfc_match_omp_parallel_master,
    1304              :               ST_OMP_PARALLEL_MASTER);
    1305         2370 :       matcho ("parallel sections", gfc_match_omp_parallel_sections,
    1306              :               ST_OMP_PARALLEL_SECTIONS);
    1307         2311 :       matcho ("parallel workshare", gfc_match_omp_parallel_workshare,
    1308              :               ST_OMP_PARALLEL_WORKSHARE);
    1309         2255 :       matcho ("parallel", gfc_match_omp_parallel, ST_OMP_PARALLEL);
    1310              :       break;
    1311          111 :     case 'r':
    1312          111 :       matcho ("requires", gfc_match_omp_requires, ST_OMP_REQUIRES);
    1313              :       break;
    1314          981 :     case 's':
    1315          981 :       matcho ("scope", gfc_match_omp_scope, ST_OMP_SCOPE);
    1316          923 :       matcho ("sections", gfc_match_omp_sections, ST_OMP_SECTIONS);
    1317          841 :       matcho ("section", gfc_match_omp_eos_error, ST_OMP_SECTION);
    1318          583 :       matcho ("single", gfc_match_omp_single, ST_OMP_SINGLE);
    1319              :       break;
    1320         9138 :     case 't':
    1321         9138 :       matcho ("target data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA);
    1322         7736 :       matcho ("target_data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA);
    1323         7734 :       matcho ("target enter data", gfc_match_omp_target_enter_data,
    1324              :               ST_OMP_TARGET_ENTER_DATA);
    1325         7265 :       matcho ("target_enter_data", gfc_match_omp_target_enter_data,
    1326              :               ST_OMP_TARGET_ENTER_DATA);
    1327         7262 :       matcho ("target exit data", gfc_match_omp_target_exit_data,
    1328              :               ST_OMP_TARGET_EXIT_DATA);
    1329         6897 :       matcho ("target_exit_data", gfc_match_omp_target_exit_data,
    1330              :               ST_OMP_TARGET_EXIT_DATA);
    1331         6895 :       matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd,
    1332              :               ST_OMP_TARGET_PARALLEL_DO_SIMD);
    1333         6874 :       matcho ("target parallel do", gfc_match_omp_target_parallel_do,
    1334              :               ST_OMP_TARGET_PARALLEL_DO);
    1335         6792 :       matcho ("target parallel loop", gfc_match_omp_target_parallel_loop,
    1336              :               ST_OMP_TARGET_PARALLEL_LOOP);
    1337         6775 :       matcho ("target parallel", gfc_match_omp_target_parallel,
    1338              :               ST_OMP_TARGET_PARALLEL);
    1339         6745 :       matchs ("target simd", gfc_match_omp_target_simd, ST_OMP_TARGET_SIMD);
    1340         6710 :       matchs ("target teams distribute parallel do simd",
    1341              :               gfc_match_omp_target_teams_distribute_parallel_do_simd,
    1342              :               ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
    1343         6656 :       matcho ("target teams distribute parallel do",
    1344              :               gfc_match_omp_target_teams_distribute_parallel_do,
    1345              :               ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO);
    1346         6588 :       matchs ("target teams distribute simd",
    1347              :               gfc_match_omp_target_teams_distribute_simd,
    1348              :               ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD);
    1349         6566 :       matcho ("target teams distribute", gfc_match_omp_target_teams_distribute,
    1350              :               ST_OMP_TARGET_TEAMS_DISTRIBUTE);
    1351         6546 :       matcho ("target teams loop", gfc_match_omp_target_teams_loop,
    1352              :               ST_OMP_TARGET_TEAMS_LOOP);
    1353         6527 :       matcho ("target teams", gfc_match_omp_target_teams, ST_OMP_TARGET_TEAMS);
    1354         6444 :       matcho ("target update", gfc_match_omp_target_update,
    1355              :               ST_OMP_TARGET_UPDATE);
    1356         4651 :       matcho ("target_update", gfc_match_omp_target_update,
    1357              :               ST_OMP_TARGET_UPDATE);
    1358         4649 :       matcho ("target", gfc_match_omp_target, ST_OMP_TARGET);
    1359         2320 :       matcho ("taskgroup", gfc_match_omp_taskgroup, ST_OMP_TASKGROUP);
    1360         2132 :       matchs ("taskloop simd", gfc_match_omp_taskloop_simd,
    1361              :               ST_OMP_TASKLOOP_SIMD);
    1362         2092 :       matcho ("taskloop", gfc_match_omp_taskloop, ST_OMP_TASKLOOP);
    1363         2019 :       matcho ("taskwait", gfc_match_omp_taskwait, ST_OMP_TASKWAIT);
    1364         1869 :       matcho ("taskyield", gfc_match_omp_taskyield, ST_OMP_TASKYIELD);
    1365         1859 :       matcho ("task", gfc_match_omp_task, ST_OMP_TASK);
    1366          675 :       matchs ("teams distribute parallel do simd",
    1367              :               gfc_match_omp_teams_distribute_parallel_do_simd,
    1368              :               ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD);
    1369          607 :       matcho ("teams distribute parallel do",
    1370              :               gfc_match_omp_teams_distribute_parallel_do,
    1371              :               ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO);
    1372          563 :       matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd,
    1373              :               ST_OMP_TEAMS_DISTRIBUTE_SIMD);
    1374          516 :       matcho ("teams distribute", gfc_match_omp_teams_distribute,
    1375              :               ST_OMP_TEAMS_DISTRIBUTE);
    1376          490 :       matcho ("teams loop", gfc_match_omp_teams_loop, ST_OMP_TEAMS_LOOP);
    1377          452 :       matcho ("teams", gfc_match_omp_teams, ST_OMP_TEAMS);
    1378          219 :       matchdo ("threadprivate", gfc_match_omp_threadprivate,
    1379              :                ST_OMP_THREADPRIVATE);
    1380              :       break;
    1381           40 :     case 'w':
    1382           40 :       matcho ("workshare", gfc_match_omp_workshare, ST_OMP_WORKSHARE);
    1383              :       break;
    1384              :     }
    1385              : 
    1386              :   /* Directive not found.  Don't error out if not -fopenmp and
    1387              :      simd_matched is false, i.e. if a directive other than one marked
    1388              :      with match has been seen.  */
    1389           71 :   if (flag_openmp || simd_matched)
    1390            8 :     gfc_error_now ("Unclassifiable OpenMP directive at %C");
    1391           71 :   goto recover;
    1392              : 
    1393          731 :  error_handling:
    1394              :   /* Directive found but failed with an error, possibly with
    1395              :      a stored an error message.  */
    1396          731 :   if ((flag_openmp || simd_matched) && gfc_error_check () == 0)
    1397            0 :     gfc_error_now ("Syntax error in statement at %C");
    1398              : 
    1399          802 :  recover:
    1400              : 
    1401              :   /* If parsing a metadirective, let the caller deal with the cleanup.  */
    1402          802 :   if (gfc_matching_omp_context_selector)
    1403              :     return ST_NONE;
    1404              : 
    1405          801 :   reject_statement ();
    1406              : 
    1407          801 :   gfc_error_recovery ();
    1408              : 
    1409          801 :   return ST_NONE;
    1410              : 
    1411        34016 :  finish:
    1412        34016 :   if (ret == ST_OMP_ERROR && new_st.ext.omp_clauses->at == OMP_AT_EXECUTION)
    1413              :     {
    1414           48 :       gfc_unset_implicit_pure (NULL);
    1415              : 
    1416           48 :       if (gfc_pure (NULL))
    1417              :         {
    1418            1 :           gfc_error_now ("OpenMP ERROR directive at %L with %<at(execution)%> "
    1419              :                          "clause in a PURE procedure", &old_locus);
    1420            1 :           reject_statement ();
    1421            1 :           gfc_error_recovery ();
    1422            1 :           return ST_NONE;
    1423              :         }
    1424              :     }
    1425        34015 :   if (!pure_ok)
    1426              :     {
    1427        30345 :       gfc_unset_implicit_pure (NULL);
    1428              : 
    1429        30345 :       if (!flag_openmp && gfc_pure (NULL))
    1430              :         {
    1431            3 :           gfc_error_now ("OpenMP directive at %C is not pure and thus may not "
    1432              :                          "appear in a PURE procedure");
    1433            3 :           reject_statement ();
    1434            3 :           gfc_error_recovery ();
    1435            3 :           return ST_NONE;
    1436              :         }
    1437              :     }
    1438        34012 :   if (ret == ST_OMP_ALLOCATE && !check_omp_allocate_stmt (&old_locus))
    1439            4 :     goto error_handling;
    1440              : 
    1441        34008 :   switch (ret)
    1442              :     {
    1443              :     /* For the constraints on clauses with the global requirement property,
    1444              :        we set omp_target_seen. This included all clauses that take the
    1445              :        DEVICE clause, (BEGIN) DECLARE_TARGET and procedures run the device
    1446              :        (which effectively is implied by the former).  */
    1447         7283 :     case ST_OMP_DECLARE_TARGET:
    1448         7283 :     case ST_OMP_INTEROP:
    1449         7283 :     case ST_OMP_TARGET:
    1450         7283 :     case ST_OMP_TARGET_DATA:
    1451         7283 :     case ST_OMP_TARGET_ENTER_DATA:
    1452         7283 :     case ST_OMP_TARGET_EXIT_DATA:
    1453         7283 :     case ST_OMP_TARGET_TEAMS:
    1454         7283 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
    1455         7283 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    1456         7283 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    1457         7283 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    1458         7283 :     case ST_OMP_TARGET_TEAMS_LOOP:
    1459         7283 :     case ST_OMP_TARGET_PARALLEL:
    1460         7283 :     case ST_OMP_TARGET_PARALLEL_DO:
    1461         7283 :     case ST_OMP_TARGET_PARALLEL_DO_SIMD:
    1462         7283 :     case ST_OMP_TARGET_PARALLEL_LOOP:
    1463         7283 :     case ST_OMP_TARGET_SIMD:
    1464         7283 :     case ST_OMP_TARGET_UPDATE:
    1465         7283 :       {
    1466         7283 :         gfc_namespace *prog_unit = gfc_current_ns;
    1467        11707 :         while (prog_unit->parent)
    1468              :           {
    1469         4432 :             if (gfc_state_stack->previous
    1470         4432 :                 && gfc_state_stack->previous->state == COMP_INTERFACE)
    1471              :               break;
    1472         4424 :             prog_unit = prog_unit->parent;
    1473              :           }
    1474         7283 :           prog_unit->omp_target_seen = true;
    1475         7283 :         break;
    1476              :       }
    1477          489 :     case ST_OMP_ALLOCATE_EXEC:
    1478          489 :     case ST_OMP_ALLOCATORS:
    1479          489 :     case ST_OMP_TEAMS:
    1480          489 :     case ST_OMP_TEAMS_DISTRIBUTE:
    1481          489 :     case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
    1482          489 :     case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    1483          489 :     case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    1484          489 :     case ST_OMP_TEAMS_LOOP:
    1485         1796 :       for (gfc_state_data *stk = gfc_state_stack->previous; stk;
    1486         1307 :            stk = stk->previous)
    1487         1307 :         if (stk && stk->tail)
    1488          422 :           switch (stk->tail->op)
    1489              :             {
    1490          229 :             case EXEC_OMP_TARGET:
    1491          229 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
    1492          229 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    1493          229 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    1494          229 :             case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    1495          229 :             case EXEC_OMP_TARGET_TEAMS_LOOP:
    1496          229 :             case EXEC_OMP_TARGET_PARALLEL:
    1497          229 :             case EXEC_OMP_TARGET_PARALLEL_DO:
    1498          229 :             case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
    1499          229 :             case EXEC_OMP_TARGET_PARALLEL_LOOP:
    1500          229 :             case EXEC_OMP_TARGET_SIMD:
    1501          229 :               if (ret == ST_OMP_ALLOCATE_EXEC || ret == ST_OMP_ALLOCATORS)
    1502            4 :                 new_st.ext.omp_clauses->contained_in_target_construct = 1;
    1503              :               else
    1504          225 :                 stk->tail->ext.omp_clauses->contains_teams_construct = 1;
    1505              :               break;
    1506              :             default:
    1507              :               break;
    1508              :             }
    1509              :       break;
    1510           78 :     case ST_OMP_ERROR:
    1511           78 :       if (new_st.ext.omp_clauses->at != OMP_AT_EXECUTION)
    1512           31 :         return ST_NONE;
    1513              :     default:
    1514              :       break;
    1515              :     }
    1516              :   return ret;
    1517              : 
    1518           23 :  do_spec_only:
    1519           23 :   reject_statement ();
    1520           23 :   gfc_clear_error ();
    1521           23 :   gfc_buffer_error (false);
    1522           23 :   gfc_current_locus = old_locus;
    1523           23 :   return ST_GET_FCN_CHARACTERISTICS;
    1524              : }
    1525              : 
    1526              : #undef matchs
    1527              : #undef matcho
    1528              : #undef matchds
    1529              : #undef matchdo
    1530              : 
    1531              : gfc_statement
    1532          262 : match_omp_directive (void)
    1533              : {
    1534          262 :   return decode_omp_directive ();
    1535              : }
    1536              : 
    1537              : static gfc_statement
    1538      3557758 : decode_gcc_attribute (void)
    1539              : {
    1540      3557758 :   locus old_locus;
    1541              : 
    1542      3557758 :   gfc_enforce_clean_symbol_state ();
    1543              : 
    1544      3557758 :   gfc_clear_error ();   /* Clear any pending errors.  */
    1545      3557758 :   gfc_clear_warning (); /* Clear any pending warnings.  */
    1546      3557758 :   old_locus = gfc_current_locus;
    1547              : 
    1548      3557758 :   match ("attributes", gfc_match_gcc_attributes, ST_ATTR_DECL);
    1549      3554774 :   match ("unroll", gfc_match_gcc_unroll, ST_NONE);
    1550      3554757 :   match ("builtin", gfc_match_gcc_builtin, ST_NONE);
    1551           12 :   match ("ivdep", gfc_match_gcc_ivdep, ST_NONE);
    1552            9 :   match ("vector", gfc_match_gcc_vector, ST_NONE);
    1553            6 :   match ("novector", gfc_match_gcc_novector, ST_NONE);
    1554              : 
    1555              :   /* All else has failed, so give up.  See if any of the matchers has
    1556              :      stored an error message of some sort.  */
    1557              : 
    1558            3 :   if (!gfc_error_check ())
    1559              :     {
    1560            1 :       if (pedantic)
    1561            0 :         gfc_error_now ("Unclassifiable GCC directive at %C");
    1562              :       else
    1563            1 :         gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
    1564              :     }
    1565              : 
    1566            3 :   reject_statement ();
    1567              : 
    1568            3 :   gfc_error_recovery ();
    1569              : 
    1570            3 :   return ST_NONE;
    1571              : }
    1572              : 
    1573              : #undef match
    1574              : 
    1575              : /* Assert next length characters to be equal to token in free form.  */
    1576              : 
    1577              : static void
    1578        54546 : verify_token_free (const char* token, int length, bool last_was_use_stmt)
    1579              : {
    1580        54546 :   int i;
    1581        54546 :   char c;
    1582              : 
    1583        54546 :   c = gfc_next_ascii_char ();
    1584       327045 :   for (i = 0; i < length; i++, c = gfc_next_ascii_char ())
    1585       217953 :     gcc_assert (c == token[i]);
    1586              : 
    1587        54546 :   gcc_assert (gfc_is_whitespace(c));
    1588        54546 :   gfc_gobble_whitespace ();
    1589        54546 :   if (last_was_use_stmt)
    1590           95 :     use_modules ();
    1591        54546 : }
    1592              : 
    1593              : /* Get the next statement in free form source.  */
    1594              : 
    1595              : static gfc_statement
    1596      4753790 : next_free (void)
    1597              : {
    1598      4753790 :   match m;
    1599      4753790 :   int i, cnt, at_bol;
    1600      4753790 :   char c;
    1601              : 
    1602      4753790 :   at_bol = gfc_at_bol ();
    1603      4753790 :   gfc_gobble_whitespace ();
    1604              : 
    1605      4753790 :   c = gfc_peek_ascii_char ();
    1606              : 
    1607      4753790 :   if (ISDIGIT (c))
    1608              :     {
    1609         2341 :       char d;
    1610              : 
    1611              :       /* Found a statement label?  */
    1612         2341 :       m = gfc_match_st_label (&gfc_statement_label);
    1613              : 
    1614         2341 :       d = gfc_peek_ascii_char ();
    1615         2341 :       if (m != MATCH_YES || !gfc_is_whitespace (d))
    1616              :         {
    1617            4 :           gfc_match_small_literal_int (&i, &cnt);
    1618              : 
    1619            4 :           if (cnt > 5)
    1620            1 :             gfc_error_now ("Too many digits in statement label at %C");
    1621              : 
    1622            4 :           if (i == 0)
    1623            1 :             gfc_error_now ("Zero is not a valid statement label at %C");
    1624              : 
    1625            4 :           do
    1626            4 :             c = gfc_next_ascii_char ();
    1627            4 :           while (ISDIGIT(c));
    1628              : 
    1629            4 :           if (!gfc_is_whitespace (c))
    1630            2 :             gfc_error_now ("Non-numeric character in statement label at %C");
    1631              : 
    1632              :           return ST_NONE;
    1633              :         }
    1634              :       else
    1635              :         {
    1636         2337 :           label_locus = gfc_current_locus;
    1637              : 
    1638         2337 :           gfc_gobble_whitespace ();
    1639              : 
    1640         2337 :           if (at_bol && gfc_peek_ascii_char () == ';')
    1641              :             {
    1642            2 :               gfc_error_now ("Semicolon at %C needs to be preceded by "
    1643              :                              "statement");
    1644            2 :               gfc_next_ascii_char (); /* Eat up the semicolon.  */
    1645            2 :               return ST_NONE;
    1646              :             }
    1647              : 
    1648         2335 :           if (gfc_match_eos () == MATCH_YES)
    1649            2 :             gfc_error_now ("Statement label without statement at %L",
    1650              :                            &label_locus);
    1651              :         }
    1652              :     }
    1653      4751449 :   else if (c == '!')
    1654              :     {
    1655              :       /* Comments have already been skipped by the time we get here,
    1656              :          except for GCC attributes and OpenMP/OpenACC directives.  */
    1657              : 
    1658      3419332 :       gfc_next_ascii_char (); /* Eat up the exclamation sign.  */
    1659      3419332 :       c = gfc_peek_ascii_char ();
    1660              : 
    1661      3419332 :       if (c == 'g')
    1662              :         {
    1663      3364786 :           int i;
    1664              : 
    1665      3364786 :           c = gfc_next_ascii_char ();
    1666     20188716 :           for (i = 0; i < 4; i++, c = gfc_next_ascii_char ())
    1667     13459144 :             gcc_assert (c == "gcc$"[i]);
    1668              : 
    1669      3364786 :           gfc_gobble_whitespace ();
    1670      3364786 :           return decode_gcc_attribute ();
    1671              : 
    1672              :         }
    1673        54546 :       else if (c == '$')
    1674              :         {
    1675              :           /* Since both OpenMP and OpenACC directives starts with
    1676              :              !$ character sequence, we must check all flags combinations */
    1677        54546 :           if ((flag_openmp || flag_openmp_simd)
    1678        34447 :               && !flag_openacc)
    1679              :             {
    1680        34216 :               verify_token_free ("$omp", 4, last_was_use_stmt);
    1681        34216 :               return decode_omp_directive ();
    1682              :             }
    1683        20330 :           else if ((flag_openmp || flag_openmp_simd)
    1684          231 :                    && flag_openacc)
    1685              :             {
    1686          231 :               gfc_next_ascii_char (); /* Eat up dollar character */
    1687          231 :               c = gfc_peek_ascii_char ();
    1688              : 
    1689          231 :               if (c == 'o')
    1690              :                 {
    1691           99 :                   verify_token_free ("omp", 3, last_was_use_stmt);
    1692           99 :                   return decode_omp_directive ();
    1693              :                 }
    1694          132 :               else if (c == 'a')
    1695              :                 {
    1696          132 :                   verify_token_free ("acc", 3, last_was_use_stmt);
    1697          132 :                   return decode_oacc_directive ();
    1698              :                 }
    1699              :             }
    1700        20099 :           else if (flag_openacc)
    1701              :             {
    1702        20099 :               verify_token_free ("$acc", 4, last_was_use_stmt);
    1703        20099 :               return decode_oacc_directive ();
    1704              :             }
    1705              :         }
    1706            0 :       gcc_unreachable ();
    1707              :     }
    1708              : 
    1709      1334452 :   if (at_bol && c == ';')
    1710              :     {
    1711            7 :       if (!(gfc_option.allow_std & GFC_STD_F2008))
    1712            2 :         gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
    1713              :                        "statement");
    1714            7 :       gfc_next_ascii_char (); /* Eat up the semicolon.  */
    1715            7 :       return ST_NONE;
    1716              :     }
    1717              : 
    1718      1334445 :   return decode_statement ();
    1719              : }
    1720              : 
    1721              : /* Assert next length characters to be equal to token in fixed form.  */
    1722              : 
    1723              : static bool
    1724         1325 : verify_token_fixed (const char *token, int length, bool last_was_use_stmt)
    1725              : {
    1726         1325 :   int i;
    1727         1325 :   char c = gfc_next_char_literal (NONSTRING);
    1728              : 
    1729         5285 :   for (i = 0; i < length; i++, c = gfc_next_char_literal (NONSTRING))
    1730         3960 :     gcc_assert ((char) gfc_wide_tolower (c) == token[i]);
    1731              : 
    1732         1325 :   if (c != ' ' && c != '0')
    1733              :     {
    1734            0 :       gfc_buffer_error (false);
    1735            0 :       gfc_error ("Bad continuation line at %C");
    1736            0 :       return false;
    1737              :     }
    1738         1325 :   if (last_was_use_stmt)
    1739            0 :     use_modules ();
    1740              : 
    1741              :   return true;
    1742              : }
    1743              : 
    1744              : /* Get the next statement in fixed-form source.  */
    1745              : 
    1746              : static gfc_statement
    1747       281601 : next_fixed (void)
    1748              : {
    1749       281601 :   int label, digit_flag, i;
    1750       281601 :   locus loc;
    1751       281601 :   gfc_char_t c;
    1752              : 
    1753       281601 :   if (!gfc_at_bol ())
    1754           46 :     return decode_statement ();
    1755              : 
    1756              :   /* Skip past the current label field, parsing a statement label if
    1757              :      one is there.  This is a weird number parser, since the number is
    1758              :      contained within five columns and can have any kind of embedded
    1759              :      spaces.  We also check for characters that make the rest of the
    1760              :      line a comment.  */
    1761              : 
    1762              :   label = 0;
    1763              :   digit_flag = 0;
    1764              : 
    1765       717825 :   for (i = 0; i < 5; i++)
    1766              :     {
    1767       630571 :       c = gfc_next_char_literal (NONSTRING);
    1768              : 
    1769       630571 :       switch (c)
    1770              :         {
    1771              :         case ' ':
    1772              :           break;
    1773              : 
    1774         6624 :         case '0':
    1775         6624 :         case '1':
    1776         6624 :         case '2':
    1777         6624 :         case '3':
    1778         6624 :         case '4':
    1779         6624 :         case '5':
    1780         6624 :         case '6':
    1781         6624 :         case '7':
    1782         6624 :         case '8':
    1783         6624 :         case '9':
    1784         6624 :           label = label * 10 + ((unsigned char) c - '0');
    1785         6624 :           label_locus = gfc_current_locus;
    1786         6624 :           digit_flag = 1;
    1787         6624 :           break;
    1788              : 
    1789              :           /* Comments have already been skipped by the time we get
    1790              :              here, except for GCC attributes and OpenMP directives.  */
    1791              : 
    1792       194297 :         case '*':
    1793       194297 :           c = gfc_next_char_literal (NONSTRING);
    1794              : 
    1795       194297 :           if (TOLOWER (c) == 'g')
    1796              :             {
    1797       964860 :               for (i = 0; i < 4; i++, c = gfc_next_char_literal (NONSTRING))
    1798       771888 :                 gcc_assert (TOLOWER (c) == "gcc$"[i]);
    1799              : 
    1800       192972 :               return decode_gcc_attribute ();
    1801              :             }
    1802         1325 :           else if (c == '$')
    1803              :             {
    1804         1325 :               if ((flag_openmp || flag_openmp_simd)
    1805          281 :                   && !flag_openacc)
    1806              :                 {
    1807          266 :                   if (!verify_token_fixed ("omp", 3, last_was_use_stmt))
    1808              :                     return ST_NONE;
    1809          266 :                   return decode_omp_directive ();
    1810              :                 }
    1811         1059 :               else if ((flag_openmp || flag_openmp_simd)
    1812           15 :                        && flag_openacc)
    1813              :                 {
    1814           15 :                   c = gfc_next_char_literal(NONSTRING);
    1815           15 :                   if (c == 'o' || c == 'O')
    1816              :                     {
    1817           10 :                       if (!verify_token_fixed ("mp", 2, last_was_use_stmt))
    1818              :                         return ST_NONE;
    1819           10 :                       return decode_omp_directive ();
    1820              :                     }
    1821            5 :                   else if (c == 'a' || c == 'A')
    1822              :                     {
    1823            5 :                       if (!verify_token_fixed ("cc", 2, last_was_use_stmt))
    1824              :                         return ST_NONE;
    1825            5 :                       return decode_oacc_directive ();
    1826              :                     }
    1827              :                 }
    1828         1044 :               else if (flag_openacc)
    1829              :                 {
    1830         1044 :                   if (!verify_token_fixed ("acc", 3, last_was_use_stmt))
    1831              :                     return ST_NONE;
    1832         1044 :                   return decode_oacc_directive ();
    1833              :                 }
    1834              :             }
    1835            4 :           gcc_fallthrough ();
    1836              : 
    1837              :           /* Comments have already been skipped by the time we get
    1838              :              here so don't bother checking for them.  */
    1839              : 
    1840            4 :         default:
    1841            4 :           gfc_buffer_error (false);
    1842            4 :           gfc_error ("Non-numeric character in statement label at %C");
    1843            4 :           return ST_NONE;
    1844              :         }
    1845              :     }
    1846              : 
    1847        87254 :   if (digit_flag)
    1848              :     {
    1849         2450 :       if (label == 0)
    1850            1 :         gfc_warning_now (0, "Zero is not a valid statement label at %C");
    1851              :       else
    1852              :         {
    1853              :           /* We've found a valid statement label.  */
    1854         2449 :           gfc_statement_label = gfc_get_st_label (label);
    1855              :         }
    1856              :     }
    1857              : 
    1858              :   /* Since this line starts a statement, it cannot be a continuation
    1859              :      of a previous statement.  If we see something here besides a
    1860              :      space or zero, it must be a bad continuation line.  */
    1861              : 
    1862        87254 :   c = gfc_next_char_literal (NONSTRING);
    1863        87254 :   if (c == '\n')
    1864            0 :     goto blank_line;
    1865              : 
    1866        87254 :   if (c != ' ' && c != '0')
    1867              :     {
    1868            0 :       gfc_buffer_error (false);
    1869            0 :       gfc_error ("Bad continuation line at %C");
    1870            0 :       return ST_NONE;
    1871              :     }
    1872              : 
    1873              :   /* Now that we've taken care of the statement label columns, we have
    1874              :      to make sure that the first nonblank character is not a '!'.  If
    1875              :      it is, the rest of the line is a comment.  */
    1876              : 
    1877       241841 :   do
    1878              :     {
    1879       241841 :       loc = gfc_current_locus;
    1880       241841 :       c = gfc_next_char_literal (NONSTRING);
    1881              :     }
    1882       241841 :   while (gfc_is_whitespace (c));
    1883              : 
    1884        87254 :   if (c == '!')
    1885            0 :     goto blank_line;
    1886        87254 :   gfc_current_locus = loc;
    1887              : 
    1888        87254 :   if (c == ';')
    1889              :     {
    1890            6 :       if (digit_flag)
    1891            2 :         gfc_error_now ("Semicolon at %C needs to be preceded by statement");
    1892            4 :       else if (!(gfc_option.allow_std & GFC_STD_F2008))
    1893            2 :         gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
    1894              :                        "statement");
    1895              :       return ST_NONE;
    1896              :     }
    1897              : 
    1898        87248 :   if (gfc_match_eos () == MATCH_YES)
    1899            1 :     goto blank_line;
    1900              : 
    1901              :   /* At this point, we've got a nonblank statement to parse.  */
    1902        87247 :   return decode_statement ();
    1903              : 
    1904            1 : blank_line:
    1905            1 :   if (digit_flag)
    1906            1 :     gfc_error_now ("Statement label without statement at %L", &label_locus);
    1907              : 
    1908            1 :   gfc_current_locus.u.lb->truncated = 0;
    1909            1 :   gfc_advance_line ();
    1910            1 :   return ST_NONE;
    1911              : }
    1912              : 
    1913              : 
    1914              : /* Return the next non-ST_NONE statement to the caller.  We also worry
    1915              :    about including files and the ends of include files at this stage.  */
    1916              : 
    1917              : static gfc_statement
    1918      1509821 : next_statement (void)
    1919              : {
    1920      1509821 :   gfc_statement st;
    1921      1509821 :   locus old_locus;
    1922              : 
    1923      1509821 :   gfc_enforce_clean_symbol_state ();
    1924      1509821 :   gfc_save_module_list ();
    1925              : 
    1926      1509821 :   gfc_new_block = NULL;
    1927              : 
    1928      1509821 :   gfc_current_ns->old_equiv = gfc_current_ns->equiv;
    1929      1509821 :   gfc_current_ns->old_data = gfc_current_ns->data;
    1930      5068311 :   for (;;)
    1931              :     {
    1932      5068311 :       gfc_statement_label = NULL;
    1933      5068311 :       gfc_buffer_error (true);
    1934              : 
    1935      5068311 :       if (gfc_at_eol ())
    1936      4996092 :         gfc_advance_line ();
    1937              : 
    1938      5068311 :       gfc_skip_comments ();
    1939              : 
    1940      5068311 :       if (gfc_at_end ())
    1941              :         {
    1942              :           st = ST_NONE;
    1943              :           break;
    1944              :         }
    1945              : 
    1946      5035399 :       if (gfc_define_undef_line ())
    1947            8 :         continue;
    1948              : 
    1949      5035391 :       old_locus = gfc_current_locus;
    1950              : 
    1951      5035391 :       st = (gfc_current_form == FORM_FIXED) ? next_fixed () : next_free ();
    1952              : 
    1953      5035382 :       if (st != ST_NONE)
    1954              :         break;
    1955              :     }
    1956              : 
    1957      1509812 :   gfc_buffer_error (false);
    1958              : 
    1959      1509812 :   if (st == ST_GET_FCN_CHARACTERISTICS)
    1960              :     {
    1961         7219 :       if (gfc_statement_label != NULL)
    1962              :         {
    1963            3 :           gfc_free_st_label (gfc_statement_label);
    1964            3 :           gfc_statement_label = NULL;
    1965              :         }
    1966         7219 :       gfc_current_locus = old_locus;
    1967              :     }
    1968              : 
    1969      1509812 :   if (st != ST_NONE)
    1970      1476900 :     check_statement_label (st);
    1971              : 
    1972      1509812 :   return st;
    1973              : }
    1974              : 
    1975              : 
    1976              : /****************************** Parser ***********************************/
    1977              : 
    1978              : /* The parser subroutines are of type 'try' that fail if the file ends
    1979              :    unexpectedly.  */
    1980              : 
    1981              : /* Macros that expand to case-labels for various classes of
    1982              :    statements.  Start with executable statements that directly do
    1983              :    things.  */
    1984              : 
    1985              : #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
    1986              :   case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
    1987              :   case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
    1988              :   case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
    1989              :   case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
    1990              :   case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
    1991              :   case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
    1992              :   case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
    1993              :   case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
    1994              :   case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
    1995              :   case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
    1996              :   case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
    1997              :   case ST_OMP_INTEROP: \
    1998              :   case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
    1999              :   case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
    2000              :   case ST_FORM_TEAM: case ST_SYNC_TEAM: \
    2001              :   case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
    2002              :   case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
    2003              :   case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA: \
    2004              :   case ST_OACC_INIT: case ST_OACC_SHUTDOWN: case ST_OACC_SET
    2005              : 
    2006              : /* Statements that mark other executable statements.  */
    2007              : 
    2008              : #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
    2009              :   case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
    2010              :   case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
    2011              :   case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
    2012              :   case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
    2013              :   case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
    2014              :   case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
    2015              :   case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
    2016              :   case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
    2017              :   case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
    2018              :   case ST_OMP_MASKED_TASKLOOP_SIMD: \
    2019              :   case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
    2020              :   case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
    2021              :   case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
    2022              :   case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
    2023              :   case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
    2024              :   case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
    2025              :   case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
    2026              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
    2027              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
    2028              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
    2029              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
    2030              :   case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
    2031              :   case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
    2032              :   case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
    2033              :   case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
    2034              :   case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
    2035              :   case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
    2036              :   case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
    2037              :   case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
    2038              :   case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
    2039              :   case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
    2040              :   case ST_OMP_ALLOCATE_EXEC: case ST_OMP_ALLOCATORS: case ST_OMP_ASSUME: \
    2041              :   case ST_OMP_TILE: case ST_OMP_UNROLL: case ST_OMP_DISPATCH: \
    2042              :   case ST_CRITICAL: \
    2043              :   case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
    2044              :   case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
    2045              :   case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
    2046              :   case ST_OACC_ATOMIC
    2047              : 
    2048              : /* Declaration statements */
    2049              : 
    2050              : #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
    2051              :   case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
    2052              :   case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
    2053              : 
    2054              : /* OpenMP and OpenACC declaration statements, which may appear anywhere in
    2055              :    the specification part.  */
    2056              : 
    2057              : #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
    2058              :   case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
    2059              :   case ST_OMP_DECLARE_VARIANT: case ST_OMP_ALLOCATE: case ST_OMP_ASSUMES: \
    2060              :   case ST_OMP_REQUIRES: case ST_OMP_GROUPPRIVATE: case ST_OMP_DECLARE_MAPPER: \
    2061              :   case ST_OACC_ROUTINE: case ST_OACC_DECLARE
    2062              : 
    2063              : /* OpenMP statements that are followed by a structured block.  */
    2064              : 
    2065              : #define case_omp_structured_block case ST_OMP_ASSUME: case ST_OMP_PARALLEL: \
    2066              :   case ST_OMP_PARALLEL_MASKED: case ST_OMP_PARALLEL_MASTER: \
    2067              :   case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_ORDERED: \
    2068              :   case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASTER: \
    2069              :   case ST_OMP_SCOPE: case ST_OMP_SECTIONS: case ST_OMP_SINGLE: \
    2070              :   case ST_OMP_TARGET: case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_PARALLEL: \
    2071              :   case ST_OMP_TARGET_TEAMS: case ST_OMP_TEAMS: case ST_OMP_TASK: \
    2072              :   case ST_OMP_TASKGROUP: \
    2073              :   case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE
    2074              : 
    2075              : /* OpenMP statements that are followed by a do loop.  */
    2076              : 
    2077              : #define case_omp_do case ST_OMP_DISTRIBUTE: \
    2078              :   case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
    2079              :   case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE_SIMD: \
    2080              :   case ST_OMP_DO: case ST_OMP_DO_SIMD: case ST_OMP_LOOP: \
    2081              :   case ST_OMP_PARALLEL_DO: case ST_OMP_PARALLEL_DO_SIMD: \
    2082              :   case ST_OMP_PARALLEL_LOOP: case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
    2083              :   case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: \
    2084              :   case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
    2085              :   case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
    2086              :   case ST_OMP_MASKED_TASKLOOP: case ST_OMP_MASKED_TASKLOOP_SIMD: \
    2087              :   case ST_OMP_MASTER_TASKLOOP: case ST_OMP_MASTER_TASKLOOP_SIMD: \
    2088              :   case ST_OMP_SIMD: \
    2089              :   case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
    2090              :   case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_SIMD: \
    2091              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
    2092              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
    2093              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
    2094              :   case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TARGET_TEAMS_LOOP: \
    2095              :   case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
    2096              :   case ST_OMP_TEAMS_DISTRIBUTE: case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
    2097              :   case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
    2098              :   case ST_OMP_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TEAMS_LOOP: \
    2099              :   case ST_OMP_TILE: case ST_OMP_UNROLL
    2100              : 
    2101              : /* Block end statements.  Errors associated with interchanging these
    2102              :    are detected in gfc_match_end().  */
    2103              : 
    2104              : #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
    2105              :                  case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
    2106              :                  case ST_END_BLOCK: case ST_END_ASSOCIATE: \
    2107              :                  case ST_END_TEAM
    2108              : 
    2109              : 
    2110              : /* Push a new state onto the stack.  */
    2111              : 
    2112              : static void
    2113       237555 : push_state (gfc_state_data *p, gfc_compile_state new_state, gfc_symbol *sym)
    2114              : {
    2115       237555 :   p->state = new_state;
    2116       237555 :   p->previous = gfc_state_stack;
    2117       237555 :   p->sym = sym;
    2118       237555 :   p->head = p->tail = NULL;
    2119       237555 :   p->do_variable = NULL;
    2120       237555 :   if (p->state != COMP_DO && p->state != COMP_DO_CONCURRENT)
    2121       203502 :     p->ext.oacc_declare_clauses = NULL;
    2122              : 
    2123              :   /* If this the state of a construct like BLOCK, DO or IF, the corresponding
    2124              :      construct statement was accepted right before pushing the state.  Thus,
    2125              :      the construct's gfc_code is available as tail of the parent state.  */
    2126       237555 :   gcc_assert (gfc_state_stack);
    2127       237555 :   p->construct = gfc_state_stack->tail;
    2128              : 
    2129       237555 :   gfc_state_stack = p;
    2130       237555 : }
    2131              : 
    2132              : 
    2133              : /* Pop the current state.  */
    2134              : static void
    2135       237056 : pop_state (void)
    2136              : {
    2137       237056 :   gfc_state_stack = gfc_state_stack->previous;
    2138            0 : }
    2139              : 
    2140              : 
    2141              : /* Try to find the given state in the state stack.  */
    2142              : 
    2143              : bool
    2144      4615347 : gfc_find_state (gfc_compile_state state)
    2145              : {
    2146      4615347 :   gfc_state_data *p;
    2147              : 
    2148     18550506 :   for (p = gfc_state_stack; p; p = p->previous)
    2149     14040208 :     if (p->state == state)
    2150              :       break;
    2151              : 
    2152      4615347 :   return p != NULL;
    2153              : }
    2154              : 
    2155              : 
    2156              : /* Starts a new level in the statement list.  */
    2157              : 
    2158              : static gfc_code *
    2159        78177 : new_level (gfc_code *q)
    2160              : {
    2161        78177 :   gfc_code *p;
    2162              : 
    2163        78177 :   p = q->block = gfc_get_code (EXEC_NOP);
    2164              : 
    2165        78177 :   gfc_state_stack->head = gfc_state_stack->tail = p;
    2166              : 
    2167        78177 :   return p;
    2168              : }
    2169              : 
    2170              : 
    2171              : /* Add the current new_st code structure and adds it to the current
    2172              :    program unit.  As a side-effect, it zeroes the new_st.  */
    2173              : 
    2174              : static gfc_code *
    2175       879159 : add_statement (void)
    2176              : {
    2177       879159 :   gfc_code *p;
    2178              : 
    2179       879159 :   p = XCNEW (gfc_code);
    2180       879159 :   *p = new_st;
    2181              : 
    2182       879159 :   p->loc = gfc_current_locus;
    2183              : 
    2184       879159 :   if (gfc_state_stack->head == NULL)
    2185       107289 :     gfc_state_stack->head = p;
    2186              :   else
    2187       771870 :     gfc_state_stack->tail->next = p;
    2188              : 
    2189       879712 :   while (p->next != NULL)
    2190              :     p = p->next;
    2191              : 
    2192       879159 :   gfc_state_stack->tail = p;
    2193              : 
    2194       879159 :   gfc_clear_new_st ();
    2195              : 
    2196       879159 :   return p;
    2197              : }
    2198              : 
    2199              : 
    2200              : /* Frees everything associated with the current statement.  */
    2201              : 
    2202              : static void
    2203     29599417 : undo_new_statement (void)
    2204              : {
    2205     29599417 :   gfc_free_statements (new_st.block);
    2206     29599417 :   gfc_free_statements (new_st.next);
    2207     29599417 :   gfc_free_statement (&new_st);
    2208     29599417 :   gfc_clear_new_st ();
    2209     29599417 : }
    2210              : 
    2211              : 
    2212              : /* If the current statement has a statement label, make sure that it
    2213              :    is allowed to, or should have one.  */
    2214              : 
    2215              : static void
    2216      1476900 : check_statement_label (gfc_statement st)
    2217              : {
    2218      1476900 :   gfc_sl_type type;
    2219              : 
    2220      1476900 :   if (gfc_statement_label == NULL)
    2221              :     {
    2222      1472133 :       if (st == ST_FORMAT)
    2223            0 :         gfc_error ("FORMAT statement at %L does not have a statement label",
    2224              :                    &new_st.loc);
    2225              :       return;
    2226              :     }
    2227              : 
    2228         4767 :   switch (st)
    2229              :     {
    2230         3721 :     case ST_END_PROGRAM:
    2231         3721 :     case ST_END_FUNCTION:
    2232         3721 :     case ST_END_SUBROUTINE:
    2233         3721 :     case ST_ENDDO:
    2234         3721 :     case ST_ENDIF:
    2235         3721 :     case ST_END_SELECT:
    2236         3721 :     case ST_END_CRITICAL:
    2237         3721 :     case ST_END_BLOCK:
    2238         3721 :     case ST_END_ASSOCIATE:
    2239         3721 :     case ST_END_TEAM:
    2240         3721 :     case_executable:
    2241         3721 :     case_exec_markers:
    2242         3721 :       if (st == ST_ENDDO || st == ST_CONTINUE)
    2243              :         type = ST_LABEL_DO_TARGET;
    2244              :       else
    2245         1027 :         type = ST_LABEL_TARGET;
    2246              :       break;
    2247              : 
    2248              :     case ST_FORMAT:
    2249              :       type = ST_LABEL_FORMAT;
    2250              :       break;
    2251              : 
    2252              :       /* Statement labels are not restricted from appearing on a
    2253              :          particular line.  However, there are plenty of situations
    2254              :          where the resulting label can't be referenced.  */
    2255              : 
    2256           12 :     default:
    2257           12 :       type = ST_LABEL_BAD_TARGET;
    2258           12 :       break;
    2259              :     }
    2260              : 
    2261         4767 :   gfc_define_st_label (gfc_statement_label, type, &label_locus);
    2262              : 
    2263         4767 :   new_st.here = gfc_statement_label;
    2264              : }
    2265              : 
    2266              : 
    2267              : /* Figures out what the enclosing program unit is.  This will be a
    2268              :    function, subroutine, program, block data or module.  */
    2269              : 
    2270              : gfc_state_data *
    2271      1063680 : gfc_enclosing_unit (gfc_compile_state * result)
    2272              : {
    2273      1063680 :   gfc_state_data *p;
    2274              : 
    2275      1542572 :   for (p = gfc_state_stack; p; p = p->previous)
    2276      1496267 :     if (p->state == COMP_FUNCTION || p->state == COMP_SUBROUTINE
    2277              :         || p->state == COMP_MODULE || p->state == COMP_SUBMODULE
    2278              :         || p->state == COMP_BLOCK_DATA || p->state == COMP_PROGRAM)
    2279              :       {
    2280              : 
    2281      1017375 :         if (result != NULL)
    2282         3226 :           *result = p->state;
    2283              :         return p;
    2284              :       }
    2285              : 
    2286        46305 :   if (result != NULL)
    2287            0 :     *result = COMP_PROGRAM;
    2288              :   return NULL;
    2289              : }
    2290              : 
    2291              : 
    2292              : /* Translate a statement enum to a string.  If strip_sentinel is true,
    2293              :    the !$OMP/!$ACC sentinel is excluded.  */
    2294              : 
    2295              : const char *
    2296        30677 : gfc_ascii_statement (gfc_statement st, bool strip_sentinel)
    2297              : {
    2298        30677 :   const char *p;
    2299              : 
    2300        30677 :   switch (st)
    2301              :     {
    2302            0 :     case ST_ARITHMETIC_IF:
    2303            0 :       p = _("arithmetic IF");
    2304            0 :       break;
    2305              :     case ST_ALLOCATE:
    2306              :       p = "ALLOCATE";
    2307              :       break;
    2308            0 :     case ST_ASSOCIATE:
    2309            0 :       p = "ASSOCIATE";
    2310            0 :       break;
    2311            1 :     case ST_ATTR_DECL:
    2312            1 :       p = _("attribute declaration");
    2313            1 :       break;
    2314            2 :     case ST_BACKSPACE:
    2315            2 :       p = "BACKSPACE";
    2316            2 :       break;
    2317            1 :     case ST_BLOCK:
    2318            1 :       p = "BLOCK";
    2319            1 :       break;
    2320            1 :     case ST_BLOCK_DATA:
    2321            1 :       p = "BLOCK DATA";
    2322            1 :       break;
    2323            5 :     case ST_CALL:
    2324            5 :       p = "CALL";
    2325            5 :       break;
    2326            0 :     case ST_CASE:
    2327            0 :       p = "CASE";
    2328            0 :       break;
    2329            0 :     case ST_CLOSE:
    2330            0 :       p = "CLOSE";
    2331            0 :       break;
    2332           18 :     case ST_COMMON:
    2333           18 :       p = "COMMON";
    2334           18 :       break;
    2335           10 :     case ST_CONTINUE:
    2336           10 :       p = "CONTINUE";
    2337           10 :       break;
    2338            2 :     case ST_CONTAINS:
    2339            2 :       p = "CONTAINS";
    2340            2 :       break;
    2341            1 :     case ST_CRITICAL:
    2342            1 :       p = "CRITICAL";
    2343            1 :       break;
    2344            4 :     case ST_CYCLE:
    2345            4 :       p = "CYCLE";
    2346            4 :       break;
    2347           22 :     case ST_DATA_DECL:
    2348           22 :       p = _("data declaration");
    2349           22 :       break;
    2350            8 :     case ST_DATA:
    2351            8 :       p = "DATA";
    2352            8 :       break;
    2353            1 :     case ST_DEALLOCATE:
    2354            1 :       p = "DEALLOCATE";
    2355            1 :       break;
    2356            1 :     case ST_MAP:
    2357            1 :       p = "MAP";
    2358            1 :       break;
    2359            0 :     case ST_UNION:
    2360            0 :       p = "UNION";
    2361            0 :       break;
    2362            1 :     case ST_STRUCTURE_DECL:
    2363            1 :       p = "STRUCTURE";
    2364            1 :       break;
    2365            1 :     case ST_DERIVED_DECL:
    2366            1 :       p = _("derived type declaration");
    2367            1 :       break;
    2368            7 :     case ST_DO:
    2369            7 :       p = "DO";
    2370            7 :       break;
    2371            2 :     case ST_ELSE:
    2372            2 :       p = "ELSE";
    2373            2 :       break;
    2374            0 :     case ST_ELSEIF:
    2375            0 :       p = "ELSE IF";
    2376            0 :       break;
    2377            0 :     case ST_ELSEWHERE:
    2378            0 :       p = "ELSEWHERE";
    2379            0 :       break;
    2380            1 :     case ST_EVENT_POST:
    2381            1 :       p = "EVENT POST";
    2382            1 :       break;
    2383            0 :     case ST_EVENT_WAIT:
    2384            0 :       p = "EVENT WAIT";
    2385            0 :       break;
    2386            3 :     case ST_FAIL_IMAGE:
    2387            3 :       p = "FAIL IMAGE";
    2388            3 :       break;
    2389            1 :     case ST_CHANGE_TEAM:
    2390            1 :       p = "CHANGE TEAM";
    2391            1 :       break;
    2392            1 :     case ST_END_TEAM:
    2393            1 :       p = "END TEAM";
    2394            1 :       break;
    2395            3 :     case ST_FORM_TEAM:
    2396            3 :       p = "FORM TEAM";
    2397            3 :       break;
    2398            2 :     case ST_SYNC_TEAM:
    2399            2 :       p = "SYNC TEAM";
    2400            2 :       break;
    2401            4 :     case ST_END_ASSOCIATE:
    2402            4 :       p = "END ASSOCIATE";
    2403            4 :       break;
    2404           43 :     case ST_END_BLOCK:
    2405           43 :       p = "END BLOCK";
    2406           43 :       break;
    2407            1 :     case ST_END_BLOCK_DATA:
    2408            1 :       p = "END BLOCK DATA";
    2409            1 :       break;
    2410            0 :     case ST_END_CRITICAL:
    2411            0 :       p = "END CRITICAL";
    2412            0 :       break;
    2413           14 :     case ST_ENDDO:
    2414           14 :       p = "END DO";
    2415           14 :       break;
    2416            2 :     case ST_END_FILE:
    2417            2 :       p = "END FILE";
    2418            2 :       break;
    2419            2 :     case ST_END_FORALL:
    2420            2 :       p = "END FORALL";
    2421            2 :       break;
    2422         1256 :     case ST_END_FUNCTION:
    2423         1256 :       p = "END FUNCTION";
    2424         1256 :       break;
    2425            4 :     case ST_ENDIF:
    2426            4 :       p = "END IF";
    2427            4 :       break;
    2428           12 :     case ST_END_INTERFACE:
    2429           12 :       p = "END INTERFACE";
    2430           12 :       break;
    2431           25 :     case ST_END_MODULE:
    2432           25 :       p = "END MODULE";
    2433           25 :       break;
    2434            4 :     case ST_END_SUBMODULE:
    2435            4 :       p = "END SUBMODULE";
    2436            4 :       break;
    2437           94 :     case ST_END_PROGRAM:
    2438           94 :       p = "END PROGRAM";
    2439           94 :       break;
    2440            4 :     case ST_END_SELECT:
    2441            4 :       p = "END SELECT";
    2442            4 :       break;
    2443         2977 :     case ST_END_SUBROUTINE:
    2444         2977 :       p = "END SUBROUTINE";
    2445         2977 :       break;
    2446            2 :     case ST_END_WHERE:
    2447            2 :       p = "END WHERE";
    2448            2 :       break;
    2449            0 :     case ST_END_STRUCTURE:
    2450            0 :       p = "END STRUCTURE";
    2451            0 :       break;
    2452            0 :     case ST_END_UNION:
    2453            0 :       p = "END UNION";
    2454            0 :       break;
    2455            0 :     case ST_END_MAP:
    2456            0 :       p = "END MAP";
    2457            0 :       break;
    2458            0 :     case ST_END_TYPE:
    2459            0 :       p = "END TYPE";
    2460            0 :       break;
    2461            0 :     case ST_ENTRY:
    2462            0 :       p = "ENTRY";
    2463            0 :       break;
    2464            2 :     case ST_EQUIVALENCE:
    2465            2 :       p = "EQUIVALENCE";
    2466            2 :       break;
    2467          274 :     case ST_ERROR_STOP:
    2468          274 :       p = "ERROR STOP";
    2469          274 :       break;
    2470           12 :     case ST_EXIT:
    2471           12 :       p = "EXIT";
    2472           12 :       break;
    2473            2 :     case ST_FLUSH:
    2474            2 :       p = "FLUSH";
    2475            2 :       break;
    2476            0 :     case ST_FORALL_BLOCK:       /* Fall through */
    2477            0 :     case ST_FORALL:
    2478            0 :       p = "FORALL";
    2479            0 :       break;
    2480            1 :     case ST_FORMAT:
    2481            1 :       p = "FORMAT";
    2482            1 :       break;
    2483            0 :     case ST_FUNCTION:
    2484            0 :       p = "FUNCTION";
    2485            0 :       break;
    2486            1 :     case ST_GENERIC:
    2487            1 :       p = "GENERIC";
    2488            1 :       break;
    2489            0 :     case ST_GOTO:
    2490            0 :       p = "GOTO";
    2491            0 :       break;
    2492            0 :     case ST_IF_BLOCK:
    2493            0 :       p = _("block IF");
    2494            0 :       break;
    2495        25190 :     case ST_IMPLICIT:
    2496        25190 :       p = "IMPLICIT";
    2497        25190 :       break;
    2498            3 :     case ST_IMPLICIT_NONE:
    2499            3 :       p = "IMPLICIT NONE";
    2500            3 :       break;
    2501            0 :     case ST_IMPLIED_ENDDO:
    2502            0 :       p = _("implied END DO");
    2503            0 :       break;
    2504            3 :     case ST_IMPORT:
    2505            3 :       p = "IMPORT";
    2506            3 :       break;
    2507            0 :     case ST_INQUIRE:
    2508            0 :       p = "INQUIRE";
    2509            0 :       break;
    2510            2 :     case ST_INTERFACE:
    2511            2 :       p = "INTERFACE";
    2512            2 :       break;
    2513            1 :     case ST_LOCK:
    2514            1 :       p = "LOCK";
    2515            1 :       break;
    2516            0 :     case ST_PARAMETER:
    2517            0 :       p = "PARAMETER";
    2518            0 :       break;
    2519            0 :     case ST_PRIVATE:
    2520            0 :       p = "PRIVATE";
    2521            0 :       break;
    2522            0 :     case ST_PUBLIC:
    2523            0 :       p = "PUBLIC";
    2524            0 :       break;
    2525            1 :     case ST_MODULE:
    2526            1 :       p = "MODULE";
    2527            1 :       break;
    2528            0 :     case ST_SUBMODULE:
    2529            0 :       p = "SUBMODULE";
    2530            0 :       break;
    2531            0 :     case ST_PAUSE:
    2532            0 :       p = "PAUSE";
    2533            0 :       break;
    2534            4 :     case ST_MODULE_PROC:
    2535            4 :       p = "MODULE PROCEDURE";
    2536            4 :       break;
    2537            3 :     case ST_NAMELIST:
    2538            3 :       p = "NAMELIST";
    2539            3 :       break;
    2540            0 :     case ST_NULLIFY:
    2541            0 :       p = "NULLIFY";
    2542            0 :       break;
    2543            0 :     case ST_OPEN:
    2544            0 :       p = "OPEN";
    2545            0 :       break;
    2546            1 :     case ST_PROGRAM:
    2547            1 :       p = "PROGRAM";
    2548            1 :       break;
    2549            0 :     case ST_PROCEDURE:
    2550            0 :       p = "PROCEDURE";
    2551            0 :       break;
    2552            0 :     case ST_READ:
    2553            0 :       p = "READ";
    2554            0 :       break;
    2555            0 :     case ST_RETURN:
    2556            0 :       p = "RETURN";
    2557            0 :       break;
    2558            2 :     case ST_REWIND:
    2559            2 :       p = "REWIND";
    2560            2 :       break;
    2561           36 :     case ST_STOP:
    2562           36 :       p = "STOP";
    2563           36 :       break;
    2564            0 :     case ST_SYNC_ALL:
    2565            0 :       p = "SYNC ALL";
    2566            0 :       break;
    2567            0 :     case ST_SYNC_IMAGES:
    2568            0 :       p = "SYNC IMAGES";
    2569            0 :       break;
    2570            0 :     case ST_SYNC_MEMORY:
    2571            0 :       p = "SYNC MEMORY";
    2572            0 :       break;
    2573            1 :     case ST_SUBROUTINE:
    2574            1 :       p = "SUBROUTINE";
    2575            1 :       break;
    2576            0 :     case ST_TYPE:
    2577            0 :       p = "TYPE";
    2578            0 :       break;
    2579            0 :     case ST_UNLOCK:
    2580            0 :       p = "UNLOCK";
    2581            0 :       break;
    2582           10 :     case ST_USE:
    2583           10 :       p = "USE";
    2584           10 :       break;
    2585            0 :     case ST_WHERE_BLOCK:        /* Fall through */
    2586            0 :     case ST_WHERE:
    2587            0 :       p = "WHERE";
    2588            0 :       break;
    2589            0 :     case ST_WAIT:
    2590            0 :       p = "WAIT";
    2591            0 :       break;
    2592            3 :     case ST_WRITE:
    2593            3 :       p = "WRITE";
    2594            3 :       break;
    2595           30 :     case ST_ASSIGNMENT:
    2596           30 :       p = _("assignment");
    2597           30 :       break;
    2598            0 :     case ST_POINTER_ASSIGNMENT:
    2599            0 :       p = _("pointer assignment");
    2600            0 :       break;
    2601            0 :     case ST_SELECT_CASE:
    2602            0 :       p = "SELECT CASE";
    2603            0 :       break;
    2604            0 :     case ST_SELECT_TYPE:
    2605            0 :       p = "SELECT TYPE";
    2606            0 :       break;
    2607            0 :     case ST_SELECT_RANK:
    2608            0 :       p = "SELECT RANK";
    2609            0 :       break;
    2610            0 :     case ST_TYPE_IS:
    2611            0 :       p = "TYPE IS";
    2612            0 :       break;
    2613            0 :     case ST_CLASS_IS:
    2614            0 :       p = "CLASS IS";
    2615            0 :       break;
    2616            0 :     case ST_RANK:
    2617            0 :       p = "RANK";
    2618            0 :       break;
    2619            1 :     case ST_SEQUENCE:
    2620            1 :       p = "SEQUENCE";
    2621            1 :       break;
    2622            0 :     case ST_SIMPLE_IF:
    2623            0 :       p = _("simple IF");
    2624            0 :       break;
    2625            3 :     case ST_STATEMENT_FUNCTION:
    2626            3 :       p = "STATEMENT FUNCTION";
    2627            3 :       break;
    2628            0 :     case ST_LABEL_ASSIGNMENT:
    2629            0 :       p = "LABEL ASSIGNMENT";
    2630            0 :       break;
    2631            2 :     case ST_ENUM:
    2632            2 :       p = "ENUM DEFINITION";
    2633            2 :       break;
    2634            0 :     case ST_ENUMERATOR:
    2635            0 :       p = "ENUMERATOR DEFINITION";
    2636            0 :       break;
    2637            4 :     case ST_END_ENUM:
    2638            4 :       p = "END ENUM";
    2639            4 :       break;
    2640            0 :     case ST_OACC_PARALLEL_LOOP:
    2641            0 :       p = "!$ACC PARALLEL LOOP";
    2642            0 :       break;
    2643            3 :     case ST_OACC_END_PARALLEL_LOOP:
    2644            3 :       p = "!$ACC END PARALLEL LOOP";
    2645            3 :       break;
    2646            3 :     case ST_OACC_PARALLEL:
    2647            3 :       p = "!$ACC PARALLEL";
    2648            3 :       break;
    2649           37 :     case ST_OACC_END_PARALLEL:
    2650           37 :       p = "!$ACC END PARALLEL";
    2651           37 :       break;
    2652           49 :     case ST_OACC_KERNELS:
    2653           49 :       p = "!$ACC KERNELS";
    2654           49 :       break;
    2655           13 :     case ST_OACC_END_KERNELS:
    2656           13 :       p = "!$ACC END KERNELS";
    2657           13 :       break;
    2658            1 :     case ST_OACC_KERNELS_LOOP:
    2659            1 :       p = "!$ACC KERNELS LOOP";
    2660            1 :       break;
    2661            2 :     case ST_OACC_END_KERNELS_LOOP:
    2662            2 :       p = "!$ACC END KERNELS LOOP";
    2663            2 :       break;
    2664            0 :     case ST_OACC_SERIAL_LOOP:
    2665            0 :       p = "!$ACC SERIAL LOOP";
    2666            0 :       break;
    2667            3 :     case ST_OACC_END_SERIAL_LOOP:
    2668            3 :       p = "!$ACC END SERIAL LOOP";
    2669            3 :       break;
    2670            0 :     case ST_OACC_SERIAL:
    2671            0 :       p = "!$ACC SERIAL";
    2672            0 :       break;
    2673           18 :     case ST_OACC_END_SERIAL:
    2674           18 :       p = "!$ACC END SERIAL";
    2675           18 :       break;
    2676            2 :     case ST_OACC_DATA:
    2677            2 :       p = "!$ACC DATA";
    2678            2 :       break;
    2679            8 :     case ST_OACC_END_DATA:
    2680            8 :       p = "!$ACC END DATA";
    2681            8 :       break;
    2682            0 :     case ST_OACC_HOST_DATA:
    2683            0 :       p = "!$ACC HOST_DATA";
    2684            0 :       break;
    2685            2 :     case ST_OACC_END_HOST_DATA:
    2686            2 :       p = "!$ACC END HOST_DATA";
    2687            2 :       break;
    2688            4 :     case ST_OACC_LOOP:
    2689            4 :       p = "!$ACC LOOP";
    2690            4 :       break;
    2691            7 :     case ST_OACC_END_LOOP:
    2692            7 :       p = "!$ACC END LOOP";
    2693            7 :       break;
    2694            0 :     case ST_OACC_DECLARE:
    2695            0 :       p = "!$ACC DECLARE";
    2696            0 :       break;
    2697            1 :     case ST_OACC_UPDATE:
    2698            1 :       p = "!$ACC UPDATE";
    2699            1 :       break;
    2700            1 :     case ST_OACC_WAIT:
    2701            1 :       p = "!$ACC WAIT";
    2702            1 :       break;
    2703            1 :     case ST_OACC_CACHE:
    2704            1 :       p = "!$ACC CACHE";
    2705            1 :       break;
    2706            1 :     case ST_OACC_ENTER_DATA:
    2707            1 :       p = "!$ACC ENTER DATA";
    2708            1 :       break;
    2709            1 :     case ST_OACC_EXIT_DATA:
    2710            1 :       p = "!$ACC EXIT DATA";
    2711            1 :       break;
    2712            4 :     case ST_OACC_ROUTINE:
    2713            4 :       p = "!$ACC ROUTINE";
    2714            4 :       break;
    2715            0 :     case ST_OACC_ATOMIC:
    2716            0 :       p = "!$ACC ATOMIC";
    2717            0 :       break;
    2718            1 :     case ST_OACC_END_ATOMIC:
    2719            1 :       p = "!$ACC END ATOMIC";
    2720            1 :       break;
    2721            0 :     case ST_OACC_INIT:
    2722            0 :       p = "!ACC INIT";
    2723            0 :       break;
    2724            0 :     case ST_OACC_SHUTDOWN:
    2725            0 :       p = "!ACC SHUTDOWN";
    2726            0 :       break;
    2727            0 :     case ST_OACC_SET:
    2728            0 :       p = "!ACC SET";
    2729            0 :       break;
    2730            8 :     case ST_OMP_ALLOCATE:
    2731            8 :     case ST_OMP_ALLOCATE_EXEC:
    2732            8 :       p = "!$OMP ALLOCATE";
    2733            8 :       break;
    2734            4 :     case ST_OMP_ALLOCATORS:
    2735            4 :       p = "!$OMP ALLOCATORS";
    2736            4 :       break;
    2737            3 :     case ST_OMP_ASSUME:
    2738            3 :       p = "!$OMP ASSUME";
    2739            3 :       break;
    2740            3 :     case ST_OMP_ASSUMES:
    2741            3 :       p = "!$OMP ASSUMES";
    2742            3 :       break;
    2743            2 :     case ST_OMP_ATOMIC:
    2744            2 :       p = "!$OMP ATOMIC";
    2745            2 :       break;
    2746            1 :     case ST_OMP_BARRIER:
    2747            1 :       p = "!$OMP BARRIER";
    2748            1 :       break;
    2749            5 :     case ST_OMP_BEGIN_METADIRECTIVE:
    2750            5 :       p = "!$OMP BEGIN METADIRECTIVE";
    2751            5 :       break;
    2752            1 :     case ST_OMP_CANCEL:
    2753            1 :       p = "!$OMP CANCEL";
    2754            1 :       break;
    2755            1 :     case ST_OMP_CANCELLATION_POINT:
    2756            1 :       p = "!$OMP CANCELLATION POINT";
    2757            1 :       break;
    2758            1 :     case ST_OMP_CRITICAL:
    2759            1 :       p = "!$OMP CRITICAL";
    2760            1 :       break;
    2761            2 :     case ST_OMP_DECLARE_MAPPER:
    2762            2 :       p = "!$OMP DECLARE MAPPER";
    2763            2 :       break;
    2764            2 :     case ST_OMP_DECLARE_REDUCTION:
    2765            2 :       p = "!$OMP DECLARE REDUCTION";
    2766            2 :       break;
    2767            4 :     case ST_OMP_DECLARE_SIMD:
    2768            4 :       p = "!$OMP DECLARE SIMD";
    2769            4 :       break;
    2770            5 :     case ST_OMP_DECLARE_TARGET:
    2771            5 :       p = "!$OMP DECLARE TARGET";
    2772            5 :       break;
    2773            3 :     case ST_OMP_DECLARE_VARIANT:
    2774            3 :       p = "!$OMP DECLARE VARIANT";
    2775            3 :       break;
    2776            1 :     case ST_OMP_DEPOBJ:
    2777            1 :       p = "!$OMP DEPOBJ";
    2778            1 :       break;
    2779            0 :     case ST_OMP_DISPATCH:
    2780            0 :       p = "!$OMP DISPATCH";
    2781            0 :       break;
    2782            1 :     case ST_OMP_DISTRIBUTE:
    2783            1 :       p = "!$OMP DISTRIBUTE";
    2784            1 :       break;
    2785            1 :     case ST_OMP_DISTRIBUTE_PARALLEL_DO:
    2786            1 :       p = "!$OMP DISTRIBUTE PARALLEL DO";
    2787            1 :       break;
    2788            1 :     case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
    2789            1 :       p = "!$OMP DISTRIBUTE PARALLEL DO SIMD";
    2790            1 :       break;
    2791            1 :     case ST_OMP_DISTRIBUTE_SIMD:
    2792            1 :       p = "!$OMP DISTRIBUTE SIMD";
    2793            1 :       break;
    2794            4 :     case ST_OMP_DO:
    2795            4 :       p = "!$OMP DO";
    2796            4 :       break;
    2797            2 :     case ST_OMP_DO_SIMD:
    2798            2 :       p = "!$OMP DO SIMD";
    2799            2 :       break;
    2800            1 :     case ST_OMP_END_ALLOCATORS:
    2801            1 :       p = "!$OMP END ALLOCATORS";
    2802            1 :       break;
    2803            0 :     case ST_OMP_END_ASSUME:
    2804            0 :       p = "!$OMP END ASSUME";
    2805            0 :       break;
    2806            2 :     case ST_OMP_END_ATOMIC:
    2807            2 :       p = "!$OMP END ATOMIC";
    2808            2 :       break;
    2809            3 :     case ST_OMP_END_CRITICAL:
    2810            3 :       p = "!$OMP END CRITICAL";
    2811            3 :       break;
    2812            0 :     case ST_OMP_END_DISPATCH:
    2813            0 :       p = "!$OMP END DISPATCH";
    2814            0 :       break;
    2815            2 :     case ST_OMP_END_DISTRIBUTE:
    2816            2 :       p = "!$OMP END DISTRIBUTE";
    2817            2 :       break;
    2818            2 :     case ST_OMP_END_DISTRIBUTE_PARALLEL_DO:
    2819            2 :       p = "!$OMP END DISTRIBUTE PARALLEL DO";
    2820            2 :       break;
    2821            2 :     case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD:
    2822            2 :       p = "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
    2823            2 :       break;
    2824            2 :     case ST_OMP_END_DISTRIBUTE_SIMD:
    2825            2 :       p = "!$OMP END DISTRIBUTE SIMD";
    2826            2 :       break;
    2827            3 :     case ST_OMP_END_DO:
    2828            3 :       p = "!$OMP END DO";
    2829            3 :       break;
    2830            2 :     case ST_OMP_END_DO_SIMD:
    2831            2 :       p = "!$OMP END DO SIMD";
    2832            2 :       break;
    2833            3 :     case ST_OMP_END_SCOPE:
    2834            3 :       p = "!$OMP END SCOPE";
    2835            3 :       break;
    2836            2 :     case ST_OMP_END_SIMD:
    2837            2 :       p = "!$OMP END SIMD";
    2838            2 :       break;
    2839            2 :     case ST_OMP_END_LOOP:
    2840            2 :       p = "!$OMP END LOOP";
    2841            2 :       break;
    2842            3 :     case ST_OMP_END_MASKED:
    2843            3 :       p = "!$OMP END MASKED";
    2844            3 :       break;
    2845            2 :     case ST_OMP_END_MASKED_TASKLOOP:
    2846            2 :       p = "!$OMP END MASKED TASKLOOP";
    2847            2 :       break;
    2848            2 :     case ST_OMP_END_MASKED_TASKLOOP_SIMD:
    2849            2 :       p = "!$OMP END MASKED TASKLOOP SIMD";
    2850            2 :       break;
    2851            3 :     case ST_OMP_END_MASTER:
    2852            3 :       p = "!$OMP END MASTER";
    2853            3 :       break;
    2854            2 :     case ST_OMP_END_MASTER_TASKLOOP:
    2855            2 :       p = "!$OMP END MASTER TASKLOOP";
    2856            2 :       break;
    2857            2 :     case ST_OMP_END_MASTER_TASKLOOP_SIMD:
    2858            2 :       p = "!$OMP END MASTER TASKLOOP SIMD";
    2859            2 :       break;
    2860           46 :     case ST_OMP_END_METADIRECTIVE:
    2861           46 :       p = "!$OMP END METADIRECTIVE";
    2862           46 :       break;
    2863            3 :     case ST_OMP_END_ORDERED:
    2864            3 :       p = "!$OMP END ORDERED";
    2865            3 :       break;
    2866           28 :     case ST_OMP_END_PARALLEL:
    2867           28 :       p = "!$OMP END PARALLEL";
    2868           28 :       break;
    2869            2 :     case ST_OMP_END_PARALLEL_DO:
    2870            2 :       p = "!$OMP END PARALLEL DO";
    2871            2 :       break;
    2872            2 :     case ST_OMP_END_PARALLEL_DO_SIMD:
    2873            2 :       p = "!$OMP END PARALLEL DO SIMD";
    2874            2 :       break;
    2875            1 :     case ST_OMP_END_PARALLEL_LOOP:
    2876            1 :       p = "!$OMP END PARALLEL LOOP";
    2877            1 :       break;
    2878            3 :     case ST_OMP_END_PARALLEL_MASKED:
    2879            3 :       p = "!$OMP END PARALLEL MASKED";
    2880            3 :       break;
    2881            2 :     case ST_OMP_END_PARALLEL_MASKED_TASKLOOP:
    2882            2 :       p = "!$OMP END PARALLEL MASKED TASKLOOP";
    2883            2 :       break;
    2884            2 :     case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD:
    2885            2 :       p = "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
    2886            2 :       break;
    2887            3 :     case ST_OMP_END_PARALLEL_MASTER:
    2888            3 :       p = "!$OMP END PARALLEL MASTER";
    2889            3 :       break;
    2890            2 :     case ST_OMP_END_PARALLEL_MASTER_TASKLOOP:
    2891            2 :       p = "!$OMP END PARALLEL MASTER TASKLOOP";
    2892            2 :       break;
    2893            2 :     case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD:
    2894            2 :       p = "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
    2895            2 :       break;
    2896            2 :     case ST_OMP_END_PARALLEL_SECTIONS:
    2897            2 :       p = "!$OMP END PARALLEL SECTIONS";
    2898            2 :       break;
    2899            3 :     case ST_OMP_END_PARALLEL_WORKSHARE:
    2900            3 :       p = "!$OMP END PARALLEL WORKSHARE";
    2901            3 :       break;
    2902            2 :     case ST_OMP_END_SECTIONS:
    2903            2 :       p = "!$OMP END SECTIONS";
    2904            2 :       break;
    2905            3 :     case ST_OMP_END_SINGLE:
    2906            3 :       p = "!$OMP END SINGLE";
    2907            3 :       break;
    2908            5 :     case ST_OMP_END_TASK:
    2909            5 :       p = "!$OMP END TASK";
    2910            5 :       break;
    2911            9 :     case ST_OMP_END_TARGET:
    2912            9 :       p = "!$OMP END TARGET";
    2913            9 :       break;
    2914            3 :     case ST_OMP_END_TARGET_DATA:
    2915            3 :       p = "!$OMP END TARGET DATA";
    2916            3 :       break;
    2917            3 :     case ST_OMP_END_TARGET_PARALLEL:
    2918            3 :       p = "!$OMP END TARGET PARALLEL";
    2919            3 :       break;
    2920            2 :     case ST_OMP_END_TARGET_PARALLEL_DO:
    2921            2 :       p = "!$OMP END TARGET PARALLEL DO";
    2922            2 :       break;
    2923            2 :     case ST_OMP_END_TARGET_PARALLEL_DO_SIMD:
    2924            2 :       p = "!$OMP END TARGET PARALLEL DO SIMD";
    2925            2 :       break;
    2926            2 :     case ST_OMP_END_TARGET_PARALLEL_LOOP:
    2927            2 :       p = "!$OMP END TARGET PARALLEL LOOP";
    2928            2 :       break;
    2929            2 :     case ST_OMP_END_TARGET_SIMD:
    2930            2 :       p = "!$OMP END TARGET SIMD";
    2931            2 :       break;
    2932            3 :     case ST_OMP_END_TARGET_TEAMS:
    2933            3 :       p = "!$OMP END TARGET TEAMS";
    2934            3 :       break;
    2935            2 :     case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE:
    2936            2 :       p = "!$OMP END TARGET TEAMS DISTRIBUTE";
    2937            2 :       break;
    2938            2 :     case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    2939            2 :       p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
    2940            2 :       break;
    2941            4 :     case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    2942            4 :       p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
    2943            4 :       break;
    2944            2 :     case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD:
    2945            2 :       p = "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
    2946            2 :       break;
    2947            2 :     case ST_OMP_END_TARGET_TEAMS_LOOP:
    2948            2 :       p = "!$OMP END TARGET TEAMS LOOP";
    2949            2 :       break;
    2950            3 :     case ST_OMP_END_TASKGROUP:
    2951            3 :       p = "!$OMP END TASKGROUP";
    2952            3 :       break;
    2953            2 :     case ST_OMP_END_TASKLOOP:
    2954            2 :       p = "!$OMP END TASKLOOP";
    2955            2 :       break;
    2956            2 :     case ST_OMP_END_TASKLOOP_SIMD:
    2957            2 :       p = "!$OMP END TASKLOOP SIMD";
    2958            2 :       break;
    2959            9 :     case ST_OMP_END_TEAMS:
    2960            9 :       p = "!$OMP END TEAMS";
    2961            9 :       break;
    2962            2 :     case ST_OMP_END_TEAMS_DISTRIBUTE:
    2963            2 :       p = "!$OMP END TEAMS DISTRIBUTE";
    2964            2 :       break;
    2965            2 :     case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO:
    2966            2 :       p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
    2967            2 :       break;
    2968            2 :     case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    2969            2 :       p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
    2970            2 :       break;
    2971            2 :     case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD:
    2972            2 :       p = "!$OMP END TEAMS DISTRIBUTE SIMD";
    2973            2 :       break;
    2974            1 :     case ST_OMP_END_TEAMS_LOOP:
    2975            1 :       p = "!$OMP END TEAMS LOOP";
    2976            1 :       break;
    2977            8 :     case ST_OMP_END_TILE:
    2978            8 :       p = "!$OMP END TILE";
    2979            8 :       break;
    2980            4 :     case ST_OMP_END_UNROLL:
    2981            4 :       p = "!$OMP END UNROLL";
    2982            4 :       break;
    2983            3 :     case ST_OMP_END_WORKSHARE:
    2984            3 :       p = "!$OMP END WORKSHARE";
    2985            3 :       break;
    2986            3 :     case ST_OMP_ERROR:
    2987            3 :       p = "!$OMP ERROR";
    2988            3 :       break;
    2989            1 :     case ST_OMP_FLUSH:
    2990            1 :       p = "!$OMP FLUSH";
    2991            1 :       break;
    2992            0 :     case ST_OMP_GROUPPRIVATE:
    2993            0 :       p = "!$OMP GROUPPRIVATE";
    2994            0 :       break;
    2995            0 :     case ST_OMP_INTEROP:
    2996            0 :       p = "!$OMP INTEROP";
    2997            0 :       break;
    2998            0 :     case ST_OMP_LOOP:
    2999            0 :       p = "!$OMP LOOP";
    3000            0 :       break;
    3001            0 :     case ST_OMP_MASKED:
    3002            0 :       p = "!$OMP MASKED";
    3003            0 :       break;
    3004            0 :     case ST_OMP_MASKED_TASKLOOP:
    3005            0 :       p = "!$OMP MASKED TASKLOOP";
    3006            0 :       break;
    3007            0 :     case ST_OMP_MASKED_TASKLOOP_SIMD:
    3008            0 :       p = "!$OMP MASKED TASKLOOP SIMD";
    3009            0 :       break;
    3010            1 :     case ST_OMP_MASTER:
    3011            1 :       p = "!$OMP MASTER";
    3012            1 :       break;
    3013            0 :     case ST_OMP_MASTER_TASKLOOP:
    3014            0 :       p = "!$OMP MASTER TASKLOOP";
    3015            0 :       break;
    3016            0 :     case ST_OMP_MASTER_TASKLOOP_SIMD:
    3017            0 :       p = "!$OMP MASTER TASKLOOP SIMD";
    3018            0 :       break;
    3019           15 :     case ST_OMP_METADIRECTIVE:
    3020           15 :       p = "!$OMP METADIRECTIVE";
    3021           15 :       break;
    3022            1 :     case ST_OMP_ORDERED:
    3023            1 :     case ST_OMP_ORDERED_DEPEND:
    3024            1 :       p = "!$OMP ORDERED";
    3025            1 :       break;
    3026            0 :     case ST_OMP_NOTHING:
    3027              :       /* Note: gfc_match_omp_nothing returns ST_NONE. */
    3028            0 :       p = "!$OMP NOTHING";
    3029            0 :       break;
    3030            9 :     case ST_OMP_PARALLEL:
    3031            9 :       p = "!$OMP PARALLEL";
    3032            9 :       break;
    3033            6 :     case ST_OMP_PARALLEL_DO:
    3034            6 :       p = "!$OMP PARALLEL DO";
    3035            6 :       break;
    3036            0 :     case ST_OMP_PARALLEL_LOOP:
    3037            0 :       p = "!$OMP PARALLEL LOOP";
    3038            0 :       break;
    3039            1 :     case ST_OMP_PARALLEL_DO_SIMD:
    3040            1 :       p = "!$OMP PARALLEL DO SIMD";
    3041            1 :       break;
    3042            0 :     case ST_OMP_PARALLEL_MASKED:
    3043            0 :       p = "!$OMP PARALLEL MASKED";
    3044            0 :       break;
    3045            0 :     case ST_OMP_PARALLEL_MASKED_TASKLOOP:
    3046            0 :       p = "!$OMP PARALLEL MASKED TASKLOOP";
    3047            0 :       break;
    3048            0 :     case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
    3049            0 :       p = "!$OMP PARALLEL MASKED TASKLOOP SIMD";
    3050            0 :       break;
    3051            0 :     case ST_OMP_PARALLEL_MASTER:
    3052            0 :       p = "!$OMP PARALLEL MASTER";
    3053            0 :       break;
    3054            0 :     case ST_OMP_PARALLEL_MASTER_TASKLOOP:
    3055            0 :       p = "!$OMP PARALLEL MASTER TASKLOOP";
    3056            0 :       break;
    3057            0 :     case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
    3058            0 :       p = "!$OMP PARALLEL MASTER TASKLOOP SIMD";
    3059            0 :       break;
    3060            1 :     case ST_OMP_PARALLEL_SECTIONS:
    3061            1 :       p = "!$OMP PARALLEL SECTIONS";
    3062            1 :       break;
    3063            1 :     case ST_OMP_PARALLEL_WORKSHARE:
    3064            1 :       p = "!$OMP PARALLEL WORKSHARE";
    3065            1 :       break;
    3066            2 :     case ST_OMP_REQUIRES:
    3067            2 :       p = "!$OMP REQUIRES";
    3068            2 :       break;
    3069            0 :     case ST_OMP_SCAN:
    3070            0 :       p = "!$OMP SCAN";
    3071            0 :       break;
    3072            1 :     case ST_OMP_SCOPE:
    3073            1 :       p = "!$OMP SCOPE";
    3074            1 :       break;
    3075            2 :     case ST_OMP_SECTIONS:
    3076            2 :       p = "!$OMP SECTIONS";
    3077            2 :       break;
    3078            1 :     case ST_OMP_SECTION:
    3079            1 :       p = "!$OMP SECTION";
    3080            1 :       break;
    3081            3 :     case ST_OMP_SIMD:
    3082            3 :       p = "!$OMP SIMD";
    3083            3 :       break;
    3084            2 :     case ST_OMP_SINGLE:
    3085            2 :       p = "!$OMP SINGLE";
    3086            2 :       break;
    3087            4 :     case ST_OMP_TARGET:
    3088            4 :       p = "!$OMP TARGET";
    3089            4 :       break;
    3090            1 :     case ST_OMP_TARGET_DATA:
    3091            1 :       p = "!$OMP TARGET DATA";
    3092            1 :       break;
    3093            1 :     case ST_OMP_TARGET_ENTER_DATA:
    3094            1 :       p = "!$OMP TARGET ENTER DATA";
    3095            1 :       break;
    3096            1 :     case ST_OMP_TARGET_EXIT_DATA:
    3097            1 :       p = "!$OMP TARGET EXIT DATA";
    3098            1 :       break;
    3099            2 :     case ST_OMP_TARGET_PARALLEL:
    3100            2 :       p = "!$OMP TARGET PARALLEL";
    3101            2 :       break;
    3102            2 :     case ST_OMP_TARGET_PARALLEL_DO:
    3103            2 :       p = "!$OMP TARGET PARALLEL DO";
    3104            2 :       break;
    3105            2 :     case ST_OMP_TARGET_PARALLEL_DO_SIMD:
    3106            2 :       p = "!$OMP TARGET PARALLEL DO SIMD";
    3107            2 :       break;
    3108            1 :     case ST_OMP_TARGET_PARALLEL_LOOP:
    3109            1 :       p = "!$OMP TARGET PARALLEL LOOP";
    3110            1 :       break;
    3111            2 :     case ST_OMP_TARGET_SIMD:
    3112            2 :       p = "!$OMP TARGET SIMD";
    3113            2 :       break;
    3114            2 :     case ST_OMP_TARGET_TEAMS:
    3115            2 :       p = "!$OMP TARGET TEAMS";
    3116            2 :       break;
    3117            2 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
    3118            2 :       p = "!$OMP TARGET TEAMS DISTRIBUTE";
    3119            2 :       break;
    3120            2 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    3121            2 :       p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
    3122            2 :       break;
    3123            2 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    3124            2 :       p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
    3125            2 :       break;
    3126            2 :     case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    3127            2 :       p = "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
    3128            2 :       break;
    3129            1 :     case ST_OMP_TARGET_TEAMS_LOOP:
    3130            1 :       p = "!$OMP TARGET TEAMS LOOP";
    3131            1 :       break;
    3132            1 :     case ST_OMP_TARGET_UPDATE:
    3133            1 :       p = "!$OMP TARGET UPDATE";
    3134            1 :       break;
    3135            1 :     case ST_OMP_TASK:
    3136            1 :       p = "!$OMP TASK";
    3137            1 :       break;
    3138            1 :     case ST_OMP_TASKGROUP:
    3139            1 :       p = "!$OMP TASKGROUP";
    3140            1 :       break;
    3141            1 :     case ST_OMP_TASKLOOP:
    3142            1 :       p = "!$OMP TASKLOOP";
    3143            1 :       break;
    3144            1 :     case ST_OMP_TASKLOOP_SIMD:
    3145            1 :       p = "!$OMP TASKLOOP SIMD";
    3146            1 :       break;
    3147            1 :     case ST_OMP_TASKWAIT:
    3148            1 :       p = "!$OMP TASKWAIT";
    3149            1 :       break;
    3150            1 :     case ST_OMP_TASKYIELD:
    3151            1 :       p = "!$OMP TASKYIELD";
    3152            1 :       break;
    3153            1 :     case ST_OMP_TEAMS:
    3154            1 :       p = "!$OMP TEAMS";
    3155            1 :       break;
    3156            1 :     case ST_OMP_TEAMS_DISTRIBUTE:
    3157            1 :       p = "!$OMP TEAMS DISTRIBUTE";
    3158            1 :       break;
    3159            1 :     case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    3160            1 :       p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
    3161            1 :       break;
    3162            1 :     case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    3163            1 :       p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
    3164            1 :       break;
    3165            1 :     case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
    3166            1 :       p = "!$OMP TEAMS DISTRIBUTE SIMD";
    3167            1 :       break;
    3168            0 :     case ST_OMP_TEAMS_LOOP:
    3169            0 :       p = "!$OMP TEAMS LOOP";
    3170            0 :       break;
    3171            2 :     case ST_OMP_THREADPRIVATE:
    3172            2 :       p = "!$OMP THREADPRIVATE";
    3173            2 :       break;
    3174            0 :     case ST_OMP_TILE:
    3175            0 :       p = "!$OMP TILE";
    3176            0 :       break;
    3177            0 :     case ST_OMP_UNROLL:
    3178            0 :       p = "!$OMP UNROLL";
    3179            0 :       break;
    3180            2 :     case ST_OMP_WORKSHARE:
    3181            2 :       p = "!$OMP WORKSHARE";
    3182            2 :       break;
    3183            0 :     default:
    3184            0 :       gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
    3185              :     }
    3186              : 
    3187        30677 :   if (strip_sentinel && p[0] == '!')
    3188           15 :     return p + strlen ("!$OMP ");
    3189              :   return p;
    3190              : }
    3191              : 
    3192              : 
    3193              : /* Create a symbol for the main program and assign it to ns->proc_name.  */
    3194              : 
    3195              : static void
    3196        28958 : main_program_symbol (gfc_namespace *ns, const char *name)
    3197              : {
    3198        28958 :   gfc_symbol *main_program;
    3199        28958 :   symbol_attribute attr;
    3200              : 
    3201        28958 :   gfc_get_symbol (name, ns, &main_program);
    3202        28958 :   gfc_clear_attr (&attr);
    3203        28958 :   attr.flavor = FL_PROGRAM;
    3204        28958 :   attr.proc = PROC_UNKNOWN;
    3205        28958 :   attr.subroutine = 1;
    3206        28958 :   attr.access = ACCESS_PUBLIC;
    3207        28958 :   attr.is_main_program = 1;
    3208        28958 :   main_program->attr = attr;
    3209        28958 :   main_program->declared_at = gfc_current_locus;
    3210        28958 :   ns->proc_name = main_program;
    3211        28958 :   gfc_commit_symbols ();
    3212        28958 : }
    3213              : 
    3214              : 
    3215              : /* Do whatever is necessary to accept the last statement.  */
    3216              : 
    3217              : static void
    3218      1441126 : accept_statement (gfc_statement st)
    3219              : {
    3220      1441126 :   switch (st)
    3221              :     {
    3222              :     case ST_IMPLICIT_NONE:
    3223              :     case ST_IMPLICIT:
    3224              :       break;
    3225              : 
    3226        76871 :     case ST_FUNCTION:
    3227        76871 :     case ST_SUBROUTINE:
    3228        76871 :     case ST_MODULE:
    3229        76871 :     case ST_SUBMODULE:
    3230        76871 :       gfc_current_ns->proc_name = gfc_new_block;
    3231        76871 :       break;
    3232              : 
    3233              :       /* If the statement is the end of a block, lay down a special code
    3234              :          that allows a branch to the end of the block from within the
    3235              :          construct.  IF and SELECT are treated differently from DO
    3236              :          (where EXEC_NOP is added inside the loop) for two
    3237              :          reasons:
    3238              :          1. END DO has a meaning in the sense that after a GOTO to
    3239              :             it, the loop counter must be increased.
    3240              :          2. IF blocks and SELECT blocks can consist of multiple
    3241              :             parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
    3242              :             Putting the label before the END IF would make the jump
    3243              :             from, say, the ELSE IF block to the END IF illegal.  */
    3244              : 
    3245        20198 :     case ST_ENDIF:
    3246        20198 :     case ST_END_SELECT:
    3247        20198 :     case ST_END_CRITICAL:
    3248        20198 :       if (gfc_statement_label != NULL)
    3249              :         {
    3250           43 :           new_st.op = EXEC_END_NESTED_BLOCK;
    3251           43 :           add_statement ();
    3252              :         }
    3253              :       break;
    3254              : 
    3255              :       /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
    3256              :          one parallel block.  Thus, we add the special code to the nested block
    3257              :          itself, instead of the parent one.  */
    3258         3350 :     case ST_END_BLOCK:
    3259         3350 :     case ST_END_ASSOCIATE:
    3260         3350 :       if (gfc_statement_label != NULL)
    3261              :         {
    3262            2 :           new_st.op = EXEC_END_BLOCK;
    3263            2 :           add_statement ();
    3264              :         }
    3265              :       break;
    3266              : 
    3267              :       /* The end-of-program unit statements do not get the special
    3268              :          marker and require a statement of some sort if they are a
    3269              :          branch target.  */
    3270              : 
    3271        79828 :     case ST_END_PROGRAM:
    3272        79828 :     case ST_END_FUNCTION:
    3273        79828 :     case ST_END_SUBROUTINE:
    3274        79828 :       if (gfc_statement_label != NULL)
    3275              :         {
    3276              :           /* After a contains section, the label was defined in a scratch
    3277              :              namespace.  Define it in the host and add the statement there.  */
    3278           60 :           if (gfc_state_stack->state == COMP_CONTAINS)
    3279              :             {
    3280           22 :               gfc_state_data *previous_state = gfc_state_stack;
    3281           22 :               gfc_namespace *old_ns = gfc_current_ns;
    3282           22 :               gfc_current_ns = old_ns->parent;
    3283           22 :               new_st.here = gfc_get_st_label (gfc_statement_label->value);
    3284           22 :               gfc_define_st_label (new_st.here, ST_LABEL_TARGET,
    3285           22 :                                    &gfc_statement_label->where);
    3286           22 :               new_st.op = EXEC_RETURN;
    3287           22 :               gfc_state_stack = gfc_state_stack->previous;
    3288           22 :               add_statement ();
    3289           22 :               gfc_state_stack = previous_state;
    3290           22 :               gfc_current_ns = old_ns;
    3291              :             }
    3292              :           else
    3293              :            {
    3294           38 :              new_st.op = EXEC_RETURN;
    3295           38 :              add_statement ();
    3296              :            }
    3297              :         }
    3298              :       else
    3299              :         {
    3300        79768 :           new_st.op = EXEC_END_PROCEDURE;
    3301        79768 :           add_statement ();
    3302              :         }
    3303              : 
    3304              :       break;
    3305              : 
    3306        10702 :     case ST_END_MODULE:
    3307        10702 :     case ST_END_SUBMODULE:
    3308              :       /* After a contains section, the label was defined in a scratch
    3309              :          namespace.  Define it in the module.  */
    3310        10702 :       if (gfc_statement_label != NULL
    3311            3 :           && gfc_state_stack->state == COMP_CONTAINS)
    3312              :         {
    3313            3 :           gfc_namespace *old_ns = gfc_current_ns;
    3314            3 :           gfc_current_ns = old_ns->parent;
    3315            3 :           gfc_define_st_label (gfc_get_st_label (gfc_statement_label->value),
    3316              :                                ST_LABEL_BAD_TARGET,
    3317              :                                &gfc_statement_label->where);
    3318            3 :           gfc_current_ns = old_ns;
    3319              :         }
    3320              :       break;
    3321              : 
    3322       783068 :     case ST_ENTRY:
    3323       783068 :     case ST_OMP_METADIRECTIVE:
    3324       783068 :     case ST_OMP_BEGIN_METADIRECTIVE:
    3325       783068 :     case ST_CHANGE_TEAM:
    3326       783068 :     case ST_END_TEAM:
    3327       783068 :     case_executable:
    3328       783068 :     case_exec_markers:
    3329       783068 :       add_statement ();
    3330       783068 :       break;
    3331              : 
    3332              :     default:
    3333              :       break;
    3334              :     }
    3335              : 
    3336      1441126 :   gfc_commit_symbols ();
    3337      1441126 :   gfc_warning_check ();
    3338      1441126 :   gfc_clear_new_st ();
    3339      1441126 : }
    3340              : 
    3341              : 
    3342              : /* Undo anything tentative that has been built for the current statement.  */
    3343              : 
    3344              : static void
    3345      9475389 : reject_statement (void)
    3346              : {
    3347      9475389 :   gfc_free_equiv_until (gfc_current_ns->equiv, gfc_current_ns->old_equiv);
    3348      9475389 :   gfc_current_ns->equiv = gfc_current_ns->old_equiv;
    3349      9475389 :   gfc_drop_interface_elements_before (current_interface_ptr,
    3350              :                                       previous_interface_head);
    3351              : 
    3352      9475389 :   gfc_reject_data (gfc_current_ns);
    3353              : 
    3354              :   /* Don't queue use-association of a module if we reject the use statement.  */
    3355      9475389 :   gfc_restore_old_module_list ();
    3356              : 
    3357      9475389 :   gfc_new_block = NULL;
    3358      9475389 :   gfc_undo_symbols ();
    3359      9475389 :   gfc_clear_warning ();
    3360      9475389 :   undo_new_statement ();
    3361      9475389 : }
    3362              : 
    3363              : 
    3364              : /* Generic complaint about an out of order statement.  We also do
    3365              :    whatever is necessary to clean up.  */
    3366              : 
    3367              : static void
    3368          270 : unexpected_statement (gfc_statement st)
    3369              : {
    3370          270 :   gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st));
    3371              : 
    3372          270 :   reject_statement ();
    3373          270 : }
    3374              : 
    3375              : 
    3376              : /* Given the next statement seen by the matcher, make sure that it is
    3377              :    in proper order with the last.  This subroutine is initialized by
    3378              :    calling it with an argument of ST_NONE.  If there is a problem, we
    3379              :    issue an error and return false.  Otherwise we return true.
    3380              : 
    3381              :    Individual parsers need to verify that the statements seen are
    3382              :    valid before calling here, i.e., ENTRY statements are not allowed in
    3383              :    INTERFACE blocks.  The following diagram is taken from the standard:
    3384              : 
    3385              :             +---------------------------------------+
    3386              :             | program  subroutine  function  module |
    3387              :             +---------------------------------------+
    3388              :             |            use               |
    3389              :             +---------------------------------------+
    3390              :             |            import         |
    3391              :             +---------------------------------------+
    3392              :             |   |       implicit none    |
    3393              :             |   +-----------+------------------+
    3394              :             |   | parameter |  implicit |
    3395              :             |   +-----------+------------------+
    3396              :             | format |     |  derived type    |
    3397              :             | entry  | parameter |  interface       |
    3398              :             |   |   data    |  specification   |
    3399              :             |   |          |  statement func  |
    3400              :             |   +-----------+------------------+
    3401              :             |   |   data    |    executable    |
    3402              :             +--------+-----------+------------------+
    3403              :             |           contains               |
    3404              :             +---------------------------------------+
    3405              :             |      internal module/subprogram       |
    3406              :             +---------------------------------------+
    3407              :             |              end           |
    3408              :             +---------------------------------------+
    3409              : 
    3410              : */
    3411              : 
    3412              : enum state_order
    3413              : {
    3414              :   ORDER_START,
    3415              :   ORDER_USE,
    3416              :   ORDER_IMPORT,
    3417              :   ORDER_IMPLICIT_NONE,
    3418              :   ORDER_IMPLICIT,
    3419              :   ORDER_SPEC,
    3420              :   ORDER_EXEC
    3421              : };
    3422              : 
    3423              : typedef struct
    3424              : {
    3425              :   enum state_order state;
    3426              :   gfc_statement last_statement;
    3427              :   locus where;
    3428              : }
    3429              : st_state;
    3430              : 
    3431              : static bool
    3432       467604 : verify_st_order (st_state *p, gfc_statement st, bool silent)
    3433              : {
    3434              : 
    3435       467604 :   switch (st)
    3436              :     {
    3437       121051 :     case ST_NONE:
    3438       121051 :       p->state = ORDER_START;
    3439       121051 :       in_exec_part = false;
    3440       121051 :       break;
    3441              : 
    3442        26396 :     case ST_USE:
    3443        26396 :       if (p->state > ORDER_USE)
    3444            0 :         goto order;
    3445        26396 :       p->state = ORDER_USE;
    3446        26396 :       break;
    3447              : 
    3448         4650 :     case ST_IMPORT:
    3449         4650 :       if (p->state > ORDER_IMPORT)
    3450            0 :         goto order;
    3451         4650 :       p->state = ORDER_IMPORT;
    3452         4650 :       break;
    3453              : 
    3454        25841 :     case ST_IMPLICIT_NONE:
    3455        25841 :       if (p->state > ORDER_IMPLICIT)
    3456            0 :         goto order;
    3457              : 
    3458              :       /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
    3459              :          statement disqualifies a USE but not an IMPLICIT NONE.
    3460              :          Duplicate IMPLICIT NONEs are caught when the implicit types
    3461              :          are set.  */
    3462              : 
    3463        25841 :       p->state = ORDER_IMPLICIT_NONE;
    3464        25841 :       break;
    3465              : 
    3466        14029 :     case ST_IMPLICIT:
    3467        14029 :       if (p->state > ORDER_IMPLICIT)
    3468        10790 :         goto order;
    3469         3239 :       p->state = ORDER_IMPLICIT;
    3470         3239 :       break;
    3471              : 
    3472          499 :     case ST_FORMAT:
    3473          499 :     case ST_ENTRY:
    3474          499 :       if (p->state < ORDER_IMPLICIT_NONE)
    3475           77 :         p->state = ORDER_IMPLICIT_NONE;
    3476              :       break;
    3477              : 
    3478         8053 :     case ST_PARAMETER:
    3479         8053 :       if (p->state >= ORDER_EXEC)
    3480            0 :         goto order;
    3481         8053 :       if (p->state < ORDER_IMPLICIT)
    3482           80 :         p->state = ORDER_IMPLICIT;
    3483              :       break;
    3484              : 
    3485         2358 :     case ST_DATA:
    3486         2358 :       if (p->state < ORDER_SPEC)
    3487           17 :         p->state = ORDER_SPEC;
    3488              :       break;
    3489              : 
    3490       260945 :     case ST_PUBLIC:
    3491       260945 :     case ST_PRIVATE:
    3492       260945 :     case ST_STRUCTURE_DECL:
    3493       260945 :     case ST_DERIVED_DECL:
    3494       260945 :     case_decl:
    3495       260945 :       if (p->state >= ORDER_EXEC)
    3496            0 :         goto order;
    3497       260945 :       if (p->state < ORDER_SPEC)
    3498       104205 :         p->state = ORDER_SPEC;
    3499              :       break;
    3500              : 
    3501         3008 :     case_omp_decl:
    3502              :       /* The OpenMP/OpenACC directives have to be somewhere in the specification
    3503              :          part, but there are no further requirements on their ordering.
    3504              :          Thus don't adjust p->state, just ignore them.  */
    3505         3008 :       if (p->state >= ORDER_EXEC)
    3506            0 :         goto order;
    3507              :       break;
    3508              : 
    3509          770 :     case ST_CHANGE_TEAM:
    3510          770 :     case ST_END_TEAM:
    3511          770 :     case_executable:
    3512          770 :     case_exec_markers:
    3513          770 :       if (p->state < ORDER_EXEC)
    3514          770 :         p->state = ORDER_EXEC;
    3515          770 :       in_exec_part = true;
    3516          770 :       break;
    3517              : 
    3518              :     default:
    3519              :       return false;
    3520              :     }
    3521              : 
    3522              :   /* All is well, record the statement in case we need it next time.  */
    3523       456810 :   p->where = gfc_current_locus;
    3524       456810 :   p->last_statement = st;
    3525       456810 :   return true;
    3526              : 
    3527        10790 : order:
    3528        10790 :   if (!silent)
    3529            1 :     gfc_error ("%s statement at %C cannot follow %s statement at %L",
    3530              :                gfc_ascii_statement (st),
    3531              :                gfc_ascii_statement (p->last_statement), &p->where);
    3532              : 
    3533              :   return false;
    3534              : }
    3535              : 
    3536              : 
    3537              : /* Handle an unexpected end of file.  This is a show-stopper...  */
    3538              : 
    3539              : static void unexpected_eof (void) ATTRIBUTE_NORETURN;
    3540              : 
    3541              : static void
    3542           33 : unexpected_eof (void)
    3543              : {
    3544           33 :   gfc_state_data *p;
    3545              : 
    3546           33 :   gfc_error ("Unexpected end of file in %qs", gfc_source_file);
    3547              : 
    3548              :   /* Memory cleanup.  Move to "second to last".  */
    3549           72 :   for (p = gfc_state_stack; p && p->previous && p->previous->previous;
    3550              :        p = p->previous);
    3551              : 
    3552           33 :   gfc_current_ns->code = (p && p->previous) ? p->head : NULL;
    3553           33 :   gfc_done_2 ();
    3554              : 
    3555           33 :   longjmp (eof_buf, 1);
    3556              : 
    3557              :   /* Avoids build error on systems where longjmp is not declared noreturn.  */
    3558              :   gcc_unreachable ();
    3559              : }
    3560              : 
    3561              : 
    3562              : /* Parse the CONTAINS section of a derived type definition.  */
    3563              : 
    3564              : gfc_access gfc_typebound_default_access;
    3565              : 
    3566              : static bool
    3567         2401 : parse_derived_contains (void)
    3568              : {
    3569         2401 :   gfc_state_data s;
    3570         2401 :   bool seen_private = false;
    3571         2401 :   bool seen_comps = false;
    3572         2401 :   bool error_flag = false;
    3573         2401 :   bool to_finish;
    3574              : 
    3575         2401 :   gcc_assert (gfc_current_state () == COMP_DERIVED);
    3576         2401 :   gcc_assert (gfc_current_block ());
    3577              : 
    3578              :   /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
    3579              :      section.  */
    3580         2401 :   if (gfc_current_block ()->attr.sequence)
    3581            1 :     gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
    3582              :                " section at %C", gfc_current_block ()->name);
    3583         2401 :   if (gfc_current_block ()->attr.is_bind_c)
    3584            1 :     gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
    3585              :                " section at %C", gfc_current_block ()->name);
    3586              : 
    3587         2401 :   accept_statement (ST_CONTAINS);
    3588         2401 :   push_state (&s, COMP_DERIVED_CONTAINS, NULL);
    3589              : 
    3590         2401 :   gfc_typebound_default_access = ACCESS_PUBLIC;
    3591              : 
    3592         2401 :   to_finish = false;
    3593         2401 :   while (!to_finish)
    3594              :     {
    3595         7201 :       gfc_statement st;
    3596         7201 :       st = next_statement ();
    3597         7201 :       switch (st)
    3598              :         {
    3599            0 :         case ST_NONE:
    3600            0 :           unexpected_eof ();
    3601            1 :           break;
    3602              : 
    3603            1 :         case ST_DATA_DECL:
    3604            1 :           gfc_error ("Components in TYPE at %C must precede CONTAINS");
    3605            1 :           goto error;
    3606              : 
    3607         3295 :         case ST_PROCEDURE:
    3608         3295 :           if (!gfc_notify_std (GFC_STD_F2003, "Type-bound procedure at %C"))
    3609            0 :             goto error;
    3610              : 
    3611         3295 :           accept_statement (ST_PROCEDURE);
    3612         3295 :           seen_comps = true;
    3613         3295 :           break;
    3614              : 
    3615          964 :         case ST_GENERIC:
    3616          964 :           if (!gfc_notify_std (GFC_STD_F2003, "GENERIC binding at %C"))
    3617            0 :             goto error;
    3618              : 
    3619          964 :           accept_statement (ST_GENERIC);
    3620          964 :           seen_comps = true;
    3621          964 :           break;
    3622              : 
    3623          507 :         case ST_FINAL:
    3624          507 :           if (!gfc_notify_std (GFC_STD_F2003, "FINAL procedure declaration"
    3625              :                                " at %C"))
    3626            1 :             goto error;
    3627              : 
    3628          506 :           accept_statement (ST_FINAL);
    3629          506 :           seen_comps = true;
    3630          506 :           break;
    3631              : 
    3632         2401 :         case ST_END_TYPE:
    3633         2401 :           to_finish = true;
    3634              : 
    3635         2401 :           if (!seen_comps
    3636         2401 :               && (!gfc_notify_std(GFC_STD_F2008, "Derived type definition "
    3637              :                                   "at %C with empty CONTAINS section")))
    3638            4 :             goto error;
    3639              : 
    3640              :           /* ST_END_TYPE is accepted by parse_derived after return.  */
    3641              :           break;
    3642              : 
    3643           32 :         case ST_PRIVATE:
    3644           32 :           if (!gfc_find_state (COMP_MODULE))
    3645              :             {
    3646            0 :               gfc_error ("PRIVATE statement in TYPE at %C must be inside "
    3647              :                          "a MODULE");
    3648            0 :               goto error;
    3649              :             }
    3650              : 
    3651           32 :           if (seen_comps)
    3652              :             {
    3653            1 :               gfc_error ("PRIVATE statement at %C must precede procedure"
    3654              :                          " bindings");
    3655            1 :               goto error;
    3656              :             }
    3657              : 
    3658           31 :           if (seen_private)
    3659              :             {
    3660            0 :               gfc_error ("Duplicate PRIVATE statement at %C");
    3661            0 :               goto error;
    3662              :             }
    3663              : 
    3664           31 :           accept_statement (ST_PRIVATE);
    3665           31 :           gfc_typebound_default_access = ACCESS_PRIVATE;
    3666           31 :           seen_private = true;
    3667           31 :           break;
    3668              : 
    3669            0 :         case ST_SEQUENCE:
    3670            0 :           gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
    3671            0 :           goto error;
    3672              : 
    3673            1 :         case ST_CONTAINS:
    3674            1 :           gfc_error ("Already inside a CONTAINS block at %C");
    3675            1 :           goto error;
    3676              : 
    3677            0 :         default:
    3678            0 :           unexpected_statement (st);
    3679            0 :           break;
    3680              :         }
    3681              : 
    3682         7193 :       continue;
    3683              : 
    3684            8 : error:
    3685            8 :       error_flag = true;
    3686            8 :       reject_statement ();
    3687         7193 :     }
    3688              : 
    3689         2401 :   pop_state ();
    3690         2401 :   gcc_assert (gfc_current_state () == COMP_DERIVED);
    3691              : 
    3692         2401 :   return error_flag;
    3693              : }
    3694              : 
    3695              : 
    3696              : /* Set attributes for the parent symbol based on the attributes of a component
    3697              :    and raise errors if conflicting attributes are found for the component.  */
    3698              : 
    3699              : static void
    3700        23052 : check_component (gfc_symbol *sym, gfc_component *c, gfc_component **lockp,
    3701              :     gfc_component **eventp)
    3702              : {
    3703        23052 :   bool coarray, lock_type, event_type, allocatable, pointer;
    3704        23052 :   coarray = lock_type = event_type = allocatable = pointer = false;
    3705        23052 :   gfc_component *lock_comp = NULL, *event_comp = NULL;
    3706              : 
    3707        23052 :   if (lockp) lock_comp = *lockp;
    3708        23052 :   if (eventp) event_comp = *eventp;
    3709              : 
    3710              :   /* Look for allocatable components.  */
    3711        23052 :   if (c->attr.allocatable
    3712        19690 :       || (c->ts.type == BT_CLASS && c->attr.class_ok
    3713          980 :           && CLASS_DATA (c)->attr.allocatable)
    3714        19032 :       || (c->ts.type == BT_DERIVED && !c->attr.pointer
    3715         3468 :           && c->ts.u.derived->attr.alloc_comp))
    3716              :     {
    3717         4636 :       allocatable = true;
    3718         4636 :       sym->attr.alloc_comp = 1;
    3719              :     }
    3720              : 
    3721              :   /* Look for pointer components.  */
    3722        23052 :   if (c->attr.pointer
    3723        21703 :       || (c->ts.type == BT_CLASS && c->attr.class_ok
    3724          980 :           && CLASS_DATA (c)->attr.class_pointer)
    3725        21381 :       || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.pointer_comp))
    3726              :     {
    3727         1898 :       pointer = true;
    3728         1898 :       sym->attr.pointer_comp = 1;
    3729              :     }
    3730              : 
    3731              :   /* Look for procedure pointer components.  */
    3732        23052 :   if (c->attr.proc_pointer
    3733        22601 :       || (c->ts.type == BT_DERIVED
    3734         4787 :           && c->ts.u.derived->attr.proc_pointer_comp))
    3735          547 :     sym->attr.proc_pointer_comp = 1;
    3736              : 
    3737              :   /* Looking for coarray components.  */
    3738        23052 :   if (c->attr.codimension
    3739        22961 :       || (c->ts.type == BT_CLASS && c->attr.class_ok
    3740          980 :           && CLASS_DATA (c)->attr.codimension))
    3741              :     {
    3742          113 :       coarray = true;
    3743          113 :       sym->attr.coarray_comp = 1;
    3744              :     }
    3745              : 
    3746        23052 :   if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.coarray_comp
    3747           12 :       && !c->attr.pointer)
    3748              :     {
    3749           11 :       coarray = true;
    3750           11 :       sym->attr.coarray_comp = 1;
    3751              :     }
    3752              : 
    3753              :   /* Looking for lock_type components.  */
    3754        23052 :   if ((c->ts.type == BT_DERIVED
    3755         4794 :           && c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
    3756           19 :           && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE)
    3757        23033 :       || (c->ts.type == BT_CLASS && c->attr.class_ok
    3758          980 :           && CLASS_DATA (c)->ts.u.derived->from_intmod
    3759              :              == INTMOD_ISO_FORTRAN_ENV
    3760            0 :           && CLASS_DATA (c)->ts.u.derived->intmod_sym_id
    3761              :              == ISOFORTRAN_LOCK_TYPE)
    3762        23033 :       || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.lock_comp
    3763            6 :           && !allocatable && !pointer))
    3764              :     {
    3765           22 :       lock_type = 1;
    3766           22 :       lock_comp = c;
    3767           22 :       sym->attr.lock_comp = 1;
    3768              :     }
    3769              : 
    3770              :     /* Looking for event_type components.  */
    3771        23052 :     if ((c->ts.type == BT_DERIVED
    3772         4794 :             && c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
    3773           19 :             && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE)
    3774        23052 :         || (c->ts.type == BT_CLASS && c->attr.class_ok
    3775          980 :             && CLASS_DATA (c)->ts.u.derived->from_intmod
    3776              :                == INTMOD_ISO_FORTRAN_ENV
    3777            0 :             && CLASS_DATA (c)->ts.u.derived->intmod_sym_id
    3778              :                == ISOFORTRAN_EVENT_TYPE)
    3779        23052 :         || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.event_comp
    3780            0 :             && !allocatable && !pointer))
    3781              :       {
    3782            0 :         event_type = 1;
    3783            0 :         event_comp = c;
    3784            0 :         sym->attr.event_comp = 1;
    3785              :       }
    3786              : 
    3787              :   /* Check for F2008, C1302 - and recall that pointers may not be coarrays
    3788              :      (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
    3789              :      unless there are nondirect [allocatable or pointer] components
    3790              :      involved (cf. 1.3.33.1 and 1.3.33.3).  */
    3791              : 
    3792        23052 :   if (pointer && !coarray && lock_type)
    3793            1 :     gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
    3794              :                "codimension or be a subcomponent of a coarray, "
    3795              :                "which is not possible as the component has the "
    3796              :                "pointer attribute", c->name, &c->loc);
    3797        23051 :   else if (pointer && !coarray && c->ts.type == BT_DERIVED
    3798          723 :            && c->ts.u.derived->attr.lock_comp)
    3799            2 :     gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
    3800              :                "of type LOCK_TYPE, which must have a codimension or be a "
    3801              :                "subcomponent of a coarray", c->name, &c->loc);
    3802              : 
    3803        23052 :   if (lock_type && allocatable && !coarray && c->ts.type == BT_DERIVED
    3804            3 :       && c->ts.u.derived->attr.lock_comp)
    3805            0 :     gfc_error ("Allocatable component %s at %L must have a codimension as "
    3806              :                "it has a noncoarray subcomponent of type LOCK_TYPE",
    3807              :                c->name, &c->loc);
    3808              : 
    3809        23052 :   if (sym->attr.coarray_comp && !coarray && lock_type)
    3810            1 :     gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
    3811              :                "subcomponent of type LOCK_TYPE must have a codimension or "
    3812              :                "be a subcomponent of a coarray. (Variables of type %s may "
    3813              :                "not have a codimension as already a coarray "
    3814              :                "subcomponent exists)", c->name, &c->loc, sym->name);
    3815              : 
    3816        23052 :   if (sym->attr.lock_comp && coarray && !lock_type)
    3817            1 :     gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
    3818              :                "subcomponent of type LOCK_TYPE must have a codimension or "
    3819              :                "be a subcomponent of a coarray. (Variables of type %s may "
    3820              :                "not have a codimension as %s at %L has a codimension or a "
    3821              :                "coarray subcomponent)", lock_comp->name, &lock_comp->loc,
    3822              :                sym->name, c->name, &c->loc);
    3823              : 
    3824              :   /* Similarly for EVENT TYPE.  */
    3825              : 
    3826        23052 :   if (pointer && !coarray && event_type)
    3827            0 :     gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
    3828              :                "codimension or be a subcomponent of a coarray, "
    3829              :                "which is not possible as the component has the "
    3830              :                "pointer attribute", c->name, &c->loc);
    3831        23052 :   else if (pointer && !coarray && c->ts.type == BT_DERIVED
    3832          724 :            && c->ts.u.derived->attr.event_comp)
    3833            0 :     gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
    3834              :                "of type EVENT_TYPE, which must have a codimension or be a "
    3835              :                "subcomponent of a coarray", c->name, &c->loc);
    3836              : 
    3837        23052 :   if (event_type && allocatable && !coarray)
    3838            0 :     gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
    3839              :                "a codimension", c->name, &c->loc);
    3840        23052 :   else if (event_type && allocatable && c->ts.type == BT_DERIVED
    3841            0 :            && c->ts.u.derived->attr.event_comp)
    3842            0 :     gfc_error ("Allocatable component %s at %L must have a codimension as "
    3843              :                "it has a noncoarray subcomponent of type EVENT_TYPE",
    3844              :                c->name, &c->loc);
    3845              : 
    3846        23052 :   if (sym->attr.coarray_comp && !coarray && event_type)
    3847            0 :     gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
    3848              :                "subcomponent of type EVENT_TYPE must have a codimension or "
    3849              :                "be a subcomponent of a coarray. (Variables of type %s may "
    3850              :                "not have a codimension as already a coarray "
    3851              :                "subcomponent exists)", c->name, &c->loc, sym->name);
    3852              : 
    3853        23052 :   if (sym->attr.event_comp && coarray && !event_type)
    3854            0 :     gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
    3855              :                "subcomponent of type EVENT_TYPE must have a codimension or "
    3856              :                "be a subcomponent of a coarray. (Variables of type %s may "
    3857              :                "not have a codimension as %s at %L has a codimension or a "
    3858              :                "coarray subcomponent)", event_comp->name, &event_comp->loc,
    3859              :                sym->name, c->name, &c->loc);
    3860              : 
    3861              :   /* Look for private components.  */
    3862        23052 :   if (sym->component_access == ACCESS_PRIVATE
    3863        22575 :       || c->attr.access == ACCESS_PRIVATE
    3864        22434 :       || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.private_comp))
    3865          911 :     sym->attr.private_comp = 1;
    3866              : 
    3867        23052 :   if (lockp) *lockp = lock_comp;
    3868        23052 :   if (eventp) *eventp = event_comp;
    3869        23052 : }
    3870              : 
    3871              : 
    3872              : static void parse_struct_map (gfc_statement);
    3873              : 
    3874              : /* Parse a union component definition within a structure definition.  */
    3875              : 
    3876              : static void
    3877          132 : parse_union (void)
    3878              : {
    3879          132 :   int compiling;
    3880          132 :   gfc_statement st;
    3881          132 :   gfc_state_data s;
    3882          132 :   gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
    3883          132 :   gfc_symbol *un;
    3884              : 
    3885          132 :   accept_statement(ST_UNION);
    3886          132 :   push_state (&s, COMP_UNION, gfc_new_block);
    3887          132 :   un = gfc_new_block;
    3888              : 
    3889          132 :   compiling = 1;
    3890              : 
    3891          132 :   while (compiling)
    3892              :     {
    3893          391 :       st = next_statement ();
    3894              :       /* Only MAP declarations valid within a union. */
    3895          391 :       switch (st)
    3896              :         {
    3897            0 :         case ST_NONE:
    3898            0 :           unexpected_eof ();
    3899              : 
    3900          257 :         case ST_MAP:
    3901          257 :           accept_statement (ST_MAP);
    3902          257 :           parse_struct_map (ST_MAP);
    3903              :           /* Add a component to the union for each map. */
    3904          257 :           if (!gfc_add_component (un, gfc_new_block->name, &c))
    3905              :             {
    3906            0 :               gfc_internal_error ("failed to create map component '%s'",
    3907              :                   gfc_new_block->name);
    3908              :               reject_statement ();
    3909              :               return;
    3910              :             }
    3911          257 :           c->ts.type = BT_DERIVED;
    3912          257 :           c->ts.u.derived = gfc_new_block;
    3913              :           /* Normally components get their initialization expressions when they
    3914              :              are created in decl.cc (build_struct) so we can look through the
    3915              :              flat component list for initializers during resolution. Unions and
    3916              :              maps create components along with their type definitions so we
    3917              :              have to generate initializers here. */
    3918          257 :           c->initializer = gfc_default_initializer (&c->ts);
    3919          257 :           break;
    3920              : 
    3921          132 :         case ST_END_UNION:
    3922          132 :           compiling = 0;
    3923          132 :           accept_statement (ST_END_UNION);
    3924          132 :           break;
    3925              : 
    3926            2 :         default:
    3927            2 :           unexpected_statement (st);
    3928            2 :           break;
    3929              :         }
    3930              :     }
    3931              : 
    3932          389 :   for (c = un->components; c; c = c->next)
    3933          257 :     check_component (un, c, &lock_comp, &event_comp);
    3934              : 
    3935              :   /* Add the union as a component in its parent structure.  */
    3936          132 :   pop_state ();
    3937          132 :   if (!gfc_add_component (gfc_current_block (), un->name, &c))
    3938              :     {
    3939            0 :       gfc_internal_error ("failed to create union component '%s'", un->name);
    3940              :       reject_statement ();
    3941              :       return;
    3942              :     }
    3943          132 :   c->ts.type = BT_UNION;
    3944          132 :   c->ts.u.derived = un;
    3945          132 :   c->initializer = gfc_default_initializer (&c->ts);
    3946              : 
    3947          132 :   un->attr.zero_comp = un->components == NULL;
    3948              : }
    3949              : 
    3950              : 
    3951              : /* Parse a STRUCTURE or MAP.  */
    3952              : 
    3953              : static void
    3954          570 : parse_struct_map (gfc_statement block)
    3955              : {
    3956          570 :   int compiling_type;
    3957          570 :   gfc_statement st;
    3958          570 :   gfc_state_data s;
    3959          570 :   gfc_symbol *sym;
    3960          570 :   gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
    3961          570 :   gfc_compile_state comp;
    3962          570 :   gfc_statement ends;
    3963              : 
    3964          570 :   if (block == ST_STRUCTURE_DECL)
    3965              :     {
    3966              :       comp = COMP_STRUCTURE;
    3967              :       ends = ST_END_STRUCTURE;
    3968              :     }
    3969              :   else
    3970              :     {
    3971          257 :       gcc_assert (block == ST_MAP);
    3972              :       comp = COMP_MAP;
    3973              :       ends = ST_END_MAP;
    3974              :     }
    3975              : 
    3976          570 :   accept_statement(block);
    3977          570 :   push_state (&s, comp, gfc_new_block);
    3978              : 
    3979          570 :   gfc_new_block->component_access = ACCESS_PUBLIC;
    3980          570 :   compiling_type = 1;
    3981              : 
    3982          570 :   while (compiling_type)
    3983              :     {
    3984         1554 :       st = next_statement ();
    3985         1554 :       switch (st)
    3986              :         {
    3987            0 :         case ST_NONE:
    3988            0 :           unexpected_eof ();
    3989              : 
    3990              :         /* Nested structure declarations will be captured as ST_DATA_DECL.  */
    3991            5 :         case ST_STRUCTURE_DECL:
    3992              :           /* Let a more specific error make it to decode_statement().  */
    3993            5 :           if (gfc_error_check () == 0)
    3994            0 :             gfc_error ("Syntax error in nested structure declaration at %C");
    3995            5 :           reject_statement ();
    3996              :           /* Skip the rest of this statement.  */
    3997            5 :           gfc_error_recovery ();
    3998            5 :           break;
    3999              : 
    4000          132 :         case ST_UNION:
    4001          132 :           accept_statement (ST_UNION);
    4002          132 :           parse_union ();
    4003          132 :           break;
    4004              : 
    4005          846 :         case ST_DATA_DECL:
    4006              :           /* The data declaration was a nested/ad-hoc STRUCTURE field.  */
    4007          846 :           accept_statement (ST_DATA_DECL);
    4008          846 :           if (gfc_new_block && gfc_new_block != gfc_current_block ()
    4009           21 :                             && gfc_new_block->attr.flavor == FL_STRUCT)
    4010           21 :               parse_struct_map (ST_STRUCTURE_DECL);
    4011              :           break;
    4012              : 
    4013          570 :         case ST_END_STRUCTURE:
    4014          570 :         case ST_END_MAP:
    4015          570 :           if (st == ends)
    4016              :             {
    4017          570 :               accept_statement (st);
    4018          570 :               compiling_type = 0;
    4019              :             }
    4020              :           else
    4021            0 :             unexpected_statement (st);
    4022              :           break;
    4023              : 
    4024            1 :         default:
    4025            1 :           unexpected_statement (st);
    4026            1 :           break;
    4027              :         }
    4028              :     }
    4029              : 
    4030              :   /* Validate each component.  */
    4031          570 :   sym = gfc_current_block ();
    4032         1719 :   for (c = sym->components; c; c = c->next)
    4033         1149 :     check_component (sym, c, &lock_comp, &event_comp);
    4034              : 
    4035          570 :   sym->attr.zero_comp = (sym->components == NULL);
    4036              : 
    4037              :   /* Allow parse_union to find this structure to add to its list of maps.  */
    4038          570 :   if (block == ST_MAP)
    4039          257 :     gfc_new_block = gfc_current_block ();
    4040              : 
    4041          570 :   pop_state ();
    4042          570 : }
    4043              : 
    4044              : 
    4045              : /* Parse a derived type.  */
    4046              : 
    4047              : static void
    4048        14304 : parse_derived (void)
    4049              : {
    4050        14304 :   int compiling_type, seen_private, seen_sequence, seen_component;
    4051        14304 :   gfc_statement st;
    4052        14304 :   gfc_state_data s;
    4053        14304 :   gfc_symbol *sym;
    4054        14304 :   gfc_component *c, *lock_comp = NULL, *event_comp = NULL;
    4055        14304 :   bool pdt_parameters;
    4056              : 
    4057        14304 :   accept_statement (ST_DERIVED_DECL);
    4058        14304 :   push_state (&s, COMP_DERIVED, gfc_new_block);
    4059              : 
    4060        14304 :   gfc_new_block->component_access = ACCESS_PUBLIC;
    4061        14304 :   seen_private = 0;
    4062        14304 :   seen_sequence = 0;
    4063        14304 :   seen_component = 0;
    4064        14304 :   pdt_parameters = false;
    4065              : 
    4066        14304 :   compiling_type = 1;
    4067              : 
    4068              : 
    4069        14304 :   while (compiling_type)
    4070              :     {
    4071        33532 :       st = next_statement ();
    4072        33532 :       switch (st)
    4073              :         {
    4074            0 :         case ST_NONE:
    4075            0 :           unexpected_eof ();
    4076              : 
    4077        18654 :         case ST_DATA_DECL:
    4078        18654 :         case ST_PROCEDURE:
    4079        18654 :           accept_statement (st);
    4080        18654 :           seen_component = 1;
    4081              :           /* Type parameters must not have an explicit access specification
    4082              :              and must be placed before a PRIVATE statement. If a PRIVATE
    4083              :              statement is encountered after type parameters, mark the remaining
    4084              :              components as PRIVATE. */
    4085        52343 :           for (c = gfc_current_block ()->components; c; c = c->next)
    4086        33691 :             if (!c->next && (c->attr.pdt_kind || c->attr.pdt_len))
    4087              :               {
    4088          962 :                 pdt_parameters = true;
    4089          962 :                 if (c->attr.access != ACCESS_UNKNOWN)
    4090              :                   {
    4091            1 :                     gfc_error ("Access specification of a type parameter at "
    4092              :                                "%C is not allowed");
    4093            1 :                     c->attr.access = ACCESS_PUBLIC;
    4094            1 :                     break;
    4095              :                   }
    4096          961 :                 if (seen_private)
    4097              :                   {
    4098            1 :                     gfc_error ("The type parameter at %C must come before a "
    4099              :                                "PRIVATE statement");
    4100            1 :                     break;
    4101              :                   }
    4102              :               }
    4103        32729 :             else if (pdt_parameters && seen_private
    4104           28 :                      && !(c->attr.pdt_kind || c->attr.pdt_len))
    4105            8 :               c->attr.access = ACCESS_PRIVATE;
    4106              :           break;
    4107              : 
    4108            0 :         case ST_FINAL:
    4109            0 :           gfc_error ("FINAL declaration at %C must be inside CONTAINS");
    4110            0 :           break;
    4111              : 
    4112        14304 :         case ST_END_TYPE:
    4113        14304 : endType:
    4114        14304 :           compiling_type = 0;
    4115              : 
    4116        14304 :           if (!seen_component)
    4117         1640 :             gfc_notify_std (GFC_STD_F2003, "Derived type "
    4118              :                             "definition at %C without components");
    4119              : 
    4120        14304 :           accept_statement (ST_END_TYPE);
    4121        14304 :           break;
    4122              : 
    4123          333 :         case ST_PRIVATE:
    4124          333 :           if (!gfc_find_state (COMP_MODULE))
    4125              :             {
    4126            0 :               gfc_error ("PRIVATE statement in TYPE at %C must be inside "
    4127              :                          "a MODULE");
    4128            0 :               break;
    4129              :             }
    4130              : 
    4131          333 :           if (seen_component && !pdt_parameters)
    4132              :             {
    4133            0 :               gfc_error ("PRIVATE statement at %C must precede "
    4134              :                          "structure components");
    4135            0 :               break;
    4136              :             }
    4137              : 
    4138          333 :           if (seen_private)
    4139            0 :             gfc_error ("Duplicate PRIVATE statement at %C");
    4140              : 
    4141          333 :           if (pdt_parameters)
    4142            7 :             s.sym->component_access = ACCESS_PUBLIC;
    4143              :           else
    4144          326 :             s.sym->component_access = ACCESS_PRIVATE;
    4145              : 
    4146          333 :           accept_statement (ST_PRIVATE);
    4147          333 :           seen_private = 1;
    4148          333 :           break;
    4149              : 
    4150          239 :         case ST_SEQUENCE:
    4151          239 :           if (seen_component)
    4152              :             {
    4153            0 :               gfc_error ("SEQUENCE statement at %C must precede "
    4154              :                          "structure components");
    4155            0 :               break;
    4156              :             }
    4157              : 
    4158          239 :           if (gfc_current_block ()->attr.sequence)
    4159            0 :             gfc_warning (0, "SEQUENCE attribute at %C already specified in "
    4160              :                          "TYPE statement");
    4161              : 
    4162          239 :           if (seen_sequence)
    4163              :             {
    4164            0 :               gfc_error ("Duplicate SEQUENCE statement at %C");
    4165              :             }
    4166              : 
    4167          239 :           seen_sequence = 1;
    4168          239 :           gfc_add_sequence (&gfc_current_block ()->attr,
    4169          239 :                             gfc_current_block ()->name, NULL);
    4170          239 :           break;
    4171              : 
    4172         2401 :         case ST_CONTAINS:
    4173         2401 :           gfc_notify_std (GFC_STD_F2003,
    4174              :                           "CONTAINS block in derived type"
    4175              :                           " definition at %C");
    4176              : 
    4177         2401 :           accept_statement (ST_CONTAINS);
    4178         2401 :           parse_derived_contains ();
    4179         2401 :           goto endType;
    4180              : 
    4181            2 :         default:
    4182            2 :           unexpected_statement (st);
    4183            2 :           break;
    4184              :         }
    4185              :     }
    4186              : 
    4187              :   /* need to verify that all fields of the derived type are
    4188              :    * interoperable with C if the type is declared to be bind(c)
    4189              :    */
    4190        14304 :   sym = gfc_current_block ();
    4191        35950 :   for (c = sym->components; c; c = c->next)
    4192        21646 :     check_component (sym, c, &lock_comp, &event_comp);
    4193              : 
    4194        14304 :   if (!seen_component)
    4195         1640 :     sym->attr.zero_comp = 1;
    4196              : 
    4197        14304 :   pop_state ();
    4198        14304 : }
    4199              : 
    4200              : 
    4201              : /* Parse an ENUM.  */
    4202              : 
    4203              : static void
    4204          156 : parse_enum (void)
    4205              : {
    4206          156 :   gfc_statement st;
    4207          156 :   int compiling_enum;
    4208          156 :   gfc_state_data s;
    4209          156 :   int seen_enumerator = 0;
    4210              : 
    4211          156 :   push_state (&s, COMP_ENUM, gfc_new_block);
    4212              : 
    4213          156 :   compiling_enum = 1;
    4214              : 
    4215          156 :   while (compiling_enum)
    4216              :     {
    4217          416 :       st = next_statement ();
    4218          416 :       switch (st)
    4219              :         {
    4220            2 :         case ST_NONE:
    4221            2 :           unexpected_eof ();
    4222          256 :           break;
    4223              : 
    4224          256 :         case ST_ENUMERATOR:
    4225          256 :           seen_enumerator = 1;
    4226          256 :           accept_statement (st);
    4227          256 :           break;
    4228              : 
    4229          154 :         case ST_END_ENUM:
    4230          154 :           compiling_enum = 0;
    4231          154 :           if (!seen_enumerator)
    4232            3 :             gfc_error ("ENUM declaration at %C has no ENUMERATORS");
    4233          154 :           accept_statement (st);
    4234          154 :           break;
    4235              : 
    4236            4 :         default:
    4237            4 :           gfc_free_enum_history ();
    4238            4 :           unexpected_statement (st);
    4239            4 :           break;
    4240              :         }
    4241              :     }
    4242          154 :   pop_state ();
    4243          154 : }
    4244              : 
    4245              : 
    4246              : /* Parse an interface.  We must be able to deal with the possibility
    4247              :    of recursive interfaces.  The parse_spec() subroutine is mutually
    4248              :    recursive with parse_interface().  */
    4249              : 
    4250              : static gfc_statement parse_spec (gfc_statement);
    4251              : 
    4252              : static void
    4253        11683 : parse_interface (void)
    4254              : {
    4255        11683 :   gfc_compile_state new_state = COMP_NONE, current_state;
    4256        11683 :   gfc_symbol *prog_unit, *sym;
    4257        11683 :   gfc_interface_info save;
    4258        11683 :   gfc_state_data s1, s2;
    4259        11683 :   gfc_statement st;
    4260              : 
    4261        11683 :   accept_statement (ST_INTERFACE);
    4262              : 
    4263        11683 :   current_interface.ns = gfc_current_ns;
    4264        11683 :   save = current_interface;
    4265              : 
    4266         4446 :   sym = (current_interface.type == INTERFACE_GENERIC
    4267         7393 :          || current_interface.type == INTERFACE_USER_OP)
    4268        11683 :         ? gfc_new_block : NULL;
    4269              : 
    4270        11683 :   push_state (&s1, COMP_INTERFACE, sym);
    4271        11683 :   current_state = COMP_NONE;
    4272              : 
    4273        18427 : loop:
    4274        30110 :   gfc_current_ns = gfc_get_namespace (current_interface.ns, 0);
    4275              : 
    4276        30110 :   st = next_statement ();
    4277        30110 :   switch (st)
    4278              :     {
    4279            2 :     case ST_NONE:
    4280            2 :       unexpected_eof ();
    4281              : 
    4282        15262 :     case ST_SUBROUTINE:
    4283        15262 :     case ST_FUNCTION:
    4284        15262 :       if (st == ST_SUBROUTINE)
    4285              :         new_state = COMP_SUBROUTINE;
    4286         6835 :       else if (st == ST_FUNCTION)
    4287         6835 :         new_state = COMP_FUNCTION;
    4288        15262 :       if (gfc_new_block->attr.pointer)
    4289              :         {
    4290           31 :           gfc_new_block->attr.pointer = 0;
    4291           31 :           gfc_new_block->attr.proc_pointer = 1;
    4292              :         }
    4293        15262 :       if (!gfc_add_explicit_interface (gfc_new_block, IFSRC_IFBODY,
    4294              :                                        gfc_new_block->formal, NULL))
    4295              :         {
    4296            2 :           reject_statement ();
    4297            2 :           gfc_free_namespace (gfc_current_ns);
    4298            2 :           goto loop;
    4299              :         }
    4300              :       /* F2008 C1210 forbids the IMPORT statement in module procedure
    4301              :          interface bodies and the flag is set to import symbols.  */
    4302        15260 :       if (gfc_new_block->attr.module_procedure)
    4303          557 :         gfc_current_ns->has_import_set = 1;
    4304        15260 :       break;
    4305              : 
    4306         3162 :     case ST_PROCEDURE:
    4307         3162 :     case ST_MODULE_PROC:        /* The module procedure matcher makes
    4308              :                                    sure the context is correct.  */
    4309         3162 :       accept_statement (st);
    4310         3162 :       gfc_free_namespace (gfc_current_ns);
    4311         3162 :       goto loop;
    4312              : 
    4313        11680 :     case ST_END_INTERFACE:
    4314        11680 :       gfc_free_namespace (gfc_current_ns);
    4315        11680 :       gfc_current_ns = current_interface.ns;
    4316        11680 :       goto done;
    4317              : 
    4318            4 :     default:
    4319            4 :       gfc_error ("Unexpected %s statement in INTERFACE block at %C",
    4320              :                  gfc_ascii_statement (st));
    4321            4 :       current_interface = save;
    4322            4 :       reject_statement ();
    4323            4 :       gfc_free_namespace (gfc_current_ns);
    4324            4 :       goto loop;
    4325              :     }
    4326              : 
    4327              : 
    4328              :   /* Make sure that the generic name has the right attribute.  */
    4329        15260 :   if (current_interface.type == INTERFACE_GENERIC
    4330         5563 :       && current_state == COMP_NONE)
    4331              :     {
    4332         2855 :       if (new_state == COMP_FUNCTION && sym)
    4333          950 :         gfc_add_function (&sym->attr, sym->name, NULL);
    4334         1905 :       else if (new_state == COMP_SUBROUTINE && sym)
    4335         1905 :         gfc_add_subroutine (&sym->attr, sym->name, NULL);
    4336              : 
    4337              :       current_state = new_state;
    4338              :     }
    4339              : 
    4340        15260 :   if (current_interface.type == INTERFACE_ABSTRACT)
    4341              :     {
    4342          524 :       gfc_add_abstract (&gfc_new_block->attr, &gfc_current_locus);
    4343          524 :       if (gfc_is_intrinsic_typename (gfc_new_block->name))
    4344            1 :         gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
    4345              :                    "cannot be the same as an intrinsic type",
    4346              :                    gfc_new_block->name);
    4347              :     }
    4348              : 
    4349        15260 :   push_state (&s2, new_state, gfc_new_block);
    4350        15260 :   accept_statement (st);
    4351        15260 :   prog_unit = gfc_new_block;
    4352        15260 :   prog_unit->formal_ns = gfc_current_ns;
    4353              : 
    4354        15261 : decl:
    4355              :   /* Read data declaration statements.  */
    4356        15261 :   st = parse_spec (ST_NONE);
    4357        15260 :   in_specification_block = true;
    4358              : 
    4359              :   /* Since the interface block does not permit an IMPLICIT statement,
    4360              :      the default type for the function or the result must be taken
    4361              :      from the formal namespace.  */
    4362        15260 :   if (new_state == COMP_FUNCTION)
    4363              :     {
    4364         6833 :         if (prog_unit->result == prog_unit
    4365         6196 :               && prog_unit->ts.type == BT_UNKNOWN)
    4366           44 :           gfc_set_default_type (prog_unit, 1, prog_unit->formal_ns);
    4367         6789 :         else if (prog_unit->result != prog_unit
    4368          637 :                    && prog_unit->result->ts.type == BT_UNKNOWN)
    4369           11 :           gfc_set_default_type (prog_unit->result, 1,
    4370           11 :                                 prog_unit->formal_ns);
    4371              :     }
    4372              : 
    4373        15260 :   if (st != ST_END_SUBROUTINE && st != ST_END_FUNCTION)
    4374              :     {
    4375            1 :       gfc_error ("Unexpected %s statement at %C in INTERFACE body",
    4376              :                  gfc_ascii_statement (st));
    4377            1 :       reject_statement ();
    4378            1 :       goto decl;
    4379              :     }
    4380              : 
    4381              :   /* Add EXTERNAL attribute to function or subroutine.  */
    4382        15259 :   if (current_interface.type != INTERFACE_ABSTRACT && !prog_unit->attr.dummy)
    4383        14504 :     gfc_add_external (&prog_unit->attr, &gfc_current_locus);
    4384              : 
    4385        15259 :   current_interface = save;
    4386        15259 :   gfc_add_interface (prog_unit);
    4387        15259 :   pop_state ();
    4388              : 
    4389        15259 :   if (current_interface.ns
    4390        15259 :         && current_interface.ns->proc_name
    4391        15259 :         && strcmp (current_interface.ns->proc_name->name,
    4392              :                    prog_unit->name) == 0)
    4393            1 :     gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
    4394              :                "enclosing procedure", prog_unit->name,
    4395              :                &current_interface.ns->proc_name->declared_at);
    4396              : 
    4397        15259 :   goto loop;
    4398              : 
    4399        11680 : done:
    4400        11680 :   pop_state ();
    4401        11680 : }
    4402              : 
    4403              : 
    4404              : /* Associate function characteristics by going back to the function
    4405              :    declaration and rematching the prefix.  */
    4406              : 
    4407              : static match
    4408         7219 : match_deferred_characteristics (gfc_typespec * ts)
    4409              : {
    4410         7219 :   locus loc;
    4411         7219 :   match m = MATCH_ERROR;
    4412         7219 :   char name[GFC_MAX_SYMBOL_LEN + 1];
    4413              : 
    4414         7219 :   loc = gfc_current_locus;
    4415              : 
    4416         7219 :   gfc_current_locus = gfc_current_block ()->declared_at;
    4417              : 
    4418         7219 :   gfc_clear_error ();
    4419         7219 :   gfc_buffer_error (true);
    4420         7219 :   m = gfc_match_prefix (ts);
    4421         7219 :   gfc_buffer_error (false);
    4422              : 
    4423         7219 :   if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
    4424              :     {
    4425         1060 :       ts->kind = 0;
    4426              : 
    4427         1060 :       if (!ts->u.derived)
    4428         7219 :         m = MATCH_ERROR;
    4429              :     }
    4430              : 
    4431              :   /* Only permit one go at the characteristic association.  */
    4432         7219 :   if (ts->kind == -1)
    4433            3 :     ts->kind = 0;
    4434              : 
    4435              :   /* Set the function locus correctly.  If we have not found the
    4436              :      function name, there is an error.  */
    4437         7219 :   if (m == MATCH_YES
    4438         7204 :       && gfc_match ("function% %n", name) == MATCH_YES
    4439        14421 :       && strcmp (name, gfc_current_block ()->name) == 0)
    4440              :     {
    4441         7189 :       gfc_current_block ()->declared_at = gfc_current_locus;
    4442         7189 :       gfc_commit_symbols ();
    4443              :     }
    4444              :   else
    4445              :     {
    4446           30 :       gfc_error_check ();
    4447           30 :       gfc_undo_symbols ();
    4448              :     }
    4449              : 
    4450         7219 :   gfc_current_locus =loc;
    4451         7219 :   return m;
    4452              : }
    4453              : 
    4454              : 
    4455              : /* Check specification-expressions in the function result of the currently
    4456              :    parsed block and ensure they are typed (give an IMPLICIT type if necessary).
    4457              :    For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
    4458              :    scope are not yet parsed so this has to be delayed up to parse_spec.  */
    4459              : 
    4460              : static bool
    4461        11906 : check_function_result_typed (void)
    4462              : {
    4463        11906 :   gfc_typespec ts;
    4464              : 
    4465        11906 :   gcc_assert (gfc_current_state () == COMP_FUNCTION);
    4466              : 
    4467        11906 :   if (!gfc_current_ns->proc_name->result)
    4468              :     return true;
    4469              : 
    4470        11906 :   ts = gfc_current_ns->proc_name->result->ts;
    4471              : 
    4472              :   /* Check type-parameters, at the moment only CHARACTER lengths possible.  */
    4473              :   /* TODO:  Extend when KIND type parameters are implemented.  */
    4474        11906 :   if (ts.type == BT_CHARACTER && ts.u.cl && ts.u.cl->length)
    4475              :     {
    4476              :       /* Reject invalid type of specification expression for length.  */
    4477          605 :       if (ts.u.cl->length->ts.type != BT_INTEGER)
    4478              :           return false;
    4479              : 
    4480          426 :       gfc_expr_check_typed (ts.u.cl->length, gfc_current_ns, true);
    4481              :     }
    4482              : 
    4483              :   return true;
    4484              : }
    4485              : 
    4486              : 
    4487              : /* Parse a set of specification statements.  Returns the statement
    4488              :    that doesn't fit.  */
    4489              : 
    4490              : static gfc_statement
    4491       107466 : parse_spec (gfc_statement st)
    4492              : {
    4493       107466 :   st_state ss;
    4494       107466 :   bool function_result_typed = false;
    4495       107466 :   bool bad_characteristic = false;
    4496       107466 :   gfc_typespec *ts;
    4497              : 
    4498       107466 :   in_specification_block = true;
    4499              : 
    4500       107466 :   verify_st_order (&ss, ST_NONE, false);
    4501       107466 :   if (st == ST_NONE)
    4502        98323 :     st = next_statement ();
    4503              : 
    4504              :   /* If we are not inside a function or don't have a result specified so far,
    4505              :      do nothing special about it.  */
    4506       107465 :   if (gfc_current_state () != COMP_FUNCTION)
    4507       107465 :     function_result_typed = true;
    4508              :   else
    4509              :     {
    4510        21020 :       gfc_symbol* proc = gfc_current_ns->proc_name;
    4511        21020 :       gcc_assert (proc);
    4512              : 
    4513        21020 :       if (proc->result && proc->result->ts.type == BT_UNKNOWN)
    4514        95679 :         function_result_typed = true;
    4515              :     }
    4516              : 
    4517       107465 : loop:
    4518              : 
    4519              :   /* If we're inside a BLOCK construct, some statements are disallowed.
    4520              :      Check this here.  Attribute declaration statements like INTENT, OPTIONAL
    4521              :      or VALUE are also disallowed, but they don't have a particular ST_*
    4522              :      key so we have to check for them individually in their matcher routine.  */
    4523       434301 :   if (gfc_current_state () == COMP_BLOCK)
    4524         2523 :     switch (st)
    4525              :       {
    4526            5 :         case ST_IMPLICIT:
    4527            5 :         case ST_IMPLICIT_NONE:
    4528            5 :         case ST_NAMELIST:
    4529            5 :         case ST_COMMON:
    4530            5 :         case ST_EQUIVALENCE:
    4531            5 :         case ST_STATEMENT_FUNCTION:
    4532            5 :           gfc_error ("%s statement is not allowed inside of BLOCK at %C",
    4533              :                      gfc_ascii_statement (st));
    4534            5 :           reject_statement ();
    4535            5 :           break;
    4536              : 
    4537              :         default:
    4538              :           break;
    4539              :       }
    4540       431778 :   else if (gfc_current_state () == COMP_BLOCK_DATA)
    4541              :     /* Fortran 2008, C1116.  */
    4542          467 :     switch (st)
    4543              :       {
    4544              :         case ST_ATTR_DECL:
    4545              :         case ST_COMMON:
    4546              :         case ST_DATA:
    4547              :         case ST_DATA_DECL:
    4548              :         case ST_DERIVED_DECL:
    4549              :         case ST_END_BLOCK_DATA:
    4550              :         case ST_EQUIVALENCE:
    4551              :         case ST_IMPLICIT:
    4552              :         case ST_IMPLICIT_NONE:
    4553              :         case ST_OMP_ALLOCATE:
    4554              :         case ST_OMP_GROUPPRIVATE:
    4555              :         case ST_OMP_THREADPRIVATE:
    4556              :         case ST_PARAMETER:
    4557              :         case ST_STRUCTURE_DECL:
    4558              :         case ST_TYPE:
    4559              :         case ST_USE:
    4560              :           break;
    4561              : 
    4562              :         case ST_NONE:
    4563              :           break;
    4564              : 
    4565            5 :         default:
    4566            5 :           gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
    4567              :                      gfc_ascii_statement (st));
    4568            5 :           reject_statement ();
    4569            5 :           break;
    4570              :       }
    4571              : 
    4572              :   /* If we find a statement that cannot be followed by an IMPLICIT statement
    4573              :      (and thus we can expect to see none any further), type the function result
    4574              :      if it has not yet been typed.  Be careful not to give the END statement
    4575              :      to verify_st_order!  */
    4576       434301 :   if (!function_result_typed && st != ST_GET_FCN_CHARACTERISTICS)
    4577              :     {
    4578        13887 :       bool verify_now = false;
    4579              : 
    4580        13887 :       if (st == ST_END_FUNCTION || st == ST_CONTAINS)
    4581              :         verify_now = true;
    4582              :       else
    4583              :         {
    4584        13585 :           st_state dummyss;
    4585        13585 :           verify_st_order (&dummyss, ST_NONE, false);
    4586        13585 :           verify_st_order (&dummyss, st, false);
    4587              : 
    4588        13585 :           if (!verify_st_order (&dummyss, ST_IMPLICIT, true))
    4589        10789 :             verify_now = true;
    4590              :         }
    4591              : 
    4592        13585 :       if (verify_now)
    4593        11091 :         function_result_typed = check_function_result_typed ();
    4594              :     }
    4595              : 
    4596       434301 :   switch (st)
    4597              :     {
    4598           12 :     case ST_NONE:
    4599           12 :       unexpected_eof ();
    4600              : 
    4601        25470 :     case ST_IMPLICIT_NONE:
    4602        25470 :     case ST_IMPLICIT:
    4603        25470 :       if (!function_result_typed)
    4604          815 :         function_result_typed = check_function_result_typed ();
    4605        25470 :       goto declSt;
    4606              : 
    4607         2854 :     case ST_FORMAT:
    4608         2854 :     case ST_ENTRY:
    4609         2854 :     case ST_DATA:       /* Not allowed in interfaces */
    4610         2854 :       if (gfc_current_state () == COMP_INTERFACE)
    4611              :         break;
    4612              : 
    4613              :       /* Fall through */
    4614              : 
    4615       319383 :     case ST_USE:
    4616       319383 :     case ST_IMPORT:
    4617       319383 :     case ST_PARAMETER:
    4618       319383 :     case ST_PUBLIC:
    4619       319383 :     case ST_PRIVATE:
    4620       319383 :     case ST_STRUCTURE_DECL:
    4621       319383 :     case ST_DERIVED_DECL:
    4622       319383 :     case_decl:
    4623       319383 :     case_omp_decl:
    4624         2854 : declSt:
    4625       319383 :       if (!verify_st_order (&ss, st, false))
    4626              :         {
    4627            1 :           reject_statement ();
    4628            1 :           st = next_statement ();
    4629            1 :           goto loop;
    4630              :         }
    4631              : 
    4632       319382 :       switch (st)
    4633              :         {
    4634        11683 :         case ST_INTERFACE:
    4635        11683 :           parse_interface ();
    4636        11683 :           break;
    4637              : 
    4638          292 :         case ST_STRUCTURE_DECL:
    4639          292 :           parse_struct_map (ST_STRUCTURE_DECL);
    4640          292 :           break;
    4641              : 
    4642        14304 :         case ST_DERIVED_DECL:
    4643        14304 :           parse_derived ();
    4644        14304 :           break;
    4645              : 
    4646         1030 :         case ST_PUBLIC:
    4647         1030 :         case ST_PRIVATE:
    4648         1030 :           if (gfc_current_state () != COMP_MODULE)
    4649              :             {
    4650            0 :               gfc_error ("%s statement must appear in a MODULE",
    4651              :                          gfc_ascii_statement (st));
    4652            0 :               reject_statement ();
    4653            0 :               break;
    4654              :             }
    4655              : 
    4656         1030 :           if (gfc_current_ns->default_access != ACCESS_UNKNOWN)
    4657              :             {
    4658            0 :               gfc_error ("%s statement at %C follows another accessibility "
    4659              :                          "specification", gfc_ascii_statement (st));
    4660            0 :               reject_statement ();
    4661            0 :               break;
    4662              :             }
    4663              : 
    4664         2060 :           gfc_current_ns->default_access = (st == ST_PUBLIC)
    4665         1030 :             ? ACCESS_PUBLIC : ACCESS_PRIVATE;
    4666              : 
    4667         1030 :           break;
    4668              : 
    4669          227 :         case ST_STATEMENT_FUNCTION:
    4670          227 :           if (gfc_current_state () == COMP_MODULE
    4671          227 :               || gfc_current_state () == COMP_SUBMODULE)
    4672              :             {
    4673            1 :               unexpected_statement (st);
    4674            1 :               break;
    4675              :             }
    4676              : 
    4677              :         default:
    4678              :           break;
    4679              :         }
    4680              : 
    4681       319379 :       accept_statement (st);
    4682       319379 :       st = next_statement ();
    4683       319375 :       goto loop;
    4684              : 
    4685           87 :     case ST_GENERIC:
    4686           87 :       accept_statement (st);
    4687           87 :       st = next_statement ();
    4688           87 :       goto loop;
    4689              : 
    4690          156 :     case ST_ENUM:
    4691          156 :       accept_statement (st);
    4692          156 :       parse_enum();
    4693          154 :       st = next_statement ();
    4694          154 :       goto loop;
    4695              : 
    4696         7219 :     case ST_GET_FCN_CHARACTERISTICS:
    4697              :       /* This statement triggers the association of a function's result
    4698              :          characteristics.  */
    4699         7219 :       ts = &gfc_current_block ()->result->ts;
    4700         7219 :       if (match_deferred_characteristics (ts) != MATCH_YES)
    4701           15 :         bad_characteristic = true;
    4702              : 
    4703         7219 :       st = next_statement ();
    4704         7219 :       goto loop;
    4705              : 
    4706              :     default:
    4707              :       break;
    4708              :     }
    4709              : 
    4710              :   /* If match_deferred_characteristics failed, then there is an error.  */
    4711       107444 :   if (bad_characteristic)
    4712              :     {
    4713           15 :       ts = &gfc_current_block ()->result->ts;
    4714           15 :       if (ts->type != BT_DERIVED && ts->type != BT_CLASS)
    4715            5 :         gfc_error ("Bad kind expression for function %qs at %L",
    4716              :                    gfc_current_block ()->name,
    4717              :                    &gfc_current_block ()->declared_at);
    4718              :       else
    4719           10 :         gfc_error ("The type for function %qs at %L is not accessible",
    4720              :                    gfc_current_block ()->name,
    4721              :                    &gfc_current_block ()->declared_at);
    4722              : 
    4723           15 :       gfc_current_block ()->ts.kind = 0;
    4724              :       /* Keep the derived type; if it's bad, it will be discovered later.  */
    4725           15 :       if (!(ts->type == BT_DERIVED && ts->u.derived))
    4726           15 :         ts->type = BT_UNKNOWN;
    4727              :     }
    4728              : 
    4729       107444 :   in_specification_block = false;
    4730              : 
    4731       107444 :   return st;
    4732              : }
    4733              : 
    4734              : 
    4735              : /* Parse a WHERE block, (not a simple WHERE statement).  */
    4736              : 
    4737              : static void
    4738          371 : parse_where_block (void)
    4739              : {
    4740          371 :   int seen_empty_else;
    4741          371 :   gfc_code *top, *d;
    4742          371 :   gfc_state_data s;
    4743          371 :   gfc_statement st;
    4744              : 
    4745          371 :   accept_statement (ST_WHERE_BLOCK);
    4746          371 :   top = gfc_state_stack->tail;
    4747              : 
    4748          371 :   push_state (&s, COMP_WHERE, gfc_new_block);
    4749              : 
    4750          371 :   d = add_statement ();
    4751          371 :   d->expr1 = top->expr1;
    4752          371 :   d->op = EXEC_WHERE;
    4753              : 
    4754          371 :   top->expr1 = NULL;
    4755          371 :   top->block = d;
    4756              : 
    4757          371 :   seen_empty_else = 0;
    4758              : 
    4759         1342 :   do
    4760              :     {
    4761         1342 :       st = next_statement ();
    4762         1342 :       switch (st)
    4763              :         {
    4764            0 :         case ST_NONE:
    4765            0 :           unexpected_eof ();
    4766              : 
    4767           40 :         case ST_WHERE_BLOCK:
    4768           40 :           parse_where_block ();
    4769           40 :           break;
    4770              : 
    4771          619 :         case ST_ASSIGNMENT:
    4772          619 :         case ST_WHERE:
    4773          619 :           accept_statement (st);
    4774          619 :           break;
    4775              : 
    4776          312 :         case ST_ELSEWHERE:
    4777          312 :           if (seen_empty_else)
    4778              :             {
    4779            1 :               gfc_error ("ELSEWHERE statement at %C follows previous "
    4780              :                          "unmasked ELSEWHERE");
    4781            1 :               reject_statement ();
    4782            1 :               break;
    4783              :             }
    4784              : 
    4785          311 :           if (new_st.expr1 == NULL)
    4786          133 :             seen_empty_else = 1;
    4787              : 
    4788          311 :           d = new_level (gfc_state_stack->head);
    4789          311 :           d->op = EXEC_WHERE;
    4790          311 :           d->expr1 = new_st.expr1;
    4791              : 
    4792          311 :           accept_statement (st);
    4793              : 
    4794          311 :           break;
    4795              : 
    4796          371 :         case ST_END_WHERE:
    4797          371 :           accept_statement (st);
    4798          371 :           break;
    4799              : 
    4800            0 :         default:
    4801            0 :           gfc_error ("Unexpected %s statement in WHERE block at %C",
    4802              :                      gfc_ascii_statement (st));
    4803            0 :           reject_statement ();
    4804            0 :           break;
    4805              :         }
    4806              :     }
    4807         1342 :   while (st != ST_END_WHERE);
    4808              : 
    4809          371 :   pop_state ();
    4810          371 : }
    4811              : 
    4812              : 
    4813              : /* Parse a FORALL block (not a simple FORALL statement).  */
    4814              : 
    4815              : static void
    4816          507 : parse_forall_block (void)
    4817              : {
    4818          507 :   gfc_code *top, *d;
    4819          507 :   gfc_state_data s;
    4820          507 :   gfc_statement st;
    4821              : 
    4822          507 :   accept_statement (ST_FORALL_BLOCK);
    4823          507 :   top = gfc_state_stack->tail;
    4824              : 
    4825          507 :   push_state (&s, COMP_FORALL, gfc_new_block);
    4826              : 
    4827          507 :   d = add_statement ();
    4828          507 :   d->op = EXEC_FORALL;
    4829          507 :   top->block = d;
    4830              : 
    4831         1026 :   do
    4832              :     {
    4833         1026 :       st = next_statement ();
    4834         1026 :       switch (st)
    4835              :         {
    4836              : 
    4837          395 :         case ST_ASSIGNMENT:
    4838          395 :         case ST_POINTER_ASSIGNMENT:
    4839          395 :         case ST_WHERE:
    4840          395 :         case ST_FORALL:
    4841          395 :           accept_statement (st);
    4842          395 :           break;
    4843              : 
    4844           46 :         case ST_WHERE_BLOCK:
    4845           46 :           parse_where_block ();
    4846           46 :           break;
    4847              : 
    4848           78 :         case ST_FORALL_BLOCK:
    4849           78 :           parse_forall_block ();
    4850           78 :           break;
    4851              : 
    4852          507 :         case ST_END_FORALL:
    4853          507 :           accept_statement (st);
    4854          507 :           break;
    4855              : 
    4856            0 :         case ST_NONE:
    4857            0 :           unexpected_eof ();
    4858              : 
    4859            0 :         default:
    4860            0 :           gfc_error ("Unexpected %s statement in FORALL block at %C",
    4861              :                      gfc_ascii_statement (st));
    4862              : 
    4863            0 :           reject_statement ();
    4864            0 :           break;
    4865              :         }
    4866              :     }
    4867         1026 :   while (st != ST_END_FORALL);
    4868              : 
    4869          507 :   pop_state ();
    4870          507 : }
    4871              : 
    4872              : 
    4873              : static gfc_statement parse_executable (gfc_statement);
    4874              : 
    4875              : /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block.  */
    4876              : 
    4877              : static void
    4878        15187 : parse_if_block (void)
    4879              : {
    4880        15187 :   gfc_code *top, *d;
    4881        15187 :   gfc_statement st;
    4882        15187 :   locus else_locus;
    4883        15187 :   gfc_state_data s;
    4884        15187 :   int seen_else;
    4885              : 
    4886        15187 :   seen_else = 0;
    4887        15187 :   accept_statement (ST_IF_BLOCK);
    4888              : 
    4889        15187 :   top = gfc_state_stack->tail;
    4890        15187 :   push_state (&s, COMP_IF, gfc_new_block);
    4891              : 
    4892        15187 :   new_st.op = EXEC_IF;
    4893        15187 :   d = add_statement ();
    4894              : 
    4895        15187 :   d->expr1 = top->expr1;
    4896        15187 :   top->expr1 = NULL;
    4897        15187 :   top->block = d;
    4898              : 
    4899        21309 :   do
    4900              :     {
    4901        21309 :       st = parse_executable (ST_NONE);
    4902              : 
    4903        21308 :       switch (st)
    4904              :         {
    4905            0 :         case ST_NONE:
    4906            0 :           unexpected_eof ();
    4907              : 
    4908         1968 :         case ST_ELSEIF:
    4909         1968 :           if (seen_else)
    4910              :             {
    4911            0 :               gfc_error ("ELSE IF statement at %C cannot follow ELSE "
    4912              :                          "statement at %L", &else_locus);
    4913              : 
    4914            0 :               reject_statement ();
    4915            0 :               break;
    4916              :             }
    4917              : 
    4918         1968 :           d = new_level (gfc_state_stack->head);
    4919         1968 :           d->op = EXEC_IF;
    4920         1968 :           d->expr1 = new_st.expr1;
    4921              : 
    4922         1968 :           accept_statement (st);
    4923              : 
    4924         1968 :           break;
    4925              : 
    4926         4151 :         case ST_ELSE:
    4927         4151 :           if (seen_else)
    4928              :             {
    4929            0 :               gfc_error ("Duplicate ELSE statements at %L and %C",
    4930              :                          &else_locus);
    4931            0 :               reject_statement ();
    4932            0 :               break;
    4933              :             }
    4934              : 
    4935         4151 :           seen_else = 1;
    4936         4151 :           else_locus = gfc_current_locus;
    4937              : 
    4938         4151 :           d = new_level (gfc_state_stack->head);
    4939         4151 :           d->op = EXEC_IF;
    4940              : 
    4941         4151 :           accept_statement (st);
    4942              : 
    4943         4151 :           break;
    4944              : 
    4945              :         case ST_ENDIF:
    4946              :           break;
    4947              : 
    4948            3 :         default:
    4949            3 :           unexpected_statement (st);
    4950            3 :           break;
    4951              :         }
    4952              :     }
    4953        21308 :   while (st != ST_ENDIF);
    4954              : 
    4955        15186 :   pop_state ();
    4956        15186 :   accept_statement (st);
    4957        15186 : }
    4958              : 
    4959              : 
    4960              : /* Parse a SELECT block.  */
    4961              : 
    4962              : static void
    4963          558 : parse_select_block (void)
    4964              : {
    4965          558 :   gfc_statement st;
    4966          558 :   gfc_code *cp;
    4967          558 :   gfc_state_data s;
    4968              : 
    4969          558 :   accept_statement (ST_SELECT_CASE);
    4970              : 
    4971          558 :   cp = gfc_state_stack->tail;
    4972          558 :   push_state (&s, COMP_SELECT, gfc_new_block);
    4973              : 
    4974              :   /* Make sure that the next statement is a CASE or END SELECT.  */
    4975          560 :   for (;;)
    4976              :     {
    4977          559 :       st = next_statement ();
    4978          559 :       if (st == ST_NONE)
    4979            0 :         unexpected_eof ();
    4980          559 :       if (st == ST_END_SELECT)
    4981              :         {
    4982              :           /* Empty SELECT CASE is OK.  */
    4983           14 :           accept_statement (st);
    4984           14 :           pop_state ();
    4985           14 :           return;
    4986              :         }
    4987          545 :       if (st == ST_CASE)
    4988              :         break;
    4989              : 
    4990            1 :       gfc_error ("Expected a CASE or END SELECT statement following SELECT "
    4991              :                  "CASE at %C");
    4992              : 
    4993            1 :       reject_statement ();
    4994              :     }
    4995              : 
    4996              :   /* At this point, we've got a nonempty select block.  */
    4997          544 :   cp = new_level (cp);
    4998          544 :   *cp = new_st;
    4999              : 
    5000          544 :   accept_statement (st);
    5001              : 
    5002         1650 :   do
    5003              :     {
    5004         1650 :       st = parse_executable (ST_NONE);
    5005         1650 :       switch (st)
    5006              :         {
    5007            0 :         case ST_NONE:
    5008            0 :           unexpected_eof ();
    5009              : 
    5010         1106 :         case ST_CASE:
    5011         1106 :           cp = new_level (gfc_state_stack->head);
    5012         1106 :           *cp = new_st;
    5013         1106 :           gfc_clear_new_st ();
    5014              : 
    5015         1106 :           accept_statement (st);
    5016              :           /* Fall through */
    5017              : 
    5018              :         case ST_END_SELECT:
    5019              :           break;
    5020              : 
    5021              :         /* Can't have an executable statement because of
    5022              :            parse_executable().  */
    5023            0 :         default:
    5024            0 :           unexpected_statement (st);
    5025            0 :           break;
    5026              :         }
    5027              :     }
    5028         1650 :   while (st != ST_END_SELECT);
    5029              : 
    5030          544 :   pop_state ();
    5031          544 :   accept_statement (st);
    5032              : }
    5033              : 
    5034              : 
    5035              : /* Pop the current selector from the SELECT TYPE stack.  */
    5036              : 
    5037              : static void
    5038         4400 : select_type_pop (void)
    5039              : {
    5040         4400 :   gfc_select_type_stack *old = select_type_stack;
    5041         4400 :   select_type_stack = old->prev;
    5042         4400 :   free (old);
    5043         4400 : }
    5044              : 
    5045              : 
    5046              : /* Parse a SELECT TYPE construct (F03:R821).  */
    5047              : 
    5048              : static void
    5049         3342 : parse_select_type_block (void)
    5050              : {
    5051         3342 :   gfc_statement st;
    5052         3342 :   gfc_code *cp;
    5053         3342 :   gfc_state_data s;
    5054              : 
    5055         3342 :   gfc_current_ns = new_st.ext.block.ns;
    5056         3342 :   accept_statement (ST_SELECT_TYPE);
    5057              : 
    5058         3342 :   cp = gfc_state_stack->tail;
    5059         3342 :   push_state (&s, COMP_SELECT_TYPE, gfc_new_block);
    5060              : 
    5061              :   /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
    5062              :      or END SELECT.  */
    5063         3352 :   for (;;)
    5064              :     {
    5065         3347 :       st = next_statement ();
    5066         3347 :       if (st == ST_NONE)
    5067            2 :         unexpected_eof ();
    5068         3345 :       if (st == ST_END_SELECT)
    5069              :         /* Empty SELECT CASE is OK.  */
    5070           23 :         goto done;
    5071         3322 :       if (st == ST_TYPE_IS || st == ST_CLASS_IS)
    5072              :         break;
    5073              : 
    5074            5 :       gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
    5075              :                  "following SELECT TYPE at %C");
    5076              : 
    5077            5 :       reject_statement ();
    5078              :     }
    5079              : 
    5080              :   /* At this point, we've got a nonempty select block.  */
    5081         3317 :   cp = new_level (cp);
    5082         3317 :   *cp = new_st;
    5083              : 
    5084         3317 :   accept_statement (st);
    5085              : 
    5086         5918 :   do
    5087              :     {
    5088         5918 :       st = parse_executable (ST_NONE);
    5089         5918 :       switch (st)
    5090              :         {
    5091            0 :         case ST_NONE:
    5092            0 :           unexpected_eof ();
    5093              : 
    5094         2601 :         case ST_TYPE_IS:
    5095         2601 :         case ST_CLASS_IS:
    5096         2601 :           cp = new_level (gfc_state_stack->head);
    5097         2601 :           *cp = new_st;
    5098         2601 :           gfc_clear_new_st ();
    5099              : 
    5100         2601 :           accept_statement (st);
    5101              :           /* Fall through */
    5102              : 
    5103              :         case ST_END_SELECT:
    5104              :           break;
    5105              : 
    5106              :         /* Can't have an executable statement because of
    5107              :            parse_executable().  */
    5108            0 :         default:
    5109            0 :           unexpected_statement (st);
    5110            0 :           break;
    5111              :         }
    5112              :     }
    5113         5918 :   while (st != ST_END_SELECT);
    5114              : 
    5115         3317 : done:
    5116         3340 :   pop_state ();
    5117         3340 :   accept_statement (st);
    5118         3340 :   gfc_current_ns = gfc_current_ns->parent;
    5119         3340 :   select_type_pop ();
    5120         3340 : }
    5121              : 
    5122              : 
    5123              : /* Parse a SELECT RANK construct.  */
    5124              : 
    5125              : static void
    5126         1060 : parse_select_rank_block (void)
    5127              : {
    5128         1060 :   gfc_statement st;
    5129         1060 :   gfc_code *cp;
    5130         1060 :   gfc_state_data s;
    5131              : 
    5132         1060 :   gfc_current_ns = new_st.ext.block.ns;
    5133         1060 :   accept_statement (ST_SELECT_RANK);
    5134              : 
    5135         1060 :   cp = gfc_state_stack->tail;
    5136         1060 :   push_state (&s, COMP_SELECT_RANK, gfc_new_block);
    5137              : 
    5138              :   /* Make sure that the next statement is a RANK IS or RANK DEFAULT.  */
    5139         1066 :   for (;;)
    5140              :     {
    5141         1063 :       st = next_statement ();
    5142         1063 :       if (st == ST_NONE)
    5143            0 :         unexpected_eof ();
    5144         1063 :       if (st == ST_END_SELECT)
    5145              :         /* Empty SELECT CASE is OK.  */
    5146            3 :         goto done;
    5147         1060 :       if (st == ST_RANK)
    5148              :         break;
    5149              : 
    5150            3 :       gfc_error ("Expected RANK or RANK DEFAULT "
    5151              :                  "following SELECT RANK at %C");
    5152              : 
    5153            3 :       reject_statement ();
    5154              :     }
    5155              : 
    5156              :   /* At this point, we've got a nonempty select block.  */
    5157         1057 :   cp = new_level (cp);
    5158         1057 :   *cp = new_st;
    5159              : 
    5160         1057 :   accept_statement (st);
    5161              : 
    5162         2392 :   do
    5163              :     {
    5164         2392 :       st = parse_executable (ST_NONE);
    5165         2392 :       switch (st)
    5166              :         {
    5167            0 :         case ST_NONE:
    5168            0 :           unexpected_eof ();
    5169              : 
    5170         1335 :         case ST_RANK:
    5171         1335 :           cp = new_level (gfc_state_stack->head);
    5172         1335 :           *cp = new_st;
    5173         1335 :           gfc_clear_new_st ();
    5174              : 
    5175         1335 :           accept_statement (st);
    5176              :           /* Fall through */
    5177              : 
    5178              :         case ST_END_SELECT:
    5179              :           break;
    5180              : 
    5181              :         /* Can't have an executable statement because of
    5182              :            parse_executable().  */
    5183            0 :         default:
    5184            0 :           unexpected_statement (st);
    5185            0 :           break;
    5186              :         }
    5187              :     }
    5188         2392 :   while (st != ST_END_SELECT);
    5189              : 
    5190         1057 : done:
    5191         1060 :   pop_state ();
    5192         1060 :   accept_statement (st);
    5193         1060 :   gfc_current_ns = gfc_current_ns->parent;
    5194         1060 :   select_type_pop ();
    5195         1060 : }
    5196              : 
    5197              : 
    5198              : /* Given a symbol, make sure it is not an iteration variable for a DO
    5199              :    statement.  This subroutine is called when the symbol is seen in a
    5200              :    context that causes it to become redefined.  If the symbol is an
    5201              :    iterator, we generate an error message and return nonzero.  */
    5202              : 
    5203              : bool
    5204       366060 : gfc_check_do_variable (gfc_symtree *st)
    5205              : {
    5206       366060 :   gfc_state_data *s;
    5207              : 
    5208       366060 :   if (!st)
    5209              :     return 0;
    5210              : 
    5211      1629589 :   for (s=gfc_state_stack; s; s = s->previous)
    5212      1263542 :     if (s->do_variable == st)
    5213              :       {
    5214            8 :         gfc_error_now ("Variable %qs at %C cannot be redefined inside "
    5215            8 :                        "loop beginning at %L", st->name, &s->head->loc);
    5216            8 :         return 1;
    5217              :       }
    5218              : 
    5219              :   return 0;
    5220              : }
    5221              : 
    5222              : 
    5223              : /* Checks to see if the current statement label closes an enddo.
    5224              :    Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
    5225              :    an error) if it incorrectly closes an ENDDO.  */
    5226              : 
    5227              : static int
    5228       956590 : check_do_closure (void)
    5229              : {
    5230       956590 :   gfc_state_data *p;
    5231              : 
    5232       956590 :   if (gfc_statement_label == NULL)
    5233              :     return 0;
    5234              : 
    5235        16165 :   for (p = gfc_state_stack; p; p = p->previous)
    5236        12479 :     if (p->state == COMP_DO || p->state == COMP_DO_CONCURRENT)
    5237              :       break;
    5238              : 
    5239         6750 :   if (p == NULL)
    5240              :     return 0;           /* No loops to close */
    5241              : 
    5242         3064 :   if (p->ext.end_do_label == gfc_statement_label)
    5243              :     {
    5244         2257 :       if (p == gfc_state_stack)
    5245              :         return 1;
    5246              : 
    5247            1 :       gfc_error ("End of nonblock DO statement at %C is within another block");
    5248            1 :       return 2;
    5249              :     }
    5250              : 
    5251              :   /* At this point, the label doesn't terminate the innermost loop.
    5252              :      Make sure it doesn't terminate another one.  */
    5253         4568 :   for (; p; p = p->previous)
    5254         3761 :     if ((p->state == COMP_DO || p->state == COMP_DO_CONCURRENT)
    5255         1057 :         && p->ext.end_do_label == gfc_statement_label)
    5256              :       {
    5257            0 :         gfc_error ("End of nonblock DO statement at %C is interwoven "
    5258              :                    "with another DO loop");
    5259            0 :         return 2;
    5260              :       }
    5261              : 
    5262              :   return 0;
    5263              : }
    5264              : 
    5265              : 
    5266              : /* Parse a series of contained program units.  */
    5267              : 
    5268              : static void parse_progunit (gfc_statement);
    5269              : 
    5270              : 
    5271              : /* Parse a CRITICAL block.  */
    5272              : 
    5273              : static void
    5274           54 : parse_critical_block (void)
    5275              : {
    5276           54 :   gfc_code *top, *d;
    5277           54 :   gfc_state_data s, *sd;
    5278           54 :   gfc_statement st;
    5279              : 
    5280          185 :   for (sd = gfc_state_stack; sd; sd = sd->previous)
    5281          131 :     if (sd->state == COMP_OMP_STRUCTURED_BLOCK)
    5282            4 :       gfc_error_now (is_oacc (sd)
    5283              :                      ? G_("CRITICAL block inside of OpenACC region at %C")
    5284              :                      : G_("CRITICAL block inside of OpenMP region at %C"));
    5285              : 
    5286           54 :   s.ext.end_do_label = new_st.label1;
    5287              : 
    5288           54 :   accept_statement (ST_CRITICAL);
    5289           54 :   top = gfc_state_stack->tail;
    5290              : 
    5291           54 :   push_state (&s, COMP_CRITICAL, gfc_new_block);
    5292              : 
    5293           54 :   d = add_statement ();
    5294           54 :   d->op = EXEC_CRITICAL;
    5295           54 :   top->block = d;
    5296              : 
    5297           54 :   do
    5298              :     {
    5299           54 :       st = parse_executable (ST_NONE);
    5300              : 
    5301           54 :       switch (st)
    5302              :         {
    5303            0 :           case ST_NONE:
    5304            0 :             unexpected_eof ();
    5305           54 :             break;
    5306              : 
    5307           54 :           case ST_END_CRITICAL:
    5308           54 :             if (s.ext.end_do_label != NULL
    5309            0 :                 && s.ext.end_do_label != gfc_statement_label)
    5310            0 :               gfc_error_now ("Statement label in END CRITICAL at %C does not "
    5311              :                              "match CRITICAL label");
    5312              : 
    5313           54 :             if (gfc_statement_label != NULL)
    5314              :               {
    5315            1 :                 new_st.op = EXEC_NOP;
    5316            1 :                 add_statement ();
    5317              :               }
    5318              :             break;
    5319              : 
    5320            0 :           default:
    5321            0 :             unexpected_statement (st);
    5322            0 :             break;
    5323              :         }
    5324              :     }
    5325           54 :   while (st != ST_END_CRITICAL);
    5326              : 
    5327           54 :   pop_state ();
    5328           54 :   accept_statement (st);
    5329           54 : }
    5330              : 
    5331              : 
    5332              : /* Set up the local namespace for a BLOCK construct.  */
    5333              : 
    5334              : gfc_namespace*
    5335        16041 : gfc_build_block_ns (gfc_namespace *parent_ns)
    5336              : {
    5337        16041 :   gfc_namespace* my_ns;
    5338        16041 :   static int numblock = 1;
    5339              : 
    5340        16041 :   my_ns = gfc_get_namespace (parent_ns, 1);
    5341        16041 :   my_ns->construct_entities = 1;
    5342              : 
    5343              :   /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
    5344              :      code generation (so it must not be NULL).
    5345              :      We set its recursive argument if our container procedure is recursive, so
    5346              :      that local variables are accordingly placed on the stack when it
    5347              :      will be necessary.  */
    5348        16041 :   if (gfc_new_block)
    5349          142 :     my_ns->proc_name = gfc_new_block;
    5350              :   else
    5351              :     {
    5352        15899 :       bool t;
    5353        15899 :       char buffer[20];  /* Enough to hold "block@2147483648\n".  */
    5354              : 
    5355        15899 :       snprintf(buffer, sizeof(buffer), "block@%d", numblock++);
    5356        15899 :       gfc_get_symbol (buffer, my_ns, &my_ns->proc_name);
    5357        31798 :       t = gfc_add_flavor (&my_ns->proc_name->attr, FL_LABEL,
    5358        15899 :                           my_ns->proc_name->name, NULL);
    5359        15899 :       gcc_assert (t);
    5360        15899 :       gfc_commit_symbol (my_ns->proc_name);
    5361              :     }
    5362              : 
    5363        16041 :   if (parent_ns->proc_name)
    5364        16038 :     my_ns->proc_name->attr.recursive = parent_ns->proc_name->attr.recursive;
    5365              : 
    5366        16041 :   return my_ns;
    5367              : }
    5368              : 
    5369              : 
    5370              : /* Parse a BLOCK construct.  */
    5371              : 
    5372              : static void
    5373         1138 : parse_block_construct (void)
    5374              : {
    5375         1138 :   gfc_namespace* my_ns;
    5376         1138 :   gfc_namespace* my_parent;
    5377         1138 :   gfc_state_data s;
    5378              : 
    5379         1138 :   gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C");
    5380              : 
    5381         1138 :   my_ns = gfc_build_block_ns (gfc_current_ns);
    5382              : 
    5383         1138 :   new_st.op = EXEC_BLOCK;
    5384         1138 :   new_st.ext.block.ns = my_ns;
    5385         1138 :   new_st.ext.block.assoc = NULL;
    5386         1138 :   accept_statement (ST_BLOCK);
    5387              : 
    5388         1138 :   push_state (&s, COMP_BLOCK, my_ns->proc_name);
    5389         1138 :   gfc_current_ns = my_ns;
    5390         1138 :   my_parent = my_ns->parent;
    5391              : 
    5392         1138 :   parse_progunit (ST_NONE);
    5393              : 
    5394              :   /* Don't depend on the value of gfc_current_ns;  it might have been
    5395              :      reset if the block had errors and was cleaned up.  */
    5396         1129 :   gfc_current_ns = my_parent;
    5397              : 
    5398         1129 :   pop_state ();
    5399         1129 : }
    5400              : 
    5401              : static void
    5402         1817 : move_associates_to_block ()
    5403              : {
    5404         1817 :   gfc_association_list *a;
    5405         1817 :   gfc_array_spec *as;
    5406              : 
    5407         3794 :   for (a = new_st.ext.block.assoc; a; a = a->next)
    5408              :     {
    5409         1977 :       gfc_symbol *sym, *tsym;
    5410         1977 :       gfc_expr *target;
    5411         1977 :       int rank, corank;
    5412              : 
    5413         1977 :       if (gfc_get_sym_tree (a->name, NULL, &a->st, false))
    5414            0 :         gcc_unreachable ();
    5415              : 
    5416         1977 :       sym = a->st->n.sym;
    5417         1977 :       sym->attr.flavor = FL_VARIABLE;
    5418         1977 :       sym->assoc = a;
    5419         1977 :       sym->declared_at = a->where;
    5420         1977 :       gfc_set_sym_referenced (sym);
    5421              : 
    5422              :       /* If the selector is a inferred type then the associate_name had better
    5423              :          be as well. Use array references, if present, to identify it as an
    5424              :          array.  */
    5425         1977 :       if (IS_INFERRED_TYPE (a->target))
    5426              :         {
    5427           18 :           sym->assoc->inferred_type = 1;
    5428           48 :           for (gfc_ref *r = a->target->ref; r; r = r->next)
    5429           30 :             if (r->type == REF_ARRAY)
    5430           18 :               sym->attr.dimension = 1;
    5431              :         }
    5432              : 
    5433              :       /* Initialize the typespec.  It is not available in all cases,
    5434              :          however, as it may only be set on the target during resolution.
    5435              :          Still, sometimes it helps to have it right now -- especially
    5436              :          for parsing component references on the associate-name
    5437              :          in case of association to a derived-type.  */
    5438         1977 :       sym->ts = a->target->ts;
    5439         1977 :       target = a->target;
    5440              : 
    5441              :       /* Don’t share the character length information between associate
    5442              :          variable and target if the length is not a compile-time constant,
    5443              :          as we don’t want to touch some other character length variable
    5444              :          when we try to initialize the associate variable’s character
    5445              :          length variable.  We do it here rather than later so that expressions
    5446              :          referencing the associate variable will automatically have the
    5447              :          correctly setup length information.  If we did it at resolution stage
    5448              :          the expressions would use the original length information, and the
    5449              :          variable a new different one, but only the latter one would be
    5450              :          correctly initialized at translation stage, and the former one would
    5451              :          need some additional setup there.  */
    5452         1977 :       if (sym->ts.type == BT_CHARACTER && sym->ts.u.cl
    5453          240 :           && !(sym->ts.u.cl->length
    5454           92 :                && sym->ts.u.cl->length->expr_type == EXPR_CONSTANT))
    5455          160 :         sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
    5456              : 
    5457              :       /* If the function has been parsed, go straight to the result to
    5458              :          obtain the expression rank.  */
    5459         1977 :       if (target->expr_type == EXPR_FUNCTION && target->symtree
    5460          545 :           && target->symtree->n.sym)
    5461              :         {
    5462          545 :           tsym = target->symtree->n.sym;
    5463          545 :           if (!tsym->result)
    5464            0 :             tsym->result = tsym;
    5465          545 :           sym->ts = tsym->result->ts;
    5466          545 :           if (sym->ts.type == BT_CLASS)
    5467              :             {
    5468           18 :               if (CLASS_DATA (sym)->as)
    5469              :                 {
    5470           12 :                   target->rank = CLASS_DATA (sym)->as->rank;
    5471           12 :                   target->corank = CLASS_DATA (sym)->as->corank;
    5472              :                 }
    5473           18 :               sym->attr.class_ok = 1;
    5474              :             }
    5475              :           else
    5476              :             {
    5477          527 :               target->rank = tsym->result->as ? tsym->result->as->rank : 0;
    5478          527 :               target->corank = tsym->result->as ? tsym->result->as->corank : 0;
    5479              :             }
    5480              :         }
    5481              : 
    5482              :       /* Check if the target expression is array valued. This cannot be done
    5483              :          by calling gfc_resolve_expr because the context is unavailable.
    5484              :          However, the references can be resolved and the rank of the target
    5485              :          expression set.  */
    5486         1959 :       if (!sym->assoc->inferred_type && target->ref && gfc_resolve_ref (target)
    5487          688 :           && target->expr_type != EXPR_ARRAY
    5488         2665 :           && target->expr_type != EXPR_COMPCALL)
    5489          687 :         gfc_expression_rank (target);
    5490              : 
    5491              :       /* Determine whether or not function expressions with unknown type are
    5492              :          structure constructors. If so, the function result can be converted
    5493              :          to be a derived type.  */
    5494         1977 :       if (target->expr_type == EXPR_FUNCTION && target->ts.type == BT_UNKNOWN)
    5495              :         {
    5496          507 :           gfc_symbol *derived;
    5497              :           /* The derived type has a leading uppercase character.  */
    5498          507 :           gfc_find_symbol (gfc_dt_upper_string (target->symtree->name),
    5499          507 :                            gfc_current_ns->parent, 1, &derived);
    5500          507 :           if (derived && derived->attr.flavor == FL_DERIVED)
    5501              :             {
    5502           34 :               sym->ts.type = BT_DERIVED;
    5503           34 :               sym->ts.u.derived = derived;
    5504           34 :               sym->assoc->inferred_type = 0;
    5505              :             }
    5506              :         }
    5507              : 
    5508         1977 :       rank = target->rank;
    5509         1977 :       corank = target->corank;
    5510              :       /* Fixup cases where the ranks are mismatched.  */
    5511         1977 :       if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
    5512              :         {
    5513          203 :           if ((!CLASS_DATA (sym)->as && (rank != 0 || corank != 0))
    5514          203 :               || (CLASS_DATA (sym)->as
    5515          141 :                   && (CLASS_DATA (sym)->as->rank != rank
    5516          109 :                       || CLASS_DATA (sym)->as->corank != corank))
    5517          171 :               || rank == -1)
    5518              :             {
    5519              :               /* Don't just (re-)set the attr and as in the sym.ts,
    5520              :               because this modifies the target's attr and as.  Copy the
    5521              :               data and do a build_class_symbol.  */
    5522           44 :               symbol_attribute attr = CLASS_DATA (target)->attr;
    5523           44 :               gfc_typespec type;
    5524           44 :               if (rank == -1 && a->ar)
    5525              :                 {
    5526           12 :                   as = gfc_get_array_spec ();
    5527           12 :                   as->rank = a->ar->dimen;
    5528           12 :                   as->corank = 0;
    5529           12 :                   as->type = AS_DEFERRED;
    5530           12 :                   attr.dimension = rank ? 1 : 0;
    5531           12 :                   attr.codimension = as->corank ? 1 : 0;
    5532           12 :                   sym->assoc->variable = true;
    5533              :                 }
    5534           32 :               else if (rank || corank)
    5535              :                 {
    5536            0 :                   as = gfc_get_array_spec ();
    5537            0 :                   as->type = AS_DEFERRED;
    5538            0 :                   as->rank = rank;
    5539            0 :                   as->corank = corank;
    5540            0 :                   attr.dimension = rank ? 1 : 0;
    5541            0 :                   attr.codimension = corank ? 1 : 0;
    5542              :                 }
    5543              :               else
    5544              :                 {
    5545           32 :                   as = NULL;
    5546           32 :                   attr.dimension = attr.codimension = 0;
    5547              :                 }
    5548           44 :               attr.class_ok = 0;
    5549           44 :               attr.associate_var = 1;
    5550           44 :               type = CLASS_DATA (sym)->ts;
    5551           44 :               if (!gfc_build_class_symbol (&type, &attr, &as))
    5552            0 :                 gcc_unreachable ();
    5553           44 :               sym->ts = type;
    5554           44 :               sym->ts.type = BT_CLASS;
    5555           44 :               sym->attr.class_ok = 1;
    5556           44 :             }
    5557              :           else
    5558          159 :             sym->attr.class_ok = 1;
    5559              :         }
    5560         1774 :       else if (rank == -1 && a->ar)
    5561              :         {
    5562           14 :           sym->as = gfc_get_array_spec ();
    5563           14 :           sym->as->rank = a->ar->dimen;
    5564           14 :           sym->as->corank = a->ar->codimen;
    5565           14 :           sym->as->type = AS_DEFERRED;
    5566           14 :           sym->attr.dimension = 1;
    5567           14 :           sym->attr.codimension = sym->as->corank ? 1 : 0;
    5568           14 :           sym->attr.pointer = 1;
    5569              :         }
    5570         1760 :       else if ((!sym->as && (rank != 0 || corank != 0))
    5571         1218 :                || (sym->as
    5572            0 :                    && (sym->as->rank != rank || sym->as->corank != corank)))
    5573              :         {
    5574          542 :           as = gfc_get_array_spec ();
    5575          542 :           as->type = AS_DEFERRED;
    5576          542 :           as->rank = rank;
    5577          542 :           as->corank = corank;
    5578          542 :           sym->as = as;
    5579          542 :           if (rank)
    5580          526 :             sym->attr.dimension = 1;
    5581          542 :           if (corank)
    5582              :             {
    5583           18 :               as->cotype = AS_ASSUMED_SHAPE;
    5584           18 :               sym->attr.codimension = 1;
    5585              :             }
    5586              :         }
    5587         1977 :       gfc_commit_symbols ();
    5588              :     }
    5589         1817 : }
    5590              : 
    5591              : /* Parse an ASSOCIATE construct.  This is essentially a BLOCK construct
    5592              :    behind the scenes with compiler-generated variables.  */
    5593              : 
    5594              : static void
    5595         1814 : parse_associate (void)
    5596              : {
    5597         1814 :   gfc_namespace* my_ns;
    5598         1814 :   gfc_state_data s;
    5599         1814 :   gfc_statement st;
    5600              : 
    5601         1814 :   gfc_notify_std (GFC_STD_F2003, "ASSOCIATE construct at %C");
    5602              : 
    5603         1814 :   my_ns = gfc_build_block_ns (gfc_current_ns);
    5604              : 
    5605         1814 :   new_st.op = EXEC_BLOCK;
    5606         1814 :   new_st.ext.block.ns = my_ns;
    5607         1814 :   gcc_assert (new_st.ext.block.assoc);
    5608              : 
    5609              :   /* Add all associate-names as BLOCK variables.  Creating them is enough
    5610              :      for now, they'll get their values during trans-* phase.  */
    5611         1814 :   gfc_current_ns = my_ns;
    5612         1814 :   move_associates_to_block ();
    5613              : 
    5614         1814 :   accept_statement (ST_ASSOCIATE);
    5615         1814 :   push_state (&s, COMP_ASSOCIATE, my_ns->proc_name);
    5616              : 
    5617         1816 : loop:
    5618         1816 :   st = parse_executable (ST_NONE);
    5619         1813 :   switch (st)
    5620              :     {
    5621            0 :     case ST_NONE:
    5622            0 :       unexpected_eof ();
    5623              : 
    5624         1811 :     case_end:
    5625         1811 :       accept_statement (st);
    5626         1811 :       my_ns->code = gfc_state_stack->head;
    5627         1811 :       break;
    5628              : 
    5629            2 :     default:
    5630            2 :       unexpected_statement (st);
    5631            2 :       goto loop;
    5632              :     }
    5633              : 
    5634         1811 :   gfc_current_ns = gfc_current_ns->parent;
    5635         1811 :   pop_state ();
    5636         1811 : }
    5637              : 
    5638              : 
    5639              : /* F2018(11.1.5.2): Track coarrays allocated within CHANGE TEAM blocks.
    5640              :    Map from team namespace to vector of allocated coarray symbols.  */
    5641              : hash_map<gfc_namespace *, vec<gfc_expr *>> team_allocated_coarrays;
    5642              : 
    5643              : /* Stack to track current CHANGE TEAM context.  */
    5644              : vec<gfc_namespace *> team_context_stack;
    5645              : 
    5646              : gfc_namespace *
    5647        18407 : get_current_team_context (void)
    5648              : {
    5649        18479 :   return team_context_stack.is_empty () ? NULL : team_context_stack.last ();
    5650              : }
    5651              : 
    5652              : 
    5653              : static void
    5654          131 : parse_change_team (void)
    5655              : {
    5656          131 :   gfc_namespace *my_ns;
    5657          131 :   gfc_state_data s;
    5658          131 :   gfc_statement st;
    5659          131 :   vec<gfc_expr *> *team_allocs;
    5660              : 
    5661          131 :   gfc_notify_std (GFC_STD_F2018, "CHANGE TEAM construct at %C");
    5662              : 
    5663          131 :   my_ns = gfc_build_block_ns (gfc_current_ns);
    5664              : 
    5665          131 :   new_st.op = EXEC_CHANGE_TEAM;
    5666          131 :   new_st.ext.block.ns = my_ns;
    5667              : 
    5668              :   /* Add all associate-names as BLOCK variables.  Creating them is enough
    5669              :      for now, they'll get their values during trans-* phase.  */
    5670          131 :   gfc_current_ns = my_ns;
    5671          131 :   if (new_st.ext.block.assoc)
    5672            3 :     move_associates_to_block ();
    5673              : 
    5674          131 :   accept_statement (ST_CHANGE_TEAM);
    5675          131 :   push_state (&s, COMP_CHANGE_TEAM, my_ns->proc_name);
    5676              : 
    5677              :   /* Push team context for tracking coarrays allocated in a team block.  */
    5678          131 :   team_context_stack.safe_push (gfc_current_ns);
    5679              : 
    5680          131 : loop:
    5681          131 :   st = parse_executable (ST_NONE);
    5682          131 :   switch (st)
    5683              :     {
    5684            0 :     case ST_NONE:
    5685            0 :       unexpected_eof ();
    5686              : 
    5687          131 :     case_end:
    5688          131 :       accept_statement (st);
    5689          131 :       my_ns->code = gfc_state_stack->head;
    5690              :       /* F2018(11.1.5.2): Deallocate coarray expressions allocated in this
    5691              :          team block,  */
    5692          131 :       team_allocs = team_allocated_coarrays.get (gfc_current_ns);
    5693          131 :       if (team_allocs)
    5694           28 :         deallocate_allocated_coarrays (team_allocs);
    5695              :       /* Pop team context.  */
    5696          131 :       team_context_stack.pop ();
    5697          131 :       break;
    5698              : 
    5699            0 :     default:
    5700            0 :       unexpected_statement (st);
    5701            0 :       goto loop;
    5702              :     }
    5703              : 
    5704          131 :   gfc_current_ns = gfc_current_ns->parent;
    5705          131 :   pop_state ();
    5706          131 : }
    5707              : 
    5708              : /* Parse a DO loop.  Note that the ST_CYCLE and ST_EXIT statements are
    5709              :    handled inside of parse_executable(), because they aren't really
    5710              :    loop statements.  */
    5711              : 
    5712              : static void
    5713        34053 : parse_do_block (void)
    5714              : {
    5715        34053 :   gfc_statement st;
    5716        34053 :   gfc_code *top;
    5717        34053 :   gfc_state_data s;
    5718        34053 :   gfc_symtree *stree;
    5719        34053 :   gfc_exec_op do_op;
    5720              : 
    5721        34053 :   do_op = new_st.op;
    5722        34053 :   s.ext.end_do_label = new_st.label1;
    5723              : 
    5724        34053 :   if (do_op == EXEC_DO_CONCURRENT)
    5725              :     {
    5726          370 :       gfc_forall_iterator *fa;
    5727          771 :       for (fa = new_st.ext.concur.forall_iterator; fa; fa = fa->next)
    5728              :         {
    5729              :           /* Apply unroll only to innermost loop (first control
    5730              :              variable).  */
    5731          401 :           if (directive_unroll != -1)
    5732              :             {
    5733            1 :               fa->annot.unroll = directive_unroll;
    5734            1 :               directive_unroll = -1;
    5735              :             }
    5736          401 :           if (directive_ivdep)
    5737            1 :             fa->annot.ivdep = directive_ivdep;
    5738          401 :           if (directive_vector)
    5739            1 :             fa->annot.vector = directive_vector;
    5740          401 :           if (directive_novector)
    5741            2 :             fa->annot.novector = directive_novector;
    5742              :         }
    5743          370 :       directive_ivdep = false;
    5744          370 :       directive_vector = false;
    5745          370 :       directive_novector = false;
    5746          370 :       stree = NULL;
    5747              :     }
    5748        33683 :   else if (new_st.ext.iterator != NULL)
    5749              :     {
    5750        33115 :       stree = new_st.ext.iterator->var->symtree;
    5751        33115 :       if (directive_unroll != -1)
    5752              :         {
    5753           16 :           new_st.ext.iterator->annot.unroll = directive_unroll;
    5754           16 :           directive_unroll = -1;
    5755              :         }
    5756        33115 :       if (directive_ivdep)
    5757              :         {
    5758            2 :           new_st.ext.iterator->annot.ivdep = directive_ivdep;
    5759            2 :           directive_ivdep = false;
    5760              :         }
    5761        33115 :       if (directive_vector)
    5762              :         {
    5763            2 :           new_st.ext.iterator->annot.vector = directive_vector;
    5764            2 :           directive_vector = false;
    5765              :         }
    5766        33115 :       if (directive_novector)
    5767              :         {
    5768            2 :           new_st.ext.iterator->annot.novector = directive_novector;
    5769            2 :           directive_novector = false;
    5770              :         }
    5771              :     }
    5772              :   else
    5773              :     stree = NULL;
    5774              : 
    5775        34053 :   accept_statement (ST_DO);
    5776              : 
    5777        34053 :   top = gfc_state_stack->tail;
    5778        67736 :   push_state (&s, do_op == EXEC_DO_CONCURRENT ? COMP_DO_CONCURRENT : COMP_DO,
    5779              :               gfc_new_block);
    5780              : 
    5781        34053 :   s.do_variable = stree;
    5782              : 
    5783        34053 :   top->block = new_level (top);
    5784        34053 :   top->block->op = EXEC_DO;
    5785              : 
    5786        34054 : loop:
    5787        34054 :   st = parse_executable (ST_NONE);
    5788              : 
    5789        34052 :   switch (st)
    5790              :     {
    5791            0 :     case ST_NONE:
    5792            0 :       unexpected_eof ();
    5793              : 
    5794        31878 :     case ST_ENDDO:
    5795        31878 :       if (s.ext.end_do_label != NULL
    5796           86 :           && s.ext.end_do_label != gfc_statement_label)
    5797            1 :         gfc_error_now ("Statement label in ENDDO at %C doesn't match "
    5798              :                        "DO label");
    5799              : 
    5800        31878 :       if (gfc_statement_label != NULL)
    5801              :         {
    5802           98 :           new_st.op = EXEC_NOP;
    5803           98 :           add_statement ();
    5804              :         }
    5805              :       break;
    5806              : 
    5807         2173 :     case ST_IMPLIED_ENDDO:
    5808              :      /* If the do-stmt of this DO construct has a do-construct-name,
    5809              :         the corresponding end-do must be an end-do-stmt (with a matching
    5810              :         name, but in that case we must have seen ST_ENDDO first).
    5811              :         We only complain about this in pedantic mode.  */
    5812         2173 :      if (gfc_current_block () != NULL)
    5813            1 :         gfc_error_now ("Named block DO at %L requires matching ENDDO name",
    5814              :                        &gfc_current_block()->declared_at);
    5815              : 
    5816              :       break;
    5817              : 
    5818            1 :     default:
    5819            1 :       unexpected_statement (st);
    5820            1 :       goto loop;
    5821              :     }
    5822              : 
    5823        34051 :   pop_state ();
    5824        34051 :   accept_statement (st);
    5825        34051 : }
    5826              : 
    5827              : /* Get the corresponding ending statement type for the OpenMP directive
    5828              :    OMP_ST.  If it does not have one, return ST_NONE.  */
    5829              : 
    5830              : gfc_statement
    5831        14481 : gfc_omp_end_stmt (gfc_statement omp_st,
    5832              :                   bool omp_do_p, bool omp_structured_p)
    5833              : {
    5834        14481 :   if (omp_do_p)
    5835              :     {
    5836         5531 :       switch (omp_st)
    5837              :         {
    5838              :         case ST_OMP_DISTRIBUTE: return ST_OMP_END_DISTRIBUTE;
    5839           46 :         case ST_OMP_DISTRIBUTE_PARALLEL_DO:
    5840           46 :           return ST_OMP_END_DISTRIBUTE_PARALLEL_DO;
    5841           33 :         case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
    5842           33 :           return ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD;
    5843           51 :         case ST_OMP_DISTRIBUTE_SIMD:
    5844           51 :           return ST_OMP_END_DISTRIBUTE_SIMD;
    5845         1247 :         case ST_OMP_DO: return ST_OMP_END_DO;
    5846          154 :         case ST_OMP_DO_SIMD: return ST_OMP_END_DO_SIMD;
    5847           65 :         case ST_OMP_LOOP: return ST_OMP_END_LOOP;
    5848         1204 :         case ST_OMP_PARALLEL_DO: return ST_OMP_END_PARALLEL_DO;
    5849          344 :         case ST_OMP_PARALLEL_DO_SIMD:
    5850          344 :           return ST_OMP_END_PARALLEL_DO_SIMD;
    5851           31 :         case ST_OMP_PARALLEL_LOOP:
    5852           31 :           return ST_OMP_END_PARALLEL_LOOP;
    5853          866 :         case ST_OMP_SIMD: return ST_OMP_END_SIMD;
    5854           79 :         case ST_OMP_TARGET_PARALLEL_DO:
    5855           79 :           return ST_OMP_END_TARGET_PARALLEL_DO;
    5856           21 :         case ST_OMP_TARGET_PARALLEL_DO_SIMD:
    5857           21 :           return ST_OMP_END_TARGET_PARALLEL_DO_SIMD;
    5858           17 :         case ST_OMP_TARGET_PARALLEL_LOOP:
    5859           17 :           return ST_OMP_END_TARGET_PARALLEL_LOOP;
    5860           34 :         case ST_OMP_TARGET_SIMD: return ST_OMP_END_TARGET_SIMD;
    5861           20 :         case ST_OMP_TARGET_TEAMS_DISTRIBUTE:
    5862           20 :           return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE;
    5863           68 :         case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
    5864           68 :           return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO;
    5865           54 :         case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    5866           54 :           return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
    5867           21 :         case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
    5868           21 :           return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD;
    5869           19 :         case ST_OMP_TARGET_TEAMS_LOOP:
    5870           19 :           return ST_OMP_END_TARGET_TEAMS_LOOP;
    5871           71 :         case ST_OMP_TASKLOOP: return ST_OMP_END_TASKLOOP;
    5872           39 :         case ST_OMP_TASKLOOP_SIMD: return ST_OMP_END_TASKLOOP_SIMD;
    5873            9 :         case ST_OMP_MASKED_TASKLOOP: return ST_OMP_END_MASKED_TASKLOOP;
    5874           15 :         case ST_OMP_MASKED_TASKLOOP_SIMD:
    5875           15 :           return ST_OMP_END_MASKED_TASKLOOP_SIMD;
    5876           15 :         case ST_OMP_MASTER_TASKLOOP: return ST_OMP_END_MASTER_TASKLOOP;
    5877           20 :         case ST_OMP_MASTER_TASKLOOP_SIMD:
    5878           20 :           return ST_OMP_END_MASTER_TASKLOOP_SIMD;
    5879            8 :         case ST_OMP_PARALLEL_MASKED_TASKLOOP:
    5880            8 :           return ST_OMP_END_PARALLEL_MASKED_TASKLOOP;
    5881           11 :         case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
    5882           11 :           return ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD;
    5883           14 :         case ST_OMP_PARALLEL_MASTER_TASKLOOP:
    5884           14 :           return ST_OMP_END_PARALLEL_MASTER_TASKLOOP;
    5885           19 :         case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
    5886           19 :           return ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD;
    5887           25 :         case ST_OMP_TEAMS_DISTRIBUTE:
    5888           25 :           return ST_OMP_END_TEAMS_DISTRIBUTE;
    5889           43 :         case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    5890           43 :           return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO;
    5891           67 :         case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    5892           67 :           return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
    5893           46 :         case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
    5894           46 :           return ST_OMP_END_TEAMS_DISTRIBUTE_SIMD;
    5895           33 :         case ST_OMP_TEAMS_LOOP:
    5896           33 :           return ST_OMP_END_TEAMS_LOOP;
    5897          197 :         case ST_OMP_TILE:
    5898          197 :           return ST_OMP_END_TILE;
    5899          417 :         case ST_OMP_UNROLL:
    5900          417 :           return ST_OMP_END_UNROLL;
    5901              :         default:
    5902              :           break;
    5903              :         }
    5904              :     }
    5905              : 
    5906         9003 :   if (omp_structured_p)
    5907              :     {
    5908         9003 :       switch (omp_st)
    5909              :         {
    5910              :         case ST_OMP_ALLOCATORS:
    5911              :           return ST_OMP_END_ALLOCATORS;
    5912              :         case ST_OMP_ASSUME:
    5913              :           return ST_OMP_END_ASSUME;
    5914              :         case ST_OMP_ATOMIC:
    5915              :           return ST_OMP_END_ATOMIC;
    5916              :         case ST_OMP_DISPATCH:
    5917              :           return ST_OMP_END_DISPATCH;
    5918              :         case ST_OMP_PARALLEL:
    5919              :           return ST_OMP_END_PARALLEL;
    5920              :         case ST_OMP_PARALLEL_MASKED:
    5921              :           return ST_OMP_END_PARALLEL_MASKED;
    5922              :         case ST_OMP_PARALLEL_MASTER:
    5923              :           return ST_OMP_END_PARALLEL_MASTER;
    5924              :         case ST_OMP_PARALLEL_SECTIONS:
    5925              :           return ST_OMP_END_PARALLEL_SECTIONS;
    5926              :         case ST_OMP_SCOPE:
    5927              :           return ST_OMP_END_SCOPE;
    5928              :         case ST_OMP_SECTIONS:
    5929              :           return ST_OMP_END_SECTIONS;
    5930              :         case ST_OMP_ORDERED:
    5931              :           return ST_OMP_END_ORDERED;
    5932              :         case ST_OMP_CRITICAL:
    5933              :           return ST_OMP_END_CRITICAL;
    5934              :         case ST_OMP_MASKED:
    5935              :           return ST_OMP_END_MASKED;
    5936              :         case ST_OMP_MASTER:
    5937              :           return ST_OMP_END_MASTER;
    5938              :         case ST_OMP_SINGLE:
    5939              :           return ST_OMP_END_SINGLE;
    5940              :         case ST_OMP_TARGET:
    5941              :           return ST_OMP_END_TARGET;
    5942              :         case ST_OMP_TARGET_DATA:
    5943              :           return ST_OMP_END_TARGET_DATA;
    5944              :         case ST_OMP_TARGET_PARALLEL:
    5945              :           return ST_OMP_END_TARGET_PARALLEL;
    5946              :         case ST_OMP_TARGET_TEAMS:
    5947              :           return ST_OMP_END_TARGET_TEAMS;
    5948              :         case ST_OMP_TASK:
    5949              :           return ST_OMP_END_TASK;
    5950              :         case ST_OMP_TASKGROUP:
    5951              :           return ST_OMP_END_TASKGROUP;
    5952              :         case ST_OMP_TEAMS:
    5953              :           return ST_OMP_END_TEAMS;
    5954              :         case ST_OMP_TEAMS_DISTRIBUTE:
    5955              :           return ST_OMP_END_TEAMS_DISTRIBUTE;
    5956              :         case ST_OMP_DISTRIBUTE:
    5957              :           return ST_OMP_END_DISTRIBUTE;
    5958              :         case ST_OMP_WORKSHARE:
    5959              :           return ST_OMP_END_WORKSHARE;
    5960              :         case ST_OMP_PARALLEL_WORKSHARE:
    5961              :           return ST_OMP_END_PARALLEL_WORKSHARE;
    5962              :         case ST_OMP_BEGIN_METADIRECTIVE:
    5963              :           return ST_OMP_END_METADIRECTIVE;
    5964              :         default:
    5965              :           break;
    5966              :         }
    5967              :     }
    5968              : 
    5969              :   return ST_NONE;
    5970              : }
    5971              : 
    5972              : /* Parse the statements of OpenMP do/parallel do.  */
    5973              : 
    5974              : static gfc_statement
    5975         5471 : parse_omp_do (gfc_statement omp_st, int nested)
    5976              : {
    5977         5471 :   gfc_statement st;
    5978         5471 :   gfc_code *cp, *np;
    5979         5471 :   gfc_state_data s;
    5980              : 
    5981         5471 :   accept_statement (omp_st);
    5982              : 
    5983         5471 :   cp = gfc_state_stack->tail;
    5984         5471 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    5985         5471 :   np = new_level (cp);
    5986         5471 :   np->op = cp->op;
    5987         5471 :   np->block = NULL;
    5988              : 
    5989         5557 :   for (;;)
    5990              :     {
    5991         5514 :       st = next_statement ();
    5992         5514 :       if (st == ST_NONE)
    5993            2 :         unexpected_eof ();
    5994         5512 :       else if (st == ST_DO)
    5995              :         break;
    5996          387 :       else if (st == ST_OMP_UNROLL || st == ST_OMP_TILE)
    5997              :         {
    5998          344 :           st = parse_omp_do (st, nested + 1);
    5999          344 :           if (st == ST_IMPLIED_ENDDO)
    6000              :             return st;
    6001          344 :           goto do_end;
    6002              :         }
    6003              :       else
    6004           43 :         unexpected_statement (st);
    6005              :     }
    6006              : 
    6007         5125 :   parse_do_block ();
    6008        10594 :   for (; nested; --nested)
    6009          344 :     pop_state ();
    6010         5125 :   if (gfc_statement_label != NULL
    6011           68 :       && gfc_state_stack->previous != NULL
    6012           68 :       && gfc_state_stack->previous->state == COMP_DO
    6013            2 :       && gfc_state_stack->previous->ext.end_do_label == gfc_statement_label)
    6014              :     {
    6015              :       /* In
    6016              :          DO 100 I=1,10
    6017              :            !$OMP DO
    6018              :              DO J=1,10
    6019              :              ...
    6020              :              100 CONTINUE
    6021              :          there should be no !$OMP END DO.  */
    6022            2 :       pop_state ();
    6023            2 :       return ST_IMPLIED_ENDDO;
    6024              :     }
    6025              : 
    6026         5123 :   check_do_closure ();
    6027         5123 :   pop_state ();
    6028              : 
    6029         5123 :   st = next_statement ();
    6030         5467 : do_end:
    6031         5467 :   gfc_statement omp_end_st = gfc_omp_end_stmt (omp_st, true, false);
    6032         5467 :   if (omp_st == ST_NONE)
    6033            0 :     gcc_unreachable ();
    6034              : 
    6035              :   /* If handling a metadirective variant, treat 'omp end metadirective'
    6036              :      as the expected end statement for the current construct.  */
    6037         5467 :   if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE)
    6038              :     {
    6039            4 :       if (st == ST_OMP_END_METADIRECTIVE)
    6040              :         st = omp_end_st;
    6041              :       else
    6042              :         {
    6043              :           /* We have found some extra statements between the loop
    6044              :              and the "end metadirective" which is required in a
    6045              :              "begin metadirective" construct, or perhaps the
    6046              :              "end metadirective" is missing entirely.  */
    6047            0 :           gfc_error_now ("Expected OMP END METADIRECTIVE at %C");
    6048            0 :           return st;
    6049              :         }
    6050              :     }
    6051              : 
    6052         5467 :   if (st == omp_end_st)
    6053              :     {
    6054          876 :       if (new_st.op == EXEC_OMP_END_NOWAIT)
    6055              :         {
    6056          384 :           if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool)
    6057           11 :             gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
    6058              :                            gfc_ascii_statement (omp_st),
    6059              :                            gfc_ascii_statement (omp_end_st));
    6060          384 :           cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool;
    6061              :         }
    6062              :       else
    6063          492 :         gcc_assert (new_st.op == EXEC_NOP);
    6064          876 :       gfc_clear_new_st ();
    6065          876 :       gfc_commit_symbols ();
    6066          876 :       gfc_warning_check ();
    6067          876 :       st = next_statement ();
    6068              :     }
    6069              :   return st;
    6070              : }
    6071              : 
    6072              : 
    6073              : /* Parse the statements of OpenMP atomic directive.  */
    6074              : 
    6075              : static gfc_statement
    6076         2707 : parse_omp_oacc_atomic (bool omp_p)
    6077              : {
    6078         2707 :   gfc_statement st, st_atomic, st_end_atomic;
    6079         2707 :   gfc_code *cp, *np;
    6080         2707 :   gfc_state_data s;
    6081         2707 :   int count;
    6082              : 
    6083         2707 :   if (omp_p)
    6084              :     {
    6085         2164 :       st_atomic = ST_OMP_ATOMIC;
    6086         2164 :       if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE)
    6087              :         st_end_atomic = ST_OMP_END_METADIRECTIVE;
    6088              :       else
    6089         2162 :         st_end_atomic = ST_OMP_END_ATOMIC;
    6090              :     }
    6091              :   else
    6092              :     {
    6093              :       st_atomic = ST_OACC_ATOMIC;
    6094              :       st_end_atomic = ST_OACC_END_ATOMIC;
    6095              :     }
    6096         2707 :   accept_statement (st_atomic);
    6097              : 
    6098         2707 :   cp = gfc_state_stack->tail;
    6099         2707 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6100         2707 :   np = new_level (cp);
    6101         2707 :   np->op = cp->op;
    6102         2707 :   np->block = NULL;
    6103         2707 :   np->ext.omp_clauses = cp->ext.omp_clauses;
    6104         2707 :   cp->ext.omp_clauses = NULL;
    6105         2707 :   count = 1 + np->ext.omp_clauses->capture;
    6106              : 
    6107         5939 :   while (count)
    6108              :     {
    6109         3232 :       st = next_statement ();
    6110         3232 :       if (st == ST_NONE)
    6111            0 :         unexpected_eof ();
    6112         3232 :       else if (np->ext.omp_clauses->compare
    6113          195 :                && (st == ST_SIMPLE_IF || st == ST_IF_BLOCK))
    6114              :         {
    6115          157 :           count--;
    6116          157 :           if (st == ST_IF_BLOCK)
    6117              :             {
    6118           68 :               parse_if_block ();
    6119              :               /* With else (or elseif).  */
    6120           68 :               if (gfc_state_stack->tail->block->block)
    6121           65 :                 count--;
    6122              :             }
    6123          157 :           accept_statement (st);
    6124              :         }
    6125         3075 :       else if (st == ST_ASSIGNMENT
    6126         3074 :                && (!np->ext.omp_clauses->compare
    6127           38 :                    || np->ext.omp_clauses->capture))
    6128              :         {
    6129         3074 :           accept_statement (st);
    6130         3074 :           count--;
    6131              :         }
    6132              :       else
    6133            1 :         unexpected_statement (st);
    6134              :     }
    6135              : 
    6136         2707 :   pop_state ();
    6137              : 
    6138         2707 :   st = next_statement ();
    6139         2707 :   if (st == st_end_atomic)
    6140              :     {
    6141          728 :       gfc_clear_new_st ();
    6142          728 :       gfc_commit_symbols ();
    6143          728 :       gfc_warning_check ();
    6144          728 :       st = next_statement ();
    6145              :     }
    6146         2707 :   return st;
    6147              : }
    6148              : 
    6149              : 
    6150              : /* Parse the statements of an OpenACC structured block.  */
    6151              : 
    6152              : static void
    6153         4847 : parse_oacc_structured_block (gfc_statement acc_st)
    6154              : {
    6155         4847 :   gfc_statement st, acc_end_st;
    6156         4847 :   gfc_code *cp, *np;
    6157         4847 :   gfc_state_data s, *sd;
    6158              : 
    6159        16631 :   for (sd = gfc_state_stack; sd; sd = sd->previous)
    6160        11784 :     if (sd->state == COMP_CRITICAL)
    6161            2 :       gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
    6162              : 
    6163         4847 :   accept_statement (acc_st);
    6164              : 
    6165         4847 :   cp = gfc_state_stack->tail;
    6166         4847 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6167         4847 :   np = new_level (cp);
    6168         4847 :   np->op = cp->op;
    6169         4847 :   np->block = NULL;
    6170         4847 :   switch (acc_st)
    6171              :     {
    6172              :     case ST_OACC_PARALLEL:
    6173         4847 :       acc_end_st = ST_OACC_END_PARALLEL;
    6174              :       break;
    6175          875 :     case ST_OACC_KERNELS:
    6176          875 :       acc_end_st = ST_OACC_END_KERNELS;
    6177          875 :       break;
    6178          321 :     case ST_OACC_SERIAL:
    6179          321 :       acc_end_st = ST_OACC_END_SERIAL;
    6180          321 :       break;
    6181          679 :     case ST_OACC_DATA:
    6182          679 :       acc_end_st = ST_OACC_END_DATA;
    6183          679 :       break;
    6184           60 :     case ST_OACC_HOST_DATA:
    6185           60 :       acc_end_st = ST_OACC_END_HOST_DATA;
    6186           60 :       break;
    6187            0 :     default:
    6188            0 :       gcc_unreachable ();
    6189              :     }
    6190              : 
    6191         4847 :   do
    6192              :     {
    6193         4847 :       st = parse_executable (ST_NONE);
    6194         4847 :       if (st == ST_NONE)
    6195            0 :         unexpected_eof ();
    6196         4847 :       else if (st != acc_end_st)
    6197              :         {
    6198            0 :           gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st));
    6199            0 :           reject_statement ();
    6200              :         }
    6201              :     }
    6202         4847 :   while (st != acc_end_st);
    6203              : 
    6204         4847 :   gcc_assert (new_st.op == EXEC_NOP);
    6205              : 
    6206         4847 :   gfc_clear_new_st ();
    6207         4847 :   gfc_commit_symbols ();
    6208         4847 :   gfc_warning_check ();
    6209         4847 :   pop_state ();
    6210         4847 : }
    6211              : 
    6212              : /* Parse the statements of OpenACC 'loop', or combined compute 'loop'.  */
    6213              : 
    6214              : static gfc_statement
    6215         5272 : parse_oacc_loop (gfc_statement acc_st)
    6216              : {
    6217         5272 :   gfc_statement st;
    6218         5272 :   gfc_code *cp, *np;
    6219         5272 :   gfc_state_data s, *sd;
    6220              : 
    6221        24201 :   for (sd = gfc_state_stack; sd; sd = sd->previous)
    6222        18929 :     if (sd->state == COMP_CRITICAL)
    6223            0 :       gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
    6224              : 
    6225         5272 :   accept_statement (acc_st);
    6226              : 
    6227         5272 :   cp = gfc_state_stack->tail;
    6228         5272 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6229         5272 :   np = new_level (cp);
    6230         5272 :   np->op = cp->op;
    6231         5272 :   np->block = NULL;
    6232              : 
    6233         5278 :   for (;;)
    6234              :     {
    6235         5275 :       st = next_statement ();
    6236         5275 :       if (st == ST_NONE)
    6237            0 :         unexpected_eof ();
    6238         5275 :       else if (st == ST_DO)
    6239              :         break;
    6240              :       else
    6241              :         {
    6242            3 :           gfc_error ("Expected DO loop at %C");
    6243            3 :           reject_statement ();
    6244              :         }
    6245              :     }
    6246              : 
    6247         5272 :   parse_do_block ();
    6248         5272 :   if (gfc_statement_label != NULL
    6249           80 :       && gfc_state_stack->previous != NULL
    6250           80 :       && gfc_state_stack->previous->state == COMP_DO
    6251            0 :       && gfc_state_stack->previous->ext.end_do_label == gfc_statement_label)
    6252              :     {
    6253            0 :       pop_state ();
    6254            0 :       return ST_IMPLIED_ENDDO;
    6255              :     }
    6256              : 
    6257         5272 :   check_do_closure ();
    6258         5272 :   pop_state ();
    6259              : 
    6260         5272 :   st = next_statement ();
    6261         5272 :   if (st == ST_OACC_END_LOOP)
    6262            2 :     gfc_warning (0, "Redundant !$ACC END LOOP at %C");
    6263         5272 :   if ((acc_st == ST_OACC_PARALLEL_LOOP && st == ST_OACC_END_PARALLEL_LOOP) ||
    6264         4345 :       (acc_st == ST_OACC_KERNELS_LOOP && st == ST_OACC_END_KERNELS_LOOP) ||
    6265         4322 :       (acc_st == ST_OACC_SERIAL_LOOP && st == ST_OACC_END_SERIAL_LOOP) ||
    6266         4173 :       (acc_st == ST_OACC_LOOP && st == ST_OACC_END_LOOP))
    6267              :     {
    6268         1101 :       gcc_assert (new_st.op == EXEC_NOP);
    6269         1101 :       gfc_clear_new_st ();
    6270         1101 :       gfc_commit_symbols ();
    6271         1101 :       gfc_warning_check ();
    6272         1101 :       st = next_statement ();
    6273              :     }
    6274              :   return st;
    6275              : }
    6276              : 
    6277              : 
    6278              : /* Parse an OpenMP allocate block, including optional ALLOCATORS
    6279              :    end directive.  */
    6280              : 
    6281              : static gfc_statement
    6282           74 : parse_openmp_allocate_block (gfc_statement omp_st)
    6283              : {
    6284           74 :   gfc_statement st;
    6285           74 :   gfc_code *cp, *np;
    6286           74 :   gfc_state_data s;
    6287           74 :   bool empty_list = false;
    6288           74 :   locus empty_list_loc;
    6289           74 :   gfc_omp_namelist *n_first = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
    6290              : 
    6291           74 :   if (omp_st == ST_OMP_ALLOCATE_EXEC
    6292           50 :       && new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL)
    6293              :     {
    6294           23 :       empty_list = true;
    6295           23 :       empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
    6296              :     }
    6297              : 
    6298           74 :   accept_statement (omp_st);
    6299              : 
    6300           74 :   cp = gfc_state_stack->tail;
    6301           74 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6302           74 :   np = new_level (cp);
    6303           74 :   np->op = cp->op;
    6304           74 :   np->block = NULL;
    6305              : 
    6306           74 :   st = next_statement ();
    6307          161 :   while (omp_st == ST_OMP_ALLOCATE_EXEC && st == ST_OMP_ALLOCATE_EXEC)
    6308              :     {
    6309           13 :       if (empty_list && !new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym)
    6310              :         {
    6311            1 :           locus *loc = &new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
    6312            1 :           gfc_error_now ("%s statements at %L and %L have both no list item but"
    6313              :                          " only one may", gfc_ascii_statement (st),
    6314              :                          &empty_list_loc, loc);
    6315            1 :           empty_list = false;
    6316              :         }
    6317           13 :       if (!new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym)
    6318              :         {
    6319            3 :           empty_list = true;
    6320            3 :           empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where;
    6321              :         }
    6322           22 :       for ( ; n_first->next; n_first = n_first->next)
    6323              :         ;
    6324           13 :       n_first->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
    6325           13 :       new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL;
    6326           13 :       gfc_free_omp_clauses (new_st.ext.omp_clauses);
    6327              : 
    6328           13 :       accept_statement (ST_NONE);
    6329           13 :       st = next_statement ();
    6330              :     }
    6331           74 :   if (st != ST_ALLOCATE && omp_st == ST_OMP_ALLOCATE_EXEC)
    6332            1 :     gfc_error_now ("Unexpected %s at %C; expected ALLOCATE or %s statement",
    6333              :                    gfc_ascii_statement (st), gfc_ascii_statement (omp_st));
    6334           73 :   else if (st != ST_ALLOCATE)
    6335            3 :     gfc_error_now ("Unexpected %s at %C; expected ALLOCATE statement after %s",
    6336              :                    gfc_ascii_statement (st), gfc_ascii_statement (omp_st));
    6337           74 :   accept_statement (st);
    6338           74 :   pop_state ();
    6339           74 :   st = next_statement ();
    6340           74 :   if (omp_st == ST_OMP_ALLOCATORS
    6341           24 :       && (st == ST_OMP_END_ALLOCATORS
    6342           20 :           || (st == ST_OMP_END_METADIRECTIVE
    6343            0 :               && gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE)))
    6344              :     {
    6345            4 :       accept_statement (st);
    6346            4 :       st = next_statement ();
    6347              :     }
    6348           74 :   return st;
    6349              : }
    6350              : 
    6351              : 
    6352              : /* Parse the statements of an OpenMP structured block.  */
    6353              : 
    6354              : static gfc_statement
    6355         8950 : parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only)
    6356              : {
    6357         8950 :   gfc_statement st, omp_end_st, first_st;
    6358         8950 :   gfc_code *cp, *np;
    6359         8950 :   gfc_state_data s, s2;
    6360              : 
    6361         8950 :   accept_statement (omp_st);
    6362              : 
    6363         8950 :   cp = gfc_state_stack->tail;
    6364         8950 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6365         8950 :   np = new_level (cp);
    6366         8950 :   np->op = cp->op;
    6367         8950 :   np->block = NULL;
    6368              : 
    6369         8950 :   omp_end_st = gfc_omp_end_stmt (omp_st, false, true);
    6370         8950 :   if (omp_end_st == ST_NONE)
    6371            0 :     gcc_unreachable ();
    6372              : 
    6373              :   /* If handling a metadirective variant, treat 'omp end metadirective'
    6374              :      as the expected end statement for the current construct.  */
    6375         8950 :   if (gfc_state_stack->previous != NULL
    6376         8950 :       && gfc_state_stack->previous->state == COMP_OMP_BEGIN_METADIRECTIVE)
    6377         8950 :     omp_end_st = ST_OMP_END_METADIRECTIVE;
    6378              : 
    6379         8950 :   bool block_construct = false;
    6380         8950 :   gfc_namespace *my_ns = NULL;
    6381         8950 :   gfc_namespace *my_parent = NULL;
    6382              : 
    6383         8950 :   first_st = st = next_statement ();
    6384              : 
    6385         8950 :   if (st == ST_BLOCK)
    6386              :     {
    6387              :       /* Adjust state to a strictly-structured block, now that we found that
    6388              :          the body starts with a BLOCK construct.  */
    6389          412 :       s.state = COMP_OMP_STRICTLY_STRUCTURED_BLOCK;
    6390              : 
    6391          412 :       block_construct = true;
    6392          412 :       gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C");
    6393              : 
    6394          412 :       my_ns = gfc_build_block_ns (gfc_current_ns);
    6395          412 :       new_st.op = EXEC_BLOCK;
    6396          412 :       new_st.ext.block.ns = my_ns;
    6397          412 :       new_st.ext.block.assoc = NULL;
    6398          412 :       accept_statement (ST_BLOCK);
    6399              : 
    6400          412 :       push_state (&s2, COMP_BLOCK, my_ns->proc_name);
    6401          412 :       gfc_current_ns = my_ns;
    6402          412 :       my_parent = my_ns->parent;
    6403          412 :       if (omp_st == ST_OMP_SECTIONS
    6404          412 :           || omp_st == ST_OMP_PARALLEL_SECTIONS)
    6405              :         {
    6406            2 :           np = new_level (cp);
    6407            2 :           np->op = cp->op;
    6408              :         }
    6409              : 
    6410          412 :       first_st = next_statement ();
    6411          412 :       st = parse_spec (first_st);
    6412              :     }
    6413              : 
    6414         8950 :   if (omp_end_st == ST_OMP_END_TARGET)
    6415         2250 :     switch (first_st)
    6416              :       {
    6417          210 :       case ST_OMP_TEAMS:
    6418          210 :       case ST_OMP_TEAMS_DISTRIBUTE:
    6419          210 :       case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
    6420          210 :       case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
    6421          210 :       case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
    6422          210 :       case ST_OMP_TEAMS_LOOP:
    6423          210 :       case ST_OMP_METADIRECTIVE:
    6424          210 :       case ST_OMP_BEGIN_METADIRECTIVE:
    6425          210 :         {
    6426          210 :           gfc_state_data *stk = gfc_state_stack->previous;
    6427          210 :           if (stk->state == COMP_OMP_STRICTLY_STRUCTURED_BLOCK)
    6428           20 :             stk = stk->previous;
    6429          210 :           stk->tail->ext.omp_clauses->target_first_st_is_teams_or_meta = true;
    6430          210 :           break;
    6431              :         }
    6432              :       default:
    6433              :         break;
    6434              :       }
    6435              : 
    6436         9190 :   do
    6437              :     {
    6438         9190 :       if (workshare_stmts_only)
    6439              :         {
    6440              :           /* Inside of !$omp workshare, only
    6441              :              scalar assignments
    6442              :              array assignments
    6443              :              where statements and constructs
    6444              :              forall statements and constructs
    6445              :              !$omp atomic
    6446              :              !$omp critical
    6447              :              !$omp parallel
    6448              :              are allowed.  For !$omp critical these
    6449              :              restrictions apply recursively.  */
    6450              :           bool cycle = true;
    6451              : 
    6452          339 :           for (;;)
    6453              :             {
    6454          339 :               switch (st)
    6455              :                 {
    6456            0 :                 case ST_NONE:
    6457            0 :                   unexpected_eof ();
    6458              : 
    6459          175 :                 case ST_ASSIGNMENT:
    6460          175 :                 case ST_WHERE:
    6461          175 :                 case ST_FORALL:
    6462          175 :                   accept_statement (st);
    6463          175 :                   break;
    6464              : 
    6465            6 :                 case ST_WHERE_BLOCK:
    6466            6 :                   parse_where_block ();
    6467            6 :                   break;
    6468              : 
    6469           12 :                 case ST_FORALL_BLOCK:
    6470           12 :                   parse_forall_block ();
    6471           12 :                   break;
    6472              : 
    6473            0 :                 case ST_OMP_ALLOCATE_EXEC:
    6474            0 :                 case ST_OMP_ALLOCATORS:
    6475            0 :                   st = parse_openmp_allocate_block (st);
    6476            0 :                   continue;
    6477              : 
    6478           13 :                 case ST_OMP_ASSUME:
    6479           13 :                 case ST_OMP_PARALLEL:
    6480           13 :                 case ST_OMP_PARALLEL_MASKED:
    6481           13 :                 case ST_OMP_PARALLEL_MASTER:
    6482           13 :                 case ST_OMP_PARALLEL_SECTIONS:
    6483           13 :                   st = parse_omp_structured_block (st, false);
    6484           12 :                   continue;
    6485              : 
    6486           14 :                 case ST_OMP_PARALLEL_WORKSHARE:
    6487           14 :                 case ST_OMP_CRITICAL:
    6488           14 :                   st = parse_omp_structured_block (st, true);
    6489           14 :                   continue;
    6490              : 
    6491            3 :                 case ST_OMP_PARALLEL_DO:
    6492            3 :                 case ST_OMP_PARALLEL_DO_SIMD:
    6493            3 :                   st = parse_omp_do (st, 0);
    6494            3 :                   continue;
    6495              : 
    6496            8 :                 case ST_OMP_ATOMIC:
    6497            8 :                   st = parse_omp_oacc_atomic (true);
    6498            8 :                   continue;
    6499              : 
    6500              :                 default:
    6501              :                   cycle = false;
    6502              :                   break;
    6503              :                 }
    6504              : 
    6505          193 :               if (!cycle)
    6506              :                 break;
    6507              : 
    6508          193 :               st = next_statement ();
    6509              :             }
    6510              :         }
    6511              :       else
    6512         9081 :         st = parse_executable (st);
    6513         9174 :       if (st == ST_NONE)
    6514            0 :         unexpected_eof ();
    6515         9174 :       else if (st == ST_OMP_SECTION
    6516          257 :                && (omp_st == ST_OMP_SECTIONS
    6517          257 :                    || omp_st == ST_OMP_PARALLEL_SECTIONS))
    6518              :         {
    6519          257 :           np = new_level (np);
    6520          257 :           np->op = cp->op;
    6521          257 :           np->block = NULL;
    6522          257 :           st = next_statement ();
    6523              :         }
    6524         8917 :       else if (block_construct && st == ST_END_BLOCK)
    6525              :         {
    6526          412 :           accept_statement (st);
    6527          412 :           gfc_current_ns->code = gfc_state_stack->head;
    6528          412 :           gfc_current_ns = my_parent;
    6529          412 :           pop_state ();  /* Inner BLOCK */
    6530          412 :           pop_state ();  /* Outer COMP_OMP_STRICTLY_STRUCTURED_BLOCK */
    6531              : 
    6532          412 :           st = next_statement ();
    6533          412 :           if (st == omp_end_st)
    6534              :             {
    6535          112 :               accept_statement (st);
    6536          112 :               st = next_statement ();
    6537              :             }
    6538          300 :           else if (omp_end_st == ST_OMP_END_METADIRECTIVE)
    6539              :             {
    6540              :               /* We have found some extra statements between the END BLOCK
    6541              :                  and the "end metadirective" which is required in a
    6542              :                  "begin metadirective" construct, or perhaps the
    6543              :                  "end metadirective" is missing entirely.  */
    6544            4 :               gfc_error_now ("Expected OMP END METADIRECTIVE at %C");
    6545              :             }
    6546              :           return st;
    6547              :         }
    6548         8505 :       else if (st != omp_end_st || block_construct)
    6549              :         {
    6550            4 :           unexpected_statement (st);
    6551            4 :           st = next_statement ();
    6552              :         }
    6553              :     }
    6554         8762 :   while (st != omp_end_st);
    6555              : 
    6556         8522 :   switch (new_st.op)
    6557              :     {
    6558         2336 :     case EXEC_OMP_END_NOWAIT:
    6559         2336 :       if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool)
    6560            6 :         gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
    6561              :                        gfc_ascii_statement (omp_st),
    6562              :                        gfc_ascii_statement (omp_end_st));
    6563         2336 :       cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool;
    6564         2336 :       break;
    6565          156 :     case EXEC_OMP_END_CRITICAL:
    6566          156 :       if (((cp->ext.omp_clauses->critical_name == NULL)
    6567          156 :             ^ (new_st.ext.omp_name == NULL))
    6568          156 :           || (new_st.ext.omp_name != NULL
    6569           48 :               && strcmp (cp->ext.omp_clauses->critical_name,
    6570              :                          new_st.ext.omp_name) != 0))
    6571            0 :         gfc_error ("Name after !$omp critical and !$omp end critical does "
    6572              :                    "not match at %C");
    6573          156 :       free (const_cast<char *> (new_st.ext.omp_name));
    6574          156 :       new_st.ext.omp_name = NULL;
    6575          156 :       break;
    6576          551 :     case EXEC_OMP_END_SINGLE:
    6577          551 :       if (cp->ext.omp_clauses->nowait && new_st.ext.omp_clauses->nowait)
    6578            1 :         gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C",
    6579              :                        gfc_ascii_statement (omp_st),
    6580              :                        gfc_ascii_statement (omp_end_st));
    6581          551 :       cp->ext.omp_clauses->nowait |= new_st.ext.omp_clauses->nowait;
    6582          551 :       if (cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE])
    6583              :         {
    6584              :           gfc_omp_namelist *nl;
    6585              :           for (nl = cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
    6586            5 :               nl->next; nl = nl->next)
    6587              :             ;
    6588            5 :           nl->next = new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
    6589              :         }
    6590              :       else
    6591          546 :         cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]
    6592          546 :           = new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE];
    6593          551 :       new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE] = NULL;
    6594          551 :       gfc_free_omp_clauses (new_st.ext.omp_clauses);
    6595          551 :       break;
    6596              :     case EXEC_NOP:
    6597              :       break;
    6598            0 :     default:
    6599            0 :       gcc_unreachable ();
    6600              :     }
    6601              : 
    6602         8522 :   gfc_clear_new_st ();
    6603         8522 :   gfc_commit_symbols ();
    6604         8522 :   gfc_warning_check ();
    6605         8522 :   pop_state ();
    6606         8522 :   st = next_statement ();
    6607         8522 :   return st;
    6608              : }
    6609              : 
    6610              : static gfc_statement
    6611          154 : parse_omp_dispatch (void)
    6612              : {
    6613          154 :   gfc_statement st;
    6614          154 :   gfc_code *cp, *np;
    6615          154 :   gfc_state_data s;
    6616              : 
    6617          154 :   accept_statement (ST_OMP_DISPATCH);
    6618              : 
    6619          154 :   cp = gfc_state_stack->tail;
    6620          154 :   push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL);
    6621          154 :   np = new_level (cp);
    6622          154 :   np->op = cp->op;
    6623          154 :   np->block = NULL;
    6624              : 
    6625          154 :   st = next_statement ();
    6626          154 :   if (st == ST_NONE)
    6627              :     {
    6628            1 :       pop_state ();
    6629            1 :       return st;
    6630              :     }
    6631          153 :   if (st == ST_CALL || st == ST_ASSIGNMENT)
    6632          150 :     accept_statement (st);
    6633              :   else
    6634              :     {
    6635            3 :       gfc_error ("%<OMP DISPATCH%> directive must be followed by a procedure "
    6636              :                  "call with optional assignment at %C");
    6637            3 :       reject_statement ();
    6638              :     }
    6639          153 :   pop_state ();
    6640          153 :   st = next_statement ();
    6641          153 :   if (st == ST_OMP_END_DISPATCH
    6642          147 :       || (st == ST_OMP_END_METADIRECTIVE
    6643            1 :           && gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE))
    6644              :     {
    6645            7 :       if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool)
    6646            1 :         gfc_error_now ("Duplicated NOWAIT clause on !$OMP DISPATCH and !$OMP "
    6647              :                        "END DISPATCH at %C");
    6648            7 :       cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool;
    6649            7 :       accept_statement (st);
    6650            7 :       st = next_statement ();
    6651              :     }
    6652              :   return st;
    6653              : }
    6654              : 
    6655              : static gfc_statement
    6656          128 : parse_omp_metadirective_body (gfc_statement omp_st)
    6657              : {
    6658          128 :   gfc_omp_variant *variant
    6659              :     = new_st.ext.omp_variants;
    6660          128 :   locus body_locus = gfc_current_locus;
    6661          128 :   bool saw_error = false;
    6662              : 
    6663          128 :   accept_statement (omp_st);
    6664              : 
    6665          128 :   gfc_statement next_st = ST_NONE;
    6666          128 :   locus next_loc;
    6667              : 
    6668          531 :   while (variant)
    6669              :     {
    6670          276 :       gfc_current_locus = body_locus;
    6671          276 :       gfc_state_data s;
    6672          276 :       bool workshare_p
    6673          276 :         = (variant->stmt == ST_OMP_WORKSHARE
    6674          276 :            || variant->stmt == ST_OMP_PARALLEL_WORKSHARE);
    6675           70 :       enum gfc_compile_state new_state
    6676              :         = (omp_st == ST_OMP_METADIRECTIVE
    6677          276 :            ? COMP_OMP_METADIRECTIVE : COMP_OMP_BEGIN_METADIRECTIVE);
    6678              : 
    6679          276 :       new_st = *variant->code;
    6680          276 :       push_state (&s, new_state, NULL);
    6681              : 
    6682          276 :       gfc_statement st;
    6683          276 :       bool old_in_metadirective_body = gfc_in_omp_metadirective_body;
    6684          276 :       gfc_in_omp_metadirective_body = true;
    6685              : 
    6686          276 :       gfc_omp_metadirective_region_count++;
    6687          276 :       gfc_omp_metadirective_region_stack.safe_push (
    6688              :         gfc_omp_metadirective_region_count);
    6689              : 
    6690          276 :       switch (variant->stmt)
    6691              :         {
    6692           37 :         case_omp_structured_block:
    6693           37 :           st = parse_omp_structured_block (variant->stmt, workshare_p);
    6694           37 :           break;
    6695          143 :         case_omp_do:
    6696          143 :           st = parse_omp_do (variant->stmt, 0);
    6697              :           /* TODO: Does st == ST_IMPLIED_ENDDO need special handling?  */
    6698          143 :           break;
    6699            0 :         case ST_OMP_ALLOCATORS:
    6700            0 :           st = parse_openmp_allocate_block (variant->stmt);
    6701            0 :           break;
    6702            4 :         case ST_OMP_ATOMIC:
    6703            4 :           st = parse_omp_oacc_atomic (true);
    6704            4 :           break;
    6705            1 :         case ST_OMP_DISPATCH:
    6706            1 :           st = parse_omp_dispatch ();
    6707            1 :           break;
    6708           91 :         default:
    6709           91 :           accept_statement (variant->stmt);
    6710           91 :           st = parse_executable (next_statement ());
    6711           91 :           break;
    6712              :         }
    6713              : 
    6714          275 :       if (gfc_state_stack->state == COMP_OMP_METADIRECTIVE
    6715          275 :           && startswith (gfc_ascii_statement (st), "!$OMP END "))
    6716              :         {
    6717          132 :           for (gfc_state_data *p = gfc_state_stack; p; p = p->previous)
    6718          131 :             if (p->state == COMP_OMP_STRUCTURED_BLOCK
    6719           88 :                 || p->state == COMP_OMP_BEGIN_METADIRECTIVE)
    6720           64 :               goto finish;
    6721            1 :           gfc_error ("Unexpected %s statement in OMP METADIRECTIVE "
    6722              :                      "block at %C",
    6723              :                      gfc_ascii_statement (st));
    6724            1 :           reject_statement ();
    6725            1 :           st = next_statement ();
    6726              :         }
    6727              : 
    6728          275 :     finish:
    6729              : 
    6730              :       /* Sanity-check that each variant finishes parsing at the same place.  */
    6731          275 :       if (next_st == ST_NONE)
    6732              :         {
    6733          127 :           next_st = st;
    6734          127 :           next_loc = gfc_current_locus;
    6735              :         }
    6736          148 :       else if (st != next_st
    6737          143 :                || next_loc.nextc != gfc_current_locus.nextc
    6738          142 :                || next_loc.u.lb != gfc_current_locus.u.lb)
    6739              :         {
    6740            6 :           saw_error = true;
    6741            6 :           next_st = st;
    6742            6 :           next_loc = gfc_current_locus;
    6743              :         }
    6744              : 
    6745          275 :       gfc_in_omp_metadirective_body = old_in_metadirective_body;
    6746              : 
    6747          275 :       if (gfc_state_stack->head)
    6748          272 :         *variant->code = *gfc_state_stack->head;
    6749          275 :       pop_state ();
    6750              : 
    6751          275 :       gfc_omp_metadirective_region_stack.pop ();
    6752          275 :       int outer_omp_metadirective_region
    6753          275 :         = gfc_omp_metadirective_region_stack.last ();
    6754              : 
    6755              :       /* Rebind labels in the last statement -- which is the first statement
    6756              :          past the end of the metadirective body -- to the outer region.  */
    6757          275 :       if (gfc_statement_label)
    6758           18 :         gfc_statement_label = gfc_rebind_label (gfc_statement_label,
    6759              :                                                 outer_omp_metadirective_region);
    6760          275 :       if ((new_st.op == EXEC_READ || new_st.op == EXEC_WRITE)
    6761            6 :           && new_st.ext.dt->format_label
    6762            6 :           && new_st.ext.dt->format_label != &format_asterisk)
    6763            4 :         new_st.ext.dt->format_label
    6764            4 :           = gfc_rebind_label (new_st.ext.dt->format_label,
    6765              :                               outer_omp_metadirective_region);
    6766          275 :       if (new_st.label1)
    6767            4 :         new_st.label1
    6768            4 :           = gfc_rebind_label (new_st.label1, outer_omp_metadirective_region);
    6769          275 :       if (new_st.here)
    6770           18 :         new_st.here
    6771           18 :           = gfc_rebind_label (new_st.here, outer_omp_metadirective_region);
    6772              : 
    6773          275 :       gfc_commit_symbols ();
    6774          275 :       gfc_warning_check ();
    6775          275 :       if (variant->next)
    6776          148 :         gfc_clear_new_st ();
    6777              : 
    6778          275 :       variant = variant->next;
    6779              :     }
    6780              : 
    6781          127 :   if (saw_error)
    6782              :     {
    6783            6 :       if (omp_st == ST_OMP_METADIRECTIVE)
    6784            2 :         gfc_error_now ("Variants in a metadirective at %L have "
    6785              :                        "different associations; "
    6786              :                        "consider using a BLOCK construct "
    6787              :                        "or BEGIN/END METADIRECTIVE", &body_locus);
    6788              :       else
    6789            4 :         gfc_error_now ("Variants in a metadirective at %L have "
    6790              :                        "different associations; "
    6791              :                        "consider using a BLOCK construct", &body_locus);
    6792              :     }
    6793              : 
    6794          127 :   return next_st;
    6795              : }
    6796              : 
    6797              : /* Accept a series of executable statements.  We return the first
    6798              :    statement that doesn't fit to the caller.  Any block statements are
    6799              :    passed on to the correct handler, which usually passes the buck
    6800              :    right back here.  */
    6801              : 
    6802              : static gfc_statement
    6803       157598 : parse_executable (gfc_statement st)
    6804              : {
    6805       157598 :   int close_flag;
    6806       157598 :   bool one_stmt_p = false;
    6807       157598 :   in_exec_part = true;
    6808              : 
    6809       157598 :   if (st == ST_NONE)
    6810        72174 :     st = next_statement ();
    6811              : 
    6812       922597 :   for (;;)
    6813              :     {
    6814              :       /* Only parse one statement for the form of metadirective without
    6815              :          an explicit begin..end.  */
    6816       922597 :       if (gfc_state_stack->state == COMP_OMP_METADIRECTIVE && one_stmt_p)
    6817              :         return st;
    6818       922541 :       one_stmt_p = true;
    6819              : 
    6820       922541 :       close_flag = check_do_closure ();
    6821       922541 :       if (close_flag)
    6822         1717 :         switch (st)
    6823              :           {
    6824            0 :           case ST_GOTO:
    6825            0 :           case ST_END_PROGRAM:
    6826            0 :           case ST_RETURN:
    6827            0 :           case ST_EXIT:
    6828            0 :           case ST_END_FUNCTION:
    6829            0 :           case ST_CYCLE:
    6830            0 :           case ST_PAUSE:
    6831            0 :           case ST_STOP:
    6832            0 :           case ST_ERROR_STOP:
    6833            0 :           case ST_END_SUBROUTINE:
    6834            0 :           case ST_END_TEAM:
    6835              : 
    6836            0 :           case ST_DO:
    6837            0 :           case ST_FORALL:
    6838            0 :           case ST_WHERE:
    6839            0 :           case ST_SELECT_CASE:
    6840            0 :             gfc_error ("%s statement at %C cannot terminate a non-block "
    6841              :                        "DO loop", gfc_ascii_statement (st));
    6842            0 :             break;
    6843              : 
    6844              :           default:
    6845              :             break;
    6846              :           }
    6847              : 
    6848       922541 :       switch (st)
    6849              :         {
    6850           12 :         case ST_NONE:
    6851           12 :           unexpected_eof ();
    6852              : 
    6853           23 :         case ST_DATA:
    6854           23 :           gfc_notify_std (GFC_STD_F95_OBS, "DATA statement at %C after the "
    6855              :                           "first executable statement");
    6856              :           /* Fall through.  */
    6857              : 
    6858       692603 :         case ST_FORMAT:
    6859       692603 :         case ST_ENTRY:
    6860       692603 :         case_executable:
    6861       692603 :           accept_statement (st);
    6862       692603 :           if (close_flag == 1)
    6863              :             return ST_IMPLIED_ENDDO;
    6864              :           break;
    6865              : 
    6866         1138 :         case ST_BLOCK:
    6867         1138 :           parse_block_construct ();
    6868         1138 :           break;
    6869              : 
    6870         1814 :         case ST_ASSOCIATE:
    6871         1814 :           parse_associate ();
    6872         1814 :           break;
    6873              : 
    6874          131 :         case ST_CHANGE_TEAM:
    6875          131 :           parse_change_team ();
    6876          131 :           break;
    6877              : 
    6878        15119 :         case ST_IF_BLOCK:
    6879        15119 :           parse_if_block ();
    6880        15119 :           break;
    6881              : 
    6882          558 :         case ST_SELECT_CASE:
    6883          558 :           parse_select_block ();
    6884          558 :           break;
    6885              : 
    6886         3342 :         case ST_SELECT_TYPE:
    6887         3342 :           parse_select_type_block ();
    6888         3342 :           break;
    6889              : 
    6890         1060 :         case ST_SELECT_RANK:
    6891         1060 :           parse_select_rank_block ();
    6892         1060 :           break;
    6893              : 
    6894        23656 :         case ST_DO:
    6895        23656 :           parse_do_block ();
    6896        23654 :           if (check_do_closure () == 1)
    6897              :             return ST_IMPLIED_ENDDO;
    6898              :           break;
    6899              : 
    6900           54 :         case ST_CRITICAL:
    6901           54 :           parse_critical_block ();
    6902           54 :           break;
    6903              : 
    6904          279 :         case ST_WHERE_BLOCK:
    6905          279 :           parse_where_block ();
    6906          279 :           break;
    6907              : 
    6908          417 :         case ST_FORALL_BLOCK:
    6909          417 :           parse_forall_block ();
    6910          417 :           break;
    6911              : 
    6912         5272 :         case ST_OACC_PARALLEL_LOOP:
    6913         5272 :         case ST_OACC_KERNELS_LOOP:
    6914         5272 :         case ST_OACC_SERIAL_LOOP:
    6915         5272 :         case ST_OACC_LOOP:
    6916         5272 :           st = parse_oacc_loop (st);
    6917         5272 :           if (st == ST_IMPLIED_ENDDO)
    6918              :             return st;
    6919         5272 :           continue;
    6920              : 
    6921         4847 :         case ST_OACC_PARALLEL:
    6922         4847 :         case ST_OACC_KERNELS:
    6923         4847 :         case ST_OACC_SERIAL:
    6924         4847 :         case ST_OACC_DATA:
    6925         4847 :         case ST_OACC_HOST_DATA:
    6926         4847 :           parse_oacc_structured_block (st);
    6927         4847 :           break;
    6928              : 
    6929           74 :         case ST_OMP_ALLOCATE_EXEC:
    6930           74 :         case ST_OMP_ALLOCATORS:
    6931           74 :           st = parse_openmp_allocate_block (st);
    6932           74 :           continue;
    6933              : 
    6934         8886 :         case_omp_structured_block:
    6935        17758 :           st = parse_omp_structured_block (st,
    6936         8886 :                                            st == ST_OMP_WORKSHARE
    6937         8886 :                                            || st == ST_OMP_PARALLEL_WORKSHARE);
    6938         8872 :           continue;
    6939              : 
    6940         4981 :         case_omp_do:
    6941         4981 :           st = parse_omp_do (st, 0);
    6942         4979 :           if (st == ST_IMPLIED_ENDDO)
    6943              :             return st;
    6944         4977 :           continue;
    6945              : 
    6946          543 :         case ST_OACC_ATOMIC:
    6947          543 :           st = parse_omp_oacc_atomic (false);
    6948          543 :           continue;
    6949              : 
    6950         2152 :         case ST_OMP_ATOMIC:
    6951         2152 :           st = parse_omp_oacc_atomic (true);
    6952         2152 :           continue;
    6953              : 
    6954          153 :         case ST_OMP_DISPATCH:
    6955          153 :           st = parse_omp_dispatch ();
    6956          153 :           continue;
    6957              : 
    6958          128 :         case ST_OMP_METADIRECTIVE:
    6959          128 :         case ST_OMP_BEGIN_METADIRECTIVE:
    6960          128 :           st = parse_omp_metadirective_body (st);
    6961          127 :           continue;
    6962              : 
    6963           62 :         case ST_OMP_END_METADIRECTIVE:
    6964           62 :           if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE)
    6965           30 :             return next_statement ();
    6966              :           else
    6967              :             return st;
    6968              : 
    6969              :         default:
    6970              :           return st;
    6971              :         }
    6972              : 
    6973       742830 :       if (directive_unroll != -1)
    6974            1 :         gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
    6975              : 
    6976       742830 :       if (directive_ivdep)
    6977            0 :         gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
    6978              : 
    6979       742830 :       if (directive_vector)
    6980            0 :         gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
    6981              : 
    6982       742830 :       if (directive_novector)
    6983            0 :         gfc_error ("%<GCC novector%> "
    6984              :                    "directive not at the start of a loop at %C");
    6985              : 
    6986       742830 :       st = next_statement ();
    6987              :     }
    6988              : }
    6989              : 
    6990              : 
    6991              : /* Update statement function formal argument lists that reference OLD_SYM
    6992              :    to point to NEW_SYM instead.  This prevents use-after-free when
    6993              :    gfc_fixup_sibling_symbols replaces and frees a symbol that is also
    6994              :    used as a statement function dummy argument (PR95879).  */
    6995              : 
    6996              : static void
    6997        81480 : fixup_st_func_formals (gfc_symtree *st, gfc_symbol *old_sym,
    6998              :                        gfc_symbol *new_sym)
    6999              : {
    7000        81480 :   if (st == NULL)
    7001              :     return;
    7002              : 
    7003        38975 :   fixup_st_func_formals (st->left, old_sym, new_sym);
    7004        38975 :   fixup_st_func_formals (st->right, old_sym, new_sym);
    7005              : 
    7006        38975 :   if (st->n.sym && st->n.sym->attr.proc == PROC_ST_FUNCTION)
    7007            4 :     for (gfc_formal_arglist *fa = st->n.sym->formal; fa; fa = fa->next)
    7008            2 :       if (fa->sym == old_sym)
    7009            2 :         fa->sym = new_sym;
    7010              : }
    7011              : 
    7012              : 
    7013              : /* Fix the symbols for sibling functions.  These are incorrectly added to
    7014              :    the child namespace as the parser didn't know about this procedure.  */
    7015              : 
    7016              : static void
    7017       210705 : gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings)
    7018              : {
    7019       210705 :   gfc_namespace *ns;
    7020       210705 :   gfc_symtree *st;
    7021       210705 :   gfc_symbol *old_sym;
    7022       210705 :   bool imported;
    7023              : 
    7024       382085 :   for (ns = siblings; ns; ns = ns->sibling)
    7025              :     {
    7026       171380 :       st = gfc_find_symtree (ns->sym_root, sym->name);
    7027              : 
    7028       171380 :       if (!st || (st->n.sym->attr.dummy && ns == st->n.sym->ns))
    7029       128543 :         goto fixup_contained;
    7030              : 
    7031        42837 :       if ((st->n.sym->attr.flavor == FL_DERIVED
    7032            0 :            && sym->attr.generic && sym->attr.function)
    7033        42837 :           ||(sym->attr.flavor == FL_DERIVED
    7034            0 :              && st->n.sym->attr.generic && st->n.sym->attr.function))
    7035            0 :         goto fixup_contained;
    7036              : 
    7037        42837 :       old_sym = st->n.sym;
    7038        42837 :       imported = old_sym->attr.imported == 1;
    7039        42837 :       if (old_sym->ns == ns
    7040         3754 :             && !old_sym->attr.contained
    7041              : 
    7042              :             /* By 14.6.1.3, host association should be excluded
    7043              :                for the following.  */
    7044         3739 :             && !(old_sym->attr.external
    7045         3739 :                   || (old_sym->ts.type != BT_UNKNOWN
    7046          193 :                         && !old_sym->attr.implicit_type)
    7047         3547 :                   || old_sym->attr.flavor == FL_PARAMETER
    7048         3547 :                   || old_sym->attr.use_assoc
    7049         3540 :                   || old_sym->attr.in_common
    7050         3540 :                   || old_sym->attr.in_equivalence
    7051         3540 :                   || old_sym->attr.data
    7052         3540 :                   || old_sym->attr.dummy
    7053         3540 :                   || old_sym->attr.result
    7054         3540 :                   || old_sym->attr.dimension
    7055         3540 :                   || old_sym->attr.allocatable
    7056         3540 :                   || old_sym->attr.intrinsic
    7057         3540 :                   || old_sym->attr.generic
    7058         3532 :                   || old_sym->attr.flavor == FL_NAMELIST
    7059         3531 :                   || old_sym->attr.flavor == FL_LABEL
    7060         3530 :                   || old_sym->attr.proc == PROC_ST_FUNCTION))
    7061              :         {
    7062              :           /* Replace it with the symbol from the parent namespace.  */
    7063         3530 :           st->n.sym = sym;
    7064         3530 :           sym->refs++;
    7065         3530 :           if (imported)
    7066            1 :             sym->attr.imported = 1;
    7067              : 
    7068              :           /* Update statement function formal argument lists that still
    7069              :              reference old_sym before releasing it (PR95879).  */
    7070         3530 :           fixup_st_func_formals (ns->sym_root, old_sym, sym);
    7071              : 
    7072         3530 :           gfc_release_symbol (old_sym);
    7073              :         }
    7074              : 
    7075        39307 : fixup_contained:
    7076              :       /* Do the same for any contained procedures.  */
    7077       171380 :       gfc_fixup_sibling_symbols (sym, ns->contained);
    7078              :     }
    7079       210705 : }
    7080              : 
    7081              : static void
    7082        16015 : parse_contained (int module)
    7083              : {
    7084        16015 :   gfc_namespace *ns, *parent_ns, *tmp;
    7085        16015 :   gfc_state_data s1, s2;
    7086        16015 :   gfc_statement st;
    7087        16015 :   gfc_symbol *sym;
    7088        16015 :   gfc_entry_list *el;
    7089        16015 :   locus old_loc;
    7090        16015 :   int contains_statements = 0;
    7091        16015 :   int seen_error = 0;
    7092              : 
    7093        16015 :   push_state (&s1, COMP_CONTAINS, NULL);
    7094        16015 :   parent_ns = gfc_current_ns;
    7095              : 
    7096        55084 :   do
    7097              :     {
    7098        55084 :       gfc_current_ns = gfc_get_namespace (parent_ns, 1);
    7099              : 
    7100        55084 :       gfc_current_ns->sibling = parent_ns->contained;
    7101        55084 :       parent_ns->contained = gfc_current_ns;
    7102              : 
    7103        55109 :  next:
    7104              :       /* Process the next available statement.  We come here if we got an error
    7105              :          and rejected the last statement.  */
    7106        55109 :       old_loc = gfc_current_locus;
    7107        55109 :       st = next_statement ();
    7108              : 
    7109        55109 :       switch (st)
    7110              :         {
    7111            1 :         case ST_NONE:
    7112            1 :           unexpected_eof ();
    7113              : 
    7114        39071 :         case ST_FUNCTION:
    7115        39071 :         case ST_SUBROUTINE:
    7116        39071 :           contains_statements = 1;
    7117        39071 :           accept_statement (st);
    7118              : 
    7119        66951 :           push_state (&s2,
    7120              :                       (st == ST_FUNCTION) ? COMP_FUNCTION : COMP_SUBROUTINE,
    7121              :                       gfc_new_block);
    7122              : 
    7123              :           /* For internal procedures, create/update the symbol in the
    7124              :              parent namespace.  */
    7125              : 
    7126        39071 :           if (!module)
    7127              :             {
    7128        20505 :               if (gfc_get_symbol (gfc_new_block->name, parent_ns, &sym))
    7129            0 :                 gfc_error ("Contained procedure %qs at %C is already "
    7130              :                            "ambiguous", gfc_new_block->name);
    7131              :               else
    7132              :                 {
    7133        20505 :                   if (gfc_add_procedure (&sym->attr, PROC_INTERNAL,
    7134              :                                          sym->name,
    7135        20505 :                                          &gfc_new_block->declared_at))
    7136              :                     {
    7137        20504 :                       if (st == ST_FUNCTION)
    7138         4793 :                         gfc_add_function (&sym->attr, sym->name,
    7139         4793 :                                           &gfc_new_block->declared_at);
    7140              :                       else
    7141        15711 :                         gfc_add_subroutine (&sym->attr, sym->name,
    7142        15711 :                                             &gfc_new_block->declared_at);
    7143              :                     }
    7144              :                 }
    7145              : 
    7146        20505 :               gfc_commit_symbols ();
    7147              :             }
    7148              :           else
    7149        18566 :             sym = gfc_new_block;
    7150              : 
    7151              :           /* Mark this as a contained function, so it isn't replaced
    7152              :              by other module functions.  */
    7153        39071 :           sym->attr.contained = 1;
    7154              : 
    7155              :           /* Set implicit_pure so that it can be reset if any of the
    7156              :              tests for purity fail.  This is used for some optimisation
    7157              :              during translation.  */
    7158        39071 :           if (!sym->attr.pure)
    7159        36505 :             sym->attr.implicit_pure = 1;
    7160              : 
    7161        39071 :           parse_progunit (ST_NONE);
    7162              : 
    7163              :           /* Fix up any sibling functions that refer to this one.  */
    7164        39069 :           gfc_fixup_sibling_symbols (sym, gfc_current_ns);
    7165              :           /* Or refer to any of its alternate entry points.  */
    7166        39325 :           for (el = gfc_current_ns->entries; el; el = el->next)
    7167          256 :             gfc_fixup_sibling_symbols (el->sym, gfc_current_ns);
    7168              : 
    7169        39069 :           gfc_current_ns->code = s2.head;
    7170        39069 :           gfc_current_ns = parent_ns;
    7171              : 
    7172        39069 :           pop_state ();
    7173        39069 :           break;
    7174              : 
    7175              :         /* These statements are associated with the end of the host unit.  */
    7176        16012 :         case ST_END_FUNCTION:
    7177        16012 :         case ST_END_MODULE:
    7178        16012 :         case ST_END_SUBMODULE:
    7179        16012 :         case ST_END_PROGRAM:
    7180        16012 :         case ST_END_SUBROUTINE:
    7181        16012 :           accept_statement (st);
    7182        16012 :           gfc_current_ns->code = s1.head;
    7183        16012 :           break;
    7184              : 
    7185           25 :         default:
    7186           25 :           gfc_error ("Unexpected %s statement in CONTAINS section at %C",
    7187              :                      gfc_ascii_statement (st));
    7188           25 :           reject_statement ();
    7189           25 :           seen_error = 1;
    7190           25 :           goto next;
    7191        55081 :           break;
    7192              :         }
    7193              :     }
    7194        55081 :   while (st != ST_END_FUNCTION && st != ST_END_SUBROUTINE
    7195        54166 :          && st != ST_END_MODULE && st != ST_END_SUBMODULE
    7196       101400 :          && st != ST_END_PROGRAM);
    7197              : 
    7198              :   /* The first namespace in the list is guaranteed to not have
    7199              :      anything (worthwhile) in it.  */
    7200        16012 :   tmp = gfc_current_ns;
    7201        16012 :   gfc_current_ns = parent_ns;
    7202        16012 :   if (seen_error && tmp->refs > 1)
    7203            0 :     gfc_free_namespace (tmp);
    7204              : 
    7205        16012 :   ns = gfc_current_ns->contained;
    7206        16012 :   gfc_current_ns->contained = ns->sibling;
    7207        16012 :   gfc_free_namespace (ns);
    7208              : 
    7209        16012 :   pop_state ();
    7210        16012 :   if (!contains_statements)
    7211           68 :     gfc_notify_std (GFC_STD_F2008, "CONTAINS statement without "
    7212              :                     "FUNCTION or SUBROUTINE statement at %L", &old_loc);
    7213        16012 : }
    7214              : 
    7215              : 
    7216              : /* The result variable in a MODULE PROCEDURE needs to be created and
    7217              :     its characteristics copied from the interface since it is neither
    7218              :     declared in the procedure declaration nor in the specification
    7219              :     part.  */
    7220              : 
    7221              : static void
    7222          134 : get_modproc_result (void)
    7223              : {
    7224          134 :   gfc_symbol *proc;
    7225          134 :   if (gfc_state_stack->previous
    7226          134 :       && gfc_state_stack->previous->state == COMP_CONTAINS
    7227          134 :       && gfc_state_stack->previous->previous->state == COMP_SUBMODULE)
    7228              :     {
    7229          102 :       proc = gfc_current_ns->proc_name ? gfc_current_ns->proc_name : NULL;
    7230          102 :       if (proc != NULL
    7231          102 :           && proc->attr.function
    7232          102 :           && proc->tlink
    7233          102 :           && proc->tlink->result
    7234          102 :           && proc->tlink->result != proc->tlink)
    7235              :         {
    7236           65 :           gfc_copy_dummy_sym (&proc->result, proc->tlink->result, 1);
    7237           65 :           gfc_set_sym_referenced (proc->result);
    7238           65 :           proc->result->attr.if_source = IFSRC_DECL;
    7239           65 :           gfc_commit_symbol (proc->result);
    7240              :         }
    7241              :     }
    7242          134 : }
    7243              : 
    7244              : 
    7245              : /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct.  */
    7246              : 
    7247              : static void
    7248        81002 : parse_progunit (gfc_statement st)
    7249              : {
    7250        81002 :   gfc_state_data *p;
    7251        81002 :   int n;
    7252              : 
    7253        81002 :   gfc_adjust_builtins ();
    7254              : 
    7255        81002 :   if (gfc_new_block
    7256        72068 :       && gfc_new_block->abr_modproc_decl
    7257          282 :       && gfc_new_block->attr.function)
    7258          134 :     get_modproc_result ();
    7259              : 
    7260        81002 :   st = parse_spec (st);
    7261        80983 :   switch (st)
    7262              :     {
    7263              :     case ST_NONE:
    7264              :       unexpected_eof ();
    7265              : 
    7266          195 :     case ST_CONTAINS:
    7267              :       /* This is not allowed within BLOCK!  */
    7268          195 :       if (gfc_current_state () != COMP_BLOCK)
    7269          194 :         goto contains;
    7270              :       break;
    7271              : 
    7272         4777 :     case_end:
    7273         4777 :       accept_statement (st);
    7274         4777 :       goto done;
    7275              : 
    7276              :     default:
    7277              :       break;
    7278              :     }
    7279              : 
    7280        76012 :   if (gfc_current_state () == COMP_FUNCTION)
    7281        13542 :     gfc_check_function_type (gfc_current_ns);
    7282              : 
    7283        76012 : loop:
    7284        76255 :   for (;;)
    7285              :     {
    7286        76255 :       st = parse_executable (st);
    7287              : 
    7288        76229 :       switch (st)
    7289              :         {
    7290            0 :         case ST_NONE:
    7291            0 :           unexpected_eof ();
    7292              : 
    7293         7975 :         case ST_CONTAINS:
    7294              :           /* This is not allowed within BLOCK!  */
    7295         7975 :           if (gfc_current_state () != COMP_BLOCK)
    7296         7973 :             goto contains;
    7297              :           break;
    7298              : 
    7299        68013 :         case_end:
    7300        68013 :           accept_statement (st);
    7301        68013 :           goto done;
    7302              : 
    7303              :         /* Specification statements cannot appear after executable statements.  */
    7304           37 :         case_decl:
    7305           37 :         case_omp_decl:
    7306           37 :           gfc_error ("%s statement at %C cannot appear after executable statements",
    7307              :                      gfc_ascii_statement (st));
    7308           37 :           reject_statement ();
    7309           37 :           st = next_statement ();
    7310           37 :           continue;
    7311              : 
    7312              :         default:
    7313              :           break;
    7314              :         }
    7315              : 
    7316          206 :       unexpected_statement (st);
    7317          206 :       reject_statement ();
    7318          206 :       st = next_statement ();
    7319              :     }
    7320              : 
    7321         8167 : contains:
    7322         8167 :   n = 0;
    7323              : 
    7324        25123 :   for (p = gfc_state_stack; p; p = p->previous)
    7325        16956 :     if (p->state == COMP_CONTAINS)
    7326          311 :       n++;
    7327              : 
    7328         8167 :   if (gfc_find_state (COMP_MODULE) == true
    7329         8167 :       || gfc_find_state (COMP_SUBMODULE) == true)
    7330          311 :     n--;
    7331              : 
    7332         8167 :   if (n > 0)
    7333              :     {
    7334            0 :       gfc_error ("CONTAINS statement at %C is already in a contained "
    7335              :                  "program unit");
    7336            0 :       reject_statement ();
    7337            0 :       st = next_statement ();
    7338            0 :       goto loop;
    7339              :     }
    7340              : 
    7341         8167 :   parse_contained (0);
    7342              : 
    7343        80955 : done:
    7344        80955 :   gfc_current_ns->code = gfc_state_stack->head;
    7345        80955 : }
    7346              : 
    7347              : 
    7348              : /* Come here to complain about a global symbol already in use as
    7349              :    something else.  */
    7350              : 
    7351              : void
    7352           19 : gfc_global_used (gfc_gsymbol *sym, locus *where)
    7353              : {
    7354           19 :   const char *name;
    7355              : 
    7356           19 :   if (where == NULL)
    7357            0 :     where = &gfc_current_locus;
    7358              : 
    7359           19 :   switch(sym->type)
    7360              :     {
    7361              :     case GSYM_PROGRAM:
    7362              :       name = "PROGRAM";
    7363              :       break;
    7364            4 :     case GSYM_FUNCTION:
    7365            4 :       name = "FUNCTION";
    7366            4 :       break;
    7367            8 :     case GSYM_SUBROUTINE:
    7368            8 :       name = "SUBROUTINE";
    7369            8 :       break;
    7370            3 :     case GSYM_COMMON:
    7371            3 :       name = "COMMON";
    7372            3 :       break;
    7373            0 :     case GSYM_BLOCK_DATA:
    7374            0 :       name = "BLOCK DATA";
    7375            0 :       break;
    7376            2 :     case GSYM_MODULE:
    7377            2 :       name = "MODULE";
    7378            2 :       break;
    7379            1 :     default:
    7380            1 :       name = NULL;
    7381              :     }
    7382              : 
    7383           17 :   if (name)
    7384              :     {
    7385           18 :       if (sym->binding_label)
    7386            3 :         gfc_error ("Global binding name %qs at %L is already being used "
    7387              :                    "as a %s at %L", sym->binding_label, where, name,
    7388              :                    &sym->where);
    7389              :       else
    7390           15 :         gfc_error ("Global name %qs at %L is already being used as "
    7391              :                    "a %s at %L", sym->name, where, name, &sym->where);
    7392              :     }
    7393              :   else
    7394              :     {
    7395            1 :       if (sym->binding_label)
    7396            1 :         gfc_error ("Global binding name %qs at %L is already being used "
    7397              :                    "at %L", sym->binding_label, where, &sym->where);
    7398              :       else
    7399            0 :         gfc_error ("Global name %qs at %L is already being used at %L",
    7400              :                    sym->name, where, &sym->where);
    7401              :     }
    7402           19 : }
    7403              : 
    7404              : 
    7405              : /* Parse a block data program unit.  */
    7406              : 
    7407              : static void
    7408           87 : parse_block_data (void)
    7409              : {
    7410           87 :   gfc_statement st;
    7411           87 :   static locus blank_locus;
    7412           87 :   static int blank_block=0;
    7413           87 :   gfc_gsymbol *s;
    7414              : 
    7415           87 :   gfc_current_ns->proc_name = gfc_new_block;
    7416           87 :   gfc_current_ns->is_block_data = 1;
    7417              : 
    7418           87 :   if (gfc_new_block == NULL)
    7419              :     {
    7420           49 :       if (blank_block)
    7421            0 :        gfc_error ("Blank BLOCK DATA at %C conflicts with "
    7422              :                   "prior BLOCK DATA at %L", &blank_locus);
    7423              :       else
    7424              :        {
    7425           49 :          blank_block = 1;
    7426           49 :          blank_locus = gfc_current_locus;
    7427              :        }
    7428              :     }
    7429              :   else
    7430              :     {
    7431           38 :       s = gfc_get_gsymbol (gfc_new_block->name, false);
    7432           38 :       if (s->defined
    7433           38 :           || (s->type != GSYM_UNKNOWN && s->type != GSYM_BLOCK_DATA))
    7434            0 :        gfc_global_used (s, &gfc_new_block->declared_at);
    7435              :       else
    7436              :        {
    7437           38 :          s->type = GSYM_BLOCK_DATA;
    7438           38 :          s->where = gfc_new_block->declared_at;
    7439           38 :          s->defined = 1;
    7440              :        }
    7441              :     }
    7442              : 
    7443           87 :   st = parse_spec (ST_NONE);
    7444              : 
    7445          174 :   while (st != ST_END_BLOCK_DATA)
    7446              :     {
    7447            1 :       gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
    7448              :                  gfc_ascii_statement (st));
    7449            1 :       reject_statement ();
    7450            1 :       st = next_statement ();
    7451              :     }
    7452           86 : }
    7453              : 
    7454              : 
    7455              : /* Following the association of the ancestor (sub)module symbols, they
    7456              :    must be set host rather than use associated and all must be public.
    7457              :    They are flagged up by 'used_in_submodule' so that they can be set
    7458              :    DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl).  Otherwise the
    7459              :    linker chokes on multiple symbol definitions.  */
    7460              : 
    7461              : static void
    7462         2728 : set_syms_host_assoc (gfc_symbol *sym)
    7463              : {
    7464         2728 :   gfc_component *c;
    7465         2728 :   const char dot[2] = ".";
    7466              :   /* Symbols take the form module.submodule_ or module.name_. */
    7467         2728 :   char parent1[2 * GFC_MAX_SYMBOL_LEN + 2];
    7468         2728 :   char parent2[2 * GFC_MAX_SYMBOL_LEN + 2];
    7469              : 
    7470         2728 :   if (sym == NULL)
    7471            0 :     return;
    7472              : 
    7473         2728 :   if (sym->attr.module_procedure)
    7474          651 :     sym->attr.external = 0;
    7475              : 
    7476         2728 :   sym->attr.use_assoc = 0;
    7477         2728 :   sym->attr.host_assoc = 1;
    7478         2728 :   sym->attr.used_in_submodule =1;
    7479              : 
    7480         2728 :   if (sym->attr.flavor == FL_DERIVED)
    7481              :     {
    7482              :       /* Derived types with PRIVATE components that are declared in
    7483              :          modules other than the parent module must not be changed to be
    7484              :          PUBLIC. The 'use-assoc' attribute must be reset so that the
    7485              :          test in symbol.cc(gfc_find_component) works correctly. This is
    7486              :          not necessary for PRIVATE symbols since they are not read from
    7487              :          the module.  */
    7488          525 :       memset(parent1, '\0', sizeof(parent1));
    7489          525 :       memset(parent2, '\0', sizeof(parent2));
    7490          525 :       strcpy (parent1, gfc_new_block->name);
    7491          525 :       strcpy (parent2, sym->module);
    7492          525 :       if (strcmp (strtok (parent1, dot), strtok (parent2, dot)) == 0)
    7493              :         {
    7494         2409 :           for (c = sym->components; c; c = c->next)
    7495         1933 :             c->attr.access = ACCESS_PUBLIC;
    7496              :         }
    7497              :       else
    7498              :         {
    7499           49 :           sym->attr.use_assoc = 1;
    7500           49 :           sym->attr.host_assoc = 0;
    7501              :         }
    7502              :     }
    7503              : }
    7504              : 
    7505              : /* Parse a module subprogram.  */
    7506              : 
    7507              : static void
    7508        10705 : parse_module (void)
    7509              : {
    7510        10705 :   gfc_statement st;
    7511        10705 :   gfc_gsymbol *s;
    7512              : 
    7513        10705 :   s = gfc_get_gsymbol (gfc_new_block->name, false);
    7514        10705 :   if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE))
    7515            1 :     gfc_global_used (s, &gfc_new_block->declared_at);
    7516              :   else
    7517              :     {
    7518        10704 :       s->type = GSYM_MODULE;
    7519        10704 :       s->where = gfc_new_block->declared_at;
    7520        10704 :       s->defined = 1;
    7521              :     }
    7522              : 
    7523              :   /* Something is nulling the module_list after this point. This is good
    7524              :      since it allows us to 'USE' the parent modules that the submodule
    7525              :      inherits and to set (most) of the symbols as host associated.  */
    7526        10705 :   if (gfc_current_state () == COMP_SUBMODULE)
    7527              :     {
    7528          273 :       use_modules ();
    7529          272 :       gfc_traverse_ns (gfc_current_ns, set_syms_host_assoc);
    7530              : 
    7531              :       /* Link the submodule namespace to the parent (sub)module namespace so
    7532              :          that internal subprograms of the ancestor module are accessible via
    7533              :          host association (Fortran 2018, 14.6.1.3).  The parent namespace is
    7534              :          already in gfc_global_ns_list when both units are compiled together.
    7535              :          The submodule's fully-qualified name is "parent.child"; strip the
    7536              :          child part to obtain the parent's name, then search the global list.  */
    7537          272 :       {
    7538          272 :         const char *submod_name = gfc_new_block->name;
    7539          272 :         const char *dot = strrchr (submod_name, '.');
    7540          272 :         if (dot != NULL)
    7541              :           {
    7542          272 :             size_t plen = (size_t) (dot - submod_name);
    7543          272 :             char parent_name[GFC_MAX_SYMBOL_LEN + 1];
    7544          272 :             gcc_assert (plen < sizeof (parent_name));
    7545          272 :             memcpy (parent_name, submod_name, plen);
    7546          272 :             parent_name[plen] = '\0';
    7547          365 :             for (gfc_namespace *ns = gfc_global_ns_list; ns; ns = ns->sibling)
    7548          344 :               if (ns->proc_name
    7549          344 :                   && strcmp (ns->proc_name->name, parent_name) == 0)
    7550              :                 {
    7551          251 :                   gfc_current_ns->parent = ns;
    7552          251 :                   break;
    7553              :                 }
    7554              :           }
    7555              :       }
    7556              :     }
    7557              : 
    7558        10704 :   st = parse_spec (ST_NONE);
    7559              : 
    7560        10706 : loop:
    7561        10706 :   switch (st)
    7562              :     {
    7563            0 :     case ST_NONE:
    7564            0 :       unexpected_eof ();
    7565              : 
    7566         7848 :     case ST_CONTAINS:
    7567         7848 :       parse_contained (1);
    7568         7848 :       break;
    7569              : 
    7570         2855 :     case ST_END_MODULE:
    7571         2855 :     case ST_END_SUBMODULE:
    7572         2855 :       accept_statement (st);
    7573         2855 :       break;
    7574              : 
    7575            3 :     default:
    7576            3 :       gfc_error ("Unexpected %s statement in MODULE at %C",
    7577              :                  gfc_ascii_statement (st));
    7578            3 :       reject_statement ();
    7579            3 :       st = next_statement ();
    7580            3 :       goto loop;
    7581              :     }
    7582        10702 :   s->ns = gfc_current_ns;
    7583        10702 : }
    7584              : 
    7585              : 
    7586              : /* Add a procedure name to the global symbol table.  */
    7587              : 
    7588              : static void
    7589        11835 : add_global_procedure (bool sub)
    7590              : {
    7591        11835 :   gfc_gsymbol *s;
    7592              : 
    7593              :   /* Only in Fortran 2003: For procedures with a binding label also the Fortran
    7594              :      name is a global identifier.  */
    7595        11835 :   if (!gfc_new_block->binding_label || gfc_notification_std (GFC_STD_F2008))
    7596              :     {
    7597        11429 :       s = gfc_get_gsymbol (gfc_new_block->name, false);
    7598              : 
    7599        11429 :       if (s->defined
    7600        11427 :           || (s->type != GSYM_UNKNOWN
    7601          100 :               && s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION)))
    7602              :         {
    7603            2 :           gfc_global_used (s, &gfc_new_block->declared_at);
    7604              :           /* Silence follow-up errors.  */
    7605            2 :           gfc_new_block->binding_label = NULL;
    7606              :         }
    7607              :       else
    7608              :         {
    7609        11427 :           s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
    7610        11427 :           s->sym_name = gfc_new_block->name;
    7611        11427 :           s->where = gfc_new_block->declared_at;
    7612        11427 :           s->defined = 1;
    7613        11427 :           s->ns = gfc_current_ns;
    7614              :         }
    7615              :     }
    7616              : 
    7617              :   /* Don't add the symbol multiple times.  */
    7618        11835 :   if (gfc_new_block->binding_label
    7619        11835 :       && (!gfc_notification_std (GFC_STD_F2008)
    7620           59 :           || strcmp (gfc_new_block->name, gfc_new_block->binding_label) != 0))
    7621              :     {
    7622          407 :       s = gfc_get_gsymbol (gfc_new_block->binding_label, true);
    7623              : 
    7624          407 :       if (s->defined
    7625          404 :           || (s->type != GSYM_UNKNOWN
    7626            5 :               && s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION)))
    7627              :         {
    7628            3 :           gfc_global_used (s, &gfc_new_block->declared_at);
    7629              :           /* Silence follow-up errors.  */
    7630            3 :           gfc_new_block->binding_label = NULL;
    7631              :         }
    7632              :       else
    7633              :         {
    7634          404 :           s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
    7635          404 :           s->sym_name = gfc_new_block->name;
    7636          404 :           s->binding_label = gfc_new_block->binding_label;
    7637          404 :           s->where = gfc_new_block->declared_at;
    7638          404 :           s->defined = 1;
    7639          404 :           s->ns = gfc_current_ns;
    7640              :         }
    7641              :     }
    7642        11835 : }
    7643              : 
    7644              : 
    7645              : /* Add a program to the global symbol table.  */
    7646              : 
    7647              : static void
    7648        20227 : add_global_program (void)
    7649              : {
    7650        20227 :   gfc_gsymbol *s;
    7651              : 
    7652        20227 :   if (gfc_new_block == NULL)
    7653              :     return;
    7654        20227 :   s = gfc_get_gsymbol (gfc_new_block->name, false);
    7655              : 
    7656        20227 :   if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_PROGRAM))
    7657            0 :     gfc_global_used (s, &gfc_new_block->declared_at);
    7658              :   else
    7659              :     {
    7660        20227 :       s->type = GSYM_PROGRAM;
    7661        20227 :       s->where = gfc_new_block->declared_at;
    7662        20227 :       s->defined = 1;
    7663        20227 :       s->ns = gfc_current_ns;
    7664              :     }
    7665              : }
    7666              : 
    7667              : /* Rewrite expression where needed.
    7668              :  - Currently this is done for co-indexed expressions only.
    7669              : */
    7670              : static void
    7671          535 : rewrite_expr_tree (gfc_namespace *gfc_global_ns_list)
    7672              : {
    7673         1130 :   for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
    7674          595 :        gfc_current_ns = gfc_current_ns->sibling)
    7675          595 :     gfc_coarray_rewrite (gfc_current_ns);
    7676          535 : }
    7677              : 
    7678              : /* Resolve all the program units.  */
    7679              : static void
    7680        32876 : resolve_all_program_units (gfc_namespace *gfc_global_ns_list)
    7681              : {
    7682        32876 :   gfc_derived_types = NULL;
    7683        32876 :   gfc_current_ns = gfc_global_ns_list;
    7684        81616 :   for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
    7685              :     {
    7686        48741 :       if (gfc_current_ns->proc_name
    7687        48741 :           && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
    7688        10692 :         continue; /* Already resolved.  */
    7689              : 
    7690        38049 :       if (gfc_current_ns->proc_name)
    7691        38049 :         gfc_current_locus = gfc_current_ns->proc_name->declared_at;
    7692        38049 :       gfc_resolve (gfc_current_ns);
    7693        38048 :       gfc_current_ns->derived_types = gfc_derived_types;
    7694        38048 :       gfc_derived_types = NULL;
    7695              :     }
    7696        32875 : }
    7697              : 
    7698              : 
    7699              : static void
    7700       235303 : clean_up_modules (gfc_gsymbol *&gsym)
    7701              : {
    7702       235303 :   if (gsym == NULL)
    7703              :     return;
    7704              : 
    7705       101214 :   clean_up_modules (gsym->left);
    7706       101214 :   clean_up_modules (gsym->right);
    7707              : 
    7708       101214 :   if (gsym->type != GSYM_MODULE)
    7709              :     return;
    7710              : 
    7711        11087 :   if (gsym->ns)
    7712              :     {
    7713        11087 :       gfc_current_ns = gsym->ns;
    7714              :       /* Disconnect any host-association parent link set for submodules
    7715              :          (see parse_module): each module/submodule namespace in gfc_gsym_root
    7716              :          is independently managed, so gfc_symbol_done_2 must not walk up to
    7717              :          and double-free a sibling top-level namespace.  */
    7718        11087 :       gfc_current_ns->parent = NULL;
    7719        11087 :       gfc_derived_types = gfc_current_ns->derived_types;
    7720        11087 :       gfc_done_2 ();
    7721        11087 :       gsym->ns = NULL;
    7722              :     }
    7723        11087 :   free (gsym);
    7724        11087 :   gsym = NULL;
    7725              : }
    7726              : 
    7727              : 
    7728              : /* Translate all the program units. This could be in a different order
    7729              :    to resolution if there are forward references in the file.  */
    7730              : static void
    7731        32875 : translate_all_program_units (gfc_namespace *gfc_global_ns_list)
    7732              : {
    7733        32875 :   int errors;
    7734              : 
    7735        32875 :   gfc_current_ns = gfc_global_ns_list;
    7736        32875 :   gfc_get_errors (NULL, &errors);
    7737              : 
    7738              :   /* We first translate all modules to make sure that later parts
    7739              :      of the program can use the decl. Then we translate the nonmodules.  */
    7740              : 
    7741       113268 :   for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
    7742              :     {
    7743        47518 :       if (!gfc_current_ns->proc_name
    7744        47518 :           || gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
    7745        37678 :         continue;
    7746              : 
    7747         9840 :       gfc_current_locus = gfc_current_ns->proc_name->declared_at;
    7748         9840 :       gfc_derived_types = gfc_current_ns->derived_types;
    7749         9840 :       gfc_generate_module_code (gfc_current_ns);
    7750         9840 :       gfc_current_ns->translated = 1;
    7751              :     }
    7752              : 
    7753        32875 :   gfc_current_ns = gfc_global_ns_list;
    7754        80393 :   for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
    7755              :     {
    7756        47518 :       if (gfc_current_ns->proc_name
    7757        47518 :           && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
    7758         9840 :         continue;
    7759              : 
    7760        37678 :       gfc_current_locus = gfc_current_ns->proc_name->declared_at;
    7761        37678 :       gfc_derived_types = gfc_current_ns->derived_types;
    7762        37678 :       gfc_generate_code (gfc_current_ns);
    7763        37678 :       gfc_current_ns->translated = 1;
    7764              :     }
    7765              : 
    7766              :   /* Clean up all the namespaces after translation.  */
    7767        32875 :   gfc_current_ns = gfc_global_ns_list;
    7768        84318 :   for (;gfc_current_ns;)
    7769              :     {
    7770        51443 :       gfc_namespace *ns;
    7771              : 
    7772        51443 :       if (gfc_current_ns->proc_name
    7773        51443 :           && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
    7774              :         {
    7775        10692 :           gfc_current_ns = gfc_current_ns->sibling;
    7776        10692 :           continue;
    7777              :         }
    7778              : 
    7779        40751 :       ns = gfc_current_ns->sibling;
    7780        40751 :       gfc_derived_types = gfc_current_ns->derived_types;
    7781        40751 :       gfc_done_2 ();
    7782        40751 :       gfc_current_ns = ns;
    7783              :     }
    7784              : 
    7785        32875 :   clean_up_modules (gfc_gsym_root);
    7786        32875 : }
    7787              : 
    7788              : 
    7789              : /* Top level parser.  */
    7790              : 
    7791              : bool
    7792        32921 : gfc_parse_file (void)
    7793              : {
    7794        32921 :   int seen_program, errors_before, errors;
    7795        32921 :   gfc_state_data top, s;
    7796        32921 :   gfc_statement st;
    7797        32921 :   locus prog_locus;
    7798        32921 :   gfc_namespace *next;
    7799              : 
    7800        32921 :   gfc_start_source_files ();
    7801              : 
    7802        32921 :   top.state = COMP_NONE;
    7803        32921 :   top.sym = NULL;
    7804        32921 :   top.previous = NULL;
    7805        32921 :   top.head = top.tail = NULL;
    7806        32921 :   top.do_variable = NULL;
    7807              : 
    7808        32921 :   gfc_state_stack = &top;
    7809              : 
    7810        32921 :   gfc_clear_new_st ();
    7811              : 
    7812        32921 :   gfc_statement_label = NULL;
    7813              : 
    7814        32921 :   gfc_omp_metadirective_region_count = 0;
    7815        32921 :   gfc_omp_metadirective_region_stack.truncate (0);
    7816        32921 :   gfc_omp_metadirective_region_stack.safe_push (0);
    7817        32921 :   gfc_in_omp_metadirective_body = false;
    7818        32921 :   gfc_matching_omp_context_selector = false;
    7819              : 
    7820        32954 :   if (setjmp (eof_buf))
    7821              :     return false;       /* Come here on unexpected EOF */
    7822              : 
    7823              :   /* Prepare the global namespace that will contain the
    7824              :      program units.  */
    7825        32921 :   gfc_global_ns_list = next = NULL;
    7826              : 
    7827        32921 :   seen_program = 0;
    7828        32921 :   errors_before = 0;
    7829              : 
    7830              :   /* Exit early for empty files.  */
    7831        32921 :   if (gfc_at_eof ())
    7832            0 :     goto done;
    7833              : 
    7834        32921 :   in_specification_block = true;
    7835        51545 : loop:
    7836        84466 :   gfc_init_2 ();
    7837        84466 :   st = next_statement ();
    7838        84463 :   switch (st)
    7839              :     {
    7840        32876 :     case ST_NONE:
    7841        32876 :       gfc_done_2 ();
    7842        32876 :       goto done;
    7843              : 
    7844        20228 :     case ST_PROGRAM:
    7845        20228 :       if (seen_program)
    7846            1 :         goto duplicate_main;
    7847        20227 :       seen_program = 1;
    7848        20227 :       prog_locus = gfc_current_locus;
    7849              : 
    7850        20227 :       push_state (&s, COMP_PROGRAM, gfc_new_block);
    7851        20227 :       main_program_symbol (gfc_current_ns, gfc_new_block->name);
    7852        20227 :       accept_statement (st);
    7853        20227 :       add_global_program ();
    7854        20227 :       parse_progunit (ST_NONE);
    7855        20208 :       goto prog_units;
    7856              : 
    7857         8840 :     case ST_SUBROUTINE:
    7858         8840 :       add_global_procedure (true);
    7859         8840 :       push_state (&s, COMP_SUBROUTINE, gfc_new_block);
    7860         8840 :       accept_statement (st);
    7861         8840 :       parse_progunit (ST_NONE);
    7862         8835 :       goto prog_units;
    7863              : 
    7864         2995 :     case ST_FUNCTION:
    7865         2995 :       add_global_procedure (false);
    7866         2995 :       push_state (&s, COMP_FUNCTION, gfc_new_block);
    7867         2995 :       accept_statement (st);
    7868         2995 :       parse_progunit (ST_NONE);
    7869         2995 :       goto prog_units;
    7870              : 
    7871           87 :     case ST_BLOCK_DATA:
    7872           87 :       push_state (&s, COMP_BLOCK_DATA, gfc_new_block);
    7873           87 :       accept_statement (st);
    7874           87 :       parse_block_data ();
    7875              :       break;
    7876              : 
    7877        10432 :     case ST_MODULE:
    7878        10432 :       push_state (&s, COMP_MODULE, gfc_new_block);
    7879        10432 :       accept_statement (st);
    7880              : 
    7881        10432 :       gfc_get_errors (NULL, &errors_before);
    7882        10432 :       parse_module ();
    7883              :       break;
    7884              : 
    7885          273 :     case ST_SUBMODULE:
    7886          273 :       push_state (&s, COMP_SUBMODULE, gfc_new_block);
    7887          273 :       accept_statement (st);
    7888              : 
    7889          273 :       gfc_get_errors (NULL, &errors_before);
    7890          273 :       parse_module ();
    7891              :       break;
    7892              : 
    7893              :     /* Anything else starts a nameless main program block.  */
    7894         8732 :     default:
    7895         8732 :       if (seen_program)
    7896            1 :         goto duplicate_main;
    7897         8731 :       seen_program = 1;
    7898         8731 :       prog_locus = gfc_current_locus;
    7899              : 
    7900         8731 :       push_state (&s, COMP_PROGRAM, gfc_new_block);
    7901         8731 :       main_program_symbol (gfc_current_ns, "MAIN__");
    7902         8731 :       parse_progunit (st);
    7903         8719 :       goto prog_units;
    7904              :     }
    7905              : 
    7906              :   /* Handle the non-program units.  */
    7907        10788 :   gfc_current_ns->code = s.head;
    7908              : 
    7909        10788 :   gfc_resolve (gfc_current_ns);
    7910              : 
    7911              :   /* Fix the implicit_pure attribute for those procedures who should
    7912              :      not have it.  */
    7913        10889 :   while (gfc_fix_implicit_pure (gfc_current_ns))
    7914              :     ;
    7915              : 
    7916              :   /* Dump the parse tree if requested.  */
    7917        10788 :   if (flag_dump_fortran_original)
    7918            0 :     gfc_dump_parse_tree (gfc_current_ns, stdout);
    7919              : 
    7920        10788 :   gfc_get_errors (NULL, &errors);
    7921        10788 :   if (s.state == COMP_MODULE || s.state == COMP_SUBMODULE)
    7922              :     {
    7923        10702 :       gfc_dump_module (s.sym->name, errors_before == errors);
    7924        10702 :       gfc_current_ns->derived_types = gfc_derived_types;
    7925        10702 :       gfc_derived_types = NULL;
    7926        10702 :       goto prog_units;
    7927              :     }
    7928              :   else
    7929              :     {
    7930           86 :       if (errors == 0)
    7931           72 :         gfc_generate_code (gfc_current_ns);
    7932           86 :       pop_state ();
    7933           86 :       gfc_done_2 ();
    7934              :     }
    7935              : 
    7936           86 :   goto loop;
    7937              : 
    7938        51459 : prog_units:
    7939              :   /* The main program and non-contained procedures are put
    7940              :      in the global namespace list, so that they can be processed
    7941              :      later and all their interfaces resolved.  */
    7942        51459 :   gfc_current_ns->code = s.head;
    7943        51459 :   if (next)
    7944              :     {
    7945        18742 :       for (; next->sibling; next = next->sibling)
    7946              :         ;
    7947        18731 :       next->sibling = gfc_current_ns;
    7948              :     }
    7949              :   else
    7950        32728 :     gfc_global_ns_list = gfc_current_ns;
    7951              : 
    7952        51459 :   next = gfc_current_ns;
    7953              : 
    7954        51459 :   pop_state ();
    7955        51459 :   goto loop;
    7956              : 
    7957        32876 : done:
    7958              :   /* Do the resolution.  */
    7959        32876 :   resolve_all_program_units (gfc_global_ns_list);
    7960              : 
    7961        32875 :   if (flag_coarray == GFC_FCOARRAY_LIB)
    7962          535 :     rewrite_expr_tree (gfc_global_ns_list);
    7963              : 
    7964              :   /* Go through all top-level namespaces and unset the implicit_pure
    7965              :      attribute for any procedures that call something not pure or
    7966              :      implicit_pure.  Because the a procedure marked as not implicit_pure
    7967              :      in one sweep may be called by another routine, we repeat this
    7968              :      process until there are no more changes.  */
    7969        32894 :   bool changed;
    7970        32894 :   do
    7971              :     {
    7972        32894 :       changed = false;
    7973        84362 :       for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
    7974        51468 :            gfc_current_ns = gfc_current_ns->sibling)
    7975              :         {
    7976        51468 :           if (gfc_fix_implicit_pure (gfc_current_ns))
    7977           19 :             changed = true;
    7978              :         }
    7979              :     }
    7980              :   while (changed);
    7981              : 
    7982              :   /* Fixup for external procedures and resolve 'omp requires'.  */
    7983        32875 :   int omp_requires;
    7984        32875 :   bool omp_target_seen;
    7985        32875 :   omp_requires = 0;
    7986        32875 :   omp_target_seen = false;
    7987        84318 :   for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
    7988        51443 :        gfc_current_ns = gfc_current_ns->sibling)
    7989              :     {
    7990        51443 :       omp_requires |= gfc_current_ns->omp_requires;
    7991        51443 :       omp_target_seen |= gfc_current_ns->omp_target_seen;
    7992        51443 :       gfc_check_externals (gfc_current_ns);
    7993              :     }
    7994        84318 :   for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
    7995        51443 :        gfc_current_ns = gfc_current_ns->sibling)
    7996        51443 :     gfc_check_omp_requires (gfc_current_ns, omp_requires);
    7997              : 
    7998              :   /* Populate omp_requires_mask (needed for resolving OpenMP
    7999              :      metadirectives and declare variant).  */
    8000        32875 :   switch (omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    8001              :     {
    8002            6 :     case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST:
    8003            6 :       omp_requires_mask
    8004            6 :         = (enum omp_requires) (omp_requires_mask
    8005              :                                | int (OMP_MEMORY_ORDER_SEQ_CST));
    8006            6 :       break;
    8007            3 :     case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL:
    8008            3 :       omp_requires_mask
    8009            3 :         = (enum omp_requires) (omp_requires_mask
    8010              :                                | int (OMP_MEMORY_ORDER_ACQ_REL));
    8011            3 :       break;
    8012            1 :     case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE:
    8013            1 :       omp_requires_mask
    8014            1 :         = (enum omp_requires) (omp_requires_mask
    8015              :                                | int (OMP_MEMORY_ORDER_ACQUIRE));
    8016            1 :       break;
    8017            4 :     case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED:
    8018            4 :       omp_requires_mask
    8019            4 :         = (enum omp_requires) (omp_requires_mask
    8020              :                                | int (OMP_MEMORY_ORDER_RELAXED));
    8021            4 :       break;
    8022            2 :     case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE:
    8023            2 :       omp_requires_mask
    8024            2 :         = (enum omp_requires) (omp_requires_mask
    8025              :                                | int (OMP_MEMORY_ORDER_RELEASE));
    8026            2 :       break;
    8027              :     }
    8028              : 
    8029        32875 :   if (omp_target_seen)
    8030         1032 :     omp_requires_mask = (enum omp_requires) (omp_requires_mask
    8031              :                                              | int (OMP_REQUIRES_TARGET_USED));
    8032        32875 :   if (omp_requires & OMP_REQ_REVERSE_OFFLOAD)
    8033           25 :     omp_requires_mask
    8034           25 :       = (enum omp_requires) (omp_requires_mask
    8035              :                              | int (OMP_REQUIRES_REVERSE_OFFLOAD));
    8036        32875 :   if (omp_requires & OMP_REQ_UNIFIED_ADDRESS)
    8037            5 :     omp_requires_mask
    8038            5 :       = (enum omp_requires) (omp_requires_mask
    8039              :                              | int (OMP_REQUIRES_UNIFIED_ADDRESS));
    8040        32875 :   if (omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
    8041            7 :     omp_requires_mask
    8042            7 :       = (enum omp_requires) (omp_requires_mask
    8043              :                              | int (OMP_REQUIRES_UNIFIED_SHARED_MEMORY));
    8044        32875 :   if (omp_requires & OMP_REQ_SELF_MAPS)
    8045           11 :     omp_requires_mask
    8046           11 :       = (enum omp_requires) (omp_requires_mask | int (OMP_REQUIRES_SELF_MAPS));
    8047        32875 :   if (omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
    8048            7 :     omp_requires_mask
    8049            7 :       = (enum omp_requires) (omp_requires_mask
    8050              :                              | int (OMP_REQUIRES_DYNAMIC_ALLOCATORS));
    8051              :   /* Do the parse tree dump.  */
    8052        32875 :   gfc_current_ns = flag_dump_fortran_original ? gfc_global_ns_list : NULL;
    8053              : 
    8054        32915 :   for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling)
    8055           40 :     if (!gfc_current_ns->proc_name
    8056           40 :         || gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
    8057              :       {
    8058           40 :         gfc_dump_parse_tree (gfc_current_ns, stdout);
    8059           40 :         fputs ("------------------------------------------\n\n", stdout);
    8060              :       }
    8061              : 
    8062              :   /* Dump C prototypes.  */
    8063        32875 :   if (flag_c_prototypes || flag_c_prototypes_external)
    8064              :     {
    8065            2 :       fprintf (stdout,
    8066              :                "#include <stddef.h>\n"
    8067              :                "#ifdef __cplusplus\n"
    8068              :                "#include <complex>\n"
    8069              :                "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
    8070              :                "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
    8071              :                "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
    8072              :                "extern \"C\" {\n"
    8073              :                "#else\n"
    8074              :                "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
    8075              :                "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
    8076              :                "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
    8077              :                "#endif\n\n");
    8078              :     }
    8079              : 
    8080              :   /* First dump BIND(C) prototypes.  */
    8081        32875 :   if (flag_c_prototypes)
    8082            2 :     gfc_dump_c_prototypes (stdout);
    8083              : 
    8084              :   /* Dump external prototypes.  */
    8085        32875 :   if (flag_c_prototypes_external)
    8086            0 :     gfc_dump_external_c_prototypes (stdout);
    8087              : 
    8088        32875 :   if (flag_c_prototypes || flag_c_prototypes_external)
    8089            2 :     fprintf (stdout, "\n#ifdef __cplusplus\n}\n#endif\n");
    8090              : 
    8091              :   /* Do the translation.  */
    8092        32875 :   translate_all_program_units (gfc_global_ns_list);
    8093              : 
    8094              :   /* Dump the global symbol ist.  We only do this here because part
    8095              :      of it is generated after mangling the identifiers in
    8096              :      trans-decl.cc.  */
    8097              : 
    8098        32875 :   if (flag_dump_fortran_global)
    8099            0 :     gfc_dump_global_symbols (stdout);
    8100              : 
    8101        32875 :   gfc_end_source_files ();
    8102              :   return true;
    8103              : 
    8104            2 : duplicate_main:
    8105              :   /* If we see a duplicate main program, shut down.  If the second
    8106              :      instance is an implied main program, i.e. data decls or executable
    8107              :      statements, we're in for lots of errors.  */
    8108            2 :   gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus);
    8109            2 :   reject_statement ();
    8110            2 :   gfc_done_2 ();
    8111              :   return true;
    8112              : }
    8113              : 
    8114              : /* Return true if this state data represents an OpenACC region.  */
    8115              : bool
    8116            7 : is_oacc (gfc_state_data *sd)
    8117              : {
    8118            7 :   switch (sd->construct->op)
    8119              :     {
    8120              :     case EXEC_OACC_PARALLEL_LOOP:
    8121              :     case EXEC_OACC_PARALLEL:
    8122              :     case EXEC_OACC_KERNELS_LOOP:
    8123              :     case EXEC_OACC_KERNELS:
    8124              :     case EXEC_OACC_SERIAL_LOOP:
    8125              :     case EXEC_OACC_SERIAL:
    8126              :     case EXEC_OACC_DATA:
    8127              :     case EXEC_OACC_HOST_DATA:
    8128              :     case EXEC_OACC_LOOP:
    8129              :     case EXEC_OACC_UPDATE:
    8130              :     case EXEC_OACC_WAIT:
    8131              :     case EXEC_OACC_CACHE:
    8132              :     case EXEC_OACC_ENTER_DATA:
    8133              :     case EXEC_OACC_EXIT_DATA:
    8134              :     case EXEC_OACC_ATOMIC:
    8135              :     case EXEC_OACC_ROUTINE:
    8136              :     case EXEC_OACC_INIT:
    8137              :     case EXEC_OACC_SHUTDOWN:
    8138              :     case EXEC_OACC_SET:
    8139              :       return true;
    8140              : 
    8141            3 :     default:
    8142            3 :       return false;
    8143              :     }
    8144              : }
    8145              : 
    8146              : /* Return true if ST is a declarative OpenMP statement.  */
    8147              : bool
    8148          262 : is_omp_declarative_stmt (gfc_statement st)
    8149              : {
    8150          262 :   switch (st)
    8151              :     {
    8152              :       case_omp_decl:
    8153              :         return true;
    8154          262 :       default:
    8155          262 :         return false;
    8156              :     }
    8157              : }
        

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.