[flang-commits] [flang] [flang][cuda] Call runtime initialize for derived type with device components (PR #157914)

via flang-commits flang-commits at lists.llvm.org
Wed Sep 10 10:58:26 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

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

<details>
<summary>Changes</summary>



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


2 Files Affected:

- (modified) flang/lib/Lower/ConvertVariable.cpp (+2-1) 
- (modified) flang/test/Lower/CUDA/cuda-allocatable-device.cuf (+8) 


``````````diff
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index b1cd14c56969a..ccfde16ce2c32 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -842,7 +842,8 @@ void Fortran::lower::defaultInitializeAtRuntime(
             Fortran::semantics::DeclTypeSpec::Category::TypeDerived &&
         !mlir::isa<fir::SequenceType>(symTy) &&
         !sym.test(Fortran::semantics::Symbol::Flag::OmpPrivate) &&
-        !sym.test(Fortran::semantics::Symbol::Flag::OmpFirstPrivate)) {
+        !sym.test(Fortran::semantics::Symbol::Flag::OmpFirstPrivate) &&
+        !Fortran::semantics::HasCUDAComponent(sym)) {
       std::string globalName = fir::NameUniquer::doGenerated(
           (converter.mangleName(*declTy->AsDerived()) + fir::kNameSeparator +
            fir::kDerivedTypeInitSuffix)
diff --git a/flang/test/Lower/CUDA/cuda-allocatable-device.cuf b/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
index aed52e7f0f49d..57c588e5beafa 100644
--- a/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
+++ b/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
@@ -12,3 +12,11 @@ end module
 ! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.device_array
 ! CHECK: fir.insert_value %{{.*}}, %c6{{.*}}, ["genre"
 ! CHECK: fir.insert_value %{{.*}}, %c5{{.*}}, ["genre"
+
+program main
+  use m
+  type(device_array) :: local
+end
+
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK: fir.call @_FortranAInitialize

``````````

</details>


https://github.com/llvm/llvm-project/pull/157914


More information about the flang-commits mailing list