Skip to content

Commit

Permalink
[flang][cuda] Allow if stmt in device subroutine (#89347)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementval committed Apr 19, 2024
1 parent 7d8616e commit a309c07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flang/lib/Semantics/check-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -369,6 +372,13 @@ 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);
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/cuf11.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a309c07

Please sign in to comment.