gcc-15.2 -Wuninitialized not detected when certain function call exists

m2rad0@tutamail.com m2rad0@tutamail.com
Sun Mar 15 03:02:14 GMT 2026


Good morning/afternoon/evening all. Long time user, first time caller here. I ran into this issue diagnosing some UB I had foolishly caused. Searched the bugzilla and found some related reports, but none identical to this situation so figured I should fire off an email at least.

possibly related:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107663
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106541
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100126

gcc_15_uninitialized.c:
---
#include <stdio.h>
struct Testing {
        int a;
        int b;
};
void seemingly_unrelated(/*void*/)
{
        printf("seemingly_unrelated(void) doesn't touch 'test' at all!\n");
}
static int func(const struct Testing *test, const int b)
{
        return test->a + b;
}
static int notmain()
{
        // comment this line out to get the expected uninitialized warning
        seemingly_unrelated("side note:", " no warning here either");

        struct Testing test;
        return func(&test, test.b); // uninitialized use of test.b

        // using two structs causes warning, as expected
        //struct Testing not_test;
        //return func(&not_test, test.b);
}
int main(void)
{
        printf("bug won't happen in main()\n");
        printf("a+b == %d\n", notmain());
        return 0;
}
---
The warnings will be caught only when the function call to 'seemingly_unrelated' is removed.

cmdline:
gcc -O0 -g -pedantic -Wall -Wextra -Wconversion -Werror -o test gcc_15_uninitialized.c && ./test

expected output:
gcc_15_uninitialized.c:20:32: error: 'test.b' is used uninitialized [-Werror=uninitialized]
gcc_15_uninitialized.c:20:16: error: 'test' may be used uninitialized [-Werror=maybe-uninitialized]

config:Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-artax-linux-gnu
Configured with: /home/builddir/gcc/gcc-15.2.0/configure --with-sysroot= --prefix=/artax --build=x86_64-artax-linux-gnu --host=x86_64-artax-linux-gnu --target=x86_64-artax-linux-gnu --with-local-prefix=/artax --with-native-system-header-dir=/artax/include --with-gxx-include-dir=/artax/include/c++ --enable-default-ssp --enable-threads=posix --enable-targets=all --enable-languages=c,c++ --disable-nls --disable-libsanitizer --disable-plugin --disable-bootstrap --disable-multilib --disable-lto
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.2.0 (GCC)


More information about the Gcc-bugs mailing list