<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85947>85947</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLDB] Operators <= and >= return a wrong result when comparing with a floating point NaN in expression evaluation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lldb
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kuilpd
</td>
</tr>
</table>
<pre>
Operators `<=` and `>=` are defined through `operator<` ([Scalar.cpp:857](https://github.com/llvm/llvm-project/blob/7812fcf3d79ef7fe9ec6bcdfc8fd9143864956cb/lldb/source/Utility/Scalar.cpp#L857)), which in turn calls a compare function. If the compare function returns `cmpUnordered`, `operator<` return `false`, which gets negated and operators `<=` and `>=` return an incorrect value `true`.
Source file with 2 comparisons, to see the operator results from the compiler:
```
#include <limits>
int main() {
float fnan = std::numeric_limits<float>::quiet_NaN();
double dnan = std::numeric_limits<double>::quiet_NaN();
bool float_comparison = 1.0f <= fnan;
bool double_comparison = 1.0 >= dnan;
return 0;
}
```
LLDB log:
```
(lldb) expr float_comparison
(bool) $0 = false
(lldb) expr double_comparison
(bool) $1 = false
(lldb) expr 1.0f <= fnan
(bool) $2 = true
(lldb) expr 1.0 >= dnan
(bool) $3 = true
```
Maybe operators `<=` and `>=` should analyze result separately, like in [APFloat.h:1240](https://github.com/llvm/llvm-project/blob/7812fcf3d79ef7fe9ec6bcdfc8fd9143864956cb/llvm/include/llvm/ADT/APFloat.h#L1240).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU1v4zYQ_TX0ZVBBIvV50MGJa6BAmhbY7jmgqJHELk2qJLVp-usLknaSJl5selnAkCyK8_TmPc4Md07OGrEn1Q2pDju--cXY_ssm1TruBjM-9b-taLk31gGpc8JuCTuQOgeux7Tw82XBIow4SY0j-MWabV7CBnMOD5F1DoS2pLr5JLjiNhPrSti-rRpSHQhtF-9XR9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