Skip to content

[flang][cuda] Allow if stmt in device subroutine #89347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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