Skip to content

Commit 7b6b023

Browse files
authored
[flang][cuda] Fix crash in semantic (#88577)
Fix for #88451 Do not perform semantic check about data transfer on assignment statement in device context.
1 parent daa8836 commit 7b6b023

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,16 @@ void CUDAChecker::Enter(const parser::CUFKernelDoConstruct &x) {
480480
}
481481

482482
void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
483+
auto lhsLoc{std::get<parser::Variable>(x.t).GetSource()};
484+
const auto &scope{context_.FindScope(lhsLoc)};
485+
const Scope &progUnit{GetProgramUnitContaining(scope)};
486+
if (IsCUDADeviceContext(&progUnit)) {
487+
return; // Data transfer with assignment is only perform on host.
488+
}
489+
483490
const evaluate::Assignment *assign{semantics::GetAssignment(x)};
484491
int nbLhs{evaluate::GetNbOfCUDASymbols(assign->lhs)};
485492
int nbRhs{evaluate::GetNbOfCUDASymbols(assign->rhs)};
486-
auto lhsLoc{std::get<parser::Variable>(x.t).GetSource()};
487493

488494
// device to host transfer with more than one device object on the rhs is not
489495
// legal.

flang/test/Semantics/cuf11.cuf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
22

3+
module mod1
4+
contains
5+
attributes(global) subroutine sub1(adev)
6+
real :: adev(10)
7+
integer :: tid
8+
tid = threadIdx%x
9+
! Use to crash the compiler. Make sure we have the proper semantic error.
10+
!ERROR: Actual argument for 'i=' has bad type 'REAL(4)'
11+
adev(tid + 1) = scale(real(tid), 2.0)
12+
end subroutine sub1
13+
end module
14+
315
subroutine sub1()
416
real, device :: adev(10), bdev(10)
517
real :: ahost(10)

0 commit comments

Comments
 (0)