From 42775a44c9a6ba8dc03ad4c88fa9321e78ebd434 Mon Sep 17 00:00:00 2001 From: Wu Yingcong Date: Thu, 21 Nov 2024 14:13:08 +0800 Subject: [PATCH] [ControlHeightReduction] Add assert to avoid underflow (#116339) `NumCHRedBranches - 1` is used later, we should add an assertion to make sure it will not underflow. --- llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index c8ee933913e6..b3883cd6e168 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1862,6 +1862,7 @@ void CHR::fixupBranchesAndSelects(CHRScope *Scope, ++NumCHRedBranches; } } + assert(NumCHRedBranches > 0); Stats.NumBranchesDelta += NumCHRedBranches - 1; Stats.WeightedNumBranchesDelta += (NumCHRedBranches - 1) * ProfileCount; ORE.emit([&]() { -- 2.11.4.GIT