This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH C] PR32207
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Shujing Zhao <pearly dot zhao at oracle dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>, Paolo Carlini <paolo dot carlini at oracle dot com>
- Date: Tue, 27 Apr 2010 06:16:06 -0700
- Subject: Re: [PATCH C] PR32207
- References: <4BD152D4.3000901@oracle.com>
On Fri, Apr 23, 2010 at 12:57 AM, Shujing Zhao <pearly.zhao@oracle.com> wrote:
> Hi,
> This patch is to fix pr32207. For the test case:
>
> extern void z();
> void f() { if ( z ) z(); }
> void g() { if ( z != 0 ) z(); }
> void h() { if ( z != (void*)0 ) z(); }
>
> The warning are:
> t.c: In function ‘f’:
> t.c:2:17: warning: the address of ‘z’ will always evaluate as ‘true’
> t.c: In function ‘g’:
> t.c:3:19: warning: the comparison will always evaluate as 'true' for the
> address of ‘z’ will never be NULL
> t.c: In function ‘h’:
> t.c:4:19: warning: the comparison will always evaluate as 'true' for the
> address of ‘z’ will never be NULL
>
> The warning message for `z!=0` and `z!=(void*)0` is changed from "the
> address of ‘z’ will never be NULL" to "the comparison will always evaluate
> as 'true' for the address of ‘z’ will never be NULL". Because for the users,
> the second and the third conditional expression are comparison expression,
> and the warning message location is focus on the operator "!=" or "==".
> Consider the user end and the location, I choose to add "the comparison ..."
> to the warning message. Is it ok?
>
> Some test cases are adjusted expected warning.
> Test on i686-pc-linux-gnu without regression.
>
> Ok for trunk?
>
> Thanks
> Pearly
>
> /gcc
> 2010-04-23 ?Shujing Zhao ?<pearly.zhao@oracle.com>
>
> ? ? ? ?PR c/32207
> ? ? ? ?* c-typeck.c (build_binary_op): Move forward check for comparison
> ? ? ? ?pointer with null pointer constant and adjust the diagnostic message.
>
> /gcc/testcase
> 2010-04-23 ?Shujing Zhao ?<pearly.zhao@oracle.com>
>
> ? ? ? ?* gcc.dg/pr32207.c: New test.
> ? ? ? ?* gcc.dg/misc-column.c: Adjust expected warning.
> ? ? ? ?* gcc.dg/Walways-true-1.c: Likewise.
> ? ? ? ?* gcc.dg/Walways-true-2.c: Likewise.
> ? ? ? ?* gcc.dg/warn-addr-cmp.c: Likewise.
>
>
>
This may have caused:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43910
--
H.J.