Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang][OpenMP] Avoid default none errors for seq loop indices in par… #76258

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

kiranchandramohan
Copy link
Contributor

…allel

@tblah
Copy link
Contributor

tblah commented Jan 11, 2024

@kiranchandramohan what more is needed to make this PR ready?

@kiranchandramohan kiranchandramohan marked this pull request as ready for review January 12, 2024 12:35
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Jan 12, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 12, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

Changes

…allel


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+5-1)
  • (modified) flang/test/Semantics/OpenMP/resolve05.f90 (+13)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index d7b13631ab4df0..b30b81cf90c951 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1946,7 +1946,11 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
       if (Symbol * found{currScope().FindSymbol(name.source)}) {
         if (symbol != found) {
           name.symbol = found; // adjust the symbol within region
-        } else if (GetContext().defaultDSA == Symbol::Flag::OmpNone) {
+        } else if (GetContext().defaultDSA == Symbol::Flag::OmpNone &&
+            // Exclude indices of sequential loops that are privatised in
+            // the scope of the parallel region, and not in this scope.
+            // TODO: check whether this should be caught in IsObjectWithDSA
+            !symbol->test(Symbol::Flag::OmpPrivate)) {
           context_.Say(name.source,
               "The DEFAULT(NONE) clause requires that '%s' must be listed in "
               "a data-sharing attribute clause"_err_en_US,
diff --git a/flang/test/Semantics/OpenMP/resolve05.f90 b/flang/test/Semantics/OpenMP/resolve05.f90
index 00f4860302183d..c4cebb48ac5c2b 100644
--- a/flang/test/Semantics/OpenMP/resolve05.f90
+++ b/flang/test/Semantics/OpenMP/resolve05.f90
@@ -17,7 +17,20 @@ subroutine default_none()
   !$omp end parallel
 end subroutine default_none
 
+! Test that indices of sequential loops are privatised and hence do not error
+! for DEFAULT(NONE)
+subroutine default_none_seq_loop
+  integer :: i
+
+  !$omp parallel do default(none)
+  do i = 1, 10
+     do j = 1, 20
+    enddo
+  enddo
+end subroutine
+
 program mm
   call default_none()
+  call default_none_seq_loop()
   !TODO: private, firstprivate, shared
 end

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this does fix the bug. Thanks!

@kiranchandramohan kiranchandramohan merged commit 3ae8746 into llvm:main Jan 15, 2024
9 checks passed
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants