llvm.org GIT mirror llvm / 2217648
[Bitcode] AtEndOfStream should only check against the size if it's known. This avoids an issue where AtEndOfStream mistakenly returns true at the /start/ of a stream. (In the rare case that the size is known and actually 0, the slow path will still handle it correctly.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221840 91177308-0d34-0410-b5e6-96231b3b80d8 Jordan Rose 4 years ago
3 changed file(s) with 58 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
226226 bool AtEndOfStream() {
227227 if (BitsInCurWord != 0)
228228 return false;
229 if (Size == NextChar)
229 if (Size != 0 && Size == NextChar)
230230 return true;
231231 fillCurWord();
232232 return BitsInCurWord == 0;
0 //===- BitstreamReaderTest.cpp - Tests for BitstreamReader ----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Bitcode/BitstreamReader.h"
10 #include "gtest/gtest.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 TEST(BitstreamReaderTest, AtEndOfStream) {
17 uint8_t Bytes[4] = {
18 0x00, 0x01, 0x02, 0x03
19 };
20 BitstreamReader Reader(std::begin(Bytes), std::end(Bytes));
21 BitstreamCursor Cursor(Reader);
22
23 EXPECT_FALSE(Cursor.AtEndOfStream());
24 (void)Cursor.Read(8);
25 EXPECT_FALSE(Cursor.AtEndOfStream());
26 (void)Cursor.Read(24);
27 EXPECT_TRUE(Cursor.AtEndOfStream());
28
29 Cursor.JumpToBit(0);
30 EXPECT_FALSE(Cursor.AtEndOfStream());
31
32 Cursor.JumpToBit(32);
33 EXPECT_TRUE(Cursor.AtEndOfStream());
34 }
35
36 TEST(BitstreamReaderTest, AtEndOfStreamJump) {
37 uint8_t Bytes[4] = {
38 0x00, 0x01, 0x02, 0x03
39 };
40 BitstreamReader Reader(std::begin(Bytes), std::end(Bytes));
41 BitstreamCursor Cursor(Reader);
42
43 Cursor.JumpToBit(32);
44 EXPECT_TRUE(Cursor.AtEndOfStream());
45 }
46
47 TEST(BitstreamReaderTest, AtEndOfStreamEmpty) {
48 uint8_t Dummy = 0xFF;
49 BitstreamReader Reader(&Dummy, &Dummy);
50 BitstreamCursor Cursor(Reader);
51
52 EXPECT_TRUE(Cursor.AtEndOfStream());
53 }
54
55 } // end anonymous namespace
77
88 add_llvm_unittest(BitcodeTests
99 BitReaderTest.cpp
10 BitstreamReaderTest.cpp
1011 )