[PATCH] D131696: [clangd] Fix an inlay-hint crash on a broken designator.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 11 10:27:27 PDT 2022
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131696
Files:
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1417,6 +1417,19 @@
)cpp" /*no designator hints expected (but param hints!)*/);
}
+TEST(DesignatorHints, NoCrash) {
+ assertDesignatorHints(R"cpp(
+ /*error-ok*/
+ class A {};
+ struct Foo { int b; };
+ Foo foo() {
+ return {
+ .b = A(),
+ };
+ }
+ )cpp" /*no crash*/);
+}
+
TEST(InlayHints, RestrictRange) {
Annotations Code(R"cpp(
auto a = false;
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -137,6 +137,8 @@
if (!Fields)
return;
for (const Expr *Init : Sem->inits()) {
+ if (!Init)
+ continue;
auto Next = llvm::make_scope_exit([&, Size(Prefix.size())] {
Fields.next(); // Always advance to the next subobject name.
Prefix.resize(Size); // Erase any designator we appended.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131696.451903.patch
Type: text/x-patch
Size: 1179 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220811/9a072f34/attachment.bin>
More information about the cfe-commits
mailing list