diff options
| author | antoyo <antoyo@users.noreply.github.com> | 2023-10-17 21:30:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-17 21:30:47 -0400 |
| commit | d64662ff3eab8b5941c88b1cfca5efda8a194f3e (patch) | |
| tree | 7aeeef8581371b5c699036d2f9855ebf7bb8a6ab /src | |
| parent | fabdc1a27313db1a17577dce440d6b3375deffc2 (diff) | |
| parent | 9d5e0ba1f51f61ba8ccaa6c37eef25ac497ea70c (diff) | |
| download | rust-d64662ff3eab8b5941c88b1cfca5efda8a194f3e.tar.gz rust-d64662ff3eab8b5941c88b1cfca5efda8a194f3e.zip | |
Merge pull request #353 from rust-lang/fix/int-types-alignment
Fix/int types alignment
Diffstat (limited to 'src')
| -rw-r--r-- | src/abi.rs | 9 | ||||
| -rw-r--r-- | src/common.rs | 16 | ||||
| -rw-r--r-- | src/context.rs | 40 | ||||
| -rw-r--r-- | src/declare.rs | 2 |
4 files changed, 46 insertions, 21 deletions
diff --git a/src/abi.rs b/src/abi.rs index 5600f1ba8a9..f601cd95f2a 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -1,4 +1,6 @@ -use gccjit::{FnAttribute, ToLValue, ToRValue, Type}; +#[cfg(feature = "master")] +use gccjit::FnAttribute; +use gccjit::{ToLValue, ToRValue, Type}; use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods}; use rustc_data_structures::fx::FxHashSet; use rustc_middle::bug; @@ -101,6 +103,7 @@ pub struct FnAbiGcc<'gcc> { pub arguments_type: Vec<Type<'gcc>>, pub is_c_variadic: bool, pub on_stack_param_indices: FxHashSet<usize>, + #[cfg(feature = "master")] pub fn_attributes: Vec<FnAttribute<'gcc>>, } @@ -129,6 +132,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { cx.type_void() } }; + #[cfg(feature = "master")] let mut non_null_args = Vec::new(); #[cfg(feature = "master")] @@ -190,14 +194,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { } else { vec![FnAttribute::NonNull(non_null_args)] }; - #[cfg(not(feature = "master"))] - let fn_attrs = Vec::new(); FnAbiGcc { return_type, arguments_type: argument_tys, is_c_variadic: self.c_variadic, on_stack_param_indices, + #[cfg(feature = "master")] fn_attributes: fn_attrs, } } diff --git a/src/common.rs b/src/common.rs index 5f54cb16d8e..93fe27e547a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -424,35 +424,35 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> { } fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.i8_type + self.is_compatible_with(cx.i8_type) } fn is_u8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.u8_type + self.is_compatible_with(cx.u8_type) } fn is_i16(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.i16_type + self.is_compatible_with(cx.i16_type) } fn is_u16(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.u16_type + self.is_compatible_with(cx.u16_type) } fn is_i32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.i32_type + self.is_compatible_with(cx.i32_type) } fn is_u32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.u32_type + self.is_compatible_with(cx.u32_type) } fn is_i64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.i64_type + self.is_compatible_with(cx.i64_type) } fn is_u64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.u64_type + self.is_compatible_with(cx.u64_type) } fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { diff --git a/src/context.rs b/src/context.rs index dcebd92a61c..243556a0e52 100644 --- a/src/context.rs +++ b/src/context.rs @@ -129,19 +129,39 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>, tcx: TyCtxt<'tcx>, supports_128bit_integers: bool) -> Self { let check_overflow = tcx.sess.overflow_checks(); - let i8_type = context.new_c_type(CType::Int8t); - let i16_type = context.new_c_type(CType::Int16t); - let i32_type = context.new_c_type(CType::Int32t); - let i64_type = context.new_c_type(CType::Int64t); - let u8_type = context.new_c_type(CType::UInt8t); - let u16_type = context.new_c_type(CType::UInt16t); - let u32_type = context.new_c_type(CType::UInt32t); - let u64_type = context.new_c_type(CType::UInt64t); + let create_type = |ctype, rust_type| { + let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap(); + let align = layout.align.abi.bytes(); + #[cfg(feature="master")] + { + context.new_c_type(ctype).get_aligned(align) + } + #[cfg(not(feature="master"))] + { + // Since libgccjit 12 doesn't contain the fix to compare aligned integer types, + // only align u128 and i128. + if layout.ty.int_size_and_signed(tcx).0.bytes() == 16 { + context.new_c_type(ctype).get_aligned(align) + } + else { + context.new_c_type(ctype) + } + } + }; + + let i8_type = create_type(CType::Int8t, tcx.types.i8); + let i16_type = create_type(CType::Int16t, tcx.types.i16); + let i32_type = create_type(CType::Int32t, tcx.types.i32); + let i64_type = create_type(CType::Int64t, tcx.types.i64); + let u8_type = create_type(CType::UInt8t, tcx.types.u8); + let u16_type = create_type(CType::UInt16t, tcx.types.u16); + let u32_type = create_type(CType::UInt32t, tcx.types.u32); + let u64_type = create_type(CType::UInt64t, tcx.types.u64); let (i128_type, u128_type) = if supports_128bit_integers { - let i128_type = context.new_c_type(CType::Int128t).get_aligned(8); // TODO(antoyo): should the alignment be hard-coded?; - let u128_type = context.new_c_type(CType::UInt128t).get_aligned(8); // TODO(antoyo): should the alignment be hard-coded?; + let i128_type = create_type(CType::Int128t, tcx.types.i128); + let u128_type = create_type(CType::UInt128t, tcx.types.u128); (i128_type, u128_type) } else { diff --git a/src/declare.rs b/src/declare.rs index 0b583c074dd..247454fa58e 100644 --- a/src/declare.rs +++ b/src/declare.rs @@ -85,10 +85,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { arguments_type, is_c_variadic, on_stack_param_indices, + #[cfg(feature="master")] fn_attributes, } = fn_abi.gcc_type(self); let func = declare_raw_fn(self, name, () /*fn_abi.llvm_cconv()*/, return_type, &arguments_type, is_c_variadic); self.on_stack_function_params.borrow_mut().insert(func, on_stack_param_indices); + #[cfg(feature="master")] for fn_attr in fn_attributes { func.add_attribute(fn_attr); } |
