Skip to content

Commit 11ef961

Browse files
committed
Fixes including fixing compilation for --no-default-features
1 parent 9b1d716 commit 11ef961

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/abi.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use gccjit::{FnAttribute, ToLValue, ToRValue, Type};
1+
#[cfg(feature = "master")]
2+
use gccjit::FnAttribute;
3+
use gccjit::{ToLValue, ToRValue, Type};
24
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods};
35
use rustc_data_structures::fx::FxHashSet;
46
use rustc_middle::bug;
@@ -101,6 +103,7 @@ pub struct FnAbiGcc<'gcc> {
101103
pub arguments_type: Vec<Type<'gcc>>,
102104
pub is_c_variadic: bool,
103105
pub on_stack_param_indices: FxHashSet<usize>,
106+
#[cfg(feature = "master")]
104107
pub fn_attributes: Vec<FnAttribute<'gcc>>,
105108
}
106109

@@ -129,6 +132,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
129132
cx.type_void()
130133
}
131134
};
135+
#[cfg(feature = "master")]
132136
let mut non_null_args = Vec::new();
133137

134138
#[cfg(feature = "master")]
@@ -190,14 +194,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
190194
} else {
191195
vec![FnAttribute::NonNull(non_null_args)]
192196
};
193-
#[cfg(not(feature = "master"))]
194-
let fn_attrs = Vec::new();
195197

196198
FnAbiGcc {
197199
return_type,
198200
arguments_type: argument_tys,
199201
is_c_variadic: self.c_variadic,
200202
on_stack_param_indices,
203+
#[cfg(feature = "master")]
201204
fn_attributes: fn_attrs,
202205
}
203206
}

src/context.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
132132
let create_type = |ctype, rust_type| {
133133
let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
134134
let align = layout.align.abi.bytes();
135-
context.new_c_type(ctype).get_aligned(align)
135+
#[cfg(feature="master")]
136+
{
137+
context.new_c_type(ctype).get_aligned(align)
138+
}
139+
#[cfg(not(feature="master"))]
140+
{
141+
// Since libgccjit 12 doesn't contain the fix to compare aligned integer types,
142+
// only align u128 and i128.
143+
if layout.ty.int_size_and_signed(tcx).0.bytes() == 16 {
144+
context.new_c_type(ctype).get_aligned(align)
145+
}
146+
else {
147+
context.new_c_type(ctype)
148+
}
149+
}
136150
};
137151

138152
let i8_type = create_type(CType::Int8t, tcx.types.i8);
@@ -271,16 +285,15 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
271285
}
272286

273287
pub fn is_native_int_type(&self, typ: Type<'gcc>) -> bool {
274-
// TODO: cache those types to not query libgccjit everytime this is called.
275288
let types = [
276-
self.context.new_c_type(CType::UInt8t),
277-
self.context.new_c_type(CType::UInt16t),
278-
self.context.new_c_type(CType::UInt32t),
279-
self.context.new_c_type(CType::UInt64t),
280-
self.context.new_c_type(CType::Int8t),
281-
self.context.new_c_type(CType::Int16t),
282-
self.context.new_c_type(CType::Int32t),
283-
self.context.new_c_type(CType::Int64t),
289+
self.u8_type,
290+
self.u16_type,
291+
self.u32_type,
292+
self.u64_type,
293+
self.i8_type,
294+
self.i16_type,
295+
self.i32_type,
296+
self.i64_type,
284297
];
285298

286299
for native_type in types {

src/declare.rs

+2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
8585
arguments_type,
8686
is_c_variadic,
8787
on_stack_param_indices,
88+
#[cfg(feature="master")]
8889
fn_attributes,
8990
} = fn_abi.gcc_type(self);
9091
let func = declare_raw_fn(self, name, () /*fn_abi.llvm_cconv()*/, return_type, &arguments_type, is_c_variadic);
9192
self.on_stack_function_params.borrow_mut().insert(func, on_stack_param_indices);
93+
#[cfg(feature="master")]
9294
for fn_attr in fn_attributes {
9395
func.add_attribute(fn_attr);
9496
}

0 commit comments

Comments
 (0)