public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33661]  New: template methods forget explicit local reg vars
@ 2007-10-04 19:33 vincent dot riviere at freesbee dot fr
  2007-12-10  1:55 ` [Bug c++/33661] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: vincent dot riviere at freesbee dot fr @ 2007-10-04 19:33 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <bug-33661-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2015-06-03 10:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
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
     [not found] <bug-33661-4@http.gcc.gnu.org/bugzilla/>
2011-08-24 10:09 ` s.schuh85 at gmail dot com
2012-05-31  8:19 ` Aleksandrs.Saveljevs at gmail dot com
2014-10-26 14:25 ` adam at os dot inf.tu-dresden.de
2015-06-03 10:05 ` pinskia at gcc dot gnu.org

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).