Skip to content

Commit

Permalink
JIT x86: Fixed NaN handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Sep 28, 2021
1 parent c30298b commit 7710047
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -8617,8 +8617,9 @@ static int zend_jit_bool_jmpznz(dasm_State **Dst, const zend_op *opline, uint32_
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
} else {
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
| jp &exit_addr
| jp >1
| je &exit_addr
|1:
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
}
} else if (false_label != (uint32_t)-1) { // JMPZ_EX
Expand Down Expand Up @@ -8657,8 +8658,9 @@ static int zend_jit_bool_jmpznz(dasm_State **Dst, const zend_op *opline, uint32_
| jne &exit_addr
|1:
} else {
| jp &exit_addr
| jp >1
| je &exit_addr
|1:
}
} else {
ZEND_ASSERT(true_label != (uint32_t)-1 || false_label != (uint32_t)-1);
Expand Down
20 changes: 20 additions & 0 deletions ext/opcache/tests/jit/nan_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
NaN handling: 001
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
opcache.protect_memory=1
--FILE--
<?php
$b = NAN;
for ($i = 0; $i < 3; $i++) {
if ($b) { echo "nan is true\n"; }
else { echo "nan is false\n"; }
}
?>
--EXPECT--
nan is true
nan is true
nan is true

1 comment on commit 7710047

@nikic
Copy link
Member

@nikic nikic commented on 7710047 Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are still some variations on this issue, for example this will print bool(false) instead of bool(true) under tracing JIT:

<?php
function test($a) { 
    var_dump((bool) $a);
}
test(NAN);

Please sign in to comment.