Merge from trunk
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / overflow-sub-2.c
blob99f59054e163bcbdc742a80e2dcfa97965cb3c58
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
3 /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
5 #define INT_MAX __INT_MAX__
6 #define INT_MIN (-__INT_MAX__ - 1)
7 #define LONG_MAX __LONG_MAX__
8 #define LONG_MIN (-__LONG_MAX__ - 1L)
9 #define LLONG_MAX __LONG_LONG_MAX__
10 #define LLONG_MIN (-__LONG_LONG_MAX__ - 1L)
12 int
13 main (void)
15 volatile int j = INT_MIN;
16 volatile int i = 1;
17 volatile int k = j - i;
18 j--;
19 j = INT_MIN + 100;
20 j -= (1 << 10);
22 j = INT_MIN;
23 i = -1;
24 k = j - -i;
26 i = INT_MIN + 1000;
27 i -= (1 << 20);
29 volatile long int l = LONG_MIN;
30 volatile long int m = 1;
31 volatile long int n = l - m;
32 l--;
33 l = LONG_MIN + 100;
34 l -= (1 << 10);
36 l = LONG_MIN;
37 m = -1;
38 n = l - -m;
40 m = LONG_MIN + 1000;
41 m -= (1 << 20);
43 return 0;
46 /* { dg-output "signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'(\n|\r\n|\r)" } */
47 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 \\+ -1 cannot be represented in type 'int'(\n|\r\n|\r)" } */
48 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483548 \\+ -1024 cannot be represented in type 'int'(\n|\r\n|\r)" } */
49 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 \\+ -1 cannot be represented in type 'int'(\n|\r\n|\r)" } */
50 /* { dg-output "\[^\n\r]*signed integer overflow: -2147482648 \\+ -1048576 cannot be represented in type 'int'(\n|\r\n|\r)" } */
51 /* { dg-output "\[^\n\r]*signed integer overflow: -\[^\n\r]* - 1 cannot be represented in type 'long int'(\n|\r\n|\r)" } */
52 /* { dg-output "\[^\n\r]*signed integer overflow: -\[^\n\r]* \\+ -1 cannot be represented in type 'long int'(\n|\r\n|\r)" } */
53 /* { dg-output "\[^\n\r]*signed integer overflow: -\[^\n\r]* \\+ -1024 cannot be represented in type 'long int'(\n|\r\n|\r)" } */
54 /* { dg-output "\[^\n\r]*signed integer overflow: -\[^\n\r]* \\+ -1 cannot be represented in type 'long int'(\n|\r\n|\r)" } */
55 /* { dg-output "\[^\n\r]*signed integer overflow: -\[^\n\r]* \\+ -1048576 cannot be represented in type 'long int'" } */