This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Avoid calling Block_copy in the "sync" GCD interceptors
ClosedPublic

Authored by kubamracek on Aug 17 2018, 1:39 PM.

Details

Summary

The synchronous dispatch functions in GCD (dispatch_sync, dispatch_barrier_sync), don't make a copy of the passed block. To maintain binary compatibility, we should avoid doing that as well in TSan, as there's no reason to do that. The synchronous dispatch functions will not return before the block is actually executed.

rdar://problem/42242579

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek created this revision.Aug 17 2018, 1:39 PM
Herald added a subscriber: Restricted Project. · View Herald TranscriptAug 17 2018, 1:39 PM
dvyukov accepted this revision.Aug 17 2018, 2:34 PM
This revision is now accepted and ready to land.Aug 17 2018, 2:34 PM

Seems fine but with some minor nits.

test/tsan/Darwin/gcd-sync-block-copy.mm
6 ↗(On Diff #161315)

For the purposes of examining test artifacts after tests have run, it's probably better to give your executables different names (e.g. %t_no_tsan and %t_with_tsan).

16 ↗(On Diff #161315)

I presume you're relying on the copy of the block to increment the reference count to your object? Perhaps add a comment to this effect?

I presume it's guaranteed that the Objective-C runtime won't try to do any tagged pointer optimizations here which would break the assumption that a copy increases the reference count?

delcypher requested changes to this revision.Aug 21 2018, 12:27 PM
This revision now requires changes to proceed.Aug 21 2018, 12:27 PM
This revision was not accepted when it landed; it landed in state Needs Revision.Aug 21 2018, 2:25 PM
This revision was automatically updated to reflect the committed changes.