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

            Bug ID: 109856
           Summary: -Wnull-dereference false positive in Emacs itree.c
                    (regression from GCC 12)
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 55083
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55083&action=edit
compile with 'gcc -O2 -Wnull-dereference' to reproduce the bug

This is GCC 13.1.1 20230426 (Red Hat 13.1.1-1) on x86-64, and this is a
regression from GCC (Ubuntu 12.2.0-17ubuntu1) 12.2.0. I ran into this problem
when compiling GNU Emacs src/itree.c. This is a stripped-down version of the
original problem (the code makes no sense by itself).

Compile the attached program with:

gcc -O2 -S -Wnull-dereference v2.i

The output is:

v2.i: In function ‘itree_remove_fix’:
v2.i:28:16: warning: potential null pointer dereference [-Wnull-dereference]
   28 |       if (other->left)
      |           ~~~~~^~~~~~

First, the diagnostic is confusing, because it highlights an entire expression,
which cannot itself be a null pointer dereference.

Second, there's no possible null pointer dereference here. The previous two
lines are "if (!other)__builtin_unreachable ();" so OTHER itself cannot be
null.

Reply via email to