diff mbox

[gccgo] Fix cmplx with mix of untyped constants and typed value

Message ID mcr7hiaznht.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Sept. 25, 2010, 12:16 a.m. UTC
This patch fixes using the predeclared function cmplx with a mix of an
untyped constant and some typed value.  It ensures that the untyped
constant picks up the type of the value.  Committed to gccgo branch.

Ian
diff mbox

Patch

diff -r 2809fbf2083a go/expressions.cc
--- a/go/expressions.cc	Wed Sep 22 14:40:29 2010 -0700
+++ b/go/expressions.cc	Fri Sep 24 17:13:03 2010 -0700
@@ -6806,6 +6806,8 @@ 
 {
   this->fn()->determine_type_no_context();
 
+  const Expression_list* args = this->args();
+
   bool is_print;
   Type* arg_type = NULL;
   switch (this->code_)
@@ -6823,8 +6825,21 @@ 
       break;
 
     case BUILTIN_CMPLX:
-      arg_type = Builtin_call_expression::real_imag_type(context->type);
-      is_print = false;
+      {
+	// For the cmplx function the type of one operand can
+	// determine the type of the other, as in a binary expression.
+	arg_type = Builtin_call_expression::real_imag_type(context->type);
+	if (args != NULL && args->size() == 2)
+	  {
+	    Type* t1 = args->front()->type();
+	    Type* t2 = args->front()->type();
+	    if (!t1->is_abstract())
+	      arg_type = t1;
+	    else if (!t2->is_abstract())
+	      arg_type = t2;
+	  }
+	is_print = false;
+      }
       break;
 
     default:
@@ -6832,7 +6847,6 @@ 
       break;
     }
 
-  const Expression_list* args = this->args();
   if (args != NULL)
     {
       for (Expression_list::const_iterator pa = args->begin();