1*7c3d14c8STreehugger Robot // Test that on the second entry to a function the origins are still right.
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&1
4*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out
5*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O1 %s -o %t && not %run %t >%t.out 2>&1
6*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out
7*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O2 %s -o %t && not %run %t >%t.out 2>&1
8*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out
9*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O3 %s -o %t && not %run %t >%t.out 2>&1
10*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out
11*7c3d14c8STreehugger Robot
12*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && not %run %t >%t.out 2>&1
13*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
14*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins -O1 %s -o %t && not %run %t >%t.out 2>&1
15*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
16*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins -O2 %s -o %t && not %run %t >%t.out 2>&1
17*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
18*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins -O3 %s -o %t && not %run %t >%t.out 2>&1
19*7c3d14c8STreehugger Robot // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
20*7c3d14c8STreehugger Robot
21*7c3d14c8STreehugger Robot #include <stdlib.h>
22*7c3d14c8STreehugger Robot
23*7c3d14c8STreehugger Robot extern "C"
f(int depth)24*7c3d14c8STreehugger Robot int f(int depth) {
25*7c3d14c8STreehugger Robot if (depth) return f(depth - 1);
26*7c3d14c8STreehugger Robot
27*7c3d14c8STreehugger Robot int x;
28*7c3d14c8STreehugger Robot int *volatile p = &x;
29*7c3d14c8STreehugger Robot return *p;
30*7c3d14c8STreehugger Robot }
31*7c3d14c8STreehugger Robot
main(int argc,char ** argv)32*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
33*7c3d14c8STreehugger Robot return f(1);
34*7c3d14c8STreehugger Robot // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
35*7c3d14c8STreehugger Robot // CHECK: {{#0 0x.* in main .*stack-origin2.cc:}}[[@LINE-2]]
36*7c3d14c8STreehugger Robot
37*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'f'
38*7c3d14c8STreehugger Robot // CHECK-ORIGINS: {{#0 0x.* in f .*stack-origin2.cc:}}[[@LINE-14]]
39*7c3d14c8STreehugger Robot
40*7c3d14c8STreehugger Robot // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*stack-origin2.cc:.* main}}
41*7c3d14c8STreehugger Robot }
42