Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9ef1f40

Browse files
committed
Add error recovery for abbreviations outside blocks in bitcode.
Adds error recovery to the bitcode munger writer that handles abbreviation definitions that do not appear in any block (not allowed by the bitcode writer). BUG=None [email protected] Review URL: https://codereview.chromium.org/1150183010
1 parent 4dd3b8a commit 9ef1f40

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ bool WriteState::emitRecord(NaClBitstreamWriter &Writer,
404404
markCurrentBlockWithOmittedAbbreviations();
405405
return Flags.getTryToRecover();
406406
}
407+
if (atOutermostScope()) {
408+
RecoverableError() << "Abbreviation definition not in block: "
409+
<< Record << "\n";
410+
return Flags.getTryToRecover();
411+
}
407412
if (getCurWriteBlockID() == naclbitc::BLOCKINFO_BLOCK_ID) {
408413
Writer.EmitBlockInfoAbbrev(SetBID, Abbrev);
409414
} else {

unittests/Bitcode/NaClMungeWriteErrorTests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,4 +663,21 @@ TEST(NaClMungeWriteErrorTests, SpecifiesTooManyOperands) {
663663
ExpectedDumpedBitcode);
664664
}
665665

666+
// Show what happens if an abbreviation definition is defined outside a block.
667+
TEST(NaClMungeWriteErrorTests, AbbreviationNotInBlock) {
668+
// Add abbreviation before all records.
669+
const uint64_t Edit[] = {
670+
0, NaClMungedBitcode::AddBefore,
671+
naclbitc::DEFINE_ABBREV, naclbitc::BLK_CODE_DEFINE_ABBREV, 1,
672+
1, 10, // lit(10)
673+
Terminator
674+
};
675+
CheckDumpEdits(
676+
ARRAY(Edit),
677+
"Error (Block unknown): Abbreviation definition not in block: 2:"
678+
" [65533, 1, 1, 10]\n",
679+
NoErrorRecoveryMessages,
680+
ExpectedDumpedBitcode);
681+
}
682+
666683
} // end of namespace naclmungetest

0 commit comments

Comments
 (0)