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

via flang-commits flang-commits at lists.llvm.org
Mon May 6 15:55:04 PDT 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-05-06T15:55:00-07:00
New Revision: ee9ca120e037b668c5d26853719368490a71fd40

URL: https://github.com/llvm/llvm-project/commit/ee9ca120e037b668c5d26853719368490a71fd40
DIFF: https://github.com/llvm/llvm-project/commit/ee9ca120e037b668c5d26853719368490a71fd40.diff

LOG: [flang][cuda] Avoid generating wrong fir.cuda_free op (#91255)

fir.cuda_free operation was wrongly generated for dummy argument.

Added: 
    

Modified: 
    flang/include/flang/Semantics/tools.h
    flang/test/Lower/CUDA/cuda-data-attribute.cuf

Removed: 
    


################################################################################
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