-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mir_alloc_static_mut
and mir_initialize_static_mut
commands
#1960
Comments
This prompted me to check what happens if you just read from static mutables, and hey presto that doesn't work. 🙀 However... The current behavior of this example seems to be that the bogus Adding My recollection is that only requiring a complete specification for outputs when using a spec as an override (vs. when proving it in the first place) is intentional. Am I misremembering? If not, I think most of the above must have already been done and there's nothing left to do here besides make the error messages comprehensible. |
Also though I think it would be good to make a copy of test_llvm_unsound_global for mir. |
(also, is this obsoleted by #1982?) |
Correct. To provide a much-needed update here: I originally opened this issue while still working on #1959 (the implementation of
This gets the job done (and does make SAW reject
Yes, I think #1982's proposal of needing to explicitly allocate static values (via
Yes, that is correct. It is sound for a specification not to specify static values in its postconditions, provided that the specification is not used in a compositional override. SAW strives to allow users to make their specifications as fine- or coarse-grained as they'd like, so in this sense, allowing users not to specify static values in postconditions fits in with SAW's existing design philosophy.
Are you referring to the |
No; that one's fine. I was thinking of other messages mentioned earlier, except that there actually aren't any, so I must have been thinking of some other issue's messages. I'll go make a test_mir_unsound_global and then I think we can call this done. |
That's been merged. |
As part of #1959, I am investigating a way to check whether an override modifies a particular mutable
static
value or not. Here is a motivating example:There are two problems with this example:
side_effect
mutates the value ofA
,side_effect_spec
does not mentionA
at all. This is a bit unsettling, asA
is mutable global state that could have an impact whenside_effect
is used as an override. And in fact...f_spec
is an incorrect specification forf
, asf
should return42
rather than27
(whicha_init
is equal to). Despite this, however, the current version ofmir_unsafe_assume_spec
#1959 (at the time of writing) will unsoundly verifyf_spec
as correct. This is becausef_spec
relies on an override forside_effect
that usesside_effect_spec
, butside_effect_spec
underspecifies whatA
's value should be in its postconditions.We want to reject examples like the one above, but how?
side_effect_spec
underspecifiesA
, but it is not obvious from looking atside_effect_ov
that this is the case, since nothing aboutside_effect_ov
mentionsA
at all. This suggests that we need a command that explicitly states which mutable static values a function makes use of (either via reads or writes).To solve this problem, I propose that we introduce a
mir_alloc_static_mut : String -> MIRSetup ()
command, similar to the LLVM backend'sllvm_alloc_global
command.mir_alloc_static_mut
would behave in the following way when used in combination withmir_verify
:mir_verify
, we start with aSymGlobalState
that does not contain any mutable static values.mir_verify
, we check if theSymGlobalState
contains any mutable static values that were not present in the originalSymGlobalState
. If so, we know that those mutable statics were written to at some point during simulation.mir_alloc_static_mut
command. If not, throw an error.Under this plan, the call to
mir_verify ... side_effect_spec
above would fail, since theside_effect
function writes toA
but does have amir_alloc_static_mut
command corresponding toA
as a precondition. Let's add one:This solves problem (1) above.
Problem (2) is still an issue, as
side_effect_spec
still does not say what the value ofA
should be in the postcondition, which would cause problems whenside_effect_ov
is used. But now we have a way to solve problem (2) as well, as there is now a straightforward way to see whether an override uses a mutable static or not: just check all of themir_alloc_static_mut
commands in the preconditions! We can see that there there is amir_alloc_static_mut "test::A"
command in the precondition, but there is no correspondingmir_points_to (mir_global "test::A") ...
command in the postcondition, so we can reasonably conclude thatside_effect_spec
underspecifiesA
. Therefore, we can throw an error when usingside_effect_ov
as an override, thereby solving problem (2).Note that the name
mir_alloc_static_mut
is perhaps slightly misleading, since the implementation of static values in thecrucible-mir
memory model does not actually perform any allocation. In the memory model, theGlobalVar
s backing static values are always allocated before simulation begins, regardless of whether they are used or not. This is arguably an implementation detail, however, and users don't need to care about this that much. Therefore, I propose that we keep the "alloc
" convention in the name, as it provides symmetry with the existingmir_alloc_mut
command.Speaking of
mir_alloc_mut
, themir_alloc_static_mut
command has the same pitfalls asmir_alloc_mut
in the sense thatmir_alloc_static_mut
does not initialize the thing that it references. Therefore, something like this would not work (in contrast with the LLVM backend):We proposed solving this issue on the
mir_alloc_mut
side by introducing amir_ref_mut_of : MIRValue -> MIRSetup MIRValue
command (see #1999) that allocates a mutable MIR reference and initializes it with a value so that subsequentmir_points_to (mir_field ...)
commands will work as expected. Similarly, I propose adding amir_initialize_static_mut : String -> MIRSetup ()
command that both "allocates" a static mutable value and initializes it with itsmir_static_initializer
value.mir_initialize_static_mut
would be tomir_alloc_static_mut
asmir_ref_mut_of
is tomir_alloc_mut
.The text was updated successfully, but these errors were encountered: