-
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.
Merge pull request #1931 from GaloisInc/T1859-mir_struct_value
`mir_find_adt`, `mir_struct_value`, and friends
- Loading branch information
Showing
38 changed files
with
1,213 additions
and
236 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
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
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,66 @@ | ||
pub struct S1 { | ||
pub x1: u32, | ||
pub y1: u32, | ||
} | ||
|
||
pub fn f1(s: S1) -> S1 { | ||
S1 { | ||
x1: s.y1.wrapping_add(1), | ||
y1: s.x1.wrapping_add(2), | ||
} | ||
} | ||
|
||
pub fn g(s: &S1) -> S1 { | ||
S1 { | ||
x1: s.y1.wrapping_add(1), | ||
y1: s.x1.wrapping_add(2), | ||
} | ||
} | ||
|
||
pub fn h(s: &mut S1) { | ||
let x1 = s.x1; | ||
let y1 = s.y1; | ||
s.x1 = y1.wrapping_add(1); | ||
s.y1 = x1.wrapping_add(2); | ||
} | ||
|
||
// Polymorphism | ||
|
||
pub struct S2<A, B> { | ||
pub x2: A, | ||
pub y2: B, | ||
} | ||
|
||
pub fn f2(s: S2<u32, u32>) -> S2<u32, u32> { | ||
S2 { | ||
x2: s.y2.wrapping_add(1), | ||
y2: s.x2.wrapping_add(2), | ||
} | ||
} | ||
|
||
pub struct S3(u32, u32); | ||
|
||
pub fn f3(s: S3) -> S3 { | ||
match s { | ||
S3(x3, y3) => S3(y3.wrapping_add(1), x3.wrapping_add(2)), | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct S4(u32); | ||
|
||
pub fn f4(s: S4) -> S4 { | ||
match s { | ||
S4(x4) => S4(x4.wrapping_add(2)), | ||
} | ||
} | ||
|
||
pub struct Foo<A>(A); | ||
|
||
pub fn bar<'a>(f1: &'a mut Foo<[u8; 4]>, f2: &'a mut Foo<S2<u32, u32>>) -> &'a mut Foo<S2<u32, u32>> { | ||
f1.0[1] = 42; | ||
f2.0.x2 = f2.0.y2; | ||
f2 | ||
} | ||
|
||
pub fn baz(_: Option<S2<u32, u32>>) {} |
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,155 @@ | ||
enable_experimental; | ||
|
||
m <- mir_load_module "test.linked-mir.json"; | ||
|
||
let s1_adt = mir_find_adt m "test::S1" []; | ||
let s2_adt = mir_find_adt m "test::S2" [mir_u32, mir_u32]; | ||
let s3_adt = mir_find_adt m "test::S3" []; | ||
let s4_adt = mir_find_adt m "test::S4" []; | ||
|
||
let foo_adt_1 = mir_find_adt m "test::Foo" [mir_array 4 mir_u8]; | ||
let foo_adt_2 = mir_find_adt m "test::Foo" [mir_adt s2_adt]; | ||
|
||
let option_adt = mir_find_adt m "core::option::Option" [mir_adt s2_adt]; | ||
|
||
let f_spec adt = do { | ||
x1 <- mir_fresh_var "x1" mir_u32; | ||
y1 <- mir_fresh_var "y1" mir_u32; | ||
let s = mir_struct_value | ||
adt | ||
[ mir_term x1 | ||
, mir_term y1 | ||
]; | ||
|
||
mir_execute_func [s]; | ||
|
||
let s' = mir_struct_value | ||
adt | ||
[ mir_term {{ y1 + 1 }} | ||
, mir_term {{ x1 + 2 }} | ||
]; | ||
mir_return s'; | ||
}; | ||
|
||
|
||
let f1_spec = f_spec s1_adt; | ||
let f2_spec = f_spec s2_adt; | ||
let f3_spec = f_spec s3_adt; | ||
|
||
let f4_spec = do { | ||
x4 <- mir_fresh_var "x4" mir_u32; | ||
let s = mir_struct_value s4_adt [mir_term x4]; | ||
|
||
mir_execute_func [s]; | ||
|
||
let s' = mir_struct_value s4_adt [mir_term {{ x4 + 2 }}]; | ||
mir_return s'; | ||
}; | ||
|
||
let g_spec = do { | ||
s_ptr <- mir_alloc (mir_adt s1_adt); | ||
x1 <- mir_fresh_var "x1" mir_u32; | ||
y1 <- mir_fresh_var "y1" mir_u32; | ||
let s = mir_struct_value | ||
s1_adt | ||
[ mir_term x1 | ||
, mir_term y1 | ||
]; | ||
mir_points_to s_ptr s; | ||
|
||
mir_execute_func [s_ptr]; | ||
|
||
let s' = mir_struct_value | ||
s1_adt | ||
[ mir_term {{ y1 + 1 }} | ||
, mir_term {{ x1 + 2 }} | ||
]; | ||
mir_return s'; | ||
}; | ||
|
||
let h_spec = do { | ||
s_ptr <- mir_alloc_mut (mir_adt s1_adt); | ||
x1 <- mir_fresh_var "x1" mir_u32; | ||
y1 <- mir_fresh_var "y1" mir_u32; | ||
let s = mir_struct_value | ||
s1_adt | ||
[ mir_term x1 | ||
, mir_term y1 | ||
]; | ||
mir_points_to s_ptr s; | ||
|
||
mir_execute_func [s_ptr]; | ||
|
||
let s' = mir_struct_value | ||
s1_adt | ||
[ mir_term {{ y1 + 1 }} | ||
, mir_term {{ x1 + 2 }} | ||
]; | ||
mir_points_to s_ptr s'; | ||
}; | ||
|
||
let bar_spec = do { | ||
f1_ptr <- mir_alloc_mut (mir_adt foo_adt_1); | ||
f1_arr_val0 <- mir_fresh_var "f1_arr_val0" mir_u8; | ||
f1_arr_val1 <- mir_fresh_var "f1_arr_val1" mir_u8; | ||
f1_arr_val2 <- mir_fresh_var "f1_arr_val2" mir_u8; | ||
f1_arr_val3 <- mir_fresh_var "f1_arr_val3" mir_u8; | ||
let f1_arr_val = mir_array_value | ||
mir_u8 | ||
[ mir_term f1_arr_val0 | ||
, mir_term f1_arr_val1 | ||
, mir_term f1_arr_val2 | ||
, mir_term f1_arr_val3 | ||
]; | ||
let f1_foo_val = mir_struct_value foo_adt_1 [f1_arr_val]; | ||
mir_points_to f1_ptr f1_foo_val; | ||
|
||
f2_ptr <- mir_alloc_mut (mir_adt foo_adt_2); | ||
f2_s2_val0 <- mir_fresh_var "f2_s2_val0" mir_u32; | ||
f2_s2_val1 <- mir_fresh_var "f2_s2_val1" mir_u32; | ||
let f2_s2_val = mir_struct_value | ||
s2_adt | ||
[ mir_term f2_s2_val0 | ||
, mir_term f2_s2_val1 | ||
]; | ||
let f2_foo_val = mir_struct_value foo_adt_2 [f2_s2_val]; | ||
mir_points_to f2_ptr f2_foo_val; | ||
|
||
mir_execute_func [f1_ptr, f2_ptr]; | ||
|
||
let f1_arr_val' = mir_array_value | ||
mir_u8 | ||
[ mir_term f1_arr_val0 | ||
, mir_term {{ 42 : [8] }} | ||
, mir_term f1_arr_val2 | ||
, mir_term f1_arr_val3 | ||
]; | ||
let f1_foo_val' = mir_struct_value foo_adt_1 [f1_arr_val']; | ||
mir_points_to f1_ptr f1_foo_val'; | ||
|
||
let f2_s2_val' = mir_struct_value | ||
s2_adt | ||
[ mir_term f2_s2_val1 | ||
, mir_term f2_s2_val1 | ||
]; | ||
let f2_foo_val' = mir_struct_value foo_adt_2 [f2_s2_val']; | ||
mir_points_to f2_ptr f2_foo_val'; | ||
|
||
mir_return f2_ptr; | ||
}; | ||
|
||
mir_verify m "test::f1" [] false f1_spec z3; | ||
mir_verify m "test::f2" [] false f2_spec z3; | ||
mir_verify m "test::f3" [] false f3_spec z3; | ||
mir_verify m "test::f4" [] false f4_spec z3; | ||
mir_verify m "test::g" [] false g_spec z3; | ||
mir_verify m "test::h" [] false h_spec z3; | ||
|
||
fails ( | ||
mir_verify m "test::f1" [] false f2_spec z3 | ||
); | ||
fails ( | ||
mir_verify m "test::f2" [] false f1_spec z3 | ||
); | ||
|
||
mir_verify m "test::bar" [] false bar_spec z3; |
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
Oops, something went wrong.