Bug #5108
closedvalue may be used uninitialized in rpcbind.c
0%
Description
Building $SRC/cmd/rpcbind (on sparc)
rpcbind.c:1061: error: 'val' may be used uninitialized in this function [-Wuninitialized]
rpcbind.c:1084: error: 'val' may be used uninitialized in this function [-Wuninitialized]
Files
Related issues
Updated by Gordon Ross about 9 years ago
- File 0002-rpcbind.c-value-may-be-used-uninitialized-sparc.patch 0002-rpcbind.c-value-may-be-used-uninitialized-sparc.patch added
Simple fix (attached)
Updated by Marcel Telka about 9 years ago
This is my analysis from May 2014:
I found that this problem is basically a bug in gcc: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42145 I did some testing with the following simple testcase: int f(void); int main(void) { int a, b; a = f(); if (a) b = f(); if (a && b) return 1; return 0; } Here are results on intel (on recent OpenIndiana hipster): $ /usr/bin/gcc --version gcc (GCC) 4.7.3 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /usr/bin/gcc -O1 -Wuninitialized -c a.c a.c: In function ‘main’: a.c:12:15: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized] $ $ $ $ /opt/gcc/4.4.4/bin/gcc --version gcc (Illumos gcc-4.4.4-il-3) 4.4.4 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /opt/gcc/4.4.4/bin/gcc -O1 -Wuninitialized -c a.c $ It is interesting that illumos-gcc 4.4.4 does NOT fail. And here are results on sparc (I'm not sure about the patch level of these gcc builds): $ uname -a SunOS bld5 5.11 1.3.6-sparc sun4u sparc SUNW,Sun-Fire-V440 $ $ $ /usr/gcc/4.4/bin/gcc --version gcc (GCC) 4.4.7 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /usr/gcc/4.4/bin/gcc -O1 -Wuninitialized -c a.c a.c: In function 'main': a.c:6: warning: 'b' may be used uninitialized in this function $ $ $ $ /usr/gcc/4.7/bin/gcc --version gcc (GCC) 4.7.3 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /usr/gcc/4.7/bin/gcc -O1 -Wuninitialized -c a.c a.c: In function 'main': a.c:12:15: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized] $ $ $ $ /usr/gcc/4.8/bin/gcc --version gcc (GCC) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /usr/gcc/4.8/bin/gcc -O1 -Wuninitialized -c a.c a.c: In function 'main': a.c:12:15: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized] if (a && b) ^ $ I had no chance[*] to test this with illumos-gcc 4.4.4 on sparc to see whether the issue is reproducible there or not. [*] yet. But since I've no access to illumos-gcc 4.4.4 on sparc I do not plan to test it. If there is somebody with illumos-gcc 4.4.4 on sparc please run the test. Thanks.
Updated by Richard PALO about 9 years ago
[corrected.. after restarting in a clean environment seemed okay]
Pedantically this is probably correct and is why -Wno-maybe-uninitialized exists...
The testsuite (following is pkgsrc 4.7.3) succeeds, and the above test program compiles without warning as well.
Executing on host: /tmp/pkgsrc/lang/gcc47/work/build/gcc/xgcc -B/tmp/pkgsrc/lang/gcc47/work/build/gcc/ /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress.c -fno-tree-ccp -fno-tree-vrp -O2 -Wuninitialized -Wno-maybe-uninitialized -S -o uninit-suppress.s (timeout = 300) spawn /tmp/pkgsrc/lang/gcc47/work/build/gcc/xgcc -B/tmp/pkgsrc/lang/gcc47/work/build/gcc/ /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress.c -fno-tree-ccp -fno-tree-vrp -O2 -Wuninitialized -Wno-maybe-uninitialized -S -o uninit-suppress.s PASS: gcc.dg/uninit-suppress.c should be suppressed (test for bogus messages, line 15) PASS: gcc.dg/uninit-suppress.c (test for excess errors) Executing on host: /tmp/pkgsrc/lang/gcc47/work/build/gcc/xgcc -B/tmp/pkgsrc/lang/gcc47/work/build/gcc/ /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c -fno-tree-ccp -fno-tree-vrp -O2 -Wuninitialized -Werror=uninitialized -Wno-error=maybe-uninitialized -S -o uninit-suppress_2.s (timeout = 300) spawn /tmp/pkgsrc/lang/gcc47/work/build/gcc/xgcc -B/tmp/pkgsrc/lang/gcc47/work/build/gcc/ /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c -fno-tree-ccp -fno-tree-vrp -O2 -Wuninitialized -Werror=uninitialized -Wno-error=maybe-uninitialized -S -o uninit-suppress_2.s /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c: In function 'foo': /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c:15:8: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized] output is: /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c: In function 'foo': /tmp/pkgsrc/lang/gcc47/work/gcc-4.7.3/gcc/testsuite/gcc.dg/uninit-suppress_2.c:15:8: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized] PASS: gcc.dg/uninit-suppress_2.c should not be promoted to error (test for warnings, line 15) PASS: gcc.dg/uninit-suppress_2.c (test for excess errors)
Naturally 'volatile' gets over it if relevant for the real case in hand.
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options or
https://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/Warning-Options.html#Warning-Options