This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/57629] New: -Wmaybe-uninitialized does not catch some conditional initialization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]