aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-11-22 02:34:39 +0000
committerAnders Carlsson <andersca@mac.com>2008-11-22 02:34:39 +0000
commitbcf6225ad69ea388e287f952981fd076636991b2 (patch)
treee06f19b1346a346ba6e661e99f83120e399f7b37 /lib/CodeGen/CGExprConstant.cpp
parent74d15dfd183b2082e8a5d4dfbf66bd861b220901 (diff)
Use tryEvaluate for constant exprs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59857 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 4ae7d90772..152207cabf 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -25,6 +25,8 @@
using namespace clang;
using namespace CodeGen;
+#define USE_TRY_EVALUATE
+
namespace {
class VISIBILITY_HIDDEN ConstExprEmitter :
public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
@@ -49,6 +51,7 @@ public:
return Visit(PE->getSubExpr());
}
+#ifndef USE_TRY_EVALUATE
// Leaves
llvm::Constant *VisitIntegerLiteral(const IntegerLiteral *E) {
return llvm::ConstantInt::get(E->getValue());
@@ -65,13 +68,14 @@ public:
llvm::Constant *VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) {
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
+#endif
llvm::Constant *VisitObjCStringLiteral(const ObjCStringLiteral *E) {
std::string S(E->getString()->getStrData(),
E->getString()->getByteLength());
llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(S);
return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
}
-
+
llvm::Constant *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
return Visit(E->getInitializer());
}
@@ -376,6 +380,7 @@ public:
return llvm::ConstantArray::get(CGM.GetStringForStringLiteral(E), false);
}
+#ifndef USE_TRY_EVALUATE
llvm::Constant *VisitDeclRefExpr(DeclRefExpr *E) {
const NamedDecl *Decl = E->getDecl();
if (const EnumConstantDecl *EC = dyn_cast<EnumConstantDecl>(Decl))
@@ -387,7 +392,8 @@ public:
llvm::Constant *VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
return EmitSizeAlignOf(E->getTypeOfArgument(), E->getType(), E->isSizeOf());
}
-
+#endif
+
llvm::Constant *VisitAddrLabelExpr(const AddrLabelExpr *E) {
assert(CGF && "Invalid address of label expression outside function.");
llvm::Constant *C =
@@ -396,6 +402,7 @@ public:
return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType()));
}
+#ifndef USE_TRY_EVALUATE
// Unary operators
llvm::Constant *VisitUnaryPlus(const UnaryOperator *E) {
return Visit(E->getSubExpr());
@@ -426,6 +433,8 @@ public:
return llvm::ConstantExpr::getZExt(SubExpr, ConvertType(E->getType()));
}
+#endif
+
llvm::Constant *VisitUnaryAddrOf(const UnaryOperator *E) {
return EmitLValue(E->getSubExpr());
}
@@ -444,6 +453,7 @@ public:
}
// Binary operators
+#ifndef USE_TRY_EVALUATE
llvm::Constant *VisitBinOr(const BinaryOperator *E) {
llvm::Constant *LHS = Visit(E->getLHS());
llvm::Constant *RHS = Visit(E->getRHS());
@@ -607,6 +617,7 @@ public:
return Visit(E->getRHS());
}
+#endif
llvm::Constant *VisitCallExpr(const CallExpr *E) {
APValue Result;