Sync with upstream 4.9 branch
[official-gcc.git] / embedded-4_9-branch / gcc / testsuite / c-c++-common / ubsan / overflow-sub-3.c
blobdeec5c411ba0f2f41b5936263ad4017484168d91
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=signed-integer-overflow" } */
4 __attribute__((noinline, noclone)) int
5 foo1 (int x, int y)
7 return x - y;
10 __attribute__((noinline, noclone)) int
11 foo2 (int x, int y)
13 unsigned int xa = (unsigned int) x - (__INT_MAX__ - 3);
14 xa &= 3;
15 x = __INT_MAX__ - 3 + xa;
16 unsigned int ya = y + 1U;
17 ya &= 1;
18 y = ya - 1;
19 return x - y;
22 int
23 main ()
25 int xm1, y;
26 for (xm1 = __INT_MAX__ - 4; xm1 < __INT_MAX__; xm1++)
27 for (y = -1; y <= 0; y++)
28 if (foo1 (xm1 + 1, y) != (int) (xm1 + 1U - y)
29 || foo2 (xm1 + 1, y) != (int) (xm1 + 1U - y))
30 __builtin_abort ();
31 return 0;
33 /* { dg-output ":7:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
34 /* { dg-output "\[^\n\r]*:19:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 cannot be represented in type 'int'" } */