This patch by Chris Manghane fixes the Go frontend to accept any untyped integer value as an index, even if the default type of the value is not "int". This fixes https://golang.org/issue/11545 . Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 228087) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -66c113f1af300ce27b99f18f792901d7327d6699 +f187e13b712824b08f2a8833033840cd52a3b95a The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 227863) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -9870,11 +9870,26 @@ void Array_index_expression::do_determine_type(const Type_context*) { this->array_->determine_type_no_context(); - this->start_->determine_type_no_context(); + + Type_context index_context(Type::lookup_integer_type("int"), false); + if (this->start_->is_constant()) + this->start_->determine_type(&index_context); + else + this->start_->determine_type_no_context(); if (this->end_ != NULL) - this->end_->determine_type_no_context(); + { + if (this->end_->is_constant()) + this->end_->determine_type(&index_context); + else + this->end_->determine_type_no_context(); + } if (this->cap_ != NULL) - this->cap_->determine_type_no_context(); + { + if (this->cap_->is_constant()) + this->cap_->determine_type(&index_context); + else + this->cap_->determine_type_no_context(); + } } // Check types of an array index. @@ -10415,9 +10430,19 @@ void String_index_expression::do_determine_type(const Type_context*) { this->string_->determine_type_no_context(); - this->start_->determine_type_no_context(); + + Type_context index_context(Type::lookup_integer_type("int"), false); + if (this->start_->is_constant()) + this->start_->determine_type(&index_context); + else + this->start_->determine_type_no_context(); if (this->end_ != NULL) - this->end_->determine_type_no_context(); + { + if (this->end_->is_constant()) + this->end_->determine_type(&index_context); + else + this->end_->determine_type_no_context(); + } } // Check types of a string index.