1*23f5f463Smrg$NetBSD: README.warnings,v 1.5 2023/07/14 19:46:25 mrg Exp $ 24c3eb207Smrg 34c3eb207SmrgWhat to do about GCC warnings and NetBSD. 44c3eb207Smrg 54c3eb207Smrg 64c3eb207SmrgNew GCC releases always come with a host of new warnings and 74c3eb207Smrgeach new warning can find real bugs, find odd code, or simply 84c3eb207Smrgbe a pain of new useless warnings, or all three and more. 94c3eb207Smrg 104c3eb207SmrgAs each warning has its own set of issues they each have their 114c3eb207Smrgown section and it is expected that this document will be 124c3eb207Smrgmodified for updates to warnings and new warnings. 134c3eb207Smrg 144c3eb207Smrg 154c3eb207Smrg<bsd.own.mk> provides several variables for use in Makefiles: 16c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_FORMAT_TRUNCATION} 17c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_FORMAT_OVERFLOW} 18c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_STRINGOP_OVERFLOW} 19c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_STRINGOP_TRUNCATION} 20c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_CAST_FUNCTION_TYPE} 21c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_IMPLICIT_FALLTHROUGH} 22f937c412Slukem COPTS.foo.c += ${CC_WNO_ADDRESS_OF_PACKED_MEMBER} 23c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_MAYBE_UNINITIALIZED} 24c4b7a9e7Slukem COPTS.foo.c += ${CC_WNO_RETURN_LOCAL_ADDR} 254c3eb207Smrg 264c3eb207Smrg 274c3eb207Smrgnew GCC 10 warnings: 284c3eb207Smrg 294c3eb207Smrg GCC 10 switched the default from "-fcommon" to "-fno-common", 304c3eb207Smrg which can cause multiply defined symbol issues. Ideally we 314c3eb207Smrg fix all of these, but "-fcommon" can be used otherwise. 324c3eb207Smrg 334c3eb207Smrg -Wno-maybe-uninitialized 344c3eb207Smrg 354c3eb207Smrg This warning was introduced in an ancient GCC but was 364c3eb207Smrg significantly enhanced in GCC 10, unfortunately, many of 374c3eb207Smrg the new instances are incorrect. 384c3eb207Smrg 39c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_MAYBE_UNINITIALIZED} 404c3eb207Smrg 414c3eb207Smrg -Wno-return-local-addr 424c3eb207Smrg 434c3eb207Smrg This warning was introduced in GCC 5 and was enhanced in GCC 444c3eb207Smrg 10. Unfortunately, the new instances are failing to correctly 454c3eb207Smrg analyze code flow and miss that most of the are handled. 464c3eb207Smrg 47c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_RETURN_LOCAL_ADDR} 484c3eb207Smrg 494c3eb207Smrg 504c3eb207Smrgnew GCC 9 warnings: 514c3eb207Smrg 524c3eb207Smrg -Wno-address-of-packed-member 534c3eb207Smrg 544c3eb207Smrg This warning was introduced in GCC 8. 554c3eb207Smrg This warning is similar to -Wformat-truncation, but for the 564c3eb207Smrg general family of string functions (str*(), etc.), and has 574c3eb207Smrg similar issues of false positives. 584c3eb207Smrg 59f937c412Slukem bsd.own.mk variable: ${CC_WNO_ADDRESS_OF_PACKED_MEMBER} 604c3eb207Smrg 614c3eb207Smrg 624c3eb207Smrgnew GCC 8 warnings: 634c3eb207Smrg 644c3eb207Smrg -Wstringop-truncation 654c3eb207Smrg 664c3eb207Smrg This warning was introduced in GCC 8. 674c3eb207Smrg This warning is similar to -Wformat-truncation, but for the 684c3eb207Smrg general family of string functions (str*(), etc.), and has 694c3eb207Smrg similar issues of false positives. 704c3eb207Smrg 71c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_STRINGOP_TRUNCATION} 724c3eb207Smrg 734c3eb207Smrg 744c3eb207Smrg -Wcast-function-type 754c3eb207Smrg 764c3eb207Smrg This warning was introduced in GCC 8. 774c3eb207Smrg This warning can find real problems. Most instances are 784c3eb207Smrg false positives, and hopefully this warning will become 794c3eb207Smrg more useful in the future. See __FPTRCAST(). 804c3eb207Smrg 81c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_CAST_FUNCTION_TYPE} 824c3eb207Smrg 834c3eb207Smrg 844c3eb207Smrgnew GCC 7 warnings: 854c3eb207Smrg 864c3eb207Smrg -Wstringop-overflow 874c3eb207Smrg 884c3eb207Smrg This warning was introduced in GCC 7. 894c3eb207Smrg This warning can find issues where source length is 904c3eb207Smrg passed as destination length (eg, strncpy() where the 914c3eb207Smrg length is strlen(src)) that are potential buffer overflow 924c3eb207Smrg cases and should always be inspected, but false positives 934c3eb207Smrg are also seen. 944c3eb207Smrg 95c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_STRINGOP_OVERFLOW} 964c3eb207Smrg 974c3eb207Smrg 984c3eb207Smrg -Wformat-truncation 994c3eb207Smrg 1004c3eb207Smrg This warning was introduced in GCC 7. 1014c3eb207Smrg This warning has many false positives where truncation is 1024c3eb207Smrg either expected or unavoidable, but also finds several real 1034c3eb207Smrg code bugs. 1044c3eb207Smrg 1054c3eb207Smrg Code should always be manually inspected for this warning 1064c3eb207Smrg as it does pick up real issues. 1074c3eb207Smrg 108c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_FORMAT_TRUNCATION} 1094c3eb207Smrg 1104c3eb207Smrg 1114c3eb207Smrg -Wformat-overflow 1124c3eb207Smrg 1134c3eb207Smrg This warning was introduced in GCC 7. 1144c3eb207Smrg This warning typically identifies a real problem, but it may 1154c3eb207Smrg fail to notice the code handles this case. 1164c3eb207Smrg 1174c3eb207Smrg Code should always be manually inspected for this warning 1184c3eb207Smrg as it does pick up real issues. 1194c3eb207Smrg 120c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_FORMAT_OVERFLOW} 1214c3eb207Smrg 1224c3eb207Smrg 1234c3eb207Smrg -Wimplicit-fallthrough 1244c3eb207Smrg 1254c3eb207Smrg This warning was introduced in GCC 7. 1264c3eb207Smrg This warning has many false positives in GCC 7, and many are 1274c3eb207Smrg fixed in newer GCC 10. Old uses should be checked occasionally. 1284c3eb207Smrg 1294c3eb207Smrg Code should always be manually inspected for this warning 1304c3eb207Smrg as it does pick up real issues. 1314c3eb207Smrg 132c4b7a9e7Slukem bsd.own.mk variable: ${CC_WNO_IMPLICIT_FALLTHROUGH} 133