[clang-tools-extra] 75b04c7 - [clangd] Fix hover crashing on null types
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 02:41:12 PST 2019
Author: Kadir Cetinkaya
Date: 2019-12-12T11:40:56+01:00
New Revision: 75b04c7af9e7c48e0128a602f2edb17272e3bfaa
URL: https://github.com/llvm/llvm-project/commit/75b04c7af9e7c48e0128a602f2edb17272e3bfaa
DIFF: https://github.com/llvm/llvm-project/commit/75b04c7af9e7c48e0128a602f2edb17272e3bfaa.diff
LOG: [clangd] Fix hover crashing on null types
Summary: Fixes https://github.com/clangd/clangd/issues/225
Reviewers: sammccall, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71403
Added:
Modified:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 5bc15629b05b..d89dc298ed85 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -242,12 +242,13 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
// 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!
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 5862b1d03bf4..3cde2948e369 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -506,6 +506,24 @@ void foo())cpp";
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);
More information about the cfe-commits
mailing list