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

--- Comment #21 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <a...@gcc.gnu.org>:

https://gcc.gnu.org/g:59dd1d7ab21ad9a7ebf641ec9aeea609c003ad2f

commit r15-2169-g59dd1d7ab21ad9a7ebf641ec9aeea609c003ad2f
Author: Andi Kleen <a...@linux.intel.com>
Date:   Tue Jan 23 23:44:48 2024 -0800

    C++: Support clang compatible [[musttail]] (PR83324)

    This patch implements a clang compatible [[musttail]] attribute for
    returns.

    musttail is useful as an alternative to computed goto for interpreters.
    With computed goto the interpreter function usually ends up very big
    which causes problems with register allocation and other per function
    optimizations not scaling. With musttail the interpreter can be instead
    written as a sequence of smaller functions that call each other. To
    avoid unbounded stack growth this requires forcing a sibling call, which
    this attribute does. It guarantees an error if the call cannot be tail
    called which allows the programmer to fix it instead of risking a stack
    overflow. Unlike computed goto it is also type-safe.

    It turns out that David Malcolm had already implemented middle/backend
    support for a musttail attribute back in 2016, but it wasn't exposed
    to any frontend other than a special plugin.

    This patch adds a [[gnu::musttail]] attribute for C++ that can be added
    to return statements. The return statement must be a direct call
    (it does not follow dependencies), which is similar to what clang
    implements. It then uses the existing must tail infrastructure.

    For compatibility it also detects clang::musttail

    Passes bootstrap and full test

    gcc/c-family/ChangeLog:

            * c-attribs.cc (set_musttail_on_return): New function.
            * c-common.h (set_musttail_on_return): Declare new function.

    gcc/cp/ChangeLog:

            PR c/83324
            * cp-tree.h (AGGR_INIT_EXPR_MUST_TAIL): Add.
            * parser.cc (cp_parser_statement): Handle musttail.
            (cp_parser_jump_statement): Dito.
            * pt.cc (tsubst_expr): Copy CALL_EXPR_MUST_TAIL_CALL.
            * semantics.cc (simplify_aggr_init_expr): Handle musttail.

Reply via email to