Bug 10842 - [3.3 regression] [arm] Clobbered link register is copied to pc under certain circumstances
Summary: [3.3 regression] [arm] Clobbered link register is copied to pc under certain ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-05-18 06:26 UTC by zhenya
Modified: 2003-06-14 16:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
gcc33bug.i (294 bytes, text/x-c)
2003-05-21 15:17 UTC, zhenya
Details

Note You need to log in before you can comment on or make changes to this bug.
Description zhenya 2003-05-18 06:26:00 UTC
Compiling the attached code with -O3 -fno-inline-functions produces assembly that exhibits the following behaviour:

functionA branches with link to functionB.
functionB clobbers the link register and branches to functionC.
functionC returns with "mov pc, lr" but lr is no longer valid.

When compiling with -O2, the link register is not used as a scratch register in functionB, and hence the "mov pc, lr" used by functionC works as expected.

This appears to be a regression from 3.2.1 (has not been tested with 3.2.2).

Release:
gcc version 3.3

Environment:
Host: FreeBSD 4.7-STABLE
Target: arm-elf
Configured with: ../configure --host=i386-unknown-freebsd4.7 --program-prefix=arm-elf- --target=arm-elf --disable-threads --with-cpu=arm7tdmi --enable-languages=c

How-To-Repeat:
arm-elf-gcc -O3 -fno-inline-functions -save-temps -c gcc33bug.i
Comment 1 zhenya 2003-05-18 06:26:00 UTC
Fix:
A workaround is to use -O2 in place of -O3, or use -ffixed-lr
Comment 2 Richard Earnshaw 2003-05-22 13:42:41 UTC
Confirmed, but already fixed in Mainline.  The following patch needs pulling up
and regression testing:

2003-01-20  Nick Clifton  <nickc@redhat.com>

        * config/arm/arm.md (sibcall_epilogue): Add an
        UNSPEC_PROLOGUE_USE to prevent the link register from being
        considered dead.
Comment 3 CVS Commits 2003-06-14 16:29:24 UTC
Subject: Bug 10842

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	rearnsha@gcc.gnu.org	2003-06-14 16:29:21

Modified files:
	gcc            : ChangeLog 
	gcc/config/arm : arm.md 

Log message:
	PR optimization/10842
	From trunk:
	2003-01-20  Nick Clifton  <nickc@redhat.com>
	
	* config/arm/arm.md (sibcall_epilogue): Add an
	UNSPEC_PROLOGUE_USE to prevent the link register from being
	considered dead.
	
	2003-02-02  Richard Earnshaw  <rearnsha@arm.com>
	
	* arm.md (sibcall_epilogue): Set the "conds" to "clob".
	(epilogue_insns): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.582&r2=1.16114.2.583
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/arm/arm.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.113.2.1&r2=1.113.2.2

Comment 4 Richard Earnshaw 2003-06-14 16:32:13 UTC
Pulled up changes from trunk.