This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][ObjC] Call synthesized copy constructor/assignment operator functions in getter/setter functions of non-trivial C struct properties
ClosedPublic

Authored by ahatanak on Aug 11 2022, 10:51 AM.

Details

Summary

This fixes a bug where the getter/setter functions were doing a trivial copy instead of calling the synthesized functions that copy non-trivial C struct types.

This fixes https://github.com/llvm/llvm-project/issues/56680.

Diff Detail

Event Timeline

ahatanak created this revision.Aug 11 2022, 10:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 10:51 AM
ahatanak requested review of this revision.Aug 11 2022, 10:51 AM

There is another bug where an object isn't destructed when a non-trivial C struct property is set. I plan to send a patch that fixes the bug after this.

ellis added a subscriber: ellis.Aug 13 2022, 9:51 AM
rjmccall added inline comments.Sep 1 2022, 10:34 AM
clang/lib/CodeGen/CGObjC.cpp
1449

When the method takes the structure by value, we're passed an owned copy with the responsibility to destroy it in the method, right? Is there a way for us to do a destructive move-assignment here and suppress the normal destruction of the parameter?

clang/test/CodeGenObjC/nontrivial-c-struct-property.m
40

Yeah, this is the pattern which it would be great to avoid if we can.

ahatanak added inline comments.Sep 1 2022, 2:54 PM
clang/lib/CodeGen/CGObjC.cpp
1449

We could check whether a function parameter is a setter parameter and avoid pushing the cleanup for it if it is.

If you are thinking about a more general way of merging copy+destruction into a move, I think we need to take a different approach.

ahatanak updated this revision to Diff 457620.Sep 2 2022, 9:49 AM

Call the move assignment operator in the setter instead of calling the copy assignment operator and the destructor.

ahatanak marked an inline comment as done.Sep 2 2022, 9:50 AM

Can we check for the right conditions when emitting the setter body and just deactivate the cleanup?

ahatanak updated this revision to Diff 457720.Sep 2 2022, 3:28 PM

Deactivate the cleanup that was pushed in EmitParmDecl.

This revision is now accepted and ready to land.Oct 13 2022, 9:28 AM
This revision was landed with ongoing or failed builds.Oct 14 2022, 10:41 AM
This revision was automatically updated to reflect the committed changes.