Patchwork Go patch committed: Always determine call types

login
register
mail settings
Submitter Ian Taylor
Date March 3, 2011, 2:08 a.m.
Message ID <mcr62s13qhr.fsf@google.com>
Download mbox | patch
Permalink /patch/85211/
State New
Headers show

Comments

Ian Taylor - March 3, 2011, 2:08 a.m.
This patch to the Go frontend ensures that call expressions have their
types determined even if the first call result is not used.  I also
removed the do_discarding_value_ field from Call_expression, since it
was write-only.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 01d938e04210 go/expressions.cc
--- a/go/expressions.cc	Wed Mar 02 17:47:01 2011 -0800
+++ b/go/expressions.cc	Wed Mar 02 18:01:17 2011 -0800
@@ -7250,6 +7250,9 @@ 
 void
 Builtin_call_expression::do_determine_type(const Type_context* context)
 {
+  if (!this->determining_types())
+    return;
+
   this->fn()->determine_type_no_context();
 
   const Expression_list* args = this->args();
@@ -8486,6 +8489,9 @@ 
 void
 Call_expression::do_determine_type(const Type_context*)
 {
+  if (!this->determining_types())
+    return;
+
   this->fn_->determine_type_no_context();
   Function_type* fntype = this->get_function_type();
   const Typed_identifier_list* parameters = NULL;
@@ -8512,6 +8518,21 @@ 
     }
 }
 
+// Called when determining types for a Call_expression.  Return true
+// if we should go ahead, false if they have already been determined.
+
+bool
+Call_expression::determining_types()
+{
+  if (this->types_are_determined_)
+    return false;
+  else
+    {
+      this->types_are_determined_ = true;
+      return true;
+    }
+}
+
 // Check types for parameter I.
 
 bool
@@ -9004,8 +9025,7 @@ 
 void
 Call_result_expression::do_determine_type(const Type_context*)
 {
-  if (this->index_ == 0)
-    this->call_->determine_type_no_context();
+  this->call_->determine_type_no_context();
 }
 
 // Return the tree.
diff -r 01d938e04210 go/expressions.h
--- a/go/expressions.h	Wed Mar 02 17:47:01 2011 -0800
+++ b/go/expressions.h	Wed Mar 02 18:01:17 2011 -0800
@@ -1161,7 +1161,7 @@ 
 		  source_location location)
     : Expression(EXPRESSION_CALL, location),
       fn_(fn), args_(args), type_(NULL), tree_(NULL), is_varargs_(is_varargs),
-      is_value_discarded_(false), varargs_are_lowered_(false),
+      varargs_are_lowered_(false), types_are_determined_(false),
       is_deferred_(false)
   { }
 
@@ -1220,7 +1220,7 @@ 
 
   void
   do_discarding_value()
-  { this->is_value_discarded_ = true; }
+  { }
 
   virtual Type*
   do_type();
@@ -1263,6 +1263,11 @@ 
   lower_varargs(Gogo*, Named_object* function, Type* varargs_type,
 		size_t param_count);
 
+  // Let a builtin expression check whether types have been
+  // determined.
+  bool
+  determining_types();
+
  private:
   bool
   check_argument_type(int, const Type*, const Type*, source_location, bool);
@@ -1286,10 +1291,10 @@ 
   tree tree_;
   // True if the last argument is a varargs argument (f(a...)).
   bool is_varargs_;
-  // True if the value is being discarded.
-  bool is_value_discarded_;
   // True if varargs have already been lowered.
   bool varargs_are_lowered_;
+  // True if types have been determined.
+  bool types_are_determined_;
   // True if the call is an argument to a defer statement.
   bool is_deferred_;
 };