Skip to content

Commit c2d665b

Browse files
committed
[clang][Interp] Support ImplicitArrayInitExpr for vectors
1 parent e614e03 commit c2d665b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,20 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
935935
return true;
936936
}
937937

938+
if (const auto *VecT = E->getType()->getAs<VectorType>()) {
939+
unsigned NumVecElements = VecT->getNumElements();
940+
QualType ElemQT = VecT->getElementType();
941+
PrimType ElemT = classifyPrim(ElemQT);
942+
943+
for (unsigned I = 0; I < NumVecElements; ++I) {
944+
if (!this->visitZeroInitializer(ElemT, ElemQT, E))
945+
return false;
946+
if (!this->emitInitElem(ElemT, I, E))
947+
return false;
948+
}
949+
return true;
950+
}
951+
938952
return false;
939953
}
940954

clang/test/AST/Interp/vectors.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ static_assert(vec4_0[3] == 0.5, ""); // ref-error {{not an integral constant exp
2525
constexpr int vec4_0_discarded = ((float4)12.0f, 0);
2626

2727

28+
/// ImplicitValueInitExpr of vector type
29+
constexpr float4 arr4[2] = {
30+
{1,2,3,4},
31+
};
32+
static_assert(arr4[0][0] == 1, ""); // ref-error {{not an integral constant expression}}
33+
static_assert(arr4[0][1] == 2, ""); // ref-error {{not an integral constant expression}}
34+
static_assert(arr4[0][2] == 3, ""); // ref-error {{not an integral constant expression}}
35+
static_assert(arr4[0][3] == 4, ""); // ref-error {{not an integral constant expression}}
36+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
37+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
38+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
39+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
40+
2841

2942
/// From constant-expression-cxx11.cpp
3043
namespace Vector {

0 commit comments

Comments
 (0)