xref: /llvm-project/compiler-rt/test/asan/TestCases/small_memcpy_test.cpp (revision 673dc3d4a0b0fbb3b9b34ae2ecbfa522627fe582)
1 // Test that small memcpy works correctly.
2 
3 // RUN: %clangxx_asan %s -o %t
4 // RUN: not %run %t 8 24 2>&1 | FileCheck %s --check-prefix=CHECK
5 // RUN: not %run %t 16 32 2>&1 | FileCheck %s --check-prefix=CHECK
6 // RUN: not %run %t 24 40 2>&1 | FileCheck %s --check-prefix=CHECK
7 // RUN: not %run %t 32 48 2>&1 | FileCheck %s --check-prefix=CHECK
8 // RUN: not %run %t 40 56 2>&1 | FileCheck %s --check-prefix=CHECK
9 // RUN: not %run %t 48 64 2>&1 | FileCheck %s --check-prefix=CHECK
10 // REQUIRES: shadow-scale-3
11 #include <assert.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 
16 #include <sanitizer/asan_interface.h>
17 
main(int argc,char ** argv)18 int main(int argc, char **argv) {
19   assert(argc == 3);
20   size_t poison_from = atoi(argv[1]);
21   size_t poison_to = atoi(argv[2]);
22   assert(poison_from <= poison_to);
23   char A1[64], A2[64];
24   fprintf(stderr, "%zd %zd\n", poison_from, poison_to - poison_from);
25   __asan_poison_memory_region(&A1[0] + poison_from, poison_to - poison_from);
26   memcpy(A1, A2, sizeof(A1));
27 // CHECK: AddressSanitizer: use-after-poison
28   return 0;
29 }
30