3 ms·
The loop invariants that you can detect may not be the loop invariants that they want. Consider: for(int i = 0; i < n; i++) {..} It looks like the invariant
by Jtsummers 6y ago
The loop invariants that you can detect may not be the loop invariants that they want. Consider:
for(int i = 0; i < n; i++) {..}
It looks like the invariant should be:
0 <= i < n
But if they mistyped the loop that would be wrong. You have to explicitly state your invariants. At best, you could detect them and ask for confirmation. And that's for an easy to detect case.
- the-smug-one 6y agoWhat programs can do is "loop invariant synthesis" (for people that want to google it), this is still quite tricky to do. There's a reason that humans also find loop invariants tricky.
- im3w1l 6y agoThis sounds like an invariant even an optimizing compiler could find, because it's such a common construct. Well... I guess they have an easier job because they can "assume away" signed overflow.
- Jtsummers 6y agoMy point was that that may not be the actual invariant. By making your invariants explicit these tools have a better chance of finding real errors since you compare the code against a specification. Deriving a specification just means your code works according to itself.
- mcguire 6y agoPresumably, you are doing something other than just incrementing i in the loop, though. Most of the time with Frama-C, all you have to provide is function pre- and post-conditions and loop invariants.
- KsassPeuk 6y agoIn fact that would be ``` 0 <= i <= n ``` As the loop reaches this value to terminate. Else, we could not deduce for example that `i = n` at the end of the loop (`0 <= i <= n && !(i < n)`).