| 1 |
/* Check that we don't misoptimize the final value of d. We used to |
| 2 |
apply loop unswitching on if(j), introducing undefined behavior |
| 3 |
that the original code wouldn't exercise, and this undefined |
| 4 |
behavior would get later passes to misoptimize the loop. */ |
| 5 |
|
| 6 |
/* { dg-do run } */ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
int x; |
| 12 |
|
| 13 |
int __attribute__ ((noinline, noclone)) |
| 14 |
xprintf (int d) { |
| 15 |
if (d) |
| 16 |
{ |
| 17 |
if (x) |
| 18 |
printf ("%d", d); |
| 19 |
abort (); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
int a, b; |
| 24 |
short c; |
| 25 |
|
| 26 |
int |
| 27 |
main () |
| 28 |
{ |
| 29 |
int j, d = 1; |
| 30 |
for (; c >= 0; c++) |
| 31 |
{ |
| 32 |
a = d; |
| 33 |
d = 0; |
| 34 |
if (b) |
| 35 |
{ |
| 36 |
xprintf (0); |
| 37 |
if (j) |
| 38 |
xprintf (0); |
| 39 |
} |
| 40 |
} |
| 41 |
xprintf (d); |
| 42 |
exit (0); |
| 43 |
} |