Skip to content

Instantly share code, notes, and snippets.

@laruence
Last active June 6, 2016 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laruence/f1d62308ff7dc9557f934b8c2e444646 to your computer and use it in GitHub Desktop.
Save laruence/f1d62308ff7dc9557f934b8c2e444646 to your computer and use it in GitHub Desktop.
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index 8ea4347..e3b7905 100644
--- a/ext/opcache/Optimizer/zend_inference.c
+++ b/ext/opcache/Optimizer/zend_inference.c
@@ -3443,6 +3443,18 @@ int zend_infer_types_ex(const zend_op_array *op_array, const zend_script *script
} \
} while (0)
+#if SIZEOF_ZEND_LONG == 8
+static int zend_can_convert_to_double_safely(zend_long val) {
+ /* https://en.wikipedia.org/wiki/IEEE_754-1985 */
+ if (val < (1L<<53) && val >= (-1L << 53)) {
+ return 1;
+ }
+ return 0;
+}
+#else
+#define zend_can_convert_to_double_safely (1)
+#endif
+
static int zend_may_be_used_as_double(const zend_op_array *op_array, zend_ssa *ssa, int var)
{
FOR_EACH_VAR_USAGE(var, CHECK_MAY_BE_USED_AS_DOUBLE);
@@ -3525,7 +3537,8 @@ static int zend_type_narrowing(const zend_op_array *op_array, const zend_script
ssa_ops[ssa_vars[j].definition].result_def < 0 &&
op_array->opcodes[ssa_vars[j].definition].opcode == ZEND_ASSIGN &&
op_array->opcodes[ssa_vars[j].definition].op2_type == IS_CONST &&
- Z_TYPE_P(CRT_CONSTANT_EX(op_array, op_array->opcodes[ssa_vars[j].definition].op2, ssa->rt_constants)) == IS_LONG) {
+ Z_TYPE_P(CRT_CONSTANT_EX(op_array, op_array->opcodes[ssa_vars[j].definition].op2, ssa->rt_constants)) == IS_LONG &&
+ zend_can_convert_to_double_safely(Z_LVAL_P(CRT_CONSTANT_EX(op_array, op_array->opcodes[ssa_vars[j].definition].op2, ssa->rt_constants)))) {
ssa_var_info[j].use_as_double = 1;
}
ssa_var_info[j].type &= ~MAY_BE_ANY;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment