[flang-commits] [flang] [Flang][OpenMP] Add diagnosing zero-length depend array sections and … (PR #224168)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 16 16:45:56 PDT 2026
https://github.com/laoshd created https://github.com/llvm/llvm-project/pull/224168
…tests.
This PR is to fix #222551.
>From 199759139eddadc95c6ee75228456836cff369a7 Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Wed, 16 Sep 2026 13:39:10 -0500
Subject: [PATCH] [Flang][OpenMP] Add diagnosing zero-length depend array
sections and tests.
---
flang/lib/Semantics/check-omp-structure.cpp | 52 ++++++++++++---------
flang/test/Semantics/OpenMP/depend01.f90 | 30 ++++++++++--
2 files changed, 58 insertions(+), 24 deletions(-)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 274efa64d03d0..372634c022ff6 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -6025,7 +6025,9 @@ void OmpStructureChecker::CheckArraySection(
for (const auto &subscript : arrayElement.Subscripts()) {
if (const auto *triplet{
std::get_if<parser::SubscriptTriplet>(&subscript.u)}) {
- if (std::get<0>(triplet->t) && std::get<1>(triplet->t)) {
+ const auto &lower{std::get<0>(triplet->t)};
+ const auto &upper{std::get<1>(triplet->t)};
+ if (lower && upper) {
std::optional<int64_t> strideVal{std::nullopt};
if (const auto &strideExpr = std::get<2>(triplet->t)) {
// OpenMP 6.0 Section 5.2.5: Array Sections
@@ -6042,28 +6044,36 @@ void OmpStructureChecker::CheckArraySection(
"Cannot specify a step for a substring"_err_en_US);
}
}
- const auto &lower{std::get<0>(triplet->t)};
- const auto &upper{std::get<1>(triplet->t)};
- if (lower && upper) {
- const auto lval{GetIntValue(lower)};
- const auto uval{GetIntValue(upper)};
- if (lval && uval) {
- int64_t sectionLen = *uval - *lval;
- if (strideVal) {
- if (*strideVal == 0) {
- continue;
- }
- sectionLen = sectionLen / *strideVal;
+ const auto lval{GetIntValue(lower)};
+ const auto uval{GetIntValue(upper)};
+ if (lval && uval) {
+ int64_t sectionLen = *uval - *lval;
+ if (strideVal) {
+ if (*strideVal == 0) {
+ continue;
}
+ sectionLen = sectionLen / *strideVal;
+ }
- if (sectionLen < 1) {
- context_.Say(GetContext().clauseSource,
- "'%s' in %s clause"
- " is a zero size array section"_err_en_US,
- name.ToString(),
- parser::omp::GetUpperName(clause, version));
- break;
- }
+ if (sectionLen < 1) {
+ context_.Say(GetContext().clauseSource,
+ "'%s' in %s clause"
+ " is a zero size array section"_err_en_US,
+ name.ToString(), parser::omp::GetUpperName(clause, version));
+ break;
+ }
+ }
+ } else if (clause == llvm::omp::Clause::OMPC_depend) {
+ if (auto extents{
+ evaluate::AsConstantExtents(context_.foldingContext(),
+ evaluate::GetShape(
+ context_.foldingContext(), *name.symbol))}) {
+ if (llvm::is_contained(*extents, 0)) {
+ context_.Say(GetContext().clauseSource,
+ "'%s' in %s clause"
+ " is a zero size array section"_err_en_US,
+ name.ToString(), parser::omp::GetUpperName(clause, version));
+ break;
}
}
}
diff --git a/flang/test/Semantics/OpenMP/depend01.f90 b/flang/test/Semantics/OpenMP/depend01.f90
index 2b23cc1c4f68c..37eb971cd90ab 100644
--- a/flang/test/Semantics/OpenMP/depend01.f90
+++ b/flang/test/Semantics/OpenMP/depend01.f90
@@ -1,10 +1,11 @@
-! RUN: %python %S/../test_errors.py %s %flang -fopenmp
-! OpenMP Version 4.5
-! 2.13.9 Depend Clause
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50
+! OpenMP Version 5.0
+! 2.17.11 Depend Clause
! List items used in depend clauses cannot be zero-length array sections.
program omp_depend
integer :: a(10) , b(10,10)
+ integer :: x(0)
a = 10
b = 20
@@ -35,6 +36,29 @@ program omp_depend
print *, a(1:10)
!$omp end task
+ !$omp task depend(in: a(:))
+ !$omp end task
+
+ !ERROR: 'x' in DEPEND clause is a zero size array section
+ !$omp task depend(in: x(:))
+ !$omp end task
+
+ !ERROR: 'x' in DEPEND clause is a zero size array section
+ !$omp task depend(out: x(:))
+ !$omp end task
+
+ !ERROR: 'x' in DEPEND clause is a zero size array section
+ !$omp task depend(inout: x(:))
+ !$omp end task
+
+ !ERROR: 'x' in DEPEND clause is a zero size array section
+ !$omp task depend(mutexinoutset: x(:))
+ !$omp end task
+
+ !ERROR: 'x' in DEPEND clause is a zero size array section
+ !$omp task depend(depobj: x(:))
+ !$omp end task
+
!$omp end single
!$omp end parallel
More information about the flang-commits
mailing list