[flang-commits] [flang] 7c2e0db - [flang][cuda] Avoid I/O error in block inside a kernel (#160599)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 24 13:48:39 PDT 2025
Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-09-24T20:48:36Z
New Revision: 7c2e0dbddee5a5c790d432591efcdfbb7508d525
URL: https://github.com/llvm/llvm-project/commit/7c2e0dbddee5a5c790d432591efcdfbb7508d525
DIFF: https://github.com/llvm/llvm-project/commit/7c2e0dbddee5a5c790d432591efcdfbb7508d525.diff
LOG: [flang][cuda] Avoid I/O error in block inside a kernel (#160599)
Make sure we get the program unit to check the device context. The scope
would be the block otherwise.
Added:
Modified:
flang/lib/Semantics/check-cuda.cpp
flang/test/Semantics/cuf23.cuf
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 077bd7f3cd56a..3d2db6a9c8aa9 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -777,7 +777,8 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
void CUDAChecker::Enter(const parser::PrintStmt &x) {
CHECK(context_.location());
const Scope &scope{context_.FindScope(*context_.location())};
- if (IsCUDADeviceContext(&scope) || deviceConstructDepth_ > 0) {
+ const Scope &progUnit{GetProgramUnitContaining(scope)};
+ if (IsCUDADeviceContext(&progUnit) || deviceConstructDepth_ > 0) {
return;
}
diff --git a/flang/test/Semantics/cuf23.cuf b/flang/test/Semantics/cuf23.cuf
index ec90545cd2b4e..8c03c18d9b0db 100644
--- a/flang/test/Semantics/cuf23.cuf
+++ b/flang/test/Semantics/cuf23.cuf
@@ -46,3 +46,10 @@ attributes(device) subroutine device1()
real, device :: a(10)
print*, a ! ok
end subroutine
+
+attributes(global) subroutine global_with_block()
+ block
+ real, device :: a(10)
+ print*, a ! ok
+ end block
+end subroutine
More information about the flang-commits
mailing list