[flang-commits] [flang] [flang][cuda] Apply implict data attribute to local arrays (PR #120293)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Tue Dec 17 11:55:47 PST 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/120293
Add the implicit data attribute to local arrays that don't have one. This is simplify the host array detection in semantic.
>From 391d63aa11c37b410e3c319ac32ef14010a535f6 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 17 Dec 2024 11:54:13 -0800
Subject: [PATCH] [flang][cuda] Apply implict data attribute to local arrays
---
flang/lib/Semantics/resolve-names.cpp | 10 +++++-----
flang/test/Semantics/cuf09.cuf | 6 ++++++
2 files changed, 11 insertions(+), 5 deletions(-)
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