Skip to content

Commit 8608cc1

Browse files
committed
[clang][Interp] Fix array element This chains
The previous test was too minimal. If we actually do something after initializing the nested array element, we end up causing a stack element type mismatch.
1 parent ba8883c commit 8608cc1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool InitLink::emit(Compiler<Emitter> *Ctx, const Expr *E) const {
9292
case K_Elem:
9393
if (!Ctx->emitConstUint32(Offset, E))
9494
return false;
95-
return Ctx->emitArrayElemPtrUint32(E);
95+
return Ctx->emitArrayElemPtrPopUint32(E);
9696
default:
9797
llvm_unreachable("Unhandled InitLink kind");
9898
}
@@ -4156,7 +4156,8 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
41564156
if (InitStackActive && !InitStack.empty()) {
41574157
unsigned StartIndex = 0;
41584158
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
4159-
if (InitStack[StartIndex].Kind != InitLink::K_Field)
4159+
if (InitStack[StartIndex].Kind != InitLink::K_Field &&
4160+
InitStack[StartIndex].Kind != InitLink::K_Elem)
41604161
break;
41614162
}
41624163

clang/test/AST/Interp/records.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,8 +1551,12 @@ namespace ArrayInitChain {
15511551

15521552
constexpr CustomOperandVal A[] = {
15531553
{},
1554+
{{"depctr_hold_cnt"}, 12, 13},
15541555
};
15551556
static_assert(A[0].Str.S == nullptr, "");
15561557
static_assert(A[0].Width == 0, "");
15571558
static_assert(A[0].Mask == 1, "");
1559+
1560+
static_assert(A[1].Width == 12, "");
1561+
static_assert(A[1].Mask == 13, "");
15581562
}

0 commit comments

Comments
 (0)