summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/pr48549.C
blob: 30799ee93f241b7d631b0c925af44020c5b0a98f (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// PR rtl-optimization/48549
// { dg-do compile }
// { dg-options "-fcompare-debug -O2" }

void
foo (void *from, void *to)
{
  long offset = reinterpret_cast <long>(to) - reinterpret_cast <long>(from);
  if (offset != static_cast <int>(offset))
    *(int *) 0xC0DE = 0;
  reinterpret_cast <int *>(from)[1] = offset;
}
struct A
{
  A () : a () {}
  A (void *x) : a (x) {}
  void *bar () { return a; }
  void *a;
};
struct C;
struct D;
struct E : public A
{
  C m1 (int);
  D m2 ();
  E () {}
  E (A x) : A (x) {}
};
struct C : public E
{
  C () {}
  C (void *x) : E (x) {}
};
struct D : public E
{
  D (void *x) : E (x) {}
};
C
E::m1 (int x)
{
  return (reinterpret_cast <char *>(bar ()) + x);
}
D
E::m2 ()
{
  return reinterpret_cast <char *>(bar ());
}
struct B
{
  E a;
  unsigned b : 16;
  unsigned c : 1;
};
void
baz (B *x)
{
  for (unsigned i = 0; i < 64; i++)
    {
      D d = x[i].a.m2 ();
      C c = x[i].a.m1 (x[i].c);
      foo (d.bar (), c.bar ());
    }
}