| 1 |
/* PR c/102989 */ |
| 2 |
/* { dg-do run { target bitint } } */ |
| 3 |
/* { dg-options "-fsanitize=signed-integer-overflow,shift -fsanitize-recover=signed-integer-overflow,shift" } */ |
| 4 |
|
| 5 |
__attribute__((noipa)) int |
| 6 |
foo (_BitInt(15) *p, _BitInt(15) *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(15) p[] = { |
| 21 |
16382wb, 1wb, |
| 22 |
-16383wb, 1wb, |
| 23 |
127wb, 129wb, |
| 24 |
-16383wb - 1, 1wb, |
| 25 |
0wb, 1wb, |
| 26 |
16383wb, 1wb, |
| 27 |
-16383wb - 1, 1wb, |
| 28 |
127wb, 130wb, |
| 29 |
-16383wb - 1, -1wb, |
| 30 |
0wb, 1wb |
| 31 |
}; |
| 32 |
_BitInt(15) q[6]; |
| 33 |
int n = foo (p, q, 14); |
| 34 |
q[4] = p[8] << (n + 2); |
| 35 |
q[5] = p[9] >> (n + 2); |
| 36 |
foo (p + 10, q, 15); |
| 37 |
} |
| 38 |
|
| 39 |
/* The 16-bit type vs. 15-bit is small inaccuracy. */ |
| 40 |
/* { dg-output "shift exponent 16 is too large for 16-bit type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 41 |
/* { dg-output "\[^\n\r]*shift exponent 16 is too large for 16-bit type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 42 |
/* { dg-output "\[^\n\r]*signed integer overflow: 16383 \\+ 1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 43 |
/* { dg-output "\[^\n\r]*signed integer overflow: -16384 - 1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 44 |
/* { dg-output "\[^\n\r]*signed integer overflow: 127 \\* 130 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 45 |
/* { dg-output "\[^\n\r]*division of -16384 by -1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 46 |
/* This isn't accurate, but libubsan right now doesn't know it is 15-bit type rather than 16-bit. */ |
| 47 |
/* { dg-output "\[^\n\r]*left shift of 0 by 15 places cannot be represented in type '_BitInt\\\(15\\\)'\[^\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 15 places cannot be represented in type '_BitInt\\\(15\\\)'" } */ |