111
|
1 /* Verify that ipa-cp will not get confused by placement new constructing an
|
|
2 object within another one when looking for dynamic type change . */
|
145
|
3 /* { dg-do run { target { nonpic || pie_enabled } } } */
|
111
|
4 /* { dg-options "-O3 -Wno-attributes" } */
|
|
5
|
|
6 extern "C" void abort (void);
|
|
7 namespace std {
|
|
8 typedef __SIZE_TYPE__ size_t;
|
|
9 }
|
|
10 inline void* __attribute__ ((always_inline))
|
|
11 operator new(std::size_t, void* __p) throw()
|
|
12 {
|
|
13 return __p;
|
|
14 }
|
|
15
|
|
16 class A
|
|
17 {
|
|
18 public:
|
|
19 char data[256];
|
|
20 A();
|
|
21 virtual int foo (int i);
|
|
22 };
|
|
23
|
|
24 class B : public A
|
|
25 {
|
|
26 public:
|
|
27 virtual int foo (int i);
|
|
28 };
|
|
29
|
|
30 class C
|
|
31 {
|
|
32 public:
|
|
33 C();
|
|
34 virtual double foo (double i);
|
|
35 };
|
|
36
|
|
37 int A::foo (int i)
|
|
38 {
|
|
39 return i + 1;
|
|
40 }
|
|
41
|
|
42 int B::foo (int i)
|
|
43 {
|
|
44 return i + 2;
|
|
45 }
|
|
46
|
|
47 double C::foo (double i)
|
|
48 {
|
|
49 return i + 3.5;
|
|
50 }
|
|
51
|
|
52 static int __attribute__ ((noinline)) middleman (class A *obj, int i)
|
|
53 {
|
|
54 return obj->foo (i);
|
|
55 }
|
|
56
|
|
57 int __attribute__ ((noinline,noclone)) get_input(void)
|
|
58 {
|
|
59 return 1;
|
|
60 }
|
|
61
|
|
62 __attribute__ ((always_inline)) C::C ()
|
|
63 {
|
|
64 }
|
|
65
|
|
66 A::A ()
|
|
67 {
|
|
68 }
|
|
69
|
|
70 static __attribute__ ((noinline)) void bah ()
|
|
71 {
|
|
72 class B b;
|
|
73
|
|
74 C *c = new ((void *) &b.data) C;
|
|
75
|
|
76 if (middleman (&b, get_input ()) != 3)
|
|
77 abort ();
|
|
78 }
|
|
79
|
|
80 int main (int argc, char *argv[])
|
|
81 {
|
|
82 int i;
|
|
83
|
|
84 for (i = 0; i < 10; i++)
|
|
85 bah ();
|
|
86 return 0;
|
|
87 }
|