blob: 2648ec7e5f1fb0c0d3c01dc69490e0b8955c91a8 [file] [log] [blame]
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00001// 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
Alexey Samsonov60164862012-08-15 08:29:17 +000017
18#include <stdlib.h>
19#include <string.h>
20int 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}}
Alexey Samsonovf96bfd82012-12-28 08:38:09 +000025 // CHECK: {{ #0 0x.* in _?main .*heap-overflow.cc:}}[[@LINE-2]]
Alexey Samsonov60164862012-08-15 08:29:17 +000026 // 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}}
Alexey Samsonov9fe914b2012-08-15 11:26:57 +000030 // CHECK-Linux: {{ #1 0x.* in main .*heap-overflow.cc:21}}
Alexey Samsonov60164862012-08-15 08:29:17 +000031
32 // CHECK-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
33 // CHECK-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
34 // CHECK-Darwin: {{ #2 0x.* in malloc.*}}
Alexey Samsonov480477c2012-10-08 13:11:18 +000035 // CHECK-Darwin: {{ #3 0x.* in _?main .*heap-overflow.cc:21}}
Alexey Samsonov60164862012-08-15 08:29:17 +000036 free(x);
37 return res;
38}