Skip to content

Commit 9f5a4c3

Browse files
committed
Fixed code generation for MOD
Fixes oss-fuzz #63570
1 parent c2b704b commit 9f5a4c3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ext/opcache/jit/zend_jit_ir.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -5413,7 +5413,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
54135413
jit_SET_EX_OPLINE(jit, opline);
54145414
ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_negative_shift));
54155415
if (Z_MODE(res_addr) == IS_REG) {
5416-
zend_jit_def_reg(jit, res_addr, ir_CONST_LONG(0)); // dead code
5416+
ref = ir_CONST_LONG(0); // dead code
54175417
}
54185418
}
54195419
} else {
@@ -5462,7 +5462,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
54625462
jit_SET_EX_OPLINE(jit, opline);
54635463
ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_negative_shift));
54645464
if (Z_MODE(res_addr) == IS_REG) {
5465-
zend_jit_def_reg(jit, res_addr, ir_CONST_LONG(0)); // dead code
5465+
ref = ir_CONST_LONG(0); // dead code
54665466
}
54675467
}
54685468
} else {
@@ -5503,7 +5503,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
55035503
jit_SET_EX_OPLINE(jit, opline);
55045504
ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_mod_by_zero));
55055505
if (Z_MODE(res_addr) == IS_REG) {
5506-
zend_jit_def_reg(jit, res_addr, ir_CONST_LONG(0)); // dead code
5506+
ref = ir_CONST_LONG(0); // dead code
55075507
}
55085508
} else if (zend_long_is_power_of_two(op2_lval) && op1_range && op1_range->min >= 0) {
55095509
ref = ir_AND_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval - 1));

ext/opcache/tests/jit/mod_008.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
JIT MOD: 008
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
function foo() {
12+
foo(1 / 0 % 0);
13+
};
14+
@foo();
15+
?>
16+
--EXPECTF--
17+
Fatal error: Uncaught DivisionByZeroError: Division by zero in %smod_008.php:3
18+
Stack trace:
19+
#0 %smod_008.php(5): foo()
20+
#1 {main}
21+
thrown in %smod_008.php on line 3

0 commit comments

Comments
 (0)