com php-src: Fix Pi constraint for -LONG_MIN adjustments: ext/opcache/Optimizer/zend_ssa.c
| From: | Nikita Popov | Date: | Sat, 19 Dec 2015 23:06:12 +0000 |
| Subject: | com php-src: Fix Pi constraint for -LONG_MIN adjustments: ext/opcache/Optimizer/zend_ssa.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90354@lists.php.net to get a copy of this message | ||
Commit: 549d7d4876d9db1e37ada3b20a12c794f7c2b4ba
Author: Nikita Popov <nikic@php.net> Sat, 19 Dec 2015 23:47:08 +0100
Parents: c9ea8fef967e7426e820e83a0d55b471f95a59e6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=549d7d4876d9db1e37ada3b20a12c794f7c2b4ba
Log:
Fix Pi constraint for -LONG_MIN adjustments
-LONG_MIN == LONG_MIN so bad things will happen.
Example of JIT miscompile:
function test($n) {
if ($n + PHP_INT_MIN == 0) {
$n2 = (int) ($n + PHP_INT_MAX);
var_dump($n2);
}
}
test(PHP_INT_MAX + 1);
Changed paths:
M ext/opcache/Optimizer/zend_ssa.c
Diff:
diff --git a/ext/opcache/Optimizer/zend_ssa.c b/ext/opcache/Optimizer/zend_ssa.c
index f18edfa..5dd55b8 100644
--- a/ext/opcache/Optimizer/zend_ssa.c
+++ b/ext/opcache/Optimizer/zend_ssa.c
@@ -96,12 +96,14 @@ static int find_adjusted_tmp_var(const zend_op_array *op_array, uint32_t build_f
} else if (op->opcode == ZEND_ADD) {
if (op->op1_type == IS_CV &&
op->op2_type == IS_CONST &&
- Z_TYPE_P(CRT_CONSTANT(op->op2)) == IS_LONG) {
+ Z_TYPE_P(CRT_CONSTANT(op->op2)) == IS_LONG &&
+ Z_LVAL_P(CRT_CONSTANT(op->op2)) != LONG_MIN) {
*adjustment = -Z_LVAL_P(CRT_CONSTANT(op->op2));
return EX_VAR_TO_NUM(op->op1.var);
} else if (op->op2_type == IS_CV &&
op->op1_type == IS_CONST &&
- Z_TYPE_P(CRT_CONSTANT(op->op1)) == IS_LONG) {
+ Z_TYPE_P(CRT_CONSTANT(op->op1)) == IS_LONG &&
+ Z_LVAL_P(CRT_CONSTANT(op->op1)) != LONG_MIN) {
*adjustment = -Z_LVAL_P(CRT_CONSTANT(op->op1));
return EX_VAR_TO_NUM(op->op2.var);
}