brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · b23675e Raw
58 lines · cpp
1// RUN: %clang_cc1 -triple x86_64                       -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s2// RUN: %clang_cc1 -triple x86_64                       -std=c++20 -fsyntax-only -verify -disable-llvm-passes -fexperimental-new-constant-interpreter %s3 4// REQUIRES: aarch64-registered-target5// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 -fsyntax-only -verify -disable-llvm-passes %s6// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 -fsyntax-only -verify -disable-llvm-passes -fexperimental-new-constant-interpreter %s7 8template <typename T>9using VecT __attribute__((vector_size(16))) = T;10 11struct FooT {12  template <typename T>13  using VecT __attribute__((vector_size(8))) = T;14};15 16void 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 46consteval 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 50void 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#endif58