You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DFCC loop contracts: a variable declared before a loop without an initializer is not havoced, so a false assertion verifies #9175
With --dfcc --apply-loop-contracts, a variable that is declared before a loop without an initializer, and read and written only inside the loop, keeps the value it got in the base-case iteration when the step case runs. A false assertion then verifies.
#include<assert.h>voidmain()
{
unsignedn;
__CPROVER_assume(n>3&&n<100);
unsignedi=0;
unsignedt;
while(i<n)
__CPROVER_loop_invariant(i <= n)
{
if(i>0)
assert(t==0); // false at i == 2 in a real run (t == 1)t=i;
i++;
}
}
Expected: VERIFICATION FAILED, as with cbmc looplocal.c --unwind 5.
Actual: VERIFICATION SUCCESSFUL.
With an initializer (unsigned t = 0;), the contract check fails as expected.
As far as I can tell, the cause is gen_loop_locals_set in src/goto-instrument/contracts/dynamic-frames/dfcc_infer_loop_assigns.cpp. It treats a variable as a loop local if "there is no write or read of it outside the loop". t is only declared outside the loop, so it is classified as a loop local and is not havoced. Unlike a variable declared inside the loop, it is not declared again in each iteration, so its value flows from one iteration into the next.
Found with CBMC 6.11.0. The same rule is on develop (4b26409).
Activity
DFCC: only variables declared inside loop are loop locals
DFCC: only variables declared inside loop are loop locals