[clang-tools-extra] r367687 - [clangd] Fix a crash when presenting values for Hover
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 08:23:04 PDT 2019
Author: ibiryukov
Date: Fri Aug 2 08:23:04 2019
New Revision: 367687
URL: http://llvm.org/viewvc/llvm-project?rev=367687&view=rev
Log:
[clangd] Fix a crash when presenting values for Hover
Summary:
We should pass the expression type, not a variable type when printing
the resulting value. Variable type may be different from what the
pretty-printing function expects, e.g. have references.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65655
Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=367687&r1=367686&r2=367687&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Aug 2 08:23:04 2019
@@ -715,7 +715,7 @@ static HoverInfo getHoverContents(const
HI.Value.emplace();
llvm::raw_string_ostream ValueOS(*HI.Value);
Result.Val.printPretty(ValueOS, const_cast<ASTContext &>(Ctx),
- Var->getType());
+ Init->getType());
}
}
}
Modified: clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp?rev=367687&r1=367686&r2=367687&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp Fri Aug 2 08:23:04 2019
@@ -1793,6 +1793,16 @@ TEST(Hover, All) {
"int\n"
"]",
},
+ {
+ R"cpp(// Should not crash when evaluating the initializer.
+ struct Test {};
+ void test() { Test && te^st = {}; }
+ )cpp",
+ "text[Declared in]code[test]\n"
+ "codeblock(cpp) [\n"
+ "struct Test &&test = {}\n"
+ "]",
+ },
};
// Create a tiny index, so tests above can verify documentation is fetched.
More information about the cfe-commits
mailing list