[flang-commits] [flang] [flang] [cuda] Fix CUDA implicit data transfer entity creation (PR #139414)
Zhen Wang via flang-commits
flang-commits at lists.llvm.org
Sat May 10 15:47:55 PDT 2025
https://github.com/wangzpgi created https://github.com/llvm/llvm-project/pull/139414
Fixed an issue in `genCUDAImplicitDataTransfer` where creating an `hlfir::Entity` from a symbol address could fail when the address comes from a `hlfir.declare` operation. Fix is to check if the address comes from a `hlfir.declare` operation. If so, use the base value from the declare op when available. Falling back to the original address otherwise.
>From 38d7efcebee251a71c7bbcfb9de3429755c32210 Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Sat, 10 May 2025 15:44:35 -0700
Subject: [PATCH] Fix CUDA implicit data transfer entity creation
---
flang/lib/Lower/Bridge.cpp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 43375e84f21fa..bfe8898ebff3d 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -4778,7 +4778,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
nbDeviceResidentObject <= 1 &&
"Only one reference to the device resident object is supported");
auto addr = getSymbolAddress(sym);
- hlfir::Entity entity{addr};
+ mlir::Value baseValue;
+ if (auto declareOp = llvm::dyn_cast<hlfir::DeclareOp>(addr.getDefiningOp()))
+ baseValue = declareOp.getBase();
+ else
+ baseValue = addr;
+
+ hlfir::Entity entity{baseValue};
auto [temp, cleanup] =
hlfir::createTempFromMold(loc, builder, entity);
auto needCleanup = fir::getIntIfConstant(cleanup);
More information about the flang-commits
mailing list