Skip to content

Commit 5eb4cc5

Browse files
authored
Unrolled build for #144706
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 <#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.
2 parents 383b9c4 + fe72018 commit 5eb4cc5

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
937937
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
938938
if let Some(fn_val) = self.get_fn_alloc(id) {
939939
let align = match fn_val {
940-
FnVal::Instance(instance) => {
941-
self.tcx.codegen_instance_attrs(instance.def).alignment.unwrap_or(Align::ONE)
940+
FnVal::Instance(_instance) => {
941+
// FIXME: Until we have a clear design for the effects of align(N) functions
942+
// on the address of function pointers, we don't consider the align(N)
943+
// attribute on functions in the interpreter.
944+
// See <https://github.com/rust-lang/rust/issues/144661> for more context.
945+
Align::ONE
942946
}
943947
// Machine-specific extra functions currently do not support alignment restrictions.
944948
FnVal::Other(_) => Align::ONE,

src/tools/miri/tests/pass/fn_align.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)