diff options
author | Haojian Wu <hokein@google.com> | 2019-02-07 16:00:44 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2019-02-07 16:00:44 +0000 |
commit | ddd64a4f50bd9afbf15cefb9497d49ebc544dce8 (patch) | |
tree | 86bdb9ca796a1dc5f688ad462da3da8b918c2355 | |
parent | a5d19759b21067d2ae4b51497de966cccf374dd5 (diff) | |
download | bcm5719-llvm-ddd64a4f50bd9afbf15cefb9497d49ebc544dce8.tar.gz bcm5719-llvm-ddd64a4f50bd9afbf15cefb9497d49ebc544dce8.zip |
[clangd] Fix an assertion failure in Selection.
Summary:
The assertion is triggered when the Decl is null.
Details for the assertion:
F0207 09:55:09.069385 47308 logging.cc:84] assert.h assertion failed at llvm/include/llvm/Support/Casting.h:105 in static bool llvm::isa_impl_cl<clang::TranslationUnitDecl, const clang:: Decl *>::doit(const From *) [To = clang::TranslationUnitDecl, From = const clang::Decl *]: Val && "isa<> used on a null pointer"
15 *** Check failure stack trace: ***
19 @ 0x55615c1f7e06 __assert_fail
20 @ 0x55615a6297d8 clang::clangd::(anonymous namespace)::SelectionVisitor::TraverseDecl()
21 @ 0x55615a62f48d clang::RecursiveASTVisitor<>::TraverseTemplateTemplateParmDecl()
22 @ 0x55615a62b264 clang::RecursiveASTVisitor<>::TraverseDecl()
23 @ 0x55615a62979c clang::clangd::(anonymous namespace)::SelectionVisitor::TraverseDecl()
24 @ 0x55615a63060c clang::RecursiveASTVisitor<>::TraverseClassTemplatePartialSpecializationDecl()
25 @ 0x55615a62ae45 clang::RecursiveASTVisitor<>::TraverseDecl()
Reviewers: sammccall
Subscribers: javed.absar, kristof.beyls, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D57879
llvm-svn: 353421
-rw-r--r-- | clang-tools-extra/clangd/Selection.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/SelectionTests.cpp | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp index 2c2fd476072..d1ea30e7ede 100644 --- a/clang-tools-extra/clangd/Selection.cpp +++ b/clang-tools-extra/clangd/Selection.cpp @@ -51,7 +51,7 @@ public: // - those that can't be stored in DynTypedNode. // We're missing some interesting things like Attr due to the latter. bool TraverseDecl(Decl *X) { - if (isa<TranslationUnitDecl>(X)) + if (X && isa<TranslationUnitDecl>(X)) return Base::TraverseDecl(X); // Already pushed by constructor. return traverseNode(X, [&] { return Base::TraverseDecl(X); }); } diff --git a/clang-tools-extra/unittests/clangd/SelectionTests.cpp b/clang-tools-extra/unittests/clangd/SelectionTests.cpp index 88406b6331e..2322a0e6a54 100644 --- a/clang-tools-extra/unittests/clangd/SelectionTests.cpp +++ b/clang-tools-extra/unittests/clangd/SelectionTests.cpp @@ -176,6 +176,16 @@ TEST(SelectionTest, CommonAncestor) { // Node types that have caused problems in the past. {"template <typename T> void foo() { [[^T]] t; }", "TypeLoc"}, + + // No crash + { + R"cpp( + template <class T> struct Foo {}; + template <[[template<class> class /*cursor here*/^U]]> + struct Foo<U<int>*> {}; + )cpp", + "TemplateTemplateParmDecl" + }, }; for (const Case &C : Cases) { Annotations Test(C.Code); |