ICF is more strict about non-common function and var
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-c-4.C
blob56d41e4967e3f966a14152e0ac58df9f154854c4
1 /* Verify that ipa-cp correctly detects the dynamic type of an object
2    under construction when doing devirtualization.  */
3 /* { dg-do run } */
4 /* { dg-options "-O3 -fno-inline"  } */
6 extern "C" void abort (void);
8 class Distraction
10 public:
11   float f;
12   double d;
13   Distraction ()
14   {
15     f = 8.3;
16     d = 10.2;
17   }
18   virtual float bar (float z);
21 class A
23 public:
24   int data;
25   A();
26   virtual int foo (int i);
29 class B : public Distraction, public A
31 public:
32   B();
33   virtual int foo (int i);
36 class C : public B
38 public:
39   virtual int foo (int i);
43 float Distraction::bar (float z)
45   f += z;
46   return f/2;
49 int A::foo (int i)
51   return i + 1;
54 int B::foo (int i)
56   return i + 2;
59 int C::foo (int i)
61   return i + 3;
64 int __attribute__ ((noinline,noclone)) get_input(void)
66   return 1;
69 static int __attribute__ ((noinline))
70 middleman (class A *obj, int i)
72   return obj->foo (i);
75 static void __attribute__ ((noinline))
76 sth2 (A *a)
78   if (a->foo (get_input ()) != 3)
79     abort ();
82 inline void __attribute__ ((always_inline)) sth1 (B *b)
84   sth2 (b);
87 inline __attribute__ ((always_inline)) A::A()
89   if (middleman (this, get_input ()) != 2)
90     abort ();
93 B::B() : Distraction(), A()
95   sth1 (this);
98 static void bah ()
100   class C c;
103 int main (int argc, char *argv[])
105   int i;
107   for (i = 0; i < 10; i++)
108     bah ();
109   return 0;