1 /* Test the attribute counted_by and its usage in
2 * __builtin_dynamic_object_size. */
4 /* { dg-options "-O2" } */
6 #include "builtin-object-size-common.h"
15 int c
[] __attribute__ ((counted_by (b
)));
18 struct nested_annotated
{
26 int c
[] __attribute__ ((counted_by (b
)));
27 } *array_nested_annotated
;
29 void __attribute__((__noinline__
)) setup (int normal_count
, int attr_count
)
32 = (struct flex
*)malloc (sizeof (struct flex
)
33 + normal_count
* sizeof (int));
34 array_flex
->b
= normal_count
;
37 = (struct annotated
*)malloc (sizeof (struct annotated
)
38 + attr_count
* sizeof (int));
39 array_annotated
->b
= attr_count
;
41 array_nested_annotated
42 = (struct nested_annotated
*)malloc (sizeof (struct nested_annotated
)
43 + attr_count
* sizeof (int));
44 array_nested_annotated
->b
= attr_count
;
49 void __attribute__((__noinline__
)) test ()
51 EXPECT(__builtin_dynamic_object_size(array_flex
->c
, 1), -1);
52 EXPECT(__builtin_dynamic_object_size(array_annotated
->c
, 1),
53 array_annotated
->b
* sizeof (int));
54 EXPECT(__builtin_dynamic_object_size(array_nested_annotated
->c
, 1),
55 array_nested_annotated
->b
* sizeof (int));
58 int main(int argc
, char *argv
[])