blob: db15bd874b316992f087b2cf4f2bc7afaadc4362 [file] [log] [blame]
Leonard Chanf921d852018-06-04 16:07:52 +00001// RUN: %clang_cc1 -verify -ffixed-point %s
2
3/* We do not yet support long long. No recommended bit widths are given for this
4 * size. */
5
6long long _Accum longlong_accum; // expected-error{{'long long _Accum' is invalid}}
7unsigned long long _Accum u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
Leonard Chanab80f3c2018-06-14 14:53:51 +00008long long _Fract longlong_fract; // expected-error{{'long long _Fract' is invalid}}
9unsigned long long _Fract u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
10
11_Sat long long _Accum sat_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
12_Sat unsigned long long _Accum sat_u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
13_Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
14_Sat unsigned long long _Fract sat_u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
15
Leonard Chanf921d852018-06-04 16:07:52 +000016
17/* Although _Complex types work with floating point numbers, the extension
18 * provides no info for complex fixed point types. */
19
20_Complex signed short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
21_Complex signed _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
22_Complex signed long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
23_Complex unsigned short _Accum cmplx_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
24_Complex unsigned _Accum cmplx_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
25_Complex unsigned long _Accum cmplx_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
26_Complex short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
27_Complex _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
28_Complex long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
29
Leonard Chanab80f3c2018-06-14 14:53:51 +000030_Complex signed short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
31_Complex signed _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
32_Complex signed long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
33_Complex unsigned short _Fract cmplx_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
34_Complex unsigned _Fract cmplx_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
35_Complex unsigned long _Fract cmplx_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
36_Complex short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
37_Complex _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
38_Complex long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
39
40_Complex _Sat signed short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
41_Complex _Sat signed _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
42_Complex _Sat signed long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
43_Complex _Sat unsigned short _Accum cmplx_sat_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
44_Complex _Sat unsigned _Accum cmplx_sat_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
45_Complex _Sat unsigned long _Accum cmplx_sat_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
46_Complex _Sat short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
47_Complex _Sat _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
48_Complex _Sat long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
49
50_Complex signed short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
51_Complex signed _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
52_Complex signed long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
53_Complex unsigned short _Fract cmplx_sat_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
54_Complex unsigned _Fract cmplx_sat_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
55_Complex unsigned long _Fract cmplx_sat_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
56_Complex short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
57_Complex _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
58_Complex long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
59
Leonard Chanf921d852018-06-04 16:07:52 +000060/* Bad combinations */
61float _Accum f_accum; // expected-error{{cannot combine with previous 'float' declaration specifier}}
62double _Accum d_accum; // expected-error{{cannot combine with previous 'double' declaration specifier}}
63_Bool _Accum b_accum; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
64char _Accum c_accum; // expected-error{{cannot combine with previous 'char' declaration specifier}}
65int _Accum i_accum; // expected-error{{cannot combine with previous 'int' declaration specifier}}
Leonard Chanab80f3c2018-06-14 14:53:51 +000066
67float _Fract f_fract; // expected-error{{cannot combine with previous 'float' declaration specifier}}
68double _Fract d_fract; // expected-error{{cannot combine with previous 'double' declaration specifier}}
69_Bool _Fract b_fract; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
70char _Fract c_fract; // expected-error{{cannot combine with previous 'char' declaration specifier}}
71int _Fract i_fract; // expected-error{{cannot combine with previous 'int' declaration specifier}}
72
73/* Bad saturated combinations */
74_Sat float f; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'float'}}
75_Sat double d; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'double'}}
76_Sat _Bool b; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not '_Bool'}}
77_Sat char c; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'char'}}
78_Sat int i; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
79_Sat _Sat _Fract fract; // expected-warning{{duplicate '_Sat' declaration specifier}}
80
Leonard Chandb01c3a2018-06-20 17:19:40 +000081
82/* Literals that cannot fit into types */
83signed short _Accum s_short_accum = 256.0hk; // expected-error{{this value is too large for this fixed point type}}
84unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{this value is too large for this fixed point type}}
85signed _Accum s_accum = 65536.0k; // expected-error{{this value is too large for this fixed point type}}
86unsigned _Accum u_accum = 65536.0uk; // expected-error{{this value is too large for this fixed point type}}
87signed long _Accum s_long_accum = 4294967296.0lk; // expected-error{{this value is too large for this fixed point type}}
88unsigned long _Accum u_long_accum = 4294967296.0ulk; // expected-error{{this value is too large for this fixed point type}}
89
90// Large values from decimal exponents
91short _Accum short_accum_exp = 2.56e2hk; // expected-error{{this value is too large for this fixed point type}}
92_Accum accum_exp = 6.5536e4k; // expected-error{{this value is too large for this fixed point type}}
93long _Accum long_accum_exp = 4.294967296e9lk; // expected-error{{this value is too large for this fixed point type}}
94unsigned short _Accum u_short_accum_exp = 2.56e2uhk; // expected-error{{this value is too large for this fixed point type}}
95unsigned _Accum u_accum_exp = 6.5536e4uk; // expected-error{{this value is too large for this fixed point type}}
96unsigned long _Accum u_long_accum_exp = 4.294967296e9ulk; // expected-error{{this value is too large for this fixed point type}}
97
98// Large value from hexidecimal exponents
99short _Accum short_accum_hex_exp = 0x1p8hk; // expected-error{{this value is too large for this fixed point type}}
100_Accum accum_hex_exp = 0x1p16k; // expected-error{{this value is too large for this fixed point type}}
101long _Accum long_accum_hex_exp = 0x1p32lk; // expected-error{{this value is too large for this fixed point type}}
102unsigned short _Accum u_short_accum_hex_exp = 0x1p8uhk; // expected-error{{this value is too large for this fixed point type}}
103unsigned _Accum u_accum_hex_exp = 0x1p16uk; // expected-error{{this value is too large for this fixed point type}}
104unsigned long _Accum u_long_accum_hex_exp = 0x1p32ulk; // expected-error{{this value is too large for this fixed point type}}
105
106// Very large exponent
107_Accum x = 1e1000000000000000000000000000000000k; // expected-error{{this value is too large for this fixed point type}}
108
109/* Although _Fract's cannot equal 1, _Fract literals written as 1 are allowed
110 * and the underlying value represents the max value for that _Fract type. */
111short _Fract short_fract_above_1 = 1.1hr; // expected-error{{this value is too large for this fixed point type}}
112_Fract fract_above_1 = 1.1r; // expected-error{{this value is too large for this fixed point type}}
113long _Fract long_fract_above_1 = 1.1lr; // expected-error{{this value is too large for this fixed point type}}
114unsigned short _Fract u_short_fract_above_1 = 1.1uhr; // expected-error{{this value is too large for this fixed point type}}
115unsigned _Fract u_fract_above_1 = 1.1ur; // expected-error{{this value is too large for this fixed point type}}
116unsigned long _Fract u_long_fract_above_1 = 1.1ulr; // expected-error{{this value is too large for this fixed point type}}
117
118short _Fract short_fract_hex_exp = 0x0.fp1hr; // expected-error{{this value is too large for this fixed point type}}
119_Fract fract_hex_exp = 0x0.fp1r; // expected-error{{this value is too large for this fixed point type}}
120long _Fract long_fract_hex_exp = 0x0.fp1lr; // expected-error{{this value is too large for this fixed point type}}
121unsigned short _Fract u_short_fract_hex_exp = 0x0.fp1uhr; // expected-error{{this value is too large for this fixed point type}}
122unsigned _Fract u_fract_hex_exp = 0x0.fp1ur; // expected-error{{this value is too large for this fixed point type}}
123unsigned long _Fract u_long_fract_hex_exp = 0x0.fp1ulr; // expected-error{{this value is too large for this fixed point type}}
124
Leonard Chanab80f3c2018-06-14 14:53:51 +0000125/* Do not allow typedef to be used with typedef'd types */
126typedef short _Fract shortfract_t;
127typedef short _Accum shortaccum_t;
128typedef _Fract fract_t;
129typedef _Accum accum_t;
130typedef long _Fract longfract_t;
131typedef long _Accum longaccum_t;
132_Sat shortfract_t td_sat_short_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
133_Sat shortaccum_t td_sat_short_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
134_Sat fract_t td_sat_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
135_Sat accum_t td_sat_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
136_Sat longfract_t td_sat_long_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
137_Sat longaccum_t td_sat_long_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
Leonard Chandb01c3a2018-06-20 17:19:40 +0000138
139/* Bad suffixes */
140_Accum fk = 1.0fk; // expected-error{{invalid suffix 'fk' on integer constant}}
141_Accum kk = 1.0kk; // expected-error{{invalid suffix 'kk' on integer constant}}
142_Accum rk = 1.0rk; // expected-error{{invalid suffix 'rk' on integer constant}}
143_Accum rk = 1.0rr; // expected-error{{invalid suffix 'rr' on integer constant}}
144_Accum qk = 1.0qr; // expected-error{{invalid suffix 'qr' on integer constant}}
145
146/* Using wrong exponent notation */
147_Accum dec_with_hex_exp1 = 0.1p10k; // expected-error{{invalid suffix 'p10k' on integer constant}}
148_Accum dec_with_hex_exp2 = 0.1P10k; // expected-error{{invalid suffix 'P10k' on integer constant}}
149_Accum hex_with_dex_exp1 = 0x0.1e10k; // expected-error{{hexadecimal floating constant requires an exponent}}
150_Accum hex_with_dex_exp2 = 0x0.1E10k; // expected-error{{hexadecimal floating constant requires an exponent}}
Leonard Chane5597ad2018-07-17 14:58:49 +0000151
152void CheckSuffixOnIntegerLiterals() {
153 _Accum short_acc_int;
154 _Accum acc_int;
155 _Accum long_acc_int;
156
157 _Accum u_short_acc_int;
158 _Accum u_acc_int;
159 _Accum u_long_acc_int;
160
161 _Fract short_fract_int;
162 _Fract fract_int;
163 _Fract long_fract_int;
164
165 _Fract u_short_fract_int;
166 _Fract u_fract_int;
167 _Fract u_long_fract_int;
168
169 // Decimal integer literals (non-zero)
170 short_acc_int = 10hk; // expected-error{{invalid suffix 'hk' on integer constant}}
171 acc_int = 10k; // expected-error{{invalid suffix 'k' on integer constant}}
172 long_acc_int = 10lk; // expected-error{{invalid suffix 'lk' on integer constant}}
173
174 u_short_acc_int = 10uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
175 u_acc_int = 10uk; // expected-error{{invalid suffix 'uk' on integer constant}}
176 u_long_acc_int = 10ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
177
178 short_fract_int = 10hr; // expected-error{{invalid suffix 'hr' on integer constant}}
179 fract_int = 10r; // expected-error{{invalid suffix 'r' on integer constant}}
180 long_fract_int = 10lr; // expected-error{{invalid suffix 'lr' on integer constant}}
181
182 u_short_fract_int = 10uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
183 u_fract_int = 10ur; // expected-error{{invalid suffix 'ur' on integer constant}}
184 u_long_fract_int = 10ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
185
186 // Decimal integer literals (0)
187 short_acc_int = 0hk; // expected-error{{invalid suffix 'hk' on integer constant}}
188 acc_int = 0k; // expected-error{{invalid suffix 'k' on integer constant}}
189 long_acc_int = 0lk; // expected-error{{invalid suffix 'lk' on integer constant}}
190
191 // Decimal integer literals (large number)
192 acc_int = 999999999999999999k; // expected-error{{invalid suffix 'k' on integer constant}}
193 fract_int = 999999999999999999r; // expected-error{{invalid suffix 'r' on integer constant}}
194
195 // Octal integer literals
196 short_acc_int = 010hk; // expected-error{{invalid suffix 'hk' on integer constant}}
197 acc_int = 010k; // expected-error{{invalid suffix 'k' on integer constant}}
198 long_acc_int = 010lk; // expected-error{{invalid suffix 'lk' on integer constant}}
199
200 u_short_acc_int = 010uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
201 u_acc_int = 010uk; // expected-error{{invalid suffix 'uk' on integer constant}}
202 u_long_acc_int = 010ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
203
204 short_fract_int = 010hr; // expected-error{{invalid suffix 'hr' on integer constant}}
205 fract_int = 010r; // expected-error{{invalid suffix 'r' on integer constant}}
206 long_fract_int = 010lr; // expected-error{{invalid suffix 'lr' on integer constant}}
207
208 u_short_fract_int = 010uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
209 u_fract_int = 010ur; // expected-error{{invalid suffix 'ur' on integer constant}}
210 u_long_fract_int = 010ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
211
212 // Hexadecimal integer literals
213 short_acc_int = 0x10hk; // expected-error{{invalid suffix 'hk' on integer constant}}
214 acc_int = 0x10k; // expected-error{{invalid suffix 'k' on integer constant}}
215 long_acc_int = 0x10lk; // expected-error{{invalid suffix 'lk' on integer constant}}
216
217 u_short_acc_int = 0x10uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
218 u_acc_int = 0x10uk; // expected-error{{invalid suffix 'uk' on integer constant}}
219 u_long_acc_int = 0x10ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
220
221 short_fract_int = 0x10hr; // expected-error{{invalid suffix 'hr' on integer constant}}
222 fract_int = 0x10r; // expected-error{{invalid suffix 'r' on integer constant}}
223 long_fract_int = 0x10lr; // expected-error{{invalid suffix 'lr' on integer constant}}
224
225 u_short_fract_int = 0x10uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
226 u_fract_int = 0x10ur; // expected-error{{invalid suffix 'ur' on integer constant}}
227 u_long_fract_int = 0x10ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
228
229 // Using auto
230 auto auto_fract = 0r; // expected-error{{invalid suffix 'r' on integer constant}}
231 // expected-warning@-1{{type specifier missing, defaults to 'int'}}
232 auto auto_accum = 0k; // expected-error{{invalid suffix 'k' on integer constant}}
233 // expected-warning@-1{{type specifier missing, defaults to 'int'}}
234}
Leonard Chand3f3e162019-01-18 21:04:25 +0000235
Leonard Chan8f7caae2019-03-06 00:28:43 +0000236// Ok conversions
237int i_const = -2.5hk;
238_Sat short _Accum sat_sa_const2 = 256.0k;
239_Sat unsigned short _Accum sat_usa_const = -1.0hk;
240short _Accum sa_const3 = 2;
241short _Accum sa_const4 = -2;
242
Leonard Chand3f3e162019-01-18 21:04:25 +0000243// Overflow
244short _Accum sa_const = 256.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}}
245short _Fract sf_const = 1.0hk; // expected-warning{{implicit conversion from 1.0 cannot fit within the range of values for 'short _Fract'}}
246unsigned _Accum ua_const = -1.0k; // expected-warning{{implicit conversion from -1.0 cannot fit within the range of values for 'unsigned _Accum'}}
247short _Accum sa_const2 = 128.0k + 128.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}}
Leonard Chan8f7caae2019-03-06 00:28:43 +0000248short s_const = 65536.0lk; // expected-warning{{implicit conversion from 65536.0 cannot fit within the range of values for 'short'}}
249unsigned u_const = -2.5hk; // expected-warning{{implicit conversion from -2.5 cannot fit within the range of values for 'unsigned int'}}
250char c_const = 256.0uk; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'char'}}
251short _Accum sa_const5 = 256; // expected-warning{{implicit conversion from 256 cannot fit within the range of values for 'short _Accum'}}
252unsigned short _Accum usa_const2 = -2; // expected-warning{{implicit conversion from -2 cannot fit within the range of values for 'unsigned short _Accum'}}