aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-01 06:44:05 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-01 06:44:05 +0000
commit4fdfb0965b396f2778091f7e6c051d17ff9791ba (patch)
treea2da7238499a9474f14af0c188cf011d867b7dc0 /lib/AST/ExprConstant.cpp
parentd26527708b2b2f3b1d747f570efd10149d48364e (diff)
Generate the correct results for the comma expression. Fixes PR3123.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60334 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index b9f3c77363..9eeaa868a5 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -513,14 +513,17 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
if (E->getOpcode() == BinaryOperator::Comma) {
- // Evaluate the side that actually matters; this needs to be
- // handled specially because calling Visit() on the LHS can
- // have strange results when it doesn't have an integral type.
if (!Visit(E->getRHS()))
return false;
-
- if (Info.ShortCircuit)
+
+ if (!Info.ShortCircuit) {
+ // If we can't evaluate the LHS, it must be because it has
+ // side effects.
+ if (!E->getLHS()->isEvaluatable(Info.Ctx))
+ Info.EvalResult.HasSideEffects = true;
+
return Extension(E->getOperatorLoc(), diag::note_comma_in_ice, E);
+ }
return true;
}
@@ -1202,8 +1205,8 @@ bool Expr::Evaluate(APValue &Result, ASTContext &Ctx, bool *isEvaluated) const {
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool Expr::isEvaluatable(ASTContext &Ctx) const {
- APValue V;
- return Evaluate(V, Ctx);
+ EvalResult Result;
+ return Evaluate(Result, Ctx) && !Result.HasSideEffects;
}
APSInt Expr::EvaluateAsInt(ASTContext &Ctx) const {