Skip to content

Commit 809af1f

Browse files
committed
Fix clippy warnings
1 parent e4b7464 commit 809af1f

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
14951495

14961496
#[cfg(not(feature = "master"))]
14971497
fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {
1498+
use crate::context::new_array_type;
1499+
14981500
let vector_type = vec
14991501
.get_type()
15001502
.unqualified()
@@ -1503,7 +1505,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15031505
let element_type = vector_type.get_element_type();
15041506
let vec_num_units = vector_type.get_num_units();
15051507
let array_type =
1506-
self.context.new_array_type_u64(self.location, element_type, vec_num_units as u64);
1508+
new_array_type(self.context, self.location, element_type, vec_num_units as u64);
15071509
let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();
15081510
self.context.new_array_access(self.location, array, idx).to_rvalue()
15091511
}

src/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::Mutability;
88
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, PointerArithmetic, Scalar};
99
use rustc_middle::ty::layout::LayoutOf;
1010

11-
use crate::context::CodegenCx;
11+
use crate::context::{CodegenCx, new_array_type};
1212
use crate::type_of::LayoutGccExt;
1313

1414
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -55,7 +55,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
5555
0 => {
5656
let context = &cx.context;
5757
let byte_type = context.new_type::<u64>();
58-
let typ = context.new_array_type_u64(None, byte_type, bytes.len() as u64 / 8);
58+
let typ = new_array_type(context, None, byte_type, bytes.len() as u64 / 8);
5959
let elements: Vec<_> = bytes
6060
.chunks_exact(8)
6161
.map(|arr| {
@@ -76,7 +76,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
7676
4 => {
7777
let context = &cx.context;
7878
let byte_type = context.new_type::<u32>();
79-
let typ = context.new_array_type_u64(None, byte_type, bytes.len() as u64 / 4);
79+
let typ = new_array_type(context, None, byte_type, bytes.len() as u64 / 4);
8080
let elements: Vec<_> = bytes
8181
.chunks_exact(4)
8282
.map(|arr| {
@@ -95,7 +95,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
9595
_ => {
9696
let context = cx.context;
9797
let byte_type = context.new_type::<u8>();
98-
let typ = context.new_array_type_u64(None, byte_type, bytes.len() as u64);
98+
let typ = new_array_type(context, None, byte_type, bytes.len() as u64);
9999
let elements: Vec<_> = bytes
100100
.iter()
101101
.map(|&byte| context.new_rvalue_from_int(byte_type, byte as i32))

src/context.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
201201

202202
// TODO(antoyo): re-enable the alignment when libgccjit fixed the issue in
203203
// gcc_jit_context_new_array_constructor (it should not use reinterpret_cast).
204-
let i128_type = context.new_array_type_u64(None, i64_type, 2)/*.get_aligned(i128_align)*/;
205-
let u128_type = context.new_array_type_u64(None, u64_type, 2)/*.get_aligned(u128_align)*/;
204+
let i128_type = new_array_type(context, None, i64_type, 2)/*.get_aligned(i128_align)*/;
205+
let u128_type = new_array_type(context, None, u64_type, 2)/*.get_aligned(u128_align)*/;
206206
(i128_type, u128_type)
207207
};
208208

@@ -608,3 +608,17 @@ fn to_gcc_tls_mode(tls_model: TlsModel) -> gccjit::TlsModel {
608608
TlsModel::Emulated => gccjit::TlsModel::GlobalDynamic,
609609
}
610610
}
611+
612+
pub fn new_array_type<'gcc>(
613+
context: &'gcc Context<'gcc>,
614+
location: Option<Location<'gcc>>,
615+
typ: Type<'gcc>,
616+
size: u64,
617+
) -> Type<'gcc> {
618+
#[cfg(feature = "master")]
619+
{
620+
context.new_array_type_u64(location, typ, size)
621+
}
622+
#[cfg(not(feature = "master"))]
623+
context.new_array_type(location, typ, size)
624+
}

src/intrinsic/llvm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gccjit::{CType, Context, Field, Function, FunctionPtrType, RValue, ToRValue,
44
use rustc_codegen_ssa::traits::BuilderMethods;
55

66
use crate::builder::Builder;
7-
use crate::context::CodegenCx;
7+
use crate::context::{CodegenCx, new_array_type};
88

99
fn encode_key_128_type<'a, 'gcc, 'tcx>(
1010
builder: &Builder<'a, 'gcc, 'tcx>,
@@ -585,15 +585,15 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
585585
"__builtin_ia32_encodekey128_u32" => {
586586
let mut new_args = args.to_vec();
587587
let m128i = builder.context.new_vector_type(builder.i64_type, 2);
588-
let array_type = builder.context.new_array_type_u64(None, m128i, 6);
588+
let array_type = new_array_type(builder.context, None, m128i, 6);
589589
let result = builder.current_func().new_local(None, array_type, "result");
590590
new_args.push(result.get_address(None));
591591
args = new_args.into();
592592
}
593593
"__builtin_ia32_encodekey256_u32" => {
594594
let mut new_args = args.to_vec();
595595
let m128i = builder.context.new_vector_type(builder.i64_type, 2);
596-
let array_type = builder.context.new_array_type_u64(None, m128i, 7);
596+
let array_type = new_array_type(builder.context, None, m128i, 7);
597597
let result = builder.current_func().new_local(None, array_type, "result");
598598
new_args.push(result.get_address(None));
599599
args = new_args.into();
@@ -620,7 +620,7 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
620620
let first_value = old_args.swap_remove(0);
621621

622622
let element_type = first_value.get_type();
623-
let array_type = builder.context.new_array_type_u64(None, element_type, 8);
623+
let array_type = new_array_type(builder.context, None, element_type, 8);
624624
let result = builder.current_func().new_local(None, array_type, "result");
625625
new_args.push(result.get_address(None));
626626

@@ -869,7 +869,7 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
869869
builder.llbb().add_assignment(None, field1, return_value);
870870
let field2 = result.access_field(None, field2);
871871
let field2_type = field2.to_rvalue().get_type();
872-
let array_type = builder.context.new_array_type_u64(None, field2_type, 6);
872+
let array_type = new_array_type(builder.context, None, field2_type, 6);
873873
let ptr = builder.context.new_cast(None, args[2], array_type.make_pointer());
874874
let field2_ptr =
875875
builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());
@@ -891,7 +891,7 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
891891
builder.llbb().add_assignment(None, field1, return_value);
892892
let field2 = result.access_field(None, field2);
893893
let field2_type = field2.to_rvalue().get_type();
894-
let array_type = builder.context.new_array_type_u64(None, field2_type, 7);
894+
let array_type = new_array_type(builder.context, None, field2_type, 7);
895895
let ptr = builder.context.new_cast(None, args[3], array_type.make_pointer());
896896
let field2_ptr =
897897
builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());
@@ -937,7 +937,7 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
937937
builder.llbb().add_assignment(None, field1, return_value);
938938
let field2 = result.access_field(None, field2);
939939
let field2_type = field2.to_rvalue().get_type();
940-
let array_type = builder.context.new_array_type_u64(None, field2_type, 8);
940+
let array_type = new_array_type(builder.context, None, field2_type, 8);
941941
let ptr = builder.context.new_cast(None, args[0], array_type.make_pointer());
942942
let field2_ptr =
943943
builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());

src/type_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::ty::layout::TyAndLayout;
1313
use rustc_middle::{bug, ty};
1414

1515
use crate::common::TypeReflection;
16-
use crate::context::CodegenCx;
16+
use crate::context::{CodegenCx, new_array_type};
1717
use crate::type_of::LayoutGccExt;
1818

1919
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -311,7 +311,7 @@ impl<'gcc, 'tcx> BaseTypeCodegenMethods for CodegenCx<'gcc, 'tcx> {
311311
len = 0;
312312
}
313313

314-
self.context.new_array_type_u64(None, ty, len)
314+
new_array_type(self.context, None, ty, len)
315315
}
316316
}
317317

0 commit comments

Comments
 (0)