Skip to content

Conversation

@clementval
Copy link
Contributor

  • Exit early when there is no device components
  • Make the retrieval of the record type more robust

@clementval clementval requested review from vzakhari and wangzpgi July 16, 2025 01:30
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Jul 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes
  • Exit early when there is no device components
  • Make the retrieval of the record type more robust

Full diff: https://github.com/llvm/llvm-project/pull/149005.diff

1 Files Affected:

  • (modified) flang/lib/Lower/ConvertVariable.cpp (+9-2)
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;

@clementval clementval merged commit 8349bbd into llvm:main Jul 16, 2025
12 checks passed
@clementval clementval deleted the cuf_fix_derived_type_assert branch July 16, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants