diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-04 11:24:39 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-04 11:24:39 +1000 |
| commit | 0225f8b09c8c41469836cd28ded856ddee14404f (patch) | |
| tree | b3fb1ca2617bae022e33f8a3bae71faf4b57e789 /compiler/rustc_const_eval | |
| parent | f6b4e45be7a72e291044bc0c071f14c5256078b7 (diff) | |
| parent | fe720181b52157f9a7195b3d9b0b28b20dc9583d (diff) | |
| download | rust-0225f8b09c8c41469836cd28ded856ddee14404f.tar.gz rust-0225f8b09c8c41469836cd28ded856ddee14404f.zip | |
Rollup merge of #144706 - zachs18:fix-144661, r=RalfJung
Do not give function allocations alignment in consteval and Miri. We do not yet have a (clear and T-lang approved) design for how `#[align(N)]` on functions should affect function pointers' addresses on various platforms, so for now do not give function pointers alignment in consteval and Miri. ---- Old summary: Not a full solution to <https://github.com/rust-lang/rust/issues/144661>, but fixes the immediate issue by making function allocations all have alignment 1 in consteval, ignoring `#[rustc_align(N)]`, so the compiler doesn't know if any offset other than 0 is non-null. A more "principlied" solution would probably be to make function pointers to `#[instruction_set(arm::t32)]` functions be at offset 1 of an align-`max(2, align attribute)` allocation instead of at offset 0 of their allocation during consteval, and on wasm to either disallow `#[align(N)]` where N > 1, or to pad the function table such that the function pointer of a `#[align(N)]` function is a multiple of `N` at runtime.
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 47bebf5371a..23b40894f16 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -937,8 +937,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // (both global from `alloc_map` and local from `extra_fn_ptr_map`) if let Some(fn_val) = self.get_fn_alloc(id) { let align = match fn_val { - FnVal::Instance(instance) => { - self.tcx.codegen_instance_attrs(instance.def).alignment.unwrap_or(Align::ONE) + FnVal::Instance(_instance) => { + // FIXME: Until we have a clear design for the effects of align(N) functions + // on the address of function pointers, we don't consider the align(N) + // attribute on functions in the interpreter. + // See <https://github.com/rust-lang/rust/issues/144661> for more context. + Align::ONE } // Machine-specific extra functions currently do not support alignment restrictions. FnVal::Other(_) => Align::ONE, |
