-
Notifications
You must be signed in to change notification settings - Fork 13.5k
centralize -Zmin-function-alignment
logic
#142854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -877,12 +877,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way we can have a lint against accessing |
||
|
||
Ord::max(global_align, fn_align).unwrap_or(Align::ONE) | ||
self.tcx.codegen_fn_attrs(instance.def_id()).alignment.unwrap_or(Align::ONE) | ||
} | ||
// Machine-specific extra functions currently do not support alignment restrictions. | ||
FnVal::Other(_) => Align::ONE, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually more important than that, if you consider that
-C
flags can differ between translation units.This ensures functions defined in a crate compiled with
-Cmin-function-alignment
get that alignment independent of the crate they are codegen'd in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a function from crate A is generated in another crate B compiled with
-Zmin-function-alignment=B
, I would expect the alignment to be at least B.