[flang-commits] [flang] [flang][OpenMP] Convert default assertion into a semantic error (PR #93438)

via flang-commits flang-commits at lists.llvm.org
Sun May 26 21:44:41 PDT 2024


https://github.com/NimishMishra created https://github.com/llvm/llvm-project/pull/93438

Currently, the handling of default clause on directives enforces an assertion on whether default clause is allowed on the directive. This causes crashes when default is erroneously defined on a directive. This PR converts the assertion into a semantic failure.

>From b5f9bb2a3526aa0f5583bbfaf0769508909bacde Mon Sep 17 00:00:00 2001
From: Nimish Mishra <neelam.nimish at gmail.com>
Date: Mon, 27 May 2024 10:05:29 +0530
Subject: [PATCH] Convert default clause assertion into a semantic error

---
 flang/lib/Semantics/resolve-directives.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index dbc531372c3f4..659f508e1c193 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2109,8 +2109,13 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
           dirContext.defaultDSA == Symbol::Flag::OmpShared) {
         // 1) default
         // Allowed only with parallel, teams and task generating constructs.
-        assert(parallelDir || taskGenDir ||
-            llvm::omp::allTeamsSet.test(dirContext.directive));
+        if (!(parallelDir || taskGenDir ||
+                llvm::omp::allTeamsSet.test(dirContext.directive)))
+          context_.Say(dirContext.directiveSource,
+              "%s directive cannot have default clause"_err_en_US,
+              parser::ToUpperCaseLetters(
+                  llvm::omp::getOpenMPDirectiveName(dirContext.directive)
+                      .str()));
         if (dirContext.defaultDSA != Symbol::Flag::OmpShared)
           declNewSymbol(dirContext.defaultDSA);
         else



More information about the flang-commits mailing list