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

--- Comment #10 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:a6db5908a55adbef0a0dc1eb2a22743064fe17b8

commit r15-4554-ga6db5908a55adbef0a0dc1eb2a22743064fe17b8
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Oct 22 22:36:03 2024 +0200

    c: Better fix for speed up compilation of large char array initializers
when not using #embed [PR117190]

    On Wed, Oct 16, 2024 at 11:09:32PM +0200, Jakub Jelinek wrote:
    > Apparently my
    > c: Speed up compilation of large char array initializers when not using
#embed
    > patch broke building glibc.
    >
    > The issue is that when using CPP_EMBED, we are guaranteed by the
    > preprocessor that there is CPP_NUMBER CPP_COMMA before it and
    > CPP_COMMA CPP_NUMBER after it (or CPP_COMMA CPP_EMBED), so RAW_DATA_CST
    > never ends up at the end of arrays of unknown length.
    > Now, the c_parser_initval optimization attempted to preserve that
property
    > rather than changing everything that e.g. inferes array number of
elements
    > from the initializer etc. to deal with RAW_DATA_CST at the end, but
    > it didn't take into account the possibility that there could be
    > CPP_COMMA followed by CPP_CLOSE_BRACE (where the CPP_COMMA is redundant).
    >
    > As we are peaking already at 4 tokens in that code, peeking more would
    > require using raw tokens and that seems to be expensive doing it for
    > every pair of tokens due to vec_free done when we are out of raw tokens.

    Sorry for rushing the previous patch too much, turns out I was wrong,
    given that the c_parser_peek_nth_token numbering is 1 based, we can peek
    also with c_parser_peek_nth_token (parser, 4) and the loop actually peeked
    just at 3 tokens, not 4.

    So, I think it is better to revert the previous patch (but keep the new
    test) and instead peek the 4th non-raw token, which is what the following
    patch does.

    Additionally, PR117190 shows one further spot which missed the peek of
    the token after CPP_COMMA, in case it is incomplete array with exactly 65
    elements with redundant comma after it, which this patch handles too.

    2024-10-22  Jakub Jelinek  <ja...@redhat.com>

            PR c/117190
    gcc/c/
            * c-parser.cc (c_parser_initval): Revert 2024-10-17 changes.
            Instead peek the 4th token and if it is not CPP_NUMBER,
            handle it like 3rd token CPP_CLOSE_BRACE for orig_len == INT_MAX.
            Also, check (2 + 2 * i)th raw token for the orig_len == INT_MAX
            case and punt if it is not CPP_NUMBER.
    gcc/testsuite/
            * c-c++-common/init-5.c: New test.

Reply via email to