This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA][PR 16361] Add warnings for NULL pointer dereferences and such
- From: Ian Lance Taylor <iant at google dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 27 Jan 2014 13:02:46 -0800
- Subject: Re: [RFA][PR 16361] Add warnings for NULL pointer dereferences and such
- Authentication-results: sourceware.org; auth=none
- References: <52E6AED6 dot 6090704 at redhat dot com>
On Mon, Jan 27, 2014 at 11:09 AM, Jeff Law <law@redhat.com> wrote:
>
> First, as is often the case, this warning is not going to catch everything.
> Dead code elimination, unreachable code elimination, etc can/will remove
> NULL pointer dereferences and if that happens we don't get a warning. It
> also will not catch cases where a NULL value flows out of a PHI into uses in
> other blocks where it is then dereferenced or otherwise used erroneously.
>
> -Wnull-dereference will warn for NULL pointer dereferences. Both those
> which appear explicitly in the IL and those which occur if NULL value flows
> from a PHI to a dereference in the same block as the PHI.
>
> -Wnull-attribute will warn if NULL is used as an argument to a function call
> where the callee's attributes have declared the argument must be non-NULL.
> Similarly for NULL as a return value when the current function has an
> attribute declaring the function can never return NULL. Similarly for NULL
> values flowing from a PHI into an argument/return in the same block as the
> PHI.
>
> We utilize the analysis done for the erroneous-paths optimization. The
> optimizations and warnings can be enabled/disabled independently. The
> warnings are not enabled by -Wall.
I want to raise the usual caution about warnings that are based on
optimizations. This leads to different results in different GCC
releases, which makes it hard for other packages to use -Werror.
However, I admit that this is less of a concern when the warning is
not part of -Wall.
Ian