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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* testing flexible array members in unions and alone in structures:
__bos/__bdos */
/* { dg-do run } */
/* { dg-options "-O2" } */
union with_fam_1 {
char a;
int b[];
} *with_fam_1_v;
union with_fam_2 {
int a;
char b[];
} *with_fam_2_v;
union with_fam_3 {
char a[];
int b[];
} *with_fam_3_v;
struct only_fam {
int b[];
} *only_fam_v;
struct only_fam_2 {
unsigned int : 2;
unsigned int : 3;
int b[];
} *only_fam_2_v;
void __attribute__((__noinline__))
setup (int n1, int n2, int n3, int n4, int n5)
{
with_fam_1_v = (union with_fam_1 *) __builtin_malloc (n1 * sizeof (int));
with_fam_2_v = (union with_fam_2 *) __builtin_malloc (n2 * sizeof (char));
with_fam_3_v = (union with_fam_3 *) __builtin_malloc (n3 * sizeof (int));
only_fam_v = (struct only_fam *) __builtin_malloc (n4 * sizeof (int));
only_fam_2_v = (struct only_fam_2 *) __builtin_malloc (n5 * sizeof (int));
return;
}
void __attribute__((__noinline__)) stuff(
union with_fam_1 *with_fam_1_v,
union with_fam_2 *with_fam_2_v,
union with_fam_3 *with_fam_3_v,
struct only_fam *only_fam_v,
struct only_fam_2 *only_fam_2_v)
{
if (__builtin_object_size(with_fam_1_v->b, 1) != -1)
__builtin_abort ();
if (__builtin_object_size(with_fam_2_v->b, 1) != -1)
__builtin_abort ();
if (__builtin_object_size(with_fam_3_v->b, 1) != -1)
__builtin_abort ();
if (__builtin_object_size(only_fam_v->b, 1) != -1)
__builtin_abort ();
if (__builtin_object_size(only_fam_2_v->b, 1) != -1)
__builtin_abort ();
}
int main (int argc, char *argv[])
{
setup (2, 3, 4, 5, 6);
stuff (with_fam_1_v, with_fam_2_v, with_fam_3_v, only_fam_v, only_fam_2_v);
return 0;
}
|