aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-11-22 21:50:49 +0000
committerAnders Carlsson <andersca@mac.com>2008-11-22 21:50:49 +0000
commit6dde0d5dc09f45f4d9508c964703e36fef1a0198 (patch)
tree3c4aab4a46bc8cb6b2982f911f3dc04c70fff198 /lib/AST/ExprConstant.cpp
parent62fd278ff94d1df43652ec30a48fe02bb598e68e (diff)
Case values must be evaluated
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 35cec0f344..5c5adb6a45 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -537,6 +537,7 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
// These need to be handled specially because the operands aren't
// necessarily integral
bool bres;
+ bool isEvaluated = true;
if (HandleConversionToBool(E->getLHS(), bres, Info)) {
// We were able to evaluate the LHS, see if we can get away with not
@@ -548,16 +549,18 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
// We can't evaluate.
return false;
}
+
+ // We did not evaluate the LHS
+ isEvaluated = false;
}
- // FIXME: If we evaluate the RHS, we need to check if the LHS has
- // any side effects.
-
if (bres == (E->getOpcode() == BinaryOperator::LOr) ||
!bres == (E->getOpcode() == BinaryOperator::LAnd)) {
Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
Result = bres;
+ Info.isEvaluated = isEvaluated;
+
return true;
}
@@ -1153,30 +1156,31 @@ APValue ComplexFloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E)
/// any crazy technique (that has nothing to do with language standards) that
/// we want to. If this function returns true, it returns the folded constant
/// in Result.
-bool Expr::Evaluate(APValue &Result, ASTContext &Ctx) const {
+bool Expr::Evaluate(APValue &Result, ASTContext &Ctx, bool *isEvaluated) const {
EvalInfo Info(Ctx);
if (getType()->isIntegerType()) {
llvm::APSInt sInt(32);
- if (EvaluateInteger(this, sInt, Info)) {
- Result = APValue(sInt);
- return true;
- }
+ if (!EvaluateInteger(this, sInt, Info))
+ return false;
+
+ Result = APValue(sInt);
} else if (getType()->isPointerType()) {
- if (EvaluatePointer(this, Result, Info)) {
- return true;
- }
+ if (!EvaluatePointer(this, Result, Info))
+ return false;
} else if (getType()->isRealFloatingType()) {
llvm::APFloat f(0.0);
- if (EvaluateFloat(this, f, Info)) {
- Result = APValue(f);
- return true;
- }
+ if (!EvaluateFloat(this, f, Info))
+ return false;
+
+ Result = APValue(f);
} else if (getType()->isComplexType()) {
- if (EvaluateComplexFloat(this, Result, Info))
- return true;
+ if (!EvaluateComplexFloat(this, Result, Info))
+ return false;
}
-
- return false;
+
+ if (isEvaluated)
+ *isEvaluated = Info.isEvaluated;
+ return true;
}
/// isEvaluatable - Call Evaluate to see if this expression can be constant