11use std:: ops:: Range ;
22
3- use rustc_abi:: {
4- Align , AlignFromBytesError , HasDataLayout , Primitive , Scalar , Size , WrappingRange ,
5- } ;
3+ use rustc_abi:: { Align , HasDataLayout , Primitive , Scalar , Size , WrappingRange } ;
64use rustc_codegen_ssa:: common;
75use rustc_codegen_ssa:: traits:: * ;
86use rustc_hir:: LangItem ;
@@ -20,9 +18,7 @@ use rustc_middle::{bug, span_bug};
2018use tracing:: { debug, instrument, trace} ;
2119
2220use crate :: common:: { AsCCharPtr , CodegenCx } ;
23- use crate :: errors:: {
24- InvalidMinimumAlignmentNotPowerOfTwo , InvalidMinimumAlignmentTooLarge , SymbolAlreadyDefined ,
25- } ;
21+ use crate :: errors:: SymbolAlreadyDefined ;
2622use crate :: llvm:: { self , True } ;
2723use crate :: type_:: Type ;
2824use crate :: type_of:: LayoutLlvmExt ;
@@ -149,22 +145,10 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
149145 // The target may require greater alignment for globals than the type does.
150146 // Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
151147 // which can force it to be smaller. Rust doesn't support this yet.
152- if let Some ( min) = cx. sess ( ) . target . min_global_align {
153- match Align :: from_bits ( min) {
154- Ok ( min) => align = align. max ( min) ,
155- Err ( err) => match err {
156- AlignFromBytesError :: NotPowerOfTwo ( align) => {
157- cx. sess ( ) . dcx ( ) . emit_err ( InvalidMinimumAlignmentNotPowerOfTwo { align } ) ;
158- }
159- AlignFromBytesError :: TooLarge ( align) => {
160- cx. sess ( ) . dcx ( ) . emit_err ( InvalidMinimumAlignmentTooLarge { align } ) ;
161- }
162- } ,
163- }
164- }
165- unsafe {
166- llvm:: LLVMSetAlignment ( gv, align. bytes ( ) as u32 ) ;
148+ if let Some ( min_global) = cx. sess ( ) . target . min_global_align {
149+ align = Ord :: max ( align, min_global) ;
167150 }
151+ llvm:: set_alignment ( gv, align) ;
168152}
169153
170154fn check_and_apply_linkage < ' ll , ' tcx > (
0 commit comments