]> granicus.if.org Git - clang/commitdiff
Refactor CheckAdditionOperands() to use early return for pointer addition.
authorRichard Trieu <rtrieu@google.com>
Mon, 12 Sep 2011 18:37:54 +0000 (18:37 +0000)
committerRichard Trieu <rtrieu@google.com>
Mon, 12 Sep 2011 18:37:54 +0000 (18:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139520 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp

index 93066a288fe8a368a4aafe02dcae9827876f80b4..bb31507c236981608de39cb1189fe28339904cae 100644 (file)
@@ -6010,32 +6010,33 @@ QualType Sema::CheckAdditionOperands( // C99 6.5.6
   if (IExp->getType()->isAnyPointerType())
     std::swap(PExp, IExp);
 
-  if (PExp->getType()->isAnyPointerType()) {
-    if (IExp->getType()->isIntegerType()) {
-      if (!checkArithmeticOpPointerOperand(*this, Loc, PExp))
-        return QualType();
+  if (!PExp->getType()->isAnyPointerType())
+    return InvalidOperands(Loc, LHS, RHS);
 
-      // Diagnose bad cases where we step over interface counts.
-      if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, PExp))
-        return QualType();
+  if (!IExp->getType()->isIntegerType())
+    return InvalidOperands(Loc, LHS, RHS);
 
-      // Check array bounds for pointer arithemtic
-      CheckArrayAccess(PExp, IExp);
-
-      if (CompLHSTy) {
-        QualType LHSTy = Context.isPromotableBitField(LHS.get());
-        if (LHSTy.isNull()) {
-          LHSTy = LHS.get()->getType();
-          if (LHSTy->isPromotableIntegerType())
-            LHSTy = Context.getPromotedIntegerType(LHSTy);
-        }
-        *CompLHSTy = LHSTy;
-      }
-      return PExp->getType();
+  if (!checkArithmeticOpPointerOperand(*this, Loc, PExp))
+    return QualType();
+
+  // Diagnose bad cases where we step over interface counts.
+  if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, PExp))
+    return QualType();
+
+  // Check array bounds for pointer arithemtic
+  CheckArrayAccess(PExp, IExp);
+
+  if (CompLHSTy) {
+    QualType LHSTy = Context.isPromotableBitField(LHS.get());
+    if (LHSTy.isNull()) {
+      LHSTy = LHS.get()->getType();
+      if (LHSTy->isPromotableIntegerType())
+        LHSTy = Context.getPromotedIntegerType(LHSTy);
     }
+    *CompLHSTy = LHSTy;
   }
 
-  return InvalidOperands(Loc, LHS, RHS);
+  return PExp->getType();
 }
 
 // C99 6.5.6