[flang-commits] [flang] [flang][Semantics][OpenMP] Don't privatise associate names (PR #108856)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Tue Sep 17 02:45:23 PDT 2024
https://github.com/tblah updated https://github.com/llvm/llvm-project/pull/108856
>From 94fb66a3489fb7088f5e46bf5d9c5bb00ed9d1c5 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Mon, 16 Sep 2024 16:49:02 +0000
Subject: [PATCH 1/2] [flang][Semantics][OpenMP] Don't privatise associate
names
The associate name preserves the association with the selector
established in the associate statement. Therefore it is incorrect to
change the data-sharing attribute of the name.
Closes #58041
---
flang/lib/Semantics/resolve-directives.cpp | 7 ++++
flang/test/Semantics/OpenMP/private-assoc.f90 | 32 +++++++++++++++++++
2 files changed, 39 insertions(+)
create mode 100644 flang/test/Semantics/OpenMP/private-assoc.f90
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 723596ad6ce454..20a9ae895484e0 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -19,6 +19,7 @@
#include "flang/Parser/parse-tree.h"
#include "flang/Parser/tools.h"
#include "flang/Semantics/expression.h"
+#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
#include <list>
#include <map>
@@ -2728,6 +2729,12 @@ void OmpAttributeVisitor::CheckObjectInNamelist(
"Variable '%s' in NAMELIST cannot be in a %s clause"_err_en_US,
name.ToString(), clauseName.str());
}
+
+ if (ultimateSymbol.has<AssocEntityDetails>()) {
+ context_.Say(name.source,
+ "Variable '%s' in ASSOCIATE cannot be in a %s clause"_err_en_US,
+ name.ToString(), clauseName.str());
+ }
}
void OmpAttributeVisitor::CheckSourceLabel(const parser::Label &label) {
diff --git a/flang/test/Semantics/OpenMP/private-assoc.f90 b/flang/test/Semantics/OpenMP/private-assoc.f90
new file mode 100644
index 00000000000000..bf50cd11de1724
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/private-assoc.f90
@@ -0,0 +1,32 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+! The ASSOCIATE name preserves the association with the selector established
+! in the associate statement. Therefore it is incorrect to change the
+! data-sharing attribute of the name.
+
+subroutine assoc_private(x)
+ integer :: x
+ associate(z => x)
+ !ERROR: Variable 'z' in ASSOCIATE cannot be in a PRIVATE clause
+ !$omp parallel private(z)
+ !$omp end parallel
+ end associate
+end subroutine
+
+subroutine assoc_firstprivate(x)
+ integer :: x
+ associate(z => x)
+ !ERROR: Variable 'z' in ASSOCIATE cannot be in a FIRSTPRIVATE clause
+ !$omp parallel firstprivate(z)
+ !$omp end parallel
+ end associate
+end subroutine
+
+subroutine assoc_lastprivate(x)
+ integer :: x
+ associate(z => x)
+ !ERROR: Variable 'z' in ASSOCIATE cannot be in a LASTPRIVATE clause
+ !$omp parallel sections lastprivate(z)
+ !$omp end parallel sections
+ end associate
+end subroutine
>From 583d69c38a29d5e1f4e7d51b3f03952b525180e7 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Tue, 17 Sep 2024 09:44:05 +0000
Subject: [PATCH 2/2] Rename CheckObjectInNamelist
---
flang/lib/Semantics/resolve-directives.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 20a9ae895484e0..45fe17c0122c09 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -718,7 +718,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
void CheckDataCopyingClause(
const parser::Name &, const Symbol &, Symbol::Flag);
void CheckAssocLoopLevel(std::int64_t level, const parser::OmpClause *clause);
- void CheckObjectInNamelist(
+ void CheckObjectInNamelistOrAssociate(
const parser::Name &, const Symbol &, Symbol::Flag);
void CheckSourceLabel(const parser::Label &);
void CheckLabelContext(const parser::CharBlock, const parser::CharBlock,
@@ -2357,7 +2357,7 @@ void OmpAttributeVisitor::ResolveOmpObject(
CheckMultipleAppearances(*name, *symbol, ompFlag);
}
if (privateDataSharingAttributeFlags.test(ompFlag)) {
- CheckObjectInNamelist(*name, *symbol, ompFlag);
+ CheckObjectInNamelistOrAssociate(*name, *symbol, ompFlag);
}
if (ompFlag == Symbol::Flag::OmpAllocate) {
@@ -2714,7 +2714,7 @@ void OmpAttributeVisitor::CheckDataCopyingClause(
}
}
-void OmpAttributeVisitor::CheckObjectInNamelist(
+void OmpAttributeVisitor::CheckObjectInNamelistOrAssociate(
const parser::Name &name, const Symbol &symbol, Symbol::Flag ompFlag) {
const auto &ultimateSymbol{symbol.GetUltimate()};
llvm::StringRef clauseName{"PRIVATE"};
More information about the flang-commits
mailing list