Bug 15886 - [3.3/3.4/4.0 Regression] SH: Miscompilation with -O2 -fPIC
Summary: [3.3/3.4/4.0 Regression] SH: Miscompilation with -O2 -fPIC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.1
: P2 normal
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-06-09 03:24 UTC by sugioka
Modified: 2004-09-13 14:15 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: sh-unknown-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.2.3 3.4.3
Known to fail: 3.4.0
Last reconfirmed: 2004-06-11 05:58:22


Attachments
testcase (44.27 KB, application/x-gzip-compressed)
2004-06-09 03:26 UTC, sugioka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sugioka 2004-06-09 03:24:38 UTC
Gcc-3.4.1 generates wrong code when compiling attached code with '-O2 -fPIC'.
Adding -fno-regmove fixes this.

Compile:
  $ sh-linux-gcc -O2 -fPIC -S dl-open.i

Miscompiled source code:
  args.caller_dl_open = __builtin_extract_return_addr (__builtin_return_address 
(0));

Generated wrong code:
  mov    r4,r11
  [snip]
  sts    pr,r0
  [snip]
  mov.l  r11,@(12,r14)       --- original pr should be stored to @(12,r14)

Correct code (-O2 -fPIC -fno-regmove):
  sts    pr,r10
  [snip]
  mov.l  r10,@(12,r14)
Comment 1 sugioka 2004-06-09 03:26:38 UTC
Created attachment 6496 [details]
testcase
Comment 2 Kazumoto Kojima 2004-06-11 02:12:26 UTC
FYI, I could find a reduced testcase and analyze it. See
http://gcc.gnu.org/ml/gcc/2004-06/msg00721.html
Comment 3 Andrew Pinski 2004-06-11 05:58:21 UTC
Kazumoto Kojima confirmed and analyzed it already.
Comment 4 Giovanni Bajo 2004-06-11 13:07:36 UTC
KK, is this a regression? In your message you say that mainline and 3.4 exhibit 
the bug, but can you test it also on an older version?
Comment 5 Kazumoto Kojima 2004-06-11 14:11:38 UTC
Yep.  I've confirmed that 3.3.4 has the same problem and 3.2.3 doesn't.
So this is a regression from 3.2.
Comment 6 CVS Commits 2004-06-11 18:15:40 UTC
Subject: Bug 15886

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amylaar@gcc.gnu.org	2004-06-11 18:15:38

Modified files:
	gcc            : ChangeLog 

Log message:
	Add PR number in:
	PR 15886:
	* sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3925&r2=2.3926

Comment 7 Mark Mitchell 2004-08-23 20:58:46 UTC
Postponed until GCC 3.4.3.
Comment 8 CVS Commits 2004-09-09 02:18:24 UTC
Subject: Bug 15886

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	kkojima@gcc.gnu.org	2004-09-09 02:18:15

Modified files:
	gcc            : ChangeLog 
	gcc/config/sh  : sh.h 

Log message:
	PR 15886
	Backport from mainline:
	2004-06-11  J"orn Rennecke <joern.rennecke@superh.com>
	
	* sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.616&r2=2.2326.2.617
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.230.4.3&r2=1.230.4.4

Comment 9 Andrew Pinski 2004-09-09 02:33:41 UTC
Fixed in 3.4.3.