[flang-commits] [flang] implicitly set device attribute for variables have VALUE attribute in device routine (PR #140952)
Zhen Wang via flang-commits
flang-commits at lists.llvm.org
Wed May 21 11:59:33 PDT 2025
https://github.com/wangzpgi created https://github.com/llvm/llvm-project/pull/140952
For variables that have VALUE attribute inside device routines, implicitly set DEVICE attribute.
>From 55913c856b56967382e1013e8d8b62f9f4c4e6ad Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Wed, 21 May 2025 11:57:54 -0700
Subject: [PATCH] implicitly set device attribute for variables have VALUE
attribute inside device routine
---
flang/lib/Semantics/resolve-names.cpp | 3 +--
flang/test/Semantics/cuf21.cuf | 14 +++++++++-----
flang/test/Semantics/modfile55.cuf | 1 +
3 files changed, 11 insertions(+), 7 deletions(-)
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
More information about the flang-commits
mailing list