Address Richard's review comments on r147561 (Evaluate support for address-of-label differences).

llvm-svn: 147631
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fc214bf..949988d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3453,7 +3453,7 @@
   }
 
   bool Success(const CCValue &V, const Expr *E) {
-    if (V.isLValue()) {
+    if (V.isLValue() || V.isAddrLabelDiff()) {
       Result = V;
       return true;
     }
@@ -4002,8 +4002,6 @@
       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 @@
           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 @@
 
   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 @@
     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;
   }