1 // PR optimization/6086
2 // { dg-do run }
3 // { dg-options "-O" }
4 
5 extern "C" void abort (void);
6 
7 struct A
8 {
9   A (int x, int y);
10   int a, b;
fooA11   int foo () { return a; }
barA12   int bar () { return b; }
13 };
14 
15 struct B
16 {
17   virtual ~B ();
18   virtual A baz () const;
19 };
20 
21 struct C
22 {
23   A foo () const;
24   B *c;
25 };
26 
foo()27 A C::foo () const
28 {
29   int x, y;
30   x = c->baz ().foo ();
31   y = c->baz ().bar ();
32   return A (x, y);
33 }
34 
baz()35 A B::baz () const
36 {
37   return A (4, 8);
38 }
39 
A(int x,int y)40 A::A (int x, int y)
41 {
42   a = x;
43   b = y;
44 }
45 
~B()46 B::~B ()
47 {
48 }
49 
50 int
main()51 main ()
52 {
53   C the_c;
54   B the_b;
55   the_c.c = &the_b;
56   if (the_c.foo().a != 4)
57     abort ();
58   return 0;
59 }
60