[flang-commits] [flang] [flang][cuda] Avoid generating wrong fir.cuda_free op (PR #91255)
via flang-commits
flang-commits at lists.llvm.org
Mon May 6 11:53:23 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
fir.cuda_free operation was wrongly generated for dummy argument.
---
Full diff: https://github.com/llvm/llvm-project/pull/91255.diff
2 Files Affected:
- (modified) flang/include/flang/Semantics/tools.h (+2)
- (modified) flang/test/Lower/CUDA/cuda-data-attribute.cuf (+7)
``````````diff
diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index 835d5f11c1772b..46978441a640ee 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -224,6 +224,8 @@ inline bool HasCUDAAttr(const Symbol &sym) {
inline bool NeedCUDAAlloc(const Symbol &sym) {
bool inDeviceSubprogram{IsCUDADeviceContext(&sym.owner())};
+ if (Fortran::semantics::IsDummy(sym))
+ return false;
if (const auto *details{
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
if (details->cudaDataAttr() &&
diff --git a/flang/test/Lower/CUDA/cuda-data-attribute.cuf b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
index 083a3cacc02062..2688d220d8bb45 100644
--- a/flang/test/Lower/CUDA/cuda-data-attribute.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
@@ -85,6 +85,13 @@ end
! CHECK: fir.cuda_free %[[DECL_U]]#1 : !fir.ref<i32> {cuda_attr = #fir.cuda<unified>}
! CHECK: fir.cuda_free %[[DECL_A]]#1 : !fir.ref<!fir.array<10xf32>> {cuda_attr = #fir.cuda<device>}
+subroutine dummy(x)
+ real, target, device :: x
+end subroutine
+
+! CHECK: func.func @_QMcuda_varPdummy
+! CHECK-NOT: fir.cuda_free
+
end module
``````````
</details>
https://github.com/llvm/llvm-project/pull/91255
More information about the flang-commits
mailing list