diff options
author | Chris Lattner <sabre@nondot.org> | 2008-07-11 19:29:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-07-11 19:29:32 +0000 |
commit | b062dcc17b79be953ea46f3c9ac5f0688e88d5f9 (patch) | |
tree | 8a1ca58f45adf252efbed5cbd8f7250e708c5797 /clang/lib/AST/ExprConstant.cpp | |
parent | ae8cc159776d68a10784a7235fa92ea9da1435ef (diff) | |
download | bcm5719-llvm-b062dcc17b79be953ea46f3c9ac5f0688e88d5f9.tar.gz bcm5719-llvm-b062dcc17b79be953ea46f3c9ac5f0688e88d5f9.zip |
implement support for __extension__, make sure the result of a
comparison has the right width.
llvm-svn: 53469
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 662104ec701..04f1572cb37 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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; |