This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: nonnull, -Wnonnull, and do/while
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>, Mark Wielaard <mjw at redhat dot com>
- Cc: stefan dot sobernig at wu dot ac dot at, gcc at gcc dot gnu dot org
- Date: Tue, 16 Feb 2016 11:11:21 +0100
- Subject: Re: nonnull, -Wnonnull, and do/while
- Authentication-results: sourceware.org; auth=none
- References: <56C2EF2C dot 4050508 at thinkersfoot dot net> <20160216100438 dot GR3163 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Feb 16, 2016 at 11:04:38AM +0100, Marek Polacek wrote:
> On Tue, Feb 16, 2016 at 10:43:08AM +0100, Stefan Sobernig wrote:
> > Under a recent gcc 6 [*], we run into -Wnonnull warnings using the
> > nonnull attribute:
>
> Yes, this warning has been enhanced for GCC 6.
>
> > test.c: In function 'f':
> > test.c:16:14: warning: nonnull argument 's' compared to NULL [-Wnonnull]
> > } while (s != NULL);
> >
> > Am I missing sth.? Is this a false positive?
>
> Well, it's just that "s" has the nonnull attribute so the compiler thinks it
> should never be null in which case comparing it to null should be redundant.
> Doesn't seem like a false positive to me, but maybe someone else feels
> otherwise.
The nonnull attribute should be solely about the value that is passed to the
function, it doesn't tell anything about the value of the argument after
it is changed. So IMHO this warning change should be reverted and instead
we should warn somewhere soon after going into SSA, only when
the SSA_NAME_IS_DEFAULT_DEF of the PARM_DECL which has non-NULL attribute
is compared to NULL.
Jakub