The Go frontend had a bug comparing a struct or array value to an
interface value when the struct or array was not addressable.  The code
that was supposed to force the struct/array into a temporary variable
did not fire, because the compiler erroneously tried to handle it as a
straight struct/array comparison.  This patch fixes the problem.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.9 branch.

The test case has been committed to the master testsuite; see
https://codereview.appspot.com/135170043 .  This fixes
http://golang.org/issue/8612 .

Ian

diff -r 3a08729cc5f8 go/expressions.cc
--- a/go/expressions.cc	Tue Aug 26 21:09:25 2014 -0700
+++ b/go/expressions.cc	Thu Aug 28 19:39:45 2014 -0700
@@ -5187,10 +5187,13 @@
   // Lower struct, array, and some interface comparisons.
   if (op == OPERATOR_EQEQ || op == OPERATOR_NOTEQ)
     {
-      if (left->type()->struct_type() != NULL)
+      if (left->type()->struct_type() != NULL
+	  && right->type()->struct_type() != NULL)
 	return this->lower_struct_comparison(gogo, inserter);
       else if (left->type()->array_type() != NULL
-	       && !left->type()->is_slice_type())
+	       && !left->type()->is_slice_type()
+	       && right->type()->array_type() != NULL
+	       && !right->type()->is_slice_type())
 	return this->lower_array_comparison(gogo, inserter);
       else if ((left->type()->interface_type() != NULL
                 && right->type()->interface_type() == NULL)

Reply via email to