Skip to content

Commit 525396a

Browse files
authored
[flang][OpenMP] Add semantic check for device clause (llvm#72789)
This patch adds the following semantic check: ``` The ancestor device-modifier must not appear on the device clause on any directive other than the target construct. ```
1 parent f48c4d8 commit 525396a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,17 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Device &x) {
27482748
const auto &device{std::get<1>(deviceClause.t)};
27492749
RequiresPositiveParameter(
27502750
llvm::omp::Clause::OMPC_device, device, "device expression");
2751+
std::optional<parser::OmpDeviceClause::DeviceModifier> modifier =
2752+
std::get<0>(deviceClause.t);
2753+
if (modifier &&
2754+
*modifier == parser::OmpDeviceClause::DeviceModifier::Ancestor) {
2755+
if (GetContext().directive != llvm::omp::OMPD_target) {
2756+
context_.Say(GetContext().clauseSource,
2757+
"The ANCESTOR device-modifier must not appear on the DEVICE clause on"
2758+
" any directive other than the TARGET construct. Found on %s construct."_err_en_US,
2759+
parser::ToUpperCaseLetters(getDirectiveName(GetContext().directive)));
2760+
}
2761+
}
27512762
}
27522763

27532764
void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
! OpenMP Version 5.2
3+
! 13.2 Device clause
4+
5+
subroutine foo
6+
7+
integer :: a
8+
9+
!$omp target device(ancestor:0)
10+
!$omp end target
11+
!$omp target device(device_num:0)
12+
!$omp end target
13+
14+
!ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET DATA construct.
15+
!$omp target data device(ancestor:0) map(tofrom:a)
16+
!$omp end target data
17+
!$omp target data device(device_num:0) map(tofrom:a)
18+
!$omp end target data
19+
20+
21+
!ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET ENTER DATA construct.
22+
!$omp target enter data device(ancestor:0) map(to:a)
23+
!$omp target exit data map(from:a)
24+
!$omp target enter data device(device_num:0) map(to:a)
25+
!$omp target exit data map(from:a)
26+
27+
!ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET UPDATE construct.
28+
!$omp target update device(ancestor:0) to(a)
29+
!$omp target update device(device_num:0) to(a)
30+
31+
end subroutine foo

0 commit comments

Comments
 (0)