Skip to content

Commit 3725717

Browse files
authored
Remove ZEND_DVAL_TO_LVAL_CAST_OK (#9215)
* Remove ZEND_DVAL_TO_LVAL_CAST_OK As far as I can see, this operation should always use the _slow method, and the results seem to be wrong when ZEND_DVAL_TO_LVAL_CAST_OK is enabled. * update NEWS
1 parent a08ffc7 commit 3725717

File tree

4 files changed

+2
-48
lines changed

4 files changed

+2
-48
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
- Standard:
2121
. Fixed bug GH-9017 (php_stream_sock_open_from_socket could return NULL).
2222
(Heiko Weber)
23+
. Fixed incorrect double to long casting in latest clang. (zeriyoshi)
2324

2425
04 Aug 2022, PHP 8.0.22
2526

Zend/Zend.m4

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,6 @@ dnl Checks for library functions.
149149
AC_CHECK_FUNCS(getpid kill sigsetjmp)
150150
151151
ZEND_CHECK_FLOAT_PRECISION
152-
153-
dnl Test whether double cast to long preserves least significant bits.
154-
AC_MSG_CHECKING(whether double cast to long preserves least significant bits)
155-
156-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
157-
#include <limits.h>
158-
#include <stdlib.h>
159-
160-
int main()
161-
{
162-
if (sizeof(long) == 4) {
163-
double d = (double) LONG_MIN * LONG_MIN + 2e9;
164-
165-
if ((long) d == 2e9 && (long) -d == -2e9) {
166-
return 0;
167-
}
168-
} else if (sizeof(long) == 8) {
169-
double correct = 18e18 - ((double) LONG_MIN * -2); /* Subtract ULONG_MAX + 1 */
170-
171-
if ((long) 18e18 == correct) { /* On 64-bit, only check between LONG_MAX and ULONG_MAX */
172-
return 0;
173-
}
174-
}
175-
return 1;
176-
}
177-
]])], [
178-
AC_DEFINE([ZEND_DVAL_TO_LVAL_CAST_OK], 1, [Define if double cast to long preserves least significant bits])
179-
AC_MSG_RESULT(yes)
180-
], [
181-
AC_MSG_RESULT(no)
182-
], [
183-
AC_MSG_RESULT(no)
184-
])
185-
186152
])
187153

188154
dnl

Zend/zend_operators.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,8 +3222,7 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const
32223222
}
32233223
/* }}} */
32243224

3225-
#ifndef ZEND_DVAL_TO_LVAL_CAST_OK
3226-
# if SIZEOF_ZEND_LONG == 4
3225+
#if SIZEOF_ZEND_LONG == 4
32273226
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d) /* {{{ */
32283227
{
32293228
double two_pow_32 = pow(2., 32.),
@@ -3253,4 +3252,3 @@ ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d)
32533252
}
32543253
/* }}} */
32553254
#endif
3256-
#endif

Zend/zend_operators.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const
9999
# define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= (double)ZEND_LONG_MAX || (d) < (double)ZEND_LONG_MIN))
100100
#endif
101101

102-
#ifdef ZEND_DVAL_TO_LVAL_CAST_OK
103-
static zend_always_inline zend_long zend_dval_to_lval(double d)
104-
{
105-
if (EXPECTED(zend_finite(d)) && EXPECTED(!zend_isnan(d))) {
106-
return (zend_long)d;
107-
} else {
108-
return 0;
109-
}
110-
}
111-
#else
112102
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d);
113103

114104
static zend_always_inline zend_long zend_dval_to_lval(double d)
@@ -120,7 +110,6 @@ static zend_always_inline zend_long zend_dval_to_lval(double d)
120110
}
121111
return (zend_long)d;
122112
}
123-
#endif
124113

125114
static zend_always_inline zend_long zend_dval_to_lval_cap(double d)
126115
{

0 commit comments

Comments
 (0)