Skip to content

Commit 386af4a

Browse files
authored
Revert "[clang][bytecode] Stack-allocate bottom function frame" (#125325)
Reverts #125253 It introduced an msan failure. Caught by a buildbot here: https://lab.llvm.org/buildbot/#/builders/164/builds/6922/steps/17/logs/stdio
1 parent 598106d commit 386af4a

File tree

6 files changed

+7
-23
lines changed

6 files changed

+7
-23
lines changed

clang/lib/AST/ByteCode/EvalEmitter.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ using namespace clang::interp;
1717

1818
EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent,
1919
InterpStack &Stk)
20-
: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx),
21-
BottomFrame(S) {
22-
S.Current = &BottomFrame;
20+
: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {
21+
// Create a dummy frame for the interpreter which does not have locals.
22+
S.Current =
23+
new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0);
2324
}
2425

2526
EvalEmitter::~EvalEmitter() {

clang/lib/AST/ByteCode/EvalEmitter.h

-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ class EvalEmitter : public SourceMapper {
122122
/// Active block which should be executed.
123123
LabelTy ActiveLabel = 0;
124124

125-
InterpFrame BottomFrame;
126-
127125
protected:
128126
#define GET_EVAL_PROTO
129127
#include "Opcodes.inc"

clang/lib/AST/ByteCode/Interp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) {
325325

326326
if (InterpFrame *Caller = S.Current->Caller) {
327327
PC = S.Current->getRetPC();
328-
InterpFrame::free(S.Current);
328+
delete S.Current;
329329
S.Current = Caller;
330330
S.Stk.push<T>(Ret);
331331
} else {
332-
InterpFrame::free(S.Current);
332+
delete S.Current;
333333
S.Current = nullptr;
334334
// The topmost frame should come from an EvalEmitter,
335335
// which has its own implementation of the Ret<> instruction.

clang/lib/AST/ByteCode/InterpFrame.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
using namespace clang;
2424
using namespace clang::interp;
2525

26-
InterpFrame::InterpFrame(InterpState &S)
27-
: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()),
28-
ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {}
29-
3026
InterpFrame::InterpFrame(InterpState &S, const Function *Func,
3127
InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize)
3228
: Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func),

clang/lib/AST/ByteCode/InterpFrame.h

-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class InterpFrame final : public Frame {
2828
/// The frame of the previous function.
2929
InterpFrame *Caller;
3030

31-
/// Bottom Frame.
32-
InterpFrame(InterpState &S);
33-
3431
/// Creates a new frame for a method call.
3532
InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller,
3633
CodePtr RetPC, unsigned ArgSize);
@@ -45,11 +42,6 @@ class InterpFrame final : public Frame {
4542
/// Destroys the frame, killing all live pointers to stack slots.
4643
~InterpFrame();
4744

48-
static void free(InterpFrame *F) {
49-
if (!F->isBottomFrame())
50-
delete F;
51-
}
52-
5345
/// Invokes the destructors for a scope.
5446
void destroy(unsigned Idx);
5547
void initScope(unsigned Idx);
@@ -127,8 +119,6 @@ class InterpFrame final : public Frame {
127119

128120
bool isStdFunction() const;
129121

130-
bool isBottomFrame() const { return IsBottom; }
131-
132122
void dump() const { dump(llvm::errs(), 0); }
133123
void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
134124

@@ -177,7 +167,6 @@ class InterpFrame final : public Frame {
177167
const size_t FrameOffset;
178168
/// Mapping from arg offsets to their argument blocks.
179169
llvm::DenseMap<unsigned, std::unique_ptr<char[]>> Params;
180-
bool IsBottom = false;
181170
};
182171

183172
} // namespace interp

clang/lib/AST/ByteCode/InterpState.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool InterpState::inConstantContext() const {
2727
}
2828

2929
InterpState::~InterpState() {
30-
while (Current && !Current->isBottomFrame()) {
30+
while (Current) {
3131
InterpFrame *Next = Current->Caller;
3232
delete Current;
3333
Current = Next;

0 commit comments

Comments
 (0)