Skip to content

Enable -Wimplicit-fallthrough compiler warning #6252

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 3 commits into from
Apr 19, 2021

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Oct 1, 2020

Introduce a pseudo-keyword fallthrough (following the Linux Kernal style) to indicate that a switch case fall-through to the following one.
This has a couple of benefits in that it normalizes our fall-through comments (which have various formulation even within the same file) and let's use enable -Wimplicit-fallthrough=3 which is included in -Wextra.

I enabled level 5 temporarily (which disables all comments) to use the newly introduce pseudo-keyword instead of comments in extension code under our control.

A couple of issues remain:

  • TimeLib would need to be patched upstream to include a /* fallthrough */ comment in an instance or we suppress this warning for DateTime
  • The JIT: the simplest solution would be to disable the compiler warning for it (or even OpCache altogether), as otherwise we would need to patch the integrated libs.

@Girgias Girgias added this to the PHP 8.1 milestone Oct 1, 2020
@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch 2 times, most recently from 05e1d65 to 25b345a Compare October 1, 2020 22:19
@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch 2 times, most recently from 2024e23 to 4c8f0fd Compare October 9, 2020 22:26
@nikic
Copy link
Member

nikic commented Oct 12, 2020

I'm a bit concerned about the annoyance this could cause for extensions... especially as they wouldn't have the macro available on old PHP versions.

@Girgias
Copy link
Member Author

Girgias commented Oct 16, 2020

I'm a bit concerned about the annoyance this could cause for extensions... especially as they wouldn't have the macro available on old PHP versions.

Right, we could potentially lower the level from 3 (the default) to 1 which accepts any comment as a fall-through comment. I suppose amending the skeleton to also generate the macro is the version is less than PHP 8.1 /undef is also an option but that wouldn't help already existing extensions :-/

@nikic
Copy link
Member

nikic commented Oct 26, 2020

Right, we could potentially lower the level from 3 (the default) to 1 which accepts any comment as a fall-through comment.

That sounds like a good approach to me.

@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch from 4c8f0fd to 5fe6948 Compare November 3, 2020 11:26
@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch from 8023794 to 4608151 Compare January 15, 2021 04:07
@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch 3 times, most recently from f6804c1 to 1a7aca6 Compare February 4, 2021 12:15
@Girgias Girgias requested a review from nikic February 4, 2021 15:33
@Girgias
Copy link
Member Author

Girgias commented Feb 4, 2021

Hopefully everything should work now, and the decision to use level 1 accepts any comment as a switch case fallthrough comment

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please commit the addition of ZEND_FALLTHROUGH and all its uses, and only leave the build system changes that enable the warning in this PR?

@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch 2 times, most recently from 55d0488 to f6f842b Compare April 6, 2021 23:51
@@ -66,7 +66,6 @@ steps:
--with-pdo-dblib \
--with-pdo-oci=shared,instantclient,/opt/oracle/instantclient \
--with-oci8=shared,instantclient,/opt/oracle/instantclient \
--enable-werror \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be dropped now.

@nikic
Copy link
Member

nikic commented Apr 16, 2021

Build failure on i386, should exclude pcre2lib.

@nikic
Copy link
Member

nikic commented Apr 16, 2021

Actually, the pcre failure should be resolved with implicit-fallthrough=1.

@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch 2 times, most recently from 89cf484 to b8c6f99 Compare April 19, 2021 02:34
@@ -918,7 +918,8 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
case PHP_STREAM_SYNC_FDSYNC:
return php_stdiop_sync(stream, 1) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
}

/* TODO Should this fallthrough? */
ZEND_FALLTHROUGH;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return PHP_STREAM_OPTION_RETURN_NOTIMPL here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might indeed be correct, I was just surprised that CI was failing because of this, so I made a quick commit adding this to see if there are any other ones.

Seems this is the last one which is also finding an actual bug :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe even PHP_STREAM_OPTION_RETURN_ERR, as this means an incorrect option value was passed.

And add it back to ext/date, ext/hash, and ext/opcache
@Girgias Girgias force-pushed the enable-Wimplicit-fallthrough branch from b8c6f99 to 35d8051 Compare April 19, 2021 12:46
@Girgias Girgias merged commit dcdc5d9 into php:master Apr 19, 2021
@Girgias Girgias deleted the enable-Wimplicit-fallthrough branch April 19, 2021 12:59
petk added a commit to petk/php-src that referenced this pull request May 9, 2024
This is a sync of the php#6252 after few
years:
- ext/date: fixed since derickr/timelib@f8caaef
- ext/hash: warning happens only on 32-bit build in
  ext/hash/sha3/generic32lc/KeccakP-1600-inplace32BI.c
- ext/opcache: IR JIT doesn't seem to have this issue
- ext/pcre remains disabled due to pcre2lib/sljit/sljitNativeARM_64.c
@petk petk mentioned this pull request May 9, 2024
3 tasks
petk added a commit to petk/php-src that referenced this pull request Jun 8, 2024
This is a sync of the php#6252 after few
years:
- ext/date: fixed since derickr/timelib@f8caaef
- ext/hash: warning happens only on 32-bit build in
  ext/hash/sha3/generic32lc/KeccakP-1600-inplace32BI.c
- ext/opcache: IR JIT doesn't seem to have this issue
- ext/pcre remains disabled due to pcre2lib/sljit/sljitNativeARM_64.c
petk added a commit that referenced this pull request Jun 8, 2024
This is a sync of the #6252 after few
years:
- ext/date: pending recheck in GH-14187
- ext/hash: warning happens only on 32-bit build in
  ext/hash/sha3/generic32lc/KeccakP-1600-inplace32BI.c
- ext/opcache: IR JIT doesn't seem to have this issue
- ext/pcre remains disabled due to pcre2lib/sljit/sljitNativeARM_64.c
  (should be rechecked and fixed upstream)
petk added a commit to petk/php-src that referenced this pull request Jun 8, 2024
This is a sync of the php#6252:
- ext/date: seems to be also fixed

Synced in 743d1fd:
- ext/hash
- ext/opcache
- ext/pcre
petk added a commit to petk/php-src that referenced this pull request Jul 22, 2024
This is a sync of the php#6252:
- ext/date: seems to be also fixed

Synced in 743d1fd:
- ext/hash
- ext/opcache
- ext/pcre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants