aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2012-01-05 23:59:40 +0000
committerEli Friedman <eli.friedman@gmail.com>2012-01-05 23:59:40 +0000
commit5930a4c5224eea3b0558655f7f8c9ea027ef573e (patch)
treefc02520b75d9caecafb9eed71fe6b1f4c0bf7d8a /lib/AST/ExprConstant.cpp
parent5d1f496f86305b4738d465031a517b5be49f9ebd (diff)
Address Richard's review comments on r147561 (Evaluate support for address-of-label differences).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147631 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index fc214bfa80..949988db1a 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -3453,7 +3453,7 @@ public:
}
bool Success(const CCValue &V, const Expr *E) {
- if (V.isLValue()) {
+ if (V.isLValue() || V.isAddrLabelDiff()) {
Result = V;
return true;
}
@@ -4002,8 +4002,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
if (!HasSameBase(LHSValue, RHSValue)) {
if (E->getOpcode() == BO_Sub) {
// Handle &&A - &&B.
- // FIXME: We're missing a check that both labels have the same
- // associated function; I'm not sure how to write this check.
if (!LHSValue.Offset.isZero() || !RHSValue.Offset.isZero())
return false;
const Expr *LHSExpr = LHSValue.Base.dyn_cast<const Expr*>();
@@ -4014,6 +4012,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
const AddrLabelExpr *RHSAddrExpr = dyn_cast<AddrLabelExpr>(RHSExpr);
if (!LHSAddrExpr || !RHSAddrExpr)
return false;
+ // Make sure both labels come from the same function.
+ if (LHSAddrExpr->getLabel()->getDeclContext() !=
+ RHSAddrExpr->getLabel()->getDeclContext())
+ return false;
Result = CCValue(LHSAddrExpr, RHSAddrExpr);
return true;
}
@@ -4113,8 +4115,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
if (E->getOpcode() == BO_Sub && LHSVal.isLValue() && RHSVal.isLValue()) {
// Handle (intptr_t)&&A - (intptr_t)&&B.
- // FIXME: We're missing a check that both labels have the same
- // associated function; I'm not sure how to write this check.
if (!LHSVal.getLValueOffset().isZero() ||
!RHSVal.getLValueOffset().isZero())
return false;
@@ -4126,6 +4126,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
const AddrLabelExpr *RHSAddrExpr = dyn_cast<AddrLabelExpr>(RHSExpr);
if (!LHSAddrExpr || !RHSAddrExpr)
return false;
+ // Make sure both labels come from the same function.
+ if (LHSAddrExpr->getLabel()->getDeclContext() !=
+ RHSAddrExpr->getLabel()->getDeclContext())
+ return false;
Result = CCValue(LHSAddrExpr, RHSAddrExpr);
return true;
}