Merge pull request #459 from tempdragon/master

fix(fmt/style): Clippy-generated Code Correction
This commit is contained in:
antoyo 2024-03-04 08:07:26 -05:00 committed by GitHub
commit e4ec64a1c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 38 additions and 43 deletions

View File

@ -63,7 +63,7 @@ pub(crate) unsafe fn codegen(
tcx, tcx,
context, context,
"__rust_alloc_error_handler", "__rust_alloc_error_handler",
&alloc_error_handler_name(alloc_error_handler_kind), alloc_error_handler_name(alloc_error_handler_kind),
&[usize, usize], &[usize, usize],
None, None,
); );
@ -93,7 +93,7 @@ fn create_wrapper_function(
let args: Vec<_> = types let args: Vec<_> = types
.iter() .iter()
.enumerate() .enumerate()
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index))) .map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
.collect(); .collect();
let func = context.new_function( let func = context.new_function(
None, None,
@ -115,7 +115,7 @@ fn create_wrapper_function(
let args: Vec<_> = types let args: Vec<_> = types
.iter() .iter()
.enumerate() .enumerate()
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index))) .map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
.collect(); .collect();
let callee = context.new_function( let callee = context.new_function(
None, None,

View File

@ -96,7 +96,7 @@ fn to_constraint(&self) -> String {
res.push('&'); res.push('&');
} }
res.push_str(&self.constraint); res.push_str(self.constraint);
res res
} }
} }
@ -304,7 +304,7 @@ fn codegen_inline_asm(
tmp_var.set_register_name(reg_name); tmp_var.set_register_name(reg_name);
outputs.push(AsmOutOperand { outputs.push(AsmOutOperand {
constraint: "r".into(), constraint: "r",
rust_idx, rust_idx,
late, late,
readwrite: false, readwrite: false,
@ -343,7 +343,7 @@ fn codegen_inline_asm(
tmp_var.set_register_name(reg_name); tmp_var.set_register_name(reg_name);
outputs.push(AsmOutOperand { outputs.push(AsmOutOperand {
constraint: "r".into(), constraint: "r",
rust_idx, rust_idx,
late, late,
readwrite: false, readwrite: false,

View File

@ -106,11 +106,10 @@ fn prepare_lto(
if !crate_type_allows_lto(*crate_type) { if !crate_type_allows_lto(*crate_type) {
dcx.emit_err(LtoDisallowed); dcx.emit_err(LtoDisallowed);
return Err(FatalError); return Err(FatalError);
} else if *crate_type == CrateType::Dylib { }
if !cgcx.opts.unstable_opts.dylib_lto { if *crate_type == CrateType::Dylib && !cgcx.opts.unstable_opts.dylib_lto {
dcx.emit_err(LtoDylib); dcx.emit_err(LtoDylib);
return Err(FatalError); return Err(FatalError);
}
} }
} }

View File

@ -77,10 +77,8 @@ fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
// boolean SSA values are i1, but they have to be stored in i8 slots, // boolean SSA values are i1, but they have to be stored in i8 slots,
// otherwise some LLVM optimization passes don't work as expected // otherwise some LLVM optimization passes don't work as expected
let val_llty = self.val_ty(value); let val_llty = self.val_ty(value);
let value = if val_llty == self.type_i1() { if val_llty == self.type_i1() {
unimplemented!(); unimplemented!();
} else {
value
}; };
let instance = Instance::mono(self.tcx, def_id); let instance = Instance::mono(self.tcx, def_id);
@ -94,11 +92,9 @@ fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
// As an optimization, all shared statics which do not have interior // As an optimization, all shared statics which do not have interior
// mutability are placed into read-only memory. // mutability are placed into read-only memory.
if !is_mutable { if !is_mutable && self.type_is_freeze(ty) {
if self.type_is_freeze(ty) { #[cfg(feature = "master")]
#[cfg(feature = "master")] global.global_set_readonly();
global.global_set_readonly();
}
} }
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {

View File

@ -255,7 +255,6 @@ fn create_dbg_var(
_variable_kind: VariableKind, _variable_kind: VariableKind,
_span: Span, _span: Span,
) -> Self::DIVariable { ) -> Self::DIVariable {
()
} }
fn dbg_scope_fn( fn dbg_scope_fn(

View File

@ -1065,7 +1065,7 @@ fn saturating_sub(
// Return `result_type`'s maximum or minimum value on overflow // Return `result_type`'s maximum or minimum value on overflow
// NOTE: convert the type to unsigned to have an unsigned shift. // NOTE: convert the type to unsigned to have an unsigned shift.
let unsigned_type = result_type.to_unsigned(&self.cx); let unsigned_type = result_type.to_unsigned(self.cx);
let shifted = self.gcc_lshr( let shifted = self.gcc_lshr(
self.gcc_int_cast(lhs, unsigned_type), self.gcc_int_cast(lhs, unsigned_type),
self.gcc_int(unsigned_type, width as i64 - 1), self.gcc_int(unsigned_type, width as i64 - 1),
@ -1108,9 +1108,10 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
// we can never unwind. // we can never unwind.
let ret_align = bx.tcx.data_layout.i32_align.abi; let ret_align = bx.tcx.data_layout.i32_align.abi;
bx.store(bx.const_i32(0), dest, ret_align); bx.store(bx.const_i32(0), dest, ret_align);
} else if wants_msvc_seh(bx.sess()) {
unimplemented!();
} else { } else {
if wants_msvc_seh(bx.sess()) {
unimplemented!();
}
#[cfg(feature = "master")] #[cfg(feature = "master")]
codegen_gnu_try(bx, try_func, data, _catch_func, dest); codegen_gnu_try(bx, try_func, data, _catch_func, dest);
#[cfg(not(feature = "master"))] #[cfg(not(feature = "master"))]
@ -1160,7 +1161,7 @@ fn codegen_gnu_try<'gcc>(
let catch_func = func.get_param(2).to_rvalue(); let catch_func = func.get_param(2).to_rvalue();
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void()); let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
let current_block = bx.block.clone(); let current_block = bx.block;
bx.switch_to_block(then); bx.switch_to_block(then);
bx.ret(bx.const_i32(0)); bx.ret(bx.const_i32(0));

View File

@ -187,7 +187,7 @@ fn init(&self, sess: &Session) {
// Get the second TargetInfo with the correct CPU features by setting the arch. // Get the second TargetInfo with the correct CPU features by setting the arch.
let context = Context::default(); let context = Context::default();
if target_cpu != "generic" { if target_cpu != "generic" {
context.add_command_line_option(&format!("-march={}", target_cpu)); context.add_command_line_option(format!("-march={}", target_cpu));
} }
**self.target_info.info.lock().expect("lock") = context.get_target_info(); **self.target_info.info.lock().expect("lock") = context.get_target_info();
@ -224,9 +224,9 @@ fn provide(&self, providers: &mut Providers) {
providers.global_backend_features = |tcx, ()| gcc_util::global_gcc_features(tcx.sess, true) providers.global_backend_features = |tcx, ()| gcc_util::global_gcc_features(tcx.sess, true)
} }
fn codegen_crate<'tcx>( fn codegen_crate(
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'_>,
metadata: EncodedMetadata, metadata: EncodedMetadata,
need_metadata_module: bool, need_metadata_module: bool,
) -> Box<dyn Any> { ) -> Box<dyn Any> {
@ -292,9 +292,9 @@ fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {
} }
impl ExtraBackendMethods for GccCodegenBackend { impl ExtraBackendMethods for GccCodegenBackend {
fn codegen_allocator<'tcx>( fn codegen_allocator(
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'_>,
module_name: &str, module_name: &str,
kind: AllocatorKind, kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind,
@ -486,6 +486,6 @@ pub fn target_features(
sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves
*/ */
}) })
.map(|feature| Symbol::intern(feature)) .map(Symbol::intern)
.collect() .collect()
} }

View File

@ -47,7 +47,7 @@ fn predefine_fn(
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty()); let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
self.linkage.set(base::linkage_to_gcc(linkage)); self.linkage.set(base::linkage_to_gcc(linkage));
let decl = self.declare_fn(symbol_name, &fn_abi); let decl = self.declare_fn(symbol_name, fn_abi);
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id()); //let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
attributes::from_fn_attrs(self, decl, instance); attributes::from_fn_attrs(self, decl, instance);

View File

@ -133,13 +133,13 @@ fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> { fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
let types = fields.to_vec(); let types = fields.to_vec();
if let Some(typ) = self.struct_types.borrow().get(fields) { if let Some(typ) = self.struct_types.borrow().get(fields) {
return typ.clone(); return *typ;
} }
let fields: Vec<_> = fields let fields: Vec<_> = fields
.iter() .iter()
.enumerate() .enumerate()
.map(|(index, field)| { .map(|(index, field)| {
self.context.new_field(None, *field, &format!("field{}_TODO", index)) self.context.new_field(None, *field, format!("field{}_TODO", index))
}) })
.collect(); .collect();
let typ = self.context.new_struct_type(None, "struct", &fields).as_type(); let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
@ -240,7 +240,7 @@ pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed:
let fields: Vec<_> = fields let fields: Vec<_> = fields
.iter() .iter()
.enumerate() .enumerate()
.map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index))) .map(|(index, field)| self.context.new_field(None, *field, format!("field_{}", index)))
.collect(); .collect();
typ.set_fields(None, &fields); typ.set_fields(None, &fields);
if packed { if packed {
@ -265,7 +265,7 @@ pub fn struct_fields<'gcc, 'tcx>(
let mut prev_effective_align = layout.align.abi; let mut prev_effective_align = layout.align.abi;
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2); let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
for i in layout.fields.index_by_increasing_offset() { for i in layout.fields.index_by_increasing_offset() {
let target_offset = layout.fields.offset(i as usize); let target_offset = layout.fields.offset(i);
let field = layout.field(cx, i); let field = layout.field(cx, i);
let effective_field_align = let effective_field_align =
layout.align.abi.min(field.align.abi).restrict_for_offset(target_offset); layout.align.abi.min(field.align.abi).restrict_for_offset(target_offset);

View File

@ -76,7 +76,7 @@ fn filter(filename: &Path) -> bool {
exe.push(&tempdir); exe.push(&tempdir);
exe.push(path.file_stem().expect("file_stem")); exe.push(path.file_stem().expect("file_stem"));
let mut compiler = Command::new("rustc"); let mut compiler = Command::new("rustc");
compiler.args(&[ compiler.args([
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir), &format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
"--sysroot", "--sysroot",
&format!("{}/build_sysroot/sysroot/", current_dir), &format!("{}/build_sysroot/sysroot/", current_dir),
@ -91,7 +91,7 @@ fn filter(filename: &Path) -> bool {
// TODO(antoyo): find a way to send this via a cli argument. // TODO(antoyo): find a way to send this via a cli argument.
let test_target = std::env::var("CG_GCC_TEST_TARGET"); let test_target = std::env::var("CG_GCC_TEST_TARGET");
if let Ok(ref target) = test_target { if let Ok(ref target) = test_target {
compiler.args(&["--target", &target]); compiler.args(["--target", target]);
let linker = format!("{}-gcc", target); let linker = format!("{}-gcc", target);
compiler.args(&[format!("-Clinker={}", linker)]); compiler.args(&[format!("-Clinker={}", linker)]);
let mut env_path = std::env::var("PATH").unwrap_or_default(); let mut env_path = std::env::var("PATH").unwrap_or_default();
@ -102,32 +102,32 @@ fn filter(filename: &Path) -> bool {
if let Some(flags) = option_env!("TEST_FLAGS") { if let Some(flags) = option_env!("TEST_FLAGS") {
for flag in flags.split_whitespace() { for flag in flags.split_whitespace() {
compiler.arg(&flag); compiler.arg(flag);
} }
} }
match profile { match profile {
Profile::Debug => {} Profile::Debug => {}
Profile::Release => { Profile::Release => {
compiler.args(&["-C", "opt-level=3", "-C", "lto=no"]); compiler.args(["-C", "opt-level=3", "-C", "lto=no"]);
} }
} }
// Test command 2: run `tempdir/x`. // Test command 2: run `tempdir/x`.
if test_target.is_ok() { if test_target.is_ok() {
let vm_parent_dir = std::env::var("CG_GCC_VM_DIR") let vm_parent_dir = std::env::var("CG_GCC_VM_DIR")
.map(|dir| PathBuf::from(dir)) .map(PathBuf::from)
.unwrap_or_else(|_| std::env::current_dir().unwrap()); .unwrap_or_else(|_| std::env::current_dir().unwrap());
let vm_dir = "vm"; let vm_dir = "vm";
let exe_filename = exe.file_name().unwrap(); let exe_filename = exe.file_name().unwrap();
let vm_home_dir = vm_parent_dir.join(vm_dir).join("home"); let vm_home_dir = vm_parent_dir.join(vm_dir).join("home");
let vm_exe_path = vm_home_dir.join(exe_filename); let vm_exe_path = vm_home_dir.join(exe_filename);
// FIXME(antoyo): panicking here makes the test pass. // FIXME(antoyo): panicking here makes the test pass.
let inside_vm_exe_path = PathBuf::from("/home").join(&exe_filename); let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename);
let mut copy = Command::new("sudo"); let mut copy = Command::new("sudo");
copy.arg("cp"); copy.arg("cp");
copy.args(&[&exe, &vm_exe_path]); copy.args([&exe, &vm_exe_path]);
let mut runtime = Command::new("sudo"); let mut runtime = Command::new("sudo");
runtime.args(&["chroot", vm_dir, "qemu-m68k-static"]); runtime.args(["chroot", vm_dir, "qemu-m68k-static"]);
runtime.arg(inside_vm_exe_path); runtime.arg(inside_vm_exe_path);
runtime.current_dir(vm_parent_dir); runtime.current_dir(vm_parent_dir);
vec![("Compiler", compiler), ("Copy", copy), ("Run-time", runtime)] vec![("Compiler", compiler), ("Copy", copy), ("Run-time", runtime)]