]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/msan/chained_origin.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / msan / chained_origin.cc
CommitLineData
92a42be0 1// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \
1a4d82fc
JJ
2// RUN: not %run %t >%t.out 2>&1
3// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-STACK < %t.out
4
92a42be0 5// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DHEAP=1 -O3 %s -o %t && \
1a4d82fc
JJ
6// RUN: not %run %t >%t.out 2>&1
7// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-HEAP < %t.out
8
92a42be0
SL
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-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
1a4d82fc
JJ
19#include <stdio.h>
20
21volatile int x, y;
22
23__attribute__((noinline))
24void fn_g(int a) {
25 x = a;
26}
27
28__attribute__((noinline))
29void fn_f(int a) {
30 fn_g(a);
31}
32
33__attribute__((noinline))
34void fn_h() {
35 y = x;
36}
37
38int main(int argc, char *argv[]) {
39#ifdef HEAP
40 int * volatile zz = new int;
41 int z = *zz;
42#else
43 int volatile z;
44#endif
45 fn_f(z);
46 fn_h();
47 return y;
48}
49
50// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
92a42be0 51// CHECK: {{#0 .* in main.*chained_origin.cc:47}}
1a4d82fc
JJ
52
53// CHECK: Uninitialized value was stored to memory at
92a42be0
SL
54// CHECK: {{#0 .* in fn_h.*chained_origin.cc:35}}
55// CHECK: {{#1 .* in main.*chained_origin.cc:46}}
1a4d82fc
JJ
56
57// CHECK: Uninitialized value was stored to memory at
92a42be0
SL
58// CHECK: {{#0 .* in fn_g.*chained_origin.cc:25}}
59// CHECK: {{#1 .* in fn_f.*chained_origin.cc:30}}
60// CHECK: {{#2 .* in main.*chained_origin.cc:45}}
1a4d82fc
JJ
61
62// CHECK-STACK: Uninitialized value was created by an allocation of 'z' in the stack frame of function 'main'
92a42be0 63// CHECK-STACK: {{#0 .* in main.*chained_origin.cc:38}}
1a4d82fc
JJ
64
65// CHECK-HEAP: Uninitialized value was created by a heap allocation
92a42be0 66// CHECK-HEAP: {{#1 .* in main.*chained_origin.cc:40}}