# cat x.c #include <stdio.h> int main() { int addr; addr = __builtin_return_address (0); printf("%d\n", addr); return 0; } # /usr/gcc-3.4/bin/gcc -O x.c x.c: In function `main': x.c:8: warning: assignment makes integer from pointer without a cast /tmp/ccoJdxcc.o(.text+0x11): In function `main': : undefined reference to `retaddr' collect2: ld returned 1 exit status
I think the fundamental problem is we treat b0 as a general register, which is not true. b0 can only be accessed by mov. As it stands now, gcc generates all kinds of invalid operations on b0/retaddr.
A new testcase: [hjl@gnu-2 tmp] $cat x.c #include <stdio.h> int addr_foo [1]; int addr_bar; void foo () { addr_foo [0] = (int) (long long) __builtin_return_address (0); printf("0x%x\n", addr_foo [0]); } void bar () { addr_bar = (int) (long long) __builtin_return_address (0); printf("0x%x\n", addr_bar); } int main() { foo (); bar (); return 0; } [hjl@gnu-2 tmp]$ /usr/gcc-3.4/bin/gcc x.c [hjl@gnu-2 tmp]$ ./a.out 0x710 0x730 [hjl@gnu-2 tmp]$ /usr/gcc-3.4/bin/gcc x.c -O /tmp/ccpLcZLd.s: Assembler messages: /tmp/ccpLcZLd.s:23: Error: Operand 2 of `st4' should be a general register /tmp/ccpLcZLd.s:51: Error: Operand 2 of `st4' should be a general register
Another testcase. Steve Ellcey's patch doesn't work. [hjl@gnu rp]$ cat y.c #include <stdio.h> int addr_foo [1]; int addr_bar; void foo () { volatile long long a = __builtin_return_address (0); addr_foo [0] = (int) (long long) a; printf("0x%x\n", addr_foo [0]); } [hjl@gnu rp]$ /export/build/linux/tools-3.3-redhat/build-ia64-linux/gcc/xgcc -B/export/build/linux/tools-3.3-redhat/build-ia64-linux/gcc/ -I. -Wall -O y.c -S y.c: In function `foo': y.c:9: warning: initialization makes integer from pointer without a cast y.c:12: internal compiler error: in instantiate_virtual_regs_lossage, at function.c:3777 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Subject: Re: __builtin_return_address may not work on ia64 I am not sure how to tie my mail to gcc-patches into the bugzilla tracking but I have submitted a new patch to fix this. The new patch is http://gcc.gnu.org/ml/gcc-patches/2003-08/msg00090.html and it replaces http://gcc.gnu.org/ml/gcc-patches/2003-07/msg02993.html but the patch http://gcc.gnu.org/ml/gcc-patches/2003-07/msg02962.html is still needed as well for a complete fix. Steve Ellcey sje@cup.hp.com
Created attachment 4551 [details] An alternative patch For LP64, if no function call is made, b0 won't be saved and the current gcc has no problem. If a function call is made, b0 will be saved in return_address_pointer_rtx and we can use it for b0. Does this approach work for ILP32? This may sounds like a bad kludge. But it may generate better code if it works.
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: rth@gcc.gnu.org 2003-08-08 22:07:15 Modified files: gcc : ChangeLog gcc/config/ia64: ia64-protos.h ia64.c ia64.h ia64.md Log message: PR target/11535 * config/ia64/ia64.c (ia64_initial_elimination_offset): Remove RETURN_ADDRESS_POINTER_REGNUM. (ia64_expand_prologue): Don't frob it. (ia64_output_function_epilogue): Likewise. (ia64_return_addr_rtx): New. (ia64_split_return_addr_rtx): New. * config/ia64/ia64-protos.h: Update. * config/ia64/ia64.h (FIRST_PSEUDO_REGISTER): Decrement. (RETURN_ADDRESS_POINTER_REGNUM): Remove. (GENERAL_REGNO_P): Don't check it. (AR_*_REGNUM): Renumber. (FIXED_REGISTERS): Remove RETURN_ADDRESS_POINTER_REGNUM. (CALL_USED_REGISTERS, CALL_REALLY_USED_REGISTERS): Likewise. (REG_ALLOC_ORDER, REG_CLASS_CONTENTS): Likewise. (ELIMINABLE_REGS, REGISTER_NAMES): Likewise. (RETURN_ADDR_RTX): Use ia64_return_addr_rtx. * config/ia64/ia64.md (UNSPEC_RET_ADDR): New. (movdi_ret_addr): New. 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.697&r2=1.16114.2.698 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64-protos.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.49.4.2&r2=1.49.4.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.198.2.10&r2=1.198.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.135.2.4&r2=1.135.2.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.94.4.7&r2=1.94.4.8
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Changes by: rth@gcc.gnu.org 2003-08-08 23:49:57 Modified files: gcc/config/ia64: ia64-protos.h ia64.c ia64.h ia64.md Log message: PR target/11535 * config/ia64/ia64.c (ia64_initial_elimination_offset): Remove RETURN_ADDRESS_POINTER_REGNUM. (ia64_expand_prologue): Don't frob it. (ia64_output_function_epilogue): Likewise. (ia64_return_addr_rtx): New. (ia64_split_return_addr_rtx): New. * config/ia64/ia64-protos.h: Update. * config/ia64/ia64.h (FIRST_PSEUDO_REGISTER): Decrement. (RETURN_ADDRESS_POINTER_REGNUM): Remove. (GENERAL_REGNO_P): Don't check it. (AR_*_REGNUM): Renumber. (FIXED_REGISTERS): Remove RETURN_ADDRESS_POINTER_REGNUM. (CALL_USED_REGISTERS, CALL_REALLY_USED_REGISTERS): Likewise. (REG_ALLOC_ORDER, REG_CLASS_CONTENTS): Likewise. (ELIMINABLE_REGS, REGISTER_NAMES): Likewise. (RETURN_ADDR_RTX): Use ia64_return_addr_rtx. * config/ia64/ia64.md (UNSPEC_RET_ADDR): New. (movdi_ret_addr): New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64-protos.h.diff?cvsroot=gcc&r1=1.59&r2=1.60 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.c.diff?cvsroot=gcc&r1=1.238&r2=1.239 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.h.diff?cvsroot=gcc&r1=1.155&r2=1.156 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.md.diff?cvsroot=gcc&r1=1.110&r2=1.111
http://gcc.gnu.org/ml/gcc-patches/2003-08/msg00283.html
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Changes by: jakub@gcc.gnu.org 2003-08-11 21:53:58 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20030811-1.c gcc/testsuite/gcc.dg: 20030811-1.c Log message: PR target/11693 * gcc.dg/20030811-1.c: New test. PR target/11535 * gcc.c-torture/execute/20030811-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2966&r2=1.2967 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030811-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030811-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_2-rhl8-branch Changes by: jakub@gcc.gnu.org 2003-08-12 14:16:45 Modified files: gcc : ChangeLog gcc/config/ia64: ia64-protos.h ia64.c ia64.h ia64.md Log message: PR target/11535 * config/ia64/ia64.c (ia64_initial_elimination_offset): Remove RETURN_ADDRESS_POINTER_REGNUM. (ia64_expand_prologue): Don't frob it. (ia64_output_function_epilogue): Likewise. (ia64_return_addr_rtx): New. (ia64_split_return_addr_rtx): New. * config/ia64/ia64-protos.h: Update. * config/ia64/ia64.h (FIRST_PSEUDO_REGISTER): Decrement. (RETURN_ADDRESS_POINTER_REGNUM): Remove. (GENERAL_REGNO_P): Don't check it. (AR_*_REGNUM): Renumber. (FIXED_REGISTERS): Remove RETURN_ADDRESS_POINTER_REGNUM. (CALL_USED_REGISTERS, CALL_REALLY_USED_REGISTERS): Likewise. (REG_ALLOC_ORDER, REG_CLASS_CONTENTS): Likewise. (ELIMINABLE_REGS, REGISTER_NAMES): Likewise. (RETURN_ADDR_RTX): Use ia64_return_addr_rtx. * config/ia64/ia64.md (UNSPEC_RET_ADDR): New. (movdi_ret_addr): New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.13152.2.657.2.27.2.156&r2=1.13152.2.657.2.27.2.157 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64-protos.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.36.2.2.8.3&r2=1.36.2.2.8.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.139.2.15.8.9&r2=1.139.2.15.8.10 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.99.2.8.8.5&r2=1.99.2.8.8.6 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.md.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.79.2.3.8.4&r2=1.79.2.3.8.5
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_2-rhl8-branch Changes by: jakub@gcc.gnu.org 2003-08-12 14:19:29 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20030811-1.c gcc/testsuite/gcc.dg: 20030811-1.c Log message: PR target/11693 * gcc.dg/20030811-1.c: New test. PR target/11535 * gcc.c-torture/execute/20030811-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.1672.2.166.2.8.2.65&r2=1.1672.2.166.2.8.2.66 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030811-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030811-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 11535 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-rhl-branch Changes by: jakub@gcc.gnu.org 2003-08-12 15:09:47 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20030811-1.c gcc/testsuite/gcc.dg: 20030811-1.c Log message: PR target/11693 * gcc.dg/20030811-1.c: New test. PR target/11535 * gcc.c-torture/execute/20030811-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-rhl-branch&r1=1.2261.2.170.2.30&r2=1.2261.2.170.2.31 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030811-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-rhl-branch&r1=NONE&r2=1.1.4.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030811-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-rhl-branch&r1=NONE&r2=1.1.4.1