[clang][Interp][NFC] Make InitField() not pop the pointer
authorTimm Bäder <tbaeder@redhat.com>
Fri, 21 Oct 2022 13:43:42 +0000 (15:43 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Mon, 7 Nov 2022 07:30:43 +0000 (08:30 +0100)
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.

clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Interp.h

index 24b5160..5362e9c 100644 (file)
@@ -936,6 +936,9 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
 
         if (!this->emitInitField(*T, FieldToInit->Offset, Initializer))
           return false;
+
+        if (!this->emitPopPtr(Initializer))
+          return false;
       } else {
         // Non-primitive case. Get a pointer to the field-to-initialize
         // on the stack and recurse into visitInitializer().
index bbe4d04..81243d8 100644 (file)
@@ -114,6 +114,9 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
 
           if (!this->emitInitField(*T, F->Offset, InitExpr))
             return false;
+
+          if (!this->emitPopPtr(InitExpr))
+            return false;
         } else {
           // Non-primitive case. Get a pointer to the field-to-initialize
           // on the stack and call visitInitialzer() for it.
index c032d09..b766674 100644 (file)
@@ -735,12 +735,12 @@ bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
 }
 
 /// 1) Pops the value from the stack
-/// 2) Pops a pointer from the stack
+/// 2) Peeks a pointer from the stack
 /// 3) Pushes the value to field I of the pointer on the stack
 template <PrimType Name, class T = typename PrimConv<Name>::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop<T>();
-  const Pointer &Field = S.Stk.pop<Pointer>().atField(I);
+  const Pointer &Field = S.Stk.peek<Pointer>().atField(I);
   Field.deref<T>() = Value;
   Field.activate();
   Field.initialize();