1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK |
2 | // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK |
3 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK |
4 | // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK |
5 | // REQUIRES: stable-runtime |
6 | |
7 | #include <stdlib.h> |
8 | __attribute__((noinline)) |
9 | static void LargeFunction(int *x, int zero) { |
10 | x[0]++; |
11 | x[1]++; |
12 | x[2]++; |
13 | x[3]++; |
14 | x[4]++; |
15 | x[5]++; |
16 | x[6]++; |
17 | x[7]++; |
18 | x[8]++; |
19 | x[9]++; |
20 | |
21 | // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} |
22 | // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} |
23 | // CHECK: {{READ of size 4 at 0x.* thread T0}} |
24 | x[zero + 103]++; // we should report this exact line |
25 | // atos incorrectly extracts the symbol name for the static functions on |
26 | // Darwin. |
27 | // CHECK-Linux: {{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-3]] |
28 | // CHECK-SunOS: {{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-4]] |
29 | // CHECK-Windows:{{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-5]] |
30 | // CHECK-FreeBSD:{{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-6]] |
31 | // CHECK-Darwin: {{#0 0x.* in .*LargeFunction.*large_func_test.cpp}}:[[@LINE-7]] |
32 | |
33 | x[10]++; |
34 | x[11]++; |
35 | x[12]++; |
36 | x[13]++; |
37 | x[14]++; |
38 | x[15]++; |
39 | x[16]++; |
40 | x[17]++; |
41 | x[18]++; |
42 | x[19]++; |
43 | } |
44 | |
45 | int main(int argc, char **argv) { |
46 | int *x = new int[100]; |
47 | LargeFunction(x, zero: argc - 1); |
48 | // CHECK: {{ #1 0x.* in main .*large_func_test.cpp:}}[[@LINE-1]] |
49 | // CHECK: {{0x.* is located 12 bytes after 400-byte region}} |
50 | // CHECK: {{allocated by thread T0 here:}} |
51 | // CHECK-Linux: {{ #0 0x.* in operator new}} |
52 | // CHECK-SunOS: {{ #0 0x.* in operator new}} |
53 | // CHECK-Windows:{{ #0 0x.* in operator new}} |
54 | // CHECK-FreeBSD:{{ #0 0x.* in operator new}} |
55 | // CHECK-Darwin: {{ #0 0x.* in .*_Zna}} |
56 | // CHECK-NEXT: {{ #1 0x.* in main .*large_func_test.cpp:}}[[@LINE-10]] |
57 | int y = x[argc]; |
58 | delete[] x; |
59 | return y; |
60 | } |
61 | |