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

Disable Divide by 0 Checks for Floats #3327

Open
cvick32 opened this issue Jul 5, 2024 · 4 comments
Open

Disable Divide by 0 Checks for Floats #3327

cvick32 opened this issue Jul 5, 2024 · 4 comments
Assignees
Labels
[C] Internal Tracks some internal work. I.e.: Users should not be affected. T-CBMC Issue related to an existing CBMC issue

Comments

@cvick32
Copy link

cvick32 commented Jul 5, 2024

Proposed change: Remove divide by 0 checks for floating point numbers, as they are well-defined in Rust? A similar change for +/- Inf was made in this PR.

Motivation: This change would eliminate false positives in verification failures.

@cvick32 cvick32 added the [C] Internal Tracks some internal work. I.e.: Users should not be affected. label Jul 5, 2024
@tautschnig
Copy link
Member

Would you have a concrete example to use as test? With CBMC v6 (merged in #2995) we do not enable division-by-zero checks for floating point numbers by default anymore, so this one might as well quietly have been fixed by #2995.

@cvick32
Copy link
Author

cvick32 commented Aug 1, 2024

Kani previously found a counterexample on this function using this harness:

fn div_euclid_f64(lhs: f64, rhs: f64) -> f64 {
    let q = (lhs / rhs).trunc();
    if lhs % rhs < 0.0 {
        if rhs > 0.0 {
            q - 1.0
        } else {
            q + 1.0
        }
    } else {
        q
    }
}

#[kani::proof]
fn kani_harness_div_euclid_f64() {
  let lhs: f64 = kani::any();
  let rhs: f64 = kani::any();
  div_euclid_f64(lhs, rhs);
}

Kani's output summary from running cargo kani --harness kani_harness_div_euclid_f64:

SUMMARY:
 ** 4 of 62 failed
Failed Checks: division by zero
 File: "src/epoch/mod.rs", line 1186, in epoch::div_euclid_f64
Failed Checks: NaN on division
 File: "src/epoch/mod.rs", line 1186, in epoch::div_euclid_f64
Failed Checks: arithmetic overflow on floating-point division
 File: "src/epoch/mod.rs", line 1186, in epoch::div_euclid_f64
Failed Checks: division by zero
 File: "src/epoch/mod.rs", line 1187, in epoch::div_euclid_f64

@tautschnig
Copy link
Member

Hmm, looks like we have a bug on the CBMC side in that floating-point division does not have checks enabled by default anymore, but floating-point remainder still has those.

@tautschnig tautschnig assigned tautschnig and unassigned cvick32 Aug 1, 2024
@tautschnig tautschnig added the T-CBMC Issue related to an existing CBMC issue label Aug 1, 2024
@tautschnig
Copy link
Member

I intend to fold the fix for this on the CBMC side into diffblue/cbmc#7885 as, until that work is completed, any floating-point remainder operations are very questionable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Internal Tracks some internal work. I.e.: Users should not be affected. T-CBMC Issue related to an existing CBMC issue
Projects
None yet
Development

No branches or pull requests

2 participants