[PATCH] D82326: [clangd] Disable printing of Value for tag-types on hover
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 22 12:54:43 PDT 2020
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
This is both confusing and crashy.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82326
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
@@ -696,6 +696,18 @@
HI.Parameters->back().Name = "v";
HI.AccessSpecifier = "public";
}},
+ {// Field type initializer.
+ R"cpp(
+ struct X { int x = 2; };
+ X ^[[x]];
+ )cpp",
+ [](HoverInfo &HI) {
+ HI.Name = "x";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "X x";
+ HI.Type = "struct X";
+ }},
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Code);
@@ -978,13 +990,14 @@
HI.LocalScope = "Foo::";
HI.Type = "int";
HI.Definition = "int x";
- HI.Value = "{1}";
+ // FIXME: Initializer for x is a DesignatedInitListExpr, hence it is
+ // of struct type and omitted.
}},
{
R"cpp(// Field, field designator
- struct Foo { int x; };
+ struct Foo { int x; int y; };
int main() {
- Foo bar = { .^[[x]] = 2 };
+ Foo bar = { .^[[x]] = 2, .y = 2 };
}
)cpp",
[](HoverInfo &HI) {
@@ -994,7 +1007,6 @@
HI.LocalScope = "Foo::";
HI.Type = "int";
HI.Definition = "int x";
- HI.Value = "{2}";
}},
{
R"cpp(// Method call
@@ -1592,7 +1604,6 @@
HI.LocalScope = "test::";
HI.Type = "struct Test &&";
HI.Definition = "Test &&test = {}";
- HI.Value = "{}";
}},
{
R"cpp(// auto on alias
@@ -1651,7 +1662,6 @@
HI.NamespaceScope = "";
HI.Name = "foo";
HI.Type = "cls<cls<cls<int>>>";
- HI.Value = "{}";
}},
{
R"cpp(// type of nested templates.
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -341,7 +341,10 @@
T->isFunctionReferenceType())
return llvm::None;
// Attempt to evaluate. If expr is dependent, evaluation crashes!
- if (E->isValueDependent() || !E->EvaluateAsRValue(Constant, Ctx))
+ if (E->isValueDependent() || !E->EvaluateAsRValue(Constant, Ctx) ||
+ // Disable printing for tag-types, as they are usually confusing and might
+ // make clang crash while printing the expressions.
+ Constant.Val.isStruct() || Constant.Val.isUnion())
return llvm::None;
// Show enums symbolically, not numerically like APValue::printPretty().
@@ -353,7 +356,7 @@
if (ECD->getInitVal() == Val)
return llvm::formatv("{0} ({1})", ECD->getNameAsString(), Val).str();
}
- return Constant.Val.getAsString(Ctx, E->getType());
+ return Constant.Val.getAsString(Ctx, T);
}
llvm::Optional<std::string> printExprValue(const SelectionTree::Node *N,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82326.272522.patch
Type: text/x-patch
Size: 3161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200622/fdaf83fb/attachment.bin>
More information about the cfe-commits
mailing list