[clang] 7b966e2 - [clang][Interp][NFC] Add GetPtrBasePop opcode

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 23:48:47 PST 2023


Author: Timm Bäder
Date: 2023-01-27T08:05:53+01:00
New Revision: 7b966e2156b8b461a29a49122286f804a30236e9

URL: https://github.com/llvm/llvm-project/commit/7b966e2156b8b461a29a49122286f804a30236e9
DIFF: https://github.com/llvm/llvm-project/commit/7b966e2156b8b461a29a49122286f804a30236e9.diff

LOG: [clang][Interp][NFC] Add GetPtrBasePop opcode

Change GetPtrBase to *not* pop the base pointer and add a *Pop variant.
This will be used in later patches.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/lib/AST/Interp/Interp.h
    clang/lib/AST/Interp/Opcodes.td

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 316ba6356436..4c3b6f59a301 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -93,7 +93,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
     const Record::Base *ToBase = R->getBase(ToDecl);
     assert(ToBase);
 
-    return this->emitGetPtrBase(ToBase->Offset, CE);
+    return this->emitGetPtrBasePop(ToBase->Offset, CE);
   }
 
   case CK_FloatingCast: {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 14d132533d24..b35cc017d3d7 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -966,6 +966,14 @@ inline bool GetPtrActiveThisField(InterpState &S, CodePtr OpPC, uint32_t Off) {
 }
 
 inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
+  const Pointer &Ptr = S.Stk.peek<Pointer>();
+  if (!CheckNull(S, OpPC, Ptr, CSK_Base))
+    return false;
+  S.Stk.push<Pointer>(Ptr.atField(Off));
+  return true;
+}
+
+inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off) {
   const Pointer &Ptr = S.Stk.pop<Pointer>();
   if (!CheckNull(S, OpPC, Ptr, CSK_Base))
     return false;

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 54487e9d011b..8b49fb4e61b1 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -274,6 +274,12 @@ def GetPtrBase : Opcode {
   // Offset of field, which is a base.
   let Args = [ArgUint32];
 }
+// [Pointer] -> [Pointer]
+def GetPtrBasePop : Opcode {
+  // Offset of field, which is a base.
+  let Args = [ArgUint32];
+}
+
 // [Pointer] -> [Pointer]
 def GetPtrVirtBase : Opcode {
   // RecordDecl of base class.


        


More information about the cfe-commits mailing list