Check array contiguity for OpenACC/Fortran
authorJulian Brown <julian@codesourcery.com>
Sat, 4 Jan 2020 01:39:56 +0000 (17:39 -0800)
committerJulian Brown <julian@codesourcery.com>
Tue, 28 Jan 2020 14:00:30 +0000 (06:00 -0800)
PR fortran/93025

gcc/fortran/
* openmp.c (resolve_omp_clauses): Check array references for contiguity.

gcc/testsuite/
* gfortran.dg/goacc/mapping-tests-2.f90: New test.
* gfortran.dg/goacc/subarrays.f95: Expect rejection of non-contiguous
array.

gcc/fortran/ChangeLog
gcc/fortran/openmp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/goacc/subarrays.f95

index c51dab2636f6a64c951e7d4d7ee0ecb9b4d59121..c7e2b31933769b36ec71bf1e618fb048d39f186d 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-28  Julian Brown  <julian@codesourcery.com>
+
+       PR fortran/93025
+       * openmp.c (resolve_omp_clauses): Check array references for contiguity.
+
 2020-01-28  Julian Brown  <julian@codesourcery.com>
 
        * gfortran.h (gfc_symbol): Add comp_mark bitfield.
index 444fdcc4751e6436ae05f9e8a1a70cc885656d6a..0accb185e87de4b22001e6e9a8741fb461874063 100644 (file)
@@ -4536,13 +4536,28 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
                    /* Look through component refs to find last array
                       reference.  */
                    if (openacc && resolved)
-                     while (array_ref
-                            && (array_ref->type == REF_COMPONENT
-                                || (array_ref->type == REF_ARRAY
-                                    && array_ref->next
-                                    && (array_ref->next->type
-                                        == REF_COMPONENT))))
-                       array_ref = array_ref->next;
+                     {
+                       /* The "!$acc cache" directive allows rectangular
+                          subarrays to be specified, with some restrictions
+                          on the form of bounds (not implemented).
+                          Only raise an error here if we're really sure the
+                          array isn't contiguous.  An expression such as
+                          arr(-n:n,-n:n) could be contiguous even if it looks
+                          like it may not be.  */
+                       if (list != OMP_LIST_CACHE
+                           && !gfc_is_simply_contiguous (n->expr, false, true)
+                           && gfc_is_not_contiguous (n->expr))
+                         gfc_error ("Array is not contiguous at %L",
+                                    &n->where);
+
+                       while (array_ref
+                              && (array_ref->type == REF_COMPONENT
+                                  || (array_ref->type == REF_ARRAY
+                                      && array_ref->next
+                                      && (array_ref->next->type
+                                          == REF_COMPONENT))))
+                         array_ref = array_ref->next;
+                     }
                  }
                if (array_ref
                    || (n->expr
index a3623672cffff33bf848f17e86227989f86b5e97..9e1af091bccb29f53ee5ec80fbb91da6f34b2f93 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-28  Tobias Burnus  <tobias@codesourcery.com>
+           Julian Brown  <julian@codesourcery.com>
+
+       * gfortran.dg/goacc/mapping-tests-2.f90: New test.
+       * gfortran.dg/goacc/subarrays.f95: Expect rejection of non-contiguous
+       array.
+
 2020-01-28  Julian Brown  <julian@codesourcery.com>
 
        * gfortran.dg/goacc/deep-copy-2.f90: Move test here (from libgomp
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90
new file mode 100644 (file)
index 0000000..1372f6a
--- /dev/null
@@ -0,0 +1,32 @@
+subroutine foo
+  type t
+    integer :: i, j
+  end type t
+
+  type t2
+    type(t) :: cc(3)
+  end type t2
+
+  type(t) x, y(3)
+  type(t2) :: z(3)
+
+  ! OK - map whole aggregated variable
+!$acc enter data copyin(x)
+  ! map(to:x [len: 8])
+
+  ! OK - map two components of the aggregated variable
+!$acc enter data copyin(x%j, x%i)
+
+  ! Bad - we cannot mix full-object and component accesses
+!$acc enter data copyin(x, x%i)
+! { dg-error "Symbol .x. has mixed component and non-component accesses" "" { target "*-*-*" } 21 }
+
+  ! Bad - we cannot do a strided access of 'x'
+  ! No C/C++ equivalent
+!$acc enter data copyin(y(:)%i)
+! { dg-error "Array is not contiguous" "" { target "*-*-*" } 26 }
+
+  ! Bad - again, a strided access
+!$acc enter data copyin(z(1)%cc(:)%i)
+! { dg-error "Array is not contiguous" "" { target "*-*-*" } 30 }
+end
index f6adde459f4312f7d050d4b050ec3122256662fd..fa0378550e9a861b79817b2e86c8bd3bbed33fca 100644 (file)
@@ -27,7 +27,7 @@ program test
   ! { dg-error "'a' in MAP clause" "" { target *-*-* } .-2 }
   !$acc end parallel
 
-  !$acc parallel copy (b(1:3,2:4))
+  !$acc parallel copy (b(1:3,2:4)) ! { dg-error "Array is not contiguous" }
   !$acc end parallel
   !$acc parallel copy (b(2:3))
   ! { dg-error "Rank mismatch" "" { target *-*-* } .-1 }