[asan] Revert r201402, r201404.
[blocksruntime.git] / lib / msan / lit_tests / use-after-free.cc
blobac47c0233a10fb064f0641d0fcc33221029542b7
1 // RUN: %clangxx_msan -m64 -O0 %s -o %t && not %t >%t.out 2>&1
2 // RUN: FileCheck %s < %t.out
3 // RUN: %clangxx_msan -m64 -O1 %s -o %t && not %t >%t.out 2>&1
4 // RUN: FileCheck %s < %t.out
5 // RUN: %clangxx_msan -m64 -O2 %s -o %t && not %t >%t.out 2>&1
6 // RUN: FileCheck %s < %t.out
7 // RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1
8 // RUN: FileCheck %s < %t.out
10 // RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %t >%t.out 2>&1
11 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
12 // RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O1 %s -o %t && not %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 -m64 -O2 %s -o %t && not %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 -m64 -O3 %s -o %t && not %t >%t.out 2>&1
17 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
19 #include <stdlib.h>
20 int main(int argc, char **argv) {
21 int *volatile p = (int *)malloc(sizeof(int));
22 *p = 42;
23 free(p);
25 if (*p)
26 exit(0);
27 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
28 // CHECK: {{#0 0x.* in main .*use-after-free.cc:}}[[@LINE-3]]
30 // CHECK-ORIGINS: Uninitialized value was created by a heap allocation
31 // CHECK-ORIGINS: {{#0 0x.* in .*free}}
32 // CHECK-ORIGINS: {{#1 0x.* in main .*use-after-free.cc:}}[[@LINE-9]]
33 return 0;