Skip to content

aarch64/arm: use read_unaligned for vld1 lane and dup loads - #2213

Draft
rootkiller6788 wants to merge 1 commit into
rust-lang:mainfrom
rootkiller6788:fix-vld1-lane-unaligned-loads
Draft

aarch64/arm: use read_unaligned for vld1 lane and dup loads#2213
rootkiller6788 wants to merge 1 commit into
rust-lang:mainfrom
rootkiller6788:fix-vld1-lane-unaligned-loads

Conversation

@rootkiller6788

@rootkiller6788 rootkiller6788 commented Aug 20, 2026

Copy link
Copy Markdown

Summary

The vld1 (load single element) and ld1r (load-and-replicate) instructions do not require the source pointer to be aligned. However, the NEON lane-load (vld1*_lane*) and dup-load (vld1*_dup*) intrinsics dereferenced the pointer directly (*ptr), which makes the compiler assume the pointer is aligned to the element's size. For unaligned pointers this is undefined behavior (and trips debug alignment checks).

This replaces the aligned dereference with ptr.read_unaligned() across all affected intrinsics, and updates the generator spec so the generated code remains in sync.

Changes

  • crates/stdarch-gen-arm/spec/neon/arm_shared.spec.yml: emit ptr.read_unaligned() instead of *ptr for the lane-load and dup-load compose expressions.
  • crates/core_arch/src/arm_shared/neon/generated.rs: update the vld1*_lane* and vld1*_dup* intrinsic bodies.
  • crates/core_arch/src/aarch64/neon/mod.rs: fix the hand-written vld1_lane_f64 / vld1q_lane_f64.

Fixes #2198

The vld1 (load single element) and ld1r (load and replicate) instructions
do not require the source pointer to be aligned. However, the lane-load and
dup-load intrinsics dereferenced the pointer directly, which inserts an
alignment requirement and is UB for unaligned pointers.

Replace the aligned dereference with ptr.read_unaligned() for the vld1*_lane*
and vld1*_dup* intrinsics, and update the generator spec so the generated
code stays in sync.

Fixes rust-lang#2198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ld1 inserts an alignment requirement

1 participant