Skip to content

Commit eb2f737

Browse files
committed
[flang][OpenMP] Add semantic check for target update
This patch adds the following semantic check for target update construct. ``` A list item can only appear in a to or from clause, but not in both. ```
1 parent 27033cc commit eb2f737

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,26 @@ void OmpStructureChecker::CheckTargetUpdate() {
14011401
context_.Say(GetContext().directiveSource,
14021402
"At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct."_err_en_US);
14031403
}
1404+
if (toClause && fromClause) {
1405+
SymbolSourceMap toSymbols, fromSymbols;
1406+
GetSymbolsInObjectList(
1407+
std::get<parser::OmpClause::To>(toClause->u).v, toSymbols);
1408+
GetSymbolsInObjectList(
1409+
std::get<parser::OmpClause::From>(fromClause->u).v, fromSymbols);
1410+
for (auto &[symbol, source] : toSymbols) {
1411+
auto fromSymbol = fromSymbols.find(symbol);
1412+
if (fromSymbol != fromSymbols.end()) {
1413+
context_.Say(source,
1414+
"A list item ('%s') can only appear in a TO or FROM clause, but not in both."_err_en_US,
1415+
symbol->name());
1416+
context_.Say(source, "'%s' appears in the TO clause."_because_en_US,
1417+
symbol->name());
1418+
context_.Say(fromSymbol->second,
1419+
"'%s' appears in the FROM clause."_because_en_US,
1420+
fromSymbol->first->name());
1421+
}
1422+
}
1423+
}
14041424
}
14051425

14061426
void OmpStructureChecker::Enter(

flang/test/Semantics/OpenMP/target-update01.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ subroutine foo(x)
1313
!ERROR: At most one NOWAIT clause can appear on the TARGET UPDATE directive
1414
!$omp target update to(x) nowait nowait
1515

16+
!ERROR: A list item ('x') can only appear in a TO or FROM clause, but not in both.
17+
!BECAUSE: 'x' appears in the TO clause.
18+
!BECAUSE: 'x' appears in the FROM clause.
19+
!$omp target update to(x) from(x)
20+
1621
end subroutine

0 commit comments

Comments
 (0)