This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix an inlay-hint crash on a broken designator.
ClosedPublic

Authored by hokein on Aug 11 2022, 10:27 AM.

Diff Detail

Event Timeline

hokein created this revision.Aug 11 2022, 10:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 10:27 AM
hokein requested review of this revision.Aug 11 2022, 10:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 10:27 AM
kadircet added inline comments.Aug 12 2022, 2:40 AM
clang-tools-extra/clangd/InlayHints.cpp
140

we should have this bail out after introducing the scope_exit below to make sure we skip the field.

clang-tools-extra/clangd/unittests/InlayHintTests.cpp
1427

a better test would be

struct A{};
struct Foo {int a; int b;};
Foo f{A(), 1);

and make sure we still get the hints for 1 as b.

hokein updated this revision to Diff 452141.Aug 12 2022, 4:43 AM
hokein marked an inline comment as done.

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

clang-tools-extra/clangd/InlayHints.cpp
140

good catch! You're right.

kadircet accepted this revision.Aug 12 2022, 5:23 AM
kadircet added inline comments.
clang-tools-extra/clangd/InlayHints.cpp
143–144

nit: can you also update the comment to mention broken initializer (and maybe even a fixme to handle these, as in theory this is likely spelled in the code, but wasn't retained in the AST even as a recoveryexpr, hence we still have a place to attach the hint)

This revision is now accepted and ready to land.Aug 12 2022, 5:23 AM
hokein updated this revision to Diff 452155.Aug 12 2022, 5:36 AM

update the comment.

clang-tools-extra/clangd/InlayHints.cpp
143–144

Done, updated the comment. I'd rather leave out the FIXME (it is unclear that we will address it).

The InitListExpr is tricky, the AST nodes is preserved in the syntactic form for InitListExpr (go-to-definition actually works on the broken initializer A() ), but here we're using the *semantic*-form...

This revision was landed with ongoing or failed builds.Aug 12 2022, 5:38 AM
This revision was automatically updated to reflect the committed changes.