From patchwork Tue Aug 24 20:21:09 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: 62623 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 5878CB70CC for ; Wed, 25 Aug 2010 06:21:30 +1000 (EST) Received: (qmail 14884 invoked by alias); 24 Aug 2010 20:21:28 -0000 Received: (qmail 14873 invoked by uid 22791); 24 Aug 2010 20:21:28 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, TW_TM, 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, 24 Aug 2010 20:21:23 +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 o7OKLL4G005367 for ; Tue, 24 Aug 2010 13:21:21 -0700 Received: from iwn36 (iwn36.prod.google.com [10.241.68.100]) by wpaz29.hot.corp.google.com with ESMTP id o7OKLGjD029498 for ; Tue, 24 Aug 2010 13:21:20 -0700 Received: by iwn36 with SMTP id 36so9036504iwn.41 for ; Tue, 24 Aug 2010 13:21:16 -0700 (PDT) Received: by 10.231.146.129 with SMTP id h1mr8671719ibv.181.1282681276393; Tue, 24 Aug 2010 13:21:16 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-124-172.mtv.corp.google.com [172.22.124.172]) by mx.google.com with ESMTPS id j2sm395283iba.18.2010.08.24.13.21.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Aug 2010 13:21:15 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Don't use statement lists in constructors Date: Tue, 24 Aug 2010 13:21:09 -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 gccgo crashed on this test case, now added as bug304.go in the unified Go testsuite. package p type S struct { v interface{} } func g(e interface{}) { } func f(s S) { g(s.v.(*int)) } The crash was because the frontend put a STATEMENT_LIST in a constructor, which failed when the gimplifier attempted to copy the value as an initializer for a temporary value. This may or may not be a bug in the gimplifier, I'm not sure. But in any case it's easy to fix in the gccgo frontend. Committed to gccgo branch. Ian diff -r fe1e44128513 go/expressions.cc --- a/go/expressions.cc Sun Aug 01 06:03:09 2010 -0700 +++ b/go/expressions.cc Tue Aug 24 13:10:49 2010 -0700 @@ -697,9 +697,6 @@ // This call will panic if the conversion is invalid. TREE_NOTHROW(check_interface_type_decl) = 0; - tree stmt_list = NULL_TREE; - append_to_statement_list(call, &stmt_list); - // If the call succeeds, pull out the value. gcc_assert(TREE_CODE(rhs_type_tree) == RECORD_TYPE); tree rhs_field = TREE_CHAIN(TYPE_FIELDS(rhs_type_tree)); @@ -710,22 +707,22 @@ // If the value is a pointer, then we can just get it from the // interface. Otherwise we have to make a copy. if (lhs_type->points_to() != NULL) - return build2(COMPOUND_EXPR, lhs_type_tree, stmt_list, + return build2(COMPOUND_EXPR, lhs_type_tree, call, fold_convert_loc(location, lhs_type_tree, val)); tree tmp = create_tmp_var(lhs_type_tree, NULL); DECL_IGNORED_P(tmp) = 0; tree make_tmp = fold_build1_loc(location, DECL_EXPR, void_type_node, tmp); - append_to_statement_list(make_tmp, &stmt_list); + tree s = build2(COMPOUND_EXPR, void_type_node, call, make_tmp); val = fold_convert_loc(location, build_pointer_type(lhs_type_tree), val); val = build_fold_indirect_ref_loc(location, val); tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node, tmp, val); - append_to_statement_list(set, &stmt_list); - - return build2(COMPOUND_EXPR, lhs_type_tree, stmt_list, tmp); + s = build2(COMPOUND_EXPR, void_type_node, s, set); + + return build2(COMPOUND_EXPR, lhs_type_tree, s, tmp); } // Convert an expression to a tree. This is implemented by the child