This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by mgehre on Nov 11 2015, 12:06 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

mgehre updated this revision to Diff 39957.Nov 11 2015, 12:06 PM
mgehre retitled this revision from to [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic.
mgehre updated this object.
mgehre added a subscriber: cfe-commits.
aaron.ballman added inline comments.Nov 11 2015, 12:11 PM
clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
19 ↗(On Diff #39957)

This same code exists in ProBoundsArrayToPointerDecayCheck.cpp and should not be duplicated. I kind of wonder whether this belongs in clangTidyUtils, or in the AST matchers. I think for right now, clangTidyUtils because they still seem a little niche.

alexfh edited edge metadata.Nov 12 2015, 5:47 AM

It may be more effective to filter out expressions that operate on implicit variables, e.g. by adding this constraint to the binaryOperator matcher:

unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())))))

(maybe also for RHS).

The benefit of this would be that it doesn't use hasAncestor/hasDescendant which can be rather expensive.

mgehre updated this revision to Diff 40448.Nov 17 2015, 3:44 PM
mgehre edited edge metadata.

Simplified with Alex suggestion. Thanks!

alexfh accepted this revision.Nov 25 2015, 6:36 AM
alexfh edited edge metadata.

Sorry for the delay, I was sick and didn't read mail.

Looks good with a nit. Thanks for the fix!

clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
28 ↗(On Diff #40448)

nit: Does this still fit to 80 characters? I mean, clang-format, please ;)

This revision is now accepted and ready to land.Nov 25 2015, 6:36 AM
This revision was automatically updated to reflect the committed changes.