From 6e4f9a957e22aaed58cf628e34d420fdfa21a3d8 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 5 Aug 2014 02:58:15 +0000 Subject: re PR go/61308 (gccgo: ICE in Expression::check_bounds [GoSmith]) PR go/61308 PR go/61866 compiler: Don't cast index expr to int before bounds check. This fixes http://gcc.gnu.org/PR61866 : on a 32-bit system, casting an int64 index to int drops the upper 32 bits of the value, and thus can cause an out-of-range index to appear to be in range. This undoes part of change 1318:fa6e0c716dba (https://codereview.appspot.com/104610044) and therefore breaks http://gcc.gnu.org/PR61308 again. I have a separate patch for that (http://codereview.appspot.com/122020043). In addition to undoing part of that change, this patch adds code to avoid a compiler crash. This changes PR61308 from a compiler crash to an incorrect error message. From-SVN: r213616 --- gcc/go/gofrontend/expressions.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'gcc/go') diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index f054d0a..adc4fb0 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -3620,6 +3620,16 @@ Unary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int) return Expression::make_error(this->location()); } + // Check for an invalid pointer dereference. We need to do this + // here because Unary_expression::do_type will return an error type + // in this case. That can cause code to appear erroneous, and + // therefore disappear at lowering time, without any error message. + if (op == OPERATOR_MULT && expr->type()->points_to() == NULL) + { + this->report_error(_("expected pointer")); + return Expression::make_error(this->location()); + } + if (op == OPERATOR_PLUS || op == OPERATOR_MINUS || op == OPERATOR_XOR) { Numeric_constant nc; @@ -9811,7 +9821,10 @@ Index_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int) Type* type = left->type(); if (type->is_error()) - return Expression::make_error(location); + { + go_assert(saw_errors()); + return Expression::make_error(location); + } else if (left->is_type_expression()) { error_at(location, "attempt to index type expression"); @@ -10298,9 +10311,9 @@ Array_index_expression::do_get_backend(Translate_context* context) 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(start_expr, loc)->get_backend(context); + Expression::check_bounds(this->start_, loc)->get_backend(context); Bexpression* start = this->start_->get_backend(context); start = gogo->backend()->convert_expression(int_btype, start, loc); -- cgit v1.1