Skip to content

Conversation

@clementval
Copy link
Contributor

@clementval clementval commented Dec 17, 2024

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

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Dec 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/120293.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+5-5)
  • (modified) flang/test/Semantics/cuf09.cuf (+6)
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

@clementval clementval merged commit bbeafe4 into llvm:main Dec 17, 2024
9 of 10 checks passed
@clementval clementval deleted the cuf_implicit_local_arrays branch December 17, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants