Re:Frama-C: Modular Analysis of C Programs
by rwmj on Tuesday October 06, 2020 @08:46AM
(#24697105)
I was wondering about this too. If I was going to guess I would say it could be stuff that applies to any language that uses fixed width machine types, and not only C. For example, this is not true:
if the type of 'a' is 32 bit int. Similarly negate(a) ≠ -a for some numbers.
[ Parent
| on HN ]
Re:Frama-C: Modular Analysis of C Programs
by ritter2a on Tuesday October 06, 2020 @09:15AM
(#24697324)
Having written test cases for a similar semantic program analysis tool, I agree: Integer overflow is a very likely cause for such "obviously correct but actually wrong" program invariants. The C semantics can make this problem even worse since signed integer overflow is undefined, leaving the user of such a framework to the mercy of the design decisions of the creators of the framework regarding undefined behavior.
Re:Frama-C: Modular Analysis of C Programs
by Jtsummers on Tuesday October 06, 2020 @11:07AM
(#24698432)
In SPARK/Ada you'd have to constrain the input for something like that or it wouldn't be able to discharge the proof. Suppose you wanted a simple function (which is too simple to write in reality, but for brevity):
function Increment(A : Integer) return Integer
with Post => Increment'Result = A + 1;
It would find the counterexample for the situation where A is equal to Integer'Last. So you'd need to add a precondition like: function Increment(A : Integer) return Integer
with Pre => A < Integer'Last,
Post => Increment'Result = A + 1;
(doing this from memory and not fluent, so syntax may be off but the idea isn't)
Re:Frama-C: Modular Analysis of C Programs
by tom_mellior on Tuesday October 06, 2020 @12:46PM
(#24699799)
You can do that in Frama-C as well. But now this new precondition must be propagated somewhere. For example, if you have some function (syntax from memory as well):
/*@ ensures \result > a; */
int increment(int a) {
return a + 1;
}
you would change it to: /*@ requires a < INT_MAX;
ensures \result > a; */
int increment(int a) {
return a + 1;
}
But if this function has N call sites, you now have N problems: At every call site you must prove that the precondition holds.
Re:Frama-C: Modular Analysis of C Programs
by mcguire on Tuesday October 06, 2020 @12:17PM
(#24699373)
Frama-C has a wp plugin that generates assertions about overflow and underflow, which is one of the best tools it has. It's not spectacular about telling you where the problem is, and wasn't great with floats, though.
Re:Frama-C: Modular Analysis of C Programs
by steerablesafe on Tuesday October 06, 2020 @09:12AM
(#24697301)
Note that it's especially nasty in C, because it's either true or undefined behavior due to signed integer overflow.
Re:Frama-C: Modular Analysis of C Programs
by aidenn0 on Tuesday October 06, 2020 @12:20PM
(#24699417)
Complicating it even more, if "a" is a signed-integer than the compiler will assume that statement holds and optimize accordingly, put your correctness prover would instead need to flag that (or add the caveat that a < INT_MAX)
Re:Frama-C: Modular Analysis of C Programs
by dvfjsdhgfv on Tuesday October 06, 2020 @01:39PM
(#24700397)
If I remember correctly, in ANSI C int is guaranteed to have the maximum value of only 65,535 when unsigned, so basically bounds checking is a must. Of course it's even more important for shorter types like char.