Add ptr_offset_from intrinsic for pointer arithmetic in gccrs
GCC's Rust front-end gains a new intrinsic for calculating pointer offsets.
GCC’s Rust front-end (gccrs) has been updated to include a new intrinsic function, ptr_offset_from<T>, which allows for calculating the offset between two pointers. This intrinsic is now registered and handled within the backend and type-checking components of gccrs. A new test case has been added to verify its functionality.
In Details
Commit 3ea530031fc7dd0f55c39060de5cabfebc166100 introduces the ptr_offset_from<T> intrinsic into the gccrs compiler. This intrinsic, implemented in gcc/rust/backend/rust-intrinsic-handlers.cc, calculates the difference between two pointers of type *const T or *mut T, returning the offset in bytes. It's registered in several places, including rust-compile-intrinsic.cc, rust-hir-type-check-intrinsic.cc, and rust-intrinsic-values.h, and is accompanied by a new torture test case. This intrinsic is essential for low-level pointer manipulation and memory management operations with…
- intrinsic
- A special function that is recognized and handled directly by the compiler or hardware, often providing optimized low-level operations that might not be expressible in standard language constructs.
- pointer arithmetic
- Performing arithmetic operations (like addition or subtraction) on memory addresses stored in pointers. The result is a new memory address, typically offset by a multiple of the size of the data type the pointer points to.
- gccrs
- The Rust front-end for GCC, enabling the compilation of Rust code using the GCC toolchain.
- backend
- The part of a compiler that takes the intermediate representation and generates machine code or assembly code for a specific target architecture.
- torture test
- A type of test case in compiler development that exercises complex or unusual language features and compiler optimizations to ensure correctness and uncover bugs.