[lld] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

Lawrence Benson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 10:11:40 PDT 2023


================
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify %s
+
+void test_builtin_vectorelements() {
+  __builtin_vectorelements(int); // expected-error {{'__builtin_vectorelements' argument must be a vector}}
+  __builtin_vectorelements(float); // expected-error {{'__builtin_vectorelements' argument must be a vector}}
+  __builtin_vectorelements(long*); // expected-error {{'__builtin_vectorelements' argument must be a vector}}
+
+  int a;
+  __builtin_vectorelements(a); // expected-error {{'__builtin_vectorelements' argument must be a vector}}
+
+  typedef int veci4 __attribute__((vector_size(16)));
+  (void) __builtin_vectorelements(veci4);
+
+  veci4 vec;
+  (void) __builtin_vectorelements(vec);
+
+  typedef veci4 some_other_vec;
+  (void) __builtin_vectorelements(some_other_vec);
+
+  struct Foo { int a; };
+  __builtin_vectorelements(struct Foo); // expected-error {{'__builtin_vectorelements' argument must be a vector}}
----------------
lawben wrote:

Are you fine with this giving an error like: (this is what is currently thrown)

```
constexpr variable 'foo' must be initialized by a constant expression
```

or should we explicitly handle this somewhere to say something like: 

```
__builtin_vectorelements cannot be consexpr evaluated with scalable vectors
```

(PS: I'm not really sure how/where to check this for the second case)

https://github.com/llvm/llvm-project/pull/69010


More information about the llvm-commits mailing list