[clang] cbffca2 - [clang][bytecode] Only save frame offset in debug builds (#202294)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 01:10:33 PDT 2026
Author: Timm Baeder
Date: 2026-06-09T10:10:27+02:00
New Revision: cbffca291f395f8b8055396a417ee7620f6582b9
URL: https://github.com/llvm/llvm-project/commit/cbffca291f395f8b8055396a417ee7620f6582b9
DIFF: https://github.com/llvm/llvm-project/commit/cbffca291f395f8b8055396a417ee7620f6582b9.diff
LOG: [clang][bytecode] Only save frame offset in debug builds (#202294)
We only ever use this value to verify that a frame has cleaned up after
itself, i.e. in assertions.
Added:
Modified:
clang/lib/AST/ByteCode/Disasm.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/InterpFrame.cpp
clang/lib/AST/ByteCode/InterpFrame.h
Removed:
################################################################################
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 e5ffe94f1e830..5a1490824b544 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 209319d069b6f..97d33dad0bd98 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;
More information about the cfe-commits
mailing list