forked from OSchip/llvm-project
[clangd] Fix hover crash on invalid decls
Summary: This also changes the way we display Size and Offset to be independent. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83143
This commit is contained in:
parent
0939e04e41
commit
50ba9f994c
|
@ -672,11 +672,10 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
|
|||
if (Record)
|
||||
Record = Record->getDefinition();
|
||||
if (Record && !Record->isDependentType()) {
|
||||
uint64_t OffsetBits = Ctx.getFieldOffset(FD);
|
||||
if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) {
|
||||
if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
|
||||
HI.Size = Size->getQuantity();
|
||||
HI.Offset = OffsetBits / 8;
|
||||
}
|
||||
if (!FD->isInvalidDecl())
|
||||
HI.Offset = Ctx.getFieldOffset(FD) / 8;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -772,6 +772,22 @@ class Foo {})cpp";
|
|||
HI.CallPassType->PassBy = PassMode::Value;
|
||||
HI.CallPassType->Converted = false;
|
||||
}},
|
||||
{// Dont crash on invalid decl
|
||||
R"cpp(
|
||||
// error-ok
|
||||
struct Foo {
|
||||
Bar [[x^x]];
|
||||
};)cpp",
|
||||
[](HoverInfo &HI) {
|
||||
HI.Name = "xx";
|
||||
HI.Kind = index::SymbolKind::Field;
|
||||
HI.NamespaceScope = "";
|
||||
HI.Definition = "int xx";
|
||||
HI.LocalScope = "Foo::";
|
||||
HI.Size = 4;
|
||||
HI.Type = "int";
|
||||
HI.AccessSpecifier = "public";
|
||||
}},
|
||||
};
|
||||
for (const auto &Case : Cases) {
|
||||
SCOPED_TRACE(Case.Code);
|
||||
|
|
Loading…
Reference in New Issue