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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Pan Li <pa...@gcc.gnu.org>:

https://gcc.gnu.org/g:9941f0295a14659e25260458efd2e46a68ad0342

commit r14-9605-g9941f0295a14659e25260458efd2e46a68ad0342
Author: Pan Li <pan2...@intel.com>
Date:   Tue Mar 19 09:43:24 2024 +0800

    RISC-V: Bugfix function target attribute pollution

    This patch depends on below ICE fix.

    https://gcc.gnu.org/pipermail/gcc-patches/2024-March/647915.html

    The function target attribute should be on a per-function basis.
    For example, we have 3 function as below:

    void test_1 () {}

    void __attribute__((target("arch=+v"))) test_2 () {}

    void __attribute__((target("arch=+zfh"))) test_3 () {}

    void test_4 () {}

    The scope of the target attribute should not extend the function body.
    Aka, test_3 cannot have the 'v' extension, as well as the test_4
    cannot have both the 'v' and 'zfh' extension.

    Unfortunately, for now the test_4 is able to leverage the 'v' and
    the 'zfh' extension which is incorrect.  This patch would like to
    fix the sticking attribute by introduce the commandline subset_list.
    When parse_arch, we always clone from the cmdline_subset_list instead
    of the current_subset_list.

    Meanwhile, we correct the print information about arch like below.

    .option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zbb1p0

    The riscv_declare_function_name hook is always after the hook
    riscv_process_target_attr.  Thus, we introduce one hash_map to record
    the 1:1 mapping from fndel to its' subset_list in advance.  And later
    the riscv_declare_function_name is able to get the right information
    about the arch.

    Below test are passed for this patch
    * The riscv fully regression test.

            PR target/114352

    gcc/ChangeLog:

            * common/config/riscv/riscv-common.cc (struct
riscv_func_target_info):
            New struct for func decl and target name.
            (struct riscv_func_target_hasher): New hasher for hash table
mapping
            from the fn_decl to fn_target_name.
            (riscv_func_decl_hash): New func to compute the hash for fn_decl.
            (riscv_func_target_hasher::hash): New func to impl hash interface.
            (riscv_func_target_hasher::equal): New func to impl equal
interface.
            (riscv_cmdline_subset_list): New static var for cmdline subset
list.
            (riscv_func_target_table_lazy_init): New func to lazy init the func
            target hash table.
            (riscv_func_target_get): New func to get target name from hash
table.
            (riscv_func_target_put): New func to put target name into hash
table.
            (riscv_func_target_remove_and_destory): New func to remove target
            info from the hash table and destory it.
            (riscv_parse_arch_string): Set the static var cmdline_subset_list.
            * config/riscv/riscv-subset.h (riscv_cmdline_subset_list): New
static
            var for cmdline subset list.
            (riscv_func_target_get): New func decl.
            (riscv_func_target_put): Ditto.
            (riscv_func_target_remove_and_destory): Ditto.
            * config/riscv/riscv-target-attr.cc
(riscv_target_attr_parser::parse_arch):
            Take cmdline_subset_list instead of current_subset_list when clone.
            (riscv_process_target_attr): Record the func target info to hash
table.
            (riscv_option_valid_attribute_p): Add new arg tree fndel.
            * config/riscv/riscv.cc (riscv_declare_function_name): Consume the
            func target info and print the arch message.

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/rvv/base/pr114352-3.c: New test.

    Signed-off-by: Pan Li <pan2...@intel.com>

Reply via email to