This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77467] Segmentation fault with switch statement in constexpr function


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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Wed Dec  7 22:37:59 2016
New Revision: 243390

URL: https://gcc.gnu.org/viewcvs?rev=243390&root=gcc&view=rev
Log:
        Backported from mainline
        2016-09-28  Jakub Jelinek  <jakub@redhat.com>

        PR c++/77467
        * constexpr.c (enum constexpr_switch_state): New.
        (struct constexpr_ctx): Add css_state field.
        (label_matches): Add CTX and STMT arguments, remove I and
        DEFAULT_LABEL.  For CASE_LABEL_EXPR assert ctx->css_state != NULL,
        handle default labels according to css_state.
        (cxx_eval_statement_list): Remove statement skipping, label_matches
        and default_label handling code.
        (cxx_eval_loop_expr): Exit after first iteration even if
        switches (jump_target).
        (cxx_eval_switch_expr): Set up css_state field in ctx, if default
        label has been seen in the body, but no cases matched, evaluate
        the body second time.
        (cxx_eval_constant_expression): Handle stmt skipping and label_matches
        here.  Handle PREDICT_EXPR.  For MODIFY_EXPR or INIT_EXPR, assert
        statement is not skipped.  For COND_EXPR during skipping, don't
        evaluate condition, just the then block and if still skipping at the
        end also the else block.
        (cxx_eval_outermost_constant_expr): Adjust constexpr_ctx initializer.
        (is_sub_constant_expr): Likewise.

        * g++.dg/cpp1y/constexpr-77467.C: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp1y/constexpr-77467.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/constexpr.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]