| 1 |
/* PR c/102989 */ |
| 2 |
/* { dg-do run { target { bitint128 && int128 } } } */ |
| 3 |
/* { dg-options "-fsanitize=signed-integer-overflow,shift -fsanitize-recover=signed-integer-overflow,shift" } */ |
| 4 |
|
| 5 |
__attribute__((noipa)) int |
| 6 |
foo (_BitInt(125) *p, _BitInt(125) *q, int n) |
| 7 |
{ |
| 8 |
q[0] = p[0] + p[1]; |
| 9 |
q[1] = p[2] - p[3]; |
| 10 |
q[2] = p[4] * p[5]; |
| 11 |
q[3] = p[6] / p[7]; |
| 12 |
q[4] = p[8] << n; |
| 13 |
q[5] = p[9] >> n; |
| 14 |
return n; |
| 15 |
} |
| 16 |
|
| 17 |
int |
| 18 |
main () |
| 19 |
{ |
| 20 |
static _BitInt(125) p[] = { |
| 21 |
21267647932558653966460912964485513214wb, 1wb, |
| 22 |
-21267647932558653966460912964485513215wb, 1wb, |
| 23 |
4611686018427387903wb, 4611686018427387905wb, |
| 24 |
-21267647932558653966460912964485513215wb - 1, 1wb, |
| 25 |
0wb, 1wb, |
| 26 |
21267647932558653966460912964485513215wb, 1wb, |
| 27 |
-21267647932558653966460912964485513215wb - 1, 1wb, |
| 28 |
4611686018427387903wb, 4611686018427387906wb, |
| 29 |
-21267647932558653966460912964485513215wb - 1, -1wb, |
| 30 |
0wb, 1wb |
| 31 |
}; |
| 32 |
_BitInt(125) q[6]; |
| 33 |
int n = foo (p, q, 123); |
| 34 |
q[4] = p[8] << (n + 5); |
| 35 |
q[5] = p[9] >> (n + 5); |
| 36 |
foo (p + 10, q, 125); |
| 37 |
} |
| 38 |
|
| 39 |
/* The 128-bit type vs. 125-bit is small inaccuracy. */ |
| 40 |
/* { dg-output "shift exponent 128 is too large for 128-bit type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 41 |
/* { dg-output "\[^\n\r]*shift exponent 128 is too large for 128-bit type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 42 |
/* { dg-output "\[^\n\r]*signed integer overflow: 0x0fffffffffffffffffffffffffffffff \\+ 1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 43 |
/* { dg-output "\[^\n\r]*signed integer overflow: 0xf0000000000000000000000000000000 - 1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 44 |
/* { dg-output "\[^\n\r]*signed integer overflow: 4611686018427387903 \\* 4611686018427387906 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 45 |
/* { dg-output "\[^\n\r]*division of 0xf0000000000000000000000000000000 by -1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 46 |
/* This isn't accurate, but libubsan right now doesn't know it is 125-bit type rather than 128-bit. */ |
| 47 |
/* { dg-output "\[^\n\r]*left shift of 0 by 125 places cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 48 |
/* The wording is totally incorrect, but at least it is diagnosed. */ |
| 49 |
/* { dg-output "\[^\n\r]*left shift of 1 by 125 places cannot be represented in type '_BitInt\\\(125\\\)'" } */ |