diff options
Diffstat (limited to 'llvm/lib/Support/APSInt.cpp')
-rw-r--r-- | llvm/lib/Support/APSInt.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Support/APSInt.cpp b/llvm/lib/Support/APSInt.cpp index 7c48880f96eac..b65b6824eaf8e 100644 --- a/llvm/lib/Support/APSInt.cpp +++ b/llvm/lib/Support/APSInt.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/APSInt.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/StringRef.h" +#include <cassert> using namespace llvm; @@ -25,14 +26,14 @@ APSInt::APSInt(StringRef Str) { APInt Tmp(NumBits, Str, /*radix=*/10); if (Str[0] == '-') { unsigned MinBits = Tmp.getMinSignedBits(); - if (MinBits > 0 && MinBits < NumBits) - Tmp = Tmp.trunc(MinBits); + if (MinBits < NumBits) + Tmp = Tmp.trunc(std::max<unsigned>(1, MinBits)); *this = APSInt(Tmp, /*isUnsigned=*/false); return; } unsigned ActiveBits = Tmp.getActiveBits(); - if (ActiveBits > 0 && ActiveBits < NumBits) - Tmp = Tmp.trunc(ActiveBits); + if (ActiveBits < NumBits) + Tmp = Tmp.trunc(std::max<unsigned>(1, ActiveBits)); *this = APSInt(Tmp, /*isUnsigned=*/true); } |