1 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64 -target-feature +bf16 %s
2
test_static_cast_from_float(float in)3 __bf16 test_static_cast_from_float(float in) {
4 return static_cast<__bf16>(in); // expected-error {{static_cast from 'float' to '__bf16' is not allowed}}
5 }
6
test_static_cast_from_float_literal(void)7 __bf16 test_static_cast_from_float_literal(void) {
8 return static_cast<__bf16>(1.0f); // expected-error {{static_cast from 'float' to '__bf16' is not allowed}}
9 }
10
test_static_cast_from_int(int in)11 __bf16 test_static_cast_from_int(int in) {
12 return static_cast<__bf16>(in); // expected-error {{static_cast from 'int' to '__bf16' is not allowed}}
13 }
14
test_static_cast_from_int_literal(void)15 __bf16 test_static_cast_from_int_literal(void) {
16 return static_cast<__bf16>(1); // expected-error {{static_cast from 'int' to '__bf16' is not allowed}}
17 }
18
test_static_cast_bfloat(__bf16 in)19 __bf16 test_static_cast_bfloat(__bf16 in) {
20 return static_cast<__bf16>(in); // this one should work
21 }
22
test_static_cast_to_float(__bf16 in)23 float test_static_cast_to_float(__bf16 in) {
24 return static_cast<float>(in); // expected-error {{static_cast from '__bf16' to 'float' is not allowed}}
25 }
26
test_static_cast_to_int(__bf16 in)27 int test_static_cast_to_int(__bf16 in) {
28 return static_cast<int>(in); // expected-error {{static_cast from '__bf16' to 'int' is not allowed}}
29 }
30
test_implicit_from_float(float in)31 __bf16 test_implicit_from_float(float in) {
32 return in; // expected-error {{cannot initialize return object of type '__bf16' with an lvalue of type 'float'}}
33 }
34
test_implicit_from_float_literal()35 __bf16 test_implicit_from_float_literal() {
36 return 1.0f; // expected-error {{cannot initialize return object of type '__bf16' with an rvalue of type 'float'}}
37 }
38
test_implicit_from_int(int in)39 __bf16 test_implicit_from_int(int in) {
40 return in; // expected-error {{cannot initialize return object of type '__bf16' with an lvalue of type 'int'}}
41 }
42
test_implicit_from_int_literal()43 __bf16 test_implicit_from_int_literal() {
44 return 1; // expected-error {{cannot initialize return object of type '__bf16' with an rvalue of type 'int'}}
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 {{cannot initialize return object of type 'float' with an lvalue of type '__bf16'}}
53 }
54
test_implicit_to_int(__bf16 in)55 int test_implicit_to_int(__bf16 in) {
56 return in; // expected-error {{cannot initialize return object of type 'int' with an lvalue of type '__bf16'}}
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