[flang-commits] [flang] Users/laos/i225225 (PR #227790)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 30 11:00:46 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-fir-hlfir
Author: laoshd
<details>
<summary>Changes</summary>
Summary
Add diagnose invalid list items in depend(depobj:) clauses to enforces the OpenMP 5.0 §2.17.11 restrictions on the depend clause with the depobj dependence type in the semantic checker, so invalid programs get a clear diagnostic instead of falling through to the not yet implemented: DEPOBJ dependence-type lowering TODO.
Per the spec, with the depobj dependence type:
• Array sections cannot be specified in depend clauses with the depobj dependence type.
• List items used in depend clauses with the depobj dependence type must be depend objects in the initialized state.
Also adds a semantics test and updates the existing Todo lowering test to use a valid depend object. Lowering remains unimplemented; this is front-end checks only.
This PR will fix #<!-- -->225225.
With AI assistance.
---
Full diff: https://github.com/llvm/llvm-project/pull/227790.diff
3 Files Affected:
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+44-4)
- (modified) flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90 (+2-1)
- (added) flang/test/Semantics/OpenMP/depend-depobj.f90 (+35)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 09b6c6bc3449f..65ff384900029 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 4e98d77d0bb3e..aecdde4ca4820 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 0000000000000..98944c72f9265
--- /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
``````````
</details>
https://github.com/llvm/llvm-project/pull/227790
More information about the flang-commits
mailing list