[Bug objc/103639] [11/12 Regression] switch case with break in fast enumeration loop generates wrong code

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Jan 1 05:32:16 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103639

--- Comment #17 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:222dbebefbbc07f78e51d82ba605988ef57e5fc9

commit r12-6162-g222dbebefbbc07f78e51d82ba605988ef57e5fc9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Jan 1 06:29:36 2022 +0100

    objc: Fix handling of break stmt inside of switch inside of ObjC foreach
[PR103639]

    The r11-3302-g3696a50beeb73f changes broke the following ObjC testcase.
    in_statement is either 0 (not in a looping statement), various IN_* flags
    for various kinds of looping statements (or OpenMP structured blocks) or
    those flags ored with IN_SWITCH_STMT when a switch appears inside of those
    contexts.  This is because break binds to switch in that last case, but
    continue binds to the looping construct in that case.
    The c_finish_bc_stmt function performs diagnostics on incorrect
    break/continue uses and then checks if in_statement & IN_OBJC_FOREACH
    and in that case jumps to the label provided by the caller, otherwise
    emits a BREAK_STMT or CONTINUE_STMT.  This is incorrect if we have
    ObjC foreach with switch nested in it and break inside of that,
    in_statement in that case is IN_OBJC_FOREACH | IN_SWITCH_STMT and
    is_break is true.  We want to handle it like other breaks inside of
    switch, i.e. emit a BREAK_STMT.

    The following patch fixes that.

    2022-01-01  Jakub Jelinek  <jakub@redhat.com>

            PR objc/103639
            * c-typeck.c (c_finish_bc_stmt): For break inside of switch inside
of
            ObjC foreach, emit normal BREAK_STMT rather than goto to label.

    2022-01-01  Iain Sandoe  <iain@sandoe.co.uk>

            PR objc/103639
            * objc.dg/pr103639.m: New test.


More information about the Gcc-bugs mailing list