[gccgo] Don't use statement lists in constructors

Message ID mcrsk23sqx6.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Aug. 24, 2010, 8:21 p.m.
gccgo crashed on this test case, now added as bug304.go in the unified
Go testsuite.

package p
type S struct {
	v interface{}
func g(e interface{}) { }
func f(s S) {

The crash was because the frontend put a STATEMENT_LIST in a
constructor, which failed when the gimplifier attempted to copy the
value as an initializer for a temporary value.  This may or may not be a
bug in the gimplifier, I'm not sure.  But in any case it's easy to fix
in the gccgo frontend.  Committed to gccgo branch.



diff -r fe1e44128513 go/expressions.cc
--- a/go/expressions.cc	Sun Aug 01 06:03:09 2010 -0700
+++ b/go/expressions.cc	Tue Aug 24 13:10:49 2010 -0700
@@ -697,9 +697,6 @@ 
   // This call will panic if the conversion is invalid.
   TREE_NOTHROW(check_interface_type_decl) = 0;
-  tree stmt_list = NULL_TREE;
-  append_to_statement_list(call, &stmt_list);
   // If the call succeeds, pull out the value.
   gcc_assert(TREE_CODE(rhs_type_tree) == RECORD_TYPE);
   tree rhs_field = TREE_CHAIN(TYPE_FIELDS(rhs_type_tree));
@@ -710,22 +707,22 @@ 
   // If the value is a pointer, then we can just get it from the
   // interface.  Otherwise we have to make a copy.
   if (lhs_type->points_to() != NULL)
-    return build2(COMPOUND_EXPR, lhs_type_tree, stmt_list,
+    return build2(COMPOUND_EXPR, lhs_type_tree, call,
 		  fold_convert_loc(location, lhs_type_tree, val));
   tree tmp = create_tmp_var(lhs_type_tree, NULL);
   DECL_IGNORED_P(tmp) = 0;
   tree make_tmp = fold_build1_loc(location, DECL_EXPR, void_type_node, tmp);
-  append_to_statement_list(make_tmp, &stmt_list);
+  tree s = build2(COMPOUND_EXPR, void_type_node, call, make_tmp);
   val = fold_convert_loc(location, build_pointer_type(lhs_type_tree), val);
   val = build_fold_indirect_ref_loc(location, val);
   tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node,
 			     tmp, val);
-  append_to_statement_list(set, &stmt_list);
-  return build2(COMPOUND_EXPR, lhs_type_tree, stmt_list, tmp);
+  s = build2(COMPOUND_EXPR, void_type_node, s, set);
+  return build2(COMPOUND_EXPR, lhs_type_tree, s, tmp);
 // Convert an expression to a tree.  This is implemented by the child