summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2017-07-22 21:23:17 -0400
committerSara Golemon <pollita@php.net>2017-07-22 21:23:17 -0400
commit1229b0f8cb483845e20d6687068a8c5edb79f5af (patch)
tree8648a3340f767d3c229fa3cca2e82c67d033f4fa
parentc068818ff33b20a233b0e847f7787459a541249d (diff)
parentc562d44321ea69612fbe3f7460055e9ed4340baa (diff)
downloadphp-git-1229b0f8cb483845e20d6687068a8c5edb79f5af.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fix compile-time optimization of NAN comparisons
-rw-r--r--Zend/zend_operators.c20
-rw-r--r--tests/lang/operators/nan-comparison-false.phpt29
2 files changed, 49 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 418d2f03ea..7d53704da3 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -2166,6 +2166,16 @@ ZEND_API int ZEND_FASTCALL is_not_equal_function(zval *result, zval *op1, zval *
ZEND_API int ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
+ if (UNEXPECTED((Z_TYPE_P(op1) == IS_DOUBLE) && isnan(Z_DVAL_P(op1)))) {
+ ZVAL_FALSE(result);
+ return SUCCESS;
+ }
+
+ if (UNEXPECTED((Z_TYPE_P(op2) == IS_DOUBLE) && isnan(Z_DVAL_P(op2)))) {
+ ZVAL_FALSE(result);
+ return SUCCESS;
+ }
+
if (compare_function(result, op1, op2) == FAILURE) {
return FAILURE;
}
@@ -2176,6 +2186,16 @@ ZEND_API int ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op
ZEND_API int ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
+ if (UNEXPECTED((Z_TYPE_P(op1) == IS_DOUBLE) && isnan(Z_DVAL_P(op1)))) {
+ ZVAL_FALSE(result);
+ return SUCCESS;
+ }
+
+ if (UNEXPECTED((Z_TYPE_P(op2) == IS_DOUBLE) && isnan(Z_DVAL_P(op2)))) {
+ ZVAL_FALSE(result);
+ return SUCCESS;
+ }
+
if (compare_function(result, op1, op2) == FAILURE) {
return FAILURE;
}
diff --git a/tests/lang/operators/nan-comparison-false.phpt b/tests/lang/operators/nan-comparison-false.phpt
new file mode 100644
index 0000000000..f7679b8b67
--- /dev/null
+++ b/tests/lang/operators/nan-comparison-false.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Comparisons with NAN should yield false, even at compile-time
+--FILE--
+<?php
+
+echo "** CONST\n";
+var_dump(0 < NAN);
+var_dump(0 <= NAN);
+var_dump(0 > NAN);
+var_dump(0 >= NAN);
+
+echo "** VAR\n";
+$nan = NAN;
+var_dump(0 < $nan);
+var_dump(0 <= $nan);
+var_dump(0 > $nan);
+var_dump(0 >= $nan);
+
+--EXPECT--
+** CONST
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+** VAR
+bool(false)
+bool(false)
+bool(false)
+bool(false)