public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jason Merrill <jason@redhat.com>, 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, take 2)
Date: Tue, 28 Nov 2017 11:58:00 -0000	[thread overview]
Message-ID: <6646d8a9-5067-3d39-c75c-b265b1e0f6cb@acm.org> (raw)
In-Reply-To: <20171128085313.GP2353@tucnak>

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  <jakub@redhat.com>
> 
> 	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

  reply	other threads:[~2017-11-28 11:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-25  0:37 [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) Jakub Jelinek
2017-11-25 10:16 ` Jakub Jelinek
2017-11-26  9:05   ` Jakub Jelinek
2017-11-27 13:39     ` Nathan Sidwell
2017-11-27 14:10       ` Jakub Jelinek
2017-11-28  9:14         ` [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) Jakub Jelinek
2017-11-28 11:58           ` Nathan Sidwell [this message]
2017-11-27 12:49   ` [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) Nathan Sidwell
2017-11-27 12:44 ` Nathan Sidwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6646d8a9-5067-3d39-c75c-b265b1e0f6cb@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).