-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Set proper alignment on constants #28920
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -254,11 +254,11 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, | |||
Some(&val) => return val, | |||
None => {} | |||
} | |||
let ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, | |||
&ccx.tcx().expr_ty(expr)); |
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.
Alignment mishap?
r=me with the formatting nit fixed. |
@bors r=eddyb 00a79c0 |
@@ -275,6 +275,10 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, | |||
}; | |||
|
|||
let lvalue = addr_of(ccx, val, "const"); | |||
unsafe { | |||
llvm::LLVMSetAlignment(lvalue, type_of::align_of(ccx, ty)); |
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.
I think this belongs inside addr_of_mut, rather than here.
@bors r- @eefriedman Good point. |
Update as per the suggestion of @eefriedman. I also had to fix the string that identifies the gdb script section, which is used as a C string but had no terminating 0 byte. The alignment changes caused that bug to trigger an error in a codegen test. |
r? @eddyb |
@@ -54,7 +54,8 @@ pub fn insert_reference_to_gdb_debug_scripts_section_global(ccx: &CrateContext) | |||
/// section. | |||
pub fn get_or_insert_gdb_debug_scripts_section_global(ccx: &CrateContext) | |||
-> llvm::ValueRef { | |||
let section_var_name = "__rustc_debug_gdb_scripts_section__"; | |||
let c_section_var_name = "__rustc_debug_gdb_scripts_section__\0"; | |||
let section_var_name = &c_section_var_name[..c_section_var_name.len()-1]; |
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.
For clarity, you might want to use c_section_var_name.as_ptr() as *const _
below.
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.
For correctness even. Not sure where I lost that change (and even more confusing that it passed the test without it). Thanks!
For enum variants, the default alignment for a specific variant might be lower than the alignment of the enum type itself. In such cases we, for example, generate memcpy calls with an alignment that's higher than the alignment of the constant we copy from. To avoid that, we need to explicitly set the required alignment on constants. Fixes rust-lang#28912.
Updated to handle upgrading the alignment of constants that are shared between types with different alignment requirements. Thanks a lot @eefriedman! |
@bors r+ |
📌 Commit 6ad079e has been approved by |
For enum variants, the default alignment for a specific variant might be lower than the alignment of the enum type itself. In such cases we, for example, generate memcpy calls with an alignment that's higher than the alignment of the constant we copy from. To avoid that, we need to explicitly set the required alignment on constants. Fixes #28912.
For enum variants, the default alignment for a specific variant might be
lower than the alignment of the enum type itself. In such cases we, for
example, generate memcpy calls with an alignment that's higher than the
alignment of the constant we copy from.
To avoid that, we need to explicitly set the required alignment on
constants.
Fixes #28912.