1 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DOFFSET=0 -O3 %s -o %t && \
2 // RUN:     not %run %t >%t.out 2>&1
3 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z1 --check-prefix=CHECK-%short-stack < %t.out
4 
5 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DOFFSET=10 -O3 %s -o %t && \
6 // RUN:     not %run %t >%t.out 2>&1
7 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z2 --check-prefix=CHECK-%short-stack < %t.out
8 
9 // RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -DOFFSET=0 -O3 %s -o %t && \
10 // RUN:     not %run %t >%t.out 2>&1
11 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z1 --check-prefix=CHECK-%short-stack < %t.out
12 
13 // RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -DOFFSET=10 -O3 %s -o %t && \
14 // RUN:     not %run %t >%t.out 2>&1
15 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z2 --check-prefix=CHECK-%short-stack < %t.out
16 
17 #include <stdio.h>
18 #include <string.h>
19 
20 int xx[10000];
21 volatile int idx = 30;
22 
fn_g(int a,int b)23 __attribute__((noinline)) void fn_g(int a, int b) {
24   xx[idx + OFFSET] = OFFSET == 0 ? a : b;
25 }
26 
fn_f(int a,int b)27 __attribute__((noinline)) void fn_f(int a, int b) {
28   fn_g(a, b);
29 }
30 
fn_h()31 __attribute__((noinline)) void fn_h() {
32   memmove(&xx[25], &xx, 7500);
33 }
34 
main(int argc,char * argv[])35 int main(int argc, char *argv[]) {
36   int volatile z1;
37   int volatile z2;
38   fn_f(z1, z2);
39   fn_h();
40   return xx[25 + idx + OFFSET];
41 }
42 
43 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
44 // CHECK: {{#0 .* in main .*chained_origin_memmove.cpp:}}[[@LINE-4]]
45 
46 // CHECK: Uninitialized value was stored to memory at
47 // CHECK-FULL-STACK: {{#1 .* in fn_h.*chained_origin_memmove.cpp:}}[[@LINE-15]]
48 // CHECK-SHORT-STACK: {{#0 .* in __msan_memmove.*msan_interceptors.cpp:}}
49 
50 // CHECK: Uninitialized value was stored to memory at
51 // CHECK-FULL-STACK: {{#0 .* in fn_g.*chained_origin_memmove.cpp:}}[[@LINE-27]]
52 // CHECK-FULL-STACK: {{#1 .* in fn_f.*chained_origin_memmove.cpp:}}[[@LINE-24]]
53 // CHECK-SHORT-STACK: {{#0 .* in fn_g.*chained_origin_memmove.cpp:}}[[@LINE-29]]
54 
55 // CHECK-Z1: Uninitialized value was created by an allocation of 'z1' in the stack frame of function 'main'
56 // CHECK-Z2: Uninitialized value was created by an allocation of 'z2' in the stack frame of function 'main'
57 // CHECK: {{#0 .* in main.*chained_origin_memmove.cpp:}}[[@LINE-22]]
58