diff mbox series

Fortran: OpenMP/OpenACC diagnose substring rejections better

Message ID f3254794-12c4-28d7-7557-7961fd903b15@codesourcery.com
State New
Headers show
Series Fortran: OpenMP/OpenACC diagnose substring rejections better | expand

Commit Message

Tobias Burnus Feb. 4, 2021, 11:24 a.m. UTC
This issue came up when looking at Julian's OpenACC patches
and by coincidence it was also discussed for OpenMP
yesterday (lang-spec F2F meeting; Issue #2607).

OpenACC rather explicitly lists what counts as 'var' and
substrings do not appear there. While OpenMP is rather
silent on this issue; I think between the
lines it can be read that it is not permitted - and
supporting it will run into many issues. (Hence, the
agreement that it should not be allowed; wording changes
still need to be voted on, cf. Issue #2607).


Without the patch, gfortran gives the
   Error: ‘str2’ in MAP clause at (1) is not a proper array section

And with the patch
   Error: Unexpected substring reference in MAP clause at (1)
Except, in one OpenMP case, it stops earlier and we get:
   Error: Syntax error in OpenMP variable list at (1)
(see testcase)

OK for mainline?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

Comments

Jakub Jelinek Feb. 4, 2021, 11:31 a.m. UTC | #1
On Thu, Feb 04, 2021 at 12:24:10PM +0100, Tobias Burnus wrote:
> This issue came up when looking at Julian's OpenACC patches
> and by coincidence it was also discussed for OpenMP
> yesterday (lang-spec F2F meeting; Issue #2607).
> 
> OpenACC rather explicitly lists what counts as 'var' and
> substrings do not appear there. While OpenMP is rather
> silent on this issue; I think between the
> lines it can be read that it is not permitted - and
> supporting it will run into many issues. (Hence, the
> agreement that it should not be allowed; wording changes
> still need to be voted on, cf. Issue #2607).
> 
> 
> Without the patch, gfortran gives the
>   Error: ‘str2’ in MAP clause at (1) is not a proper array section
> 
> And with the patch
>   Error: Unexpected substring reference in MAP clause at (1)
> Except, in one OpenMP case, it stops earlier and we get:
>   Error: Syntax error in OpenMP variable list at (1)
> (see testcase)
> 
> OK for mainline?

Ok.

	Jakub
diff mbox series

Patch

Fortran: OpenMP/OpenACC diagnose substring rejections better

gcc/fortran/ChangeLog:

	* openmp.c (resolve_omp_clauses): Explicitly diagnose
	substrings as not permitted.

gcc/testsuite/ChangeLog:

	* gfortran.dg/goacc/substring.f90: New test.
	* gfortran.dg/gomp/substring.f90: New test.

 gcc/fortran/openmp.c                          |  8 +++++++-
 gcc/testsuite/gfortran.dg/goacc/substring.f90 | 27 +++++++++++++++++++++++++++
 gcc/testsuite/gfortran.dg/gomp/substring.f90  | 22 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 9a3a8f63b5e..aab17f0589f 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -5212,7 +5212,13 @@  resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
 		    || (n->expr
 			&& (!resolved || n->expr->expr_type != EXPR_VARIABLE)))
 		  {
-		    if (!resolved
+		    if (array_ref
+			&& (array_ref->type == REF_SUBSTRING
+			    || (array_ref->next
+				&& array_ref->next->type == REF_SUBSTRING)))
+		      gfc_error ("Unexpected substring reference in %s clause "
+				 "at %L", name, &n->where);
+		    else if (!resolved
 			|| n->expr->expr_type != EXPR_VARIABLE
 			|| array_ref->next
 			|| array_ref->type != REF_ARRAY)
diff --git a/gcc/testsuite/gfortran.dg/goacc/substring.f90 b/gcc/testsuite/gfortran.dg/goacc/substring.f90
new file mode 100644
index 00000000000..25031daddf3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/substring.f90
@@ -0,0 +1,27 @@ 
+implicit none
+character(len=10) :: str1, str2(5,5)
+
+type t
+  character(len=10) :: str1, str2(5,5)
+end type t
+type(t) :: v
+
+!$acc enter data copyin(v%str1)       ! OK
+!$acc enter data copyin(v%str2)       ! OK
+!$acc enter data copyin(v%str2(1,2))  ! OK
+!$acc enter data copyin(str1)         ! OK
+!$acc enter data copyin(str2)         ! OK
+!$acc enter data copyin(str2(1,2))    ! OK
+
+!$acc enter data copyin(v%str1(2:5))       ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc enter data copyin(v%str2(1,2)(2:4))  ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc enter data copyin(str1(2:5))         ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc enter data copyin(str2(1,2)(2:4))    ! { dg-error "Unexpected substring reference in MAP clause" }
+
+!$acc parallel
+!$acc update host(v%str1(2:5))             ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc update host(v%str2(1,2)(2:4))        ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc update host(str1(2:5))               ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc update host(str2(1,2)(2:4))          ! { dg-error "Unexpected substring reference in MAP clause" }
+!$acc end parallel
+end
diff --git a/gcc/testsuite/gfortran.dg/gomp/substring.f90 b/gcc/testsuite/gfortran.dg/gomp/substring.f90
new file mode 100644
index 00000000000..23d7fb7e48a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/substring.f90
@@ -0,0 +1,22 @@ 
+implicit none
+character(len=10) :: str1, str2(5,5)
+
+type t
+  character(len=10) :: str1, str2(5,5)
+end type t
+type(t) :: v
+
+!$omp target enter data map(to: str1)      ! OK
+!$omp target enter data map(to: str2)      ! OK
+!$omp target enter data map(to: str2(2,5)) ! OK
+
+!$omp target enter data map(to: str1(2,5))         ! { dg-error "Syntax error in OpenMP variable list" }
+!$omp target enter data map(to: str2(1,2)(2:4))    ! { dg-error "Unexpected substring reference in MAP clause" }
+
+!$omp target enter data map(to: v%str1)       ! OK
+!$omp target enter data map(to: v%str2)       ! OK
+!$omp target enter data map(to: v%str2(1,2))  ! OK
+
+!$omp target enter data map(to: v%str1(2:5))       ! { dg-error "Unexpected substring reference in MAP clause" }
+!$omp target enter data map(to: v%str2(1,2)(2:4))  ! { dg-error "Unexpected substring reference in MAP clause" }
+end