Hide Forgot
Description of problem: gcc on Fedora 16 fails to generate "memcpy" code when compiling a function calling a static inline function containing __builtin_memcpy with an immediate value as the destination argument. Version-Release number of selected component (if applicable): gcc-4.6.2-1.fc16.x86_64 How reproducible: always Steps to Reproduce: 1. compile the following function with "gcc -O -S" ---- static inline void *cp(void* d,void* s,int l) { return __builtin_memcpy(d,s,l); } void main(void *p) { cp(0,p,256); } ---- When we change to "cp(p,0,256)", it generates expected code. Actual results: ... main: .LFB1: .cfi_startproc rep ret .cfi_endproc .LFE1: ... Expected results: ... main: .LFB1: .cfi_startproc movq %rdi, %rdx movl $0, %esi movl $256, %eax (code for memcpy) ... Additional info:
memcpy (0, p, 256); is undefined behavior at runtime, therefore gcc is free to insert there any kind of code it likes. The parameters to main are not valid C either.
ccp optimizes away even memcpy calls that don't trigger undefined behavior (just implementation defined behavior). Tracking that as PR51683 upstream.