https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105961
Bug ID: 105961
Summary: -Wanalyzer-use-of-uninitialized-value false positive
after "= {0}"
Product: gcc
Version: 12.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: eggert at cs dot ucla.edu
Target Milestone: ---
This is gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1) on x86-64. I do not
observe the bug with gcc-12 (Ubuntu 12-20220319-1ubuntu1) 12.0.1 20220319
(experimental) [master r12-7719-g8ca61ad148f] on x86-64.
Compile the attached program (derived from bleeding-edge Emacs) with:
gcc -O2 -S -fanalyzer t.i
GCC complains:
In function ‘dump_mmap_release’,
inlined from ‘pdumper_load’ at t.i:50527:5:
t.i:49512:10: warning: use of uninitialized value ‘sections[i].release’
[CWE-457] [-Wanalyzer-use-of-uninitialized-value]
49512 | if (map->release)
| ~~~^~~~~~~~~
‘pdumper_load’: events 1-9
|
|50318 | pdumper_load (const char *dump_filename, char *argv0)
| | ^~~~~~~~~~~~
| | |
| | (1) entry to ‘pdumper_load’
|......
|50331 | struct dump_memory_map sections[NUMBER_DUMP_SECTIONS] = { 0 };
| | ~~~~~~~~
| | |
| | (2) region created on stack here
|......
The region is obviously initialized, via the "= { 0 }" at the end. The
following change pacifies GCC, but should not be necessary.
--- t.i 2022-06-13 13:06:59.000000000 -0700
+++ u.i 2022-06-13 13:09:18.000000000 -0700
@@ -50329,6 +50329,7 @@
struct dump_header header_buf = { 0 };
struct dump_header *header = &header_buf;
struct dump_memory_map sections[NUMBER_DUMP_SECTIONS] = { 0 };
+ memset (sections, 0, sizeof sections);
const struct timespec start_time = current_timespec ();
char *dump_filename_copy;