Bug 20076 - [3.4 Regression] __builtin_return(__builtin_apply()) inlined incorrectly
Summary: [3.4 Regression] __builtin_return(__builtin_apply()) inlined incorrectly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2005-02-19 12:56 UTC by Andrew Church
Modified: 2018-03-08 03:25 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.0.4 2.95.3
Known to fail: 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2006-01-07 01:53:07


Attachments
Test source file (from description) (141 bytes, text/plain)
2005-02-19 12:57 UTC, Andrew Church
Details
gcc test.c -S -O2 (496 bytes, text/plain)
2005-02-19 12:58 UTC, Andrew Church
Details
gcc test.c -S -O2 -finline-functions (bad) (436 bytes, text/plain)
2005-02-19 12:59 UTC, Andrew Church
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Church 2005-02-19 12:56:04 UTC
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
Comment 1 Andrew Church 2005-02-19 12:57:19 UTC
Created attachment 8231 [details]
Test source file (from description)
Comment 2 Andrew Church 2005-02-19 12:58:16 UTC
Created attachment 8232 [details]
gcc test.c -S -O2
Comment 3 Andrew Church 2005-02-19 12:59:22 UTC
Created attachment 8233 [details]
gcc test.c -S -O2 -finline-functions (bad)
Comment 4 Andrew Pinski 2005-02-19 13:22:27 UTC
Confirmed.
Comment 5 Jakub Jelinek 2005-04-05 11:19:35 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-04/msg00497.html>
Comment 6 GCC Commits 2005-04-05 20:10:24 UTC
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

Comment 7 GCC Commits 2005-04-06 05:57:52 UTC
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

Comment 8 Joseph S. Myers 2005-04-06 14:18:54 UTC
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.
Comment 9 Gabriel Dos Reis 2006-02-28 10:02:08 UTC
fixed in 4.0.0