Skip to content

Commit 388d2a4

Browse files
clementvalmahesh-attarde
authored andcommitted
[flang][cuda] Avoid I/O error in block inside a kernel (llvm#160599)
Make sure we get the program unit to check the device context. The scope would be the block otherwise.
1 parent 7ef5552 commit 388d2a4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
777777
void CUDAChecker::Enter(const parser::PrintStmt &x) {
778778
CHECK(context_.location());
779779
const Scope &scope{context_.FindScope(*context_.location())};
780-
if (IsCUDADeviceContext(&scope) || deviceConstructDepth_ > 0) {
780+
const Scope &progUnit{GetProgramUnitContaining(scope)};
781+
if (IsCUDADeviceContext(&progUnit) || deviceConstructDepth_ > 0) {
781782
return;
782783
}
783784

flang/test/Semantics/cuf23.cuf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ attributes(device) subroutine device1()
4646
real, device :: a(10)
4747
print*, a ! ok
4848
end subroutine
49+
50+
attributes(global) subroutine global_with_block()
51+
block
52+
real, device :: a(10)
53+
print*, a ! ok
54+
end block
55+
end subroutine

0 commit comments

Comments
 (0)