Skip to content

Commit 64d1933

Browse files
authored
Rollup merge of #140072 - folkertdev:miri-fn-align, r=RalfJung
handle function alignment in miri tracking issue: rust-lang/rust#82232 Fixes #4282 The `#[repr(align(N))]` attribute on functions was ignored when using miri. For such a function, its address should be a multiple of `N`. There is some further discussion in the thread [#t-compiler/const-eval > function address alignment](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/function.20address.20alignment) on how `dyn Fn` should be handled. The behavior there appears to be consistent between miri and nightly, though both may be incorrect. In any case, that can be resolved separately.
2 parents f9c64a3 + fe10d9e commit 64d1933

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/pass/fn_align.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@compile-flags: -Zmin-function-alignment=8
2+
#![feature(fn_align)]
3+
4+
// When a function uses `repr(align(N))`, the function address should be a multiple of `N`.
5+
6+
#[repr(align(256))]
7+
fn foo() {}
8+
9+
#[repr(align(16))]
10+
fn bar() {}
11+
12+
#[repr(align(4))]
13+
fn baz() {}
14+
15+
fn main() {
16+
assert!((foo as usize).is_multiple_of(256));
17+
assert!((bar as usize).is_multiple_of(16));
18+
19+
// The maximum of `repr(align(N))` and `-Zmin-function-alignment=N` is used.
20+
assert!((baz as usize).is_multiple_of(8));
21+
}

0 commit comments

Comments
 (0)