Move handling of __builtin_nan("") out of CGBuiltin.cpp into ExprConstant.cpp



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57157 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index c20cf4c..2b92cc7 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -556,6 +556,20 @@
   case Builtin::BI__builtin_infl:
     Result = llvm::APFloat::getInf(Sem);
     return true;
+      
+  case Builtin::BI__builtin_nan:
+  case Builtin::BI__builtin_nanf:
+  case Builtin::BI__builtin_nanl:
+    // If this is __builtin_nan("") turn this into a simple nan, otherwise we
+    // can't constant fold it.
+    if (const StringLiteral *S = 
+        dyn_cast<StringLiteral>(E->getArg(0)->IgnoreParenCasts())) {
+      if (!S->isWide() && S->getByteLength() == 0) { // empty string.
+        Result = llvm::APFloat::getNaN(Sem);
+        return true;
+      }
+    }
+    return false;
   }
 }