56 lines · c
1// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,WITHOUT %s2// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=thread | FileCheck -check-prefixes CHECK,TSAN %s3 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 - with7// __tsan_atomicXXX_load().8//9// CHECK-LABEL: @instrumented110// TSAN: call void @__tsan_func_entry11// WITHOUT-NOT: call void @__tsan_func_entry12// TSAN: call void @__tsan_read413// WITHOUT-NOT: call void @__tsan_read414// TSAN: call i32 @__tsan_atomic32_load15// WITHOUT-NOT: call i32 @__tsan_atomic32_load16// TSAN: call void @__tsan_func_exit17// WITHOUT-NOT: call void @__tsan_func_exit18// CHECK: ret i3219int 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 for25// function entry/exit and atomics, but not plain memory accesses.26//27// CHECK-LABEL: @no_false_positives128// TSAN: call void @__tsan_func_entry29// WITHOUT-NOT: call void @__tsan_func_entry30// TSAN-NOT: call void @__tsan_read431// WITHOUT-NOT: call void @__tsan_read432// TSAN: call i32 @__tsan_atomic32_load33// WITHOUT-NOT: call i32 @__tsan_atomic32_load34// TSAN: call void @__tsan_func_exit35// WITHOUT-NOT: call void @__tsan_func_exit36// CHECK: ret i3237__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_instrumentation144// TSAN-NOT: call void @__tsan_func_entry45// WITHOUT-NOT: call void @__tsan_func_entry46// TSAN-NOT: call void @__tsan_read447// WITHOUT-NOT: call void @__tsan_read448// TSAN-NOT: call i32 @__tsan_atomic32_load49// WITHOUT-NOT: call i32 @__tsan_atomic32_load50// TSAN-NOT: call void @__tsan_func_exit51// WITHOUT-NOT: call void @__tsan_func_exit52// CHECK: ret i3253__attribute__((disable_sanitizer_instrumentation)) int no_instrumentation1(int *a, _Atomic int *b) {54 return *a + *b;55}56