diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-12-15 07:12:24 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-12-15 07:12:24 +0000 |
| commit | f80f18a11af32b69375a2b2cc0a5265412d9720f (patch) | |
| tree | 88c454111f6d4f591b406525f44ad2156b6658af | |
| parent | 27ecda1efdb3b86cb92072be153dabfbf8d770fc (diff) | |
| download | bcm5719-llvm-f80f18a11af32b69375a2b2cc0a5265412d9720f.tar.gz bcm5719-llvm-f80f18a11af32b69375a2b2cc0a5265412d9720f.zip | |
Generalize an assert.
llvm-svn: 121851
| -rw-r--r-- | llvm/include/llvm/Support/MathExtras.h | 6 | ||||
| -rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index 6740786dec7..d0b34771ae1 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -76,6 +76,12 @@ inline bool isUIntN(unsigned N, uint64_t x) { return x == (x & (~0ULL >> (64 - N))); } +/// isIIntN - Checks if an signed integer fits into the given (dynamic) +/// bit width. +inline bool isIntN(unsigned N, int64_t x) { + return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1))); +} + /// isMask_32 - This function returns true if the argument is a sequence of ones /// starting at the least significant bit with the remainder zero (32 bit /// version). Ex. isMask_32(0x0000FFFFU) == true. diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 6f9692d2274..fc7a7547561 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -48,7 +48,8 @@ void MCStreamer::EmitDwarfSetLineAddr(int64_t LineDelta, void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace) { assert(Size <= 8 && "Invalid size"); - assert(!(Size == 1 && (signed)Value > 255) && "Invalid size"); + unsigned Bits = 8 * Size; + assert((isUIntN(Bits, Value) || isIntN(Bits, Value)) && "Invalid size"); char buf[8]; // FIXME: Endianness assumption. for (unsigned i = 0; i != Size; ++i) |

