Bug 115554 - RISC-V: ICE in case of multiple target-arch attributes
Summary: RISC-V: ICE in case of multiple target-arch attributes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2024-06-20 07:20 UTC by Christoph Müllner
Modified: 2024-07-17 06:33 UTC (History)
0 users

See Also:
Host:
Target: riscv
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Müllner 2024-06-20 07:20:34 UTC
Minimal reproducers (for target-arch):

extern
__attribute__((target("arch=+zba")))
__attribute__((target("arch=+zbb")))
void foo(void);

extern
__attribute__((target("arch=+zbb")))
__attribute__((target("arch=+zbb")))
void bar(void);

The ICE is a bug.
If multiple target-arch attributes should not be allowed,
then an error message is the right solution.

Allowing multiple target-X attributes is problematic, as can be seen for baz().
I.e., does the second attribute amend or replace the previous one?
However, accepting multiple target-X attributes if they are equal (like for bar)
could be done.

The assertion was added in the GCC 14 cycle (commit 9941f0295a1).
GCC 14 and 15 are affected. GCC 13 is not affected (we don't have RISC-V target-arch
attributes in GCC 13).

The ICE looks like this:
$ riscv64-unknown-linux-gnu-gcc bar.c -c
bar.c:4:1: internal compiler error: in riscv_func_target_put, at common/config/riscv/riscv-common.cc:521
    4 | void foo(void);
      | ^~~~
0xc15306 riscv_func_target_put(tree_node*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
        /home/cm/src/gcc/riscv-mainline/gcc/common/config/riscv/riscv-common.cc:521
0x18234d3 riscv_process_target_attr
        /home/cm/src/gcc/riscv-mainline/gcc/config/riscv/riscv-target-attr.cc:370
0x182334c riscv_process_target_attr
        /home/cm/src/gcc/riscv-mainline/gcc/config/riscv/riscv-target-attr.cc:314
0x182363d riscv_option_valid_attribute_p(tree_node*, tree_node*, tree_node*, int)
        /home/cm/src/gcc/riscv-mainline/gcc/config/riscv/riscv-target-attr.cc:389
0xd560ee handle_target_attribute
        /home/cm/src/gcc/riscv-mainline/gcc/c-family/c-attribs.cc:5915
0xc24d04 decl_attributes(tree_node**, tree_node*, int, tree_node*)
        /home/cm/src/gcc/riscv-mainline/gcc/attribs.cc:900
0xc2bbed c_decl_attributes
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-decl.cc:5501
0xc43b77 start_decl(c_declarator*, c_declspecs*, bool, tree_node*, bool, unsigned int*)
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-decl.cc:5647
0xcb4d73 c_parser_declaration_or_fndef
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-parser.cc:2773
0xcc158b c_parser_external_declaration
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-parser.cc:2053
0xcc1fb5 c_parser_translation_unit
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-parser.cc:1907
0xcc1fb5 c_parse_file()
        /home/cm/src/gcc/riscv-mainline/gcc/c/c-parser.cc:27303
0xd3b9c1 c_common_parse_file()
        /home/cm/src/gcc/riscv-mainline/gcc/c-family/c-opts.cc:1322
Comment 1 Christoph Müllner 2024-06-20 07:24:27 UTC
Forgot to mention:
The ICE is triggered by an assertion in riscv_func_target_put(), which ensures
we don't have more than one target-arch attribute in one function declaration.
Comment 2 Richard Biener 2024-06-20 07:33:25 UTC
target and optimize attributes "accumulate"