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