[flang-commits] [flang] [Flang][OpenMP] Fix to construct-names inside OpenMP construct with default(none) (PR #82479)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 21 02:53:45 PST 2024


https://github.com/harishch4 created https://github.com/llvm/llvm-project/pull/82479

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.

>From 9b9a0ad54d2ed2b7f63f2fae5fccff53636770c4 Mon Sep 17 00:00:00 2001
From: Harish Chambeti <harishcse44 at gmail.com>
Date: Wed, 21 Feb 2024 16:05:05 +0530
Subject: [PATCH 1/2] Fix to construct-names inside OpenMP construct with
 default(none)

---
 flang/lib/Semantics/resolve-directives.cpp   | 6 ++++++
 flang/test/Semantics/OpenMP/default-none.f90 | 8 ++++++++
 2 files changed, 14 insertions(+)

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..1f6caaab820cc6 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
\ No newline at end of file

>From 2389e57a8f3408395f3f15869f9f0c27a0911ee4 Mon Sep 17 00:00:00 2001
From: harishch4 <harishcse44 at gmail.com>
Date: Wed, 21 Feb 2024 16:21:59 +0530
Subject: [PATCH 2/2] Update default-none.f90

---
 flang/test/Semantics/OpenMP/default-none.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Semantics/OpenMP/default-none.f90 b/flang/test/Semantics/OpenMP/default-none.f90
index 1f6caaab820cc6..11ba878ea77940 100644
--- a/flang/test/Semantics/OpenMP/default-none.f90
+++ b/flang/test/Semantics/OpenMP/default-none.f90
@@ -46,4 +46,4 @@ subroutine sb4
     loop: do i = 1, 10
     end do loop
   !$omp end parallel
-end subroutine
\ No newline at end of file
+end subroutine



More information about the flang-commits mailing list