Commit Graph

1148 Commits

Author SHA1 Message Date
Angel Garcia Gomez 32af5bc51a Create interfaces and tests for the overlapping replacements fix in clang-tidy.
Summary: No changes in clang-tidy yet.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 249402
2015-10-06 13:52:51 +00:00
Aaron Ballman aaa4080d21 Add a new module for the C++ Core Guidelines, and the first checker for those guidelines: cppcoreguidelines-pro-type-reinterpret-cast.
Patch by Matthias Gehre!

llvm-svn: 249399
2015-10-06 13:31:00 +00:00
Aaron Ballman 46bc30472b Adding a checker (cert-dcl50-cpp) that detects the definition of a C-style variadic function in C++ code. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/DCL50-CPP.+Do+not+define+a+C-style+variadic+function
llvm-svn: 249343
2015-10-05 20:08:59 +00:00
Angel Garcia Gomez b9f3059509 Use better mocks in modernize-make-unique, and fix matcher.
Summary: Add the second template argument to the unique_ptr mock, and update the matcher so that it only matches against cases where the second argument is the default.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 249305
2015-10-05 12:20:17 +00:00
Angel Garcia Gomez 199e5232b3 Document a bug in loop-convert and fix one of its subcases.
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
2015-10-05 11:15:39 +00:00
Angel Garcia Gomez c50b9fbb84 Fix bug in modernize-use-nullptr.
Summary:
https://llvm.org/bugs/show_bug.cgi?id=24960

modernize-use-nullptr would hit an assertion in some cases involving macros and initializer lists, due to finding a node with more than one parent (the two forms of the initializer list).

However, this doesn't mean that the replacement is incorrect, so instead of just rejecting this case I tried to find a way to make it work. Looking at the semantic form of the InitListExpr made sense to me (looking at both forms results in false negatives) but I am not sure of the things that we can miss by skipping the syntactic form.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 249291
2015-10-05 08:40:13 +00:00
Craig Topper 8f70a9f892 SourceRanges are small and trivially copyable, don't them by reference. NFC
llvm-svn: 249258
2015-10-04 04:53:37 +00:00
Yaron Keren 8b563665c3 Replace double negation of !FileID.isInvalid() with FileID.isValid().
+couple more of double-negated !SourceLocation.isInvalid() unfixed in r249228.

llvm-svn: 249235
2015-10-03 10:46:20 +00:00
Aaron Ballman b91d64c6cc Taking a stab at fixing failing build bots that use make. Unfortunately, the build logs do not point to much useful information for tracking this down, such as:
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/31782/steps/compile/logs/stdio

llvm-svn: 249136
2015-10-02 14:28:44 +00:00
Aaron Ballman 67e06ddb51 Hopefully rectifying a build bot issue with:
http://bb.pgr.jp/builders/i686-mingw32-RA-on-linux/builds/2833/steps/build_llvmclang/logs/stdio

Also, drive-by comment fix in a makefile.

llvm-svn: 249133
2015-10-02 14:01:55 +00:00
Aaron Ballman ea2f90c96b Adding a new clang-tidy module to house CERT-specific checkers, and map existing checkers to CERT secure coding rules and recommendations for both C (https://www.securecoding.cert.org/confluence/display/c/SEI+CERT+C+Coding+Standard) and C++ (https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=637).
llvm-svn: 249130
2015-10-02 13:27:19 +00:00
Angel Garcia Gomez 88d204442b Handle trailing underscores on modernize-loop-convert variable namer.
Summary: https://llvm.org/bugs/show_bug.cgi?id=24961.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 249127
2015-10-02 13:20:11 +00:00
NAKAMURA Takumi 0ed0740c7e Fix the *unchecked* commit.
llvm-svn: 249100
2015-10-01 23:50:06 +00:00
Chris Bieneman 261d3ea0f8 [CMake] Don't include the test directories if CLANG_INCLUDE_TESTS is Off
This matches Clang's behavior.

llvm-svn: 249048
2015-10-01 18:16:56 +00:00
Angel Garcia Gomez 05ca3ec7d0 Update clang-tidy documentation.
Summary:
Improve modernize-use-auto documentation (https://llvm.org/bugs/show_bug.cgi?id=24962).
Add documentation for modernize-make-unique.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 249017
2015-10-01 14:50:40 +00:00
Angel Garcia Gomez 90bf895aa3 Prevent loop-convert from leaving empty lines after removing an alias 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
2015-10-01 13:08:21 +00:00
Alexander Kornienko eef2c237a5 [clang-tidy] fix add_new_check.py
Before this check, I would get the following error:

Updating ./misc/CMakeLists.txt...
Creating ./misc/NoReinterpret_castCheck.h...
Creating ./misc/NoReinterpret_castCheck.cpp...
Updating ./misc/MiscTidyModule.cpp...
Creating ../test/clang-tidy/misc-no-reinterpret_cast.cpp...
Creating ../docs/clang-tidy/checks/misc-no-reinterpret_cast.rst...
Traceback (most recent call last):

File "./add_new_check.py", line 271, in <module>
  main()
File "./add_new_check.py", line 267, in main
  update_checks_list(module_path)
File "./add_new_check.py", line 220, in update_checks_list
  os.listdir('docs/clang-tidy/checks')))
OSError: [Errno 2] No such file or directory: 'docs/clang-tidy/checks'

Patch by Matthias Gehre!

Differential revision: http://reviews.llvm.org/D13272

llvm-svn: 248997
2015-10-01 09:23:20 +00:00
Alexander Kornienko 30c423b1e3 [clang-tidy] Implement FixitHints for identifier references in IdentifierNamingCheck
This diff requires http://reviews.llvm.org/D13079 to be applied first. I wasn't sure about how to make patch series in Phabricator, and I wanted to keep the two separate for clarity.

It looks like that most cases can be supported with this patch. I'm not totally sure about the actual coverage though. I think that the matchers are very generic, but I'm still not totally fluent with the AST.

Patch by Beren Minor!

Differential revision: http://reviews.llvm.org/D13081

llvm-svn: 248996
2015-10-01 09:19:40 +00:00
Angel Garcia Gomez 2bfb7cbddb Add support for 'cbegin()' and 'cend()' on modernize-loop-convert.
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
2015-10-01 08:57:11 +00:00
Aaron Ballman 8db15e4a4d Adding a checker (misc-non-copyable-objects) that detects situations where a non-copyable C type is being dereferenced, such as FILE or pthread_mutex_t. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object
llvm-svn: 248907
2015-09-30 14:09:38 +00:00
Alexander Kornienko 87e1da6205 [clang-tidy] Added missing check lines, made the checking stricter.
llvm-svn: 248899
2015-09-30 13:32:42 +00:00
Alexander Kornienko 08023c696d [clang-tidy] Fix an assertion in the readability-braces-around-statements check.
llvm-svn: 248895
2015-09-30 12:48:42 +00:00
Alexander Kornienko 42e651fa43 [clang-tidy] Better diagnostic in tests when clang-tidy fails.
llvm-svn: 248886
2015-09-30 10:41:53 +00:00
Aaron Ballman 0f28d62a12 Some of the build bots are unhappy about the overload of the global operator new() because it was accidentally marked noexcept instead of noexcept(false). This should correct those bots.
llvm-svn: 248797
2015-09-29 14:26:00 +00:00
Aaron Ballman 5edd83de91 Silencing bot failures a more creative and definitive way.
llvm-svn: 248794
2015-09-29 13:38:00 +00:00
Aaron Ballman 872c95c26f Hopefully silencing some built bot warnings. Note, this should be unsigned long instead of unsigned int, but then *other* builds start to fail because of duplicate redefinitions of size_t.
llvm-svn: 248792
2015-09-29 13:20:26 +00:00
Aaron Ballman de34985caa Adding a checker (misc-new-delete-overloads) that detects mismatched overloads of operator new and operator delete. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/DCL54-CPP.+Overload+allocation+and+deallocation+functions+as+a+pair+in+the+same+scope
llvm-svn: 248791
2015-09-29 13:12:21 +00:00
Angel Garcia Gomez 26fd0e8b62 Create modernize-make-unique check.
Summary: create a check that replaces 'std::unique_ptr<type>(new type(args...))' with 'std::make_unique<type>(args...)'. It was on the list of "Ideas for new Tools". It needs to be tested more carefully, but first I wanted to know if you think it is worth the effort.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 248785
2015-09-29 09:36:41 +00:00
Aaron Ballman 176a1a3931 Fixing a sphinx warning.
llvm-svn: 248729
2015-09-28 19:27:37 +00:00
Guillaume Papin 68b591079a [clang-tidy] add option to specify build path
Summary:
compile_commands.json is usually generated in the build directory.
Projects like LLVM/Clang enforce out-of-source builds.
This option allow allow such projects to work out of the box, without
moving the compilation database manually.

The naming of the option is similar to the one use by other tools:

    clang-{check,modernize,query,rename,tidy} -p=<build_path> <...>

Reviewers: alexfh

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

llvm-svn: 248723
2015-09-28 17:53:04 +00:00
Manuel Klimek 55dc5df59f Install clang-query by default.
It is already installed by the autotools build, and it is useful for
developers who are not working on LLVM/Clang itself.

llvm-svn: 248710
2015-09-28 13:26:39 +00:00
Alexander Kornienko 3d77768e2a [clang-tidy] Code factorization and cleanup in IdentifierNamingCheck
This is to level the ground a little bit, in preparation for the changes in http://reviews.llvm.org/D13081.

Code factorization replaces all insertions to NamingCheckFailures map with a unique addUsage function that does the job.
There is also no more difference between the declaration and the references to a given identifier, both cases are treated as ranges in the Usage vector. There is also a check to avoid duplicated ranges to be inserted, which sometimes triggered erroneous replacements.

References can now also be added before the declaration of the identifier is actually found; this looks to be the case for example when a templated class uses its parameters to specialize its templated base class.

Patch by Beren Minor!

Differential revision: http://reviews.llvm.org/D13079

llvm-svn: 248700
2015-09-28 08:59:12 +00:00
Alexander Kornienko 501e6cd283 [clang-tidy] Removed a stray empty line in the docs.
llvm-svn: 248699
2015-09-28 08:52:55 +00:00
Alexander Kornienko 91b53846f7 [clang-tidy] Updated misc-unused-raii documentation.
llvm-svn: 248594
2015-09-25 17:50:11 +00:00
Angel Garcia Gomez 8535c6c278 Add NamingStyle option to modernize-loop-convert.
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
2015-09-24 17:02:19 +00:00
Angel Garcia Gomez bd432b2d04 Remove dangling parenthesis.
Summary: Remove parenthesis surrounding the new loop index.

Reviewers: klimek

Subscribers: cfe-commits, klimek

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

llvm-svn: 248507
2015-09-24 15:29:46 +00:00
Angel Garcia Gomez aed6dde955 Solve comment on rL248418.
Summary: Solve comment on rL248418.

Reviewers: alexfh

Subscribers: cfe-commits, klimek

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

llvm-svn: 248489
2015-09-24 13:26:28 +00:00
Manuel Klimek a88ce501fe Use simpler interface for getting the pointee type for a node.
llvm-svn: 248449
2015-09-24 00:16:38 +00:00
Manuel Klimek b457b68f8d Fix loop-convert for trivially copyable types.
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
2015-09-23 22:28:14 +00:00
Manuel Klimek 143b644238 Fix loop-convert for const references to containers.
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
2015-09-23 18:40:47 +00:00
Daniel Jasper f631191305 misc-unused-parameter: Ignore lambda static invokers.
llvm-svn: 248252
2015-09-22 09:20:20 +00:00
Angel Garcia Gomez 415af0184c Replace references to "transform" with references to "check" where neccessary in the documentation.
Summary: Replace references to "transform" with references to "check" where neccessary in the documentation.

Reviewers: alexfh

Subscribers: cfe-commits, klimek

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

llvm-svn: 248153
2015-09-21 12:53:30 +00:00
Alexander Kornienko 3e748fbd17 [clang-tidy] Fixed formatting of headings in the docs.
llvm-svn: 248151
2015-09-21 12:13:27 +00:00
Angel Garcia Gomez f41a631b50 Refactor LoopConvertCheck.
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
2015-09-21 09:32:59 +00:00
Craig Topper 18929c5069 Pass SourceLocation by value instead of by const reference since its just a 32-bit integer. NFC
llvm-svn: 248139
2015-09-21 01:33:03 +00:00
NAKAMURA Takumi e677e2f545 clang-tools-extra: Appease PR24881. [-Wdocumentation]
\returns doesn't accept \li, but \parblock \li.

llvm-svn: 248080
2015-09-19 02:21:28 +00:00
Angel Garcia Gomez b22084e113 Update clang-tidy documentation.
Summary: Update documentation of the modernize module with clang-modernize's documentation.

Subscribers: cfe-commits, klimek, alexfh

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

llvm-svn: 247987
2015-09-18 14:08:57 +00:00
Alexander Kornienko 8221ab3499 [clang-tidy] install helper scripts
Scripts are installed in same location as clang-fromat ones, so I think will be good idea to not create dedicated directory.

I checked this patch on my own build on RHEL 6.

Please check it in if it's OK, because I don't have SVN write access.

I think will be good idea to backport this patch to 3.7 release branch.

Probably same should be done for configure build.

Patch by Eugene Zelenko!

Differential revision: http://reviews.llvm.org/D12700

llvm-svn: 247890
2015-09-17 14:37:26 +00:00
Angel Garcia Gomez 387dc0b019 Add a test to modernize-loop-convert.
Summary: Add the test about replacements in several arguments of the same macro call, now that the problem has been fixed.

Reviewers: alexfh

Subscribers: cfe-commits, klimek

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

llvm-svn: 247889
2015-09-17 14:25:39 +00:00
Aaron Ballman b9ea09c445 Refactors AST matching code to use the new AST matcher names. This patch correlates to r247885 which performs the AST matcher rename in Clang.
llvm-svn: 247886
2015-09-17 13:31:25 +00:00