diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-04-20 12:52:50 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-04-20 13:08:53 +0200 |
| commit | 2d21c140154c5387712938dbc2ca427e2df4dfc2 (patch) | |
| tree | 38368811ee7d2788d5183a747a1924f9586a3f2f /compiler/rustc_const_eval/src/interpret | |
| parent | 49e5e4e3a5610c240a717cb99003a5d5d3356679 (diff) | |
| download | rust-2d21c140154c5387712938dbc2ca427e2df4dfc2.tar.gz rust-2d21c140154c5387712938dbc2ca427e2df4dfc2.zip | |
respect `repr(align(N))` on functions in miri
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index d077900587e..3bde7457ad6 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -872,8 +872,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // # Function pointers // (both global from `alloc_map` and local from `extra_fn_ptr_map`) - if self.get_fn_alloc(id).is_some() { - return AllocInfo::new(Size::ZERO, Align::ONE, AllocKind::Function, Mutability::Not); + if let Some(fn_val) = self.get_fn_alloc(id) { + let align = match fn_val { + FnVal::Instance(instance) => { + // Function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag; + // the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment. + let fn_align = self.tcx.codegen_fn_attrs(instance.def_id()).alignment; + let global_align = self.tcx.sess.opts.unstable_opts.min_function_alignment; + + Ord::max(global_align, fn_align).unwrap_or(Align::ONE) + } + FnVal::Other(_) => Align::ONE, + }; + + return AllocInfo::new(Size::ZERO, align, AllocKind::Function, Mutability::Not); } // # Global allocations |
