Skip to content

Commit

Permalink
[flang][cuda] Enforce PINNED attribute when ALLOCATE with PINNED opti…
Browse files Browse the repository at this point in the history
…on (#89455)

When the PINNED option is specified on an ALLOCATE statement, the object
must have the PINNED attribute.
  • Loading branch information
clementval committed Apr 19, 2024
1 parent 7c3dfb2 commit 16e3464
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flang/lib/Semantics/check-allocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ bool AllocationCheckerHelper::RunChecks(SemanticsContext &context) {
return false;
}
}
if (allocateInfo_.gotPinned) {
std::optional<common::CUDADataAttr> cudaAttr{GetCUDADataAttr(ultimate_)};
if (!cudaAttr || *cudaAttr != common::CUDADataAttr::Pinned) {
context.Say(name_.source,
"Object in ALLOCATE must have PINNED attribute when PINNED option is specified"_err_en_US);
}
}
return RunCoarrayRelatedChecks(context);
}

Expand Down
8 changes: 8 additions & 0 deletions flang/test/Semantics/cuf07.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ module m
!BECAUSE: 'ma' is a host-associated allocatable and is not definable in a device subprogram
deallocate(ma)
end subroutine

subroutine hostsub()
integer, allocatable, device :: ia(:)
logical :: plog

!ERROR: Object in ALLOCATE must have PINNED attribute when PINNED option is specified
allocate(ia(100), pinned = plog)
end subroutine
end module

0 comments on commit 16e3464

Please sign in to comment.