]> granicus.if.org Git - clang/commitdiff
[Index] Prevent canonical decl becoming nullptr
authorKrasimir Georgiev <krasimir@google.com>
Tue, 18 Jul 2017 07:20:53 +0000 (07:20 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Tue, 18 Jul 2017 07:20:53 +0000 (07:20 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308269 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/IndexingContext.cpp
test/Index/Core/no-templated-canonical-decl.cpp [new file with mode: 0644]

index c4aa51d62f02de7643aa374abaa7a66d04fc3e6f..addee691e80463ce4623e73daa0f4f1924eec6c1 100644 (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;
diff --git a/test/Index/Core/no-templated-canonical-decl.cpp b/test/Index/Core/no-templated-canonical-decl.cpp
new file mode 100644 (file)
index 0000000..5434e9c
--- /dev/null
@@ -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