Skip to content

Conversation

@clementval
Copy link
Contributor

No description provided.

@clementval clementval requested a review from wangzpgi September 24, 2025 17:39
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 24, 2025

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/160571.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+11-3)
  • (modified) flang/test/Semantics/cuf23.cuf (+14)
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<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); + } + } } } } 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() 
@clementval clementval enabled auto-merge (squash) September 24, 2025 17:41
@clementval clementval merged commit 1b944e2 into llvm:main Sep 24, 2025
12 checks passed
@clementval clementval deleted the cuf_print_error branch September 24, 2025 18:21
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

3 participants