Skip to content

Commit aee5f51

Browse files
committed
[MERGE #6150 @MikeHolman] fix failure restoring arguments object when aliased in try block
Merge pull request #6150 from MikeHolman:argrestoreintry for stack args bailout needs to know if value we are restoring is arguments (or an alias), but we don't precisely track flow in try blocks, so if assignment is to a writethrough sym we should give up on stack args. Fixes #6058
2 parents 79adb49 + 9c4c3f9 commit aee5f51

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,17 @@ GlobOpt::OptArguments(IR::Instr *instr)
15371537
CannotAllocateArgumentsObjectOnStack(instr->m_func);
15381538
return;
15391539
}
1540+
1541+
// Disable stack args if we are aliasing arguments inside try block to a writethrough symbol.
1542+
// We don't have precise tracking of these symbols, so bailout couldn't know if it needs to restore arguments object or not after exception
1543+
Region* tryRegion = this->currentRegion ? this->currentRegion->GetSelfOrFirstTryAncestor() : nullptr;
1544+
if (tryRegion && tryRegion->GetType() == RegionTypeTry &&
1545+
tryRegion->writeThroughSymbolsSet &&
1546+
tryRegion->writeThroughSymbolsSet->Test(dst->AsRegOpnd()->m_sym->m_id))
1547+
{
1548+
CannotAllocateArgumentsObjectOnStack(instr->m_func);
1549+
return;
1550+
}
15401551
if(!dst->AsRegOpnd()->GetStackSym()->m_nonEscapingArgObjAlias)
15411552
{
15421553
CurrentBlockData()->TrackArgumentsSym(dst->AsRegOpnd());

test/Optimizer/argrestoreintry.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function bar() {
2+
throw new Error();
3+
}
4+
function foo() {
5+
try {
6+
x = arguments;
7+
bar();
8+
} catch (e) {
9+
return x.length;
10+
}
11+
var x = {
12+
j: 1,
13+
k: 2.2
14+
};
15+
}
16+
foo();
17+
foo();
18+
let pass = foo() === 0;
19+
20+
print(pass ? "Pass" : "Fail")

test/Optimizer/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,4 +1611,10 @@
16111611
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1</compile-flags>
16121612
</default>
16131613
</test>
1614+
<test>
1615+
<default>
1616+
<files>argrestoreintry.js</files>
1617+
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1</compile-flags>
1618+
</default>
1619+
</test>
16141620
</regress-exe>

0 commit comments

Comments
 (0)