https://gcc.gnu.org/g:d0d6b4b045bc9663b6d2ddb78a9154cce8dc19d2
commit r17-5817-gd0d6b4b045bc9663b6d2ddb78a9154cce8dc19d2 Author: Kito Cheng <[email protected]> Date: Wed Sep 2 20:51:39 2026 +0800 c++: let the target see the attributes that wait for instantiation cplus_decl_attributes splices the late attributes out before calling decl_attributes, so targetm.insert_attributes never sees them on the template. On RISC-V this drops the psABI ABI tag when the function type is dependent: ```c++ template <typename T> __attribute__((riscv_vls_cc(128))) void a (T) {} ``` a<int> mangles as _Z1aIiEvT_ instead of _Z1aB16riscv_vls_cc_128IiEvT_. Call the hook before the splice instead. A template declaration now goes through the hook twice. gcc/cp/ChangeLog: * decl2.cc (cplus_decl_attributes): Call targetm.insert_attributes before the late attributes are spliced out of the list. gcc/testsuite/ChangeLog: * g++.target/riscv/mangle-vls-cc.C: Expect the tag on a template whose type is dependent. Diff: --- gcc/cp/decl2.cc | 6 ++++++ gcc/testsuite/g++.target/riscv/mangle-vls-cc.C | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 563fae5db0d4..b1723b3d3050 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2145,6 +2145,12 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) { if (check_for_bare_parameter_packs (attributes)) return; + + /* Ask the target now rather than leaving it to decl_attributes below: + a target that adds an attribute of its own in reaction to one of + these would never see the ones we are about to splice out. */ + targetm.insert_attributes (STRIP_TEMPLATE (*decl), &attributes); + late_attrs = splice_template_attributes (&attributes, *decl); } diff --git a/gcc/testsuite/g++.target/riscv/mangle-vls-cc.C b/gcc/testsuite/g++.target/riscv/mangle-vls-cc.C index 849debce4f95..3ca6138344af 100644 --- a/gcc/testsuite/g++.target/riscv/mangle-vls-cc.C +++ b/gcc/testsuite/g++.target/riscv/mangle-vls-cc.C @@ -56,7 +56,7 @@ void plain () {} /* { dg-final { scan-assembler "_Z6taggedB16riscv_vls_cc_128B4userv:" } } */ /* { dg-final { scan-assembler "_Z7tagged2B3abcB16riscv_vls_cc_128B4userv:" } } */ /* { dg-final { scan-assembler "_ZN2ns1S6memberB16riscv_vls_cc_128Ev:" } } */ -/* { dg-final { scan-assembler "_Z3tplIiEvT_:" } } */ +/* { dg-final { scan-assembler "_Z3tplB16riscv_vls_cc_128IiEvT_:" } } */ /* { dg-final { scan-assembler "_Z9tpl_nodepB16riscv_vls_cc_128IiEvv:" } } */ /* { dg-final { scan-assembler "_Z9vector_ccv:" } } */ /* { dg-final { scan-assembler "_Z5plainv:" } } */
