User account creation filtered due to spam.

Bug 15057 - [3.4 Regression] Compiling of conditional value throw constructs cause a segmentation violation
Summary: [3.4 Regression] Compiling of conditional value throw constructs cause a segm...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 critical
Target Milestone: 3.4.1
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2004-04-21 20:47 UTC by Christian Groove
Modified: 2004-09-09 23:40 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Groove 2004-04-21 20:47:53 UTC
Hy there 
 
first of all, the new gcc-3.4 is a real improvement. 
It is definitivly better the the gcc-3.3.1 is used before, 
thanks for your work. 
 
OK, here is the bug: The following throw construct cause 
a crash of g++ when compiling this (taken from TOra-Tool): 
 
	throw (<conditional>) ? <exprA> : <exprB> ; 
 
A workaround for this is the follwing: 
 
static retType __eval(  ) 
{ 
	if <conditional> 
		return <exprA> 
	else 
		return <exprB> 
} 
 
 
I had to do this in order to make the tool TOra to 
compile. 
 
Thanks
Comment 1 Andrew Pinski 2004-04-21 20:51:52 UTC
I think this is invalid as the compile needs to do a copy of the expression but I do not know until I look 
into the full preprocessed source as there is non yet.
Comment 2 Wolfgang Bangerth 2004-04-21 21:02:53 UTC
It's also a good question whether we get 
  throw (c) ? a : b; 
right in the sense that it means 
  throw ((c) ? a : b) 
and not 
  (throw (c)) ? a : b 
 
But just as Andrew said: no preprocessed sources, no definite answer. 
 
W. 
Comment 3 Christian Groove 2004-04-22 20:26:53 UTC
(In reply to comment #1) 
> I think this is invalid as the compile needs to do a copy of the expression 
> but I do not know until I look  
> into the full preprocessed source as there is non yet. 
 
The construct ist correct. It worked also in some 
previously version of G++ and other c++ compilers 
too ! 
The only think that has to be make sure is that the 
types of the conditional structure is unequivocally. 
Anyway my replacement was correct, so the conditional 
must be correct too ! 
 
 
Comment 4 Wolfgang Bangerth 2004-04-22 22:06:16 UTC
How can we say if you don't provide us with a testcase? 
 
W. 
Comment 5 Christian Groove 2004-04-23 22:16:02 UTC
(In reply to comment #4) 
> How can we say if you don't provide us with a testcase?  
>   
> W.  
 
Here we are: 
 
 
#include <stdio.h> 
#include <string.h> 
 
 
char *  null = (char *) 0 ; 
 
 
// simple exception class  
class errMessage 
{ 
	private: char		messag[20] ; 
	private: int			kind; 
 
	public: errMessage(char* msg, int knd) 
	{ 
		strncpy(messag,msg,19) ; 
		kind = knd ; 
	}; 
}; 
 
 
// the error causing method 
int simpleDepp(char* m1)  
{ 
	puts ("having some troubles") ; 
 
 
 
	if (m1 == (void *) 0) 
	{ 
		throw errMessage("forget me", 23) ; 
	} 
	else 
	{ 
		throw (null == m1) ?  
			errMessage("panic", 23) :  
			errMessage(m1, 23) ; 
	} 
} 
 
 
int main (int argc, char** argv) 
{ 
	try 
	{ 
		const int egal = simpleDepp(null) ; 
	} 
	catch(errMessage er) 
	{ 
		puts("caught something") ; 
	} 
} 
 
Comment 6 Andrew Pinski 2004-04-23 22:27:51 UTC
I think I miss understood you when you said it seg faulted, I thought the resulting program was 
segfaulting and not GCC.

Confirmed in 3.4.0.
Was not broken in 3.3.3, already fixed in 3.5.0.

Here is the backtrace:
539       if (TYPE_P (exp))
(gdb) bt
#0  wrap_cleanups_r (tp=0x808f30e, walk_subtrees=0x808f30e, data=0x0) at ../../gcc/cp/except.c:
539
#1  0x08303092 in walk_tree (tp=0x808f30e, func=0x80aaa90 <wrap_cleanups_r>, data=0x0, 
htab_=0x84b64f0)
    at ../../gcc/tree-inline.c:1748
#2  0x08303166 in walk_tree (tp=0xbffeb94c, func=0x80aaa90 <wrap_cleanups_r>, data=0x0, 
htab_=0x84b64f0)
    at ../../gcc/tree-inline.c:1796
#3  0x08303166 in walk_tree (tp=0xbffeb928, func=0x80aaa90 <wrap_cleanups_r>, data=0x0, 
htab_=0x84b64f0)
    at ../../gcc/tree-inline.c:1796
#4  0x083035cb in walk_tree_without_duplicates (tp=0x808f30e, func=0x808f30e 
<cp_lexer_next_token_is_keyword+30>,
    data=0x808f30e) at ../../gcc/tree-inline.c:1955
#5  0x080ab1ac in build_throw (exp=0x4019c648) at ../../gcc/cp/except.c:704
#6  0x0809110e in cp_parser_assignment_expression (parser=0x40128580) at ../../gcc/cp/parser.c:
13141
#7  0x08091857 in cp_parser_expression (parser=0x40128580) at ../../gcc/cp/parser.c:5289
#8  0x080919da in cp_parser_expression_statement (parser=0x40128580, in_statement_expr_p=false)
    at ../../gcc/cp/parser.c:5593
#9  0x08095477 in cp_parser_statement (parser=0x40128580, in_statement_expr_p=false) at ../../
gcc/cp/parser.c:5477
#10 0x08095a9b in cp_parser_compound_statement (parser=0x40128580) at ../../gcc/cp/parser.c:
5658
#11 0x08099ad9 in cp_parser_implicitly_scoped_statement (parser=0x40128580) at ../../gcc/cp/
parser.c:6150
#12 0x08095950 in cp_parser_statement (parser=0x40128580, in_statement_expr_p=false) at ../../
gcc/cp/parser.c:5730
#13 0x08095a9b in cp_parser_compound_statement (parser=0x40128580) at ../../gcc/cp/parser.c:
5658
#14 0x0809927e in cp_parser_ctor_initializer_opt_and_function_body (parser=0x40128580) at ../../
gcc/cp/parser.c:11339
#15 0x0809950f in cp_parser_function_definition_after_declarator (parser=0x40128580, 
inline_p=false)
    at ../../gcc/cp/parser.c:14206
#16 0x0809991d in cp_parser_init_declarator (parser=0x40128580, decl_specifiers=0x4019f9d8, 
prefix_attributes=0x0,
    function_definition_allowed_p=true, member_p=false, declares_class_or_enum=0, 
function_definition_p=0xbffebb47)
    at ../../gcc/cp/parser.c:14151
#17 0x08094e02 in cp_parser_simple_declaration (parser=0x40128580, 
function_definition_allowed_p=true)
    at ../../gcc/cp/parser.c:6481
#18 0x08094f68 in cp_parser_block_declaration (parser=0x40128580, statement_p=false) at ../../gcc/
cp/parser.c:6397
#19 0x0809a2df in cp_parser_declaration (parser=0x40128580) at ../../gcc/cp/parser.c:6317
#20 0x0809a55f in cp_parser_declaration_seq_opt (parser=0x40128580) at ../../gcc/cp/parser.c:6226
#21 0x0809a72b in c_parse_file () at ../../gcc/cp/parser.c:2319
#22 0x080ec0e2 in c_common_parse_file (set_yydebug=134804238) at ../../gcc/c-opts.c:1237
#23 0x082cc21d in toplev_main (argc=134804238, argv=0xbffebfae) at ../../gcc/toplev.c:1822
#24 0x080ef8de in main (argc=134804238, argv=0x808f30e) at ../../gcc/main.c:35
Comment 7 Wolfgang Bangerth 2004-04-24 05:38:54 UTC
Interesting: by simple variations of the source code, I seem to be able 
to trigger ICEs in about every single function of the compiler. Anyway, here 
is something pretty small: 
----------- 
class S  
{ 
  public: 
    S(){} 
};  
  
int foo(char* m1) {  
  throw (m1 ? S() : S()); 
} 
------------ 
 
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/c++ -c x.cc          
 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc 
x.cc: In function `int foo(char*)': 
x.cc:8: 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. 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -c x.cc 
 
W. 
Comment 8 Mark Mitchell 2004-06-05 20:19:59 UTC
Working on a fix.
Comment 9 CVS Commits 2004-06-07 15:52:31 UTC
Subject: Bug 15057

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:52:23

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.470&r2=2.2326.2.471
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.476.4.6&r2=1.476.4.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.115&r2=1.3892.2.116
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.164.4.4&r2=1.164.4.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.31&r2=1.157.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.28&r2=1.816.2.29
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.197&r2=1.3389.2.198
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 10 CVS Commits 2004-06-07 15:54:23 UTC
Subject: Bug 15057

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:54:15

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3859&r2=2.3860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.509&r2=1.510
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4083&r2=1.4084
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&r1=1.167&r2=1.168
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.200&r2=1.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.859&r2=1.860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3816&r2=1.3817
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 11 Mark Mitchell 2004-06-07 16:25:08 UTC
Fixed in GCC 3.4.1.