35 lines · cpp
1// RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3// RUN: %clangxx_msan -O1 %s -o %t && not %run %t >%t.out 2>&14// RUN: FileCheck %s < %t.out5// RUN: %clangxx_msan -O2 %s -o %t && not %run %t >%t.out 2>&16// RUN: FileCheck %s < %t.out7// RUN: %clangxx_msan -O3 %s -o %t && not %run %t >%t.out 2>&18// RUN: FileCheck %s < %t.out9 10// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && not %run %t >%t.out 2>&111// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out12// RUN: %clangxx_msan -fsanitize-memory-track-origins -O1 %s -o %t && not %run %t >%t.out 2>&113// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out14// RUN: %clangxx_msan -fsanitize-memory-track-origins -O2 %s -o %t && not %run %t >%t.out 2>&115// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out16// RUN: %clangxx_msan -fsanitize-memory-track-origins -O3 %s -o %t && not %run %t >%t.out 2>&117// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out18 19#include <stdlib.h>20int main(int argc, char **argv) {21 int *volatile p = (int *)malloc(sizeof(int));22 *p = 42;23 free(p);24 25 if (*p)26 exit(0);27 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value28 // CHECK: {{#0 0x.* in main .*use-after-free.cpp:}}[[@LINE-3]]29 30 // CHECK-ORIGINS: Uninitialized value was created by a heap deallocation31 // CHECK-ORIGINS: {{#0 0x.* in .*free}}32 // CHECK-ORIGINS: {{#1 0x.* in main .*use-after-free.cpp:}}[[@LINE-9]]33 return 0;34}35