[clang] [clang][Interp] Member Pointers (PR #91303)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri May 24 21:24:10 PDT 2024


================
@@ -3123,10 +3172,28 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
     }
   }
 
+  std::optional<unsigned> CalleeOffset;
   // Add the (optional, implicit) This pointer.
   if (const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
-    if (!this->visit(MC->getImplicitObjectArgument()))
-      return false;
+    if (!FuncDecl && classifyPrim(E->getCallee()) == PT_MemberPtr) {
+      // If we end up creating a CallPtr op for this, we need the base of the
+      // member pointer as the instance pointer, and later extract the function
+      // decl as the function pointer.
+      const Expr *Callee = E->getCallee();
+      CalleeOffset =
+          this->allocateLocalPrimitive(Callee, PT_MemberPtr, true, false);
+      if (!this->visit(Callee))
+        return false;
+      if (!this->emitSetLocal(PT_MemberPtr, *CalleeOffset, E))
+        return false;
+      if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))
----------------
tbaederr wrote:

We could also `dup()` the value before the `SetLocal` - but the `SetLocal` will remove it from the stack, so we have to get the value somehow again.

https://github.com/llvm/llvm-project/pull/91303


More information about the cfe-commits mailing list