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

Kajetan Puchalski via flang-commits flang-commits at lists.llvm.org
Tue Jun 3 05:42:58 PDT 2025


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

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.

>From b59fe2b597f19de2f657858f236e80a7ecc14117 Mon Sep 17 00:00:00 2001
From: Kajetan Puchalski <kajetan.puchalski at arm.com>
Date: Tue, 3 Jun 2025 12:35:03 +0000
Subject: [PATCH] [flang][OpenMP] Show error for task depend with no valid
 modifiers

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.

Signed-off-by: Kajetan Puchalski <kajetan.puchalski at arm.com>
---
 flang/lib/Semantics/check-omp-structure.cpp | 7 +++++++
 flang/test/Semantics/OpenMP/task-depend.f90 | 8 ++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/task-depend.f90

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
+



More information about the flang-commits mailing list