[cfe-commits] r57157 - in /cfe/trunk/lib: AST/ExprConstant.cpp CodeGen/CGBuiltin.cpp

Chris Lattner sabre at nondot.org
Sun Oct 5 23:31:58 PDT 2008


Author: lattner
Date: Mon Oct  6 01:31:58 2008
New Revision: 57157

URL: http://llvm.org/viewvc/llvm-project?rev=57157&view=rev
Log:
Move handling of __builtin_nan("") out of CGBuiltin.cpp into ExprConstant.cpp


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=57157&r1=57156&r2=57157&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct  6 01:31:58 2008
@@ -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;
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=57157&r1=57156&r2=57157&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct  6 01:31:58 2008
@@ -46,11 +46,14 @@
   case Builtin::BI__builtin_inf:
   case Builtin::BI__builtin_inff:
   case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_nan:
+  case Builtin::BI__builtin_nanf:
+  case Builtin::BI__builtin_nanl:
   case Builtin::BI__builtin_classify_type:
   case Builtin::BI__builtin_constant_p: {
     APValue Result;
-    bool IsCst = E->tryEvaluate(Result, CGM.getContext());
-    assert(IsCst && "These must all be constants!");
+    if (!E->tryEvaluate(Result, CGM.getContext()))
+      break;  // Not a constant, expand below.
     
     if (Result.isInt())
       return RValue::get(llvm::ConstantInt::get(Result.getInt()));
@@ -231,22 +234,6 @@
     return RValue::get(Builder.CreateCall(F));
   }
 
-  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 just
-    // call libm nan.
-    if (const StringLiteral *S = 
-          dyn_cast<StringLiteral>(E->getArg(0)->IgnoreParenCasts())) {
-      if (!S->isWide() && S->getByteLength() == 0) { // empty string.
-        const llvm::fltSemantics &Sem = 
-          CGM.getContext().getFloatTypeSemantics(E->getType());
-        return RValue::get(ConstantFP::get(APFloat::getNaN(Sem)));
-      }
-    }
-    // Otherwise, call libm 'nan'.
-    break;
-  }
   case Builtin::BI__builtin_powi:
   case Builtin::BI__builtin_powif:
   case Builtin::BI__builtin_powil: {





More information about the cfe-commits mailing list