Skip to content

Conversation

akuhlens
Copy link
Contributor

@akuhlens akuhlens commented Sep 4, 2025

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.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp openacc flang:semantics labels Sep 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-openacc

Author: Andre Kuhlenschmidt (akuhlens)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/156982.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+6)
  • (modified) flang/test/Semantics/OpenACC/acc-reduction-validity.f90 (+12-2)
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

@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-flang-semantics

Author: Andre Kuhlenschmidt (akuhlens)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/156982.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+6)
  • (modified) flang/test/Semantics/OpenACC/acc-reduction-validity.f90 (+12-2)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants