1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
3 
4 #include <stdio.h>
5 
6 #define SCHAR_MAX __SCHAR_MAX__
7 #define SHRT_MAX __SHRT_MAX__
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-__INT_MAX__ - 1)
10 
11 void __attribute__((noinline,noclone))
check(int i,int j)12 check (int i, int j)
13 {
14   if (i != j)
15     __builtin_abort ();
16 }
17 
18 int
main(void)19 main (void)
20 {
21   fputs ("UBSAN TEST START\n", stderr);
22 
23   /* Test integer promotion.  */
24 #if __SCHAR_MAX__ == 127
25   volatile signed char a = -2;
26   volatile signed char b = SCHAR_MAX;
27   volatile signed char c = a * b;
28   check (c, 2);
29 #endif
30 
31 #if __SHRT_MAX__ == 32767
32   volatile short d = SHRT_MAX;
33   volatile short e = 2;
34   volatile short f = d * e;
35   check (f, -2);
36 #endif
37 
38 #if __INT_MAX__ == 2147483647
39   volatile int m = INT_MAX;
40   volatile int n = 1;
41   volatile int o = m * n;
42   check (o, INT_MAX);
43 
44   m = INT_MIN;
45   o = m * n;
46   check (o, INT_MIN);
47 #endif
48 
49   fputs ("UBSAN TEST END\n", stderr);
50   return 0;
51 }
52 
53 /* { dg-output "UBSAN TEST START(\n|\r\n|\r)UBSAN TEST END" } */
54