[flang-commits] [flang] [flang][cuda] Allow if stmt in device subroutine (PR #89347)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Apr 18 22:56:41 PDT 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/89347
None
>From 10485925155614848e69ba6050e4eeb332249849 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 18 Apr 2024 22:55:47 -0700
Subject: [PATCH] [flang][cuda] Allow if stmt in device subroutine
---
flang/lib/Semantics/check-cuda.cpp | 9 +++++++++
flang/test/Semantics/cuf11.cuf | 4 ++++
2 files changed, 13 insertions(+)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index fb1ebadd378586..397fdc49196487 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -344,6 +344,9 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
[&](const common::Indirection<parser::BackspaceStmt> &x) {
WarnOnIoStmt(source);
},
+ [&](const common::Indirection<parser::IfStmt> &x) {
+ Check(x.value());
+ },
[&](const auto &x) {
if (auto msg{ActionStmtChecker<IsCUFKernelDo>::WhyNotOk(x)}) {
context_.Say(source, std::move(*msg));
@@ -369,6 +372,12 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
Check(std::get<parser::Block>(eb->t));
}
}
+ void Check(const parser::IfStmt &is) {
+ const auto &uS{std::get<parser::UnlabeledStatement<parser::ActionStmt>>(is.t)};
+ CheckUnwrappedExpr(context_, uS.source,
+ std::get<parser::ScalarLogicalExpr>(is.t));
+ Check(uS.statement, uS.source);
+ }
void Check(const parser::LoopControl::Bounds &bounds) {
Check(bounds.lower);
Check(bounds.upper);
diff --git a/flang/test/Semantics/cuf11.cuf b/flang/test/Semantics/cuf11.cuf
index de7ff29743242b..554ac258e55101 100644
--- a/flang/test/Semantics/cuf11.cuf
+++ b/flang/test/Semantics/cuf11.cuf
@@ -30,3 +30,7 @@ logical function compare_h(a,b)
!ERROR: 'b' is not an object of derived type; it is implicitly typed
compare_h = (a%h .eq. b%h)
end
+
+attributes(global) subroutine sub2()
+ if (threadIdx%x == 1) print *, "I'm number one"
+end subroutine
More information about the flang-commits
mailing list