[flang-commits] [flang] [flang][cuda] Avoid generating wrong fir.cuda_free op (PR #91255)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Mon May 6 11:52:52 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/91255

fir.cuda_free operation was wrongly generated for dummy argument. 

>From 5f864b9d2556b079c00c3504ee37fc3158111f56 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 6 May 2024 11:50:30 -0700
Subject: [PATCH] [flang][cuda] Avoid generating wrong fir.cuda_free op

---
 flang/include/flang/Semantics/tools.h         | 2 ++
 flang/test/Lower/CUDA/cuda-data-attribute.cuf | 7 +++++++
 2 files changed, 9 insertions(+)

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
 
 



More information about the flang-commits mailing list