Skip to content

Remove ZEND_DVAL_TO_LVAL_CAST_OK #9215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PHP NEWS
- Standard:
. Fixed bug GH-9017 (php_stream_sock_open_from_socket could return NULL).
(Heiko Weber)
. Fixed incorrect double to long casting in latest clang. (zeriyoshi)

04 Aug 2022, PHP 8.0.22

Expand Down
34 changes: 0 additions & 34 deletions Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -149,40 +149,6 @@ dnl Checks for library functions.
AC_CHECK_FUNCS(getpid kill sigsetjmp)

ZEND_CHECK_FLOAT_PRECISION

dnl Test whether double cast to long preserves least significant bits.
AC_MSG_CHECKING(whether double cast to long preserves least significant bits)

AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <limits.h>
#include <stdlib.h>

int main()
{
if (sizeof(long) == 4) {
double d = (double) LONG_MIN * LONG_MIN + 2e9;

if ((long) d == 2e9 && (long) -d == -2e9) {
return 0;
}
} else if (sizeof(long) == 8) {
double correct = 18e18 - ((double) LONG_MIN * -2); /* Subtract ULONG_MAX + 1 */

if ((long) 18e18 == correct) { /* On 64-bit, only check between LONG_MAX and ULONG_MAX */
return 0;
}
}
return 1;
}
]])], [
AC_DEFINE([ZEND_DVAL_TO_LVAL_CAST_OK], 1, [Define if double cast to long preserves least significant bits])
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
], [
AC_MSG_RESULT(no)
])

])

dnl
Expand Down
4 changes: 1 addition & 3 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3222,8 +3222,7 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const
}
/* }}} */

#ifndef ZEND_DVAL_TO_LVAL_CAST_OK
# if SIZEOF_ZEND_LONG == 4
#if SIZEOF_ZEND_LONG == 4
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d) /* {{{ */
{
double two_pow_32 = pow(2., 32.),
Expand Down Expand Up @@ -3253,4 +3252,3 @@ ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d)
}
/* }}} */
#endif
#endif
11 changes: 0 additions & 11 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const
# define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= (double)ZEND_LONG_MAX || (d) < (double)ZEND_LONG_MIN))
#endif

#ifdef ZEND_DVAL_TO_LVAL_CAST_OK
static zend_always_inline zend_long zend_dval_to_lval(double d)
{
if (EXPECTED(zend_finite(d)) && EXPECTED(!zend_isnan(d))) {
return (zend_long)d;
} else {
return 0;
}
}
#else
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d);

static zend_always_inline zend_long zend_dval_to_lval(double d)
Expand All @@ -120,7 +110,6 @@ static zend_always_inline zend_long zend_dval_to_lval(double d)
}
return (zend_long)d;
}
#endif

static zend_always_inline zend_long zend_dval_to_lval_cap(double d)
{
Expand Down