gcc/testsuite/gcc.c-torture/execute/arith-1.c
raw| 1 | void abort (void); |
| 2 | void exit (int); |
| 3 | |
| 4 | unsigned |
| 5 | sat_add (unsigned i) |
| 6 | { |
| 7 | unsigned ret = i + 1; |
| 8 | if (ret < i) |
| 9 | ret = i; |
| 10 | return ret; |
| 11 | } |
| 12 | |
| 13 | unsigned |
| 14 | sat_add2 (unsigned i) |
| 15 | { |
| 16 | unsigned ret = i + 1; |
| 17 | if (ret > i) |
| 18 | return ret; |
| 19 | return i; |
| 20 | } |
| 21 | |
| 22 | unsigned |
| 23 | sat_add3 (unsigned i) |
| 24 | { |
| 25 | unsigned ret = i - 1; |
| 26 | if (ret > i) |
| 27 | ret = i; |
| 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | unsigned |
| 32 | sat_add4 (unsigned i) |
| 33 | { |
| 34 | unsigned ret = i - 1; |
| 35 | if (ret < i) |
| 36 | return ret; |
| 37 | return i; |
| 38 | } |
| 39 | |
| 40 | int |
| 41 | main (void) |
| 42 | { |
| 43 | if (sat_add (~0U) != ~0U) |
| 44 | abort (); |
| 45 | if (sat_add2 (~0U) != ~0U) |
| 46 | abort (); |
| 47 | if (sat_add3 (0U) != 0U) |
| 48 | abort (); |
| 49 | if (sat_add4 (0U) != 0U) |
| 50 | abort (); |
| 51 | exit (0); |
| 52 | } |