Extended the matched assignment operators when checking for bound changes in a body of the loop. This updated list covers all the (current) possible assignments.
Details
- Reviewers
NoQ dcoughlin xazax.hun zaks.anna klimek aaron.ballman george.karpenkov - Commits
- rG4c87d233b07c: [analyzer] LoopUnrolling: update the matched assignment operators
rL328619: [analyzer] LoopUnrolling: update the matched assignment operators
rC328619: [analyzer] LoopUnrolling: update the matched assignment operators
Diff Detail
Event Timeline
lib/StaticAnalyzer/Core/LoopUnrolling.cpp | ||
---|---|---|
99–100 | Maybe instead of enumerating all the assignment operators here it would be better to have a matcher that checks isAssignmentOp for CXXOperatorCalls/BinaryOperators? This would be less error prone and more future proof. |
- Updated to use a custom AST matcher for assignment operator check. (More structured and efficient.)
- Tests added as well.
Yay.
Thanks Gabor, i didn't think about it but it looks very nice to have such matcher.
I think the matcher shouldn't be checker-local, but shared into ASTMatchers.h all other matchers - not only this matcher is universally useful, but also i have weird vague memories that matchers may collide by name if defined in different translation units differently (if this is indeed this way then having the same matcher in multiple places is very bad).
isAssignmentOp matcher moved to ASTMatchers.h
(Manuel added to reviewers as the code owner of ASTMatchers)
Not sure how clang/docs/LibASTMatchersReference.html is supposed to be updated.
include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
3931 | Maybe -/// \brief Matches all kind of assignment operators. +/// \brief Matches all kinds of assignment operators. | |
3938 | Needs unittests, probably in clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp ? |
A nit, otherwise LG!
lib/StaticAnalyzer/Core/PathDiagnostic.cpp | ||
---|---|---|
693 | Is this change related? Maybe you forgot to add a dependency to this revision? |
Aside from a request for another test, the matcher parts LGTM.
unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | ||
---|---|---|
1992 | Can you also add a test like: struct S { S& operator=(const S&); }; void x() { S s1, s2; s1 = s2; } |
Yepp, but added as a different patch since implemented it for cxxOperatorCall as well. (I guess Aaron's test request implied it and I find it useful as well.)
See: https://reviews.llvm.org/D44893
Added the assignment operator matcher patch as a dependency and rebased on top of that.
Maybe