From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1729) id 7DA08385842B; Mon, 14 Feb 2022 15:59:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7DA08385842B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kwok Yeung To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openmp: More Fortran front-end fixes for metadirectives X-Act-Checkin: gcc X-Git-Author: Kwok Cheung Yeung X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: 38ed9d83b893df0bbd098c7b44dbbeb56ed7dd1c X-Git-Newrev: 8cb0121af50eacb63098a79ff8c6deae05883c6f Message-Id: <20220214155942.7DA08385842B@sourceware.org> Date: Mon, 14 Feb 2022 15:59:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Feb 2022 15:59:42 -0000 https://gcc.gnu.org/g:8cb0121af50eacb63098a79ff8c6deae05883c6f commit 8cb0121af50eacb63098a79ff8c6deae05883c6f Author: Kwok Cheung Yeung Date: Fri Feb 11 15:42:50 2022 +0000 openmp: More Fortran front-end fixes for metadirectives This adds a check for declarative OpenMP directives in metadirective variants (already present in the C/C++ front-ends), and fixes an ICE when an empty metadirective (i.e. just '!$omp metadirective') is presented. 2022-02-11 Kwok Cheung Yeung gcc/fortran/ * gfortran.h (is_omp_declarative_stmt): New. * openmp.c (match_omp_metadirective): Reject declarative OpenMP directives with 'sorry'. * parse.c (parse_omp_metadirective_body): Check that state stack head is non-null before dereferencing. (is_omp_declarative_stmt): New. gcc/testsuite/ * gfortran.dg/gomp/metadirective-2.f90 (main): Test empty metadirective. Diff: --- gcc/fortran/ChangeLog.omp | 9 +++++++++ gcc/fortran/gfortran.h | 1 + gcc/fortran/openmp.c | 3 +++ gcc/fortran/parse.c | 16 +++++++++++++++- gcc/testsuite/ChangeLog.omp | 5 +++++ gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 | 5 ++++- 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 070744413db..e76884dbc0c 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,12 @@ +2022-02-11 Kwok Cheung Yeung + + * gfortran.h (is_omp_declarative_stmt): New. + * openmp.c (match_omp_metadirective): Reject declarative OpenMP + directives with 'sorry'. + * parse.c (parse_omp_metadirective_body): Check that state stack head + is non-null before dereferencing. + (is_omp_declarative_stmt): New. + 2022-02-11 Kwok Cheung Yeung * decl.c (gfc_match_end): Search for first previous state that is not diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 338dcad240b..f9b36ca5205 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3833,6 +3833,7 @@ bool gfc_parse_file (void); void gfc_global_used (gfc_gsymbol *, locus *); gfc_namespace* gfc_build_block_ns (gfc_namespace *); gfc_statement match_omp_directive (void); +bool is_omp_declarative_stmt (gfc_statement); /* dependency.c */ int gfc_dep_compare_functions (gfc_expr *, gfc_expr *, bool); diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 1f82e09f270..43e5be004f9 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -5037,6 +5037,9 @@ match_omp_metadirective (bool begin_p) gfc_statement directive = match_omp_directive (); gfc_matching_omp_context_selector = false; + if (is_omp_declarative_stmt (directive)) + sorry ("declarative directive variants are not supported"); + if (gfc_error_flag_test ()) { gfc_current_locus = old_loc; diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index 7d3aa9e0488..00e2dda2f06 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -5820,7 +5820,8 @@ parse_omp_metadirective_body (gfc_statement omp_st) gfc_in_metadirective_body = old_in_metadirective_body; - *clause->code = *gfc_state_stack->head; + if (gfc_state_stack->head) + *clause->code = *gfc_state_stack->head; pop_state (); gfc_commit_symbols (); @@ -7082,3 +7083,16 @@ is_oacc (gfc_state_data *sd) return false; } } + +/* Return true if ST is a declarative OpenMP statement. */ +bool +is_omp_declarative_stmt (gfc_statement st) +{ + switch (st) + { + case_omp_decl: + return true; + default: + return false; + } +} diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 2b610c00ef3..07bdb9d0645 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,8 @@ +2022-02-11 Kwok Cheung Yeung + + * gfortran.dg/gomp/metadirective-2.f90 (main): Test empty + metadirective. + 2022-02-11 Kwok Cheung Yeung * gfortran.dg/gomp/metadirective-8.f90: New. diff --git a/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 b/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 index 06c324589d0..cdd5e85068e 100644 --- a/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 @@ -43,7 +43,7 @@ program main end do !$omp end metadirective - ! Test labels in the body + ! Test labels in the body. !$omp begin metadirective & !$omp& when (device={arch("nvptx")}: parallel do) & !$omp& when (device={arch("gcn")}: parallel) @@ -56,4 +56,7 @@ program main 20 continue end do !$omp end metadirective + + ! Test empty metadirective. + !$omp metadirective end program