]> granicus.if.org Git - clang/commitdiff
[index] Fix crash when indexing a C++14 PCH/module related to TemplateTemplateParmDec...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 26 Jan 2018 19:26:12 +0000 (19:26 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 26 Jan 2018 19:26:12 +0000 (19:26 +0000)
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

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

lib/Index/IndexDecl.cpp
lib/Serialization/ASTWriter.cpp
test/Index/Core/index-pch.cpp [new file with mode: 0644]

index e14750e046eb9cc7d464a1cb5a4554f032e1da51..f1ef6c0ea21fc1ca47416b51bcf5126ef511107b 100644 (file)
@@ -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) {
index 8d5eda1822ae4a29f5452ca0a3e2957cd8c81c18..d1bfe281e2fb2fdb4b86f3e97283f46a513a4651 100644 (file)
@@ -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/test/Index/Core/index-pch.cpp b/test/Index/Core/index-pch.cpp
new file mode 100644 (file)
index 0000000..8c5a92b
--- /dev/null
@@ -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;