[flang-commits] [flang] [flang][cuda] Do not emit warning for SHARED variable in device subprogram (PR #115195)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Wed Nov 6 11:08:26 PST 2024


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

SHARED attribute is explicitly meant to be used in device subprogram (https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#cfpg-var-qual-attr-shared).

Do not emit warning. 

>From 73beec540f7d9dd6084d0f21b0375713eb87b0fd Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 6 Nov 2024 11:06:43 -0800
Subject: [PATCH] [flang][cuda] Do not emit warning for SHARED variable in
 device subprogram

---
 flang/lib/Semantics/check-declarations.cpp | 4 +++-
 flang/test/Semantics/cuf03.cuf             | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index f8e873008ceabc..86881225e1e55c 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -928,7 +928,9 @@ void CheckHelper::CheckObjectEntity(
         details.cudaDataAttr().value_or(common::CUDADataAttr::Device) !=
             common::CUDADataAttr::Device &&
         details.cudaDataAttr().value_or(common::CUDADataAttr::Device) !=
-            common::CUDADataAttr::Managed) {
+            common::CUDADataAttr::Managed &&
+        details.cudaDataAttr().value_or(common::CUDADataAttr::Device) !=
+            common::CUDADataAttr::Shared) {
       Warn(common::UsageWarning::CUDAUsage,
           "Dummy argument '%s' may not have ATTRIBUTES(%s) in a device subprogram"_warn_en_US,
           symbol.name(),
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index a98dd60cdb8a4e..93b136ad7d3157 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -55,13 +55,14 @@ module m
   real, unified :: um
 
  contains
-  attributes(device) subroutine devsubr(n,da)
+  attributes(device) subroutine devsubr(n,da,rs)
     integer, intent(in) :: n
     real, device :: da(*) ! ok
     real, managed :: ma(n) ! ok
     !WARNING: Pointer 'dp' may not be associated in a device subprogram
     real, device, pointer :: dp
     real, constant :: rc ! ok
+    real, shared :: rs ! ok
     !ERROR: Object 'u' with ATTRIBUTES(UNIFIED) must be declared in a host subprogram
     real, unified :: u
   end subroutine



More information about the flang-commits mailing list