Skip to content

Commit da4276f

Browse files
committed
analyze: create updates_forbidden set and pass it to dataflow
1 parent c248af1 commit da4276f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

c2rust-analyze/src/analyze.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ struct FuncInfo<'tcx> {
554554
/// get a complete [`Assignment`] for this function, which maps every [`PointerId`] in this
555555
/// function to a [`PermissionSet`] and [`FlagSet`].
556556
lasn: MaybeUnset<LocalAssignment>,
557+
/// Local part of the `updates_forbidden` mask.
558+
l_updates_forbidden: MaybeUnset<LocalPointerTable<PermissionSet>>,
557559
/// Constraints on pointee types gathered from the body of this function.
558560
pointee_constraints: MaybeUnset<pointee_type::ConstraintSet<'tcx>>,
559561
/// Local part of pointee type sets.
@@ -872,6 +874,8 @@ fn run(tcx: TyCtxt) {
872874
const INITIAL_FLAGS: FlagSet = FlagSet::empty();
873875

874876
let mut gasn = GlobalAssignment::new(gacx.num_pointers(), INITIAL_PERMS, INITIAL_FLAGS);
877+
let mut g_updates_forbidden = GlobalPointerTable::new(gacx.num_pointers());
878+
875879
for (ptr, &info) in gacx.ptr_info().iter() {
876880
if should_make_fixed(info) {
877881
gasn.flags[ptr].insert(FlagSet::FIXED);
@@ -897,6 +901,7 @@ fn run(tcx: TyCtxt) {
897901
for info in func_info.values_mut() {
898902
let num_pointers = info.acx_data.num_pointers();
899903
let mut lasn = LocalAssignment::new(num_pointers, INITIAL_PERMS, INITIAL_FLAGS);
904+
let l_updates_forbidden = LocalPointerTable::new(num_pointers);
900905

901906
for (ptr, &info) in info.acx_data.local_ptr_info().iter() {
902907
if should_make_fixed(info) {
@@ -905,6 +910,7 @@ fn run(tcx: TyCtxt) {
905910
}
906911

907912
info.lasn.set(lasn);
913+
info.l_updates_forbidden.set(l_updates_forbidden);
908914
}
909915

910916
// Load permission info from PDG
@@ -1121,16 +1127,19 @@ fn run(tcx: TyCtxt) {
11211127
let field_ltys = gacx.field_ltys.clone();
11221128
let acx = gacx.function_context_with_data(&mir, info.acx_data.take());
11231129
let mut asn = gasn.and(&mut info.lasn);
1130+
let updates_forbidden = g_updates_forbidden.and(&info.l_updates_forbidden);
11241131

11251132
let r = panic_detail::catch_unwind(AssertUnwindSafe(|| {
11261133
// `dataflow.propagate` and `borrowck_mir` both run until the assignment converges
11271134
// on a fixpoint, so there's no need to do multiple iterations here.
1128-
info.dataflow.propagate(&mut asn.perms_mut());
1135+
info.dataflow
1136+
.propagate(&mut asn.perms_mut(), &updates_forbidden);
11291137

11301138
borrowck::borrowck_mir(
11311139
&acx,
11321140
&info.dataflow,
11331141
&mut asn.perms_mut(),
1142+
&updates_forbidden,
11341143
name.as_str(),
11351144
&mir,
11361145
field_ltys,

c2rust-analyze/src/borrowck/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::context::AdtMetadataTable;
44
use crate::context::{AnalysisCtxt, PermissionSet};
55
use crate::dataflow::DataflowConstraints;
66
use crate::labeled_ty::{LabeledTy, LabeledTyCtxt};
7-
use crate::pointer_id::PointerTableMut;
7+
use crate::pointer_id::{PointerTable, PointerTableMut};
88
use crate::util::{describe_rvalue, RvalueDesc};
99
use indexmap::{IndexMap, IndexSet};
1010
use rustc_hir::def_id::DefId;
@@ -120,6 +120,7 @@ pub fn borrowck_mir<'tcx>(
120120
acx: &AnalysisCtxt<'_, 'tcx>,
121121
dataflow: &DataflowConstraints,
122122
hypothesis: &mut PointerTableMut<PermissionSet>,
123+
updates_forbidden: &PointerTable<PermissionSet>,
123124
name: &str,
124125
mir: &Body<'tcx>,
125126
field_ltys: HashMap<DefId, context::LTy<'tcx>>,
@@ -181,7 +182,7 @@ pub fn borrowck_mir<'tcx>(
181182
}
182183

183184
eprintln!("propagate");
184-
changed |= dataflow.propagate(hypothesis);
185+
changed |= dataflow.propagate(hypothesis, updates_forbidden);
185186
eprintln!("done propagating");
186187

187188
if !changed {

c2rust-analyze/src/dataflow/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ impl DataflowConstraints {
4545
}
4646

4747
/// Update the pointer permissions in `hypothesis` to satisfy these constraints.
48-
pub fn propagate(&self, hypothesis: &mut PointerTableMut<PermissionSet>) -> bool {
48+
///
49+
/// If `restrict_updates[ptr]` has some flags set, then those flags will be left unchanged in
50+
/// `hypothesis[ptr]`.
51+
pub fn propagate(
52+
&self,
53+
hypothesis: &mut PointerTableMut<PermissionSet>,
54+
updates_forbidden: &PointerTable<PermissionSet>,
55+
) -> bool {
4956
eprintln!("=== propagating ===");
5057
eprintln!("constraints:");
5158
for c in &self.constraints {
@@ -130,7 +137,7 @@ impl DataflowConstraints {
130137
}
131138
}
132139

133-
match self.propagate_inner(hypothesis, &mut PropagatePerms, None) {
140+
match self.propagate_inner(hypothesis, &mut PropagatePerms, Some(updates_forbidden)) {
134141
Ok(changed) => changed,
135142
Err(msg) => {
136143
panic!("{}", msg);

0 commit comments

Comments
 (0)