[flang-commits] [flang] [flang][Semantics][OpenMP] Don't privatise associate names (PR #108856)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon Sep 16 09:55:20 PDT 2024
https://github.com/tblah created https://github.com/llvm/llvm-project/pull/108856
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
>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] [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
More information about the flang-commits
mailing list