Skip to content

Commit 58b49ce

Browse files
committed
[clang][Interp] Support __builtin_vectorelements
1 parent cce026b commit 58b49ce

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,15 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
12511251
return this->emitConst(Size.getQuantity(), E);
12521252
}
12531253

1254+
if (Kind == UETT_VectorElements) {
1255+
if (const auto *VT = E->getTypeOfArgument()->getAs<VectorType>())
1256+
return this->emitConst(VT->getNumElements(), E);
1257+
1258+
// FIXME: Apparently we need to catch the fact that a sizeless vector type
1259+
// has been passed and diagnose that (at run time).
1260+
assert(E->getTypeOfArgument()->isSizelessVectorType());
1261+
}
1262+
12541263
return false;
12551264
}
12561265

clang/test/AST/Interp/vectors.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ namespace Vector {
1313
return VI4 { n * 3, n + 4, n - 5, n / 6 };
1414
}
1515
constexpr auto v1 = f(10);
16+
static_assert(__builtin_vectorelements(v1) == (16 / sizeof(int)), "");
1617

1718
typedef double __attribute__((vector_size(32))) VD4;
1819
constexpr VD4 g(int n) {
1920
return (VD4) { n / 2.0, n + 1.5, n - 5.4, n * 0.9 };
2021
}
2122
constexpr auto v2 = g(4);
23+
static_assert(__builtin_vectorelements(v2) == (32 / sizeof(double)), "");
2224
}
2325

2426
/// FIXME: We need to support BitCasts between vector types.

0 commit comments

Comments
 (0)