@@ -883,7 +883,7 @@ GlobOpt::ToTypeSpec(BVSparse<JitArenaAllocator> *bv, BasicBlock *block, IRType t
883
883
// instruction itself should disable arguments object optimization.
884
884
if(block->globOptData.argObjSyms && block->globOptData.IsArgumentsSymID(id))
885
885
{
886
- CannotAllocateArgumentsObjectOnStack(insertBeforeInstr->m_func );
886
+ CannotAllocateArgumentsObjectOnStack(nullptr );
887
887
}
888
888
889
889
if (block->globOptData.liveVarSyms->Test(id))
@@ -13087,10 +13087,10 @@ GlobOpt::OptArraySrc(IR::Instr ** const instrRef, Value ** src1Val, Value ** src
13087
13087
void
13088
13088
GlobOpt::OptArgLenAndConst(IR::Instr* instr, Value** src1Val)
13089
13089
{
13090
- if (instr->m_func->IsStackArgsEnabled() && instr->IsInlined())
13090
+ if (instr->usesStackArgumentsObject && instr->IsInlined())
13091
13091
{
13092
13092
IR::Opnd* src1 = instr->GetSrc1();
13093
- auto replaceInstr = [&](IR::Instr* instr, IR:: Opnd* newopnd, Value** src1Val )
13093
+ auto replaceInstr = [&](IR::Opnd* newopnd)
13094
13094
{
13095
13095
this->CaptureByteCodeSymUses(instr);
13096
13096
instr->m_opcode = Js::OpCode::Ld_A;
@@ -13102,22 +13102,20 @@ GlobOpt::OptArgLenAndConst(IR::Instr* instr, Value** src1Val)
13102
13102
*src1Val = this->OptSrc(instr->GetSrc1(), &instr);
13103
13103
instr->m_func->hasArgLenAndConstOpt = true;
13104
13104
};
13105
+ Assert(CurrentBlockData()->IsArgumentsOpnd(src1));
13105
13106
switch(instr->m_opcode)
13106
13107
{
13107
13108
case Js::OpCode::LdLen_A:
13108
13109
{
13109
- if (CurrentBlockData()->IsArgumentsOpnd(src1))
13110
- {
13111
- IR::AddrOpnd* newopnd = IR::AddrOpnd::New(Js::TaggedInt::ToVarUnchecked(instr->m_func->actualCount - 1), IR::AddrOpndKindConstantVar, instr->m_func);
13112
- replaceInstr(instr, newopnd, src1Val);
13113
- }
13110
+ IR::AddrOpnd* newopnd = IR::AddrOpnd::New(Js::TaggedInt::ToVarUnchecked(instr->m_func->actualCount - 1), IR::AddrOpndKindConstantVar, instr->m_func);
13111
+ replaceInstr(newopnd);
13114
13112
break;
13115
13113
}
13116
13114
13117
13115
case Js::OpCode::LdElemI_A:
13118
13116
{
13119
13117
IR::IndirOpnd* indirOpndSrc1 = src1->AsIndirOpnd();
13120
- if (!indirOpndSrc1->GetIndexOpnd() && CurrentBlockData()->IsArgumentsOpnd(src1) )
13118
+ if (!indirOpndSrc1->GetIndexOpnd())
13121
13119
{
13122
13120
int argIndex = indirOpndSrc1->GetOffset() + 1;
13123
13121
IR::Instr* defInstr = nullptr;
@@ -13131,7 +13129,17 @@ GlobOpt::OptArgLenAndConst(IR::Instr* instr, Value** src1Val)
13131
13129
}
13132
13130
return false;
13133
13131
});
13134
- replaceInstr(instr, defInstr->GetSrc1(), src1Val);
13132
+ // If we cannot find the right instruction. I.E. When calling arguments[2] and no arguments were passed to the func
13133
+ if (defInstr == nullptr)
13134
+ {
13135
+ IR::Opnd * undefined = IR::AddrOpnd::New(instr->m_func->GetScriptContextInfo()->GetUndefinedAddr(), IR::AddrOpndKindDynamicVar, instr->m_func, true);
13136
+ undefined->SetValueType(ValueType::Undefined);
13137
+ replaceInstr(undefined);
13138
+ }
13139
+ else
13140
+ {
13141
+ replaceInstr(defInstr->GetSrc1());
13142
+ }
13135
13143
}
13136
13144
break;
13137
13145
}
0 commit comments