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  <ja...@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 via email to