From 8d8fea8a57068a0c5f0c1df766679a25f4272481 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 28 Nov 2020 18:22:45 -0800 Subject: [PATCH] compiler: always use int context for index values For golang/go#14844 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273889 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/expressions.cc | 31 +++++----------------------- gcc/testsuite/go.test/test/shift1.go | 18 ++++++++++------ 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index af4d0526b2f..698969fc8c8 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -68b1c7659a6b25d537a4ff3365ab070fa6215b0b +af683486b4de5503b2b6d9ae974a2ab1eeb92290 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index dc7399ebb3a..d1546300d0e 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -12802,24 +12802,11 @@ Array_index_expression::do_determine_type(const Type_context*) this->array_->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(); + this->start_->determine_type(&index_context); if (this->end_ != NULL) - { - if (this->end_->is_constant()) - this->end_->determine_type(&index_context); - else - this->end_->determine_type_no_context(); - } + this->end_->determine_type(&index_context); if (this->cap_ != NULL) - { - if (this->cap_->is_constant()) - this->cap_->determine_type(&index_context); - else - this->cap_->determine_type_no_context(); - } + this->cap_->determine_type(&index_context); } // Check types of an array index. @@ -13488,17 +13475,9 @@ String_index_expression::do_determine_type(const Type_context*) this->string_->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(); + this->start_->determine_type(&index_context); if (this->end_ != NULL) - { - if (this->end_->is_constant()) - this->end_->determine_type(&index_context); - else - this->end_->determine_type_no_context(); - } + this->end_->determine_type(&index_context); } // Check types of a string index. diff --git a/gcc/testsuite/go.test/test/shift1.go b/gcc/testsuite/go.test/test/shift1.go index 04f5321b73f..d6a6c38839f 100644 --- a/gcc/testsuite/go.test/test/shift1.go +++ b/gcc/testsuite/go.test/test/shift1.go @@ -1,6 +1,6 @@ // errorcheck -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -18,13 +18,13 @@ func h(x float64) int { return 0 } var ( s uint = 33 u = 1.0 << s // ERROR "invalid operation|shift of non-integer operand" - v float32 = 1 << s // ERROR "invalid" "as type float32" + v float32 = 1 << s // ERROR "invalid" ) // non-constant shift expressions var ( - e1 = g(2.0 << s) // ERROR "invalid|shift of non-integer operand" "as type interface" - f1 = h(2 << s) // ERROR "invalid" "as type float64" + e1 = g(2.0 << s) // ERROR "invalid|shift of non-integer operand" + f1 = h(2 << s) // ERROR "invalid" g1 int64 = 1.1 << s // ERROR "truncated" ) @@ -66,8 +66,15 @@ func _() { u2 = 1<