[committed] Fix m68k bootstrap segfault with late-combine
[official-gcc.git] / gcc / testsuite / c-c++-common / asan / pointer-subtract-2.c
blob7ef106c03ce505fde5681d823d75dde15b731fc9
1 /* { dg-do run } */
2 /* { dg-set-target-env-var ASAN_OPTIONS "detect_invalid_pointer_pairs=2 halt_on_error=1" } */
3 /* { dg-options "-fsanitize=address,pointer-subtract" } */
5 volatile __PTRDIFF_TYPE__ v;
7 void
8 bar (char *p, char *q)
10 v = q - p;
11 v = p - q;
14 char global[10000] = {};
16 int
17 main ()
19 /* Heap allocated memory. */
20 char *p = (char *)__builtin_malloc (42);
21 bar (p, p + 20);
22 __builtin_free (p);
24 /* Global variable. */
25 bar (&global[0], &global[100]);
26 bar (&global[1000], &global[9000]);
27 bar (&global[500], &global[10]);
28 bar (&global[0], &global[10000]);
30 /* Stack variable. */
31 char stack[10000];
32 bar (&stack[0], &stack[100]);
33 bar (&stack[1000], &stack[9000]);
34 bar (&stack[500], &stack[10]);
36 return 0;