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
Fix: A workaround is to use -O2 in place of -O3, or use -ffixed-lr
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.
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
Pulled up changes from trunk.