* Go patch committed: Don't crash on invalid tuple assignment
@ 2010-12-16 1:47 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2010-12-16 1:47 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 160 bytes --]
This patch to the Go frontend avoids a crash on an invalid tuple
assignment. Bootstrapped and tested on x86_64-unknown-linux-gnu.
Committed to mainline.
Ian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: crash --]
[-- Type: text/x-diff, Size: 2521 bytes --]
diff -r 2d785fe6afc9 go/expressions.cc
--- a/go/expressions.cc Wed Dec 15 16:42:28 2010 -0800
+++ b/go/expressions.cc Wed Dec 15 17:15:16 2010 -0800
@@ -8655,6 +8655,9 @@
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 @@
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 -r 2d785fe6afc9 go/statements.cc
--- a/go/statements.cc Wed Dec 15 16:42:28 2010 -0800
+++ b/go/statements.cc Wed Dec 15 17:15:16 2010 -0800
@@ -782,6 +782,12 @@
{
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 @@
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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-12-16 1:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-16 1:47 Go patch committed: Don't crash on invalid tuple assignment Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).