Skip to content

Conversation

@jerhard
Copy link
Member

@jerhard jerhard commented Oct 21, 2020

In order to implement proper handling of integer overflows in the analyzed C code, and to be able to deal with values outside the range of OCaml-int64 (#120), we have to make several changes to the integer domains.

  1. Add ikind information to the integer domains.
  2. Use arbitrary precision integers in the implementation of the domains.
  3. In the implementation of the abstract operations of the integer domains, add detection & handling of overflows.

Regarding 1., I added an functor IntDomLifter, that takes a module of signature IntDomain.S and adds a layer to store the ikind.

TODOs:

  • it is not clear how the top and bot should look like in the IntDomLifter. These either would have to be of some arbitrary ikind or some additional Top and Bottom element
  • 2 and 3. still have to be implemented

This shows a problem in the treatment of operations:
    (Excluded (s, r)) op (Definite y)

Excluded(s op y, _) is in general not a correct result value here.
(Where s op y := {x op y | x in s})
This is because there might be an z in gamma(Excluded (s, r)) such that
    z op y (mod 2^32)
is in (s op y).

Some overflow checking is needed.
Some preliminary work to store the ikind for abstract integer values.
We want to have the ikind available for all abstract integer values, when
we perform operations on them, but we don't really want to store the
ikind redundantly in each of the integer domain implementations.

We introduce a IntDomLifter, that takes a integer domain implementation
and adds the ikind information to it. In the future, this
IntDomLifter should pass the ikind to the domain operations that need it.
This is the reason why we need a separate signature Z for instantiations
of the IntDomLifter which is different from the signature S.
In the signature Z only the creation of abstract value expects an ikind,
but - unlike S - the integer operations itself will not require it.

Needs to be reworked inorder not to fail test cases.
@vogler
Copy link
Collaborator

vogler commented Oct 21, 2020

Instead of copying module type S to module type Z, it'd be better to just include the common values.

@vogler
Copy link
Collaborator

vogler commented Oct 21, 2020

Instead of carrying ikind around we could add it as an argument for operations. Adding an indirection and additional 64 bit for ikind for every abstract int might be costly.
Since a lot of bot/top handling is shared, it's maybe a good idea anyway to merge operations into an unop/binop which gets the operation and ikind.
If we still want to keep the specialized functions like add, sub etc., they could be added by some functor.

@jerhard
Copy link
Member Author

jerhard commented Oct 22, 2020

Instead of carrying ikind around we could add it as an argument for operations.

I think there are places besides the arithmetic operations where we want to know the ikind. E.g. if we perform a widen on ints, it would be useful to know what the ikind of the integers is that is being widened.

@jerhard jerhard added the sv-comp SV-COMP (analyses, results), witnesses label Nov 24, 2020
@jerhard jerhard changed the title WIP: Add proper handling of integer-overflows Add proper handling of integer-overflows Nov 25, 2020
@michael-schwarz
Copy link
Member

michael-schwarz commented Nov 25, 2020

This causes sv-comp/sv-benchmarks/c/loops/linear_search.c to unsoundly claim that the error is not reached.
Edit: This seems to be UB in the benchmark, see sosy-lab/sv-benchmarks#1241

@michael-schwarz
Copy link
Member

I pushed a problematic example where the ikinds don't line up:

    signed char* s = malloc(10*sizeof(signed char));
    s[0] = -5;

    unsigned char* us = s;
    *us = 12;

This is valid C, and GCC also doesn't complain, but we currently fail with - Fatal error: exception Failure("ikinds signed char and unsigned char are incompatible. Values: (-5) and (12)")

This is this issue we discussed where it would be necessary to go to supertop for Int of different ikind.

@michael-schwarz michael-schwarz merged commit e602b97 into master Nov 26, 2020
@michael-schwarz michael-schwarz deleted the overflow_handling branch November 26, 2020 12:51
@sim642 sim642 added this to the SV-COMP 2021 milestone Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sv-comp SV-COMP (analyses, results), witnesses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants