diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-03-24 01:14:50 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-03-24 01:14:50 +0000 |
commit | 42edd0d32a729d2735a6fb152ba6bf349bf0a169 (patch) | |
tree | 7e1cd71fbc4e53b8431d05ee7575b60417425135 /lib/AST/ExprConstant.cpp | |
parent | ff59a8ab68326c7f50c78f0cc5a99b1f8fd02b01 (diff) |
Fix PR3868 by making Evaluate handle cases like "(long)&a + 4".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index c2449166fc..b0954e149c 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -918,7 +918,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { !RHSTy->isIntegralType()) { // We can't continue from here for non-integral types, and they // could potentially confuse the following operations. - // FIXME: Deal with EQ and friends. return false; } @@ -926,14 +925,36 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { if (!Visit(E->getLHS())) return false; // error in subexpression. - // Only support arithmetic on integers for now. - if (!Result.isInt()) + APValue RHSVal; + if (!EvaluateIntegerOrLValue(E->getRHS(), RHSVal, Info)) return false; - - llvm::APSInt RHS; - if (!EvaluateInteger(E->getRHS(), RHS, Info)) + + // Handle cases like (unsigned long)&a + 4. + if (E->isAdditiveOp() && Result.isLValue() && RHSVal.isInt()) { + uint64_t offset = Result.getLValueOffset(); + if (E->getOpcode() == BinaryOperator::Add) + offset += RHSVal.getInt().getZExtValue(); + else + offset -= RHSVal.getInt().getZExtValue(); + Result = APValue(Result.getLValueBase(), offset); + return true; + } + + // Handle cases like 4 + (unsigned long)&a + if (E->getOpcode() == BinaryOperator::Add && + RHSVal.isLValue() && Result.isInt()) { + uint64_t offset = RHSVal.getLValueOffset(); + offset += Result.getInt().getZExtValue(); + Result = APValue(RHSVal.getLValueBase(), offset); + return true; + } + + // All the following cases expect both operands to be an integer + if (!Result.isInt() || !RHSVal.isInt()) return false; + APSInt& RHS = RHSVal.getInt(); + switch (E->getOpcode()) { default: return Error(E->getOperatorLoc(), diag::note_invalid_subexpr_in_ice, E); |