Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSan false positive with dispatch_apply() over an Objective-C NSArray (on macOS) #61262

Open
seanm opened this issue Mar 8, 2023 · 0 comments
Labels
compiler-rt:tsan Thread sanitizer false-positive Warning fires when it should not

Comments

@seanm
Copy link

seanm commented Mar 8, 2023

On macOS 12.x and 13.x on both x86_64 and Arm64 with Xcode this simple code in a toy app:

NSArray* array = @[@1, @2, @3, @4, @5, @6, @7];

dispatch_apply([array count], DISPATCH_APPLY_AUTO, ^(size_t idx) {
	NSNumber* unused = array[idx]; // TSan says race here?!
	(void)unused;
});

Causes a TSan warning:

WARNING: ThreadSanitizer: data race (pid=33556)
  Read of size 8 at 0x00010b863380 by thread T6:
    #0 __45-[AppDelegate applicationDidFinishLaunching:]_block_invoke <null> (TSanTest:arm64+0x100002d4c)
    #1 __wrap_dispatch_apply_block_invoke <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x7db4c)
    #2 _dispatch_client_callout2 <null> (libdispatch.dylib:arm64e+0x6a10)

  Previous write of size 8 at 0x00010b863380 by main thread:
    #0 __copy_helper_block_e8_32s <null> (TSanTest:arm64+0x100002874)
    #1 _call_copy_helpers_excp <null> (libsystem_blocks.dylib:arm64e+0x2120)
    #2 -[AppDelegate applicationDidFinishLaunching:] <null> (TSanTest:arm64+0x100002c9c)
    #3 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ <null> (CoreFoundation:arm64e+0x7655c)
    #4 <null> <null> (0x0001b16b7e50)

  Location is heap block of size 40 at 0x00010b863360 allocated by main thread:
    #0 malloc <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x54e90)
    #1 _Block_copy <null> (libsystem_blocks.dylib:arm64e+0x1b30)
    #2 -[AppDelegate applicationDidFinishLaunching:] <null> (TSanTest:arm64+0x100002c9c)
    #3 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ <null> (CoreFoundation:arm64e+0x7655c)
    #4 <null> <null> (0x0001b16b7e50)

  Thread T6 (tid=1384939, running) is a GCD worker thread

I'm 99% sure there's no bug in my example code above.

I figure this is either:

  1. A TSan false positive, hence this ticket
  2. a macOS bug (I filed FB9995377 too)

(I'd appreciate if anyone knows which.)

@EugeneZelenko EugeneZelenko added compiler-rt:tsan Thread sanitizer false-positive Warning fires when it should not and removed new issue labels Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:tsan Thread sanitizer false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants