From fa5eb22ad4e127b1fa960b33da890afb5bca3f92 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Fri, 18 Jun 2021 15:49:56 +0700 Subject: [PATCH] [NFC] Assert non-zero factor before division This is to ensure that zero denominator leads to controlled assertion failure rather than UB. --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 1382826..a4cbcd4 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::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. -- 2.7.4