[llvm] fa5eb22 - [NFC] Assert non-zero factor before division

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 18 01:51:10 PDT 2021


Author: Max Kazantsev
Date: 2021-06-18T15:50:50+07:00
New Revision: fa5eb22ad4e127b1fa960b33da890afb5bca3f92

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

LOG: [NFC] Assert non-zero factor before division

This is to ensure that zero denominator leads to controlled
assertion failure rather than UB.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 1382826c838e..a4cbcd4cffef 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3919,6 +3919,7 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
     if (Base.BaseOffset == std::numeric_limits<int64_t>::min() && Factor == -1)
       continue;
     int64_t NewBaseOffset = (uint64_t)Base.BaseOffset * Factor;
+    assert(Factor != 0 && "Zero factor not expected!");
     if (NewBaseOffset / Factor != Base.BaseOffset)
       continue;
     // If the offset will be truncated at this use, check that it is in bounds.


        


More information about the llvm-commits mailing list