[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.
This commit is contained in:
Michael Klemm 2025-08-19 17:52:27 +02:00 committed by GitHub
parent 538bd83b37
commit a5f1ddd115
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 1 deletions

View File

@ -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});
}
}

View File

@ -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