public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf
@ 2024-05-05 22:15 kacper.slominski72 at gmail dot com
2024-05-05 22:21 ` [Bug tree-optimization/114952] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: kacper.slominski72 at gmail dot com @ 2024-05-05 22:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114952
Bug ID: 114952
Summary: False positive -Wmaybe-uninitialized starting at -O3
in libbpf
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: kacper.slominski72 at gmail dot com
Target Milestone: ---
Created attachment 58105
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58105&action=edit
Preprocessed elf.c source code
When compiling libbpf (both as a part of the Linux kernel build, and as a
standalone library), starting with at least GCC 11.1, there are some false
positive -Wmaybe-uninitalized warnings generated when compiling with -O3.
In function ‘elf_close’,
inlined from ‘elf_close’ at elf.c:53:6,
inlined from ‘elf_find_func_offset_from_file’ at elf.c:384:2:
elf.c:57:9: warning: ‘elf_fd.elf’ may be used uninitialized
[-Wmaybe-uninitialized]
57 | elf_end(elf_fd->elf);
| ^~~~~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:377:23: note: ‘elf_fd.elf’ was declared here
377 | struct elf_fd elf_fd;
| ^~~~~~
In function ‘elf_close’,
inlined from ‘elf_close’ at elf.c:53:6,
inlined from ‘elf_find_func_offset_from_file’ at elf.c:384:2:
elf.c:58:9: warning: ‘elf_fd.fd’ may be used uninitialized
[-Wmaybe-uninitialized]
58 | close(elf_fd->fd);
| ^~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:377:23: note: ‘elf_fd.fd’ was declared here
377 | struct elf_fd elf_fd;
| ^~~~~~
From a quick look at the source code, as far as I can see, elf_fd is always
initialized at this point (looking at elf_find_func_offset_from_file), and I
think inlining has something to do with this (and hence it doesn't show up at
-O2).
Attached is a preprocessed copy of elf.c. To reproduce, run:
$ gcc preprocessed.c -c -O3 -Wmaybe-uninitialized
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114952] False positive -Wmaybe-uninitialized starting at -O3 in libbpf
2024-05-05 22:15 [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf kacper.slominski72 at gmail dot com
@ 2024-05-05 22:21 ` pinskia at gcc dot gnu.org
2024-05-07 12:43 ` sjames at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-05 22:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114952
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely GCC does not know errno is non-zero after the call to elf_open and
checking `fd < 0`.
Adding:
if (ret == 0) __builtin_unreachable();
After the assignment of `ret = -errono;` fixes the warning.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114952] False positive -Wmaybe-uninitialized starting at -O3 in libbpf
2024-05-05 22:15 [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf kacper.slominski72 at gmail dot com
2024-05-05 22:21 ` [Bug tree-optimization/114952] " pinskia at gcc dot gnu.org
@ 2024-05-07 12:43 ` sjames at gcc dot gnu.org
2024-05-07 18:45 ` pinskia at gcc dot gnu.org
2024-06-08 8:43 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-05-07 12:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114952
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jemarch at gcc dot gnu.org
--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
We hit this when poking at wiring up BPF support properly in Gentoo. It's a
pain because both default to building with -Werror=maybe-uninitialized.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114952] False positive -Wmaybe-uninitialized starting at -O3 in libbpf
2024-05-05 22:15 [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf kacper.slominski72 at gmail dot com
2024-05-05 22:21 ` [Bug tree-optimization/114952] " pinskia at gcc dot gnu.org
2024-05-07 12:43 ` sjames at gcc dot gnu.org
@ 2024-05-07 18:45 ` pinskia at gcc dot gnu.org
2024-06-08 8:43 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-07 18:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114952
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I don't think this is a `False positive` exactly because GCC has no
knowledge that errno could be non-zero after a fail call to open.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114952] False positive -Wmaybe-uninitialized starting at -O3 in libbpf
2024-05-05 22:15 [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf kacper.slominski72 at gmail dot com
` (2 preceding siblings ...)
2024-05-07 18:45 ` pinskia at gcc dot gnu.org
@ 2024-06-08 8:43 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2024-06-08 8:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114952
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Possibly duplicate of bug 61846
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-08 8:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-05 22:15 [Bug c/114952] New: False positive -Wmaybe-uninitialized starting at -O3 in libbpf kacper.slominski72 at gmail dot com
2024-05-05 22:21 ` [Bug tree-optimization/114952] " pinskia at gcc dot gnu.org
2024-05-07 12:43 ` sjames at gcc dot gnu.org
2024-05-07 18:45 ` pinskia at gcc dot gnu.org
2024-06-08 8:43 ` manu 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).