Fortran: OpenMP/OpenACC diagnose substring rejections better
authorTobias Burnus <tobias@codesourcery.com>
Thu, 4 Feb 2021 11:32:59 +0000 (12:32 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 4 Feb 2021 11:32:59 +0000 (12:32 +0100)
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
gcc/testsuite/gfortran.dg/goacc/substring.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/substring.f90 [new file with mode: 0644]

index 9a3a8f6..aab17f0 100644 (file)
@@ -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 (file)
index 0000000..25031da
--- /dev/null
@@ -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 (file)
index 0000000..23d7fb7
--- /dev/null
@@ -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