1 // RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out
2 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
3 // RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out
4 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
5 // RUN: %clangxx_asan -m64 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out
6 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
7 // RUN: %clangxx_asan -m64 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out
8 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
9 // RUN: %clangxx_asan -m32 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out
10 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
11 // RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out
12 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
13 // RUN: %clangxx_asan -m32 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out
14 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
15 // RUN: %clangxx_asan -m32 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out
16 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
17
18 #include <stdlib.h>
main()19 int main() {
20 char *x = (char*)malloc(10 * sizeof(char));
21 free(x);
22 return x[5];
23 // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
24 // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
25 // CHECK: {{READ of size 1 at 0x.* thread T0}}
26 // CHECK: {{ #0 0x.* in _?main .*use-after-free.cc:22}}
27 // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
28 // CHECK: {{freed by thread T0 here:}}
29
30 // CHECK-Linux: {{ #0 0x.* in .*free}}
31 // CHECK-Linux: {{ #1 0x.* in main .*use-after-free.cc:21}}
32
33 // CHECK-Darwin: {{ #0 0x.* in _?wrap_free}}
34 // CHECK-Darwin: {{ #1 0x.* in _?main .*use-after-free.cc:21}}
35
36 // CHECK: {{previously allocated by thread T0 here:}}
37
38 // CHECK-Linux: {{ #0 0x.* in .*malloc}}
39 // CHECK-Linux: {{ #1 0x.* in main .*use-after-free.cc:20}}
40
41 // CHECK-Darwin: {{ #0 0x.* in _?wrap_malloc.*}}
42 // CHECK-Darwin: {{ #1 0x.* in _?main .*use-after-free.cc:20}}
43 }
44