[llvm] [ControlHeightReduction] Add assert to avoid underflow (PR #116339)

Wu Yingcong via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 00:29:47 PST 2024


https://github.com/yingcong-wu created https://github.com/llvm/llvm-project/pull/116339

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

>From f59c8f25f274407db954c45ee40076775fbc16bc Mon Sep 17 00:00:00 2001
From: Wu Yingcong <yingcong.wu at intel.com>
Date: Fri, 15 Nov 2024 16:28:08 +0800
Subject: [PATCH] Add assert to avoid 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 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