[clang] 9a3b969 - [clang][Interp][NFC] Make InitField() not pop the pointer

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 6 23:31:00 PST 2022


Author: Timm Bäder
Date: 2022-11-07T08:30:43+01:00
New Revision: 9a3b969d1faa77d4c629ddb797d317579fbe0555

URL: https://github.com/llvm/llvm-project/commit/9a3b969d1faa77d4c629ddb797d317579fbe0555
DIFF: https://github.com/llvm/llvm-project/commit/9a3b969d1faa77d4c629ddb797d317579fbe0555.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 24b5160eafbc..5362e9cb1ab0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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().

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index bbe4d04c8974..81243d846bc1 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -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.

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c032d0985621..b7666745efd4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -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();


        


More information about the cfe-commits mailing list