Skip to content
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
20 changes: 20 additions & 0 deletions flang/lib/Semantics/check-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,4 +774,24 @@ 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) {
return;
}

auto &outputItemList{std::get<std::list<Fortran::parser::OutputItem>>(x.t)};
for (const auto &item : outputItemList) {
if (const auto *x{std::get_if<parser::Expr>(&item.u)}) {
if (const auto *expr{GetExpr(context_, *x)}) {
if (Fortran::evaluate::HasCUDADeviceAttrs(*expr)) {
context_.Say(parser::FindSourceLocation(*x),
"device data not allowed in I/O statements"_err_en_US);
}
}
}
}
}

} // namespace Fortran::semantics
1 change: 1 addition & 0 deletions flang/lib/Semantics/check-cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CUDAChecker : public virtual BaseChecker {
void Leave(const parser::OpenACCLoopConstruct &);
void Enter(const parser::DoConstruct &);
void Leave(const parser::DoConstruct &);
void Enter(const parser::PrintStmt &);

private:
SemanticsContext &context_;
Expand Down
34 changes: 34 additions & 0 deletions flang/test/Semantics/cuf23.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc

program test
real, device :: a(10)
a = 1.0
!ERROR: device data not allowed in I/O statements
print *, a(1)
!ERROR: device data not allowed in I/O statements
print *, a
end

subroutine host()
integer :: i
real, device :: a(10)
!$acc parallel loop
do i = 1, 10
print*, a(i) ! ok
end do

!$cuf kernel do
do i = 1, 10
print*, a(i) ! ok
end do
end subroutine

attributes(global) subroutine global1()
real, device :: a(10)
print*, a ! ok
end subroutine

attributes(device) subroutine device1()
real, device :: a(10)
print*, a ! ok
end subroutine