public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vincent dot riviere at freesbee dot fr" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/33661] New: template methods forget explicit local reg vars Date: Thu, 04 Oct 2007 19:33:00 -0000 [thread overview] Message-ID: <bug-33661-14645@http.gcc.gnu.org/bugzilla/> (raw) 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 T> 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<char>::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
next reply other threads:[~2007-10-04 19:33 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-10-04 19:33 vincent dot riviere at freesbee dot fr [this message] 2007-12-10 1:55 ` [Bug c++/33661] " pinskia at gcc dot gnu dot org 2008-02-02 20:49 ` vincent dot riviere at freesbee dot fr 2008-02-05 10:29 ` rguenth at gcc dot gnu dot org 2008-02-05 19:57 ` vincent dot riviere at freesbee dot fr 2008-04-29 17:10 ` pinskia at gcc dot gnu dot org 2008-04-30 13:35 ` adam at os dot inf dot tu-dresden dot de 2008-04-30 15:33 ` vincent dot riviere at freesbee dot fr 2008-04-30 20:22 ` adam at os dot inf dot tu-dresden dot de
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-33661-14645@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).