From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9934 invoked by alias); 4 Oct 2007 19:33:29 -0000 Received: (qmail 9902 invoked by uid 48); 4 Oct 2007 19:33:19 -0000 Date: Thu, 04 Oct 2007 19:33:00 -0000 Subject: [Bug c++/33661] New: template methods forget explicit local reg vars X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "vincent dot riviere at freesbee dot fr" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg00378.txt.bz2 Hello. http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Local-Reg-Vars.html#Local-Reg-Vars "However, using the variable as an asm operand guarantees that the specified register is used for the operand." This does not always work if the code is inside a template method which gets inlined. For this testcase, imagine a system call invoked by trap #0. It returns a pointer into d0, and clobbers d1/a0/a1. $ cat a.cpp template class Tpl { public: static long* MySysCall() { register long retval __asm__("d0"); asm ( "trap #0\n\t" "move.l %0,%0\n\t" : "=r"(retval) : : "d1", "a0", "a1" ); return (long*)retval; } }; void f() { long* p = Tpl::MySysCall(); *p = 1; } Note that I added an extra "move.l %0,%0" to see which register is affected to %0. $ g++ -S a.cpp -O1 -o - #NO_APP .file "a.cpp" .text .align 2 .globl _Z1fv .type _Z1fv, @function _Z1fv: .LFB3: link.w %fp,#0 .LCFI0: move.l %a2,-(%sp) .LCFI1: #APP trap #0 move.l %a2,%a2 #NO_APP moveq #1,%d0 move.l %d0,(%a2) move.l (%sp)+,%a2 unlk %fp rts .LFE3: .size _Z1fv, .-_Z1fv .globl __gxx_personality_v0 .ident "GCC: (GNU) 4.2.1" .section .note.GNU-stack,"",@progbits We can see that even though we requested "retval" to be mapped to d0, it has been mapped to a2. The problem does not appear if the code is in a method of a standard class (not a method of a template). Another way to get it work is to add "volatile" to the register variable declaration. -- Summary: template methods forget explicit local reg vars Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vincent dot riviere at freesbee dot fr GCC target triplet: m68k-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661