[PATCH C] PR32207

H.J. Lu hjl.tools@gmail.com
Tue Apr 27 13:51:00 GMT 2010


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.



More information about the Gcc-patches mailing list