public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39375] New: asm with a "=X" output overwrites the output
@ 2009-03-05 2:53 balrogg at gmail dot com
2009-03-05 2:55 ` [Bug c/39375] " balrogg at gmail dot com
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: balrogg at gmail dot com @ 2009-03-05 2:53 UTC (permalink / raw)
To: gcc-bugs
The info pages give something like
__asm__ ("xxx" : "=X" (sum));
as an example of adding a hint for gcc that the instruction clobbers "sum".
However if the variable is an array element, gcc will clobber the variable for
you (in case you forgot) by generating a move from a random register to the
variable. I don't know if liveness analysis is done on element basis for
arrays, but it doesn't generate warnings either.
Similarly for "=X" but not "=m" or "=r".
For example on x86,
__asm__ ("outl %%eax, (%%dx)" : "=X" (params[1]));
to indicate that the IO causes params[1] to be overwritten, results in:
400532: ef out %eax,(%dx)
400533: 89 45 f4 mov %eax,-0xc(%rbp)
with all -O levels.
Similarly on ARM a move from r3 is generated that overwrites the array element.
--
Summary: asm with a "=X" output overwrites the output
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: balrogg at gmail dot com
GCC build triplet: x86_64-linux-gnu, arm-linux-gnueabi
GCC host triplet: x86_64-linux-gnu, arm-linux-gnueabi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/39375] asm with a "=X" output overwrites the output
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
@ 2009-03-05 2:55 ` balrogg at gmail dot com
2009-03-05 10:42 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: balrogg at gmail dot com @ 2009-03-05 2:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from balrogg at gmail dot com 2009-03-05 02:55 -------
(In reply to comment #0)
> Similarly for "=X" but not "=m" or "=r".
Rather, similarly for "=g".
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/39375] asm with a "=X" output overwrites the output
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
2009-03-05 2:55 ` [Bug c/39375] " balrogg at gmail dot com
@ 2009-03-05 10:42 ` rguenth at gcc dot gnu dot org
2009-03-06 10:34 ` balrogg at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-05 10:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-03-05 10:42 -------
You need to use a "memory" clobber instead. "=X" (params[1]) says to GCC
that the asm operand 0 should be stored to params[1], which it does
(it allocates %eax to it). Note that plain use of %eax and %dx is a
bad idea as well, instead you should use proper inputs and outputs with
register constraints.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/39375] asm with a "=X" output overwrites the output
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
2009-03-05 2:55 ` [Bug c/39375] " balrogg at gmail dot com
2009-03-05 10:42 ` rguenth at gcc dot gnu dot org
@ 2009-03-06 10:34 ` balrogg at gmail dot com
2009-03-16 16:53 ` balrogg at gmail dot com
2009-03-16 17:02 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: balrogg at gmail dot com @ 2009-03-06 10:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from balrogg at gmail dot com 2009-03-06 10:34 -------
(In reply to comment #2)
> You need to use a "memory" clobber instead. "=X" (params[1]) says to GCC
> that the asm operand 0 should be stored to params[1], which it does
> (it allocates %eax to it).
Note that "=r" doesn't produce the useless move. Neither does "=X" (params) if
params is an integer.
Note also that the documentation uses "=X" (sum) as an example of adding a
dependency on the asm statement.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/39375] asm with a "=X" output overwrites the output
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
` (2 preceding siblings ...)
2009-03-06 10:34 ` balrogg at gmail dot com
@ 2009-03-16 16:53 ` balrogg at gmail dot com
2009-03-16 17:02 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: balrogg at gmail dot com @ 2009-03-16 16:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from balrogg at gmail dot com 2009-03-16 16:53 -------
Reopening because
int params; __asm__ ("xxx" : "=X" (params));
and
int params[1]; __asm__ ("xxx" : "=X" (params[0]));
still produce different output in a way that is undocumented.
--
balrogg at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/39375] asm with a "=X" output overwrites the output
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
` (3 preceding siblings ...)
2009-03-16 16:53 ` balrogg at gmail dot com
@ 2009-03-16 17:02 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-03-16 17:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2009-03-16 17:02 -------
(In reply to comment #4)
> Reopening because
> int params; __asm__ ("xxx" : "=X" (params));
> and
> int params[1]; __asm__ ("xxx" : "=X" (params[0]));
> still produce different output in a way that is undocumented.
How so? "=X" (params[0]) says it can be in memory which means params is
addressable. This is documented as "=X" really means "=rfm" (plus extra
constraints which don't correspond to r, f, or m).
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <bug-39375-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2012-01-02 4:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-05 2:53 [Bug c/39375] New: asm with a "=X" output overwrites the output balrogg at gmail dot com
2009-03-05 2:55 ` [Bug c/39375] " balrogg at gmail dot com
2009-03-05 10:42 ` rguenth at gcc dot gnu dot org
2009-03-06 10:34 ` balrogg at gmail dot com
2009-03-16 16:53 ` balrogg at gmail dot com
2009-03-16 17:02 ` pinskia at gcc dot gnu dot org
[not found] <bug-39375-4@http.gcc.gnu.org/bugzilla/>
2012-01-02 4:17 ` 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).