1 /* PR middle-end/38364 */ 2 /* { dg-do run } */ 3 /* { dg-options "-O2 -ftrapv" } */ 4 /* { dg-require-effective-target trapping } */ 5 6 extern void abort (void); 7 8 static inline short f1(short x,short y)9f1 (short x, short y) 10 { 11 if (x > 0) 12 { 13 if (y > 0) 14 { 15 if (x > __SHRT_MAX__ / y) 16 return x; 17 } 18 else if (y < (-__SHRT_MAX__ - 1) / x) 19 return x; 20 } 21 else 22 { 23 if (y > 0) 24 { 25 if (x < (-__SHRT_MAX__ - 1) / y) 26 return x; 27 } 28 else if (x != 0 && y < __SHRT_MAX__ / x) 29 return x; 30 } 31 return x * y; 32 } 33 34 static inline signed char f2(signed char x,signed char y)35f2 (signed char x, signed char y) 36 { 37 if (((x ^ y) & (((x ^ ((x ^ y) & (1 << (__CHAR_BIT__ - 1)))) - y) ^ y)) < 0) 38 return x; 39 return x - y; 40 } 41 42 unsigned int v; 43 44 int f3(int x,unsigned int y)45f3 (int x, unsigned int y) 46 { 47 f1 (1, 1); 48 return 1; 49 } 50 51 int f4(unsigned short x)52f4 (unsigned short x) 53 { 54 v = x; 55 return 1; 56 } 57 58 int f5(int x)59f5 (int x) 60 { 61 if (f2 (x, 1)) 62 f1 (1, f4 (1)); 63 return x; 64 } 65 66 int f6(unsigned int x)67f6 (unsigned int x) 68 { 69 f4 (x < (1 != f5 (0))); 70 return x; 71 } 72 73 int main(void)74main (void) 75 { 76 f6 (1); 77 if (v != 0) 78 abort (); 79 return 0; 80 } 81