diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index f664339a8c5..628a83cb0de 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -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 diff --git a/unittests/Bitcode/BitstreamReaderTest.cpp b/unittests/Bitcode/BitstreamReaderTest.cpp index c99239b48a4..2be774cc539 100644 --- a/unittests/Bitcode/BitstreamReaderTest.cpp +++ b/unittests/Bitcode/BitstreamReaderTest.cpp @@ -121,6 +121,7 @@ TEST(BitstreamReaderTest, setArtificialByteLimit) { SimpleBitstreamCursor Cursor(Reader); Cursor.setArtificialByteLimit(8); + EXPECT_EQ(8u, Cursor.getSizeIfKnown()); while (!Cursor.AtEndOfStream()) (void)Cursor.Read(1); @@ -134,6 +135,7 @@ TEST(BitstreamReaderTest, setArtificialByteLimitNotWordBoundary) { SimpleBitstreamCursor Cursor(Reader); Cursor.setArtificialByteLimit(5); + EXPECT_EQ(8u, Cursor.getSizeIfKnown()); while (!Cursor.AtEndOfStream()) (void)Cursor.Read(1); @@ -148,11 +150,13 @@ TEST(BitstreamReaderTest, setArtificialByteLimitPastTheEnd) { // 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, setArtificialByteLimitPastTheEndKnown) { 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) {