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

Interval Analysis for Floating-point values #761

Merged
merged 62 commits into from
Jul 27, 2022

Conversation

Dudeldu
Copy link
Contributor

@Dudeldu Dudeldu commented Jun 16, 2022

Adds basic interval analysis for float and double values (Related to Issue: #734)

We implemented an interval analysis for floating-point values. In order to capture operations leading to unrepresentable values and their rounding mode dependent representations in the concrete execution, all abstract operations overestimate the worst case interval by using the rounding mode that creates the largest possible interval on both bounds.

Introduces following settings:

  • ana.float.interval : Enables the float interval domain (default: disabled)
    • arithmetic operations on floats (+, -, *, /)
    • casts between ints and floats (and vice versa)
    • builtins for is_nan, is_normal, is_finite, sign, is_inf (although we can not use the captured information for more precise information inside branching)
    • abstractions for different math functions like cos, tan, sin ,...
  • __attribute__((goblint_precision("no-float-interval"))): to disable/enable the float domain on a node/function level
  • warn.float: Adds warnings related to the analysis results (default: enabled)
    • warn on equality/inequality check on floats
    • warn on operations done on values that could be +/- Infinity or NaN
    • warn in places where where loos track of the exact information (the point where the interval no longer only contains one value)

Dudeldu and others added 21 commits May 6, 2022 17:14
* add some implementation for the "norm" method in FloatDomain, however at the moment incorrect

Now, the norm method is called at eval_binop and successfully fails,
which currently is wanted like this, just to test that it works.
We need to change it now s.t. it prints a warning instead of an error.

* Rework norm slightly s.t. it uses set_overflow_flag now, which however is still incorrect

* Add FloatMessage message category in messageCategory.ml

Also add it in options.schema.json

* Add a todo note for later in sarifRules.ml

* Add a regression test for float that expects a warning for division by zeron / infinity

* Clean up floatDomain.ml slightly: Remove TODOs/FIXMEs and inline message warning

* Fix regression test naming and merge them together

* Remove FloatMessage module in messageCategory.ml, as it's not needed anymore

* Remove todo message

* Remove todo message

* Remove todo comments and/or clean up some stuff

* Clean up float domain etc. with fixes from PR

- Better warning message
- use is_top function instead of checking for None in the domain
- revert unrelated change
- make 'warn.float' option not a default option
- make regression test as minimal as possible

* In floatDomain.ml, rearrange of_const function s.t. it finds the norm function

* Add float warning parameter to 03-infinity_or_nan.c regression test
- lattice related functions (leq, widen, narrow, join, meet)
 - arithmetic operations (add, sub, mul, div)
 - casts (f2i, i2f)
* Support FFloat and FDouble
- Implement float operators in C
- Support FFloat and FDouble

* Allow using DBL_MIN, DBL_MAX
Some compilers specifiy DBL_MIN, DBL_MAX as long double.
As we do not support long double in neither cil nor goblint itself, but want to use DBL_MIN, DBL_MAX, we have no other option than to explicitly check for this two cases
@michael-schwarz michael-schwarz self-requested a review June 16, 2022 11:48
@michael-schwarz michael-schwarz added student-job practical-course Practical Course at TUM sv-comp SV-COMP (analyses, results), witnesses labels Jun 16, 2022
@michael-schwarz
Copy link
Member

Nice, thanks for the PR! 🚀 I hope to find some time to review it this weekend!

I resolved the merge conflicts on the benchmarking machine, and started a run of all of sv-comp on that machine (2min timeout). I'll send you the results on slack.
I guess in the meanwhile, it would make sense to keep merging the upstream master into yours from time-to-time so they don't diverge too much. (nothing fancy like rebasing needed, we do this with our branches all the time as well).

@jerhard
Copy link
Member

jerhard commented Jul 14, 2022

The missing content is due to the float domain being disabled at that point. Therefore we have nothing to show. This should be the exact same behaviour as if you disable all integer domains with --disable ana.int.def_exc

Ah, indeed I did not notice that.

@FelixKrayer FelixKrayer removed their assignment Jul 18, 2022
Copy link
Member

@michael-schwarz michael-schwarz left a comment

Choose a reason for hiding this comment

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

Looks good to be merged from my perspective! Any more comments @sim642 @stilscher @jerhard?

@sim642 sim642 self-requested a review July 25, 2022 17:55
@jerhard jerhard self-requested a review July 26, 2022 09:25
src/analyses/base.ml Outdated Show resolved Hide resolved
src/cdomains/floatDomain.ml Outdated Show resolved Hide resolved
| Interval (r1, r2) when not (is_exact result) && is_exact_before ->
Messages.warn
~category:Messages.Category.Float
~tags:[CWE 197; CWE 681; CWE 1339]
Copy link
Member

Choose a reason for hiding this comment

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

Are CWE 197 and CWE 681 really applicable for binary operations on floats?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I don't think those two really apply here either.

| Top ->
Messages.warn
~category:Messages.Category.Float
~tags:[CWE 197; CWE 681; CWE 1339]
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above.

@michael-schwarz michael-schwarz merged commit cfab02b into goblint:master Jul 27, 2022
sim642 added a commit to sim642/opam-repository that referenced this pull request Aug 18, 2022
CHANGES:

Goblint "lean" release after a lot of cleanup.

* Remove unmaintained analyses: OSEK, ARINC, shapes, containment, deadlocksByRaces (goblint/analyzer#460, goblint/analyzer#736, goblint/analyzer#812, goblint/analyzer#474).
* Add interactive analysis (goblint/analyzer#391).
* Add server mode (goblint/analyzer#522).
* Add Compilation Database support (goblint/analyzer#406, goblint/analyzer#448).
* Add floating point domain, unrolled array domain and improved struct domains (goblint/analyzer#734, goblint/analyzer#761, goblint/analyzer#577, goblint/analyzer#419).
* Add static loop unrolling and heap variable unrolling (goblint/analyzer#563, goblint/analyzer#722).
* Improve race detection with may-happen-in-parallel analysis (goblint/analyzer#529, goblint/analyzer#518, goblint/analyzer#595).
* Reimplement lockset and deadlock analyses (goblint/analyzer#659, goblint/analyzer#662, goblint/analyzer#650, goblint/analyzer#655).
* Add pthread extraction to Promela (goblint/analyzer#220).
* Add location spans to output (goblint/analyzer#428, goblint/analyzer#449).
* Improve race reporting (goblint/analyzer#550, goblint/analyzer#551).
* Improve dead code reporting (goblint/analyzer#94, goblint/analyzer#353, goblint/analyzer#785).
* Refactor warnings (goblint/analyzer#55, goblint/analyzer#783).
* Add JSON schema for configuration (goblint/analyzer#476, goblint/analyzer#499).
* Refactor option names (goblint/analyzer#28, goblint/analyzer#192, goblint/analyzer#516, goblint/analyzer#675).
* Add bash completion (goblint/analyzer#669).
* Add OCaml 4.13 and 4.14 support, remove OCaml 4.09 support (goblint/analyzer#503, goblint/analyzer#672).
sim642 added a commit to sim642/opam-repository that referenced this pull request Aug 18, 2022
CHANGES:

Goblint "lean" release after a lot of cleanup.

* Remove unmaintained analyses: OSEK, ARINC, shapes, containment, deadlocksByRaces (goblint/analyzer#460, goblint/analyzer#736, goblint/analyzer#812, goblint/analyzer#474).
* Add interactive analysis (goblint/analyzer#391).
* Add server mode (goblint/analyzer#522).
* Add Compilation Database support (goblint/analyzer#406, goblint/analyzer#448).
* Add floating point domain, unrolled array domain and improved struct domains (goblint/analyzer#734, goblint/analyzer#761, goblint/analyzer#577, goblint/analyzer#419).
* Add static loop unrolling and heap variable unrolling (goblint/analyzer#563, goblint/analyzer#722).
* Improve race detection with may-happen-in-parallel analysis (goblint/analyzer#529, goblint/analyzer#518, goblint/analyzer#595).
* Reimplement lockset and deadlock analyses (goblint/analyzer#659, goblint/analyzer#662, goblint/analyzer#650, goblint/analyzer#655).
* Add pthread extraction to Promela (goblint/analyzer#220).
* Add location spans to output (goblint/analyzer#428, goblint/analyzer#449).
* Improve race reporting (goblint/analyzer#550, goblint/analyzer#551).
* Improve dead code reporting (goblint/analyzer#94, goblint/analyzer#353, goblint/analyzer#785).
* Refactor warnings (goblint/analyzer#55, goblint/analyzer#783).
* Add JSON schema for configuration (goblint/analyzer#476, goblint/analyzer#499).
* Refactor option names (goblint/analyzer#28, goblint/analyzer#192, goblint/analyzer#516, goblint/analyzer#675).
* Add bash completion (goblint/analyzer#669).
* Add OCaml 4.13 and 4.14 support, remove OCaml 4.09 support (goblint/analyzer#503, goblint/analyzer#672).
@sim642 sim642 mentioned this pull request Aug 19, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature practical-course Practical Course at TUM precision student-job sv-comp SV-COMP (analyses, results), witnesses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants