[all-commits] [llvm/llvm-project] 492a4a: [APInt] Fix 1-bit edge case in smul_ov()

Nikita Popov via All-commits all-commits at lists.llvm.org
Sat Oct 16 11:31:23 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 492a4a428f77556d413c2179fad9ba4ae6d130b9
      https://github.com/llvm/llvm-project/commit/492a4a428f77556d413c2179fad9ba4ae6d130b9
  Author: Nikita Popov <nikita.ppv at gmail.com>
  Date:   2021-10-16 (Sat, 16 Oct 2021)

  Changed paths:
    M llvm/lib/Support/APInt.cpp
    M llvm/unittests/ADT/APIntTest.cpp

  Log Message:
  -----------
  [APInt] Fix 1-bit edge case in smul_ov()

The sdiv used to check for overflow can itself overflow if the
LHS is signed min and the RHS is -1. The code tried to account for
this by also checking the commuted version. However, for 1-bit
values, signed min and -1 are the same value, so both divisions
overflow. As such, the overflow for -1 * -1 was not detected
(which results in -1 rather than 1 for 1-bit values). Fix this by
explicitly checking for this case instead.

Noticed while adding exhaustive test coverage for smul_ov(),
which is also part of this commit.




More information about the All-commits mailing list