https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69975

            Bug ID: 69975
           Summary: Missing uninitilized warning / optimized to use wrong
                    value
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jan.sm...@alcatel-lucent.com
  Target Milestone: ---

#include <stdio.h>

int X;

int foo(int yyy, int zzz)
{
    int xxx;

    if (yyy)
    {
        printf("in y\n");
        xxx = 5;
    }

    if (zzz)
    {
        printf("in x\n");
        X = xxx;
    }

    return X;
}

int main(void)
{
    printf("got %d\n", foo(0,1));
    return 0;
}


$ gcc test-uninit.c -o /tmp/bla -O1  -Wall -Wuninitialized  && /tmp/bla
in x
got 5

$ gcc test-uninit.c -o /tmp/bla -O0  -Wall -Wuninitialized  && /tmp/bla
in x
got 0


I would have expected random garbage from the stack, but never ever '5'. 
(which makes it seem as if the (yyy) condition was true.)

And this should really give a compile time warning.

If this is considered undefined behaviour, then it is not cought by
-fsanitize=undefined in GCC 5.3

Reply via email to