libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / flex-array-counted-by-5.c
blob68f9b0f7c8d21f218477de819dddb43d444be864
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" } */
6 #include "builtin-object-size-common.h"
8 struct annotated {
9 int b;
10 int c[] __attribute__ ((counted_by (b)));
11 } *array_annotated;
13 struct nested_annotated {
14 struct {
15 union {
16 int b;
17 float f;
19 int n;
21 int c[] __attribute__ ((counted_by (b)));
22 } *array_nested_annotated;
24 void __attribute__((__noinline__)) setup (int attr_count)
26 array_annotated
27 = (struct annotated *)malloc (sizeof (struct annotated));
28 array_annotated->b = attr_count;
30 array_nested_annotated
31 = (struct nested_annotated *)malloc (sizeof (struct nested_annotated));
32 array_nested_annotated->b = attr_count -1;
34 return;
37 void __attribute__((__noinline__)) test ()
39 EXPECT(__builtin_dynamic_object_size(array_annotated->c, 1), 0);
40 EXPECT(__builtin_dynamic_object_size(array_nested_annotated->c, 1), 0);
43 int main(int argc, char *argv[])
45 setup (-10);
46 test ();
47 DONE ();