Skip to content

Commit 1c2d47e

Browse files
committed
[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 (cherry picked from commit c925c16)
1 parent 407ea67 commit 1c2d47e

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
@@ -6604,17 +6604,17 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
66046604
while (NumLocations--) {
66056605
assert(Idx < Record.size() &&
66066606
"Invalid data, missing pragma diagnostic states");
6607-
SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
6608-
auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
6609-
assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
6610-
assert(IDAndOffset.second == 0 && "not a start location for a FileID");
6607+
FileID FID = ReadFileID(F, Record, Idx);
6608+
assert(FID.isValid() && "invalid FileID for transition");
6609+
// FIXME: Remove this once we don't need the side-effects.
6610+
(void)SourceMgr.getSLocEntryOrNull(FID);
66116611
unsigned Transitions = Record[Idx++];
66126612

66136613
// Note that we don't need to set up Parent/ParentOffset here, because
66146614
// we won't be changing the diagnostic state within imported FileIDs
66156615
// (other than perhaps appending to the main source file, which has no
66166616
// parent).
6617-
auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
6617+
auto &F = Diag.DiagStatesByLoc.Files[FID];
66186618
F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
66196619
for (unsigned I = 0; I != Transitions; ++I) {
66206620
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)