Skip to content

Commit

Permalink
nowrshmsk: Check for stride==0
Browse files Browse the repository at this point in the history
log2(0) returns -inf, which gives undefined behaviour when casting to an int.  So catch the case when it's 0 just set the width to 0.
  • Loading branch information
KrystalDelusion authored Jan 30, 2025
1 parent 31b00b4 commit cf52cf3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontends/ast/simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,10 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
lsb_expr->children[stride_ix]->detectSignWidth(stride_width, stride_sign);
max_width = std::max(i_width, stride_width);
// Stride width calculated from actual stride value.
stride_width = std::ceil(std::log2(std::abs(stride)));
if (stride == 0)
stride_width = 0;
else
stride_width = std::ceil(std::log2(std::abs(stride)));

if (i_width + stride_width > max_width) {
// For (truncated) i*stride to be within the range of dst, the following must hold:
Expand Down

0 comments on commit cf52cf3

Please sign in to comment.