https://gcc.gnu.org/g:a85c1fa3d82221748329b7f7dda329ba8fa22d04
commit r17-3978-ga85c1fa3d82221748329b7f7dda329ba8fa22d04 Author: Tobias Burnus <[email protected]> Date: Mon Sep 7 21:03:38 2026 +0200 OpenMP/Fortran: Support underscore variant of directive names OpenMP added underscore variants to multi-word directive names, which are for Fortran (excluding not yet implemented ones) the following - now supported since this commit: 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: * parse.cc (decode_omp_directive): Parse underscore variant of multi-word directive names as well. libgomp/ChangeLog: * libgomp.texi (OpenMP 6.0 Impl Status): Mark underscore variant of multi-word directive names as supported by Fortran. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/underscore_directives-2.f90: New test. * gfortran.dg/gomp/underscore_directives.f90: New test. Diff: --- gcc/fortran/parse.cc | 20 ++++++ .../gfortran.dg/gomp/underscore_directives-2.f90 | 20 ++++++ .../gfortran.dg/gomp/underscore_directives.f90 | 73 ++++++++++++++++++++++ libgomp/libgomp.texi | 2 +- 4 files changed, 114 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 311dfedabce1..c8e60c9d665b 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -1049,14 +1049,24 @@ decode_omp_directive (void) case 'd': matchdo ("declare mapper", gfc_match_omp_declare_mapper, ST_OMP_DECLARE_MAPPER); + matchdo ("declare_mapper", gfc_match_omp_declare_mapper, + ST_OMP_DECLARE_MAPPER); matchds ("declare reduction", gfc_match_omp_declare_reduction, ST_OMP_DECLARE_REDUCTION); + matchds ("declare_reduction", gfc_match_omp_declare_reduction, + ST_OMP_DECLARE_REDUCTION); matchds ("declare simd", gfc_match_omp_declare_simd, ST_OMP_DECLARE_SIMD); + matchds ("declare_simd", gfc_match_omp_declare_simd, + ST_OMP_DECLARE_SIMD); matchdo ("declare target", gfc_match_omp_declare_target, ST_OMP_DECLARE_TARGET); + matchdo ("declare_target", gfc_match_omp_declare_target, + ST_OMP_DECLARE_TARGET); matchdo ("declare variant", gfc_match_omp_declare_variant, ST_OMP_DECLARE_VARIANT); + matchdo ("declare_variant", gfc_match_omp_declare_variant, + ST_OMP_DECLARE_VARIANT); break; case 'e': matchs ("end assume", gfc_match_omp_eos_error, ST_OMP_END_ASSUME); @@ -1116,6 +1126,8 @@ decode_omp_directive (void) case 'c': matcho ("cancellation% point", gfc_match_omp_cancellation_point, ST_OMP_CANCELLATION_POINT); + matcho ("cancellation_point", gfc_match_omp_cancellation_point, + ST_OMP_CANCELLATION_POINT); matcho ("cancel", gfc_match_omp_cancel, ST_OMP_CANCEL); matcho ("critical", gfc_match_omp_critical, ST_OMP_CRITICAL); break; @@ -1186,6 +1198,7 @@ decode_omp_directive (void) matcho ("end sections", gfc_match_omp_end_nowait, ST_OMP_END_SECTIONS); matcho ("end single", gfc_match_omp_end_single, ST_OMP_END_SINGLE); matcho ("end target data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA); + matcho ("end target_data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA); matchs ("end target parallel do simd", gfc_match_omp_end_nowait, ST_OMP_END_TARGET_PARALLEL_DO_SIMD); matcho ("end target parallel do", gfc_match_omp_end_nowait, @@ -1306,10 +1319,15 @@ decode_omp_directive (void) break; case 't': matcho ("target data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA); + matcho ("target_data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA); matcho ("target enter data", gfc_match_omp_target_enter_data, ST_OMP_TARGET_ENTER_DATA); + matcho ("target_enter_data", gfc_match_omp_target_enter_data, + ST_OMP_TARGET_ENTER_DATA); matcho ("target exit data", gfc_match_omp_target_exit_data, ST_OMP_TARGET_EXIT_DATA); + matcho ("target_exit_data", gfc_match_omp_target_exit_data, + ST_OMP_TARGET_EXIT_DATA); matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd, ST_OMP_TARGET_PARALLEL_DO_SIMD); matcho ("target parallel do", gfc_match_omp_target_parallel_do, @@ -1335,6 +1353,8 @@ decode_omp_directive (void) matcho ("target teams", gfc_match_omp_target_teams, ST_OMP_TARGET_TEAMS); matcho ("target update", gfc_match_omp_target_update, ST_OMP_TARGET_UPDATE); + matcho ("target_update", gfc_match_omp_target_update, + ST_OMP_TARGET_UPDATE); matcho ("target", gfc_match_omp_target, ST_OMP_TARGET); matcho ("taskgroup", gfc_match_omp_taskgroup, ST_OMP_TASKGROUP); matchs ("taskloop simd", gfc_match_omp_taskloop_simd, diff --git a/gcc/testsuite/gfortran.dg/gomp/underscore_directives-2.f90 b/gcc/testsuite/gfortran.dg/gomp/underscore_directives-2.f90 new file mode 100644 index 000000000000..384e20662924 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/underscore_directives-2.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } + +! OpenMP 6 adds underscore variants to the directive names +! Check declare_mapper here + +module m2 + type t + integer :: ptr + end type t + !$omp declare mapper(mymapper : t :: v) map(v%ptr) +contains + subroutine mapit(y) + type(t) :: y + ! Must be last until implemented + !$omp target_enter_data map(mapper(mymapper), to: y) ! { dg-error "Sorry, declared mapper 'mymapper', used for 'y' at .1., is not yet supported" } + end +end + + + diff --git a/gcc/testsuite/gfortran.dg/gomp/underscore_directives.f90 b/gcc/testsuite/gfortran.dg/gomp/underscore_directives.f90 new file mode 100644 index 000000000000..ebcc9f9969dd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/underscore_directives.f90 @@ -0,0 +1,73 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } + +! OpenMP 6 adds underscore variants to the directive names +! Check all but declare_mapper here. + +subroutine test + !$omp declare_target enter(test) +end + +subroutine data + integer :: x + !$omp target_enter_data map(x) + + !$omp target_data map(x) + call bar(x) + !$omp end target_data + + !$omp target_update from(x) + + !$omp target_exit_data map(x) +end subroutine data + +module m +contains +subroutine varfn() +end +subroutine basefn() + !$omp declare_variant(varfn) match(construct={parallel}) +end +end + +module m3 +!$omp declare_reduction (foo:integer:omp_out = omp_out + omp_in) +contains + integer function foo (x, y) + integer, value :: x, y + !$omp declare_simd (foo) linear (y : 2) + end function foo +subroutine bar + integer :: b, i, a(64) + a = 1 + b = 0 + !$omp parallel + !$omp cancellation_point parallel + !$omp critical (bar) + b = b + 1 + !$omp end critical (bar) + !$omp cancel parallel + !$omp end parallel + + !$omp simd reduction (foo: b) + do i = 1, 64 + b = b + a(i) + end do +end +end + +! { dg-final { scan-tree-dump "#pragma omp target enter data map\\(to:x\\)" "original" } } +! { dg-final { scan-tree-dump "#pragma omp target data map\\(tofrom:x\\)" "original" } } +! { dg-final { scan-tree-dump "#pragma omp target update from\\(x\\)" "original" } } +! { dg-final { scan-tree-dump "#pragma omp target exit data map\\(from:x\\)" "original" } } + +! { dg-final { scan-tree-dump "#pragma omp simd linear\\(i:1\\) reduction\\(b\\)" "original" } } + +! { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare target \\(device_type\\(any\\)\\)\\)\\)" "original" } } +! { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare simd \\(linear\\(1:2\\)\\)\\)\\)" "original" } } + +! { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant base \\(varfn match construct = {parallel}\\)\\)\\)" "original" } } +! { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant variant" "original" } } + +! { dg-final { scan-tree-dump "__builtin_GOMP_cancellation_point \\(1\\);" "original" } } + diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 92d82f2f66c4..a358f347fed1 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -641,7 +641,7 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @unnumberedsubsec Other new OpenMP 6.0 features @multitable @columnfractions .60 .10 .25 -@item Multi-word directives now use underscore by default @tab N @tab +@item Multi-word directives now use underscore by default @tab P @tab Only in Fortran @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab @item Mapping lambda captures @tab N @tab @item New @code{omp_pause_stop_tool} constant for @code{omp_pause_resource}
