Skip to content

Commit 0800f12

Browse files
committed
[flang][OpenMP] Don't allow namelist variables with threadprivate
While the standard doesn't explicitly mention namelist variables in this case, it does prohibit privatization of namelist variables. Flang decided to also prohibit namelist variables from appearing in a reduction clause. Variables that are part of a namelist are linked to I/O mechanisms, and their memory association and initialization are managed by the compiler in a way that conflicts with the requirements of threadprivate variables. I propose we should add this restriction.
1 parent 30fa7a2 commit 0800f12

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,10 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
15161516
"A variable in a %s directive cannot appear in an "
15171517
"EQUIVALENCE statement"_err_en_US,
15181518
ContextDirectiveAsFortran());
1519+
} else if (name->symbol->test(Symbol::Flag::InNamelist)) {
1520+
context_.Say(name->source,
1521+
"A variable in a %s directive cannot appear in a NAMELIST"_err_en_US,
1522+
ContextDirectiveAsFortran());
15191523
} else if (name->symbol->test(Symbol::Flag::OmpThreadprivate) &&
15201524
GetContext().directive ==
15211525
llvm::omp::Directive::OMPD_declare_target) {
@@ -1571,6 +1575,11 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
15711575
ContextDirectiveAsFortran(), obj->name(),
15721576
name.symbol->name());
15731577
}
1578+
if (obj->test(Symbol::Flag::InNamelist)) {
1579+
context_.Say(name.source,
1580+
"A variable in a %s directive cannot appear in a NAMELIST"_err_en_US,
1581+
ContextDirectiveAsFortran());
1582+
}
15741583
}
15751584
}
15761585
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags
2+
3+
! Check that namelist variables cannot be used with threadprivate
4+
5+
module m
6+
integer :: nam1
7+
common /com1/nam1
8+
namelist /nam/nam1
9+
10+
!ERROR: A variable in a THREADPRIVATE directive cannot appear in a NAMELIST
11+
!$omp threadprivate(/com1/)
12+
end

0 commit comments

Comments
 (0)