[PATCH] D101743: [clangd] Fix hover crash on broken code
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 4 01:56:17 PDT 2021
kadircet updated this revision to Diff 342671.
kadircet added a comment.
- s/x/undefined
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101743/new/
https://reviews.llvm.org/D101743
Files:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2438,6 +2438,20 @@
}
}
+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
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -505,7 +505,7 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101743.342671.patch
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210504/9fd25a3d/attachment-0001.bin>
More information about the cfe-commits
mailing list