Bug 10635 - [3.3/3.4 regression] ICE (segfault) when dereferencing an incomplete type casted from a void pointer
Summary: [3.3/3.4 regression] ICE (segfault) when dereferencing an incomplete type cas...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 3.3.1
Assignee: Mark Mitchell
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2003-05-06 03:36 UTC by shea.williams
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-02 11:34:50


Attachments
moc_timelabel.ii (145.47 KB, text/x-c++)
2003-05-21 15:17 UTC, shea.williams
Details

Note You need to log in before you can comment on or make changes to this bug.
Description shea.williams 2003-05-06 03:36:01 UTC
command below produces this:
 /usr/lib/gcc-lib/i386-linux/3.2.3/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -I/home/williasp/payload/src/include -I/usr/local/qt-x11-free-3.0.6/include -I/home/williasp/payload/generic-sw/src/gstaci-framework/include -I/home/williasp/payload/generic-sw/src/gstaci-framework/built-source -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ moc_timelabel.cpp -Wall moc_timelabel.ii
ignoring nonexistent directory "/home/williasp/payload/src/include"
GNU CPP version 3.2.3 20030415 (Debian prerelease) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/qt-x11-free-3.0.6/include
 /home/williasp/payload/generic-sw/src/gstaci-framework/include
 /home/williasp/payload/generic-sw/src/gstaci-framework/built-source
 /usr/include/c++/3.2
 /usr/include/c++/3.2/i386-linux
 /usr/include/c++/3.2/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-linux/3.2.3/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-linux/3.2.3/cc1plus -fpreprocessed moc_timelabel.ii -quiet -dumpbase moc_timelabel.cpp -gstabs -Wall -version -o moc_timelabel.s
GNU CPP version 3.2.3 20030415 (Debian prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.3 20030415 (Debian prerelease) (i386-linux)
        compiled by GNU C version 3.2.3 20030415 (Debian prerelease).
moc_timelabel.cpp: In member function `virtual bool TimeLabel::qt_invoke(int, 
   QUObject*)':
moc_timelabel.cpp:84: internal error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Release:
gcc version 3.2.3 20030415 (Debian prerelease)

Environment:
Debian GNU/Linux Sarge/Sid distribution
g++ -v produces:
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3 20030415 (Debian prerelease)

How-To-Repeat:
All I did was run the following:

g++ -Wall -I/home/williasp/payload/src/include -I/usr/local/qt-x11-free-3.0.6/include -I/home/williasp/payload/generic-sw/src/gstaci-framework/include -I/home/williasp/payload/generic-sw/src/gstaci-framework/built-source -gstabs -c moc_timelabel.cpp -o moc_timelabel.o
Comment 1 Giovanni Bajo 2003-05-06 10:43:57 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed, it ICEs 3.3 CVS 20030503 and 3.4 CVS 20030503.
    
    ------------------------------------------------------
    struct INCOMPLETE;
    
    void* foo(void);
    
    struct Foo
    {
        void get_incomplete(INCOMPLETE );
        
        void bar(void)
        {
            get_incomplete((INCOMPLETE) *((INCOMPLETE*)foo())); 
        }
    };
    ------------------------------------------------------
    pr10635.cpp: In member function `void Foo::bar()':
    pr10635.cpp:11: internal compiler error: Segmentation fault
    
    The code is illegal because it is trying to use an
    incomplete type (in the original code: QDateTime was not
    yet defined when TimeLabel::qt_invoke() is compiled,
    probably it's just a matter of including one more header).
    
    Not a regression: 2.95 had an accept-illegal on this, so
    it's slightly better now, the code is rejected (even if not
    gracefully).
Comment 2 Giovanni Bajo 2003-05-12 19:43:17 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-prs@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<gcc-gnats@gcc.gnu.org>,
	<Shea.Williams@colorado.edu>,
	<nobody@gcc.gnu.org>
Cc:  
Subject: Re: c++/10635: [3.3/3.4 regression] ICE (segfault) when dereferencing an incomplete type casted from a void pointer
Date: Mon, 12 May 2003 19:43:17 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10635
 
 After analyzing a duplicate of this (c++/10727), I noticed that if I move
 the function get_incomplete() outside the Foo class (in the reduced snippet
 above), GCC 2.95 correctly rejects the code. Thus, I mark this as a
 regression, since the behaviour on this issue is globally worse than it used
 to be.
 Notice that this happens with moc code generated by Qt, so it's very
 important to fix this.
 
 Giovanni Bajo
Comment 3 Volker Reichelt 2003-06-02 11:34:50 UTC
Here's a shorter testcase that ICE's since gcc 3.0:

-----------------------------------------------
struct A;

void foo(A);

void bar(A* p)
{
    foo((A) *p);
}
-----------------------------------------------
Comment 4 GCC Commits 2003-06-12 17:21:46 UTC
Subject: Bug 10635

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-06-12 17:21:40

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog typeck.c 
Added files:
	gcc/testsuite/g++.dg/expr: cast1.C 

Log message:
	PR c++/10635
	* typeck.c (build_c_cast): Check that the destination type is
	complete.
	
	PR c++/10635
	* g++.dg/expr/cast1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2763&r2=1.2764
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/cast1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3415&r2=1.3416
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.463&r2=1.464

Comment 5 GCC Commits 2003-06-12 17:21:47 UTC
Subject: Bug 10635

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-06-12 17:21:40

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog typeck.c 
Added files:
	gcc/testsuite/g++.dg/expr: cast1.C 

Log message:
	PR c++/10635
	* typeck.c (build_c_cast): Check that the destination type is
	complete.
	
	PR c++/10635
	* g++.dg/expr/cast1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2763&r2=1.2764
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/cast1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3415&r2=1.3416
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.463&r2=1.464

Comment 8 GCC Commits 2003-06-12 17:24:11 UTC
Subject: Bug 10635

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-06-12 17:24:07

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 

Log message:
	PR c++/10635
	* typeck.c (build_c_cast): Check that the destination type is
	complete.
	
	PR c++/10635
	* g++.dg/expr/cast1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.145&r2=1.3076.2.146
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.184&r2=1.2261.2.185

Comment 9 GCC Commits 2003-06-12 17:24:12 UTC
Subject: Bug 10635

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-06-12 17:24:07

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 

Log message:
	PR c++/10635
	* typeck.c (build_c_cast): Check that the destination type is
	complete.
	
	PR c++/10635
	* g++.dg/expr/cast1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.145&r2=1.3076.2.146
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.184&r2=1.2261.2.185

Comment 10 Mark Mitchell 2003-06-12 17:28:56 UTC
Fixed with attached patch in GCC 3.3.1, GCC 3.4.