Debian Codegraph @

gcc/testsuite/c-c++-common/hwasan/very-large-objects.c

raw
1 /* { dg-do compile } */
2
3 /* Ensure the sanitizer can handle very large offsets (i.e. that the hooks
4 handle offsets too large for the relevant instructions).
5 Just want to make sure this compiles without an ICE. */
6 #ifndef ASIZE
7 # define ASIZE 0x10000000000UL
8 #endif
9
10 typedef __UINT64_TYPE__ uint64_t;
11
12 #if __LONG_MAX__ < 8 * ASIZE
13 # undef ASIZE
14 # define ASIZE 4096
15 #endif
16
17 extern void abort (void);
18
19 int __attribute__((noinline))
20 foo (const char *s)
21 {
22 if (!s)
23 return 1;
24 if (s[0] != 'a')
25 abort ();
26 s += ASIZE - 1;
27 if (s[0] != 'b')
28 abort ();
29 return 0;
30 }
31
32 int (*fn) (const char *) = foo;
33
34 int __attribute__((noinline))
35 bar (void)
36 {
37 char s[ASIZE];
38 s[0] = 'a';
39 s[ASIZE - 1] = 'b';
40 foo (s);
41 foo (s);
42 return 0;
43 }
44
45 int __attribute__((noinline))
46 baz (long i)
47 {
48 if (i)
49 return fn (0);
50 else
51 {
52 char s[ASIZE];
53 s[0] = 'a';
54 s[ASIZE - 1] = 'b';
55 foo (s);
56 foo (s);
57 return fn (0);
58 }
59 }
60
61 int __attribute__((noinline))
62 very_large_offset (int *p)
63 {
64 char init_array[(uint64_t)0xfefefef];
65 char other_array[(uint64_t)0xfefefef];
66 return (int)init_array[p[1]] + (int)other_array[p[0]];
67 }
68