summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-07-18 07:20:53 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-07-18 07:20:53 +0000
commite62dd8b5e985c86e0c766a89cce6162b463c39ea (patch)
tree3dded7dabd64466e752a88d79963469ba4a770cc
parentb78f3b89e171d276d0e05731efdde152585fc240 (diff)
downloadbcm5719-llvm-e62dd8b5e985c86e0c766a89cce6162b463c39ea.tar.gz
bcm5719-llvm-e62dd8b5e985c86e0c766a89cce6162b463c39ea.zip
[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
-rw-r--r--clang/lib/Index/IndexingContext.cpp6
-rw-r--r--clang/test/Index/Core/no-templated-canonical-decl.cpp4
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp
index c4aa51d62f0..addee691e80 100644
--- a/clang/lib/Index/IndexingContext.cpp
+++ b/clang/lib/Index/IndexingContext.cpp
@@ -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/clang/test/Index/Core/no-templated-canonical-decl.cpp b/clang/test/Index/Core/no-templated-canonical-decl.cpp
new file mode 100644
index 00000000000..5434e9cb651
--- /dev/null
+++ b/clang/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@B | <no-cgname> | Def | rel: 0
OpenPOWER on IntegriCloud