[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bogus -Wnull-dereference warning
From: |
Bruno Haible |
Subject: |
bogus -Wnull-dereference warning |
Date: |
Tue, 20 Aug 2024 03:32:12 +0200 |
Paul Eggert wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-08/msg00088.html>:
> Also m4 still has a bogus -Wnull-dereference diagnostic, unrelated to the
> verror.h changes, that somebody needs to investigate when they find the time.
The warning can be seen with gcc 14.1 or 14.2. How to reproduce:
$ ./configure --enable-gcc-warnings
$ make V=1
The result with gcc 14.x:
gcc -I../lib -I../lib -fanalyzer -fstrict-flex-arrays -Wall
-Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time
-Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches
-Wduplicated-cond -Wextra -Wformat-signedness -Wflex-array-member-not-at-end
-Winit-self -Winline -Winvalid-pch -Wlogical-op -Wmissing-declarations
-Wmissing-include-dirs -Wmissing-prototypes -Wmissing-variable-declarations
-Wnested-externs -Wnull-dereference -Wold-style-definition -Wopenmp-simd
-Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstack-protector
-Wstrict-flex-arrays -Wstrict-overflow -Wstrict-prototypes
-Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format
-Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn
-Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types
-Wsync-nand -Wtrampolines -Wuninitialized -Wunknown-pragmas
-Wunsafe-loop-optimizations -Wunused-macros -Wvariadic-macros
-Wvector-operation-performance -Wwrite-strings -Warray-bounds=2
-Wattribute-alias=2 -Wbidi-chars=any,ucn -Wformat-overflow=2 -Wformat=2
-Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2
-Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031
-Wno-analyzer-malloc-leak -g -O2 -c output.c
output.c: In function 'make_room_for':
output.c:491:40: warning: potential null pointer dereference
[-Wnull-dereference]
491 | output_file = output_diversion->u.file;
| ~~~~~~~~~~~~~~~~~~~^~~~~
I submitted this as a GCC bug:
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116426>
A consequence of this warning is that with --enable-gcc-warnings, all
gcc versions from 11 to 14 produce warnings on glibc systems:
gcc 11.5.0:
error: function might be candidate for attribute 'cold'
gcc 12.4.0:
error: function might be candidate for attribute 'cold'
gcc 13.3.0:
error: function might be candidate for attribute 'cold'
error: potential null pointer dereference
gcc 14.2.0:
error: potential null pointer dereference
Reminder about the other warning:
CC macro.o
In function 'call_macro.part.0':
../../../src/macro.c:272:1: error: function might be candidate for attribute
'cold' [-Werror=suggest-attribute=cold]
272 | call_macro (symbol *sym, int argc, token_data **argv,
| ^~~~~~~~~~
Which is a bogus warning as well. I cannot find it reported in the GCC bug
tracker. But at least, it's fixed in GCC 14.
What can we do about it? I don't find it adequate to change the logic of
the function 'make_room_for'. Usually we
- disable a warning option completely if it generates nearly only false
alarms,
- disable a warning option for a certain compilation unit, to work around
specific false alarms.
Here we are in the second case. Here's a proposed patch.
0001-maint-Avoid-a-gcc-14-warning-that-makes-enable-gcc-w.patch
Description: Text Data
- bogus -Wnull-dereference warning,
Bruno Haible <=