Commit Graph

1838 Commits

Author SHA1 Message Date
Yitzhak Mandelbaum f9ce864558 [clang-tidy] Fix bug in bugprone-use-after-move check
Summary:
The bugprone-use-after-move check exhibits false positives for certain uses of
the C++17 if/switch init statements. These false positives are caused by a bug
in the ExprSequence calculations.

This revision adds tests for the false positives and fixes the corresponding
sequence calculation.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67292

llvm-svn: 371396
2019-09-09 12:59:14 +00:00
Alexander Kornienko 30424e4268 [clang-tidy] Make most ArgumentCommentCheck options local, as they should be
llvm-svn: 371076
2019-09-05 14:48:31 +00:00
Alexander Kornienko 42443e50ce Add a bugprone-argument-comment option: IgnoreSingleArgument.
Summary:
Add bugprone-argument-comment option: IgnoreSingleArgument.
When true, the check will ignore the single argument.

Sometimes, it's not necessary to add comment to single argument.
For example:

> std::string name("Yubo Xie");
> pScreen->SetWidth(1920);
> pScreen->SetHeight(1080);

This option can ignore such single argument in bugprone-argument-comment check.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Tags: #clang

Patch by Yubo Xie.

Differential Revision: https://reviews.llvm.org/D67056

llvm-svn: 371075
2019-09-05 14:48:23 +00:00
Alexander Kornienko b6d9703050 [clang-tidy] Fix bugprone-argument-comment bug: negative literal number is not checked.
Summary:
For example:
```
void foo(int a);
foo(-2);
```
should be fixed as:
```
foo(/*a=*/-2);
```
This change tries to fix this issue.

Reviewers: alexfh, hokein, aaron.ballman

Reviewed By: alexfh, aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Patch by Yubo Xie.

Differential Revision: https://reviews.llvm.org/D67084

llvm-svn: 371072
2019-09-05 14:13:57 +00:00
Kadir Cetinkaya 4a16c29551 [clang-tidy] Fix definitions in headers check to respect qualifiers
Summary:
The check was generating a fix without taking qualifiers in return type
into account. This patch changes the insertion location to be before qualifers.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67213

llvm-svn: 371022
2019-09-05 08:11:21 +00:00
Alexander Kornienko 240a2e25c6 [clang-tidy] Fix bugprone-argument-comment bug if there are marcos.
Summary:
Fix bugprone-argument-comment bug if there are marcos.

For example:
```
void j(int a, int b, int c);
j(X(1), /*b=*/1, X(1));
```

clang-tidy can't recognize comment "/*b=*/". It suggests fix like this:
```
j(X(1), /*b=*//*b=*/1, X(1));
```

This change tries to fix this issue.

Reviewers: alexfh, hokein, aaron.ballman

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Patch by Yubo Xie.

Differential Revision: https://reviews.llvm.org/D67080

llvm-svn: 370919
2019-09-04 16:19:32 +00:00
Haojian Wu 67853ac4e0 [clang-tidy] Fix a false positive in unused-using-decl check
The previous matcher "hasAnyTemplateArgument(templateArgument())" only
matches the first template argument, but the check wants to iterate all
template arguments. This patch fixes this.

Also some refactorings in this patch (to make the code reusable).

llvm-svn: 370760
2019-09-03 14:13:00 +00:00
Daniel Sanders 5b4f640499 [clang-tidy] Add llvm-prefer-register-over-unsigned to clang-tidy
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).

Reviewers: arsenm, bogner

Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, mgorny, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D65919

llvm-svn: 370512
2019-08-30 20:01:59 +00:00
Haojian Wu d1a24bab3a [clang-tidy] Fix the potential infinite loop in recordIsTriviallyDefaultConstructible.
Summary:
The recordIsTriviallyDefaultConstructible may cause an infinite loop when
running on an ill-formed decl.

Reviewers: gribozavr

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66874

llvm-svn: 370200
2019-08-28 13:45:53 +00:00
Sam McCall 9004c077c0 [clang-tidy] readability-identifier-naming shouldn't complain about CRTP pseudo-overrides
Reviewers: ilya-biryukov

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66864

llvm-svn: 370193
2019-08-28 12:08:57 +00:00
Benjamin Kramer 3c614f7b48 [clang-tidy] Manually enable exceptions in tesst that uses them
llvm-svn: 369853
2019-08-24 17:19:06 +00:00
Kristof Umann dabfea85fc [clang-tidy] Possibility of displaying duplicate warnings
Summary: In case a checker is registered multiple times as an alias, the emitted warnings are uniqued by the report message. However, it is random which checker name is included in the warning. When processing the output of clang-tidy this behavior caused some problems. In this commit the uniquing key contains the checker name too.

Reviewers: alexfh, xazax.hun, Szelethus, aaron.ballman, lebedev.ri, JonasToth, gribozavr

Reviewed By: alexfh

Subscribers: dkrupp, whisperity, rnkovacs, mgrang, cfe-commits

Patch by Tibor Brunner!

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65065

llvm-svn: 369763
2019-08-23 14:57:27 +00:00
Haojian Wu c4905a232c [clang-tidy] Don't emit google-runtime-references warning for functions defined in macros.
Summary:
The macro are usually defined in the common/base headers which are hard
for normal users to modify it.

Reviewers: gribozavr, alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66631

llvm-svn: 369739
2019-08-23 08:47:27 +00:00
Yuanfang Chen f24c1e6b51 [clang-tidy] Check for dynamically initialized statics in headers.
Finds instances where variables with static storage are initialized dynamically in header files.

Reviewed By: aaron.ballman, alexfh

Patch by Charles Zhang!

Differential Revision: https://reviews.llvm.org/D62829

llvm-svn: 369568
2019-08-21 20:00:01 +00:00
Richard Trieu 8f9e489a66 Fix typo. "piont" => "point"
Found by Chris Morris (cwmorris).

llvm-svn: 369316
2019-08-20 00:28:21 +00:00
Diego Astiazaran b46131e5c3 [clang-doc] Fix records in global namespace
When a Record is declared in the global namespace, clang-doc serializes
it as a child of the global namespace, so the global namespace is now
one if its parent namespaces. This namespace was not being included in
the list of namespaces of the Info causing paths to be incorrect and the
index rendered incorrectly.
Affected tests have been fixed.

Differential revision: https://reviews.llvm.org/D66298

llvm-svn: 369123
2019-08-16 16:10:32 +00:00
Diego Astiazaran 6a29ae4bde [clang-doc] Fix bitcode writer for access specifiers
Bitcode writer was not emitting the corresponding record for the Access attribute of a FunctionInfo. This has been added.
AS_none was being used as the default value for any AcesssSpecifier attribute
(in FunctionInfo and MemberTypeInfo), this has been changed to AS_public
because this is the enum value that evaluates to 0.
The bitcode writer doesn't write values that are 0 so if an attribute
was set to AS_public, this value is not written and after reading the
bitcode it would have the default value which is AS_none. This is why
the default value is now AS_public.

Differential Revision: https://reviews.llvm.org/D66151

llvm-svn: 369063
2019-08-15 23:04:27 +00:00
Zinovy Nis 6d83ab0870 [clang-tidy] Add FixItHint for performance-noexcept-move-constructor
Differential Revision: https://reviews.llvm.org/D65104

llvm-svn: 367785
2019-08-04 13:32:39 +00:00
Eric Fiselier a2a6f85366 [clang-tidy]: Google: new check 'google-upgrade-googletest-case'
Introduce a new check to upgrade user code based on API changes in Googletest.

The check finds uses of old Googletest APIs with "case" in their name and replaces them with the new APIs named with "suite".

Patch by Alex Strelnikov (strel@google.com)
Reviewed as D62977.

llvm-svn: 367263
2019-07-29 21:38:56 +00:00
Tom Roeder fc8c65b2e1 [clang-tidy] Add a module for the Linux kernel.
Summary:
Now that clang is going to be able to build the Linux kernel again on
x86, and we have gen_compile_commands.py upstream for generating
compile_commands.json, clang-tidy can be used on the Linux kernel
source.

To that end, this commit adds a new clang-tidy module to be used for
checks specific to Linux kernel source. The Linux kernel follows its own
style of C, and it will be useful to separate those checks into their
own module.

This also adds an initial check that makes sure that return values from
the kernel error functions like PTR_ERR and ERR_PTR are checked. It also
makes sure that any functions that directly return values from these
functions are checked.

Subscribers: xazax.hun, gribozavr, Eugene.Zelenko, lebedev.ri, mgorny, jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

Reviewers: aaron.ballman, alexfh, hokein, JonasToth

Differential Revision: https://reviews.llvm.org/D59963

llvm-svn: 367071
2019-07-25 22:32:50 +00:00
Julie Hockett 337aea438c [clang-tidy] Exclude forward decls from fuchsia-multiple-inheritance
Addresses b39770.

Differential Revision: https://reviews.llvm.org/D64813

llvm-svn: 366354
2019-07-17 17:40:53 +00:00
Nathan Huckleberry b53e13cd43 [clang-tidy] Fix crash on end location inside macro
Summary:
Lexer::getLocForEndOfToken is defined to return an
invalid location if the given location is inside a macro.
Other checks conditionally warn based off location
validity. Updating this check to do the same.

Reviewers: JonasToth, aaron.ballman, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: lebedev.ri, nickdesaulniers, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64607

llvm-svn: 366353
2019-07-17 17:22:43 +00:00
Ilya Biryukov f81ee439a4 [clang-tidy] Adjust location of namespace comment diagnostic
Summary:
If there is no comment, place it at the closing brace of a namespace
definition. Previously it was placed at the next character after the
closing brace.

The new position produces a better location for highlighting in clangd
and does not seem to make matters worse for clang-tidy.

Reviewers: alexfh, hokein

Reviewed By: alexfh, hokein

Subscribers: xazax.hun, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64861

llvm-svn: 366337
2019-07-17 15:22:14 +00:00
Matthias Gehre ffca322266 [clang-tidy] initial version of readability-convert-member-functions-to-static
Summary:
Finds non-static member functions that can be made ``static``.

I have run this check (repeatedly) over llvm-project. It made 1708 member functions
``static``. Out of those, I had to exclude 22 via ``NOLINT`` because their address
was taken and stored in a variable of pointer-to-member type (e.g. passed to
llvm::StringSwitch).
It also made 243 member functions ``const``. (This is currently very conservative
to have no false-positives and can hopefully be extended in the future.)

You can find the results here: https://github.com/mgehre/llvm-project/commits/static_const_eval

Reviewers: alexfh, aaron.ballman

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61749

llvm-svn: 366265
2019-07-16 21:19:00 +00:00
Fangrui Song 67ab269e1d [test] Delete trailing spaces from YAML tests after D65566/r365869
llvm-svn: 365874
2019-07-12 06:01:37 +00:00
Dmitri Gribenko f717148b3a Enhance abseil-faster-strsplit-delimiter to handle other non-printable characters.
Summary:
Currently it fails on cases like '\001'.

Note: Since `StringLiteral::outputString` dumps most nonprintable
characters in octal value, the exact string literal format isn't preserved,
e.g. `"\x01"` becomes `'\001'`.

Reviewers: gribozavr

Reviewed By: gribozavr

Subscribers: lebedev.ri, Eugene.Zelenko, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64151

Patch by Xiaoyi Zhang.

llvm-svn: 365463
2019-07-09 11:04:04 +00:00
Jian Cai 967aa5745d A test commit following 'Obtaining Commit Access' (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)
llvm-svn: 365380
2019-07-08 19:53:22 +00:00
Dmitri Gribenko e6020f5c62 [clang-tidy] new check: bugprone-posix-return
Summary:
Checks if any calls to posix functions (except posix_openpt) expect negative return values.
These functions return either 0 on success or an errno on failure, which is positive only.

Reviewers: JonasToth, gribozavr, alexfh, hokein

Reviewed By: gribozavr

Subscribers: Eugene.Zelenko, lebedev.ri, llozano, george.burgess.iv, xazax.hun, srhines, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63623

Patch by Jian Cai.

llvm-svn: 365007
2019-07-03 09:20:18 +00:00
Douglas Yung c900c46d77 [NFC] Marking test added in r363975 as unsupported on Windows.
This test references a path that does not exist on Windows causing
it to emit different output from what was expected leading to a
failure when run on Windows.

llvm-svn: 364120
2019-06-22 01:09:00 +00:00
Matthias Gehre eeb3f99d23 [clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
Summary: The fixit `int square(int /*num*/)` yields `error: parameter name omitted` for C code. Enable it only for C++ code.

Reviewers: klimek, ilya-biryukov, lebedev.ri, aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63088

llvm-svn: 364106
2019-06-21 21:30:25 +00:00
Reid Kleckner b250a62a51 Quote path to Python executable in case it has spaces
These days Python 3 is typically installed into C:/Program Files, so
cope with that.

Similar to r364077 in compiler-rt.

llvm-svn: 364087
2019-06-21 18:17:04 +00:00
Kadir Cetinkaya b9b1aaf07d [clang-tidy] Move test files of rL363975 into Inputs directory
llvm-svn: 364008
2019-06-21 07:54:27 +00:00
Serge Guelton 60ca31a7dd [clang-tidy] Fail gracefully upon empty database fields
Fix bz#42281

Differential Revision: https://reviews.llvm.org/D63613

llvm-svn: 363975
2019-06-20 20:25:59 +00:00
Aaron Puchert 44940048dd Fix more tests after r363749
Apparently -Wmissing-prototypes is used for quite a few integration
tests.

llvm-svn: 363760
2019-06-19 01:54:05 +00:00
Julie Hockett d9b3d08a9a [clang-tidy] Split fuchsia-default-arguments
Splits fuchsia-default-arguments check into two checks. fuchsia-default-arguments-calls warns if a function or method is called with default arguments. fuchsia-default-arguments-declarations warns if a function or method is declared with default parameters.

Committed on behalf of @diegoast (Diego Astiazarán).

Resolves b38051.

Differential Revision: https://reviews.llvm.org/D62437

llvm-svn: 363712
2019-06-18 18:07:33 +00:00
Dmitri Gribenko 558369b549 [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17
Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63253

Patch by Johan Vikström.

llvm-svn: 363273
2019-06-13 15:16:44 +00:00
Dmitri Gribenko 0030306555 [clang-tidy] Fixed abseil-time-subtraction to work on C++17
Summary: Fixed abseil-time-subtraction to work on C++17

Reviewers: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63261

Patch by Johan Vikström.

llvm-svn: 363272
2019-06-13 15:11:02 +00:00
Dmitri Gribenko 93f96b2be9 [clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17
Summary: Made abseil-upgrade-duration-conversions tests pass on c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63262

Patch by Johan Vikström.

llvm-svn: 363270
2019-06-13 14:27:54 +00:00
Dmitri Gribenko ab240c5eee [clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17
Summary: Fixed abseil-duration-unnecessary-conversion tests for c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63263

Patch by Johan Vikström.

llvm-svn: 363263
2019-06-13 13:52:45 +00:00
Dmitri Gribenko cf7d768351 Fixed a crash in misc-redundant-expression ClangTidy checker
Summary: It was trying to pass a dependent expression into constant evaluator.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63188

llvm-svn: 363133
2019-06-12 08:40:53 +00:00
Clement Courbet f63feaf3c2 [clang-tidy] Fix typo in bugprone-string-constructor.
s/bigger then/bigger than/

llvm-svn: 363053
2019-06-11 12:12:06 +00:00
Dmitri Gribenko be20daa8eb Fixed google-readability-casting test to work in c++17
Summary: Fixed google-readability-casting.cpp to get tests working in c++17

Reviewers: gribozavr, hokein

Reviewed By: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63128

Patch by Shaurya Gupta.

llvm-svn: 363047
2019-06-11 10:59:22 +00:00
Nikolai Kosjar 60e1296a9a [clang-tidy] Make the plugin honor NOLINT
Instantiate a ClangTidyDiagnosticConsumer also for the plugin case and
let it forward the diagnostics to the external diagnostic engine that is
already in place.

One minor difference to the clang-tidy executable case is that the
compiler checks/diagnostics are referred to with their original name.
For example, for -Wunused-variable the plugin will refer to the check as
"-Wunused-variable" while the clang-tidy executable will refer to that
as "clang-diagnostic- unused-variable". This is because the compiler
diagnostics never reach ClangTidyDiagnosticConsumer.

Differential Revision: https://reviews.llvm.org/D61487

llvm-svn: 362702
2019-06-06 13:13:27 +00:00
Haojian Wu df95e6109e [clang-tidy] Fix an assertion failure in misc-redundant-expression.
Summary:
The assertion "isIntegerConstantExpr" is triggered in the
isIntegerConstantExpr(), we should not call it if the expression is value
dependent.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62947

llvm-svn: 362701
2019-06-06 12:58:48 +00:00
Haojian Wu 448acbc06f [clang-tidy] Fix make-unique tests on C++2a.
Summary:
These test cases are illgal in C++2a ("new Foo{}" needs to see the
default constructor), so move them to the C++14-only tests.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62845

llvm-svn: 362679
2019-06-06 07:48:55 +00:00
George Burgess IV 5b2a85d0de android: add a close-on-exec check on pipe()
On Android, pipe() is better to be replaced by pipe2() with O_CLOEXEC
flag to avoid file descriptor leakage.

Patch by Jian Cai!

Differential Revision: https://reviews.llvm.org/D61967

llvm-svn: 362673
2019-06-06 05:21:45 +00:00
George Burgess IV 3da331b456 android: add a close-on-exec check on pipe2()
On Android, pipe2() is better to set O_CLOEXEC flag to avoid file
descriptor leakage.

Patch by Jian Cai!

Differential Revision: https://reviews.llvm.org/D62049

llvm-svn: 362672
2019-06-06 05:21:39 +00:00
Haojian Wu ceb0cc54f9 [clang-tidy] Fix make-unique check to work in C++17 mode.
Summary:
Previously, we intended to omit the check fix to the case when constructor has
any braced-init-list argument. But the HasListInitializedArgument was not
correct to handle all cases (Foo(Bar{1, 2}) will return false in C++14
mode).

This patch fixes it, corrects the tests, and makes the check to run at C++17 mode.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62736

llvm-svn: 362361
2019-06-03 08:14:15 +00:00
Stephane Moore ec1982f07f Revise the google-objc-global-variable-declaration check to match the style guide.
Summary:
Revise the google-objc-global-variable-declaration check to match the style guide.

This commit updates the check as follows:
(1) Do not emit fixes for extern global constants.
(2) Allow the second character of prefixes for constants to be numeric (the new guideline is that global constants should generally be named with a prefix that begins with a capital letter followed by one or more capital letters or numbers).

https://google.github.io/styleguide/objcguide.html#prefixes

This is an amended re-submission of https://reviews.llvm.org/rG12e3726fadb0b2a4d8aeed0a2817b5159f9d029d.

Contributed By: yaqiji

Reviewers: Wizard, benhamilton, stephanemoore

Reviewed By: benhamilton, stephanemoore

Subscribers: mgorny, cfe-commits, yaqiji

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62045

llvm-svn: 362279
2019-05-31 23:41:15 +00:00
Stephane Moore 9ac757bf09 Rollback "Revise the google-objc-global-variable-declaration check to match the style guide." 💥
The change introduced new test failures.

Phabricator URL of original commit: https://reviews.llvm.org/rG12e3726fadb0b2a4d8aeed0a2817b5159f9d029d

llvm-svn: 361914
2019-05-29 02:23:32 +00:00