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] Fix PR c++/27952


Hi,

Currently the C++ front-end seg faults on the following invalid testcases:

Test 1:

struct A { virtual ~A() {} };
struct B : A, virtual A {};
struct C : A, B {};
C c;

Test 2:

struct A {};
struct B : A, virtual A {};
struct C : B {};

The seg faults are triggered inside decay_conversion and initialize_local_var,
both of couldn't handle NULL parameters so the first part of the patch
is adding
those checks into the two affected functions.

After the seg fault had been fixed inside decay_conversion the
following assertion
was triggered inside build_special_member_call a few lines down from
the call to decay_conversion, so the final portion of the patch is to
make build_special_member_call
return early if decay_conversion failed, avoiding the ICE.

Bootstrapped and regression tested on i686-pc-linux-gnu with no new failures.
Ok for mainline?

Cheers,
Lee.

:ADDPATCH C++:

cp/

2006-06-10 Lee Millward <lee.millward@gmail.com>

      PR c++/27952
      * typeck2.c (decay_conversion): Robustify.
      * decl.c (initialize_local_var): Likewise.
      * call.c (build_special_member_call): Return early if
      decay_conversion fails.

testsuite/

2006-06-10 Lee Millward <lee.millward@gmail.com>

      PR c++/27952
      * g++.dg/inherit/multiple2.C: New test.
      * g++.dg/inherit/multiple3.C: Likewise.
Index: gcc/testsuite/g++.dg/inherit/multiple2.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/multiple2.C	(revision 0)
+++ gcc/testsuite/g++.dg/inherit/multiple2.C	(revision 0)
@@ -0,0 +1,13 @@
+//PR c++/27952
+
+struct A
+{
+    virtual ~A() {}
+};
+
+struct B : A, virtual A {}; // { dg-error "duplicate base" } 
+
+struct C : A, B {}; // { dg-warning "direct base" } 
+
+C c; 
+
Index: gcc/testsuite/g++.dg/inherit/multiple3.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/multiple3.C	(revision 0)
+++ gcc/testsuite/g++.dg/inherit/multiple3.C	(revision 0)
@@ -0,0 +1,7 @@
+//PR c++/27952
+
+struct A {};
+
+struct B : A, virtual A {}; // { dg-error "duplicate base type" }
+
+struct C : B {};
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 114495)
+++ gcc/cp/typeck.c	(working copy)
@@ -1442,6 +1442,9 @@ decay_conversion (tree exp)
   tree type;
   enum tree_code code;
 
+  if(!exp)
+    return error_mark_node;
+
   type = TREE_TYPE (exp);
   if (type == error_mark_node)
     return error_mark_node;
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 114495)
+++ gcc/cp/decl.c	(working copy)
@@ -4957,6 +4957,9 @@ initialize_local_var (tree decl, tree in
 void
 initialize_artificial_var (tree decl, tree init)
 {
+  if(!decl || !init)
+    return;
+
   if (TREE_CODE (init) == TREE_LIST)
     init = build_constructor_from_list (NULL_TREE, init);
   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 114495)
+++ gcc/cp/call.c	(working copy)
@@ -5206,6 +5206,10 @@ build_special_member_call (tree instance
 	 Otherwise, we look it up using the VTT we were given.  */
       vtt = TREE_CHAIN (CLASSTYPE_VTABLES (current_class_type));
       vtt = decay_conversion (vtt);
+
+      if(vtt == error_mark_node)
+        return error_mark_node;
+
       vtt = build3 (COND_EXPR, TREE_TYPE (vtt),
 		    build2 (EQ_EXPR, boolean_type_node,
 			    current_in_charge_parm, integer_zero_node),

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