[PATCH] D83143: [clangd] Fix hover crash on invalid decls
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 3 14:02:58 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50ba9f994c6f: [clangd] Fix hover crash on invalid decls (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83143/new/
https://reviews.llvm.org/D83143
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
@@ -772,6 +772,22 @@
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);
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -672,11 +672,10 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83143.275461.patch
Type: text/x-patch
Size: 1586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200703/27af9174/attachment.bin>
More information about the cfe-commits
mailing list