brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · b98bc3d Raw
59 lines · cpp
1// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \2// RUN:     not %run %t >%t.out 2>&13// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%short-stack --check-prefix=CHECK-STACK < %t.out4 5// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DHEAP=1 -O3 %s -o %t && \6// RUN:     not %run %t >%t.out 2>&17// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%short-stack --check-prefix=CHECK-HEAP < %t.out8 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>&112// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%short-stack --check-prefix=CHECK-STACK < %t.out13 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>&116// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-HEAP < %t.out17 18#include <stdio.h>19 20volatile int x, y;21 22__attribute__((noinline)) void fn_g(int &a) { x = a; }23 24__attribute__((noinline)) void fn_f(int &a) { fn_g(a); }25 26__attribute__((noinline)) void fn_h() { y = x; }27 28int main(int argc, char *argv[]) {29#ifdef HEAP30  int * volatile zz = new int;31  int z = *zz;32#else33  int volatile z;34#endif35  fn_f((int &)z);36  fn_h();37  return y;38}39 40// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value41// CHECK: {{#0 .* in main.*chained_origin.cpp:}}[[@LINE-4]]42 43// CHECK: Uninitialized value was stored to memory at44// CHECK-FULL-STACK: {{#0 .* in fn_h.*chained_origin.cpp:}}[[@LINE-18]]45// CHECK-FULL-STACK: {{#1 .* in main.*chained_origin.cpp:}}[[@LINE-9]]46// CHECK-SHORT-STACK: {{#0 .* in fn_h.*chained_origin.cpp:}}[[@LINE-21]]47 48// CHECK: Uninitialized value was stored to memory at49// CHECK-FULL-STACK: {{#0 .* in fn_g.*chained_origin.cpp:}}[[@LINE-27]]50// CHECK-FULL-STACK: {{#1 .* in fn_f.*chained_origin.cpp:}}[[@LINE-26]]51// CHECK-FULL-STACK: {{#2 .* in main.*chained_origin.cpp:}}[[@LINE-16]]52// CHECK-SHORT-STACK: {{#0 .* in fn_g.*chained_origin.cpp:}}[[@LINE-37]]53 54// CHECK-STACK: Uninitialized value was created by an allocation of 'z' in the stack frame55// CHECK-STACK: {{#0 .* in main.*chained_origin.cpp:}}[[@LINE-22]]56 57// CHECK-HEAP: Uninitialized value was created by a heap allocation58// CHECK-HEAP: {{#1 .* in main.*chained_origin.cpp:}}[[@LINE-28]]59