[llvm] 42775a4 - [ControlHeightReduction] Add assert to avoid underflow (#116339)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 22:13:12 PST 2024


Author: Wu Yingcong
Date: 2024-11-21T14:13:08+08:00
New Revision: 42775a44c9a6ba8dc03ad4c88fa9321e78ebd434

URL: https://github.com/llvm/llvm-project/commit/42775a44c9a6ba8dc03ad4c88fa9321e78ebd434
DIFF: https://github.com/llvm/llvm-project/commit/42775a44c9a6ba8dc03ad4c88fa9321e78ebd434.diff

LOG: [ControlHeightReduction] Add assert to avoid underflow (#116339)

`NumCHRedBranches - 1` is used later, we should add an assertion to make
sure it will not underflow.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index c8ee933913e65a..b3883cd6e1688e 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([&]() {


        


More information about the llvm-commits mailing list