https://github.com/ipranjalks updated https://github.com/llvm/llvm-project/pull/238672
>From c10a8371a154b16fb3984d844449c124aa938cdf Mon Sep 17 00:00:00 2001 From: Pranjal Srivastava <[email protected]> Date: Wed, 4 Nov 2026 05:23:47 +0000 Subject: [PATCH 1/3] Use APSInt::compareValues when checking ordered depend count --- clang/docs/ReleaseNotes.md | 4 ++++ clang/lib/Sema/SemaOpenMP.cpp | 2 +- clang/test/OpenMP/ordered_messages.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 409d2459b0580b..4e37123d33c518 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1578,6 +1578,10 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was renamed to `alpha.core.Use captured by copy when a nested construct has `default(firstprivate)` or `default(private)`, which could silently lose writes such as the result of a reduction on the nested construct. +- Fixed a crash when analyzing an OpenMP `ordered` directive with a `depend` or + `doacross` clause inside a loop whose `ordered` clause argument has a + bit-width other than 32 bits (such as `int` on 16-bit targets or `long long`). + (#GH235971) ### SYCL Support diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 88217bd836edc5..290510ee5a95a9 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23751,7 +23751,7 @@ ProcessOpenMPDoacrossClauseCommon(Sema &SemaRef, bool IsSource, Expr *SimpleExpr = RefExpr->IgnoreParenCasts(); if (!IsSource) { if (Stack->getParentOrderedRegionParam().first && - DepCounter >= TotalDepCount) { + llvm::APSInt::compareValues(DepCounter, TotalDepCount) >= 0) { SemaRef.Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); continue; } diff --git a/clang/test/OpenMP/ordered_messages.cpp b/clang/test/OpenMP/ordered_messages.cpp index 8575713698647c..ddea01c1830590 100644 --- a/clang/test/OpenMP/ordered_messages.cpp +++ b/clang/test/OpenMP/ordered_messages.cpp @@ -416,3 +416,29 @@ int k; return foo<int>(); // expected-note {{in instantiation of function template specialization 'foo<int>' requested here}} } + +void gh235971() { + int k; +#pragma omp for ordered(1LL) + for (int i = 0; i < 10; ++i) { +#if _OPENMP >= 202111 +#pragma omp ordered doacross(sink : i - 1) +#pragma omp ordered doacross(sink : i, k) // omp52-error {{unexpected expression: number of expressions is larger than the number of associated loops}} +#else +#pragma omp ordered depend(sink : i - 1) +#pragma omp ordered depend(sink : i, k) // expected-error {{unexpected expression: number of expressions is larger than the number of associated loops}} +#endif + } + + const short One = 1; +#pragma omp for ordered(One) + for (int i = 0; i < 10; ++i) { +#if _OPENMP >= 202111 +#pragma omp ordered doacross(sink : i - 1) +#pragma omp ordered doacross(sink : i, k) // omp52-error {{unexpected expression: number of expressions is larger than the number of associated loops}} +#else +#pragma omp ordered depend(sink : i - 1) +#pragma omp ordered depend(sink : i, k) // expected-error {{unexpected expression: number of expressions is larger than the number of associated loops}} +#endif + } +} >From 9d482004139b1e295e5a495d968b0955500bcb20 Mon Sep 17 00:00:00 2001 From: Pranjal Srivastava <[email protected]> Date: Fri, 6 Nov 2026 03:53:15 +0000 Subject: [PATCH 2/3] Address review feedback: initialize DepCounter with TotalDepCount.getBitWidth() --- clang/lib/Sema/SemaOpenMP.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 290510ee5a95a9..38b6626a363e33 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23730,7 +23730,6 @@ ProcessOpenMPDoacrossClauseCommon(Sema &SemaRef, bool IsSource, SmallVector<Expr *, 8> Vars; DSAStackTy::OperatorOffsetTy OpsOffs; - llvm::APSInt DepCounter(/*BitWidth=*/32); llvm::APSInt TotalDepCount(/*BitWidth=*/32); if (const Expr *OrderedCountExpr = @@ -23738,6 +23737,7 @@ ProcessOpenMPDoacrossClauseCommon(Sema &SemaRef, bool IsSource, TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(SemaRef.Context); TotalDepCount.setIsUnsigned(/*Val=*/true); } + llvm::APSInt DepCounter(TotalDepCount.getBitWidth()); for (Expr *RefExpr : VarList) { assert(RefExpr && "NULL expr in OpenMP doacross clause."); @@ -23751,7 +23751,7 @@ ProcessOpenMPDoacrossClauseCommon(Sema &SemaRef, bool IsSource, Expr *SimpleExpr = RefExpr->IgnoreParenCasts(); if (!IsSource) { if (Stack->getParentOrderedRegionParam().first && - llvm::APSInt::compareValues(DepCounter, TotalDepCount) >= 0) { + DepCounter >= TotalDepCount) { SemaRef.Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); continue; } >From e62fc166daca6df1c0e81658057a42a507f234d0 Mon Sep 17 00:00:00 2001 From: Pranjal Srivastava <[email protected]> Date: Wed, 18 Nov 2026 20:00:39 +0000 Subject: [PATCH 3/3] Explicitly pass isUnsigned=true to DepCounter constructor --- clang/lib/Sema/SemaOpenMP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 38b6626a363e33..f4d0a9641ea6d2 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -23737,7 +23737,7 @@ ProcessOpenMPDoacrossClauseCommon(Sema &SemaRef, bool IsSource, TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(SemaRef.Context); TotalDepCount.setIsUnsigned(/*Val=*/true); } - llvm::APSInt DepCounter(TotalDepCount.getBitWidth()); + llvm::APSInt DepCounter(TotalDepCount.getBitWidth(), /*isUnsigned=*/true); for (Expr *RefExpr : VarList) { assert(RefExpr && "NULL expr in OpenMP doacross clause."); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
