[Bug target/48861] New: A Bug When Assembler Instructions with C Expression Operands in arm-elf-gcc 4.5

cascardo at holoscopio dot com gcc-bugzilla@gcc.gnu.org
Mon May 9 18:42:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48861

           Summary: A Bug When Assembler Instructions with C Expression
                    Operands in arm-elf-gcc 4.5
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: shangyunhai@gmail.com
                CC: cascardo@holoscopio.com


Thadeu Lima de Souza Cascardo <cascardo at holoscopio dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cascardo at holoscopio dot
                   |                            |com

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 from Thadeu Lima de Souza Cascardo <cascardo at holoscopio dot com> 2011-05-09 18:32:20 UTC ---
This is a duplicate of 48863. Reporter sent the same bug three times. Please,
mark as resolved/duplicate.



More information about the Gcc-bugs mailing list