[Fortran, OpenACC] Reject vars of different scope in $acc declare (PR94120)

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.
This commit is contained in:
Tobias Burnus 2020-03-12 10:57:56 +01:00
parent b73f69020f
commit 98aeb1ef51
9 changed files with 94 additions and 17 deletions

View 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

View 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)
{

View 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

View 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

View 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 } }

View 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" } }

View file

@ -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

View file

@ -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

View file

@ -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