]> granicus.if.org Git - clang/commitdiff
A not equal for an unordered relation should return true as specified in IEEE-754...
authorMon P Wang <wangmp@apple.com>
Thu, 29 Apr 2010 05:53:29 +0000 (05:53 +0000)
committerMon P Wang <wangmp@apple.com>
Thu, 29 Apr 2010 05:53:29 +0000 (05:53 +0000)
NAN != NAN ? 1 : 0 should return 1.  Also fix the case for complex.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102598 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/CodeGen/const-unordered-compare.c [new file with mode: 0644]

index 1c2b76eede680ddc91e7c2702ba943652a1d0969..c1a42d88fffa8287e4b8db524597b41b79d10834 100644 (file)
@@ -1119,9 +1119,11 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
         assert(E->getOpcode() == BinaryOperator::NE &&
                "Invalid complex comparison.");
         return Success(((CR_r == APFloat::cmpGreaterThan ||
-                         CR_r == APFloat::cmpLessThan) &&
+                         CR_r == APFloat::cmpLessThan ||
+                         CR_r == APFloat::cmpUnordered) ||
                         (CR_i == APFloat::cmpGreaterThan ||
-                         CR_i == APFloat::cmpLessThan)), E);
+                         CR_i == APFloat::cmpLessThan ||
+                         CR_i == APFloat::cmpUnordered)), E);
       }
     } else {
       if (E->getOpcode() == BinaryOperator::EQ)
@@ -1164,7 +1166,8 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
       return Success(CR == APFloat::cmpEqual, E);
     case BinaryOperator::NE:
       return Success(CR == APFloat::cmpGreaterThan
-                     || CR == APFloat::cmpLessThan, E);
+                     || CR == APFloat::cmpLessThan
+                     || CR == APFloat::cmpUnordered, E);
     }
   }
 
diff --git a/test/CodeGen/const-unordered-compare.c b/test/CodeGen/const-unordered-compare.c
new file mode 100644 (file)
index 0000000..ac7d35b
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// Checks folding of an unordered comparison
+int nan_ne_check() {
+  // CHECK: store i32 1
+  return (__builtin_nanf("") != __builtin_nanf("")) ? 1 : 0;
+}