Compiling lua-5.4.2 using Cygwin gcc 10.2.0: In function ‘str_unpack’: lstrlib.c:1722:18: warning: ‘u.n’ may be used uninitialized in this function [-Wmaybe-uninitialized]

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiling lua-5.4.2 using Cygwin gcc 10.2.0: In function ‘str_unpack’: lstrlib.c:1722:18: warning: ‘u.n’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Thorkil Naur
Dear Lua'ers,

On a Windows 7 machine running 32-bit Cygwin

> $ uname -a
> CYGWIN_NT-6.1-WOW Annette-Pc2 3.1.7(0.340/5/3) 2020-08-22 19:03 i686 Cygwin

with

> $ gcc --version
> gcc (GCC) 10.2.0
> Copyright (C) 2020 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

when compiling lua-5.4.2, I get the following:

> $ make generic
> ...
> gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3     -c -o lstrlib.o lstrlib.c
> lstrlib.c: In function ‘str_unpack’:
> lstrlib.c:1722:18: warning: ‘u.n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>  1722 |         else num = u.n;
>       |              ~~~~^~~~~
> ...

Neither with

> $ uname -a
> FreeBSD tn34.thorkilnaur.dk 12.2-RELEASE FreeBSD 12.2-RELEASE r366954 GENERIC  i386
> $ cc -v
> FreeBSD clang version 10.0.1 ([hidden email]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
> Target: i386-unknown-freebsd12.2
> Thread model: posix
> InstalledDir: /usr/bin

nor with

> $ uname -a
> Linux tn41.thorkilnaur.dk 5.6.13-100.fc30.i686 #1 SMP Fri May 15 00:02:53 UTC 2020 i686 i686 i386 GNU/Linux
> $ gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-redhat-linux/9/lto-wrapper
> Target: i686-redhat-linux
> Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
> Thread model: posix
> gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)

do I see this warning.

Best regards
Thorkil
Reply | Threaded
Open this post in threaded view
|

Re: Compiling lua-5.4.2 using Cygwin gcc 10.2.0: In function ‘str_unpack’: lstrlib.c:1722:18: warning: ‘u.n’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Roberto Ierusalimschy
> On a Windows 7 machine running 32-bit Cygwin
>
> [...]
>
> when compiling lua-5.4.2, I get the following:
>
> > $ make generic
> > ...
> > gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3     -c -o lstrlib.o lstrlib.c
> > lstrlib.c: In function ‘str_unpack’:
> > lstrlib.c:1722:18: warning: ‘u.n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> >  1722 |         else num = u.n;

This is a problem of gcc trying (unsuccessfully) to be too smart :-(
Its documentation is explicit about that issue:

  -Wmaybe-uninitialized
   [...]
   These warnings are made optional because GCC may not be able to
   determine when the code is correct in spite of appearing to have an
   error.

Despite this disclaimer, this option is enabled by -Wall.

-- Roberto