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
main.c (1.23 KB)
chk.c (643 Bytes)