This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fold strstr (s, t) eq/ne s to strcmp (s, t) eq/ne 0 if strlen (t) is known
- From: Bernd Schmidt <bschmidt at redhat dot com>
- To: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, gcc Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Mon, 5 Dec 2016 19:08:32 +0100
- Subject: Re: Fold strstr (s, t) eq/ne s to strcmp (s, t) eq/ne 0 if strlen (t) is known
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjMn2AWAP9tu+qknHnPEhOAh7Au7Ke4YFGcJeSkfJ=Ts=Zg@mail.gmail.com>
On 12/05/2016 07:02 PM, Prathamesh Kulkarni wrote:
This patch folds strstr (s, t) eq/ne s to strcmp (s, t) eq/ne 0 if
strlen (t) is known.
That's not the same thing, is it?
s = "hello world", t = "hello":
strstr (s, t) == s, but not strcmp (s, t) == 0.
I think you'd want memcmp (s, t, strlen (t)) == 0.
Bernd