public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109239] New: -Wanalyzer-deref-before-check seen on Linux kernel due to inlining with -fno-delete-null-pointer-checks
@ 2023-03-21 19:14 dmalcolm at gcc dot gnu.org
  2023-03-22 12:42 ` [Bug analyzer/109239] " cvs-commit at gcc dot gnu.org
  2023-03-22 12:48 ` dmalcolm at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-21 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109239
           Summary: -Wanalyzer-deref-before-check seen on Linux kernel due
                    to inlining with -fno-delete-null-pointer-checks
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 54724
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54724&action=edit
Reproducer

I'm seeing various -Wanalyzer-deref-before-check false positives on the Linux
kernel; hopefully the attached is a representative reproducer for all of them.

When compiled with:
  -fanalyzer -fno-delete-null-pointer-checks -O2
trunk falsely complains:

In function 'bus_get',
    inlined from 'bus_remove_file' at <source>:122:7,
    inlined from 'remove_probe_files' at <source>:139:3,
    inlined from 'bus_unregister' at <source>:150:3:
<source>:105:6: warning: check of 'bus' for NULL after already dereferencing it
[-Wanalyzer-deref-before-check]
  105 |   if (bus) {
      |      ^
  'bus_unregister': events 1-2
    |
    |  147 |   if (bus->dev_root)
    |      |       ~~~^~~~~~~~~~
    |      |          |
    |      |          (1) pointer 'bus' is dereferenced here
    |......
    |  150 |   remove_probe_files(bus);
    |      |   ~       
    |      |   |
    |      |   (2) inlined call to 'remove_probe_files' from 'bus_unregister'
    |
    +--> 'remove_probe_files': event 3
           |
           |  139 |   bus_remove_file(bus, &bus_attr_drivers_autoprobe);
           |      |   ^
           |      |   |
           |      |   (3) inlined call to 'bus_remove_file' from
'remove_probe_files'
           |
           +--> 'bus_remove_file': event 4
                  |
                  |  122 |   if (bus_get(bus)) {
                  |      |       ^
                  |      |       |
                  |      |       (4) inlined call to 'bus_get' from
'bus_remove_file'
                  |
                  +--> 'bus_get': event 5
                         |
                         |  105 |   if (bus) {
                         |      |      ^
                         |      |      |
                         |      |      (5) pointer 'bus' is checked for NULL
here but it was already dereferenced at (1)
                         |
Compiler returned: 0

Trunk: https://godbolt.org/z/ErKf6fz86

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-22 12:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 19:14 [Bug analyzer/109239] New: -Wanalyzer-deref-before-check seen on Linux kernel due to inlining with -fno-delete-null-pointer-checks dmalcolm at gcc dot gnu.org
2023-03-22 12:42 ` [Bug analyzer/109239] " cvs-commit at gcc dot gnu.org
2023-03-22 12:48 ` dmalcolm 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).