1 /* { dg-do run } */
2 /* { dg-options "-fcheck-pointer-bounds -mmpx" } */
3 
4 
5 #include <stdint.h>
6 #include <string.h>
7 #include "mpx-check.h"
8 
9 #ifdef __i386__
10 /* i386 directory size is 4MB.  */
11 #define MPX_NUM_L2_BITS 10
12 #define MPX_NUM_IGN_BITS 2
13 #else /* __i386__ */
14 /* x86_64 directory size is 2GB.  */
15 #define MPX_NUM_L2_BITS 17
16 #define MPX_NUM_IGN_BITS 3
17 #endif /* !__i386__ */
18 
19 
20 /* bt_num_of_elems is the number of elements in bounds table.  */
21 unsigned long bt_num_of_elems = (1UL << MPX_NUM_L2_BITS);
22 
23 /* Function to test MPX wrapper of memmove function.
24    Check case with no BT allocated for data.  */
25 
26 int
mpx_test(int argc,const char ** argv)27 mpx_test (int argc, const char **argv)
28 {
29   void **arr = 0;
30   posix_memalign ((void **) (&arr),
31            1UL << (MPX_NUM_L2_BITS + MPX_NUM_IGN_BITS),
32            2 * bt_num_of_elems * sizeof (void *));
33   void **src = arr, **dst = arr, **ptr = arr;
34   src += 10;
35   dst += 1;
36   ptr += bt_num_of_elems + 100;
37   ptr[0] = __bnd_set_ptr_bounds (arr + 1, sizeof (void *) + 1);
38   memmove (dst, src, 5 * sizeof (void *));
39   return 0;
40 }
41