https://github.com/kevinsala created https://github.com/llvm/llvm-project/pull/218589
The condition to update upper-bound of number of threads was inverted. We now update the upper-bound with any constant value even if it we already found a non-constant value. Test to be added. >From 4a7453879437dece66b2f70ad30389e9e049da74 Mon Sep 17 00:00:00 2001 From: Kevin Sala <[email protected]> Date: Tue, 14 Jul 2026 08:52:13 -0700 Subject: [PATCH] [Clang][OpenMP] Fix upper-bound for number of threads --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 4b8b1de973407..4f5eb2d7160da 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6712,8 +6712,8 @@ static void getNumThreads(CodeGenFunction &CGF, const CapturedStmt *CS, if (NTExpr->isIntegerConstantExpr(CGF.getContext())) if (auto Constant = NTExpr->getIntegerConstantExpr(CGF.getContext())) UpperBound = - UpperBound - ? Constant->getZExtValue() + (UpperBound <= 0) + ? static_cast<int32_t>(Constant->getZExtValue()) : std::min(UpperBound, static_cast<int32_t>(Constant->getZExtValue())); // If we haven't found a upper bound, remember we saw a thread limiting @@ -6757,12 +6757,13 @@ const Expr *CGOpenMPRuntime::getNumThreadsExprForTargetDirective( const Expr **NTPtr = UpperBoundOnly ? nullptr : &NT; auto CheckForConstExpr = [&](const Expr *E, const Expr **EPtr) { - if (E->isIntegerConstantExpr(CGF.getContext())) { + if (E->isIntegerConstantExpr(CGF.getContext())) if (auto Constant = E->getIntegerConstantExpr(CGF.getContext())) - UpperBound = UpperBound ? Constant->getZExtValue() - : std::min(UpperBound, - int32_t(Constant->getZExtValue())); - } + UpperBound = + (UpperBound <= 0) + ? static_cast<int32_t>(Constant->getZExtValue()) + : std::min(UpperBound, + static_cast<int32_t>(Constant->getZExtValue())); // If we haven't found a upper bound, remember we saw a thread limiting // clause. if (UpperBound == -1) _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
