-
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.
Draft: Basic checking for underspecified mutable allocs in overrides
- Loading branch information
1 parent
2d306dd
commit 2e79a1e
Showing
8 changed files
with
476 additions
and
14 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
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 |
1 change: 1 addition & 0 deletions
1
intTests/test_mir_unsafe_assume_spec_statics/test.linked-mir.json
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 @@ | ||
{"fns":[{"abi":{"kind":"Rust"},"args":[],"body":{"blocks":[{"block":{"data":[{"kind":"Assign","lhs":{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"}},"pos":"test.rs:1:21: 1:23","rhs":{"kind":"Use","usevar":{"data":{"rendered":{"kind":"uint","size":4,"val":"42"},"ty":"ty::u32"},"kind":"Constant"}}}],"terminator":{"kind":"Return","pos":"test.rs:1:1: 1:24"}},"blockid":"bb0"}],"vars":[{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"}]},"name":"test/65ce71a4::A","return_ty":"ty::u32","spread_arg":null},{"abi":{"kind":"Rust"},"args":[],"body":{"blocks":[{"block":{"data":[],"terminator":{"args":[],"cleanup":null,"destination":[{"data":[],"var":{"is_zst":false,"mut":{"kind":"Not"},"name":"_1","ty":"ty::u32"}},"bb1"],"from_hir_call":true,"func":{"data":{"rendered":{"kind":"zst"},"ty":"ty::FnDef::5c073f3fd0b9c562"},"kind":"Constant"},"kind":"Call","pos":"test.rs:12:5: 12:18"}},"blockid":"bb0"},{"block":{"data":[],"terminator":{"args":[],"cleanup":null,"destination":[{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"}},"bb2"],"from_hir_call":true,"func":{"data":{"rendered":{"kind":"zst"},"ty":"ty::FnDef::5c073f3fd0b9c562"},"kind":"Constant"},"kind":"Call","pos":"test.rs:13:5: 13:18"}},"blockid":"bb1"},{"block":{"data":[],"terminator":{"kind":"Return","pos":"test.rs:14:2: 14:2"}},"blockid":"bb2"}],"vars":[{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"},{"is_zst":false,"mut":{"kind":"Not"},"name":"_1","ty":"ty::u32"}]},"name":"test/65ce71a4::foo","return_ty":"ty::u32","spread_arg":null},{"abi":{"kind":"Rust"},"args":[],"body":{"blocks":[{"block":{"data":[{"kind":"Assign","lhs":{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_1","ty":"ty::RawPtr::63e5937014067f41"}},"pos":"test.rs:5:22: 5:23","rhs":{"kind":"Use","usevar":{"data":{"rendered":{"def_id":"test/65ce71a4::A","kind":"static_ref"},"ty":"ty::RawPtr::63e5937014067f41"},"kind":"Constant"}}},{"kind":"Assign","lhs":{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"}},"pos":"test.rs:5:22: 5:23","rhs":{"kind":"Use","usevar":{"data":{"data":[{"kind":"Deref"}],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_1","ty":"ty::RawPtr::63e5937014067f41"}},"kind":"Copy"}}},{"kind":"Assign","lhs":{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_2","ty":"ty::RawPtr::63e5937014067f41"}},"pos":"test.rs:6:9: 6:10","rhs":{"kind":"Use","usevar":{"data":{"rendered":{"def_id":"test/65ce71a4::A","kind":"static_ref"},"ty":"ty::RawPtr::63e5937014067f41"},"kind":"Constant"}}},{"kind":"Assign","lhs":{"data":[{"kind":"Deref"}],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_2","ty":"ty::RawPtr::63e5937014067f41"}},"pos":"test.rs:6:9: 6:14","rhs":{"kind":"Use","usevar":{"data":{"rendered":{"kind":"uint","size":4,"val":"0"},"ty":"ty::u32"},"kind":"Constant"}}}],"terminator":{"kind":"Return","pos":"test.rs:9:2: 9:2"}},"blockid":"bb0"}],"vars":[{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::u32"},{"is_zst":false,"mut":{"kind":"Mut"},"name":"_1","ty":"ty::RawPtr::63e5937014067f41"},{"is_zst":false,"mut":{"kind":"Mut"},"name":"_2","ty":"ty::RawPtr::63e5937014067f41"}]},"name":"test/65ce71a4::side_effect","return_ty":"ty::u32","spread_arg":null}],"adts":[],"statics":[{"kind":"body","mutable":true,"name":"test/65ce71a4::A","ty":"ty::u32"}],"vtables":[],"traits":[],"intrinsics":[{"inst":{"def_id":"test/65ce71a4::foo","kind":"Item","substs":[]},"name":"test/65ce71a4::foo"},{"inst":{"def_id":"test/65ce71a4::side_effect","kind":"Item","substs":[]},"name":"test/65ce71a4::side_effect"}],"tys":[{"name":"ty::u32","ty":{"kind":"Uint","uintkind":{"kind":"U32"}}},{"name":"ty::FnDef::5c073f3fd0b9c562","ty":{"defid":"test/65ce71a4::side_effect","kind":"FnDef"}},{"name":"ty::RawPtr::63e5937014067f41","ty":{"kind":"RawPtr","mutability":{"kind":"Mut"},"ty":"ty::u32"}}],"roots":["test/65ce71a4::side_effect","test/65ce71a4::foo"]} |
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,14 @@ | ||
static mut A: u32 = 42; | ||
|
||
pub fn side_effect() -> u32 { | ||
unsafe { | ||
let v: u32 = A; | ||
A = 0; | ||
v | ||
} | ||
} | ||
|
||
pub fn foo() -> u32 { | ||
side_effect(); | ||
side_effect() | ||
} |
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,56 @@ | ||
enable_experimental; | ||
|
||
m <- mir_load_module "test.linked-mir.json"; | ||
|
||
let side_spec_1 = do { | ||
let a_static = mir_static "test::A"; | ||
a_init <- mir_fresh_var "A" mir_u32; | ||
mir_points_to a_static (mir_term a_init); | ||
|
||
mir_execute_func []; | ||
|
||
mir_points_to a_static (mir_term {{ 0 : [32] }}); | ||
mir_return (mir_term a_init); | ||
}; | ||
|
||
let side_spec_2 = do { | ||
let a_static = mir_static "test::A"; | ||
a_init <- mir_fresh_var "A" mir_u32; | ||
mir_points_to a_static (mir_term a_init); | ||
|
||
mir_execute_func []; | ||
|
||
mir_return (mir_term a_init); | ||
}; | ||
|
||
// This spec is erroneous—see the comments below in the "Avoid unsoundness" | ||
// part of the test. | ||
let foo_spec = do { | ||
let a_static = mir_static "test::A"; | ||
a_init <- mir_fresh_var "A" mir_u32; | ||
mir_points_to a_static (mir_term a_init); | ||
|
||
mir_execute_func []; | ||
|
||
mir_points_to a_static (mir_term {{ 0 : [32] }}); | ||
mir_return (mir_term a_init); | ||
}; | ||
|
||
/////////////////////// | ||
// Avoid unsoundness // | ||
/////////////////////// | ||
|
||
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; | ||
|
||
// This should not verify, as invoking `side_effect` should cause `foo` to | ||
// always return `0` rather than the original value of A. | ||
fails ( | ||
mir_verify m "test::foo" [side_ov_1] false foo_spec z3 | ||
); | ||
// This should not verify, as side_spec_2 underspecifies the mutable | ||
// static `a_ptr` in its postconditions. SAW will catch this when attempting | ||
// to use side_ov_2 as an override. | ||
fails ( | ||
mir_verify m "test::foo" [side_ov_2] false foo_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.