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
* [Bug c++/33661] template methods forget explicit local reg vars
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 ` pinskia at gcc dot gnu dot org
2008-02-02 20:49 ` vincent dot riviere at freesbee dot fr
` (6 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-12-10 1:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-12-10 01:55 -------
Confirmed,
It also fails with 3.3 so this is not a regression.
A testcase for PPC:
template<class T>
class Tpl
{
public:
static long* MySysCall()
{
register long retval __asm__("r3");
asm
(
"trap #0\n\t"
"move.l %0,%0\n\t"
: "=r"(retval)
:
: "r4"
);
return (long*)retval;
}
};
void f()
{
long* p = Tpl<char>::MySysCall();
*p = 1;
}
Note I did not change the inline-asm's string though so it will not assemble.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Known to fail| |3.3.3 4.1.0 4.3.0
Last reconfirmed|0000-00-00 00:00:00 |2007-12-10 01:55:24
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
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
` (5 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: vincent dot riviere at freesbee dot fr @ 2008-02-02 20:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from vincent dot riviere at freesbee dot fr 2008-02-02 20:48 -------
Still fails in GCC release 4.2.3
--
vincent dot riviere at freesbee dot fr changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|3.3.3 4.1.0 4.3.0 |3.3.3 4.1.0 4.2.3 4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
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
` (4 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-05 10:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-02-05 10:28 -------
This works for me on x86_64 with 4.3.0.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
` (2 preceding siblings ...)
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
` (3 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: vincent dot riviere at freesbee dot fr @ 2008-02-05 19:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from vincent dot riviere at freesbee dot fr 2008-02-05 19:56 -------
Same problem with GCC 4.3-20080201 on target i686-pc-linux-gnu
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
` (3 preceding siblings ...)
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
` (2 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-29 17:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2008-04-29 17:09 -------
*** Bug 36080 has been marked as a duplicate of this bug. ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |adam at os dot inf dot tu-
| |dresden dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
` (4 preceding siblings ...)
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
7 siblings, 0 replies; 13+ messages in thread
From: adam at os dot inf dot tu-dresden dot de @ 2008-04-30 13:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from adam at os dot inf dot tu-dresden dot de 2008-04-30 13:34 -------
Even if this is not a regression it would be very helpful if g++ would emit a
warning that the register allocation will be ignored. Those bugs are subtle.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
` (5 preceding siblings ...)
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
7 siblings, 0 replies; 13+ messages in thread
From: vincent dot riviere at freesbee dot fr @ 2008-04-30 15:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from vincent dot riviere at freesbee dot fr 2008-04-30 15:32 -------
This is not a regression, however it is a bug, it has to be fixed. Inline
assembly coupled with templates is very powerful, however because of this bug
it is unusable :-(
If I remember well, a workaround is to put the assembly in an inline global
function, then call it from the template method.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
2007-10-04 19:33 [Bug c++/33661] New: template methods forget explicit local reg vars vincent dot riviere at freesbee dot fr
` (6 preceding siblings ...)
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
7 siblings, 0 replies; 13+ messages in thread
From: adam at os dot inf dot tu-dresden dot de @ 2008-04-30 20:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from adam at os dot inf dot tu-dresden dot de 2008-04-30 20:22 -------
(In reply to comment #7)
> This is not a regression, however it is a bug, it has to be fixed. Inline
> assembly coupled with templates is very powerful, however because of this bug
> it is unusable :-(
I fully agree. I don't know how hard this one is to fix so at least a
warning/error would be good to have. Silently ignoring the allocation just
causes bugs nobody wants to have.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
[not found] <bug-33661-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2014-10-26 14:25 ` adam at os dot inf.tu-dresden.de
@ 2015-06-03 10:05 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-06-03 10:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |krebbel at gcc dot gnu.org
--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 66393 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
[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
3 siblings, 0 replies; 13+ messages in thread
From: adam at os dot inf.tu-dresden.de @ 2014-10-26 14:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
--- Comment #11 from Adam Lackorzynski <adam at os dot inf.tu-dresden.de> ---
Confirming issue still exists for 4.7.4, 4.8.4, 4.9.2 and 5.0 (tested on
x86_64).
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
[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
3 siblings, 0 replies; 13+ messages in thread
From: Aleksandrs.Saveljevs at gmail dot com @ 2012-05-31 8:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
--- Comment #10 from Aleksandrs Saveljevs <Aleksandrs.Saveljevs at gmail dot com> 2012-05-31 08:16:41 UTC ---
Confirming that the bug still exists on ARM, x86 and x86_64 as of GCC 4.6.3.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/33661] template methods forget explicit local reg vars
[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
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: s.schuh85 at gmail dot com @ 2011-08-24 10:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33661
Stefan Schuh <s.schuh85 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |s.schuh85 at gmail dot com
--- Comment #9 from Stefan Schuh <s.schuh85 at gmail dot com> 2011-08-24 10:00:48 UTC ---
I can confirm this bug in gcc version 4.5.2 on i686-linux-gnu
and in gcc version 4.6.0 on s390x-ibm-linux-gnu
^ permalink raw reply [flat|nested] 13+ messages in thread
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).