[PATCH] D71403: [clangd] Fix hover crashing on null types
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 01:48:56 PST 2019
kadircet created this revision.
kadircet added reviewers: sammccall, ilya-biryukov.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.
Fixes https://github.com/clangd/clangd/issues/225
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71403
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
@@ -506,6 +506,24 @@
HI.NamespaceScope = "";
HI.Value = "&\"1234\"[0]";
}},
+ {R"cpp(// Should not crash
+ template <typename T>
+ struct Tmpl {
+ Tmpl(int name);
+ };
+
+ template <typename A>
+ void boom(int name) {
+ new Tmpl<A>([[na^me]]);
+ })cpp",
+ [](HoverInfo &HI) {
+ HI.Name = "name";
+ HI.Definition = "int name";
+ HI.Kind = index::SymbolKind::Parameter;
+ HI.Type = "int";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "boom::";
+ }},
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -242,12 +242,13 @@
// FIXME: handle variadics.
}
-llvm::Optional<std::string> printExprValue(const Expr *E, const ASTContext &Ctx) {
+llvm::Optional<std::string> printExprValue(const Expr *E,
+ const ASTContext &Ctx) {
Expr::EvalResult Constant;
// Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
// to the enclosing call.
QualType T = E->getType();
- if (T->isFunctionType() || T->isFunctionPointerType() ||
+ if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
T->isFunctionReferenceType())
return llvm::None;
// Attempt to evaluate. If expr is dependent, evaluation crashes!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71403.233539.patch
Type: text/x-patch
Size: 1794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191212/34dae67b/attachment.bin>
More information about the cfe-commits
mailing list