[flang-commits] [flang] implicitly set device attribute for variables have VALUE attribute in device routine (PR #140952)

via flang-commits flang-commits at lists.llvm.org
Wed May 21 12:00:06 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Zhen Wang (wangzpgi)

<details>
<summary>Changes</summary>

For variables that have VALUE attribute inside device routines, implicitly set DEVICE attribute.

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


3 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+1-2) 
- (modified) flang/test/Semantics/cuf21.cuf (+9-5) 
- (modified) flang/test/Semantics/modfile55.cuf (+1) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3f4a06444c4f3..f7c6a948375e4 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -9375,8 +9375,7 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) {
 static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
   if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
     auto *object{symbol.detailsIf<ObjectEntityDetails>()};
-    if (!object->cudaDataAttr() && !IsValue(symbol) &&
-        !IsFunctionResult(symbol)) {
+    if (!object->cudaDataAttr() && !IsFunctionResult(symbol)) {
       // Implicitly set device attribute if none is set in device context.
       object->set_cudaDataAttr(common::CUDADataAttr::Device);
     }
diff --git a/flang/test/Semantics/cuf21.cuf b/flang/test/Semantics/cuf21.cuf
index b8b99a8d1d9be..4251493c52e65 100644
--- a/flang/test/Semantics/cuf21.cuf
+++ b/flang/test/Semantics/cuf21.cuf
@@ -1,5 +1,6 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
-! Test generic matching with scalars argument without device attr
+! Test generic matching with scalars argument and argument
+! with VALUE attribute without DEVICE attr inside device routine
 
 module mlocModule
   interface maxlocUpdate
@@ -9,19 +10,22 @@ module mlocModule
   end interface maxlocUpdate
 contains
 
-  attributes(global) subroutine maxlocPartialMaskR_32F1D()
+  attributes(global) subroutine maxlocPartialMaskR_32F1D(back)
     implicit none
+    logical, intent(in), value :: back
     real(4) :: mval
 
-    call maxlocUpdate(mval)
+    call maxlocUpdate(mval, back)
 
   end subroutine maxlocPartialMaskR_32F1D
 
-  attributes(device) subroutine maxlocUpdateR_32F(mval)
+  attributes(device) subroutine maxlocUpdateR_32F(mval, back)
     real(4) :: mval
+    logical :: back
   end subroutine maxlocUpdateR_32F
 
-  attributes(device) subroutine maxlocUpdateR_64F(mval)
+  attributes(device) subroutine maxlocUpdateR_64F(mval, back)
     real(8) :: mval
+    logical :: back
   end subroutine maxlocUpdateR_64F
 end module
diff --git a/flang/test/Semantics/modfile55.cuf b/flang/test/Semantics/modfile55.cuf
index 2338b745d8355..abe6c30fa0f67 100644
--- a/flang/test/Semantics/modfile55.cuf
+++ b/flang/test/Semantics/modfile55.cuf
@@ -33,6 +33,7 @@ end
 !contains
 !attributes(global) subroutine globsub(x,y,z)
 !real(4),value::x
+!attributes(device)x
 !real(4)::y
 !attributes(device) y
 !real(4)::z

``````````

</details>


https://github.com/llvm/llvm-project/pull/140952


More information about the flang-commits mailing list