This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33661] New: template methods forget explicit local reg vars
- From: "vincent dot riviere at freesbee dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Oct 2007 19:33:19 -0000
- Subject: [Bug c++/33661] New: template methods forget explicit local reg vars
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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