aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/sse2-bfloat16-scalar-typecheck.c
blob: f76d5547758e6c8770ccf0b46016c88de10f11e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* { dg-do compile } */
/* { dg-options "-msse2 -O2" } */


__bf16 glob_bfloat;

int is_an_int;
short is_a_short_int;
float is_a_float;
float is_a_float16;
double is_a_double;

float *float_ptr;

__bf16 foo1 (void) { return (__bf16) 0x1234; } /* { dg-error {invalid conversion to type '__bf16'} } */
__bf16 foo2 (void) { return (__bf16) (short) 0x1234; } /* { dg-error {invalid conversion to type '__bf16'} } */

__bf16 footest (__bf16 scalar0)
{

  /* Initialisation  */

  __bf16 scalar1_1;
  __bf16 scalar1_2 = glob_bfloat;
  __bf16 scalar1_3 = 0;   /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_4 = 0.1; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_5 = is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_6 = is_an_int;  /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_7 = is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_8 = is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar1_9 = is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */

  int initi_1_1 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  float initi_1_2 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  _Float16 initi_1_3 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  short initi_1_4 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  double initi_1_5 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */

  __bf16 scalar2_1 = {}; /* { dg-error {empty scalar initializer} } */
  __bf16 scalar2_2 = { glob_bfloat };
  __bf16 scalar2_3 = { 0 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_4 = { 0.1 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_5 = { is_a_float }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_6 = { is_an_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_7 = { is_a_float16 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_8 = { is_a_double }; /* { dg-error {invalid conversion to type '__bf16'} } */
  __bf16 scalar2_9 = { is_a_short_int }; /* { dg-error {invalid conversion to type '__bf16'} } */

  int initi_2_1 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  float initi_2_2 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  _Float16 initi_2_3 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  short initi_2_4 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  double initi_2_5 = { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */

  /* Assignments.  */

  glob_bfloat = glob_bfloat;
  glob_bfloat = 0;   /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = 0.1; /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = is_an_int; /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
  glob_bfloat = is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */

  is_an_int = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  is_a_float = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  is_a_float16 = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  is_a_double = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  is_a_short_int = glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */

  /* Casting.  */

  (void) glob_bfloat;
  (__bf16) glob_bfloat;

  (int) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  (float) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  (_Float16) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  (double) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */
  (short) glob_bfloat; /* { dg-error {invalid conversion from type '__bf16'} } */

  (__bf16) is_an_int; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) is_a_float; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) is_a_float16; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) is_a_double; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) is_a_short_int; /* { dg-error {invalid conversion to type '__bf16'} } */

  /* Compound literals.  */

  (__bf16) {}; /* { dg-error {empty scalar initializer} } */
  (__bf16) { glob_bfloat };
  (__bf16) { 0 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { 0.1 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { is_a_float }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { is_an_int }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { is_a_float16 }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { is_a_double }; /* { dg-error {invalid conversion to type '__bf16'} } */
  (__bf16) { is_a_short_int }; /* { dg-error {invalid conversion to type '__bf16'} } */

  (int) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  (float) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  (_Float16) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  (double) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */
  (short) { glob_bfloat }; /* { dg-error {invalid conversion from type '__bf16'} } */

  /* Arrays and Structs.  */

  typedef __bf16 array_type[2];
  extern __bf16 extern_array[];

  __bf16 array[2];
  __bf16 zero_length_array[0];
  __bf16 empty_init_array[] = {};
  typedef __bf16 some_other_type[is_an_int];

  struct struct1 {
    __bf16 a;
  };

  union union1 {
    __bf16 a;
  };

  /* Addressing and dereferencing.  */

  __bf16 *bfloat_ptr = &scalar0;
  scalar0 = *bfloat_ptr;

  /* Pointer assignment.  */

  __bf16 *bfloat_ptr2 = bfloat_ptr;
  __bf16 *bfloat_ptr3 = array;

  /* Pointer arithmetic.  */

  ++bfloat_ptr;
  --bfloat_ptr;
  bfloat_ptr++;
  bfloat_ptr--;
  bfloat_ptr += 1;
  bfloat_ptr -= 1;
  bfloat_ptr - bfloat_ptr2;
  bfloat_ptr = &bfloat_ptr3[0];
  bfloat_ptr = &bfloat_ptr3[1];

  /* Simple comparison.  */
  scalar0 > glob_bfloat; /* { dg-error {operation not permitted on type '__bf16'} } */
  glob_bfloat == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 > is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
  is_a_float == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 > 0; /* { dg-error {operation not permitted on type '__bf16'} } */
  0 == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 > 0.1; /* { dg-error {operation not permitted on type '__bf16'} } */
  0.1 == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 > is_an_int; /* { dg-error {operation not permitted on type '__bf16'} } */
  is_an_int == scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */

  /* Pointer comparison.  */

  bfloat_ptr == &scalar0;
  bfloat_ptr != &scalar0;
  bfloat_ptr < &scalar0;
  bfloat_ptr <= &scalar0;
  bfloat_ptr > &scalar0;
  bfloat_ptr >= &scalar0;
  bfloat_ptr == bfloat_ptr2;
  bfloat_ptr != bfloat_ptr2;
  bfloat_ptr < bfloat_ptr2;
  bfloat_ptr <= bfloat_ptr2;
  bfloat_ptr > bfloat_ptr2;
  bfloat_ptr >= bfloat_ptr2;

  /* Conditional expressions.  */

  0 ? scalar0 : scalar0;
  0 ? scalar0 : is_a_float; /* { dg-error {invalid conversion from type '__bf16'} } */
  0 ? is_a_float : scalar0; /* { dg-error {invalid conversion from type '__bf16'} } */
  0 ? scalar0 : 0; /* { dg-error {invalid conversion to type '__bf16'} } */
  0 ? 0 : scalar0; /* { dg-error {invalid conversion to type '__bf16'} } */
  0 ? 0.1 : scalar0; /* { dg-error {invalid conversion from type '__bf16'} } */
  0 ? scalar0 : 0.1; /* { dg-error {invalid conversion from type '__bf16'} } */
  0 ? bfloat_ptr : bfloat_ptr2;
  0 ? bfloat_ptr : float_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */
  0 ? float_ptr : bfloat_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */

  scalar0 ? scalar0 : scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 ? is_a_float : scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 ? scalar0 : is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 ? is_a_float : is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */

  /* Unary operators.  */

  +scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  -scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  ~scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  !scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  *scalar0; /* { dg-error {invalid type argument of unary '\*'} } */
  __real scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  __imag scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  ++scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  --scalar0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0++; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0--; /* { dg-error {operation not permitted on type '__bf16'} } */

  /* Binary arithmetic operations.  */

  scalar0 = glob_bfloat + *bfloat_ptr; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 = glob_bfloat + 0.1; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 = glob_bfloat + 0; /* { dg-error {operation not permitted on type '__bf16'} } */
  scalar0 = glob_bfloat + is_a_float; /* { dg-error {operation not permitted on type '__bf16'} } */

  return scalar0;
}