From patchwork Tue Aug 31 22:02:48 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: 63321 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 54DCEB7159 for ; Wed, 1 Sep 2010 08:03:28 +1000 (EST) Received: (qmail 23345 invoked by alias); 31 Aug 2010 22:03:26 -0000 Received: (qmail 23249 invoked by uid 22791); 31 Aug 2010 22:03:25 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, 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; Tue, 31 Aug 2010 22:02:55 +0000 Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id o7VM2rQa005532 for ; Tue, 31 Aug 2010 15:02:53 -0700 Received: from gwb11 (gwb11.prod.google.com [10.200.2.11]) by hpaq12.eem.corp.google.com with ESMTP id o7VM2X91008344 for ; Tue, 31 Aug 2010 15:02:52 -0700 Received: by gwb11 with SMTP id 11so2786146gwb.32 for ; Tue, 31 Aug 2010 15:02:51 -0700 (PDT) Received: by 10.150.204.10 with SMTP id b10mr2616761ybg.139.1283292171574; Tue, 31 Aug 2010 15:02:51 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-124-178.mtv.corp.google.com [172.22.124.178]) by mx.google.com with ESMTPS id q38sm1557239yba.6.2010.08.31.15.02.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 31 Aug 2010 15:02:50 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Don't get confused by floating point array length Date: Tue, 31 Aug 2010 15:02:48 -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 Go's untyped constants mean that you can use a floating point number as an array length, as long as it has an integral value. That works fine, but some of the tree code wound up using a floating point constant unexpectedly, leading to a compiler crash. This patch fixes the problem. Committed to gccgo branch. Ian Index: gcc/go/Make-lang.in =================================================================== --- gcc/go/Make-lang.in (revision 163703) +++ gcc/go/Make-lang.in (revision 163704) @@ -176,6 +176,7 @@ go/statements.o: go/statements.cc $(GO_S $(GO_C_H) $(GO_TYPES_H) $(GO_EXPRESSIONS_H) $(GO_GOGO_H) \ $(GO_STATEMENTS_H) go/types.o: go/types.cc $(GO_SYSTEM_H) intl.h $(TREE_H) $(GIMPLE_H) \ - $(REAL_H) $(GO_C_H) $(GO_GOGO_H) go/operator.h $(GO_EXPRESSIONS_H) \ - $(GO_STATEMENTS_H) go/export.h $(GO_IMPORT_H) $(GO_TYPES_H) + $(REAL_H) convert.h $(GO_C_H) $(GO_GOGO_H) go/operator.h \ + $(GO_EXPRESSIONS_H) $(GO_STATEMENTS_H) go/export.h $(GO_IMPORT_H) \ + $(GO_TYPES_H) go/unsafe.o: go/unsafe.cc $(GO_SYSTEM_H) $(GO_TYPES_H) $(GO_GOGO_H) Index: gcc/go/types.cc =================================================================== --- gcc/go/types.cc (revision 163703) +++ gcc/go/types.cc (revision 163704) @@ -16,6 +16,7 @@ extern "C" #include "tree.h" #include "gimple.h" #include "real.h" +#include "convert.h" } #include "go-c.h" @@ -3438,7 +3439,9 @@ Array_type::get_length_tree(Gogo* gogo) // Make up a translation context for the array length // expression. FIXME: This won't work in general. Translate_context context(gogo, NULL, NULL, NULL_TREE); - this->length_tree_ = save_expr(this->length_->get_tree(&context)); + tree len = this->length_->get_tree(&context); + len = convert_to_integer(integer_type_node, len); + this->length_tree_ = save_expr(len); } } return this->length_tree_;