-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements supports for overrides in the SAW MIR backend, largely inspired by the existing implementation in the LLVM backend. I've added a `test_mir_unsafe_assume_spec` integration test to kick the tires and ensure the basics work as expected. Checks off one box in #1859. Still TODO: * Resolve the TODOs in the `test_mir_unsafe_assume_spec` test case (and the related code in `executeCond`) involving mutable allocations/statics in the postconditions of overrides. * Add a SAW remote API test case
- Loading branch information
1 parent
a697049
commit b1a4a16
Showing
15 changed files
with
882 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
all: test.linked-mir.json | ||
|
||
test.linked-mir.json: test.rs | ||
saw-rustc $< | ||
$(MAKE) remove-unused-build-artifacts | ||
|
||
.PHONY: remove-unused-build-artifacts | ||
remove-unused-build-artifacts: | ||
rm -f test libtest.mir libtest.rlib | ||
|
||
.PHONY: clean | ||
clean: remove-unused-build-artifacts | ||
rm -f test.linked-mir.json |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pub fn f(_x: u32) -> u32 { | ||
unimplemented!("f should be overridden"); | ||
} | ||
|
||
pub fn g(x: u32) -> u32 { | ||
f(x).wrapping_add(1) | ||
} | ||
|
||
pub fn h(x: u32) -> u32 { | ||
x.wrapping_add(1) | ||
} | ||
|
||
pub fn g2() -> u32 { | ||
f(2).wrapping_add(1) | ||
} | ||
|
||
pub fn p(_x: &u32, _y: &u32) -> u32 { | ||
unimplemented!("p should be overriden"); | ||
} | ||
|
||
pub fn q(x: &u32, y: &u32) -> u32 { | ||
p(x, y) | ||
} | ||
|
||
pub fn side_effect(a: &mut u32) -> u32 { | ||
let v: u32 = *a; | ||
*a = 0; | ||
v | ||
} | ||
|
||
pub fn foo(x: u32) -> u32 { | ||
let mut b: u32 = x; | ||
side_effect(&mut b); | ||
side_effect(&mut b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
enable_experimental; | ||
|
||
let f_generic_spec (x : Term) = do { | ||
mir_execute_func [mir_term x]; | ||
|
||
mir_return (mir_term x); | ||
}; | ||
|
||
let f_spec = do { | ||
x <- mir_fresh_var "x" mir_u32; | ||
f_generic_spec x; | ||
}; | ||
|
||
let f2_spec = do { | ||
let x = {{ 2 : [32] }}; | ||
f_generic_spec x; | ||
}; | ||
|
||
let f3_spec = do { | ||
let x = {{ 3 : [32] }}; | ||
f_generic_spec x; | ||
}; | ||
|
||
let g_spec = do { | ||
x <- mir_fresh_var "x" mir_u32; | ||
|
||
mir_execute_func [mir_term x]; | ||
|
||
mir_return (mir_term {{ x + 1 }}); | ||
}; | ||
|
||
let g2_spec = do { | ||
mir_execute_func []; | ||
|
||
mir_return (mir_term {{ 3 : [32] }}); | ||
}; | ||
|
||
let h_spec = g_spec; | ||
|
||
let p_spec_1 = do { | ||
x_ptr <- mir_alloc mir_u32; | ||
x <- mir_fresh_var "x" mir_u32; | ||
mir_points_to x_ptr (mir_term x); | ||
|
||
y_ptr <- mir_alloc mir_u32; | ||
y <- mir_fresh_var "y" mir_u32; | ||
mir_points_to y_ptr (mir_term y); | ||
|
||
mir_execute_func [x_ptr, y_ptr]; | ||
|
||
mir_return (mir_term {{ x + y }}); | ||
}; | ||
|
||
let p_spec_2 = do { | ||
x_ptr <- mir_alloc mir_u32; | ||
x <- mir_fresh_var "x" mir_u32; | ||
mir_points_to x_ptr (mir_term x); | ||
|
||
mir_execute_func [x_ptr, x_ptr]; | ||
|
||
mir_return (mir_term {{ 2 * x }}); | ||
}; | ||
|
||
let q_spec = p_spec_1; | ||
|
||
let side_spec_1 = do { | ||
a_ptr <- mir_alloc_mut mir_u32; | ||
a <- mir_fresh_var "a" mir_u32; | ||
mir_points_to a_ptr (mir_term a); | ||
|
||
mir_execute_func [a_ptr]; | ||
|
||
mir_points_to a_ptr (mir_term {{ 0 : [32] }}); | ||
mir_return (mir_term a); | ||
}; | ||
|
||
let side_spec_2 = do { | ||
a_ptr <- mir_alloc_mut mir_u32; | ||
a <- mir_fresh_var "a" mir_u32; | ||
mir_points_to a_ptr (mir_term a); | ||
|
||
mir_execute_func [a_ptr]; | ||
|
||
mir_return (mir_term a); | ||
}; | ||
|
||
let foo_spec = do { | ||
x <- mir_fresh_var "x" mir_u32; | ||
|
||
mir_execute_func [mir_term x]; | ||
|
||
mir_return (mir_term {{ x }}); | ||
}; | ||
|
||
m <- mir_load_module "test.linked-mir.json"; | ||
|
||
//////////// | ||
// Basics // | ||
//////////// | ||
|
||
f_ov <- mir_unsafe_assume_spec m "test::f" f_spec; | ||
f2_ov <- mir_unsafe_assume_spec m "test::f" f2_spec; | ||
f3_ov <- mir_unsafe_assume_spec m "test::f" f3_spec; | ||
|
||
// `g` should fail without an override for `f`... | ||
fails ( | ||
mir_verify m "test::g" [] false g_spec z3 | ||
); | ||
// ...but should succeed with an `f` override. | ||
mir_verify m "test::g" [f_ov] false g_spec z3; | ||
// `h` never calls `f`, but it's still fine to redundantly pass an `f` override | ||
mir_verify m "test::h" [f_ov] false h_spec z3; | ||
|
||
// `g2` will succeed with both a generic `f` override as well as a specialized | ||
// one where the argument and result values are concrete. | ||
mir_verify m "test::g2" [f_ov] false g2_spec z3; | ||
mir_verify m "test::g2" [f2_ov] false g2_spec z3; | ||
mir_verify m "test::g2" [f_ov, f2_ov] false g2_spec z3; | ||
|
||
// Overrides that fail to match. | ||
fails ( | ||
mir_verify m "test::g" [f3_ov] false g_spec z3 | ||
); | ||
fails ( | ||
mir_verify m "test::g2" [f3_ov] false g2_spec z3 | ||
); | ||
|
||
////////////// | ||
// Pointers // | ||
////////////// | ||
|
||
p_ov_1 <- mir_unsafe_assume_spec m "test::p" p_spec_1; | ||
p_ov_2 <- mir_unsafe_assume_spec m "test::p" p_spec_2; | ||
|
||
mir_verify m "test::q" [p_ov_1] false q_spec z3; | ||
fails ( | ||
mir_verify m "test::q" [p_ov_2] false q_spec z3 | ||
); | ||
|
||
/////////////////////// | ||
// Avoid unsoundness // | ||
/////////////////////// | ||
|
||
// https://github.com/GaloisInc/saw-script/issues/30 | ||
|
||
side_ov_1 <- mir_verify m "test::side_effect" [] false side_spec_1 z3; | ||
side_ov_2 <- mir_verify m "test::side_effect" [] false side_spec_2 z3; | ||
|
||
fails ( | ||
mir_verify m "test::foo" [side_ov_1] false foo_spec z3 | ||
); | ||
// TODO: This should not verify, as side_spec_2 underspecifies the mutable | ||
// allocation `a_ptr`. We need to implement a check that catches this. | ||
// fails ( | ||
// mir_verify m "test::foo" [side_ov_2] false foo_spec z3 | ||
// ); | ||
|
||
// TODO: Add similar tests for mutable statics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
set -e | ||
|
||
$SAW test.saw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.