This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to create builtin strncmp
- To: rth at cygnus dot com
- Subject: Re: Patch to create builtin strncmp
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Wed, 22 Mar 2000 23:48:39 -0500 (EST)
- Cc: egcs-patches at egcs dot cygnus dot com
> From: Richard Henderson <rth@cygnus.com>
>
> On Wed, Mar 22, 2000 at 07:10:55PM -0500, Kaveh R. Ghazi wrote:
> > Er, no you don't need to know the lengths of both strings. You only
> > need to know the length of *one* of them. That's how the regular
> > builtin strcmp works today.
>
> Then expand_builtin_strcmp is wrong. I don't see any wording
> in md.texi that cmpstrsi must compare byte-wise and must not
> read past the first mismatched byte.
>
> Consider non-constant "hi\0" abutting a page boundary with
> an unmapped page following. Compare that with the constant
> "hi there". Recall that memcmp _is_ allowed to read N bytes,
> and there's nothing to stop us reading 4 bytes from the first
> string and faulting.
>
> You may not even get a fault with the current compiler, but
> that doesn't mean the code is correct.
> r~
Okay, thanks for the explanation. I guess then we have to either
disable the existing builtin strcmp, or add language to md.texi about
cmpstrsi to restrict it for the bounary conditions you listed above.
(In which case my patch becomes valid.)
I see a cmpstr* in c4x.md, i370.md, i386.md and pj.md. In these cases
does it meet the conditions you listed?
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions