Skip to content

[flang][cuda] Allow GOTO, EXIT, CYCLE and SELECT CASE in device procedures #121612

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 1 commit into from
Jan 4, 2025
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
23 changes: 23 additions & 0 deletions flang/lib/Semantics/check-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
[&](const common::Indirection<parser::IfConstruct> &x) {
Check(x.value());
},
[&](const common::Indirection<parser::CaseConstruct> &x) {
const auto &caseList{
std::get<std::list<parser::CaseConstruct::Case>>(
x.value().t)};
for (const parser::CaseConstruct::Case &c : caseList) {
Check(std::get<parser::Block>(c.t));
}
},
[&](const auto &x) {
if (auto source{parser::GetSource(x)}) {
context_.Say(*source,
Expand Down Expand Up @@ -347,9 +355,24 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
hostArray->name());
}
}
void ErrorInCUFKernel(parser::CharBlock source) {
if (IsCUFKernelDo) {
context_.Say(
source, "Statement may not appear in cuf kernel code"_err_en_US);
}
}
void Check(const parser::ActionStmt &stmt, const parser::CharBlock &source) {
common::visit(
common::visitors{
[&](const common::Indirection<parser::CycleStmt> &) {
ErrorInCUFKernel(source);
},
[&](const common::Indirection<parser::ExitStmt> &) {
ErrorInCUFKernel(source);
},
[&](const common::Indirection<parser::GotoStmt> &) {
ErrorInCUFKernel(source);
},
[&](const common::Indirection<parser::StopStmt> &) { return; },
[&](const common::Indirection<parser::PrintStmt> &) {},
[&](const common::Indirection<parser::WriteStmt> &x) {
Expand Down
53 changes: 53 additions & 0 deletions flang/test/Semantics/cuf09.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,59 @@ module m
print*,threadIdx%x
stop ! ok
end subroutine

attributes(global) subroutine cycletest()
integer :: i
do i = 1, 10
cycle ! ok
end do
end subroutine

attributes(global) subroutine gototest()
integer :: i
goto 10
10 print *, "X is negative!"
end subroutine

attributes(global) subroutine exittest()
integer :: i
do i = 1, 10
if (i == 1) then
exit ! ok
end if
end do
end subroutine

attributes(global) subroutine selectcasetest()
integer :: i
select case(i)
case (1)
print*,'main'
case default
print*, 'default'
end select
end subroutine

subroutine host()
integer :: i
!$cuf kernel do
do i = 1, 10
!ERROR: Statement may not appear in cuf kernel code
cycle
end do

!$cuf kernel do
do i = 1, 10
if (i == 1) then
!ERROR: Statement may not appear in cuf kernel code
exit ! ok
end if

!ERROR: Statement may not appear in cuf kernel code
goto 10
10 print *, "X is negative!"
end do
end subroutine
end

program main
Expand Down
Loading