r308269 - [Index] Prevent canonical decl becoming nullptr
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 00:20:54 PDT 2017
Author: krasimir
Date: Tue Jul 18 00:20:53 2017
New Revision: 308269
URL: http://llvm.org/viewvc/llvm-project?rev=308269&view=rev
Log:
[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
Added:
cfe/trunk/test/Index/Core/no-templated-canonical-decl.cpp
Modified:
cfe/trunk/lib/Index/IndexingContext.cpp
Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=308269&r1=308268&r2=308269&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Tue Jul 18 00:20:53 2017
@@ -260,8 +260,10 @@ static const Decl *adjustParent(const De
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;
Added: cfe/trunk/test/Index/Core/no-templated-canonical-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/no-templated-canonical-decl.cpp?rev=308269&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/no-templated-canonical-decl.cpp (added)
+++ cfe/trunk/test/Index/Core/no-templated-canonical-decl.cpp Tue Jul 18 00:20:53 2017
@@ -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
More information about the cfe-commits
mailing list