diff --git a/Cargo.lock b/Cargo.lock index ec20868ad0..9c69d8fdcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,6 +281,7 @@ dependencies = [ "lazy_static", "log", "rustc-private-link", + "semver", ] [[package]] @@ -1697,9 +1698,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" dependencies = [ "serde", ] diff --git a/c2rust-ast-builder/src/builder.rs b/c2rust-ast-builder/src/builder.rs index 7a8ccff7a1..1b5beaf52e 100644 --- a/c2rust-ast-builder/src/builder.rs +++ b/c2rust-ast-builder/src/builder.rs @@ -178,13 +178,13 @@ impl Make for &str { impl Make for String { fn make(self, mk: &Builder) -> Ident { - Ident::new(&*self, mk.span) + Ident::new(&self, mk.span) } } impl Make for &String { fn make(self, mk: &Builder) -> Ident { - Ident::new(&*self, mk.span) + Ident::new(self, mk.span) } } @@ -209,7 +209,7 @@ impl<'a> Make for &'a str { impl<'a> Make for &'a str { fn make(self, mk_: &Builder) -> Visibility { - let kind = match self { + match self { "pub" => Visibility::Public(VisPublic { pub_token: token::Pub(mk_.span), }), @@ -230,8 +230,7 @@ impl<'a> Make for &'a str { path: Box::new(mk().path("super")), }), _ => panic!("unrecognized string for Visibility: {:?}", self), - }; - kind + } } } @@ -251,7 +250,7 @@ impl<'a> Make for &'a str { } } -impl<'a> Make for Abi { +impl Make for Abi { fn make(self, _mk: &Builder) -> Extern { Extern::Explicit(self.name.to_token_stream().to_string()) } @@ -379,13 +378,13 @@ impl Make for Lit { impl Make for String { fn make(self, mk: &Builder) -> Lit { - Lit::Str(LitStr::new(&*self, mk.span)) + Lit::Str(LitStr::new(&self, mk.span)) } } impl Make for &String { fn make(self, mk: &Builder) -> Lit { - Lit::Str(LitStr::new(&*self, mk.span)) + Lit::Str(LitStr::new(self, mk.span)) } } @@ -884,7 +883,7 @@ impl Builder { let rhs = rhs.make(&self); match op { - BinOp::Lt(_) | BinOp::Shl(_) if has_rightmost_cast(&*lhs) => lhs = mk().paren_expr(lhs), + BinOp::Lt(_) | BinOp::Shl(_) if has_rightmost_cast(&lhs) => lhs = mk().paren_expr(lhs), _ => {} } @@ -2596,13 +2595,13 @@ fn has_rightmost_cast(expr: &Expr) -> bool { attrs: _, op: _, ref expr, - }) => has_rightmost_cast(&**expr), + }) => has_rightmost_cast(expr), Expr::Binary(ExprBinary { attrs: _, left: _, op: _, ref right, - }) => has_rightmost_cast(&**right), + }) => has_rightmost_cast(right), _ => false, } } diff --git a/c2rust-transpile/src/c_ast/conversion.rs b/c2rust-transpile/src/c_ast/conversion.rs index 26933af954..26033bf0ae 100644 --- a/c2rust-transpile/src/c_ast/conversion.rs +++ b/c2rust-transpile/src/c_ast/conversion.rs @@ -1011,18 +1011,15 @@ impl ConversionContext { let label_name = from_value::>(node.extras[0].clone()) .expect("unnamed label in C source code"); - match self + if let Some(old_label_name) = self .typed_context .label_names .insert(CStmtId(new_id), label_name.clone()) { - Some(old_label_name) => { - panic!( - "Duplicate label name with id {}. Old name: {}. New name: {}", - new_id, old_label_name, label_name, - ); - } - None => {} + panic!( + "Duplicate label name with id {}. Old name: {}. New name: {}", + new_id, old_label_name, label_name, + ); } let label_stmt = CStmtKind::Label(substmt); diff --git a/c2rust-transpile/src/c_ast/mod.rs b/c2rust-transpile/src/c_ast/mod.rs index 7a942f69bb..e879ae4612 100644 --- a/c2rust-transpile/src/c_ast/mod.rs +++ b/c2rust-transpile/src/c_ast/mod.rs @@ -1182,7 +1182,7 @@ impl CExprKind { } } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CastKind { BitCast, LValueToRValue, @@ -1296,7 +1296,7 @@ impl UnOp { } /// Represents a binary operator in C (6.5.5 Multiplicative operators - 6.5.14 Logical OR operator) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BinOp { Multiply, // * Divide, // / @@ -1521,7 +1521,7 @@ pub struct AsmOperand { } /// Type qualifiers (6.7.3) -#[derive(Debug, Copy, Clone, Default, PartialEq)] +#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)] pub struct Qualifiers { /// The `const` qualifier, which marks lvalues as non-assignable. /// @@ -1557,7 +1557,7 @@ impl Qualifiers { } /// Qualified type -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct CQualTypeId { pub qualifiers: Qualifiers, pub ctype: CTypeId, @@ -1580,7 +1580,7 @@ impl CQualTypeId { /// Represents a type in C (6.2.5 Types) /// /// Reflects the types in -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum CTypeKind { Void, diff --git a/c2rust-transpile/src/c_ast/print.rs b/c2rust-transpile/src/c_ast/print.rs index 3d05eb6f9f..1c2c23d2df 100644 --- a/c2rust-transpile/src/c_ast/print.rs +++ b/c2rust-transpile/src/c_ast/print.rs @@ -556,12 +556,9 @@ impl Printer { self.writer.write_all(b"__thread ")?; } self.print_qtype(typ, Some(ident.as_str()), context)?; - match initializer { - Some(init) => { - self.writer.write_all(b" = ")?; - self.print_expr(init, context)?; - } - None => {} + if let Some(init) = initializer { + self.writer.write_all(b" = ")?; + self.print_expr(init, context)?; } self.writer.write_all(b";")?; if newline { diff --git a/c2rust-transpile/src/rust_ast/comment_store.rs b/c2rust-transpile/src/rust_ast/comment_store.rs index bec7dd591f..8371ca9fc3 100644 --- a/c2rust-transpile/src/rust_ast/comment_store.rs +++ b/c2rust-transpile/src/rust_ast/comment_store.rs @@ -294,7 +294,7 @@ pub fn insert_comment_attrs(attrs: &mut Vec, new_comments: SmallVec<[ } for c in new_comments { - let lit = Lit::new(proc_macro2::Literal::string(&*c)); + let lit = Lit::new(proc_macro2::Literal::string(c)); let mut tokens = TokenStream::new(); eq.to_tokens(&mut tokens); lit.to_tokens(&mut tokens); diff --git a/c2rust-transpile/src/translator/assembly.rs b/c2rust-transpile/src/translator/assembly.rs index 0fd709e0ce..9f3450447e 100644 --- a/c2rust-transpile/src/translator/assembly.rs +++ b/c2rust-transpile/src/translator/assembly.rs @@ -157,7 +157,7 @@ fn parse_constraints( if !(is_explicit_reg || is_tied) { // Attempt to parse machine-specific constraints if let Some((machine_constraints, is_mem)) = - translate_machine_constraint(&*constraints, arch) + translate_machine_constraint(&constraints, arch) { constraints = machine_constraints.into(); mem_only = is_mem; @@ -368,7 +368,7 @@ fn rewrite_reserved_reg_operands( for (i, operand) in operands.iter().enumerate() { if operand.is_positional() { total_positional += 1; - } else if let Some((reg, mods)) = reg_is_reserved(&*operand.constraints, arch) { + } else if let Some((reg, mods)) = reg_is_reserved(&operand.constraints, arch) { rewrite_idxs.push((i, reg.to_owned(), mods.to_owned())); } } @@ -615,7 +615,7 @@ fn rewrite_asm bool, M: Fn(usize) -> usize>( out.push_str(input_op_mapper(idx).to_string().as_str()); if !new_modifiers.is_empty() { out.push(':'); - out.push_str(&*new_modifiers); + out.push_str(&new_modifiers); } out.push_str(if mem_only { "}]" } else { "}" }); // Push the rest of the chunk @@ -739,7 +739,7 @@ impl<'c> Translation<'c> { for (i, input) in inputs.iter().enumerate() { let (_dir_spec, _mem_only, parsed) = parse_constraints(&input.constraints, arch)?; // Only pair operands with an explicit register or index - if is_regname_or_int(&*parsed) { + if is_regname_or_int(&parsed) { inputs_by_register.insert(parsed, (i, input.clone())); } else { other_inputs.push((parsed, (i, input.clone()))); @@ -807,7 +807,7 @@ impl<'c> Translation<'c> { // Determine whether the assembly is in AT&T syntax let att_syntax = match arch { - Arch::X86OrX86_64 => asm_is_att_syntax(&*rewritten_asm), + Arch::X86OrX86_64 => asm_is_att_syntax(&rewritten_asm), _ => false, }; @@ -926,7 +926,7 @@ impl<'c> Translation<'c> { // Emit dir_spec(constraint), quoting constraint if needed push_expr(&mut tokens, mk().ident_expr(operand.dir_spec.to_string())); - let constraints_ident = if is_regname_or_int(&*operand.constraints) { + let constraints_ident = if is_regname_or_int(&operand.constraints) { mk().lit_expr(operand.constraints.trim_matches('"')) } else { mk().ident_expr(operand.constraints) diff --git a/c2rust-transpile/src/translator/comments.rs b/c2rust-transpile/src/translator/comments.rs index f39dd7573e..09cb082ee8 100644 --- a/c2rust-transpile/src/translator/comments.rs +++ b/c2rust-transpile/src/translator/comments.rs @@ -166,7 +166,7 @@ impl<'c> Translation<'c> { let mut visitor = CommentLocator { ast_context: &self.ast_context, comment_context: &self.comment_context, - comment_store: &mut *self.comment_store.borrow_mut(), + comment_store: &mut self.comment_store.borrow_mut(), spans: &mut spans, top_decls: &top_decls, last_id: None, diff --git a/c2rust-transpile/src/translator/literals.rs b/c2rust-transpile/src/translator/literals.rs index beae633f4b..ded98bbfec 100644 --- a/c2rust-transpile/src/translator/literals.rs +++ b/c2rust-transpile/src/translator/literals.rs @@ -95,7 +95,9 @@ impl<'c> Translation<'c> { if (val as i32) < 0 { mk().unary_expr( "-", - mk().lit_expr(mk().int_lit((val as i32).abs() as u128, "i32")), + mk().lit_expr( + mk().int_lit((val as i32).unsigned_abs() as u128, "i32"), + ), ) } else { mk().lit_expr(mk().int_lit(val as u128, "i32")) @@ -121,8 +123,8 @@ impl<'c> Translation<'c> { mk().call_expr(fn_path, args) } - CTypeKind::Double => mk().lit_expr(mk().float_lit(&*str, "f64")), - CTypeKind::Float => mk().lit_expr(mk().float_lit(&*str, "f32")), + CTypeKind::Double => mk().lit_expr(mk().float_lit(&str, "f64")), + CTypeKind::Float => mk().lit_expr(mk().float_lit(&str, "f32")), ref k => panic!("Unsupported floating point literal type {:?}", k), }; Ok(WithStmts::new_val(val)) diff --git a/c2rust-transpile/src/translator/mod.rs b/c2rust-transpile/src/translator/mod.rs index 4289ed69f5..e3b87d17f2 100644 --- a/c2rust-transpile/src/translator/mod.rs +++ b/c2rust-transpile/src/translator/mod.rs @@ -57,7 +57,7 @@ use crate::PragmaVec; pub const INNER_SUFFIX: &str = "_Inner"; pub const PADDING_SUFFIX: &str = "_PADDING"; -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum DecayRef { Yes, Default, diff --git a/dynamic_instrumentation/Cargo.toml b/dynamic_instrumentation/Cargo.toml index 763e02de48..1d5678058f 100644 --- a/dynamic_instrumentation/Cargo.toml +++ b/dynamic_instrumentation/Cargo.toml @@ -12,6 +12,7 @@ cargo-util = "0.1" indexmap = "1.8" lazy_static = "1.4" log = "0.4" +semver = "1.0.12" # needed b/c cargo 0.62 > semver 1.0.10 fails `cargo doc` [build-dependencies] rustc-private-link = { path = "../rustc-private-link" } diff --git a/dynamic_instrumentation/src/instrument_memory.rs b/dynamic_instrumentation/src/instrument_memory.rs index 72a038ae19..b277ceaaf0 100644 --- a/dynamic_instrumentation/src/instrument_memory.rs +++ b/dynamic_instrumentation/src/instrument_memory.rs @@ -10,9 +10,9 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{ - BasicBlock, BasicBlockData, Body, BorrowKind, CastKind, Constant, Local, LocalDecl, Location, - Mutability, Operand, Place, PlaceElem, ProjectionElem, Rvalue, SourceInfo, Statement, - StatementKind, Terminator, TerminatorKind, START_BLOCK, + BasicBlock, BasicBlockData, Body, BorrowKind, CastKind, Constant, ConstantKind, Local, + LocalDecl, Location, Mutability, Operand, Place, PlaceElem, ProjectionElem, Rvalue, SourceInfo, + Statement, StatementKind, Terminator, TerminatorKind, START_BLOCK, }; use rustc_middle::ty::{self, ParamEnv, TyCtxt}; use rustc_span::def_id::{DefId, DefPathHash, CRATE_DEF_INDEX}; @@ -184,7 +184,7 @@ struct CollectFunctionInstrumentationPoints<'a, 'tcx: 'a> { instrumentation_points: RefCell>>, - rvalue_dest: Option>, + rvalue_dest: Option>, } impl<'a, 'tcx: 'a> CollectFunctionInstrumentationPoints<'a, 'tcx> { @@ -263,7 +263,7 @@ fn to_mir_place(place: &Place) -> MirPlace { } // gets the one and only input Place, if applicable -fn rv_place<'tcx>(rv: &'tcx Rvalue) -> Option> { +fn rv_place<'tcx>(rv: &Rvalue<'tcx>) -> Option> { match rv { Rvalue::Use(op) => op.place(), Rvalue::Repeat(op, _) => op.place(), @@ -630,6 +630,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for CollectFunctionInstrumentationPoints<'a, 't func, args, destination, + target, .. } => { let mut arg_local = mir_loc::Local { index: 1 }; @@ -674,7 +675,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for CollectFunctionInstrumentationPoints<'a, 't } } if let &ty::FnDef(def_id, _) = func.ty(self.body, self.tcx).kind() { - if destination.is_some() { + if true { println!("term: {:?}", terminator.kind); let fn_name = self.tcx.item_name(def_id); // println!( @@ -709,31 +710,27 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for CollectFunctionInstrumentationPoints<'a, 't .map(|op| to_mir_place(&op.place().unwrap())) .next(), // FIXME: hooks have sources - destination: destination.map(|d| to_mir_place(&d.0)), + destination: Some(to_mir_place(destination)), transfer_kind: TransferKind::Ret(self.func_hash()), }, ); } else if destination - .unwrap() - .0 .ty(&self.body.local_decls, self.tcx) .ty .is_unsafe_ptr() { location.statement_index = 0; - location.block = destination.unwrap().1; + location.block = target.unwrap(); // Non-hooked fn with raw-ptr result called; trace destination self.add_instrumentation_point( location, arg_fn, - vec![InstrumentationOperand::RawPtr(Operand::Copy( - destination.unwrap().0, - ))], + vec![InstrumentationOperand::RawPtr(Operand::Copy(*destination))], false, false, EventMetadata { source: Some(to_mir_place(&Local::from_u32(0).into())), - destination: destination.map(|d| to_mir_place(&d.0)), + destination: Some(to_mir_place(destination)), transfer_kind: TransferKind::Ret( self.tcx.def_path_hash(def_id).convert(), ), @@ -776,7 +773,11 @@ fn make_const(tcx: TyCtxt, idx: u32) -> Operand { Operand::Constant(Box::new(Constant { span: DUMMY_SP, user_ty: None, - literal: ty::Const::from_bits(tcx, idx.into(), ParamEnv::empty().and(tcx.types.u32)).into(), + literal: ConstantKind::Ty(ty::Const::from_bits( + tcx, + idx.into(), + ParamEnv::empty().and(tcx.types.u32), + )), })) } @@ -894,12 +895,13 @@ fn apply_instrumentation<'tcx>( InstrumentationOperand::AddressUsize(make_const(tcx, loc_idx)), ); - let (blocks, locals) = body.basic_blocks_and_local_decls_mut(); + let (blocks, locals) = (body.basic_blocks.as_mut(), &mut body.local_decls); let mut extra_statements = None; if after_call { let call = blocks[loc.block].terminator_mut(); let ret_value = if let TerminatorKind::Call { - destination: Some((place, _next_block)), + destination: place, + //target: Some(_next_block), args, .. } = &mut call.kind @@ -943,12 +945,11 @@ fn apply_instrumentation<'tcx>( let orig_call = blocks[successor_block].terminator_mut(); if let ( TerminatorKind::Call { - destination: Some((_, instrument_dest)), + target: instrument_dest, .. }, TerminatorKind::Call { - destination: Some((_, orig_dest)), - .. + target: orig_dest, .. }, ) = (&mut instrument_call.kind, &mut orig_call.kind) { @@ -986,7 +987,7 @@ fn insert_call<'tcx>( mut args: Vec>, ) -> (BasicBlock, Local) { println!("ST: {:?}", statement_index); - let (blocks, locals) = body.basic_blocks_and_local_decls_mut(); + let (blocks, locals) = (body.basic_blocks.as_mut(), &mut body.local_decls); let successor_stmts = blocks[block].statements.split_off(statement_index); let successor_terminator = blocks[block].terminator.take(); @@ -1015,7 +1016,8 @@ fn insert_call<'tcx>( kind: TerminatorKind::Call { func, args: args.iter().map(|arg| arg.inner()).collect(), - destination: Some((ret_local.into(), successor_block)), + destination: ret_local.into(), + target: Some(successor_block), cleanup: None, from_hir_call: true, fn_span: DUMMY_SP, @@ -1066,7 +1068,7 @@ fn cast_ptr_to_usize<'tcx>( let mut projs = Vec::with_capacity(deref.projection.len() + 1); projs.extend(deref.projection); projs.push(ProjectionElem::Deref); - deref.projection = tcx.intern_place_elems(&*projs); + deref.projection = tcx.intern_place_elems(&projs); let cast_stmt = Statement { source_info: SourceInfo::outermost(DUMMY_SP), kind: StatementKind::Assign(Box::new(( diff --git a/rust-toolchain b/rust-toolchain index f24eb00eda..1fd15e6e3b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-02-14 +nightly-2022-07-11