Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a7e3df
Upgraded to the newest nightly (1.65, 2022-08-08) with `miri`.
kkysen Aug 10, 2022
0a7a2d4
Fixed errors so `c2rust-instrument` compiles again. I kept all behav…
kkysen Aug 10, 2022
e8b553d
`cargo clippy --fix` for `c2rust-instrument`.
kkysen Aug 10, 2022
0344af0
Fixed other new `clippy` errors after update to 1.65 (all quite simpl…
kkysen Aug 10, 2022
c277c62
Fixed most of the errors (rest I'm unsure about) in `c2rust-analyze`.…
kkysen Aug 10, 2022
49d2b61
Figured out to fix another error by looking at the type difference vs…
kkysen Aug 10, 2022
55a5087
Merge branch 'master' into kkysen/update-rustc
kkysen Aug 10, 2022
df32e6c
analyze: misc fixes for rustc update
spernsteiner Aug 10, 2022
cbe60c0
update atomic intrinsic usage for newer rustc
fw-immunant Aug 11, 2022
239f0f2
Fixed a `clippy` warning that I think got undone in a merge.
kkysen Aug 11, 2022
a792e00
Improved error message if new `atomic::Ordering` gets new variants.
kkysen Aug 11, 2022
d990fb3
Prefer `format!` over `.to_owned() + `.
kkysen Aug 11, 2022
2e092a6
Use `order_name` in `atomic_cxchg_*` code, too.
kkysen Aug 11, 2022
5e5fb31
Merge some patterns in `atomic_cxchg_*` code.
kkysen Aug 11, 2022
a7f2dce
update remaining references to old atomic intrinsics
fw-immunant Aug 12, 2022
ae42f28
Fixed up some comments.
kkysen Aug 12, 2022
776cddf
Switched to `CastKind::PointerExposeAddress` (for strict provenance),…
kkysen Aug 12, 2022
906968b
Fixed fat ptr to `usize` cast error by first casting all ptrs to `*co…
kkysen Aug 12, 2022
54a3490
Merge branch 'master' into kkysen/update-rustc
kkysen Aug 15, 2022
ca5cc33
Updated the snapshot (just `Misc` => `PointerExposeAddress`).
kkysen Aug 15, 2022
52b6693
Merge branch 'master' into kkysen/update-rustc
kkysen Aug 16, 2022
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
8 changes: 4 additions & 4 deletions c2rust-analyze/src/borrowck/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ 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,
context,
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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion c2rust-analyze/src/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 5 additions & 3 deletions c2rust-analyze/src/borrowck/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
ref func,
ref args,
destination,
target,
..
} => {
let func_ty = func.ty(self.local_decls, *self.ltcx);
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions c2rust-analyze/src/dataflow/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
ref func,
ref args,
destination,
target,
..
} => {
let func_ty = func.ty(self.mir, tcx);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions c2rust-analyze/src/expr_rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions c2rust-analyze/src/labeled_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: FnMut(Ty<'tcx>) -> 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
Expand All @@ -166,19 +166,19 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
let args = substs.types().map(|t| self.label(t, f)).collect::<Vec<_>>();
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)
}
RawPtr(mty) => {
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)
}
Expand All @@ -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::<Vec<_>>();
let args = elems.iter().map(|ty| self.label(ty, f)).collect::<Vec<_>>();
self.mk(ty, self.mk_slice(&args), label)
}

Expand All @@ -220,7 +217,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::<Vec<_>>())
self.mk_slice(&tys.iter().map(|&ty| self.label(ty, f)).collect::<Vec<_>>())
}

/// Substitute in arguments for any type parameter references (`Param`) in a labeled type.
Expand Down Expand Up @@ -291,7 +288,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()
Expand Down
1 change: 1 addition & 0 deletions c2rust-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion c2rust-analyze/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn ty_callee<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Callee<'tcx>>
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;
}
Expand Down
21 changes: 10 additions & 11 deletions c2rust-ast-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ impl Make<Ident> for &str {

impl Make<Ident> for String {
fn make(self, mk: &Builder) -> Ident {
Ident::new(&*self, mk.span)
Ident::new(&self, mk.span)
}
}

impl Make<Ident> for &String {
fn make(self, mk: &Builder) -> Ident {
Ident::new(&*self, mk.span)
Ident::new(self, mk.span)
}
}

Expand All @@ -205,7 +205,7 @@ impl<'a> Make<Path> for &'a str {

impl<'a> Make<Visibility> 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),
}),
Expand All @@ -226,8 +226,7 @@ impl<'a> Make<Visibility> for &'a str {
path: Box::new(mk().path("super")),
}),
_ => panic!("unrecognized string for Visibility: {:?}", self),
};
kind
}
}
}

Expand All @@ -247,7 +246,7 @@ impl<'a> Make<Extern> for &'a str {
}
}

impl<'a> Make<Extern> for Abi {
impl Make<Extern> for Abi {
fn make(self, _mk: &Builder) -> Extern {
Extern::Explicit(self.name.to_token_stream().to_string())
}
Expand Down Expand Up @@ -375,13 +374,13 @@ impl Make<NestedMeta> for Lit {

impl Make<Lit> for String {
fn make(self, mk: &Builder) -> Lit {
Lit::Str(LitStr::new(&*self, mk.span))
Lit::Str(LitStr::new(&self, mk.span))
}
}

impl Make<Lit> for &String {
fn make(self, mk: &Builder) -> Lit {
Lit::Str(LitStr::new(&*self, mk.span))
Lit::Str(LitStr::new(self, mk.span))
}
}

Expand Down Expand Up @@ -824,7 +823,7 @@ impl Builder {

pub fn binary_expr(self, op: BinOp, mut lhs: Box<Expr>, rhs: Box<Expr>) -> Box<Expr> {
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),
_ => {}
}

Expand Down Expand Up @@ -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,
}
}
Expand Down
13 changes: 5 additions & 8 deletions c2rust-transpile/src/c_ast/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,18 +1011,15 @@ impl ConversionContext {

let label_name = from_value::<Rc<str>>(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);
Expand Down
10 changes: 5 additions & 5 deletions c2rust-transpile/src/c_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ impl CExprKind {
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CastKind {
BitCast,
LValueToRValue,
Expand Down Expand Up @@ -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, // /
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand All @@ -1580,7 +1580,7 @@ impl CQualTypeId {
/// Represents a type in C (6.2.5 Types)
///
/// Reflects the types in <http://clang.llvm.org/doxygen/classclang_1_1Type.html>
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CTypeKind {
Void,

Expand Down
9 changes: 3 additions & 6 deletions c2rust-transpile/src/c_ast/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,9 @@ impl<W: Write> Printer<W> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion c2rust-transpile/src/rust_ast/comment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn insert_comment_attrs(attrs: &mut Vec<Attribute>, 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);
Expand Down
Loading