When Go code takes a slice of a pointer to an array, the compiler was
failing to check whether that point is nil, as is required by the Go 1.2
addition of reliable nil checks.  This patch fixes that oversight.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

diff -r befe27e79459 go/expressions.cc
--- a/go/expressions.cc	Thu Dec 12 12:41:44 2013 -0800
+++ b/go/expressions.cc	Thu Dec 12 13:00:22 2013 -0800
@@ -10259,6 +10259,14 @@
     {
       Expression* deref = Expression::make_unary(OPERATOR_MULT, left,
 						 location);
+
+      // For an ordinary index into the array, the pointer will be
+      // dereferenced.  For a slice it will not--the resulting slice
+      // will simply reuse the pointer, which is incorrect if that
+      // pointer is nil.
+      if (end != NULL || cap != NULL)
+	deref->issue_nil_check();
+
       return Expression::make_array_index(deref, start, end, cap, location);
     }
   else if (type->is_string_type())

Reply via email to