Skip to content

[flang][OpenMP] Add semantic check for device clause #72789

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 1 commit into from
Nov 21, 2023
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
11 changes: 11 additions & 0 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,17 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Device &x) {
const auto &device{std::get<1>(deviceClause.t)};
RequiresPositiveParameter(
llvm::omp::Clause::OMPC_device, device, "device expression");
std::optional<parser::OmpDeviceClause::DeviceModifier> modifier =
std::get<0>(deviceClause.t);
if (modifier &&
*modifier == parser::OmpDeviceClause::DeviceModifier::Ancestor) {
if (GetContext().directive != llvm::omp::OMPD_target) {
context_.Say(GetContext().clauseSource,
"The ANCESTOR device-modifier must not appear on the DEVICE clause on"
" any directive other than the TARGET construct. Found on %s construct."_err_en_US,
parser::ToUpperCaseLetters(getDirectiveName(GetContext().directive)));
}
}
}

void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
Expand Down
31 changes: 31 additions & 0 deletions flang/test/Semantics/OpenMP/device-clause01.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! OpenMP Version 5.2
! 13.2 Device clause

subroutine foo

integer :: a

!$omp target device(ancestor:0)
!$omp end target
!$omp target device(device_num:0)
!$omp end target

!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.
!$omp target data device(ancestor:0) map(tofrom:a)
!$omp end target data
!$omp target data device(device_num:0) map(tofrom:a)
!$omp end target data


!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.
!$omp target enter data device(ancestor:0) map(to:a)
!$omp target exit data map(from:a)
!$omp target enter data device(device_num:0) map(to:a)
!$omp target exit data map(from:a)

!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.
!$omp target update device(ancestor:0) to(a)
!$omp target update device(device_num:0) to(a)

end subroutine foo