Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion crates/newyork/src/heap_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,17 +1912,30 @@ mod tests {
#[test]
fn condition_observes_overlap_store_flags_unbounded() {
use crate::ir::ValueId;

let mut statements = establish_fmp_statements();
statements.extend(overlap_store_statements(2));
statements.push(literal_binding(4, 0x40));
statements.push(loop_with_condition(Expression::MLoad {
offset: Value::int(ValueId(4)),
region: MemoryRegion::Unknown,
}));
let results = object_with_code(statements, vec![]).analyze_heap(TEST_HEAP_SIZE);
assert!(
results.fmp_could_be_unbounded(),
"a loop condition loading from static offset 0x40 after an overlap store observes the corruption"
);

let mut statements = establish_fmp_statements();
statements.extend(overlap_store_statements(2));
statements.push(loop_with_condition(Expression::MLoad {
offset: Value::int(ValueId(4)),
region: MemoryRegion::FreePointerSlot,
}));
let results = object_with_code(statements, vec![]).analyze_heap(TEST_HEAP_SIZE);
assert!(
results.fmp_could_be_unbounded(),
"a loop condition reading mload(0x40) after an overlap store observes the corruption"
"a loop condition loading from the free pointer slot after an overlap store observes the corruption"
);
}

Expand Down
22 changes: 20 additions & 2 deletions crates/newyork/src/mem_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ mod tests {
let offset_id = ValueId(2);
let value_id = ValueId(3);
let result_id = ValueId(4);
let addend_id = ValueId(5);

let statements = vec![
Statement::Let {
Expand All @@ -1727,6 +1728,13 @@ mod tests {
value_type: Type::Int(BitWidth::I256),
},
},
Statement::Let {
bindings: vec![addend_id],
value: Expression::Literal {
value: BigUint::from(32u32),
value_type: Type::Int(BitWidth::I256),
},
},
Statement::Let {
bindings: vec![offset_id],
value: Expression::Binary {
Expand All @@ -1736,7 +1744,7 @@ mod tests {
value_type: Type::Int(BitWidth::I256),
},
rhs: Value {
id: ValueId(100),
id: addend_id,
value_type: Type::Int(BitWidth::I256),
},
},
Expand Down Expand Up @@ -1779,7 +1787,17 @@ mod tests {
data: BTreeMap::new(),
};

let _statistics = optimizer.optimize_object(&mut object);
let statistics = optimizer.optimize_object(&mut object);

assert_eq!(statistics.loads_eliminated, 1);
assert!(
matches!(
object.code.statements.last(),
Some(Statement::Let { bindings, value: Expression::Var(forwarded) })
if bindings == &vec![result_id] && *forwarded == value_id
),
"the load at the folded offset must be replaced by the stored value"
);
}

#[test]
Expand Down
14 changes: 8 additions & 6 deletions crates/newyork/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4128,12 +4128,14 @@ mod tests {
let block = &mut Block { statements };
simplifier.simplify_block(block);

if let Statement::Return { offset, .. } = &block.statements[block.statements.len() - 1] {
assert!(
offset.id.0 == 1
|| matches!(block.statements.last(), Some(Statement::Return { .. }))
);
}
let Some(Statement::Return { offset, length }) = block.statements.last() else {
panic!("the block must still end in a return");
};
assert_eq!(
(offset.id, length.id),
(ValueId(1), ValueId(1)),
"uses of the copy `v2 := v1` must be rewritten to its source"
);
}

#[test]
Expand Down
Loading