This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] More fallout from Fix PR c++/28250: ICE with invalid catch


On 20 Jul, Volker Reichelt wrote:
> On 16 Jul, Mark Mitchell wrote:
>> Volker Reichelt wrote:
>> 
>>> 2006-07-14  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
>>> 
>>> 	PR c++/28250
>>> 	* name-lookup.c (pushdecl_maybe_friend): Return early on
>>> 	error_mark_node.
>>> 	* except.c (expand_start_catch_block): Use error_mark_node instead
>>> 	of NULL_TREE for invalid decls.
>>> 	* parser.c (cp_parser_exception_declaration): Return error_mark_node
>>> 	on invalid catch parameter. Simplify.
>> 
>> OK, thanks.

Alas there's even more fallout from the patch for PR 28250. :-(
The compiler now ICE's on the following code snippet:

  void foo()
  {
    try { throw; }
    catch () {}
  }

bug.cc: In function 'void foo()':
bug.cc:4: error: expected type-specifier before ')' token
bug.cc:4: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]

The segfault happens deep in the bowels of the middle-end:

  #0  remove_useless_stmts_1 (tp=0x2aaaaaf831f0, data=0x7fffffd8b670)
      at tree-iterator.h:93
  #1  0x0000000000546aa4 in remove_useless_stmts_1 (tp=<value optimized out>, 
      data=0x7fffffd8b670) at ../../gcc/gcc/tree-cfg.c:1915
  #2  0x0000000000546b55 in remove_useless_stmts_1 (tp=0x2aaaaaf7bf90, 
      data=0x7fffffd8b670) at ../../gcc/gcc/tree-cfg.c:1741
  #3  0x000000000054775d in remove_useless_stmts ()
      at ../../gcc/gcc/tree-cfg.c:1949
  #4  0x00000000008981ae in execute_one_pass (pass=0xc78700)
      at ../../gcc/gcc/passes.c:864
  #5  0x000000000089831c in execute_pass_list (pass=0xc78700)
      at ../../gcc/gcc/passes.c:911
  #6  0x000000000055f359 in tree_lowering_passes (fn=<value optimized out>)
      at ../../gcc/gcc/tree-optimize.c:324
  #7  0x00000000008e7a78 in cgraph_lower_function (node=0x2aaaaaf7d790)
      at ../../gcc/gcc/cgraphunit.c:448
  #8  0x00000000008e8697 in cgraph_analyze_function (node=0x2aaaaaf7d790)
      at ../../gcc/gcc/cgraphunit.c:919

One question is, why do we end up there at all after an error
has been issued?

Anyway. The following patch fixes the problem by using void_type_node
instead of error_mark_node to mark an invalid handler type.

This is only a kludge, but better than a segfault and better than
the NULL_TREE we used before, because the bogus
"'...' handler must be the last handler for its try block"
message are suppressed.

Maybe I should add a comment like
/*  FIXME: Handle error_mark_nodes correctly.  */

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline? Or any other ideas?

Regards,
Volker

:ADDPATCH C++:


2006-07-20  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28250
	* semantics.c (finish_handler_parms): Use void_type_node instead of
	error_mark_node for an invalid handler type.

===================================================================
--- gcc/gcc/cp/semantics.c	2006-07-20 02:37:18 +0200
+++ gcc/gcc/cp/semantics.c	2006-07-20 02:36:54 +0200
@@ -1089,7 +1089,7 @@ finish_handler_parms (tree decl, tree ha
     }
   else
     type = expand_start_catch_block (decl);
-  HANDLER_TYPE (handler) = type;
+  HANDLER_TYPE (handler) = (type == error_mark_node ? void_type_node : type);
   if (!processing_template_decl && type)
     mark_used (eh_type_info (type));
 }
===================================================================

2006-07-20  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28250
	* g++.dg/eh/catch4.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/eh/catch4.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/eh/catch4.C	2006-07-20 17:38:45 +0200
@@ -0,0 +1,8 @@
+// PR c++/28250
+// { dg-do compile }
+
+void foo()
+{
+  try { throw; }
+  catch () {}  // { dg-error "type-specifier" }
+}
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]