[llvm-commits] [llvm] r121402 - /llvm/trunk/lib/MC/MCStreamer.cpp

John Tytgat john at bass-software.com
Sun Dec 12 07:10:02 PST 2010


In message <20101209192621.AF9112A6C12C at llvm.org>
          Devang Patel <dpatel at apple.com> wrote:

> Author: dpatel
> Date: Thu Dec  9 13:26:21 2010
> New Revision: 121402
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=121402&view=rev
> Log:
> Add assert to catch an attempt to emit .byte 256
> 
> Modified:
>     llvm/trunk/lib/MC/MCStreamer.cpp
> 
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=121402&r1=121401&r2=121402&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Thu Dec  9 13:26:21 2010
> @@ -47,7 +47,8 @@
>  /// pass in a MCExpr for constant integers.
>  void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size,
>                                unsigned AddrSpace) {
> -  assert(Size <= 8);
> +  assert(Size <= 8 && "Invalid size");
> +  assert(!(Size == 1 && (signed)Value > 255) && "Invalid size");

This doesn't catch the Size = 1 and Value = 1UL<<63 case.  Use
Value > 255U instead ?

>    char buf[8];
>    // FIXME: Endianness assumption.
>    for (unsigned i = 0; i != Size; ++i)

I've attached a small patch checking on more Value & Size cases.  Please
commit after review.

John.
-- 
John Tytgat
John at bass-software.com
-------------- next part --------------
Index: lib/MC/MCStreamer.cpp
===================================================================
--- lib/MC/MCStreamer.cpp	(revision 121635)
+++ lib/MC/MCStreamer.cpp	(working copy)
@@ -48,11 +48,11 @@
 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size,
                               unsigned AddrSpace) {
   assert(Size <= 8 && "Invalid size");
-  assert(!(Size == 1 && (signed)Value > 255) && "Invalid size");
   char buf[8];
   // FIXME: Endianness assumption.
-  for (unsigned i = 0; i != Size; ++i)
-    buf[i] = uint8_t(Value >> (i * 8));
+  for (unsigned i = 0; i != Size; ++i, Value >>= 8)
+    buf[i] = uint8_t(Value);
+  assert(Value == 0 && "Invalid size");
   EmitBytes(StringRef(buf, Size), AddrSpace);
 }
 


More information about the llvm-commits mailing list