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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <l...@gcc.gnu.org>:

https://gcc.gnu.org/g:14b15a9a473fc69b0251e625c397e70c396f0c0c

commit r16-3236-g14b15a9a473fc69b0251e625c397e70c396f0c0c
Author: Dimitar Dimitrov <dimi...@dinux.eu>
Date:   Sat Aug 16 20:30:14 2025 -0600

    [PATCH] RISC-V: Fix block matching in arch-canonicalize [PR121538]

    Commit r16-3028-g0c517ddf9b136c introduced parsing of conditional blocks
    in riscv-ext*.def.  For simplicity, it used a simple regular expression
    to match the C++ lambda function for each condition.  But the regular
    expression is too simple - it matches only the first scoped code block,
    without any trailing closing braces.

    The "c" dependency for the "zca" extension has two code blocks inside
    its conditional.  One for RV32 and one for RV64.  The script matches
    only the RV32 block, and leaves the RV64 one.  Any strings left, in turn,
    are considered a list of non-conditional extensions.  Thus the quoted
    strings "d" and "zcd" from that block are taken as "simple"
(non-conditional)
    dependencies:

      if (subset_list->xlen () == 64)
        {
          if (subset_list->lookup ("d"))
            return subset_list->lookup ("zcd");

    As a result, arch-canonicalize erroneously adds "d" extension:
      $ ./config/riscv/arch-canonicalize rv32ec
      rv32efdc_zicsr_zca_zcd_zcf

      Before r16-3028-g0c517ddf9b136c the command returned:
      $ ./config/riscv/arch-canonicalize rv32ec
      rv32ec

    Fix by extending the conditional block match until the number of opening
    and closing braces is equal.  This change might seem crude, but it does
    save us from introducing a full C++ parser into the simple
    arch-canonicalize python script.  With this patch the script now
    returns:

      $ ./config/riscv/arch-canonicalize rv32ec
      rv32ec_zca

    Ok for trunk?

            PR target/121538

    gcc/ChangeLog:

            * config/riscv/arch-canonicalize (parse_dep_exts):
            Match condition block up to closing brace.
            (test_parse_long_condition_block): New test.

Reply via email to