diff options
author | Richard Trieu <rtrieu@google.com> | 2011-09-12 18:37:54 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2011-09-12 18:37:54 +0000 |
commit | 6eef9fb34c75278f2e17149d33c7957437bd9a1a (patch) | |
tree | c4341bbcde0d512ca9f05cffc902c1441c9e4fed /lib/Sema/SemaExpr.cpp | |
parent | e389585f8a40f80004d3b98b99f3980305ef78a0 (diff) |
Refactor CheckAdditionOperands() to use early return for pointer addition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139520 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 93066a288f..bb31507c23 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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 |