summaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-09-16 05:47:20 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-09-16 05:47:20 +0000
commit05d63fcfcf0fb9292d55a2fa6e7cbf2129c3e265 (patch)
tree03800353a564c0cdcf3c12bb8940b28389b243a9 /gcc/go
parent13197b1a99dbd7aa34765380ab7a38b4da4d254e (diff)
downloadgcc-05d63fcfcf0fb9292d55a2fa6e7cbf2129c3e265.tar.gz
Fix defer when not calling recover in function with named results.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178905 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/gogo-tree.cc18
-rw-r--r--gcc/go/gofrontend/gogo.cc18
-rw-r--r--gcc/go/gofrontend/runtime.def6
-rw-r--r--gcc/go/gofrontend/statements.cc9
4 files changed, 30 insertions, 21 deletions
diff --git a/gcc/go/gofrontend/gogo-tree.cc b/gcc/go/gofrontend/gogo-tree.cc
index fbddc0492f6..49a0ba40bbd 100644
--- a/gcc/go/gofrontend/gogo-tree.cc
+++ b/gcc/go/gofrontend/gogo-tree.cc
@@ -1592,15 +1592,25 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
&& !this->type_->results()->empty()
&& !this->type_->results()->front().name().empty())
{
- // If the result variables are named, we need to return them
- // again, because they might have been changed by a defer
- // function.
+ // If the result variables are named, and we are returning from
+ // this function rather than panicing through it, we need to
+ // return them again, because they might have been changed by a
+ // defer function. The runtime routines set the defer_stack
+ // variable to true if we are returning from this function.
retval = this->return_value(gogo, named_function, end_loc,
&stmt_list);
set = fold_build2_loc(end_loc, MODIFY_EXPR, void_type_node,
DECL_RESULT(this->fndecl_), retval);
ret_stmt = fold_build1_loc(end_loc, RETURN_EXPR, void_type_node, set);
- append_to_statement_list(ret_stmt, &stmt_list);
+
+ Expression* ref =
+ Expression::make_temporary_reference(this->defer_stack_, end_loc);
+ tree tref = ref->get_tree(&context);
+ tree s = build3_loc(end_loc, COND_EXPR, void_type_node, tref,
+ ret_stmt, NULL_TREE);
+
+ append_to_statement_list(s, &stmt_list);
+
}
go_assert(*fini == NULL_TREE);
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index c544eba8d2f..4a89ca80ba5 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -2976,27 +2976,27 @@ Function::determine_types()
this->block_->determine_types();
}
-// Get a pointer to the variable holding the defer stack for this
-// function, making it if necessary. At least at present, the value
-// of this variable is not used. However, a pointer to this variable
-// is used as a marker for the functions on the defer stack associated
-// with this function. Doing things this way permits inlining a
+// Get a pointer to the variable representing the defer stack for this
+// function, making it if necessary. The value of the variable is set
+// by the runtime routines to true if the function is returning,
+// rather than panicing through. A pointer to this variable is used
+// as a marker for the functions on the defer stack associated with
+// this function. A function-specific variable permits inlining a
// function which uses defer.
Expression*
Function::defer_stack(source_location location)
{
- Type* t = Type::make_pointer_type(Type::make_void_type());
if (this->defer_stack_ == NULL)
{
- Expression* n = Expression::make_nil(location);
+ Type* t = Type::lookup_bool_type();
+ Expression* n = Expression::make_boolean(false, location);
this->defer_stack_ = Statement::make_temporary(t, n, location);
this->defer_stack_->set_is_address_taken();
}
Expression* ref = Expression::make_temporary_reference(this->defer_stack_,
location);
- Expression* addr = Expression::make_unary(OPERATOR_AND, ref, location);
- return Expression::make_unsafe_cast(t, addr, location);
+ return Expression::make_unary(OPERATOR_AND, ref, location);
}
// Export the function.
diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def
index 219ccb8bd90..a7828edeb2e 100644
--- a/gcc/go/gofrontend/runtime.def
+++ b/gcc/go/gofrontend/runtime.def
@@ -165,10 +165,10 @@ DEF_GO_RUNTIME(SET_DEFER_RETADDR, "__go_set_defer_retaddr", P1(POINTER),
R1(BOOL))
// Check for a deferred function in an exception handler.
-DEF_GO_RUNTIME(CHECK_DEFER, "__go_check_defer", P1(POINTER), R0())
+DEF_GO_RUNTIME(CHECK_DEFER, "__go_check_defer", P1(BOOLPTR), R0())
// Run deferred functions.
-DEF_GO_RUNTIME(UNDEFER, "__go_undefer", P1(POINTER), R0())
+DEF_GO_RUNTIME(UNDEFER, "__go_undefer", P1(BOOLPTR), R0())
// Panic with a runtime error.
DEF_GO_RUNTIME(RUNTIME_ERROR, "__go_runtime_error", P1(INT), R0())
@@ -207,7 +207,7 @@ DEF_GO_RUNTIME(GO, "__go_go", P2(FUNC_PTR, POINTER), R0())
// Defer a function.
-DEF_GO_RUNTIME(DEFER, "__go_defer", P3(POINTER, FUNC_PTR, POINTER), R0())
+DEF_GO_RUNTIME(DEFER, "__go_defer", P3(BOOLPTR, FUNC_PTR, POINTER), R0())
// Run a select statement.
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index bb43dcdee43..82be1129028 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -2539,11 +2539,10 @@ Return_statement::do_traverse_assignments(Traverse_assignments* tassign)
// Lower a return statement. If we are returning a function call
// which returns multiple values which match the current function,
-// split up the call's results. If the function has named result
-// variables, and the return statement lists explicit values, then
-// implement it by assigning the values to the result variables and
-// changing the statement to not list any values. This lets
-// panic/recover work correctly.
+// split up the call's results. If the return statement lists
+// explicit values, implement this statement by assigning the values
+// to the result variables and change this statement to a naked
+// return. This lets panic/recover work correctly.
Statement*
Return_statement::do_lower(Gogo*, Named_object* function, Block* enclosing,