aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul-Antoine Arras <parras@baylibre.com>2025-01-06 18:38:11 +0100
committerPaul-Antoine Arras <parras@baylibre.com>2025-01-13 18:56:18 +0100
commit2ea4801cf7a4ebc0145b84f84ae7f4961e57b64f (patch)
treebb1d6c26dc857186ff7394848cdb2e80e6647ea5
parentecf688edc217472774817cc1284e75a9f72fe1b4 (diff)
downloadgcc-2ea4801cf7a4ebc0145b84f84ae7f4961e57b64f.zip
gcc-2ea4801cf7a4ebc0145b84f84ae7f4961e57b64f.tar.gz
gcc-2ea4801cf7a4ebc0145b84f84ae7f4961e57b64f.tar.bz2
Accept commas between clauses in OpenMP declare variant
Add support to the Fortran parser for the OpenMP syntax that allows a comma after the directive name and between clauses of declare variant. The C and C++ parsers already support this syntax so only a new test is added. gcc/fortran/ChangeLog: * openmp.cc (gfc_match_omp_declare_variant): Match comma after directive name and between clauses. Emit more useful diagnostics. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-variant-2.f90: Remove error test for a comma after the directive name. Add tests for other invalid syntaxes (extra comma and invalid clause). * c-c++-common/gomp/adjust-args-5.c: New test. * gfortran.dg/gomp/adjust-args-11.f90: New test.
-rw-r--r--gcc/fortran/openmp.cc23
-rw-r--r--gcc/testsuite/c-c++-common/gomp/adjust-args-5.c21
-rw-r--r--gcc/testsuite/gfortran.dg/gomp/adjust-args-11.f9045
-rw-r--r--gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f9010
4 files changed, 87 insertions, 12 deletions
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index e00044d..0f1aaa0 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -6559,7 +6559,6 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
match
gfc_match_omp_declare_variant (void)
{
- bool first_p = true;
char buf[GFC_MAX_SYMBOL_LEN + 1];
if (gfc_match (" (") != MATCH_YES)
@@ -6617,11 +6616,15 @@ gfc_match_omp_declare_variant (void)
return MATCH_ERROR;
}
- bool has_match = false, has_adjust_args = false;
+ bool has_match = false, has_adjust_args = false, error_p = false;
locus adjust_args_loc;
for (;;)
{
+ gfc_gobble_whitespace ();
+ gfc_match_char (',');
+ gfc_gobble_whitespace ();
+
enum clause
{
match,
@@ -6637,13 +6640,9 @@ gfc_match_omp_declare_variant (void)
}
else
{
- if (first_p)
- {
- gfc_error ("expected %<match%> or %<adjust_args%> at %C");
- return MATCH_ERROR;
- }
- else
- break;
+ if (gfc_match_omp_eos () != MATCH_YES)
+ error_p = true;
+ break;
}
if (gfc_match (" (") != MATCH_YES)
@@ -6689,8 +6688,12 @@ gfc_match_omp_declare_variant (void)
for (gfc_omp_namelist *n = *head; n != NULL; n = n->next)
n->u.need_device_ptr = true;
}
+ }
- first_p = false;
+ if (error_p || (!has_match && !has_adjust_args))
+ {
+ gfc_error ("expected %<match%> or %<adjust_args%> at %C");
+ return MATCH_ERROR;
}
if (has_adjust_args && !has_match)
diff --git a/gcc/testsuite/c-c++-common/gomp/adjust-args-5.c b/gcc/testsuite/c-c++-common/gomp/adjust-args-5.c
new file mode 100644
index 0000000..8aff73c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/adjust-args-5.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+/* Check that the OpenMP 5.1 syntax with commas after the directive name and
+ between clauses is supported. */
+
+int f (int a, void *b, float c[2]);
+
+#pragma omp declare variant (f), match (construct={dispatch}), adjust_args (nothing: a), adjust_args (need_device_ptr: b, c)
+int f0 (int a, void *b, float c[2]);
+
+int test () {
+ int a;
+ void *b;
+ float c[2];
+ struct {int a;} s;
+
+ #pragma omp dispatch, novariants(0), nocontext(1)
+ s.a = f0 (a, b, c);
+
+ return s.a;
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/adjust-args-11.f90 b/gcc/testsuite/gfortran.dg/gomp/adjust-args-11.f90
new file mode 100644
index 0000000..d2eb7c1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/adjust-args-11.f90
@@ -0,0 +1,45 @@
+! { dg-do compile }
+
+! Check that the OpenMP syntax with commas between clauses is supported.
+! A comma after the directive name is introduced in 5.2, which currently is only
+! partially supported.
+
+module main
+ use iso_c_binding, only: c_ptr
+ implicit none
+
+ type :: struct
+ integer :: a
+ real :: b
+ end type
+
+ interface
+ integer function f(a, b, c)
+ import c_ptr
+ integer, intent(in) :: a
+ type(c_ptr), intent(inout) :: b
+ type(c_ptr), intent(out) :: c(:)
+ end function
+ integer function f0(a, b, c)
+ import c_ptr
+ integer, intent(in) :: a
+ type(c_ptr), intent(inout) :: b
+ type(c_ptr), intent(out) :: c(:)
+ !$omp declare variant (f), match (construct={dispatch}) , &
+ !$omp& adjust_args (nothing: a) ,adjust_args (need_device_ptr: b),adjust_args (need_device_ptr: c)
+ end function
+ end interface
+
+contains
+subroutine test
+ integer :: a
+ type(c_ptr) :: b
+ type(c_ptr) :: c(2)
+ type(struct) :: s
+
+ !!$omp dispatch, nocontext(.false.), novariants(.false.) ! Not supported yet
+ !$omp dispatch nocontext(.false.), novariants(.false.)
+ s%a = f0 (a, b, c)
+
+end subroutine
+end module
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90
index 62d2cb9..17b112f 100644
--- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90
@@ -182,8 +182,14 @@ contains
subroutine f74 ()
!$omp declare variant (f1) match(construct={requires}) ! { dg-warning "unknown selector 'requires' for context selector set 'construct' at .1." }
end subroutine
- subroutine f75 ()
- !$omp declare variant (f1),match(construct={parallel}) ! { dg-error "expected 'match' or 'adjust_args' at .1." }
+ subroutine f75a ()
+ !$omp declare variant(f1) ,,match(construct={dispatch}) adjust_args(need_device_ptr : c) ! { dg-error "expected 'match' or 'adjust_args' at .1." }
+ end subroutine
+ subroutine f75b ()
+ !$omp declare variant(f1) match(construct={dispatch}),,adjust_args(need_device_ptr : c) ! { dg-error "expected 'match' or 'adjust_args' at .1." }
+ end subroutine
+ subroutine f75c ()
+ !$omp declare variant(f1) match(construct={dispatch}),nowait(a) ! { dg-error "expected 'match' or 'adjust_args' at .1." }
end subroutine
subroutine f76 ()
!$omp declare variant (f1) match(implementation={atomic_default_mem_order("relaxed")}) ! { dg-error "expected identifier at .1." }