[PATCH] D42588: [index] Fix crash when indexing a C++14 PCH/module related to TemplateTemplateParmDecls of alias templates
This revision was automatically updated to reflect the committed changes. Closed by commit rL323549: [index] Fix crash when indexing a C++14 PCH/module related to… (authored by akirtzidis, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D42588?vs=131620=131629#toc Repository: rL LLVM https://reviews.llvm.org/D42588 Files: cfe/trunk/lib/Index/IndexDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/test/Index/Core/index-pch.cpp Index: cfe/trunk/lib/Serialization/ASTWriter.cpp === --- cfe/trunk/lib/Serialization/ASTWriter.cpp +++ cfe/trunk/lib/Serialization/ASTWriter.cpp @@ -5537,7 +5537,9 @@ 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(D)) + // TemplateTemplateParmDecls that are part of an alias template, should not + // have TU as lexical context. + if (isa(D) || isa(D)) return; SourceManager = Context->getSourceManager(); Index: cfe/trunk/lib/Index/IndexDecl.cpp === --- cfe/trunk/lib/Index/IndexDecl.cpp +++ cfe/trunk/lib/Index/IndexDecl.cpp @@ -664,8 +664,11 @@ 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 @@ } } -return Visit(D->getTemplatedDecl()); +return Visit(Parent); } bool VisitFriendDecl(const FriendDecl *D) { Index: cfe/trunk/test/Index/Core/index-pch.cpp === --- cfe/trunk/test/Index/Core/index-pch.cpp +++ cfe/trunk/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 _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 + using is_detected = typename DETECTOR::value_t; Index: cfe/trunk/lib/Serialization/ASTWriter.cpp === --- cfe/trunk/lib/Serialization/ASTWriter.cpp +++ cfe/trunk/lib/Serialization/ASTWriter.cpp @@ -5537,7 +5537,9 @@ 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(D)) + // TemplateTemplateParmDecls that are part of an alias template, should not + // have TU as lexical context. + if (isa(D) || isa(D)) return; SourceManager = Context->getSourceManager(); Index: cfe/trunk/lib/Index/IndexDecl.cpp === --- cfe/trunk/lib/Index/IndexDecl.cpp +++ cfe/trunk/lib/Index/IndexDecl.cpp @@ -664,8 +664,11 @@ 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 @@ } } -return Visit(D->getTemplatedDecl()); +return Visit(Parent); } bool VisitFriendDecl(const FriendDecl *D) { Index: cfe/trunk/test/Index/Core/index-pch.cpp === --- cfe/trunk/test/Index/Core/index-pch.cpp +++ cfe/trunk/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 _Op, class... _Args> +struct DETECTOR { + using value_t = int; +}; + +struct nonesuch {}; + +//
[PATCH] D42588: [index] Fix crash when indexing a C++14 PCH/module related to TemplateTemplateParmDecls of alias templates
nathawes accepted this revision. nathawes added a comment. This revision is now accepted and ready to land. Looks good to me! Repository: rC Clang https://reviews.llvm.org/D42588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42588: [index] Fix crash when indexing a C++14 PCH/module related to TemplateTemplateParmDecls of alias templates
akyrtzi created this revision. akyrtzi added reviewers: cfe-commits, nathawes. Herald added subscribers: kristof.beyls, aemerson. 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 Repository: rC Clang https://reviews.llvm.org/D42588 Files: lib/Index/IndexDecl.cpp lib/Serialization/ASTWriter.cpp test/Index/Core/index-pch.cpp Index: test/Index/Core/index-pch.cpp === --- /dev/null +++ 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 _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 + using is_detected = typename DETECTOR::value_t; Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -5537,7 +5537,9 @@ 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(D)) + // TemplateTemplateParmDecls that are part of an alias template, should not + // have TU as lexical context. + if (isa(D) || isa(D)) return; SourceManager = Context->getSourceManager(); Index: lib/Index/IndexDecl.cpp === --- lib/Index/IndexDecl.cpp +++ lib/Index/IndexDecl.cpp @@ -664,8 +664,11 @@ 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 @@ } } -return Visit(D->getTemplatedDecl()); +return Visit(Parent); } bool VisitFriendDecl(const FriendDecl *D) { Index: test/Index/Core/index-pch.cpp === --- /dev/null +++ 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 _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 + using is_detected = typename DETECTOR ::value_t; Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -5537,7 +5537,9 @@ 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(D)) + // TemplateTemplateParmDecls that are part of an alias template, should not + // have TU as lexical context. + if (isa(D) || isa(D)) return; SourceManager = Context->getSourceManager(); Index: lib/Index/IndexDecl.cpp === --- lib/Index/IndexDecl.cpp +++ lib/Index/IndexDecl.cpp @@ -664,8 +664,11 @@ 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 =