1 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,WITHOUT %s 2 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=thread | FileCheck -check-prefixes CHECK,TSAN %s 3 4 // Instrumented function. 5 // TSan inserts calls to __tsan_func_entry() and __tsan_func_exit() to prologue/epilogue. 6 // Non-atomic loads are instrumented with __tsan_readXXX(), atomic loads - with 7 // __tsan_atomicXXX_load(). 8 // 9 // CHECK-LABEL: @instrumented1 10 // TSAN: call void @__tsan_func_entry 11 // WITHOUT-NOT: call void @__tsan_func_entry 12 // TSAN: call void @__tsan_read4 13 // WITHOUT-NOT: call void @__tsan_read4 14 // TSAN: call i32 @__tsan_atomic32_load 15 // WITHOUT-NOT: call i32 @__tsan_atomic32_load 16 // TSAN: call void @__tsan_func_exit 17 // WITHOUT-NOT: call void @__tsan_func_exit 18 // CHECK: ret i32 19 int instrumented1(int *a, _Atomic int *b) { 20 return *a + *b; 21 } 22 23 // Function with no_sanitize("thread"). 24 // TSan only inserts instrumentation necessary to prevent false positives: calls are inserted for 25 // function entry/exit and atomics, but not plain memory accesses. 26 // 27 // CHECK-LABEL: @no_false_positives1 28 // TSAN: call void @__tsan_func_entry 29 // WITHOUT-NOT: call void @__tsan_func_entry 30 // TSAN-NOT: call void @__tsan_read4 31 // WITHOUT-NOT: call void @__tsan_read4 32 // TSAN: call i32 @__tsan_atomic32_load 33 // WITHOUT-NOT: call i32 @__tsan_atomic32_load 34 // TSAN: call void @__tsan_func_exit 35 // WITHOUT-NOT: call void @__tsan_func_exit 36 // CHECK: ret i32 37 __attribute__((no_sanitize("thread"))) int no_false_positives1(int *a, _Atomic int *b) { 38 return *a + *b; 39 } 40 41 // Function with disable_sanitizer_instrumentation: no instrumentation at all. 42 // 43 // CHECK-LABEL: @no_instrumentation1 44 // TSAN-NOT: call void @__tsan_func_entry 45 // WITHOUT-NOT: call void @__tsan_func_entry 46 // TSAN-NOT: call void @__tsan_read4 47 // WITHOUT-NOT: call void @__tsan_read4 48 // TSAN-NOT: call i32 @__tsan_atomic32_load 49 // WITHOUT-NOT: call i32 @__tsan_atomic32_load 50 // TSAN-NOT: call void @__tsan_func_exit 51 // WITHOUT-NOT: call void @__tsan_func_exit 52 // CHECK: ret i32 53 __attribute__((disable_sanitizer_instrumentation)) int no_instrumentation1(int *a, _Atomic int *b) { 54 return *a + *b; 55 } 56