[C++ PATCH] Fix delayed folding -Wnonnull regression (PR c++/86210)
Jason Merrill
jason@redhat.com
Wed Jun 20 15:34:00 GMT 2018
On Wed, Jun 20, 2018 at 10:32 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> This patch fixes a regression caused by C++ delayed folding, when
> check_nonnull_arg is called, the arguments aren't folded yet and so unlike
> GCC 4.8 and earlier we don't report -Wnonnull warning unless the argument is
> literal NULL without any folding.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk? Is this something we should backport (at least to 8.2) or not?
OK for trunk and 8.2.
> 2018-06-20 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/86210
> * c-common.c (check_nonnull_arg): Use fold_for_warn. Adjust obsolete
> comment.
>
> * g++.dg/warn/Wnonnull4.C: New test.
>
> --- gcc/c-family/c-common.c.jj 2018-06-20 08:15:20.697849713 +0200
> +++ gcc/c-family/c-common.c 2018-06-20 12:14:27.828098317 +0200
> @@ -5404,10 +5404,8 @@ check_nonnull_arg (void *ctx, tree param
> if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
> return;
>
> - /* When not optimizing diagnose the simple cases of null arguments.
> - When optimization is enabled defer the checking until expansion
> - when more cases can be detected. */
> - if (integer_zerop (param))
> + /* Diagnose the simple cases of null arguments. */
> + if (integer_zerop (fold_for_warn (param)))
> {
> warning_at (pctx->loc, OPT_Wnonnull, "null argument where non-null "
> "required (argument %lu)", (unsigned long) param_num);
> --- gcc/testsuite/g++.dg/warn/Wnonnull4.C.jj 2018-06-20 12:21:50.424552232 +0200
> +++ gcc/testsuite/g++.dg/warn/Wnonnull4.C 2018-06-20 12:20:47.356487553 +0200
> @@ -0,0 +1,21 @@
> +// PR c++/86210
> +// { dg-do compile }
> +// { dg-options "-Wnonnull" }
> +
> +void *declared_not_defined (void *p) __attribute__((nonnull));
> +
> +inline void *declared_and_defined (void *p) __attribute__((nonnull));
> +
> +int
> +main ()
> +{
> + int *const p = 0;
> + declared_not_defined (p); // { dg-warning "null argument where non-null required" }
> + declared_and_defined (p); // { dg-warning "null argument where non-null required" }
> +}
> +
> +void *
> +declared_and_defined (void *p)
> +{
> + return p;
> +}
>
> Jakub
More information about the Gcc-patches
mailing list