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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:0970bb8565616f61c6b7a7dd0edbc829b0064703

commit r16-7920-g0970bb8565616f61c6b7a7dd0edbc829b0064703
Author: Jakub Jelinek <[email protected]>
Date:   Thu Mar 5 21:43:55 2026 +0100

    c++: Avoid caching TARGET_EXPR slot value if exception is thrown from
TARGET_EXPR_INITIAL [PR124145]

    The following testcase is miscompiled, we throw exception only during
    the first bar () call and not during the second and in that case reach
    the inline asm.
    The problem is that the TARGET_EXPR handling calls
                ctx->global->put_value (new_ctx.object, new_ctx.ctor);
    first for aggregate/vectors, then
            if (is_complex)
              /* In case no initialization actually happens, clear out any
                 void_node from a previous evaluation.  */
              ctx->global->put_value (slot, NULL_TREE);
    and then recurses on TARGET_EXPR_INITIAL.
    Even for is_complex it can actually store partially the result in the
    slot before throwing.

    When TARGET_EXPR_INITIAL doesn't throw, we do
      if (ctx->save_expr)
        ctx->save_expr->safe_push (slot);
    and that arranges for the value in slot be invalidated at the end of
    surrounding CLEANUP_POINT_EXPR.
    But in case when it does throw this isn't done.

    The following patch fixes it by moving that push to save_expr
    before the if (*jump_target) return NULL_TREE; check.

    2026-03-05  Jakub Jelinek  <[email protected]>

            PR c++/124145
            * constexpr.cc (cxx_eval_constant_expression) <case TARGET_EXPR>:
Move
            ctx->save_expr->safe_push (slot) call before if (*jump_target)
test.
            Use TARGET_EXPR_INITIAL instead of TREE_OPERAND.

            * g++.dg/cpp26/constexpr-eh18.C: New test.

Reply via email to