1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable -fno-sanitize-recover=signed-integer-overflow" } */
3 
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)
8 
9 void __attribute__((noinline,noclone))
check(int i,int j)10 check (int i, int j)
11 {
12   if (i != j)
13     __builtin_abort ();
14 }
15 
16 int
main(void)17 main (void)
18 {
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
26 
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
33 
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);
39 
40   m = INT_MIN;
41   o = m * n;
42   check (o, INT_MIN);
43 #endif
44   return 0;
45 }
46