• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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))
LargeFunction(int * x,int zero)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   x[zero + 111]++;  // we should report this exact line
33 
34   x[10]++;
35   x[11]++;
36   x[12]++;
37   x[13]++;
38   x[14]++;
39   x[15]++;
40   x[16]++;
41   x[17]++;
42   x[18]++;
43   x[19]++;
44 }
45 
main(int argc,char ** argv)46 int main(int argc, char **argv) {
47   int *x = new int[100];
48   LargeFunction(x, argc - 1);
49   delete x;
50 }
51 
52 // CHECK: {{.*ERROR: AddressSanitizer heap-buffer-overflow on address}}
53 // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
54 // CHECK: {{READ of size 4 at 0x.* thread T0}}
55 
56 // atos incorrectly extracts the symbol name for the static functions on
57 // Darwin.
58 // CHECK-Linux:  {{    #0 0x.* in LargeFunction.*large_func_test.cc:32}}
59 // CHECK-Darwin: {{    #0 0x.* in .*LargeFunction.*large_func_test.cc:32}}
60 
61 // CHECK: {{    #1 0x.* in main .*large_func_test.cc:48}}
62 // CHECK: {{0x.* is located 44 bytes to the right of 400-byte region}}
63 // CHECK: {{allocated by thread T0 here:}}
64 // CHECK: {{    #0 0x.* in operator new.*}}
65 // CHECK: {{    #1 0x.* in main .*large_func_test.cc:47}}
66