summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix another case where loop-convert wasn't handling correctly data members.Angel Garcia Gomez2015-11-061-3/+3
| | | | | | | | | | | | | | | Summary: If the container expression was obtained from the point where "size" (which usually is a const method) is invoked, then the topmost node in this expression may be an implicit cast to const. When the container is a data member, the check was trying to obtain the member expression directly and was failing in the case mentioned above. This is solved by ignoring implicit casts. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14378 llvm-svn: 252278
* Handle correctly containers that are data members in modernize-loop-convert.Angel Garcia Gomez2015-11-031-5/+8
| | | | | | | | | | | | | | | | Summary: I recently found that the variable naming wasn't working as expected with containers that are data members. The new index always received the name "Elem" (or equivalent) regardless of the container's name. The check was assuming that the container's declaration was a VarDecl, which cannot be converted to a FieldDecl (a data member), and then it could never retrieve its name. This also fixes some cases where the check failed to find the container at all (so it didn't do any fix) because of the same reason. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14289 llvm-svn: 251943
* Improve more the const-detection in modernize-loop-convert.Angel Garcia Gomez2015-11-031-0/+2
| | | | | | | | | | | | Summary: The previous change was focused in detecting when a non-const object was used in a constant way. Looks like I forgot the most important and trivial case: when the object is already constant. Failing to detect this cases results in compile errors, due to trying to bind a constant object to a non-const reference in the range-for statement. This change should fix that. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14282 llvm-svn: 251940
* Make the modernize-loop-convert's const-detection smarter.Angel Garcia Gomez2015-11-021-7/+33
| | | | | | | | | | | | | | | | Summary: Now, it detects that several kinds of usages are can't modify the elements. Examples: -When an usage is a call to a const member function or operator of the element. -If the element is used as an argument to a function or constructor that takes a const-reference or a value. -LValue to RValue conversion, if the element is a fundamental type (which allows the use of most of the builtin operators). Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14198 llvm-svn: 251808
* Only copy small types in modernize-loop-convert.Angel Garcia Gomez2015-10-301-15/+19
| | | | | | | | | | | | Summary: If the size of the type is above a certain bound, we'll take a const reference. This bound can be set as an option. For now, the default value is 16 bytes. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14176 llvm-svn: 251694
* Don't use "auto" on loops over fundamental types in modernize-loop-convert.Angel Garcia Gomez2015-10-221-19/+18
| | | | | | | | | | | | Summary: using "auto" on a loop that iterates over ints is kind of an overkill. Use the real type name instead. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13982 llvm-svn: 251015
* Make string constants in the modernize module static.Angel Garcia Gomez2015-10-221-13/+13
| | | | | | | | | | | | Summary: Add static to global variables, if they are not in an anonymous namespace. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13975 llvm-svn: 251005
* Document a bug in loop-convert and fix one of its subcases.Angel Garcia Gomez2015-10-051-2/+15
| | | | | | | | | | | | Summary: Now that we prioritize copying trivial types over using const-references where possible, I found some cases where, after the transformation, the loop was using the address of the local copy instead of the original object. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13431 llvm-svn: 249300
* Prevent loop-convert from leaving empty lines after removing an alias ↵Angel Garcia Gomez2015-10-011-1/+28
| | | | | | | | | | | | | | declaration. Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=17716. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13342 llvm-svn: 249006
* Add support for 'cbegin()' and 'cend()' on modernize-loop-convert.Angel Garcia Gomez2015-10-011-5/+8
| | | | | | | | | | | | | | | Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=22196 . Also add a non-trivially copyable type to fix some tests that were meant to be about using const-refs, but were changed in r248438. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13292 llvm-svn: 248994
* Add NamingStyle option to modernize-loop-convert.Angel Garcia Gomez2015-09-241-2/+12
| | | | | | | | | | | | Summary: Add an option to specify wich style must be followed when choosing the new index name. Reviewers: alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13052 llvm-svn: 248517
* Remove dangling parenthesis.Angel Garcia Gomez2015-09-241-1/+11
| | | | | | | | | | | | Summary: Remove parenthesis surrounding the new loop index. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13133 llvm-svn: 248507
* Solve comment on rL248418.Angel Garcia Gomez2015-09-241-3/+1
| | | | | | | | | | | | Summary: Solve comment on rL248418. Reviewers: alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13129 llvm-svn: 248489
* Use simpler interface for getting the pointee type for a node.Manuel Klimek2015-09-241-1/+1
| | | | llvm-svn: 248449
* Fix loop-convert for trivially copyable types.Manuel Klimek2015-09-231-31/+32
| | | | | | | | | | | | | | Previously, we would rewrite: void f(const vector<int> &v) { for (size_t i = 0; i < v.size(); ++i) { to for (const auto &elem : v) { Now we rewrite it to: for (auto elem : v) { (and similarly for iterator based loops). llvm-svn: 248438
* Fix loop-convert for const references to containers.Manuel Klimek2015-09-231-0/+6
| | | | | | | | | | | | Previously we would use a non-const loop variable in the range-based loop for: void f(const std::vector<int> &v) { for (size_t i = 0; i < v.size(); ++i) { Now we use const auto&. Note that we'll also want to use a copy at least for simple types. llvm-svn: 248418
* Refactor LoopConvertCheck.Angel Garcia Gomez2015-09-211-212/+245
| | | | | | | | | | | | Summary: Reorder the code in a more logical and understandable way. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D12797 llvm-svn: 248144
* Refactors AST matching code to use the new AST matcher names. This patch ↵Aaron Ballman2015-09-171-17/+18
| | | | | | correlates to r247885 which performs the AST matcher rename in Clang. llvm-svn: 247886
* Another patch for modernize-loop-convert.Angel Garcia Gomez2015-09-111-5/+45
| | | | | | | | | | | | | | | | | | Summary: 1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning. 2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types. 3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well. 4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though). 5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops. 6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12734 llvm-svn: 247399
* Avoid using rvalue references with trivially copyable types.Angel Garcia Gomez2015-09-081-31/+47
| | | | | | | | | | | | | | | | Summary: When the dereference operator returns a value that is trivially copyable (like a pointer), copy it. After this change, modernize-loop-convert check can be applied to the whole llvm source code without breaking any build or test. Reviewers: alexfh, klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12675 llvm-svn: 246989
* Fix several corner cases for loop-convert check.Angel Garcia Gomez2015-09-011-2/+32
| | | | | | | | | | | | Summary: Reduced the amount of wrong conversions of this check. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12530 llvm-svn: 246550
* Disable several more clang-tidy modernize checkers when not compiling in C++ ↵Aaron Ballman2015-08-281-3/+8
| | | | | | mode. Loop conversion would make recommendations for C code, so added a test to ensure that does not happen. The pass by value, use auto and replace auto_ptr checkers would not make recommendations for C code, and are disabled for performance reasons, but do not require an extra test. llvm-svn: 246310
* Avoid LoopConvertCheck replacements in template instantiations.Angel Garcia Gomez2015-08-251-0/+3
| | | | | | | | | | | | Summary: Prevent LoopConvertCheck from doing replacements in template instantiations, and add a test. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D12321 llvm-svn: 245942
* [clang-tidy] Fix bug in modernize-loop-convert check.Alexander Kornienko2015-08-201-2/+3
| | | | | | | | http://reviews.llvm.org/D12186 Patch by Angel Garcia! llvm-svn: 245561
* [clang-tidy] Fix LoopConvertCheck bug.Alexander Kornienko2015-08-191-6/+4
| | | | | | | | | | | | Fix LoopConvertCheck bug: StringRef to temporaries. Also add LLVM_ATTRIBUTE_UNUSED to ModernizeModuleAnchorDestination. http://reviews.llvm.org/D12157 Patch by Angel Garcia! llvm-svn: 245458
* [clang-tidy] Add loop-convert check to clang-tidy.Alexander Kornienko2015-08-191-0/+668
Move LoopConvert from clang-modernize to modernize module in clang-tidy. http://reviews.llvm.org/D12076 Patch by Angel Garcia! llvm-svn: 245427
OpenPOWER on IntegriCloud