[PATCH] D35212: [Index] Prevent canonical decl becoming nullptr

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 13:16:50 PDT 2017


krasimir updated this revision to Diff 106930.
krasimir added a comment.

- Add an Index test case


https://reviews.llvm.org/D35212

Files:
  lib/Index/IndexingContext.cpp
  test/Index/Core/no-templated-canonical-decl.cpp


Index: test/Index/Core/no-templated-canonical-decl.cpp
===================================================================
--- /dev/null
+++ test/Index/Core/no-templated-canonical-decl.cpp
@@ -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 at B | <no-cgname> | Def | rel: 0
Index: lib/Index/IndexingContext.cpp
===================================================================
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -260,8 +260,10 @@
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35212.106930.patch
Type: text/x-patch
Size: 980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170717/174e80e3/attachment.bin>


More information about the cfe-commits mailing list