-
Notifications
You must be signed in to change notification settings - Fork 286
Fix --nan-check false positive for finite/+INFINITY division #8745
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
Open
tautschnig
wants to merge
1
commit into
diffblue:develop
Choose a base branch
from
tautschnig:fix-8634-inf-nan
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Test case for bug fix: finite / +INFINITY should NOT trigger --nan-check | ||
| // According to IEEE 754-2019 Section 6.1: "division(x, ∞) for finite x" | ||
| // should produce 0.0, not NaN. Hence, none of the operations below should | ||
| // trigger nan-check assertions. | ||
|
|
||
| #include <assert.h> | ||
| #include <math.h> | ||
| #include <stdint.h> | ||
|
|
||
| union float_bits | ||
| { | ||
| uint32_t u; | ||
| float f; | ||
| }; | ||
|
|
||
| int main(void) | ||
| { | ||
| // Test case 1: Using union to create +INFINITY as mentioned in the bug report | ||
| union float_bits a, b; | ||
| a.u = 1065353216; // 1.0 | ||
| b.u = 2139095040; // +INF | ||
|
|
||
| // This should produce 0.0, not NaN - should NOT trigger nan-check failure | ||
| float result1 = a.f / b.f; | ||
| assert(fpclassify(result1) == FP_ZERO && !signbit(result1)); | ||
|
|
||
| // Test case 2: Direct assignment as mentioned in the bug report | ||
| float x = 1.0f; | ||
| float y = INFINITY; | ||
| float result2 = x / y; | ||
| assert(fpclassify(result2) == FP_ZERO && !signbit(result2)); | ||
|
|
||
| // Test case 3: Negative finite / infinity should also be 0.0 (negative zero) | ||
| float neg_x = -1.0f; | ||
| float result3 = neg_x / INFINITY; | ||
| assert(fpclassify(result3) == FP_ZERO && signbit(result3)); | ||
|
|
||
| // Test case 4: Various finite values divided by infinity | ||
| float nd_positive = __VERIFIER_nondet_float(); | ||
| __CPROVER_assume(isfinite(nd_positive) && nd_positive > 0); | ||
| float result4 = nd_positive / INFINITY; | ||
| assert(fpclassify(result4) == FP_ZERO && !signbit(result4)); | ||
| float nd_negative = __VERIFIER_nondet_float(); | ||
| __CPROVER_assume(isfinite(nd_negative) && nd_negative < 0); | ||
| float result5 = nd_negative / INFINITY; | ||
| assert(fpclassify(result5) == FP_ZERO && signbit(result5)); | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| CORE no-new-smt broken-cprover-smt-backend | ||
| main.c | ||
| --nan-check | ||
| ^VERIFICATION SUCCESSFUL$ | ||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This test verifies that dividing a finite float by +INFINITY does NOT | ||
| incorrectly trigger a NaN check failure (bug fix). According to IEEE 754-2019 | ||
| Section 6.1, division(x, ∞) for finite x = 0.0. Only inf/inf should produce NaN | ||
| (which is covered in test float-inf-div-inf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Test case for bug fix: inf / inf SHOULD trigger --nan-check failure | ||
| // According to IEEE 754-2019, inf/inf produces NaN | ||
|
|
||
| #include <assert.h> | ||
| #include <math.h> | ||
|
|
||
| int main(void) | ||
| { | ||
| // Ensure infinity / infinity produces NaN and triggers nan-check | ||
| float inf1 = INFINITY; | ||
| float inf2 = INFINITY; | ||
| float result1 = inf1 / inf2; // Should trigger NaN check | ||
| assert(isnan(result1)); | ||
|
|
||
| // Also test -inf / inf | ||
| float result2 = (-INFINITY) / INFINITY; // Should trigger NaN check | ||
| assert(isnan(result2)); | ||
|
|
||
| // And inf / -inf | ||
| float result3 = INFINITY / (-INFINITY); // Should trigger NaN check | ||
| assert(isnan(result3)); | ||
|
|
||
| // And -inf / -inf | ||
| float result4 = (-INFINITY) / (-INFINITY); // Should trigger NaN check | ||
| assert(isnan(result4)); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| CORE | ||
| main.c | ||
| --nan-check | ||
| \[main.NaN.1\] line \d+ NaN on / in inf1 / inf2: FAILURE | ||
| \[main.NaN.2\] line \d+ NaN on / in -(\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(\(float\)1\.000000e\+300\)) / (\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(float\)1\.000000e\+300): FAILURE | ||
| \[main.NaN.3\] line \d+ NaN on / in (\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(float\)1\.000000e\+300) / -(\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(\(float\)1\.000000e\+300\)): FAILURE | ||
| \[main.NaN.4\] line \d+ NaN on / in -(\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(\(float\)1\.000000e\+300\)) / -(\+INFINITY|return_value___builtin_(huge_val|inf)f\$\d+|\(\(float\)1\.000000e\+300\)): FAILURE | ||
| ^\*\* 4 of \d+ failed | ||
| ^VERIFICATION FAILED$ | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This test verifies that inf/inf correctly triggers NaN check failures. | ||
| According to IEEE 754-2019, inf/inf = NaN. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| CORE | ||
| fp-isNegative1.smt2 | ||
|
|
||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| ^unsat$ | ||
| -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| (set-logic FP) | ||
|
|
||
| ; positive number | ||
| (define-fun pos () Float32 (fp #b0 #b10000000 #b00000000000000000000000)) | ||
|
|
||
| ; negative number | ||
| (define-fun neg () Float32 (fp #b1 #b10000000 #b00000000000000000000000)) | ||
|
|
||
| ; fp.isNegative should be true for neg, false for pos | ||
| (assert (not (fp.isNegative neg))) | ||
| (check-sat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| CORE | ||
| fp-isPositive1.smt2 | ||
|
|
||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| ^unsat$ | ||
| -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| (set-logic FP) | ||
|
|
||
| ; positive number | ||
| (define-fun pos () Float32 (fp #b0 #b10000000 #b00000000000000000000000)) | ||
|
|
||
| ; negative number | ||
| (define-fun neg () Float32 (fp #b1 #b10000000 #b00000000000000000000000)) | ||
|
|
||
| ; fp.isPositive should be true for pos, false for neg | ||
| (assert (not (fp.isPositive pos))) | ||
| (check-sat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.