1*f937c412Slukem$NetBSD: README.warnings,v 1.2 2023/06/03 08:52:54 lukem Exp $ 288427844Smrg 388427844SmrgWhat to do about GCC warnings and NetBSD. 488427844Smrg 588427844Smrg 688427844SmrgNew GCC releases always come with a host of new warnings and 788427844Smrgeach new warning can find real bugs, find odd code, or simply 888427844Smrgbe a pain of new useless warnings, or all three and more. 988427844Smrg 1088427844SmrgAs each warning has its own set of issues they each have their 1188427844Smrgown section and it is expected that this document will be 1288427844Smrgmodified for updates to warnings and new warnings. 1388427844Smrg 1488427844Smrg 1588427844Smrg<bsd.own.mk> provides several variables for use in Makefiles: 1688427844Smrg COPTS.foo.c += ${GCC_NO_FORMAT_TRUNCATION} 1788427844Smrg COPTS.foo.c += ${GCC_NO_FORMAT_OVERFLOW} 1888427844Smrg COPTS.foo.c += ${GCC_NO_STRINGOP_OVERFLOW} 1988427844Smrg COPTS.foo.c += ${GCC_NO_STRINGOP_TRUNCATION} 2088427844Smrg COPTS.foo.c += ${GCC_NO_CAST_FUNCTION_TYPE} 2188427844Smrg COPTS.foo.c += ${GCC_NO_IMPLICIT_FALLTHRU} 22*f937c412Slukem COPTS.foo.c += ${CC_WNO_ADDRESS_OF_PACKED_MEMBER} 2388427844Smrg COPTS.foo.c += ${GCC_NO_MAYBE_UNINITIALIZED} 2488427844Smrg COPTS.foo.c += ${GCC_NO_RETURN_LOCAL_ADDR} 2588427844Smrg 2688427844Smrg 2788427844Smrgnew GCC 10 warnings: 2888427844Smrg 2988427844Smrg GCC 10 switched the default from "-fcommon" to "-fno-common", 3088427844Smrg which can cause multiply defined symbol issues. Ideally we 3188427844Smrg fix all of these, but "-fcommon" can be used otherwise. 3288427844Smrg 3388427844Smrg -Wno-maybe-uninitialized 3488427844Smrg 3588427844Smrg This warning was introduced in an ancient GCC but was 3688427844Smrg significantly enhanced in GCC 10, unfortunately, many of 3788427844Smrg the new instances are incorrect. 3888427844Smrg 3988427844Smrg bsd.own.mk variable: ${GCC_NO_MAYBE_UNINITIALIZED} 4088427844Smrg 4188427844Smrg -Wno-return-local-addr 4288427844Smrg 4388427844Smrg This warning was introduced in GCC 5 and was enhanced in GCC 4488427844Smrg 10. Unfortunately, the new instances are failing to correctly 4588427844Smrg analyze code flow and miss that most of the are handled. 4688427844Smrg 4788427844Smrg bsd.own.mk variable: ${GCC_NO_RETURN_LOCAL_ADDR} 4888427844Smrg 4988427844Smrg 5088427844Smrgnew GCC 9 warnings: 5188427844Smrg 5288427844Smrg -Wno-address-of-packed-member 5388427844Smrg 5488427844Smrg This warning was introduced in GCC 8. 5588427844Smrg This warning is similar to -Wformat-truncation, but for the 5688427844Smrg general family of string functions (str*(), etc.), and has 5788427844Smrg similar issues of false positives. 5888427844Smrg 59*f937c412Slukem bsd.own.mk variable: ${CC_WNO_ADDRESS_OF_PACKED_MEMBER} 6088427844Smrg 6188427844Smrg 6288427844Smrgnew GCC 8 warnings: 6388427844Smrg 6488427844Smrg -Wstringop-truncation 6588427844Smrg 6688427844Smrg This warning was introduced in GCC 8. 6788427844Smrg This warning is similar to -Wformat-truncation, but for the 6888427844Smrg general family of string functions (str*(), etc.), and has 6988427844Smrg similar issues of false positives. 7088427844Smrg 7188427844Smrg bsd.own.mk variable: ${GCC_NO_STRINGOP_TRUNCATION} 7288427844Smrg 7388427844Smrg 7488427844Smrg -Wcast-function-type 7588427844Smrg 7688427844Smrg This warning was introduced in GCC 8. 7788427844Smrg This warning can find real problems. Most instances are 7888427844Smrg false positives, and hopefully this warning will become 7988427844Smrg more useful in the future. See __FPTRCAST(). 8088427844Smrg 8188427844Smrg bsd.own.mk variable: ${GCC_NO_CAST_FUNCTION_TYPE} 8288427844Smrg 8388427844Smrg 8488427844Smrgnew GCC 7 warnings: 8588427844Smrg 8688427844Smrg -Wstringop-overflow 8788427844Smrg 8888427844Smrg This warning was introduced in GCC 7. 8988427844Smrg This warning can find issues where source length is 9088427844Smrg passed as destination length (eg, strncpy() where the 9188427844Smrg length is strlen(src)) that are potential buffer overflow 9288427844Smrg cases and should always be inspected, but false positives 9388427844Smrg are also seen. 9488427844Smrg 9588427844Smrg bsd.own.mk variable: ${GCC_NO_STRINGOP_OVERFLOW} 9688427844Smrg 9788427844Smrg 9888427844Smrg -Wformat-truncation 9988427844Smrg 10088427844Smrg This warning was introduced in GCC 7. 10188427844Smrg This warning has many false positives where truncation is 10288427844Smrg either expected or unavoidable, but also finds several real 10388427844Smrg code bugs. 10488427844Smrg 10588427844Smrg Code should always be manually inspected for this warning 10688427844Smrg as it does pick up real issues. 10788427844Smrg 10888427844Smrg bsd.own.mk variable: ${GCC_NO_FORMAT_TRUNCATION} 10988427844Smrg 11088427844Smrg 11188427844Smrg -Wformat-overflow 11288427844Smrg 11388427844Smrg This warning was introduced in GCC 7. 11488427844Smrg This warning typically identifies a real problem, but it may 11588427844Smrg fail to notice the code handles this case. 11688427844Smrg 11788427844Smrg Code should always be manually inspected for this warning 11888427844Smrg as it does pick up real issues. 11988427844Smrg 12088427844Smrg bsd.own.mk variable: ${GCC_NO_FORMAT_OVERFLOW} 12188427844Smrg 12288427844Smrg 12388427844Smrg -Wimplicit-fallthrough 12488427844Smrg 12588427844Smrg This warning was introduced in GCC 7. 12688427844Smrg This warning has many false positives in GCC 7, and many are 12788427844Smrg fixed in newer GCC 10. Old uses should be checked occasionally. 12888427844Smrg 12988427844Smrg Code should always be manually inspected for this warning 13088427844Smrg as it does pick up real issues. 13188427844Smrg 13288427844Smrg bsd.own.mk variable: ${GCC_NO_IMPLICIT_FALLTHRU} 133