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=memory | FileCheck -check-prefixes CHECK,MSAN %s
3 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=kernel-memory | FileCheck -check-prefixes CHECK,KMSAN %s
4 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=memory -fno-sanitize-memory-param-retval | FileCheck -check-prefixes CHECK,MSAN,RETTLS %s
6 // Instrumented function.
7 // MSan uses memset(addr, -1, size) to poison allocas and stores shadow of the return value in
8 // __msan_retval_tls. KMSAN uses __msan_poison_alloca() to poison allocas and calls
9 // __msan_get_context_state() at function prologue to access the task context struct (including the
10 // shadow of the return value).
12 // CHECK-LABEL: i32 @instrumented1
13 // KMSAN: __msan_get_context_state
14 // WITHOUT-NOT: __msan_poison_alloca
15 // WITHOUT-NOT: @llvm.memset
16 // MSAN: @llvm.memset{{.*}}({{.*}}, i8 -1
17 // KMSAN: __msan_poison_alloca
18 // WITHOUT-NOT: __msan_retval_tls
19 // RETTLS: __msan_retval_tls
21 int instrumented1(int *a
) {
26 // Function with no_sanitize("memory")/no_sanitize("kernel-memory"): no shadow propagation, but
27 // unpoisons memory to prevent false positives.
28 // MSan uses memset(addr, 0, size) to unpoison locals, KMSAN uses __msan_unpoison_alloca(). Both
29 // tools still access the retval shadow to write 0 to it.
31 // CHECK-LABEL: i32 @no_false_positives1
32 // KMSAN: __msan_get_context_state
33 // WITHOUT-NOT: __msan_unpoison_alloca
34 // WITHOUT-NOT: @llvm.memset
35 // MSAN: @llvm.memset{{.*}}({{.*}}, i8 0
36 // KMSAN: __msan_unpoison_alloca
37 // WITHOUT-NOT: __msan_retval_tls
38 // RETTLS: __msan_retval_tls
40 __attribute__((no_sanitize("memory"))) __attribute__((no_sanitize("kernel-memory"))) int no_false_positives1(int *a
) {
45 // Function with disable_sanitizer_instrumentation: no instrumentation at all.
47 // CHECK-LABEL: i32 @no_instrumentation1
48 // KMSAN-NOT: __msan_get_context_state
49 // WITHOUT-NOT: __msan_poison_alloca
50 // WITHOUT-NOT: @llvm.memset
51 // MSAN-NOT: @llvm.memset{{.*}}({{.*}}, i8 0
52 // KMSAN-NOT: __msan_unpoison_alloca
53 // WITHOUT-NOT: __msan_retval_tls
54 // MSAN-NOT: __msan_retval_tls
56 __attribute__((disable_sanitizer_instrumentation
)) int no_instrumentation1(int *a
) {