[Index] Prevent canonical decl becoming nullptr

Summary:
This patch prevents getCanonicalDecl returning nullptr in case it finds
a canonical TemplateDeclaration with no attached TemplatedDecl.
Found by running the indexer over a version of the standard library deep inside
a template metaprogramming mess.

Reviewers: klimek, vsk

Reviewed By: vsk

Subscribers: vsk, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D35212

llvm-svn: 308269
This commit is contained in:
Krasimir Georgiev 2017-07-18 07:20:53 +00:00
parent b78f3b89e1
commit e62dd8b5e9
2 changed files with 8 additions and 2 deletions

View File

@ -260,8 +260,10 @@ static const Decl *adjustParent(const Decl *Parent) {
static const Decl *getCanonicalDecl(const Decl *D) {
D = D->getCanonicalDecl();
if (auto TD = dyn_cast<TemplateDecl>(D)) {
D = TD->getTemplatedDecl();
assert(D->isCanonicalDecl());
if (auto TTD = TD->getTemplatedDecl()) {
D = TTD;
assert(D->isCanonicalDecl());
}
}
return D;

View File

@ -0,0 +1,4 @@
// RUN: c-index-test core -print-source-symbols -include-locals -- %s | FileCheck %s
template <template <typename> class A> class B { typedef A<int> A_int; };
// CHECK: [[@LINE-1]]:46 | class(Gen)/C++ | B | c:@ST>1#t>1#T@B | <no-cgname> | Def | rel: 0