Author: Timm Baeder Date: 2026-08-10T14:09:48+02:00 New Revision: f7e6af8aa89a5a68f7c2877cdf2e3b47685eda01
URL: https://github.com/llvm/llvm-project/commit/f7e6af8aa89a5a68f7c2877cdf2e3b47685eda01 DIFF: https://github.com/llvm/llvm-project/commit/f7e6af8aa89a5a68f7c2877cdf2e3b47685eda01.diff LOG: [clang][bytecode] Remove the !Caller case in Ret opcodes (#215226) The bottom frame is always created via an `EvalEmitter`, which has its own implementation of the `Ret` opcode. The exception is `Context::Run`/`isPotentialConstantExpr`. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/lib/AST/ByteCode/Interp.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 9f1d9b899052d..ce7a95ed49c06 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -555,8 +555,8 @@ const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const { } bool Context::Run(State &Parent, const Function *Func) { - InterpState State(Parent, *P, Stk, *this, Func); auto Memory = std::make_unique<char[]>(InterpFrame::allocSize(Func)); + InterpState State(Parent, *P, Stk, *this, Func); InterpFrame *Frame = new (Memory.get()) InterpFrame( State, Func, /*Caller=*/nullptr, CodePtr(), Func->getArgSize()); State.Current = Frame; diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 582cb108f5816..4c8d11a9dd77a 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -295,21 +295,18 @@ PRESERVE_NONE bool Ret(InterpState &S) { assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); #endif - if (!S.checkingPotentialConstantExpression() || S.Current->Caller) - cleanupAfterFunctionCall(S, S.Current->getFunction()); - - if (InterpFrame *Caller = S.Current->Caller) { - S.PC = S.Current->getRetPC(); - InterpFrame::free(S.Current); - S.Current = Caller; - S.Stk.push<T>(Ret); - } else { - InterpFrame::free(S.Current); - S.Current = nullptr; - // The topmost frame should come from an EvalEmitter, - // which has its own implementation of the Ret<> instruction. - } + InterpFrame *Caller = S.Current->Caller; + + // This only happens via Context::Run(). + if (!Caller) + return true; + cleanupAfterFunctionCall(S, S.Current->getFunction()); + + S.PC = S.Current->getRetPC(); + InterpFrame::free(S.Current); + S.Current = Caller; + S.Stk.push<T>(Ret); return true; } @@ -318,18 +315,16 @@ PRESERVE_NONE inline bool RetVoid(InterpState &S) { assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); #endif - if (!S.checkingPotentialConstantExpression() || S.Current->Caller) - cleanupAfterFunctionCall(S, S.Current->getFunction()); + InterpFrame *Caller = S.Current->Caller; + // This only happens via Context::Run(). + if (!Caller) + return true; - if (InterpFrame *Caller = S.Current->Caller) { - S.PC = S.Current->getRetPC(); - InterpFrame::free(S.Current); - S.Current = Caller; - } else { - InterpFrame::free(S.Current); - S.Current = nullptr; - } + cleanupAfterFunctionCall(S, S.Current->getFunction()); + S.PC = S.Current->getRetPC(); + InterpFrame::free(S.Current); + S.Current = Caller; return true; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
