Skip to content

Commit 5d4b953

Browse files
committed
OpenMP/Fortran: Fix module-use renaming with declare mapper/reduction
Use the same logic as in gfc_compare_derived_types to compare the types. Additionally, the 'declare' part only permits derived types (per syntax) and not class - while using the mapper/reduction with CLASS variables is possible. gcc/fortran/ChangeLog: * openmp.cc (gfc_omp_udm_find, gfc_omp_udr_find): Fix to handle derived-type renaming via module use. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-mapper-6.f90: New test. * gfortran.dg/gomp/declare-mapper-7.f90: New test. * gfortran.dg/gomp/declare-reduction-3.f90: New test. * gfortran.dg/gomp/declare-reduction-4.f90: New test.
1 parent 50ba4a8 commit 5d4b953

5 files changed

Lines changed: 176 additions & 8 deletions

File tree

gcc/fortran/openmp.cc

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5976,11 +5976,21 @@ gfc_omp_udm_find (gfc_symtree *st, gfc_typespec *ts)
59765976
if (st == NULL)
59775977
return NULL;
59785978

5979+
gfc_symbol *dt = (ts->type == BT_CLASS
5980+
? CLASS_DATA (ts->u.derived)->ts.u.derived
5981+
: ts->u.derived);
59795982
for (omp_udm = st->n.omp_udm; omp_udm; omp_udm = omp_udm->next)
5980-
if ((omp_udm->ts.type == BT_DERIVED || omp_udm->ts.type == BT_CLASS)
5981-
&& (ts->type == BT_DERIVED || ts->type == BT_CLASS)
5982-
&& strcmp (omp_udm->ts.u.derived->name, ts->u.derived->name) == 0)
5983-
return omp_udm;
5983+
{
5984+
if (dt == omp_udm->ts.u.derived)
5985+
return omp_udm;
5986+
/* Special case for comparing derived types across namespaces. If the
5987+
true names and module names are the same and the module name is
5988+
nonnull, then they are equal. */
5989+
if (dt->module && omp_udm->ts.u.derived->module
5990+
&& strcmp (dt->name, omp_udm->ts.u.derived->name) == 0
5991+
&& strcmp (dt->module, omp_udm->ts.u.derived->module) == 0)
5992+
return omp_udm;
5993+
}
59845994

59855995
return NULL;
59865996
}
@@ -6292,14 +6302,25 @@ gfc_omp_udr_find (gfc_symtree *st, gfc_typespec *ts)
62926302
if (st == NULL)
62936303
return NULL;
62946304

6305+
gfc_symbol *dt = NULL;
6306+
if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
6307+
dt = (ts->type == BT_CLASS
6308+
? CLASS_DATA (ts->u.derived)->ts.u.derived : ts->u.derived);
62956309
for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
62966310
if (omp_udr->ts.type == ts->type
6297-
|| ((omp_udr->ts.type == BT_DERIVED || omp_udr->ts.type == BT_CLASS)
6298-
&& (ts->type == BT_DERIVED || ts->type == BT_CLASS)))
6311+
|| (dt && omp_udr->ts.type == BT_DERIVED))
62996312
{
6300-
if (omp_udr->ts.type == BT_DERIVED || omp_udr->ts.type == BT_CLASS)
6313+
if (dt && omp_udr->ts.type == BT_DERIVED)
63016314
{
6302-
if (strcmp (omp_udr->ts.u.derived->name, ts->u.derived->name) == 0)
6315+
gfc_symbol *dtu = omp_udr->ts.u.derived;
6316+
if (dt == dtu)
6317+
return omp_udr;
6318+
/* Special case for comparing derived types across namespaces. If
6319+
the true names and module names are the same and the module name
6320+
is nonnull, then they are equal. */
6321+
if (dt->module && dtu->module
6322+
&& strcmp (dt->name, dtu->name) == 0
6323+
&& strcmp (dt->module, dtu->module) == 0)
63036324
return omp_udr;
63046325
}
63056326
else if (omp_udr->ts.kind == ts->kind)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
! Check that type renaming via module use is properly handled.
2+
3+
module first
4+
implicit none
5+
type t
6+
integer, pointer :: x(:)
7+
end type t
8+
!$omp declare mapper(t :: v) map(v, v%x)
9+
end module
10+
11+
module second
12+
implicit none
13+
type t
14+
integer, pointer :: y(:)
15+
integer, pointer :: z(:)
16+
end type t
17+
!$omp declare mapper(t :: v) map(v, v%y, v%z)
18+
end module
19+
20+
subroutine sub2
21+
use first, t1 => t
22+
use second, t2 => t
23+
implicit none
24+
type(t1) :: var
25+
type(t2) :: var2
26+
27+
allocate(var%x(1:20))
28+
allocate(var2%y(1:3), var2%z(5))
29+
var%x = 9
30+
var2%y = 1
31+
var2%z = 43
32+
33+
!$omp target map(tofrom: var) ! { dg-error "Sorry, declared mapper 'default', used for 'var' at .1., is not yet supported" }
34+
block
35+
var%x = 4
36+
end block
37+
38+
!$omp target map(tofrom: var2) ! { dg-error "Sorry, declared mapper 'default', used for 'var2' at .1., is not yet supported" }
39+
block
40+
var2%y = 3
41+
var2%z = 7
42+
end block
43+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! Check that type renaming via module use is properly handled.
2+
3+
module zero
4+
implicit none
5+
type t
6+
integer, pointer :: x(:)
7+
integer, pointer :: y(:)
8+
end type t
9+
end module zero
10+
11+
module first
12+
use zero, only: t1 => t
13+
implicit none
14+
!$omp declare mapper(t1 :: v1) map(v1, v1%x)
15+
end module
16+
17+
module second
18+
use zero, only: t2 => t
19+
implicit none
20+
!$omp declare mapper(t2 :: v2) map(v2, v2%x, v2%y)
21+
end module
22+
23+
subroutine sub2
24+
use first ! { dg-note "Previous !.OMP DECLARE MAPPER from module 'first'" }
25+
use second ! { dg-error "Ambiguous !.OMP DECLARE MAPPER 'default' for type 't' from module 'second'" }
26+
implicit none
27+
! type(t1) :: var1
28+
! type(t2) :: var2
29+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
! Check that type renaming via module use is properly handled.
2+
3+
module first
4+
implicit none
5+
type t
6+
integer :: x = 0
7+
end type t
8+
!$omp declare reduction(+: t : omp_out%x = omp_out%x + omp_in%x)
9+
end module
10+
11+
module second
12+
implicit none
13+
type t
14+
integer :: y = 0
15+
end type t
16+
!$omp declare reduction(+: t : omp_out%y = omp_out%y + omp_in%y)
17+
end module
18+
19+
subroutine sub2
20+
use first, t1 => t
21+
use second, t2 => t
22+
implicit none
23+
type(t1) :: var(5), sum1
24+
type(t2) :: var2(3), sum2
25+
integer :: i
26+
27+
var%x = [(2*i, i = 1,5)]
28+
var2%y = [(5*i+1, i = 1,3)]
29+
sum1%x = 0
30+
sum2%y = 0
31+
32+
!$omp parallel do reduction(+:sum1)
33+
do i = 1, size(var)
34+
sum1%x = sum1%x + var(i)%x
35+
end do
36+
37+
!$omp parallel do reduction(+:sum2)
38+
do i = 1, size(var2)
39+
sum2%y = sum2%y + var2(i)%y
40+
end do
41+
42+
if (sum1%x /= sum(var%x)) stop 1
43+
if (sum2%y /= sum(var2%y)) stop 2
44+
end
45+
46+
call sub2
47+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! Check that type renaming via module use is properly handled.
2+
3+
module zero
4+
implicit none
5+
type t
6+
integer :: x = 0
7+
end type t
8+
end module zero
9+
10+
module first
11+
use zero, only: t1 => t
12+
implicit none
13+
!$omp declare reduction(+: t1 : omp_out%x = omp_out%x + omp_in%x)
14+
end module
15+
16+
module second
17+
use zero, only: t2 => t
18+
implicit none
19+
!$omp declare reduction(+: t2 : omp_out%x = omp_out%x + omp_in%x)
20+
end module
21+
22+
subroutine sub2
23+
use first ! { dg-note "Previous !.OMP DECLARE REDUCTION from module 'first'" }
24+
use second ! { dg-error "Ambiguous !.OMP DECLARE REDUCTION 'operator \\+' for type 'TYPE\\(t\\)' from module 'second' at .1." }
25+
implicit none
26+
type(t1) :: var(5), sum1
27+
type(t2) :: var2(3), sum2
28+
end

0 commit comments

Comments
 (0)