Commit Graph

1998 Commits

Author SHA1 Message Date
Nathan James 7c4782ce91
[clang-tidy] Fix regression in RenamerClangTidy
See bug https://bugs.llvm.org/show_bug.cgi\?id\=46976
2020-08-04 09:27:01 +01:00
Nathan James 3b44b6c900
[clang-tidy][NFC] Use correct size call for reserve 2020-08-04 00:31:19 +01:00
Nathan James 9f21947a33
[clang-tidy][NFC] Small refactor 2020-08-01 11:04:29 +01:00
Nathan James 4888c9ce97
[clang-tidy] readability-identifier-naming checks configs for included files
When checking for the style of a decl that isn't in the main file, the check will now search for the configuration that the included files uses to gather the style for its decls.

This can be useful to silence warnings in header files that follow a different naming convention without using header-filter to silence all warnings(even from other checks) in the header file.

Reviewed By: aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D84814
2020-08-01 10:35:32 +01:00
Nathan James 1fd2049e38
[clang-tidy][NFC] Added convienence methods for getting optional options
These methods abstract away Error handling when trying to read options that can't be parsed by logging the error automatically and returning None.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84812
2020-08-01 01:45:34 +01:00
Bjorn Pettersson 0d25d3b7e3 [clang-tidy] Fix build problem after commit 45a720a864
When building with LLVM8.0 on RHEL7.8 I got failures like this
after commit 45a720a864320bbbe:

/app/llvm/8.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/
5.4.0/../../../../include/c++/5.4.0/ext/new_allocator.h:120:23:
error: no matching constructor for initialization of
'std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >'
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

...

../../clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:73:15:
note: in instantiation of function template specialization
'std::vector<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >,
std::allocator<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> > > >::emplace_back<llvm::StringRef,
const std::__cxx11::basic_string<char> &>' requested here
Options.emplace_back(KeyValue.getKey(), KeyValue.getValue().Value);

This is an attempt to avoid such build problems.
2020-07-31 14:29:03 +02:00
Nathan James c23ae3f18e
[clang-tidy][NFC] Use StringMap for ClangTidyCheckFactories::FacoryMap
Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84926
2020-07-30 22:57:33 +01:00
Nathan James 45a720a864
[clang-tidy] Use StringMap for ClangTidyOptions::OptionsMap
Ordering of options isn't important so an `llvm::StringMap` is a much better container for this purpose.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84868
2020-07-30 10:31:13 +01:00
Nathan James bbc2ddecbd
[clang-tidy] Handled insertion only fixits when determining conflicts.
Handle insertion fix-its when removing incompatible errors by introducting a new EventType `ET_Insert`
This has lower prioirty than End events, but higher than begin.
Idea being If an insert is at the same place as a begin event, the insert should be processed first to reduce unnecessary conflicts.
Likewise if its at the same place as an end event, process the end event first for the same reason.

This also fixes https://bugs.llvm.org/show_bug.cgi?id=46511.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82898
2020-07-29 16:35:44 +01:00
Nathan James 62beb7c6f4
[clang-tidy] Fix module options being registered with different priorities
Not a bug that is ever likely to materialise, but still worth fixing

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D84850
2020-07-29 16:19:07 +01:00
Nathan James b99630e432
[clang-tidy] Fix RedundantStringCStrCheck with r values
The previous fix for this, https://reviews.llvm.org/D76761, Passed test cases but failed in the real world as std::string has a non trivial destructor so creates a CXXBindTemporaryExpr.

This handles that shortfall and updates the test case std::basic_string implementation to use a non trivial destructor to reflect real world behaviour.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84831
2020-07-29 15:35:31 +01:00
Nathan James 7bae3188e0 [clang-tidy][NFC] Make OptionsView methods as const where missing 2020-07-28 14:52:43 +01:00
Nathan James 13c9bbc28e
[clang-tidy] Refactor IncludeInserter
Simplified how `IncludeInserter` is used in Checks by abstracting away the SourceManager and PPCallbacks inside the method `registerPreprocessor`.
Changed checks that use `IncludeInserter` to no longer use a `std::unique_ptr`, instead the IncludeInserter is just a member of the class thats initialized with an `IncludeStyle`.
Saving an unnecessary allocation.

This results in the removal of the field `IncludeSorter::IncludeStyle` from the checks, as its wrapped in the `IncludeInserter`.
No longer need to create an instance of the `IncludeInserter` in the registerPPCallbacks, now that method only needs to contain:
```
Inserter.registerPreprocessor(PP);
```
Also added a helper method to `IncludeInserter` called `createMainFileInclusionInsertion`, purely sugar but does better express intentions.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83680
2020-07-27 12:48:55 +01:00
Hannes Käufler 3bbf3e026d Replace comment by private method; NFC. 2020-07-26 13:59:45 -04:00
Haojian Wu 82dbb1b2b4 Fix the clang-tidy build after get/isIntegerConstantExpression
refactoring.
2020-07-22 09:38:56 +02:00
Nathan James fcf0f75a59
[clang-tidy] OptionsView::store specialized on bool
Following on fcf7cc268f and 672207c319 which granted checks the ability to read boolean configuration arguments as `true` or `false`.
This enables storing the options back to the configuration file using `true` and `false`.
This is in line with how clang-format dumps boolean options in its style config.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83053
2020-07-14 22:19:37 +01:00
Nathan James c3bdc9814d
[clang-tidy] Reworked enum options handling(again)
Reland b9306fd after fixing the issue causing mac builds to fail unittests.

Following on from D77085, I was never happy with the passing a mapping to the option get/store functions. This patch addresses this by using explicit specializations to handle the serializing and deserializing of enum options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82188
2020-07-11 10:13:20 +01:00
Nathan James a25487fd8c
[clang-tidy] Use Options priority in enum options where it was missing 2020-07-10 12:27:08 +01:00
Haojian Wu 5f41ca48d1 [clang-tidy] More strict on matching the standard memset function in memset-usage check.
The check assumed the matched function call has 3 arguments, but the
matcher didn't guaranteed that.

Differential Revision: https://reviews.llvm.org/D83301
2020-07-10 11:42:35 +02:00
Ellis Hoag dfa0db79d0 Warn pointer captured in async block
The block arguments in dispatch_async() and dispatch_after() are
guaranteed to escape. If those blocks capture any pointers with the
noescape attribute then it is an error.
2020-07-07 13:31:14 -04:00
Nathan James 41bbb875e4
[NFC] Use hasAnyName matcher in place of anyOf(hasName()...) 2020-07-07 14:31:04 +01:00
Haojian Wu 3b1e3d2273 [clang-tidy] Fix an unused-raii check crash on objective-c++.
Differential Revision: https://reviews.llvm.org/D83293
2020-07-07 13:36:20 +02:00
Nathan James 0196600367 [clang-tidy] Fix incorrect default option in fc3c693b61 2020-07-06 14:44:03 +01:00
Nathan James fc3c693b61
[clang-tidy] Added alias llvm-else-after-return.
Added an alias llvm-else-after-return from readability-else-after-return to help enforce one of the llvm coding guidelines.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82825
2020-07-06 14:39:03 +01:00
Dmitri Gribenko 5689b38c6a Removed a RecursiveASTVisitor feature to visit operator kinds with different methods
Summary:
This feature was only used in two places, but contributed a non-trivial
amount to the complexity of RecursiveASTVisitor, and was buggy (see my
recent patches where I was fixing the bugs that I noticed). I don't
think the convenience benefit of this feature is worth the complexity.

Besides complexity, another issue with the current state of
RecursiveASTVisitor is the non-uniformity in how it handles different
AST nodes. All AST nodes follow a regular pattern, but operators are
special -- and this special behavior not documented. Correct usage of
RecursiveASTVisitor relies on shadowing member functions with specific
names and signatures. Near misses don't cause any compile-time errors,
incorrectly named or typed methods are just silently ignored. Therefore,
predictability of RecursiveASTVisitor API is quite important.

This change reduces the size of the `clang` binary by 38 KB (0.2%) in
release mode, and by 7 MB (0.3%) in debug mode. The `clang-tidy` binary
is reduced by 205 KB (0.3%) in release mode, and by 5 MB (0.4%) in debug
mode. I don't think these code size improvements are significant enough
to justify this change on its own (for me, the primary motivation is
reducing code complexity), but they I think are a nice side-effect.

Reviewers: rsmith, sammccall, ymandel, aaron.ballman

Reviewed By: rsmith, sammccall, ymandel, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82921
2020-07-06 13:38:01 +02:00
Nathan James e8158bf0e7 [NFC] Clean up braces and anon namespace 2020-07-05 11:16:40 +01:00
Nathan James d3bf1f3af2 Revert "[clang-tidy] For `run-clang-tidy.py` escape the paths that are used for analysis."
This reverts commit 068fa35746.

Based on a regression reported in https://bugs.llvm.org/show_bug.cgi?id=46536
2020-07-02 08:54:55 +01:00
Eric Schweitz e158154087 [clang-tidy] Allows the prevailing include header guard in Flang to be recognized rather than flagged as a violation in phabricator.
Differential revision: https://reviews.llvm.org/D82807
2020-07-01 12:47:36 -07:00
Nathan James 669494e9c0
[clang-tidy] fix cppcoreguidelines-init-variables with catch variables
Ignore catch statement var decls.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82924
2020-07-01 13:40:20 +01:00
Adam Balogh 4da65c2920 [clang-tidy] New util `Aliasing` factored out from `bugprone-infinite-loop`
Function `hasPtrOrReferenceInfFunc()` of `bugprone-infinite-loop` is a
generic function which could be reused in another checks. This patch
moves this function into a newly created utility module.

Differential Revision: https://reviews.llvm.org/D81396
2020-07-01 09:04:27 +02:00
Nathan James a06a5ed978
[clang-tidy] Added option to readability-else-after-return
Added a 'RefactorConditionVariables' option to control how the check handles condition variables

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82824
2020-06-30 19:34:45 +01:00
Nathan James 2efba0e812
[clang-tidy] performance-faster-string-find string-view
Extend the default string like classes to include `std::basic_string_view`.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82720
2020-06-30 16:45:59 +01:00
David Blaikie 11cd977017 Add missing #include
A forward declaration was insufficient here - since Regex needs to be
complete for the implicit dtor to be compiled correctly. (that, or the
dtor would have to be made explicit and out of line)
2020-06-29 22:08:20 -07:00
Nathan James 860aefd078
[clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82661
2020-06-29 16:05:52 +01:00
Nathan James 1f228e572d
[clang-tidy] Fix hicpp-named-paramater
Currently this alias instantiates the readability-identifier-naming check, just swap it out to use the readability-named-paramater check.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82711
2020-06-29 15:28:09 +01:00
Nathan James e34523c87c Revert "[clang-tidy] relanding b9306fd"
This reverts commit 37cc4fa2ea. More investigation needed
2020-06-29 09:44:11 +01:00
Nathan James 37cc4fa2ea
[clang-tidy] relanding b9306fd
Added some sanity checks to figure out the cause of a (seemingly unrelated) test failure on mac.
These can be removed should no issues arise on that platform again.
2020-06-29 09:29:39 +01:00
Nico Weber 8f73c4432b Revert "[clang-tidy] Reworked enum options handling(again)"
This reverts commit b9306fd042
and follow-up 42a51587c7.

It seems to build check-clang-tools on macOS, see comments on
https://reviews.llvm.org/D82188
2020-06-28 21:49:29 -04:00
Nathan James bfd99be0fc
[clang-tidy] Update lang restrictions on perf module 2020-06-28 15:18:08 +01:00
Nathan James 42a51587c7
Fix build errors after b9306fd0 2020-06-28 11:02:19 +01:00
Nathan James b9306fd042
[clang-tidy] Reworked enum options handling(again)
Following on from D77085, I was never happy with the passing a mapping to the option get/store functions. This patch addresses this by using explicit specializations to handle the serializing and deserializing of enum options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82188
2020-06-28 10:18:33 +01:00
Jeff Trull 95a3550dc8 Repair various issues with modernize-avoid-bind
In the process of running this check on a large codebase I found a
number of limitations, and thought I would pass on my fixes for
possible integration upstream:

* Templated function call operators are not supported
* Function object constructors are always used directly in the lambda
  body, even if their arguments are not captured
* Placeholders with namespace qualifiers (std::placeholders::_1) are
  not detected
* Lambda arguments should be forwarded to the stored function
* Data members from other classes still get captured with this
* Expressions (as opposed to variables) inside std::ref are not captured
  properly
* Function object templates sometimes have their template arguments
  replaced with concrete types

This patch resolves all those issues and adds suitable unit tests.
2020-06-25 07:29:53 -04:00
Valentin Clement ddf7ae852c [openmp] Add missing dependencies for OMP.h.inc after d90443b 2020-06-23 11:48:04 -04:00
Mikael Holmen 82a882db08 Silence gcc warning about extra ";" [NFC] 2020-06-23 11:28:34 +02:00
Nathan James 6ae0f5f3e1
[clang-tidy] RenamerClangTidy wont emit fixes in scratch space
Prevent fixes being displayed if usages are found in the scratch buffer.
See [[ https://bugs.llvm.org/show_bug.cgi?id=46219 | Fix-It hints are being generated in the ScratchBuffer ]].
It may be wise down the line to put in a general fix in clang-tidy to prevent ScratchBuffer replacements being applied, but for now this will help.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82162
2020-06-22 18:26:18 +01:00
Nathan James 9a8b041144
[clang-tidy] llvm-twine-local ignores parameters
Ignore paramater declarations of type `::llvm::Twine`, These don't suffer the same use after free risks as local twines.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82281
2020-06-22 18:25:45 +01:00
Nathan James 23063296b5
[clang-tidy] Improved accuracy of check list updater script
- Added `FixItHint` comments to Check files for the script to mark those checks as offering fix-its when the fix-its are generated in another file.
 - Case insensitive file searching when looking for the file a checker code resides in.

Also regenerated the list, sphinx had no issue generating the docs after this.

Reviewed By: sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D81932
2020-06-22 11:07:24 +01:00
Nathan James db90d31570
[clang-tidy] Implement storeOptions for checks missing it.
Just adds the storeOptions for Checks that weren't already storing their options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82223
2020-06-21 19:01:11 +01:00
Eric Christopher da6332f5f9 [clang-tidy] As part of using inclusive language within
the llvm project, migrate away from the use of blacklist and whitelist.
2020-06-20 15:20:11 -07:00
Eric Christopher ef455a55bc Update comment to be more clear. 2020-06-20 14:44:41 -07:00