Skip to content

Commit 7dbe049

Browse files
committed
[Serialized diagnostics] Use a 5-bit VBR encoding for file IDs.
File IDs have been expressed using a 10-bit fixed field. This limits us to 1023 different files in which we can emit diagnostics, where overflowing would simply crash. With the introduction of macros and their generated source buffers, we're much more likely to overflow. Switch to a 5-bit VBR field, which is slightly smaller for the common case where there are few files involving diagnositcs, and which also allows us to have up to 2^32-1 file IDs.
1 parent 15fe681 commit 7dbe049

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Frontend/SerializedDiagnosticConsumer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void emitRecordID(unsigned ID, const char *Name,
404404
static void
405405
addSourceLocationAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> Abbrev) {
406406
using namespace llvm;
407-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // File ID.
407+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 5)); // File ID.
408408
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Line.
409409
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Column.
410410
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Offset;
@@ -488,7 +488,7 @@ void SerializedDiagnosticConsumer::emitBlockInfoBlock() {
488488
// Emit the abbreviation for RECORD_FILENAME.
489489
Abbrev = std::make_shared<BitCodeAbbrev>();
490490
Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME));
491-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped file ID.
491+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 5)); // Mapped file ID.
492492
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Size.
493493
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modification time.
494494
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
@@ -508,9 +508,9 @@ void SerializedDiagnosticConsumer::emitBlockInfoBlock() {
508508
// Emit the abbreviation for RECORD_SOURCE_FILE_CONTENTS.
509509
Abbrev = std::make_shared<BitCodeAbbrev>();
510510
Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_FILE_CONTENTS));
511-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // File ID.
511+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 5)); // File ID.
512512
addRangeLocationAbbrev(Abbrev);
513-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // File size.
513+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // File size.
514514
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File contents.
515515
Abbrevs.set(RECORD_SOURCE_FILE_CONTENTS,
516516
Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));

0 commit comments

Comments
 (0)