aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c
blob: 21badc57982b31d826580f763d02453addefd92b (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
/* 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 = {.b = {1, 2, 3, 4, 5}};

union with_fam_2 {
  int a;
  char b[];  
} with_fam_2_v = {.a = 0x1f2f3f4f};

union with_fam_3 {
  char a[];  
  int b[];  
} with_fam_3_v = {.b = {0x1f2f3f4f, 0x5f6f7f7f}};

struct only_fam {
  int b[]; 
} only_fam_v = {{7, 11}};

struct only_fam_2 {
  unsigned int : 2;
  unsigned int : 3;
  int b[]; 
} only_fam_2_v = {{7, 11}};

int main ()
{
  if (__builtin_object_size(with_fam_1_v.b, 1) != 20)
    __builtin_abort ();
  if (__builtin_object_size(with_fam_2_v.b, 1) != 4)
    __builtin_abort ();
  if (__builtin_object_size(with_fam_3_v.b, 1) != 8)
    __builtin_abort ();
  if (__builtin_object_size(only_fam_v.b, 1) != 8)
    __builtin_abort ();
  if (__builtin_object_size(only_fam_2_v.b, 1) != 8)
    __builtin_abort ();

  return 0;
}