Commit a39fd33d by Ian Lance Taylor

Always dereference nil receiver passed to value method.

From-SVN: r178835
parent 43052d45
...@@ -1281,16 +1281,7 @@ Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl) ...@@ -1281,16 +1281,7 @@ Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl)
DECL_ARG_TYPE(parm_decl) = TREE_TYPE(parm_decl); DECL_ARG_TYPE(parm_decl) = TREE_TYPE(parm_decl);
go_assert(DECL_INITIAL(var_decl) == NULL_TREE); go_assert(DECL_INITIAL(var_decl) == NULL_TREE);
// The receiver might be passed as a null pointer. tree init = build_fold_indirect_ref_loc(loc, parm_decl);
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);
if (is_in_heap) if (is_in_heap)
{ {
...@@ -1301,18 +1292,9 @@ Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl) ...@@ -1301,18 +1292,9 @@ Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl)
space = fold_convert(build_pointer_type(val_type), space); space = fold_convert(build_pointer_type(val_type), space);
tree spaceref = build_fold_indirect_ref_loc(no->location(), space); tree spaceref = build_fold_indirect_ref_loc(no->location(), space);
TREE_THIS_NOTRAP(spaceref) = 1; 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, tree set = fold_build2_loc(loc, MODIFY_EXPR, void_type_node,
spaceref, parmref); spaceref, init);
init = fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(space), init = fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(space), set, space);
build3(COND_EXPR, void_type_node,
check, set, NULL_TREE),
space);
} }
DECL_INITIAL(var_decl) = init; DECL_INITIAL(var_decl) = init;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment