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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits