Dead
[official-gcc.git] / gomp-20050608-branch / gcc / testsuite / gcc.dg / tree-ssa / pr21029.c
blobde2595aee55cc75310102c8efb51f8577acb00d2
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fwrapv" } */
4 /* PR tree-optimization/21029
6 f() used to get optimized to an infinite loop by tree-vrp, because
7 j is assumed to be non-negative. Even though the conversion from
8 unsigned to signed has unspecified results if the expression value
9 is not representable in the signed type, the compiler itself (e.g.,
10 the Ada front end) depends on wrap-around behavior. */
12 unsigned int f(void) {
13 unsigned char i = 123;
14 signed char j;
17 if ((j = (signed char) i) < 0)
18 break;
19 else
20 i++;
21 while (1);
23 return i;
26 /* Now let's torture it a bit further. Narrowing conversions need
27 similar treatment. */
29 unsigned int f1 (void) {
30 unsigned short i = 123;
31 signed char j;
34 if ((j = (signed char) i) < 0)
35 break;
36 else
37 i++;
38 while (1);
40 return i;
43 /* And so do widening conversions. */
45 unsigned int f2 (void) {
46 unsigned char i = 123;
47 signed short j;
50 if ((j = (signed short) (signed char) i) < 0)
51 break;
52 else
53 i++;
54 while (1);
56 return i;
59 /* Check same-sign truncations with an increment that turns into
60 decrements. */
62 unsigned int f3 (void) {
63 signed short i = 5;
64 signed char j;
67 if ((j = (signed char) i) < 0)
68 break;
69 else
70 i += 255;
71 while (1);
73 return i;
76 /* Check that the truncation above doesn't confuse the result of the
77 test after a widening conversion. */
79 unsigned int f4 (void) {
80 signed short i = -123;
81 signed int j;
84 if ((j = (signed int) (signed char) i) > 0)
85 break;
86 else
87 i += 255;
88 while (1);
90 return i;
93 /* Even if we omit the widening truncation, the narrowing truncation
94 is implementation-defined. */
96 unsigned int f5 (void) {
97 signed long i = -123;
98 signed char j;
101 if ((j = (signed char) i) > 0)
102 break;
103 else
104 i += 255;
105 while (1);
107 return i;
110 int main (void) {
111 f ();
112 f1 ();
113 f2 ();
114 f3 ();
115 f4 ();
116 f5 ();
117 return 0;