Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 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 |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 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}} |
Alexey Samsonov | f96bfd8 | 2012-12-28 08:38:09 +0000 | [diff] [blame] | 25 | // CHECK: {{ #0 0x.* in _?main .*heap-overflow.cc:}}[[@LINE-2]] |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 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}} |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 30 | // CHECK-Linux: {{ #1 0x.* in main .*heap-overflow.cc:21}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 31 | |
| 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 Samsonov | 480477c | 2012-10-08 13:11:18 +0000 | [diff] [blame] | 35 | // CHECK-Darwin: {{ #3 0x.* in _?main .*heap-overflow.cc:21}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 36 | free(x); |
| 37 | return res; |
| 38 | } |