This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Don't crash when creating pointers to members.
ClosedPublic

Authored by mboehme on Jun 28 2023, 4:33 AM.

Details

Summary

The newly added tests crash without the other changes in this patch.

Diff Detail

Event Timeline

mboehme created this revision.Jun 28 2023, 4:33 AM
Herald added a project: Restricted Project. · View Herald Transcript
mboehme requested review of this revision.Jun 28 2023, 4:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 4:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 requested changes to this revision.Jun 28 2023, 4:50 AM
gribozavr2 added a subscriber: gribozavr2.

Using PointerValue to model pointers to data members does not look right to me, because a pointer to data member is an offset within an object that we apply this pointer to, it is not a specific storage location.

I think we either shouldn't be modeling them at all (current implementation) and fix any crashes in the downstream code to allow non-modeled constructs in more places, or we should have a distinct kind of Value for pointers to members.

This revision now requires changes to proceed.Jun 28 2023, 4:50 AM
sammccall accepted this revision.Jun 28 2023, 5:12 AM

Per offline discussion, I think modelling pointer-to-member as PointerValue does make sense, though that's not completely obvious.
Can we document this on PointerValue? (And that it points to a StorageLocation for the decl, which has no value)

clang/lib/Analysis/FlowSensitive/Transfer.cpp
236

I'm a bit confused by this. Why bail out rather than create the storage location?

C::x is going to be part of &C::x, and we're going to create the storagelocation by calling getStorageLocation() on line 456. So why not do it already?

Using PointerValue to model pointers to data members does not look right to me, because a pointer to data member is an offset within an object that we apply this pointer to, it is not a specific storage location.

I think we either shouldn't be modeling them at all (current implementation) and fix any crashes in the downstream code to allow non-modeled constructs in more places, or we should have a distinct kind of Value for pointers to members.

After some offline discussion, I'll proceed by not modeling pointers to members at all for the time being (i.e. not associating them with a Value) but fixing the crashes.

Modeling pointers-to-members as a PointerValue works to the extent that it allows us to compare different pointers-to-members for equality, but where it breaks down is if we want to dereference them (assuming that we know unambiguously what value the pointer-to-member will have). At that point, what we would probably want is some MemberPointerValue that refers to the Decl for the field or member function being referenced.

I'll ping this patch once it's ready to review again.

mboehme marked an inline comment as done.Jun 28 2023, 6:26 AM
mboehme added inline comments.
clang/lib/Analysis/FlowSensitive/Transfer.cpp
236

We can't associate a storage location with *S because it's not a glvalue, and only glvalues are allowed to be associated with storage locations. So we have to defer this work until we get to the & operator.

mboehme updated this revision to Diff 535401.Jun 28 2023, 7:25 AM
mboehme marked an inline comment as done.

Don't produce values for pointers to members. For consistency, also make
the NullToMemberPointer cast not produce any values.

PTAL

clang/lib/Analysis/FlowSensitive/Transfer.cpp
447

While I'm here, streamline the code for the not-pointer-to-member case.

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

Noticed that the parameter here was unused, so I removed it.

gribozavr2 accepted this revision.Jun 28 2023, 8:01 AM
This revision is now accepted and ready to land.Jun 28 2023, 8:01 AM
xazax.hun accepted this revision.Jun 28 2023, 8:46 AM

Pre-merge failure looks unrelated

mboehme retitled this revision from [clang][dataflow] Implement support for pointers to members. to [clang][dataflow] Don't crash when creating pointers to members..Jun 28 2023, 11:42 PM
This revision was landed with ongoing or failed builds.Jun 29 2023, 12:13 AM
This revision was automatically updated to reflect the committed changes.