summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2018-01-26 19:26:12 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2018-01-26 19:26:12 +0000
commit71b74ebb1e3732e3e40fe288ef864de91febc6ed (patch)
tree68a9f61bdc697265e6abfeb5b2e605b3029595ff
parent1a1edbfb048e83091bf6352e2be380d90976ed9b (diff)
downloadbcm5719-llvm-71b74ebb1e3732e3e40fe288ef864de91febc6ed.tar.gz
bcm5719-llvm-71b74ebb1e3732e3e40fe288ef864de91febc6ed.zip
[index] Fix crash when indexing a C++14 PCH/module related to TemplateTemplateParmDecls of alias templates
TemplateTemplateParmDecls of alias templates ended-up serialized as 'file-level decls' which was causing a crash while trying to index a PCH/module file that contained them. Commit makes sure TemplateTemplateParmDecls are not recorded as such kind of decls. Fixes crash of rdar://36608297 Differential Revision: https://reviews.llvm.org/D42588 llvm-svn: 323549
-rw-r--r--clang/lib/Index/IndexDecl.cpp7
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp4
-rw-r--r--clang/test/Index/Core/index-pch.cpp17
3 files changed, 25 insertions, 3 deletions
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp
index e14750e046e..f1ef6c0ea21 100644
--- a/clang/lib/Index/IndexDecl.cpp
+++ b/clang/lib/Index/IndexDecl.cpp
@@ -664,8 +664,11 @@ public:
bool VisitTemplateDecl(const TemplateDecl *D) {
- // Index the default values for the template parameters.
const NamedDecl *Parent = D->getTemplatedDecl();
+ if (!Parent)
+ return true;
+
+ // Index the default values for the template parameters.
if (D->getTemplateParameters() &&
shouldIndexTemplateParameterDefaultValue(Parent)) {
const TemplateParameterList *Params = D->getTemplateParameters();
@@ -684,7 +687,7 @@ public:
}
}
- return Visit(D->getTemplatedDecl());
+ return Visit(Parent);
}
bool VisitFriendDecl(const FriendDecl *D) {
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 8d5eda1822a..d1bfe281e2f 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5537,7 +5537,9 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
return;
// FIXME: ParmVarDecls that are part of a function type of a parameter of
// a function/objc method, should not have TU as lexical context.
- if (isa<ParmVarDecl>(D))
+ // TemplateTemplateParmDecls that are part of an alias template, should not
+ // have TU as lexical context.
+ if (isa<ParmVarDecl>(D) || isa<TemplateTemplateParmDecl>(D))
return;
SourceManager &SM = Context->getSourceManager();
diff --git a/clang/test/Index/Core/index-pch.cpp b/clang/test/Index/Core/index-pch.cpp
new file mode 100644
index 00000000000..8c5a92b612c
--- /dev/null
+++ b/clang/test/Index/Core/index-pch.cpp
@@ -0,0 +1,17 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 | FileCheck %s
+// RUN: %clang_cc1 -emit-pch %s -std=c++14 -o %t.pch
+// RUN: c-index-test core -print-source-symbols -module-file %t.pch | FileCheck %s
+
+// CHECK: [[@LINE+2]]:8 | struct(Gen)/C++ | DETECTOR | [[DETECTOR_USR:.*]] | {{.*}} | Def | rel: 0
+template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args>
+struct DETECTOR {
+ using value_t = int;
+};
+
+struct nonesuch {};
+
+// CHECK: [[@LINE+4]]:9 | type-alias/C++ | is_detected
+// CHECK: [[@LINE+3]]:32 | struct(Gen)/C++ | DETECTOR | [[DETECTOR_USR]] | {{.*}} | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | is_detected
+template <template<class...> class _Op, class... _Args>
+ using is_detected = typename DETECTOR<nonesuch, void, _Op, _Args...>::value_t;
OpenPOWER on IntegriCloud