Truly independent web browser
LibWasm: Check for an add or a sub before reading a step’s arguments
sideshowbarker85180b134847
diff --git a/Libraries/LibWasm/JIT/src/passes/interrupt_checks.rs b/Libraries/LibWasm/JIT/src/passes/interrupt_checks.rsindex f7476567555..8107a529a50 100644--- a/Libraries/LibWasm/JIT/src/passes/interrupt_checks.rs+++ b/Libraries/LibWasm/JIT/src/passes/interrupt_checks.rs@@ -93,7 +93,8 @@ fn test_of(func: &Func, loop_: &Loop, block: BlockId, counters: [Value; 2]) -> O/// By how much `next` changes `phi`, if that is one up or down.fn step_of(func: &Func, phi: Value, next: Value) -> Option<i32> {let node = func.node(next);- if node.ty != Type::I32 {+ // NB: Only an addition or a subtraction has two values as its arguments; a constant's first argument is its value.+ if node.ty != Type::I32 || !matches!(node.op, Op::Add | Op::Sub) {return None;}let (left, right) = (func.resolve(node.args[0]), func.resolve(node.args[1]));diff --git a/Libraries/LibWasm/JIT/tests/interrupt_checks.rs b/Libraries/LibWasm/JIT/tests/interrupt_checks.rsindex 2d4e7a8e7b5..ba08b8bf6fa 100644--- a/Libraries/LibWasm/JIT/tests/interrupt_checks.rs+++ b/Libraries/LibWasm/JIT/tests/interrupt_checks.rs@@ -199,3 +199,19 @@ fn a_subtraction_counts_too() {.concat();assert_eq!(check_count(&in_a_loop(inner)), 1);}++#[test]+fn a_counter_set_to_a_constant_keeps_its_check() {+ // The loop goes on while its counter is nonzero, and the back edge gives the counter a constant, whose value isn't+ // the index of any value in the function.+ let body = [+ LOOP.to_vec(),+ get(I),+ constant(2185),+ set(I),+ BR_IF_0.to_vec(),+ vec![END],+ ]+ .concat();+ assert_eq!(check_count(&body), 1);+}