Debian Codegraph @

gcc/testsuite/gcc.dg/strict-flex-array-3.c

raw
1 /* test the combination of attribute strict_flex_array and option
2 -fstrict-flex-arrays: when both attribute and option specified,
3 attribute will have higher priority. */
4 /* { dg-do run } */
5 /* { dg-options "-O2 -fstrict-flex-arrays=0" } */
6
7 #include "builtin-object-size-common.h"
8
9 #define expect(p, _v) do { \
10 size_t v = _v; \
11 if (p == v) \
12 __builtin_printf ("ok: %s == %zd\n", #p, p); \
13 else \
14 { \
15 __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
16 FAIL (); \
17 } \
18 } while (0);
19
20 #ifdef __AVR__
21 /* AVR-Libc doesn't support %zd, thus use %d for size_t. */
22 #undef expect
23 #define expect(p, _v) do { \
24 size_t v = _v; \
25 if (p == v) \
26 __builtin_printf ("ok: %s == %d\n", #p, p); \
27 else \
28 { \
29 __builtin_printf ("WAT: %s == %d (expected %d)\n", #p, p, v); \
30 FAIL (); \
31 } \
32 } while (0);
33 #endif /* AVR */
34
35 struct trailing_array_1 {
36 int a;
37 int b;
38 int c[4] __attribute__ ((strict_flex_array (1)));
39 };
40
41 struct trailing_array_2 {
42 int a;
43 int b;
44 int c[1] __attribute__ ((strict_flex_array (2)));
45 };
46
47 struct trailing_array_3 {
48 int a;
49 int b;
50 int c[0] __attribute__ ((strict_flex_array (3)));
51 };
52 struct trailing_array_4 {
53 int a;
54 int b;
55 int c[];
56 };
57
58 void __attribute__((__noinline__)) stuff(
59 struct trailing_array_1 *normal,
60 struct trailing_array_2 *trailing_1,
61 struct trailing_array_3 *trailing_0,
62 struct trailing_array_4 *trailing_flex)
63 {
64 expect(__builtin_object_size(normal->c, 1), 4 * __SIZEOF_INT__);
65 expect(__builtin_object_size(trailing_1->c, 1), __SIZEOF_INT__);
66 expect(__builtin_object_size(trailing_0->c, 1), 0);
67 expect(__builtin_object_size(trailing_flex->c, 1), -1);
68 }
69
70 int main(int argc, char *argv[])
71 {
72 stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
73
74 DONE ();
75 }