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