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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:1d7f57da583782ae5d56655a3ac413bdf259838a

commit r15-8266-g1d7f57da583782ae5d56655a3ac413bdf259838a
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Mar 18 18:48:14 2025 +0100

    c, c++: Support musttail attribute even using __attribute__ form [PR116545]

    Apparently some programs in the wild use
     #if __has_attribute(musttail)
       __attribute__((musttail)) return foo ();
     #else
       return foo ();
     #endif
    clang supports musttail both as a standard attribute ([[clang::musttail]]
    which we also support for compatibility) and the above worked just
    fine with GCC 14 which had __has_attribute(musttail) 0.  Now that it is
    0, this doesn't compile anymore.
    So, either we need to ensure that __has_attribute(musttail) is 0
    and just __has_c{,pp}_attribute({gnu,clang}::musttail) are non-zero,
    or IMHO better we just make it work in the attribute form, especially for
    C < C23 I can see why some projects would prefer that form.
    While [[gnu::musttail]] is rejected as an error in C11 etc. before GCC 15,
    rather than just handled as an unknown attribute.
    I view this as both a regression and compatibility issue.
    The patch handles it in similar spots to fallthrough/assume attributes
    inside of __attribute__ for C, and for C++ enables mixing of standard [[]]
    and GNU __attribute__(()) attributes at the start of statements in any
order.

    While working on it, I've noticed we weren't diagnosing arguments to the
    clang::musttail attribute (fixed by the c-attribs.cc hunk) and newly
    on the __attribute__ form attribute (in that case the arguments aren't just
    skipped, they are always parsed and because we don't call decl_attributes
    etc., it wouldn't be diagnosed without a manual check).

    2025-03-18  Jakub Jelinek  <ja...@redhat.com>

            PR c/116545
    gcc/
            * doc/extend.texi (musttail statement attribute): Document
            that musttail GNU attribute can be used as well.
    gcc/c-family/
            * c-attribs.cc (c_common_clang_attributes): Add musttail.
    gcc/c/
            * c-parser.cc (c_parser_declaration_or_fndef): Parse
            __attribute__((musttail)) return.
            (c_parser_handle_musttail): Diagnose attribute arguments.
            (c_parser_statement_after_labels): Parse
            __attribute__((musttail)) return.
    gcc/cp/
            * parser.cc (cp_parser_statement): Call cp_parser_attributes_opt
            rather than cp_parser_std_attribute_spec_seq.
            (cp_parser_jump_statement): Diagnose gnu::musttail attributes
            with no arguments.
    gcc/testsuite/
            * c-c++-common/attr-fallthrough-2.c: Adjust expected diagnostics
            for C++.
            * c-c++-common/musttail15.c: New test.
            * c-c++-common/musttail16.c: New test.
            * c-c++-common/musttail17.c: New test.
            * c-c++-common/musttail18.c: New test.
            * c-c++-common/musttail19.c: New test.
            * c-c++-common/musttail20.c: New test.
            * c-c++-common/musttail21.c: New test.
            * c-c++-common/musttail22.c: New test.
            * c-c++-common/musttail23.c: New test.
            * c-c++-common/musttail24.c: New test.
            * g++.dg/musttail7.C: New test.
            * g++.dg/musttail8.C: New test.
            * g++.dg/musttail12.C: New test.
            * g++.dg/musttail13.C: New test.
            * g++.dg/musttail14.C: New test.
            * g++.dg/ext/pr116545.C: New test.
  • [Bug c/116545] Support old styl... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to