From patchwork Fri Oct 8 20:44:15 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: 67285 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 1ED16B6EFF for ; Sat, 9 Oct 2010 07:49:44 +1100 (EST) Received: (qmail 1919 invoked by alias); 8 Oct 2010 20:49:42 -0000 Received: (qmail 1905 invoked by uid 22791); 8 Oct 2010 20:49:40 -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, 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; Fri, 08 Oct 2010 20:49:35 +0000 Received: from kpbe13.cbf.corp.google.com (kpbe13.cbf.corp.google.com [172.25.105.77]) by smtp-out.google.com with ESMTP id o98KnTmZ029417 for ; Fri, 8 Oct 2010 13:49:32 -0700 Received: from pzk5 (pzk5.prod.google.com [10.243.19.133]) by kpbe13.cbf.corp.google.com with ESMTP id o98KiK0e013894 for ; Fri, 8 Oct 2010 13:44:21 -0700 Received: by pzk5 with SMTP id 5so42370pzk.9 for ; Fri, 08 Oct 2010 13:44:20 -0700 (PDT) Received: by 10.114.136.19 with SMTP id j19mr3427628wad.54.1286570659254; Fri, 08 Oct 2010 13:44:19 -0700 (PDT) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id p6sm1110759wal.19.2010.10.08.13.44.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 08 Oct 2010 13:44:18 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Thunk statements need not be the only statements in a block Date: Fri, 08 Oct 2010 13:44:15 -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 The Go parser arranges for thunk statements (from go and defer statements in the language) to be the only statements in their block. The code which simplifies these statements was assuming that. However, it is possible for the passes which enforce order of evaluation to break the thunk statements into multiple statements. This patch fixes the simplification code to assume that the thunk statement is the last statement in the block, rather than assuming that it is the only statement in the block. Committed to gccgo branch. Ian diff -r 5f836c41c4e8 go/gogo.h --- a/go/gogo.h Fri Oct 08 13:37:52 2010 -0700 +++ b/go/gogo.h Fri Oct 08 13:42:06 2010 -0700 @@ -856,11 +856,6 @@ void determine_types(); - // Swap the block's statements with STATEMENTS. - void - swap_statements(std::vector& statements) - { this->statements_.swap(statements); } - // Return true if execution of this block may fall through to the // next block. bool diff -r 5f836c41c4e8 go/statements.cc --- a/go/statements.cc Fri Oct 08 13:37:52 2010 -0700 +++ b/go/statements.cc Fri Oct 08 13:42:06 2010 -0700 @@ -1768,11 +1768,11 @@ int Simplify_thunk_traverse::block(Block* b) { - // The parser ensures that thunk statements always appear in a block - // which has only a single statement. - if (b->statements()->size() != 1) + // The parser ensures that thunk statements always appear at the end + // of a block. + if (b->statements()->size() < 1) return TRAVERSE_CONTINUE; - Thunk_statement* stat = b->statements()->front()->thunk_statement(); + Thunk_statement* stat = b->statements()->back()->thunk_statement(); if (stat == NULL) return TRAVERSE_CONTINUE; if (stat->simplify_statement(this->gogo_, b)) @@ -1897,16 +1897,14 @@ else gcc_unreachable(); - // The current block should only have the go statement. - gcc_assert(block->statements()->size() == 1); - gcc_assert(block->statements()->front() == this); - std::vector statements; - statements.push_back(s); - block->swap_statements(statements); + // The current block should end with the go statement. + gcc_assert(block->statements()->size() >= 1); + gcc_assert(block->statements()->back() == this); + block->replace_statement(block->statements()->size() - 1, s); // We already ran the determine_types pass, so we need to run it now - // for this new block. - block->determine_types(); + // for the new statement. + s->determine_types(); // Sanity check. gogo->check_types_in_block(block);