[PATCH] D38833: BitstreamWriter: Better assertion when a block's abbrev code size is too small
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 13 23:29:58 PDT 2018
lebedev.ri added inline comments.
================
Comment at: unittests/Bitcode/BitstreamWriterTest.cpp:75-182
+TEST(BitstreamWriterTest, trapOnSmallAbbrev_CodeLength2) {
+ SmallString<64> Buffer;
+ BitstreamWriter W(Buffer);
+ W.EnterSubblock(bitc::FIRST_APPLICATION_BLOCKID, /*CodeLen*/2);
+ auto Abbrev = std::make_shared<BitCodeAbbrev>();
+ Abbrev->Add(BitCodeAbbrevOp(42U));
+ unsigned AbbrevCode = W.EmitAbbrev(std::move(Abbrev));
----------------
This looks rather monstrous, with a lot of duplication.
I was suggesting to just do:
```
TEST(BitstreamWriterTest, trapOnSmallAbbrevUsingBlockInfo_CodeLength3_Ok) {
SmallString<64> Buffer;
BitstreamWriter W(Buffer);
W.EnterBlockInfoBlock();
auto Abbrev = std::make_shared<BitCodeAbbrev>();
Abbrev->Add(BitCodeAbbrevOp(2U);
(void)W.EmitBlockInfoAbbrev(bitc::FIRST_APPLICATION_BLOCKID,
std::move(Abbrev));
W.ExitBlock();
W.EnterSubblock(bitc::FIRST_APPLICATION_BLOCKID, /*CodeLen*/3);
W.EmitRecordWithAbbrev(Abbrev, makeArrayRef(2U));
W.ExitBlock();
}
TEST(BitstreamWriterTest, trapOnSmallAbbrevUsingBlockInfo_CodeLength3_LastOk) {
SmallString<64> Buffer;
BitstreamWriter W(Buffer);
W.EnterBlockInfoBlock();
auto Abbrev = std::make_shared<BitCodeAbbrev>();
Abbrev->Add(BitCodeAbbrevOp(3U);
(void)W.EmitBlockInfoAbbrev(bitc::FIRST_APPLICATION_BLOCKID,
std::move(Abbrev));
W.ExitBlock();
W.EnterSubblock(bitc::FIRST_APPLICATION_BLOCKID, /*CodeLen*/3);
W.EmitRecordWithAbbrev(Abbrev, makeArrayRef(3U));
W.ExitBlock();
}
TEST(BitstreamWriterTest, trapOnSmallAbbrevUsingBlockInfo_CodeLength3_NotOk) {
SmallString<64> Buffer;
BitstreamWriter W(Buffer);
W.EnterBlockInfoBlock();
auto Abbrev = std::make_shared<BitCodeAbbrev>();
Abbrev->Add(BitCodeAbbrevOp(4U);
(void)W.EmitBlockInfoAbbrev(bitc::FIRST_APPLICATION_BLOCKID,
std::move(Abbrev));
W.ExitBlock();
W.EnterSubblock(bitc::FIRST_APPLICATION_BLOCKID, /*CodeLen*/3);
W.EmitRecordWithAbbrev(Abbrev, makeArrayRef(4U));
W.ExitBlock();
TEST(BitstreamWriterTest, trapOnSmallAbbrevUsingBlockInfo_CodeLength3_NoOverFlow) {
SmallString<64> Buffer;
BitstreamWriter W(Buffer);
W.EnterBlockInfoBlock();
auto Abbrev = std::make_shared<BitCodeAbbrev>();
Abbrev->Add(BitCodeAbbrevOp(4294967295U); // i32 -1
(void)W.EmitBlockInfoAbbrev(bitc::FIRST_APPLICATION_BLOCKID,
std::move(Abbrev));
W.ExitBlock();
W.EnterSubblock(bitc::FIRST_APPLICATION_BLOCKID, /*CodeLen*/32);
W.EmitRecordWithAbbrev(Abbrev, makeArrayRef(4294967295U));
W.ExitBlock();
}
```
Repository:
rL LLVM
https://reviews.llvm.org/D38833
More information about the llvm-commits
mailing list