Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update rustc to nightly-2022-08-08 #595

Merged
merged 21 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions c2rust-analyze/src/borrowck/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {

// 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")
}
}
}

Expand Down Expand Up @@ -127,15 +131,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 +259,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 +268,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();
kkysen marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions c2rust-analyze/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
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
27 changes: 18 additions & 9 deletions c2rust-analyze/src/expr_rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(..) => {}
Expand Down Expand Up @@ -163,14 +164,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 Expand Up @@ -249,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>,
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
Loading