[flang-commits] [flang] [flang][OpenMP][#225225] Add diagnosis on invalid list items in depend(depobj:) clauses (PR #227790)
via flang-commits
flang-commits at lists.llvm.org
Fri Oct 9 04:24:39 PDT 2026
https://github.com/laoshd updated https://github.com/llvm/llvm-project/pull/227790
>From c5efbb428dd8ad5c165eb496f6929ea4ddcf9e5f Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Wed, 30 Sep 2026 05:43:45 -0500
Subject: [PATCH] [FLANG][OpenMP] Implement DEPOBJ dependence type checks in
OmpStructureChecker and add related tests.
---
flang/lib/Semantics/check-omp-structure.cpp | 48 +++++++++++++++++--
.../OpenMP/Todo/depend-clause-depobj.f90 | 3 +-
flang/test/Semantics/OpenMP/depend-depobj.f90 | 35 ++++++++++++++
3 files changed, 81 insertions(+), 5 deletions(-)
create mode 100644 flang/test/Semantics/OpenMP/depend-depobj.f90
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 09b6c6bc3449fb..65ff3849000296 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -5257,6 +5257,42 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
"one locator"_err_en_US);
}
}
+ // [5.0:256:1-2], [5.1:288:19-20], [5.2:323:1-2]
+ // With the DEPOBJ dependence type, array sections cannot be specified and
+ // the list items must be depend objects (scalar integer variables of kind
+ // omp_depend_kind, which is c_intptr_t). This does not apply on the DEPOBJ
+ // construct itself, where the DEPOBJ dependence type is already disallowed.
+ bool isDepobjType{dir != llvm::omp::OMPD_depobj &&
+ taskDep->GetTaskDepType() ==
+ parser::OmpTaskDependenceType::Value::Depobj};
+ auto checkDepobjVar = [&](const parser::OmpObject &object) {
+ const parser::Designator *designator{GetDesignatorFromObj(object)};
+ if (!designator) {
+ context_.Say(GetContext().clauseSource,
+ "A list item in a DEPEND clause with the DEPOBJ dependence type must be a depend object"_err_en_US);
+ return;
+ }
+ evaluate::ExpressionAnalyzer ea{context_};
+ auto restore{ea.AllowWholeAssumedSizeArray(true)};
+ MaybeExpr expr{ea.Analyze(*designator)};
+ if (!expr) {
+ return;
+ }
+ if (expr->Rank() != 0) {
+ context_.Say(GetContext().clauseSource,
+ "Array sections cannot be specified in a DEPEND clause with the DEPOBJ dependence type"_err_en_US);
+ return;
+ }
+ // A depend object is a scalar integer of omp_depend_kind (c_intptr_t).
+ std::optional<evaluate::DynamicType> type{expr->GetType()};
+ int depobjKind{static_cast<int>(
+ context_.targetCharacteristics().integerKindForPointer())};
+ if (!type || type->category() != evaluate::TypeCategory::Integer ||
+ type->kind() != depobjKind) {
+ context_.Say(GetContext().clauseSource,
+ "A list item in a DEPEND clause with the DEPOBJ dependence type must be a depend object (a scalar integer variable of kind omp_depend_kind)"_err_en_US);
+ }
+ };
for (const auto &object : objList.v) {
if (const auto *name{GetCommonBlockFromObj(object)}) {
context_.Say(GetContext().clauseSource,
@@ -5264,10 +5300,14 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
"clause"_err_en_US,
name->ToString());
} else if (auto *dataRef{GetDataRefFromObj(object)}) {
- CheckDependList(*dataRef);
- if (const auto *arr{GetArrayElementFromObj(object)}) {
- CheckArraySection(
- *arr, GetLastName(*dataRef), llvm::omp::Clause::OMPC_depend);
+ if (isDepobjType) {
+ checkDepobjVar(object);
+ } else {
+ CheckDependList(*dataRef);
+ if (const auto *arr{GetArrayElementFromObj(object)}) {
+ CheckArraySection(
+ *arr, GetLastName(*dataRef), llvm::omp::Clause::OMPC_depend);
+ }
}
}
}
diff --git a/flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90 b/flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90
index 4e98d77d0bb3e3..aecdde4ca48204 100644
--- a/flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90
+++ b/flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90
@@ -4,7 +4,8 @@
!CHECK: not yet implemented: DEPOBJ dependence-type
subroutine f00(x)
- integer :: x
+ use iso_c_binding, only: c_intptr_t
+ integer(c_intptr_t) :: x
!$omp task depend(depobj: x)
!$omp end task
end
diff --git a/flang/test/Semantics/OpenMP/depend-depobj.f90 b/flang/test/Semantics/OpenMP/depend-depobj.f90
new file mode 100644
index 00000000000000..98944c72f9265b
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/depend-depobj.f90
@@ -0,0 +1,35 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
+
+! OpenMP 5.0 2.17.11 depend Clause restrictions for the DEPOBJ dependence type:
+! - Array sections cannot be specified.
+! - List items must be depend objects (scalar integers of omp_depend_kind).
+
+subroutine f00(x, y, obj, objs)
+ use iso_c_binding, only: c_intptr_t
+ integer :: x
+ integer :: y(10)
+ integer(c_intptr_t) :: obj
+ integer(c_intptr_t) :: objs(10)
+
+ ! A plain integer is not a depend object (wrong kind).
+ !ERROR: A list item in a DEPEND clause with the DEPOBJ dependence type must be a depend object (a scalar integer variable of kind omp_depend_kind)
+ !$omp task depend(depobj: x)
+ !$omp end task
+
+ ! Array sections cannot be specified.
+ !ERROR: Array sections cannot be specified in a DEPEND clause with the DEPOBJ dependence type
+ !$omp task depend(depobj: objs(1:3))
+ !$omp end task
+
+ ! A whole array is not a depend object.
+ !ERROR: Array sections cannot be specified in a DEPEND clause with the DEPOBJ dependence type
+ !$omp task depend(depobj: y)
+ !$omp end task
+
+ ! A valid depend object (scalar) and a depend-object array element are accepted
+ ! by semantics (lowering is not yet implemented).
+ !$omp task depend(depobj: obj)
+ !$omp end task
+ !$omp task depend(depobj: objs(2))
+ !$omp end task
+end
More information about the flang-commits
mailing list