Skip to content

Commit f2a0dd3

Browse files
authored
[flang][cuda] Add restriction on assumed size device variable (llvm#87664)
According to https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfpg-var-qual-attr-device > A device array may be an explicit-shape array, an allocatable array, or an assumed-shape dummy array. Assumed size array are not supported. This patch adds an error for that case.
1 parent dad065d commit f2a0dd3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,11 @@ void CheckHelper::CheckObjectEntity(
948948
"Component '%s' with ATTRIBUTES(DEVICE) must also be allocatable"_err_en_US,
949949
symbol.name());
950950
}
951+
if (IsAssumedSizeArray(symbol)) {
952+
messages_.Say(
953+
"Object '%s' with ATTRIBUTES(DEVICE) may not be assumed size"_err_en_US,
954+
symbol.name());
955+
}
951956
break;
952957
case common::CUDADataAttr::Managed:
953958
if (!IsAutomatic(symbol) && !IsAllocatable(symbol) &&

flang/test/Semantics/cuf03.cuf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module m
5151
contains
5252
attributes(device) subroutine devsubr(n,da)
5353
integer, intent(in) :: n
54-
real, device :: da(*) ! ok
54+
!ERROR: Object 'da' with ATTRIBUTES(DEVICE) may not be assumed size
55+
real, device :: da(*)
5556
real, managed :: ma(n) ! ok
5657
!WARNING: Pointer 'dp' may not be associated in a device subprogram
5758
real, device, pointer :: dp

0 commit comments

Comments
 (0)