This patch by Chris Manghane fixes the Go frontend to permit string slice expressions when the start of the slice is the length of the setring. This were previously erroneously forbidden when using a constant index. This fixes https://golang.org/issue/11522 . 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 227184) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -d6d59d5927c4ea0c02468ebc6a2df431fb64595a +14ca4b6130b9a7132d132f418e9ea283b3a52c08 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 227039) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -10341,7 +10341,10 @@ String_index_expression::do_check_types( { ival_valid = true; if (mpz_sgn(ival) < 0 - || (sval_valid && mpz_cmp_ui(ival, sval.length()) >= 0)) + || (sval_valid + && (this->end_ == NULL + ? mpz_cmp_ui(ival, sval.length()) >= 0 + : mpz_cmp_ui(ival, sval.length()) > 0))) { error_at(this->start_->location(), "string index out of bounds"); this->set_is_error();