|
1 | | -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c23 -fexperimental-decimal-floating-point -fsyntax-only -verify=c %s |
2 | | -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x c++ -std=c++2c -fexperimental-decimal-floating-point -fsyntax-only -verify=cxx %s |
3 | | - |
4 | | -// c-no-diagnostics |
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c23 -fexperimental-decimal-floating-point -fsyntax-only -verify=expected,c %s |
| 2 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x c++ -std=c++2c -fexperimental-decimal-floating-point -fsyntax-only -verify=expected,cxx %s |
5 | 3 |
|
6 | 4 | // _Decimal32, _Decimal64, and _Decimal128 are never keywords in C++. |
7 | 5 | _Decimal32 d32; // cxx-error {{unknown type name '_Decimal32'}} |
8 | 6 | _Decimal64 d64; // cxx-error {{unknown type name '_Decimal64'}} |
9 | 7 | _Decimal128 d28; // cxx-error {{unknown type name '_Decimal128'}} |
| 8 | + |
| 9 | +// DFP types are available via the GNU mode attribute in both C and C++. |
| 10 | +typedef float __attribute__((mode(SD))) D32; |
| 11 | +typedef float __attribute__((mode(DD))) D64; |
| 12 | +typedef float __attribute__((mode(TD))) D128; |
| 13 | + |
| 14 | +// The GNU mode attribute requires a floating point base type for DFP types. |
| 15 | +// These are ok. |
| 16 | +long double __attribute((mode(SD))) ldamsd; |
| 17 | +double __attribute((mode(DD))) damdd; |
| 18 | +_Float16 __attribute((mode(SD))) f16amsd; |
| 19 | +__bf16 __attribute((mode(SD))) bf16amsd; |
| 20 | +__float128 __attribute((mode(TD))) f128amtd; |
| 21 | +// These are not ok. |
| 22 | +void __attribute((mode(SD))) vamsd; // expected-error {{type of machine mode does not match type of base type}} |
| 23 | +int __attribute((mode(DD))) iamdd; // expected-error {{type of machine mode does not match type of base type}} |
| 24 | +int* __attribute((mode(TD))) ipamtd; // expected-error {{mode attribute only supported for integer and floating-point types}} |
| 25 | +float __attribute((mode(TD))) *fapmtd; // expected-error {{mode attribute only supported for integer and floating-point types}} |
| 26 | + |
| 27 | +// DFP types may be used as vector elements, but declaration form is restricted. |
| 28 | +float __attribute__((mode(V4SD))) famv4sd; // expected-warning {{deprecated; use the 'vector_size' attribute instead}} |
| 29 | +float __attribute__((mode(SD))) __attribute__((vector_size(16))) famsdv16; |
| 30 | +D64 __attribute__((vector_size(16))) d64av16; |
| 31 | + |
| 32 | +// DFP types are not allowed as elements of complex types. |
| 33 | +D32 _Complex d32c; // expected-error {{'_Complex type-name' is invalid}} |
| 34 | +_Decimal32 _Complex kd32c; // c-error {{'_Complex _Decimal32' is invalid}} \ |
| 35 | + cxx-error {{unknown type name '_Decimal32'}} |
| 36 | + |
| 37 | +_Static_assert(sizeof(D32) == 4); |
| 38 | +_Static_assert(sizeof(D64) == 8); |
| 39 | +_Static_assert(sizeof(D128) == 16); |
| 40 | + |
| 41 | +_Static_assert(_Alignof(D32) == 4); |
| 42 | +_Static_assert(_Alignof(D64) == 8); |
| 43 | +_Static_assert(_Alignof(D128) == 16); |
| 44 | + |
| 45 | +struct s { |
| 46 | + D32 d32; |
| 47 | + D64 d64; |
| 48 | + D128 d128; |
| 49 | + union { |
| 50 | + D32 ud32; |
| 51 | + D64 ud64; |
| 52 | + D128 ud128; |
| 53 | + }; |
| 54 | +}; |
| 55 | + |
| 56 | +struct bitfield { |
| 57 | + D32 d32 : 32; // expected-error {{bit-field 'd32' has non-integral type}} |
| 58 | + D64 d64 : 64; // expected-error {{bit-field 'd64' has non-integral type}} |
| 59 | + D128 d128 : 128; // expected-error {{bit-field 'd128' has non-integral type}} |
| 60 | +}; |
| 61 | + |
| 62 | +D32 test_d32(D32 d32) { |
| 63 | + return d32; |
| 64 | +} |
| 65 | + |
| 66 | +D64 test_d64(D64 d64) { |
| 67 | + return d64; |
| 68 | +} |
| 69 | + |
| 70 | +D128 test_d128(D128 d128) { |
| 71 | + return d128; |
| 72 | +} |
| 73 | + |
| 74 | +void test_builtin_complex(D32 d32) { |
| 75 | + __auto_type lv = __builtin_complex(d32, d32); // expected-error {{'_Complex _Decimal32' is invalid}} |
| 76 | +} |
| 77 | + |
| 78 | +void test_generic(D32 d32, D64 d64, D128 d128) { |
| 79 | + (void)_Generic(d32, D64 : 0, D128 : 0); // expected-error-re {{controlling expression type {{.*}} not compatible with any generic association type}} |
| 80 | + (void)_Generic(d64, D32 : 0, D128 : 0); // expected-error-re {{controlling expression type {{.*}} not compatible with any generic association type}} |
| 81 | + (void)_Generic(d128, D32 : 0, D64 : 0); // expected-error-re {{controlling expression type {{.*}} not compatible with any generic association type}} |
| 82 | + _Static_assert(_Generic(d32, D64 : 0, D128 : 0, default : 1) == 1); |
| 83 | + _Static_assert(_Generic(d64, D32 : 0, D128 : 0, default : 1) == 1); |
| 84 | + _Static_assert(_Generic(d128, D32 : 0, D64 : 0, default : 1) == 1); |
| 85 | + _Static_assert(_Generic(d32, D32 : 1, D64 : 0, D128 : 0) == 1); |
| 86 | + _Static_assert(_Generic(d64, D32 : 0, D64 : 1, D128 : 0) == 1); |
| 87 | + _Static_assert(_Generic(d128, D32 : 0, D64 : 0, D128 : 1) == 1); |
| 88 | +} |
0 commit comments