diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 2c747d8ea844..bad5c379bcbf 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -146,7 +146,7 @@ private: /// the declaration's ID. std::vector DeclOffsets; - /// \brief Vector of pairs of raw location/DeclID. + /// \brief Sorted (by file offset) vector of pairs of file offset/DeclID. typedef SmallVector, 64> LocDeclIDsTy; struct DeclIDInFileInfo { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 0c9f0a1247cd..1b44baa9ce53 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -3501,7 +3501,9 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { SourceManager &SM = Context->getSourceManager(); SourceLocation FileLoc = SM.getFileLoc(Loc); assert(SM.isLocalSourceLocation(FileLoc)); - FileID FID = SM.getFileID(FileLoc); + FileID FID; + unsigned Offset; + llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); if (FID.isInvalid()) return; const SrcMgr::SLocEntry *Entry = &SM.getSLocEntry(FID); @@ -3511,11 +3513,10 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { if (!Info) Info = new DeclIDInFileInfo(); - unsigned RawLoc = FileLoc.getRawEncoding(); - std::pair LocDecl(RawLoc, ID); + std::pair LocDecl(Offset, ID); LocDeclIDsTy &Decls = Info->DeclIDs; - if (Decls.empty() || Decls.back().first <= RawLoc) { + if (Decls.empty() || Decls.back().first <= Offset) { Decls.push_back(LocDecl); return; }