[RISCV] Simplify usage of SplatPat_simm5_plus1. NFC (#125340)
[llvm-project.git] / clang / test / SemaCXX / builtin_vectorelements.cpp
blobb23675ea0ac6a7451eff294e0cbcba7b41d985da
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
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
8 template <typename T>
9 using VecT __attribute__((vector_size(16))) = T;
11 struct FooT {
12 template <typename T>
13 using VecT __attribute__((vector_size(8))) = T;
16 void test_builtin_vectorelements() {
17 using veci4 __attribute__((vector_size(16))) = int;
18 (void) __builtin_vectorelements(veci4);
20 using some_other_vec = veci4;
21 (void) __builtin_vectorelements(some_other_vec);
23 using some_int = int;
24 (void) __builtin_vectorelements(some_int); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
26 class Foo {};
27 __builtin_vectorelements(Foo); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
29 struct Bar { veci4 vec; };
30 (void) __builtin_vectorelements(Bar{}.vec);
32 struct Baz { using VecT = veci4; };
33 (void) __builtin_vectorelements(Baz::VecT);
35 (void) __builtin_vectorelements(FooT::VecT<long>);
36 (void) __builtin_vectorelements(VecT<char>);
38 constexpr int i4 = __builtin_vectorelements(veci4);
39 constexpr int i4p8 = __builtin_vectorelements(veci4) + 8;
43 #if defined(__ARM_FEATURE_SVE)
44 #include <arm_sve.h>
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}}
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}}
57 #endif