[flang-commits] [flang] 8349bbd - [flang][cuda] Exit early when there is no device components (#149005)

via flang-commits flang-commits at lists.llvm.org
Wed Jul 16 10:08:15 PDT 2025


Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-07-16T10:08:11-07:00
New Revision: 8349bbd0b98c84836d55593c7eb035c2b0f4e87a

URL: https://github.com/llvm/llvm-project/commit/8349bbd0b98c84836d55593c7eb035c2b0f4e87a
DIFF: https://github.com/llvm/llvm-project/commit/8349bbd0b98c84836d55593c7eb035c2b0f4e87a.diff

LOG: [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

Added: 
    

Modified: 
    flang/lib/Lower/ConvertVariable.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 2bfa9618aa4b9..6c4516686f9d0 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -802,13 +802,20 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter,
     const Fortran::semantics::DerivedTypeSpec *derived{type ? type->AsDerived()
                                                             : nullptr};
     if (derived) {
+      if (!FindCUDADeviceAllocatableUltimateComponent(*derived))
+        return; // No device components.
+
       fir::FirOpBuilder &builder = converter.getFirOpBuilder();
       mlir::Location loc = converter.getCurrentLocation();
 
       fir::ExtendedValue exv =
           converter.getSymbolExtendedValue(symbol.GetUltimate(), &symMap);
-      auto recTy = mlir::dyn_cast<fir::RecordType>(
-          fir::unwrapRefType(fir::getBase(exv).getType()));
+      mlir::Type baseTy = fir::unwrapRefType(fir::getBase(exv).getType());
+      if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(baseTy))
+        baseTy = boxTy.getEleTy();
+      baseTy = fir::unwrapRefType(baseTy);
+      auto recTy =
+          mlir::dyn_cast<fir::RecordType>(fir::unwrapSequenceType(baseTy));
       assert(recTy && "expected fir::RecordType");
 
       llvm::SmallVector<mlir::Value> coordinates;


        


More information about the flang-commits mailing list