From patchwork Wed Aug 7 19:01:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 265593 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9B8CE2C0090 for ; Thu, 8 Aug 2013 05:01:35 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=GHu+Fcgd/I0xJvVAU0bJsxSYxcpba5zRQGutA6ZfABsVaT75aOLb6 +vd56mTJV9JcjcTepjbT3L7gTIYpXeHLffVPh9rOdmw+8Do/rPyLnaEOjaizO06Z 5xFoy0IIusxbeDc+1HFgNveJGBTHPb3qWs1arMkiBFpUfOpON23vE0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=zPFmEGhOhEED/i594fe/zAP4A+o=; b=oeh2vKcDtc48U5v7O35I 3WqRLe29Z6XmJhbQkQ3lo0Ry7sewLp8sgZWnTdYsknv++8ykPNqdMo26KSM2nxAK nNtqd8T+awXRWwCDk9rLTou0+0lmghFPgl+Z3XPmXueVaSFU8maPXwqnxZAMLbV7 OuO5cl077IRg/GtaqV3SuxE= Received: (qmail 30728 invoked by alias); 7 Aug 2013 19:01:29 -0000 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 Received: (qmail 30702 invoked by uid 89); 7 Aug 2013 19:01:28 -0000 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RDNS_NONE, SPF_PASS, T_TVD_MIME_NO_HEADERS autolearn=no version=3.3.1 Received: from Unknown (HELO mail-oa0-f44.google.com) (209.85.219.44) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 07 Aug 2013 19:01:27 +0000 Received: by mail-oa0-f44.google.com with SMTP id l20so4136720oag.31 for ; Wed, 07 Aug 2013 12:01:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=o6bllZEHVeaejEt4jD8MX7SconCWGrfJFvJE4Pz+ySc=; b=jZA5BOv0mYd58d/qddvPMKQRQHFDxWRg75TDysbBuQoUS2Oue5GFKw/xBqIQ41BuZF BA5fRQyPy427BIcff4hzxAWDy+CEkv5iFjq2501YZWfVhCTwcLCQs/B3jCR3KB3d1FF5 CZ+1X/jf67xkVZoIuPebzhGblpEWq2EHNvslskLQnzDN1x0Rd40Wt5N2m8Sh4kNM+r+G CuAYfdGRUNBBXVxONTt7BaW9aOjzuCkAoOuqbP0lzIE4xb1/m969UTGjIizserwApoX9 1kHyrISEiU3nr0Gl4nx12KkVq+Xedd3a0jU6QpHa8isQr/60pmEOP1g9EaI+4FGG/mC5 DV1Q== X-Gm-Message-State: ALoCoQn9rHJM8x9IWCAZR+h8euDbKAamLiaa5J/TZ9MiMTkzmiE1BCwQEJqbm2srfNxQntB4Ep4aJN5FrmRlBwlHOfnskkzjFAWE1/xBydoWIr0/EEY8Y88whumlo55gVP6ymYBwWEtMGlk5E3aI4kM8+Buw7J8fIRTatGO/gVpJKzH/ap+38xrcxmHS9WWOtas+rR7aaWx5jm+eNSx5x7Xuxlq2PXbG6w== X-Received: by 10.182.60.138 with SMTP id h10mr3565935obr.104.1375902080393; Wed, 07 Aug 2013 12:01:20 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com ([2620:0:1000:3204:fdf7:175d:ba07:2dc4]) by mx.google.com with ESMTPSA id fh1sm9574163oeb.7.2013.08.07.12.01.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 07 Aug 2013 12:01:20 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix missing return error for type switches Date: Wed, 07 Aug 2013 12:01:17 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-Virus-Found: No The Go frontend gave an incorrect "missing return" error message for a type switch with a case with multiple types, as in "case T1, T2:". This patch fixes that problem. This patch also changes the "missing return" error message to use the same text as the gc compiler, and reports it at the end of the function rather than the start of the function, again to match the gc compiler. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch. Ian Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 201536) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -3133,7 +3133,8 @@ Check_return_statements_traverse::functi return TRAVERSE_CONTINUE; if (func->block()->may_fall_through()) - error_at(func->location(), "control reaches end of non-void function"); + error_at(func->block()->end_location(), + "missing return at end of function"); return TRAVERSE_CONTINUE; } Index: gcc/go/gofrontend/statements.cc =================================================================== --- gcc/go/gofrontend/statements.cc (revision 201536) +++ gcc/go/gofrontend/statements.cc (working copy) @@ -4093,6 +4093,16 @@ Type_case_clauses::Type_case_clause::low bool Type_case_clauses::Type_case_clause::may_fall_through() const { + if (this->is_fallthrough_) + { + // This case means that we automatically fall through to the + // next case (it's used for T1 in case T1, T2:). It does not + // mean that we fall through to the end of the type switch as a + // whole. There is sure to be a next case and that next case + // will determine whether we fall through to the statements + // after the type switch. + return false; + } if (this->statements_ == NULL) return true; return this->statements_->may_fall_through(); Index: gcc/testsuite/go.test/test/fixedbugs/bug086.go =================================================================== --- gcc/testsuite/go.test/test/fixedbugs/bug086.go (revision 200210) +++ gcc/testsuite/go.test/test/fixedbugs/bug086.go (working copy) @@ -6,12 +6,12 @@ package main -func f() int { // ERROR "return|control" +func f() int { if false { return 0; } // we should not be able to return successfully w/o a return statement -} +} // ERROR "return" func main() { print(f(), "\n");