https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96894
Bug ID: 96894
Summary: Analyzer assumes pointer is NULL, even if pointer was
tested to be non-null before
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
Created attachment 49174
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49174&action=edit
fibheap.c, preprocessed version from gdb/binutils master
Using gcc-11 (SUSE Linux) 11.0.0 20200901 (experimental) [revision
b1850c617b14eedaf60b358f3b7d4707cff73b8a].
Invoked like this:
...
$ gcc-11 fibheap.c -fanalyzer -S
...
We have:
...
fibheap.c: In function ‘fibnode_remove’:
fibheap.c:3122:42: warning: dereference of NULL ‘*(node).parent’ [CWE-690]
[-Wanalyzer-null-dereference]
3122 | && node->parent->child == node)
| ~~~~~~~~~~~~^~~~~~~
...
Looking at the source code, we have:
...
3118 if (node->parent !=
3119
3120 ((void *)0)
3121
3122 && node->parent->child == node)
3123 node->parent->child = ret;
...
So, just before dereferencing node->parent, we check that it's non-null, so the
warning that node->parent is dereferenced while it's null makes no sense.