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] Fix to construct-names inside OpenMP construct with default(none) #82479

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

harishch4
Copy link
Contributor

@harishch4 harishch4 commented Feb 21, 2024

When a do loop with a construct-name is used inside OpenMP construct with default(none), an incorrect error will be raised as below.

program cn_and_default
    implicit none
    integer :: i

    !$omp parallel default(none)
        loop: do i = 1, 10
        end do loop
    !$omp end parallel
end program

The DEFAULT(NONE) clause requires that 'loop' must be listed in a data-sharing attribute clause

This patch fixes this by adding a condition to check and skip processing construct-names.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 21, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: None (harishch4)

Changes

When a do loop with a construct-name is used inside OpenMP construct with default(none), an assertion will be raised as below.

program cn_and_default
    implicit none
    integer :: i

    !$omp parallel default(none)
        loop: do i = 1, 10
        end do loop
    !$omp end parallel
end program

> The DEFAULT(NONE) clause requires that 'loop' must be listed in a data-sharing attribute clause

This patch fixes this by adding a condition to check and skip processing construct-names.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+6)
  • (modified) flang/test/Semantics/OpenMP/default-none.f90 (+8)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 4b6d083671bc92..a826f0181e580c 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1982,6 +1982,12 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
 void OmpAttributeVisitor::Post(const parser::Name &name) {
   auto *symbol{name.symbol};
   if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
+    // Exclude construct-names
+    if (auto *details{symbol->detailsIf<semantics::MiscDetails>()}) {
+      if (details->kind() == semantics::MiscDetails::Kind::ConstructName) {
+        return;
+      }
+    }
     if (!symbol->owner().IsDerivedType() && !IsProcedure(*symbol) &&
         !IsObjectWithDSA(*symbol) && !IsNamedConstant(*symbol)) {
       // TODO: create a separate function to go through the rules for
diff --git a/flang/test/Semantics/OpenMP/default-none.f90 b/flang/test/Semantics/OpenMP/default-none.f90
index d027f46f005846..11ba878ea77940 100644
--- a/flang/test/Semantics/OpenMP/default-none.f90
+++ b/flang/test/Semantics/OpenMP/default-none.f90
@@ -39,3 +39,11 @@ subroutine sb3(x)
    print *, x
  end subroutine
 end subroutine
+
+!construct-name inside default(none)
+subroutine sb4
+  !$omp parallel default(none)
+    loop: do i = 1, 10
+    end do loop
+  !$omp end parallel
+end subroutine

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@NimishMishra NimishMishra left a comment

Choose a reason for hiding this comment

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

LGTM

@kiranchandramohan
Copy link
Contributor

an assertion will be raised as below.
This is an incorrect error and not an assertion right?

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LG.

@harishch4
Copy link
Contributor Author

This is an incorrect error and not an assertion right?

Yes, it is an incorrect error. Updated the comment. Thanks.

@harishch4 harishch4 merged commit 40fae67 into llvm:main Feb 21, 2024
8 checks passed
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

5 participants