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 __attribute__((noinline)) 20 static void LargeFunction(int *x, int zero) { 21 x[0]++; 22 x[1]++; 23 x[2]++; 24 x[3]++; 25 x[4]++; 26 x[5]++; 27 x[6]++; 28 x[7]++; 29 x[8]++; 30 x[9]++; 31 32 // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} 33 // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} 34 // CHECK: {{READ of size 4 at 0x.* thread T0}} 35 x[zero + 103]++; // we should report this exact line 36 // atos incorrectly extracts the symbol name for the static functions on 37 // Darwin. 38 // CHECK-Linux: {{#0 0x.* in LargeFunction.*large_func_test.cc:}}[[@LINE-3]] 39 // CHECK-Darwin: {{#0 0x.* in .*LargeFunction.*large_func_test.cc}}:[[@LINE-4]] 40 41 x[10]++; 42 x[11]++; 43 x[12]++; 44 x[13]++; 45 x[14]++; 46 x[15]++; 47 x[16]++; 48 x[17]++; 49 x[18]++; 50 x[19]++; 51 } 52 53 int main(int argc, char **argv) { 54 int *x = new int[100]; 55 LargeFunction(x, argc - 1); 56 // CHECK: {{ #1 0x.* in _?main .*large_func_test.cc:}}[[@LINE-1]] 57 // CHECK: {{0x.* is located 12 bytes to the right of 400-byte region}} 58 // CHECK: {{allocated by thread T0 here:}} 59 // CHECK-Linux: {{ #0 0x.* in operator new.*}} 60 // CHECK-Darwin: {{ #0 0x.* in .*_Zna.*}} 61 // CHECK: {{ #1 0x.* in _?main .*large_func_test.cc:}}[[@LINE-7]] 62 delete x; 63 } 64