Skip to content

Commit c925c16

Browse files
authored
[clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation (llvm#87427)
For pragma diagnostic mappings, we always write/read `SourceLocation` with offset 0. This is equivalent to just writing a `FileID`, which is exactly what this patch starts doing. Originally reviewed here: https://reviews.llvm.org/D137213
1 parent 3b19cd7 commit c925c16

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace serialization {
4141
/// Version 4 of AST files also requires that the version control branch and
4242
/// revision match exactly, since there is no backward compatibility of
4343
/// AST files at this time.
44-
const unsigned VERSION_MAJOR = 29;
44+
const unsigned VERSION_MAJOR = 30;
4545

4646
/// AST file minor version number supported by this version of
4747
/// Clang.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6622,17 +6622,17 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
66226622
while (NumLocations--) {
66236623
assert(Idx < Record.size() &&
66246624
"Invalid data, missing pragma diagnostic states");
6625-
SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
6626-
auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
6627-
assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
6628-
assert(IDAndOffset.second == 0 && "not a start location for a FileID");
6625+
FileID FID = ReadFileID(F, Record, Idx);
6626+
assert(FID.isValid() && "invalid FileID for transition");
6627+
// FIXME: Remove this once we don't need the side-effects.
6628+
(void)SourceMgr.getSLocEntryOrNull(FID);
66296629
unsigned Transitions = Record[Idx++];
66306630

66316631
// Note that we don't need to set up Parent/ParentOffset here, because
66326632
// we won't be changing the diagnostic state within imported FileIDs
66336633
// (other than perhaps appending to the main source file, which has no
66346634
// parent).
6635-
auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
6635+
auto &F = Diag.DiagStatesByLoc.Files[FID];
66366636
F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
66376637
for (unsigned I = 0; I != Transitions; ++I) {
66386638
unsigned Offset = Record[Idx++];

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,9 +3131,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
31313131
continue;
31323132
++NumLocations;
31333133

3134-
SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0);
3135-
assert(!Loc.isInvalid() && "start loc for valid FileID is invalid");
3136-
AddSourceLocation(Loc, Record);
3134+
AddFileID(FileIDAndFile.first, Record);
31373135

31383136
Record.push_back(FileIDAndFile.second.StateTransitions.size());
31393137
for (auto &StatePoint : FileIDAndFile.second.StateTransitions) {

0 commit comments

Comments
 (0)