User account creation filtered due to spam.

Bug 7754 - ICE SIGSEGV on union with template parameter
Summary: ICE SIGSEGV on union with template parameter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: ---
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2002-08-28 18:16 UTC by dv
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dv 2002-08-28 18:16:01 UTC
	Segmentation fault wrapped as ICE for a union with a member
	whose type is a template parameter of surrounding function.

Release:
3.3 20020828 (experimental)

Environment:
System: Linux octo 2.4.18-xfs-1.1 #1 Mon Jul 1 05:12:32 MEST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /dwarf/pdsrc/gcc/cvs/gcc/configure --program-suffix=-test --prefix=/usr/local/gcc-test --enable-shared --enable-threads=posix --enable-version-specific-runtime-libs --enable-languages=c,c++

How-To-Repeat:

bug.cpp:
template <typename T> void f(T const &t)
{
    union { char c; T t_; }; // compile time check for T==POD
}
	gcc -c bug.cpp
Comment 2 Nathan Sidwell 2002-09-13 14:04:22 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed as a regression
Comment 3 pop 2002-09-29 10:29:05 UTC
From: =?iso-8859-1?Q?Pop_S=E9bastian?= <pop@gauvain.u-strasbg.fr>
To: nathan@gcc.gnu.org, dv@vollmann.ch, gcc-bugs@gcc.gnu.org,
	gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc: aoliva@redhat.com
Subject: Re: c++/7754: ICE SIGSEGV on union with template parameter
Date: Sun, 29 Sep 2002 10:29:05 +0200

 On Fri, Sep 13, 2002 at 09:04:23PM -0000, nathan@gcc.gnu.org wrote:
 > Synopsis: ICE SIGSEGV on union with template parameter
 > 
 > State-Changed-From-To: open->analyzed
 > State-Changed-By: nathan
 > State-Changed-When: Fri Sep 13 14:04:22 2002
 > State-Changed-Why:
 >     confirmed as a regression
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7754
 
 SIGSEGV happens in tree.c:
 
 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
    The precise way of comparison depends on their data type.  */
 
 int
 tree_int_cst_lt (t1, t2)
      tree t1, t2;
 {
   if (t1 == t2)
     return 0;
 
 =>if (TREE_UNSIGNED (TREE_TYPE (t1)) != TREE_UNSIGNED (TREE_TYPE (t2)))
     {
       int t1_sgn = tree_int_cst_sgn (t1);
       int t2_sgn = tree_int_cst_sgn (t2);
 
       if (t1_sgn < t2_sgn)
         return 1;
       else if (t1_sgn > t2_sgn)
         return 0;
       /* Otherwise, both are non-negative, so we compare them as
          unsigned just in case one of them would overflow a signed
          type.  */
     }
   else if (! TREE_UNSIGNED (TREE_TYPE (t1)))
     return INT_CST_LT (t1, t2);
 
   return INT_CST_LT_UNSIGNED (t1, t2);
 }
 
 
 At this point t2 is equal to 0, and that crashes the compiler.
 
 The following patch introduced this code without checking of non-NULL for t2:
 
 2002-04-26  Alexandre Oliva  <aoliva@redhat.com>
 http://gcc.gnu.org/ml/gcc-patches/2002-04/msg01549.html
 
 
 Alexandre, could you review this patch and the associated bug-report please?
 
 Thanks, 
 Sebastian
Comment 4 Mark Mitchell 2002-10-03 00:05:02 UTC
Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-Why: Working on a fix.
Comment 5 Mark Mitchell 2002-10-03 22:25:08 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed in G++ 3.2.1.
Comment 6 Mark Mitchell 2002-10-04 05:13:59 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7754
Date: 4 Oct 2002 05:13:59 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-03 22:13:59
 
 Modified files:
 	gcc/cp         : ChangeLog decl2.c pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/template: ptrmem3.C union1.C 
 
 Log message:
 	PR c++/7931
 	* pt.c (for_each_template_parm_r): Handle BASELINKs.
 	
 	PR c++/7754
 	* decl2.c (finish_anon_union): Do not expand anonymous unions when
 	procesing template functions.
 	* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
 	type. Call layout_decl.
 	(tsubst_expr, case DECL_STMT): Handle anonymous unions.
 	
 	PR c++/7931
 	* g++.dg/template/ptrmem3.C: New test.
 	
 	PR c++/7754
 	* g++.dg/template/union1.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2981&r2=1.2982
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.563&r2=1.564
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.620&r2=1.621
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2118&r2=1.2119
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/union1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 

Comment 7 Mark Mitchell 2002-10-04 05:13:59 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7754
Date: 4 Oct 2002 05:13:59 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-03 22:13:59
 
 Modified files:
 	gcc/cp         : ChangeLog decl2.c pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/template: ptrmem3.C union1.C 
 
 Log message:
 	PR c++/7931
 	* pt.c (for_each_template_parm_r): Handle BASELINKs.
 	
 	PR c++/7754
 	* decl2.c (finish_anon_union): Do not expand anonymous unions when
 	procesing template functions.
 	* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
 	type. Call layout_decl.
 	(tsubst_expr, case DECL_STMT): Handle anonymous unions.
 	
 	PR c++/7931
 	* g++.dg/template/ptrmem3.C: New test.
 	
 	PR c++/7754
 	* g++.dg/template/union1.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2981&r2=1.2982
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.563&r2=1.564
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.620&r2=1.621
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2118&r2=1.2119
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/union1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 
Comment 8 Mark Mitchell 2002-10-04 05:25:16 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7754
Date: 4 Oct 2002 05:25:16 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-03 22:25:16
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 	gcc/cp         : ChangeLog decl2.c pt.c 
 Added files:
 	gcc/testsuite/g++.dg/template: union1.C 
 
 Log message:
 	PR c++/7754
 	* decl2.c (finish_anon_union): Do not expand anonymous unions when
 	procesing template functions.
 	* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
 	type. Call layout_decl.
 	(tsubst_expr, case DECL_STMT): Handle anonymous unions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.19&r2=1.1672.2.166.2.20
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/union1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.10&r2=1.2685.2.114.2.11
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.520.2.7.2.3&r2=1.520.2.7.2.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.578.2.11.2.1&r2=1.578.2.11.2.2
 

Comment 9 Mark Mitchell 2002-10-08 22:52:14 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7754
Date: 8 Oct 2002 22:52:14 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-08 15:52:14
 
 Modified files:
 	gcc/cp         : ChangeLog decl2.c pt.c 
 
 Log message:
 	PR c++/7754
 	* decl2.c (finish_anon_union): Do not expand anonymous unions when
 	procesing template functions.
 	* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
 	type. Call layout_decl.
 	(tsubst_expr, case DECL_STMT): Handle anonymous unions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2984&r2=1.2985
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.565&r2=1.566
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.622&r2=1.623
 

Comment 10 Mark Mitchell 2002-10-08 22:53:22 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7754
Date: 8 Oct 2002 22:53:22 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-08 15:53:22
 
 Modified files:
 	gcc/cp         : ChangeLog decl2.c pt.c 
 
 Log message:
 	PR c++/7754
 	* decl2.c (finish_anon_union): Do not expand anonymous unions when
 	procesing template functions.
 	* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
 	type. Call layout_decl.
 	(tsubst_expr, case DECL_STMT): Handle anonymous unions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.14&r2=1.2685.2.114.2.15
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.520.2.7.2.5&r2=1.520.2.7.2.6
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.578.2.11.2.3&r2=1.578.2.11.2.4