Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/FindIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class FindIntrinsics : public IRMutator {
Expr a = c->args[0];
Expr b = c->args[1];

if (Call::as_intrinsic(b, {Call::signed_integer_overflow})) {
// Letting signed integer overflow through here would result in
// infinite recursion when we try to construct the rounding
// terms.
return Expr{};
}

// Helper to make the appropriate shift.
auto rounding_shift = [&](const Expr &a, const Expr &b) {
if (c->is_intrinsic(Call::shift_right)) {
Expand Down Expand Up @@ -203,7 +210,7 @@ class FindIntrinsics : public IRMutator {
}
}

return Expr();
return Expr{};
}

template<typename LetOrLetStmt>
Expand Down
5 changes: 5 additions & 0 deletions test/correctness/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ int main(int argc, char **argv) {
check_intrinsics_over_range<int32_t>();
check_intrinsics_over_range<uint32_t>();

// Signed integer overflow on the RHS of a shift used to cause infinite
// recursion (issue #9108)
Expr e = simplify(i32x << (i32x << 67));
check(e, e);

// The intrinsics-matching pass substitutes in widening lets. At
// one point this caused a missing symbol bug for the code below
// due to a subexpression not getting mutated.
Expand Down
Loading