[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #1 from jellegeerts at gmail dot com  2010-08-31 20:02 ---
Created an attachment (id=21619)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21619action=view)
output of `gcc -v -save-temps -std=c99 -O -g -Wall gcctest.c -o gcctest'


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #2 from jellegeerts at gmail dot com  2010-08-31 20:03 ---
Created an attachment (id=21620)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21620action=view)
output of `gcc -v -save-temps -std=c99 -O -g -Wall gcctest.c -o gcctest'


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #3 from jellegeerts at gmail dot com  2010-08-31 20:03 ---
Created an attachment (id=21621)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21621action=view)
the `.i' file that GCC created


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #4 from jellegeerts at gmail dot com  2010-08-31 20:04 ---
Created an attachment (id=21622)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21622action=view)
`.i' file that GCC created


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jakub at gcc dot gnu dot org


--- Comment #5 from jakub at gcc dot gnu dot org  2010-08-31 20:13 ---
That's because the whole foo function doesn't have any side-effects, so it is
optimized away completely.


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #6 from jellegeerts at gmail dot com  2010-08-31 20:14 ---
It also happens in functions that do have side-effects. I can give you an
example if you want?


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #7 from jellegeerts at gmail dot com  2010-08-31 20:32 ---
Updated code snippet, GCC doesn't warn here either if we leave `#if 0' as-is,
even though the function foo() may have side-effects.


#include stdio.h

static int array[32];

#if 0 // If '#if 1' is used, GCC warns correctly about the use of uninitialized
variable 'i' below.
int foo(void);
int foo(void)
#else
static int foo(void)
#endif
{
for (int i; i  32; ++i)
{
if (array[i])
return 1;
}

return 0;
}

int main(void)
{
foo();

return 0;
}



-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread manu at gcc dot gnu dot org


--- Comment #8 from manu at gcc dot gnu dot org  2010-08-31 20:37 ---
(In reply to comment #7)
 Updated code snippet, GCC doesn't warn here either if we leave `#if 0' as-is,
 even though the function foo() may have side-effects.

No, the function below does not have any side-effects. The result of the
program is the same whether the function runs or not because the return value
is ignored. To have a side-effect you need to write/print, change global
memory, or affect the return value of the program.

Until then, this is invalid. Please, reopen when you have a valid testcase
(there are bugs in Wuninitialized, so I wouldn't be surprised if you find one).


-- 

manu at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||manu at gcc dot gnu dot org
 Status|UNCONFIRMED |RESOLVED
 Resolution||WORKSFORME


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #9 from jellegeerts at gmail dot com  2010-08-31 20:47 ---
Okay. :)

Though, why does GCC warn when we have `#if 1', and not if we have `#if 0'?
Just curiosity...


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #10 from jellegeerts at gmail dot com  2010-08-31 20:49 ---
Also, it seems a bit questionable to not warn when it is clearly(?) not the
developers intent to use an uninitialized variable. What is the rationale
behind this? Is it a pragmatic thing?


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jakub at gcc dot gnu dot org


--- Comment #11 from jakub at gcc dot gnu dot org  2010-08-31 20:53 ---
Because when foo is not static, it has to be compiled.  If it is static, GCC
figures it is a pure function (only reads memory and arguments and computes
from it its return value) and as the result in main of the function isn't used,
that call is optimized away very early.  As foo isn't used anywhere else, it
isn't compiled at all.


-- 


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



[Bug c/45467] gcc won't warn about an uninitialized value

2010-08-31 Thread jellegeerts at gmail dot com


--- Comment #12 from jellegeerts at gmail dot com  2010-08-31 20:54 ---
Thanks. :)


-- 


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