| 1 |
/* PR middle-end/91450 */ |
| 2 |
|
| 3 |
__attribute__((noipa)) unsigned long long |
| 4 |
foo (int a, int b) |
| 5 |
{ |
| 6 |
unsigned long long r; |
| 7 |
if (!__builtin_mul_overflow (a, b, &r)) |
| 8 |
__builtin_abort (); |
| 9 |
return r; |
| 10 |
} |
| 11 |
|
| 12 |
__attribute__((noipa)) unsigned long long |
| 13 |
bar (int a, int b) |
| 14 |
{ |
| 15 |
unsigned long long r; |
| 16 |
if (a >= 0) |
| 17 |
return 0; |
| 18 |
if (!__builtin_mul_overflow (a, b, &r)) |
| 19 |
__builtin_abort (); |
| 20 |
return r; |
| 21 |
} |
| 22 |
|
| 23 |
__attribute__((noipa)) unsigned long long |
| 24 |
baz (int a, int b) |
| 25 |
{ |
| 26 |
unsigned long long r; |
| 27 |
if (b >= 0) |
| 28 |
return 0; |
| 29 |
if (!__builtin_mul_overflow (a, b, &r)) |
| 30 |
__builtin_abort (); |
| 31 |
return r; |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noipa)) unsigned long long |
| 35 |
qux (int a, int b) |
| 36 |
{ |
| 37 |
unsigned long long r; |
| 38 |
if (a >= 0) |
| 39 |
return 0; |
| 40 |
if (b < 0) |
| 41 |
return 0; |
| 42 |
if (!__builtin_mul_overflow (a, b, &r)) |
| 43 |
__builtin_abort (); |
| 44 |
return r; |
| 45 |
} |
| 46 |
|
| 47 |
__attribute__((noipa)) unsigned long long |
| 48 |
quux (int a, int b) |
| 49 |
{ |
| 50 |
unsigned long long r; |
| 51 |
if (a < 0) |
| 52 |
return 0; |
| 53 |
if (b >= 0) |
| 54 |
return 0; |
| 55 |
if (!__builtin_mul_overflow (a, b, &r)) |
| 56 |
__builtin_abort (); |
| 57 |
return r; |
| 58 |
} |
| 59 |
|
| 60 |
int |
| 61 |
main () |
| 62 |
{ |
| 63 |
if (foo (-4, 2) != -8ULL) |
| 64 |
__builtin_abort (); |
| 65 |
if (foo (2, -4) != -8ULL) |
| 66 |
__builtin_abort (); |
| 67 |
if (bar (-4, 2) != -8ULL) |
| 68 |
__builtin_abort (); |
| 69 |
if (baz (2, -4) != -8ULL) |
| 70 |
__builtin_abort (); |
| 71 |
if (qux (-4, 2) != -8ULL) |
| 72 |
__builtin_abort (); |
| 73 |
if (quux (2, -4) != -8ULL) |
| 74 |
__builtin_abort (); |
| 75 |
if (foo (-2, 1) != -2ULL) |
| 76 |
__builtin_abort (); |
| 77 |
if (foo (1, -2) != -2ULL) |
| 78 |
__builtin_abort (); |
| 79 |
if (bar (-2, 1) != -2ULL) |
| 80 |
__builtin_abort (); |
| 81 |
if (baz (1, -2) != -2ULL) |
| 82 |
__builtin_abort (); |
| 83 |
if (qux (-2, 1) != -2ULL) |
| 84 |
__builtin_abort (); |
| 85 |
if (quux (1, -2) != -2ULL) |
| 86 |
__builtin_abort (); |
| 87 |
return 0; |
| 88 |
} |