move -Wno-error=uninitialized to configure
PATCH 1/1 move -Wno-error=uninitialized to configure
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
--- configure | 15 ++++++++++++++- rules.mak | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)
configure +14 -1
@@ -526,8 +526,21 @@ if test -z "$werror" ; then fi fi +# Disable uninitialized variable warning or convert it to non-error, if possible +cat > $TMPC <<EOF +int main(void) {} +EOF +if $cc -Werror -Wno-error=uninitialized -c -o $TMPO $TMPC > /dev/null 2> /dev/null ; then + # Enable werror by default for recent compilers + werror_cflags="-Werror -Wno-error=uninitialized" +elif $cc -Werror -Wno-uninitialized -c -o $TMPO $TMPC > /dev/null 2> /dev/null ; then + werror_cflags="-Werror -Wno-uninitialized" +else + werror_cflags="-Werror" +fi + if test "$werror" = "yes" ; then - CFLAGS="$CFLAGS -Werror" + CFLAGS="$CFLAGS $werror_cflags" fi if test "$solaris" = "no" ; then
rules.mak +1 -1
@@ -1,6 +1,6 @@ %.o: %.c - $(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -Werror -Wno-error=uninitialized -c -o $@ $<," CC $(TARGET_DIR)$@") + $(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@") %.o: %.S $(call quiet-command,$(CC) $(CPPFLAGS) -c -o $@ $<," AS $(TARGET_DIR)$@")
Signature · 1 line
1.6.2.2
Quoted 2 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Why? Shouldn't we be fixing the uninitialized variables?
Paul
Quoted 7 lines · Paul Brook
Quoted 2 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Why? Shouldn't we be fixing the uninitialized variables?
Paul
gcc's algorithm for detecting uninitialized variables is famously unreliable. Just scattering '= 0' around the code masks the warning but hides the fact that application logic might still be broken.
Signature · 1 line
MST
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Paul Brook
Quoted 2 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Quoted 8 lines
Quoted 3 lines
Why? Shouldn't we be fixing the uninitialized variables?
Paul
gcc's algorithm for detecting uninitialized variables is famously unreliable. Just scattering '= 0' around the code masks the warning but hides the fact that application logic might still be broken.
To clarify: what's broken is that gcc has false positives in the logic. And if you work around this by adding initialization where it's not really required, you confuse other tools that would otherwise have a chance to detect an error.
Signature · 1 line
MST
Quoted 15 lines · Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Paul Brook
Quoted 2 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Quoted 8 lines
Quoted 3 lines
Why? Shouldn't we be fixing the uninitialized variables?
Paul
gcc's algorithm for detecting uninitialized variables is famously unreliable. Just scattering '= 0' around the code masks the warning but hides the fact that application logic might still be broken.
Quoted 4 lines
To clarify: what's broken is that gcc has false positives in the logic. And if you work around this by adding initialization where it's not really required, you confuse other tools that would otherwise have a chance to detect an error.
In that case should we be using -Wno-uninitialized?
The whole point of -Werror is that it forces us to keep the code clean. Having to mentally filter out false positives just doesn't work. Once you have routinely expected warnings then people stop checking for new ones.
Paul
Quoted 21 lines · Paul Brook
Quoted 15 lines · Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Paul Brook
Quoted 2 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Quoted 8 lines
Quoted 3 lines
Why? Shouldn't we be fixing the uninitialized variables?
Paul
gcc's algorithm for detecting uninitialized variables is famously unreliable. Just scattering '= 0' around the code masks the warning but hides the fact that application logic might still be broken.
Quoted 4 lines
To clarify: what's broken is that gcc has false positives in the logic. And if you work around this by adding initialization where it's not really required, you confuse other tools that would otherwise have a chance to detect an error.
Quoted 7 lines
In that case should we be using -Wno-uninitialized?
The whole point of -Werror is that it forces us to keep the code clean. Having to mentally filter out false positives just doesn't work. Once you have routinely expected warnings then people stop checking for new ones.
Paul
That's what -Wno-error=uninitialized does: makes the filtering automatically so you don't need to filter it mentally.
Signature · 1 line
MST
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Paul Brook
The whole point of -Werror is that it forces us to keep the code clean. Having to mentally filter out false positives just doesn't work. Once you have routinely expected warnings then people stop checking for new ones.
That's what -Wno-error=uninitialized does: makes the filtering automatically so you don't need to filter it mentally.
Right, but not all versions of GCC that support '-Werror' support '-Wno-error=...'. As I tried to hint at previously, the only sensible way to deal with this is to use '-Werror=...' to be specific about the types of checking that you want, so that you can avoid checks that produce false positives, and only enable the checking on versions of GCC that support it. Otherwise, future versions of GCC could produce all sorts of false positives that you have no control over. '-Werror=...' doesn't fix that entirely, but at least it's a start.
I've already seen several 'fixes' to QEMU to suppress false positives. For some strange reason people always pick the magic value '0' when 'shutting GCC up'. *sigh* At the very least, *please please please* consider something like Linux's uninitialized_var() macro for this.
(BTW, recommended reading: http://lwn.net/Articles/331593/)
Cheers,
Signature · 1 line
Stuart Brady
Quoted 8 lines · Paul Brook
Quoted 3 lines · Michael S. Tsirkin
Move -Wno-error=uninitialized out of rules.mak and into configure. Only use it if supported by compiler.
Why? Shouldn't we be fixing the uninitialized variables?
Fixing older compilers to support -Wno-error is out of the scope of this project.
Signature · 1 line
error compiling committee.c: too many arguments to function