diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index a02ecaa762ae..cdb72b95ad71 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -625,7 +625,12 @@ public: /// Negates *this using two's complement logic. /// /// \returns An APInt value representing the negation of *this. - APInt operator-() const { return APInt(BitWidth, 0) - (*this); } + APInt operator-() const { + APInt Result(*this); + Result.flipAllBits(); + ++Result; + return Result; + } /// \brief Logical negation operator. ///