Skip to content

Commit 47e9093

Browse files
kparzyszsvkeerthy
authored andcommitted
[flang][OpenMP] Verify that arguments to COPYPRIVATE are variables (#141823)
The check if the arguments are variable list items was missing, leading to a crash in lowering in some invalid situations. This fixes the first testcase reported in #141481
1 parent cdbb861 commit 47e9093

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ std::optional<bool> OmpStructureChecker::IsContiguous(
390390
object.u);
391391
}
392392

393+
void OmpStructureChecker::CheckVariableListItem(
394+
const SymbolSourceMap &symbols) {
395+
for (auto &[symbol, source] : symbols) {
396+
if (!IsVariableListItem(*symbol)) {
397+
context_.SayWithDecl(
398+
*symbol, source, "'%s' must be a variable"_err_en_US, symbol->name());
399+
}
400+
}
401+
}
402+
393403
void OmpStructureChecker::CheckMultipleOccurrence(
394404
semantics::UnorderedSymbolSet &listVars,
395405
const std::list<parser::Name> &nameList, const parser::CharBlock &item,
@@ -4587,6 +4597,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Copyprivate &x) {
45874597
CheckAllowedClause(llvm::omp::Clause::OMPC_copyprivate);
45884598
SymbolSourceMap symbols;
45894599
GetSymbolsInObjectList(x.v, symbols);
4600+
CheckVariableListItem(symbols);
45904601
CheckIntentInPointer(symbols, llvm::omp::Clause::OMPC_copyprivate);
45914602
CheckCopyingPolymorphicAllocatable(
45924603
symbols, llvm::omp::Clause::OMPC_copyprivate);
@@ -4859,12 +4870,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::From &x) {
48594870
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
48604871
SymbolSourceMap symbols;
48614872
GetSymbolsInObjectList(objList, symbols);
4862-
for (const auto &[symbol, source] : symbols) {
4863-
if (!IsVariableListItem(*symbol)) {
4864-
context_.SayWithDecl(
4865-
*symbol, source, "'%s' must be a variable"_err_en_US, symbol->name());
4866-
}
4867-
}
4873+
CheckVariableListItem(symbols);
48684874

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

49144915
// Ref: [4.5:109:19]
49154916
// If a list item is an array section it must specify contiguous storage.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class OmpStructureChecker
174174
bool IsExtendedListItem(const Symbol &sym);
175175
bool IsCommonBlock(const Symbol &sym);
176176
std::optional<bool> IsContiguous(const parser::OmpObject &object);
177+
void CheckVariableListItem(const SymbolSourceMap &symbols);
177178
void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
178179
const std::list<parser::Name> &nameList, const parser::CharBlock &item,
179180
const std::string &clauseName);

flang/test/Semantics/OpenMP/copyprivate04.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ program omp_copyprivate
7070
! Named constants are shared.
7171
!$omp single
7272
!ERROR: COPYPRIVATE variable 'pi' is not PRIVATE or THREADPRIVATE in outer context
73+
!ERROR: 'pi' must be a variable
7374
!$omp end single copyprivate(pi)
7475

7576
!$omp parallel do
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 -fopenmp
2+
3+
! The first testcase from https://github.com/llvm/llvm-project/issues/141481
4+
5+
subroutine f00
6+
type t
7+
end type
8+
9+
!ERROR: 't' must be a variable
10+
!$omp single copyprivate(t)
11+
!$omp end single
12+
end

0 commit comments

Comments
 (0)