This revision was automatically updated to reflect the committed changes. Closed by commit rG4cb1686bfe8e: [clangd] Fix a selection tree crash for unmatched-bracket code. (authored by hokein).
Changed prior to commit: https://reviews.llvm.org/D118322?vs=403516&id=403753#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D118322/new/ https://reviews.llvm.org/D118322 Files: clang-tools-extra/clangd/Selection.cpp clang-tools-extra/clangd/unittests/SelectionTests.cpp Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -523,6 +523,10 @@ auto l = [^[[foo = bar]]] { }; })cpp", "VarDecl"}, + {R"cpp( + /*error-ok*/ + void func() [[{^]])cpp", + "CompoundStmt"}, }; for (const Case &C : Cases) { Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -306,6 +306,14 @@ return SelectionTree::Unselected; } + // The eof token is used as a sentinel. + // In general, source range from an AST node should not claim the eof token, + // but it could occur for unmatched-bracket cases. + // FIXME: fix it in TokenBuffer, expandedTokens(SourceRange) should not + // return the eof token. + if (ExpandedTokens.back().kind() == tok::eof) + ExpandedTokens = ExpandedTokens.drop_back(); + SelectionTree::Selection Result = NoTokens; while (!ExpandedTokens.empty()) { // Take consecutive tokens from the same context together for efficiency.
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -523,6 +523,10 @@ auto l = [^[[foo = bar]]] { }; })cpp", "VarDecl"}, + {R"cpp( + /*error-ok*/ + void func() [[{^]])cpp", + "CompoundStmt"}, }; for (const Case &C : Cases) { Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -306,6 +306,14 @@ return SelectionTree::Unselected; } + // The eof token is used as a sentinel. + // In general, source range from an AST node should not claim the eof token, + // but it could occur for unmatched-bracket cases. + // FIXME: fix it in TokenBuffer, expandedTokens(SourceRange) should not + // return the eof token. + if (ExpandedTokens.back().kind() == tok::eof) + ExpandedTokens = ExpandedTokens.drop_back(); + SelectionTree::Selection Result = NoTokens; while (!ExpandedTokens.empty()) { // Take consecutive tokens from the same context together for efficiency.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits