1 // RUN: %clang_cc1 -triple x86_64 -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s
3 // REQUIRES: aarch64-registered-target
4 // RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s
7 using VecT
__attribute__((vector_size(16))) = T
;
11 using VecT
__attribute__((vector_size(8))) = T
;
14 void test_builtin_vectorelements() {
15 using veci4
__attribute__((vector_size(16))) = int;
16 (void) __builtin_vectorelements(veci4
);
18 using some_other_vec
= veci4
;
19 (void) __builtin_vectorelements(some_other_vec
);
22 (void) __builtin_vectorelements(some_int
); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
25 __builtin_vectorelements(Foo
); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
27 struct Bar
{ veci4 vec
; };
28 (void) __builtin_vectorelements(Bar
{}.vec
);
30 struct Baz
{ using VecT
= veci4
; };
31 (void) __builtin_vectorelements(Baz::VecT
);
33 (void) __builtin_vectorelements(FooT::VecT
<long>);
34 (void) __builtin_vectorelements(VecT
<char>);
36 constexpr int i4
= __builtin_vectorelements(veci4
);
37 constexpr int i4p8
= __builtin_vectorelements(veci4
) + 8;
41 #if defined(__ARM_FEATURE_SVE)
44 consteval
int consteval_elements() { // expected-error {{consteval function never produces a constant expression}}
45 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 void test_bad_constexpr() {
49 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}}
50 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}}
51 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}}
52 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}}