From patchwork Tue Jan 24 20:52:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 137653 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 AD22FB6F68 for ; Wed, 25 Jan 2012 07:53:00 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1328043180; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=YtV8LXEIlnqQSlcxoqZ14aH2qfw=; b=flAdl4YkxysUIKp zkHe7OYUnU5fhtRvw/2aMykY0Pqy4IatCWOD/46Wnp0PLIH8L0VdWwFtjqU48sJ8 bLPmckZa2TWCar0InWdtGHpRY9x0vGHpSqjc14U72AMVd6szgXAUA7+RH/hBDVdj SQeQYUsTgc06cpdv1ANEzzajAuAk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:X-Gm-Message-State:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=B3MNnsUGwX93kdOHfcFKss5xN4LIOwdTrAstel2XMMZXTztDw1WNJpQ414sWu2 p05RMrH2fqFDzBv+22zmzdibJEFEolJf3JAdfElpyBPwxFV0sTKeCV0lRZlnJUvh KB7mO0Botv55Z2QiBXZJxMhNB3/46VFFdRe/g1OMaWj08=; Received: (qmail 13784 invoked by alias); 24 Jan 2012 20:52:56 -0000 Received: (qmail 13775 invoked by uid 22791); 24 Jan 2012 20:52:55 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Jan 2012 20:52:42 +0000 Received: by dakf10 with SMTP id f10so409495dak.20 for ; Tue, 24 Jan 2012 12:52:41 -0800 (PST) Received: by 10.68.83.105 with SMTP id p9mr33792769pby.92.1327438361929; Tue, 24 Jan 2012 12:52:41 -0800 (PST) Received: by 10.68.83.105 with SMTP id p9mr33792741pby.92.1327438361814; Tue, 24 Jan 2012 12:52:41 -0800 (PST) Received: from coign.google.com ([2620:0:1000:2301:f2de:f1ff:fe40:72a8]) by mx.google.com with ESMTPS id i1sm576367pbt.19.2012.01.24.12.52.40 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Jan 2012 12:52:41 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix type switch block Date: Tue, 24 Jan 2012 12:52:39 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkuFW1UpiYu2vREiZuN8wvIXTdy47ciMknSraqjFoBZAgI9WOr0RmpeFsA/ecUDwpB4La2Hq1L4nYeoYHclakPY8C6xR5udR6ImC+t/DDy8Krmml103GsZkTegryyqb0Uh6uOmgwDQI+JFFVa4nVV9Vx+aSht0WZeXhyjIX6JNqoHNnNpc= 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 In Go, in a type switch like switch t := 0; t := x.(type) the two variables named 't' are in different blocks; they are not a redefinition. This patch implements that in gccgo. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 725daf468f17 go/parse.cc --- a/go/parse.cc Tue Jan 24 11:31:26 2012 -0800 +++ b/go/parse.cc Tue Jan 24 12:49:40 2012 -0800 @@ -4057,6 +4057,7 @@ Expression* switch_val = NULL; bool saw_send_stmt; Type_switch type_switch; + bool have_type_switch_block = false; if (this->simple_stat_may_start_here()) { switch_val = this->simple_stat(false, &saw_send_stmt, NULL, @@ -4099,7 +4100,14 @@ id_loc)); if (is_coloneq) { - // This must be a TypeSwitchGuard. + // This must be a TypeSwitchGuard. It is in a + // different block from any initial SimpleStat. + if (saw_simple_stat) + { + this->gogo_->start_block(id_loc); + have_type_switch_block = true; + } + switch_val = this->simple_stat(false, &saw_send_stmt, NULL, &type_switch); if (!type_switch.found) @@ -4142,13 +4150,23 @@ if (this->peek_token()->is_op(OPERATOR_SEMICOLON)) this->advance_token(); if (!this->peek_token()->is_op(OPERATOR_LCURLY)) - return; + { + if (have_type_switch_block) + this->gogo_->add_block(this->gogo_->finish_block(location), + location); + this->gogo_->add_block(this->gogo_->finish_block(location), + location); + return; + } if (type_switch.found) type_switch.expr = Expression::make_error(location); } else { error_at(this->location(), "expected %<{%>"); + if (have_type_switch_block) + this->gogo_->add_block(this->gogo_->finish_block(this->location()), + location); this->gogo_->add_block(this->gogo_->finish_block(this->location()), location); return; @@ -4165,6 +4183,10 @@ if (statement != NULL) this->gogo_->add_statement(statement); + if (have_type_switch_block) + this->gogo_->add_block(this->gogo_->finish_block(this->location()), + location); + this->gogo_->add_block(this->gogo_->finish_block(this->location()), location); }