summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-12 21:03:10 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-12 21:03:10 +0000
commit38092374b54828c8469b1f5112e1a4e94040f070 (patch)
tree04469f666ca0ee6847a5b7a0ccf8b24048c0a1ab
parent3ff4863baa46d3e370b164824f9120104950a0ce (diff)
downloadgcc-38092374b54828c8469b1f5112e1a4e94040f070.tar.gz
compiler: Check for nil when slicing pointer to array.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205942 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/gofrontend/expressions.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index a5a056b12ed..35bcdbb5145 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10259,6 +10259,14 @@ Index_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
{
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())