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

            Bug ID: 90844
           Summary: Another case of missing use of uninitialized variable
                    warning
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: subscriptions-gnu at vsbe dot com
  Target Milestone: ---

this is somewhat similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501,
but a bit different. Here is the code to trigger the problem:

vvvvvvvvvvv  try.c  vvvvvvvvvvvvvvvvvvvvvvvvvvv
static int func1(int x) { return 1; }

static int func2(void)
{
        int number;
        if (func2() == 0) number += func1(0);
        return number;
}

int main(int argc, char **argv)
{
        int counter;
        counter +=  func2();
        return counter;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Running on 4.19.28-2 x86_64 GNU/Linux, using compiler version

vvvvvvvvvvvvvvvvvvvvvvvvvvvv
arm-eabi-gcc  -v
Using built-in specs.
COLLECT_GCC=/usr/local/google/home/vbendeb/new_projects/1grepo/chroot/opt/coreboot-sdk/bin/arm-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/local/google/home/vbendeb/new_projects/1grepo/chroot/opt/coreboot-sdk/bin/../lib/gcc/arm-eabi/8.3.0/lto-wrapper
Target: arm-eabi
Configured with: ../gcc-8.3.0/configure --prefix=/opt/coreboot-sdk
--libexecdir=/opt/coreboot-sdk/lib --target=arm-eabi --disable-werror
--disable-shared --enable-lto --enable-plugins --enable-gold
--enable-ld=default --disable-libssp --disable-bootstrap --disable-nls
--disable-libquadmath --without-headers --disable-threads --enable-interwork
--enable-multilib --enable-targets=all --disable-libatomic --disable-libcc1
--disable-decimal-float --enable-languages=c,ada --with-system-zlib
--with-gmp=/var/tmp/portage/dev-embedded/coreboot-sdk-0.0.1-r74/work/coreboot-sdk-0.0.1/out/opt/coreboot-sdk
--with-mpfr=/var/tmp/portage/dev-embedded/coreboot-sdk-0.0.1-r74/work/coreboot-sdk-0.0.1/out/opt/coreboot-sdk
--with-mpc=/var/tmp/portage/dev-embedded/coreboot-sdk-0.0.1-r74/work/coreboot-sdk-0.0.1/out/opt/coreboot-sdk
--with-gnu-as --with-gnu-ld --with-pkgversion='coreboot toolchain v '
Thread model: single
gcc version 8.3.0 (coreboot toolchain v ) 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


The below invocation properly highlights two instance of the uninitialized
variable assignment:

$ arm-eabi-gcc -Wall -o try.o -c try.c
try.c: In function 'func2':
try.c:7:34: warning: 'number' may be used uninitialized in this function
[-Wmaybe-uninitialized]
         if (func2() == 0) number += func1(0);
                                  ^~
try.c: In function 'main':
try.c:14:17: warning: 'counter' is used uninitialized in this function
[-Wuninitialized]
         counter +=  func2();
                 ^~
$





The following invocation triggers only one warning:

$ arm-eabi-gcc -Wall -Os -flto  -o try.o -c try.c
try.c: In function 'main':
try.c:14:17: warning: 'counter' is used uninitialized in this function
[-Wuninitialized]
         counter +=  func2();
                 ^~
$

Reply via email to