public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107571] Missing fallthrough attribute diagnostics Date: Fri, 17 Nov 2023 14:51:10 +0000 [thread overview] Message-ID: <bug-107571-4-hTfwkjidJG@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107571-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107571 --- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:52eedfa00960f2d255ec542626e3531a65aa8bb8 commit r14-5561-g52eedfa00960f2d255ec542626e3531a65aa8bb8 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Nov 17 15:43:31 2023 +0100 c++: Implement C++ DR 2406 - [[fallthrough]] attribute and iteration statements The following patch implements CWG 2406 - [[fallthrough]] attribute and iteration statements The genericization of some loops leaves nothing at all or just a label after a body of a loop, so if the loop is later followed by case or default label in a switch, the fallthrough statement isn't diagnosed. The following patch implements it by marking the IFN_FALLTHROUGH call in such a case, such that during gimplification it can be pedantically diagnosed even if it is followed by case or default label or some normal labels followed by case/default labels. While looking into this, I've discovered other problems. expand_FALLTHROUGH_r is removing the IFN_FALLTHROUGH calls from the IL, but wasn't telling that to walk_gimple_stmt/walk_gimple_seq_mod, so the callers would then skip the next statement after it, and it would return non-NULL if the removed stmt was last in the sequence. This could lead to wi->callback_result being set even if it didn't appear at the very end of switch sequence. The patch makes use of wi->removed_stmt such that the callers properly know what happened, and use different way to handle the end of switch sequence case. That change discovered a bug in the gimple-walk handling of wi->removed_stmt. If that flag is set, the callback is telling the callers that the current statement has been removed and so the innermost walk_gimple_seq_mod shouldn't gsi_next. The problem is that wi->removed_stmt is only reset at the start of a walk_gimple_stmt, but that can be too late for some cases. If we have two nested gimple sequences, say GIMPLE_BIND as the last stmt of some gimple seq, we remove the last statement inside of that GIMPLE_BIND, set wi->removed_stmt there, don't do gsi_next correctly because already gsi_remove moved us to the next stmt, there is no next stmt, so we return back to the caller, but wi->removed_stmt is still set and so we don't do gsi_next even in the outer sequence, despite the GIMPLE_BIND (etc.) not being removed. That means we walk the GIMPLE_BIND with its whole sequence again. The patch fixes that by resetting wi->removed_stmt after we've used that flag in walk_gimple_seq_mod. Nothing really uses that flag after the outermost walk_gimple_seq_mod, it is just a private notification that the stmt callback has removed a stmt. 2023-11-17 Jakub Jelinek <jakub@redhat.com> PR c++/107571 gcc/ * gimplify.cc (expand_FALLTHROUGH_r): Use wi->removed_stmt after gsi_remove, change the way of passing fallthrough stmt at the end of sequence to expand_FALLTHROUGH. Diagnose IFN_FALLTHROUGH with GF_CALL_NOTHROW flag. (expand_FALLTHROUGH): Change loc into array of 2 location_t elts, don't test wi.callback_result, instead check whether first elt is not UNKNOWN_LOCATION and in that case pedwarn with the second location. * gimple-walk.cc (walk_gimple_seq_mod): Clear wi->removed_stmt after the flag has been used. * internal-fn.def (FALLTHROUGH): Mention in comment the special meaning of the TREE_NOTHROW/GF_CALL_NOTHROW flag on the calls. gcc/c-family/ * c-gimplify.cc (genericize_c_loop): For C++ mark IFN_FALLTHROUGH call at the end of loop body as TREE_NOTHROW. gcc/testsuite/ * g++.dg/DRs/dr2406.C: New test.
next prev parent reply other threads:[~2023-11-17 14:51 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-08 14:49 [Bug c++/107571] New: " jakub at gcc dot gnu.org 2022-11-08 22:27 ` [Bug c++/107571] " jakub at gcc dot gnu.org 2022-11-08 22:28 ` mpolacek at gcc dot gnu.org 2022-11-08 22:40 ` jakub at gcc dot gnu.org 2022-11-09 0:36 ` joseph at codesourcery dot com 2023-11-17 14:51 ` cvs-commit at gcc dot gnu.org [this message] 2023-11-17 14:55 ` jakub at gcc dot gnu.org
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=bug-107571-4-hTfwkjidJG@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /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: linkBe 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).