[llvm] r264650 - Explicitly test BitstreamReader::setArtificialByteLimit, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 28 13:39:41 PDT 2016
Author: dexonsmith
Date: Mon Mar 28 15:39:41 2016
New Revision: 264650
URL: http://llvm.org/viewvc/llvm-project?rev=264650&view=rev
Log:
Explicitly test BitstreamReader::setArtificialByteLimit, NFC
Explicitly check that artificial byte limit is rounded correctly by
exposing BitstreamReader::Size through a new accessor, getSizeIfKnown.
The original code for rounding (from r264547) wasn't obviously correct,
and even though r264623 cleaned it up (by calling llvm::alignTo) I think
it's worth testing.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=264650&r1=264649&r2=264650&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Mon Mar 28 15:39:41 2016
@@ -373,6 +373,9 @@ public:
if (!Size || Size > Limit)
Size = Limit;
}
+
+ /// Return the Size, if known.
+ uint64_t getSizeIfKnown() const { return Size; }
};
/// When advancing through a bitstream cursor, each advance can discover a few
Modified: llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp?rev=264650&r1=264649&r2=264650&view=diff
==============================================================================
--- llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp (original)
+++ llvm/trunk/unittests/Bitcode/BitstreamReaderTest.cpp Mon Mar 28 15:39:41 2016
@@ -121,6 +121,7 @@ TEST(BitstreamReaderTest, setArtificialB
SimpleBitstreamCursor Cursor(Reader);
Cursor.setArtificialByteLimit(8);
+ EXPECT_EQ(8u, Cursor.getSizeIfKnown());
while (!Cursor.AtEndOfStream())
(void)Cursor.Read(1);
@@ -134,6 +135,7 @@ TEST(BitstreamReaderTest, setArtificialB
SimpleBitstreamCursor Cursor(Reader);
Cursor.setArtificialByteLimit(5);
+ EXPECT_EQ(8u, Cursor.getSizeIfKnown());
while (!Cursor.AtEndOfStream())
(void)Cursor.Read(1);
@@ -148,11 +150,13 @@ TEST(BitstreamReaderTest, setArtificialB
// The size of the memory object isn't known yet. Set it too high and
// confirm that we don't read too far.
- Cursor.setArtificialByteLimit(20);
+ Cursor.setArtificialByteLimit(24);
+ EXPECT_EQ(24u, Cursor.getSizeIfKnown());
while (!Cursor.AtEndOfStream())
(void)Cursor.Read(1);
EXPECT_EQ(12u, Cursor.getCurrentByteNo());
+ EXPECT_EQ(12u, Cursor.getSizeIfKnown());
}
TEST(BitstreamReaderTest, setArtificialByteLimitPastTheEndKnown) {
@@ -165,9 +169,11 @@ TEST(BitstreamReaderTest, setArtificialB
while (!Cursor.AtEndOfStream())
(void)Cursor.Read(1);
EXPECT_EQ(12u, Cursor.getCurrentByteNo());
+ EXPECT_EQ(12u, Cursor.getSizeIfKnown());
Cursor.setArtificialByteLimit(20);
EXPECT_TRUE(Cursor.AtEndOfStream());
+ EXPECT_EQ(12u, Cursor.getSizeIfKnown());
}
TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
More information about the llvm-commits
mailing list