From patchwork Sat Sep 25 00:16:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 65713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EA37DB70F8 for ; Sat, 25 Sep 2010 10:16:39 +1000 (EST) Received: (qmail 8384 invoked by alias); 25 Sep 2010 00:16:36 -0000 Received: (qmail 8376 invoked by uid 22791); 25 Sep 2010 00:16:35 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, TW_PL, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 25 Sep 2010 00:16:30 +0000 Received: from hpaq5.eem.corp.google.com (hpaq5.eem.corp.google.com [172.25.149.5]) by smtp-out.google.com with ESMTP id o8P0GRo4001768 for ; Fri, 24 Sep 2010 17:16:27 -0700 Received: from pxi5 (pxi5.prod.google.com [10.243.27.5]) by hpaq5.eem.corp.google.com with ESMTP id o8P0GPvG009190 for ; Fri, 24 Sep 2010 17:16:26 -0700 Received: by pxi5 with SMTP id 5so2015201pxi.0 for ; Fri, 24 Sep 2010 17:16:25 -0700 (PDT) Received: by 10.142.148.3 with SMTP id v3mr3424638wfd.2.1285373785535; Fri, 24 Sep 2010 17:16:25 -0700 (PDT) Received: from coign.google.com ([67.218.106.122]) by mx.google.com with ESMTPS id u16sm2976561wfg.20.2010.09.24.17.16.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 24 Sep 2010 17:16:24 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Fix cmplx with mix of untyped constants and typed value Date: Fri, 24 Sep 2010 17:16:14 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 -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();