Skip to content

Commit 7e1437b

Browse files
authored
[flang][cuda] Detect illegal data transfer in semantic (llvm#125591)
When the LHS is a device variable and the RHS has implicit transfer, this is considered as an illegal transfer according to https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#implicit-data-transfer-in-expressions. Detect this is semantic .
1 parent 79e804b commit 7e1437b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

flang/lib/Semantics/assignment.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ void AssignmentContext::Analyze(const parser::AssignmentStmt &stmt) {
9090
if (whereDepth_ > 0) {
9191
CheckShape(lhsLoc, &lhs);
9292
}
93+
if (context_.foldingContext().languageFeatures().IsEnabled(
94+
common::LanguageFeature::CUDA)) {
95+
const auto &scope{context_.FindScope(lhsLoc)};
96+
const Scope &progUnit{GetProgramUnitContaining(scope)};
97+
if (!IsCUDADeviceContext(&progUnit)) {
98+
if (Fortran::evaluate::HasCUDADeviceAttrs(lhs) &&
99+
Fortran::evaluate::HasCUDAImplicitTransfer(rhs)) {
100+
context_.Say(lhsLoc, "Unsupported CUDA data transfer"_err_en_US);
101+
}
102+
}
103+
}
93104
}
94105
}
95106

flang/test/Semantics/cuf18.cuf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
3+
subroutine sub1()
4+
real, allocatable, device :: a(:)
5+
6+
!ERROR: Unsupported CUDA data transfer
7+
a = a + 10 ! Illegal expression according to 3.4.2
8+
end subroutine
9+
10+
11+

0 commit comments

Comments
 (0)