[llvm-commits] [llvm] r111336 - /llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
Chris Lattner
sabre at nondot.org
Tue Aug 17 17:29:18 PDT 2010
Author: lattner
Date: Tue Aug 17 19:29:18 2010
New Revision: 111336
URL: http://llvm.org/viewvc/llvm-project?rev=111336&view=rev
Log:
don't emit zero bit fields with Emit, fixing undefined behavior,
PR7778
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h?rev=111336&r1=111335&r2=111336&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h Tue Aug 17 19:29:18 2010
@@ -88,7 +88,7 @@
//===--------------------------------------------------------------------===//
void Emit(uint32_t Val, unsigned NumBits) {
- assert(NumBits <= 32 && "Invalid value size!");
+ assert(NumBits && NumBits <= 32 && "Invalid value size!");
assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
CurValue |= Val << CurBit;
if (CurBit + NumBits < 32) {
@@ -277,10 +277,12 @@
switch (Op.getEncoding()) {
default: assert(0 && "Unknown encoding!");
case BitCodeAbbrevOp::Fixed:
- Emit((unsigned)V, (unsigned)Op.getEncodingData());
+ if (Op.getEncodingData())
+ Emit((unsigned)V, (unsigned)Op.getEncodingData());
break;
case BitCodeAbbrevOp::VBR:
- EmitVBR64(V, (unsigned)Op.getEncodingData());
+ if (Op.getEncodingData())
+ EmitVBR64(V, (unsigned)Op.getEncodingData());
break;
case BitCodeAbbrevOp::Char6:
Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
More information about the llvm-commits
mailing list