[flang-commits] [flang] [flang][cuda] Propagate CUDA attrs from parent variable to component allocations (PR #206614)

Vijay Kandiah via flang-commits flang-commits at lists.llvm.org
Mon Jun 29 16:51:28 PDT 2026


================
@@ -459,17 +459,41 @@ class AllocateStmtHelper {
     fir::StoreOp::create(builder, loc, falseConv, pinned);
   }
 
+  /// When the allocate object is a structure component
+  /// (e.g., managed_var(1)%component), check whether the base variable has
+  /// CUDA attributes. If so, update \p sym to the base symbol and return true
+  /// so allocations use the parent's memory space.
+  bool propagateCUDAAttrsFromParent(const Allocation &alloc,
+                                    const Fortran::semantics::Symbol *&sym) {
+    if (const auto *sc = std::get_if<Fortran::parser::StructureComponent>(
+            &alloc.getAllocObj().u)) {
+      const Fortran::parser::Name &baseName =
+          Fortran::parser::GetFirstName(*sc);
+      if (baseName.symbol &&
+          (Fortran::semantics::HasCUDAAttr(*baseName.symbol) ||
+           Fortran::semantics::HasCUDAComponent(*baseName.symbol))) {
----------------
VijayKandiah wrote:

Agree, `HasCUDAComponent` on the parent is too broad. Removed the check.

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


More information about the flang-commits mailing list