[flang-commits] [flang] fb4d72e - [flang][acc] honor reduction clause's implied copy attribute (#156982)
via flang-commits
flang-commits at lists.llvm.org
Sat Sep 6 08:30:12 PDT 2025
Author: Andre Kuhlenschmidt
Date: 2025-09-06T08:30:08-07:00
New Revision: fb4d72e2bc6b7068e887573869274d9eddada54a
URL: https://github.com/llvm/llvm-project/commit/fb4d72e2bc6b7068e887573869274d9eddada54a
DIFF: https://github.com/llvm/llvm-project/commit/fb4d72e2bc6b7068e887573869274d9eddada54a.diff
LOG: [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.
Added:
Modified:
flang/lib/Semantics/resolve-directives.cpp
flang/test/Semantics/OpenACC/acc-reduction-validity.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index a08e764ecf936..ac3794a95b065 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -304,6 +304,12 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
return false;
}
+ bool Pre(const parser::AccClause::Reduction &x) {
+ const auto &objectList{std::get<parser::AccObjectList>(x.v.t)};
+ ResolveAccObjectList(objectList, Symbol::Flag::AccReduction);
+ return false;
+ }
+
void Post(const parser::Name &);
private:
diff --git a/flang/test/Semantics/OpenACC/acc-reduction-validity.f90 b/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
index 0cdf33a2adb94..fd83e411191db 100644
--- a/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
@@ -177,13 +177,23 @@ program openacc_reduction_validity
end program
subroutine sum()
- ! ERROR: 'sum' is already declared in this scoping unit
+ !ERROR: 'sum' is already declared in this scoping unit
integer :: i,sum
sum = 0
- !$acc parallel
+ !$acc parallel
+ !ERROR: Only variables are allowed in data clauses on the LOOP directive
!$acc loop independent gang reduction(+:sum)
do i=1,10
sum = sum + i
enddo
!$acc end parallel
end subroutine
+
+subroutine reduce()
+ integer :: red = 0, ii
+ !$acc parallel loop default(none) reduction(+:red)
+ do ii = 1, 10
+ red = red + ii
+ end do
+ !$acc end parallel
+end subroutine
More information about the flang-commits
mailing list