This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Check for nil pointer when slicing pointer to array
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Thu, 12 Dec 2013 13:03:12 -0800
- Subject: Go patch committed: Check for nil pointer when slicing pointer to array
- Authentication-results: sourceware.org; auth=none
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())