[Bug c/27308] New: Compiler generates incorrect code when calling a function with the result of an inline function as parameter

Eric dot Doenges at betty-tv dot com gcc-bugzilla@gcc.gnu.org
Tue Apr 25 12:36:00 GMT 2006


Consider the following code:


typedef unsigned int  UINT32;
typedef unsigned char BOOL;
#define __SWI_BIOS_ContainerUsage  1234

#define __swicall1(type,name,type1,arg1)                         \
  static inline type name(type1 arg1) {                               \
    register long __r0 __asm__ ("r0") = (long)arg1;              \
    register long __res __asm__ ("r0");                                 \
    __asm__ __volatile__ ("swi\t%2\n\t"                               \
                          : "=r" (__res)                                       
    \
                          : "0" (__r0), "i" (__SWI_##name)                \
                          : "r1", "r2", "r3", "ip", "lr", "cc",                
\
                            "memory");                                         
 \
    return((type)__res);                                                      
\
  }
__swicall1(UINT32,BIOS_ContainerUsage,BOOL,verbose);
int sprintf(char *p, const char *frmt, ...);

void testme(char *tmp)
{
  sprintf(tmp, " %d%% Containers\n", BIOS_ContainerUsage(1));
  sprintf(tmp, " %d%% Containers\n", 2 * BIOS_ContainerUsage(1));
}

For the first call to sprintf, gcc generates the following assembler code:

        mov     r0, #1
        swi     #1234

        ldr     r5, .L3
        mov     r0, r4
        mov     r1, r5
        mov     r2, r4
        bl      sprintf

This is clearly wrong, since r2 should hold the result of the swi (which is
returned in r0). For the
second call to sprintf, gcc generates correct code:

        mov     r0, #1
        swi     #1234

        mov     r2, r0, asl #1
        mov     r1, r5
        mov     r0, r4
        ldmfd   sp!, {r4, r5, lr}
        b       sprintf


-- 
           Summary: Compiler generates incorrect code when calling a
                    function with the result of an inline function as
                    parameter
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Eric dot Doenges at betty-tv dot com
  GCC host triplet: powerpc-apple-darwin8.5.0
GCC target triplet: arm-elf-unknown


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



More information about the Gcc-bugs mailing list