From: Argyrios Kyrtzidis Date: Fri, 28 Oct 2011 23:57:43 +0000 (+0000) Subject: [PCH] In ASTWriter::associateDeclWithFile don't bother finding the file loc X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19645d2ae928580b62f9feff91c5aa5e19f5f20d;p=clang [PCH] In ASTWriter::associateDeclWithFile don't bother finding the file loc if we are not interested in the decl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143255 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 52c80d1248..2c747d8ea8 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -162,8 +162,7 @@ private: /// that it contains. FileDeclIDsTy FileDeclIDs; - void associateDeclWithFile(const Decl *D, serialization::DeclID, - SourceLocation FileLoc); + void associateDeclWithFile(const Decl *D, serialization::DeclID); /// \brief The first ID number we can use for our own types. serialization::TypeID FirstTypeID; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 749c27b1aa..0c9f0a1247 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3486,17 +3486,20 @@ static inline bool compLocDecl(std::pair L, return L.first < R.first; } -void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID, - SourceLocation FileLoc) { +void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { assert(ID); - assert(FileLoc.isValid()); - assert(FileLoc.isFileID()); + assert(D); + + SourceLocation Loc = D->getLocation(); + if (Loc.isInvalid()) + return; // We only keep track of the file-level declarations of each file. if (!D->getLexicalDeclContext()->isFileContext()) return; SourceManager &SM = Context->getSourceManager(); + SourceLocation FileLoc = SM.getFileLoc(Loc); assert(SM.isLocalSourceLocation(FileLoc)); FileID FID = SM.getFileID(FileLoc); if (FID.isInvalid()) diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 1b95e927f9..3e3e28dfbb 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -1662,10 +1662,8 @@ void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { } SourceManager &SM = Context.getSourceManager(); - if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) { - SourceLocation FileLoc = SM.getFileLoc(Loc); - associateDeclWithFile(D, ID, FileLoc); - } + if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) + associateDeclWithFile(D, ID); } // Build and emit a record for this declaration