2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / overflow-mul-1.c
blob04a9ec7c27d273dad6cad236e876901a6b22de37
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable -fno-sanitize-recover=signed-integer-overflow" } */
4 #define SCHAR_MAX __SCHAR_MAX__
5 #define SHRT_MAX __SHRT_MAX__
6 #define INT_MAX __INT_MAX__
7 #define INT_MIN (-__INT_MAX__ - 1)
9 void __attribute__((noinline,noclone))
10 check (int i, int j)
12 if (i != j)
13 __builtin_abort ();
16 int
17 main (void)
19 /* Test integer promotion. */
20 #if __SCHAR_MAX__ == 127
21 volatile signed char a = -2;
22 volatile signed char b = SCHAR_MAX;
23 volatile signed char c = a * b;
24 check (c, 2);
25 #endif
27 #if __SHRT_MAX__ == 32767
28 volatile short d = SHRT_MAX;
29 volatile short e = 2;
30 volatile short f = d * e;
31 check (f, -2);
32 #endif
34 #if __INT_MAX__ == 2147483647
35 volatile int m = INT_MAX;
36 volatile int n = 1;
37 volatile int o = m * n;
38 check (o, INT_MAX);
40 m = INT_MIN;
41 o = m * n;
42 check (o, INT_MIN);
43 #endif
44 return 0;