diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2014-06-15 09:41:30 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2014-06-15 21:00:07 -0400 |
commit | 81d52ecd50d856aa8879413261956d0801e7fd12 (patch) | |
tree | b672e3331504ebd1670bbc67be3f33e358fef061 /pp_pack.c | |
parent | d39195d4cbd0258917ad8f5f002fc6548080938a (diff) | |
download | perl-81d52ecd50d856aa8879413261956d0801e7fd12.tar.gz |
Some low-hanging -Wunreachable-code fruits.
- after return/croak/die/exit, return/break are pointless
(break is not a terminator/separator, it's a goto)
- after goto, another goto (!) is pointless
- in some cases (usually function ends) introduce explicit NOT_REACHED
to make the noreturn nature clearer (do not do this everywhere, though,
since that would mean adding NOT_REACHED after every croak)
- for the added NOT_REACHED also add /* NOTREACHED */ since
NOT_REACHED is for gcc (and VC), while the comment is for linters
- declaring variables in switch blocks is just too fragile:
it kind of works for narrowing the scope (which is nice),
but breaks the moment there are initializations for the variables
(the initializations will be skipped since the flow will bypass
the start of the block); in some easy cases simply hoist the declarations
out of the block and move them earlier
Note 1: Since after this patch the core is not yet -Wunreachable-code
clean, not enabling that via cflags.SH, one needs to -Accflags=... it.
Note 2: At least with the older gcc 4.4.7 there are far too many
"unreachable code" warnings, which seem to go away with gcc 4.8,
maybe better flow control analysis. Therefore, the warning should
eventually be enabled only for modernish gccs (what about clang and
Intel cc?)
Diffstat (limited to 'pp_pack.c')
-rw-r--r-- | pp_pack.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -448,7 +448,7 @@ S_measure_struct(pTHX_ tempsym_t* symptr) case e_star: Perl_croak(aTHX_ "Within []-length '*' not allowed in %s", _action( symptr ) ); - break; + default: /* e_no_len and e_number */ len = symptr->length; @@ -567,7 +567,7 @@ S_group_end(pTHX_ const char *patptr, const char *patend, char ender) } Perl_croak(aTHX_ "No group ending character '%c' found in template", ender); - return 0; + NOT_REACHED; /* NOTREACHED */ } @@ -934,7 +934,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c cuv = 0; cdouble = 0; continue; - break; + case '(': { tempsym_t savsym = *symptr; @@ -1060,7 +1060,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c break; case '/': Perl_croak(aTHX_ "'/' must follow a numeric type in unpack"); - break; + case 'A': case 'Z': case 'a': @@ -2083,6 +2083,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) bool found = next_symbol(symptr); bool utf8 = (symptr->flags & FLAG_PARSE_UTF8) ? 1 : 0; bool warn_utf8 = ckWARN(WARN_UTF8); + char* from; PERL_ARGS_ASSERT_PACK_REC; @@ -2163,8 +2164,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) (int) TYPE_NO_MODIFIERS(datumtype)); case '%': Perl_croak(aTHX_ "'%%' may not be used in pack"); - { - char *from; + case '.' | TYPE_IS_SHRIEKING: case '.': if (howlen == e_star) from = start; @@ -2213,7 +2213,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) goto shrink; } break; - } + case '(': { tempsym_t savsym = *symptr; U32 group_modifiers = TYPE_MODIFIERS(datumtype & ~symptr->flags); |