Bug 48862 - A Bug When Assembler Instructions with C Expression Operands in arm-elf-gcc 4.5
Summary: A Bug When Assembler Instructions with C Expression Operands in arm-elf-gcc 4.5
Status: RESOLVED DUPLICATE of bug 48863
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-04 06:37 UTC by Dillon
Modified: 2011-05-10 00:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dillon 2011-05-04 06:37:05 UTC
Assembler instructions with C expression operands, gcc(arm-elf-gcc) compiler may produce the wrong instrctions sequence with option -O2.There is a case only for test below.

In the case, the second instruction ("mov r0, r1") destroyed r0 without saving, but r0 kept the value of variable fd and the variable should be passed to "swi   0". I think it's a serious bug, gcc compiler does not consider that "unsigned  high = length / 23" may produce a function call.
================================case  start ================================
static __inline__ int __syscall_test(int fd, unsigned pad, unsigned long high, unsigned low)
{
     unsigned int __sys_result;
    {
        register int _a1 __asm__ ("r0") = fd;
        register int _a2 __asm__ ("r1") = pad;
        register int _a3 __asm__ ("r2") = high;
        register int _a4 __asm__ ("r3") = low;

        __asm__ __volatile__ ("swi  0"
                : "=r"(_a1)
                : "0"(_a1),"r"(_a3), "r"(_a4));
        __sys_result = _a1;
    }
    return __sys_result;
}




int f_test(int fd, long long length)
{
    unsigned low = length & 0xffffffff;

    unsigned  high = length / 23;

    return __syscall_test(fd, 0, high, low);
}

---------------------- compile result --------------
    .file   "case.c"
    .global __divdi3
    .text
    .align  2
    .global f_test
    .type   f_test, %function
f_test:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 0
    stmfd   sp!, {r4, lr}
    mov r0, r1
    mov r4, r1
    mov r3, #0
    mov r1, r2
    mov r2, #23
    bl  __divdi3
    mov r3, r4
    mov r2, r0
@ 10 "case.c" 1
    swi 0
@ 0 "" 2
    ldmfd   sp!, {r4, pc}
    .size   f_test, .-f_test
    .ident  "GCC: (GNU) 4.5.2"
==================== end ===============================
Comment 1 Thadeu Lima de Souza Cascardo 2011-05-09 18:31:50 UTC
This is a duplicate of 48863. Reporter sent the same bug three times. Please, mark as resolved/duplicate.
Comment 2 Dillon 2011-05-10 00:41:40 UTC
This is a duplicate of 48863

*** This bug has been marked as a duplicate of bug 48863 ***