[flang-commits] [flang] [flang][cuda] Do not check dummy in stmt function in device code (PR #212037)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Sat Jul 25 09:53:44 PDT 2026
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/212037
None
>From 070ca5ffb98d1997dfcbaa4fe35ef267ec19ab40 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Sat, 25 Jul 2026 09:53:11 -0700
Subject: [PATCH] [flang][cuda] Do not check dummy in stmt function in device
code
---
flang/include/flang/Evaluate/characteristics.h | 3 +++
flang/lib/Evaluate/characteristics.cpp | 1 +
flang/lib/Semantics/check-call.cpp | 5 +++--
flang/test/Semantics/CUDA/cuf02.cuf | 11 +++++++++++
4 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index bc37f3d39c2ec..1ba0bf693c763 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -420,6 +420,9 @@ struct Procedure {
std::optional<common::CUDASubprogramAttrs> cudaSubprogramAttrs;
// Used only by CUDA semantic checks; this is not a CUDA procedure attribute.
bool hasOpenACCRoutine{false};
+ // Statement functions are inlined; CUDA data-attribute matching does not
+ // apply to their dummy arguments.
+ bool isStmtFunction{false};
};
} // namespace Fortran::evaluate::characteristics
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 8750cd3c3ebb6..4b05a25fd8f58 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -669,6 +669,7 @@ static std::optional<Procedure> CharacterizeProcedure(
}
result.cudaSubprogramAttrs = subp.cudaSubprogramAttrs();
result.hasOpenACCRoutine = !subp.openACCRoutineInfos().empty();
+ result.isStmtFunction = subp.stmtFunction().has_value();
return std::move(result);
},
[&](const semantics::ProcEntityDetails &proc)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 0680a48bac2be..6309b3617f84b 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1125,8 +1125,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
// CUDA specific checks
// TODO: These are disabled in OpenACC constructs, which may not be
- // correct when the target is not a GPU.
- if (!intrinsic &&
+ // correct when the target is not a GPU. Statement functions are inlined
+ // during lowering, so CUDA data attributes do not apply to their dummies.
+ if (!intrinsic && !procedure.isStmtFunction &&
!dummy.attrs.test(characteristics::DummyDataObject::Attr::Value) &&
!FindOpenACCConstructContaining(scope)) {
std::optional<common::CUDADataAttr> actualDataAttr, dummyDataAttr;
diff --git a/flang/test/Semantics/CUDA/cuf02.cuf b/flang/test/Semantics/CUDA/cuf02.cuf
index ac230069cf16f..9a01a693f16e7 100644
--- a/flang/test/Semantics/CUDA/cuf02.cuf
+++ b/flang/test/Semantics/CUDA/cuf02.cuf
@@ -27,6 +27,17 @@ module m
stmtfunc(x) = x + 1. ! ok
x = stmtfunc(x) ! ok
end
+ attributes(device) real function s6_declared(x)
+ implicit none
+ integer i, n
+ real conv, x, y
+ ! Explicitly declared locals get ATTRIBUTES(DEVICE); statement functions
+ ! are inlined, so CUDA data-attribute matching must not apply to dummies.
+ conv(i) = real(i)
+ n = 0
+ y = x - conv(n) ! ok
+ s6_declared = y
+ end
attributes(device) subroutine s6_bad
badstmt(x) = hostfunc(x)
!ERROR: 'hostfunc' may not be called in device code
More information about the flang-commits
mailing list