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

via flang-commits flang-commits at lists.llvm.org
Wed Sep 24 11:05:17 PDT 2025


Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-09-24T18:05:13Z
New Revision: 1b944e24d2aed0c8a0dbabedf8c51e7291f151a1

URL: https://github.com/llvm/llvm-project/commit/1b944e24d2aed0c8a0dbabedf8c51e7291f151a1
DIFF: https://github.com/llvm/llvm-project/commit/1b944e24d2aed0c8a0dbabedf8c51e7291f151a1.diff

LOG: [flang][cuda] Allow print of managed and unified variables (#160571)

Added: 
    

Modified: 
    flang/lib/Semantics/check-cuda.cpp
    flang/test/Semantics/cuf23.cuf

Removed: 
    


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


        


More information about the flang-commits mailing list