Debian Codegraph @

gcc/testsuite/gcc.dg/flex-array-counted-by-5.c

raw
1 /* Test the attribute counted_by and its usage in
2 * __builtin_dynamic_object_size: when the counted_by field is negative. */
3 /* { dg-do run } */
4 /* { dg-options "-O2" } */
5
6 #include "builtin-object-size-common.h"
7
8 struct annotated {
9 int b;
10 int c[] __attribute__ ((counted_by (b)));
11 } *array_annotated;
12
13 struct nested_annotated {
14 struct {
15 union {
16 int b;
17 float f;
18 };
19 int n;
20 };
21 int c[] __attribute__ ((counted_by (b)));
22 } *array_nested_annotated;
23
24 void __attribute__((__noinline__)) setup (int attr_count)
25 {
26 array_annotated
27 = (struct annotated *)malloc (sizeof (struct annotated));
28 array_annotated->b = attr_count;
29
30 array_nested_annotated
31 = (struct nested_annotated *)malloc (sizeof (struct nested_annotated));
32 array_nested_annotated->b = attr_count -1;
33
34 return;
35 }
36
37 void __attribute__((__noinline__)) test ()
38 {
39 EXPECT(__builtin_dynamic_object_size(array_annotated->c, 1), 0);
40 EXPECT(__builtin_dynamic_object_size(array_nested_annotated->c, 1), 0);
41 }
42
43 int main(int argc, char *argv[])
44 {
45 setup (-10);
46 test ();
47 DONE ();
48 }