Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flang/lib/Evaluate/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,8 @@ bool IsSaved(const Symbol &original) {
return false;
} else if (scopeKind == Scope::Kind::Module ||
(scopeKind == Scope::Kind::MainProgram &&
(symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)))) {
(symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)) &&
Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol))) {
// 8.5.16p4
// In main programs, implied SAVE matters only for pointer
// initialization targets and coarrays.
Expand Down Expand Up @@ -1755,7 +1756,7 @@ bool IsSaved(const Symbol &original) {
} else if (scope.hasSAVE()) {
return true; // bare SAVE statement
} else if (const Symbol * block{FindCommonBlockContaining(symbol)};
block && block->attrs().test(Attr::SAVE)) {
block && block->attrs().test(Attr::SAVE)) {
return true; // in COMMON with SAVE
} else {
return false;
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Lower/CUDA/cuda-program-global.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ program test
integer, device :: a(10)
integer, unified :: u(10)
integer, allocatable, pinned :: p(:)
real, device, target :: t(10)
integer :: b(10)
integer :: i
print*,i
Expand All @@ -18,6 +19,7 @@ end
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
! CHECK: hlfir.declare %[[ALLOCA]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "p", data_attr = #cuf.cuda<pinned>, uniq_name = "_QFEp"} -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
! CHECK: cuf.alloc !fir.array<10xf32> {bindc_name = "t", data_attr = #cuf.cuda<device>, uniq_name = "_QFEt"} -> !fir.ref<!fir.array<10xf32>>

! CHECK-NOT: fir.global internal @_QFEa {data_attr = #cuf.cuda<device>} : !fir.array<10xi32> {{{$}}
! CHECK: fir.global internal @_QFEb : !fir.array<10xi32> {{{$}}
Expand Down
Loading