diff options
author | Mike Stump <mrs@apple.com> | 2009-05-30 03:56:50 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-05-30 03:56:50 +0000 |
commit | 4572baba9d18c275968ac113fd73b0e3c77cccb8 (patch) | |
tree | 44e7e7aecb0a94e4684285446e7f4fef347fa12e /lib/AST/ExprConstant.cpp | |
parent | c8f2c61f4f667c2bc3e4e74b274fa397a4232393 (diff) |
Improve __builtin_nanf support; we now can deal with them as constants.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72607 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index d0d8b81bab..eac73eaf2f 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -18,6 +18,8 @@ #include "clang/AST/ASTDiagnostic.h" #include "clang/Basic/TargetInfo.h" #include "llvm/Support/Compiler.h" +#include <cstring> + using namespace clang; using llvm::APSInt; using llvm::APFloat; @@ -1311,14 +1313,23 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { 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 + // If this is __builtin_nan() turn this into a 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. + if (!S->isWide()) { const llvm::fltSemantics &Sem = Info.Ctx.getFloatTypeSemantics(E->getType()); - Result = llvm::APFloat::getNaN(Sem); + char *s = (char *)malloc (S->getByteLength()+1); + memcpy(s, S->getStrData(), S->getByteLength()); + s[S->getByteLength()] = 0; + long l; + char *endp; + l = strtol(S->getStrData(), &endp, 0); + if (endp != (S->getStrData() + S->getByteLength())) + return false; + unsigned type = (unsigned int)l;; + Result = llvm::APFloat::getNaN(Sem, false, type); return true; } } |