This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add a test that we can access fields of anonymous records.
ClosedPublic

Authored by mboehme on Jun 21 2023, 4:09 AM.

Diff Detail

Event Timeline

mboehme created this revision.Jun 21 2023, 4:09 AM
Herald added a project: Restricted Project. · View Herald Transcript
mboehme requested review of this revision.Jun 21 2023, 4:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 4:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mboehme added a reviewer: ymandel.
sammccall accepted this revision.Jun 21 2023, 4:29 AM
sammccall added inline comments.
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
5464

assert that the result is non-null?

This revision is now accepted and ready to land.Jun 21 2023, 4:29 AM
mboehme marked an inline comment as done.Jun 21 2023, 4:30 AM
mboehme added inline comments.
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
5464

getChild() returns a reference, so the result can't be null. It asserts internally that the child exists, so if the child doesn't exist, we'll get an assertion failure.

mboehme marked an inline comment as done.Jun 21 2023, 4:31 AM
mboehme retitled this revision from BEGIN_PUBLIC [clang][dataflow] Treat fields of anonymous records as being part of their parent. to [clang][dataflow] Treat fields of anonymous records as being part of their parent..Jun 21 2023, 4:33 AM
mboehme edited the summary of this revision. (Show Details)
gribozavr2 accepted this revision.Jun 21 2023, 5:51 AM
gribozavr2 added a subscriber: gribozavr2.
gribozavr2 added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
305 ↗(On Diff #533212)

Could we somehow take advantage of the IndirectFieldDecl instead of recursing ourselves? Seems like that way we would be delegating to Clang the questions of the name injection/lookup.

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
5458

Could we make some stronger assertion to prove that the transfer function works? It seems to me that getChild() by itself does not prove that.

For example, store and load the value and assert that it is the same.

mboehme updated this revision to Diff 534891.Jun 27 2023, 3:03 AM

Undo all of the non-test changes. This patch now only introduces a test that
we can access fields of anonymous structs.

I realized based on gribozavr2's comment that we shouldn't be lumping all fields
of anonymous records into the parent record, as this goes against the grain of
the Clang AST and, for example, requires special-case code in MemberExpr.

Instead, I realized that everything essentially already works -- anonymous
records were already being correctly added as fields of their parent record.
The only thing that needs to be fixed is handling IndirectFieldDecl correctly
when transferring CXXCtorInitializer. This will come in a followup patch.

mboehme marked 2 inline comments as done.Jun 27 2023, 3:05 AM

PTAL

clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
305 ↗(On Diff #533212)

Thanks for pointing this out.

I realized I was really working against the grain of the Clang AST. I've changed this patch so that it merely adds a new test (to demonstrate that we are already representing fields of anonymous records correctly).

The thing that actually needs to be fixed is the handling of CXXCtorInitializer; I'll do this in a followup patch.

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
5458

Good point, done.

mboehme retitled this revision from [clang][dataflow] Treat fields of anonymous records as being part of their parent. to [clang][dataflow] Initialize fields of anonymous records correctly..Jun 27 2023, 3:07 AM
mboehme edited the summary of this revision. (Show Details)
xazax.hun accepted this revision.Jun 27 2023, 9:19 AM
ymandel accepted this revision.Jun 27 2023, 10:05 AM
mboehme retitled this revision from [clang][dataflow] Initialize fields of anonymous records correctly. to [clang][dataflow] Add a test that we can access fields of anonymous records..Jun 28 2023, 1:00 AM
mboehme edited the summary of this revision. (Show Details)
mboehme marked 2 inline comments as done.

Pre-merge failure looks unrelated

This revision was landed with ongoing or failed builds.Jun 28 2023, 2:12 AM
This revision was automatically updated to reflect the committed changes.