diff mbox

[C++] PR 59082

Message ID 52EB92AE.1070500@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Jan. 31, 2014, 12:10 p.m. UTC
Hi,

in this ICE on invalid regression we emit a sensible error message about 
the duplicate base and then we ICE when we process the function, because 
TYPE_VFIELD (type) is null in build_vfield_ref. My changes just check 
for the offending situation and return early from build_base_path 
(fold_build_pointer_plus would crash for an error_mark_node).

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2014-01-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59082
	* class.c (build_vfield_ref): Early return error_mark_node if
	TYPE_VFIELD (type) is null.
	(build_base_path): Check return value of build_vfield_ref.

/testsuite
2014-01-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59082
	* g++.dg/inherit/crash4.C: New.

Comments

Jason Merrill Jan. 31, 2014, 4:12 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 207336)
+++ cp/class.c	(working copy)
@@ -431,6 +431,9 @@  build_base_path (enum tree_code code,
 	v_offset = build_vfield_ref (cp_build_indirect_ref (expr, RO_NULL,
                                                             complain),
 				     TREE_TYPE (TREE_TYPE (expr)));
+      
+      if (v_offset == error_mark_node)
+	return error_mark_node;
 
       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
       v_offset = build1 (NOP_EXPR,
@@ -625,7 +628,9 @@  build_vfield_ref (tree datum, tree type)
 {
   tree vfield, vcontext;
 
-  if (datum == error_mark_node)
+  if (datum == error_mark_node
+      /* Can happen in case of duplicate base types (c++/59082).  */
+      || !TYPE_VFIELD (type))
     return error_mark_node;
 
   /* First, convert to the requested type.  */
Index: testsuite/g++.dg/inherit/crash4.C
===================================================================
--- testsuite/g++.dg/inherit/crash4.C	(revision 0)
+++ testsuite/g++.dg/inherit/crash4.C	(working copy)
@@ -0,0 +1,10 @@ 
+// PR c++/59082
+
+struct A {};
+
+struct B : virtual A, A {};  // { dg-error "duplicate base type" }
+
+A foo(const B &b)
+{
+  return b;
+}