[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:45:11 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: None (NimishMishra)

<details>
<summary>Changes</summary>

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.

Fixes https://github.com/llvm/llvm-project/issues/93437

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


1 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+7-2) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list