Bug 57629 - -Wmaybe-uninitialized does not catch some conditional initialization
Summary: -Wmaybe-uninitialized does not catch some conditional initialization
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-16 12:07 UTC by Szabolcs Nagy
Modified: 2013-06-16 15:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Szabolcs Nagy 2013-06-16 12:07:45 UTC
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
Comment 1 Manuel López-Ibáñez 2013-06-16 15:23:46 UTC
Dup

*** This bug has been marked as a duplicate of bug 18501 ***