Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translation of __builtin_*_overflow functions #684

Merged
merged 11 commits into from
Oct 12, 2024

Conversation

schuessf
Copy link
Contributor

@schuessf schuessf commented Oct 8, 2024

In GNU C there are functions to check for overflows of arithmetic operations (__builtin_*_overflow). These functions perform an arithmetic operation on the first two arguments (without producing any overflows), write the result to the third argument and return whether an overflow would occur using the normal arithmetic operation.
Currently, we simply overapproximate the return value of these functions. This is in general unsound as we do not consider that the third argument changes at all. Also this is quite imprecise, which led to 55 unknown results in SV-COMP 24.

Therefore this PR handles these functions properly. This is done in the following way:

  • First we calculate the result of the arithmetic operation (without any overflows). For the integer translation this is the "usual" operations, while for the bitvector translation we choose a large enough bitvector to store the result (e.g. 64bit for the multiplication of two 32bit integers).
  • Then we have to shrink this result to fit in the result type again, s.t. we can write it to the third argument (Note: This also uses the optimization to avoid "unnecessary" heap variables, if the third argument is of the form &x. Therefore this depends on Fix translation of atomic functions #685).
  • Then we return 1 iff the original result did fit in the result type.

For each of the three cases I added a new method to ExpressionTranslation accordingly, as these cases differ between the integer translation and the bitvector translation.

@schuessf schuessf changed the title Fix translation for __builtin_*_overflow functions Fix translation of __builtin_*_overflow functions Oct 10, 2024
Copy link
Contributor

@maul-esel maul-esel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing and fixing this! I left some minor comments and questions, but overall 👍

@schuessf schuessf merged commit 2d3a79f into dev Oct 12, 2024
3 of 4 checks passed
@schuessf schuessf deleted the wip/fs/builtin-overflow branch October 12, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants