public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/24761]  New: Missing register load before inline asm in templated function causes SIGSEGV
@ 2005-11-09 19:43 krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 19:46 ` [Bug inline-asm/24761] " krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: krzysiek-gcc dot gnu dot org at lichota dot net @ 2005-11-09 19:43 UTC (permalink / raw)
  To: gcc-bugs

I have a templated function which uses inline assembler (with MMX
instructions). Inline assembler is passed pointer to array element.
When this function is instantiated for the first time, code before inline
assembler is generated correctly. When it is instantiated for the second time,
one of registers used in inline assembler is not loaded from stack and causes
segfault when it is dereferenced in inline assembler.

I will attach test case.


g++-4.0 -v:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.2 (Debian 4.0.2-2)


-- 
           Summary: Missing register load before inline asm in templated
                    function causes SIGSEGV
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: krzysiek-gcc dot gnu dot org at lichota dot net
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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


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

* [Bug inline-asm/24761] Missing register load before inline asm in templated function causes SIGSEGV
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
@ 2005-11-09 19:46 ` krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 19:50 ` krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: krzysiek-gcc dot gnu dot org at lichota dot net @ 2005-11-09 19:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from krzysiek-gcc dot gnu dot org at lichota dot net  2005-11-09 19:46 -------
Created an attachment (id=10193)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10193&action=view)
Testcase for the bug

This is the testcase. Compile with:
g++-4.0 -save-temps -fPIC -ggdb3 -Wno-non-virtual-dtor -O0 -pthread
-fkeep-inline-functions testcase10.cpp

When both calls to bar() are instantiated, the segfault occurs.
When only one is instantiated (the other is commented out), it works correctly.


-- 


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


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

* [Bug inline-asm/24761] Missing register load before inline asm in templated function causes SIGSEGV
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 19:46 ` [Bug inline-asm/24761] " krzysiek-gcc dot gnu dot org at lichota dot net
@ 2005-11-09 19:50 ` krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 20:00 ` krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: krzysiek-gcc dot gnu dot org at lichota dot net @ 2005-11-09 19:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from krzysiek-gcc dot gnu dot org at lichota dot net  2005-11-09 19:49 -------
Created an attachment (id=10195)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10195&action=view)
Assembler code generated from testcase

This is code generated from testcase.
In first instantiation eax register is loaded before inline asm starts:
        .loc 1 25 0
        movl    -16(%ebp), %eax
        addl    -20(%ebp), %eax
        sall    $2, %eax
        addl    8(%ebp), %eax
        movl    %eax, -8(%ebp)
        .loc 1 41 0
        movl    -16(%ebp), %eax
        addl    -24(%ebp), %eax
        sall    $2, %eax
        movl    %eax, %edx
        addl    -12(%ebp), %edx
        movl    -8(%ebp), %eax
#APP
               movq   (%edx), %mm0   ;

In the second instantiation, eax is not loaded:
        .loc 1 25 0
        movl    -16(%ebp), %eax
        addl    -20(%ebp), %eax
        sall    $2, %eax
        addl    8(%ebp), %eax
        movl    %eax, -8(%ebp)
        .loc 1 41 0
        movl    -16(%ebp), %eax
        addl    -24(%ebp), %eax
        sall    $2, %eax
        movl    %eax, %edx
        addl    -12(%ebp), %edx
#APP
               movq   (%edx), %mm0   ;

Then in line:
       pxor   (%eax), %mm0   ;

eax is dereferenced and segfault occurs.


-- 


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


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

* [Bug inline-asm/24761] Missing register load before inline asm in templated function causes SIGSEGV
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 19:46 ` [Bug inline-asm/24761] " krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 19:50 ` krzysiek-gcc dot gnu dot org at lichota dot net
@ 2005-11-09 20:00 ` krzysiek-gcc dot gnu dot org at lichota dot net
  2005-11-09 20:24 ` [Bug c++/24761] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: krzysiek-gcc dot gnu dot org at lichota dot net @ 2005-11-09 20:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from krzysiek-gcc dot gnu dot org at lichota dot net  2005-11-09 20:00 -------
Created an attachment (id=10196)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10196&action=view)
Correct code generated by g++ 3.4.2

This is the correct code generated by g++ 3.4.2. It loads eax before inline asm
starts in both instantiations.


-- 


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


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

* [Bug c++/24761] [4.0/4.1 Regression] Missing register load before inline asm in templated function causes SIGSEGV
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (2 preceding siblings ...)
  2005-11-09 20:00 ` krzysiek-gcc dot gnu dot org at lichota dot net
@ 2005-11-09 20:24 ` pinskia at gcc dot gnu dot org
  2005-11-09 20:28 ` [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+" pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-09 20:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2005-11-09 20:24 -------
Simplified example:
template <int>
int f(int i)
{
  asm("%0 %1 " : "+r"(i) );
  return i;
}

int main(void)
{
  f<0>(0)+ f<1>(0);
}
-----


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
          Component|inline-asm                  |c++
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |2.95.3 4.0.0 4.1.0
      Known to work|                            |3.4.0 3.3.3 3.2.3 3.0.4
   Last reconfirmed|0000-00-00 00:00:00         |2005-11-09 20:24:19
               date|                            |
            Summary|Missing register load before|[4.0/4.1 Regression] Missing
                   |inline asm in templated     |register load before inline
                   |function causes SIGSEGV     |asm in templated function
                   |                            |causes SIGSEGV
   Target Milestone|---                         |4.0.3


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


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

* [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+"
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (3 preceding siblings ...)
  2005-11-09 20:24 ` [Bug c++/24761] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-11-09 20:28 ` pinskia at gcc dot gnu dot org
  2005-11-10  9:03 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-09 20:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2005-11-09 20:28 -------
For the first time template is instantiated, we get:
__asm__("%0 %1 ":"=r" i:"0" i);

The second time, we get:
__asm__("%0 %1 ":"=r" i:);

Somehow we brought back a bug from 2.95.3 (weird isn't it).


-- 


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


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

* [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+"
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (4 preceding siblings ...)
  2005-11-09 20:28 ` [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+" pinskia at gcc dot gnu dot org
@ 2005-11-10  9:03 ` jakub at gcc dot gnu dot org
  2005-11-12 20:42 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-11-10  9:03 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-11-09 20:24:19         |2005-11-10 09:03:35
               date|                            |


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


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

* [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+"
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (5 preceding siblings ...)
  2005-11-10  9:03 ` jakub at gcc dot gnu dot org
@ 2005-11-12 20:42 ` jakub at gcc dot gnu dot org
  2005-11-12 20:43 ` jakub at gcc dot gnu dot org
  2005-11-12 22:13 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-11-12 20:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2005-11-12 20:42 -------
Subject: Bug 24761

Author: jakub
Date: Sat Nov 12 20:42:23 2005
New Revision: 106831

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106831
Log:
        PR c++/24761
        * pt.c (tsubst_copy_asm_operands): New function.
        (tsubst_expr) <case ASM_EXPR>: Use it.

        * g++.dg/template/asm1.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/asm1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+"
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (6 preceding siblings ...)
  2005-11-12 20:42 ` jakub at gcc dot gnu dot org
@ 2005-11-12 20:43 ` jakub at gcc dot gnu dot org
  2005-11-12 22:13 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-11-12 20:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jakub at gcc dot gnu dot org  2005-11-12 20:43 -------
Subject: Bug 24761

Author: jakub
Date: Sat Nov 12 20:43:27 2005
New Revision: 106832

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106832
Log:
        PR c++/24761
        * pt.c (tsubst_copy_asm_operands): New function.
        (tsubst_expr) <case ASM_EXPR>: Use it.

        * g++.dg/template/asm1.C: New test.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/asm1.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/pt.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+"
  2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
                   ` (7 preceding siblings ...)
  2005-11-12 20:43 ` jakub at gcc dot gnu dot org
@ 2005-11-12 22:13 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-12 22:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2005-11-12 22:13 -------
Fixed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-11-12 22:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-09 19:43 [Bug inline-asm/24761] New: Missing register load before inline asm in templated function causes SIGSEGV krzysiek-gcc dot gnu dot org at lichota dot net
2005-11-09 19:46 ` [Bug inline-asm/24761] " krzysiek-gcc dot gnu dot org at lichota dot net
2005-11-09 19:50 ` krzysiek-gcc dot gnu dot org at lichota dot net
2005-11-09 20:00 ` krzysiek-gcc dot gnu dot org at lichota dot net
2005-11-09 20:24 ` [Bug c++/24761] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-11-09 20:28 ` [Bug c++/24761] [4.0/4.1 Regression] templates and inline-asm and "+" pinskia at gcc dot gnu dot org
2005-11-10  9:03 ` jakub at gcc dot gnu dot org
2005-11-12 20:42 ` jakub at gcc dot gnu dot org
2005-11-12 20:43 ` jakub at gcc dot gnu dot org
2005-11-12 22:13 ` 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).