Don't allow MCStreamer::EmitIntValue to output 0-byte integers.
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 20 Aug 2014 22:46:38 +0000 (22:46 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 20 Aug 2014 22:46:38 +0000 (22:46 +0000)
It makes no sense and can hide bugs. In particular, it lead
to left shift by 64 bits, which is an undefined behavior,
properly reported by UBSan.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216134 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
lib/MC/MCStreamer.cpp

index c01f3acc66176cc240046ebe02938b363746ee0b..aafc5e1850e9385d2c1fec9dc862b43b29dfba9c 100644 (file)
@@ -2612,7 +2612,8 @@ bool AsmParser::parseDirectiveFill() {
 
   for (uint64_t i = 0, e = NumValues; i != e; ++i) {
     getStreamer().EmitIntValue(FillExpr, NonZeroFillSize);
-    getStreamer().EmitIntValue(0, FillSize - NonZeroFillSize);
+    if (NonZeroFillSize < FillSize)
+      getStreamer().EmitIntValue(0, FillSize - NonZeroFillSize);
   }
 
   return false;
index e7ee9e481bf6f0502b0a141f446a4ecd24cd402d..914e337267002c14fb07dfab4a41852979a08911 100644 (file)
@@ -72,7 +72,7 @@ void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
 /// EmitIntValue - Special case of EmitValue that avoids the client having to
 /// pass in a MCExpr for constant integers.
 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
-  assert(Size <= 8 && "Invalid size");
+  assert(1 <= Size && Size <= 8 && "Invalid size");
   assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
          "Invalid size");
   char buf[8];