Index: cfe/trunk/lib/AST/ASTContext.cpp =================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp +++ cfe/trunk/lib/AST/ASTContext.cpp @@ -99,20 +99,13 @@ }; RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { - if (!CommentsLoaded && ExternalSource) { - ExternalSource->ReadComments(); - -#ifndef NDEBUG - ArrayRef RawComments = Comments.getComments(); - assert(std::is_sorted(RawComments.begin(), RawComments.end(), - BeforeThanCompare(SourceMgr))); -#endif - - CommentsLoaded = true; - } - assert(D); + // If we already tried to load comments but there are none, + // we won't find anything. + if (CommentsLoaded && Comments.getComments().empty()) + return nullptr; + // User can not attach documentation to implicit declarations. if (D->isImplicit()) return nullptr; @@ -162,12 +155,6 @@ isa(D)) return nullptr; - ArrayRef RawComments = Comments.getComments(); - - // If there are no comments anywhere, we won't find anything. - if (RawComments.empty()) - return nullptr; - // Find declaration location. // For Objective-C declarations we generally don't expect to have multiple // declarators, thus use declaration starting location as the "declaration @@ -206,6 +193,23 @@ if (DeclLoc.isInvalid() || !DeclLoc.isFileID()) return nullptr; + if (!CommentsLoaded && ExternalSource) { + ExternalSource->ReadComments(); + +#ifndef NDEBUG + ArrayRef RawComments = Comments.getComments(); + assert(std::is_sorted(RawComments.begin(), RawComments.end(), + BeforeThanCompare(SourceMgr))); +#endif + + CommentsLoaded = true; + } + + ArrayRef RawComments = Comments.getComments(); + // If there are no comments anywhere, we won't find anything. + if (RawComments.empty()) + return nullptr; + // Find the comment that occurs just after this declaration. ArrayRef::iterator Comment; {