* [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
@ 2022-03-18 16:27 Tobias Burnus
2022-03-18 16:38 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2022-03-18 16:27 UTC (permalink / raw)
To: gcc-patches, fortran, Jakub Jelinek
[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]
SELECT TYPE, SELECT RANK and ASSOCIATE have
associate-name => selector
and create a pointer to the selector.
GCC was fixed to handle CLASS properly in
class(t) :: var
!$omp ... firstprivate(var)
As a side effect, firstprivate(assoc_name) now also gets
handled that way, effectively trying to firstprivate(selector)
which should be shared...
While firstprivate(var) does not appear explicitly, it gets
added via gfc_omp_predetermined_sharing.
I went for the simple solution and handle it only
in gfortran's ctor/dtor.
An alternative would be to set OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE,
which is currently only set for C++'s __for_end / __for_range
and then later process it in ctor/dtor. I am not sure whether that's
really best and what's the best way to propagate it. One way would
be to create and use OMP_CLAUSE_DEFAULT_FIRSTPRIVATE_NO_REFERENCE.
OK as is (simple version) – or is a fuller version better. If so,
suggestion how to do this best?
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: fix-assoc-name-priv.diff --]
[-- Type: text/x-patch, Size: 3893 bytes --]
Fortran/OpenMP: Fix privatization of associated names
gfc_omp_predetermined_sharing cases the associate-name pointer variable
to be OMP_CLAUSE_DEFAULT_FIRSTPRIVATE, which is fine. However, the associated
selector is shared. Thus, the target of associate-name pointer should not get
copied. (It was before but because of gfc_omp_privatize_by_reference returning
false, the selector was not only wrongly copied but this was also not done
properly.)
gcc/fortran/ChangeLog:
PR fortran/103039
* trans-openmp.cc (gfc_omp_clause_copy_ctor, gfc_omp_clause_dtor):
Only privatize pointer for associate names.
libgomp/ChangeLog:
PR fortran/103039
* testsuite/libgomp.fortran/associate4.f90: New test.
gcc/fortran/trans-openmp.cc | 10 +++
libgomp/testsuite/libgomp.fortran/associate4.f90 | 92 ++++++++++++++++++++++++
2 files changed, 102 insertions(+)
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index fad76a4791f..101924f5e76 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -808,6 +808,11 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE
|| OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
+ /* Privatize pointer, only; cf. gfc_omp_predetermined_sharing. */
+ if (DECL_P (OMP_CLAUSE_DECL (clause))
+ && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
+ return build2 (MODIFY_EXPR, TREE_TYPE (dest), dest, src);
+
if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
&& DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
&& GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
@@ -1321,6 +1326,11 @@ gfc_omp_clause_dtor (tree clause, tree decl)
tree type = TREE_TYPE (decl), tem;
tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
+ /* Only pointer was privatized; cf. gfc_omp_clause_copy_ctor. */
+ if (DECL_P (OMP_CLAUSE_DECL (clause))
+ && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
+ return NULL_TREE;
+
if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
&& DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
&& GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
diff --git a/libgomp/testsuite/libgomp.fortran/associate4.f90 b/libgomp/testsuite/libgomp.fortran/associate4.f90
new file mode 100644
index 00000000000..f0949b5530d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/associate4.f90
@@ -0,0 +1,92 @@
+! PR fortran/51722
+
+module m
+implicit none
+
+contains
+
+subroutine seltype
+
+type :: a
+ integer :: p = 2
+end type a
+
+type, extends(a) :: b
+ integer :: cnt = 0
+end type b
+
+integer :: k, s
+class(a), pointer :: x
+
+allocate(a :: x)
+s = 0
+select type (y => x)
+class is (a)
+!$omp parallel do default(shared) private(k) reduction(+:s)
+ do k = 1,10
+ s = s + k*y%p
+ end do
+!$omp end parallel do
+end select
+
+if (s /= 110) error stop
+deallocate(x)
+allocate(b :: x)
+
+s = 0
+select type (y => x)
+class is (b)
+!$omp parallel do default(shared) private(k) reduction(+:s)
+ do k = 1,10
+ s = s + k*y%p
+!$omp atomic update
+ y%cnt = y%cnt + 2
+ end do
+!$omp end parallel do
+if (s /= 110) error stop
+if (y%p /= 2) error stop
+if (y%cnt /= 10*2) error stop
+end select
+
+deallocate(x)
+
+end subroutine seltype
+
+subroutine assoc
+
+type :: b
+ integer :: r = 3
+end type b
+
+type :: a
+ integer :: p = 2
+ class(b), pointer :: u => null()
+end type a
+
+integer :: k, s
+class(a), pointer :: x
+
+s = 0
+allocate(a :: x)
+allocate(b :: x%u)
+
+associate(f => x%u)
+!$omp parallel do default(shared) private(k) reduction(+:s)
+ do k = 1,10
+ s = s + k*f%r
+ end do
+!$omp end parallel do
+end associate
+
+deallocate(x%u)
+deallocate(x)
+
+if (s /= 165) error stop
+end subroutine assoc
+end module m
+
+use m
+implicit none (type, external)
+call seltype
+call assoc
+end
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
2022-03-18 16:27 [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039] Tobias Burnus
@ 2022-03-18 16:38 ` Jakub Jelinek
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2022-03-18 16:38 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
On Fri, Mar 18, 2022 at 05:27:02PM +0100, Tobias Burnus wrote:
> SELECT TYPE, SELECT RANK and ASSOCIATE have
> associate-name => selector
> and create a pointer to the selector.
>
> GCC was fixed to handle CLASS properly in
> class(t) :: var
> !$omp ... firstprivate(var)
> As a side effect, firstprivate(assoc_name) now also gets
> handled that way, effectively trying to firstprivate(selector)
> which should be shared...
>
> While firstprivate(var) does not appear explicitly, it gets
> added via gfc_omp_predetermined_sharing.
>
> I went for the simple solution and handle it only
> in gfortran's ctor/dtor.
>
> An alternative would be to set OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE,
> which is currently only set for C++'s __for_end / __for_range
> and then later process it in ctor/dtor. I am not sure whether that's
> really best and what's the best way to propagate it. One way would
> be to create and use OMP_CLAUSE_DEFAULT_FIRSTPRIVATE_NO_REFERENCE.
>
> OK as is (simple version) – or is a fuller version better. If so,
> suggestion how to do this best?
LGTM.
> Fortran/OpenMP: Fix privatization of associated names
>
> gfc_omp_predetermined_sharing cases the associate-name pointer variable
> to be OMP_CLAUSE_DEFAULT_FIRSTPRIVATE, which is fine. However, the associated
> selector is shared. Thus, the target of associate-name pointer should not get
> copied. (It was before but because of gfc_omp_privatize_by_reference returning
> false, the selector was not only wrongly copied but this was also not done
> properly.)
>
> gcc/fortran/ChangeLog:
>
> PR fortran/103039
> * trans-openmp.cc (gfc_omp_clause_copy_ctor, gfc_omp_clause_dtor):
> Only privatize pointer for associate names.
>
> libgomp/ChangeLog:
>
> PR fortran/103039
> * testsuite/libgomp.fortran/associate4.f90: New test.
>
> gcc/fortran/trans-openmp.cc | 10 +++
> libgomp/testsuite/libgomp.fortran/associate4.f90 | 92 ++++++++++++++++++++++++
> 2 files changed, 102 insertions(+)
>
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
2022-03-18 13:15 Tobias Burnus
@ 2022-03-18 13:21 ` Jakub Jelinek
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2022-03-18 13:21 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
On Fri, Mar 18, 2022 at 02:15:11PM +0100, Tobias Burnus wrote:
> This patch addresses a side issue found when looking at PR103039.
>
> Namely instead of printing:
>
> 55 | !$omp parallel firstprivate(tt)
> | 1
> Error: ASSOCIATE name ‘__tmp_INTEGER_4’ in FIRSTPRIVATE clause at (1)
>
> With the patch, the error is:
>
> Error: Associate name ‘tt’ in FIRSTPRIVATE clause at (1)
>
> That is: It prints the proper name and it uses 'associate name'
> matching the Fortran standard – and takes into account that an
> associate name not only used with ASSOCIATE but also with
> SELECT TYPE, SELECT RANK, and (untested) CHANGE TEAMS.
>
> OK for mainline?
LGTM, thanks.
> Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
>
> gcc/fortran/ChangeLog:
>
> PR fortran/103039
> * openmp.cc (resolve_omp_clauses): Improve associate-name diagnostic
> for select type/rank.
>
> gcc/testsuite/ChangeLog:
>
> PR fortran/103039
> * gfortran.dg/gomp/associate1.f90: Update dg-error.
> * gfortran.dg/gomp/associate2.f90: New test.
>
> gcc/fortran/openmp.cc | 12 +++--
> gcc/testsuite/gfortran.dg/gomp/associate1.f90 | 40 +++++++-------
> gcc/testsuite/gfortran.dg/gomp/associate2.f90 | 76 +++++++++++++++++++++++++++
> 3 files changed, 104 insertions(+), 24 deletions(-)
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
@ 2022-03-18 13:15 Tobias Burnus
2022-03-18 13:21 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2022-03-18 13:15 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches, fortran
[-- Attachment #1: Type: text/plain, Size: 905 bytes --]
This patch addresses a side issue found when looking at PR103039.
Namely instead of printing:
55 | !$omp parallel firstprivate(tt)
| 1
Error: ASSOCIATE name ‘__tmp_INTEGER_4’ in FIRSTPRIVATE clause at (1)
With the patch, the error is:
Error: Associate name ‘tt’ in FIRSTPRIVATE clause at (1)
That is: It prints the proper name and it uses 'associate name'
matching the Fortran standard – and takes into account that an
associate name not only used with ASSOCIATE but also with
SELECT TYPE, SELECT RANK, and (untested) CHANGE TEAMS.
OK for mainline?
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: openmp-assoc-name.diff --]
[-- Type: text/x-patch, Size: 7594 bytes --]
Fortran/OpenMP: Improve associate-name diagnostic [PR103039]
gcc/fortran/ChangeLog:
PR fortran/103039
* openmp.cc (resolve_omp_clauses): Improve associate-name diagnostic
for select type/rank.
gcc/testsuite/ChangeLog:
PR fortran/103039
* gfortran.dg/gomp/associate1.f90: Update dg-error.
* gfortran.dg/gomp/associate2.f90: New test.
gcc/fortran/openmp.cc | 12 +++--
gcc/testsuite/gfortran.dg/gomp/associate1.f90 | 40 +++++++-------
gcc/testsuite/gfortran.dg/gomp/associate2.f90 | 76 +++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 24 deletions(-)
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 16cd03a3d67..714148138c2 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -6782,8 +6782,10 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
gfc_error ("Cray pointee %qs in SHARED clause at %L",
n->sym->name, &n->where);
if (n->sym->attr.associate_var)
- gfc_error ("ASSOCIATE name %qs in SHARED clause at %L",
- n->sym->name, &n->where);
+ gfc_error ("Associate name %qs in SHARED clause at %L",
+ n->sym->attr.select_type_temporary
+ ? n->sym->assoc->target->symtree->n.sym->name
+ : n->sym->name, &n->where);
if (omp_clauses->detach
&& n->sym == omp_clauses->detach->symtree->n.sym)
gfc_error ("DETACH event handle %qs in SHARED clause at %L",
@@ -7163,8 +7165,10 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
gfc_error ("Cray pointee %qs in %s clause at %L",
n->sym->name, name, &n->where);
if (n->sym->attr.associate_var)
- gfc_error ("ASSOCIATE name %qs in %s clause at %L",
- n->sym->name, name, &n->where);
+ gfc_error ("Associate name %qs in %s clause at %L",
+ n->sym->attr.select_type_temporary
+ ? n->sym->assoc->target->symtree->n.sym->name
+ : n->sym->name, name, &n->where);
if (list != OMP_LIST_PRIVATE && is_reduction)
{
if (n->sym->attr.proc_pointer)
diff --git a/gcc/testsuite/gfortran.dg/gomp/associate1.f90 b/gcc/testsuite/gfortran.dg/gomp/associate1.f90
index abc5ae95a0d..a44099e005f 100644
--- a/gcc/testsuite/gfortran.dg/gomp/associate1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/associate1.f90
@@ -16,65 +16,65 @@ program associate1
j = 2
associate(k => v, l => a(i, j), m => a(i, :))
associate(n => b(j)%c(:, :)%i, o => a, p => b)
-!$omp parallel shared (l) ! { dg-error "ASSOCIATE name" }
+!$omp parallel shared (l) ! { dg-error "Associate name" }
!$omp end parallel
-!$omp parallel firstprivate (m) ! { dg-error "ASSOCIATE name" }
+!$omp parallel firstprivate (m) ! { dg-error "Associate name" }
!$omp end parallel
-!$omp parallel reduction (+: k) ! { dg-error "ASSOCIATE name" }
+!$omp parallel reduction (+: k) ! { dg-error "Associate name" }
!$omp end parallel
-!$omp parallel do firstprivate (k) ! { dg-error "ASSOCIATE name" }
+!$omp parallel do firstprivate (k) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp parallel do lastprivate (n) ! { dg-error "ASSOCIATE name" }
+!$omp parallel do lastprivate (n) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp parallel do private (o) ! { dg-error "ASSOCIATE name" }
+!$omp parallel do private (o) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp parallel do shared (p) ! { dg-error "ASSOCIATE name" }
+!$omp parallel do shared (p) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp task private (k) ! { dg-error "ASSOCIATE name" }
+!$omp task private (k) ! { dg-error "Associate name" }
!$omp end task
-!$omp task shared (l) ! { dg-error "ASSOCIATE name" }
+!$omp task shared (l) ! { dg-error "Associate name" }
!$omp end task
-!$omp task firstprivate (m) ! { dg-error "ASSOCIATE name" }
+!$omp task firstprivate (m) ! { dg-error "Associate name" }
!$omp end task
-!$omp do private (l) ! { dg-error "ASSOCIATE name" }
+!$omp do private (l) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp do reduction (*: k) ! { dg-error "ASSOCIATE name" }
+!$omp do reduction (*: k) ! { dg-error "Associate name" }
do i = 1, 10
end do
-!$omp sections private(o) ! { dg-error "ASSOCIATE name" }
+!$omp sections private(o) ! { dg-error "Associate name" }
!$omp section
!$omp section
!$omp end sections
-!$omp parallel sections firstprivate(p) ! { dg-error "ASSOCIATE name" }
+!$omp parallel sections firstprivate(p) ! { dg-error "Associate name" }
!$omp section
!$omp section
!$omp endparallelsections
-!$omp parallelsections lastprivate(m) ! { dg-error "ASSOCIATE name" }
+!$omp parallelsections lastprivate(m) ! { dg-error "Associate name" }
!$omp section
!$omp section
!$omp endparallelsections
-!$omp sections reduction(+:k) ! { dg-error "ASSOCIATE name" }
+!$omp sections reduction(+:k) ! { dg-error "Associate name" }
!$omp section
!$omp section
!$omp end sections
-!$omp simd private (l) ! { dg-error "ASSOCIATE name" }
+!$omp simd private (l) ! { dg-error "Associate name" }
do i = 1, 10
end do
k = 1
-!$omp simd lastprivate (m) ! { dg-error "ASSOCIATE name" }
+!$omp simd lastprivate (m) ! { dg-error "Associate name" }
do i = 1, 10
end do
k = 1
-!$omp simd reduction (+: k) ! { dg-error "ASSOCIATE name" }
+!$omp simd reduction (+: k) ! { dg-error "Associate name" }
do i = 1, 10
end do
k = 1
-!$omp simd linear (k : 2) ! { dg-error "ASSOCIATE name" }
+!$omp simd linear (k : 2) ! { dg-error "Associate name" }
do i = 1, 10
k = k + 2
end do
diff --git a/gcc/testsuite/gfortran.dg/gomp/associate2.f90 b/gcc/testsuite/gfortran.dg/gomp/associate2.f90
new file mode 100644
index 00000000000..d4e97cb0ed2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/associate2.f90
@@ -0,0 +1,76 @@
+! { dg-do compile }
+!
+! PR fortran/103039
+!
+
+subroutine shared_test(cc, ar)
+implicit none
+class(*) :: cc
+integer :: ar(..)
+
+associate(aa => cc)
+ !$omp parallel shared(aa) ! { dg-error "Associate name 'aa' in SHARED clause" }
+ !$omp end parallel
+end associate
+
+select type(tt => cc)
+ type is (integer)
+ !$omp parallel shared(tt) ! { dg-error "Associate name 'tt' in SHARED clause" }
+ !$omp end parallel
+end select
+
+select type(cc)
+ type is (integer)
+ !$omp parallel shared(cc) ! { dg-error "Associate name 'cc' in SHARED clause" }
+ !$omp end parallel
+end select
+
+select rank(rr => ar)
+ rank(1)
+ !$omp parallel shared(rr) ! { dg-error "Associate name 'rr' in SHARED clause" }
+ !$omp end parallel
+end select
+
+select rank(ar)
+ rank(1)
+ !$omp parallel shared(ar) ! { dg-error "Associate name 'ar' in SHARED clause" }
+ !$omp end parallel
+end select
+end
+
+
+
+subroutine firstprivate_test(cc, ar)
+implicit none
+class(*) :: cc
+integer :: ar(..)
+
+associate(aa => cc)
+ !$omp parallel firstprivate(aa) ! { dg-error "Associate name 'aa' in FIRSTPRIVATE clause" }
+ !$omp end parallel
+end associate
+
+select type(tt => cc)
+ type is (integer)
+ !$omp parallel firstprivate(tt) ! { dg-error "Associate name 'tt' in FIRSTPRIVATE clause" }
+ !$omp end parallel
+end select
+
+select type(cc)
+ type is (integer)
+ !$omp parallel firstprivate(cc) ! { dg-error "Associate name 'cc' in FIRSTPRIVATE clause" }
+ !$omp end parallel
+end select
+
+select rank(rr => ar)
+ rank(1)
+ !$omp parallel firstprivate(rr) ! { dg-error "Associate name 'rr' in FIRSTPRIVATE clause" }
+ !$omp end parallel
+end select
+
+select rank(ar)
+ rank(1)
+ !$omp parallel firstprivate(ar) ! { dg-error "Associate name 'ar' in FIRSTPRIVATE clause" }
+ !$omp end parallel
+end select
+end
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-18 16:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 16:27 [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039] Tobias Burnus
2022-03-18 16:38 ` Jakub Jelinek
-- strict thread matches above, loose matches on Subject: below --
2022-03-18 13:15 Tobias Burnus
2022-03-18 13:21 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).