clang vs gcc warning flags
Ryan Libby
rlibby at freebsd.org
Wed Jan 6 19:53:26 UTC 2021
One of the more annoying things about keeping the gcc build going is the
set of warnings that gcc acts on but clang only recognizes for
compatibility. As a common example, -Wredundant-decls has no effect
in clang, but will break the gcc build. There are a couple dozen such
flags [1][2], and a few of them are in our default set of warnings, such
as in sys/conf/kern.mk, these ones in CWARNFLAGS:
- Wredundant-decls
- Wnested-externs
- Wmissing-include-dirs
additionally some warnings are explicitly disabled for clang, but not
for gcc in CWARNEXTRA:
- Wempty-body
- Wunused-function
Similarly, in share/mk/bsd.sys.mk:
- Winline (although, Wno-error'd)
- Wnested-externs
- Wredundant-decls
- Wold-style-definition
So I suggest we harmonize these somewhat.
- Wnested-externs I just do not understand. We have specified this
warning flag for some 25 years but to me it seems completely without
value. I suggest we just delete it.
- Wredundant-decls, I'm not sure about. I have never seen this detect
anything that will cause misbehavior, but most of the time that it
fires it does indicate some kind of genuine--but harmless--mistake.
- Wmissing-include-dirs doesn't seem to occur often and usually
indicates a genuine (but again harmless) mistake in a makefile. I
think we should keep it.
- Wempty-body, Wunused-function. I'm not sure. These are proscriptive
about things that are not necessarily problems. We are apparently
already clean for them in the kernel gcc build, so perhaps we should
enable them for the kernel clang build. In any case, I think we
should bring these into agreement between clang and gcc, one way or
the other.
Another sticking point may be contrib software. I think we generally
don't want to fail builds of contrib software for things that are
ultimately harmless. For bsd.sys.mk this could be accomplished by
enabling such warnings only at WARNS >= 6. For the kernel, we could
come up with some other mechanism.
I'll put up a review soon for deleting -Wnested-externs unless there are
objections. If there is agreement about the others, I'll include those
too.
Ryan
[1] https://clang.llvm.org/docs/DiagnosticsReference.html
[2] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
More information about the freebsd-hackers
mailing list