From patchwork Tue Dec 14 23:45:52 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: 75587 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 4DCB3B6F11 for ; Wed, 15 Dec 2010 10:46:11 +1100 (EST) Received: (qmail 16735 invoked by alias); 14 Dec 2010 23:46:09 -0000 Received: (qmail 16726 invoked by uid 22791); 14 Dec 2010 23:46:08 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 23:46:03 +0000 Received: from wpaz29.hot.corp.google.com (wpaz29.hot.corp.google.com [172.24.198.93]) by smtp-out.google.com with ESMTP id oBENk17u027628 for ; Tue, 14 Dec 2010 15:46:01 -0800 Received: from pvg13 (pvg13.prod.google.com [10.241.210.141]) by wpaz29.hot.corp.google.com with ESMTP id oBENk0il020789 for ; Tue, 14 Dec 2010 15:46:00 -0800 Received: by pvg13 with SMTP id 13so290478pvg.24 for ; Tue, 14 Dec 2010 15:46:00 -0800 (PST) Received: by 10.142.254.21 with SMTP id b21mr4955197wfi.391.1292370360213; Tue, 14 Dec 2010 15:46:00 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-182.mtv.corp.google.com [172.22.122.182]) by mx.google.com with ESMTPS id p8sm738253wff.16.2010.12.14.15.45.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Dec 2010 15:45:59 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix comparisons of string and interface type Date: Tue, 14 Dec 2010 15:45:52 -0800 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 comparisons of string and interface types. The code was assuming that a string type could only be compared with another string type, which is not correct. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 440aea85b07b go/expressions.cc --- a/go/expressions.cc Tue Dec 14 15:32:56 2010 -0800 +++ b/go/expressions.cc Tue Dec 14 15:42:01 2010 -0800 @@ -5938,9 +5938,8 @@ gcc_unreachable(); } - if (left_type->is_string_type()) - { - gcc_assert(right_type->is_string_type()); + if (left_type->is_string_type() && right_type->is_string_type()) + { tree string_type = Type::make_string_type()->get_tree(context->gogo()); static tree string_compare_decl; left_tree = Gogo::call_builtin(&string_compare_decl, @@ -5954,13 +5953,12 @@ right_tree); right_tree = build_int_cst_type(integer_type_node, 0); } - - if ((left_type->interface_type() != NULL - && right_type->interface_type() == NULL - && !right_type->is_nil_type()) - || (left_type->interface_type() == NULL - && !left_type->is_nil_type() - && right_type->interface_type() != NULL)) + else if ((left_type->interface_type() != NULL + && right_type->interface_type() == NULL + && !right_type->is_nil_type()) + || (left_type->interface_type() == NULL + && !left_type->is_nil_type() + && right_type->interface_type() != NULL)) { // Comparing an interface value to a non-interface value. if (left_type->interface_type() == NULL)