[flang-commits] [flang] 5198923 - [flang][OpenMP] Allow common blocks in nested directives (#88430)
via flang-commits
flang-commits at lists.llvm.org
Mon Apr 22 06:19:46 PDT 2024
Author: Leandro Lupori
Date: 2024-04-22T10:19:42-03:00
New Revision: 5198923c70bb5b91b07e15ce141339d778322635
URL: https://github.com/llvm/llvm-project/commit/5198923c70bb5b91b07e15ce141339d778322635
DIFF: https://github.com/llvm/llvm-project/commit/5198923c70bb5b91b07e15ce141339d778322635.diff
LOG: [flang][OpenMP] Allow common blocks in nested directives (#88430)
COMMON block names must be declared in the same scoping unit in
which the OpenMP directive or clause appears, but OpenMP
constructs must not be considered as scoping units. Instead,
consider only program units and block constructs as such.
Added:
Modified:
flang/lib/Semantics/resolve-directives.cpp
flang/test/Semantics/OpenMP/resolve03.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index f4ac7f198d854e..318687508ff1f5 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2096,15 +2096,10 @@ Symbol *OmpAttributeVisitor::ResolveOmpCommonBlockName(
if (!name) {
return nullptr;
}
- // First check if the Common Block is declared in the current scope
- if (auto *cur{GetContext().scope.FindCommonBlock(name->source)}) {
- name->symbol = cur;
- return cur;
- }
- // Then check parent scope
- if (auto *prev{GetContext().scope.parent().FindCommonBlock(name->source)}) {
- name->symbol = prev;
- return prev;
+ if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
+ .FindCommonBlock(name->source)}) {
+ name->symbol = cb;
+ return cb;
}
return nullptr;
}
diff --git a/flang/test/Semantics/OpenMP/resolve03.f90 b/flang/test/Semantics/OpenMP/resolve03.f90
index b9306c4fe9cb4d..ebc66ca12ebf44 100644
--- a/flang/test/Semantics/OpenMP/resolve03.f90
+++ b/flang/test/Semantics/OpenMP/resolve03.f90
@@ -8,6 +8,9 @@
common /c/ a, b
integer a(3), b
+ common /tc/ x
+ integer x
+ !$omp threadprivate(/tc/)
A = 1
B = 2
@@ -19,4 +22,26 @@
!$omp end parallel
end block
print *, a, b
+
+ !$omp parallel
+ block
+ !$omp single
+ x = 18
+ !ERROR: COMMON block must be declared in the same scoping unit in which the OpenMP directive or clause appears
+ !$omp end single copyprivate(/tc/)
+ end block
+ !$omp end parallel
+
+ ! Common block names may be used inside nested OpenMP directives.
+ !$omp parallel
+ !$omp parallel copyin(/tc/)
+ x = x + 10
+ !$omp end parallel
+ !$omp end parallel
+
+ !$omp parallel
+ !$omp single
+ x = 18
+ !$omp end single copyprivate(/tc/)
+ !$omp end parallel
end
More information about the flang-commits
mailing list