[llvm-commits] [llvm] r121851 - in /llvm/trunk: include/llvm/Support/MathExtras.h lib/MC/MCStreamer.cpp

Rafael Espindola rafael.espindola at gmail.com
Tue Dec 14 23:12:24 PST 2010


Author: rafael
Date: Wed Dec 15 01:12:24 2010
New Revision: 121851

URL: http://llvm.org/viewvc/llvm-project?rev=121851&view=rev
Log:
Generalize an assert.

Modified:
    llvm/trunk/include/llvm/Support/MathExtras.h
    llvm/trunk/lib/MC/MCStreamer.cpp

Modified: llvm/trunk/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=121851&r1=121850&r2=121851&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h (original)
+++ llvm/trunk/include/llvm/Support/MathExtras.h Wed Dec 15 01:12:24 2010
@@ -76,6 +76,12 @@
   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.

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=121851&r1=121850&r2=121851&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Wed Dec 15 01:12:24 2010
@@ -48,7 +48,8 @@
 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)





More information about the llvm-commits mailing list