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

source code of compiler-rt/test/msan/chained_origin.cpp