aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2014-07-08 21:28:17 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2014-07-08 21:28:17 +0000
commitfd4de8b2be2b2994124c0e8a555c3fb075e5d63e (patch)
treebc50ed8007463a31599c6fc7da23894649df1b9f /gcc
parent0630a48fdf38d31f5a413b5907f95ca0c3bed52b (diff)
downloadgcc-fd4de8b2be2b2994124c0e8a555c3fb075e5d63e.zip
gcc-fd4de8b2be2b2994124c0e8a555c3fb075e5d63e.tar.gz
gcc-fd4de8b2be2b2994124c0e8a555c3fb075e5d63e.tar.bz2
re PR go/61308 (gccgo: ICE in Expression::check_bounds [GoSmith])
PR go/61308 compiler: Convert array start index before bounds checking. From-SVN: r212372
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/expressions.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index c481bc5..53c0068 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10218,7 +10218,8 @@ Array_index_expression::do_get_backend(Translate_context* context)
Location loc = this->location();
Gogo* gogo = context->gogo();
- Btype* int_btype = Type::lookup_integer_type("int")->get_backend(gogo);
+ Type* int_type = Type::lookup_integer_type("int");
+ Btype* int_btype = int_type->get_backend(gogo);
// We need to convert the length and capacity to the Go "int" type here
// because the length of a fixed-length array could be of type "uintptr"
@@ -10259,8 +10260,15 @@ Array_index_expression::do_get_backend(Translate_context* context)
: RUNTIME_ERROR_SLICE_SLICE_OUT_OF_BOUNDS));
Bexpression* crash = gogo->runtime_error(code, loc)->get_backend(context);
+ if (this->start_->type()->integer_type() == NULL
+ && !Type::are_convertible(int_type, this->start_->type(), NULL))
+ {
+ go_assert(saw_errors());
+ return context->backend()->error_expression();
+ }
+ Expression* start_expr = Expression::make_cast(int_type, this->start_, loc);
Bexpression* bad_index =
- Expression::check_bounds(this->start_, loc)->get_backend(context);
+ Expression::check_bounds(start_expr, loc)->get_backend(context);
Bexpression* start = this->start_->get_backend(context);
start = gogo->backend()->convert_expression(int_btype, start, loc);