public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42643] "may be used uninitialized" compiled with "-Wall -O"
       [not found] <bug-42643-4@http.gcc.gnu.org/bugzilla/>
@ 2012-01-06 20:09 ` mi+gcc at aldan dot algebra.com
  2012-12-28 21:27 ` steven at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mi+gcc at aldan dot algebra.com @ 2012-01-06 20:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42643

--- Comment #2 from mi+gcc at aldan dot algebra.com 2012-01-06 20:08:54 UTC ---
Created attachment 26259
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26259
Live test case (file from Mozilla's NSS package)

Even when using gcc-4.6 (more specifically gcc version 4.6.3 20111104
(prerelease) (FreeBSD Ports Collection)), I still get a bogus warning on the
attached file, unless the optimization level is at -O3 AND the -fPIC is not
specified:

mi@narawntapu:nss/lib/util (1778) gcc46 -Wall -O3 -c nssb64e.i
mi@narawntapu:nss/lib/util (1779) gcc46 -Wall -O2 -c nssb64e.i
nssb64e.i: In function 'NSSBase64_EncodeItem_Util':
nssb64e.i:3239:15: warning: 'out_len' may be used uninitialized in this
function [-Wuninitialized]
mi@narawntapu:nss/lib/util (1780) gcc46 -Wall -O3 -fPIC -c nssb64e.i
nssb64e.i: In function 'NSSBase64_EncodeItem_Util':
nssb64e.i:3239:15: warning: 'out_len' may be used uninitialized in this
function [-Wuninitialized]


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/42643] "may be used uninitialized" compiled with "-Wall -O"
       [not found] <bug-42643-4@http.gcc.gnu.org/bugzilla/>
  2012-01-06 20:09 ` [Bug c/42643] "may be used uninitialized" compiled with "-Wall -O" mi+gcc at aldan dot algebra.com
@ 2012-12-28 21:27 ` steven at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: steven at gcc dot gnu.org @ 2012-12-28 21:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42643

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mi+gcc at aldan dot
                   |                            |algebra.com
         Resolution|                            |FIXED

--- Comment #3 from Steven Bosscher <steven at gcc dot gnu.org> 2012-12-28 21:27:07 UTC ---
(In reply to comment #2)
> Created attachment 26259 [details]
> Live test case (file from Mozilla's NSS package)
> 
> Even when using gcc-4.6 (more specifically gcc version 4.6.3 20111104
> (prerelease) (FreeBSD Ports Collection)), I still get a bogus warning on the
> attached file, unless the optimization level is at -O3 AND the -fPIC is not
> specified:
> 
> mi@narawntapu:nss/lib/util (1778) gcc46 -Wall -O3 -c nssb64e.i
> mi@narawntapu:nss/lib/util (1779) gcc46 -Wall -O2 -c nssb64e.i
> nssb64e.i: In function 'NSSBase64_EncodeItem_Util':
> nssb64e.i:3239:15: warning: 'out_len' may be used uninitialized in this
> function [-Wuninitialized]
> mi@narawntapu:nss/lib/util (1780) gcc46 -Wall -O3 -fPIC -c nssb64e.i
> nssb64e.i: In function 'NSSBase64_EncodeItem_Util':
> nssb64e.i:3239:15: warning: 'out_len' may be used uninitialized in this
> function [-Wuninitialized]

Why is this warning "bogus" in your opinion? It looks valid to me...

The compiler cannot tell that out_len is initialized. The only place
where out_len can pick up a value, is in the call to PL_Base64EncodeBuffer:

    dummy = PL_Base64EncodeBuffer (inItem->data, inItem->len, 64,
       out_string, max_out_len, &out_len);

The compiler can't look into PL_Base64EncodeBuffer to see if a value will
be assigned to "PRUint32 * output_destlen". The programmer can see that
this will happen, or that otherwise NULL will be returned, but that is a
really hard problem for the compiler.  If you expect it to do that, you
should be looking for a static checker that can do this kind of expensive
analysis. There are GCC plugins that can do it.

FWIW the test case of comment #0 is fixed since GCC 4.6, so closing this
problem report as FIXED.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/42643] "may be used uninitialized" compiled with "-Wall -O"
  2010-01-07  0:48 [Bug c/42643] New: " numidee at synopsys dot com
@ 2010-04-21  0:29 ` davidxl at gcc dot gnu dot org
  0 siblings, 0 replies; 3+ messages in thread
From: davidxl at gcc dot gnu dot org @ 2010-04-21  0:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from davidxl at gcc dot gnu dot org  2010-04-21 00:29 -------
(In reply to comment #0)
> When compiling the source with "-Wall -O", gcc gives the following warning:
> 
> % gcc -c -Wall -O gcc_test.c
> gcc_test.c: In function ?functionLeon?:
> gcc_test.c:11: warning: ?reference? may be used uninitialized in this function
> 
> % cat gcc_test.c
> #include<stdio.h>
> 
> typedef struct {
>   int yb;
> } TCRData;
> 
> void functionLeon (TCRData *pParent, int pBool);
> void functionLeon (TCRData *pParent, int pBool)
> {
>     int isRootCell;
>     TCRData *reference;
> 
>     isRootCell = (pParent == NULL);
> 
>     if (!isRootCell)
>         reference = pParent;
> 
>     if (pBool) {
>        if(!isRootCell)
>           reference->yb++;
>     }
> }
> 
> % gcc -v
> Using built-in specs.
> Target: x86_64-redhat-linux
> Configured with: ../../src/gcc-4.4.0/configure
> --prefix=/remote/depotsrc/depotsrc/amd64-2.4/local_install/gcc-4.4.0
> --enable-bootstrap --enable-shared --enable-threads=posix --disable-checking
> -with-gmp=/remote/depotsrc/depotsrc/amd64-2.4/local_install/gmp-4.3.1
> --with-mpfr=/remote/depotsrc/depotsrc/amd64-2.4/local_install/mpfr-2.4.1
> --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
> --enable-languages=c,c++,fortran --with-cpu=generic --build=x86_64-redhat-linux
> Thread model: posix
> gcc version 4.4.0 (GCC)
> 

This is a common case handled by patch in

http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00706.html


-- 

davidxl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidxl at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42643


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-28 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42643-4@http.gcc.gnu.org/bugzilla/>
2012-01-06 20:09 ` [Bug c/42643] "may be used uninitialized" compiled with "-Wall -O" mi+gcc at aldan dot algebra.com
2012-12-28 21:27 ` steven at gcc dot gnu.org
2010-01-07  0:48 [Bug c/42643] New: " numidee at synopsys dot com
2010-04-21  0:29 ` [Bug c/42643] " davidxl at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).