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