c: Support C2x empty initializer braces
[platform/upstream/gcc.git] / gcc / testsuite / gcc.target / i386 / sse2-bfloat16-scalar-typecheck.c
1 /* { dg-do compile } */
2 /* { dg-options "-msse2 -O2" } */
3
4
5 __bf16 glob_bfloat;
6
7 int is_an_int;
8 short is_a_short_int;
9 float is_a_float;
10 float is_a_float16;
11 double is_a_double;
12
13 float *float_ptr;
14
15 __bf16 foo1 (void) { return (__bf16) 0x1234; } /* { dg-error {invalid conversion to type '__bf16'} } */
16 __bf16 foo2 (void) { return (__bf16) (short) 0x1234; } /* { dg-error {invalid conversion to type '__bf16'} } */
17
18 __bf16 footest (__bf16 scalar0)
19 {
20
21   /* Initialisation  */
22
23   __bf16 scalar1_1;
24   __bf16 scalar1_2 = glob_bfloat;
25   __bf16 scalar1_3 = 0;   /* { dg-error {invalid conversion to type '__bf16'} } */
26   __bf16 scalar1_4 = 0.1; /* { dg-error {invalid conversion to type '__bf16'} } */
27   __bf16 scalar1_5 = is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
28   __bf16 scalar1_6 = is_an_int;  /* { dg-error {invalid conversion to type '__bf16'} } */
29   __bf16 scalar1_7 = is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
30   __bf16 scalar1_8 = is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
31   __bf16 scalar1_9 = is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */
32
33   int initi_1_1 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
34   float initi_1_2 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
35   _Float16 initi_1_3 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
36   short initi_1_4 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
37   double initi_1_5 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
38
39   __bf16 scalar2_1 = {};
40   __bf16 scalar2_2 = { glob_bfloat };
41   __bf16 scalar2_3 = { 0 }; /* { dg-error {invalid conversion to type '__bf16'} } */
42   __bf16 scalar2_4 = { 0.1 }; /* { dg-error {invalid conversion to type '__bf16'} } */
43   __bf16 scalar2_5 = { is_a_float }; /* { dg-error {invalid conversion to type '__bf16'} } */
44   __bf16 scalar2_6 = { is_an_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
45   __bf16 scalar2_7 = { is_a_float16 }; /* { dg-error {invalid conversion to type '__bf16'} } */
46   __bf16 scalar2_8 = { is_a_double }; /* { dg-error {invalid conversion to type '__bf16'} } */
47   __bf16 scalar2_9 = { is_a_short_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
48
49   int initi_2_1 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
50   float initi_2_2 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
51   _Float16 initi_2_3 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
52   short initi_2_4 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
53   double initi_2_5 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
54
55   /* Assignments.  */
56
57   glob_bfloat = glob_bfloat;
58   glob_bfloat = 0;   /* { dg-error {invalid conversion to type '__bf16'} } */
59   glob_bfloat = 0.1; /* { dg-error {invalid conversion to type '__bf16'} } */
60   glob_bfloat = is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
61   glob_bfloat = is_an_int; /* { dg-error {invalid conversion to type '__bf16'} } */
62   glob_bfloat = is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
63   glob_bfloat = is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
64   glob_bfloat = is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */
65
66   is_an_int = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
67   is_a_float = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
68   is_a_float16 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
69   is_a_double = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
70   is_a_short_int = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
71
72   /* Casting.  */
73
74   (void) glob_bfloat;
75   (__bf16) glob_bfloat;
76
77   (int) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
78   (float) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
79   (_Float16) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
80   (double) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
81   (short) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
82
83   (__bf16) is_an_int; /* { dg-error {invalid conversion to type '__bf16'} } */
84   (__bf16) is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
85   (__bf16) is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
86   (__bf16) is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
87   (__bf16) is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */
88
89   /* Compound literals.  */
90
91   (__bf16) {};
92   (__bf16) { glob_bfloat };
93   (__bf16) { 0 }; /* { dg-error {invalid conversion to type '__bf16'} } */
94   (__bf16) { 0.1 }; /* { dg-error {invalid conversion to type '__bf16'} } */
95   (__bf16) { is_a_float }; /* { dg-error {invalid conversion to type '__bf16'} } */
96   (__bf16) { is_an_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
97   (__bf16) { is_a_float16 }; /* { dg-error {invalid conversion to type '__bf16'} } */
98   (__bf16) { is_a_double }; /* { dg-error {invalid conversion to type '__bf16'} } */
99   (__bf16) { is_a_short_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
100
101   (int) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
102   (float) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
103   (_Float16) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
104   (double) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
105   (short) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
106
107   /* Arrays and Structs.  */
108
109   typedef __bf16 array_type[2];
110   extern __bf16 extern_array[];
111
112   __bf16 array[2];
113   __bf16 zero_length_array[0];
114   __bf16 empty_init_array[] = {};
115   typedef __bf16 some_other_type[is_an_int];
116
117   struct struct1 {
118     __bf16 a;
119   };
120
121   union union1 {
122     __bf16 a;
123   };
124
125   /* Addressing and dereferencing.  */
126
127   __bf16 *bfloat_ptr = &scalar0;
128   scalar0 = *bfloat_ptr;
129
130   /* Pointer assignment.  */
131
132   __bf16 *bfloat_ptr2 = bfloat_ptr;
133   __bf16 *bfloat_ptr3 = array;
134
135   /* Pointer arithmetic.  */
136
137   ++bfloat_ptr;
138   --bfloat_ptr;
139   bfloat_ptr++;
140   bfloat_ptr--;
141   bfloat_ptr += 1;
142   bfloat_ptr -= 1;
143   bfloat_ptr - bfloat_ptr2;
144   bfloat_ptr = &bfloat_ptr3[0];
145   bfloat_ptr = &bfloat_ptr3[1];
146
147   /* Simple comparison.  */
148   scalar0 > glob_bfloat; /* { dg-error {operation not permitted on type '__bf16'} } */
149   glob_bfloat == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
150   scalar0 > is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
151   is_a_float == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
152   scalar0 > 0; /* { dg-error {operation not permitted on type '__bf16'} } */
153   0 == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
154   scalar0 > 0.1; /* { dg-error {operation not permitted on type '__bf16'} } */
155   0.1 == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
156   scalar0 > is_an_int; /* { dg-error {operation not permitted on type '__bf16'} } */
157   is_an_int == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
158
159   /* Pointer comparison.  */
160
161   bfloat_ptr == &scalar0;
162   bfloat_ptr != &scalar0;
163   bfloat_ptr < &scalar0;
164   bfloat_ptr <= &scalar0;
165   bfloat_ptr > &scalar0;
166   bfloat_ptr >= &scalar0;
167   bfloat_ptr == bfloat_ptr2;
168   bfloat_ptr != bfloat_ptr2;
169   bfloat_ptr < bfloat_ptr2;
170   bfloat_ptr <= bfloat_ptr2;
171   bfloat_ptr > bfloat_ptr2;
172   bfloat_ptr >= bfloat_ptr2;
173
174   /* Conditional expressions.  */
175
176   0 ? scalar0 : scalar0;
177   0 ? scalar0 : is_a_float; /* { dg-error {invalid conversion from type '__bf16'} } */
178   0 ? is_a_float : scalar0; /* { dg-error {invalid conversion from type '__bf16'} } */
179   0 ? scalar0 : 0; /* { dg-error {invalid conversion to type '__bf16'} } */
180   0 ? 0 : scalar0; /* { dg-error {invalid conversion to type '__bf16'} } */
181   0 ? 0.1 : scalar0; /* { dg-error {invalid conversion from type '__bf16'} } */
182   0 ? scalar0 : 0.1; /* { dg-error {invalid conversion from type '__bf16'} } */
183   0 ? bfloat_ptr : bfloat_ptr2;
184   0 ? bfloat_ptr : float_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */
185   0 ? float_ptr : bfloat_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */
186
187   scalar0 ? scalar0 : scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
188   scalar0 ? is_a_float : scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
189   scalar0 ? scalar0 : is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
190   scalar0 ? is_a_float : is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
191
192   /* Unary operators.  */
193
194   +scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
195   -scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
196   ~scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
197   !scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
198   *scalar0; /* { dg-error {invalid type argument of unary '\*'} } */
199   __real scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
200   __imag scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
201   ++scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
202   --scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
203   scalar0++; /* { dg-error {operation not permitted on type '__bf16'} } */
204   scalar0--; /* { dg-error {operation not permitted on type '__bf16'} } */
205
206   /* Binary arithmetic operations.  */
207
208   scalar0 = glob_bfloat + *bfloat_ptr; /* { dg-error {operation not permitted on type '__bf16'} } */
209   scalar0 = glob_bfloat + 0.1; /* { dg-error {operation not permitted on type '__bf16'} } */
210   scalar0 = glob_bfloat + 0; /* { dg-error {operation not permitted on type '__bf16'} } */
211   scalar0 = glob_bfloat + is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
212
213   return scalar0;
214 }
215