[clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic

Summary:
Inside a range-based for-loop over an array, the compiler
generates pointer arithmetic (end = array + size). Don't flag this.

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D14582

llvm-svn: 254182
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
index 15ea27a..9dcd7c4 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
@@ -22,9 +22,11 @@
 
   // Flag all operators +, -, +=, -=, ++, -- that result in a pointer
   Finder->addMatcher(
-      binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"),
-                           hasOperatorName("+="), hasOperatorName("-=")),
-                     hasType(pointerType()))
+      binaryOperator(
+          anyOf(hasOperatorName("+"), hasOperatorName("-"),
+                hasOperatorName("+="), hasOperatorName("-=")),
+          hasType(pointerType()),
+          unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
           .bind("expr"),
       this);
 
@@ -36,8 +38,10 @@
 
   // Array subscript on a pointer (not an array) is also pointer arithmetic
   Finder->addMatcher(
-      arraySubscriptExpr(hasBase(ignoringImpCasts(anyOf(hasType(pointerType()),
-                                                        hasType(decayedType(hasDecayedType(pointerType())))))))
+      arraySubscriptExpr(
+          hasBase(ignoringImpCasts(
+              anyOf(hasType(pointerType()),
+                    hasType(decayedType(hasDecayedType(pointerType())))))))
           .bind("expr"),
       this);
 }