Home | History | Annotate | Download | only in msan
      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-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-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-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 
     19 #include <stdio.h>
     20 
     21 volatile int x, y;
     22 
     23 __attribute__((noinline))
     24 void fn_g(int a) {
     25   x = a;
     26 }
     27 
     28 __attribute__((noinline))
     29 void fn_f(int a) {
     30   fn_g(a);
     31 }
     32 
     33 __attribute__((noinline))
     34 void fn_h() {
     35   y = x;
     36 }
     37 
     38 int 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
     51 // CHECK: {{#0 .* in main.*chained_origin.cc:47}}
     52 
     53 // CHECK: Uninitialized value was stored to memory at
     54 // CHECK: {{#0 .* in fn_h.*chained_origin.cc:35}}
     55 // CHECK: {{#1 .* in main.*chained_origin.cc:46}}
     56 
     57 // CHECK: Uninitialized value was stored to memory at
     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}}
     61 
     62 // CHECK-STACK: Uninitialized value was created by an allocation of 'z' in the stack frame of function 'main'
     63 // CHECK-STACK: {{#0 .* in main.*chained_origin.cc:38}}
     64 
     65 // CHECK-HEAP: Uninitialized value was created by a heap allocation
     66 // CHECK-HEAP: {{#1 .* in main.*chained_origin.cc:40}}
     67