Skip to content

Commit fd34a0f

Browse files
committed
[MERGE #5154 @aneeshdk] Fixing a bug in HomeObj retrieval code in lowerer
Merge pull request #5154 from aneeshdk:LowererHomeObjBugFix For ScriptFunction which does not have home object we are expected to return undefined. The logic in Lowerer was getting the wrong offset for this case.
2 parents 579267d + 083fea3 commit fd34a0f

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

lib/Backend/Lower.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24617,33 +24617,35 @@ Lowerer::GenerateLdHomeObj(IR::Instr* instr)
2461724617

2461824618
InsertObjectPoison(instanceRegOpnd, branchInstr, instr, false);
2461924619

24620-
// Is this an function with inline cache and home obj??
24621-
IR::Opnd * vtableAddressInlineFuncHomObjOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheAndHomeObj);
24622-
InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjOpnd, Js::OpCode::BrNeq_A, labelInlineFunc, instr);
24623-
IR::IndirOpnd *indirInlineFuncHomeObjOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>::GetOffsetOfHomeObj(), TyMachPtr, func);
24624-
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjOpnd, instr);
24625-
InsertBranch(Js::OpCode::Br, testLabel, instr);
24626-
24627-
instr->InsertBefore(labelInlineFunc);
24628-
24629-
// Is this a function with inline cache, home obj and computed name??
24630-
IR::Opnd * vtableAddressInlineFuncHomObjCompNameOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheHomeObjAndComputedName);
24631-
InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjCompNameOpnd, Js::OpCode::BrNeq_A, scriptFuncLabel, instr);
24632-
IR::IndirOpnd *indirInlineFuncHomeObjCompNameOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithComputedName<Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>>::GetOffsetOfHomeObj(), TyMachPtr, func);
24633-
Lowerer::InsertMove(dstOpnd, indirInlineFuncHomeObjCompNameOpnd, instr);
24634-
InsertBranch(Js::OpCode::Br, testLabel, instr);
24635-
24636-
instr->InsertBefore(scriptFuncLabel);
24637-
IR::IndirOpnd *indirOpnd = nullptr;
24638-
if (func->GetJITFunctionBody()->HasComputedName())
24639-
{
24640-
indirOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithComputedName<Js::ScriptFunctionWithHomeObj>::GetOffsetOfHomeObj(), TyMachPtr, func);
24620+
if (func->GetJITFunctionBody()->HasHomeObj())
24621+
{
24622+
// Is this an function with inline cache and home obj??
24623+
IR::Opnd * vtableAddressInlineFuncHomObjOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheAndHomeObj);
24624+
IR::BranchInstr* inlineFuncHomObjOpndBr = InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjOpnd, Js::OpCode::BrNeq_A, labelInlineFunc, instr);
24625+
InsertObjectPoison(instanceRegOpnd, inlineFuncHomObjOpndBr, instr, false);
24626+
IR::IndirOpnd *indirInlineFuncHomeObjOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>::GetOffsetOfHomeObj(), TyMachPtr, func);
24627+
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjOpnd, instr);
24628+
InsertBranch(Js::OpCode::Br, testLabel, instr);
24629+
24630+
instr->InsertBefore(labelInlineFunc);
24631+
24632+
// Is this a function with inline cache, home obj and computed name??
24633+
IR::Opnd * vtableAddressInlineFuncHomObjCompNameOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheHomeObjAndComputedName);
24634+
IR::BranchInstr* inlineFuncHomObjCompNameBr = InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjCompNameOpnd, Js::OpCode::BrNeq_A, scriptFuncLabel, instr);
24635+
InsertObjectPoison(instanceRegOpnd, inlineFuncHomObjCompNameBr, instr, false);
24636+
IR::IndirOpnd *indirInlineFuncHomeObjCompNameOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithComputedName<Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>>::GetOffsetOfHomeObj(), TyMachPtr, func);
24637+
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjCompNameOpnd, instr);
24638+
InsertBranch(Js::OpCode::Br, testLabel, instr);
24639+
24640+
instr->InsertBefore(scriptFuncLabel);
24641+
IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::ScriptFunctionWithHomeObj::GetOffsetOfHomeObj(), TyMachPtr, func);
24642+
Lowerer::InsertMove(instanceRegOpnd, indirOpnd, instr);
2464124643
}
2464224644
else
2464324645
{
24644-
indirOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::ScriptFunctionWithHomeObj::GetOffsetOfHomeObj(), TyMachPtr, func);
24646+
// Even if the function does not have home object in eval cases we still have the LdHomeObj opcode
24647+
InsertBranch(Js::OpCode::Br, labelDone, instr);
2464524648
}
24646-
Lowerer::InsertMove(instanceRegOpnd, indirOpnd, instr);
2464724649

2464824650
instr->InsertBefore(testLabel);
2464924651
InsertTestBranch(instanceRegOpnd, instanceRegOpnd, Js::OpCode::BrEq_A, labelDone, instr);

0 commit comments

Comments
 (0)