aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-10-06 06:31:58 +0000
committerChris Lattner <sabre@nondot.org>2008-10-06 06:31:58 +0000
commit9e62171a25e3a08fb5c49fb370f83faf5ae786f5 (patch)
treeea9acdeb6f6083e2e2be7fb89b80daebec44d296
parent1f32999ec79a980576e100d64d5f3267eb19ea49 (diff)
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
-rw-r--r--lib/AST/ExprConstant.cpp14
-rw-r--r--lib/CodeGen/CGBuiltin.cpp23
2 files changed, 19 insertions, 18 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index c20cf4c0c5..2b92cc7355 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -556,6 +556,20 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
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;
}
}
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index 10b47f1a48..99a3463a22 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -46,11 +46,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
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 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
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: {