public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/8028: GCC 3.x __builtin_apply() passes wrong arguments
@ 2002-09-24 19:36 achurch
0 siblings, 0 replies; only message in thread
From: achurch @ 2002-09-24 19:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 8028
>Category: c
>Synopsis: GCC 3.x __builtin_apply() passes wrong arguments
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Sep 24 19:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Andrew Church
>Release: 3.2
>Organization:
>Environment:
System: Linux crystal 2.4.18 #9 SMP Mon Sep 2 16:03:12 JST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /usr/src/gcc-3.2/configure --prefix=/packages/gcc3 --program-suffix=3 --enable-languages=c,c++
>Description:
Calling a function via __builtin_apply() passes the wrong arguments to the
function if another function which takes arguments has been called
previously.
>How-To-Repeat:
gcc3 -O0 foo.c -o foo
./foo ; echo $?
--------------- BEGIN foo.c ---------------
int foo(int n)
{
return n;
}
int bar(int n)
{
return n+1;
}
int quux(int n)
{
foo(0);
__builtin_return(__builtin_apply((void *)bar, __builtin_apply_args(), 64));
}
int main(int argc, char **argv)
{
return quux(argc);
}
---------------- END foo.c ----------------
The program should exit with a value of argc+1, but instead exits with a
stack-dependent return value (I get 99). The following part of the
assembly listing for quux() looks suspicious:
...
movl $0, (%esp)
call foo <-- call foo(0)
movl (%ebx), %edx
movl %esp, -172(%ebp)
subl $64, %esp <-- space for __builtin_apply() arguments?
leal 4(%esp), %eax <-- copy arguments to ESP+4 (BUG???)
...
The offset of "4" in the last line above seems to reflect the amount of
argument space required for foo()--if I pass foo() two parameters, it
changes to 8, if three parameters then 12, etc.
>Fix:
Move everything but the __builtin_apply() call into a separate function
that takes no parameters, and call that function before calling
__builtin_apply(). (It seems to be safe to declare the new function
"static inline".)
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-09-25 2:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-24 19:36 c/8028: GCC 3.x __builtin_apply() passes wrong arguments achurch
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).