Author: akirtzidis
Date: Fri Jan 26 11:26:12 2018
New Revision: 323549

URL: http://llvm.org/viewvc/llvm-project?rev=323549&view=rev
Log:
[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

Added:
    cfe/trunk/test/Index/Core/index-pch.cpp
Modified:
    cfe/trunk/lib/Index/IndexDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=323549&r1=323548&r2=323549&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Fri Jan 26 11:26:12 2018
@@ -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) {

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=323549&r1=323548&r2=323549&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Jan 26 11:26:12 2018
@@ -5537,7 +5537,9 @@ void ASTWriter::associateDeclWithFile(co
     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();

Added: cfe/trunk/test/Index/Core/index-pch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-pch.cpp?rev=323549&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/index-pch.cpp (added)
+++ cfe/trunk/test/Index/Core/index-pch.cpp Fri Jan 26 11:26:12 2018
@@ -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;


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to