[flang-commits] [flang] [flang][cuda] Allow if stmt in device subroutine (PR #89347)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri Apr 19 07:05:02 PDT 2024
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/89347
>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 1/2] [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
>From 6c7998fefb021def86b0c076e8f8e624d1c039f5 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 19 Apr 2024 07:04:49 -0700
Subject: [PATCH 2/2] clang-format
---
flang/lib/Semantics/check-cuda.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 397fdc49196487..a9e57de7e2f2b5 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -373,9 +373,10 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
}
}
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));
+ 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) {
More information about the flang-commits
mailing list