[flang-commits] [flang] [flang][OpenACC] Resolve associations before testing declare flags (PR #221346)

via flang-commits flang-commits at lists.llvm.org
Fri Sep 4 14:08:13 PDT 2026


https://github.com/yebinchon created https://github.com/llvm/llvm-project/pull/221346

The OpenACC declare flags are set by semantics on a single symbol: the one resolved in the scope containing the !$acc declare directive. Any other scope naming the same entity reaches it through an association symbol, and those symbols carry their own, empty flag sets.
The allocate and deallocate action helpers tested the symbol taken straight from the ALLOCATE or DEALLOCATE statement. For an allocatable declared in a host scope and allocated in an internal subprogram the AccDeclare test
therefore failed, no acc.declare_action attribute was attached, and ACCDeclareActionConversion had nothing to convert. The emitted recipes were never called, so the device copy was neither created on allocation nor deleted on deallocation.
Resolve to the ultimate symbol and pass it on. Forwarding the resolved symbol is required because the deallocation attach helpers independently re-test the data clause flags.
This matches the rest of the OpenACC lowering, which already resolves before reading these flags. Recipe names are unaffected because mangleName resolves associations itself before mangling.

>From ca733b075830a9b6c5ce08f3d3044352cd1001e9 Mon Sep 17 00:00:00 2001
From: Yebin Chon <ychon at nvidia.com>
Date: Fri, 4 Sep 2026 14:04:21 -0700
Subject: [PATCH] [flang][OpenACC] Resolve associations before testing declare
 flags

---
 flang/lib/Lower/Allocatable.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 5f79b77592307..5f10319ab0101 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -484,9 +484,9 @@ class AllocateStmtHelper {
 
   void postAllocationAction(const Allocation &alloc,
                             const fir::MutableBoxValue &box) {
-    if (alloc.getSymbol().test(Fortran::semantics::Symbol::Flag::AccDeclare))
-      Fortran::lower::attachDeclarePostAllocAction(converter, builder,
-                                                   alloc.getSymbol());
+    auto &ult = alloc.getSymbol().GetUltimate();
+    if (ult.test(Fortran::semantics::Symbol::Flag::AccDeclare))
+      Fortran::lower::attachDeclarePostAllocAction(converter, builder, ult);
   }
 
   void setPinnedToFalse() {
@@ -929,16 +929,18 @@ static void preDeallocationAction(Fortran::lower::AbstractConverter &converter,
                                   fir::FirOpBuilder &builder,
                                   mlir::Value beginOpValue,
                                   const Fortran::semantics::Symbol &sym) {
-  if (sym.test(Fortran::semantics::Symbol::Flag::AccDeclare))
+  auto &ult = sym.GetUltimate();
+  if (ult.test(Fortran::semantics::Symbol::Flag::AccDeclare))
     Fortran::lower::attachDeclarePreDeallocAction(converter, builder,
-                                                  beginOpValue, sym);
+                                                  beginOpValue, ult);
 }
 
 static void postDeallocationAction(Fortran::lower::AbstractConverter &converter,
                                    fir::FirOpBuilder &builder,
                                    const Fortran::semantics::Symbol &sym) {
-  if (sym.test(Fortran::semantics::Symbol::Flag::AccDeclare))
-    Fortran::lower::attachDeclarePostDeallocAction(converter, builder, sym);
+  auto &ult = sym.GetUltimate();
+  if (ult.test(Fortran::semantics::Symbol::Flag::AccDeclare))
+    Fortran::lower::attachDeclarePostDeallocAction(converter, builder, ult);
 }
 
 static mlir::Value genCudaDeallocate(fir::FirOpBuilder &builder,



More information about the flang-commits mailing list