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