public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100496] New: False positive with -Wmaybe-uninitialized
@ 2021-05-10 8:29 jochen447 at concept dot de
2021-05-10 18:12 ` [Bug c/100496] " pinskia at gcc dot gnu.org
2021-05-10 21:39 ` msebor at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: jochen447 at concept dot de @ 2021-05-10 8:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100496
Bug ID: 100496
Summary: False positive with -Wmaybe-uninitialized
Product: gcc
Version: 11.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jochen447 at concept dot de
Target Milestone: ---
Created attachment 50784
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50784&action=edit
minimal example code to trigger the false positive warning
I have a piece of C code that is 100% correct, compiles fine, but evokes a
warning with -Wmaybe-uninitialized:
$ gcc -c -Wmaybe-uninitialized uninit.c
uninit.c: In function ‘findEncoding’:
uninit.c:19:3: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
19 | XmlUtf8Convert(p, p + sizeof(buf) - 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uninit.c:14:13: note: by argument 2 of type ‘const char * const’ to
‘XmlUtf8Convert’ declared here
14 | extern void XmlUtf8Convert(char* p_start, const char* const p_end);
| ^~~~~~~~~~~~~~
uninit.c:17:8: note: ‘buf’ declared here
17 | char buf[128];
| ^~~
The compiler complains about the 2nd argument passed down to function
XmlUtf8Convert. It is indeed pointing to uninitialized memory (but so is the
first argument). But it cannot see that this pointer serves as a guard (pointer
arithmetic) - it is never dereferenced inside the function XmlUtf8Convert.
So the compiler's assumptions are wrong here.
More info:
==========
$ uname -a
Linux inspiron14l 5.11.18-300.fc34.x86_64 #1 SMP Mon May 3 15:10:32 UTC 2021
x86_64 x86_64 x86_64 GNU/Linux
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-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=/builddir/build/BUILD/gcc-11.1.1-20210428/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.1 20210428 (Red Hat 11.1.1-1) (GCC)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-10 21:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 8:29 [Bug c/100496] New: False positive with -Wmaybe-uninitialized jochen447 at concept dot de
2021-05-10 18:12 ` [Bug c/100496] " pinskia at gcc dot gnu.org
2021-05-10 21:39 ` msebor at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).