Commit 5ae2ca96 by Ian Lance Taylor

Don't crash on invalid return statement.

From-SVN: r168102
parent bc77e3e1
...@@ -2567,6 +2567,8 @@ Return_statement::do_get_tree(Translate_context* context) ...@@ -2567,6 +2567,8 @@ Return_statement::do_get_tree(Translate_context* context)
{ {
Function* function = context->function()->func_value(); Function* function = context->function()->func_value();
tree fndecl = function->get_decl(); tree fndecl = function->get_decl();
if (fndecl == error_mark_node || DECL_RESULT(fndecl) == error_mark_node)
return error_mark_node;
const Typed_identifier_list* results = this->results_; const Typed_identifier_list* results = this->results_;
...@@ -2580,6 +2582,8 @@ Return_statement::do_get_tree(Translate_context* context) ...@@ -2580,6 +2582,8 @@ Return_statement::do_get_tree(Translate_context* context)
tree set; tree set;
if (retval == NULL_TREE) if (retval == NULL_TREE)
set = NULL_TREE; set = NULL_TREE;
else if (retval == error_mark_node)
return error_mark_node;
else else
set = fold_build2_loc(this->location(), MODIFY_EXPR, void_type_node, set = fold_build2_loc(this->location(), MODIFY_EXPR, void_type_node,
DECL_RESULT(fndecl), retval); DECL_RESULT(fndecl), retval);
...@@ -2591,13 +2595,13 @@ Return_statement::do_get_tree(Translate_context* context) ...@@ -2591,13 +2595,13 @@ Return_statement::do_get_tree(Translate_context* context)
{ {
gcc_assert(!VOID_TYPE_P(TREE_TYPE(TREE_TYPE(fndecl)))); gcc_assert(!VOID_TYPE_P(TREE_TYPE(TREE_TYPE(fndecl))));
tree val = (*this->vals_->begin())->get_tree(context); tree val = (*this->vals_->begin())->get_tree(context);
if (val == error_mark_node)
return error_mark_node;
gcc_assert(results != NULL && results->size() == 1); gcc_assert(results != NULL && results->size() == 1);
val = Expression::convert_for_assignment(context, val = Expression::convert_for_assignment(context,
results->begin()->type(), results->begin()->type(),
(*this->vals_->begin())->type(), (*this->vals_->begin())->type(),
val, this->location()); val, this->location());
if (val == error_mark_node)
return error_mark_node;
tree set = build2(MODIFY_EXPR, void_type_node, tree set = build2(MODIFY_EXPR, void_type_node,
DECL_RESULT(fndecl), val); DECL_RESULT(fndecl), val);
SET_EXPR_LOCATION(set, this->location()); SET_EXPR_LOCATION(set, this->location());
...@@ -2618,11 +2622,11 @@ Return_statement::do_get_tree(Translate_context* context) ...@@ -2618,11 +2622,11 @@ Return_statement::do_get_tree(Translate_context* context)
{ {
gcc_assert(pv != this->vals_->end()); gcc_assert(pv != this->vals_->end());
tree val = (*pv)->get_tree(context); tree val = (*pv)->get_tree(context);
if (val == error_mark_node)
return error_mark_node;
val = Expression::convert_for_assignment(context, pr->type(), val = Expression::convert_for_assignment(context, pr->type(),
(*pv)->type(), val, (*pv)->type(), val,
this->location()); this->location());
if (val == error_mark_node)
return error_mark_node;
tree set = build2(MODIFY_EXPR, void_type_node, tree set = build2(MODIFY_EXPR, void_type_node,
build3(COMPONENT_REF, TREE_TYPE(field), build3(COMPONENT_REF, TREE_TYPE(field),
retvar, field, NULL_TREE), retvar, field, NULL_TREE),
......
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