Commit Graph

2071 Commits

Author SHA1 Message Date
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
Eric Christopher f8a463c170 As part of using inclusive language within the llvm project,
migrate away from the use of blacklist and whitelist.
2020-06-19 15:43:51 -07:00
Daniel af4f2eb476
[clang-tidy] remove duplicate fixes of alias checkers
when both a check and its alias are enabled, we should only take the fixes of one of them and not both.
This patch fixes bug 45577
https://bugs.llvm.org/show_bug.cgi?id=45577

Reviewed By: aaron.ballman, njames93

Differential Revision: https://reviews.llvm.org/D80753
2020-06-19 20:40:59 +01:00
Nathan James c3b4486a57
[NFC] Simplify IncludeInsertions appending to diagnostics 2020-06-19 13:22:49 +01:00
Nathan James 4836188ad9
[clang-tidy] Extend InheritParentConfig to CommandLineConfig
Extend the `InheritParentConfig` support introduced in D75184 for the command line option `--config`.
The current behaviour of `--config` is to when set, disable looking for `.clang-tidy` configuration files.
This new behaviour lets you set `InheritParentConfig` to true in the command line to then look for `.clang-tidy` configuration files to be merged with what's been specified on the command line.

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D81949
2020-06-19 12:02:19 +01:00
Nathan James 8b0df1c1a9
[NFC] Refactor Registry loops to range for 2020-06-19 00:40:10 +01:00
hyd-dev d9b8aada82
[clang-tidy] Add --use-color command line option and UseColor option to control colors in diagnostics
This patch adds `--use-color` command line option and `UseColor` option to clang-tidy to control colors in diagnostics. With these options, users can force colorful output. This is useful when using clang-tidy with parallelization command line tools (like ninja and GNU parallel), as they often pipe clang-tidy's standard output and make the colors disappear.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D79477
2020-06-18 16:16:14 +01:00
Nathan James 850bb889a5
[clang-tidy] RenamerClangTidy group redecls into 1 warning.
This changes the behavious of `RenamerClangTidyCheck` based checks by grouping declarations of the same thing into 1 warning where it is first declared.
This cleans up clang-tidy output and prevents issues where 1 fix-it couldn't be applied, yet all other warnings(and fix-its) for the same declaration would be applied.
The old behaviour of forward declaring a class without defining it isn't affected, i.e. no warnings will be emitted for that case.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82059
2020-06-18 15:50:16 +01:00
Benjamin Kramer c76edaabdd [clang-tidy] Prune dead code. NFC. 2020-06-17 21:16:59 +02:00
Nathan James 08c83ed757
[clang-tidy][NFC] Remove the double look-up on IncludeInserter
Refactor out the double lookup in `IncludeInserter` when trying to get the `IncludeSorter` for a specified `FileID`.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82004
2020-06-17 19:48:34 +01:00
Michał Górny d4f298c820 [clang-tools-extra] Prevent linking to duplicate .a libs and dylib
Fix various tool libraries not to link to clang's .a libraries and dylib
simultaneously.  This may cause breakage, in particular through
duplicate command-line option declarations.

Differential Revision: https://reviews.llvm.org/D81967
2020-06-17 19:00:26 +02:00
Nathan James ccd127008a
[clang-tidy] warnings-as-error no longer exits with ErrorCount
When using `-warnings-as-errors`, If there are any warnings promoted to errors, clang-tidy exits with the number of warnings. This really isn't needed and can cause issues when the number of warnings doesn't fit into 8 bits as POSIX terminals aren't designed to handle more than that.
This addresses https://bugs.llvm.org/show_bug.cgi?id=46305.

Bug originally added in D15528

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D81953
2020-06-17 14:35:37 +01:00
Nathan James e1ba7241c3 [clang-tidy] simplify-bool-expr ignores template instantiations
Ignore template instantiations in the matchers, Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=46226 | readability-simplify-boolean-expr false-positive for bool from template. ]]

Reviewed By: aaron.ballman, lebedev.ri

Differential Revision: https://reviews.llvm.org/D81336
2020-06-16 13:54:48 +01:00
njames93 740575dc23 [clangd] Fix readability-else-after-return 'Adding a note without main diagnostic' crash
Fix a crash in clangd caused by an (admittidly incorrect) Remark diagnositic being emitted from readability-else-after-return.
This crash doesn't occur in clang-tidy so there are no tests there for this.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D81785
2020-06-16 12:01:56 +01:00
Andi-Bogdan Postelnicu 068fa35746 [clang-tidy] For `run-clang-tidy.py` escape the paths that are used for analysis.
Some paths can have special chars like `file++c.cpp` in this case the regex will
fail if we don't escape it.
2020-06-16 12:21:18 +03:00
Zinovy Nis c063b4a72b Fix crash on misc-redundant-expression
Differential Revision: https://reviews.llvm.org/D80896
2020-06-05 18:43:57 +03:00
Nathan James e21c3f223a [clang-tidy] ignore builtin varargs from pro-type-vararg-check
Disables the check from warning on some built in vararg functions, Address [[ https://bugs.llvm.org/show_bug.cgi?id=45860 | Clang-tidy should not consider __builtin_constant_p a variadic function. ]]

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D80887
2020-06-04 17:58:23 +01:00
Zinovy Nis 6271b96bef [clang-tidy][modernize-loop-convert] Make loop var type human readable
Differential Revision: https://reviews.llvm.org/D80536
2020-06-04 19:51:45 +03:00
Konrad Kleine e636e6b79a [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro
Summary:
This check finds macro expansions of `DISALLOW_COPY_AND_ASSIGN(Type)` and
replaces them with a deleted copy constructor and a deleted assignment operator.

Before the `delete` keyword was introduced in C++11 it was common practice to
declare a copy constructor and an assignment operator as a private members. This
effectively makes them unusable to the public API of a class.

With the advent of the `delete` keyword in C++11 we can abandon the
`private` access of the copy constructor and the assignment operator and
delete the methods entirely.

Migration example:

```
lang=dif
class Foo {
  private:
  -  DISALLOW_COPY_AND_ASSIGN(Foo);
  +  Foo(const Foo &) = delete;
  +  const Foo &operator=(const Foo &) = delete;
  };
```

Reviewers: alexfh, hokein, aaron.ballman, njames93

Reviewed By: njames93

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D80531
2020-06-03 16:56:03 -04:00
Dmitri Gribenko c1911fcb06 Replaced C++2a with C++20 in clang-tools-extra
Reviewers: hlopko, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: wuzish, aaron.ballman, nemanjai, kbarton, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81087
2020-06-03 14:54:10 +02:00
Nico Weber fd2740143e attempt to fix build after add51e152a 2020-06-03 06:49:50 -04:00
Matthias Gehre add51e152a [clang-tidy] add new check readability-use-anyofallof
Summary:
Finds range-based for loops that can be replaced by a call to ``std::any_of`` or
``std::all_of``. In C++ 20 mode, suggests ``std::ranges::any_of`` or
``std::ranges::all_of``.
For now, no fixits are produced.

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77572
2020-06-03 12:19:06 +02:00
Nathan James 5952125691 clang-tidy and clang-query wont crash with invalid command line options
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=46141 | clang-tidy crashed for unknown command line argument. ]]

Reviewed By: aaron.ballman, thakis

Differential Revision: https://reviews.llvm.org/D80879
2020-05-31 17:41:29 +01:00
Nathan James f4b0ebb89b Revert "clang-tidy and clang-query wont crash with invalid command line options"
This reverts commit f23ddbe3c3.
2020-05-31 16:40:09 +01:00
Nathan James f23ddbe3c3 clang-tidy and clang-query wont crash with invalid command line options
Summary: Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=46141 | clang-tidy crashed for unknown command line argument. ]]

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80879
2020-05-31 16:01:41 +01:00
Nathan James 44119626de [clang-tidy] RenamerClangTidyChecks ignore builtin and command line macros
Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=42635 | readability-identifier-naming option MacroDefinitionCase should ignore macros passed as parameters. ]]

Reviewers: aaron.ballman, alexfh, gribozavr2, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80631
2020-05-30 20:49:33 +01:00
Jan Korous 1a5c97f3a4 [ASTMatchers] Matchers related to C++ inheritance
Differential Revision: https://reviews.llvm.org/D79063
2020-05-29 12:38:01 -07:00
Yitzhak Mandelbaum a1b88afe46 [clang-tidy] Fix build broken by commit 7cfdff7b4a (D80023) 2020-05-28 13:39:58 -04:00
Tom Lokovic 7cfdff7b4a [clang-tidy] Add abseil-string-find-str-contains checker.
Summary: This adds a checker which suggests replacing string.find(...) == npos with absl::StrContains.

Reviewers: alexfh, hokein, aaron.ballman, njames93, ymandel

Reviewed By: ymandel

Subscribers: ymandel, Eugene.Zelenko, xazax.hun, mgorny, Charusso, phosek, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D80023
2020-05-28 12:35:57 -04:00
Stephen Kelly 2be92b7f7e Fix ignore-traversal to call correct method
As is done by ignoreParenImpCasts(). We were not previously calling the
correct internal method.  Adjust tests to account for this.
2020-05-24 22:33:10 +01:00
Nathan James 4c5818dd8c [clang-tidy] Fix potential assert in use-noexcept check
Summary: Fix a potential assert in use-noexcept check if there is an issue getting the `TypeSourceInfo` as well as a small clean up.

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80371
2020-05-24 14:40:58 +01:00
Stephen Kelly 5e9392deaf Add explicit traversal mode to matchers for implicit constructors 2020-05-24 12:36:15 +01:00
Joe Ranieri e4bb3e25e4 [clang-tidy] Expand the list of functions in bugprone-unused-return-value
This change adds common C, C++, and POSIX functions to the clang-tidy unused return value checker.

Differential Revision: https://reviews.llvm.org/D76083
2020-05-22 12:57:58 -04:00
Stephen Kelly a72307c3a6 Set traversal explicitly where needed in clang-tidy
Reviewers: aaron.ballman

Subscribers: nemanjai, kbarton, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72530
2020-05-21 22:34:37 +01:00
Kirill Bobyrev 968d293063 [clang-tidy] NFC: Cleanup Python scripts
Summary: Silence few PEP8 warnings.

Reviewers: hokein

Reviewed By: hokein

Subscribers: Eugene.Zelenko, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78985
2020-05-18 12:21:27 +02:00
Nathan James 4f0cc10bf5 [NFC][clang-tidy] use hasOperands in place of hasEitherOperand 2020-05-18 10:11:22 +01:00
Nathan James 7af0c8559b [clang-tidy] Transformer checks now store IncludeStyle option 2020-05-16 01:14:55 +01:00
Nathan James aef778d4d3 [clang-tidy] Fix assertion in RenamerClangTidyChecks 2020-05-15 12:15:35 +01:00
Sylvestre Ledru a832fc4b0c Revert two patches, not ready to be shared
Revert "clang-tidy doc: add a note for checkers with an autofix"

This reverts commit dc0f79ea5b.

Revert "add_new_check.py: Update of the template to add an autofix section"

This reverts commit f97f92e5b0.
2020-05-10 11:27:13 +02:00
Sylvestre Ledru f97f92e5b0 add_new_check.py: Update of the template to add an autofix section
Summary: As discussed here: https://reviews.llvm.org/D77983

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78052
2020-05-10 11:25:19 +02:00
Nathan James 0e49ac73ea [NFC] Small rework to RenamerClangTidyCheck addUsage 2020-05-09 18:57:05 +01:00
Nathan James 82ddae061b [clang-tidy] RenamerClangTidy now renames dependent member expr when the member can be resolved
Summary:
Sometimes in templated code Member references are reported as `DependentScopeMemberExpr` because that's what the standard dictates, however in many trivial cases it is easy to resolve the reference to its actual Member.
Take this code:
```
template<typename T>
class A{
  int value;
  A& operator=(const A& Other){
    value = Other.value;
    this->value = Other.value;
    return *this;
  }
};
```
When ran with `clang-tidy file.cpp -checks=readability-identifier-naming --config="{CheckOptions: [{key: readability-identifier-naming.MemberPrefix, value: m_}]}" -fix`
Current behaviour:
```
template<typename T>
class A{
  int m_value;
  A& operator=(const A& Other){
    m_value = Other.value;
    this->value = Other.value;
    return *this;
  }
};
```
As `this->value` and `Other.value` are Dependent they are ignored when creating the fix-its, however this can easily be resolved.
Proposed behaviour:
```
template<typename T>
class A{
  int m_value;
  A& operator=(const A& Other){
    m_value = Other.m_value;
    this->m_value = Other.m_value;
    return *this;
  }
};
```

Reviewers: aaron.ballman, JonasToth, alexfh, hokein, gribozavr2

Reviewed By: aaron.ballman

Subscribers: merge_guards_bot, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D73052
2020-05-09 16:21:49 +01:00
Haojian Wu 2a3498e24f [clang-tidy] Exclude function calls in std namespace for bugprone-argument-comment.
Reviewers: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79494
2020-05-07 09:00:49 +02:00
Tamás Zolnai fedd52682e [clang-tidy]: Add cert-str34-c alias for bugprone-signed-char-misuse.
Summary:
Added `DiagnoseSignedUnsignedCharComparisons` option to
filter out unrelated use cases. The SEI cert catches explicit
integer casts (two use cases), while in the case of
`signed char` \ `unsigned char` comparison, we have implicit
conversions.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79334
2020-05-06 12:36:01 +02:00
Dmitri Gribenko 3adaa97f01 Fix ForRangeCopyCheck not triggering on iterators returning elements by value in C++17.
Summary:
The AST is different in C++17 in that there is no MaterializeTemporaryExpr for in the AST for a loop variable that is initialized from an iterator that returns its elements by value.

Account for this by checking that the variable is not initialized by an operator* call that returns a value type.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79440
2020-05-06 09:42:13 +02:00
Konrad Kleine 24b4965ce6 [clang/clang-tools-extra] Fix BZ44437 - add_new_check.py does not work with Python 3
Summary:
This fixes https://bugs.llvm.org/show_bug.cgi?id=44437.

Thanks to Arnaud Desitter for providing the patch in the bug report!

A simple example program to reproduce this error is this:

```lang=python

import sys

with open(sys.argv[0], 'r') as f:
  lines = f.readlines()
lines = iter(lines)
line = lines.next()
print(line)
```

which will error with this in python python 3:

```
Traceback (most recent call last):
  File "./mytest.py", line 8, in <module>
    line = lines.next()
AttributeError: 'list_iterator' object has no attribute 'next'
```

Here's the same strategy applied to my test program as applied to the `add_new_check.py` file:

```lang=python

import sys

with open(sys.argv[0], 'r') as f:
  lines = f.readlines()
lines = iter(lines)
line = next(lines)
print(line)
```

The built-in function `next()` is new since Python 2.6: https://docs.python.org/2/library/functions.html#next

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79419
2020-05-05 17:22:50 -04:00
Yitzhak Mandelbaum c5b1a03525 [clang-tidy] In TransformerClangTidyCheck, support option IncludeStyle.
Summary:
The new option allows the user to specify which file naming convention is used
by the source code ('llvm' or 'google').

Reviewers: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79380
2020-05-05 10:38:31 -04:00
Sam McCall d10c995b4d std::isspace -> llvm::isSpace (where locale should be ignored)
I've left out some cases where I wasn't totally sure this was right or
whether the include was ok (compiler-rt) or idiomatic (flang).
2020-05-02 15:36:04 +02:00
Tamás Zolnai 030ff901f4 [clang-tidy] extend bugprone-signed-char-misuse check with array subscript case.
Summary:
To cover STR34-C rule's second use case, where ``signed char`` is
used for array subscript after an integer conversion. In the case
of non-ASCII character this conversion will result in a value
in excess of UCHAR_MAX.

There is another clang-tidy check which catches these cases.
cppcoreguidelines-pro-bounds-constant-array-index catches any
indexing which is not integer constant. I think this check is
very strict about the index (e.g. constant), so it's still useful
to cover the ``signed char`` use case in this check, so we
can provide a way to catch the SEI cert rule's use cases on a
codebase, where this CPP guideline is not used.

Reviewers: aaron.ballman, njames93

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D78904
2020-05-02 14:05:05 +02:00
Paula Toth 8683f5de53 [clang-tidy] Add check callee-namespace.
Summary:
This check will ensure that all calls to functions resolve to one inside the `__llvm_libc` namespace.

This is done to ensure that if we include a public header then we don't accidentally call into the a function within the global namespace.

Reviewers: aaron.ballman, njames93

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits, sivachandra

Tags: #clang-tools-extra, #libc-project, #clang

Differential Revision: https://reviews.llvm.org/D78890
2020-04-28 17:22:23 -07:00
Matthias Gehre 145dcef8bd [clang-tidy] modernize-use-using: Fix broken fixit with InjectedClassName
Summary:
Before this PR, `modernize-use-using` would transform the typedef in
```
template <int A>
struct InjectedClassName {
  typedef InjectedClassName b;
};
```
into `using b = InjectedClassName<A>;` and
```
template <int>
struct InjectedClassNameWithUnnamedArgument {
  typedef InjectedClassNameWithUnnamedArgument b;
};
```
into `using b = InjectedClassNameWithUnnamedArgument<>;`.
The first fixit is surprising because its different than the code
before, but the second fixit doesn't even compile.

This PR adds an option to the TypePrinter to print InjectedClassNameType without
template parameters (i.e. as written).

Reviewers: aaron.ballman, alexfh, hokein, njames93

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77979
2020-04-27 14:23:23 +02:00
Benjamin Kramer c758181525 [clang-tidy] Use StringSwitch in a bunch of places. NFCI. 2020-04-26 17:24:47 +02:00
Haojian Wu a466e4be38 [clangd] Fix modernize-loop-convert "multiple diag in flight" crash.
Summary:
this maybe not ideal, but it is trivial and does fix the crash.

Fixes https://github.com/clangd/clangd/issues/156.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78715
2020-04-24 11:16:36 +02:00
Andi-Bogdan Postelnicu bbb7921da9 [clang-tidy] Add option to use alpha checkers from clang-analyzer when using `run-clang-tidy.py`
Summary: Add option to use alpha checkers from clang-analyzer when using `run-clang-tidy.py`.

Reviewers: JonasToth

Subscribers: xazax.hun, baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, dkrupp, Charusso, ASDenysPetrov, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77882
2020-04-23 11:36:50 +03:00
Aaron Ballman 6a30894391 C++2a -> C++20 in some identifiers; NFC. 2020-04-21 15:37:19 -04:00
Kim Viggedal b2d8c89ea4 Remove false positive in AvoidNonConstGlobalVariables.
Addresses post-commit review feedback from https://reviews.llvm.org/D70265
2020-04-15 14:48:06 -04:00
Dmitry Polukhin cb1ee34e9d [clang-tidy] Optional inheritance of file configs from parent directories
Summary:
Without this patch clang-tidy stops finding file configs on the nearest
.clang-tidy file. In some cases it is not very convenient because it
results in common parts duplication into every child .clang-tidy file.
This diff adds optional config inheritance from the parent directories
config files.

Test Plan:

Added test cases in existing config test.

Reviewers: alexfh, gribozavr2, klimek, hokein

Subscribers: njames93, arphaman, xazax.hun, aheejin, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75184
2020-04-15 06:41:31 -07:00
Nathan James 672207c319 [clang-tidy] Convert config options that are bools to use the bool overload of get(GlobalOrLocal)?
Summary: This was done with a script that looks for calls to Options.get(GlobalOrLocal) that take an integer for the second argument and the result is either compared not equal to 0 or implicitly converted to bool. There may be other occurances

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: wuzish, nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77831
2020-04-12 23:06:09 +01:00
Michael Wyman 89f1321fe4 [clang-tidy] Add check to find calls to NSInvocation methods under ARC that don't have proper object argument lifetimes.
Summary: This check is similar to an ARC Migration check that warned about this incorrect usage under ARC, but most projects are no longer undergoing migration from pre-ARC code. The documentation for NSInvocation is not explicit about these requirements and incorrect usage has been found in many of our projects.

Reviewers: stephanemoore, benhamilton, dmaclach, alexfh, aaron.ballman, hokein, njames93

Reviewed By: stephanemoore, benhamilton, aaron.ballman

Subscribers: xazax.hun, Eugene.Zelenko, mgorny, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D77571
2020-04-10 08:51:21 -07:00
Matthias Gehre eaa5559094 [clang-tidy] misc-unused-parameters: Don't remove parameter from lambda
Summary:
Previously, the check would fix
```
using fn = void(int);
void f(fn *);
void test() {
  // CHECK-MESSAGES: :[[@LINE+2]]:12: warning: parameter 'I' is unused
  // CHECK-FIXES: {{^}}  f([](int  /*I*/) {
  f([](int I) { return; });
}
```
into
`f([]() { return; });` which breaks compilation. Now the check is disabled from Lambdas.

The AST is not so easy to use. For
```
    auto l = [](int) {  return;  };
    f(l);
```
one gets
```
 `-CallExpr <line:7:5, col:8> 'void'
      |-ImplicitCastExpr <col:5> 'void (*)(fn *)' <FunctionToPointerDecay>
      | `-DeclRefExpr <col:5> 'void (fn *)' lvalue Function 0x55a91a545e28 'f' 'void (fn *)'
      `-ImplicitCastExpr <col:7> 'void (*)(int)' <UserDefinedConversion>
        `-CXXMemberCallExpr <col:7> 'void (*)(int)'
          `-MemberExpr <col:7> '<bound member function type>' .operator void (*)(int) 0x55a91a546850
            `-ImplicitCastExpr <col:7> 'const (lambda at line:6:14)' lvalue <NoOp>
              `-DeclRefExpr <col:7> '(lambda at line:6:14)':'(lambda at line:6:14)' lvalue Var 0x55a91a5461c0 'l' '(lambda at line:6:14)':'(lambda at line:6:14)'
```
There is no direct use of the `operator()(int I)` of the lambda, so the `!Indexer->getOtherRefs(Function).empty()`
does not fire. In the future, we might be able to use the conversion operator `operator void (*)(int)` to mark
the call operator as having an "other ref".

Reviewers: aaron.ballman, alexfh, hokein, njames93

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77680
2020-04-09 19:26:41 +02:00
Yitzhak Mandelbaum 5e5d366718 [libTooling] Simplify the representation of Transformer's RewriteRules.
Summary:
This revision simplifies the representation of edits in rewrite rules. The
simplified form is more general, allowing the user more flexibility in building
custom edit specifications.

The changes extend the API, without changing the signature of existing
functions. So this only risks breaking users that directly accessed the
`RewriteRule` struct.

Reviewers: gribozavr2

Subscribers: jfb, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77419
2020-04-08 08:45:41 -04:00
Johannes Doerfert 530377018f [OpenMP] "UnFix" last layering problem with FrontendOpenMP
It seems one target was missed in D77666 which kept some bots red [0].

[0] http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/12079/steps/build%20stage%201/logs/stdio
2020-04-07 22:47:41 -05:00
Nathan James 0361798dbe [clang-tidy] Fix buildbot failing with explicit specialization in class scope 2020-04-07 21:30:29 +01:00
Johannes Doerfert f9d558c871 [OpenMP] "UnFix" layering problem with FrontendOpenMP
This reverts commit 97aa593a83 as it
causes problems (PR45453) https://reviews.llvm.org/D77574#1966321.

This additionally adds an explicit reference to FrontendOpenMP to
clang-tidy where ASTMatchers is used.

This is hopefully just a temporary solution. The dependence on
`FrontendOpenMP` from `ASTMatchers` should be handled by CMake
implicitly, not us explicitly.

Reviewed By: aheejin

Differential Revision: https://reviews.llvm.org/D77666
2020-04-07 14:41:18 -05:00
Nathan James 9dff9ecdd1 [clang-tidy] Change checks that take enum configurations to use a new access method.
Summary: Change all checks that take enums as configuration to use enum specific methods in `ClangTidyCheck::OptionsView`.

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: wuzish, nemanjai, kbarton, arphaman, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D76606
2020-04-07 20:04:31 +01:00
Nathan James fcf7cc268f [clang-tidy] Added support for validating configuration options
Summary:
Adds support for `ClangTidyCheck::OptionsView` to deteremine:
  - If an option is found in the configuration.
  - If an integer option read from configuration is parsable to an integer.
  - Parse and Serialize enum configuration options directly using a mapping from `llvm::StringRef` to `EnumType`.
  - If an integer or enum option isn't parseable but there is a default value it will issue a warning to stderr that the config value hasn't been used.
  - If an enum option isn't parsable it can provide a hint if the value was a typo.

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D77085
2020-04-07 19:54:34 +01:00
Johannes Doerfert 97aa593a83 [OpenMP] Fix layering problem with FrontendOpenMP
Summary:
ASTMatchers is used in various places and it now exposes the
LLVMFrontendOpenMP library to its users without them needing to depend
on it explicitly.

Reviewers: lebedev.ri

Subscribers: mgorny, yaxunl, bollu, guansong, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77574
2020-04-06 13:04:26 -05:00
Paula Toth 00a5755897 [clang-tidy] Add check llvmlibc-implementation-in-namespace.
Summary:
This check makes sure all llvm-libc implementations falls within the `__llvm_libc` namespace.

Reviewers: alexfh, aaron.ballman, hokein, njames93

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, libc-commits, mgorny, xazax.hun, MaskRay, cfe-commits, sivachandra

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D76818
2020-04-06 10:49:49 -07:00
Johannes Doerfert 8ea07f62a6 [OpenMP] Add extra qualification to OpenMP clause id
Forgot to adjust this use in 419a559c5a.
2020-04-05 23:10:58 -05:00
Kazuaki Ishizaki dd5571d51a [clang-tools-extra] NFC: Fix trivial typo in documents and comments
Differential Revision: https://reviews.llvm.org/D77458
2020-04-05 15:28:40 +09:00
Kazuaki Ishizaki abdd042bb7 [clang-tools-extra] NFC: Fix trivial typo in documents and comments
Differential Revision: https://reviews.llvm.org/D77458
2020-04-05 11:26:19 +09:00
Tamás Zolnai 0f9e1e3ae7 [clang-tidy]: fix false positive of cert-oop54-cpp check.
Summary:
It seems we need a different matcher for binary operator
in a template context.

Fixes this issue:
https://bugs.llvm.org/show_bug.cgi?id=44499

Reviewers: aaron.ballman, alexfh, hokein, njames93

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D76990
2020-04-04 17:19:17 +02:00
Nathan James 2c7ea1c4c5 [clang-tidy] Address false positive in modernize-use-default-member-init
Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=45363 | incorrect warning emitted by "modernize-use-default-member-init" (new to 10.0.0) ]].

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77199
2020-04-03 19:43:46 +01:00
Benjamin Kramer 02cb21df3f Make helpers static. NFC. 2020-04-03 12:48:25 +02:00
Nathan James 3807079d70 [clang-tidy] Fix crash in readability-redundant-string-cstr
Summary: Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=45286 | clang-tidy-11: Crash in DynTypedMatcher::matches during readability-redundant-string-cstr check ]]

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D76761
2020-03-31 13:27:32 +01:00
Nathan Ridge b9d9968f63 [clangd] Handle clang-tidy suppression comments for diagnostics inside macro expansions
Summary:
Not handling this was a side-effect of being overly cautious when trying
to avoid reading files for which clangd doesn't have the source mapped.

Fixes https://github.com/clangd/clangd/issues/266

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet,
usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75286
2020-03-29 15:19:13 -04:00
Nathan Ridge 15f1fe1506 clang-format fixes in ClangTidyDiagnosticConsumer.cpp and DiagnosticsTets.cpp
Subscribers: jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77023
2020-03-29 15:19:09 -04:00
Benjamin Kramer 4065e92195 Upgrade some instances of std::sort to llvm::sort. NFC. 2020-03-28 19:23:29 +01:00
Nathan James 7693a9b931 [clang-tidy] Fix RenamerClangTidy handling qualified TypeLocs
Summary:
Previously if a type was accessed with a qualifier, RenamerClangTidy wouldn't rename the TypeLoc, this patch addresses this shortfall by trying to find the Unqualified TypeLoc first. Also fixed a broken test case that was dependent on this broken behaviour.

Example:
```
struct a{};

void foo(const a&);
void foo(a&);
void foo(a);
void foo(a&&);
void foo(const a);
```
exec `-checks=readability-identifier-naming --config="{CheckOptions: [{key: readability-identifier-naming.StructCase, value: CamelCase}]}" -fix`
Current Behaviour:
```
struct A{};

void foo(const a&);
void foo(A&);
void foo(A);
void foo(A&&);
void foo(const a);
```
Proposed new behaviour:
```
struct A{};

void foo(const A&);
void foo(A&);
void foo(A);
void foo(A&&);
void foo(const A);
```

Reviewers: aaron.ballman, gribozavr2, alexfh

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76549
2020-03-23 13:45:34 +00:00
Whisperity df5fa48739 [clang-tidy][NFC] Add missing check group docs and order entries
Differential Revision: https://reviews.llvm.org/D76541
2020-03-23 11:05:34 +01:00
abelkocsis 0f4c70dd3e [clang-tidy] Add spuriously-wake-up-functions check
Summary:
According to
https://wiki.sei.cmu.edu/confluence/display/cplusplus/CON54-CPP.+Wrap+functions+that+can+spuriously+wake+up+in+a+loop
and
https://wiki.sei.cmu.edu/confluence/display/c/CON36-C.+Wrap+functions+that+can+spuriously+wake+up+in+a+loop
misc-spuriously-wake-up-functions check is created. The check finds
`cnd_wait` or `wait` function calls in an `IfStmt` and  warns the user to
replace it with a `WhileStmt` or use it with a lambda parameter.

Reviewers: aaron.ballman, alexfh, hokein, jfb, Charusso

Reviewed By: aaron.ballman

Subscribers: sylvestre.ledru, whisperity, Eugene.Zelenko, mgorny, dexonsmith, cfe-commits, gerazo, xazax.hun, steakhal, Charusso

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D70876
2020-03-21 12:04:03 +01:00
Paula Toth 556b917fff [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes
Summary:
Made llvmlibc::RestrictSystemLibcHeadersCheck a subclass of protability::RestrictSystemIncludesCheck to re-use common code between the two.
This also adds the ability to white list linux development headers.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: mgorny, xazax.hun, MaskRay, cfe-commits, sivachandra

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D76395
2020-03-20 15:53:05 -07:00
Nathan James 1365ab4b63 [clang-tidy] RenamerClangTidy now correctly renames `using namespace` decls
Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=45039 | readability-identifier-naming doesn't rename using namespace correctly. ]]

Reviewers: aaron.ballman, gribozavr2, JonasToth, hokein, alexfh

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75220
2020-03-18 22:14:40 +00:00
Alex Cameron 9bb5685b21 [clang-tidy] misc-unconventional-assign-operator suggest to use rvalue references in C++03 mode
Summary:
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=27702
I wasn't sure how this type of thing is usually tested. So any advice would be appreciated.
`check-llvm`, `check-clang` and `check-clang-tools` are clean for me.
**C++98**
```
tetsuo@garland-c-16-sgp1-01:~/dev/llvm-project/test$ cat compile_commands.json
[
{
  "directory": "/home/tetsuo/dev/llvm-project/test",
  "command": "/usr/bin/c++      -std=gnu++98 -o CMakeFiles/test.dir/test.cpp.o -c /home/tetsuo/dev/llvm-project/test/test.cpp",
  "file": "/home/tetsuo/dev/llvm-project/test/test.cpp"
}
]
tetsuo@garland-c-16-sgp1-01:~/dev/llvm-project/test$ ../build/bin/clang-tidy --checks=misc-unconventional-assign-operator test.cpp
3053 warnings generated.
/home/tetsuo/dev/llvm-project/test/test.cpp:7:3: warning: operator=() should take 'Foo const&' or 'Foo' [misc-unconventional-assign-operator]
  Foo &operator=(Foo &Other) {
  ^
Suppressed 3052 warnings (3052 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
```
**C++17**
```
tetsuo@garland-c-16-sgp1-01:~/dev/llvm-project/test$ cat compile_commands.json
[
{
  "directory": "/home/tetsuo/dev/llvm-project/test",
  "command": "/usr/bin/c++      -std=gnu++17 -o CMakeFiles/test.dir/test.cpp.o -c /home/tetsuo/dev/llvm-project/test/test.cpp",
  "file": "/home/tetsuo/dev/llvm-project/test/test.cpp"
}
]
tetsuo@garland-c-16-sgp1-01:~/dev/llvm-project/test$ ../build/bin/clang-tidy --checks=misc-unconventional-assign-operator test.cpp
5377 warnings generated.
/home/tetsuo/dev/llvm-project/test/test.cpp:7:3: warning: operator=() should take 'Foo const&', 'Foo&&' or 'Foo' [misc-unconventional-assign-operator]
  Foo &operator=(Foo &Other) {
  ^
Suppressed 5376 warnings (5376 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
```

Reviewers: njames93, MaskRay, alexfh, hokein, aaron.ballman

Reviewed By: njames93

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D75901
2020-03-18 21:39:23 +00:00
Haojian Wu 8a593e29ab [AST] Correct the CXXOperatorCallExpr source range.
Summary:
Previously, the range for "->" CXXOperatorCallExpr is the range of the
class object (not including the operator!), e.g. "[[vector_ptr]]->size()".

This patch includes the range of the operator, which fixes the issue
where clangd doesn't go to the overloaded operator "->" definition.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76128
2020-03-16 16:51:10 +01:00
Paweł Barań 2f20417ef0 Add AllowMissingMoveFunctionsWhenCopyIsDeleted flag to cppcoreguidelines-special-member-functions
The flag allows classes to don't define move operations when copy operations
are explicitly deleted. This flag is related to Google C++ Style Guide
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types
2020-03-16 08:14:48 -04:00
Tamás Zolnai 04410c565a [clang-tidy] extend bugprone-signed-char-misuse check.
Summary:
Cover a new use case when using a 'signed char' as an integer
might lead to issue with non-ASCII characters. Comparing
a 'signed char' with an 'unsigned char' using equality / unequality
operator produces an unexpected result for non-ASCII characters.

Reviewers: aaron.ballman, alexfh, hokein, njames93

Reviewed By: njames93

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75749
2020-03-14 20:00:00 +01:00
Hyrum Wright 3860b2a0bd [clang-tidy] Update Abseil Duration Conversion check to find more cases.
This change improves the check to handle cases with internal scalar
multiplication.

Differential Revision: https://reviews.llvm.org/D75558
2020-03-13 12:52:37 -04:00
Kim Viggedal 512767eb3f Add CppCoreGuidelines I.2 "Avoid non-const global variables" check
Cpp Core Guideline I.2, a.k.a "Avoid non-const global variables"
For detailed documentation, see:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#i2-avoid-non-const-global-variables
2020-03-13 10:05:13 -04:00
Paula Toth eb41cc6198 [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.
Summary: This adds a new module to enforce standards specific to the llvm-libc project. This change also adds the first check which restricts user from including system libc headers accidentally which can lead to subtle bugs that would be a challenge to detect.

Reviewers: alexfh, hokein, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: juliehockett, arphaman, jfb, abrachet, sivachandra, Eugene.Zelenko, njames93, mgorny, xazax.hun, MaskRay, cfe-commits

Tags: #clang-tools-extra, #libc-project, #clang

Differential Revision: https://reviews.llvm.org/D75332
2020-03-12 11:46:05 -07:00
Jonathan Roelofs 2c9cf9f4dd [clang-tidy] New check: bugprone-suspicious-include
Detects and fixes suspicious code like: `#include "foo.cpp"`.

Inspired by: https://twitter.com/lefticus/status/1228458240364687360?s=20

https://reviews.llvm.org/D74669
2020-03-12 09:59:28 -06:00
Reid Kleckner d7c5037e6b Prune TargetInfo.h include from ParsedAttr.h, NFC
Saves ~400 includes of related headers:

$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \
    | grep '^[-+] ' | sort | uniq -c | sort -nr
    468 -    llvm-project/clang/include/clang/Basic/TargetInfo.h
    468 -    llvm-project/clang/include/clang/Basic/TargetCXXABI.h
    368 -    llvm-project/llvm/include/llvm/Support/CodeGen.h
    368 -    llvm-project/clang/include/clang/Basic/XRayInstr.h
    368 -    llvm-project/clang/include/clang/Basic/CodeGenOptions.h
    368 -    llvm-project/clang/include/clang/Basic/CodeGenOptions.def
    367 -    llvm-project/llvm/include/llvm/ADT/FloatingPointMode.h
    367 -    llvm-project/clang/include/clang/Basic/DebugInfoOptions.h
2020-03-11 20:47:11 -07:00
Reid Kleckner e08464fb45 Avoid including FileManager.h from SourceManager.h
Most clients of SourceManager.h need to do things like turning source
locations into file & line number pairs, but this doesn't require
bringing in FileManager.h and LLVM's FS headers.

The main code change here is to sink SM::createFileID into the cpp file.
I reason that this is not performance critical because it doesn't happen
on the diagnostic path, it happens along the paths of macro expansion
(could be hot) and new includes (less hot).

Saves some includes:
    309 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileManager.h
    272 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileSystemOptions.h
    271 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/VirtualFileSystem.h
    267 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/FileSystem.h
    266 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Chrono.h

Differential Revision: https://reviews.llvm.org/D75406
2020-03-11 13:53:12 -07:00
Paula Toth ebdb98f254 [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.
Summary:
Created a general check for restrict-system-includes under portability as recommend in the comments under D75332. I also fleshed out the user facing documentation to show examples for common use-cases such as allow-list, block-list, and wild carding.

Removed fuchsia's check as per phosek sugguestion.

Reviewers: aaron.ballman, phosek, alexfh, hokein, njames93

Reviewed By: phosek

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, phosek, cfe-commits, MaskRay

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D75786
2020-03-10 13:33:06 -07:00
Nathan James 66945b62f4 Add Optional overload to DiagnosticBuilder operator <<
Reviewers: aaron.ballman, gribozavr2, lebedev.ri

Reviewed By: gribozavr2

Subscribers: wuzish, nemanjai, kbarton, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75714
2020-03-10 17:44:10 +00:00
Nico Weber 714466bf36 Revert "[clang-tidy] New check: bugprone-suspicious-include"
This reverts commit 1e0669bfe0
(and follow-ups 698a127129 and
52bbdad7d6).
The tests fail fail on Windows, see https://reviews.llvm.org/D74669
2020-03-10 10:28:20 -04:00
Nathan James 1fc5be0669 [NFC] Tweak OptionsUtils 2020-03-10 12:50:58 +00:00
Nathan James 97572fa6e9 [NFC] use hasAnyOperatorName and hasAnyOverloadedOperatorName functions in clang-tidy matchers 2020-03-10 00:42:21 +00:00
Jonathan Roelofs 1e0669bfe0 [clang-tidy] New check: bugprone-suspicious-include
Detects and fixes suspicious code like: `#include "foo.cpp"`.

Inspired by: https://twitter.com/lefticus/status/1228458240364687360?s=20

https://reviews.llvm.org/D74669
2020-03-09 15:54:32 -06:00
Jonathan Roelofs c71ef7a85d Drop HEADER_ per review feedback on D74669 2020-03-09 12:14:22 -06:00
Jonathan Roelofs 47caa69120 [clang-tidy] Use ; as separator for HeaderFileExtensions
... and deprecate use of ',' for the same.

https://reviews.llvm.org/D75621
2020-03-09 11:32:44 -06:00
Jonathan Roelofs 3486cc014b [clang-tidy] Generalize HeaderFileExtensions.{h,cpp}. NFC
https://reviews.llvm.org/D75489
2020-03-09 11:32:44 -06:00
Nathan James 2ce821cbc9 Fix build failure from rG223a43ee8d89 2020-03-09 08:12:52 +00:00
Nathan James 223a43ee8d [clang-tidy] [NFC] Remove unnecessary matchers
Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: wuzish, nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75803
2020-03-09 07:38:15 +00:00
Nathan James fc3c80c386 [ASTMatchers] adds isComparisonOperator to BinaryOperator and CXXOperatorCallExpr
Reviewers: aaron.ballman, gribozavr2

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75800
2020-03-09 00:05:10 +00:00
Nathan James dcba401a39 Fix 45129: Incorrect generated configuration modernize-make-shared.IncludeStyle 2020-03-06 00:07:08 +00:00
Nathan James e40a742a50 [clang-tidy] Change checks to use new isLanguageVersionSupported restriction
Summary: Modifies all checks that are language version dependent to use `isLanguageVersionSupported`

Reviewers: jdoerfert, lebedev.ri, aaron.ballman, gribozavr2, Eugene.Zelenko

Reviewed By: gribozavr2

Subscribers: wuzish, nemanjai, xazax.hun, hiraditya, kbarton, steven_wu, dexonsmith, arphaman, lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75340
2020-03-03 16:43:45 +00:00
Joe Turner 071002ffdb [clang-tidy] Copy the Ranges field from the Diagnostic when creating the ClangTidyError
Differential Revision: https://reviews.llvm.org/D68887
2020-03-02 12:39:16 +01:00
Stefanos Baziotis 21390eab4c [ADT][NFC] SCCIterator: Change hasLoop() to hasCycle() 2020-03-01 19:17:21 +02:00
Karasev Nikita 365c99fd7d Skip TemplateSpecializedType in modernize-pass-by-value.
Existing 'modernize-pass-by-value' check works only with non template values in
initializers. Fixes PR37210.
2020-02-28 09:17:16 -05:00
Nathan James 39c4246e1e [clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation

Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein

Reviewed By: gribozavr2

Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 13:05:05 +00:00
Reid Kleckner 86565c1309 Avoid SourceManager.h include in RawCommentList.h, add missing incs
SourceManager.h includes FileManager.h, which is expensive due to
dependencies on LLVM FS headers.

Remove dead BeforeThanCompare specialization.

Sink ASTContext::addComment to cpp file.

This reduces the time to compile a file that does nothing but include
ASTContext.h from ~3.4s to ~2.8s for me.

Saves these includes:
    219 -    ../clang/include/clang/Basic/SourceManager.h
    204 -    ../clang/include/clang/Basic/FileSystemOptions.h
    204 -    ../clang/include/clang/Basic/FileManager.h
    165 -    ../llvm/include/llvm/Support/VirtualFileSystem.h
    164 -    ../llvm/include/llvm/Support/SourceMgr.h
    164 -    ../llvm/include/llvm/Support/SMLoc.h
    161 -    ../llvm/include/llvm/Support/Path.h
    141 -    ../llvm/include/llvm/ADT/BitVector.h
    128 -    ../llvm/include/llvm/Support/MemoryBuffer.h
    124 -    ../llvm/include/llvm/Support/FileSystem.h
    124 -    ../llvm/include/llvm/Support/Chrono.h
    124 -    .../MSVCSTL/include/stack
    122 -    ../llvm/include/llvm-c/Types.h
    122 -    ../llvm/include/llvm/Support/NativeFormatting.h
    122 -    ../llvm/include/llvm/Support/FormatProviders.h
    122 -    ../llvm/include/llvm/Support/CBindingWrapping.h
    122 -    .../MSVCSTL/include/xtimec.h
    122 -    .../MSVCSTL/include/ratio
    122 -    .../MSVCSTL/include/chrono
    121 -    ../llvm/include/llvm/Support/FormatVariadicDetails.h
    118 -    ../llvm/include/llvm/Support/MD5.h
    109 -    .../MSVCSTL/include/deque
    105 -    ../llvm/include/llvm/Support/Host.h
    105 -    ../llvm/include/llvm/Support/Endian.h

Reviewed By: aaron.ballman, hans

Differential Revision: https://reviews.llvm.org/D75279
2020-02-27 13:49:40 -08:00
Eugene Zelenko db8911aad7 [clang-tidy] rename_check.py: maintain alphabetical order in Renamed checks section
Summary:
Also use //check// in add_new_check.py for terminology consistency.

PS

My GitHub ID is [[ https://github.com/EugeneZelenko | EugeneZelenko ]], if it's necessary for attribution.

Reviewers: alexfh, hokein, aaron.ballman, njames93, MyDeveloperDay

Reviewed By: njames93

Subscribers: Andi, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D73580
2020-02-20 17:31:08 +00:00
Roman Lebedev c8f9e526bc
[clang-tidy] misc-no-recursion: point to the function defs, not decls
Results in slightly better UX.
This actually was the initial intent, but it kinda got lost along the way.
2020-02-20 14:17:30 +03:00
Nathan James d1d5180e69 [NFC] Fix issues with clang-tidy checks list.rst
Added FixItHint comments to ReservedIdentifierCheck and IdentifierNamingCheck to trick the python scripts into detecting a fix it is provided as it can't see the FixItHints in RenamerClangTidyCheck.cpp
2020-02-19 23:19:09 +00:00
Balázs Kéri fa6aef4427 [clang-tidy] Added a case to UnconventionalAssignOperatorCheck.
Summary:
The check accepts now a `return (*this = something);` as return
statement too (beneath of `*this`).

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: aaron.ballman

Subscribers: xazax.hun, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D74529
2020-02-19 10:07:34 +01:00
Eric Christopher 28728bf06f Fix a signed/unsigned warning promoted to error. 2020-02-18 17:49:22 -08:00
Karasev Nikita 47282b1b4b Fix PR#44620 'readability-redundant-string-cstr quick-fix causes invalid code'
static void f2(std::string&&) {}
static void f() {
	std::string const s;
	f2(s.c_str()); // readability-redundant-string-cstr previously warning
}

Skips the problematic AST pattern in the matcher.
2020-02-18 15:33:52 -05:00
Alexey Romanov 5e7d0ebf73 Cover cases like (b && c && b) in the redundant expression check.
readability-redundant-expression now detects expressions where a logical
or bitwise operator had equivalent LHS and RHS where the equivalent
operands were separated by more operands.
2020-02-18 11:42:32 -05:00
Benjamin Kramer 5fc5c7db38 Strength reduce vectors into arrays. NFCI. 2020-02-17 15:37:35 +01:00
Johannes Doerfert 803ad3137b [FIX] Repair clang-tidy check after D72304 2020-02-15 01:15:45 -06:00
Roman Lebedev 49bffa5f8b
[clang-tidy] misc-no-recursion: a new check
Summary:
Recursion is a powerful tool, but like any tool
without care it can be dangerous. For example,
if the recursion is unbounded, you will
eventually run out of stack and crash.

You can of course track the recursion depth
but if it is hardcoded, there can always be some
other environment when that depth is too large,
so said magic number would need to be env-dependent.
But then your program's behavior is suddenly more env-dependent.

Also, recursion, while it does not outright stop optimization,
recursive calls are less great than normal calls,
for example they hinder inlining.

Recursion is banned in some coding guidelines:
* SEI CERT DCL56-CPP. Avoid cycles during initialization of static objects
* JPL 2.4 Do not use direct or indirect recursion.
* I'd say it is frowned upon in LLVM, although not banned
And is plain unsupported in some cases:
* OpenCL 1.2, 6.9 Restrictions: i. Recursion is not supported.

So there's clearly a lot of reasons why one might want to
avoid recursion, and replace it with worklist handling.
It would be great to have a enforcement for it though.

This implements such a check.
Here we detect both direct and indirect recursive calls,
although since clang-tidy (unlike clang static analyzer)
is CTU-unaware, if the recursion transcends a single standalone TU,
we will naturally not find it :/

The algorithm is pretty straight-forward:
1. Build call-graph for the entire TU.
   For that, the existing `clang::CallGraph` is re-used,
   although it had to be modified to also track the location of the call.
2. Then, the hard problem: how do we detect recursion?
   Since we have a graph, let's just do the sane thing,
   and look for Strongly Connected Function Declarations - widely known as `SCC`.
   For that LLVM provides `llvm::scc_iterator`,
   which is internally an Tarjan's DFS algorithm, and is used throught LLVM,
   so this should be as performant as possible.
3. Now that we've got SCC's, we discard those that don't contain loops.
   Note that there may be more than one loop in SCC!
4. For each loopy SCC, we call out each function, and print a single example
   call graph that shows recursion -- it didn't seem worthwhile enumerating
   every possible loop in SCC, although i suppose it could be implemented.
   * To come up with that call graph cycle example, we start at first SCC node,
     see which callee of the node is within SCC (and is thus known to be in cycle),
     and recurse into it until we hit the callee that is already in call stack.

Reviewers: JonasToth, aaron.ballman, ffrankies, Eugene.Zelenko, erichkeane, NoQ

Reviewed By: aaron.ballman

Subscribers: Charusso, Naghasan, bader, riccibruno, mgorny, Anastasia, xazax.hun, cfe-commits

Tags: #llvm, #clang

Differential Revision: https://reviews.llvm.org/D72362
2020-02-13 23:37:53 +03:00
Nathan James 8c4cf23dee Fix crash in InfinteLoopCheck 2020-02-13 20:20:37 +00:00
Haojian Wu a45ca670f5 [clang-tidy] No misc-definitions-in-headers warning on C++14 variable templates.
Reviewers: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74468
2020-02-12 16:56:31 +01:00
Justin Lebar 1bd6123b78 Use std::foo_t rather than std::foo in LLVM.
Summary: C++14 migration. No functional change.

Reviewers: bkramer, JDevlieghere, lebedev.ri

Subscribers: MatzeB, hiraditya, jkorous, dexonsmith, arphaman, kadircet, lebedev.ri, usaxena95, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74384
2020-02-11 15:12:51 -08:00
Nathan James c69ec64768 [clang-tidy] Added check to disable bugprone-infinite-loop on known false condition
Summary: Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=44816 | bugprone-infinite-loop false positive with CATCH2 ]] by disabling the check on loops where the condition is known to always eval as false, in other words not a loop.

Reviewers: aaron.ballman, alexfh, hokein, gribozavr2, JonasToth

Reviewed By: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D74374
2020-02-11 19:37:11 +00:00
Michael Wyman 0151ddc2e8 Create a clang-tidy check to warn when -dealloc is implemented inside an ObjC class category.
Summary: Such implementations may override the class's own implementation, and even be a danger in case someone later comes and adds one to the class itself. Most times this has been encountered have been a mistake.

Reviewers: stephanemoore, benhamilton, dmaclach

Reviewed By: stephanemoore, benhamilton, dmaclach

Subscribers: dmaclach, mgorny, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D72876
2020-02-10 08:56:28 -07:00
Richard Smith da3dc0011e PR44684: Look through parens and similar constructs when determining
whether a call is to a builtin.

We already had a general mechanism to do this but for some reason
weren't using it. In passing, check for the other unary operators that
can intervene in a reasonably-direct function call (we already handled
'&' but missed '*' and '+').

This reverts commit aaae6b1b61,
reinstating af80b8ccc5, with a fix to
clang-tidy.
2020-02-06 12:21:54 -08:00