summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-35-array-cast-0.c
blob: ea4d49258a2e628d7f5f8ae6b16e973e9bb75f40 (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
/* { dg-do run } */
/* { dg-options  "-flto -flto-partition=none -fipa-dead-field-eliminate -fdump-ipa-structure-reorg -fipa-typelist-field=b -fipa-typelist-struct=astruct_s" } */

#include <assert.h>
#include <stdio.h>
#include <stddef.h>

int
main (int argc, char **argv)
{
  struct astruct_s
  {
    _Bool a;
    _Bool b;
    _Bool c;
    _Bool d;
  };
  struct astruct_s a[2][2];
  struct bstruct_s
  {
    _Bool a;
    _Bool c;
    _Bool d;
  };
  struct bstruct_s *b_ptr = (struct bstruct_s *) &a;
  // a[0][0] = b_ptr + 0 + 0;
  // a[0][1] = b_ptr + 0 + sizeof(astruct_s)
  // a[1][0] = b_ptr + 2*sizeof(astruct_s) + 0;
  // a[1][1] = b_ptr + 2*sizeof(astruct_s) + sizeof(astruct_s);
  // as a function of argc
  // a[argc][argc] = b_ptr + 2*sizeof(astruct_s)* argc + sizeof(astruct_s)*argc
  // TODO: Can't put size of astruct_s because
  // we don't change sizeof yet...
  int size = sizeof (struct bstruct_s);
  struct bstruct_s *b_ptr_2 = b_ptr + 2 * argc + argc;
  struct bstruct_s *b = (struct bstruct_s *) &(a[argc][argc]);
  assert (b_ptr_2 == b);
}