gccrs: Register global_allocator attribute
gccrs now recognizes the `global_allocator` attribute, enabling basic validation of its usage.
The gccrs Rust compiler now registers the #[global_allocator] attribute. This commit enables gccrs to recognize this attribute and perform initial sanity checks, such as ensuring it’s applied only to static items. While this does not implement the full functionality for custom allocators, it’s a necessary step for understanding and validating the attribute’s presence in the code.
In Details
This commit adds support for the #[global_allocator] attribute within the gccrs Rust frontend. It involves updating the attribute checking mechanisms in rust-builtin-attribute-checker.cc and rust-attributes.cc to recognize GLOBAL_ALLOCATOR. The check_valid_attribute_for_item function is updated to enforce that this attribute can only be applied to static items. This is a preliminary step, as full handling of custom allocators is not yet implemented, but it allows for basic syntactic validation.
- gccrs
- The GCC Rust frontend, responsible for parsing, type-checking, and generating code for Rust programs using the GCC compiler infrastructure.
- global_allocator
- A Rust attribute that allows developers to specify a custom global allocator for memory management. This attribute must be applied to a static item that implements the
GlobalAlloctrait. - attribute
- In Rust, attributes are metadata attached to code elements (like functions, structs, or modules) using
#[...]syntax. They provide information to the compiler or other tools, influencing behavior or enabling specific features. - static item
- A variable or constant that has a fixed memory location throughout the program's lifetime. In Rust, global allocators must be defined as static items.