Index: clang/lib/AST/Interp/Interp.h =================================================================== --- clang/lib/AST/Interp/Interp.h +++ clang/lib/AST/Interp/Interp.h @@ -1499,10 +1499,11 @@ } inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) { - auto NewFrame = std::make_unique(S, Func, PC); - Pointer ThisPtr; if (Func->hasThisPointer()) { - ThisPtr = NewFrame->getThis(); + size_t ThisOffset = + Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0); + const Pointer &ThisPtr = S.Stk.peek(ThisOffset); + if (!CheckInvoke(S, PC, ThisPtr)) return false; @@ -1513,6 +1514,7 @@ if (!CheckCallable(S, PC, Func)) return false; + auto NewFrame = std::make_unique(S, Func, PC); InterpFrame *FrameBefore = S.Current; S.Current = NewFrame.get(); Index: clang/lib/AST/Interp/InterpStack.h =================================================================== --- clang/lib/AST/Interp/InterpStack.h +++ clang/lib/AST/Interp/InterpStack.h @@ -67,6 +67,10 @@ return *reinterpret_cast(peek(aligned_size())); } + template T &peek(size_t Offset) const { + return *reinterpret_cast(peek(Offset)); + } + /// Returns a pointer to the top object. void *top() const { return Chunk ? peek(0) : nullptr; }