Skip to content

Conversation

@clementval
Copy link
Contributor

Host arrays are normally not allowed in device context unless they have a PARAMETER attribute. This patch update the check so no error is emitted.

@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

Host arrays are normally not allowed in device context unless they have a PARAMETER attribute. This patch update the check so no error is emitted.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+1)
  • (modified) flang/test/Semantics/cuf09.cuf (+7)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 9c044a47c79834..d8c9db22417398 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -110,6 +110,7 @@ struct FindHostArray
     if (const auto *details{
             symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
       if (details->IsArray() &&
+          !symbol.attrs().test(Fortran::semantics::Attr::PARAMETER) &&
           (!details->cudaDataAttr() ||
               (details->cudaDataAttr() &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Device &&
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index c551ecbff2cc06..f120c931926cbc 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -1,6 +1,7 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
 module m
  integer :: m(100)
+ integer, parameter :: p(5) = [1,2,3,4,5]
  contains
   attributes(device) subroutine devsub
     !ERROR: Statement may not appear in device code
@@ -22,6 +23,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 hostparameter(a)
+    integer :: a(*)
+    i = threadIdx%x
+    if (i .le. N) a(i) = p(i) ! ok. p is parameter
+  end subroutine
 end
 
 program main

@clementval clementval requested a review from klausler December 17, 2024 21:22
@clementval clementval merged commit 97b7bac into llvm:main Dec 17, 2024
5 of 6 checks passed
@clementval clementval deleted the cuf_host_array_parameter branch December 17, 2024 21:41
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