Skip to content

Commit 8349bbd

Browse files
authored
[flang][cuda] Exit early when there is no device components (#149005)
- Exit early when there is no device components - Make the retrieval of the record type more robust
1 parent bd6c16c commit 8349bbd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,20 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter,
802802
const Fortran::semantics::DerivedTypeSpec *derived{type ? type->AsDerived()
803803
: nullptr};
804804
if (derived) {
805+
if (!FindCUDADeviceAllocatableUltimateComponent(*derived))
806+
return; // No device components.
807+
805808
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
806809
mlir::Location loc = converter.getCurrentLocation();
807810

808811
fir::ExtendedValue exv =
809812
converter.getSymbolExtendedValue(symbol.GetUltimate(), &symMap);
810-
auto recTy = mlir::dyn_cast<fir::RecordType>(
811-
fir::unwrapRefType(fir::getBase(exv).getType()));
813+
mlir::Type baseTy = fir::unwrapRefType(fir::getBase(exv).getType());
814+
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(baseTy))
815+
baseTy = boxTy.getEleTy();
816+
baseTy = fir::unwrapRefType(baseTy);
817+
auto recTy =
818+
mlir::dyn_cast<fir::RecordType>(fir::unwrapSequenceType(baseTy));
812819
assert(recTy && "expected fir::RecordType");
813820

814821
llvm::SmallVector<mlir::Value> coordinates;

0 commit comments

Comments
 (0)