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
Perl_cast_uv broken with CASTFLAGS=7, no quad math, uvsize=4 #15162
Comments
From pipcet@gmail.comCreated by pipcet@gmail.comTL;DR: patch: Inline Patchdiff --git a/numeric.c b/numeric.c
index f1de219..f645502 100644
--- a/numeric.c
+++ b/numeric.c
@@ -39,7 +39,7 @@ Perl_cast_ulong(NV f)
if (f < U32_MAX_P1_HALF)
return (U32) f;
f -= U32_MAX_P1_HALF;
- return ((U32) f) | (1 + U32_MAX >> 1);
+ return ((U32) f) | (1 + (U32_MAX >> 1));
#else
return (U32) f;
#endif
@@ -57,7 +57,7 @@ Perl_cast_i32(NV f)
if (f < U32_MAX_P1_HALF)
return (I32)(U32) f;
f -= U32_MAX_P1_HALF;
- return (I32)(((U32) f) | (1 + U32_MAX >> 1));
+ return (I32)(((U32) f) | (1 + (U32_MAX >> 1)));
#else
return (I32)(U32) f;
#endif
@@ -76,7 +76,7 @@ Perl_cast_iv(NV f)
if (f < UV_MAX_P1_HALF)
return (IV)(UV) f;
f -= UV_MAX_P1_HALF;
- return (IV)(((UV) f) | (1 + UV_MAX >> 1));
+ return (IV)(((UV) f) | (1 + (UV_MAX >> 1)));
#else
return (IV)(UV) f;
#endif
@@ -94,7 +94,7 @@ Perl_cast_uv(NV f)
if (f < UV_MAX_P1_HALF)
return (UV) f;
f -= UV_MAX_P1_HALF;
- return ((UV) f) | (1 + UV_MAX >> 1);
+ return ((UV) f) | (1 + (UV_MAX >> 1));
#else
return (UV) f;
#endif
The symptom is that t/base/lex.t fails with the error message not ok 7 :443541004: generated by this code eval '$foo = 123+123.4+123e4+123.4E5+123.4e+5+.12;'; $foo = int($foo * 100 + .5); We're off by 1<<31! The culprit is in numeric.c's Perl_cast_uv, which return ((UV) f) | (1 + UV_MAX >> 1); I think that should be return ((UV) f) | (1 + (UV_MAX >> 1)); which is equivalent on systems for which UV_MAX + 1 isn't 0 (assuming numeric.c:79:40: warning: suggest parentheses around ‘+’ inside ‘>>’ So even if I'm wrong, this code should probably be fixed another way (It's very suspicious that I'm using gcc but castflags has been set to Unfortunately, perlbug doesn't run yet on the virtual machine, so I'm The GCC backend I'm using is experimental and not really ready for public Perl Info
|
From pipcet@gmail.comperl-002.diffdiff --git a/numeric.c b/numeric.c
index f1de219..f645502 100644
--- a/numeric.c
+++ b/numeric.c
@@ -39,7 +39,7 @@ Perl_cast_ulong(NV f)
if (f < U32_MAX_P1_HALF)
return (U32) f;
f -= U32_MAX_P1_HALF;
- return ((U32) f) | (1 + U32_MAX >> 1);
+ return ((U32) f) | (1 + (U32_MAX >> 1));
#else
return (U32) f;
#endif
@@ -57,7 +57,7 @@ Perl_cast_i32(NV f)
if (f < U32_MAX_P1_HALF)
return (I32)(U32) f;
f -= U32_MAX_P1_HALF;
- return (I32)(((U32) f) | (1 + U32_MAX >> 1));
+ return (I32)(((U32) f) | (1 + (U32_MAX >> 1)));
#else
return (I32)(U32) f;
#endif
@@ -76,7 +76,7 @@ Perl_cast_iv(NV f)
if (f < UV_MAX_P1_HALF)
return (IV)(UV) f;
f -= UV_MAX_P1_HALF;
- return (IV)(((UV) f) | (1 + UV_MAX >> 1));
+ return (IV)(((UV) f) | (1 + (UV_MAX >> 1)));
#else
return (IV)(UV) f;
#endif
@@ -94,7 +94,7 @@ Perl_cast_uv(NV f)
if (f < UV_MAX_P1_HALF)
return (UV) f;
f -= UV_MAX_P1_HALF;
- return ((UV) f) | (1 + UV_MAX >> 1);
+ return ((UV) f) | (1 + (UV_MAX >> 1));
#else
return (UV) f;
#endif
|
From @tonycozOn Fri Feb 05 21:31:07 2016, pipcet@gmail.com wrote:
I didn't get the exact failures you did by manually setting castflags to 7, but I did get failures, and I did see the same warnings. Your changes fixed both the compiler warnings and the test failures. Applied your changes as 071db91 and added you to AUTHORS in 966178a. Tony |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#127474 (status was 'resolved')
Searchable as RT127474$
The text was updated successfully, but these errors were encountered: