[flang-commits] [flang] [flang][OpenMP] Show error for task depend with no valid modifiers (PR #142595)

via flang-commits flang-commits at lists.llvm.org
Tue Jun 3 05:43:34 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Kajetan Puchalski (mrkajetanp)

<details>
<summary>Changes</summary>

If a "TASK DEPEND" clause is not given a valid task dependece type modifier, the semantic checks for the clause will result in an ICE because they assume that such modifiers will be present. Check whether the modifiers are present and show an appropriate error instead of crashing the compiler if they are not.

Fixes llvm#<!-- -->133678.

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


2 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+7) 
- (added) flang/test/Semantics/OpenMP/task-depend.f90 (+8) 


``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 76dfd40c6a62c..f9d645dc2e78a 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -4420,6 +4420,13 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
     CheckDoacross(*doaDep);
     CheckDependenceType(doaDep->GetDepType());
   } else {
+    using Modifier = parser::OmpDependClause::TaskDep::Modifier;
+    auto &modifiers{std::get<std::optional<std::list<Modifier>>>(taskDep->t)};
+    if (!modifiers) {
+      context_.Say(GetContext().clauseSource,
+          "A DEPEND clause on a TASK construct must have a valid task dependence type"_err_en_US);
+      return;
+    }
     CheckTaskDependenceType(taskDep->GetTaskDepType());
   }
 
diff --git a/flang/test/Semantics/OpenMP/task-depend.f90 b/flang/test/Semantics/OpenMP/task-depend.f90
new file mode 100644
index 0000000000000..69a37e014bde3
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/task-depend.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+program test
+! ERROR: A DEPEND clause on a TASK construct must have a valid task dependence type
+!$omp task depend(ii)
+!$omp end task
+end
+

``````````

</details>


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


More information about the flang-commits mailing list