https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109131
Bug ID: 109131
Summary: -Wanalyzer-deref-before-check false positive seen in
git's builtin/show-ref.c
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 54664
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54664&action=edit
Reduced reproducer
Trunk erroneously emits:
deref-before-check-git-show-ref.c: In function 'cmd_show_ref':
deref-before-check-git-show-ref.c:39:8: warning: check of 'argv' for NULL after
already dereferencing it [-Wanalyzer-deref-before-check]
39 | if (!pattern)
| ^
'cmd_show_ref': events 1-8
|
| 31 | if (exclude_arg)
| | ^
| | |
| | (1) following 'false' branch...
|......
| 34 | pattern = argv;
| | ~~~~~~~~~~~~~~
| | |
| | (2) ...to here
| 35 | if (!*pattern)
| | ~ ~~~~~~~~
| | | |
| | | (3) pointer 'argv' is dereferenced here
| | (4) following 'false' branch...
|......
| 38 | if (verify) {
| | ~~~~~~~
| | ||
| | |(5) ...to here
| | (6) following 'true' branch...
| 39 | if (!pattern)
| | ~~~~~~~~~
| | ||
| | |(7) ...to here
| | (8) pointer 'argv' is checked for NULL here but it was
already dereferenced at (3)
|
on the attached.
https://godbolt.org/z/oW4hvqx7K