[all-commits] [llvm/llvm-project] f4ec17: [ARM] Fix undefined behavior in `isLegalAddImmedia...

Simon Tatham via All-commits all-commits at lists.llvm.org
Fri Mar 21 02:04:11 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f4ec179bf5295f92aa0346392a58fad54f9b458e
      https://github.com/llvm/llvm-project/commit/f4ec179bf5295f92aa0346392a58fad54f9b458e
  Author: Simon Tatham <simon.tatham at arm.com>
  Date:   2025-03-21 (Fri, 21 Mar 2025)

  Changed paths:
    M llvm/include/llvm/Support/MathExtras.h
    M llvm/lib/Target/ARM/ARMISelLowering.cpp

  Log Message:
  -----------
  [ARM] Fix undefined behavior in `isLegalAddImmediate` (#132219)

Building clang under UBsan, it reported an integer overflow in this
function when the input value was -2^63, because it's UB to pass the
maximum negative value of an integer type to `std::abs`.

Fixed by adding a new absolute-value function in `MathExtras.h` whose
return type is the unsigned version of the argument type, and using that
instead.

(This seems like the kind of thing C++ should have already had, but
apparently it doesn't, and I couldn't find an existing one in LLVM
Support either.)



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list