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
14 changes: 11 additions & 3 deletions flang/lib/Semantics/check-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,17 @@ void CUDAChecker::Enter(const parser::PrintStmt &x) {
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);
for (const Symbol &sym : CollectCudaSymbols(*expr)) {
if (const auto *details = sym.GetUltimate()
.detailsIf<semantics::ObjectEntityDetails>()) {
if (details->cudaDataAttr() &&
(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
*details->cudaDataAttr() ==
common::CUDADataAttr::Constant)) {
context_.Say(parser::FindSourceLocation(*x),
"device data not allowed in I/O statements"_err_en_US);
}
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions flang/test/Semantics/cuf23.cuf
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc

module devicemod
real, constant :: c(10)
end module

program test
use devicemod
real, device :: a(10)
real, managed :: m(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

print*, m(9) ! ok
print*, m ! ok

!ERROR: device data not allowed in I/O statements
print*, c
!ERROR: device data not allowed in I/O statements
print*, c(5)
end

subroutine host()
Expand Down