From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 87737 invoked by alias); 28 Nov 2017 11:55:23 -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 87723 invoked by uid 89); 28 Nov 2017 11:55:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_SHORT,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mail-qk0-f196.google.com Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Nov 2017 11:55:20 +0000 Received: by mail-qk0-f196.google.com with SMTP id b85so73469qkc.13 for ; Tue, 28 Nov 2017 03:55:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XjQHlNZMUqKFP0NEWSzjXOuy6yNkPi8hEt2GL/OBLVs=; b=g4wGvBUYK/UedVgUn3KhKeW9v1XCwO+lDViCEtMSE2hTpcychpSQWkCDtdV1gHrLe6 00/zpkdOPKvr9ihv4M3LIuU3gxdCoGTbiRjEH1bdrfZq2/yDDtS6MRWNnNSr39toubQN RgKBOkFmsygFQ/GuAZbTUcHOsV0m5o0X7kyAyvrAnWElKfI328gYI+WyXvPNn4KGxD8e 6BkxKVaWkx2YkiXa2JGIehDcaYif/7fFaRwm/YRXno10iViEO7h+pbW/4yo1FN0l3ysD x07ppzNhlVhFJ1lyx1yTvl+UfLj25UOGHJwNF8WOI5xLH1S4NxwGQStVI9IBUwKxTT3F M2CA== X-Gm-Message-State: AJaThX5dQCvPf1JaFmlKKJWRlq/jytd2hAi/2MlCSfq0Xh6d5D9aeOhg 6ZB8U0tFsylS27N4teAAdDs= X-Google-Smtp-Source: AGs4zMaxX1W1xNUg/FCesIH7QyM2z92kF8mB+BRsgtlIZcFZ92SCNKnUkXmVy1ipggslU25YZEfrcg== X-Received: by 10.55.188.71 with SMTP id m68mr29505316qkf.44.1511870118669; Tue, 28 Nov 2017 03:55:18 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:38a4]) by smtp.googlemail.com with ESMTPSA id k1sm18870880qtf.11.2017.11.28.03.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2017 03:55:18 -0800 (PST) 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, take 2) To: Jakub Jelinek Cc: Jason Merrill , gcc-patches@gcc.gnu.org References: <20171124215953.GE14653@tucnak> <20171125090122.GH14653@tucnak> <20171126002256.GJ14653@tucnak> <553dc61a-6963-2d41-d55d-9b3fab8bd6f0@acm.org> <20171127130105.GH2353@tucnak> <20171128085313.GP2353@tucnak> From: Nathan Sidwell Message-ID: <6646d8a9-5067-3d39-c75c-b265b1e0f6cb@acm.org> Date: Tue, 28 Nov 2017 11:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171128085313.GP2353@tucnak> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2017-11/txt/msg02396.txt.bz2 On 11/28/2017 03:53 AM, Jakub Jelinek wrote: > On Mon, Nov 27, 2017 at 02:01:05PM +0100, Jakub Jelinek wrote: >> 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. > > ... > > Here is an updated patch, on top of the C patch I've just posted: > http://gcc.gnu.org/ml/gcc-patches/2017-11/msg02372.html > (though that dependency could be easily removed if needed by dropping the > c_switch_covers_all_cases_p call and SWITCH_ALL_CASES_P setting from > SWITCH_STMT_ALL_CASES_P). > Note, looking for default is still needed, because in templates we do not > build the cases splay tree and therefore would never set > SWITCH_STMT_ALL_CASES_P. Computing the cases splay tree is probably too > expensive, but default tracking is cheap. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2017-11-28 Jakub Jelinek > > PR sanitizer/81275 > * cp-tree.h (SWITCH_STMT_ALL_CASES_P): Define. > (SWITCH_STMT_NO_BREAK_P): Define. > (note_break_stmt, note_iteration_stmt_body_start, > note_iteration_stmt_body_end): Declare. > * decl.c (struct cp_switch): Add has_default_p, break_stmt_seen_p > and in_loop_body_p fields. > (push_switch): Clear them. > (pop_switch): Set SWITCH_STMT_CANNOT_FALLTHRU_P if has_default_p > and !break_stmt_seen_p. Assert in_loop_body_p is false. > (note_break_stmt, note_iteration_stmt_body_start, > note_iteration_stmt_body_end): New functions. > (finish_case_label): Set has_default_p when both low and high > are NULL_TREE. > * parser.c (cp_parser_iteration_statement): Use > note_iteration_stmt_body_start and note_iteration_stmt_body_end > around parsing iteration body. > * pt.c (tsubst_expr): Likewise. > * cp-objcp-common.c (cxx_block_may_fallthru): Return false for > SWITCH_STMT which contains no BREAK_STMTs, contains a default: > CASE_LABEL_EXPR and where SWITCH_STMT_BODY isn't empty and > can't fallthru. > * semantics.c (finish_break_stmt): Call note_break_stmt. > * cp-gimplify.c (genericize_switch_stmt): Copy SWITCH_STMT_ALL_CASES_P > bit to SWITCH_ALL_CASES_P. Assert that if SWITCH_STMT_NO_BREAK_P then > the break label is not TREE_USED. Ok. one nit. > #define SWITCH_STMT_BODY(NODE) TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 1) > #define SWITCH_STMT_TYPE(NODE) TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 2) > #define SWITCH_STMT_SCOPE(NODE) TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 3) > +/* True if there all case labels for all possible values of switch cond, either s/all/are/ (first one, no trailing 'g' modifier :) > + because there is a default: case label or because the case label ranges cover > + all values. */ nathan -- Nathan Sidwell