Bug 570663: turn a tableswitch on trace into a no-op if it has no cases, r=njn

This commit is contained in:
David Mandelin 2010-08-16 18:56:04 -07:00
parent a17fda2b7d
commit 6b0104f903
3 changed files with 27 additions and 2 deletions

View File

@ -8731,13 +8731,22 @@ TraceRecorder::tableswitch()
high = GET_JUMPX_OFFSET(pc);
}
/*
* If there are no cases, this is a no-op. The default case immediately
* follows in the bytecode and is always taken, so we need no special
* action to handle it.
*/
int count = high + 1 - low;
if (count == 0)
return ARECORD_CONTINUE;
/* Cap maximum table-switch size for modesty. */
if ((high + 1 - low) > MAX_TABLE_SWITCH)
if (count > MAX_TABLE_SWITCH)
return InjectStatus(switchop());
/* Generate switch LIR. */
SwitchInfo* si = new (traceAlloc()) SwitchInfo();
si->count = high + 1 - low;
si->count = count;
si->table = 0;
si->index = (uint32) -1;
LIns* diff = lir->ins2(LIR_subi, v_ins, lir->insImmI(low));

View File

@ -0,0 +1,4 @@
// don't crash
for (var a = 0; a < 4; a++) {
switch (NaN) {}
}

View File

@ -0,0 +1,12 @@
function f() {
var x;
for (var a = 0; a < 4; a++) {
switch (NaN) {
default:
x = a;
}
}
assertEq(x, 3);
}
f();