gccrs: turn on can_alias_all on build_pointer_type
Rust raw pointers in gccrs are now treated as possibly aliasing, aligning with Rust semantics.
The gccrs compiler now correctly reflects Rust’s semantics regarding pointer aliasing. Raw pointers in Rust are defined as potentially aliasing all other memory, while reference types have stronger guarantees. This change ensures that the can_alias_all attribute is enabled when building pointer types in gccrs, aligning compiler behavior with the language specification.
In Details
The pointer_type function in rust-gcc.cc has been updated to enable the can_alias_all attribute. This aligns with Rust's language semantics, where raw pointers (*T) are assumed to alias all other memory, whereas references (&T, &mut T) have stricter aliasing rules. Enabling can_alias_all for pointer types in GCC's internal representation ensures that optimization passes do not make unsafe assumptions about pointer aliasing.
- gccrs
- The Rust front-end for GCC, enabling GCC to compile Rust code.
- can_alias_all
- An optimization qualifier that indicates a pointer may alias any memory location. Enabling this prevents certain optimizations that rely on aliasing assumptions, ensuring correctness for volatile-like accesses.
- raw pointers
- In Rust, pointers (
*const Tand*mut T) that follow C-like semantics. They do not perform automatic null checks or bounds checking and have weaker aliasing guarantees than references. - reference types
- In Rust, references (
&Tand&mut T) provide safe, managed access to data. They have strict aliasing rules, meaning mutable references cannot alias other references to the same data, and immutable references can alias each other. - aliasing
- In programming, aliasing occurs when two or more different variables or expressions refer to the same memory location. This can complicate compiler optimizations.