• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64 -target-feature +bf16 %s
2 
test_cast_from_float(float in)3 __bf16 test_cast_from_float(float in) {
4   return (__bf16)in; // expected-error {{cannot type-cast to __bf16}}
5 }
6 
test_cast_from_float_literal(void)7 __bf16 test_cast_from_float_literal(void) {
8   return (__bf16)1.0f; // expected-error {{cannot type-cast to __bf16}}
9 }
10 
test_cast_from_int(int in)11 __bf16 test_cast_from_int(int in) {
12   return (__bf16)in; // expected-error {{cannot type-cast to __bf16}}
13 }
14 
test_cast_from_int_literal(void)15 __bf16 test_cast_from_int_literal(void) {
16   return (__bf16)1; // expected-error {{cannot type-cast to __bf16}}
17 }
18 
test_cast_bfloat(__bf16 in)19 __bf16 test_cast_bfloat(__bf16 in) {
20   return (__bf16)in; // this one should work
21 }
22 
test_cast_to_float(__bf16 in)23 float test_cast_to_float(__bf16 in) {
24   return (float)in; // expected-error {{cannot type-cast from __bf16}}
25 }
26 
test_cast_to_int(__bf16 in)27 int test_cast_to_int(__bf16 in) {
28   return (int)in; // expected-error {{cannot type-cast from __bf16}}
29 }
30 
test_implicit_from_float(float in)31 __bf16 test_implicit_from_float(float in) {
32   return in; // expected-error {{returning 'float' from a function with incompatible result type '__bf16'}}
33 }
34 
test_implicit_from_float_literal(void)35 __bf16 test_implicit_from_float_literal(void) {
36   return 1.0f; // expected-error {{returning 'float' from a function with incompatible result type '__bf16'}}
37 }
38 
test_implicit_from_int(int in)39 __bf16 test_implicit_from_int(int in) {
40   return in; // expected-error {{returning 'int' from a function with incompatible result type '__bf16'}}
41 }
42 
test_implicit_from_int_literal(void)43 __bf16 test_implicit_from_int_literal(void) {
44   return 1; // expected-error {{returning 'int' from a function with incompatible result type '__bf16'}}
45 }
46 
test_implicit_bfloat(__bf16 in)47 __bf16 test_implicit_bfloat(__bf16 in) {
48   return in; // this one should work
49 }
50 
test_implicit_to_float(__bf16 in)51 float test_implicit_to_float(__bf16 in) {
52   return in; // expected-error {{returning '__bf16' from a function with incompatible result type 'float'}}
53 }
54 
test_implicit_to_int(__bf16 in)55 int test_implicit_to_int(__bf16 in) {
56   return in; // expected-error {{returning '__bf16' from a function with incompatible result type 'int'}}
57 }
58 
test_cond(__bf16 a,__bf16 b,_Bool which)59 __bf16 test_cond(__bf16 a, __bf16 b, _Bool which) {
60   // Conditional operator _should_ be supported, without nonsense
61   // complaints like 'types __bf16 and __bf16 are not compatible'
62   return which ? a : b;
63 }
64 
test_cond_float(__bf16 a,__bf16 b,_Bool which)65 __bf16 test_cond_float(__bf16 a, __bf16 b, _Bool which) {
66   return which ? a : 1.0f; // expected-error {{incompatible operand types ('__bf16' and 'float')}}
67 }
68 
test_cond_int(__bf16 a,__bf16 b,_Bool which)69 __bf16 test_cond_int(__bf16 a, __bf16 b, _Bool which) {
70   return which ? a : 1; // expected-error {{incompatible operand types ('__bf16' and 'int')}}
71 }
72