[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
Fri Aug 12 04:43:19 PDT 2022


hokein updated this revision to Diff 452141.
hokein marked an inline comment as done.
hokein added a comment.

address review comment -- make sure we skip the corresponding field when its
init expr is null, and polish the testcase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131696/new/

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,17 @@
   )cpp" /*no designator hints expected (but param hints!)*/);
 }
 
+TEST(DesignatorHints, NoCrash) {
+  assertDesignatorHints(R"cpp(
+    /*error-ok*/
+    struct A {};
+    struct Foo {int a; int b;};
+    void test() {
+      Foo f{A(), $b[[1]]};
+    }
+  )cpp", ExpectedHint{".b=", "b"});
+}
+
 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
@@ -141,7 +141,7 @@
       Fields.next();       // Always advance to the next subobject name.
       Prefix.resize(Size); // Erase any designator we appended.
     });
-    if (llvm::isa<ImplicitValueInitExpr>(Init))
+    if (!Init || llvm::isa<ImplicitValueInitExpr>(Init))
       continue; // a "hole" for a subobject that was not explicitly initialized
 
     const auto *BraceElidedSubobject = llvm::dyn_cast<InitListExpr>(Init);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131696.452141.patch
Type: text/x-patch
Size: 1287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220812/04b5c3d7/attachment.bin>


More information about the cfe-commits mailing list