-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLDB] Fix operators <= and >= returning a wrong result when comparin…
…g to a floating point NaN (#108060) Implement operators `<=` and `>=` to explicitly check the comparison results to be `cmpLessThan` or `cmpEqual` instead of negating the result of `operators<`. Fixes #85947
- Loading branch information
Showing
5 changed files
with
168 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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,3 @@ | ||
CXX_SOURCES := main.cpp | ||
|
||
include Makefile.rules |
This file contains 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,130 @@ | ||
""" | ||
Test floating point expressions with zero, NaN, dernormalized and infinite | ||
numbers. | ||
""" | ||
|
||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class FPNaNTestCase(TestBase): | ||
def setUp(self): | ||
# Call super's setUp(). | ||
TestBase.setUp(self) | ||
# Find the line number to break inside main(). | ||
self.line = line_number("main.cpp", "// Set break point at this line.") | ||
|
||
def test(self): | ||
self.build() | ||
exe = self.getBuildArtifact("a.out") | ||
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) | ||
|
||
# Break inside the main. | ||
lldbutil.run_break_set_by_file_and_line( | ||
self, "main.cpp", self.line, num_expected_locations=1 | ||
) | ||
|
||
self.runCmd("run", RUN_SUCCEEDED) | ||
# Zero and denorm | ||
self.expect( | ||
"expr +0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "0"], | ||
) | ||
self.expect( | ||
"expr -0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "0"], | ||
) | ||
self.expect( | ||
"expr 0.0 / 0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "NaN"], | ||
) | ||
self.expect( | ||
"expr 0 / 0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "NaN"], | ||
) | ||
self.expect( | ||
"expr 1 / +0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "+Inf"], | ||
) | ||
self.expect( | ||
"expr 1 / -0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "-Inf"], | ||
) | ||
self.expect( | ||
"expr +0.0 / +0.0 != +0.0 / +0.0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "true"], | ||
) | ||
self.expect( | ||
"expr -1.f * 0", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["float", "-0"], | ||
) | ||
self.expect( | ||
"expr 0x0.123p-1", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["double", "0.0355224609375"], | ||
) | ||
# NaN | ||
self.expect( | ||
"expr fnan < fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr fnan <= fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr fnan > fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr fnan >= fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr fnan == fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr fnan != fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "true"], | ||
) | ||
self.expect( | ||
"expr 1.0 <= fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr 1.0f < fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "false"], | ||
) | ||
self.expect( | ||
"expr 1.0f != fnan", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["bool", "true"], | ||
) | ||
self.expect( | ||
"expr (unsigned int) fdenorm", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["int", "0"], | ||
) | ||
self.expect( | ||
"expr (unsigned int) (1.0f + fdenorm)", | ||
VARIABLES_DISPLAYED_CORRECTLY, | ||
substrs=["int", "1"], | ||
) |
This file contains 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,8 @@ | ||
#include <limits> | ||
|
||
int main() { | ||
float fnan = std::numeric_limits<float>::quiet_NaN(); | ||
float fdenorm = std::numeric_limits<float>::denorm_min(); | ||
|
||
// Set break point at this line. | ||
} |