This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Fix a -Waddress regression (PR c/69768)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 11 Feb 2016 20:54:27 +0100
- Subject: Re: [C/C++ PATCH] Fix a -Waddress regression (PR c/69768)
- Authentication-results: sourceware.org; auth=none
- References: <20160211162526 dot GD3017 at tucnak dot redhat dot com> <56BCD949 dot 9010300 at redhat dot com> <20160211194424 dot GF3017 at tucnak dot redhat dot com>
On Thu, Feb 11, 2016 at 08:44:24PM +0100, Jakub Jelinek wrote:
> Hi!
>
> On Thu, Feb 11, 2016 at 01:56:09PM -0500, Jason Merrill wrote:
> > On 02/11/2016 11:25 AM, Jakub Jelinek wrote:
> > >+ && !integer_zerop (tree_strip_nop_conversions (op1)))
> >
> > Maybe cp_fold rather than tree_strip_nop_conversions?
>
> Is it safe to call cp_fully_fold (typeck.c only calls it by that name,
> not cp_fold) on perhaps type or value dependent argument?
> E.g. on
> template <int N>
> int
> bar ()
> {
> return "foo1" != (void *) N
> && "foo2" != (const char *) ((void *) N)
> && "foo3" != (const char *) ((void *) (N - N))
> && "foo4" != (const char *) ((void *) (&e - &e))
> && "foo5" != "foo6";
> }
> op1 is NON_DEPENDENT_EXPR. If yes, here is an alternative (that has the same
> behavior on the testcase as 5.x does). The C FE didn't use to fold it, so
> I'm preserving its behavior.
>
> 2016-02-11 Jakub Jelinek <jakub@redhat.com>
>
> PR c/69768
> * c-typeck.c (parser_build_binary_op): Strip nops from integer_zerop
> arguments for -Waddress warning.
>
> * typeck.c (cp_build_binary_op): cp_fully_fold integer_zerop
> arguments for -Waddress warning. Fix up formatting.
>
> * c-c++-common/Waddress-1.c: New test.
>
> --- gcc/c/c-typeck.c.jj 2016-02-11 20:28:51.316491659 +0100
> +++ gcc/c/c-typeck.c 2016-02-11 20:29:50.778672554 +0100
> @@ -3597,8 +3597,10 @@ parser_build_binary_op (location_t locat
> of testing for equality or inequality of a string literal with NULL. */
> if (code == EQ_EXPR || code == NE_EXPR)
> {
> - if ((code1 == STRING_CST && !integer_zerop (arg2.value))
> - || (code2 == STRING_CST && !integer_zerop (arg1.value)))
> + if ((code1 == STRING_CST
> + && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
> + || (code2 == STRING_CST
> + && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
> warning_at (location, OPT_Waddress,
> "comparison with string literal results in unspecified behavior");
> }
The C part looks ok to me.
Marek