diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -8992,9 +8992,12 @@ SourceRange ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx) { - SourceLocation beg = ReadSourceLocation(F, Record, Idx); - SourceLocation end = ReadSourceLocation(F, Record, Idx); - return SourceRange(beg, end); + SourceLocation::UIntTy Begin = Record[Idx++]; + SourceLocation::UIntTy Delta = Record[Idx++]; + return SourceRange( + TranslateSourceLocation(F, ReadUntranslatedSourceLocation(Begin)), + TranslateSourceLocation(F, + ReadUntranslatedSourceLocation(Begin + Delta))); } /// Read a floating-point value diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -5202,14 +5202,19 @@ Record.push_back(Raw); } -void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { +static SourceLocation::UIntTy encodeForWrite(SourceLocation Loc) { SourceLocation::UIntTy Raw = Loc.getRawEncoding(); - Record.push_back((Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))); + return SourceLocation::UIntTy{(Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))}; +} + +void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { + Record.push_back(encodeForWrite(Loc)); } void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { AddSourceLocation(Range.getBegin(), Record); - AddSourceLocation(Range.getEnd(), Record); + Record.push_back(encodeForWrite(Range.getEnd()) - + encodeForWrite(Range.getBegin())); } void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) {