Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clangxx_asan -O0 %s -o %t
      2 // RUN: not %run %t A 2>&1 | FileCheck --check-prefix=CHECK-A %s
      3 // RUN: not %run %t B 2>&1 | FileCheck --check-prefix=CHECK-B %s
      4 // RUN: not %run %t C 2>&1 | FileCheck --check-prefix=CHECK-C %s
      5 // RUN: not %run %t D 2>&1 | FileCheck --check-prefix=CHECK-D %s
      6 // RUN: not %run %t E 2>&1 | FileCheck --check-prefix=CHECK-E %s
      7 
      8 // RUN: not %run %t K 2>&1 | FileCheck --check-prefix=CHECK-K %s
      9 // RUN: not %run %t L 2>&1 | FileCheck --check-prefix=CHECK-L %s
     10 // RUN: not %run %t M 2>&1 | FileCheck --check-prefix=CHECK-M %s
     11 // RUN: not %run %t N 2>&1 | FileCheck --check-prefix=CHECK-N %s
     12 // RUN: not %run %t O 2>&1 | FileCheck --check-prefix=CHECK-O %s
     13 
     14 #include <sanitizer/asan_interface.h>
     15 
     16 #include <stdlib.h>
     17 #include <string.h>
     18 int main(int argc, char **argv) {
     19   if (argc != 2) return 1;
     20   char *x = new char[16];
     21   memset(x, 0xab, 16);
     22   int res = 1;
     23   switch (argv[1][0]) {
     24     case 'A': res = __sanitizer_unaligned_load16(x + 15); break;
     25 //  CHECK-A ERROR: AddressSanitizer: heap-buffer-overflow on address
     26 //  CHECK-A: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-2]]
     27 //  CHECK-A: is located 0 bytes to the right of 16-byte region
     28     case 'B': res = __sanitizer_unaligned_load32(x + 14); break;
     29 //  CHECK-B: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     30     case 'C': res = __sanitizer_unaligned_load32(x + 13); break;
     31 //  CHECK-C: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     32     case 'D': res = __sanitizer_unaligned_load64(x + 15); break;
     33 //  CHECK-D: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     34     case 'E': res = __sanitizer_unaligned_load64(x + 9); break;
     35 //  CHECK-E: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     36 
     37     case 'K': __sanitizer_unaligned_store16(x + 15, 0); break;
     38 //  CHECK-K ERROR: AddressSanitizer: heap-buffer-overflow on address
     39 //  CHECK-K: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-2]]
     40 //  CHECK-K: is located 0 bytes to the right of 16-byte region
     41     case 'L': __sanitizer_unaligned_store32(x + 15, 0); break;
     42 //  CHECK-L: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     43     case 'M': __sanitizer_unaligned_store32(x + 13, 0); break;
     44 //  CHECK-M: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     45     case 'N': __sanitizer_unaligned_store64(x + 10, 0); break;
     46 //  CHECK-N: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     47     case 'O': __sanitizer_unaligned_store64(x + 14, 0); break;
     48 //  CHECK-O: main{{.*}}unaligned_loads_and_stores.cc:[[@LINE-1]]
     49   }
     50   delete x;
     51   return res;
     52 }
     53