[flang-commits] [flang] a5f1ddd - [Flang][OpenMP] Fix issue with named constants in SHARED and FIRSTPRIVATE clauses (#154335)
via flang-commits
flang-commits at lists.llvm.org
Tue Aug 19 09:07:23 PDT 2025
Author: Michael Klemm
Date: 2025-08-19T17:52:27+02:00
New Revision: a5f1ddd115a7ec55bc085402cc73c4133894e3b0
URL: https://github.com/llvm/llvm-project/commit/a5f1ddd115a7ec55bc085402cc73c4133894e3b0
DIFF: https://github.com/llvm/llvm-project/commit/a5f1ddd115a7ec55bc085402cc73c4133894e3b0.diff
LOG: [Flang][OpenMP] Fix issue with named constants in SHARED and FIRSTPRIVATE clauses (#154335)
The seemingly was a regression that prevented the usage of named
constant (w/ PARAMETER attribute) in SHARED and FIRSTPRIVATE clauses.
This PR corrects that.
Added:
flang/test/Semantics/OpenMP/named-constants.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 9b1733796ddc8..2b36b085ae08d 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2560,11 +2560,24 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) {
break;
}
+ // Named constants are OK to be used within 'shared' and 'firstprivate'
+ // clauses. The check for this happens a few lines below.
+ bool SharedOrFirstprivate = false;
+ switch (x.Id()) {
+ case llvm::omp::Clause::OMPC_shared:
+ case llvm::omp::Clause::OMPC_firstprivate:
+ SharedOrFirstprivate = true;
+ break;
+ default:
+ break;
+ }
+
if (const parser::OmpObjectList *objList{GetOmpObjectList(x)}) {
SymbolSourceMap symbols;
GetSymbolsInObjectList(*objList, symbols);
for (const auto &[symbol, source] : symbols) {
- if (!IsVariableListItem(*symbol)) {
+ if (!IsVariableListItem(*symbol) &&
+ !(IsNamedConstant(*symbol) && SharedOrFirstprivate)) {
deferredNonVariables_.insert({symbol, source});
}
}
diff --git a/flang/test/Semantics/OpenMP/named-constants.f90 b/flang/test/Semantics/OpenMP/named-constants.f90
new file mode 100644
index 0000000000000..ac0850066cebe
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/named-constants.f90
@@ -0,0 +1,44 @@
+!RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+module named_constants
+ implicit none
+contains
+ subroutine shrd()
+ implicit none
+ integer, parameter :: n = 7
+ real, parameter :: m = 7.0
+ logical, parameter :: l = .false.
+ integer, dimension(3), parameter :: a = [1, 2, 3]
+ ! no error expected
+ !$omp parallel shared(n, m, l, a)
+ print *, n, m, l, a
+ !$omp end parallel
+ end subroutine shrd
+
+ subroutine frstprvt()
+ implicit none
+ integer, parameter :: n = 7
+ real, parameter :: m = 7.0
+ logical, parameter :: l = .false.
+ integer, dimension(3), parameter :: a = [1, 2, 3]
+ ! no error expected
+ !$omp parallel firstprivate(n, m, l, a)
+ print *, n, m, l, a
+ !$omp end parallel
+ end subroutine frstprvt
+
+ subroutine prvt()
+ implicit none
+ integer, parameter :: n = 7
+ real, parameter :: m = 7.0
+ logical, parameter :: l = .false.
+ integer, dimension(3), parameter :: a = [1, 2, 3]
+ !ERROR: 'n' must be a variable
+ !ERROR: 'm' must be a variable
+ !ERROR: 'l' must be a variable
+ !ERROR: 'a' must be a variable
+ !$omp parallel private(n, m, l, a)
+ print *, n, m, l, a
+ !$omp end parallel
+ end subroutine prvt
+end module named_constants
More information about the flang-commits
mailing list