[flang-commits] [flang] [flang][cuda] Allow print of managed and unified variables (PR #160571)

via flang-commits flang-commits at lists.llvm.org
Wed Sep 24 10:39:59 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

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

<details>
<summary>Changes</summary>



---
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
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()

``````````

</details>


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


More information about the flang-commits mailing list