I would like to compare the GCC builtin function memcpy
versus the one one from libc. However, all iterations of -fno-builtin
or -fno-builtin-memcpy
seem to be ignored.
//g++ -O3 foo.cpp -S or
//g++ -O3 -fno-builtin foo.cpp -S
#include <string.h>
int main() {
volatile int n = 1000;
//int n = 1000;
float *x = new float[1000];
float *y = new float[1000];
memcpy(y,x,sizeof(float)*n);
//__builtin_memcpy(y,x,sizeof(float)*n);
}
What I have found is that if n
in the source code above is not volatile then it inlines built-in code. However, when n
is made volatile then it calls the function __memcpy_chk
which is a version of memcpy with buffer overflow checking. If n
is volatile and I instead call __builtin_memcpy
then it calls memcpy
.
So my conclusion so far is that the builtin code is only generated if n
is known at compile time and that -fno-builtin
is useless. I'm using GCC 4.8.2.
Is -fno-builtin
obsolete? Is there a way to make GCC call memcpy
from the C library even when n
is known at compile time?