-
Notifications
You must be signed in to change notification settings - Fork 550
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
[PATCH] Clean up integer conversions #15693
Comments
From @petdanceCreated by @petdanceAs part of my work at making everything run clean under clang's Perl Info
|
From @petdanceinteger-types.diffdiff --git a/embed.fnc b/embed.fnc
index 5cc73b7..c659eff 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -2606,7 +2606,7 @@ s |void |force_ident_maybe_lex|char pit
s |void |incline |NN const char *s
s |int |intuit_method |NN char *s|NULLOK SV *ioname|NULLOK CV *cv
s |int |intuit_more |NN char *s
-s |I32 |lop |I32 f|int x|NN char *s
+s |I32 |lop |I32 f|U8 x|NN char *s
rs |void |missingterm |NULLOK char *s
s |void |no_op |NN const char *const what|NULLOK char *s
s |int |pending_ident
diff --git a/proto.h b/proto.h
index 1d79c46..0243910 100644
--- a/proto.h
+++ b/proto.h
@@ -5488,7 +5488,7 @@ STATIC int S_intuit_method(pTHX_ char *s, SV *ioname, CV *cv);
STATIC int S_intuit_more(pTHX_ char *s);
#define PERL_ARGS_ASSERT_INTUIT_MORE \
assert(s)
-STATIC I32 S_lop(pTHX_ I32 f, int x, char *s);
+STATIC I32 S_lop(pTHX_ I32 f, U8 x, char *s);
#define PERL_ARGS_ASSERT_LOP \
assert(s)
PERL_STATIC_NO_RET void S_missingterm(pTHX_ char *s)
diff --git a/toke.c b/toke.c
index ffac930..2495bc2 100644
--- a/toke.c
+++ b/toke.c
@@ -1890,7 +1890,7 @@ S_check_uni(pTHX)
*/
STATIC I32
-S_lop(pTHX_ I32 f, int x, char *s)
+S_lop(pTHX_ I32 f, U8 x, char *s)
{
PERL_ARGS_ASSERT_LOP;
diff --git a/op.c b/op.c
index cf1399e..f25a116 100644
--- a/op.c
+++ b/op.c
@@ -10103,7 +10103,7 @@ Perl_ck_fun(pTHX_ OP *o)
{
GV * const gv = cGVOPx_gv(kUNOP->op_first);
name = GvNAME(gv);
- len = GvNAMELEN(gv);
+ len = (STRLEN)GvNAMELEN(gv);
name_utf8 = GvNAMEUTF8(gv) ? SVf_UTF8 : 0;
}
else if (kid->op_type == OP_AELEM
diff --git a/pad.c b/pad.c
index e810ccd..beff5a4 100644
--- a/pad.c
+++ b/pad.c
@@ -2746,7 +2746,7 @@ Perl_newPADNAMEpvn(const char *s, STRLEN len)
PadnamePV(pn) = alloc->xpadn_str;
Copy(s, PadnamePV(pn), len, char);
*(PadnamePV(pn) + len) = '\0';
- PadnameLEN(pn) = len;
+ PadnameLEN(pn) = (U8)len;
return pn;
}
diff --git a/pp_sort.c b/pp_sort.c
index 4f0553b..8736bc6 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1802,7 +1802,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b)
/* entry zero of a stack is always PL_sv_undef, which
* simplifies converting a '()' return into undef in scalar context */
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
- result = SvIV(*PL_stack_sp);
+ result = (I32)SvIV(*PL_stack_sp);
LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
@@ -1849,7 +1849,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
/* entry zero of a stack is always PL_sv_undef, which
* simplifies converting a '()' return into undef in scalar context */
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
- result = SvIV(*PL_stack_sp);
+ result = (I32)SvIV(*PL_stack_sp);
LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
@@ -1877,7 +1877,7 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
/* entry zero of a stack is always PL_sv_undef, which
* simplifies converting a '()' return into undef in scalar context */
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
- result = SvIV(*PL_stack_sp);
+ result = (I32)SvIV(*PL_stack_sp);
LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
@@ -1931,7 +1931,7 @@ S_amagic_ncmp(pTHX_ SV *const a, SV *const b)
if (tmpsv) {
if (SvIOK(tmpsv)) {
- const I32 i = SvIVX(tmpsv);
+ const I32 i = (I32)SvIVX(tmpsv);
return SORT_NORMAL_RETURN_VALUE(i);
}
else {
@@ -1951,7 +1951,7 @@ S_amagic_i_ncmp(pTHX_ SV *const a, SV *const b)
if (tmpsv) {
if (SvIOK(tmpsv)) {
- const I32 i = SvIVX(tmpsv);
+ const I32 i = (I32)SvIVX(tmpsv);
return SORT_NORMAL_RETURN_VALUE(i);
}
else {
@@ -1971,7 +1971,7 @@ S_amagic_cmp(pTHX_ SV *const str1, SV *const str2)
if (tmpsv) {
if (SvIOK(tmpsv)) {
- const I32 i = SvIVX(tmpsv);
+ const I32 i = (I32)SvIVX(tmpsv);
return SORT_NORMAL_RETURN_VALUE(i);
}
else {
@@ -1993,7 +1993,7 @@ S_amagic_cmp_locale(pTHX_ SV *const str1, SV *const str2)
if (tmpsv) {
if (SvIOK(tmpsv)) {
- const I32 i = SvIVX(tmpsv);
+ const I32 i = (I32)SvIVX(tmpsv);
return SORT_NORMAL_RETURN_VALUE(i);
}
else {
|
From @jkeenanOn Tue Nov 01 21:30:44 2016, petdance wrote:
What command-line options would we provide to ./Configure to test out this patch in a before/after scenario? If you can provide that, I can test it out in my FreeBSD VMs, where clang is default C compiler. Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @petdanceThere's nothing to test specifically. This patch is just adding some casts in response to some warnings that clang came up with under -Weverything. |
From @khwilliamsonOn 11/01/2016 10:30 PM, Andy Lester (via RT) wrote:
Having merely briefly scanned the patch, so I don't know for certain, |
From @petdance
I'm not sure what I would double check. If they should be IV and not I32, then I'll look into doing it that way instead. I was just matching the target variable. |
From @khwilliamsonOn 11/02/2016 08:57 AM, Andy Lester via RT wrote:
Someone who actually knows about this should weigh in. If the target
|
From @hvdsOn Wed Nov 02 07:57:27 2016, petdance wrote:
That final comment makes me wonder what value is being added here. Warnings are supposed to be useful by encouraging you to stop and think whether the code is really doing the right thing. If you're just mechanically adding casts to make the warning go away, I think we might well be better off without - I would normally take the existence of the cast as evidence that someone _has_ thought about it. Hugo |
From @cpansproutOn Wed Nov 02 08:08:19 2016, public@khwilliamson.com wrote:
(Caveat: I have not looked at the code or the patch.) If it measure the length of something stored in memory (string, array, etc.), then it should be SSize_t. Otherwise, it if measure something small that we *know* will not exceed 32 bits, then I32 is fine. Otherwise, it may need to hold a large number, so it should be IV (or UV if no negative numbers will be encountered [but changing signedness is an easy way to introduce bugs, so I32->IV is a safer change than I32->UV]). -- Father Chrysostomos |
From @cpansproutOn Wed Nov 02 15:48:40 2016, sprout wrote:
My s must not be working (or mut not be working).
Again. (Or I could be using subjunctive. :-) -- Father Chrysostomos |
From @petdanceI'm going to reject this patch, and resubmit just the one change change that should be a nonissue. And then I will open the discussion of handling of ints that -Weverything complains about on p5p. |
@petdance - Status changed from 'open' to 'rejected' |
From @iabynOn Tue, Nov 01, 2016 at 09:30:44PM -0700, Andy Lester wrote:
This one looks good.
This is casting from I32 to STRLEN (aka Size_t), so a sign conversion.
pad variable name lengths are U8, because the lexer croaks if identifier I Think newPADNAMEpvn(const char *s, STRLEN len), which is an API For info: $ perl -le'print q{my $}, "a" x 252' | perl
[and lots of of similar I32 casts related to returning an I32 (-1,0,-1) I wonder whether instead we should change typedef I32 (*SVCOMPARE_t) (pTHX_ SV* const, SV* const); to return an IV instead of an I32 and fix up all the static sort subs to -- |
Migrated from rt.perl.org#129998 (status was 'rejected')
Searchable as RT129998$
The text was updated successfully, but these errors were encountered: