[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:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: yebinchon
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/221346.diff
1 Files Affected:
- (modified) flang/lib/Lower/Allocatable.cpp (+9-7)
``````````diff
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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/221346
More information about the flang-commits
mailing list