PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr22591.c
blobf1f5ec84932cf5c5bd96c51c27229fbe44aa136f
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 void abort ();
6 typedef struct _Node
7 {
8 struct _Node *next, *prev;
9 } Node;
11 void __attribute__ ((noinline)) append (Node * q, Node * p)
13 p->next = q;
14 p->prev = q;
15 q->next = p;
16 q->prev = p;
19 inline void
20 swap (Node ** a, Node ** b)
22 Node *tmp = *a;
23 *a = *b;
24 *b = tmp;
27 /* Miscompilation seems to happen here. If one removes the if condition
28 (which should be true) the program works fine. */
29 void
30 ListSwap (Node * x, Node * y)
32 Node *tmp;
33 if (x->next)
35 swap (&x->next, &y->next);
36 swap (&x->prev, &y->prev);
37 x->next->prev = x->prev->next = x;
38 y->next->prev = y->prev->next = y;
42 int
43 main ()
45 Node A, A1, B, B1;
47 append (&A, &A1);
48 append (&B, &B1);
50 ListSwap (&A, &B);
52 if (&A != A.next->prev)
53 abort ();
55 return 0;