* [gccgo] Don't crash on argument count mismatch
@ 2010-07-03 6:05 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2010-07-03 6:05 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 184 bytes --]
Code like
a, b := f()
would crash the compiler when f returns a single result, rather than
issuing a sensible error message. This patch fixes that. Committed to
gccgo branch.
Ian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mismatch --]
[-- Type: text/x-diff, Size: 2566 bytes --]
diff -r 19486205521b go/expressions.cc
--- a/go/expressions.cc Fri Jul 02 12:59:20 2010 -0700
+++ b/go/expressions.cc Fri Jul 02 22:34:05 2010 -0700
@@ -8614,6 +8614,9 @@
void
do_determine_type(const Type_context*);
+ void
+ do_check_types(Gogo*);
+
Expression*
do_copy()
{
@@ -8661,23 +8664,50 @@
Type*
Call_result_expression::do_type()
{
- if (this->call_->is_error_expression())
+ // 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();
+ if (ce == NULL)
return Type::make_error_type();
- Function_type* fntype =
- this->call_->call_expression()->get_function_type();
+ Function_type* fntype = ce->get_function_type();
if (fntype == NULL)
return Type::make_error_type();
const Typed_identifier_list* results = fntype->results();
Typed_identifier_list::const_iterator pr = results->begin();
for (unsigned int i = 0; i < this->index_; ++i)
{
- gcc_assert(pr != results->end());
+ if (pr == results->end())
+ return Type::make_error_type();
++pr;
}
- gcc_assert(pr != results->end());
+ if (pr == results->end())
+ 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.
+
+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)
+ error_at(this->location(),
+ "number of results does not match number of values");
+}
+
// Determine the type. We have nothing to do here, but the 0 result
// needs to pass down to the caller.
diff -r 19486205521b go/statements.cc
--- a/go/statements.cc Fri Jul 02 12:59:20 2010 -0700
+++ b/go/statements.cc Fri Jul 02 22:34:05 2010 -0700
@@ -358,7 +358,10 @@
gcc_assert(this->decl_ == NULL_TREE);
tree type_tree = this->type()->get_tree(context->gogo());
if (type_tree == error_mark_node)
- return error_mark_node;
+ {
+ this->decl_ = error_mark_node;
+ return error_mark_node;
+ }
// We can only use create_tmp_var if the type is not addressable.
if (!TREE_ADDRESSABLE(type_tree))
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-07-03 6:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-03 6:05 [gccgo] Don't crash on argument count mismatch 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).