Commit Graph

687 Commits

Author SHA1 Message Date
Nathan James 980618145b
[clang-tidy][docs] Update check options with boolean values instead of non-zero/0/1
Using bools instead of integers better conveys the expected value of the option.

Reviewed By: Eugene.Zelenko, aaron.ballman

Differential Revision: https://reviews.llvm.org/D92652
2020-12-07 12:13:57 +00:00
Vasily Kulikov cac5be495e
[clang-tidy] implement concurrency-mt-unsafe
Checks for some thread-unsafe functions against a black list
of known-to-be-unsafe functions. Usually they access static variables
without synchronization (e.g. gmtime(3)) or utilize signals
in a racy way (e.g. sleep(3)).

The patch adds a check instead of auto-fix as thread-safe alternatives
usually have API with an additional argument
(e.g. gmtime(3) v.s. gmtime_r(3)) or have a different semantics
(e.g. exit(3) v.s. __exit(3)), so it is a rather tricky
or non-expected fix.

An option specifies which functions in libc should be considered
thread-safe, possible values are `posix`, `glibc`,
or `any` (the most strict check). It defaults to 'any' as it is
unknown what target libc type is - clang-tidy may be run
on linux but check sources compiled for other *NIX.

The check is used in Yandex Taxi backend and has caught
many unpleasant bugs. A similar patch for coroutine-unsafe API
is coming next.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D90944
2020-11-30 12:27:17 +03:00
Vasily Kulikov 8da7efbb0d
[clang-tidy] add concurrency module
The module will contain checks related to concurrent programming (including threads, fibers, coroutines, etc.).

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D91656
2020-11-30 12:27:17 +03:00
Aaron Ballman ed242da0ff Fix a typo in the documentation to unbreak the sphinx builder. 2020-11-25 07:34:08 -05:00
smhc 9c4df9eecb [clang-tidy] Support IgnoredRegexp configuration to selectively suppress identifier naming checks
The idea of suppressing naming checks for variables is to support code bases that allow short variables named e.g 'x' and 'i' without prefix/suffixes or casing styles. This was originally proposed as a 'ShortSizeThreshold' however has been made more generic with a regex to suppress identifier naming checks for those that match.

Reviewed By: njames93, aaron.ballman

Differential Revision: https://reviews.llvm.org/D90282
2020-11-25 01:18:44 +00:00
Chris Kennelly e4f9b5d442 [clang-tidy] Include std::basic_string_view in readability-redundant-string-init.
std::string_view("") produces a string_view instance that compares
equal to std::string_view(), but requires more complex initialization
(storing the address of the string literal, rather than zeroing).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91009
2020-11-20 10:06:57 -05:00
Chris Kennelly 25f5406f08 [clang-tidy] Extend bugprone-string-constructor-check to std::string_view.
This allows for matching the constructors std::string has in common with
std::string_view.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91015
2020-11-18 21:16:03 -05:00
Frank Derry Wanye 9ca6fc4e09 Add a new altera kernel name restriction check to clang-tidy.
The altera kernel name restriction check finds kernel files and include
directives whose filename is "kernel.cl", "Verilog.cl", or "VHDL.cl".
Such kernel file names cause the Altera Offline Compiler to generate
intermediate design files that have the same names as certain internal
files, which leads to a compilation error.

As per the "Guidelines for Naming the Kernel" section in the "Intel FPGA
SDK for OpenCL Pro Edition: Programming Guide."

This reverts the reversion from 43a38a6523.
2020-11-09 09:26:50 -05:00
Balázs Kéri d1b2a52319 [clang-tidy] Add signal-handler-check for SEI CERT rule SIG30-C
SIG30-C. Call only asynchronous-safe functions within signal handlers

First version of this check, only minimal list of functions is allowed
("strictly conforming" case), for C only.

Differential Revision: https://reviews.llvm.org/D87449
2020-11-04 16:42:30 +01:00
Nico Weber c88390468c Revert "Add a new altera kernel name restriction check to clang-tidy."
This reverts commit 43a38a6523,
and follow-up 5a7bc5e259.

The commit breaks check-clang-tools, the test added in the change
does not pass.
2020-11-02 10:30:42 -05:00
Frank Derry Wanye 43a38a6523 Add a new altera kernel name restriction check to clang-tidy.
The altera kernel name restriction check finds kernel files and include
directives whose filename is "kernel.cl", "Verilog.cl", or "VHDL.cl".
Such kernel file names cause the Altera Offline Compiler to generate
intermediate design files that have the same names as certain internal
files, which leads to a compilation error.

As per the "Guidelines for Naming the Kernel" section in the "Intel FPGA
SDK for OpenCL Pro Edition: Programming Guide."
2020-11-02 10:11:38 -05:00
Pedro Gonnet 43e451f9f3 Fix gendered documentation
Changed two references to developers as "he" or "him" to the more neutral "they".

Reviewed By: JDevlieghere, sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D78807
2020-10-31 12:17:19 +01:00
Nathan James 86ef379800
[clang-tidy] Add scoped enum constants to identifier naming check
Added option `ScopedEnumConstant(Prefix|Case|Suffix)` to readability-identitied-naming.
This controls the style for constants in scoped enums, declared as enum (class|struct).
If this option is unspecified the EnumConstant style will be used instead.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D89407
2020-10-19 15:57:47 +01:00
Nathan James 8a548bc203
[clang-tidy] modernize-loop-convert reverse iteration support
Enables support for transforming loops of the form
```
for (auto I = Cont.rbegin(), E = Cont.rend(); I != E;++I)
```

This is done automatically in C++20 mode using `std::ranges::reverse_view` but there are options to specify a different function to reverse iterator over a container.
This is the first step, down the line I'd like to possibly extend this support for array based loops
```
for (unsigned I = Arr.size() - 1;I >=0;--I) Arr[I]...
```

Currently if you pass a reversing function with no header in the options it will just assume that the function exists, however as we have the ASTContext it may be as wise to check before applying, or at least lower the confidence level if we can't find it.

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D82089
2020-10-16 14:16:30 +01:00
Sylvestre Ledru 002968a320 [clang-tidy] Add an example for misc-unused-alias-decls
Differential Revision: https://reviews.llvm.org/D89270
2020-10-13 13:56:04 +02:00
Adam Balogh d6c9dc3c17 [clang-tidy] Remove obsolete checker google-runtime-references
The rules which is the base of this checker is removed from the
//Google C++ Style Guide// in May:
[[ https://github.com/google/styleguide/pull/553 | Update C++ styleguide ]].
Now this checker became obsolete.

Differential Revision: https://reviews.llvm.org/D88831
2020-10-06 14:03:55 +02:00
Roman Lebedev ace644030e
[clang-tidy] Implement readability-function-cognitive-complexity check
Currently, there is basically just one clang-tidy check to impose
some sanity limits on functions - `clang-tidy-readability-function-size`.
It is nice, allows to limit line count, total number of statements,
number of branches, number of function parameters (not counting
implicit `this`), nesting level.

However, those are simple generic metrics. It is still trivially possible
to write a function, which does not violate any of these metrics,
yet is still rather unreadable.

Thus, some additional, slightly more complicated metric is needed.
There is a well-known [[ https://en.wikipedia.org/wiki/Cyclomatic_complexity | Cyclomatic complexity]], but certainly has its downsides.
And there is a [[ https://www.sonarsource.com/docs/CognitiveComplexity.pdf | COGNITIVE COMPLEXITY by SonarSource ]], which is available for opensource on https://sonarcloud.io/.

This check checks function Cognitive Complexity metric, and flags
the functions with Cognitive Complexity exceeding the configured limit.
The default limit is `25`, same as in 'upstream'.

The metric is implemented as per [[ https://www.sonarsource.com/docs/CognitiveComplexity.pdf | COGNITIVE COMPLEXITY by SonarSource ]] specification version 1.2 (19 April 2017), with two notable exceptions:
   * `preprocessor conditionals` (`#ifdef`, `#if`, `#elif`, `#else`,
     `#endif`) are not accounted for.
      Could be done. Currently, upstream does not account for them either.
   * `each method in a recursion cycle` is not accounted for.
      It can't be fully implemented, because cross-translational-unit
      analysis would be needed, which is not possible in clang-tidy.
      Thus, at least right now, i completely avoided implementing it.

There are some further possible improvements:
* Are GNU statement expressions (`BinaryConditionalOperator`) really free?
  They should probably cause nesting level increase,
  and complexity level increase when they are nested within eachother.
* Microsoft SEH support
* ???

Reviewed By: aaron.ballman, JonasToth, lattner

Differential Revision: https://reviews.llvm.org/D36836
2020-10-03 00:27:13 +03:00
Florian Mayer 9d40fb808f Allow to specify macro names for android-comparison-in-temp-failure-retry
Some projects do not use the TEMP_FAILURE_RETRY macro but define their
own one, as not to depend on glibc / Bionic details. By allowing the
user to override the list of macros, these projects can also benefit
from this check.

Differential Revision: https://reviews.llvm.org/D83144
2020-10-01 10:09:26 -07:00
Alexander Kornienko fdfe324da1 [clang-tidy] IncludeInserter: allow <> in header name
This adds a pair of overloads for create(MainFile)?IncludeInsertion methods that
use the presence of the <> in the file name to control whether the #include
directive will use angle brackets or quotes. Motivating examples:
https://reviews.llvm.org/D82089#inline-789412 and
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp#L433

The overloads with the IsAngled parameter can be removed after the users are
updated.

Update usages of createIncludeInsertion.

Update (almost all) usages of createMainFileIncludeInsertion.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85666
2020-09-28 15:14:04 +02:00
Adam Balogh 4fc0214a10 [clang-tidy] New check cppcoreguidelines-prefer-member-initializer
Finds member initializations in the constructor body which can be placed
into the initialization list instead. This does not only improves the
readability of the code but also affects positively its performance.
Class-member assignments inside a control statement or following the
first control statement are ignored.

Differential Revision: https://reviews.llvm.org/D71199
2020-09-21 14:42:58 +02:00
Kirill Bobyrev 3e5a4ef51a Fix table formatting after D87686 2020-09-16 12:27:59 +02:00
Kirill Bobyrev a909a84ef2
[clang-tidy] Improve documentation on Clangd integration
The integration is already complete; this patch updates information as well as
suggests using Clang-Tidy via Clangd integration that is vastly available
in most editors through LSP client plugins.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D87686
2020-09-16 12:10:00 +02:00
Nico Weber 33c9dbbd38 Add an explicit toggle for the static analyzer in clang-tidy
Instead of using CLANG_ENABLE_STATIC_ANALYZER for use of the
static analyzer in both clang and clang-tidy, add a second
toggle CLANG_TIDY_ENABLE_STATIC_ANALYZER.

This allows enabling the static analyzer in clang-tidy while
disabling it in clang.

Differential Revison: https://reviews.llvm.org/D87118
2020-09-10 10:48:17 -04:00
Roman Lebedev ebf496d805
Revert "[clang-tidy] New check readability-prefer-member-initializer"
Either contains unbounded loops, or has *very* high runtime,
100+x of all the current clang-tidy checks.

This reverts commit f5fd7486d6.
2020-09-10 16:32:18 +03:00
serge-sans-paille 875b8537ee [clang-tidy] Fix reST syntax
Authored by Eisuke Kawashima [https://github.com/llvm/llvm-project/pull/245]
2020-09-10 13:56:57 +02:00
Frank Derry Wanye 156b127945 Add a new altera check for structure packing and alignment.
The altera struct pack align lint check finds structs that are inefficiently
packed or aligned and recommends packing/aligning of the structs using the
packed and aligned attributes as needed in a warning.
2020-09-08 09:35:14 -04:00
Aaron Puchert da6b3aa4c6 Attempt to fix Sphinx build failure, NFC
A code block wasn't properly introduced.
2020-09-05 18:25:27 +02:00
Adam Balogh 14dd073782 [Clang-Tidy] New check `bugprone-redundant-branch-condition`
Checking the same condition again in a nested `if` usually make no sense,
except if the value of the expression could have been changed between
the two checks. Although compilers may optimize this out, such code is
suspicious: the programmer may have meant to check something else.
Therefore it is worth to find such places in the code and notify the
user about the problem.

This patch implements a basic check for this problem. Currently it
only detects redundant conditions where the condition is a variable of
integral type. It also detects the possible bug if the variable is in an
//or// or //and// logical expression in the inner if and/or the variable
is in an //and// logical expression in the outer if statement. Negated
cases are not handled yet.

Differential Revision: https://reviews.llvm.org/D81272
2020-08-31 16:00:59 +02:00
Adam Balogh f5fd7486d6 [clang-tidy] New check readability-prefer-member-initializer
Finds member initializations in the constructor body which can
be placed to the member initializers of the constructor instead.
This does not only improves the readability of the code but also
affects positively its performance. Class-member assignments
inside a control statement or following the first control
statement are ignored.

Differential Revision: https://reviews.llvm.org/D71199
2020-08-31 15:59:29 +02:00
Bernhard Manfred Gruber 345053390a Add support for C++20 concepts and decltype to modernize-use-trailing-return-type. 2020-08-15 10:40:22 -04:00
Bogdan Serea 35bee3503f [clang-tidy] prevent generated checks from triggering assertions on anonymous functions
Skeleton checks generated by clang-tidy add_check.py cause assertions to fail when run over anonymous functions(lambda functions). This patch introduces an additional check to verify that the target function is not anonymous before calling getName().
The code snippet from the [[ https://clang.llvm.org/extra/clang-tidy/Contributing.html | clang-tidy tutorial  ]]is also updated.

Reviewed By: alexfh, DavidTruby

Differential Revision: https://reviews.llvm.org/D85218
2020-08-12 12:43:40 +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
Atmn Patel 78443666bc [OpenMP] Add firstprivate as a default data-sharing attribute to clang
This implements the default(firstprivate) clause as defined in OpenMP
Technical Report 8 (2.22.4).

Reviewed By: jdoerfert, ABataev

Differential Revision: https://reviews.llvm.org/D75591
2020-07-12 23:01:40 -05:00
Aaron Ballman aef04d3306 Speculatively fix the sphinx build. 2020-07-07 13:54:28 -04: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 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
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
lh123 43e3c39327 Revert "[Docs] Fix typo and test git commit access. NFC."
This reverts commit c19e82c6b3.
2020-06-27 18:58:03 +08:00
lh123 c19e82c6b3 [Docs] Fix typo and test git commit access. NFC. 2020-06-27 13:35:59 +08: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
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
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
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 65fa0a9f7f [clang-tidy] Added MacroDefiniton docs for readability-identifier-naming
Updates the docs to include `MacroDefinition` documentation. The docs are still missing `ObjCIVar` however I don't have a clue about how that looks in code. If someone wants to show the code block needed for the example I'll add that in too.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D80877
2020-06-03 09:23:32 +01: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
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 b0828135db clang-tidy doc: Fix the syntax to use rst list type 2020-05-10 11:25:20 +02:00
Sylvestre Ledru dc0f79ea5b clang-tidy doc: add a note for checkers with an autofix
Summary:
Currently, when looking at a checker documentation, we have to go back
to the whole list or look at the sources to figure out if an autofix
is available or not.

Reviewers: alexfh, aaron.ballman

Subscribers: wuzish, Eugene.Zelenko, nemanjai, kbarton, arphaman, Charusso, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77983
2020-05-10 11:25:19 +02:00