Index: lib/tsan/rtl/tsan_interceptors_mac.cc =================================================================== --- lib/tsan/rtl/tsan_interceptors_mac.cc +++ lib/tsan/rtl/tsan_interceptors_mac.cc @@ -19,6 +19,7 @@ #include "tsan_interceptors.h" #include "tsan_interface.h" #include "tsan_interface_ann.h" +#include "sanitizer_common/sanitizer_addrhashmap.h" #include #include @@ -303,13 +304,18 @@ } // Return an address on which we can synchronize (Acquire and Release) for a -// Obj-C tagged pointer (which is not a valid pointer). Ideally should be a -// derived address from 'obj', but for now just return the same global address. -// TODO(kubamracek): Return different address for different pointers. +// Obj-C tagged pointer (which is not a valid pointer). We allocate some memory +// to obtain a stable address (the backing array in the hash map could change). +// The memory is never free'd and allocation and locking is slow, but this code +// only runs for @synchronized with tagged pointers, which should be very rare. static uptr SyncAddressForTaggedPointer(void *obj) { - (void)obj; - static u64 addr; - return (uptr)&addr; + typedef AddrHashMap Map; + static Map Addresses; + Map::Handle h(&Addresses, (uptr) obj); + if (h.created()) { + *h = (uptr) InternalAlloc(/*size=*/1); + } + return *h; } // Address on which we can synchronize for an Objective-C object. Supports Index: test/tsan/Darwin/objc-synchronize-cycle-tagged.mm =================================================================== --- test/tsan/Darwin/objc-synchronize-cycle-tagged.mm +++ test/tsan/Darwin/objc-synchronize-cycle-tagged.mm @@ -1,7 +1,6 @@ // RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support // RUN: %run %t 6 2>&1 | FileCheck %s --check-prefix=SIX // RUN: not %run %t 7 2>&1 | FileCheck %s --check-prefix=SEVEN -// XFAIL: * #import @@ -12,7 +11,7 @@ int main(int argc, char* argv[]) { assert(argc == 2); - int arg = atoi(argv[0]); + int arg = atoi(argv[1]); @autoreleasepool { NSObject* obj = [NSObject new];