aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2010-12-16 01:26:35 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2010-12-16 01:26:35 +0000
commit7a2d845d3e116031530ae201dfb5e75edf995f31 (patch)
treeca5c495ffeeafb07a66c20b5f108e55f599a2b02
parentfaff9b0430d73d651ac9b0987091721de2cac8dd (diff)
downloadgcc-7a2d845d3e116031530ae201dfb5e75edf995f31.zip
gcc-7a2d845d3e116031530ae201dfb5e75edf995f31.tar.gz
gcc-7a2d845d3e116031530ae201dfb5e75edf995f31.tar.bz2
Don't crash on invalid tuple assignment.
From-SVN: r167892
-rw-r--r--gcc/go/gofrontend/expressions.cc30
-rw-r--r--gcc/go/gofrontend/statements.cc12
2 files changed, 24 insertions, 18 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 6a7ba45..8187e6d 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -8655,6 +8655,9 @@ Call_result_expression::do_traverse(Traverse* traverse)
Type*
Call_result_expression::do_type()
{
+ if (this->classification() == EXPRESSION_ERROR)
+ return Type::make_error_type();
+
// THIS->CALL_ can be replaced with a temporary reference due to
// Call_expression::do_must_eval_in_order when there is an error.
Call_expression* ce = this->call_->call_expression();
@@ -8668,34 +8671,25 @@ Call_result_expression::do_type()
for (unsigned int i = 0; i < this->index_; ++i)
{
if (pr == results->end())
- return Type::make_error_type();
+ break;
++pr;
}
if (pr == results->end())
- return Type::make_error_type();
+ {
+ this->report_error(_("number of results does not match "
+ "number of values"));
+ return Type::make_error_type();
+ }
return pr->type();
}
-// Check the type. This is where we give an error if we're trying to
-// extract too many values from a call.
+// Check the type. Just make sure that we trigger the warning in
+// do_type.
void
Call_result_expression::do_check_types(Gogo*)
{
- bool ok = true;
- Call_expression* ce = this->call_->call_expression();
- if (ce != NULL)
- ok = this->index_ < ce->result_count();
- else
- {
- // This can happen when the call returns a single value but we
- // are asking for the second result.
- if (this->call_->is_error_expression())
- return;
- ok = false;
- }
- if (!ok)
- this->report_error(_("number of results does not match number of values"));
+ this->type();
}
// Determine the type. We have nothing to do here, but the 0 result
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index ce389ab..2c0dba0 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -782,6 +782,12 @@ Tuple_assignment_statement::do_lower(Gogo*, Block* enclosing)
{
gcc_assert(prhs != this->rhs_->end());
+ if ((*plhs)->is_error_expression()
+ || (*plhs)->type()->is_error_type()
+ || (*prhs)->is_error_expression()
+ || (*prhs)->type()->is_error_type())
+ continue;
+
if ((*plhs)->is_sink_expression())
{
b->add_statement(Statement::make_statement(*prhs));
@@ -802,6 +808,12 @@ Tuple_assignment_statement::do_lower(Gogo*, Block* enclosing)
plhs != this->lhs_->end();
++plhs, ++prhs)
{
+ if ((*plhs)->is_error_expression()
+ || (*plhs)->type()->is_error_type()
+ || (*prhs)->is_error_expression()
+ || (*prhs)->type()->is_error_type())
+ continue;
+
if ((*plhs)->is_sink_expression())
continue;