Skip to content

[flang][cuda] Fix crash in semantic #88577

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 12, 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
8 changes: 7 additions & 1 deletion flang/lib/Semantics/check-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,16 @@ void CUDAChecker::Enter(const parser::CUFKernelDoConstruct &x) {
}

void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
auto lhsLoc{std::get<parser::Variable>(x.t).GetSource()};
const auto &scope{context_.FindScope(lhsLoc)};
const Scope &progUnit{GetProgramUnitContaining(scope)};
if (IsCUDADeviceContext(&progUnit)) {
return; // Data transfer with assignment is only perform on host.
}

const evaluate::Assignment *assign{semantics::GetAssignment(x)};
int nbLhs{evaluate::GetNbOfCUDASymbols(assign->lhs)};
int nbRhs{evaluate::GetNbOfCUDASymbols(assign->rhs)};
auto lhsLoc{std::get<parser::Variable>(x.t).GetSource()};

// device to host transfer with more than one device object on the rhs is not
// legal.
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Semantics/cuf11.cuf
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
! RUN: %python %S/test_errors.py %s %flang_fc1

module mod1
contains
attributes(global) subroutine sub1(adev)
real :: adev(10)
integer :: tid
tid = threadIdx%x
! Use to crash the compiler. Make sure we have the proper semantic error.
!ERROR: Actual argument for 'i=' has bad type 'REAL(4)'
adev(tid + 1) = scale(real(tid), 2.0)
end subroutine sub1
end module

subroutine sub1()
real, device :: adev(10), bdev(10)
real :: ahost(10)
Expand Down