Commit Graph

1130 Commits

Author SHA1 Message Date
Alexander Kornienko 7b9f3e28cc [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34449

**Problem:**

Clang-tidy check misc-unused-parameters comments out parameter name omitting following characters (e.g. square brackets) what results in its complete removal. Compilation errors might occur after clang-tidy fix as well.

**Patch description:**

Changed removal range. The range should end after parameter name, not after whole parameter declarator (which might be followed by e.g. square brackets).

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Pawel Maciocha!

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

llvm-svn: 313355
2017-09-15 11:28:28 +00:00
Alexander Kornienko e5590927d6 [clang-tidy] fixed misc-unused-parameters omitting parameters default value
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34450

**Problem:**

Clang-tidy check misc-unused-parameters omits parameter default value what results in its complete removal. Compilation errors might occur after clang-tidy fix.

**Patch description:**

Changed removal range. The range should end after parameter declarator, not after whole parameter declaration (which might contain a default value).

Reviewers: alexfh, xazax.hun

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

Tags: #clang-tools-extra

Patch by Pawel Maciocha!

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

llvm-svn: 313150
2017-09-13 14:55:13 +00:00
Jonas Toth 6ccc1c342a [clang-tidy] Implement type-based check for `gsl::owner`
This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template <typename T> 
void f(T t) { delete t; }
// ...
f(gsl::owner<int*>(new int(42)));
```
Will created false positive (the deletion is problematic), since the type deduction
removes the wrapping `typeAlias`.

Codereview in D36354

llvm-svn: 313067
2017-09-12 20:00:42 +00:00
Jonas Toth 8bfdc0b1cc [clang-tidy] Revert Implement type-based check for gsl::owner
This should unbreak the buildbot for visual studio 2015 for now.

llvm-svn: 313059
2017-09-12 18:35:54 +00:00
Jonas Toth a5d53274f3 [clang-tidy] Implement type-based check for `gsl::owner`
This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template <typename T> 
void f(T t) { delete t; }
// ...
f(gsl::owner<int*>(new int(42)));
```
Will created false positive (the deletion is problematic), since the type deduction
removes the wrapping `typeAlias`.

Please give your comments :)

llvm-svn: 313043
2017-09-12 16:20:51 +00:00
Peter Szecsi 2087113f6c [clang-tidy] SuspiciousEnumUsageCheck bugfix
iThere is a reported bug on the checker not handling the some APSInt values
correctly: https://bugs.llvm.org/show_bug.cgi?id=34400

This patch aims to fix it.

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

llvm-svn: 313016
2017-09-12 09:40:13 +00:00
Roman Lebedev 728284dc39 [clang-tidy] FunctionSizeCheck: wrap FunctionASTVisitor into anon namespace, NFC
This check is relatively simple, and is often being used
as an example. I'm aware of at least two cases, when
simply copying the FunctionASTVisitor class to a new
check resulted in a rather unobvious segfault. Having it
in anonymous namespace prevents such a problem.

No functionality change, so i opted to avoid phabricator,
especially since clang-tidy reviews are seriously jammed.

llvm-svn: 312912
2017-09-11 13:12:31 +00:00
Jonas Toth a735803801 [clang-tidy] add more aliases for the hicpp module
This patch will introduce even more aliases for the hicpp-module to already existing
checks and is a follow up for D30383 finishing the other sections.
It fixes a forgotten highlight in hicpp-braces-around-statements.rst, too.

llvm-svn: 312901
2017-09-11 09:20:07 +00:00
Rafael Espindola d63b2f3996 Update for PrintHelpMessage not calling exit.
llvm-svn: 312769
2017-09-08 00:33:39 +00:00
Kevin Funk d331cb66f9 Make run-clang-tidy compatible with Python 3.x
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, JDevlieghere

Tags: #clang-tools-extra

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

Change-Id: I89a95d1e082e566e7e64c2a5ca4123c543e6b1be
llvm-svn: 312532
2017-09-05 12:36:33 +00:00
Benjamin Kramer 6be49244b1 [cppcoreguidelines] Don't rely on SmallPtrSet iteration order.
The fixit emission breaks if the iteration order changes and also missed
to emit fixits for some edge cases.

llvm-svn: 312166
2017-08-30 20:18:40 +00:00
Jonas Toth 673dbd1aff [clang-tidy] Improve hicpp-exception-baseclass to handle generic code better
Summary:
This patch is a followup to the first revision D36583, that had problems with 
generic code and its diagnostic messages, which were found by @lebedev.ri

Reviewers: alexfh, aaron.ballman, lebedev.ri, hokein

Reviewed By: aaron.ballman, lebedev.ri

Subscribers: klimek, sbenza, cfe-commits, JDevlieghere, lebedev.ri, xazax.hun

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

llvm-svn: 312134
2017-08-30 15:59:01 +00:00
Jonas Toth a8c34530df [clang-tidy] hicpp bitwise operations on signed integers
Summary:
This check implements the rule [[ http://www.codingstandard.com/section/5-6-shift-operators/ | 5.6. HIC++ ]]
that forbidds bitwise operations on signed integer types.

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

Reviewed By: aaron.ballman

Subscribers: cfe-commits, mgorny, JDevlieghere, xazax.hun

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

llvm-svn: 312122
2017-08-30 13:32:05 +00:00
Jonas Toth a88abd58b4 [clang-tidy] test commit for granted access
llvm-svn: 312102
2017-08-30 07:50:28 +00:00
Daniel Marjamaki cad8443724 [clang-tidy] Fix 'misc-misplaced-widening-cast' assertion error.
Reviewers: alexfh, xazax.hun, danielmarjamaki

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

llvm-svn: 311984
2017-08-29 06:25:24 +00:00
Haojian Wu 3f495944de [clang-tidy] A follow-up fix of braced-init-list constructors in make-unique check.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311652
2017-08-24 13:35:55 +00:00
Alexander Kornienko 15ea4ebbb2 [clang-tidy] bugprone-undefined-memory-manipulation: include type into the message
Having the actual type in the message helps a lot understanding warnings in templates ;)

+ fix a false negative for type aliases.

llvm-svn: 311651
2017-08-24 12:11:05 +00:00
Alexander Kornienko dea43983ae [clang-tidy] Add modernize-use-equals-default.IgnoreMacros option
llvm-svn: 311136
2017-08-17 23:07:59 +00:00
Haojian Wu 80330ffc6b [clang-tidy] Ignore statements inside a template instantiation.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311086
2017-08-17 14:12:38 +00:00
Haojian Wu 4b956cb70d [clang-tidy] Don't generate fixes for initializer_list constructor in make_unique check.
Summary:
The current fix will break the compilation -- because braced list is not
deducible in std::make_unique (with the use of forwarding) without
specifying the type explicitly.

We could support it in the future.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311078
2017-08-17 10:14:52 +00:00
Chih-Hung Hsieh 2414429962 [clang-tidy] Remove unused static variable.
Differential Revision: https://reviews.llvm.org/D36761

llvm-svn: 311040
2017-08-16 21:00:06 +00:00
Chih-Hung Hsieh a54d379812 [clang-tidy] Use const char* to compile with VC cl.exe.
Summary:
cl.exe does not accept constexpr char FuncBindingStr[] = ...

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

llvm-svn: 311035
2017-08-16 19:13:35 +00:00
Chih-Hung Hsieh 41d29b15e8 [clang-tidy] Add a close-on-exec check on epoll_create() in Android module.
Summary:
epoll_create() is better to be replaced by epoll_create1() with EPOLL_CLOEXEC
flag to avoid file descriptor leakage.

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

llvm-svn: 311029
2017-08-16 18:02:49 +00:00
Chih-Hung Hsieh 3be4ecb15b [clang-tidy] Add a close-on-exec check on epoll_create1() in Android module.
Summary:
epoll_create1() is better to set EPOLL_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 311028
2017-08-16 17:53:12 +00:00
Chih-Hung Hsieh 5ac20c9c25 [clang-tidy] Add a close-on-exec check on accept4() in Android module.
Summary:
accept4() is better to set SOCK_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 311027
2017-08-16 17:46:18 +00:00
Chih-Hung Hsieh ae3527e6bb [clang-tidy] Add a close-on-exec check on accept() in Android module.
Summary:
accept() is better to be replaced by accept4() with SOCK_CLOEXEC
flag to avoid file descriptor leakage.

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

llvm-svn: 311024
2017-08-16 17:18:16 +00:00
Chih-Hung Hsieh fec506daaa [clang-tidy] Use CloexecCheck as base class.
Summary:
Simplify registerMatchers and check functions in CloexecCreatCheck,
CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.

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

llvm-svn: 311020
2017-08-16 16:59:26 +00:00
Chih-Hung Hsieh 7651e66cdf [clang-tidy] Add a close-on-exec check on inotify_init1() in Android module.
Summary:
inotify_init1() is better to set IN_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 310863
2017-08-14 17:45:48 +00:00
Chih-Hung Hsieh 2e6f9a16f9 [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.
Summary:
inotify_init() is better to be replaced by inotify_init1() with IN_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 310861
2017-08-14 17:25:41 +00:00
Chih-Hung Hsieh 56650e7fc5 [clang-tidy] Add a close-on-exec check on dup() in Android module.
Summary:
dup() is better to be replaced by fcntl() to avoid file descriptor leakage.

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

llvm-svn: 310858
2017-08-14 17:04:16 +00:00
Simon Pilgrim 7c87ebf3cd Fix Wdocumentation warning - typo in argument list. NFCI.
llvm-svn: 310783
2017-08-12 18:50:53 +00:00
Aaron Ballman a3274e5443 Add hicpp-exception-baseclass to the HIC++ module.
This enforces that throwing an exception in C++ requires that exception to inherit from std::exception.

Patch by Jonas Toth.

llvm-svn: 310727
2017-08-11 16:31:51 +00:00
Aaron Ballman 6c2920a30a Implement hicpp-braces-around-statements as an alias to readability-braces-around-statements.
Patch by Jonas Toth.

llvm-svn: 310707
2017-08-11 12:12:36 +00:00
Yan Wang b21739f988 [clang-tidy] Fix for buildbot.
Summary:
Fix an issue for windows.

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

llvm-svn: 310669
2017-08-10 22:09:22 +00:00
Reid Kleckner 8d4d57035f Revert "[clang-tidy] Refactor the code and add a close-on-exec check on memfd_create() in Android module."
This reverts commit r310630.

The new code broke on Windows and was untested. On Linux, it was
selecting the "int" overload of operator<<, which definitely does not
print the right thing when fed a "Mode" char.

llvm-svn: 310661
2017-08-10 21:21:15 +00:00
Yan Wang d61c2a18cb [clang-tidy] Refactor the code and add a close-on-exec check on memfd_create() in Android module.
Summary:
1. Refactor the structure of the code by adding a base class for all close-on-exec checks, which implements most of the needed functions.
2. memfd_create() is better to set MFD_CLOEXEC flag to avoid file descriptor leakage.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh, hokein

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

Tags: #clang-tools-extra

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

llvm-svn: 310630
2017-08-10 17:18:10 +00:00
Gabor Horvath 0b16c10de3 [clang-tidy] Add integer division check
Patch by: Reka Nikolett Kovacs

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

llvm-svn: 310589
2017-08-10 13:30:30 +00:00
Alexander Kornienko ff6b2af499 [clang-tidy] Add modernize-use-emplace.IgnoreImplicitConstructors option
llvm-svn: 310584
2017-08-10 12:19:05 +00:00
Benjamin Kramer 1436192d68 [clang-tidy] Don't compute the edit distance if it's over the threshold.
No functional change intended.

llvm-svn: 310532
2017-08-09 22:09:29 +00:00
Haojian Wu be5d4487b4 [clang-tidy] Fix another crash in make-unique check.
Summary:
The crash happens when calling `reset` method without any preceding
operation like "->" or ".", this could happen in a subclass of the
"std::unique_ptr".

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 310496
2017-08-09 17:03:42 +00:00
Alexander Kornienko 9b8df6ae02 [clang-tidy] Ignore newlines in checks list
This is a follow up to https://reviews.llvm.org/D30567 where I overlooked that
LLVM YAML parser doesn't support multiline literal folding.

llvm-svn: 310491
2017-08-09 16:00:31 +00:00
Gabor Horvath 40b6512d9e [clang-tidy] Add new readability non-idiomatic static access check
Patch by: Lilla Barancsuk

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

llvm-svn: 310371
2017-08-08 15:33:48 +00:00
Alexander Kornienko f1a6552a95 [clang-tidy] 'implicit cast' -> 'implicit conversion'
Summary:
This patch renames checks, check options and changes messages to use correct
term "implicit conversion" instead of "implicit cast" (which has been in use in
Clang AST since ~10 years, but it's still technically incorrect w.r.t. C++
standard).

  * performance-implicit-cast-in-loop -> performance-implicit-conversion-in-loop
  * readability-implicit-bool-cast -> readability-implicit-bool-conversion
    - readability-implicit-bool-cast.AllowConditionalIntegerCasts ->
      readability-implicit-bool-conversion.AllowIntegerConditions
    - readability-implicit-bool-cast.AllowConditionalPointerCasts ->
      readability-implicit-bool-conversion.AllowPointerConditions

Reviewers: hokein, jdennett

Reviewed By: hokein

Subscribers: mgorny, JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 310366
2017-08-08 14:53:52 +00:00
Haojian Wu 115b707584 [clang-tidy] Ignore macros in make-unique check.
Summary:
The check doesn't fully support smart-ptr usages inside macros, which
may cause incorrect fixes, or even crashes, ignore them for now.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 310050
2017-08-04 11:18:00 +00:00
Haojian Wu dc1c7610b8 [clang-tidy] Support initializer-list constructor cases in modernize-make-unique.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: malcolm.parsons, JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 310035
2017-08-04 08:07:05 +00:00
Manuel Klimek 7b9c117b82 Adapt clang-tidy checks to changing semantics of hasDeclaration.
Differential Revision: https://reviews.llvm.org/D36154

llvm-svn: 309810
2017-08-02 13:13:11 +00:00
Malcolm Parsons 2f96843396 [clang-tidy] Handle anonymous structs/unions in member init checks.
Use getAnyMember() instead of getMember() to avoid crash on anonymous
structs/unions.
Don't warn about initializing members of an anonymous union.

Fixes PR32966.

Reviewed by alexfh.

llvm-svn: 309668
2017-08-01 09:54:05 +00:00
Alexander Kornienko f3321c5f68 [clang-tidy] readability-redundant-declaration: ignore friends and macros
llvm-svn: 309379
2017-07-28 12:46:02 +00:00
Felix Berger 603ea2df2a [clang-tidy] Do not issue fixit for explicit template specializations
Summary:

Do not issue fixit in UnnecessaryValueParamCheck if the function is an explicit template specialization as this could cause build breakages.

Reviewers: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 309067
2017-07-26 00:45:41 +00:00
Gabor Horvath 97c8e09790 [clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation
check

Patch by: Reka Nikolett Kovacs

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

llvm-svn: 308954
2017-07-25 06:52:08 +00:00