https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124588
Bug ID: 124588
Summary: missing -Wuninitialized when certain function call
exists
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: m2rad0 at tutamail dot com
Target Milestone: ---
I ran into this issue diagnosing some bad code written by me. Searched and
found some related reports, but none identical to this situation.
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:", "should this also cause a warning?");
struct Testing test;
return func(&test, test.b); // uninitialized use of test.b
// using two different structs outputs only a -Wuninitialized warning
//struct Testing not_test;
//return func(¬_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)