aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-11 19:29:32 +0000
committerChris Lattner <sabre@nondot.org>2008-07-11 19:29:32 +0000
commitac7cb603979a0e5a6a216ccbd20eee7647c96b54 (patch)
tree7f617c8b3718aef762b87dcdf42ffdf3105296eb /lib/AST/ExprConstant.cpp
parent7a76778e218da57a3b10c80066a0a938f28987b6 (diff)
implement support for __extension__, make sure the result of a
comparison has the right width. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 662104ec70..04f1572cb3 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -220,6 +220,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
break;
case BinaryOperator::Add: Result += RHS; break;
case BinaryOperator::Sub: Result -= RHS; break;
+ case BinaryOperator::And: Result &= RHS; break;
+ case BinaryOperator::Xor: Result ^= RHS; break;
+ case BinaryOperator::Or: Result |= RHS; break;
+
case BinaryOperator::Shl:
Result <<= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
break;
@@ -227,16 +231,30 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
Result >>= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
break;
- // FIXME: Need to set the result width?
- case BinaryOperator::LT: Result = Result < RHS; break;
- case BinaryOperator::GT: Result = Result > RHS; break;
- case BinaryOperator::LE: Result = Result <= RHS; break;
- case BinaryOperator::GE: Result = Result >= RHS; break;
- case BinaryOperator::EQ: Result = Result == RHS; break;
- case BinaryOperator::NE: Result = Result != RHS; break;
- case BinaryOperator::And: Result &= RHS; break;
- case BinaryOperator::Xor: Result ^= RHS; break;
- case BinaryOperator::Or: Result |= RHS; break;
+ case BinaryOperator::LT:
+ Result = Result < RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
+ case BinaryOperator::GT:
+ Result = Result > RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
+ case BinaryOperator::LE:
+ Result = Result <= RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
+ case BinaryOperator::GE:
+ Result = Result >= RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
+ case BinaryOperator::EQ:
+ Result = Result == RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
+ case BinaryOperator::NE:
+ Result = Result != RHS;
+ Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+ break;
case BinaryOperator::Comma:
// C99 6.6p3: "shall not contain assignment, ..., or comma operators,
@@ -293,16 +311,15 @@ bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
// See C99 6.6p3.
default:
return false;
- case UnaryOperator::Extension:
- assert(0 && "Handle UnaryOperator::Extension");
- return false;
case UnaryOperator::LNot: {
bool Val = Result == 0;
Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
Result = Val;
break;
}
+ case UnaryOperator::Extension:
case UnaryOperator::Plus:
+ // The result is always just the subexpr
break;
case UnaryOperator::Minus:
Result = -Result;