From f6b24ea67b5898295e2fc645327837037462a0fd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 6 Oct 2008 05:59:01 +0000 Subject: instead of making codegen try to know about all of the builtins to generate constants for them, just use the constant evaluator to do the job. This also fixes crashes on 'unknown constant builtins'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57155 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index e0c39c9cba..50f0d12240 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -14,6 +14,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "CGObjCRuntime.h" +#include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/StmtVisitor.h" #include "llvm/Constants.h" @@ -608,14 +609,13 @@ public: } llvm::Constant *VisitCallExpr(const CallExpr *E) { - if (const ImplicitCastExpr *IcExpr = - dyn_cast(E->getCallee())) - if (const DeclRefExpr *DRExpr = - dyn_cast(IcExpr->getSubExpr())) - if (const FunctionDecl *FDecl = - dyn_cast(DRExpr->getDecl())) - if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID()) - return EmitBuiltinExpr(builtinID, E); + APValue Result; + if (E->tryEvaluate(Result, CGM.getContext())) { + if (Result.isInt()) + return llvm::ConstantInt::get(Result.getInt()); + if (Result.isFloat()) + return llvm::ConstantFP::get(Result.getFloat()); + } CGM.ErrorUnsupported(E, "constant call expression"); return llvm::Constant::getNullValue(ConvertType(E->getType())); @@ -818,21 +818,6 @@ public: llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); return llvm::UndefValue::get(Ty); } - - llvm::Constant *EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) - { - switch (BuiltinID) { - default: - CGM.ErrorUnsupported(E, "constant builtin function"); - return 0; - case Builtin::BI__builtin_huge_valf: { - const llvm::fltSemantics &Sem = - CGM.getContext().getFloatTypeSemantics(E->getType()); - return llvm::ConstantFP::get(llvm::APFloat::getInf(Sem)); - } - } - } - }; } // end anonymous namespace. -- cgit v1.2.3