Skip to content
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
3 changes: 2 additions & 1 deletion flang/lib/Optimizer/Builder/FIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,8 @@ static bool recordTypeCanBeMemCopied(fir::RecordType recordType) {
for (auto [_, fieldType] : recordType.getTypeList()) {
// Derived type component may have user assignment (so far, we cannot tell
// in FIR, so assume it is always the case, TODO: get the actual info).
if (mlir::isa<fir::RecordType>(fir::unwrapSequenceType(fieldType)))
if (mlir::isa<fir::RecordType>(fir::unwrapSequenceType(fieldType)) &&
!fir::isa_builtin_c_devptr_type(fir::unwrapSequenceType(fieldType)))
return false;
// Allocatable components need deep copy.
if (auto boxType = mlir::dyn_cast<fir::BaseBoxType>(fieldType))
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Lower/CUDA/cuda-devptr.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

module cudafct
use __fortran_builtins, only : c_devptr => __builtin_c_devptr

type :: t1
type(c_devptr) :: devp
integer :: a
end type

contains
function c_devloc(x)
use iso_c_binding, only: c_loc
Expand All @@ -12,6 +18,10 @@ contains
real, target, device :: x
c_devloc%cptr = c_loc(x)
end function

attributes(device) function get_t1()
type(t1) :: get_t1
end
end

subroutine sub1()
Expand Down Expand Up @@ -68,3 +78,12 @@ end subroutine
! CHECK: %[[P_ADDR_COORD:.*]] = fir.coordinate_of %[[P_CPTR_COORD]], %[[ADDRESS_FIELD]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
! CHECK: %[[ADDR:.*]] = fir.load %[[RES_ADDR_COORD]] : !fir.ref<i64>
! CHECK: fir.store %[[ADDR]] to %[[P_ADDR_COORD]] : !fir.ref<i64>

attributes(global) subroutine assign_nested_c_devptr(p, a)
use cudafct
type(t1), device :: p
p = get_t1()
end subroutine

! CHECK-LABEL: func.func @_QPassign_nested_c_devptr
! CHECK-NOT: fir.call @_FortranAAssign
Loading