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