public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/37195]  New: unrelated variables get the same memory address in inline assembly
@ 2008-08-21 21:15 jdemeyer at cage dot ugent dot be
  2008-08-21 21:17 ` [Bug inline-asm/37195] " jdemeyer at cage dot ugent dot be
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-08-21 21:15 UTC (permalink / raw)
  To: gcc-bugs

In the following inline assembly statement (the second one in the attached
program), the operands %0 and %5 are stored in exactly the same memory address
-44(%ebp), even though they refer to different variables (and all the output
constraints have the earlyclobber modifier).

asm("   shrdl %6, %4, %3\n"
    "   movl %3, %0\n"
    "   movl %5, %2\n"
    "   shrdl %6, %2, %1\n"
    "   shrl %6, %2\n"
    : "=&rm" (d0), "=&r" (d1), "=&r" (d2)
    : "2" (c0), "1" (c1), "g" (c2), "cI" (s)
    : "%eax", "%esi", "%edi", "cc"
);

This code is compiled as
    shrdl %cl, %edx, %ebx
    movl %ebx, -40(%ebp)
    movl -40(%ebp), %ebx
    shrdl %cl, %ebx, %edx
    shrl %cl, %ebx


Command line:
gcc-4.2.4 -O1 -save-temps asmtest.c -c -o asmtest.o

Note: gcc 4.3.1 does not seem to have this problem.


Output of gcc -v:
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.2.4/work/gcc-4.2.4/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.2.4
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.4/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.4
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.4/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.4/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.4/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --enable-secureplt --disable-multilib --enable-libmudflap
--disable-libssp --disable-libgcj --with-arch=i686
--enable-languages=c,c++,treelang,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.2.4 (Gentoo 4.2.4)


-- 
           Summary: unrelated variables get the same memory address in
                    inline assembly
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jdemeyer at cage dot ugent dot be
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug inline-asm/37195] unrelated variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
@ 2008-08-21 21:17 ` jdemeyer at cage dot ugent dot be
  2008-09-01 18:19 ` jdemeyer at cage dot ugent dot be
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-08-21 21:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jdemeyer at cage dot ugent dot be  2008-08-21 21:16 -------
Created an attachment (id=16123)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16123&action=view)
Source code which shows the problem


-- 


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


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

* [Bug inline-asm/37195] unrelated variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
  2008-08-21 21:17 ` [Bug inline-asm/37195] " jdemeyer at cage dot ugent dot be
@ 2008-09-01 18:19 ` jdemeyer at cage dot ugent dot be
  2008-09-01 18:20 ` jdemeyer at cage dot ugent dot be
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-01 18:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jdemeyer at cage dot ugent dot be  2008-09-01 18:18 -------
Created an attachment (id=16183)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16183&action=view)
Better and simpler test case

The second test case, asmtest2.i exhibits the bug on even more versions of gcc.
 To run the testcase, do
gcc -O1 -save-temps asmtest2.i -o asmtest2

Consider the following piece of inline assembly (the second one of asmtest2.i):
asm("# ASM 2\n"
    "movl %5, %2\n"
    "movl %4, %0\n"
    "movl %0, %1\n"
    "movl %3, %0\n"
    : "=&a" (c0), "=&rm" (c1), "=&rm" (c2)
    : "rm" (b0), "rm" (b1), "0" (b2)
    : "cc", "%esi", "%edi", "%edx"
);

gcc 4.3.2 compiles this as
movl %eax, -40(%ebp)
movl -24(%ebp), %eax
movl %eax, -44(%ebp)
movl -40(%ebp), %eax

Note that %2 and %3 are both stored in -40(%ebp).  I think this is a bug.

I have tried this with the following versions of gcc, all of which have the
bug: 3.4.6, 4.0.3, 4.1.2, 4.2.4, 4.3.1, 4.3.2


-- 

jdemeyer at cage dot ugent dot be changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #16123|0                           |1
        is obsolete|                            |


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


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

* [Bug inline-asm/37195] unrelated variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
  2008-08-21 21:17 ` [Bug inline-asm/37195] " jdemeyer at cage dot ugent dot be
  2008-09-01 18:19 ` jdemeyer at cage dot ugent dot be
@ 2008-09-01 18:20 ` jdemeyer at cage dot ugent dot be
  2008-09-01 21:26 ` jdemeyer at cage dot ugent dot be
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-01 18:20 UTC (permalink / raw)
  To: gcc-bugs



-- 

jdemeyer at cage dot ugent dot be changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major


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


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

* [Bug inline-asm/37195] unrelated variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (2 preceding siblings ...)
  2008-09-01 18:20 ` jdemeyer at cage dot ugent dot be
@ 2008-09-01 21:26 ` jdemeyer at cage dot ugent dot be
  2008-09-02  8:53 ` jdemeyer at cage dot ugent dot be
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-01 21:26 UTC (permalink / raw)
  To: gcc-bugs



-- 

jdemeyer at cage dot ugent dot be changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jdemeyer at cage dot ugent
                   |                            |dot be
           Severity|major                       |normal
            Version|4.3.2                       |4.4.0


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


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

* [Bug inline-asm/37195] unrelated variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (3 preceding siblings ...)
  2008-09-01 21:26 ` jdemeyer at cage dot ugent dot be
@ 2008-09-02  8:53 ` jdemeyer at cage dot ugent dot be
  2008-09-03  7:59 ` [Bug inline-asm/37195] different " jdemeyer at cage dot ugent dot be
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-02  8:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jdemeyer at cage dot ugent dot be  2008-09-02 08:52 -------
Created an attachment (id=16187)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16187&action=view)
Further testcase simplification

The third testcase uses only "rm" and "=&rm" constraints, which means that it
might not be specific to i386 targets.  I still have to try other targets. 
Note that the bug only occurs if there are sufficiently many registers in the
clobber list (otherwise the compiler just uses registers for everything).


-- 

jdemeyer at cage dot ugent dot be changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #16183|0                           |1
        is obsolete|                            |


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


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

* [Bug inline-asm/37195] different variables get the same memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (4 preceding siblings ...)
  2008-09-02  8:53 ` jdemeyer at cage dot ugent dot be
@ 2008-09-03  7:59 ` jdemeyer at cage dot ugent dot be
  2008-09-29 19:23 ` [Bug inline-asm/37195] different variables get the same overlapping " jdemeyer at cage dot ugent dot be
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-03  7:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jdemeyer at cage dot ugent dot be  2008-09-03 07:57 -------
Created an attachment (id=16200)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16200&action=view)
Testcase for powerpc-unknown-linux-gnu

Also fails on powerpc:
$ gcc -O1 test37195-powerpc.i -save-temps -c -o test37195-powerpc.o
test37195-powerpc.s: Assembler messages:
test37195-powerpc.s:119: Error: ASM 2: %1 and %5 are both equal to 16(1)
test37195-powerpc.s:192: Error: ASM 3: %2 and %5 are both equal to 16(1)

$ gcc -v
Using built-in specs.
Target: powerpc-unknown-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.2.4/work/gcc-4.2.4/configure
--prefix=/usr --bindir=/usr/powerpc-unknown-linux-gnu/gcc-bin/4.2.4
--includedir=/usr/lib/gcc/powerpc-unknown-linux-gnu/4.2.4/include
--datadir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/4.2.4
--mandir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/4.2.4/man
--infodir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/4.2.4/info
--with-gxx-include-dir=/usr/lib/gcc/powerpc-unknown-linux-gnu/4.2.4/include/g++-v4
--host=powerpc-unknown-linux-gnu --build=powerpc-unknown-linux-gnu
--enable-altivec --enable-nls --without-included-gettext --with-system-zlib
--disable-checking --disable-werror --enable-secureplt --disable-multilib
--enable-libmudflap --disable-libssp --disable-libgcj
--enable-languages=c,c++,treelang,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.2.4 (Gentoo 4.2.4 p1.0)


-- 


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


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

* [Bug inline-asm/37195] different variables get the same overlapping memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (5 preceding siblings ...)
  2008-09-03  7:59 ` [Bug inline-asm/37195] different " jdemeyer at cage dot ugent dot be
@ 2008-09-29 19:23 ` jdemeyer at cage dot ugent dot be
  2008-12-25 17:19 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2008-09-29 19:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jdemeyer at cage dot ugent dot be  2008-09-29 19:22 -------
Created an attachment (id=16428)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16428&action=view)
Unified testcase

This testcase exhibits the problem on i386, x86_64, powerpc and powerpc64 using
preprocessor macros.


-- 


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


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

* [Bug inline-asm/37195] different variables get the same overlapping memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (6 preceding siblings ...)
  2008-09-29 19:23 ` [Bug inline-asm/37195] different variables get the same overlapping " jdemeyer at cage dot ugent dot be
@ 2008-12-25 17:19 ` pinskia at gcc dot gnu dot org
  2009-11-21  9:15 ` pinskia at gcc dot gnu dot org
  2010-04-30  7:25 ` jdemeyer at cage dot ugent dot be
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-25 17:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2008-12-25 17:18 -------
Works for me on PPC64 in 4.3.2 but not in 4.1.1.


-- 


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


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

* [Bug inline-asm/37195] different variables get the same overlapping memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (7 preceding siblings ...)
  2008-12-25 17:19 ` pinskia at gcc dot gnu dot org
@ 2009-11-21  9:15 ` pinskia at gcc dot gnu dot org
  2010-04-30  7:25 ` jdemeyer at cage dot ugent dot be
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-21  9:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2009-11-21 09:15 -------
*** Bug 41294 has been marked as a duplicate of this bug. ***


-- 


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


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

* [Bug inline-asm/37195] different variables get the same overlapping memory address in inline assembly
  2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
                   ` (8 preceding siblings ...)
  2009-11-21  9:15 ` pinskia at gcc dot gnu dot org
@ 2010-04-30  7:25 ` jdemeyer at cage dot ugent dot be
  9 siblings, 0 replies; 11+ messages in thread
From: jdemeyer at cage dot ugent dot be @ 2010-04-30  7:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jdemeyer at cage dot ugent dot be  2010-04-30 07:24 -------
On first sight, it looks fixed in gcc 4.6.0 SVN.


-- 


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


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

end of thread, other threads:[~2010-04-30  7:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-21 21:15 [Bug inline-asm/37195] New: unrelated variables get the same memory address in inline assembly jdemeyer at cage dot ugent dot be
2008-08-21 21:17 ` [Bug inline-asm/37195] " jdemeyer at cage dot ugent dot be
2008-09-01 18:19 ` jdemeyer at cage dot ugent dot be
2008-09-01 18:20 ` jdemeyer at cage dot ugent dot be
2008-09-01 21:26 ` jdemeyer at cage dot ugent dot be
2008-09-02  8:53 ` jdemeyer at cage dot ugent dot be
2008-09-03  7:59 ` [Bug inline-asm/37195] different " jdemeyer at cage dot ugent dot be
2008-09-29 19:23 ` [Bug inline-asm/37195] different variables get the same overlapping " jdemeyer at cage dot ugent dot be
2008-12-25 17:19 ` pinskia at gcc dot gnu dot org
2009-11-21  9:15 ` pinskia at gcc dot gnu dot org
2010-04-30  7:25 ` jdemeyer at cage dot ugent dot be

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