[flang-commits] [flang] bbeafe4 - [flang][cuda] Apply implict data attribute to local arrays (#120293)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 17 12:56:43 PST 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-12-17T12:56:39-08:00
New Revision: bbeafe4b94bb3db89b579d8a6fd914cc96b0af06

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

LOG: [flang][cuda] Apply implict data attribute to local arrays (#120293)

Add the implicit data attribute to local arrays that don't have one.
This simplifies the host array detection in semantic.

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/cuf09.cuf

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3a1ccec1fdf4bd..51e8b15e6adf02 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8973,12 +8973,12 @@ void ResolveNamesVisitor::FinishSpecificationPart(
     if (NeedsExplicitType(symbol)) {
       ApplyImplicitRules(symbol);
     }
-    if (inDeviceSubprogram && IsDummy(symbol) &&
-        symbol.has<ObjectEntityDetails>()) {
-      auto *dummy{symbol.detailsIf<ObjectEntityDetails>()};
-      if (!dummy->cudaDataAttr() && !IsValue(symbol)) {
+    if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
+      auto *object{symbol.detailsIf<ObjectEntityDetails>()};
+      if (!object->cudaDataAttr() && !IsValue(symbol) &&
+          (IsDummy(symbol) || object->IsArray())) {
         // Implicitly set device attribute if none is set in device context.
-        dummy->set_cudaDataAttr(common::CUDADataAttr::Device);
+        object->set_cudaDataAttr(common::CUDADataAttr::Device);
       }
     }
     if (IsDummy(symbol) && isImplicitNoneType() &&

diff  --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index c551ecbff2cc06..e0ca814aec26a0 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -22,6 +22,12 @@ module m
     !ERROR: Host array 'm' cannot be present in device context
     if (i .le. N) a(i) = m(i)
   end subroutine
+
+  attributes(global) subroutine localarray()
+    integer :: a(10)
+    i = threadIdx%x
+    a(i) = i
+  end subroutine
 end
 
 program main


        


More information about the flang-commits mailing list