1 // RUN: %clang_cc1 -triple x86_64 -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s 2 // RUN: %clang_cc1 -triple x86_64 -std=c++20 -fsyntax-only -verify -disable-llvm-passes -fexperimental-new-constant-interpreter %s 3 4 // REQUIRES: aarch64-registered-target 5 // RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s 6 // RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 -fsyntax-only -verify -disable-llvm-passes -fexperimental-new-constant-interpreter %s 7 8 template <typename T> 9 using VecT __attribute__((vector_size(16))) = T; 10 11 struct FooT { 12 template <typename T> 13 using VecT __attribute__((vector_size(8))) = T; 14 }; 15 16 void test_builtin_vectorelements() { 17 using veci4 __attribute__((vector_size(16))) = int; 18 (void) __builtin_vectorelements(veci4); 19 20 using some_other_vec = veci4; 21 (void) __builtin_vectorelements(some_other_vec); 22 23 using some_int = int; 24 (void) __builtin_vectorelements(some_int); // expected-error {{argument to __builtin_vectorelements must be of vector type}} 25 26 class Foo {}; 27 __builtin_vectorelements(Foo); // expected-error {{argument to __builtin_vectorelements must be of vector type}} 28 29 struct Bar { veci4 vec; }; 30 (void) __builtin_vectorelements(Bar{}.vec); 31 32 struct Baz { using VecT = veci4; }; 33 (void) __builtin_vectorelements(Baz::VecT); 34 35 (void) __builtin_vectorelements(FooT::VecT<long>); 36 (void) __builtin_vectorelements(VecT<char>); 37 38 constexpr int i4 = __builtin_vectorelements(veci4); 39 constexpr int i4p8 = __builtin_vectorelements(veci4) + 8; 40 } 41 42 43 #if defined(__ARM_FEATURE_SVE) 44 #include <arm_sve.h> 45 46 consteval int consteval_elements() { // expected-error {{consteval function never produces a constant expression}} 47 return __builtin_vectorelements(svuint64_t); // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} 48 } 49 50 void test_bad_constexpr() { 51 constexpr int eval = consteval_elements(); // expected-error {{initialized by a constant expression}} // expected-error {{not a constant expression}} // expected-note {{in call}} // expected-note {{in call}} 52 constexpr int i32 = __builtin_vectorelements(svuint32_t); // expected-error {{initialized by a constant expression}} // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} 53 constexpr int i16p8 = __builtin_vectorelements(svuint16_t) + 16; // expected-error {{initialized by a constant expression}} // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} 54 constexpr int lambda = [] { return __builtin_vectorelements(svuint16_t); }(); // expected-error {{initialized by a constant expression}} // expected-note {{cannot determine number of elements for sizeless vectors in a constant expression}} // expected-note {{in call}} 55 } 56 57 #endif 58