1f921d854SLeonard Chan // RUN: %clang_cc1 -verify -ffixed-point %s
2f921d854SLeonard Chan
3f921d854SLeonard Chan /* We do not yet support long long. No recommended bit widths are given for this
4f921d854SLeonard Chan * size. */
5f921d854SLeonard Chan
6f921d854SLeonard Chan long long _Accum longlong_accum; // expected-error{{'long long _Accum' is invalid}}
7f921d854SLeonard Chan unsigned long long _Accum u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
8ab80f3c8SLeonard Chan long long _Fract longlong_fract; // expected-error{{'long long _Fract' is invalid}}
9ab80f3c8SLeonard Chan unsigned long long _Fract u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
10ab80f3c8SLeonard Chan
11ab80f3c8SLeonard Chan _Sat long long _Accum sat_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
12ab80f3c8SLeonard Chan _Sat unsigned long long _Accum sat_u_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
13ab80f3c8SLeonard Chan _Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
14ab80f3c8SLeonard Chan _Sat unsigned long long _Fract sat_u_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
15ab80f3c8SLeonard Chan
16f921d854SLeonard Chan
17f921d854SLeonard Chan /* Although _Complex types work with floating point numbers, the extension
18f921d854SLeonard Chan * provides no info for complex fixed point types. */
19f921d854SLeonard Chan
20f921d854SLeonard Chan _Complex signed short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
21f921d854SLeonard Chan _Complex signed _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
22f921d854SLeonard Chan _Complex signed long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
23f921d854SLeonard Chan _Complex unsigned short _Accum cmplx_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
24f921d854SLeonard Chan _Complex unsigned _Accum cmplx_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
25f921d854SLeonard Chan _Complex unsigned long _Accum cmplx_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
26f921d854SLeonard Chan _Complex short _Accum cmplx_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
27f921d854SLeonard Chan _Complex _Accum cmplx_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
28f921d854SLeonard Chan _Complex long _Accum cmplx_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
29f921d854SLeonard Chan
30ab80f3c8SLeonard Chan _Complex signed short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
31ab80f3c8SLeonard Chan _Complex signed _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
32ab80f3c8SLeonard Chan _Complex signed long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
33ab80f3c8SLeonard Chan _Complex unsigned short _Fract cmplx_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
34ab80f3c8SLeonard Chan _Complex unsigned _Fract cmplx_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
35ab80f3c8SLeonard Chan _Complex unsigned long _Fract cmplx_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
36ab80f3c8SLeonard Chan _Complex short _Fract cmplx_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
37ab80f3c8SLeonard Chan _Complex _Fract cmplx_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
38ab80f3c8SLeonard Chan _Complex long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
39ab80f3c8SLeonard Chan
40ab80f3c8SLeonard Chan _Complex _Sat signed short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
41ab80f3c8SLeonard Chan _Complex _Sat signed _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
42ab80f3c8SLeonard Chan _Complex _Sat signed long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
43ab80f3c8SLeonard Chan _Complex _Sat unsigned short _Accum cmplx_sat_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
44ab80f3c8SLeonard Chan _Complex _Sat unsigned _Accum cmplx_sat_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
45ab80f3c8SLeonard Chan _Complex _Sat unsigned long _Accum cmplx_sat_u_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
46ab80f3c8SLeonard Chan _Complex _Sat short _Accum cmplx_sat_s_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
47ab80f3c8SLeonard Chan _Complex _Sat _Accum cmplx_sat_s_accum; // expected-error{{'_Complex _Accum' is invalid}}
48ab80f3c8SLeonard Chan _Complex _Sat long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
49ab80f3c8SLeonard Chan
50ab80f3c8SLeonard Chan _Complex signed short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
51ab80f3c8SLeonard Chan _Complex signed _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
52ab80f3c8SLeonard Chan _Complex signed long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
53ab80f3c8SLeonard Chan _Complex unsigned short _Fract cmplx_sat_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
54ab80f3c8SLeonard Chan _Complex unsigned _Fract cmplx_sat_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
55ab80f3c8SLeonard Chan _Complex unsigned long _Fract cmplx_sat_u_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
56ab80f3c8SLeonard Chan _Complex short _Fract cmplx_sat_s_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
57ab80f3c8SLeonard Chan _Complex _Fract cmplx_sat_s_fract; // expected-error{{'_Complex _Fract' is invalid}}
58ab80f3c8SLeonard Chan _Complex long _Fract cmplx_sat_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
59ab80f3c8SLeonard Chan
60f921d854SLeonard Chan /* Bad combinations */
61f921d854SLeonard Chan float _Accum f_accum; // expected-error{{cannot combine with previous 'float' declaration specifier}}
62f921d854SLeonard Chan double _Accum d_accum; // expected-error{{cannot combine with previous 'double' declaration specifier}}
63f921d854SLeonard Chan _Bool _Accum b_accum; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
64f921d854SLeonard Chan char _Accum c_accum; // expected-error{{cannot combine with previous 'char' declaration specifier}}
65f921d854SLeonard Chan int _Accum i_accum; // expected-error{{cannot combine with previous 'int' declaration specifier}}
66ab80f3c8SLeonard Chan
67ab80f3c8SLeonard Chan float _Fract f_fract; // expected-error{{cannot combine with previous 'float' declaration specifier}}
68ab80f3c8SLeonard Chan double _Fract d_fract; // expected-error{{cannot combine with previous 'double' declaration specifier}}
69ab80f3c8SLeonard Chan _Bool _Fract b_fract; // expected-error{{cannot combine with previous '_Bool' declaration specifier}}
70ab80f3c8SLeonard Chan char _Fract c_fract; // expected-error{{cannot combine with previous 'char' declaration specifier}}
71ab80f3c8SLeonard Chan int _Fract i_fract; // expected-error{{cannot combine with previous 'int' declaration specifier}}
72ab80f3c8SLeonard Chan
73ab80f3c8SLeonard Chan /* Bad saturated combinations */
74ab80f3c8SLeonard Chan _Sat float f; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'float'}}
75ab80f3c8SLeonard Chan _Sat double d; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'double'}}
76ab80f3c8SLeonard Chan _Sat _Bool b; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not '_Bool'}}
77ab80f3c8SLeonard Chan _Sat char c; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'char'}}
78ab80f3c8SLeonard Chan _Sat int i; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
79ab80f3c8SLeonard Chan _Sat _Sat _Fract fract; // expected-warning{{duplicate '_Sat' declaration specifier}}
80ab80f3c8SLeonard Chan
81db01c3adSLeonard Chan
82db01c3adSLeonard Chan /* Literals that cannot fit into types */
83db01c3adSLeonard Chan signed short _Accum s_short_accum = 256.0hk; // expected-error{{this value is too large for this fixed point type}}
84db01c3adSLeonard Chan unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{this value is too large for this fixed point type}}
85db01c3adSLeonard Chan signed _Accum s_accum = 65536.0k; // expected-error{{this value is too large for this fixed point type}}
86db01c3adSLeonard Chan unsigned _Accum u_accum = 65536.0uk; // expected-error{{this value is too large for this fixed point type}}
87db01c3adSLeonard Chan signed long _Accum s_long_accum = 4294967296.0lk; // expected-error{{this value is too large for this fixed point type}}
88db01c3adSLeonard Chan unsigned long _Accum u_long_accum = 4294967296.0ulk; // expected-error{{this value is too large for this fixed point type}}
89db01c3adSLeonard Chan
90db01c3adSLeonard Chan // Large values from decimal exponents
91db01c3adSLeonard Chan short _Accum short_accum_exp = 2.56e2hk; // expected-error{{this value is too large for this fixed point type}}
92db01c3adSLeonard Chan _Accum accum_exp = 6.5536e4k; // expected-error{{this value is too large for this fixed point type}}
93db01c3adSLeonard Chan long _Accum long_accum_exp = 4.294967296e9lk; // expected-error{{this value is too large for this fixed point type}}
94db01c3adSLeonard Chan unsigned short _Accum u_short_accum_exp = 2.56e2uhk; // expected-error{{this value is too large for this fixed point type}}
95db01c3adSLeonard Chan unsigned _Accum u_accum_exp = 6.5536e4uk; // expected-error{{this value is too large for this fixed point type}}
96db01c3adSLeonard Chan unsigned long _Accum u_long_accum_exp = 4.294967296e9ulk; // expected-error{{this value is too large for this fixed point type}}
97db01c3adSLeonard Chan
98db01c3adSLeonard Chan // Large value from hexidecimal exponents
99db01c3adSLeonard Chan short _Accum short_accum_hex_exp = 0x1p8hk; // expected-error{{this value is too large for this fixed point type}}
100db01c3adSLeonard Chan _Accum accum_hex_exp = 0x1p16k; // expected-error{{this value is too large for this fixed point type}}
101db01c3adSLeonard Chan long _Accum long_accum_hex_exp = 0x1p32lk; // expected-error{{this value is too large for this fixed point type}}
102db01c3adSLeonard Chan unsigned short _Accum u_short_accum_hex_exp = 0x1p8uhk; // expected-error{{this value is too large for this fixed point type}}
103db01c3adSLeonard Chan unsigned _Accum u_accum_hex_exp = 0x1p16uk; // expected-error{{this value is too large for this fixed point type}}
104db01c3adSLeonard Chan unsigned long _Accum u_long_accum_hex_exp = 0x1p32ulk; // expected-error{{this value is too large for this fixed point type}}
105db01c3adSLeonard Chan
106db01c3adSLeonard Chan // Very large exponent
107db01c3adSLeonard Chan _Accum x = 1e1000000000000000000000000000000000k; // expected-error{{this value is too large for this fixed point type}}
108db01c3adSLeonard Chan
109db01c3adSLeonard Chan /* Although _Fract's cannot equal 1, _Fract literals written as 1 are allowed
110db01c3adSLeonard Chan * and the underlying value represents the max value for that _Fract type. */
111db01c3adSLeonard Chan short _Fract short_fract_above_1 = 1.1hr; // expected-error{{this value is too large for this fixed point type}}
112db01c3adSLeonard Chan _Fract fract_above_1 = 1.1r; // expected-error{{this value is too large for this fixed point type}}
113db01c3adSLeonard Chan long _Fract long_fract_above_1 = 1.1lr; // expected-error{{this value is too large for this fixed point type}}
114db01c3adSLeonard Chan unsigned short _Fract u_short_fract_above_1 = 1.1uhr; // expected-error{{this value is too large for this fixed point type}}
115db01c3adSLeonard Chan unsigned _Fract u_fract_above_1 = 1.1ur; // expected-error{{this value is too large for this fixed point type}}
116db01c3adSLeonard Chan unsigned long _Fract u_long_fract_above_1 = 1.1ulr; // expected-error{{this value is too large for this fixed point type}}
117db01c3adSLeonard Chan
118db01c3adSLeonard Chan short _Fract short_fract_hex_exp = 0x0.fp1hr; // expected-error{{this value is too large for this fixed point type}}
119db01c3adSLeonard Chan _Fract fract_hex_exp = 0x0.fp1r; // expected-error{{this value is too large for this fixed point type}}
120db01c3adSLeonard Chan long _Fract long_fract_hex_exp = 0x0.fp1lr; // expected-error{{this value is too large for this fixed point type}}
121db01c3adSLeonard Chan unsigned short _Fract u_short_fract_hex_exp = 0x0.fp1uhr; // expected-error{{this value is too large for this fixed point type}}
122db01c3adSLeonard Chan unsigned _Fract u_fract_hex_exp = 0x0.fp1ur; // expected-error{{this value is too large for this fixed point type}}
123db01c3adSLeonard Chan unsigned long _Fract u_long_fract_hex_exp = 0x0.fp1ulr; // expected-error{{this value is too large for this fixed point type}}
124db01c3adSLeonard Chan
125ab80f3c8SLeonard Chan /* Do not allow typedef to be used with typedef'd types */
126ab80f3c8SLeonard Chan typedef short _Fract shortfract_t;
127ab80f3c8SLeonard Chan typedef short _Accum shortaccum_t;
128ab80f3c8SLeonard Chan typedef _Fract fract_t;
129ab80f3c8SLeonard Chan typedef _Accum accum_t;
130ab80f3c8SLeonard Chan typedef long _Fract longfract_t;
131ab80f3c8SLeonard Chan typedef long _Accum longaccum_t;
132ab80f3c8SLeonard Chan _Sat shortfract_t td_sat_short_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
133ab80f3c8SLeonard Chan _Sat shortaccum_t td_sat_short_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
134ab80f3c8SLeonard Chan _Sat fract_t td_sat_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
135ab80f3c8SLeonard Chan _Sat accum_t td_sat_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
136ab80f3c8SLeonard Chan _Sat longfract_t td_sat_long_fract; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
137ab80f3c8SLeonard Chan _Sat longaccum_t td_sat_long_accum; // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'type-name'}}
138db01c3adSLeonard Chan
139db01c3adSLeonard Chan /* Bad suffixes */
140ef374440SLeonard Chan _Accum fk = 1.0fk; // expected-error{{invalid suffix 'fk' on fixed-point constant}}
141ef374440SLeonard Chan _Accum kk = 1.0kk; // expected-error{{invalid suffix 'kk' on fixed-point constant}}
142ef374440SLeonard Chan _Accum rk = 1.0rk; // expected-error{{invalid suffix 'rk' on fixed-point constant}}
143ef374440SLeonard Chan _Accum rk = 1.0rr; // expected-error{{invalid suffix 'rr' on fixed-point constant}}
144ef374440SLeonard Chan _Accum qk = 1.0qr; // expected-error{{invalid suffix 'qr' on fixed-point constant}}
145db01c3adSLeonard Chan
146db01c3adSLeonard Chan /* Using wrong exponent notation */
147ef374440SLeonard Chan _Accum dec_with_hex_exp1 = 0.1p10k; // expected-error{{invalid suffix 'p10k' on fixed-point constant}}
148ef374440SLeonard Chan _Accum dec_with_hex_exp2 = 0.1P10k; // expected-error{{invalid suffix 'P10k' on fixed-point constant}}
149db01c3adSLeonard Chan _Accum hex_with_dex_exp1 = 0x0.1e10k; // expected-error{{hexadecimal floating constant requires an exponent}}
150db01c3adSLeonard Chan _Accum hex_with_dex_exp2 = 0x0.1E10k; // expected-error{{hexadecimal floating constant requires an exponent}}
151e5597ad9SLeonard Chan
CheckSuffixOnIntegerLiterals(void)1527de71613SAaron Ballman void CheckSuffixOnIntegerLiterals(void) {
153e5597ad9SLeonard Chan _Accum short_acc_int;
154e5597ad9SLeonard Chan _Accum acc_int;
155e5597ad9SLeonard Chan _Accum long_acc_int;
156e5597ad9SLeonard Chan
157e5597ad9SLeonard Chan _Accum u_short_acc_int;
158e5597ad9SLeonard Chan _Accum u_acc_int;
159e5597ad9SLeonard Chan _Accum u_long_acc_int;
160e5597ad9SLeonard Chan
161e5597ad9SLeonard Chan _Fract short_fract_int;
162e5597ad9SLeonard Chan _Fract fract_int;
163e5597ad9SLeonard Chan _Fract long_fract_int;
164e5597ad9SLeonard Chan
165e5597ad9SLeonard Chan _Fract u_short_fract_int;
166e5597ad9SLeonard Chan _Fract u_fract_int;
167e5597ad9SLeonard Chan _Fract u_long_fract_int;
168e5597ad9SLeonard Chan
169e5597ad9SLeonard Chan // Decimal integer literals (non-zero)
170e5597ad9SLeonard Chan short_acc_int = 10hk; // expected-error{{invalid suffix 'hk' on integer constant}}
171e5597ad9SLeonard Chan acc_int = 10k; // expected-error{{invalid suffix 'k' on integer constant}}
172e5597ad9SLeonard Chan long_acc_int = 10lk; // expected-error{{invalid suffix 'lk' on integer constant}}
173e5597ad9SLeonard Chan
174e5597ad9SLeonard Chan u_short_acc_int = 10uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
175e5597ad9SLeonard Chan u_acc_int = 10uk; // expected-error{{invalid suffix 'uk' on integer constant}}
176e5597ad9SLeonard Chan u_long_acc_int = 10ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
177e5597ad9SLeonard Chan
178e5597ad9SLeonard Chan short_fract_int = 10hr; // expected-error{{invalid suffix 'hr' on integer constant}}
179e5597ad9SLeonard Chan fract_int = 10r; // expected-error{{invalid suffix 'r' on integer constant}}
180e5597ad9SLeonard Chan long_fract_int = 10lr; // expected-error{{invalid suffix 'lr' on integer constant}}
181e5597ad9SLeonard Chan
182e5597ad9SLeonard Chan u_short_fract_int = 10uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
183e5597ad9SLeonard Chan u_fract_int = 10ur; // expected-error{{invalid suffix 'ur' on integer constant}}
184e5597ad9SLeonard Chan u_long_fract_int = 10ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
185e5597ad9SLeonard Chan
186e5597ad9SLeonard Chan // Decimal integer literals (0)
187e5597ad9SLeonard Chan short_acc_int = 0hk; // expected-error{{invalid suffix 'hk' on integer constant}}
188e5597ad9SLeonard Chan acc_int = 0k; // expected-error{{invalid suffix 'k' on integer constant}}
189e5597ad9SLeonard Chan long_acc_int = 0lk; // expected-error{{invalid suffix 'lk' on integer constant}}
190e5597ad9SLeonard Chan
191e5597ad9SLeonard Chan // Decimal integer literals (large number)
192e5597ad9SLeonard Chan acc_int = 999999999999999999k; // expected-error{{invalid suffix 'k' on integer constant}}
193e5597ad9SLeonard Chan fract_int = 999999999999999999r; // expected-error{{invalid suffix 'r' on integer constant}}
194e5597ad9SLeonard Chan
195e5597ad9SLeonard Chan // Octal integer literals
196e5597ad9SLeonard Chan short_acc_int = 010hk; // expected-error{{invalid suffix 'hk' on integer constant}}
197e5597ad9SLeonard Chan acc_int = 010k; // expected-error{{invalid suffix 'k' on integer constant}}
198e5597ad9SLeonard Chan long_acc_int = 010lk; // expected-error{{invalid suffix 'lk' on integer constant}}
199e5597ad9SLeonard Chan
200e5597ad9SLeonard Chan u_short_acc_int = 010uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
201e5597ad9SLeonard Chan u_acc_int = 010uk; // expected-error{{invalid suffix 'uk' on integer constant}}
202e5597ad9SLeonard Chan u_long_acc_int = 010ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
203e5597ad9SLeonard Chan
204e5597ad9SLeonard Chan short_fract_int = 010hr; // expected-error{{invalid suffix 'hr' on integer constant}}
205e5597ad9SLeonard Chan fract_int = 010r; // expected-error{{invalid suffix 'r' on integer constant}}
206e5597ad9SLeonard Chan long_fract_int = 010lr; // expected-error{{invalid suffix 'lr' on integer constant}}
207e5597ad9SLeonard Chan
208e5597ad9SLeonard Chan u_short_fract_int = 010uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
209e5597ad9SLeonard Chan u_fract_int = 010ur; // expected-error{{invalid suffix 'ur' on integer constant}}
210e5597ad9SLeonard Chan u_long_fract_int = 010ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
211e5597ad9SLeonard Chan
212e5597ad9SLeonard Chan // Hexadecimal integer literals
213e5597ad9SLeonard Chan short_acc_int = 0x10hk; // expected-error{{invalid suffix 'hk' on integer constant}}
214e5597ad9SLeonard Chan acc_int = 0x10k; // expected-error{{invalid suffix 'k' on integer constant}}
215e5597ad9SLeonard Chan long_acc_int = 0x10lk; // expected-error{{invalid suffix 'lk' on integer constant}}
216e5597ad9SLeonard Chan
217e5597ad9SLeonard Chan u_short_acc_int = 0x10uhk; // expected-error{{invalid suffix 'uhk' on integer constant}}
218e5597ad9SLeonard Chan u_acc_int = 0x10uk; // expected-error{{invalid suffix 'uk' on integer constant}}
219e5597ad9SLeonard Chan u_long_acc_int = 0x10ulk; // expected-error{{invalid suffix 'ulk' on integer constant}}
220e5597ad9SLeonard Chan
221e5597ad9SLeonard Chan short_fract_int = 0x10hr; // expected-error{{invalid suffix 'hr' on integer constant}}
222e5597ad9SLeonard Chan fract_int = 0x10r; // expected-error{{invalid suffix 'r' on integer constant}}
223e5597ad9SLeonard Chan long_fract_int = 0x10lr; // expected-error{{invalid suffix 'lr' on integer constant}}
224e5597ad9SLeonard Chan
225e5597ad9SLeonard Chan u_short_fract_int = 0x10uhr; // expected-error{{invalid suffix 'uhr' on integer constant}}
226e5597ad9SLeonard Chan u_fract_int = 0x10ur; // expected-error{{invalid suffix 'ur' on integer constant}}
227e5597ad9SLeonard Chan u_long_fract_int = 0x10ulr; // expected-error{{invalid suffix 'ulr' on integer constant}}
228e5597ad9SLeonard Chan
229e5597ad9SLeonard Chan // Using auto
230e5597ad9SLeonard Chan auto auto_fract = 0r; // expected-error{{invalid suffix 'r' on integer constant}}
231*c0141f3cSAaron Ballman // expected-warning@-1{{type specifier missing, defaults to 'int'}}
232e5597ad9SLeonard Chan auto auto_accum = 0k; // expected-error{{invalid suffix 'k' on integer constant}}
233*c0141f3cSAaron Ballman // expected-warning@-1{{type specifier missing, defaults to 'int'}}
234e5597ad9SLeonard Chan }
235d3f3e162SLeonard Chan
2368f7caae0SLeonard Chan // Ok conversions
2378f7caae0SLeonard Chan int i_const = -2.5hk;
2388f7caae0SLeonard Chan _Sat short _Accum sat_sa_const2 = 256.0k;
2398f7caae0SLeonard Chan _Sat unsigned short _Accum sat_usa_const = -1.0hk;
2408f7caae0SLeonard Chan short _Accum sa_const3 = 2;
2418f7caae0SLeonard Chan short _Accum sa_const4 = -2;
2428f7caae0SLeonard Chan
243d3f3e162SLeonard Chan // Overflow
244d3f3e162SLeonard Chan short _Accum sa_const = 256.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}}
245d3f3e162SLeonard Chan short _Fract sf_const = 1.0hk; // expected-warning{{implicit conversion from 1.0 cannot fit within the range of values for 'short _Fract'}}
246d3f3e162SLeonard Chan unsigned _Accum ua_const = -1.0k; // expected-warning{{implicit conversion from -1.0 cannot fit within the range of values for 'unsigned _Accum'}}
247d3f3e162SLeonard Chan short _Accum sa_const2 = 128.0k + 128.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}}
2488f7caae0SLeonard Chan short s_const = 65536.0lk; // expected-warning{{implicit conversion from 65536.0 cannot fit within the range of values for 'short'}}
2498f7caae0SLeonard Chan unsigned u_const = -2.5hk; // expected-warning{{implicit conversion from -2.5 cannot fit within the range of values for 'unsigned int'}}
2508f7caae0SLeonard Chan char c_const = 256.0uk; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'char'}}
2518f7caae0SLeonard Chan short _Accum sa_const5 = 256; // expected-warning{{implicit conversion from 256 cannot fit within the range of values for 'short _Accum'}}
2528f7caae0SLeonard Chan unsigned short _Accum usa_const2 = -2; // expected-warning{{implicit conversion from -2 cannot fit within the range of values for 'unsigned short _Accum'}}
253474177c0SBevin Hansson
254474177c0SBevin Hansson short _Accum add_ovf1 = 255.0hk + 20.0hk; // expected-warning {{overflow in expression; result is -237.0 with type 'short _Accum'}}
255474177c0SBevin Hansson short _Accum add_ovf2 = 10 + 0.5hr; // expected-warning {{overflow in expression; result is 0.5 with type 'short _Fract'}}
256474177c0SBevin Hansson short _Accum sub_ovf1 = 16.0uhk - 32.0uhk; // expected-warning {{overflow in expression; result is 240.0 with type 'unsigned short _Accum'}}
257474177c0SBevin Hansson short _Accum sub_ovf2 = -255.0hk - 20; // expected-warning {{overflow in expression; result is 237.0 with type 'short _Accum'}}
258474177c0SBevin Hansson short _Accum mul_ovf1 = 200.0uhk * 10.0uhk; // expected-warning {{overflow in expression; result is 208.0 with type 'unsigned short _Accum'}}
259474177c0SBevin Hansson short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr); // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
260474177c0SBevin Hansson short _Accum div_ovf1 = 255.0hk / 0.5hk; // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}}
261474177c0SBevin Hansson
262aa0d19a0SBevin Hansson short _Accum shl_ovf1 = 255.0hk << 8; // expected-warning {{overflow in expression; result is -256.0 with type 'short _Accum'}}
263aa0d19a0SBevin Hansson short _Fract shl_ovf2 = -0.25hr << 3; // expected-warning {{overflow in expression; result is 0.0 with type 'short _Fract'}}
264aa0d19a0SBevin Hansson unsigned short _Accum shl_ovf3 = 100.5uhk << 3; // expected-warning {{overflow in expression; result is 36.0 with type 'unsigned short _Accum'}}
265aa0d19a0SBevin Hansson short _Fract shl_ovf4 = 0.25hr << 2; // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
266aa0d19a0SBevin Hansson
267aa0d19a0SBevin Hansson _Accum shl_bw1 = 0.000091552734375k << 32; // expected-warning {{shift count >= width of type}} \
268aa0d19a0SBevin Hansson expected-warning {{overflow in expression; result is -65536.0 with type '_Accum'}}
269aa0d19a0SBevin Hansson unsigned _Fract shl_bw2 = 0.65ur << 16; // expected-warning {{shift count >= width of type}} \
270aa0d19a0SBevin Hansson expected-warning {{overflow in expression; result is 0.0 with type 'unsigned _Fract'}}
271aa0d19a0SBevin Hansson _Sat short _Accum shl_bw3 = (_Sat short _Accum)80.0hk << 17; // expected-warning {{shift count >= width of type}}
272aa0d19a0SBevin Hansson short _Accum shr_bw1 = 1.0hk >> 17; // expected-warning {{shift count >= width of type}}
273aa0d19a0SBevin Hansson
274aa0d19a0SBevin Hansson _Accum shl_neg1 = 25.5k << -5; // expected-warning {{shift count is negative}} \
275aa0d19a0SBevin Hansson // expected-warning {{overflow in expression; result is 0.0 with type '_Accum'}}
276aa0d19a0SBevin Hansson _Accum shr_neg1 = 8.75k >> -9; // expected-warning {{shift count is negative}}
277aa0d19a0SBevin Hansson _Fract shl_neg2 = 0.25r << -17; // expected-warning {{shift count is negative}} \
278aa0d19a0SBevin Hansson // expected-warning {{overflow in expression; result is 0.0 with type '_Fract'}}
279aa0d19a0SBevin Hansson
280474177c0SBevin Hansson // No warnings for saturation
281474177c0SBevin Hansson short _Fract add_sat = (_Sat short _Fract)0.5hr + 0.5hr;
282474177c0SBevin Hansson short _Accum sub_sat = (_Sat short _Accum)-200.0hk - 80.0hk;
283474177c0SBevin Hansson short _Accum mul_sat = (_Sat short _Accum)80.0hk * 10.0hk;
284474177c0SBevin Hansson short _Fract div_sat = (_Sat short _Fract)0.9hr / 0.1hr;
285aa0d19a0SBevin Hansson short _Accum shl_sat = (_Sat short _Accum)200.0hk << 5;
28633bae9c2SBevin Hansson
28733bae9c2SBevin Hansson // Division by zero
28833bae9c2SBevin Hansson short _Accum div_zero = 4.5k / 0.0lr; // expected-error {{initializer element is not a compile-time constant}}
289