diff --git a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp index 2f34532ae935..dff6d181486a 100644 --- a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp @@ -199,7 +199,8 @@ unsigned BitstreamCursor::readRecord(unsigned AbbrevID, unsigned NumElts = ReadVBR(6); // Get the element encoding. - assert(i+2 == e && "array op not second to last?"); + if (i+2 != e) + report_fatal_error("Array op not second to last"); const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); if (EltEnc.getEncoding() == BitCodeAbbrevOp::Array || EltEnc.getEncoding() == BitCodeAbbrevOp::Blob) diff --git a/llvm/test/Bitcode/Inputs/invalid-array-op-not-2nd-to-last.bc b/llvm/test/Bitcode/Inputs/invalid-array-op-not-2nd-to-last.bc new file mode 100644 index 000000000000..a4b94f8213df Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-array-op-not-2nd-to-last.bc differ diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index 6dfab58375e8..41173d17e5df 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -105,3 +105,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-vector-element-type.bc 2>&1 RUN: FileCheck --check-prefix=ELEMENT-TYPE %s ELEMENT-TYPE: Invalid type + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-op-not-2nd-to-last.bc 2>&1 | \ +RUN: FileCheck --check-prefix=ARRAY-NOT-2LAST %s + +ARRAY-NOT-2LAST: Array op not second to last