This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch commtited: Convert array start index before bounds check
- 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: Tue, 08 Jul 2014 14:28:20 -0700
- Subject: Go patch commtited: Convert array start index before bounds check
- Authentication-results: sourceware.org; auth=none
This patch from Chris Manghane fixes an ICE-on-invalid in the gccgo
frontend, reported as PR 61308. The fix is to convert an array start
index to int before doing a bounds check on the type. Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r d53fa58639b9 go/expressions.cc
--- a/go/expressions.cc Tue Jul 08 13:42:21 2014 -0700
+++ b/go/expressions.cc Tue Jul 08 14:12:32 2014 -0700
@@ -10218,7 +10218,8 @@
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 @@
: 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);