summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2017-07-22 20:58:54 -0400
committerSara Golemon <pollita@php.net>2017-07-22 21:22:51 -0400
commitc562d44321ea69612fbe3f7460055e9ed4340baa (patch)
tree124b2bc0ebb10224127f281ff39b2ce83600efed
parentad12da49085c05e11a65eafae1384eae43804d1d (diff)
downloadphp-git-c562d44321ea69612fbe3f7460055e9ed4340baa.tar.gz
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 3a8929b83f..0b4d82b5d5 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -2151,6 +2151,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;
}
@@ -2161,6 +2171,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)