[cfe-dev] memcpy behaviour when destination unknown
rajesh viswabramana
viswabramana.rajesh at gmail.com
Mon May 21 23:28:02 PDT 2012
Hi *,
General behaviour is __builtin_memcpy_chk function should be called for all
memcpy calls, to check object size(destination).
I have noticed in clang for memcpy function when destination buffer *unknown
* than, memcpy calls optimized to memcpy.
Where as if destination has *known* pointer at compilation time than it
will call builtin_memcpy_chk which in turn calls memcpy.
extern int l1;
test_func ()
{
char buf1[10], buf2[10];
........
memcpy(buf1, s3, l1); // Destination is known(buf1), length is not
known calls memcpy_chk
r = l1 == 1 ? buf1 : buf2;
memcpy(r, s3, l1 + 1); // Destination is not known(might be buf1 or
buf2), so optimizing call to memcpy
......
}
To compare the behaviour with gcc, for all above memcpy calls memcpy_chk
function called.
I have attached codes of sample program (test program, as well library call
impl).
When sample code run on CLANG, Its abort. where as in GCC it run
sucessfully.
*Any info why the optimization behaviour in clang is differ from gcc.*
Regards,
Rajesh
*further info about object size checking in gcc.*
*http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html*<http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120522/c4b7f5ae/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 1261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120522/c4b7f5ae/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chk.c
Type: text/x-csrc
Size: 643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120522/c4b7f5ae/attachment-0001.c>
More information about the cfe-dev
mailing list