This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/57629] New: -Wmaybe-uninitialized does not catch some conditional initialization
- From: "nszabolcs at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 16 Jun 2013 12:07:45 +0000
- Subject: [Bug c/57629] New: -Wmaybe-uninitialized does not catch some conditional initialization
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57629
Bug ID: 57629
Summary: -Wmaybe-uninitialized does not catch some conditional
initialization
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: nszabolcs at gmail dot com
In the following example gcc should be able to prove that
x may be uninitialized, but it does not warn.
$ gcc-4.8 -c -O2 -Wmaybe-uninitialized example.c
$ cat example.c
int f(void);
int g(void) {
int x;
if (f())
x = 1;
return x;
}
With -O2 the generated code actually unconditionally returns 1
and discards the return value of f().
This is something the compiler can and should warn about when
specifically asked to.
$ gcc-4.8 -S -fno-asynchronous-unwind-tables -O2 -Wmaybe-uninitialized
example.c
$ cat example.s
.file "example.c"
.text
.p2align 4,,15
.globl g
.type g, @function
g:
subl $12, %esp
call f
movl $1, %eax
addl $12, %esp
ret
.size g, .-g
.ident "GCC: (GNU) 4.8.0"
.section .note.GNU-stack,"",@progbits