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; 11+ 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] 11+ messages in thread
* [Bug c/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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 ` rguenth at gcc dot gnu dot org
2006-04-25 12:49 ` rguenth at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-04-25 12:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2006-04-25 12:38 -------
*** Bug 27305 has been marked as a duplicate of this bug. ***
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-04-25 12:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2006-04-25 12:49 -------
This is probably a problem with the inline asm constraints. Try removing the
__asm__("r0") from the __res variable. Also try simplifying the testcase by
storing the result of BIOS_ContainerUsage(1) to memory rather than calling
printf.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric dot Doenges at betty-tv dot com @ 2006-04-25 14:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from Eric dot Doenges at betty-tv dot com 2006-04-25 14:37 -------
Storing the result to memory generates correct code
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (2 preceding siblings ...)
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
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric dot Doenges at betty-tv dot com @ 2006-04-25 14:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from Eric dot Doenges at betty-tv dot com 2006-04-25 14:43 -------
Removing the __asm__ ("r0") from __res works around the bug - but then I cannot
depend on gcc
always allocating r0 for __res, can I ? I found no other way to tell gcc which
registers it must use.
I'm assuming this is a bug in gcc, not the asm constraint, because the same
code works flawlessly with
gcc-3.4.3.
As to simplifying the testcase - storing the result of BIOS_ContainerUsage to
memory generates correct
code regardless of wether __res is forced to r0 or not, making it worthless as
a test case.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (3 preceding siblings ...)
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
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-04-25 15:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rguenth at gcc dot gnu dot org 2006-04-25 15:45 -------
__res should be allocated to the same register as __r0 due to the '0'
constraint which tells gcc to use the same register as for "=r" (__res).
Whoops - I obviously meant to remove the __asm__("r0") from the __r0
variable... But maybe it works vice-versa, too.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (4 preceding siblings ...)
2006-04-25 15:45 ` rguenth at gcc dot gnu dot org
@ 2006-04-25 18:34 ` pinskia at gcc dot gnu dot org
2006-04-26 6:26 ` Eric dot Doenges at betty-tv dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-25 18:34 UTC (permalink / raw)
To: gcc-bugs
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|blocker |normal
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (5 preceding siblings ...)
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
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric dot Doenges at betty-tv dot com @ 2006-04-26 6:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from Eric dot Doenges at betty-tv dot com 2006-04-26 06:26 -------
Unfortunately, removing the __asm__ ("r0") from __r0 does not circumvent the
problem.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (6 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-05-12 9:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from ramana at gcc dot gnu dot org 2009-05-12 09:36 -------
Confirmed with r147377
--
ramana at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-05-12 09:36:02
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (7 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: ramana at gcc dot gnu dot org @ 2010-01-10 0:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from ramana at gcc dot gnu dot org 2010-01-10 00:12 -------
Can't see this problem with -O2 on trunk , 4.3 branch and 4.4 branch. I tried
with -mcpu=arm7tdmi
--
ramana at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |WAITING
Target Milestone|--- |4.3.5
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/27308] Compiler generates incorrect code when calling a function with the result of an inline function as parameter
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
` (8 preceding siblings ...)
2010-01-10 0:12 ` ramana at gcc dot gnu dot org
@ 2010-05-22 18:17 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-22 18:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2010-05-22 18:11 -------
GCC 4.3.5 is being released, adjusting target milestone.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.3.5 |4.3.6
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27308
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-05-22 18:17 UTC | newest]
Thread overview: 11+ 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
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).