The Go frontend was carefully checking for a nil receiver in a value method, and setting the value to zero in that case. This is wrong: a nil receiver passed to a value method should crash. This patch fixes this, by simply removing the unnecessary generated code. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 1f4ec4d512ee go/gogo-tree.cc --- a/go/gogo-tree.cc Tue Sep 13 11:22:31 2011 -0700 +++ b/go/gogo-tree.cc Tue Sep 13 14:30:19 2011 -0700 @@ -1281,16 +1281,7 @@ DECL_ARG_TYPE(parm_decl) = TREE_TYPE(parm_decl); go_assert(DECL_INITIAL(var_decl) == NULL_TREE); - // The receiver might be passed as a null pointer. - tree check = fold_build2_loc(loc, NE_EXPR, boolean_type_node, parm_decl, - fold_convert_loc(loc, TREE_TYPE(parm_decl), - null_pointer_node)); - tree ind = build_fold_indirect_ref_loc(loc, parm_decl); - TREE_THIS_NOTRAP(ind) = 1; - Btype* btype = no->var_value()->type()->get_backend(gogo); - tree zero_init = expr_to_tree(gogo->backend()->zero_expression(btype)); - tree init = fold_build3_loc(loc, COND_EXPR, TREE_TYPE(ind), - check, ind, zero_init); + tree init = build_fold_indirect_ref_loc(loc, parm_decl); if (is_in_heap) { @@ -1301,18 +1292,9 @@ space = fold_convert(build_pointer_type(val_type), space); tree spaceref = build_fold_indirect_ref_loc(no->location(), space); TREE_THIS_NOTRAP(spaceref) = 1; - tree check = fold_build2_loc(loc, NE_EXPR, boolean_type_node, - parm_decl, - fold_convert_loc(loc, TREE_TYPE(parm_decl), - null_pointer_node)); - tree parmref = build_fold_indirect_ref_loc(no->location(), parm_decl); - TREE_THIS_NOTRAP(parmref) = 1; tree set = fold_build2_loc(loc, MODIFY_EXPR, void_type_node, - spaceref, parmref); - init = fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(space), - build3(COND_EXPR, void_type_node, - check, set, NULL_TREE), - space); + spaceref, init); + init = fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(space), set, space); } DECL_INITIAL(var_decl) = init;