Hi Jason:

Jason Merrill <[email protected]> 於 2026年8月28日週五 上午2:55寫道:
>
> On 8/27/26 4:10 AM, Kito Cheng wrote:
> > The RISC-V psABI[1] says a function using a standard calling convention 
> > variant has
> > to append an extra ABI tag to its mangled name, following the "ABI tags"
> > rule of the Itanium C++ ABI.  The only variant listed so far is the
> > fixed-length vector calling convention, whose tag is
> > riscv_vls_cc_<ABI_VLEN>:
> >
> > ```c
> > __attribute__((riscv_vls_cc(128))) void foo();
> > ```
> >
> > now mangles as _Z3fooB16riscv_vls_cc_128v.
> >
> > The C++ mangler cannot know about target attributes, so we adds a target
> > hook, TARGET_CXX_IMPLICIT_ABI_TAGS, that hands back extra tags for a decl.
> >
> > NOTE: I tried to not adding the new hook by attaching abi_tag attribute,
> > however I tried to doing that on TARGET_INSERT_ATTRIBUTES and
> > doing some hack way on TARGET_ATTRIBUTE_TABLE during adding calling
> > convention attribute, but both are no work well.
>
> How did that fail?  Using TARGET_INSERT_ATTRIBUTES sounds promising to me.

It fails for templates. One key issue is template handling.
The ABI tag needs to be added if the `vls_cc` attribute is present.
However, the attribute might dropped by
`splice_template_attributes` / `is_late_template_attribute`, and
`TARGET_INSERT_ATTRIBUTES` is invoked only after that point. Therefore,
`TARGET_INSERT_ATTRIBUTES` cannot add the ABI tag correctly.

The relevant call flow is roughly:

cplus_decl_attributes
|
|- processing_template_decl? -> splice_template_attributes
|                               # VLS CC attribute may dropped here
|
|- decl_attributes
|  |- targetm.insert_attributes
|     # The VLS CC attribute is no longer visible here
|
|- save_template_attributes
   # The VLS CC attribute is restored here


I am not very familiar with the C++ front end, especially its template handling,
so I may be missing a better way to handle this.

Thanks :)

> Jason
>

Reply via email to