1 // PR rtl-optimization/23478
2 // { dg-do run }
3 // { dg-options "-O2" }
4
5 extern "C" void abort ();
6 bool tthrow;
7 struct C3 { int i; };
8 class C14 {};
9 struct C7
10 {
11 virtual ~C7 ();
12 };
13
~C7()14 C7::~C7 ()
15 {
16 asm volatile ("" : : : "memory");
17 }
18 class C2 : public C7 {};
19
20 template <class X> class C13
21 {
22 bool ma;
23 X *mb;
24 public:
throw()25 explicit C13 (X *p = 0) throw () : ma (p != 0), mb (p) {}
26 ~C13 ();
27 };
28
29 template <class X>
~C13()30 C13<X>::~C13 ()
31 {
32 asm volatile ("" : : "r" (ma), "r" (mb) : "memory");
33 }
34
35 struct C1
36 {
37 C1 (const C3 &, const C3 &, const C3 &, const C3 *&);
38 };
39
C1(const C3 &,const C3 &,const C3 &,const C3 * &)40 C1::C1 (const C3 &, const C3 &, const C3 &, const C3 *&)
41 {
42 if (!tthrow)
43 throw 24;
44 }
45
46 struct C8
47 {
48 struct C15 {};
49 typedef C15 *C9;
50 virtual void f1 (C2 &, long *, void *, C3 &, void *, bool) = 0;
51 virtual C13<C14> f3 () const = 0;
~C8C852 virtual ~C8 () {}
53 };
54
55 bool
xx14()56 xx14 ()
57 {
58 bool b = false;
59 if (tthrow)
60 throw 6;
61 asm volatile ("" : : "r" (&b) : "memory");
62 return b;
63 }
64
65 bool
xx2()66 xx2 ()
67 {
68 bool b = false;
69 if (tthrow)
70 throw 6;
71 asm volatile ("" : : "r" (&b) : "memory");
72 return b;
73 }
74
75 C13<C7>
xx9()76 xx9 ()
77 {
78 return C13<C7>();
79 }
80
81 C2 &
xx10()82 xx10 ()
83 {
84 static C2 c2;
85 return c2;
86 }
87
88 C3 &
xx12()89 xx12 ()
90 {
91 static C3 c3 = { 1 };
92 return c3;
93 }
94
95 const C3 &
xx5()96 xx5 ()
97 {
98 static const C3 c3 = { 2 };
99 return c3;
100 }
101
102 const C3 *&
xx4()103 xx4 ()
104 {
105 static const C3 *p;
106 if (tthrow)
107 throw 6;
108 return p;
109 }
110
111 long ll13;
112
113 long
xx13()114 xx13 ()
115 {
116 long ret;
117 asm volatile ("" : "=r" (ret) : "r" (ll13));
118 return ret;
119 }
120
121 void
xx15(C3 & x,C13<C1> & y)122 xx15 (C3 &x, C13<C1> &y)
123 {
124 asm volatile ("" : : "r" (&x), "r" (&y) : "memory");
125 }
126
127 long
xx16(const void * x)128 xx16 (const void *x)
129 {
130 long ret;
131 asm volatile ("" : "=r" (ret) : "0" (1), "r" (x) : "memory");
132 return ret;
133 }
134
135 void
xx1(C13<C14> x)136 xx1 (C13<C14> x)
137 {
138 asm volatile ("" : : "r" (&x) : "memory");
139 if (tthrow)
140 throw 6;
141 }
142
143 void
xx3(const C7 * x)144 xx3 (const C7 *x)
145 {
146 if (x)
147 abort ();
148 }
149
150 void
xx7()151 xx7 ()
152 {
153 asm volatile ("" : : : "memory");
154 }
155
156 struct C5
157 {
158 C13<C7> f2 (C3 &v1, const void *v2, C8 *v6);
159 C7 *m2[2];
160 long m1[2];
161 };
162
163 C13<C7>
f2(C3 & v1,const void * v2,C8 * v6)164 C5::f2 (C3 &v1, const void *v2, C8 *v6)
165 {
166 C13<C7> v13 = xx9 ();
167 C2 &v9 = xx10 ();
168 for (long i = 1; i < 2; i++)
169 xx3 (m2[i]);
170 const C3 &ld = xx5 ();
171 xx7 ();
172 if (xx2 ())
173 throw "";
174 xx4 ();
175 C3 &si = xx12 ();
176 for (long i = 0; i < xx16 (v2); ++i)
177 {
178 C13<C1> sk (new C1 (xx5 (), ld, xx5 (), xx4 ()));
179 xx15 (si, sk);
180 }
181 long v4 = xx13 ();
182 for (long i = v4 - 1; i >= 0; --i)
183 m1[i] = i;
184 bool v8 = xx2 ();
185 for (long i = 0; i < 2 && !xx14 (); i++)
186 {
187 v6[i].f1 (v9, 0, __null, v1, __null, v8);
188 if (v8)
189 xx1 (v6[i].f3 ());
190 }
191 return v13;
192 }
193
194 int
main(void)195 main (void)
196 {
197 C5 c5 = { { __null, __null }, { 0, 0 } };
198 bool seen = false;
199 try
200 {
201 c5.f2 (xx12 (), __null, __null);
202 }
203 catch (int n)
204 {
205 if (n != 24)
206 abort ();
207 seen = true;
208 }
209 if (!seen)
210 abort ();
211 }
212