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