Skip to content

Commit 9a3b969

Browse files
committed
[clang][Interp][NFC] Make InitField() not pop the pointer
This was confusing. InitElem peeks a pointer, while InitElemPop will pop the pointer. However, for fields, InitField would pop the pointer and no InitFieldPop exists. At least make InitField and InitElem behave the same.
1 parent 6e557e2 commit 9a3b969

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
936936

937937
if (!this->emitInitField(*T, FieldToInit->Offset, Initializer))
938938
return false;
939+
940+
if (!this->emitPopPtr(Initializer))
941+
return false;
939942
} else {
940943
// Non-primitive case. Get a pointer to the field-to-initialize
941944
// on the stack and recurse into visitInitializer().

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
114114

115115
if (!this->emitInitField(*T, F->Offset, InitExpr))
116116
return false;
117+
118+
if (!this->emitPopPtr(InitExpr))
119+
return false;
117120
} else {
118121
// Non-primitive case. Get a pointer to the field-to-initialize
119122
// on the stack and call visitInitialzer() for it.

clang/lib/AST/Interp/Interp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,12 +735,12 @@ bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
735735
}
736736

737737
/// 1) Pops the value from the stack
738-
/// 2) Pops a pointer from the stack
738+
/// 2) Peeks a pointer from the stack
739739
/// 3) Pushes the value to field I of the pointer on the stack
740740
template <PrimType Name, class T = typename PrimConv<Name>::T>
741741
bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
742742
const T &Value = S.Stk.pop<T>();
743-
const Pointer &Field = S.Stk.pop<Pointer>().atField(I);
743+
const Pointer &Field = S.Stk.peek<Pointer>().atField(I);
744744
Field.deref<T>() = Value;
745745
Field.activate();
746746
Field.initialize();

0 commit comments

Comments
 (0)