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