================ @@ -688,6 +695,36 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) { return Mode; } +template <typename DeclT> +static clang::Decl *preferDefinitionImpl(clang::Decl *D) { + if (auto *X = dyn_cast<DeclT>(D)) + if (auto *Def = X->getDefinition()) + return Def; + return D; +} + +template <> clang::Decl *preferDefinitionImpl<ObjCMethodDecl>(clang::Decl *D) { + if (const auto *X = dyn_cast<ObjCMethodDecl>(D)) { + for (auto *I : X->redecls()) + if (I->hasBody()) + return I; + } + return D; +} + +static Decl *getDefinitionOrCanonicalDecl(Decl *D) { + assert(D); + D = D->getCanonicalDecl(); + D = preferDefinitionImpl<VarDecl>(D); + D = preferDefinitionImpl<FunctionDecl>(D); + D = preferDefinitionImpl<TagDecl>(D); + D = preferDefinitionImpl<ObjCMethodDecl>(D); + assert(D); + return D; +} + ---------------- steakhal wrote:
```suggestion ``` I don't think this code is used upstream. https://github.com/llvm/llvm-project/pull/131175 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits