1 /* { dg-do run } */
2 /* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O2" } } */
3 /* { dg-options "-fsanitize=float-cast-overflow -DUSE_FLT_DBL_LDBL" } */
4 /* { dg-additional-options "-DUSE_INT128" { target int128 } } */
5 
6 #include "float-cast-overflow-7.h"
7 
8 #define TEST(type1, type2) \
9   if (type1##_MIN)						\
10     {								\
11       type2 min = type1##_MIN;					\
12       type2 add = -1.0;						\
13       while (1)							\
14 	{							\
15 	  volatile type2 tem = min + add;			\
16 	  if (tem != min)					\
17 	    {							\
18 	      volatile type1 tem3 = cvt_##type1##_##type2 (tem);\
19 	      break;						\
20 	    }							\
21 	  add = add * type2##_RADIX;				\
22 	  if (min == add)					\
23 	    break;						\
24 	}							\
25     }								\
26   else								\
27     {								\
28       volatile type1 tem3 = cvt_##type1##_##type2 (-1.0f);	\
29     }								\
30   {								\
31     type2 max = type1##_MAX;					\
32     type2 add = 1.0;						\
33     while (1)							\
34       {								\
35 	volatile type2 tem = max + add;				\
36 	if (tem != max)						\
37 	  {							\
38 	    volatile type1 tem3 = cvt_##type1##_##type2 (tem);	\
39 	    break;						\
40 	  }							\
41 	add = add * type2##_RADIX;				\
42 	if (max == add)						\
43 	  break;						\
44       }								\
45   }
46 
47 #ifdef si128_MAX
48 # define TESTS128(type2) TEST (si128, type2) TEST (ui128, type2)
49 #else
50 # define TESTS128(type2)
51 #endif
52 
53 #define TESTS(type2) \
54   TEST (sc, type2) TEST (c, type2) TEST (uc, type2)	\
55   TEST (ss, type2) TEST (us, type2)			\
56   TEST (si, type2) TEST (ui, type2)			\
57   TEST (sl, type2) TEST (ul, type2)			\
58   TEST (sll, type2) TEST (ull, type2)			\
59   TESTS128 (type2)
60 
61 int
main()62 main ()
63 {
64 #ifdef f_MAX
65   TESTS (f)
66 #endif
67 #ifdef d_MAX
68   TESTS (d)
69 #endif
70 #ifdef ld_MAX
71   TESTS (ld)
72 #endif
73 #ifdef f80_MAX
74   TESTS (f80)
75 #endif
76 #ifdef f128_MAX
77   TESTS (f128)
78 #endif
79 #ifdef BROKEN_DECIMAL_INT128
80 # undef TESTS128
81 # define TESTS128(type2)
82 # undef TWO
83 # undef M1U
84 # undef MAXS
85 # define TWO 2ULL
86 # define M1U -1ULL
87 # define MAXS (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
88 #endif
89 #ifdef d32_MAX
90   TESTS (d32)
91 #endif
92 #ifdef d64_MAX
93   TESTS (d64)
94 #endif
95 #ifdef d128_MAX
96   TESTS (d128)
97 #endif
98   return 0;
99 }
100 
101 /* float */
102 /* { dg-output " -129 is outside the range of representable values of type 'signed char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
103 /* { dg-output "\[^\n\r]* (-129|-1) is outside the range of representable values of type 'char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
104 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned char'\[^\n\r]*(\n|\r\n|\r)" } */
105 /* { dg-output "\[^\n\r]* -32769 is outside the range of representable values of type 'short int'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
106 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'short unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
107 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
108 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
109 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long int'\[^\n\r]*(\n|\r\n|\r)" } */
110 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
111 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long long int'\[^\n\r]*(\n|\r\n|\r)" } */
112 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
113 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type '__int128'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
114 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type '__int128 unsigned'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
115 /* No error for float and __int128 unsigned max value, as ui128_MAX is +Inf in float.  */
116 /* double */
117 /* { dg-output "\[^\n\r]* -129 is outside the range of representable values of type 'signed char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
118 /* { dg-output "\[^\n\r]* (-129|-1) is outside the range of representable values of type 'char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
119 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned char'\[^\n\r]*(\n|\r\n|\r)" } */
120 /* { dg-output "\[^\n\r]* -32769 is outside the range of representable values of type 'short int'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
121 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'short unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
122 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
123 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
124 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long int'\[^\n\r]*(\n|\r\n|\r)" } */
125 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
126 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long long int'\[^\n\r]*(\n|\r\n|\r)" } */
127 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
128 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type '__int128'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
129 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type '__int128 unsigned'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
130 /* long double */
131 /* { dg-output "\[^\n\r]* -129 is outside the range of representable values of type 'signed char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
132 /* { dg-output "\[^\n\r]* (-129|-1) is outside the range of representable values of type 'char'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
133 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned char'\[^\n\r]*(\n|\r\n|\r)" } */
134 /* { dg-output "\[^\n\r]* -32769 is outside the range of representable values of type 'short int'\[^\n\r]*(\n|\r\n|\r)" { target { ilp32 || lp64 } } } */
135 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'short unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
136 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
137 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
138 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long int'\[^\n\r]*(\n|\r\n|\r)" } */
139 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
140 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type 'long long int'\[^\n\r]*(\n|\r\n|\r)" } */
141 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type 'long long unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
142 /* { dg-output "\[^\n\r]* \[0-9.e+-]* is outside the range of representable values of type '__int128'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
143 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type '__int128 unsigned'\[^\n\r]*(\n|\r\n|\r)" { target { int128 } } } */
144