Skip to content

Commit 1b944e2

Browse files
authored
[flang][cuda] Allow print of managed and unified variables (#160571)
1 parent 106fea9 commit 1b944e2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,17 @@ void CUDAChecker::Enter(const parser::PrintStmt &x) {
785785
for (const auto &item : outputItemList) {
786786
if (const auto *x{std::get_if<parser::Expr>(&item.u)}) {
787787
if (const auto *expr{GetExpr(context_, *x)}) {
788-
if (Fortran::evaluate::HasCUDADeviceAttrs(*expr)) {
789-
context_.Say(parser::FindSourceLocation(*x),
790-
"device data not allowed in I/O statements"_err_en_US);
788+
for (const Symbol &sym : CollectCudaSymbols(*expr)) {
789+
if (const auto *details = sym.GetUltimate()
790+
.detailsIf<semantics::ObjectEntityDetails>()) {
791+
if (details->cudaDataAttr() &&
792+
(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
793+
*details->cudaDataAttr() ==
794+
common::CUDADataAttr::Constant)) {
795+
context_.Say(parser::FindSourceLocation(*x),
796+
"device data not allowed in I/O statements"_err_en_US);
797+
}
798+
}
791799
}
792800
}
793801
}

flang/test/Semantics/cuf23.cuf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc
22

3+
module devicemod
4+
real, constant :: c(10)
5+
end module
6+
37
program test
8+
use devicemod
49
real, device :: a(10)
10+
real, managed :: m(10)
511
a = 1.0
612
!ERROR: device data not allowed in I/O statements
713
print *, a(1)
814
!ERROR: device data not allowed in I/O statements
915
print *, a
16+
17+
print*, m(9) ! ok
18+
print*, m ! ok
19+
20+
!ERROR: device data not allowed in I/O statements
21+
print*, c
22+
!ERROR: device data not allowed in I/O statements
23+
print*, c(5)
1024
end
1125

1226
subroutine host()

0 commit comments

Comments
 (0)