Open jiten-thakkar opened 7 years ago
@michael-emmi Can you please give your thoughts on this issue? Here the problem is that in the generated boogie code, the variable in the ensure statement is not the same as the return variable. I talked with @zvonimir and we are thinking of adding a return
function in contracts in smack. What do you think?
Ah yes, the problem here is that you want to refer to the value returned from the function in the ensures
specification. In general, this cannot be matched to a single LLVM register variable, so encoding this as a call to ensures
with a return value as an argument will not work.
This was partially handled in an older version, e.g., in the now failing result.c regression, via the result
function of smack-contracts.h:
int old(int term);
int result(void);
(There was also an old
function, to refer to the pre-call value of a given expression.)
These functions need to be reimplemented. Also, they should be renamed to __CONTRACT_old
and __CONTRACT_result
to be consistent with the other contract functions.
By the way, as a developer, you should compile Smack in debug mode, in which case you will notice a failing assertion long before Boogie code even gets generated on this example. The failing assertion insists that procedure specifications should be declared at the start of procedures, before any loops.
By the way, see here for the previous implementation of result
.
Smack gives error while verifying this code:
Here is the error:
You can look at the bpl file here: https://gist.github.com/jiten-thakkar/b4c21f53d9b63e6ae0f3474ddf47873b