Skip to content

Commit 32e04be

Browse files
committed
[MERGE #5901 @rajatd] Bug fixes for .call/.apply target inlining
Merge pull request #5901 from rajatd:bugfix
2 parents e018bc9 + 10808ce commit 32e04be

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

lib/Backend/IR.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,6 +3464,11 @@ IR::Instr* Instr::GetBytecodeArgOutCapture()
34643464
this->m_opcode == Js::OpCode::ArgOut_A_InlineBuiltIn);
34653465
Assert(this->m_dst->GetStackSym()->m_isArgCaptured);
34663466
IR::Instr* instr = this->GetSrc1()->GetStackSym()->m_instrDef;
3467+
while (instr->m_opcode != Js::OpCode::BytecodeArgOutCapture)
3468+
{
3469+
Assert(instr->GetSrc1() && instr->GetSrc1()->GetStackSym() && instr->GetSrc1()->GetStackSym()->IsSingleDef());
3470+
instr = instr->GetSrc1()->GetStackSym()->m_instrDef;
3471+
}
34673472
Assert(instr->m_opcode == Js::OpCode::BytecodeArgOutCapture);
34683473
return instr;
34693474
}

lib/Runtime/Language/DynamicProfileInfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,13 @@ namespace Js
11721172
if (functionBody->GetCallSiteToCallApplyCallSiteArray())
11731173
{
11741174
Js::ProfileId callApplyCallSiteId = functionBody->GetCallSiteToCallApplyCallSiteArray()[callSiteId];
1175+
if (callApplyCallSiteId == Js::Constants::NoProfileId)
1176+
{
1177+
return nullptr;
1178+
}
1179+
11751180
Assert(callApplyCallSiteId < functionBody->GetProfiledCallApplyCallSiteCount());
1176-
1181+
11771182
if (callApplyTargetInfo[callApplyCallSiteId].isPolymorphic)
11781183
{
11791184
return nullptr;

lib/Runtime/Language/InterpreterStackFrame.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,11 +3909,14 @@ namespace Js
39093909
if (callSiteToCallApplyCallSiteMap)
39103910
{
39113911
Js::ProfileId callApplyCallSiteId = callSiteToCallApplyCallSiteMap[profileId];
3912-
Assert(callApplyCallSiteId < functionBody->GetProfiledCallApplyCallSiteCount());
3913-
if (callApplyCallSiteId != Js::Constants::NoProfileId)
3912+
if (callApplyCallSiteId < functionBody->GetProfiledCallApplyCallSiteCount())
39143913
{
39153914
dynamicProfileInfo->RecordCallApplyTargetInfo(functionBody, callApplyCallSiteId, targetFunction->GetFunctionInfo(), targetFunction);
39163915
}
3916+
else
3917+
{
3918+
Assert(callApplyCallSiteId == Js::Constants::NoProfileId);
3919+
}
39173920
}
39183921
}
39193922
}

test/inlining/callTarget.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,34 @@ test2();
7272
test2();
7373
test2();
7474
WScript.Echo("PASSED\n");
75+
76+
function test3(a, b)
77+
{
78+
return String.prototype.replace.call(a, b, "a")
79+
}
80+
test3("foobar", /foo/i)
81+
test3("foobar", /foo/i)
82+
test3("foobar", /foo/i)
83+
print("passed")
84+
85+
function test4()
86+
{
87+
function bar(a)
88+
{
89+
return 'call'
90+
}
91+
function test()
92+
{
93+
return this;
94+
}
95+
function foo()
96+
{
97+
test[bar('1')](this);
98+
test.call(this);
99+
}
100+
foo()
101+
foo()
102+
foo()
103+
}
104+
test4()
105+
print("passed")

0 commit comments

Comments
 (0)