GCC 3.4.3 (i686-pc-linux-gnu) generates incorrect code when a function containing __builtin_return(__builtin_apply(...)) is inlined, whether by the "inline" keyword or with -finline-functions. For example, take this simple program: int bar(int hoge) { return hoge; } int foo(int xyzzy) { __builtin_return(__builtin_apply(bar,__builtin_apply_args(),64)); } int main(int ac, char **av) { return foo(9)==9 && foo(42)==42 ? 0 : 1; } This should generate a main() with two calls to foo(), but with -finline-functions, main() instead consists of a __builtin_apply() call to bar() directly, using the arguments to main() rather than the argument passed to foo(). See attached assembly listings. $ gcc -vReading specs from /pkg/gcc/lib/gcc/i686-pc-linux-gnu/3.4.3/specs Configured with: /tmp/packager17310.149/gcc-3.4.3/configure --prefix=/pkg/gcc --enable-languages=c,c++ --disable-shared --disable-nls Thread model: posix gcc version 3.4.3
Created attachment 8231 [details] Test source file (from description)
Created attachment 8232 [details] gcc test.c -S -O2
Created attachment 8233 [details] gcc test.c -S -O2 -finline-functions (bad)
Confirmed.
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-04/msg00497.html>
Subject: Bug 20076 CVSROOT: /cvs/gcc Module name: gcc Changes by: jakub@gcc.gnu.org 2005-04-05 20:10:14 Modified files: gcc : ChangeLog tree-inline.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: builtin-apply4.c Log message: PR tree-optimization/20076 * tree-inline.c (inline_forbidden_p_1): Prevent inlining functions that call __builtin_return or __builtin_apply_args. * gcc.dg/builtin-apply4.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8149&r2=2.8150 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&r1=1.178&r2=1.179 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5288&r2=1.5289 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtin-apply4.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 20076 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: jakub@gcc.gnu.org 2005-04-06 05:57:39 Modified files: gcc : ChangeLog tree-inline.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: builtin-apply4.c Log message: PR tree-optimization/20076 * tree-inline.c (inline_forbidden_p_1): Prevent inlining functions that call __builtin_return or __builtin_apply_args. * gcc.dg/builtin-apply4.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.137&r2=2.7592.2.138 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.170.8.2&r2=1.170.8.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.108&r2=1.5084.2.109 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtin-apply4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
gcc.dg/builtin-apply4.c execution test is failing on mainline on ia64-hpux. gcc-testresults also shows it failing on 4.0 branch on ia64-linux.
fixed in 4.0.0