Skip to content

Commit 16e3464

Browse files
authored
[flang][cuda] Enforce PINNED attribute when ALLOCATE with PINNED option (#89455)
When the PINNED option is specified on an ALLOCATE statement, the object must have the PINNED attribute.
1 parent 7c3dfb2 commit 16e3464

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

flang/lib/Semantics/check-allocate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ bool AllocationCheckerHelper::RunChecks(SemanticsContext &context) {
611611
return false;
612612
}
613613
}
614+
if (allocateInfo_.gotPinned) {
615+
std::optional<common::CUDADataAttr> cudaAttr{GetCUDADataAttr(ultimate_)};
616+
if (!cudaAttr || *cudaAttr != common::CUDADataAttr::Pinned) {
617+
context.Say(name_.source,
618+
"Object in ALLOCATE must have PINNED attribute when PINNED option is specified"_err_en_US);
619+
}
620+
}
614621
return RunCoarrayRelatedChecks(context);
615622
}
616623

flang/test/Semantics/cuf07.cuf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ module m
2323
!BECAUSE: 'ma' is a host-associated allocatable and is not definable in a device subprogram
2424
deallocate(ma)
2525
end subroutine
26+
27+
subroutine hostsub()
28+
integer, allocatable, device :: ia(:)
29+
logical :: plog
30+
31+
!ERROR: Object in ALLOCATE must have PINNED attribute when PINNED option is specified
32+
allocate(ia(100), pinned = plog)
33+
end subroutine
2634
end module

0 commit comments

Comments
 (0)