From 4a7e3df5bd7bcd1406fccb5af2675a7aef5da8b3 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 21:25:00 -0700 Subject: [PATCH 01/18] Upgraded to the newest nightly (1.65, 2022-08-08) with `miri`. --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 72a896fdd2..7b98babb0e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-02-14" +channel = "nightly-2022-08-08" components = ["rustfmt-preview", "rustc-dev", "rust-src"] From 0a7a2d451014048dcafc65b49a0b4c2814ae5fe3 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 21:32:32 -0700 Subject: [PATCH 02/18] Fixed errors so `c2rust-instrument` compiles again. I kept all behavior identical, though it's possible a few patterns could be relaxed. --- dynamic_instrumentation/src/instrument.rs | 27 +++++++++++--------- dynamic_instrumentation/src/into_operand.rs | 8 ++++-- dynamic_instrumentation/src/mir_utils/mod.rs | 2 +- dynamic_instrumentation/src/point/apply.rs | 11 +++++--- dynamic_instrumentation/src/point/build.rs | 4 ++- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/dynamic_instrumentation/src/instrument.rs b/dynamic_instrumentation/src/instrument.rs index b05e804659..ec85317eec 100644 --- a/dynamic_instrumentation/src/instrument.rs +++ b/dynamic_instrumentation/src/instrument.rs @@ -10,7 +10,7 @@ use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, BorrowKind, HasLocalDecls, Local, LocalDecl, Location, Operand, Place, PlaceElem, Rvalue, SourceInfo, Terminator, TerminatorKind, START_BLOCK, }; -use rustc_middle::ty::{self, TyCtxt, TyS}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::def_id::{DefId, DefPathHash}; use rustc_span::DUMMY_SP; use std::collections::HashMap; @@ -109,11 +109,11 @@ impl Instrumenter { } } -fn is_shared_or_unsafe_ptr(ty: &TyS) -> bool { +fn is_shared_or_unsafe_ptr(ty: Ty) -> bool { ty.is_unsafe_ptr() || (ty.is_region_ptr() && !ty.is_mutable_ptr()) } -fn is_region_or_unsafe_ptr(ty: &TyS) -> bool { +fn is_region_or_unsafe_ptr(ty: Ty) -> bool { ty.is_unsafe_ptr() || ty.is_region_ptr() } @@ -336,6 +336,7 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> { func, args, destination, + target, .. } => { let mut callee_arg: Place = Local::new(1).into(); @@ -370,8 +371,7 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> { callee_arg.local.increment_by(1); } } - if let (&ty::FnDef(def_id, _), &Some(destination)) = (func_kind, destination) { - let (dest_place, dest_block) = destination; + if let (&ty::FnDef(def_id, _), &Some(target)) = (func_kind, target) { println!("term: {:?}", terminator.kind); let fn_name = self.tcx().item_name(def_id); if HOOK_FUNCTIONS.contains(&fn_name.as_str()) { @@ -380,25 +380,25 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> { // Hooked function called; trace args self.loc(location, func_def_id) .source(args) - .dest(&dest_place) + .dest(destination) .after_call() .transfer(TransferKind::Ret(self.func_hash())) .arg_vars(args.iter().cloned()) .debug_mir(location) .add_to(self); - } else if is_region_or_unsafe_ptr(dest_place.ty(self, self.tcx()).ty) { + } else if is_region_or_unsafe_ptr(destination.ty(self, self.tcx()).ty) { let instrumentation_location = Location { statement_index: 0, - block: dest_block, + block: target, }; self.loc(instrumentation_location, arg_fn) .source(&0) - .dest(&dest_place) + .dest(destination) .transfer(TransferKind::Ret( self.tcx().def_path_hash(def_id).convert(), )) - .arg_var(dest_place) + .arg_var(*destination) .debug_mir(location) .add_to(self); } @@ -481,7 +481,9 @@ pub 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 = body.basic_blocks.as_mut(); + let locals = &mut body.local_decls; let successor_stmts = blocks[block].statements.split_off(statement_index); let successor_terminator = blocks[block].terminator.take(); @@ -510,7 +512,8 @@ pub fn insert_call<'tcx>( kind: TerminatorKind::Call { func, args: args.iter().map(|arg| arg.inner().clone()).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, diff --git a/dynamic_instrumentation/src/into_operand.rs b/dynamic_instrumentation/src/into_operand.rs index f59ec3ef0b..fcf0c4ed58 100644 --- a/dynamic_instrumentation/src/into_operand.rs +++ b/dynamic_instrumentation/src/into_operand.rs @@ -1,5 +1,5 @@ use rustc_middle::{ - mir::{Constant, Local, Operand, Place}, + mir::{Constant, ConstantKind, Local, Operand, Place}, ty::{self, ParamEnv, TyCtxt}, }; use rustc_span::DUMMY_SP; @@ -37,6 +37,10 @@ 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), + )), })) } diff --git a/dynamic_instrumentation/src/mir_utils/mod.rs b/dynamic_instrumentation/src/mir_utils/mod.rs index bf501bbf46..e16176ce7d 100644 --- a/dynamic_instrumentation/src/mir_utils/mod.rs +++ b/dynamic_instrumentation/src/mir_utils/mod.rs @@ -5,7 +5,7 @@ mod deref; pub use deref::*; /// Get the one and only input [`Place`], if applicable. -pub fn rv_place<'tcx>(rv: &'tcx Rvalue) -> Option> { +pub fn rv_place<'tcx>(rv: &Rvalue<'tcx>) -> Option> { use Rvalue::*; match rv { Use(op) => op.place(), diff --git a/dynamic_instrumentation/src/point/apply.rs b/dynamic_instrumentation/src/point/apply.rs index 9dab740fe5..978aad9d09 100644 --- a/dynamic_instrumentation/src/point/apply.rs +++ b/dynamic_instrumentation/src/point/apply.rs @@ -68,7 +68,8 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { state.add_fn(callee_id, tcx); } - let (blocks, locals) = body.basic_blocks_and_local_decls_mut(); + let blocks = body.basic_blocks.as_mut(); + let locals = &mut body.local_decls; // Add the MIR location as the first argument to the instrumentation function let loc_idx = state.get_mir_loc_idx(body_def, loc, metadata.clone()); @@ -81,7 +82,9 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { if after_call { let call = blocks[loc.block].terminator_mut(); let ret_value = if let TerminatorKind::Call { - destination: Some((place, _next_block)), + destination: place, + // TODO(kkysen) I kept the `Some` pattern so the `match` is identical; do we need this? + target: Some(_next_block), args, .. } = &mut call.kind @@ -126,11 +129,11 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { let orig_call = blocks[successor_block].terminator_mut(); if let ( TerminatorKind::Call { - destination: Some((_, instrument_dest)), + target: Some(instrument_dest), .. }, TerminatorKind::Call { - destination: Some((_, orig_dest)), + target: Some(orig_dest), .. }, ) = (&mut instrument_call.kind, &mut orig_call.kind) diff --git a/dynamic_instrumentation/src/point/build.rs b/dynamic_instrumentation/src/point/build.rs index d77b570986..423fd07a1b 100644 --- a/dynamic_instrumentation/src/point/build.rs +++ b/dynamic_instrumentation/src/point/build.rs @@ -148,7 +148,9 @@ impl<'tcx> InstrumentationBuilder<'_, 'tcx> { match &block.terminator().kind { TerminatorKind::Call { args, - destination: Some((destination, _)), + destination, + // TODO(kkysen) I kept the `Some` pattern so the `match` is identical; do we need this? + target: Some(_), func, .. } => { From e8b553d997855a1680053b08a70968f9ba027654 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 21:34:29 -0700 Subject: [PATCH 03/18] `cargo clippy --fix` for `c2rust-instrument`. --- dynamic_instrumentation/src/point/apply.rs | 2 +- dynamic_instrumentation/src/point/cast.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamic_instrumentation/src/point/apply.rs b/dynamic_instrumentation/src/point/apply.rs index 978aad9d09..2475efd458 100644 --- a/dynamic_instrumentation/src/point/apply.rs +++ b/dynamic_instrumentation/src/point/apply.rs @@ -119,7 +119,7 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { } let (successor_block, _) = - insert_call(tcx, *body, loc.block, loc.statement_index, func, args); + insert_call(tcx, body, loc.block, loc.statement_index, func, args); let blocks = body.basic_blocks_mut(); if after_call { diff --git a/dynamic_instrumentation/src/point/cast.rs b/dynamic_instrumentation/src/point/cast.rs index 5bf89c5b86..4b5db5fa4c 100644 --- a/dynamic_instrumentation/src/point/cast.rs +++ b/dynamic_instrumentation/src/point/cast.rs @@ -52,7 +52,7 @@ pub 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(( From 0344af0b227927ee3746e924b93f22a33fee65a0 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 22:03:10 -0700 Subject: [PATCH 04/18] Fixed other new `clippy` errors after update to 1.65 (all quite simple fixes). --- c2rust-ast-builder/src/builder.rs | 21 +++++++++---------- c2rust-transpile/src/c_ast/conversion.rs | 13 +++++------- c2rust-transpile/src/c_ast/mod.rs | 10 ++++----- c2rust-transpile/src/c_ast/print.rs | 9 +++----- .../src/rust_ast/comment_store.rs | 2 +- c2rust-transpile/src/translator/assembly.rs | 12 +++++------ c2rust-transpile/src/translator/comments.rs | 2 +- c2rust-transpile/src/translator/literals.rs | 8 ++++--- c2rust-transpile/src/translator/mod.rs | 2 +- pdg/src/builder.rs | 2 +- 10 files changed, 38 insertions(+), 43 deletions(-) diff --git a/c2rust-ast-builder/src/builder.rs b/c2rust-ast-builder/src/builder.rs index ff1b074d36..252339c988 100644 --- a/c2rust-ast-builder/src/builder.rs +++ b/c2rust-ast-builder/src/builder.rs @@ -174,13 +174,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) } } @@ -205,7 +205,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), }), @@ -226,8 +226,7 @@ impl<'a> Make for &'a str { path: Box::new(mk().path("super")), }), _ => panic!("unrecognized string for Visibility: {:?}", self), - }; - kind + } } } @@ -247,7 +246,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()) } @@ -375,13 +374,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)) } } @@ -824,7 +823,7 @@ impl Builder { pub fn binary_expr(self, op: BinOp, mut lhs: Box, rhs: Box) -> Box { 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), _ => {} } @@ -2263,13 +2262,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 e995d4efc0..e1e49ae1d5 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 5cd64045fa..5827fd5bd7 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, }; @@ -918,7 +918,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 0dbdd674b8..8a7b59dc2d 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 f9a33a3886..a969cab356 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 f71cc12b45..a9e86c042a 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/pdg/src/builder.rs b/pdg/src/builder.rs index fa63a2e015..651ffa89c1 100644 --- a/pdg/src/builder.rs +++ b/pdg/src/builder.rs @@ -63,7 +63,7 @@ impl EventKindExt for EventKind { } fn parent(&self, obj: (GraphId, NodeId)) -> Option<(GraphId, NodeId)> { - self.has_parent().then(|| obj) + self.has_parent().then_some(obj) } fn to_node_kind(&self) -> Option { From c277c6272394fefd24a6c75f24368bd17f631862 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 22:27:56 -0700 Subject: [PATCH 05/18] Fixed most of the errors (rest I'm unsure about) in `c2rust-analyze`. I kept all behavior identical, though it's possible a few `.unwrap()`s could be elided. --- c2rust-analyze/src/borrowck/def_use.rs | 8 ++++---- c2rust-analyze/src/borrowck/mod.rs | 2 +- c2rust-analyze/src/borrowck/type_check.rs | 8 +++++--- c2rust-analyze/src/dataflow/type_check.rs | 8 +++++--- c2rust-analyze/src/expr_rewrite.rs | 6 ++++-- c2rust-analyze/src/labeled_ty.rs | 12 ++++++------ c2rust-analyze/src/main.rs | 1 + c2rust-analyze/src/util.rs | 2 +- dynamic_instrumentation/src/point/apply.rs | 2 +- dynamic_instrumentation/src/point/build.rs | 4 ++-- 10 files changed, 30 insertions(+), 23 deletions(-) diff --git a/c2rust-analyze/src/borrowck/def_use.rs b/c2rust-analyze/src/borrowck/def_use.rs index ca0fd4bfd2..8f53fc826c 100644 --- a/c2rust-analyze/src/borrowck/def_use.rs +++ b/c2rust-analyze/src/borrowck/def_use.rs @@ -127,7 +127,7 @@ impl<'tcx> Visitor<'tcx> for DefUseVisitor<'tcx, '_> { } } - fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { eprintln!( "visit local {:?} with context {:?} = {:?} at {:?}", local, @@ -135,7 +135,7 @@ impl<'tcx> Visitor<'tcx> for DefUseVisitor<'tcx, '_> { categorize(context), location ); - let var = self.maps.variable(*local); + let var = self.maps.variable(local); let point = self.maps.point_mid_location(location); match categorize(context) { Some(DefUse::Def) => { @@ -255,7 +255,7 @@ impl<'tcx> Visitor<'tcx> for LoanInvalidatedAtVisitor<'tcx, '_> { } } - fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { eprintln!( "loan_invalidated_at: visit local {:?} with context {:?} = {:?} at {:?}", local, @@ -264,7 +264,7 @@ impl<'tcx> Visitor<'tcx> for LoanInvalidatedAtVisitor<'tcx, '_> { location ); - let local_loans = self.loans.get(local).map_or(&[] as &[_], |x| x); + let local_loans = self.loans.get(&local).map_or(&[] as &[_], |x| x); for &(_path, loan, borrow_kind) in local_loans { // All paths rooted in this local overlap the local. self.access_loan_at_location(loan, borrow_kind, context, location); diff --git a/c2rust-analyze/src/borrowck/mod.rs b/c2rust-analyze/src/borrowck/mod.rs index 9bc50feaf3..50b6d367fc 100644 --- a/c2rust-analyze/src/borrowck/mod.rs +++ b/c2rust-analyze/src/borrowck/mod.rs @@ -138,7 +138,7 @@ fn run_polonius<'tcx>( let term_start = maps.point(bb, term_idx, SubPoint::Start); let term_mid = maps.point(bb, term_idx, SubPoint::Mid); facts.cfg_edge.push((term_start, term_mid)); - for &succ in bb_data.terminator().successors() { + for succ in bb_data.terminator().successors() { let succ_start = maps.point(succ, 0, SubPoint::Start); facts.cfg_edge.push((term_mid, succ_start)); } diff --git a/c2rust-analyze/src/borrowck/type_check.rs b/c2rust-analyze/src/borrowck/type_check.rs index 4f20b94c62..224132bbc2 100644 --- a/c2rust-analyze/src/borrowck/type_check.rs +++ b/c2rust-analyze/src/borrowck/type_check.rs @@ -210,6 +210,7 @@ impl<'tcx> TypeChecker<'tcx, '_> { ref func, ref args, destination, + target, .. } => { let func_ty = func.ty(self.local_decls, *self.ltcx); @@ -218,9 +219,10 @@ impl<'tcx> TypeChecker<'tcx, '_> { Some(Callee::PtrOffset { .. }) => { // We handle this like a pointer assignment. - // `destination` must be `Some` because the function doesn't diverge. - let destination = destination.unwrap(); - let pl_lty = self.visit_place(destination.0); + // `target` must be `Some` because the function doesn't diverge. + // TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this? + target.unwrap(); + let pl_lty = self.visit_place(destination); assert!(args.len() == 2); let rv_lty = self.visit_operand(&args[0]); self.do_assign(pl_lty, rv_lty); diff --git a/c2rust-analyze/src/dataflow/type_check.rs b/c2rust-analyze/src/dataflow/type_check.rs index ae8d833d4e..13a42ed18b 100644 --- a/c2rust-analyze/src/dataflow/type_check.rs +++ b/c2rust-analyze/src/dataflow/type_check.rs @@ -196,6 +196,7 @@ impl<'tcx> TypeChecker<'tcx, '_> { ref func, ref args, destination, + target, .. } => { let func_ty = func.ty(self.mir, tcx); @@ -204,10 +205,11 @@ impl<'tcx> TypeChecker<'tcx, '_> { Some(Callee::PtrOffset { .. }) => { // We handle this like a pointer assignment. - // `destination` must be `Some` because the function doesn't diverge. - let destination = destination.unwrap(); + // `target` must be `Some` because the function doesn't diverge. + // TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this? + target.unwrap(); let ctx = PlaceContext::MutatingUse(MutatingUseContext::Store); - let pl_lty = self.visit_place(destination.0, ctx); + let pl_lty = self.visit_place(destination, ctx); assert!(args.len() == 2); let rv_lty = self.visit_operand(&args[0]); self.do_assign(pl_lty.label, rv_lty.label); diff --git a/c2rust-analyze/src/expr_rewrite.rs b/c2rust-analyze/src/expr_rewrite.rs index e28193e623..99d55d5484 100644 --- a/c2rust-analyze/src/expr_rewrite.rs +++ b/c2rust-analyze/src/expr_rewrite.rs @@ -163,14 +163,16 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> { ref func, ref args, destination, + target, .. } => { let func_ty = func.ty(self.mir, tcx); - let pl_ty = destination.map(|(pl, _)| self.acx.type_of(pl)); + let pl_ty = self.acx.type_of(destination); if let Some(callee) = util::ty_callee(tcx, func_ty) { // Special cases for particular functions. - let pl_ty = pl_ty.unwrap(); + // TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this? + target.unwrap(); match callee { Callee::PtrOffset { .. } => { self.visit_ptr_offset(&args[0], pl_ty); diff --git a/c2rust-analyze/src/labeled_ty.rs b/c2rust-analyze/src/labeled_ty.rs index 028f33ab38..1636783414 100644 --- a/c2rust-analyze/src/labeled_ty.rs +++ b/c2rust-analyze/src/labeled_ty.rs @@ -153,7 +153,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { /// Label a `Ty` using a callback. The callback runs at every type constructor to produce a /// label for that node in the tree. pub fn label) -> L>(&self, ty: Ty<'tcx>, f: &mut F) -> LabeledTy<'tcx, L> { - use rustc_middle::ty::TyKind::*; + use rustc_type_ir::TyKind::*; let label = f(ty); match ty.kind() { // Types with no arguments @@ -166,11 +166,11 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { let args = substs.types().map(|t| self.label(t, f)).collect::>(); self.mk(ty, self.mk_slice(&args), label) } - Array(elem, _) => { + &Array(elem, _) => { let args = [self.label(elem, f)]; self.mk(ty, self.mk_slice(&args), label) } - Slice(elem) => { + &Slice(elem) => { let args = [self.label(elem, f)]; self.mk(ty, self.mk_slice(&args), label) } @@ -178,7 +178,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { let args = [self.label(mty.ty, f)]; self.mk(ty, self.mk_slice(&args), label) } - Ref(_, mty, _) => { + &Ref(_, mty, _) => { let args = [self.label(mty, f)]; self.mk(ty, self.mk_slice(&args), label) } @@ -220,7 +220,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { where F: FnMut(Ty<'tcx>) -> L, { - self.mk_slice(&tys.iter().map(|ty| self.label(ty, f)).collect::>()) + self.mk_slice(&tys.iter().map(|&ty| self.label(ty, f)).collect::>()) } /// Substitute in arguments for any type parameter references (`Param`) in a labeled type. @@ -291,7 +291,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { where F: FnMut(Ty<'tcx>, &[Ty<'tcx>], L) -> Ty<'tcx>, { - use rustc_middle::ty::TyKind::*; + use rustc_type_ir::TyKind::*; let args = lty .args .iter() diff --git a/c2rust-analyze/src/main.rs b/c2rust-analyze/src/main.rs index 122b03cdd4..1fcb3957e3 100644 --- a/c2rust-analyze/src/main.rs +++ b/c2rust-analyze/src/main.rs @@ -12,6 +12,7 @@ extern crate rustc_mir_build; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; +extern crate rustc_type_ir; use crate::context::{ AnalysisCtxt, FlagSet, GlobalAnalysisCtxt, GlobalAssignment, LTy, LocalAssignment, diff --git a/c2rust-analyze/src/util.rs b/c2rust-analyze/src/util.rs index 50acf7cc74..61bfeaa15d 100644 --- a/c2rust-analyze/src/util.rs +++ b/c2rust-analyze/src/util.rs @@ -82,7 +82,7 @@ pub fn ty_callee<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> match name.as_str() { "offset" => { // The `offset` inherent method of `*const T` and `*mut T`. - let parent_did = tcx.parent(did)?; + let parent_did = tcx.parent(did); if tcx.def_kind(parent_did) != DefKind::Impl { return None; } diff --git a/dynamic_instrumentation/src/point/apply.rs b/dynamic_instrumentation/src/point/apply.rs index 2475efd458..001a3168cf 100644 --- a/dynamic_instrumentation/src/point/apply.rs +++ b/dynamic_instrumentation/src/point/apply.rs @@ -83,7 +83,7 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { let call = blocks[loc.block].terminator_mut(); let ret_value = if let TerminatorKind::Call { destination: place, - // TODO(kkysen) I kept the `Some` pattern so the `match` is identical; do we need this? + // TODO(kkysen) I kept the `Some` pattern so that the `match` is identical. Do we need this? target: Some(_next_block), args, .. diff --git a/dynamic_instrumentation/src/point/build.rs b/dynamic_instrumentation/src/point/build.rs index 423fd07a1b..ed01af709f 100644 --- a/dynamic_instrumentation/src/point/build.rs +++ b/dynamic_instrumentation/src/point/build.rs @@ -149,8 +149,8 @@ impl<'tcx> InstrumentationBuilder<'_, 'tcx> { TerminatorKind::Call { args, destination, - // TODO(kkysen) I kept the `Some` pattern so the `match` is identical; do we need this? - target: Some(_), + // TODO(kkysen) I kept the `Some` pattern so that the `match` is identical. Do we need this? + target: Some(_), func, .. } => { From 49d2b615cc87e3a4bdeae25f9310d0cffb375c77 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 23:03:35 -0700 Subject: [PATCH 06/18] Figured out to fix another error by looking at the type difference vs. the old `rustc` code. --- c2rust-analyze/src/labeled_ty.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/c2rust-analyze/src/labeled_ty.rs b/c2rust-analyze/src/labeled_ty.rs index 1636783414..73aa60d46f 100644 --- a/c2rust-analyze/src/labeled_ty.rs +++ b/c2rust-analyze/src/labeled_ty.rs @@ -199,10 +199,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> { self.mk(ty, self.mk_slice(&args), label) } Tuple(elems) => { - let args = elems - .types() - .map(|ty| self.label(ty, f)) - .collect::>(); + let args = elems.iter().map(|ty| self.label(ty, f)).collect::>(); self.mk(ty, self.mk_slice(&args), label) } From df32e6c407db04eb592f83613d800caa075d4b8c Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Wed, 10 Aug 2022 11:58:51 -0700 Subject: [PATCH 07/18] analyze: misc fixes for rustc update --- c2rust-analyze/src/borrowck/def_use.rs | 4 ++++ c2rust-analyze/src/context.rs | 1 + c2rust-analyze/src/expr_rewrite.rs | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/c2rust-analyze/src/borrowck/def_use.rs b/c2rust-analyze/src/borrowck/def_use.rs index 8f53fc826c..e92ecceeff 100644 --- a/c2rust-analyze/src/borrowck/def_use.rs +++ b/c2rust-analyze/src/borrowck/def_use.rs @@ -81,6 +81,10 @@ pub fn categorize(context: PlaceContext) -> Option { // Debug info is neither def nor use. PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None, + + PlaceContext::MutatingUse(MutatingUseContext::Deinit | MutatingUseContext::SetDiscriminant) => { + panic!("These statements are not allowed in this MIR phase") + } } } diff --git a/c2rust-analyze/src/context.rs b/c2rust-analyze/src/context.rs index 3a15f5e36e..b78a24fd69 100644 --- a/c2rust-analyze/src/context.rs +++ b/c2rust-analyze/src/context.rs @@ -342,6 +342,7 @@ impl<'tcx> TypeOf<'tcx> for Rvalue<'tcx> { match *self { Rvalue::Use(ref op) => acx.type_of(op), + Rvalue::CopyForDeref(pl) => acx.type_of(pl), Rvalue::Repeat(ref op, _) => { let op_lty = acx.type_of(op); let ty = self.ty(acx, acx.tcx()); diff --git a/c2rust-analyze/src/expr_rewrite.rs b/c2rust-analyze/src/expr_rewrite.rs index 99d55d5484..d6f065e05a 100644 --- a/c2rust-analyze/src/expr_rewrite.rs +++ b/c2rust-analyze/src/expr_rewrite.rs @@ -3,7 +3,7 @@ use crate::pointer_id::PointerTable; use crate::type_desc::{self, Ownership, Quantity}; use crate::util::{self, Callee}; use rustc_middle::mir::{ - BasicBlock, Body, Location, Operand, Rvalue, Statement, StatementKind, Terminator, + BasicBlock, Body, Location, Operand, Place, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_span::{Span, DUMMY_SP}; @@ -132,6 +132,7 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> { } StatementKind::FakeRead(..) => {} StatementKind::SetDiscriminant { .. } => todo!("statement {:?}", stmt), + StatementKind::Deinit(..) => {} StatementKind::StorageLive(..) => {} StatementKind::StorageDead(..) => {} StatementKind::Retag(..) => {} @@ -251,23 +252,29 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> { Rvalue::ShallowInitBox(ref _op, _ty) => { // TODO } + Rvalue::CopyForDeref(pl) => { + self.enter_rvalue_operand(0, |v| v.visit_place(pl, expect_ty)); + } } } fn visit_operand(&mut self, op: &Operand<'tcx>, expect_ty: LTy<'tcx>) { match *op { Operand::Copy(pl) | Operand::Move(pl) => { - if let Some(ptr) = self.acx.ptr_of(pl) { - let expect_ptr = expect_ty.label; - self.emit_ptr_cast(ptr, expect_ptr); - } - - // TODO: walk over `pl` to handle all derefs (casts, `*x` -> `(*x).get()`) + self.visit_place(pl, expect_ty); } Operand::Constant(..) => {} } } + fn visit_place(&mut self, pl: Place<'tcx>, expect_ty: LTy<'tcx>) { + if let Some(ptr) = self.acx.ptr_of(pl) { + let expect_ptr = expect_ty.label; + self.emit_ptr_cast(ptr, expect_ptr); + } + // TODO: walk over `pl` to handle all derefs (casts, `*x` -> `(*x).get()`) + } + fn visit_operand_desc( &mut self, op: &Operand<'tcx>, From cbe60c073198656de1cd9fb126345b3ff0cc6a2d Mon Sep 17 00:00:00 2001 From: fw Date: Thu, 11 Aug 2022 15:01:47 -0400 Subject: [PATCH 08/18] update atomic intrinsic usage for newer rustc --- c2rust-transpile/src/translator/atomics.rs | 101 ++++++-------------- c2rust-transpile/src/translator/builtins.rs | 15 +-- 2 files changed, 39 insertions(+), 77 deletions(-) diff --git a/c2rust-transpile/src/translator/atomics.rs b/c2rust-transpile/src/translator/atomics.rs index 2327aab0e9..531bdc7a52 100644 --- a/c2rust-transpile/src/translator/atomics.rs +++ b/c2rust-transpile/src/translator/atomics.rs @@ -75,28 +75,25 @@ impl<'c> Translation<'c> { }) } + fn order_name(order: Ordering) -> &'static str { + use Ordering::*; + match order { + SeqCst => "seqcst", + AcqRel => "acqrel", + Acquire => "acquire", + Release => "release", + Relaxed => "relaxed", + _ => unreachable!("Did we not handle a case above??"), + } + } + match name { "__atomic_load" | "__atomic_load_n" => ptr.and_then(|ptr| { - use Ordering::*; - let intrinsic_name = match static_order(order) { - SeqCst => Some("atomic_load"), - AcqRel => None, - Acquire => Some("atomic_load_acq"), - Release => None, - Relaxed => Some("atomic_load_relaxed"), - _ => unreachable!("Did we not handle a case above??"), - } - .ok_or_else(|| { - format_translation_err!( - self.ast_context - .display_loc(&self.ast_context[order_id].loc), - "Invalid memory ordering for __atomic_load", - ) - })?; + let intrinsic_name = "atomic_load_".to_owned() + order_name(static_order(order)); self.use_feature("core_intrinsics"); - let atomic_load = mk().abs_path_expr(vec!["core", "intrinsics", intrinsic_name]); + let atomic_load = mk().abs_path_expr(vec!["core", "intrinsics", &intrinsic_name]); let call = mk().call_expr(atomic_load, vec![ptr]); if name == "__atomic_load" { let ret = val1.expect("__atomic_load should have a ret argument"); @@ -124,27 +121,13 @@ impl<'c> Translation<'c> { let val = val1.expect("__atomic_store must have a val argument"); ptr.and_then(|ptr| { val.and_then(|val| { - use Ordering::*; - let intrinsic_name = match static_order(order) { - SeqCst => Some("atomic_store"), - AcqRel => None, - Acquire => None, - Release => Some("atomic_store_rel"), - Relaxed => Some("atomic_store_relaxed"), - _ => unreachable!("Did we not handle a case above??"), - } - .ok_or_else(|| { - format_translation_err!( - self.ast_context - .display_loc(&self.ast_context[order_id].loc), - "Invalid memory ordering for __atomic_store", - ) - })?; + let intrinsic_name = + "atomic_store_".to_owned() + order_name(static_order(order)); self.use_feature("core_intrinsics"); let atomic_store = - mk().abs_path_expr(vec!["core", "intrinsics", intrinsic_name]); + mk().abs_path_expr(vec!["core", "intrinsics", &intrinsic_name]); let val = if name == "__atomic_store" { mk().unary_expr(UnOp::Deref(Default::default()), val) } else { @@ -164,27 +147,13 @@ impl<'c> Translation<'c> { let val = val1.expect("__atomic_store must have a val argument"); ptr.and_then(|ptr| { val.and_then(|val| { - use Ordering::*; - let intrinsic_name = match static_order(order) { - SeqCst => Some("atomic_xchg"), - AcqRel => Some("atomic_xchg_acqrel"), - Acquire => Some("atomic_xchg_acq"), - Release => Some("atomic_xchg_rel"), - Relaxed => Some("atomic_xchg_relaxed"), - _ => unreachable!("Did we not handle a case above??"), - } - .ok_or_else(|| { - format_translation_err!( - self.ast_context - .display_loc(&self.ast_context[order_id].loc), - "Invalid memory ordering for __atomic_exchange", - ) - })?; + let intrinsic_name = + "atomic_xchg_".to_owned() + order_name(static_order(order)); self.use_feature("core_intrinsics"); let fn_path = - mk().abs_path_expr(vec!["core", "intrinsics", intrinsic_name]); + mk().abs_path_expr(vec!["core", "intrinsics", &intrinsic_name]); let val = if name == "__atomic_exchange" { mk().unary_expr(UnOp::Deref(Default::default()), val) } else { @@ -233,15 +202,15 @@ impl<'c> Translation<'c> { let intrinsic_name = (|| { Some(match (order, order_fail) { (_, Release | AcqRel) => return None, - (SeqCst, SeqCst) => "", - (SeqCst, Acquire) => "_failacq", - (SeqCst, Relaxed) => "_failrelaxed", - (AcqRel, Acquire) => "_acqrel", - (AcqRel, Relaxed) => "_acqrel_failrelaxed", - (Release, Relaxed) => "_rel", - (Acquire, Acquire) => "_acq", - (Acquire, Relaxed) => "_acq_failrelaxed", - (Relaxed, Relaxed) => "_relaxed", + (SeqCst, SeqCst) => "_seqcst_seqcst", + (SeqCst, Acquire) => "_seqcst_acquire", + (SeqCst, Relaxed) => "_seqcst_relaxed", + (AcqRel, Acquire) => "_acqrel_acquire", + (AcqRel, Relaxed) => "_acqrel_relaxed", + (Release, Relaxed) => "_release_relaxed", + (Acquire, Acquire) => "_acquire_acquire", + (Acquire, Relaxed) => "_acquire_relaxed", + (Relaxed, Relaxed) => "_relaxed_relaxed", (SeqCst | AcqRel | Release | Acquire | Relaxed, _) => { return None } @@ -320,16 +289,8 @@ impl<'c> Translation<'c> { "atomic_and" }; - use Ordering::*; - let intrinsic_suffix = match static_order(order) { - SeqCst => "", - AcqRel => "_acqrel", - Acquire => "_acq", - Release => "_rel", - Relaxed => "_relaxed", - _ => unreachable!("Unknown memory ordering"), - }; - let intrinsic_name = format!("{intrinsic_name}{intrinsic_suffix}"); + let intrinsic_suffix = order_name(static_order(order)); + let intrinsic_name = format!("{intrinsic_name}_{intrinsic_suffix}"); let fetch_first = name.starts_with("__atomic_fetch"); let val = val1.expect("__atomic arithmetic operations must have a val argument"); diff --git a/c2rust-transpile/src/translator/builtins.rs b/c2rust-transpile/src/translator/builtins.rs index 5262c5830f..938a2f64b5 100644 --- a/c2rust-transpile/src/translator/builtins.rs +++ b/c2rust-transpile/src/translator/builtins.rs @@ -493,18 +493,18 @@ impl<'c> Translation<'c> { | "__sync_nand_and_fetch_8" | "__sync_nand_and_fetch_16" => { let func_name = if builtin_name.contains("_add_") { - "atomic_xadd" + "atomic_xadd_seqcst" } else if builtin_name.contains("_sub_") { - "atomic_xsub" + "atomic_xsub_seqcst" } else if builtin_name.contains("_or_") { - "atomic_or" + "atomic_or_seqcst" } else if builtin_name.contains("_xor_") { - "atomic_xor" + "atomic_xor_seqcst" } else if builtin_name.contains("_nand_") { - "atomic_nand" + "atomic_nand_seqcst" } else { // We can't explicitly check for "_and_" since they all contain it - "atomic_and" + "atomic_and_seqcst" }; let arg0 = self.convert_expr(ctx.used(), args[0])?; @@ -520,7 +520,8 @@ impl<'c> Translation<'c> { "__sync_synchronize" => { self.use_feature("core_intrinsics"); - let atomic_func = mk().abs_path_expr(vec!["core", "intrinsics", "atomic_fence"]); + let atomic_func = + mk().abs_path_expr(vec!["core", "intrinsics", "atomic_fence_seqcst"]); let call_expr = mk().call_expr(atomic_func, vec![]); self.convert_side_effects_expr( ctx, From 239f0f2844b737f1a6dc15925d1ddb2660ea22ec Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Thu, 11 Aug 2022 15:40:17 -0700 Subject: [PATCH 09/18] Fixed a `clippy` warning that I think got undone in a merge. --- dynamic_instrumentation/src/point/apply.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_instrumentation/src/point/apply.rs b/dynamic_instrumentation/src/point/apply.rs index eb7046ff47..f434ea3385 100644 --- a/dynamic_instrumentation/src/point/apply.rs +++ b/dynamic_instrumentation/src/point/apply.rs @@ -121,7 +121,7 @@ impl<'tcx, 'a> InstrumentationApplier<'tcx, 'a> { let (successor_block, _) = insert_call( tcx, - *body, + body, instrumentation_location.block, instrumentation_location.statement_index, func, From a792e003336e7f2429e8894ed001539c263d04ff Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Thu, 11 Aug 2022 15:44:59 -0700 Subject: [PATCH 10/18] Improved error message if new `atomic::Ordering` gets new variants. --- c2rust-transpile/src/translator/atomics.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/c2rust-transpile/src/translator/atomics.rs b/c2rust-transpile/src/translator/atomics.rs index 531bdc7a52..29d78b6fe4 100644 --- a/c2rust-transpile/src/translator/atomics.rs +++ b/c2rust-transpile/src/translator/atomics.rs @@ -83,7 +83,10 @@ impl<'c> Translation<'c> { Acquire => "acquire", Release => "release", Relaxed => "relaxed", - _ => unreachable!("Did we not handle a case above??"), + _ => unreachable!( + "new variants added to `{}`", + std::any::type_name::() + ), } } From d990fb3727cf73328b3ff3bd367b2068a80590ae Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Thu, 11 Aug 2022 15:47:33 -0700 Subject: [PATCH 11/18] Prefer `format!` over `.to_owned() + `. --- c2rust-transpile/src/translator/atomics.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c2rust-transpile/src/translator/atomics.rs b/c2rust-transpile/src/translator/atomics.rs index 29d78b6fe4..c248c3671f 100644 --- a/c2rust-transpile/src/translator/atomics.rs +++ b/c2rust-transpile/src/translator/atomics.rs @@ -92,7 +92,7 @@ impl<'c> Translation<'c> { match name { "__atomic_load" | "__atomic_load_n" => ptr.and_then(|ptr| { - let intrinsic_name = "atomic_load_".to_owned() + order_name(static_order(order)); + let intrinsic_name = format!("atomic_load_{}", order_name(static_order(order))); self.use_feature("core_intrinsics"); @@ -125,7 +125,7 @@ impl<'c> Translation<'c> { ptr.and_then(|ptr| { val.and_then(|val| { let intrinsic_name = - "atomic_store_".to_owned() + order_name(static_order(order)); + format!("atomic_store_{}", order_name(static_order(order))); self.use_feature("core_intrinsics"); @@ -151,7 +151,7 @@ impl<'c> Translation<'c> { ptr.and_then(|ptr| { val.and_then(|val| { let intrinsic_name = - "atomic_xchg_".to_owned() + order_name(static_order(order)); + format!("atomic_xchg_{}", order_name(static_order(order))); self.use_feature("core_intrinsics"); From 2e092a642b6ceab8ec4ca8bba888acfae2063690 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Thu, 11 Aug 2022 16:14:01 -0700 Subject: [PATCH 12/18] Use `order_name` in `atomic_cxchg_*` code, too. --- c2rust-transpile/src/translator/atomics.rs | 41 +++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/c2rust-transpile/src/translator/atomics.rs b/c2rust-transpile/src/translator/atomics.rs index c248c3671f..40954a3cd6 100644 --- a/c2rust-transpile/src/translator/atomics.rs +++ b/c2rust-transpile/src/translator/atomics.rs @@ -202,27 +202,26 @@ impl<'c> Translation<'c> { let order = static_order(order); let order_fail = static_order(order_fail); use Ordering::*; - let intrinsic_name = (|| { - Some(match (order, order_fail) { - (_, Release | AcqRel) => return None, - (SeqCst, SeqCst) => "_seqcst_seqcst", - (SeqCst, Acquire) => "_seqcst_acquire", - (SeqCst, Relaxed) => "_seqcst_relaxed", - (AcqRel, Acquire) => "_acqrel_acquire", - (AcqRel, Relaxed) => "_acqrel_relaxed", - (Release, Relaxed) => "_release_relaxed", - (Acquire, Acquire) => "_acquire_acquire", - (Acquire, Relaxed) => "_acquire_relaxed", - (Relaxed, Relaxed) => "_relaxed_relaxed", - (SeqCst | AcqRel | Release | Acquire | Relaxed, _) => { - return None - } - - (_, _) => unreachable!("Did we not handle a case above??"), - }) - })() - .map(|suffix| { - format!("atomic_cxchg{}{}", if weak { "weak" } else { "" }, suffix) + let intrinsic_name = match (order, order_fail) { + (_, Release | AcqRel) => None, + (SeqCst, SeqCst) + | (SeqCst, Acquire) + | (SeqCst, Relaxed) + | (AcqRel, Acquire) + | (AcqRel, Relaxed) + | (Release, Relaxed) + | (Acquire, Acquire) + | (Acquire, Relaxed) + | (Relaxed, Relaxed) => Some((order, order_fail)), + (SeqCst | AcqRel | Release | Acquire | Relaxed, _) => None, + + (_, _) => unreachable!("Did we not handle a case above??"), + } + .map(|(order, order_fail)| { + let weak = if weak { "weak" } else { "" }; + let order = order_name(order); + let order_fail = order_name(order_fail); + format!("atomic_cxchg{weak}_{order}_{order_fail}") }) .ok_or_else(|| { format_translation_err!( From 5e5fb311929dde9e248b3df7a5c8e7b75517714c Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Thu, 11 Aug 2022 16:15:57 -0700 Subject: [PATCH 13/18] Merge some patterns in `atomic_cxchg_*` code. --- c2rust-transpile/src/translator/atomics.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/c2rust-transpile/src/translator/atomics.rs b/c2rust-transpile/src/translator/atomics.rs index 40954a3cd6..7e46cf695d 100644 --- a/c2rust-transpile/src/translator/atomics.rs +++ b/c2rust-transpile/src/translator/atomics.rs @@ -204,15 +204,12 @@ impl<'c> Translation<'c> { use Ordering::*; let intrinsic_name = match (order, order_fail) { (_, Release | AcqRel) => None, - (SeqCst, SeqCst) - | (SeqCst, Acquire) - | (SeqCst, Relaxed) - | (AcqRel, Acquire) - | (AcqRel, Relaxed) + (SeqCst, SeqCst | Acquire | Relaxed) + | (AcqRel, Acquire | Relaxed) | (Release, Relaxed) - | (Acquire, Acquire) - | (Acquire, Relaxed) - | (Relaxed, Relaxed) => Some((order, order_fail)), + | (Acquire | Relaxed, Acquire | Relaxed) => { + Some((order, order_fail)) + } (SeqCst | AcqRel | Release | Acquire | Relaxed, _) => None, (_, _) => unreachable!("Did we not handle a case above??"), From a7f2dce69aa22627709eef104231a7abc69d8d09 Mon Sep 17 00:00:00 2001 From: fw Date: Thu, 11 Aug 2022 22:36:12 -0400 Subject: [PATCH 14/18] update remaining references to old atomic intrinsics these were missed in the last round of changes --- c2rust-transpile/src/translator/builtins.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/c2rust-transpile/src/translator/builtins.rs b/c2rust-transpile/src/translator/builtins.rs index 938a2f64b5..244ccfc7dd 100644 --- a/c2rust-transpile/src/translator/builtins.rs +++ b/c2rust-transpile/src/translator/builtins.rs @@ -422,7 +422,7 @@ impl<'c> Translation<'c> { let returns_val = builtin_name.starts_with("__sync_val"); self.convert_atomic_cxchg( ctx, - "atomic_cxchg", + "atomic_cxchg_seqcst_seqcst", arg0, arg1, arg2, @@ -537,8 +537,9 @@ impl<'c> Translation<'c> { | "__sync_lock_test_and_set_16" => { self.use_feature("core_intrinsics"); - // Emit `atomic_xchg_acq(arg0, arg1)` - let atomic_func = mk().abs_path_expr(vec!["core", "intrinsics", "atomic_xchg_acq"]); + // Emit `atomic_xchg_acquire(arg0, arg1)` + let atomic_func = + mk().abs_path_expr(vec!["core", "intrinsics", "atomic_xchg_acquire"]); let arg0 = self.convert_expr(ctx.used(), args[0])?; let arg1 = self.convert_expr(ctx.used(), args[1])?; arg0.and_then(|arg0| { @@ -560,9 +561,9 @@ impl<'c> Translation<'c> { | "__sync_lock_release_16" => { self.use_feature("core_intrinsics"); - // Emit `atomic_store_rel(arg0, 0)` + // Emit `atomic_store_release(arg0, 0)` let atomic_func = - mk().abs_path_expr(vec!["core", "intrinsics", "atomic_store_rel"]); + mk().abs_path_expr(vec!["core", "intrinsics", "atomic_store_release"]); let arg0 = self.convert_expr(ctx.used(), args[0])?; arg0.and_then(|arg0| { let zero = mk().lit_expr(mk().int_lit(0, "")); From ae42f28c1308f754b9e9d0ea8945d4c1a2ca8655 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Fri, 12 Aug 2022 12:53:01 -0700 Subject: [PATCH 15/18] Fixed up some comments. --- dynamic_instrumentation/src/point/cast.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dynamic_instrumentation/src/point/cast.rs b/dynamic_instrumentation/src/point/cast.rs index 4b5db5fa4c..c5f4b7b95e 100644 --- a/dynamic_instrumentation/src/point/cast.rs +++ b/dynamic_instrumentation/src/point/cast.rs @@ -30,7 +30,7 @@ pub fn cast_ptr_to_usize<'tcx>( let arg_ty = arg.inner().ty(locals, tcx); let ptr = match arg { - // If we were given an address as a usize, no conversion is necessary + // If we were given an address as a `usize`, no conversion is necessary. InstrumentationArg::Op(ArgKind::AddressUsize(_arg)) => { assert!( arg_ty.is_integral() || arg_ty.is_unit(), @@ -40,7 +40,7 @@ pub fn cast_ptr_to_usize<'tcx>( ); return None; } - // From a reference `r`, cast through raw ptr to usize: `r as *mut _ as usize` + // From a reference `r`, cast through a raw ptr to a `usize`: `r as *mut _ as usize`. InstrumentationArg::Op(ArgKind::Reference(arg)) => { assert!(arg_ty.is_region_ptr()); let inner_ty = arg_ty.builtin_deref(false).unwrap(); @@ -63,7 +63,7 @@ pub fn cast_ptr_to_usize<'tcx>( new_stmts.push(cast_stmt); Operand::Move(raw_ptr_local.into()) } - // From a raw pointer `r`, cast: `r as usize` + // From a raw pointer `r`, cast: `r as usize`. InstrumentationArg::Op(ArgKind::RawPtr(arg)) => { assert!( arg_ty.is_unsafe_ptr(), @@ -73,8 +73,8 @@ pub fn cast_ptr_to_usize<'tcx>( ); arg.to_copy() } - // From a place to which a reference is also constructed, create a raw - // ptr with `addr_of!` + // From a place to which a reference is also constructed, + // create a raw ptr with `addr_of!`. InstrumentationArg::AddrOf(arg) => { let arg_place = arg.place().expect("Can't get the address of a constant"); let arg_place = remove_outer_deref(arg_place, tcx); @@ -100,8 +100,7 @@ pub fn cast_ptr_to_usize<'tcx>( } }; - // Cast the raw ptr to a usize before passing to the - // instrumentation function + // Cast the raw ptr to a `usize` before passing to the instrumentation function. let usize_ty = tcx.mk_mach_uint(ty::UintTy::Usize); let casted_local = locals.push(LocalDecl::new(usize_ty, DUMMY_SP)); let casted_arg = Operand::Move(casted_local.into()); From 776cddf2d627b52222dfb217a79dc0fe5f4c7656 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Fri, 12 Aug 2022 12:53:49 -0700 Subject: [PATCH 16/18] Switched to `CastKind::PointerExposeAddress` (for strict provenance), but now we get errors cast fat ptrs to `usize`. --- dynamic_instrumentation/src/point/cast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_instrumentation/src/point/cast.rs b/dynamic_instrumentation/src/point/cast.rs index c5f4b7b95e..bf093dcdcd 100644 --- a/dynamic_instrumentation/src/point/cast.rs +++ b/dynamic_instrumentation/src/point/cast.rs @@ -108,7 +108,7 @@ pub fn cast_ptr_to_usize<'tcx>( source_info: SourceInfo::outermost(DUMMY_SP), kind: StatementKind::Assign(Box::new(( casted_local.into(), - Rvalue::Cast(CastKind::Misc, ptr, usize_ty), + Rvalue::Cast(CastKind::PointerExposeAddress, ptr, usize_ty), ))), }; new_stmts.push(cast_stmt); From 906968bffba98ecf95487bec9c6e64d374b176d0 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Fri, 12 Aug 2022 14:41:02 -0700 Subject: [PATCH 17/18] Fixed fat ptr to `usize` cast error by first casting all ptrs to `*const [(); 0]`, an opaque ptr. --- dynamic_instrumentation/src/point/cast.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dynamic_instrumentation/src/point/cast.rs b/dynamic_instrumentation/src/point/cast.rs index bf093dcdcd..e15f12336d 100644 --- a/dynamic_instrumentation/src/point/cast.rs +++ b/dynamic_instrumentation/src/point/cast.rs @@ -4,7 +4,7 @@ use rustc_middle::{ CastKind, Local, LocalDecl, Mutability, Operand, ProjectionElem, Rvalue, SourceInfo, Statement, StatementKind, }, - ty::{self, TyCtxt}, + ty::{self, TyCtxt, TypeAndMut}, }; use rustc_span::DUMMY_SP; @@ -44,7 +44,6 @@ pub fn cast_ptr_to_usize<'tcx>( InstrumentationArg::Op(ArgKind::Reference(arg)) => { assert!(arg_ty.is_region_ptr()); let inner_ty = arg_ty.builtin_deref(false).unwrap(); - let raw_ptr_ty = tcx.mk_ptr(inner_ty); let raw_ptr_local = locals.push(LocalDecl::new(raw_ptr_ty, DUMMY_SP)); @@ -100,6 +99,25 @@ pub fn cast_ptr_to_usize<'tcx>( } }; + let ptr = { + // Use `*const [(); 0]` as the opaque pointer type. + let thin_raw_ptr_ty = tcx.mk_ptr(TypeAndMut { + ty: tcx.mk_array(tcx.mk_unit(), 0), + mutbl: Mutability::Not, + }); + let casted_local = locals.push(LocalDecl::new(thin_raw_ptr_ty, DUMMY_SP)); + let casted_arg = Operand::Move(casted_local.into()); + let cast_stmt = Statement { + source_info: SourceInfo::outermost(DUMMY_SP), + kind: StatementKind::Assign(Box::new(( + casted_local.into(), + Rvalue::Cast(CastKind::Misc, ptr, thin_raw_ptr_ty), + ))), + }; + new_stmts.push(cast_stmt); + casted_arg + }; + // Cast the raw ptr to a `usize` before passing to the instrumentation function. let usize_ty = tcx.mk_mach_uint(ty::UintTy::Usize); let casted_local = locals.push(LocalDecl::new(usize_ty, DUMMY_SP)); From ca5cc3345ba32796d0a4d3ffb642633ae78aada8 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 15 Aug 2022 11:32:37 -0700 Subject: [PATCH 18/18] Updated the snapshot (just `Misc` => `PointerExposeAddress`). --- ...dg__tests__analysis_test_pdg_snapshot.snap | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pdg/src/snapshots/c2rust_pdg__tests__analysis_test_pdg_snapshot.snap b/pdg/src/snapshots/c2rust_pdg__tests__analysis_test_pdg_snapshot.snap index 7765e0ab03..08b5091d63 100644 --- a/pdg/src/snapshots/c2rust_pdg__tests__analysis_test_pdg_snapshot.snap +++ b/pdg/src/snapshots/c2rust_pdg__tests__analysis_test_pdg_snapshot.snap @@ -63,10 +63,10 @@ nodes_that_need_write = [] g { n[0]: copy _ => _38 @ bb27[6]: fn main; _38 = null_mut(); n[1]: copy n[0] => _2 @ bb0[0]: fn push; _36 = push(move _37, move _38); - n[2]: value.store _ => _20.* @ bb4[7]: fn invalid; (*_20) = const 0_usize as *mut pointers::S (Misc); - n[3]: value.store _ => _17.* @ bb8[4]: fn fdevent_unregister; (*_17) = const 0_usize as *mut pointers::fdnode_st (Misc); - n[4]: int_to_ptr _ => _2 @ bb0[2]: fn test_ref_field; _2 = const 0_usize as *const pointers::S (Misc); - n[5]: int_to_ptr _ => _5 @ bb0[8]: fn test_ref_field; _5 = const 0_usize as *const pointers::S (Misc); + n[2]: value.store _ => _20.* @ bb4[7]: fn invalid; (*_20) = const 0_usize as *mut pointers::S (PointerFromExposedAddress); + n[3]: value.store _ => _17.* @ bb8[4]: fn fdevent_unregister; (*_17) = const 0_usize as *mut pointers::fdnode_st (PointerFromExposedAddress); + n[4]: int_to_ptr _ => _2 @ bb0[2]: fn test_ref_field; _2 = const 0_usize as *const pointers::S (PointerFromExposedAddress); + n[5]: int_to_ptr _ => _5 @ bb0[8]: fn test_ref_field; _5 = const 0_usize as *const pointers::S (PointerFromExposedAddress); } nodes_that_need_write = [] @@ -385,19 +385,19 @@ g { nodes_that_need_write = [] g { - n[0]: copy _ => _5 @ bb2[2]: fn no_owner; _5 = const {alloc2: *mut *mut pointers::S}; + n[0]: copy _ => _5 @ bb2[2]: fn no_owner; _5 = const {alloc8: *mut *mut pointers::S}; n[1]: addr.store n[0] => _ @ bb2[3]: fn no_owner; (*_5) = move _2 as *mut pointers::S (Misc); - n[2]: copy _ => _5 @ bb2[2]: fn no_owner; _5 = const {alloc2: *mut *mut pointers::S}; + n[2]: copy _ => _5 @ bb2[2]: fn no_owner; _5 = const {alloc8: *mut *mut pointers::S}; n[3]: addr.store n[2] => _ @ bb2[3]: fn no_owner; (*_5) = move _2 as *mut pointers::S (Misc); - n[4]: copy _ => _12 @ bb3[4]: fn no_owner; _12 = const {alloc2: *mut *mut pointers::S}; + n[4]: copy _ => _12 @ bb3[4]: fn no_owner; _12 = const {alloc8: *mut *mut pointers::S}; n[5]: addr.load n[4] => _ @ bb3[5]: fn no_owner; _11 = (*_12); - n[6]: copy _ => _6 @ bb2[9]: fn invalid; _6 = const {alloc2: *mut *mut pointers::S}; + n[6]: copy _ => _6 @ bb2[9]: fn invalid; _6 = const {alloc8: *mut *mut pointers::S}; n[7]: addr.store n[6] => _ @ bb2[10]: fn invalid; (*_6) = move _5; - n[8]: copy _ => _19 @ bb3[17]: fn invalid; _19 = const {alloc2: *mut *mut pointers::S}; + n[8]: copy _ => _19 @ bb3[17]: fn invalid; _19 = const {alloc8: *mut *mut pointers::S}; n[9]: field.0 n[8] => _18 @ bb3[18]: fn invalid; _18 = ((*(*_19)).0: i32); n[10]: addr.load n[9] => _ @ bb3[18]: fn invalid; _18 = ((*(*_19)).0: i32); - n[11]: copy _ => _20 @ bb4[6]: fn invalid; _20 = const {alloc2: *mut *mut pointers::S}; - n[12]: addr.store n[11] => _ @ bb4[7]: fn invalid; (*_20) = const 0_usize as *mut pointers::S (Misc); + n[11]: copy _ => _20 @ bb4[6]: fn invalid; _20 = const {alloc8: *mut *mut pointers::S}; + n[12]: addr.store n[11] => _ @ bb4[7]: fn invalid; (*_20) = const 0_usize as *mut pointers::S (PointerFromExposedAddress); } nodes_that_need_write = [12, 11, 7, 6, 3, 2, 1, 0] @@ -451,7 +451,7 @@ g { n[3]: copy n[2] => _7 @ bb2[9]: fn simple1; _7 = move _8 as *mut libc::c_void (Misc); n[4]: free n[3] => _6 @ bb3[2]: fn simple1; _6 = realloc(move _7, move _9); n[5]: copy n[1] => _16 @ bb4[20]: fn simple1; _16 = _1; - n[6]: ptr_to_int n[5] => _ @ bb4[21]: fn simple1; _15 = move _16 as usize (Misc); + n[6]: ptr_to_int n[5] => _ @ bb4[21]: fn simple1; _15 = move _16 as usize (PointerExposeAddress); n[7]: copy n[1] => _21 @ bb4[33]: fn simple1; _21 = _1; n[8]: copy n[7] => _20 @ bb4[34]: fn simple1; _20 = move _21 as *mut libc::c_void (Misc); n[9]: free n[8] => _19 @ bb4[36]: fn simple1; _19 = free(move _20); @@ -466,7 +466,7 @@ g { n[4]: addr.store n[3] => _ @ bb4[8]: fn simple1; ((*_11).0: i32) = const 10_i32; n[5]: copy n[1] => _12 @ bb4[10]: fn simple1; _12 = _5; n[6]: copy n[2] => _13 @ bb4[13]: fn simple1; _13 = _11; - n[7]: int_to_ptr _ => _17 @ bb4[27]: fn simple1; _17 = move _18 as *const libc::c_void (Misc); + n[7]: int_to_ptr _ => _17 @ bb4[27]: fn simple1; _17 = move _18 as *const libc::c_void (PointerFromExposedAddress); } nodes_that_need_write = [4, 3, 2, 1, 0] @@ -491,7 +491,7 @@ g { n[12]: value.load _ => _19 @ bb7[4]: fn fdevent_unregister; _19 = ((*_1).0: *mut *mut pointers::fdnode_st); n[13]: offset[0] n[12] => _18 @ bb7[10]: fn fdevent_unregister; _18 = offset(move _19, move _20); n[14]: copy n[13] => _17 @ bb8[3]: fn fdevent_unregister; _17 = &mut (*_18); - n[15]: addr.store n[14] => _ @ bb8[4]: fn fdevent_unregister; (*_17) = const 0_usize as *mut pointers::fdnode_st (Misc); + n[15]: addr.store n[14] => _ @ bb8[4]: fn fdevent_unregister; (*_17) = const 0_usize as *mut pointers::fdnode_st (PointerFromExposedAddress); n[16]: copy n[1] => _20 @ bb6[6]: fn lighttpd_test; _20 = _1; n[17]: copy n[16] => _19 @ bb6[7]: fn lighttpd_test; _19 = move _20 as *mut libc::c_void (Misc); n[18]: free n[17] => _18 @ bb6[9]: fn lighttpd_test; _18 = free(move _19); @@ -596,7 +596,7 @@ g { n[28]: addr.load n[27] => _ @ bb1[3]: fn fdevent_fdnode_event_unsetter; _8 = ((*_2).4: i32); n[29]: value.load _ => _3 @ bb1[2]: fn fdevent_unregister; _3 = (*_4); n[30]: copy n[29] => _12 @ bb1[11]: fn fdevent_unregister; _12 = _3; - n[31]: ptr_to_int n[30] => _ @ bb1[12]: fn fdevent_unregister; _11 = move _12 as usize (Misc); + n[31]: ptr_to_int n[30] => _ @ bb1[12]: fn fdevent_unregister; _11 = move _12 as usize (PointerExposeAddress); n[32]: copy n[29] => _23 @ bb8[7]: fn fdevent_unregister; _23 = _3; n[33]: copy n[32] => _1 @ bb0[0]: fn fdnode_free; _22 = fdnode_free(move _23); n[34]: copy n[33] => _4 @ bb0[3]: fn fdnode_free; _4 = _1; @@ -803,8 +803,8 @@ nodes_that_need_write = [5, 4, 1, 0] g { n[0]: alloc _ => _1 @ bb1[2]: fn test_ptr_int_ptr; _1 = malloc(move _2); n[1]: copy n[0] => _5 @ bb2[4]: fn test_ptr_int_ptr; _5 = _1; - n[2]: ptr_to_int n[1] => _ @ bb2[5]: fn test_ptr_int_ptr; _4 = move _5 as usize (Misc); - n[3]: int_to_ptr _ => _1 @ bb2[10]: fn test_ptr_int_ptr; _1 = move _6 as *mut libc::c_void (Misc); + n[2]: ptr_to_int n[1] => _ @ bb2[5]: fn test_ptr_int_ptr; _4 = move _5 as usize (PointerExposeAddress); + n[3]: int_to_ptr _ => _1 @ bb2[10]: fn test_ptr_int_ptr; _1 = move _6 as *mut libc::c_void (PointerFromExposedAddress); n[4]: copy n[3] => _8 @ bb2[14]: fn test_ptr_int_ptr; _8 = _1; n[5]: free n[4] => _7 @ bb2[15]: fn test_ptr_int_ptr; _7 = free(move _8); }