File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -774,4 +774,24 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
774774 }
775775}
776776
777+ void CUDAChecker::Enter (const parser::PrintStmt &x) {
778+ CHECK (context_.location ());
779+ const Scope &scope{context_.FindScope (*context_.location ())};
780+ if (IsCUDADeviceContext (&scope) || deviceConstructDepth_ > 0 ) {
781+ return ;
782+ }
783+
784+ auto &outputItemList{std::get<std::list<Fortran::parser::OutputItem>>(x.t )};
785+ for (const auto &item : outputItemList) {
786+ if (const auto *x{std::get_if<parser::Expr>(&item.u )}) {
787+ 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);
791+ }
792+ }
793+ }
794+ }
795+ }
796+
777797} // namespace Fortran::semantics
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class CUDAChecker : public virtual BaseChecker {
4949 void Leave (const parser::OpenACCLoopConstruct &);
5050 void Enter (const parser::DoConstruct &);
5151 void Leave (const parser::DoConstruct &);
52+ void Enter (const parser::PrintStmt &);
5253
5354private:
5455 SemanticsContext &context_;
Original file line number Diff line number Diff line change 1+ ! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc
2+
3+ program test
4+ real, device :: a(10)
5+ a = 1.0
6+ !ERROR: device data not allowed in I/O statements
7+ print *, a(1)
8+ !ERROR: device data not allowed in I/O statements
9+ print *, a
10+ end
11+
12+ subroutine host()
13+ integer :: i
14+ real, device :: a(10)
15+ !$acc parallel loop
16+ do i = 1, 10
17+ print*, a(i) ! ok
18+ end do
19+
20+ !$cuf kernel do
21+ do i = 1, 10
22+ print*, a(i) ! ok
23+ end do
24+ end subroutine
25+
26+ attributes(global) subroutine global1()
27+ real, device :: a(10)
28+ print*, a ! ok
29+ end subroutine
30+
31+ attributes(device) subroutine device1()
32+ real, device :: a(10)
33+ print*, a ! ok
34+ end subroutine
You can’t perform that action at this time.
0 commit comments