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>
19 #include <string.h>
main(int argc,char ** argv)20 int main(int argc, char **argv) {
21 char *x = (char*)malloc(10 * sizeof(char));
22 memset(x, 0, 10);
23 int res = x[argc * 10]; // BOOOM
24 // CHECK: {{READ of size 1 at 0x.* thread T0}}
25 // CHECK: {{ #0 0x.* in _?main .*heap-overflow.cc:}}[[@LINE-2]]
26 // CHECK: {{0x.* is located 0 bytes to the right of 10-byte region}}
27 // CHECK: {{allocated by thread T0 here:}}
28
29 // CHECK-Linux: {{ #0 0x.* in .*malloc}}
30 // CHECK-Linux: {{ #1 0x.* in main .*heap-overflow.cc:21}}
31
32 // CHECK-Darwin: {{ #0 0x.* in _?wrap_malloc.*}}
33 // CHECK-Darwin: {{ #1 0x.* in _?main .*heap-overflow.cc:21}}
34 free(x);
35 return res;
36 }
37