Patchwork Go patch committed: Don't crash on invalid type conversion

login
register
mail settings
Submitter Ian Taylor
Date Dec. 22, 2010, 6:17 a.m.
Message ID <mcrlj3iib55.fsf@google.com>
Download mbox | patch
Permalink /patch/76361/
State New
Headers show

Comments

Ian Taylor - Dec. 22, 2010, 6:17 a.m.
This patch to the Go frontend avoids a crash on an invalid type
conversion, by checking for a conversion of an erroneous or undefined
type.  The Type::are_convertible function always return true for error
types to avoid knock-on errors; this is a case where we really do need
to consider the error.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.

Ian

Patch

diff -r 0da266c3a538 go/expressions.cc
--- a/go/expressions.cc	Tue Dec 21 17:36:48 2010 -0800
+++ b/go/expressions.cc	Tue Dec 21 22:14:18 2010 -0800
@@ -3242,6 +3242,18 @@ 
   Type* expr_type = this->expr_->type();
   std::string reason;
 
+  if (type->is_error_type()
+      || type->is_undefined()
+      || expr_type->is_error_type()
+      || expr_type->is_undefined())
+    {
+      // Make sure we emit an error for an undefined type.
+      type->base();
+      expr_type->base();
+      this->set_is_error();
+      return;
+    }
+
   if (this->may_convert_function_types_
       && type->function_type() != NULL
       && expr_type->function_type() != NULL)