Author: ibiryukov Date: Wed Feb 20 11:26:39 2019 New Revision: 354507 URL: http://llvm.org/viewvc/llvm-project?rev=354507&view=rev Log: [clangd] Fix a crash in Selection
Summary: The assertion checking that a range of a node is a token range does not hold in case of "split" tokens, e.g. between two closing template argument lists (`vector<vector<int>>`). Reviewers: kadircet, sammccall Reviewed By: kadircet Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58447 Modified: clang-tools-extra/trunk/clangd/Selection.cpp clang-tools-extra/trunk/unittests/clangd/SelectionTests.cpp Modified: clang-tools-extra/trunk/clangd/Selection.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=354507&r1=354506&r2=354507&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Selection.cpp (original) +++ clang-tools-extra/trunk/clangd/Selection.cpp Wed Feb 20 11:26:39 2019 @@ -198,11 +198,10 @@ private: auto E = SM.getDecomposedLoc(R.getEnd()); if (B.first != SelFile || E.first != SelFile) continue; - assert(R.isTokenRange()); // Try to cover up to the next token, spaces between children don't count. if (auto Tok = Lexer::findNextToken(R.getEnd(), SM, LangOpts)) E.second = SM.getFileOffset(Tok->getLocation()); - else + else if (R.isTokenRange()) E.second += Lexer::MeasureTokenLength(R.getEnd(), SM, LangOpts); ChildRanges.push_back({B.second, E.second}); } Modified: clang-tools-extra/trunk/unittests/clangd/SelectionTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SelectionTests.cpp?rev=354507&r1=354506&r2=354507&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SelectionTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SelectionTests.cpp Wed Feb 20 11:26:39 2019 @@ -232,6 +232,11 @@ TEST(SelectionTest, Selected) { }]]]] } )cpp", + R"cpp( + template <class T> + struct unique_ptr {}; + void foo(^$C[[unique_ptr<unique_ptr<$C[[int]]>>]]^ a) {} + )cpp", }; for (const char *C : Cases) { Annotations Test(C); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits