This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c/8028: GCC 3.x __builtin_apply() passes wrong arguments
- From: achurch at achurch dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: Wed, 25 Sep 2002 11:28:20 JST
- Subject: c/8028: GCC 3.x __builtin_apply() passes wrong arguments
>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: