1
- // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s
2
- // expected-no-diagnostics
1
+ // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension %s
3
2
4
3
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
5
4
#define LITTLE_END 1
9
8
#error "huh?"
10
9
#endif
11
10
11
+ // We also support _BitInt as long as it is >=8 and a power of 2.
12
+ typedef _BitInt (8 ) BitInt8;
13
+ typedef _BitInt (32 ) BitInt32;
14
+ typedef _BitInt (128 ) BitInt128;
15
+
12
16
typedef double vector4double __attribute__ ((__vector_size__(32 )));
13
17
typedef float vector4float __attribute__ ((__vector_size__(16 )));
14
18
typedef long long vector4long __attribute__ ((__vector_size__(32 )));
15
19
typedef int vector4int __attribute__ ((__vector_size__(16 )));
16
20
typedef short vector4short __attribute__ ((__vector_size__(8 )));
17
21
typedef char vector4char __attribute__ ((__vector_size__(4 )));
22
+ typedef BitInt8 vector4BitInt8 __attribute__ ((__vector_size__(4 )));
23
+ typedef BitInt32 vector4BitInt32 __attribute__ ((__vector_size__(16 )));
24
+ typedef BitInt128 vector4BitInt128 __attribute__ ((__vector_size__(64 )));
18
25
typedef double vector8double __attribute__ ((__vector_size__(64 )));
19
26
typedef float vector8float __attribute__ ((__vector_size__(32 )));
20
27
typedef long long vector8long __attribute__ ((__vector_size__(64 )));
21
28
typedef int vector8int __attribute__ ((__vector_size__(32 )));
22
29
typedef short vector8short __attribute__ ((__vector_size__(16 )));
23
30
typedef char vector8char __attribute__ ((__vector_size__(8 )));
31
+ typedef BitInt8 vector8BitInt8 __attribute__ ((__vector_size__(8 )));
32
+ typedef BitInt32 vector8BitInt32 __attribute__ ((__vector_size__(32 )));
33
+ typedef BitInt128 vector8BitInt128 __attribute__ ((__vector_size__(128 )));
24
34
25
35
#define CHECK_NUM (__size, __typeFrom, __typeTo, ...) \
26
36
constexpr vector##__size##__typeTo \
@@ -34,6 +44,9 @@ typedef char vector8char __attribute__((__vector_size__(8)));
34
44
CHECK_NUM(__size, __typeFrom, int , __VA_ARGS__) \
35
45
CHECK_NUM(__size, __typeFrom, short , __VA_ARGS__) \
36
46
CHECK_NUM(__size, __typeFrom, char , __VA_ARGS__) \
47
+ CHECK_NUM(__size, __typeFrom, BitInt8, __VA_ARGS__) \
48
+ CHECK_NUM(__size, __typeFrom, BitInt32, __VA_ARGS__) \
49
+ CHECK_NUM(__size, __typeFrom, BitInt128, __VA_ARGS__) \
37
50
static_assert( \
38
51
__builtin_bit_cast ( \
39
52
unsigned , \
@@ -56,7 +69,10 @@ typedef char vector8char __attribute__((__vector_size__(8)));
56
69
CHECK_TO_ALL_TYPES(__size, long , __VA_ARGS__) \
57
70
CHECK_TO_ALL_TYPES(__size, int , __VA_ARGS__) \
58
71
CHECK_TO_ALL_TYPES(__size, short , __VA_ARGS__) \
59
- CHECK_TO_ALL_TYPES(__size, char , __VA_ARGS__)
72
+ CHECK_TO_ALL_TYPES(__size, char , __VA_ARGS__) \
73
+ CHECK_TO_ALL_TYPES(__size, BitInt8, __VA_ARGS__) \
74
+ CHECK_TO_ALL_TYPES(__size, BitInt32, __VA_ARGS__) \
75
+ CHECK_TO_ALL_TYPES(__size, BitInt128, __VA_ARGS__)
60
76
61
77
CHECK_ALL_COMBINATIONS(4 , 0 , 1 , 2 , 3 );
62
78
CHECK_ALL_COMBINATIONS (8 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 );
@@ -77,23 +93,28 @@ constexpr vector4char vectorShuffle2 =
77
93
__builtin_shufflevector (vector4charConst1, vector4charConst2, 4 , 5 , 6 , 7 );
78
94
static_assert (__builtin_bit_cast(unsigned , vectorShuffle2) ==
79
95
(LITTLE_END ? 0x07060504 : 0x04050607 ));
80
- constexpr vector4char vectorShuffle3 = __builtin_shufflevector(
81
- vector4charConst1, vector4charConst2, -1 , -1 , -1 , -1 );
82
- static_assert (__builtin_bit_cast(unsigned , vectorShuffle3) ==
83
- (LITTLE_END ? 0x00000000 : 0x00000000 ));
84
- constexpr vector4char vectorShuffle4 =
96
+ constexpr vector4char vectorShuffle3 =
85
97
__builtin_shufflevector (vector4charConst1, vector4charConst2, 0 , 2 , 4 , 6 );
86
- static_assert (__builtin_bit_cast(unsigned , vectorShuffle4 ) ==
98
+ static_assert (__builtin_bit_cast(unsigned , vectorShuffle3 ) ==
87
99
(LITTLE_END ? 0x06040200 : 0x00020406 ));
88
- constexpr vector8char vectorShuffle5 = __builtin_shufflevector(
100
+ constexpr vector8char vectorShuffle4 = __builtin_shufflevector(
89
101
vector8intConst, vector8intConst, 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 );
90
- static_assert (__builtin_bit_cast(unsigned long long , vectorShuffle5 ) ==
102
+ static_assert (__builtin_bit_cast(unsigned long long , vectorShuffle4 ) ==
91
103
(LITTLE_END ? 0x0E0C0A080E0C0A08 : 0x080A0C0E080A0C0E ));
92
- constexpr vector4char vectorShuffle6 =
104
+ constexpr vector4char vectorShuffle5 =
93
105
__builtin_shufflevector (vector8intConst, vector8intConst, 0 , 2 , 4 , 6 );
94
- static_assert (__builtin_bit_cast(unsigned , vectorShuffle6 ) ==
106
+ static_assert (__builtin_bit_cast(unsigned , vectorShuffle5 ) ==
95
107
(LITTLE_END ? 0x0E0C0A08 : 0x080A0C0E ));
96
- constexpr vector8char vectorShuffle7 = __builtin_shufflevector(
108
+ constexpr vector8char vectorShuffle6 = __builtin_shufflevector(
97
109
vector4charConst1, vector4charConst2, 0 , 2 , 4 , 6 , 1 , 3 , 5 , 7 );
98
- static_assert (__builtin_bit_cast(unsigned long long , vectorShuffle7 ) ==
110
+ static_assert (__builtin_bit_cast(unsigned long long , vectorShuffle6 ) ==
99
111
(LITTLE_END ? 0x0705030106040200 : 0x0002040601030507 ));
112
+
113
+ constexpr vector4char
114
+ vectorShuffleFail1 = // expected-error {{constexpr variable 'vectorShuffleFail1'\
115
+ must be initialized by a constant expression}}
116
+ __builtin_shufflevector ( // expected-error {{index for __builtin_shufflevector must be within\
117
+ the bounds of the input vectors in a constexpr context. An index of\
118
+ -1 at position 0 was found. -1 is only allowed at runtime.}}
119
+ vector4charConst1,
120
+ vector4charConst2, -1 , -1 , -1 , -1 );
0 commit comments