Skip to content

Commit

Permalink
[clangd] Fix hover crash on broken code
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D101743
  • Loading branch information
kadircet authored and memfrob committed Oct 4, 2022
1 parent 6adefec commit 25f32c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ llvm::Optional<StringRef> setterVariableName(const CXXMethodDecl *CMD) {
if (auto *CE = llvm::dyn_cast<CallExpr>(RHS->IgnoreCasts())) {
if (CE->getNumArgs() != 1)
return llvm::None;
auto *ND = llvm::dyn_cast<NamedDecl>(CE->getCalleeDecl());
auto *ND = llvm::dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl());
if (!ND || !ND->getIdentifier() || ND->getName() != "move" ||
!ND->isInStdNamespace())
return llvm::None;
Expand Down
14 changes: 14 additions & 0 deletions clang-tools-extra/clangd/unittests/HoverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,20 @@ TEST(Hover, DocsFromAST) {
}
}

TEST(Hover, NoCrash) {
Annotations T(R"cpp(
/* error-ok */
template<typename T> T foo(T);
// Setter variable heuristic might fail if the callexpr is broken.
struct X { int Y; void [[^setY]](float) { Y = foo(undefined); } };)cpp");

TestTU TU = TestTU::withCode(T.code());
auto AST = TU.build();
for (const auto &P : T.points())
getHover(AST, P, format::getLLVMStyle(), nullptr);
}

TEST(Hover, DocsFromMostSpecial) {
Annotations T(R"cpp(
// doc1
Expand Down

0 comments on commit 25f32c9

Please sign in to comment.