57 lines · plain
1// Check that ignore_noninstrumented_modules=1 suppresses reporting races from2// system libraries on OS X. There are currently false positives coming from3// libxpc, libdispatch, CoreFoundation and others, because these libraries use4// TSan-invisible atomics as synchronization.5 6// RUN: %clang_tsan %s -o %t -framework Foundation7 8// Check that without the flag, there are false positives.9// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0 %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE10 11// With ignore_noninstrumented_modules=1, no races are reported.12// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s13 14// With ignore_noninstrumented_modules=1, races in user's code are still reported.15// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE16 17#import <Foundation/Foundation.h>18 19#import "../test.h"20 21char global_buf[64];22 23void *Thread1(void *x) {24 barrier_wait(&barrier);25 strcpy(global_buf, "hello world");26 return NULL;27}28 29void *Thread2(void *x) {30 strcpy(global_buf, "world hello");31 barrier_wait(&barrier);32 return NULL;33}34 35int main(int argc, char *argv[]) {36 fprintf(stderr, "Hello world.\n");37 38 // NSUserDefaults uses XPC which triggers the false positive.39 NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];40 fprintf(stderr, "d = %p\n", d);41 42 if (argc > 1 && strcmp(argv[1], "race") == 0) {43 barrier_init(&barrier, 2);44 pthread_t t[2];45 pthread_create(&t[0], NULL, Thread1, NULL);46 pthread_create(&t[1], NULL, Thread2, NULL);47 pthread_join(t[0], NULL);48 pthread_join(t[1], NULL);49 }50 51 fprintf(stderr, "Done.\n");52}53 54// CHECK: Hello world.55// CHECK-RACE: SUMMARY: ThreadSanitizer: data race56// CHECK: Done.57