[llvm-commits] [llvm] r61297 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyLibCalls.cpp test/Transforms/SimplifyLibCalls/2008-12-20-StrcmpMemcmp.ll

Dale Johannesen dalej at apple.com
Mon Dec 22 17:27:56 PST 2008


On Dec 22, 2008, at 4:56 PMPST, Chris Lattner wrote:

> On Dec 22, 2008, at 7:15 AM, Török Edwin wrote:
>>>>
>> So is it a bug in MemCmp optimization?
>
> hi Edwin,
>
> This is a really important question that I don't know the answer to.
> My understanding is that memcmp only touches the bytes necessary to
> make a decision: it is not allowed to touch the full size if
> unneeded.  However, I don't really *know* that, and nothing I find
> online in a quick scan comes up with an obvious answer.

The standard defines memcmp functionality as:

The memcmp function compares the first n characters of the object  
pointed to be s1 to the first n characters of the object pointed to by  
s2.

It doesn't say anything about comparing fewer than n characters, let  
alone requiring this under some circumstances.  So I don't think it is  
required, although an implementation may compare fewer under the as-if  
rule.  It does say that accessing one of its arguments  beyond the end  
of an object is undefined behavior; this would presumably always be  
the case if we're getting a page fault, but that's a user error.

But legalese aside, IMO the current darwin implementation is much  
friendlier to users, and should be left alone.  I'm also reasonably  
sure it will break some things if we change it.






More information about the llvm-commits mailing list