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

             Bug #: 50943
           Summary: asm goto in templated code causes internal compiler
                    segfaults
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: dummy...@gmail.com


Created attachment 25675
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25675
The code that causes a segfault

I tested the code in mingw-tdm64 4.5.2, 4.6.1, and under the mac port for
4.6.1, all with the same result.

$ gcc-fsf-4.6 -v -save-temps main.cpp
Using built-in specs.
COLLECT_GCC=gcc-fsf-4.6
COLLECT_LTO_WRAPPER=/sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.1.0/4.6.1/lto-wrapper
Target: x86_64-apple-darwin11.1.0
Configured with: ../gcc-4.6.1/configure --prefix=/sw
--prefix=/sw/lib/gcc4.6 --mandir=/sw/share/man
--infodir=/sw/lib/gcc4.6/info
--enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw
--with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw
--with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include
--x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.6
--enable-cloog-backend=isl
Thread model: posix
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.7.2' '-v' '-save-temps'
'-mtune=core2'
 /sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.1.0/4.6.1/cc1plus -E
-quiet -v -D__DYNAMIC__ main.cpp -fPIC -mmacosx-version-min=10.7.2
-mtune=core2 -fpch-preprocess -o main.ii
ignoring nonexistent directory
"/sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../x86_64-apple-darwin11.1.0/include"
#include "..." search starts here:
#include <...> search starts here:

/sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../include/c++/4.6.1

/sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../include/c++/4.6.1/x86_64-apple-darwin11.1.0

/sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/../../../../include/c++/4.6.1/backward
 /sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/include
 /usr/local/include
 /sw/lib/gcc4.6/include
 /sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.1.0/4.6.1/include-fixed
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.7.2' '-v' '-save-temps'
'-mtune=core2'
 /sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.1.0/4.6.1/cc1plus
-fpreprocessed main.ii -fPIC -quiet -dumpbase main.cpp
-mmacosx-version-min=10.7.2 -mtune=core2 -auxbase main -version -o main.s
GNU C++ (GCC) version 4.6.1 (x86_64-apple-darwin11.1.0)
       compiled by GNU C version 4.6.1, GMP version 5.0.2, MPFR version 3.0.1,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 4.6.1 (x86_64-apple-darwin11.1.0)
       compiled by GNU C version 4.6.1, GMP version 5.0.2, MPFR version 3.0.1,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b15fbe702f97b74ba102fe17491ae6a1
main.cpp: In function ‘bool work(int*, int) [with T = int]’:
main.cpp:15:1: internal compiler error: Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ cat main.ii
# 1 "main.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.cpp"

template<class T>
bool work(int* data, int bit) {
    asm goto("lock and %0, %1;"
             "jz %l[other]"
    : : "r"(~(1 << bit)), "m"(data) : : other);
    return false;
other:
    return true;
}

int main(int argc, char** argv) {
    int data = 2;
    work<int>(&data, data);
    return 0;
}

Reply via email to