Skip to content

Clippy related fixes #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6f76488
fix(fmt/style): Remove unncessary clones, into's and deref's
tempdragon Mar 8, 2024
9ea3c19
fix(fmt/style): Further apply Clippy suggestions manually
tempdragon Mar 9, 2024
c6b7558
fix(declare.rs): Clone `name` when buiding without the master feat.
tempdragon Mar 9, 2024
8d4d878
fix(clippy): Clone-related clippy workarounds
tempdragon Mar 11, 2024
ad97b8c
fix(liftime): Gen. by cargo clippy
tempdragon Mar 11, 2024
091de55
fix(fmt): Try to comply to the format requirement
tempdragon Mar 11, 2024
d2cda90
fix(clippy): redundant variables in `simd.rs`
tempdragon Mar 11, 2024
3fd9db3
fix(fmt): Rewrite a condition according to clippy
tempdragon Mar 11, 2024
a7d39b8
fix(from_low_high): Renamed according to clippy requirements
tempdragon Mar 11, 2024
817d2f2
fix(pattern_type_mismatch)): Fix mismatch with ref/deref
tempdragon Mar 16, 2024
878f572
fix(comments): Add some info and revert `else if`
tempdragon Mar 16, 2024
390f906
revert(lifetime): Add "needless" lifetime(s) and allow it in clippy
tempdragon Mar 16, 2024
f6cab2c
feat(CI): Add clippy check to workflow.
tempdragon Mar 16, 2024
653118e
feat(clippy): Suppress lint `suspicious_else_formatting` temporarily
tempdragon Mar 16, 2024
225a32f
Revert "feat(CI): Add clippy check to workflow."
tempdragon Mar 16, 2024
89acb10
feat(ci): Install clippy in ci.yml(But no testing)
tempdragon Mar 16, 2024
4e4efb9
feat(ci): Add clippy check for both master and non-master
tempdragon Mar 16, 2024
3b01fba
fix(intrinsic/mod.rs): Update comments
tempdragon Mar 16, 2024
0a49351
fix(lifetime): Add lifetimes back.
tempdragon Mar 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
run: sudo apt-get install ninja-build ripgrep llvm-14-tools

- name: Install rustfmt
run: rustup component add rustfmt
- name: Install rustfmt & clippy
run: rustup component add rustfmt clippy

- name: Download artifact
run: curl -LO https://github.com/antoyo/gcc/releases/latest/download/${{ matrix.libgccjit_version.gcc }}
Expand Down Expand Up @@ -98,6 +98,11 @@ jobs:
- name: Check formatting
run: cargo fmt -- --check

- name: clippy
run: |
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets --features master -- -D warnings

duplicates:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
let mut function_features = function_features
.iter()
.flat_map(|feat| to_gcc_features(cx.tcx.sess, feat).into_iter())
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match x {
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match *x {
InstructionSetAttr::ArmA32 => "-thumb-mode", // TODO(antoyo): support removing feature.
InstructionSetAttr::ArmT32 => "thumb-mode",
}))
Expand All @@ -118,8 +118,8 @@ pub fn from_fn_attrs<'gcc, 'tcx>(

if feature.starts_with('-') {
Some(format!("no{}", feature))
} else if feature.starts_with('+') {
Some(feature[1..].to_string())
} else if let Some(stripped) = feature.strip_prefix('+') {
Some(stripped.to_string())
} else {
Some(feature.to_string())
}
Expand Down
3 changes: 1 addition & 2 deletions src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ fn prepare_lto(
}

let archive_data = unsafe {
Mmap::map(File::open(&path).expect("couldn't open rlib"))
.expect("couldn't map rlib")
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
};
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
let obj_files = archive
Expand Down
2 changes: 1 addition & 1 deletion src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub(crate) unsafe fn codegen(
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
// transmuting an rvalue to an lvalue.
// Segfault is actually in gcc::jit::reproducer::get_identifier_as_lvalue
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
context.dump_reproducer_to_file(format!("/tmp/reproducers/{}.c", module.name));
println!("Dumped reproducer {}", module.name);
}
if env::var("CG_GCCJIT_DUMP_TO_FILE").as_deref() == Ok("1") {
Expand Down
2 changes: 1 addition & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn compile_codegen_unit(

let target_cpu = gcc_util::target_cpu(tcx.sess);
if target_cpu != "generic" {
context.add_command_line_option(&format!("-march={}", target_cpu));
context.add_command_line_option(format!("-march={}", target_cpu));
}

if tcx
Expand Down
36 changes: 17 additions & 19 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

let mut on_stack_param_indices = FxHashSet::default();
if let Some(indices) = self.on_stack_params.borrow().get(&gcc_func) {
on_stack_param_indices = indices.clone();
on_stack_param_indices.clone_from(indices);
}

if all_args_match {
Expand Down Expand Up @@ -256,8 +256,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
actual_val.dereference(self.location).to_rvalue()
} else {
assert!(
!((actual_ty.is_vector() && !expected_ty.is_vector())
|| (!actual_ty.is_vector() && expected_ty.is_vector())),
(!expected_ty.is_vector() || actual_ty.is_vector())
&& (expected_ty.is_vector() || !actual_ty.is_vector()),
"{:?} ({}) -> {:?} ({}), index: {:?}[{}]",
actual_ty,
actual_ty.is_vector(),
Expand All @@ -277,8 +277,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
.collect();

// NOTE: to take into account variadic functions.
for i in casted_args.len()..args.len() {
casted_args.push(args[i]);
for arg in args.iter().skip(casted_args.len()) {
casted_args.push(*arg);
}

Cow::Owned(casted_args)
Expand Down Expand Up @@ -353,15 +353,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let function_address_names = self.function_address_names.borrow();
let original_function_name = function_address_names.get(&func_ptr);
llvm::adjust_intrinsic_arguments(
&self,
self,
gcc_func,
args.into(),
&func_name,
original_function_name,
)
};
let args_adjusted = args.len() != previous_arg_count;
let args = self.check_ptr_call("call", func_ptr, &*args);
let args = self.check_ptr_call("call", func_ptr, &args);

// gccjit requires to use the result of functions, even when it's not used.
// That's why we assign the result to a local or call add_eval().
Expand All @@ -373,7 +373,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
unsafe { RETURN_VALUE_COUNT += 1 };
let return_value = self.cx.context.new_call_through_ptr(self.location, func_ptr, &args);
let return_value = llvm::adjust_intrinsic_return_value(
&self,
self,
return_value,
&func_name,
&args,
Expand Down Expand Up @@ -441,7 +441,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
self.block.add_assignment(
self.location,
result,
self.cx.context.new_call(self.location, func, &args),
self.cx.context.new_call(self.location, func, args),
);
result.to_rvalue()
}
Expand Down Expand Up @@ -595,7 +595,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
) -> RValue<'gcc> {
let try_block = self.current_func().new_block("try");

let current_block = self.block.clone();
let current_block = self.block;
self.block = try_block;
let call = self.call(typ, fn_attrs, None, func, args, None); // TODO(antoyo): use funclet here?
self.block = current_block;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// NOTE: due to opaque pointers now being used, we need to cast here.
let ptr = self.context.new_cast(self.location, ptr, typ.make_pointer());
// NOTE: array indexing is always considered in bounds in GCC (TODO(antoyo): to be verified).
let mut indices = indices.into_iter();
let mut indices = indices.iter();
let index = indices.next().expect("first index in inbounds_gep");
let mut result = self.context.new_array_access(self.location, ptr, *index);
for index in indices {
Expand Down Expand Up @@ -1684,7 +1684,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {

fn zext(&mut self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<'gcc> {
// FIXME(antoyo): this does not zero-extend.
if value.get_type().is_bool() && dest_typ.is_i8(&self.cx) {
if value.get_type().is_bool() && dest_typ.is_i8(self.cx) {
// FIXME(antoyo): hack because base::from_immediate converts i1 to i8.
// Fix the code in codegen_ssa::base::from_immediate.
return value;
Expand Down Expand Up @@ -2057,7 +2057,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
self.context.new_rvalue_from_vector(self.location, mask_type, &vector_elements);
let shifted = self.context.new_rvalue_vector_perm(self.location, res, res, mask);
shift *= 2;
res = op(res, shifted, &self.context);
res = op(res, shifted, self.context);
}
self.context
.new_vector_access(self.location, res, self.context.new_rvalue_zero(self.int_type))
Expand All @@ -2073,7 +2073,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
}

pub fn vector_reduce_op(&mut self, src: RValue<'gcc>, op: BinaryOp) -> RValue<'gcc> {
let loc = self.location.clone();
let loc = self.location;
self.vector_reduce(src, |a, b, context| context.new_binary_op(loc, op, a.get_type(), a, b))
}

Expand All @@ -2090,7 +2090,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
let element_count = vector_type.get_num_units();
(0..element_count)
.into_iter()
.map(|i| {
self.context
.new_vector_access(
Expand Down Expand Up @@ -2121,7 +2120,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
let element_count = vector_type.get_num_units();
(0..element_count)
.into_iter()
.map(|i| {
self.context
.new_vector_access(
Expand All @@ -2141,7 +2139,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

// Inspired by Hacker's Delight min implementation.
pub fn vector_reduce_min(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
let loc = self.location.clone();
let loc = self.location;
self.vector_reduce(src, |a, b, context| {
let differences_or_zeros = difference_or_zero(loc, a, b, context);
context.new_binary_op(loc, BinaryOp::Plus, b.get_type(), b, differences_or_zeros)
Expand All @@ -2150,7 +2148,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

// Inspired by Hacker's Delight max implementation.
pub fn vector_reduce_max(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
let loc = self.location.clone();
let loc = self.location;
self.vector_reduce(src, |a, b, context| {
let differences_or_zeros = difference_or_zero(loc, a, b, context);
context.new_binary_op(loc, BinaryOp::Minus, a.get_type(), a, differences_or_zeros)
Expand Down Expand Up @@ -2345,7 +2343,7 @@ impl<'tcx> HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {

impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
fn target_spec(&self) -> &Target {
&self.cx.target_spec()
self.cx.target_spec()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)

let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());

let func = if let Some(_func) = cx.get_declared_value(&sym) {
let func = if let Some(_func) = cx.get_declared_value(sym) {
// FIXME(antoyo): we never reach this because get_declared_value only returns global variables
// and here we try to get a function.
unreachable!();
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
}*/
} else {
cx.linkage.set(FunctionType::Extern);
let func = cx.declare_fn(&sym, &fn_abi);
let func = cx.declare_fn(sym, fn_abi);

attributes::from_fn_attrs(cx, func, instance);

Expand Down
11 changes: 6 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

fn global_string(&self, string: &str) -> LValue<'gcc> {
// TODO(antoyo): handle non-null-terminated strings.
let string = self.context.new_string_literal(&*string);
let string = self.context.new_string_literal(string);
let sym = self.generate_local_symbol_name("str");
let global = self.declare_private_global(&sym, self.val_ty(string));
global.global_set_initializer_rvalue(string);
Expand Down Expand Up @@ -170,7 +170,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
return self
.context
.new_rvalue_from_double(ty, f32::from_bits(data as u32) as f64);
} else if ty == self.double_type {
}
if ty == self.double_type {
return self.context.new_rvalue_from_double(ty, f64::from_bits(data as u64));
}

Expand Down Expand Up @@ -293,7 +294,7 @@ impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
} else if self.is_ulonglong(cx) {
cx.longlong_type
} else {
self.clone()
*self
}
}

Expand All @@ -319,7 +320,7 @@ impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
} else if self.is_longlong(cx) {
cx.ulonglong_type
} else {
self.clone()
*self
}
}
}
Expand Down Expand Up @@ -432,7 +433,7 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
}

fn is_vector(&self) -> bool {
let mut typ = self.clone();
let mut typ = *self;
loop {
if typ.dyncast_vector().is_some() {
return true;
Expand Down
24 changes: 8 additions & 16 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
let attrs = self.tcx.codegen_fn_attrs(def_id);

let value = match codegen_static_initializer(&self, def_id) {
let value = match codegen_static_initializer(self, def_id) {
Ok((value, _)) => value,
// Error has already been reported
Err(_) => return,
Expand Down Expand Up @@ -231,13 +231,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}

let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = self.declare_global(
&sym,
llty,
GlobalKind::Exported,
is_tls,
fn_attrs.link_section,
);
let global =
self.declare_global(sym, llty, GlobalKind::Exported, is_tls, fn_attrs.link_section);

if !self.tcx.is_reachable_non_generic(def_id) {
#[cfg(feature = "master")]
Expand All @@ -246,7 +241,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

global
} else {
check_and_apply_linkage(&self, &fn_attrs, ty, sym)
check_and_apply_linkage(self, fn_attrs, ty, sym)
};

if !def_id.is_local() {
Expand Down Expand Up @@ -367,11 +362,8 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
let gcc_type = cx.layout_of(ty).gcc_type(cx);
if let Some(linkage) = attrs.import_linkage {
// Declare a symbol `foo` with the desired linkage.
let global1 = cx.declare_global_with_linkage(
&sym,
cx.type_i8(),
base::global_linkage_to_gcc(linkage),
);
let global1 =
cx.declare_global_with_linkage(sym, cx.type_i8(), base::global_linkage_to_gcc(linkage));

// Declare an internal global `extern_with_linkage_foo` which
// is initialized with the address of `foo`. If `foo` is
Expand All @@ -380,7 +372,7 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
// `extern_with_linkage_foo` will instead be initialized to
// zero.
let mut real_name = "_rust_extern_with_linkage_".to_string();
real_name.push_str(&sym);
real_name.push_str(sym);
let global2 = cx.define_global(&real_name, gcc_type, is_tls, attrs.link_section);
// TODO(antoyo): set linkage.
let value = cx.const_ptrcast(global1.get_address(None), gcc_type);
Expand All @@ -397,6 +389,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
// don't do this then linker errors can be generated where the linker
// complains that one object files has a thread local version of the
// symbol and another one doesn't.
cx.declare_global(&sym, gcc_type, GlobalKind::Imported, is_tls, attrs.link_section)
cx.declare_global(sym, gcc_type, GlobalKind::Imported, is_tls, attrs.link_section)
}
}
10 changes: 5 additions & 5 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}

pub fn sess(&self) -> &'tcx Session {
&self.tcx.sess
self.tcx.sess
}

pub fn bitcast_if_needed(
Expand Down Expand Up @@ -431,7 +431,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let func_name = self.tcx.symbol_name(instance).name;

let func = if self.intrinsics.borrow().contains_key(func_name) {
self.intrinsics.borrow()[func_name].clone()
self.intrinsics.borrow()[func_name]
} else {
get_fn(self, instance)
};
Expand Down Expand Up @@ -485,7 +485,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let symbol_name = tcx.symbol_name(instance).name;
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
self.linkage.set(FunctionType::Extern);
let func = self.declare_fn(symbol_name, &fn_abi);
let func = self.declare_fn(symbol_name, fn_abi);
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
func
}
Expand All @@ -505,7 +505,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
}

fn sess(&self) -> &Session {
&self.tcx.sess
self.tcx.sess
}

fn check_overflow(&self) -> bool {
Expand Down Expand Up @@ -612,7 +612,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
// user defined names
let mut name = String::with_capacity(prefix.len() + 6);
name.push_str(prefix);
name.push_str(".");
name.push('.');
base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
name
}
Expand Down
Loading
Loading