2018-04-30 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr34244.c
blob262c92f1fa06b5441549bf35e5d1a3d306ffa57b
1 /* PR tree-optimization/34244 */
2 /* { dg-do run } */
3 /* { dg-options "-O2 " } */
5 int __attribute__((noinline)) GetParent(void)
7 static int count = 0;
8 count++;
9 switch (count)
11 case 1:
12 case 3:
13 case 4:
14 return 1;
15 default:
16 return 0;
19 int __attribute__((noinline)) FindCommonAncestor(int aNode1, int aNode2)
21 if (aNode1 && aNode2) {
22 int offset = 0;
23 int anc1 = aNode1;
24 for (;;) {
25 ++offset;
26 int parent = GetParent();
27 if (!parent)
28 break;
29 anc1 = parent;
31 int anc2 = aNode2;
32 for (;;) {
33 --offset;
34 int parent = GetParent();
35 if (!parent)
36 break;
37 anc2 = parent;
39 if (anc1 == anc2) {
40 anc1 = aNode1;
41 anc2 = aNode2;
42 while (offset > 0) {
43 anc1 = GetParent();
44 --offset;
46 while (offset < 0) {
47 anc2 = GetParent();
48 ++offset;
50 while (anc1 != anc2) {
51 anc1 = GetParent();
52 anc2 = GetParent();
54 return anc1;
57 return 0;
59 extern void abort (void);
60 int main()
62 if (FindCommonAncestor (1, 1) != 0)
63 abort ();
64 return 0;