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

            Bug ID: 116426
           Summary: [13/14 Regression] bogus -Wnull-dereference warning
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 58959
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58959&action=edit
test case output-preprocessed.c

In the attached program 'output-preprocessed.c', GCC 14.2.0 and 13.3.0 produce
a warning:

$ gcc -Wnull-dereference -O -S output-preprocessed.c
output-preprocessed.c: In function ‘make_room_for’:
output-preprocessed.c:116:40: warning: potential null pointer dereference
[-Wnull-dereference]
  116 |       output_file = output_diversion->u.file;
      |                     ~~~~~~~~~~~~~~~~~~~^~~~~

Whereas GCC 12.4.0 produces no warning.

The warning is not justified, because
* Due to line 114, output_diversion and selected_diversion have the same value.
* If the condition in line 74 evaluated to true, the statements in lines
76..112 were executed. The last of these statements dereferences
selected_diversion; therefore selected_diversion cannot be NULL in this case.
By the previous remark, output_diversion cannot be NULL either.
* If the condition in line 74 evaluated to false, the statements in lines
76..112 were skipped. Since in the condition, output_diversion was
dereferenced, output_diversion cannot be NULL in this case.

Reply via email to