Skip to content

Commit bf4ef6c

Browse files
PenguinwizzardMikeHolman
authored andcommitted
Check for post-lower opcodes earlier than normal.
This change promotes several asserts to failfasts, and adds two additional ones, in order to ensure that no post-lower opcodes are added earlier than the lowerer phase, either by being added to the incoming bytecode buffer, or by corrupting a part of the IR during the earlier phases of the JIT.
1 parent ff21352 commit bf4ef6c

5 files changed

Lines changed: 14 additions & 17 deletions

File tree

lib/Backend/BackwardPass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,8 @@ BackwardPass::ProcessBlock(BasicBlock * block)
25352535
}
25362536
#endif
25372537

2538+
AssertOrFailFastMsg(!instr->IsLowered(), "Lowered instruction detected in pre-lower context!");
2539+
25382540
this->currentInstr = instr;
25392541
this->currentRegion = this->currentBlock->GetFirstInstr()->AsLabelInstr()->GetRegion();
25402542

lib/Backend/IR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ class Instr
484484
bool dstIsAlwaysConvertedToInt32 : 1;
485485
bool dstIsAlwaysConvertedToNumber : 1;
486486
bool isCallInstrProtectedByNoProfileBailout : 1;
487+
bool isNonFastPathFrameDisplay : 1;
487488
protected:
488489
bool isCloned:1;
489490
bool hasBailOutInfo:1;

lib/Backend/IRBuilder.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ IRBuilder::Build()
704704
}
705705
}
706706
#endif
707-
AssertMsg(Js::OpCodeUtil::IsValidByteCodeOpcode(newOpcode), "Error getting opcode from m_jnReader.Op()");
707+
AssertOrFailFastMsg(Js::OpCodeUtil::IsValidByteCodeOpcode(newOpcode), "Error getting opcode from m_jnReader.Op()");
708708

709709
uint layoutAndSize = layoutSize * Js::OpLayoutType::Count + Js::OpCodeUtil::GetOpCodeLayout(newOpcode);
710710
switch(layoutAndSize)
@@ -6824,22 +6824,16 @@ IRBuilder::BuildEmpty(Js::OpCode newOpcode, uint32 offset)
68246824
Js::Constants::NoByteCodeOffset);
68256825
}
68266826

6827-
IR::RegOpnd* tempRegOpnd = IR::RegOpnd::New(StackSym::New(this->m_func), TyVar, this->m_func);
6827+
IR::Instr* lfd = IR::Instr::New(
6828+
Js::OpCode::LdFrameDisplay,
6829+
this->BuildDstOpnd(this->m_func->GetJITFunctionBody()->GetLocalFrameDisplayReg()),
6830+
this->BuildDstOpnd(this->m_func->GetJITFunctionBody()->GetLocalClosureReg()),
6831+
this->BuildDstOpnd(this->m_func->GetJITFunctionBody()->GetLocalFrameDisplayReg()),
6832+
this->m_func);
68286833
this->AddInstr(
6829-
IR::Instr::New(
6830-
Js::OpCode::LdFrameDisplay,
6831-
tempRegOpnd,
6832-
this->BuildSrcOpnd(this->m_func->GetJITFunctionBody()->GetLocalClosureReg()),
6833-
this->BuildSrcOpnd(this->m_func->GetJITFunctionBody()->GetLocalFrameDisplayReg()),
6834-
this->m_func),
6835-
Js::Constants::NoByteCodeOffset);
6836-
this->AddInstr(
6837-
IR::Instr::New(
6838-
Js::OpCode::MOV,
6839-
this->BuildDstOpnd(this->m_func->GetJITFunctionBody()->GetLocalFrameDisplayReg()),
6840-
tempRegOpnd,
6841-
this->m_func),
6834+
lfd,
68426835
Js::Constants::NoByteCodeOffset);
6836+
lfd->isNonFastPathFrameDisplay = true;
68436837
}
68446838
break;
68456839

lib/Backend/IRBuilderAsmJs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ IRBuilderAsmJs::Build()
144144
{
145145
Assert(newOpcode != Js::OpCodeAsmJs::EndOfBlock);
146146

147-
AssertMsg(Js::OpCodeUtilAsmJs::IsValidByteCodeOpcode(newOpcode), "Error getting opcode from m_jnReader.Op()");
147+
AssertOrFailFastMsg(Js::OpCodeUtilAsmJs::IsValidByteCodeOpcode(newOpcode), "Error getting opcode from m_jnReader.Op()");
148148

149149
uint layoutAndSize = layoutSize * Js::OpLayoutTypeAsmJs::Count + Js::OpCodeUtilAsmJs::GetOpCodeLayout(newOpcode);
150150
switch (layoutAndSize)

lib/Backend/Lower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23484,7 +23484,7 @@ void Lowerer::LowerLdFrameDisplay(IR::Instr *instr, bool doStackFrameDisplay)
2348423484
// If the dst opnd is a byte code temp, that indicates we're prepending a block scope or some such and
2348523485
// shouldn't attempt to do this.
2348623486
if (envDepth == (uint16)-1 ||
23487-
(!doStackFrameDisplay && instr->GetDst()->AsRegOpnd()->m_sym->IsTempReg(instr->m_func)) ||
23487+
(!doStackFrameDisplay && (instr->isNonFastPathFrameDisplay || instr->GetDst()->AsRegOpnd()->m_sym->IsTempReg(instr->m_func))) ||
2348823488
PHASE_OFF(Js::FrameDisplayFastPathPhase, func))
2348923489
{
2349023490
if (isStrict)

0 commit comments

Comments
 (0)