This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Add checks for self-assignment.
ClosedPublic

Authored by schittir on Jul 19 2023, 8:29 PM.

Diff Detail

Event Timeline

schittir created this revision.Jul 19 2023, 8:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 8:29 PM
schittir requested review of this revision.Jul 19 2023, 8:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 8:29 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
schittir updated this revision to Diff 542333.Jul 20 2023, 12:24 AM

Please consider these changes for review.

schittir planned changes to this revision.Jul 20 2023, 12:25 AM
schittir requested review of this revision.

Hmm, it seems exceptionally unlikely for a move assignment operator to be invoked on an object with itself as the source argument. That would require an explicit use of std::move() as in:

Value x = ...;
x = std::move(x);

Rather than protecting against that and making it a no-opt, I think we would want to be informed of code that manages to do so because it is probably not intended. We could instead assert(this !=RHS), but I'm not sure that is warranted either.

I'm assuming this patch was made in response to a static analysis report. If so, I suggest we follow up with the static analysis vendor.

tahonermann accepted this revision.Jul 21 2023, 11:27 AM

On second thought, and after having read https://stackoverflow.com/a/9322542/11634221, I think this change is fine. There are legitimate scenarios for which self move assignment should work in the sense that the object value is preserved or is left in a valid but unspecified state; UB should be avoided.

This revision is now accepted and ready to land.Jul 21 2023, 11:27 AM
This revision was landed with ongoing or failed builds.Jul 24 2023, 12:39 AM
This revision was automatically updated to reflect the committed changes.

@tahonermann Thank you for considering this thoroughly. This patch is now landed.

jplehr added a subscriber: jplehr.Jul 24 2023, 12:59 AM

Hi,
it seems that this broke the AMDGPU OpenMP buildbot https://lab.llvm.org/buildbot/#/builders/193/builds/35271
Happy to help if you need more info etc.

This doesn't compile, could you fix this or revert 8ac137acefc01caf636db5f95eb0977c97def1ba ?

clang/lib/AST/APValue.cpp
393–399

Ditto for the other changes

This comment was removed by michaelplatings.
schittir updated this revision to Diff 552243.Aug 22 2023, 12:39 AM

Fix errors.

@jplehr @michaelplatings @MitalAshok @tahonermann - sorry this one slipped through the cracks. I fixed the errors now. Thank you for your review.

schittir reopened this revision.Aug 22 2023, 12:42 AM
This revision is now accepted and ready to land.Aug 22 2023, 12:42 AM
tahonermann accepted this revision.Aug 22 2023, 8:06 AM

Thank you for following up, Sindhu! Looks good!

schittir marked an inline comment as done.EditedAug 22 2023, 8:24 AM

Thank you for the review, @aaron.ballman and @tahonermann
Investigating the build failure...
Test failure seems unrelated to this patch's changes.

This revision was landed with ongoing or failed builds.Aug 24 2023, 9:21 AM
This revision was automatically updated to reflect the committed changes.