Skip to content

Commit a5f1ddd

Browse files
authored
[Flang][OpenMP] Fix issue with named constants in SHARED and FIRSTPRIVATE clauses (llvm#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.
1 parent 538bd83 commit a5f1ddd

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,11 +2560,24 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) {
25602560
break;
25612561
}
25622562

2563+
// Named constants are OK to be used within 'shared' and 'firstprivate'
2564+
// clauses. The check for this happens a few lines below.
2565+
bool SharedOrFirstprivate = false;
2566+
switch (x.Id()) {
2567+
case llvm::omp::Clause::OMPC_shared:
2568+
case llvm::omp::Clause::OMPC_firstprivate:
2569+
SharedOrFirstprivate = true;
2570+
break;
2571+
default:
2572+
break;
2573+
}
2574+
25632575
if (const parser::OmpObjectList *objList{GetOmpObjectList(x)}) {
25642576
SymbolSourceMap symbols;
25652577
GetSymbolsInObjectList(*objList, symbols);
25662578
for (const auto &[symbol, source] : symbols) {
2567-
if (!IsVariableListItem(*symbol)) {
2579+
if (!IsVariableListItem(*symbol) &&
2580+
!(IsNamedConstant(*symbol) && SharedOrFirstprivate)) {
25682581
deferredNonVariables_.insert({symbol, source});
25692582
}
25702583
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
!RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
module named_constants
4+
implicit none
5+
contains
6+
subroutine shrd()
7+
implicit none
8+
integer, parameter :: n = 7
9+
real, parameter :: m = 7.0
10+
logical, parameter :: l = .false.
11+
integer, dimension(3), parameter :: a = [1, 2, 3]
12+
! no error expected
13+
!$omp parallel shared(n, m, l, a)
14+
print *, n, m, l, a
15+
!$omp end parallel
16+
end subroutine shrd
17+
18+
subroutine frstprvt()
19+
implicit none
20+
integer, parameter :: n = 7
21+
real, parameter :: m = 7.0
22+
logical, parameter :: l = .false.
23+
integer, dimension(3), parameter :: a = [1, 2, 3]
24+
! no error expected
25+
!$omp parallel firstprivate(n, m, l, a)
26+
print *, n, m, l, a
27+
!$omp end parallel
28+
end subroutine frstprvt
29+
30+
subroutine prvt()
31+
implicit none
32+
integer, parameter :: n = 7
33+
real, parameter :: m = 7.0
34+
logical, parameter :: l = .false.
35+
integer, dimension(3), parameter :: a = [1, 2, 3]
36+
!ERROR: 'n' must be a variable
37+
!ERROR: 'm' must be a variable
38+
!ERROR: 'l' must be a variable
39+
!ERROR: 'a' must be a variable
40+
!$omp parallel private(n, m, l, a)
41+
print *, n, m, l, a
42+
!$omp end parallel
43+
end subroutine prvt
44+
end module named_constants

0 commit comments

Comments
 (0)