[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

llvm-svn: 367687
This commit is contained in:
Ilya Biryukov 2019-08-02 15:23:04 +00:00
parent 809e9d1efa
commit 25082817eb
2 changed files with 11 additions and 1 deletions

View File

@ -715,7 +715,7 @@ static HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
HI.Value.emplace();
llvm::raw_string_ostream ValueOS(*HI.Value);
Result.Val.printPretty(ValueOS, const_cast<ASTContext &>(Ctx),
Var->getType());
Init->getType());
}
}
}

View File

@ -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.