public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/32971]  New: Inline asm with offset addressing fails to compile in 4.0+ without -O
@ 2007-08-03  4:47 kinetik at orcon dot net dot nz
  2007-08-03  4:48 ` [Bug inline-asm/32971] " kinetik at orcon dot net dot nz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kinetik at orcon dot net dot nz @ 2007-08-03  4:47 UTC (permalink / raw)
  To: gcc-bugs

The following test case fails to compile without optimization with gcc 4.3.0
(20070503 (experimental)), 4.1.2 (20070502 (Red Hat 4.1.2-12)), and 4.0.4
(20060904 (prerelease) (Debian 4.0.3-7)), but succeeds with 3.3.6 (Debian
1:3.3.6-15) and 3.4.6 (Debian 3.4.6-5).  With optimization (-O and -O2), it
compiles fine with all of the gcc versions mentioned above.

The failing configurations are generating invalid assembly and gas emits the
following error:
/tmp/ccnbmIy1.s:12: Error: register value used as expression

Looking at the assembly emitted by gcc, the failing case looks like:
        lea (%edx)(%eax), %eax

..and with the working configurations, I get the expected code:
        lea 4(%eax), %eax

#include <stddef.h>

struct coord { int x; int y; };

int *
foo(struct coord * c)
{
  int * i;
  asm ("lea %1(%2), %0"
       : "=r" (i)
       : "m" (*(size_t *) offsetof(struct coord, y)),
         "r" (c)
       : "memory");
  return i;
}


-- 
           Summary: Inline asm with offset addressing fails to compile in
                    4.0+ without -O
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kinetik at orcon dot net dot nz
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32971


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug inline-asm/32971] Inline asm with offset addressing fails to compile in 4.0+ without -O
  2007-08-03  4:47 [Bug inline-asm/32971] New: Inline asm with offset addressing fails to compile in 4.0+ without -O kinetik at orcon dot net dot nz
@ 2007-08-03  4:48 ` kinetik at orcon dot net dot nz
  2007-08-03  4:51 ` kinetik at orcon dot net dot nz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kinetik at orcon dot net dot nz @ 2007-08-03  4:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kinetik at orcon dot net dot nz  2007-08-03 04:48 -------
Created an attachment (id=14014)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14014&action=view)
testcase


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32971


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug inline-asm/32971] Inline asm with offset addressing fails to compile in 4.0+ without -O
  2007-08-03  4:47 [Bug inline-asm/32971] New: Inline asm with offset addressing fails to compile in 4.0+ without -O kinetik at orcon dot net dot nz
  2007-08-03  4:48 ` [Bug inline-asm/32971] " kinetik at orcon dot net dot nz
@ 2007-08-03  4:51 ` kinetik at orcon dot net dot nz
  2007-08-03  5:11 ` kinetik at flim dot org
  2007-08-03 12:17 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: kinetik at orcon dot net dot nz @ 2007-08-03  4:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kinetik at orcon dot net dot nz  2007-08-03 04:51 -------
Using a memory operand to pass the offset value is not ideal in the first
place, but I'm not sure how else I can do it.  It looks like the "i" contraint
(immediate value) is what I want, but the following code:

  asm ("lea %1(%2), %0"
       : "=r" (i)
       : "i" (offsetof(struct coord, y)),
         "r" (c)
       : "memory");

...generates the following assembly, which gas fails to assemble due to syntax
errors:
        lea $4(%eax), %eax


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32971


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug inline-asm/32971] Inline asm with offset addressing fails to compile in 4.0+ without -O
  2007-08-03  4:47 [Bug inline-asm/32971] New: Inline asm with offset addressing fails to compile in 4.0+ without -O kinetik at orcon dot net dot nz
  2007-08-03  4:48 ` [Bug inline-asm/32971] " kinetik at orcon dot net dot nz
  2007-08-03  4:51 ` kinetik at orcon dot net dot nz
@ 2007-08-03  5:11 ` kinetik at flim dot org
  2007-08-03 12:17 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: kinetik at flim dot org @ 2007-08-03  5:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from kinetik at flim dot org  2007-08-03 05:11 -------
(In reply to comment #2)
>   asm ("lea %1(%2), %0"
>        : "=r" (i)
>        : "i" (offsetof(struct coord, y)),
>          "r" (c)
>        : "memory");

Bug #29357 suggests that I need to use %c1 rather than %1 here, and indeed this
works and I believe this is the correct solution.

I'm don't know enough to know if the original reason I opened the bug is still
valid (i.e. it's a regression), or if I'm just being bitten by behaviour
changes when I'm abusing the meaning of the operand (I suspect the latter), so
I'll leave the bug open for someone to review and confirm or close.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32971


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug inline-asm/32971] Inline asm with offset addressing fails to compile in 4.0+ without -O
  2007-08-03  4:47 [Bug inline-asm/32971] New: Inline asm with offset addressing fails to compile in 4.0+ without -O kinetik at orcon dot net dot nz
                   ` (2 preceding siblings ...)
  2007-08-03  5:11 ` kinetik at flim dot org
@ 2007-08-03 12:17 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-03 12:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-08-03 12:17 -------
%m means it can represent it as memory access which means access it via a
register, this is not a bug.


-- 

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=32971


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-08-03 12:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-03  4:47 [Bug inline-asm/32971] New: Inline asm with offset addressing fails to compile in 4.0+ without -O kinetik at orcon dot net dot nz
2007-08-03  4:48 ` [Bug inline-asm/32971] " kinetik at orcon dot net dot nz
2007-08-03  4:51 ` kinetik at orcon dot net dot nz
2007-08-03  5:11 ` kinetik at flim dot org
2007-08-03 12:17 ` pinskia at gcc dot gnu dot 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).