The Linux Kernel Is Close To Enabling "-Wimplicit-fallthrough" By Default
The -Wimplicit-fallthrough compiler flag has been around since GCC 7 for warning over switch fall-through cases where it could lead to potential bugs / unexpected behavior if the programmer inadvertently forgot to add a "break" statement to a case. The Linux kernel is looking to soon enable this warning by default.
The -Wimplicit-fallthrough warning tries to be smart about its handling and only warn the programmer/user when appropriate and acknowledging cases where a switch case fall-through would be desirable. Newer Linux kernel developer Gustavo A. R. Silva has been working through more than two thousand warnings from this implicit-fallthrough compiler flag. Of 2,311 cases currently in the kernel where warnings have been emitted, only 32 are left to be gone through to determine if there is any code bugs or a false positive.
In the process a number of bugs have been addressed thanks to this compiler warning, some of which bugs have lasted in the mainline kernel for more than five years. Once addressing the remaining cases, the plan is to enable "-Wimplicit-fallthrough" by default in future kernel builds to prevent similar bugs from creeping into the kernel in the future.
More details on this effort via this pull request for Linux 5.2 that is marking more switch-fallthroughs as expected.
Those unfamiliar with this GCC compiler warning can learn more via this Red Hat developer blog post.
The -Wimplicit-fallthrough warning tries to be smart about its handling and only warn the programmer/user when appropriate and acknowledging cases where a switch case fall-through would be desirable. Newer Linux kernel developer Gustavo A. R. Silva has been working through more than two thousand warnings from this implicit-fallthrough compiler flag. Of 2,311 cases currently in the kernel where warnings have been emitted, only 32 are left to be gone through to determine if there is any code bugs or a false positive.
In the process a number of bugs have been addressed thanks to this compiler warning, some of which bugs have lasted in the mainline kernel for more than five years. Once addressing the remaining cases, the plan is to enable "-Wimplicit-fallthrough" by default in future kernel builds to prevent similar bugs from creeping into the kernel in the future.
More details on this effort via this pull request for Linux 5.2 that is marking more switch-fallthroughs as expected.
Those unfamiliar with this GCC compiler warning can learn more via this Red Hat developer blog post.
18 Comments