[clang-tools-extra] 50ba9f9 - [clangd] Fix hover crash on invalid decls
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 3 13:55:41 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-07-03T22:51:04+02:00
New Revision: 50ba9f994c6f9c51692282494c3b40dbc69b4abd
URL: https://github.com/llvm/llvm-project/commit/50ba9f994c6f9c51692282494c3b40dbc69b4abd
DIFF: https://github.com/llvm/llvm-project/commit/50ba9f994c6f9c51692282494c3b40dbc69b4abd.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 616d4c91c0f7..f495052d2d30 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -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;
}
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 4059f8307c4c..3be796a6fb89 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -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);
More information about the cfe-commits
mailing list