summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-10-06 05:59:01 +0000
committerChris Lattner <sabre@nondot.org>2008-10-06 05:59:01 +0000
commite50e90142ef1913f86f39a537817c66b627720d3 (patch)
tree76ca6f1f0a4146e31c26eb4b8562a6833eb8e200 /clang/lib/CodeGen/CGExprConstant.cpp
parent37346e081c47a7a9921baf568cd4299cb85813b5 (diff)
downloadbcm5719-llvm-e50e90142ef1913f86f39a537817c66b627720d3.tar.gz
bcm5719-llvm-e50e90142ef1913f86f39a537817c66b627720d3.zip
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'. llvm-svn: 57155
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp31
1 files changed, 8 insertions, 23 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index e0c39c9cbac..50f0d122405 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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<const ImplicitCastExpr>(E->getCallee()))
- if (const DeclRefExpr *DRExpr =
- dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr()))
- if (const FunctionDecl *FDecl =
- dyn_cast<const FunctionDecl>(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.
OpenPOWER on IntegriCloud