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