<div>Hi *,</div>
<div> </div>
<div>General behaviour is __builtin_memcpy_chk function should be called for all memcpy calls, to check object size(destination).</div>
<div> </div>
<div>I have noticed in clang for memcpy function when destination buffer <u>unknown</u> than, memcpy calls optimized to memcpy.</div>
<div>Where as if destination has <u>known</u> pointer at compilation time than it will call builtin_memcpy_chk which in turn calls memcpy.</div>
<div> </div>
<div>extern int l1;</div>
<div> </div>
<div>test_func ()</div>
<div>{</div>
<div>    char buf1[10], buf2[10]; </div>
<div>             ........</div>
<div>    memcpy(buf1, s3, l1); // Destination is known(buf1), length is not known calls memcpy_chk</div>
<div> </div>
<div>    r = l1 == 1 ? buf1 : buf2;<br>    memcpy(r, s3, l1 + 1); // Destination is not known(might be buf1 or buf2), so optimizing call to memcpy</div>
<div>              ......</div>
<div>}</div>
<div><br>To compare the behaviour with gcc, for all above memcpy calls memcpy_chk function called.</div>
<div> </div>
<div>I have attached codes of sample program (test program, as well library call impl).</div>
<div> </div>
<div>When sample code run on CLANG, Its abort. where as in GCC it run sucessfully.</div>
<div> </div>
<div><strong>Any info why the optimization behaviour in clang is differ from gcc.</strong></div>
<div> </div>
<div> </div>
<div>Regards,</div>
<div>Rajesh</div>
<div> </div>
<div> </div>
<div><em>further info about object size checking in gcc.</em></div>
<div><a href="http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html" target="_blank"><em>http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html</em></a></div>
<div> </div>
<div> </div>
<div> </div>