Bug 770502 - __builtin_memcpy code generation problem
Summary: __builtin_memcpy code generation problem
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 16
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-12-27 06:27 UTC by m0459129523
Modified: 2011-12-27 12:34 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-12-27 08:50:38 UTC
Type: ---


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 51683 0 None None None Never

Description m0459129523 2011-12-27 06:27:23 UTC
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:

Comment 1 Jakub Jelinek 2011-12-27 08:50:38 UTC
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.

Comment 2 Jakub Jelinek 2011-12-27 12:34:58 UTC
ccp optimizes away even memcpy calls that don't trigger undefined behavior (just implementation defined behavior).  Tracking that as PR51683 upstream.


Note You need to log in before you can comment on or make changes to this bug.