Index: clang/include/clang/AST/ASTContext.h =================================================================== --- clang/include/clang/AST/ASTContext.h +++ clang/include/clang/AST/ASTContext.h @@ -727,43 +727,12 @@ class RawCommentAndCacheFlags { public: - enum Kind { - /// We searched for a comment attached to the particular declaration, but - /// didn't find any. - /// - /// getRaw() == 0. - NoCommentInDecl = 0, - - /// We have found a comment attached to this particular declaration. - /// - /// getRaw() != 0. - FromDecl, - - /// This declaration does not have an attached comment, and we have - /// searched the redeclaration chain. - /// - /// If getRaw() == 0, the whole redeclaration chain does not have any - /// comments. - /// - /// If getRaw() != 0, it is a comment propagated from other - /// redeclaration. - FromRedecl - }; - - Kind getKind() const LLVM_READONLY { - return Data.getInt(); - } - - void setKind(Kind K) { - Data.setInt(K); - } - const RawComment *getRaw() const LLVM_READONLY { - return Data.getPointer(); + return Comment; } void setRaw(const RawComment *RC) { - Data.setPointer(RC); + Comment = RC; } const Decl *getOriginalDecl() const LLVM_READONLY { @@ -775,11 +744,11 @@ } private: - llvm::PointerIntPair Data; + const RawComment * Comment; const Decl *OriginalDecl; }; - /// Mapping from declarations to comments attached to any + /// Mapping from canonical declarations to comments attached to any /// redeclaration. /// /// Raw comments are owned by Comments list. This mapping is populated Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -369,71 +369,43 @@ const Decl *D, const Decl **OriginalDecl) const { D = adjustDeclToTemplate(D); + const Decl* CanonicalDecl = D->getCanonicalDecl(); // Check whether we have cached a comment for this declaration already. { llvm::DenseMap::iterator Pos = - RedeclComments.find(D); + RedeclComments.find(CanonicalDecl); if (Pos != RedeclComments.end()) { const RawCommentAndCacheFlags &Raw = Pos->second; - if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { - if (OriginalDecl) - *OriginalDecl = Raw.getOriginalDecl(); - return Raw.getRaw(); - } + if (OriginalDecl) + *OriginalDecl = Raw.getOriginalDecl(); + return Raw.getRaw(); } } - // Search for comments attached to declarations in the redeclaration chain. - const RawComment *RC = nullptr; - const Decl *OriginalDeclForRC = nullptr; + // We don't have comment for D in cache - search for any comment attached to + // declarations in the redeclaration chain. for (auto I : D->redecls()) { - llvm::DenseMap::iterator Pos = - RedeclComments.find(I); - if (Pos != RedeclComments.end()) { - const RawCommentAndCacheFlags &Raw = Pos->second; - if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { - RC = Raw.getRaw(); - OriginalDeclForRC = Raw.getOriginalDecl(); - break; - } - } else { - RC = getRawCommentForDeclNoCache(I); - OriginalDeclForRC = I; - RawCommentAndCacheFlags Raw; - if (RC) { - // Call order swapped to work around ICE in VS2015 RTM (Release Win32) - // https://connect.microsoft.com/VisualStudio/feedback/details/1741530 - Raw.setKind(RawCommentAndCacheFlags::FromDecl); - Raw.setRaw(RC); - } else - Raw.setKind(RawCommentAndCacheFlags::NoCommentInDecl); - Raw.setOriginalDecl(I); - RedeclComments[I] = Raw; - if (RC) - break; - } - } - - // If we found a comment, it should be a documentation comment. - assert(!RC || RC->isDocumentation() || LangOpts.CommentOpts.ParseAllComments); + if (const RawComment *RC = getRawCommentForDeclNoCache(I)) { + // If we find a comment, it should be a documentation comment. + assert(RC->isDocumentation() || LangOpts.CommentOpts.ParseAllComments); - if (OriginalDecl) - *OriginalDecl = OriginalDeclForRC; + if (OriginalDecl) + *OriginalDecl = I; - // Update cache for every declaration in the redeclaration chain. - RawCommentAndCacheFlags Raw; - Raw.setRaw(RC); - Raw.setKind(RawCommentAndCacheFlags::FromRedecl); - Raw.setOriginalDecl(OriginalDeclForRC); + RawCommentAndCacheFlags NewCachedComment; + // Call order swapped to work around ICE in VS2015 RTM (Release Win32) + // https://connect.microsoft.com/VisualStudio/feedback/details/1741530 + NewCachedComment.setRaw(RC); + NewCachedComment.setOriginalDecl(I); + RedeclComments[CanonicalDecl] = NewCachedComment; - for (auto I : D->redecls()) { - RawCommentAndCacheFlags &R = RedeclComments[I]; - if (R.getKind() == RawCommentAndCacheFlags::NoCommentInDecl) - R = Raw; + return RC; + } } - return RC; + // We didn't find any comment attached to any redeclaration of D. + return nullptr; } static void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod,