From: Kwok Cheung Yeung Date: Fri, 11 Feb 2022 15:42:50 +0000 (+0000) Subject: openmp: More Fortran front-end fixes for metadirectives X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=484384f0b284e771c1828b07590ee3353cff16b7;p=thirdparty%2Fgcc.git 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.cc (match_omp_metadirective): Reject declarative OpenMP directives with 'sorry'. * parse.cc (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 --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 180a54b17dc9..bce274c0ea52 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.cc (match_omp_metadirective): Reject declarative OpenMP + directives with 'sorry'. + * parse.cc (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.cc (gfc_match_end): Search for first previous state that is not diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index edc45ca09eed..6099b2b9638a 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3859,6 +3859,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.cc */ int gfc_dep_compare_functions (gfc_expr *, gfc_expr *, bool); diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 3661271d4a98..af54bd531575 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -5151,6 +5151,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.cc b/gcc/fortran/parse.cc index e1eb81ce0731..1d216247bc3d 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -5859,7 +5859,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 (); @@ -7125,3 +7126,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 2fc0f1d9b7d0..2ca7567c25c7 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 06c324589d03..cdd5e85068e1 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