Debian Codegraph @

gcc/testsuite/g++.dg/tree-ssa/sra-eh-1.C

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-sra" } */
3
4 struct E
5 {
6 short c;
7 E (short param) : c(param) {};
8 };
9
10 volatile short vs = 0;
11 long buf[16];
12 long * volatile pbuf = (long *) &buf;
13
14 static void __attribute__((noinline))
15 unrelated_throwing (void)
16 {
17 throw E (256);
18 }
19
20 struct S {
21 long *b;
22 int c;
23 int s;
24 };
25
26 static void __attribute__((noinline))
27 crazy_alloc_s (struct S *p)
28 {
29 int s = p->c ? p->c * 2 : 16;
30
31 long *b = pbuf;
32 if (!b || s > 16)
33 {
34 p->s = -p->s;
35 throw E (127);
36 }
37
38 __builtin_memcpy (b, p->b, p->c);
39 p->b = b;
40 p->s = s;
41 pbuf = 0;
42 return;
43 }
44
45 long __attribute__((noipa))
46 process (long v)
47 {
48 return v + 1;
49 }
50
51 void __attribute__((noipa))
52 check (int s, short c)
53 {
54 if (vs < c)
55 vs = c;
56 if (c == 127)
57 {
58 if (s >= 0)
59 __builtin_abort ();
60 }
61 else
62 {
63 if (s != 0)
64 __builtin_abort ();
65 }
66 return;
67 }
68
69
70 void
71 foo (void)
72 {
73 struct S foo_stack;
74
75 foo_stack.c = 0;
76 crazy_alloc_s (&foo_stack);
77 foo_stack.b[0] = 1;
78 foo_stack.c = 1;
79
80 while (foo_stack.c)
81 {
82 long l = foo_stack.b[--foo_stack.c];
83
84 if (l > 0)
85 {
86 for (int i = 0; i < 4; i++)
87 {
88 try
89 {
90 if (foo_stack.s <= foo_stack.c + 1)
91 crazy_alloc_s (&foo_stack);
92 }
93 catch (E e)
94 {
95 check (foo_stack.s, e.c);
96 return;
97 }
98 l = process (l);
99 foo_stack.b[foo_stack.c++] = l;
100 }
101 }
102 }
103 return;
104 }
105
106
107 volatile int vi;
108
109 int __attribute__((noipa))
110 save (int s)
111 {
112 vi = s;
113 return 0;
114 }
115
116 int __attribute__((noipa))
117 restore ()
118 {
119 return vi;
120 }
121
122
123 void
124 bar (void)
125 {
126 struct S bar_stack;
127
128 bar_stack.c = 0;
129 crazy_alloc_s (&bar_stack);
130 bar_stack.b[0] = 1;
131 bar_stack.c = 1;
132
133 while (bar_stack.c)
134 {
135 long l = bar_stack.b[--bar_stack.c];
136
137 if (l > 0)
138 {
139 for (int i = 0; i < 4; i++)
140 {
141 try
142 {
143 if (i == 2)
144 {
145 bar_stack.s = save (bar_stack.s);
146 unrelated_throwing ();
147 }
148 if (bar_stack.s <= bar_stack.c + 1)
149 crazy_alloc_s (&bar_stack);
150 }
151 catch (E e)
152 {
153 check (bar_stack.s, e.c);
154 if (e.c == 127)
155 return;
156 bar_stack.s = restore ();
157 continue;
158 }
159 l = process (l);
160 bar_stack.b[bar_stack.c++] = l;
161 }
162 }
163 }
164 return;
165 }
166
167
168
169
170 int main (int argc, char **argv)
171 {
172 vs = 0;
173 pbuf = (long *) &buf;
174 foo ();
175 if (vs != 127)
176 __builtin_abort ();
177
178 vs = 0;
179 pbuf = (long *) &buf;
180 bar ();
181 if (vs != 256)
182 __builtin_abort ();
183 return 0;
184 }
185
186 /* { dg-final { scan-tree-dump "Created a replacement for foo_stack offset" "sra"} } */
187 /* { dg-final { scan-tree-dump "Created a replacement for bar_stack offset" "sra"} } */