compiler: Accept untyped integral values as string/array indices.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 29 Sep 2015 22:27:53 +0000 (22:27 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 29 Sep 2015 22:27:53 +0000 (22:27 +0000)
    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

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index 448e5e82bad8fad375dc31b59a2dc9921ccc1edf..eaa24dcbfef2f6931d0e1bc93e5876f307d889f2 100644 (file)
@@ -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 7ad271f109b9eef26f89a7421714cce127446542..56bbf619bd85c596a755d1e97876165a67bec7c3 100644 (file)
@@ -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.