This bug applies to gcc 4.0 and 4.1.

The following code:

--- snip here ---
extern void Assert( const char *file, int linenum, const char *function,
               const char *condition, int &ignoreflag);

#define ASSERT(ZZ)       \
    {   static int ignore = 0; \
            if( !ignore && !(ZZ) ) \
                            Assert( __FILE__, __LINE__, __PRETTY_FUNCTION__,
#ZZ, ignore); }

class foo
{
    public:
        int x;
};

class bar
{
    public:
        foo f;
};

bar *
testcase()
{
    bar *r = new bar();
    foo *f = &r->f;
    ASSERT((void *)f == (void *)r);
    return r;
}

--- snip here ---

causes a segfault:

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java
--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-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060730 (prerelease) (Debian 4.0.3-6)

$ g++ -c -O testcase.C -o testcase.o
distcc[30704] ERROR: compile /home/joe/.ccache/testcase.tmp.barstow.30700.ii on
localhost failed
testcase.C: In function 'bar* testcase()':
testcase.C:20: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions,
see <URL:file:///usr/share/doc/gcc-4.0/README.Bugs>.

$ g++-4.1 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060729 (prerelease) (Debian 4.1.1-10)
$ g++-4.1 -c -O testcase.C -o testcase.o
testcase.C: In function 'bar* testcase()':
testcase.C:20: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions,
see <URL:file:///usr/share/doc/gcc-4.1/README.Bugs>.

Removing the ASSERT, or changing the assert to "if ((void *)f == (void *)r)",
causes the crash to go away.


-- 
           Summary: ICE (segfault) when comparing pointers with -O (and
                    higher)
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hoserhead at woot dot net
 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=28683

Reply via email to