Skip to content

[flang][OpenMP] Verify that arguments to COPYPRIVATE are variables #141823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ std::optional<bool> OmpStructureChecker::IsContiguous(
object.u);
}

void OmpStructureChecker::CheckVariableListItem(
const SymbolSourceMap &symbols) {
for (auto &[symbol, source] : symbols) {
if (!IsVariableListItem(*symbol)) {
context_.SayWithDecl(
*symbol, source, "'%s' must be a variable"_err_en_US, symbol->name());
}
}
}

void OmpStructureChecker::CheckMultipleOccurrence(
semantics::UnorderedSymbolSet &listVars,
const std::list<parser::Name> &nameList, const parser::CharBlock &item,
Expand Down Expand Up @@ -4587,6 +4597,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Copyprivate &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_copyprivate);
SymbolSourceMap symbols;
GetSymbolsInObjectList(x.v, symbols);
CheckVariableListItem(symbols);
CheckIntentInPointer(symbols, llvm::omp::Clause::OMPC_copyprivate);
CheckCopyingPolymorphicAllocatable(
symbols, llvm::omp::Clause::OMPC_copyprivate);
Expand Down Expand Up @@ -4859,12 +4870,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::From &x) {
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
SymbolSourceMap symbols;
GetSymbolsInObjectList(objList, symbols);
for (const auto &[symbol, source] : symbols) {
if (!IsVariableListItem(*symbol)) {
context_.SayWithDecl(
*symbol, source, "'%s' must be a variable"_err_en_US, symbol->name());
}
}
CheckVariableListItem(symbols);

// Ref: [4.5:109:19]
// If a list item is an array section it must specify contiguous storage.
Expand Down Expand Up @@ -4904,12 +4910,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::To &x) {
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
SymbolSourceMap symbols;
GetSymbolsInObjectList(objList, symbols);
for (const auto &[symbol, source] : symbols) {
if (!IsVariableListItem(*symbol)) {
context_.SayWithDecl(
*symbol, source, "'%s' must be a variable"_err_en_US, symbol->name());
}
}
CheckVariableListItem(symbols);

// Ref: [4.5:109:19]
// If a list item is an array section it must specify contiguous storage.
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class OmpStructureChecker
bool IsExtendedListItem(const Symbol &sym);
bool IsCommonBlock(const Symbol &sym);
std::optional<bool> IsContiguous(const parser::OmpObject &object);
void CheckVariableListItem(const SymbolSourceMap &symbols);
void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
const std::list<parser::Name> &nameList, const parser::CharBlock &item,
const std::string &clauseName);
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/copyprivate04.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ program omp_copyprivate
! Named constants are shared.
!$omp single
!ERROR: COPYPRIVATE variable 'pi' is not PRIVATE or THREADPRIVATE in outer context
!ERROR: 'pi' must be a variable
!$omp end single copyprivate(pi)

!$omp parallel do
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Semantics/OpenMP/copyprivate05.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp

! The first testcase from https://github.com/llvm/llvm-project/issues/141481

subroutine f00
type t
end type

!ERROR: 't' must be a variable
!$omp single copyprivate(t)
!$omp end single
end