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

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 23:24:53 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Wu Yingcong (yingcong-wu)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/116339.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp (+1) 


``````````diff
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([&]() {

``````````

</details>


https://github.com/llvm/llvm-project/pull/116339


More information about the llvm-commits mailing list