Skip to content

Commit fb4d72e

Browse files
authored
[flang][acc] honor reduction clause's implied copy attribute (#156982)
The Open ACC spec states that the reduction clause implies the copy clause. Account for this in the check for `default(none)` variables. Add a test that shouldn't error, but did before this PR.
1 parent 86ac4a0 commit fb4d72e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
304304
return false;
305305
}
306306

307+
bool Pre(const parser::AccClause::Reduction &x) {
308+
const auto &objectList{std::get<parser::AccObjectList>(x.v.t)};
309+
ResolveAccObjectList(objectList, Symbol::Flag::AccReduction);
310+
return false;
311+
}
312+
307313
void Post(const parser::Name &);
308314

309315
private:

flang/test/Semantics/OpenACC/acc-reduction-validity.f90

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,23 @@ program openacc_reduction_validity
177177
end program
178178

179179
subroutine sum()
180-
! ERROR: 'sum' is already declared in this scoping unit
180+
!ERROR: 'sum' is already declared in this scoping unit
181181
integer :: i,sum
182182
sum = 0
183-
!$acc parallel
183+
!$acc parallel
184+
!ERROR: Only variables are allowed in data clauses on the LOOP directive
184185
!$acc loop independent gang reduction(+:sum)
185186
do i=1,10
186187
sum = sum + i
187188
enddo
188189
!$acc end parallel
189190
end subroutine
191+
192+
subroutine reduce()
193+
integer :: red = 0, ii
194+
!$acc parallel loop default(none) reduction(+:red)
195+
do ii = 1, 10
196+
red = red + ii
197+
end do
198+
!$acc end parallel
199+
end subroutine

0 commit comments

Comments
 (0)