GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

C++: Ensure target sees attributes waiting for instantiation

Fixes RISC-V ABI tag for dependent template types.

This commit corrects how C++ attributes are handled for dependent template types, specifically fixing an issue on RISC-V where ABI tags were dropped. Previously, late attributes were spliced out before the target could see them, causing incorrect mangling for templates like template <typename T> __attribute__((riscv_vls_cc(128))) void a (T) {}. The fix ensures the target hook insert_attributes is called before attributes are spliced, allowing ABI tags to be correctly incorporated.

In Details

This change modifies decl2.cc in GCC's C++ frontend to call targetm.insert_attributes before the cplus_decl_attributes function splices out late attributes. This ensures that attributes attached to a declaration, especially those that depend on template instantiation, are visible to the target backend. For instance, on RISC-V, this preserves the riscv_vls_cc ABI tag when a function template's type is dependent, correcting mangling from _Z1aIiEvT_ to _Z1aB16riscv_vls_cc_128IiEvT_. The declaration in decl.h and the test case in g++.target/riscv/mangle-vls-cc.C are updated accord…

For Context
attributes
Keywords or directives (like __attribute__((...))) used to provide extra information to the compiler about functions, variables, or types, influencing optimization, code generation, or behavior.
instantiation
The process of creating a specific version of a template (e.g., a class or function) for a particular type or set of types. For example, instantiating std::vector<int> creates a vector specifically for integers.
ABI
Application Binary Interface. Defines how low-level code is structured, including function calling conventions, data layout, and name mangling. Incorrect ABI compliance can lead to runtime errors.
name mangling
The process of altering the names of functions and variables during compilation to include additional information, such as their namespace, class, and parameter types. This is crucial for C++'s function overloading and name resolution.
RISC-V
An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles. It is designed to be simple, modular, and extensible.
Filed Under: c++abirisc-vtemplates