aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-09-29 22:27:53 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-09-29 22:27:53 +0000
commit3734a25644d2f7ea652303f4268de9e52e4a5a64 (patch)
treebe482fe03750db0319b2dd4ca21fd62cdae003d3 /gcc/go
parent01bdcc80e25866fcd982075617f62a53c18659a3 (diff)
downloadgcc-3734a25644d2f7ea652303f4268de9e52e4a5a64.zip
gcc-3734a25644d2f7ea652303f4268de9e52e4a5a64.tar.gz
gcc-3734a25644d2f7ea652303f4268de9e52e4a5a64.tar.bz2
compiler: Accept untyped integral values as string/array indices.
When determining the type of an index for a string/array indexing expression, the gofrontend would disallow floating-point and complex values even if they were integral and throw an internal error. This patch changes gofrontend to use an integral type context when determining the types of a string/array index. Fixes golang/go#11545. Reviewed-on: https://go-review.googlesource.com/13796 From-SVN: r228270
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/expressions.cc35
2 files changed, 31 insertions, 6 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 448e5e8..eaa24dc 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -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.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 7ad271f..56bbf61 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -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.