public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/27308]  New: Compiler generates incorrect code when calling a function with the result of an inline function as parameter
@ 2006-04-25 12:36 Eric dot Doenges at betty-tv dot com
  2006-04-25 12:38 ` [Bug c/27308] " rguenth at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Eric dot Doenges at betty-tv dot com @ 2006-04-25 12:36 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <bug-27308-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2012-01-10 15:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-25 12:36 [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
2006-04-25 12:38 ` [Bug c/27308] " rguenth at gcc dot gnu dot org
2006-04-25 12:49 ` rguenth at gcc dot gnu dot org
2006-04-25 14:38 ` Eric dot Doenges at betty-tv dot com
2006-04-25 14:43 ` Eric dot Doenges at betty-tv dot com
2006-04-25 15:45 ` rguenth at gcc dot gnu dot org
2006-04-25 18:34 ` [Bug target/27308] " pinskia at gcc dot gnu dot org
2006-04-26  6:26 ` Eric dot Doenges at betty-tv dot com
2009-05-12  9:36 ` ramana at gcc dot gnu dot org
2010-01-10  0:12 ` ramana at gcc dot gnu dot org
2010-05-22 18:17 ` rguenth at gcc dot gnu dot org
     [not found] <bug-27308-4@http.gcc.gnu.org/bugzilla/>
2011-04-28 16:26 ` rguenth at gcc dot gnu.org
2012-01-10 15:59 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).