This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH C] PR32207


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]