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

Andrew D'Addesio <modchipv12 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |modchipv12 at gmail dot com

--- Comment #5 from Andrew D'Addesio <modchipv12 at gmail dot com> ---
GCC already warns about this at compile time, but the warning sometimes doesn't
appear (due to PR88058, as Andrew Pinski just mentioned). Plus, the warning is
a bit confusing and could be reworded.

For example, create the following files:

foo.c:

    int foo(const unsigned char *buf)
    {
        (void)buf; /* unused parameter */
        return 1;
    }

test.c:

    int foo(const unsigned char *buf);

    struct mytype {
        char c;
    };

    static struct mytype d = { 42 };

    int test(int x)
    {
        const unsigned char buf[32];
        const struct mytype *ptr = &d;

        if (x != 0)
            ptr = &(const struct mytype){ 43 };

        foo(buf);
    #ifdef CALL_FOO_TWICE
        foo(buf);
    #endif

        return ptr->c;
    }

    int main()
    {
        return test(1); /* returns 43 on GCC8, 0 on GCC9+ */
    }

Compiling with one foo() call gives us a warning:

    $ gcc -std=c99 -Wall -Wextra -pedantic -O1 -o test test.c foo.c
    test.c: In function ‘main’:
    test.c:26:15: warning: ‘<U2cf0>.c’ is used uninitialized in this function
[-Wuninitialized]
       26 |     return ptr->c;
          |            ~~~^~~
    $ ./test
    $ echo $?
    0

However, compiling with two foo() calls makes the warning disappear, for some
reason:

    $ gcc -DCALL_FOO_TWICE -std=c99 -Wall -Wextra -pedantic -O1 -o test test.c
foo.c
    $ ./test
    $ echo $?
    0

My GCC version is 9.3.1 20200317 (Red Hat 9.3.1-1) on Fedora 31 x86-64.

Reply via email to