Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>%t.out
      2 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
      3 // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>%t.out
      4 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
      5 // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>%t.out
      6 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
      7 // RUN: %clangxx_asan -O3 %s -o %t && not %t 2>%t.out
      8 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
      9 
     10 #include <stdlib.h>
     11 __attribute__((noinline))
     12 static void LargeFunction(int *x, int zero) {
     13   x[0]++;
     14   x[1]++;
     15   x[2]++;
     16   x[3]++;
     17   x[4]++;
     18   x[5]++;
     19   x[6]++;
     20   x[7]++;
     21   x[8]++;
     22   x[9]++;
     23 
     24   // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
     25   // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
     26   // CHECK: {{READ of size 4 at 0x.* thread T0}}
     27   x[zero + 103]++;  // we should report this exact line
     28   // atos incorrectly extracts the symbol name for the static functions on
     29   // Darwin.
     30   // CHECK-Linux:  {{#0 0x.* in LargeFunction.*large_func_test.cc:}}[[@LINE-3]]
     31   // CHECK-Darwin: {{#0 0x.* in .*LargeFunction.*large_func_test.cc}}:[[@LINE-4]]
     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, argc - 1);
     48   // CHECK: {{    #1 0x.* in main .*large_func_test.cc:}}[[@LINE-1]]
     49   // CHECK: {{0x.* is located 12 bytes to the right of 400-byte region}}
     50   // CHECK: {{allocated by thread T0 here:}}
     51   // CHECK-Linux: {{    #0 0x.* in operator new.*}}
     52   // CHECK-Darwin: {{    #0 0x.* in .*_Zna.*}}
     53   // CHECK: {{    #1 0x.* in main .*large_func_test.cc:}}[[@LINE-7]]
     54   delete x;
     55 }
     56