build: Add -Werror=implicit-fallthrough compile flag #21430
pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:210313-fall changing 7 files +14 −7-
hebasto commented at 9:10 pm on March 13, 2021: member
-
DrahtBot added the label Build system on Mar 13, 2021
-
DrahtBot added the label GUI on Mar 13, 2021
-
DrahtBot added the label Mining on Mar 13, 2021
-
DrahtBot added the label RPC/REST/ZMQ on Mar 13, 2021
-
DrahtBot commented at 11:47 pm on March 13, 2021: member
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Conflicts
No conflicts as of last run.
-
MarcoFalke removed the label GUI on Mar 14, 2021
-
MarcoFalke removed the label Mining on Mar 14, 2021
-
MarcoFalke removed the label RPC/REST/ZMQ on Mar 14, 2021
-
practicalswift commented at 4:28 pm on March 15, 2021: contributor
cr ACK e95d14e07e9215d6d8ba1a56d13485a18e3550ba: patch looks correct!
I’ve always been worried about introduction of bugs in our code due to unintentional fallthroughs. Thanks for reducing the number of things to worry about by one :)
As always: explicit is better than implicit! :)
-
in configure.ac:443 in e95d14e07e outdated
438@@ -439,6 +439,7 @@ if test "x$enable_werror" = "xyes"; then 439 [AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])]) 440 AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]]) 441 AX_CHECK_COMPILE_FLAG([-Werror=mismatched-tags], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=mismatched-tags"], [], [$CXXFLAG_WERROR]) 442+ AX_CHECK_COMPILE_FLAG([-Werror=implicit-fallthrough], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=implicit-fallthrough"], [], [$CXXFLAG_WERROR]) 443 fi 444 445 if test "x$CXXFLAGS_overridden" = "xno"; then
MarcoFalke commented at 4:34 pm on March 15, 2021:any reason to not enable the warning as well?
hebasto commented at 4:47 pm on March 15, 2021:You are right!
From https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html:
-Wimplicit-fallthrough
is the same as-Wimplicit-fallthrough=3
…The
-Wimplicit-fallthrough=3
warning is enabled by-Wextra
.But that is not the case for clang. Going to fix it now.
MarcoFalke approvedMarcoFalke commented at 4:35 pm on March 15, 2021: membercr ACK e95d14e07e9215d6d8ba1a56d13485a18e3550ba
didn’t review the leveldb build change
MarcoFalke added the label Needs Guix build on Mar 15, 2021hebasto force-pushed on Mar 15, 2021hebasto commented at 5:02 pm on March 15, 2021: memberUpdated e95d14e07e9215d6d8ba1a56d13485a18e3550ba -> 2f3436bcad878a313ce53bab2fc8a2fed9056351 (pr21430.01 -> pr21430.02, diff):
- addressed @MarcoFalke’s comment:
any reason to not enable the warning as well? @MarcoFalke didn’t review the leveldb build change
practicalswift commented at 5:46 pm on March 15, 2021: contributorcr re-ACK 2f3436bcad878a313ce53bab2fc8a2fed9056351
Consider submitting the
tinyformat.h
changes upstream too (https://github.com/c42f/tinyformat).DrahtBot removed the label Needs Guix build on Mar 19, 2021MarcoFalke deleted a comment on Apr 6, 2021DrahtBot added the label Needs rebase on Apr 6, 2021hebasto force-pushed on Apr 13, 2021hebasto commented at 7:10 am on April 13, 2021: memberRebased 2f3436bcad878a313ce53bab2fc8a2fed9056351 -> 5bc16d28e73a068382e66fce9ffcb604a3db34dc (pr21430.02 -> pr21430.03) due to the conflicts with #21610 and #21613.DrahtBot removed the label Needs rebase on Apr 13, 2021practicalswift commented at 6:39 am on April 14, 2021: contributorcr ACK 5bc16d28e73a068382e66fce9ffcb604a3db34dc: patch looks correct
Thanks a lot for doing this @hebasto: the introduction of
-Werror=implicit-fallthrough
in our project combined with proper[[fallthrough]]
annotations will most likely kill the “unintended fallthroughs” bug class for good.Killing bug instances is cool, but killing entire bug classes is even cooler! :)
DrahtBot added the label Needs rebase on Jun 17, 2021hebasto force-pushed on Jun 17, 2021hebasto commented at 4:01 pm on June 17, 2021: memberRebased 5bc16d28e73a068382e66fce9ffcb604a3db34dc -> 45dc9f383cf46a556fefa609dc88135cfe55b5bc (pr21430.03 -> pr21430.04) due to the conflict with #22258.DrahtBot removed the label Needs rebase on Jun 17, 2021practicalswift commented at 8:00 pm on June 17, 2021: contributorcr re-ACK 45dc9f383cf46a556fefa609dc88135cfe55b5bcin configure.ac:1249 in 45dc9f383c outdated
1245@@ -1245,7 +1246,7 @@ AC_LINK_IFELSE( 1246 1247 AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem]) 1248 1249-LEVELDB_CPPFLAGS= 1250+LEVELDB_CPPFLAGS="-DFALLTHROUGH_INTENDED=@<:@@<:@fallthrough@:>@@:>@"
fanquake commented at 8:51 am on June 30, 2021:Shouldn’t this be done inMakefile.leveldb.include
?
fanquake commented at 8:52 am on June 30, 2021: memberConcept ACK.DrahtBot added the label Needs rebase on Jul 1, 2021hebasto force-pushed on Jul 3, 2021hebasto commented at 4:41 pm on July 3, 2021: memberUpdated 45dc9f383cf46a556fefa609dc88135cfe55b5bc -> ebc36d94cbc927a5c68873b92442937c420f317f (pr21430.04 -> pr21430.05):
DrahtBot removed the label Needs rebase on Jul 3, 2021Use C++17 [[fallthrough]] attribute, and drop -Wno-implicit-fallthrough 014110c47dbuild: Add -Werror=implicit-fallthrough compile flag 3c4c8e79bain src/Makefile.leveldb.include:14 in ebc36d94cb outdated
10@@ -11,6 +11,7 @@ EXTRA_LIBRARIES += $(LIBMEMENV_INT) 11 LIBLEVELDB += $(LIBLEVELDB_INT) $(LIBCRC32C) 12 LIBMEMENV += $(LIBMEMENV_INT) 13 14+LEVELDB_CPPFLAGS += -DFALLTHROUGH_INTENDED=[[fallthrough]]
fanquake commented at 1:00 am on July 5, 2021:This should be inLEVELDB_CPPFLAGS_INT
and down with the other defines.
hebasto force-pushed on Jul 5, 2021hebasto commented at 6:02 am on July 5, 2021: memberUpdated ebc36d94cbc927a5c68873b92442937c420f317f -> 3c4c8e79baf02af97ba1502189f649b04ef2198d (pr21430.05 -> pr21430.06, diff):
fanquake approvedfanquake commented at 4:33 am on July 9, 2021: memberACK 3c4c8e79baf02af97ba1502189f649b04ef2198d - looks ok to me now. Checked that warnings occur in our code & leveldb by removing a[[fallthrough]]
orFALLTHROUGH_INTENDED
.theStack commented at 7:46 pm on July 12, 2021: memberConcept ACKjarolrod commented at 3:46 pm on July 17, 2021: memberACK 3c4c8e79baf02af97ba1502189f649b04ef2198d
This is nice to be able to detect fallthroughs going forward. Appropriate since GCC 7 is the current minimum supported GCC.
Tested that the codebase itself will throw the warning by following the same step of removing one of the added
[[fallthrough]]
statements as outlined here: #21430#pullrequestreview-702673309hebasto commented at 4:30 pm on July 17, 2021: memberDo you mind making another (final?) review?
theStack approvedtheStack commented at 1:42 am on July 18, 2021: memberACK 3c4c8e79baf02af97ba1502189f649b04ef2198d
Tested that removing an arbitrary
[[fallthrough]]
statment in the codebase leads to either a warning (default configuration) or an error (if configured with--enable-werror
) with clang 11.0.1-2 (Debian bullseye/sid), e.g.:0hash.cpp:52:9: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough] 1 case 2: 2 ^ 3hash.cpp:52:9: note: insert '[[fallthrough]];' to silence this warning 4 case 2: 5 ^ 6 [[fallthrough]]; 7hash.cpp:52:9: note: insert 'break;' to avoid fall-through 8 case 2: 9 ^ 10 break; 111 error generated.
By the way, any reason we don’t
--enable-werror
by default? Being on the cautious side would seem to be a more sane default to me.fanquake merged this on Jul 18, 2021fanquake closed this on Jul 18, 2021
MarcoFalke commented at 7:15 am on July 18, 2021: memberBy the way, any reason we don’t –enable-werror by default? Being on the cautious side would seem to be a more sane default to me.
There might be unknown warnings in future releases of compilers that we are not aware of. Also, compilers might produce false warnings if they have bugs. So we only error on well tested and selected warnings.
hebasto deleted the branch on Jul 18, 2021sidhujag referenced this in commit ea5c504276 on Jul 23, 2021gwillen referenced this in commit 2fa422afec on Jun 1, 2022DrahtBot locked this on Aug 18, 2022
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-23 21:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me