https://gcc.gnu.org/g:de7fc69d08a863b526440bb94d7aa2697a5d7627
commit r17-2257-gde7fc69d08a863b526440bb94d7aa2697a5d7627 Author: Philip Herron <[email protected]> Date: Mon Jun 29 19:59:25 2026 +0100 gccrs: turn on can_alias_all on build_pointer_type Rust semantics are that all raw pointers can alias but then we get stronger garentees on reference types. Fixes Rust-GCC#4536 gcc/rust/ChangeLog: * rust-gcc.cc (pointer_type): turn on can alias gcc/testsuite/ChangeLog: * rust/execute/raw-pointer-aliasing.rs: New test. Signed-off-by: Philip Herron <[email protected]> Diff: --- gcc/rust/rust-gcc.cc | 2 +- gcc/testsuite/rust/execute/raw-pointer-aliasing.rs | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index ab02bcd556a0..00f35638144e 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -444,7 +444,7 @@ pointer_type (tree to_type) { if (error_operand_p (to_type)) return error_mark_node; - tree type = build_pointer_type (to_type); + tree type = build_pointer_type_for_mode (to_type, VOIDmode, true); return type; } diff --git a/gcc/testsuite/rust/execute/raw-pointer-aliasing.rs b/gcc/testsuite/rust/execute/raw-pointer-aliasing.rs new file mode 100644 index 000000000000..d19730b043fb --- /dev/null +++ b/gcc/testsuite/rust/execute/raw-pointer-aliasing.rs @@ -0,0 +1,25 @@ +// { dg-options "-O2" } + +#![feature(no_core)] +#![no_core] + +extern "C" { + fn malloc(n: u64) -> *mut u8; +} + +fn f() -> i32 { + unsafe { + let p = malloc(4) as *mut i32; + *p = 27; + *(p as *mut i16) = 42; + *p + } +} + +fn main() -> i32 { + if f() == 27 { + 1 + } else { + 0 + } +}
