xref: /netbsd-src/external/gpl3/gcc/README.warnings (revision 884278440515145417c952d8fcd78d23cc76bd34)
1*88427844Smrg$NetBSD: README.warnings,v 1.1 2021/04/15 05:15:04 mrg Exp $
2*88427844Smrg
3*88427844SmrgWhat to do about GCC warnings and NetBSD.
4*88427844Smrg
5*88427844Smrg
6*88427844SmrgNew GCC releases always come with a host of new warnings and
7*88427844Smrgeach new warning can find real bugs, find odd code, or simply
8*88427844Smrgbe a pain of new useless warnings, or all three and more.
9*88427844Smrg
10*88427844SmrgAs each warning has its own set of issues they each have their
11*88427844Smrgown section and it is expected that this document will be
12*88427844Smrgmodified for updates to warnings and new warnings.
13*88427844Smrg
14*88427844Smrg
15*88427844Smrg<bsd.own.mk> provides several variables for use in Makefiles:
16*88427844Smrg   COPTS.foo.c += ${GCC_NO_FORMAT_TRUNCATION}
17*88427844Smrg   COPTS.foo.c += ${GCC_NO_FORMAT_OVERFLOW}
18*88427844Smrg   COPTS.foo.c += ${GCC_NO_STRINGOP_OVERFLOW}
19*88427844Smrg   COPTS.foo.c += ${GCC_NO_STRINGOP_TRUNCATION}
20*88427844Smrg   COPTS.foo.c += ${GCC_NO_CAST_FUNCTION_TYPE}
21*88427844Smrg   COPTS.foo.c += ${GCC_NO_IMPLICIT_FALLTHRU}
22*88427844Smrg   COPTS.foo.c += ${GCC_NO_ADDR_OF_PACKED_MEMBER}
23*88427844Smrg   COPTS.foo.c += ${GCC_NO_MAYBE_UNINITIALIZED}
24*88427844Smrg   COPTS.foo.c += ${GCC_NO_RETURN_LOCAL_ADDR}
25*88427844Smrg
26*88427844Smrg
27*88427844Smrgnew GCC 10 warnings:
28*88427844Smrg
29*88427844Smrg  GCC 10 switched the default from "-fcommon" to "-fno-common",
30*88427844Smrg  which can cause multiply defined symbol issues.  Ideally we
31*88427844Smrg  fix all of these, but "-fcommon" can be used otherwise.
32*88427844Smrg
33*88427844Smrg  -Wno-maybe-uninitialized
34*88427844Smrg
35*88427844Smrg      This warning was introduced in an ancient GCC but was
36*88427844Smrg      significantly enhanced in GCC 10, unfortunately, many of
37*88427844Smrg      the new instances are incorrect.
38*88427844Smrg
39*88427844Smrg      bsd.own.mk variable: ${GCC_NO_MAYBE_UNINITIALIZED}
40*88427844Smrg
41*88427844Smrg  -Wno-return-local-addr
42*88427844Smrg
43*88427844Smrg      This warning was introduced in GCC 5 and was enhanced in GCC
44*88427844Smrg      10.  Unfortunately, the new instances are failing to correctly
45*88427844Smrg      analyze code flow and miss that most of the are handled.
46*88427844Smrg
47*88427844Smrg      bsd.own.mk variable: ${GCC_NO_RETURN_LOCAL_ADDR}
48*88427844Smrg
49*88427844Smrg
50*88427844Smrgnew GCC 9 warnings:
51*88427844Smrg
52*88427844Smrg  -Wno-address-of-packed-member
53*88427844Smrg
54*88427844Smrg      This warning was introduced in GCC 8.
55*88427844Smrg      This warning is similar to -Wformat-truncation, but for the
56*88427844Smrg      general family of string functions (str*(), etc.), and has
57*88427844Smrg      similar issues of false positives.
58*88427844Smrg
59*88427844Smrg      bsd.own.mk variable: ${GCC_NO_ADDR_OF_PACKED_MEMBER}
60*88427844Smrg
61*88427844Smrg
62*88427844Smrgnew GCC 8 warnings:
63*88427844Smrg
64*88427844Smrg  -Wstringop-truncation
65*88427844Smrg
66*88427844Smrg      This warning was introduced in GCC 8.
67*88427844Smrg      This warning is similar to -Wformat-truncation, but for the
68*88427844Smrg      general family of string functions (str*(), etc.), and has
69*88427844Smrg      similar issues of false positives.
70*88427844Smrg
71*88427844Smrg      bsd.own.mk variable: ${GCC_NO_STRINGOP_TRUNCATION}
72*88427844Smrg
73*88427844Smrg
74*88427844Smrg  -Wcast-function-type
75*88427844Smrg
76*88427844Smrg      This warning was introduced in GCC 8.
77*88427844Smrg      This warning can find real problems.  Most instances are
78*88427844Smrg      false positives, and hopefully this warning will become
79*88427844Smrg      more useful in the future.  See __FPTRCAST().
80*88427844Smrg
81*88427844Smrg      bsd.own.mk variable: ${GCC_NO_CAST_FUNCTION_TYPE}
82*88427844Smrg
83*88427844Smrg
84*88427844Smrgnew GCC 7 warnings:
85*88427844Smrg
86*88427844Smrg  -Wstringop-overflow
87*88427844Smrg
88*88427844Smrg      This warning was introduced in GCC 7.
89*88427844Smrg      This warning can find issues where source length is
90*88427844Smrg      passed as destination length (eg, strncpy() where the
91*88427844Smrg      length is strlen(src)) that are potential buffer overflow
92*88427844Smrg      cases and should always be inspected, but false positives
93*88427844Smrg      are also seen.
94*88427844Smrg
95*88427844Smrg      bsd.own.mk variable: ${GCC_NO_STRINGOP_OVERFLOW}
96*88427844Smrg
97*88427844Smrg
98*88427844Smrg  -Wformat-truncation
99*88427844Smrg
100*88427844Smrg    This warning was introduced in GCC 7.
101*88427844Smrg    This warning has many false positives where truncation is
102*88427844Smrg    either expected or unavoidable, but also finds several real
103*88427844Smrg    code bugs.
104*88427844Smrg
105*88427844Smrg    Code should always be manually inspected for this warning
106*88427844Smrg    as it does pick up real issues.
107*88427844Smrg
108*88427844Smrg    bsd.own.mk variable: ${GCC_NO_FORMAT_TRUNCATION}
109*88427844Smrg
110*88427844Smrg
111*88427844Smrg  -Wformat-overflow
112*88427844Smrg
113*88427844Smrg    This warning was introduced in GCC 7.
114*88427844Smrg    This warning typically identifies a real problem, but it may
115*88427844Smrg    fail to notice the code handles this case.
116*88427844Smrg
117*88427844Smrg    Code should always be manually inspected for this warning
118*88427844Smrg    as it does pick up real issues.
119*88427844Smrg
120*88427844Smrg    bsd.own.mk variable: ${GCC_NO_FORMAT_OVERFLOW}
121*88427844Smrg
122*88427844Smrg
123*88427844Smrg  -Wimplicit-fallthrough
124*88427844Smrg
125*88427844Smrg    This warning was introduced in GCC 7.
126*88427844Smrg    This warning has many false positives in GCC 7, and many are
127*88427844Smrg    fixed in newer GCC 10.  Old uses should be checked occasionally.
128*88427844Smrg
129*88427844Smrg    Code should always be manually inspected for this warning
130*88427844Smrg    as it does pick up real issues.
131*88427844Smrg
132*88427844Smrg    bsd.own.mk variable: ${GCC_NO_IMPLICIT_FALLTHRU}
133