Fixes including fixing compilation for --no-default-features

This commit is contained in:
Antoni Boucher 2023-10-17 19:43:20 -04:00
parent e5fa9f8692
commit 9d5e0ba1f5
3 changed files with 31 additions and 13 deletions

View File

@ -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,
}
}

View File

@ -132,7 +132,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let create_type = |ctype, rust_type| {
let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
let align = layout.align.abi.bytes();
context.new_c_type(ctype).get_aligned(align)
#[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);
@ -271,16 +285,15 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
pub fn is_native_int_type(&self, typ: Type<'gcc>) -> bool {
// TODO: cache those types to not query libgccjit everytime this is called.
let types = [
self.context.new_c_type(CType::UInt8t),
self.context.new_c_type(CType::UInt16t),
self.context.new_c_type(CType::UInt32t),
self.context.new_c_type(CType::UInt64t),
self.context.new_c_type(CType::Int8t),
self.context.new_c_type(CType::Int16t),
self.context.new_c_type(CType::Int32t),
self.context.new_c_type(CType::Int64t),
self.u8_type,
self.u16_type,
self.u32_type,
self.u64_type,
self.i8_type,
self.i16_type,
self.i32_type,
self.i64_type,
];
for native_type in types {

View File

@ -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);
}