Follow up to previous commit - I missed two cases that also need to support underscore variants ...
Namely, cases like !$omp assume(s) contains(cancellation_point) and !$omp ... if(target_data: cond) Committed as Rev. r17-3983-ged4b096464cd75 Tobias
commit ed4b096464cd751c3a8af378a0f9724b55532621 Author: Tobias Burnus <[email protected]> Date: Tue Sep 8 09:22:09 2026 +0200 OpenMP/Fortran: Part 2 - support underscore variant of directive names Follow up to r17-3978-ga85c1fa3d82221 - OpenMP added underscore variants to multi-word directive names; this patch adds those to gfc_omp_directives - such that they can be used in the 'absent' and 'contains' clauses of assume(s). Additionally, handle 'target_...' as directive-name modifier in the 'if' clause. The following directives have underscores in Fortran (excluding not yet implemented ones): declare_mapper, declare_reduction, declare_simd, declare_target, declare_variant, (end) target_data, target_enter_data, target_exit_data, target_update, and cancellation_point. gcc/fortran/ChangeLog: * openmp.cc (gfc_omp_directives): Add underscore variants. (gfc_match_omp_clauses): Handle underscore directive names variants of 'target_...' in the 'if' clause. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/underscore_directives-3.f90: New test. --- gcc/fortran/openmp.cc | 24 ++++++++++++++++++++ .../gfortran.dg/gomp/underscore_directives-3.f90 | 26 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index e559a2db0db..6737e1e3796 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -67,14 +67,21 @@ static const struct gfc_omp_directive gfc_omp_directives[] = { {"atomic", GFC_OMP_DIR_EXECUTABLE, ST_OMP_ATOMIC}, {"barrier", GFC_OMP_DIR_EXECUTABLE, ST_OMP_BARRIER}, {"cancellation point", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCELLATION_POINT}, + {"cancellation_point", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCELLATION_POINT}, {"cancel", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CANCEL}, {"critical", GFC_OMP_DIR_EXECUTABLE, ST_OMP_CRITICAL}, /* {"declare induction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_INDUCTION}, */ + /* {"declare_induction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_INDUCTION}, */ {"declare mapper", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_MAPPER}, + {"declare_mapper", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_MAPPER}, {"declare reduction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_REDUCTION}, + {"declare_reduction", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_REDUCTION}, {"declare simd", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_SIMD}, + {"declare_simd", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_SIMD}, {"declare target", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_TARGET}, + {"declare_target", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_TARGET}, {"declare variant", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_VARIANT}, + {"declare_variant", GFC_OMP_DIR_DECLARATIVE, ST_OMP_DECLARE_VARIANT}, {"depobj", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DEPOBJ}, {"dispatch", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DISPATCH}, {"distribute", GFC_OMP_DIR_EXECUTABLE, ST_OMP_DISTRIBUTE}, @@ -107,9 +114,13 @@ static const struct gfc_omp_directive gfc_omp_directives[] = { /* {"split", GFC_OMP_DIR_EXECUTABLE, ST_OMP_SPLIT}, */ /* {"strip", GFC_OMP_DIR_EXECUTABLE, ST_OMP_STRIP}, */ {"target data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_DATA}, + {"target_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_DATA}, {"target enter data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_ENTER_DATA}, + {"target_enter_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_ENTER_DATA}, {"target exit data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_EXIT_DATA}, + {"target_exit_data", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_EXIT_DATA}, {"target update", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_UPDATE}, + {"target_update", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET_UPDATE}, {"target", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TARGET}, /* {"taskgraph", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASKGRAPH}, */ /* {"task iteration", GFC_OMP_DIR_EXECUTABLE, ST_OMP_TASK_ITERATION}, */ @@ -3532,6 +3543,11 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, "target update : %e )", "target enter data : %e )", "target exit data : %e )" }; + static const char *ifs2[] = { + "target_data : %e )", + "target_update : %e )", + "target_enter_data : %e )", + "target_exit_data : %e )" }; int i; for (i = 0; i < OMP_IF_LAST; i++) if (c->if_exprs[i] == NULL @@ -3539,6 +3555,14 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, break; if (i < OMP_IF_LAST) continue; + for (i = 0; i < (int) ARRAY_SIZE (ifs2); i++) + if (c->if_exprs[OMP_IF_TARGET_DATA + i] == NULL + && (gfc_match (ifs2[i], + &c->if_exprs[OMP_IF_TARGET_DATA + i]) + == MATCH_YES)) + break; + if (i < (int) ARRAY_SIZE (ifs2)) + continue; } if (gfc_match (" %e )", &c->if_expr) == MATCH_YES) continue; diff --git a/gcc/testsuite/gfortran.dg/gomp/underscore_directives-3.f90 b/gcc/testsuite/gfortran.dg/gomp/underscore_directives-3.f90 new file mode 100644 index 00000000000..973dda1db70 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/underscore_directives-3.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } + +! OpenMP 6 adds underscore variants to the directive names +! Check 'if' clause and constructs in contains/absent clauses of assume(s) + +subroutine sub(x) + integer :: x + + !$omp target_enter_data map(x) if(target_enter_data : x > 0) + !$omp target_data map(x) if(target_data : x < 0) + call sub2(x) + !$omp end target_data + !$omp target_exit_data map(x) if(target_exit_data : x > 0) + + !$omp target_update from(x) if (target_update : x == 0) +end + +module m2 +!$omp assumes absent(cancellation_point, target_data, target_enter_data, target_exit_data, target_update) + +!$omp assumes contains(declare_mapper) ! { dg-error "Invalid 'DECLARE MAPPER' directive at .1. in CONTAINS clause: declarative, informational, and meta directives not permitted" } +!$omp assumes contains(declare_reduction) ! { dg-error "Invalid 'DECLARE REDUCTION' directive at .1. in CONTAINS clause: declarative, informational, and meta directives not permitted" } +!$omp assumes contains(declare_simd) ! { dg-error "Invalid 'DECLARE SIMD' directive at .1. in CONTAINS clause: declarative, informational, and meta directives not permitted" } +!$omp assumes contains(declare_target) ! { dg-error "Invalid 'DECLARE TARGET' directive at .1. in CONTAINS clause: declarative, informational, and meta directives not permitted" } +!$omp assumes contains(declare_variant) ! { dg-error "Invalid 'DECLARE VARIANT' directive at .1. in CONTAINS clause: declarative, informational, and meta directives not permitted" } +end
