From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127052 invoked by alias); 27 Nov 2017 13:01:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127043 invoked by uid 89); 27 Nov 2017 13:01:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Nov 2017 13:01:45 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5946119D00F; Mon, 27 Nov 2017 13:01:44 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC57D5D972; Mon, 27 Nov 2017 13:01:30 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vARD16TM015306; Mon, 27 Nov 2017 14:01:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vARD15vB015305; Mon, 27 Nov 2017 14:01:05 +0100 Date: Mon, 27 Nov 2017 14:10:00 -0000 From: Jakub Jelinek To: Nathan Sidwell Cc: Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [C++ PATCH] Avoid -Wreturn-type warnings if a switch has default label, no breaks inside of it, but is followed by a break (PR sanitizer/81275) Message-ID: <20171127130105.GH2353@tucnak> Reply-To: Jakub Jelinek References: <20171124215953.GE14653@tucnak> <20171125090122.GH14653@tucnak> <20171126002256.GJ14653@tucnak> <553dc61a-6963-2d41-d55d-9b3fab8bd6f0@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <553dc61a-6963-2d41-d55d-9b3fab8bd6f0@acm.org> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02298.txt.bz2 On Mon, Nov 27, 2017 at 07:49:41AM -0500, Nathan Sidwell wrote: > On 11/25/2017 07:22 PM, Jakub Jelinek wrote: > > On Sat, Nov 25, 2017 at 10:01:22AM +0100, Jakub Jelinek wrote: > > > Actually, thinking about it some more, maybe it would be more efficient > > > to gather this information during construction of the SWITCH_STMT in some > > > new flag on the tree, so cxx_block_may_fallthru would just: > > > > Here it is implemented, bootstrapped/regtested on x86_64-linux and > > i686-linux, ok for trunk? > > nice. > > > --- gcc/cp/cp-tree.h.jj 2017-11-17 08:40:32.000000000 +0100 > > +++ gcc/cp/cp-tree.h 2017-11-25 21:25:48.277897180 +0100 > > > +/* Set if the body of a switch stmt contains a default: case label > > + and does not contain any break; stmts, thus if SWITCH_STMT_BODY > > + is not empty and doesn't fallthru, then the whole SWITCH_STMT > > + can't fallthru either. */ > > +#define SWITCH_STMT_CANNOT_FALLTHRU_P(NODE) \ > > + TREE_LANG_FLAG_0 (SWITCH_STMT_CHECK (NODE)) > > The macro name isn't quite right. As the comment says, it's not sufficient > that this flag is set for the switch to not fall through -- the switch body > must be non-empty (which I presume it cannot be as there must be a default > label), and it cannot fall through in its own right. You are right that I can remove the || SWITCH_STMT_BODY (stmt) == NULL_TREE, part, because then there wouldn't be any case labels in it either. > The semantics of this flag are more like SWITCH_STMT_COVERS_ALL_CASES, > perhaps something of that ilk would be a clearer name? Well, that is only part of it. Right now in the patch it does SWITCH_STMT_WITH_DEFAULT_WITHOUT_BREAK_P(NODE) When not processing_template_decl, we could perhaps do better and have it SWITCH_STMT_COVERS_ALL_CASES_NO_BREAK_P(NODE), because in that case we have the splay tree of all the case labels and we could compute whether even without default: they cover all values. Could add that as a follow-up. Any preference on the macro name then? Jakub