]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/c-c++-common/asan/pointer-compare-2.c
Cherry-pick libsanitizer pointer-pair tristate option.
[thirdparty/gcc.git] / gcc / testsuite / c-c++-common / asan / pointer-compare-2.c
CommitLineData
05abad4c 1/* { dg-do run } */
4c4f3c3f 2/* { dg-set-target-env-var ASAN_OPTIONS "detect_invalid_pointer_pairs=2 halt_on_error=1" } */
05abad4c
ML
3/* { dg-options "-fsanitize=address,pointer-compare" } */
4
5volatile int v;
6
7int
8foo (char *p)
9{
10 char *p2 = p + 20;
11 v = p > p2;
12 return v;
13}
14
15void
16bar (char *p, char *q)
17{
18 v = p <= q;
19}
20
21void
22baz (char *p, char *q)
23{
24 v = (p != 0 && p < q);
25}
26
27char global[8192] = {};
28char small_global[7] = {};
29
30int
31main ()
32{
33 /* Heap allocated memory. */
34 char *p = (char *)__builtin_malloc (42);
35 int r = foo (p);
36 __builtin_free (p);
37
38 p = (char *)__builtin_malloc (1024);
39 bar (p, p + 1024);
40 bar (p + 1024, p + 1023);
41 bar (p + 1, p + 1023);
42 __builtin_free (p);
43
44 p = (char *)__builtin_malloc (4096);
45 bar (p, p + 4096);
46 bar (p + 10, p + 100);
47 bar (p + 1024, p + 4096);
48 bar (p + 4095, p + 4096);
49 bar (p + 4095, p + 4094);
50 bar (p + 100, p + 4096);
51 bar (p + 100, p + 4094);
52 __builtin_free (p);
53
54 /* Global variable. */
55 bar (&global[0], &global[1]);
56 bar (&global[1], &global[2]);
57 bar (&global[2], &global[1]);
58 bar (&global[0], &global[100]);
59 bar (&global[1000], &global[7000]);
60 bar (&global[500], &global[10]);
61 p = &global[0];
62 bar (p, p + 8192);
63 p = &global[8000];
64 bar (p, p + 192);
65
66 p = &small_global[0];
67 bar (p, p + 1);
68 bar (p, p + 7);
69 bar (p + 7, p + 1);
70 bar (p + 6, p + 7);
71 bar (p + 7, p + 7);
72
73 /* Stack variable. */
74 char stack[10000];
75 bar (&stack[0], &stack[100]);
76 bar (&stack[1000], &stack[9000]);
77 bar (&stack[500], &stack[10]);
78
79 baz (0, &stack[10]);
80
81 return 0;
82}