Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / builtin_vectorelements.cpp
blob59ff09ac72e42d7b3db5b155eafe15ea1fe19884
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
6 template <typename T>
7 using VecT __attribute__((vector_size(16))) = T;
9 struct FooT {
10 template <typename 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);
21 using some_int = int;
22 (void) __builtin_vectorelements(some_int); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
24 class Foo {};
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)
42 #include <arm_sve.h>
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}}
55 #endif