https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/202294
>From cf6251f7e6f37c1aafaf739b8bc74e467bd0118a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 8 Jun 2026 09:42:39 +0200 Subject: [PATCH] FrameOffset --- clang/lib/AST/ByteCode/Disasm.cpp | 2 ++ clang/lib/AST/ByteCode/Interp.h | 6 ++++++ clang/lib/AST/ByteCode/InterpFrame.cpp | 8 +++++--- clang/lib/AST/ByteCode/InterpFrame.h | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp index cf7afcd6d4b1e..4caf830a0a1b4 100644 --- a/clang/lib/AST/ByteCode/Disasm.cpp +++ b/clang/lib/AST/ByteCode/Disasm.cpp @@ -570,7 +570,9 @@ LLVM_DUMP_METHOD void InterpFrame::dump(llvm::raw_ostream &OS, OS.indent(Spaces) << "Depth: " << Depth << "\n"; OS.indent(Spaces) << "ArgSize: " << ArgSize << "\n"; OS.indent(Spaces) << "Args: " << (void *)Args << "\n"; +#ifndef NDEBUG OS.indent(Spaces) << "FrameOffset: " << FrameOffset << "\n"; +#endif OS.indent(Spaces) << "FrameSize: " << (Func ? Func->getFrameSize() : 0) << "\n"; diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index d2ca122d0e805..b9cdd6aba4027 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -260,7 +260,10 @@ PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC) { const T &Ret = S.Stk.pop<T>(); assert(S.Current); + +#ifndef NDEBUG assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); +#endif if (!S.checkingPotentialConstantExpression() || S.Current->Caller) cleanupAfterFunctionCall(S, PC, S.Current->getFunction()); @@ -280,7 +283,10 @@ PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC) { } PRESERVE_NONE inline bool RetVoid(InterpState &S, CodePtr &PC) { + +#ifndef NDEBUG assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); +#endif if (!S.checkingPotentialConstantExpression() || S.Current->Caller) cleanupAfterFunctionCall(S, PC, S.Current->getFunction()); diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 9c9318fe0e55a..bde3e11451602 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -25,13 +25,15 @@ using namespace clang::interp; InterpFrame::InterpFrame(InterpState &S) : Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()), - ArgSize(0), Args(nullptr), FrameOffset(0) {} + ArgSize(0), Args(nullptr) {} InterpFrame::InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize) : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func), - RetPC(RetPC), ArgSize(ArgSize), Args(static_cast<char *>(S.Stk.top())), - FrameOffset(S.Stk.size()) { + RetPC(RetPC), ArgSize(ArgSize), Args(static_cast<char *>(S.Stk.top())) { +#ifndef NDEBUG + FrameOffset = S.Stk.size(); +#endif if (!Func) return; diff --git a/clang/lib/AST/ByteCode/InterpFrame.h b/clang/lib/AST/ByteCode/InterpFrame.h index 7dbf58c23fd5c..4d772e1b55f46 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.h +++ b/clang/lib/AST/ByteCode/InterpFrame.h @@ -92,8 +92,10 @@ class InterpFrame final : public Frame { /// Returns the current function. const Function *getFunction() const { return Func; } +#ifndef NDEBUG /// Returns the offset on the stack at which the frame starts. size_t getFrameOffset() const { return FrameOffset; } +#endif /// Returns the value of a local variable. template <typename T> const T &getLocal(unsigned Offset) const { @@ -223,8 +225,10 @@ class InterpFrame final : public Frame { const unsigned ArgSize; /// Pointer to the arguments in the callee's frame. char *Args = nullptr; +#ifndef NDEBUG /// Offset on the stack at entry. - const size_t FrameOffset; + size_t FrameOffset = 0; +#endif public: unsigned MSVCConstexprAllowed = 0; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
