Skip to content

[LLDB] Operators <= and >= return a wrong result when comparing with a floating point NaN in expression evaluation #85947

@kuilpd

Description

@kuilpd

Operators <= and >= are defined through operator< (Scalar.cpp:857), 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions