[flang-commits] [flang] [flang][OpenMP] Don't abort when default is used on an invalid directive (PR #107586)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Mon Sep 9 08:57:28 PDT 2024


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/107586

>From 84bbca866dd6d21eba82a38e7c13eb177166c226 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 6 Sep 2024 10:29:53 -0300
Subject: [PATCH 1/2] [flang][OpenMP] Don't abort when default is used on an
 invalid directive

The previous assert was not considering programs with semantic errors.

Fixes https://github.com/llvm/llvm-project/issues/107495
---
 flang/lib/Semantics/resolve-directives.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 4aecb8b8e7b479..01ce8d989fdd15 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2152,7 +2152,9 @@ void OmpAttributeVisitor::CreateImplicitSymbols(
         dirContext.defaultDSA == Symbol::Flag::OmpShared) {
       // 1) default
       // Allowed only with parallel, teams and task generating constructs.
-      assert(parallelDir || taskGenDir || teamsDir);
+      if (!parallelDir && !taskGenDir && !teamsDir) {
+        return;
+      }
       if (dirContext.defaultDSA != Symbol::Flag::OmpShared)
         makePrivateSymbol(dirContext.defaultDSA);
       else

>From 21b2c27530748b44b3dadfa7d438d915a4ce0500 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Mon, 9 Sep 2024 12:54:15 -0300
Subject: [PATCH 2/2] Test DEFAULT on (not allowed) DO directive

---
 flang/test/Semantics/OpenMP/default.f90 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/flang/test/Semantics/OpenMP/default.f90 b/flang/test/Semantics/OpenMP/default.f90
index 94de7fa4686927..a8d170724c12c9 100644
--- a/flang/test/Semantics/OpenMP/default.f90
+++ b/flang/test/Semantics/OpenMP/default.f90
@@ -31,4 +31,13 @@ program omp_default
   end do
   !$omp end teams
 
+  !$omp parallel
+  !ERROR: DEFAULT clause is not allowed on the DO directive
+  !$omp do default(private)
+  do i = 1, 10
+     k = i
+  end do
+  !$omp end do
+  !$omp end parallel
+
 end program omp_default



More information about the flang-commits mailing list