From: Argyrios Kyrtzidis Date: Tue, 9 Oct 2012 01:23:45 +0000 (+0000) Subject: When storing the C++ overridden methods, store them once for the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38eb1e161f602ee810dfb8a5a0d8462572f22689;p=clang When storing the C++ overridden methods, store them once for the canonical method; avoid storing them again for an out-of-line definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165472 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 83f3f9ca11..94bb9a9259 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -993,7 +993,7 @@ bool ASTContext::BitfieldFollowsNonBitfield(const FieldDecl *FD, ASTContext::overridden_cxx_method_iterator ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { llvm::DenseMap::const_iterator Pos - = OverriddenMethods.find(Method); + = OverriddenMethods.find(Method->getCanonicalDecl()); if (Pos == OverriddenMethods.end()) return 0; @@ -1003,7 +1003,7 @@ ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { ASTContext::overridden_cxx_method_iterator ASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { llvm::DenseMap::const_iterator Pos - = OverriddenMethods.find(Method); + = OverriddenMethods.find(Method->getCanonicalDecl()); if (Pos == OverriddenMethods.end()) return 0; @@ -1013,7 +1013,7 @@ ASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { unsigned ASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { llvm::DenseMap::const_iterator Pos - = OverriddenMethods.find(Method); + = OverriddenMethods.find(Method->getCanonicalDecl()); if (Pos == OverriddenMethods.end()) return 0; @@ -1022,6 +1022,7 @@ ASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { void ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden) { + assert(Method->isCanonicalDecl() && Overridden->isCanonicalDecl()); OverriddenMethods[Method].push_back(Overridden); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 09792285bc..aec5f01a91 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6038,7 +6038,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, // Find any virtual functions that this function overrides. if (CXXMethodDecl *Method = dyn_cast(NewFD)) { if (!Method->isFunctionTemplateSpecialization() && - !Method->getDescribedFunctionTemplate()) { + !Method->getDescribedFunctionTemplate() && + Method->isCanonicalDecl()) { if (AddOverriddenMethods(Method->getParent(), Method)) { // If the function was marked as "static", we have a problem. if (NewFD->getStorageClass() == SC_Static) { diff --git a/test/Index/overrides.cpp b/test/Index/overrides.cpp index 698b2566bb..a711d82bea 100644 --- a/test/Index/overrides.cpp +++ b/test/Index/overrides.cpp @@ -15,6 +15,9 @@ struct D : C { virtual void f(int); }; +void C::g() {} + // RUN: c-index-test -test-load-source local %s | FileCheck %s // CHECK: overrides.cpp:11:16: CXXMethod=g:11:16 (virtual) [Overrides @7:16] Extent=[11:3 - 11:19] // CHECK: overrides.cpp:15:16: CXXMethod=f:15:16 (virtual) [Overrides @2:16, @6:16] Extent=[15:3 - 15:22] +// CHECK: overrides.cpp:18:9: CXXMethod=g:18:9 (Definition) (virtual) [Overrides @7:16] Extent=[18:1 - 18:15]