Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Bitstream/BitstreamReader.h
Line
Count
Source (jump to first uncovered line)
1
//===- BitstreamReader.h - Low-level bitstream reader interface -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This header defines the BitstreamReader class.  This class can be used to
10
// read an arbitrary bitstream, regardless of its contents.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_BITSTREAM_BITSTREAMREADER_H
15
#define LLVM_BITSTREAM_BITSTREAMREADER_H
16
17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/SmallVector.h"
19
#include "llvm/Bitstream/BitCodes.h"
20
#include "llvm/Support/Endian.h"
21
#include "llvm/Support/ErrorHandling.h"
22
#include "llvm/Support/MathExtras.h"
23
#include "llvm/Support/MemoryBuffer.h"
24
#include <algorithm>
25
#include <cassert>
26
#include <climits>
27
#include <cstddef>
28
#include <cstdint>
29
#include <memory>
30
#include <string>
31
#include <utility>
32
#include <vector>
33
34
namespace llvm {
35
36
/// This class maintains the abbreviations read from a block info block.
37
class BitstreamBlockInfo {
38
public:
39
  /// This contains information emitted to BLOCKINFO_BLOCK blocks. These
40
  /// describe abbreviations that all blocks of the specified ID inherit.
41
  struct BlockInfo {
42
    unsigned BlockID;
43
    std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
44
    std::string Name;
45
    std::vector<std::pair<unsigned, std::string>> RecordNames;
46
  };
47
48
private:
49
  std::vector<BlockInfo> BlockInfoRecords;
50
51
public:
52
  /// If there is block info for the specified ID, return it, otherwise return
53
  /// null.
54
1.12M
  const BlockInfo *getBlockInfo(unsigned BlockID) const {
55
1.12M
    // Common case, the most recent entry matches BlockID.
56
1.12M
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID1.09M
)
57
338k
      return &BlockInfoRecords.back();
58
784k
59
784k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
60
1.70M
         i != e; 
++i923k
)
61
1.42M
      if (BlockInfoRecords[i].BlockID == BlockID)
62
500k
        return &BlockInfoRecords[i];
63
784k
    
return nullptr283k
;
64
784k
  }
65
66
25.6k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
67
25.6k
    if (const BlockInfo *BI = getBlockInfo(BlockID))
68
32
      return *const_cast<BlockInfo*>(BI);
69
25.5k
70
25.5k
    // Otherwise, add a new record.
71
25.5k
    BlockInfoRecords.emplace_back();
72
25.5k
    BlockInfoRecords.back().BlockID = BlockID;
73
25.5k
    return BlockInfoRecords.back();
74
25.5k
  }
75
};
76
77
/// This represents a position within a bitstream. There may be multiple
78
/// independent cursors reading within one bitstream, each maintaining their
79
/// own local state.
80
class SimpleBitstreamCursor {
81
  ArrayRef<uint8_t> BitcodeBytes;
82
  size_t NextChar = 0;
83
84
public:
85
  /// This is the current data we have pulled from the stream but have not
86
  /// returned to the client. This is specifically and intentionally defined to
87
  /// follow the word size of the host machine for efficiency. We use word_t in
88
  /// places that are aware of this to make it perfectly explicit what is going
89
  /// on.
90
  using word_t = size_t;
91
92
private:
93
  word_t CurWord = 0;
94
95
  /// This is the number of bits in CurWord that are valid. This is always from
96
  /// [0...bits_of(size_t)-1] inclusive.
97
  unsigned BitsInCurWord = 0;
98
99
public:
100
  static const constexpr size_t MaxChunkSize = sizeof(word_t) * 8;
101
102
45.4k
  SimpleBitstreamCursor() = default;
103
  explicit SimpleBitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
104
19.5k
      : BitcodeBytes(BitcodeBytes) {}
105
  explicit SimpleBitstreamCursor(StringRef BitcodeBytes)
106
31.2k
      : BitcodeBytes(arrayRefFromStringRef(BitcodeBytes)) {}
107
  explicit SimpleBitstreamCursor(MemoryBufferRef BitcodeBytes)
108
201
      : SimpleBitstreamCursor(BitcodeBytes.getBuffer()) {}
109
110
405k
  bool canSkipToPos(size_t pos) const {
111
405k
    // pos can be skipped to if it is a valid address or one byte past the end.
112
405k
    return pos <= BitcodeBytes.size();
113
405k
  }
114
115
31.4M
  bool AtEndOfStream() {
116
31.4M
    return BitsInCurWord == 0 && 
BitcodeBytes.size() <= NextChar2.58M
;
117
31.4M
  }
118
119
  /// Return the bit # of the bit we are reading.
120
1.86M
  uint64_t GetCurrentBitNo() const {
121
1.86M
    return NextChar*CHAR_BIT - BitsInCurWord;
122
1.86M
  }
123
124
  // Return the byte # of the current bit.
125
35.9k
  uint64_t getCurrentByteNo() const { return GetCurrentBitNo() / 8; }
126
127
34.8k
  ArrayRef<uint8_t> getBitcodeBytes() const { return BitcodeBytes; }
128
129
  /// Reset the stream to the specified bit number.
130
2.03M
  Error JumpToBit(uint64_t BitNo) {
131
2.03M
    size_t ByteNo = size_t(BitNo/8) & ~(sizeof(word_t)-1);
132
2.03M
    unsigned WordBitNo = unsigned(BitNo & (sizeof(word_t)*8-1));
133
2.03M
    assert(canSkipToPos(ByteNo) && "Invalid location");
134
2.03M
135
2.03M
    // Move the cursor to the right word.
136
2.03M
    NextChar = ByteNo;
137
2.03M
    BitsInCurWord = 0;
138
2.03M
139
2.03M
    // Skip over any bits that are already consumed.
140
2.03M
    if (WordBitNo) {
141
1.75M
      if (Expected<word_t> Res = Read(WordBitNo))
142
1.75M
        return Error::success();
143
18.4E
      else
144
18.4E
        return Res.takeError();
145
282k
    }
146
282k
147
282k
    return Error::success();
148
282k
  }
149
150
  /// Get a pointer into the bitstream at the specified byte offset.
151
243k
  const uint8_t *getPointerToByte(uint64_t ByteNo, uint64_t NumBytes) {
152
243k
    return BitcodeBytes.data() + ByteNo;
153
243k
  }
154
155
  /// Get a pointer into the bitstream at the specified bit offset.
156
  ///
157
  /// The bit offset must be on a byte boundary.
158
243k
  const uint8_t *getPointerToBit(uint64_t BitNo, uint64_t NumBytes) {
159
243k
    assert(!(BitNo % 8) && "Expected bit on byte boundary");
160
243k
    return getPointerToByte(BitNo / 8, NumBytes);
161
243k
  }
162
163
36.2M
  Error fillCurWord() {
164
36.2M
    if (NextChar >= BitcodeBytes.size())
165
0
      return createStringError(std::errc::io_error,
166
0
                               "Unexpected end of file reading %u of %u bytes",
167
0
                               NextChar, BitcodeBytes.size());
168
36.2M
169
36.2M
    // Read the next word from the stream.
170
36.2M
    const uint8_t *NextCharPtr = BitcodeBytes.data() + NextChar;
171
36.2M
    unsigned BytesRead;
172
36.2M
    if (BitcodeBytes.size() >= NextChar + sizeof(word_t)) {
173
36.2M
      BytesRead = sizeof(word_t);
174
36.2M
      CurWord =
175
36.2M
          support::endian::read<word_t, support::little, support::unaligned>(
176
36.2M
              NextCharPtr);
177
36.2M
    } else {
178
26.2k
      // Short read.
179
26.2k
      BytesRead = BitcodeBytes.size() - NextChar;
180
26.2k
      CurWord = 0;
181
131k
      for (unsigned B = 0; B != BytesRead; 
++B105k
)
182
105k
        CurWord |= uint64_t(NextCharPtr[B]) << (B * 8);
183
26.2k
    }
184
36.2M
    NextChar += BytesRead;
185
36.2M
    BitsInCurWord = BytesRead * 8;
186
36.2M
    return Error::success();
187
36.2M
  }
188
189
366M
  Expected<word_t> Read(unsigned NumBits) {
190
366M
    static const unsigned BitsInWord = MaxChunkSize;
191
366M
192
366M
    assert(NumBits && NumBits <= BitsInWord &&
193
366M
           "Cannot return zero or more than BitsInWord bits!");
194
366M
195
366M
    static const unsigned Mask = sizeof(word_t) > 4 ? 
0x3f0
: 0x1f;
196
366M
197
366M
    // If the field is fully contained by CurWord, return it quickly.
198
366M
    if (BitsInCurWord >= NumBits) {
199
330M
      word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
200
330M
201
330M
      // Use a mask to avoid undefined behavior.
202
330M
      CurWord >>= (NumBits & Mask);
203
330M
204
330M
      BitsInCurWord -= NumBits;
205
330M
      return R;
206
330M
    }
207
36.2M
208
36.2M
    word_t R = BitsInCurWord ? 
CurWord25.4M
:
010.8M
;
209
36.2M
    unsigned BitsLeft = NumBits - BitsInCurWord;
210
36.2M
211
36.2M
    if (Error fillResult = fillCurWord())
212
0
      return std::move(fillResult);
213
36.2M
214
36.2M
    // If we run out of data, abort.
215
36.2M
    if (BitsLeft > BitsInCurWord)
216
0
      return createStringError(std::errc::io_error,
217
0
                               "Unexpected end of file reading %u of %u bits",
218
0
                               BitsInCurWord, BitsLeft);
219
36.2M
220
36.2M
    word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
221
36.2M
222
36.2M
    // Use a mask to avoid undefined behavior.
223
36.2M
    CurWord >>= (BitsLeft & Mask);
224
36.2M
225
36.2M
    BitsInCurWord -= BitsLeft;
226
36.2M
227
36.2M
    R |= R2 << (NumBits - BitsLeft);
228
36.2M
229
36.2M
    return R;
230
36.2M
  }
231
232
35.0M
  Expected<uint32_t> ReadVBR(unsigned NumBits) {
233
35.0M
    Expected<unsigned> MaybeRead = Read(NumBits);
234
35.0M
    if (!MaybeRead)
235
0
      return MaybeRead;
236
35.0M
    uint32_t Piece = MaybeRead.get();
237
35.0M
238
35.0M
    if ((Piece & (1U << (NumBits-1))) == 0)
239
31.4M
      return Piece;
240
3.56M
241
3.56M
    uint32_t Result = 0;
242
3.56M
    unsigned NextBit = 0;
243
7.14M
    while (
true7.14M
) {
244
7.14M
      Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit;
245
7.14M
246
7.14M
      if ((Piece & (1U << (NumBits-1))) == 0)
247
3.56M
        return Result;
248
3.58M
249
3.58M
      NextBit += NumBits-1;
250
3.58M
      MaybeRead = Read(NumBits);
251
3.58M
      if (!MaybeRead)
252
0
        return MaybeRead;
253
3.58M
      Piece = MaybeRead.get();
254
3.58M
    }
255
3.56M
  }
256
257
  // Read a VBR that may have a value up to 64-bits in size. The chunk size of
258
  // the VBR must still be <= 32 bits though.
259
102M
  Expected<uint64_t> ReadVBR64(unsigned NumBits) {
260
102M
    Expected<uint64_t> MaybeRead = Read(NumBits);
261
102M
    if (!MaybeRead)
262
0
      return MaybeRead;
263
102M
    uint32_t Piece = MaybeRead.get();
264
102M
265
102M
    if ((Piece & (1U << (NumBits-1))) == 0)
266
60.3M
      return uint64_t(Piece);
267
42.3M
268
42.3M
    uint64_t Result = 0;
269
42.3M
    unsigned NextBit = 0;
270
90.7M
    while (
true90.7M
) {
271
90.7M
      Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit;
272
90.7M
273
90.7M
      if ((Piece & (1U << (NumBits-1))) == 0)
274
42.3M
        return Result;
275
48.4M
276
48.4M
      NextBit += NumBits-1;
277
48.4M
      MaybeRead = Read(NumBits);
278
48.4M
      if (!MaybeRead)
279
0
        return MaybeRead;
280
48.4M
      Piece = MaybeRead.get();
281
48.4M
    }
282
42.3M
  }
283
284
2.67M
  void SkipToFourByteBoundary() {
285
2.67M
    // If word_t is 64-bits and if we've read less than 32 bits, just dump
286
2.67M
    // the bits we have up to the next 32-bit boundary.
287
2.67M
    if (sizeof(word_t) > 4 &&
288
2.67M
        BitsInCurWord >= 32) {
289
1.42M
      CurWord >>= BitsInCurWord-32;
290
1.42M
      BitsInCurWord = 32;
291
1.42M
      return;
292
1.42M
    }
293
1.25M
294
1.25M
    BitsInCurWord = 0;
295
1.25M
  }
296
297
  /// Return the size of the stream in bytes.
298
15.5k
  size_t SizeInBytes() const { return BitcodeBytes.size(); }
299
300
  /// Skip to the end of the file.
301
0
  void skipToEnd() { NextChar = BitcodeBytes.size(); }
302
};
303
304
/// When advancing through a bitstream cursor, each advance can discover a few
305
/// different kinds of entries:
306
struct BitstreamEntry {
307
  enum {
308
    Error,    // Malformed bitcode was found.
309
    EndBlock, // We've reached the end of the current block, (or the end of the
310
              // file, which is treated like a series of EndBlock records.
311
    SubBlock, // This is the start of a new subblock of a specific ID.
312
    Record    // This is a record with a specific AbbrevID.
313
  } Kind;
314
315
  unsigned ID;
316
317
7.42k
  static BitstreamEntry getError() {
318
7.42k
    BitstreamEntry E; E.Kind = Error; return E;
319
7.42k
  }
320
321
1.12M
  static BitstreamEntry getEndBlock() {
322
1.12M
    BitstreamEntry E; E.Kind = EndBlock; return E;
323
1.12M
  }
324
325
912k
  static BitstreamEntry getSubBlock(unsigned ID) {
326
912k
    BitstreamEntry E; E.Kind = SubBlock; E.ID = ID; return E;
327
912k
  }
328
329
27.6M
  static BitstreamEntry getRecord(unsigned AbbrevID) {
330
27.6M
    BitstreamEntry E; E.Kind = Record; E.ID = AbbrevID; return E;
331
27.6M
  }
332
};
333
334
/// This represents a position within a bitcode file, implemented on top of a
335
/// SimpleBitstreamCursor.
336
///
337
/// Unlike iterators, BitstreamCursors are heavy-weight objects that should not
338
/// be passed by value.
339
class BitstreamCursor : SimpleBitstreamCursor {
340
  // This is the declared size of code values used for the current block, in
341
  // bits.
342
  unsigned CurCodeSize = 2;
343
344
  /// Abbrevs installed at in this block.
345
  std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
346
347
  struct Block {
348
    unsigned PrevCodeSize;
349
    std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
350
351
1.16M
    explicit Block(unsigned PCS) : PrevCodeSize(PCS) {}
352
  };
353
354
  /// This tracks the codesize of parent blocks.
355
  SmallVector<Block, 8> BlockScope;
356
357
  BitstreamBlockInfo *BlockInfo = nullptr;
358
359
public:
360
  static const size_t MaxChunkSize = sizeof(word_t) * 8;
361
362
45.4k
  BitstreamCursor() = default;
363
  explicit BitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
364
19.5k
      : SimpleBitstreamCursor(BitcodeBytes) {}
365
  explicit BitstreamCursor(StringRef BitcodeBytes)
366
16.8k
      : SimpleBitstreamCursor(BitcodeBytes) {}
367
  explicit BitstreamCursor(MemoryBufferRef BitcodeBytes)
368
201
      : SimpleBitstreamCursor(BitcodeBytes) {}
369
370
  using SimpleBitstreamCursor::AtEndOfStream;
371
  using SimpleBitstreamCursor::canSkipToPos;
372
  using SimpleBitstreamCursor::fillCurWord;
373
  using SimpleBitstreamCursor::getBitcodeBytes;
374
  using SimpleBitstreamCursor::GetCurrentBitNo;
375
  using SimpleBitstreamCursor::getCurrentByteNo;
376
  using SimpleBitstreamCursor::getPointerToByte;
377
  using SimpleBitstreamCursor::JumpToBit;
378
  using SimpleBitstreamCursor::Read;
379
  using SimpleBitstreamCursor::ReadVBR;
380
  using SimpleBitstreamCursor::ReadVBR64;
381
  using SimpleBitstreamCursor::SizeInBytes;
382
383
  /// Return the number of bits used to encode an abbrev #.
384
336k
  unsigned getAbbrevIDWidth() const { return CurCodeSize; }
385
386
  /// Flags that modify the behavior of advance().
387
  enum {
388
    /// If this flag is used, the advance() method does not automatically pop
389
    /// the block scope when the end of a block is reached.
390
    AF_DontPopBlockAtEnd = 1,
391
392
    /// If this flag is used, abbrev entries are returned just like normal
393
    /// records.
394
    AF_DontAutoprocessAbbrevs = 2
395
  };
396
397
  /// Advance the current bitstream, returning the next entry in the stream.
398
29.7M
  Expected<BitstreamEntry> advance(unsigned Flags = 0) {
399
30.0M
    while (
true30.0M
) {
400
30.0M
      if (AtEndOfStream())
401
7.41k
        return BitstreamEntry::getError();
402
30.0M
403
30.0M
      Expected<unsigned> MaybeCode = ReadCode();
404
30.0M
      if (!MaybeCode)
405
0
        return MaybeCode.takeError();
406
30.0M
      unsigned Code = MaybeCode.get();
407
30.0M
408
30.0M
      if (Code == bitc::END_BLOCK) {
409
1.12M
        // Pop the end of the block unless Flags tells us not to.
410
1.12M
        if (!(Flags & AF_DontPopBlockAtEnd) && 
ReadBlockEnd()1.12M
)
411
6
          return BitstreamEntry::getError();
412
1.12M
        return BitstreamEntry::getEndBlock();
413
1.12M
      }
414
28.9M
415
28.9M
      if (Code == bitc::ENTER_SUBBLOCK) {
416
912k
        if (Expected<unsigned> MaybeSubBlock = ReadSubBlockID())
417
912k
          return BitstreamEntry::getSubBlock(MaybeSubBlock.get());
418
18.4E
        else
419
18.4E
          return MaybeSubBlock.takeError();
420
28.0M
      }
421
28.0M
422
28.0M
      if (Code == bitc::DEFINE_ABBREV &&
423
28.0M
          
!(Flags & AF_DontAutoprocessAbbrevs)519k
) {
424
370k
        // We read and accumulate abbrev's, the client can't do anything with
425
370k
        // them anyway.
426
370k
        if (Error Err = ReadAbbrevRecord())
427
0
          return std::move(Err);
428
370k
        continue;
429
370k
      }
430
27.6M
431
27.6M
      return BitstreamEntry::getRecord(Code);
432
27.6M
    }
433
29.7M
  }
434
435
  /// This is a convenience function for clients that don't expect any
436
  /// subblocks. This just skips over them automatically.
437
16.5M
  Expected<BitstreamEntry> advanceSkippingSubblocks(unsigned Flags = 0) {
438
16.5M
    while (
true16.5M
) {
439
16.5M
      // If we found a normal entry, return it.
440
16.5M
      Expected<BitstreamEntry> MaybeEntry = advance(Flags);
441
16.5M
      if (!MaybeEntry)
442
0
        return MaybeEntry;
443
16.5M
      BitstreamEntry Entry = MaybeEntry.get();
444
16.5M
445
16.5M
      if (Entry.Kind != BitstreamEntry::SubBlock)
446
16.5M
        return Entry;
447
2.47k
448
2.47k
      // If we found a sub-block, just skip over it and check the next entry.
449
2.47k
      if (Error Err = SkipBlock())
450
0
        return std::move(Err);
451
2.47k
    }
452
16.5M
  }
453
454
30.6M
  Expected<unsigned> ReadCode() { return Read(CurCodeSize); }
455
456
  // Block header:
457
  //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
458
459
  /// Having read the ENTER_SUBBLOCK code, read the BlockID for the block.
460
913k
  Expected<unsigned> ReadSubBlockID() { return ReadVBR(bitc::BlockIDWidth); }
461
462
  /// Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body
463
  /// of this block.
464
137k
  Error SkipBlock() {
465
137k
    // Read and ignore the codelen value.
466
137k
    if (Expected<uint32_t> Res = ReadVBR(bitc::CodeLenWidth))
467
137k
      ; // Since we are skipping this block, we don't care what code widths are
468
18.4E
        // used inside of it.
469
18.4E
    else
470
18.4E
      return Res.takeError();
471
137k
472
137k
    SkipToFourByteBoundary();
473
137k
    Expected<unsigned> MaybeNum = Read(bitc::BlockSizeWidth);
474
137k
    if (!MaybeNum)
475
0
      return MaybeNum.takeError();
476
137k
    size_t NumFourBytes = MaybeNum.get();
477
137k
478
137k
    // Check that the block wasn't partially defined, and that the offset isn't
479
137k
    // bogus.
480
137k
    size_t SkipTo = GetCurrentBitNo() + NumFourBytes * 4 * 8;
481
137k
    if (AtEndOfStream())
482
0
      return createStringError(std::errc::illegal_byte_sequence,
483
0
                               "can't skip block: already at end of stream");
484
137k
    if (!canSkipToPos(SkipTo / 8))
485
12
      return createStringError(std::errc::illegal_byte_sequence,
486
12
                               "can't skip to bit %zu from %" PRIu64, SkipTo,
487
12
                               GetCurrentBitNo());
488
137k
489
137k
    if (Error Res = JumpToBit(SkipTo))
490
0
      return Res;
491
137k
492
137k
    return Error::success();
493
137k
  }
494
495
  /// Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
496
  Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = nullptr);
497
498
1.12M
  bool ReadBlockEnd() {
499
1.12M
    if (BlockScope.empty()) 
return true6
;
500
1.12M
501
1.12M
    // Block tail:
502
1.12M
    //    [END_BLOCK, <align4bytes>]
503
1.12M
    SkipToFourByteBoundary();
504
1.12M
505
1.12M
    popBlockScope();
506
1.12M
    return false;
507
1.12M
  }
508
509
private:
510
1.12M
  void popBlockScope() {
511
1.12M
    CurCodeSize = BlockScope.back().PrevCodeSize;
512
1.12M
513
1.12M
    CurAbbrevs = std::move(BlockScope.back().PrevAbbrevs);
514
1.12M
    BlockScope.pop_back();
515
1.12M
  }
516
517
  //===--------------------------------------------------------------------===//
518
  // Record Processing
519
  //===--------------------------------------------------------------------===//
520
521
public:
522
  /// Return the abbreviation for the specified AbbrevId.
523
17.9M
  const BitCodeAbbrev *getAbbrev(unsigned AbbrevID) {
524
17.9M
    unsigned AbbrevNo = AbbrevID - bitc::FIRST_APPLICATION_ABBREV;
525
17.9M
    if (AbbrevNo >= CurAbbrevs.size())
526
0
      report_fatal_error("Invalid abbrev number");
527
17.9M
    return CurAbbrevs[AbbrevNo].get();
528
17.9M
  }
529
530
  /// Read the current record and discard it, returning the code for the record.
531
  Expected<unsigned> skipRecord(unsigned AbbrevID);
532
533
  Expected<unsigned> readRecord(unsigned AbbrevID,
534
                                SmallVectorImpl<uint64_t> &Vals,
535
                                StringRef *Blob = nullptr);
536
537
  //===--------------------------------------------------------------------===//
538
  // Abbrev Processing
539
  //===--------------------------------------------------------------------===//
540
  Error ReadAbbrevRecord();
541
542
  /// Read and return a block info block from the bitstream. If an error was
543
  /// encountered, return None.
544
  ///
545
  /// \param ReadBlockInfoNames Whether to read block/record name information in
546
  /// the BlockInfo block. Only llvm-bcanalyzer uses this.
547
  Expected<Optional<BitstreamBlockInfo>>
548
  ReadBlockInfoBlock(bool ReadBlockInfoNames = false);
549
550
  /// Set the block info to be used by this BitstreamCursor to interpret
551
  /// abbreviated records.
552
8.73k
  void setBlockInfo(BitstreamBlockInfo *BI) { BlockInfo = BI; }
553
};
554
555
} // end llvm namespace
556
557
#endif // LLVM_BITSTREAM_BITSTREAMREADER_H