| 1 |
// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify=expected,both |
| 2 |
// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify=expected,both |
| 3 |
// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref,both %s -Wno-constant-evaluated |
| 4 |
// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify=expected,both |
| 5 |
// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify=expected,both |
| 6 |
// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref,both %s -Wno-constant-evaluated |
| 7 |
// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify=expected,both |
| 8 |
// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -verify=ref,both %s -Wno-constant-evaluated |
| 9 |
|
| 10 |
|
| 11 |
namespace strcmp { |
| 12 |
constexpr char kFoobar[6] = {'f','o','o','b','a','r'}; |
| 13 |
constexpr char kFoobazfoobar[12] = {'f','o','o','b','a','z','f','o','o','b','a','r'}; |
| 14 |
|
| 15 |
static_assert(__builtin_strcmp("", "") == 0, ""); |
| 16 |
static_assert(__builtin_strcmp("abab", "abab") == 0, ""); |
| 17 |
static_assert(__builtin_strcmp("abab", "abba") == -1, ""); |
| 18 |
static_assert(__builtin_strcmp("abab", "abaa") == 1, ""); |
| 19 |
static_assert(__builtin_strcmp("ababa", "abab") == 1, ""); |
| 20 |
static_assert(__builtin_strcmp("abab", "ababa") == -1, ""); |
| 21 |
static_assert(__builtin_strcmp("a\203", "a") == 1, ""); |
| 22 |
static_assert(__builtin_strcmp("a\203", "a\003") == 1, ""); |
| 23 |
static_assert(__builtin_strcmp("abab\0banana", "abab") == 0, ""); |
| 24 |
static_assert(__builtin_strcmp("abab", "abab\0banana") == 0, ""); |
| 25 |
static_assert(__builtin_strcmp("abab\0banana", "abab\0canada") == 0, ""); |
| 26 |
static_assert(__builtin_strcmp(0, "abab") == 0, ""); // both-error {{not an integral constant}} \ |
| 27 |
// both-note {{dereferenced null}} |
| 28 |
static_assert(__builtin_strcmp("abab", 0) == 0, ""); // both-error {{not an integral constant}} \ |
| 29 |
// both-note {{dereferenced null}} |
| 30 |
|
| 31 |
static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar) == -1, ""); |
| 32 |
static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar + 6) == 0, ""); // both-error {{not an integral constant}} \ |
| 33 |
// both-note {{dereferenced one-past-the-end}} |
| 34 |
|
| 35 |
/// Used to assert because we're passing a dummy pointer to |
| 36 |
/// __builtin_strcmp() when evaluating the return statement. |
| 37 |
constexpr bool char_memchr_mutable() { |
| 38 |
char buffer[] = "mutable"; |
| 39 |
return __builtin_strcmp(buffer, "mutable") == 0; |
| 40 |
} |
| 41 |
static_assert(char_memchr_mutable(), ""); |
| 42 |
} |
| 43 |
|
| 44 |
/// Copied from constant-expression-cxx11.cpp |
| 45 |
namespace strlen { |
| 46 |
constexpr const char *a = "foo\0quux"; |
| 47 |
constexpr char b[] = "foo\0quux"; |
| 48 |
constexpr int f() { return 'u'; } |
| 49 |
constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 }; |
| 50 |
|
| 51 |
static_assert(__builtin_strlen("foo") == 3, ""); |
| 52 |
static_assert(__builtin_strlen("foo\0quux") == 3, ""); |
| 53 |
static_assert(__builtin_strlen("foo\0quux" + 4) == 4, ""); |
| 54 |
|
| 55 |
constexpr bool check(const char *p) { |
| 56 |
return __builtin_strlen(p) == 3 && |
| 57 |
__builtin_strlen(p + 1) == 2 && |
| 58 |
__builtin_strlen(p + 2) == 1 && |
| 59 |
__builtin_strlen(p + 3) == 0 && |
| 60 |
__builtin_strlen(p + 4) == 4 && |
| 61 |
__builtin_strlen(p + 5) == 3 && |
| 62 |
__builtin_strlen(p + 6) == 2 && |
| 63 |
__builtin_strlen(p + 7) == 1 && |
| 64 |
__builtin_strlen(p + 8) == 0; |
| 65 |
} |
| 66 |
|
| 67 |
static_assert(check(a), ""); |
| 68 |
static_assert(check(b), ""); |
| 69 |
static_assert(check(c), ""); |
| 70 |
|
| 71 |
constexpr int over1 = __builtin_strlen(a + 9); // both-error {{constant expression}} \ |
| 72 |
// both-note {{one-past-the-end}} |
| 73 |
constexpr int over2 = __builtin_strlen(b + 9); // both-error {{constant expression}} \ |
| 74 |
// both-note {{one-past-the-end}} |
| 75 |
constexpr int over3 = __builtin_strlen(c + 9); // both-error {{constant expression}} \ |
| 76 |
// both-note {{one-past-the-end}} |
| 77 |
|
| 78 |
constexpr int under1 = __builtin_strlen(a - 1); // both-error {{constant expression}} \ |
| 79 |
// both-note {{cannot refer to element -1}} |
| 80 |
constexpr int under2 = __builtin_strlen(b - 1); // both-error {{constant expression}} \ |
| 81 |
// both-note {{cannot refer to element -1}} |
| 82 |
constexpr int under3 = __builtin_strlen(c - 1); // both-error {{constant expression}} \ |
| 83 |
// both-note {{cannot refer to element -1}} |
| 84 |
|
| 85 |
constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator. |
| 86 |
constexpr int bad = __builtin_strlen(d); // both-error {{constant expression}} \ |
| 87 |
// both-note {{one-past-the-end}} |
| 88 |
} |
| 89 |
|
| 90 |
namespace nan { |
| 91 |
constexpr double NaN1 = __builtin_nan(""); |
| 92 |
|
| 93 |
/// The current interpreter does not accept this, but it should. |
| 94 |
constexpr float NaN2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}} |
| 95 |
#if __cplusplus < 201703L |
| 96 |
// expected-error@-2 {{must be initialized by a constant expression}} |
| 97 |
#endif |
| 98 |
|
| 99 |
constexpr double NaN3 = __builtin_nan("foo"); // both-error {{must be initialized by a constant expression}} |
| 100 |
constexpr float NaN4 = __builtin_nanf(""); |
| 101 |
//constexpr long double NaN5 = __builtin_nanf128(""); |
| 102 |
|
| 103 |
/// FIXME: This should be accepted by the current interpreter as well. |
| 104 |
constexpr char f[] = {'0', 'x', 'A', 'E', '\0'}; |
| 105 |
constexpr double NaN6 = __builtin_nan(f); // ref-error {{must be initialized by a constant expression}} |
| 106 |
|
| 107 |
/// FIXME: Current interpreter misses diagnostics. |
| 108 |
constexpr char f2[] = {'0', 'x', 'A', 'E'}; /// No trailing 0 byte. |
| 109 |
constexpr double NaN7 = __builtin_nan(f2); // both-error {{must be initialized by a constant expression}} \ |
| 110 |
// expected-note {{read of dereferenced one-past-the-end pointer}} |
| 111 |
static_assert(!__builtin_issignaling(__builtin_nan("")), ""); |
| 112 |
static_assert(__builtin_issignaling(__builtin_nans("")), ""); |
| 113 |
} |
| 114 |
|
| 115 |
namespace fmin { |
| 116 |
constexpr float f1 = __builtin_fmin(1.0, 2.0f); |
| 117 |
static_assert(f1 == 1.0f, ""); |
| 118 |
|
| 119 |
constexpr float min = __builtin_fmin(__builtin_nan(""), 1); |
| 120 |
static_assert(min == 1, ""); |
| 121 |
constexpr float min2 = __builtin_fmin(1, __builtin_nan("")); |
| 122 |
static_assert(min2 == 1, ""); |
| 123 |
constexpr float min3 = __builtin_fmin(__builtin_inf(), __builtin_nan("")); |
| 124 |
static_assert(min3 == __builtin_inf(), ""); |
| 125 |
} |
| 126 |
|
| 127 |
namespace inf { |
| 128 |
static_assert(__builtin_isinf(__builtin_inf()), ""); |
| 129 |
static_assert(!__builtin_isinf(1.0), ""); |
| 130 |
|
| 131 |
static_assert(__builtin_isfinite(1.0), ""); |
| 132 |
static_assert(!__builtin_isfinite(__builtin_inf()), ""); |
| 133 |
|
| 134 |
static_assert(__builtin_isnormal(1.0), ""); |
| 135 |
static_assert(!__builtin_isnormal(__builtin_inf()), ""); |
| 136 |
|
| 137 |
#ifndef __AVR__ |
| 138 |
static_assert(__builtin_issubnormal(0x1p-1070), ""); |
| 139 |
#endif |
| 140 |
static_assert(!__builtin_issubnormal(__builtin_inf()), ""); |
| 141 |
|
| 142 |
static_assert(__builtin_iszero(0.0), ""); |
| 143 |
static_assert(!__builtin_iszero(__builtin_inf()), ""); |
| 144 |
|
| 145 |
static_assert(__builtin_issignaling(__builtin_nans("")), ""); |
| 146 |
static_assert(!__builtin_issignaling(__builtin_inf()), ""); |
| 147 |
} |
| 148 |
|
| 149 |
namespace isfpclass { |
| 150 |
char isfpclass_inf_pos_0[__builtin_isfpclass(__builtin_inf(), 0x0200) ? 1 : -1]; // fcPosInf |
| 151 |
char isfpclass_inf_pos_1[!__builtin_isfpclass(__builtin_inff(), 0x0004) ? 1 : -1]; // fcNegInf |
| 152 |
char isfpclass_inf_pos_2[__builtin_isfpclass(__builtin_infl(), 0x0207) ? 1 : -1]; // fcSNan|fcQNan|fcNegInf|fcPosInf |
| 153 |
char isfpclass_inf_pos_3[!__builtin_isfpclass(__builtin_inf(), 0x01F8) ? 1 : -1]; // fcFinite |
| 154 |
char isfpclass_pos_0 [__builtin_isfpclass(1.0, 0x0100) ? 1 : -1]; // fcPosNormal |
| 155 |
char isfpclass_pos_1 [!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal |
| 156 |
char isfpclass_pos_2 [__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite |
| 157 |
char isfpclass_pos_3 [!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan |
| 158 |
#ifndef __AVR__ |
| 159 |
char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal |
| 160 |
char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite |
| 161 |
char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative |
| 162 |
char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite |
| 163 |
#endif |
| 164 |
char isfpclass_pzero_0 [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero |
| 165 |
char isfpclass_pzero_1 [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite |
| 166 |
char isfpclass_pzero_2 [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero |
| 167 |
char isfpclass_pzero_3 [!__builtin_isfpclass(0.0, 0x0003) ? 1 : -1]; // fcNan |
| 168 |
char isfpclass_nzero_0 [__builtin_isfpclass(-0.0f, 0x0060) ? 1 : -1]; // fcZero |
| 169 |
char isfpclass_nzero_1 [__builtin_isfpclass(-0.0, 0x01F8) ? 1 : -1]; // fcFinite |
| 170 |
char isfpclass_nzero_2 [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero |
| 171 |
char isfpclass_nzero_3 [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan |
| 172 |
char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal |
| 173 |
char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive |
| 174 |
#ifndef __AVR__ |
| 175 |
char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite |
| 176 |
char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite |
| 177 |
#endif |
| 178 |
char isfpclass_neg_0 [__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal |
| 179 |
char isfpclass_neg_1 [!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal |
| 180 |
char isfpclass_neg_2 [__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite |
| 181 |
char isfpclass_neg_3 [!__builtin_isfpclass(-1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan |
| 182 |
char isfpclass_inf_neg_0[__builtin_isfpclass(-__builtin_inf(), 0x0004) ? 1 : -1]; // fcNegInf |
| 183 |
char isfpclass_inf_neg_1[!__builtin_isfpclass(-__builtin_inff(), 0x0200) ? 1 : -1]; // fcPosInf |
| 184 |
char isfpclass_inf_neg_2[__builtin_isfpclass(-__builtin_infl(), 0x0207) ? 1 : -1]; // ~fcFinite |
| 185 |
char isfpclass_inf_neg_3[!__builtin_isfpclass(-__builtin_inf(), 0x03C0) ? 1 : -1]; // fcPositive |
| 186 |
char isfpclass_qnan_0 [__builtin_isfpclass(__builtin_nan(""), 0x0002) ? 1 : -1]; // fcQNan |
| 187 |
char isfpclass_qnan_1 [!__builtin_isfpclass(__builtin_nanf(""), 0x0001) ? 1 : -1]; // fcSNan |
| 188 |
char isfpclass_qnan_2 [__builtin_isfpclass(__builtin_nanl(""), 0x0207) ? 1 : -1]; // ~fcFinite |
| 189 |
char isfpclass_qnan_3 [!__builtin_isfpclass(__builtin_nan(""), 0x01F8) ? 1 : -1]; // fcFinite |
| 190 |
char isfpclass_snan_0 [__builtin_isfpclass(__builtin_nansf(""), 0x0001) ? 1 : -1]; // fcSNan |
| 191 |
char isfpclass_snan_1 [!__builtin_isfpclass(__builtin_nans(""), 0x0002) ? 1 : -1]; // fcQNan |
| 192 |
char isfpclass_snan_2 [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 1 : -1]; // ~fcFinite |
| 193 |
char isfpclass_snan_3 [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 1 : -1]; // fcFinite |
| 194 |
} |
| 195 |
|
| 196 |
namespace fpclassify { |
| 197 |
char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))]; |
| 198 |
char classify_snan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))]; |
| 199 |
char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())]; |
| 200 |
char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())]; |
| 201 |
char classify_normal [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)]; |
| 202 |
#ifndef __AVR__ |
| 203 |
char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)]; |
| 204 |
char classify_denorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)]; |
| 205 |
char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)]; |
| 206 |
#endif |
| 207 |
char classify_zero [__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)]; |
| 208 |
char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)]; |
| 209 |
char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)]; |
| 210 |
} |
| 211 |
|
| 212 |
namespace fabs { |
| 213 |
static_assert(__builtin_fabs(-14.0) == 14.0, ""); |
| 214 |
} |
| 215 |
|
| 216 |
namespace std { |
| 217 |
struct source_location { |
| 218 |
struct __impl { |
| 219 |
unsigned int _M_line; |
| 220 |
const char *_M_file_name; |
| 221 |
signed char _M_column; |
| 222 |
const char *_M_function_name; |
| 223 |
}; |
| 224 |
using BuiltinT = decltype(__builtin_source_location()); // OK. |
| 225 |
}; |
| 226 |
} |
| 227 |
|
| 228 |
namespace SourceLocation { |
| 229 |
constexpr auto A = __builtin_source_location(); |
| 230 |
static_assert(A->_M_line == __LINE__ -1, ""); |
| 231 |
static_assert(A->_M_column == 22, ""); |
| 232 |
static_assert(__builtin_strcmp(A->_M_function_name, "") == 0, ""); |
| 233 |
static_assert(__builtin_strcmp(A->_M_file_name, __FILE__) == 0, ""); |
| 234 |
|
| 235 |
static_assert(__builtin_LINE() == __LINE__, ""); |
| 236 |
|
| 237 |
struct Foo { |
| 238 |
int a = __builtin_LINE(); |
| 239 |
}; |
| 240 |
|
| 241 |
static_assert(Foo{}.a == __LINE__, ""); |
| 242 |
|
| 243 |
struct AA { |
| 244 |
int n = __builtin_LINE(); |
| 245 |
}; |
| 246 |
struct B { |
| 247 |
AA a = {}; |
| 248 |
}; |
| 249 |
constexpr void f() { |
| 250 |
constexpr B c = {}; |
| 251 |
static_assert(c.a.n == __LINE__ - 1, ""); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
#define BITSIZE(x) (sizeof(x) * 8) |
| 256 |
namespace popcount { |
| 257 |
static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned int), ""); |
| 258 |
static_assert(__builtin_popcount(0) == 0, ""); |
| 259 |
static_assert(__builtin_popcountl(~0ul) == __CHAR_BIT__ * sizeof(unsigned long), ""); |
| 260 |
static_assert(__builtin_popcountl(0) == 0, ""); |
| 261 |
static_assert(__builtin_popcountll(~0ull) == __CHAR_BIT__ * sizeof(unsigned long long), ""); |
| 262 |
static_assert(__builtin_popcountll(0) == 0, ""); |
| 263 |
static_assert(__builtin_popcountg((unsigned char)~0) == __CHAR_BIT__ * sizeof(unsigned char), ""); |
| 264 |
static_assert(__builtin_popcountg((unsigned char)0) == 0, ""); |
| 265 |
static_assert(__builtin_popcountg((unsigned short)~0) == __CHAR_BIT__ * sizeof(unsigned short), ""); |
| 266 |
static_assert(__builtin_popcountg((unsigned short)0) == 0, ""); |
| 267 |
static_assert(__builtin_popcountg(~0u) == __CHAR_BIT__ * sizeof(unsigned int), ""); |
| 268 |
static_assert(__builtin_popcountg(0u) == 0, ""); |
| 269 |
static_assert(__builtin_popcountg(~0ul) == __CHAR_BIT__ * sizeof(unsigned long), ""); |
| 270 |
static_assert(__builtin_popcountg(0ul) == 0, ""); |
| 271 |
static_assert(__builtin_popcountg(~0ull) == __CHAR_BIT__ * sizeof(unsigned long long), ""); |
| 272 |
static_assert(__builtin_popcountg(0ull) == 0, ""); |
| 273 |
#ifdef __SIZEOF_INT128__ |
| 274 |
static_assert(__builtin_popcountg(~(unsigned __int128)0) == __CHAR_BIT__ * sizeof(unsigned __int128), ""); |
| 275 |
static_assert(__builtin_popcountg((unsigned __int128)0) == 0, ""); |
| 276 |
#endif |
| 277 |
#ifndef __AVR__ |
| 278 |
static_assert(__builtin_popcountg(~(unsigned _BitInt(128))0) == __CHAR_BIT__ * sizeof(unsigned _BitInt(128)), ""); |
| 279 |
static_assert(__builtin_popcountg((unsigned _BitInt(128))0) == 0, ""); |
| 280 |
#endif |
| 281 |
|
| 282 |
/// From test/Sema/constant-builtins-2.c |
| 283 |
char popcount1[__builtin_popcount(0) == 0 ? 1 : -1]; |
| 284 |
char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1]; |
| 285 |
char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1]; |
| 286 |
char popcount4[__builtin_popcount(~0L) == BITSIZE(int) ? 1 : -1]; |
| 287 |
char popcount5[__builtin_popcountl(0L) == 0 ? 1 : -1]; |
| 288 |
char popcount6[__builtin_popcountl(0xF0F0L) == 8 ? 1 : -1]; |
| 289 |
char popcount7[__builtin_popcountl(~0L) == BITSIZE(long) ? 1 : -1]; |
| 290 |
char popcount8[__builtin_popcountll(0LL) == 0 ? 1 : -1]; |
| 291 |
char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1]; |
| 292 |
char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1]; |
| 293 |
char popcount11[__builtin_popcountg(0U) == 0 ? 1 : -1]; |
| 294 |
char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1]; |
| 295 |
char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1]; |
| 296 |
char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1]; |
| 297 |
char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1]; |
| 298 |
#ifdef __SIZEOF_INT128__ |
| 299 |
char popcount16[__builtin_popcountg(~(unsigned __int128)0) == BITSIZE(__int128) ? 1 : -1]; |
| 300 |
#endif |
| 301 |
#ifndef __AVR__ |
| 302 |
char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == BITSIZE(_BitInt(128)) ? 1 : -1]; |
| 303 |
#endif |
| 304 |
} |
| 305 |
|
| 306 |
namespace parity { |
| 307 |
/// From test/Sema/constant-builtins-2.c |
| 308 |
char parity1[__builtin_parity(0) == 0 ? 1 : -1]; |
| 309 |
char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1]; |
| 310 |
char parity3[__builtin_parity(0xb822) == 0 ? 1 : -1]; |
| 311 |
char parity4[__builtin_parity(0xb823) == 1 ? 1 : -1]; |
| 312 |
char parity5[__builtin_parity(0xb824) == 0 ? 1 : -1]; |
| 313 |
char parity6[__builtin_parity(0xb825) == 1 ? 1 : -1]; |
| 314 |
char parity7[__builtin_parity(0xb826) == 1 ? 1 : -1]; |
| 315 |
char parity8[__builtin_parity(~0) == 0 ? 1 : -1]; |
| 316 |
char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1]; |
| 317 |
char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1]; |
| 318 |
} |
| 319 |
|
| 320 |
namespace clrsb { |
| 321 |
char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1]; |
| 322 |
char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1]; |
| 323 |
char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 324 |
char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1]; |
| 325 |
char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1]; |
| 326 |
char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 327 |
char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1]; |
| 328 |
char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1]; |
| 329 |
char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1]; |
| 330 |
char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1]; |
| 331 |
char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1]; |
| 332 |
char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1]; |
| 333 |
} |
| 334 |
|
| 335 |
namespace bitreverse { |
| 336 |
char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1]; |
| 337 |
char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1]; |
| 338 |
char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1]; |
| 339 |
char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480 ? 1 : -1]; |
| 340 |
} |
| 341 |
|
| 342 |
namespace expect { |
| 343 |
constexpr int a() { |
| 344 |
return 12; |
| 345 |
} |
| 346 |
static_assert(__builtin_expect(a(),1) == 12, ""); |
| 347 |
static_assert(__builtin_expect_with_probability(a(), 1, 1.0) == 12, ""); |
| 348 |
} |
| 349 |
|
| 350 |
namespace rotateleft { |
| 351 |
char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1]; |
| 352 |
char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1]; |
| 353 |
char rotateleft3[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : -1]; |
| 354 |
char rotateleft4[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 0x87F6E5D4C3B2A19ULL ? 1 : -1]; |
| 355 |
} |
| 356 |
|
| 357 |
namespace rotateright { |
| 358 |
char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1]; |
| 359 |
char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1]; |
| 360 |
char rotateright3[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 : -1]; |
| 361 |
char rotateright4[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1]; |
| 362 |
} |
| 363 |
|
| 364 |
namespace ffs { |
| 365 |
char ffs1[__builtin_ffs(0) == 0 ? 1 : -1]; |
| 366 |
char ffs2[__builtin_ffs(1) == 1 ? 1 : -1]; |
| 367 |
char ffs3[__builtin_ffs(0xfbe71) == 1 ? 1 : -1]; |
| 368 |
char ffs4[__builtin_ffs(0xfbe70) == 5 ? 1 : -1]; |
| 369 |
char ffs5[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1]; |
| 370 |
char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1]; |
| 371 |
char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1]; |
| 372 |
} |
| 373 |
|
| 374 |
namespace EhReturnDataRegno { |
| 375 |
void test11(int X) { |
| 376 |
switch (X) { |
| 377 |
case __builtin_eh_return_data_regno(0): // constant foldable. |
| 378 |
break; |
| 379 |
} |
| 380 |
__builtin_eh_return_data_regno(X); // both-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/// From test/SemaCXX/builtins.cpp |
| 385 |
namespace test_launder { |
| 386 |
#define TEST_TYPE(Ptr, Type) \ |
| 387 |
static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type") |
| 388 |
|
| 389 |
struct Dummy {}; |
| 390 |
|
| 391 |
using FnType = int(char); |
| 392 |
using MemFnType = int (Dummy::*)(char); |
| 393 |
using ConstMemFnType = int (Dummy::*)() const; |
| 394 |
|
| 395 |
void foo() {} |
| 396 |
|
| 397 |
void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp, |
| 398 |
MemFnType mfp, ConstMemFnType cmfp, int (&Arr)[5]) { |
| 399 |
__builtin_launder(vp); // both-error {{void pointer argument to '__builtin_launder' is not allowed}} |
| 400 |
__builtin_launder(cvp); // both-error {{void pointer argument to '__builtin_launder' is not allowed}} |
| 401 |
__builtin_launder(fnp); // both-error {{function pointer argument to '__builtin_launder' is not allowed}} |
| 402 |
__builtin_launder(mfp); // both-error {{non-pointer argument to '__builtin_launder' is not allowed}} |
| 403 |
__builtin_launder(cmfp); // both-error {{non-pointer argument to '__builtin_launder' is not allowed}} |
| 404 |
(void)__builtin_launder(&fnp); |
| 405 |
__builtin_launder(42); // both-error {{non-pointer argument to '__builtin_launder' is not allowed}} |
| 406 |
__builtin_launder(nullptr); // both-error {{non-pointer argument to '__builtin_launder' is not allowed}} |
| 407 |
__builtin_launder(foo); // both-error {{function pointer argument to '__builtin_launder' is not allowed}} |
| 408 |
(void)__builtin_launder(Arr); |
| 409 |
} |
| 410 |
|
| 411 |
void test_builtin_launder(char *p, const volatile int *ip, const float *&fp, |
| 412 |
double *__restrict dp) { |
| 413 |
int x; |
| 414 |
__builtin_launder(x); // both-error {{non-pointer argument to '__builtin_launder' is not allowed}} |
| 415 |
|
| 416 |
TEST_TYPE(p, char*); |
| 417 |
TEST_TYPE(ip, const volatile int*); |
| 418 |
TEST_TYPE(fp, const float*); |
| 419 |
TEST_TYPE(dp, double *__restrict); |
| 420 |
|
| 421 |
char *d = __builtin_launder(p); |
| 422 |
const volatile int *id = __builtin_launder(ip); |
| 423 |
int *id2 = __builtin_launder(ip); // both-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}} |
| 424 |
const float* fd = __builtin_launder(fp); |
| 425 |
} |
| 426 |
|
| 427 |
void test_launder_return_type(const int (&ArrayRef)[101], int (&MArrRef)[42][13], |
| 428 |
void (**&FuncPtrRef)()) { |
| 429 |
TEST_TYPE(ArrayRef, const int *); |
| 430 |
TEST_TYPE(MArrRef, int(*)[13]); |
| 431 |
TEST_TYPE(FuncPtrRef, void (**)()); |
| 432 |
} |
| 433 |
|
| 434 |
template <class Tp> |
| 435 |
constexpr Tp *test_constexpr_launder(Tp *tp) { |
| 436 |
return __builtin_launder(tp); |
| 437 |
} |
| 438 |
constexpr int const_int = 42; |
| 439 |
constexpr int const_int2 = 101; |
| 440 |
constexpr const int *const_ptr = test_constexpr_launder(&const_int); |
| 441 |
static_assert(&const_int == const_ptr, ""); |
| 442 |
static_assert(const_ptr != test_constexpr_launder(&const_int2), ""); |
| 443 |
|
| 444 |
void test_non_constexpr() { |
| 445 |
constexpr int i = 42; // both-note {{address of non-static constexpr variable 'i' may differ on each invocation}} |
| 446 |
constexpr const int *ip = __builtin_launder(&i); // both-error {{constexpr variable 'ip' must be initialized by a constant expression}} |
| 447 |
// both-note@-1 {{pointer to 'i' is not a constant expression}} |
| 448 |
} |
| 449 |
|
| 450 |
constexpr bool test_in_constexpr(const int &i) { |
| 451 |
return (__builtin_launder(&i) == &i); |
| 452 |
} |
| 453 |
|
| 454 |
static_assert(test_in_constexpr(const_int), ""); |
| 455 |
void f() { |
| 456 |
constexpr int i = 42; |
| 457 |
static_assert(test_in_constexpr(i), ""); |
| 458 |
} |
| 459 |
|
| 460 |
struct Incomplete; // both-note {{forward declaration}} |
| 461 |
struct IncompleteMember { |
| 462 |
Incomplete &i; |
| 463 |
}; |
| 464 |
void test_incomplete(Incomplete *i, IncompleteMember *im) { |
| 465 |
// both-error@+1 {{incomplete type 'Incomplete' where a complete type is required}} |
| 466 |
__builtin_launder(i); |
| 467 |
__builtin_launder(&i); // OK |
| 468 |
__builtin_launder(im); // OK |
| 469 |
} |
| 470 |
|
| 471 |
void test_noexcept(int *i) { |
| 472 |
static_assert(noexcept(__builtin_launder(i)), ""); |
| 473 |
} |
| 474 |
#undef TEST_TYPE |
| 475 |
} // end namespace test_launder |
| 476 |
|
| 477 |
|
| 478 |
/// FIXME: The commented out tests here use a IntAP value and fail. |
| 479 |
/// This currently means we will leak the IntAP value since nothing cleans it up. |
| 480 |
namespace clz { |
| 481 |
char clz1[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1]; |
| 482 |
char clz2[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1]; |
| 483 |
char clz3[__builtin_clz(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1]; |
| 484 |
int clz4 = __builtin_clz(0); |
| 485 |
char clz5[__builtin_clzl(0xFL) == BITSIZE(long) - 4 ? 1 : -1]; |
| 486 |
char clz6[__builtin_clzll(0xFFLL) == BITSIZE(long long) - 8 ? 1 : -1]; |
| 487 |
char clz7[__builtin_clzs(0x1) == BITSIZE(short) - 1 ? 1 : -1]; |
| 488 |
char clz8[__builtin_clzs(0xf) == BITSIZE(short) - 4 ? 1 : -1]; |
| 489 |
char clz9[__builtin_clzs(0xfff) == BITSIZE(short) - 12 ? 1 : -1]; |
| 490 |
|
| 491 |
int clz10 = __builtin_clzg((unsigned char)0); |
| 492 |
char clz11[__builtin_clzg((unsigned char)0, 42) == 42 ? 1 : -1]; |
| 493 |
char clz12[__builtin_clzg((unsigned char)0x1) == BITSIZE(char) - 1 ? 1 : -1]; |
| 494 |
char clz13[__builtin_clzg((unsigned char)0x1, 42) == BITSIZE(char) - 1 ? 1 : -1]; |
| 495 |
char clz14[__builtin_clzg((unsigned char)0xf) == BITSIZE(char) - 4 ? 1 : -1]; |
| 496 |
char clz15[__builtin_clzg((unsigned char)0xf, 42) == BITSIZE(char) - 4 ? 1 : -1]; |
| 497 |
char clz16[__builtin_clzg((unsigned char)(1 << (BITSIZE(char) - 1))) == 0 ? 1 : -1]; |
| 498 |
char clz17[__builtin_clzg((unsigned char)(1 << (BITSIZE(char) - 1)), 42) == 0 ? 1 : -1]; |
| 499 |
int clz18 = __builtin_clzg((unsigned short)0); |
| 500 |
char clz19[__builtin_clzg((unsigned short)0, 42) == 42 ? 1 : -1]; |
| 501 |
char clz20[__builtin_clzg((unsigned short)0x1) == BITSIZE(short) - 1 ? 1 : -1]; |
| 502 |
char clz21[__builtin_clzg((unsigned short)0x1, 42) == BITSIZE(short) - 1 ? 1 : -1]; |
| 503 |
char clz22[__builtin_clzg((unsigned short)0xf) == BITSIZE(short) - 4 ? 1 : -1]; |
| 504 |
char clz23[__builtin_clzg((unsigned short)0xf, 42) == BITSIZE(short) - 4 ? 1 : -1]; |
| 505 |
char clz24[__builtin_clzg((unsigned short)(1 << (BITSIZE(short) - 1))) == 0 ? 1 : -1]; |
| 506 |
char clz25[__builtin_clzg((unsigned short)(1 << (BITSIZE(short) - 1)), 42) == 0 ? 1 : -1]; |
| 507 |
int clz26 = __builtin_clzg(0U); |
| 508 |
char clz27[__builtin_clzg(0U, 42) == 42 ? 1 : -1]; |
| 509 |
char clz28[__builtin_clzg(0x1U) == BITSIZE(int) - 1 ? 1 : -1]; |
| 510 |
char clz29[__builtin_clzg(0x1U, 42) == BITSIZE(int) - 1 ? 1 : -1]; |
| 511 |
char clz30[__builtin_clzg(0xfU) == BITSIZE(int) - 4 ? 1 : -1]; |
| 512 |
char clz31[__builtin_clzg(0xfU, 42) == BITSIZE(int) - 4 ? 1 : -1]; |
| 513 |
char clz32[__builtin_clzg(1U << (BITSIZE(int) - 1)) == 0 ? 1 : -1]; |
| 514 |
char clz33[__builtin_clzg(1U << (BITSIZE(int) - 1), 42) == 0 ? 1 : -1]; |
| 515 |
int clz34 = __builtin_clzg(0UL); |
| 516 |
char clz35[__builtin_clzg(0UL, 42) == 42 ? 1 : -1]; |
| 517 |
char clz36[__builtin_clzg(0x1UL) == BITSIZE(long) - 1 ? 1 : -1]; |
| 518 |
char clz37[__builtin_clzg(0x1UL, 42) == BITSIZE(long) - 1 ? 1 : -1]; |
| 519 |
char clz38[__builtin_clzg(0xfUL) == BITSIZE(long) - 4 ? 1 : -1]; |
| 520 |
char clz39[__builtin_clzg(0xfUL, 42) == BITSIZE(long) - 4 ? 1 : -1]; |
| 521 |
char clz40[__builtin_clzg(1UL << (BITSIZE(long) - 1)) == 0 ? 1 : -1]; |
| 522 |
char clz41[__builtin_clzg(1UL << (BITSIZE(long) - 1), 42) == 0 ? 1 : -1]; |
| 523 |
int clz42 = __builtin_clzg(0ULL); |
| 524 |
char clz43[__builtin_clzg(0ULL, 42) == 42 ? 1 : -1]; |
| 525 |
char clz44[__builtin_clzg(0x1ULL) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 526 |
char clz45[__builtin_clzg(0x1ULL, 42) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 527 |
char clz46[__builtin_clzg(0xfULL) == BITSIZE(long long) - 4 ? 1 : -1]; |
| 528 |
char clz47[__builtin_clzg(0xfULL, 42) == BITSIZE(long long) - 4 ? 1 : -1]; |
| 529 |
char clz48[__builtin_clzg(1ULL << (BITSIZE(long long) - 1)) == 0 ? 1 : -1]; |
| 530 |
char clz49[__builtin_clzg(1ULL << (BITSIZE(long long) - 1), 42) == 0 ? 1 : -1]; |
| 531 |
#ifdef __SIZEOF_INT128__ |
| 532 |
// int clz50 = __builtin_clzg((unsigned __int128)0); |
| 533 |
char clz51[__builtin_clzg((unsigned __int128)0, 42) == 42 ? 1 : -1]; |
| 534 |
char clz52[__builtin_clzg((unsigned __int128)0x1) == BITSIZE(__int128) - 1 ? 1 : -1]; |
| 535 |
char clz53[__builtin_clzg((unsigned __int128)0x1, 42) == BITSIZE(__int128) - 1 ? 1 : -1]; |
| 536 |
char clz54[__builtin_clzg((unsigned __int128)0xf) == BITSIZE(__int128) - 4 ? 1 : -1]; |
| 537 |
char clz55[__builtin_clzg((unsigned __int128)0xf, 42) == BITSIZE(__int128) - 4 ? 1 : -1]; |
| 538 |
#endif |
| 539 |
#ifndef __AVR__ |
| 540 |
// int clz58 = __builtin_clzg((unsigned _BitInt(128))0); |
| 541 |
char clz59[__builtin_clzg((unsigned _BitInt(128))0, 42) == 42 ? 1 : -1]; |
| 542 |
char clz60[__builtin_clzg((unsigned _BitInt(128))0x1) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; |
| 543 |
char clz61[__builtin_clzg((unsigned _BitInt(128))0x1, 42) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; |
| 544 |
char clz62[__builtin_clzg((unsigned _BitInt(128))0xf) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1]; |
| 545 |
char clz63[__builtin_clzg((unsigned _BitInt(128))0xf, 42) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1]; |
| 546 |
#endif |
| 547 |
} |
| 548 |
|
| 549 |
namespace ctz { |
| 550 |
char ctz1[__builtin_ctz(1) == 0 ? 1 : -1]; |
| 551 |
char ctz2[__builtin_ctz(8) == 3 ? 1 : -1]; |
| 552 |
char ctz3[__builtin_ctz(1 << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1]; |
| 553 |
int ctz4 = __builtin_ctz(0); |
| 554 |
char ctz5[__builtin_ctzl(0x10L) == 4 ? 1 : -1]; |
| 555 |
char ctz6[__builtin_ctzll(0x100LL) == 8 ? 1 : -1]; |
| 556 |
char ctz7[__builtin_ctzs(1 << (BITSIZE(short) - 1)) == BITSIZE(short) - 1 ? 1 : -1]; |
| 557 |
int ctz8 = __builtin_ctzg((unsigned char)0); |
| 558 |
char ctz9[__builtin_ctzg((unsigned char)0, 42) == 42 ? 1 : -1]; |
| 559 |
char ctz10[__builtin_ctzg((unsigned char)0x1) == 0 ? 1 : -1]; |
| 560 |
char ctz11[__builtin_ctzg((unsigned char)0x1, 42) == 0 ? 1 : -1]; |
| 561 |
char ctz12[__builtin_ctzg((unsigned char)0x10) == 4 ? 1 : -1]; |
| 562 |
char ctz13[__builtin_ctzg((unsigned char)0x10, 42) == 4 ? 1 : -1]; |
| 563 |
char ctz14[__builtin_ctzg((unsigned char)(1 << (BITSIZE(char) - 1))) == BITSIZE(char) - 1 ? 1 : -1]; |
| 564 |
char ctz15[__builtin_ctzg((unsigned char)(1 << (BITSIZE(char) - 1)), 42) == BITSIZE(char) - 1 ? 1 : -1]; |
| 565 |
int ctz16 = __builtin_ctzg((unsigned short)0); |
| 566 |
char ctz17[__builtin_ctzg((unsigned short)0, 42) == 42 ? 1 : -1]; |
| 567 |
char ctz18[__builtin_ctzg((unsigned short)0x1) == 0 ? 1 : -1]; |
| 568 |
char ctz19[__builtin_ctzg((unsigned short)0x1, 42) == 0 ? 1 : -1]; |
| 569 |
char ctz20[__builtin_ctzg((unsigned short)0x10) == 4 ? 1 : -1]; |
| 570 |
char ctz21[__builtin_ctzg((unsigned short)0x10, 42) == 4 ? 1 : -1]; |
| 571 |
char ctz22[__builtin_ctzg((unsigned short)(1 << (BITSIZE(short) - 1))) == BITSIZE(short) - 1 ? 1 : -1]; |
| 572 |
char ctz23[__builtin_ctzg((unsigned short)(1 << (BITSIZE(short) - 1)), 42) == BITSIZE(short) - 1 ? 1 : -1]; |
| 573 |
int ctz24 = __builtin_ctzg(0U); |
| 574 |
char ctz25[__builtin_ctzg(0U, 42) == 42 ? 1 : -1]; |
| 575 |
char ctz26[__builtin_ctzg(0x1U) == 0 ? 1 : -1]; |
| 576 |
char ctz27[__builtin_ctzg(0x1U, 42) == 0 ? 1 : -1]; |
| 577 |
char ctz28[__builtin_ctzg(0x10U) == 4 ? 1 : -1]; |
| 578 |
char ctz29[__builtin_ctzg(0x10U, 42) == 4 ? 1 : -1]; |
| 579 |
char ctz30[__builtin_ctzg(1U << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1]; |
| 580 |
char ctz31[__builtin_ctzg(1U << (BITSIZE(int) - 1), 42) == BITSIZE(int) - 1 ? 1 : -1]; |
| 581 |
int ctz32 = __builtin_ctzg(0UL); |
| 582 |
char ctz33[__builtin_ctzg(0UL, 42) == 42 ? 1 : -1]; |
| 583 |
char ctz34[__builtin_ctzg(0x1UL) == 0 ? 1 : -1]; |
| 584 |
char ctz35[__builtin_ctzg(0x1UL, 42) == 0 ? 1 : -1]; |
| 585 |
char ctz36[__builtin_ctzg(0x10UL) == 4 ? 1 : -1]; |
| 586 |
char ctz37[__builtin_ctzg(0x10UL, 42) == 4 ? 1 : -1]; |
| 587 |
char ctz38[__builtin_ctzg(1UL << (BITSIZE(long) - 1)) == BITSIZE(long) - 1 ? 1 : -1]; |
| 588 |
char ctz39[__builtin_ctzg(1UL << (BITSIZE(long) - 1), 42) == BITSIZE(long) - 1 ? 1 : -1]; |
| 589 |
int ctz40 = __builtin_ctzg(0ULL); |
| 590 |
char ctz41[__builtin_ctzg(0ULL, 42) == 42 ? 1 : -1]; |
| 591 |
char ctz42[__builtin_ctzg(0x1ULL) == 0 ? 1 : -1]; |
| 592 |
char ctz43[__builtin_ctzg(0x1ULL, 42) == 0 ? 1 : -1]; |
| 593 |
char ctz44[__builtin_ctzg(0x10ULL) == 4 ? 1 : -1]; |
| 594 |
char ctz45[__builtin_ctzg(0x10ULL, 42) == 4 ? 1 : -1]; |
| 595 |
char ctz46[__builtin_ctzg(1ULL << (BITSIZE(long long) - 1)) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 596 |
char ctz47[__builtin_ctzg(1ULL << (BITSIZE(long long) - 1), 42) == BITSIZE(long long) - 1 ? 1 : -1]; |
| 597 |
#ifdef __SIZEOF_INT128__ |
| 598 |
// int ctz48 = __builtin_ctzg((unsigned __int128)0); |
| 599 |
char ctz49[__builtin_ctzg((unsigned __int128)0, 42) == 42 ? 1 : -1]; |
| 600 |
char ctz50[__builtin_ctzg((unsigned __int128)0x1) == 0 ? 1 : -1]; |
| 601 |
char ctz51[__builtin_ctzg((unsigned __int128)0x1, 42) == 0 ? 1 : -1]; |
| 602 |
char ctz52[__builtin_ctzg((unsigned __int128)0x10) == 4 ? 1 : -1]; |
| 603 |
char ctz53[__builtin_ctzg((unsigned __int128)0x10, 42) == 4 ? 1 : -1]; |
| 604 |
char ctz54[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1)) == BITSIZE(__int128) - 1 ? 1 : -1]; |
| 605 |
char ctz55[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1), 42) == BITSIZE(__int128) - 1 ? 1 : -1]; |
| 606 |
#endif |
| 607 |
#ifndef __AVR__ |
| 608 |
// int ctz56 = __builtin_ctzg((unsigned _BitInt(128))0); |
| 609 |
char ctz57[__builtin_ctzg((unsigned _BitInt(128))0, 42) == 42 ? 1 : -1]; |
| 610 |
char ctz58[__builtin_ctzg((unsigned _BitInt(128))0x1) == 0 ? 1 : -1]; |
| 611 |
char ctz59[__builtin_ctzg((unsigned _BitInt(128))0x1, 42) == 0 ? 1 : -1]; |
| 612 |
char ctz60[__builtin_ctzg((unsigned _BitInt(128))0x10) == 4 ? 1 : -1]; |
| 613 |
char ctz61[__builtin_ctzg((unsigned _BitInt(128))0x10, 42) == 4 ? 1 : -1]; |
| 614 |
char ctz62[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1)) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; |
| 615 |
char ctz63[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1), 42) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; |
| 616 |
#endif |
| 617 |
} |
| 618 |
|
| 619 |
namespace bswap { |
| 620 |
extern int f(void); |
| 621 |
int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f(); |
| 622 |
int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f(); |
| 623 |
int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f(); |
| 624 |
} |
| 625 |
|
| 626 |
#define CFSTR __builtin___CFStringMakeConstantString |
| 627 |
void test7(void) { |
| 628 |
const void *X; |
| 629 |
#if !defined(_AIX) |
| 630 |
X = CFSTR("\242"); // both-warning {{input conversion stopped}} |
| 631 |
X = CFSTR("\0"); // no-warning |
| 632 |
X = CFSTR(242); // both-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}} |
| 633 |
X = CFSTR("foo", "bar"); // both-error {{too many arguments to function call}} |
| 634 |
#endif |
| 635 |
} |
| 636 |
|
| 637 |
/// The actual value on my machine is 22, but I have a feeling this will be different |
| 638 |
/// on other targets, so just checking for != 0 here. Light testing is fine since |
| 639 |
/// the actual implementation uses analyze_os_log::computeOSLogBufferLayout(), which |
| 640 |
/// is tested elsewhere. |
| 641 |
static_assert(__builtin_os_log_format_buffer_size("%{mask.xyz}s", "abc") != 0, ""); |
| 642 |
|
| 643 |
/// Copied from test/Sema/constant_builtins_vector.cpp. |
| 644 |
/// Some tests are missing since we run this for multiple targets, |
| 645 |
/// some of which do not support _BitInt. |
| 646 |
#ifndef __AVR__ |
| 647 |
typedef _BitInt(128) BitInt128; |
| 648 |
typedef double vector4double __attribute__((__vector_size__(32))); |
| 649 |
typedef float vector4float __attribute__((__vector_size__(16))); |
| 650 |
typedef long long vector4long __attribute__((__vector_size__(32))); |
| 651 |
typedef int vector4int __attribute__((__vector_size__(16))); |
| 652 |
typedef short vector4short __attribute__((__vector_size__(8))); |
| 653 |
typedef char vector4char __attribute__((__vector_size__(4))); |
| 654 |
typedef BitInt128 vector4BitInt128 __attribute__((__vector_size__(64))); |
| 655 |
typedef double vector8double __attribute__((__vector_size__(64))); |
| 656 |
typedef float vector8float __attribute__((__vector_size__(32))); |
| 657 |
typedef long long vector8long __attribute__((__vector_size__(64))); |
| 658 |
typedef int vector8int __attribute__((__vector_size__(32))); |
| 659 |
typedef short vector8short __attribute__((__vector_size__(16))); |
| 660 |
typedef char vector8char __attribute__((__vector_size__(8))); |
| 661 |
typedef BitInt128 vector8BitInt128 __attribute__((__vector_size__(128))); |
| 662 |
|
| 663 |
namespace convertvector { |
| 664 |
constexpr vector4double from_vector4double_to_vector4double_var = |
| 665 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4double); |
| 666 |
constexpr vector4float from_vector4double_to_vector4float_var = |
| 667 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4float); |
| 668 |
constexpr vector4long from_vector4double_to_vector4long_var = |
| 669 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4long); |
| 670 |
constexpr vector4int from_vector4double_to_vector4int_var = |
| 671 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4int); |
| 672 |
constexpr vector4short from_vector4double_to_vector4short_var = |
| 673 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4short); |
| 674 |
constexpr vector4char from_vector4double_to_vector4char_var = |
| 675 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4char); |
| 676 |
constexpr vector4BitInt128 from_vector4double_to_vector4BitInt128_var = |
| 677 |
__builtin_convertvector((vector4double){0, 1, 2, 3}, vector4BitInt128); |
| 678 |
constexpr vector4double from_vector4float_to_vector4double_var = |
| 679 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4double); |
| 680 |
constexpr vector4float from_vector4float_to_vector4float_var = |
| 681 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4float); |
| 682 |
constexpr vector4long from_vector4float_to_vector4long_var = |
| 683 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4long); |
| 684 |
constexpr vector4int from_vector4float_to_vector4int_var = |
| 685 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4int); |
| 686 |
constexpr vector4short from_vector4float_to_vector4short_var = |
| 687 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4short); |
| 688 |
constexpr vector4char from_vector4float_to_vector4char_var = |
| 689 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4char); |
| 690 |
constexpr vector4BitInt128 from_vector4float_to_vector4BitInt128_var = |
| 691 |
__builtin_convertvector((vector4float){0, 1, 2, 3}, vector4BitInt128); |
| 692 |
constexpr vector4double from_vector4long_to_vector4double_var = |
| 693 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4double); |
| 694 |
constexpr vector4float from_vector4long_to_vector4float_var = |
| 695 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4float); |
| 696 |
constexpr vector4long from_vector4long_to_vector4long_var = |
| 697 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4long); |
| 698 |
constexpr vector4int from_vector4long_to_vector4int_var = |
| 699 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4int); |
| 700 |
constexpr vector4short from_vector4long_to_vector4short_var = |
| 701 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4short); |
| 702 |
constexpr vector4char from_vector4long_to_vector4char_var = |
| 703 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4char); |
| 704 |
constexpr vector4BitInt128 from_vector4long_to_vector4BitInt128_var = |
| 705 |
__builtin_convertvector((vector4long){0, 1, 2, 3}, vector4BitInt128); |
| 706 |
constexpr vector4double from_vector4int_to_vector4double_var = |
| 707 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4double); |
| 708 |
constexpr vector4float from_vector4int_to_vector4float_var = |
| 709 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4float); |
| 710 |
constexpr vector4long from_vector4int_to_vector4long_var = |
| 711 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4long); |
| 712 |
constexpr vector4int from_vector4int_to_vector4int_var = |
| 713 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4int); |
| 714 |
constexpr vector4short from_vector4int_to_vector4short_var = |
| 715 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4short); |
| 716 |
constexpr vector4char from_vector4int_to_vector4char_var = |
| 717 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4char); |
| 718 |
constexpr vector4BitInt128 from_vector4int_to_vector4BitInt128_var = |
| 719 |
__builtin_convertvector((vector4int){0, 1, 2, 3}, vector4BitInt128); |
| 720 |
constexpr vector4double from_vector4short_to_vector4double_var = |
| 721 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4double); |
| 722 |
constexpr vector4float from_vector4short_to_vector4float_var = |
| 723 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4float); |
| 724 |
constexpr vector4long from_vector4short_to_vector4long_var = |
| 725 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4long); |
| 726 |
constexpr vector4int from_vector4short_to_vector4int_var = |
| 727 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4int); |
| 728 |
constexpr vector4short from_vector4short_to_vector4short_var = |
| 729 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4short); |
| 730 |
constexpr vector4char from_vector4short_to_vector4char_var = |
| 731 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4char); |
| 732 |
constexpr vector4BitInt128 from_vector4short_to_vector4BitInt128_var = |
| 733 |
__builtin_convertvector((vector4short){0, 1, 2, 3}, vector4BitInt128); |
| 734 |
constexpr vector4double from_vector4char_to_vector4double_var = |
| 735 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4double); |
| 736 |
constexpr vector4float from_vector4char_to_vector4float_var = |
| 737 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4float); |
| 738 |
constexpr vector4long from_vector4char_to_vector4long_var = |
| 739 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4long); |
| 740 |
constexpr vector4int from_vector4char_to_vector4int_var = |
| 741 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4int); |
| 742 |
constexpr vector4short from_vector4char_to_vector4short_var = |
| 743 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4short); |
| 744 |
constexpr vector4char from_vector4char_to_vector4char_var = |
| 745 |
__builtin_convertvector((vector4char){0, 1, 2, 3}, vector4char); |
| 746 |
constexpr vector8double from_vector8double_to_vector8double_var = |
| 747 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 748 |
vector8double); |
| 749 |
constexpr vector8float from_vector8double_to_vector8float_var = |
| 750 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 751 |
vector8float); |
| 752 |
constexpr vector8long from_vector8double_to_vector8long_var = |
| 753 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 754 |
vector8long); |
| 755 |
constexpr vector8int from_vector8double_to_vector8int_var = |
| 756 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 757 |
vector8int); |
| 758 |
constexpr vector8short from_vector8double_to_vector8short_var = |
| 759 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 760 |
vector8short); |
| 761 |
constexpr vector8char from_vector8double_to_vector8char_var = |
| 762 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 763 |
vector8char); |
| 764 |
constexpr vector8BitInt128 from_vector8double_to_vector8BitInt128_var = |
| 765 |
__builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7}, |
| 766 |
vector8BitInt128); |
| 767 |
constexpr vector8double from_vector8float_to_vector8double_var = |
| 768 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 769 |
vector8double); |
| 770 |
constexpr vector8float from_vector8float_to_vector8float_var = |
| 771 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 772 |
vector8float); |
| 773 |
constexpr vector8long from_vector8float_to_vector8long_var = |
| 774 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 775 |
vector8long); |
| 776 |
constexpr vector8int from_vector8float_to_vector8int_var = |
| 777 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, vector8int); |
| 778 |
constexpr vector8short from_vector8float_to_vector8short_var = |
| 779 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 780 |
vector8short); |
| 781 |
constexpr vector8char from_vector8float_to_vector8char_var = |
| 782 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 783 |
vector8char); |
| 784 |
constexpr vector8BitInt128 from_vector8float_to_vector8BitInt128_var = |
| 785 |
__builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, |
| 786 |
vector8BitInt128); |
| 787 |
constexpr vector8double from_vector8long_to_vector8double_var = |
| 788 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, |
| 789 |
vector8double); |
| 790 |
constexpr vector8float from_vector8long_to_vector8float_var = |
| 791 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, |
| 792 |
vector8float); |
| 793 |
constexpr vector8long from_vector8long_to_vector8long_var = |
| 794 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8long); |
| 795 |
constexpr vector8int from_vector8long_to_vector8int_var = |
| 796 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8int); |
| 797 |
constexpr vector8short from_vector8long_to_vector8short_var = |
| 798 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, |
| 799 |
vector8short); |
| 800 |
constexpr vector8char from_vector8long_to_vector8char_var = |
| 801 |
__builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8char); |
| 802 |
constexpr vector8double from_vector8int_to_vector8double_var = |
| 803 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, |
| 804 |
vector8double); |
| 805 |
constexpr vector8float from_vector8int_to_vector8float_var = |
| 806 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8float); |
| 807 |
constexpr vector8long from_vector8int_to_vector8long_var = |
| 808 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8long); |
| 809 |
constexpr vector8int from_vector8int_to_vector8int_var = |
| 810 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8int); |
| 811 |
constexpr vector8short from_vector8int_to_vector8short_var = |
| 812 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8short); |
| 813 |
constexpr vector8char from_vector8int_to_vector8char_var = |
| 814 |
__builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8char); |
| 815 |
constexpr vector8double from_vector8short_to_vector8double_var = |
| 816 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, |
| 817 |
vector8double); |
| 818 |
constexpr vector8float from_vector8short_to_vector8float_var = |
| 819 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, |
| 820 |
vector8float); |
| 821 |
constexpr vector8long from_vector8short_to_vector8long_var = |
| 822 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, |
| 823 |
vector8long); |
| 824 |
constexpr vector8int from_vector8short_to_vector8int_var = |
| 825 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, vector8int); |
| 826 |
constexpr vector8short from_vector8short_to_vector8short_var = |
| 827 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, |
| 828 |
vector8short); |
| 829 |
constexpr vector8char from_vector8short_to_vector8char_var = |
| 830 |
__builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, |
| 831 |
vector8char); |
| 832 |
|
| 833 |
constexpr vector8double from_vector8char_to_vector8double_var = |
| 834 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, |
| 835 |
vector8double); |
| 836 |
constexpr vector8float from_vector8char_to_vector8float_var = |
| 837 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, |
| 838 |
vector8float); |
| 839 |
constexpr vector8long from_vector8char_to_vector8long_var = |
| 840 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8long); |
| 841 |
constexpr vector8int from_vector8char_to_vector8int_var = |
| 842 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8int); |
| 843 |
constexpr vector8short from_vector8char_to_vector8short_var = |
| 844 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, |
| 845 |
vector8short); |
| 846 |
constexpr vector8char from_vector8char_to_vector8char_var = |
| 847 |
__builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8char); |
| 848 |
constexpr vector8double from_vector8BitInt128_to_vector8double_var = |
| 849 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 850 |
vector8double); |
| 851 |
constexpr vector8float from_vector8BitInt128_to_vector8float_var = |
| 852 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 853 |
vector8float); |
| 854 |
constexpr vector8long from_vector8BitInt128_to_vector8long_var = |
| 855 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 856 |
vector8long); |
| 857 |
constexpr vector8int from_vector8BitInt128_to_vector8int_var = |
| 858 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 859 |
vector8int); |
| 860 |
constexpr vector8short from_vector8BitInt128_to_vector8short_var = |
| 861 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 862 |
vector8short); |
| 863 |
constexpr vector8char from_vector8BitInt128_to_vector8char_var = |
| 864 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 865 |
vector8char); |
| 866 |
constexpr vector8BitInt128 from_vector8BitInt128_to_vector8BitInt128_var = |
| 867 |
__builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7}, |
| 868 |
vector8BitInt128); |
| 869 |
static_assert(from_vector8BitInt128_to_vector8BitInt128_var[0] == 0, ""); // ref-error {{not an integral constant expression}} |
| 870 |
static_assert(from_vector8BitInt128_to_vector8BitInt128_var[1] == 1, ""); // ref-error {{not an integral constant expression}} |
| 871 |
static_assert(from_vector8BitInt128_to_vector8BitInt128_var[2] == 2, ""); // ref-error {{not an integral constant expression}} |
| 872 |
static_assert(from_vector8BitInt128_to_vector8BitInt128_var[3] == 3, ""); // ref-error {{not an integral constant expression}} |
| 873 |
static_assert(from_vector8BitInt128_to_vector8BitInt128_var[4] == 4, ""); // ref-error {{not an integral constant expression}} |
| 874 |
} |
| 875 |
|
| 876 |
namespace shufflevector { |
| 877 |
constexpr vector4char vector4charConst1 = {0, 1, 2, 3}; |
| 878 |
constexpr vector4char vector4charConst2 = {4, 5, 6, 7}; |
| 879 |
constexpr vector8char vector8intConst = {8, 9, 10, 11, 12, 13, 14, 15}; |
| 880 |
constexpr vector4char vectorShuffle1 = |
| 881 |
__builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 1, 2, 3); |
| 882 |
constexpr vector4char vectorShuffle2 = |
| 883 |
__builtin_shufflevector(vector4charConst1, vector4charConst2, 4, 5, 6, 7); |
| 884 |
constexpr vector4char vectorShuffle3 = |
| 885 |
__builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 2, 4, 6); |
| 886 |
constexpr vector8char vectorShuffle4 = __builtin_shufflevector( |
| 887 |
vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14); |
| 888 |
constexpr vector4char vectorShuffle5 = |
| 889 |
__builtin_shufflevector(vector8intConst, vector8intConst, 0, 2, 4, 6); |
| 890 |
constexpr vector8char vectorShuffle6 = __builtin_shufflevector( |
| 891 |
vector4charConst1, vector4charConst2, 0, 2, 4, 6, 1, 3, 5, 7); |
| 892 |
|
| 893 |
static_assert(vectorShuffle6[0] == 0, "");// ref-error {{not an integral constant expression}} |
| 894 |
static_assert(vectorShuffle6[1] == 2, "");// ref-error {{not an integral constant expression}} |
| 895 |
static_assert(vectorShuffle6[2] == 4, "");// ref-error {{not an integral constant expression}} |
| 896 |
static_assert(vectorShuffle6[3] == 6, "");// ref-error {{not an integral constant expression}} |
| 897 |
static_assert(vectorShuffle6[4] == 1, "");// ref-error {{not an integral constant expression}} |
| 898 |
static_assert(vectorShuffle6[5] == 3, "");// ref-error {{not an integral constant expression}} |
| 899 |
static_assert(vectorShuffle6[6] == 5, "");// ref-error {{not an integral constant expression}} |
| 900 |
static_assert(vectorShuffle6[7] == 7, "");// ref-error {{not an integral constant expression}} |
| 901 |
|
| 902 |
constexpr vector4char vectorShuffleFail1 = __builtin_shufflevector( // both-error {{must be initialized by a constant expression}}\ |
| 903 |
// ref-error {{index for __builtin_shufflevector not within the bounds of the input vectors; index of -1 found at position 0 is not permitted in a constexpr context}} |
| 904 |
vector4charConst1, |
| 905 |
vector4charConst2, -1, -1, -1, -1); |
| 906 |
} |
| 907 |
|
| 908 |
#endif |