From f2c5e56b4e37e56ac98984d79a9881136277cff1 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Wed, 24 Sep 2025 10:38:27 -0700 Subject: [PATCH] [flang][cuda] Allow print of managed and unified variables --- flang/lib/Semantics/check-cuda.cpp | 14 +++++++++++--- flang/test/Semantics/cuf23.cuf | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp index 8d95a3ab580ef..077bd7f3cd56a 100644 --- a/flang/lib/Semantics/check-cuda.cpp +++ b/flang/lib/Semantics/check-cuda.cpp @@ -785,9 +785,17 @@ void CUDAChecker::Enter(const parser::PrintStmt &x) { for (const auto &item : outputItemList) { if (const auto *x{std::get_if(&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()) { + 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); + } + } } } } diff --git a/flang/test/Semantics/cuf23.cuf b/flang/test/Semantics/cuf23.cuf index 386ad50a70acb..ec90545cd2b4e 100644 --- a/flang/test/Semantics/cuf23.cuf +++ b/flang/test/Semantics/cuf23.cuf @@ -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()