summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-11-13 00:03:19 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-11-13 00:03:19 +0000
commitc7ec5fcf24308e6151845e9c3e8740f7c8682e06 (patch)
tree8e2915241387c68e0422712972ab9aa0d51d578c /clang/lib/AST/Expr.cpp
parente9c16a6a7939001b3cf1758335c4c4cf5277ebe4 (diff)
downloadbcm5719-llvm-c7ec5fcf24308e6151845e9c3e8740f7c8682e06.tar.gz
bcm5719-llvm-c7ec5fcf24308e6151845e9c3e8740f7c8682e06.zip
Fix bug in constant evaluation exposed by 176.gcc.
- Evaluation of , operator used bogus assumption that LHS could be evaluated as an integral expression even though its type is unspecified. This change is making isICE very permissive of the LHS in non-evaluated contexts because it is not clear what predicate we would use to reject code here. The standard didn't offer me any guidance; opinions? llvm-svn: 59196
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index c54fc40ecb2..e9903df6128 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -870,10 +870,26 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
const BinaryOperator *Exp = cast<BinaryOperator>(this);
llvm::APSInt LHS, RHS;
+ // Comma operator requires special handling.
+ if (Exp->getOpcode() == BinaryOperator::Comma) {
+ // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
+ // *except* when they are contained within a subexpression that is not
+ // evaluated". Note that Assignment can never happen due to constraints
+ // on the LHS subexpr, so we don't need to check it here.
+ if (isEvaluated) {
+ if (Loc) *Loc = getLocStart();
+ return false;
+ }
+
+ // The result of the constant expr is the RHS.
+ return Exp->getRHS()->isIntegerConstantExpr(Result, Ctx, Loc,
+ isEvaluated);
+ }
+
// Initialize result to have correct signedness and width.
Result = llvm::APSInt(static_cast<uint32_t>(Ctx.getTypeSize(getType())),
- !getType()->isSignedIntegerType());
-
+ !getType()->isSignedIntegerType());
+
// The LHS of a constant expr is always evaluated and needed.
if (!Exp->getLHS()->isIntegerConstantExpr(LHS, Ctx, Loc, isEvaluated))
return false;
@@ -945,20 +961,6 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
case BinaryOperator::LOr:
Result = LHS != 0 || RHS != 0;
break;
-
- case BinaryOperator::Comma:
- // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
- // *except* when they are contained within a subexpression that is not
- // evaluated". Note that Assignment can never happen due to constraints
- // on the LHS subexpr, so we don't need to check it here.
- if (isEvaluated) {
- if (Loc) *Loc = getLocStart();
- return false;
- }
-
- // The result of the constant expr is the RHS.
- Result = RHS;
- return true;
}
assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
OpenPOWER on IntegriCloud