[Fortran, OpenACC] Reject vars of different scope in $acc declare (PR94120)
authorTobias Burnus <tobias@codesourcery.com>
Thu, 12 Mar 2020 09:57:56 +0000 (10:57 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 12 Mar 2020 09:57:56 +0000 (10:57 +0100)
2020-03-12  Tobias Burnus  <tobias@codesourcery.com>

        PR middle-end/94120
        * openmp.c (gfc_match_oacc_declare): Accept function-result
        variables; reject variables declared in a different scoping unit.

2020-03-12  Tobias Burnus  <tobias@codesourcery.com>

        PR middle-end/94120
        * gfortran.dg/goacc/pr78260-2.f90: Correct scan-tree-dump-times.
        Extend test case to result variables.
        * gfortran.dg/goacc/declare-2.f95: Actually check module-declaration
        restriction of OpenACC.
        * gfortran.dg/goacc/declare-3.f95: Remove case where this
        restriction is violated.
        * gfortran.dg/goacc/pr94120-1.f90: New.
        * gfortran.dg/goacc/pr94120-2.f90: New.
        * gfortran.dg/goacc/pr94120-3.f90: New.

gcc/fortran/ChangeLog
gcc/fortran/openmp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/goacc/declare-2.f95
gcc/testsuite/gfortran.dg/goacc/declare-3.f95
gcc/testsuite/gfortran.dg/goacc/pr78260-2.f90
gcc/testsuite/gfortran.dg/goacc/pr94120-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/goacc/pr94120-2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/goacc/pr94120-3.f90 [new file with mode: 0644]

index b3ff063045379e0e9723a13a03db119762ca723b..661e4ce7eba45ff2f8a20b673a3058b566574e47 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR middle-end/94120
+       * openmp.c (gfc_match_oacc_declare): Accept function-result
+       variables; reject variables declared in a different scoping unit.
+
 2020-03-08  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/93581
index 35f6b2f4938bd96a26cf5de5d68b3c1436aea8fd..930bca541b98c7670f60d4257d4b30498ed03ea2 100644 (file)
@@ -2155,7 +2155,8 @@ gfc_match_oacc_declare (void)
     {
       gfc_symbol *s = n->sym;
 
-      if (s->ns->proc_name && s->ns->proc_name->attr.proc == PROC_MODULE)
+      if (gfc_current_ns->proc_name
+         && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
        {
          if (n->u.map_op != OMP_MAP_ALLOC && n->u.map_op != OMP_MAP_TO)
            {
@@ -2174,6 +2175,15 @@ gfc_match_oacc_declare (void)
          return MATCH_ERROR;
        }
 
+      if ((s->result == s && s->ns->contained != gfc_current_ns)
+         || ((s->attr.flavor == FL_UNKNOWN || s->attr.flavor == FL_VARIABLE)
+             && s->ns != gfc_current_ns))
+       {
+         gfc_error ("Variable %qs shall be declared in the same scoping unit "
+                    "as !$ACC DECLARE at %L", s->name, &where);
+         return MATCH_ERROR;
+       }
+
       if ((s->attr.dimension || s->attr.codimension)
          && s->attr.dummy && s->as->type != AS_EXPLICIT)
        {
index 5e232c691d5186c44fb3357c320d79764eb5a5e3..a1f0e3a18c5c13e742646190d511ac361403acca 100644 (file)
@@ -1,3 +1,16 @@
+2020-03-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR middle-end/94120
+       * gfortran.dg/goacc/pr78260-2.f90: Correct scan-tree-dump-times.
+       Extend test case to result variables.
+       * gfortran.dg/goacc/declare-2.f95: Actually check module-declaration
+       restriction of OpenACC.
+       * gfortran.dg/goacc/declare-3.f95: Remove case where this
+       restriction is violated.
+       * gfortran.dg/goacc/pr94120-1.f90: New.
+       * gfortran.dg/goacc/pr94120-2.f90: New.
+       * gfortran.dg/goacc/pr94120-3.f90: New.
+
 2020-03-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/94130
index 7aa3dab4707b16b6d7d9391267c04ce9a1401fc5..bad5de9d757df0d11eeb3717e85ae6030a016a41 100644 (file)
@@ -1,9 +1,5 @@
 
 module amod
-
-contains
-
-subroutine asubr (b)
   implicit none
   integer :: b(8)
 
@@ -16,9 +12,24 @@ subroutine asubr (b)
   !$acc declare present_or_create (b) ! { dg-error "present on multiple" }
   !$acc declare deviceptr (b) ! { dg-error "Invalid clause in module" }
   !$acc declare create (b) copyin (b) ! { dg-error "present on multiple" }
+end module
 
+module amod2
+contains
+subroutine asubr (a, b, c, d, e, f, g, h, i, j, k)
+  implicit none
+  integer, dimension(8) :: a, b, c, d, e, f, g, h, i, j, k
+
+  !$acc declare copy (a)
+  !$acc declare copyout (b)
+  !$acc declare present (c)
+  !$acc declare present_or_copy (d)
+  !$acc declare present_or_copyin (e)
+  !$acc declare present_or_copyout (f)
+  !$acc declare present_or_create (g)
+  !$acc declare deviceptr (h)
+  !$acc declare create (j) copyin (k)
 end subroutine
-
 end module
 
 module bmod
index 80d9903a9dc6cff57528e5d01a980ab25365b19b..9127cba6600d7acb18bda5db29bf57692545f033 100644 (file)
@@ -14,12 +14,6 @@ module mod_b
   !$acc declare copyin (b)
 end module
 
-module mod_c
-  implicit none
-  integer :: c
-  !$acc declare deviceptr (c)
-end module
-
 module mod_d
   implicit none
   integer :: d
@@ -35,7 +29,6 @@ end module
 subroutine sub1
   use mod_a
   use mod_b
-  use mod_c
   use mod_d
   use mod_e
 end subroutine sub1
@@ -43,11 +36,10 @@ end subroutine sub1
 program test
   use mod_a
   use mod_b
-  use mod_c
   use mod_d
   use mod_e
 
-  ! { dg-final { scan-tree-dump {(?n)#pragma acc data map\(force_alloc:d\) map\(force_deviceptr:c\) map\(force_to:b\) map\(force_alloc:a\)$} original } }
+  ! { dg-final { scan-tree-dump {(?n)#pragma acc data map\(force_alloc:d\) map\(force_to:b\) map\(force_alloc:a\)$} original } }
 end program test
 
 ! { dg-final { scan-tree-dump-times {#pragma acc data} 1 original } }
index e28564d6f700a18663e53bf24ba491abd58c0559..f8a3dc864ccdfe988e403389d51fe4da30261d7e 100644 (file)
@@ -4,6 +4,8 @@
 
 ! PR fortran/78260
 
+! Loosely related to PR fortran/94120
+
 module m
   implicit none
   integer :: n = 0
@@ -14,7 +16,14 @@ contains
     f1 = 5 
     !$acc end kernels
   end function f1
+  integer function g1() result(g1res)
+    !$acc declare present(g1res)
+    !$acc kernels copyin(g1res)
+    g1res = 5 
+    !$acc end kernels
+  end function g1
 end module m
 ! { dg-final { scan-tree-dump-times "#pragma acc data map\\(force_present:__result_f1\\)" 1 "original" } }
-! { dg-final { scan-tree-dump-times "#pragma acc data map\\(force_present:__result_f1\\)" 1 "original" } }
-
+! { dg-final { scan-tree-dump-times "#pragma acc kernels map\\(to:__result_f1\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma acc data map\\(force_present:g1res\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma acc kernels map\\(to:g1res\\)" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr94120-1.f90 b/gcc/testsuite/gfortran.dg/goacc/pr94120-1.f90
new file mode 100644 (file)
index 0000000..8d1fc16
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+!
+! PR fortran/94120
+!
+implicit none
+integer :: i
+contains
+  subroutine f()
+    !$acc declare copy(i)  ! { dg-error "Variable 'i' shall be declared in the same scoping unit as !.ACC DECLARE" }
+  end
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr94120-2.f90 b/gcc/testsuite/gfortran.dg/goacc/pr94120-2.f90
new file mode 100644 (file)
index 0000000..216c04b
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+!
+! PR fortran/94120
+!
+! BLOCK is not supported in OpenACC <= 3.0
+!
+subroutine f()
+  block
+    integer :: k
+    !$acc declare copy(j)  ! { dg-error "Sorry, !.ACC DECLARE at .1. is not allowed in BLOCK construct" }
+  end block
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr94120-3.f90 b/gcc/testsuite/gfortran.dg/goacc/pr94120-3.f90
new file mode 100644 (file)
index 0000000..1eec90a
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+!
+! PR fortran/94120
+!
+! Note: BLOCK is not supported in OpenACC <= 3.0 – but the following check comes earlier:
+! It is also invalid because the variable is in a different scoping unit
+!
+subroutine g()
+  integer :: k
+  block
+    !$acc declare copy(k)  ! { dg-error "Variable 'k' shall be declared in the same scoping unit as !.ACC DECLARE" }
+  end block
+end