about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-01-15 04:08:12 -0500
committerGitHub <noreply@github.com>2025-01-15 04:08:12 -0500
commit56eb7bd9a98498d06dce35734c439704c0fdca03 (patch)
treea35b23906675e3209317d661102a8047ff20010e /compiler/rustc_codegen_gcc
parentbf4aeeb45c7d3dee7930a78d759445b8b8615caa (diff)
parent58d6301cad7ac20407e708cd9d1ec499d1804015 (diff)
downloadrust-56eb7bd9a98498d06dce35734c439704c0fdca03.tar.gz
rust-56eb7bd9a98498d06dce35734c439704c0fdca03.zip
Rollup merge of #134678 - zachs18:offset-ptr-update, r=tgross35
Update `ReadDir::next` in `std::sys::pal::unix::fs` to use `&raw const (*p).field` instead of `p.byte_offset().cast()`

Since https://github.com/rust-lang/reference/pull/1387 and https://github.com/rust-lang/rust/pull/117572, `&raw mut (*p).field`/`addr_of!((*p).field)` is defined to have the same inbounds preconditions as `ptr::offset`/`ptr::byte_offset`. I.e. `&raw const (*p).field` does not require that `p: *const T` point to a full `size_of::<T>()` bytes of memory, only that `p.byte_add(offset_of!(T, field))` is defined.

The old comment "[...] we don't even get to use `&raw const (*entry_ptr).d_name` because that operation requires the full extent of *entry_ptr to be in bounds of the same allocation, which is not necessarily the case here [...]" is now outdated, and the code can be simplified to use `&raw const (*entry_ptr).field`.

-------

There should be no behavior differences from this PR.

The `: *const dirent64` on line 716 and the `const _: usize = mem::offset_of!(dirent64, $field);` and comment on lines 749-751 are just sanity checks and should not affect semantics.

Since the `offset_ptr!` macro is only called three times, and all with the same local variable entry_ptr, I just used the local variable directly in the macro instead of taking it as an input, and renamed the macro to `entry_field_ptr!`.

The whole macro could also be removed and replaced with just using `&raw const (*entry_ptr).field`  in the three places, but the comments on the macro seemed worthwhile to keep.
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions