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
Родитель ad726bd20b
Коммит 4fd6a8ce4c
3 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -8733,13 +8733,22 @@ TraceRecorder::tableswitch()
high = GET_JUMPX_OFFSET(pc); 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. */ /* Cap maximum table-switch size for modesty. */
if ((high + 1 - low) > MAX_TABLE_SWITCH) if (count > MAX_TABLE_SWITCH)
return InjectStatus(switchop()); return InjectStatus(switchop());
/* Generate switch LIR. */ /* Generate switch LIR. */
SwitchInfo* si = new (traceAlloc()) SwitchInfo(); SwitchInfo* si = new (traceAlloc()) SwitchInfo();
si->count = high + 1 - low; si->count = count;
si->table = 0; si->table = 0;
si->index = (uint32) -1; si->index = (uint32) -1;
LIns* diff = lir->ins2(LIR_subi, v_ins, lir->insImmI(low)); LIns* diff = lir->ins2(LIR_subi, v_ins, lir->insImmI(low));

Просмотреть файл

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

Просмотреть файл

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