Commit Graph

284 Commits

Author SHA1 Message Date
Gabor Horvath ec87e17c84 [clang-tidy] Misc redundant expressions checker updated for macros
Redundant Expression Checker is updated to be able to detect expressions that
contain macros. Also, other small details are modified to improve the current
implementation.

The improvements in detail are as follows:
* Binary and ternary operator expressions containing two constants, with at
least one of them from a macro, are detected and tested for redundancy.

Macro expressions are treated somewhat differently from other expressions,
because the particular values of macros can vary across builds.
They can be considered correct and intentional, even if macro values equal,
produce ranges that exclude each other or fully overlap, etc. 

* The code structure is slightly modified: typos are corrected,
comments are added and some functions are renamed to improve comprehensibility,
both in the checker and the test file. A few test cases are moved to another
function.

* The checker is now able to detect redundant CXXFunctionalCastExprs as well.
A corresponding test case is added.

Patch by: Lilla Barancsuk!

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

llvm-svn: 317570
2017-11-07 13:17:58 +00:00
Benjamin Kramer 252dd8b745 [clang-tidy] Use a more efficient map for the virtual near miss check.
DenseMap performs better here. No functionality change intended.

llvm-svn: 315277
2017-10-10 07:21:51 +00:00
Richard Smith 2ccecb9d88 Fix up clang-tidy after clang r314037.
llvm-svn: 314047
2017-09-22 23:47:20 +00:00
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
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
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
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
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
Alexander Kornienko b1c7432117 [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are used
llvm-svn: 308605
2017-07-20 12:02:03 +00:00
Faisal Vali cb8e01acd0 [NFC] Update function call names as changed in MacroInfo that should refer to Parameters (as opposed to Arguments).
This syncs them up with clang commit r308190

Thanks!

llvm-svn: 308191
2017-07-17 17:20:57 +00:00
Gabor Horvath 2990ac1ebd [clang-tidy] Enable inline variable definitions in headers
Differential Revision: https://reviews.llvm.org/D34449

llvm-svn: 306538
2017-06-28 12:47:35 +00:00
Alexander Kornienko 564f1c74b6 Revert "[clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed."
This reverts commit r304949.

https://reviews.llvm.org/D34002#775830

llvm-svn: 305057
2017-06-09 07:34:58 +00:00
Yan Wang 98b74fc7d6 [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.
Summary:  "misc-noexcept-move-constructor" is better not to be issued when "-fno-exceptions" is set.

Reviewers: chh, alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits, xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 304949
2017-06-07 22:39:20 +00:00
Alexander Kornienko f1dc12eb69 [clang-tidy] Make misc-inaccurate-erase work with real C++11 containers.
The check failed to match iterator->const_iterator conversion that is happening
at least when using the libstdc++'s vector. We might want to make it match even
more flexible patterns, if we see more false negatives.

llvm-svn: 304879
2017-06-07 08:25:51 +00:00
Alexander Kornienko 0bdd8a1964 [clang-tidy] misc-inaccurate-erase: support call by pointer
+ replace matchesName calls with more efficient alternatives.

llvm-svn: 304811
2017-06-06 17:49:45 +00:00
Florian Gross da197aab63 [clang-tidy] Make misc-static-assert accept assert(!"msg")
Added negated string literals to the set of IsAlwaysFalse expressions to avoid flagging of assert(!"msg").

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

llvm-svn: 304657
2017-06-03 10:13:55 +00:00
Alexander Kornienko a49cfef414 [clang-tidy] Add `const` to operator() to fix a warning.
llvm-svn: 304583
2017-06-02 18:47:50 +00:00
Alexander Kornienko d9a4491b0a [clang-tidy] check for __func__/__FUNCTION__ in lambdas
Add a clang-tidy check for using func__/FUNCTION__ inside lambdas. This
evaluates to the string operator(), which is almost never useful and almost
certainly not what the author intended.

Patch by Bryce Liu!

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

llvm-svn: 304570
2017-06-02 17:36:32 +00:00
Alexander Kornienko 0055d97d4b [clang-tidy] Use getLocalOrGlobal for the StrictMode option
llvm-svn: 304154
2017-05-29 13:59:27 +00:00
Chih-Hung Hsieh 2857b1245b [clang-tidy] Do not dereference a null BaseType
Check BaseType before dereference.
Simplified test case is derived from Android Open Source code.

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

llvm-svn: 303645
2017-05-23 16:19:04 +00:00
Alexander Kornienko f2dc6492ed [clang-tidy] misc-move-const-arg shouldn't complain on std::move(lambda)
llvm-svn: 303554
2017-05-22 14:30:14 +00:00
Alexander Kornienko 4d5dd3b7ef [clang-tidy] Optimize misc-unused-parameters. NFCI
Don't traverse AST each time we need to find references to a certain function.
Traverse the AST once using RAV and cache the index of function references.

The speed up on a particular large file was about 1000x.

llvm-svn: 303230
2017-05-17 02:25:11 +00:00
Alexander Kornienko d0488d427c Change EOL style to LF. NFC
llvm-svn: 302534
2017-05-09 14:56:28 +00:00
Alexander Kornienko b48986782b [clang-tidy] Fix misc-move-const-arg for move-only types.
Summary: Fix misc-move-const-arg false positives on move-only types.

Reviewers: sbenza

Reviewed By: sbenza

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 302261
2017-05-05 17:33:49 +00:00
Gabor Horvath 1a92506f36 [clang-tidy] misc-misplaced-widening-cast: Disable checking of implicit widening casts by default.
Patch by Ádám Balogh!

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

llvm-svn: 300699
2017-04-19 14:55:58 +00:00
Nirav Dave 21d5d4fbbf Silence -Wlogical-op-parentheses warning NFC
llvm-svn: 300324
2017-04-14 14:36:45 +00:00
Gabor Horvath 6f0e2ac858 [clang-tidy] Fixes to misc-forwarding-reference-overload check.
* Style fixes to tests
* Make it work consistently on all platforms

Patch by András Leitereg!

llvm-svn: 300320
2017-04-14 12:31:36 +00:00
Gabor Horvath b3856d65ea [clang-tidy] Check for forwarding reference overload in constructors.
Patch by András Leitereg!

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

llvm-svn: 299638
2017-04-06 09:56:42 +00:00
Alexander Kornienko 5816a8bbb1 [clang-tidy] Fix diag message for catch-by-value
Summary:
```
catch (std::exception ex)
{
}
```

Was flagged with "catch handler catches a pointer value".

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits, JDevlieghere

Patch by Florian Gross!

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

llvm-svn: 298608
2017-03-23 15:17:44 +00:00
Alexander Kornienko c3acd2e9c0 [clang-tidy] Catch trivially true statements like a != 1 || a != 3
Catch trivially true statements of the form a != 1 || a != 3. Statements like
these are likely errors. They are particularly easy to miss when handling enums:

enum State {
RUNNING,
STOPPED,
STARTING,
ENDING
}

...
if (state != RUNNING || state != STARTING)
...

Patch by Blaise Watson!

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

llvm-svn: 298607
2017-03-23 15:13:54 +00:00
Alexander Kornienko b10daaf198 [Clang-tidy] Fix for misc-noexcept-move-constructor false triggers on defaulted declarations
Summary:
There is no need for triggering warning when noexcept specifier in move constructor or move-assignment operator is neither evaluated nor uninstantiated.

This fixes bug reported here: bugs.llvm.org/show_bug.cgi?id=24712

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JonasToth, JDevlieghere, cfe-commits

Tags: #clang-tools-extra

Patch by Marek Jenda!

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

llvm-svn: 298101
2017-03-17 16:40:34 +00:00
Martin Bohme 96d29e5761 [clang-tidy] misc-use-after-move: Fix failing assertion
Summary:
I've added a test case that (without the fix) triggers the assertion,
which happens when a move happens in an implicitly called conversion
operator.

This patch also fixes nondeterministic behavior in the source code
location reported for the move when the move is constained in an init list;
this was causing buildbot failures in the previous attempt to submit
this patch (see D30569 and rL297004).

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits

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

llvm-svn: 297272
2017-03-08 12:34:51 +00:00
Martin Bohme 2e5f130bf4 Revert "[clang-tidy] misc-use-after-move: Fix failing assertion"
This reverts commit r297004; it was causing buildbots to fail.

llvm-svn: 297006
2017-03-06 09:46:27 +00:00
Martin Bohme a6391ae52b [clang-tidy] misc-use-after-move: Fix failing assertion
Summary:
I've added a test case that (without the fix) triggers the assertion,
which happens when a move happens in an implicitly called conversion
operator.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 297004
2017-03-06 08:55:42 +00:00
Haojian Wu ead59eeade [clang-tidy] Ignore instantiated functions and static data members of classes in misc-definitions-in-headers.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 295178
2017-02-15 14:10:50 +00:00
Malcolm Parsons 51642f9d0a [clang-tidy] Don't warn about call to unresolved operator*
Summary:
The misc-unconventional-assign-operator check had a false positive
warning when the 'operator*' in 'return *this' was unresolved.

Change matcher to allow calls to unresolved operator.

Fixes PR31531.

Reviewers: alexfh, aaron.ballman

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 295176
2017-02-15 14:01:41 +00:00
Haojian Wu be2588fa7f [clang-tidy] Improve diagnostic message for misc-definitions-in-header.
Summary:
Users might get confused easily when they see the check's message on
full template function speciliations.

Add a note to the output message, which mentions these kind of function
specializations are treated as regular functions.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 295048
2017-02-14 12:39:22 +00:00
Alexander Kornienko 28239b166f [clang-tidy] Fix misc-unused-using-decls false positives in presence of compile errors
llvm-svn: 294578
2017-02-09 10:41:27 +00:00
Alexander Kornienko 385c2a3134 [clang-tidy] hasErrorOccurred() -> hasUncompilableErrorOccurred()
hasErrorOccurred() -> hasUncompilableErrorOccurred(), since we only care about
errors that lead to invalid AST.

llvm-svn: 294467
2017-02-08 16:11:22 +00:00
Alexander Kornienko bb64200e16 [clang-tidy] Supresses misc-move-constructor-init warning for const fields.
Patch by CJ DiMeglio!

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

llvm-svn: 294459
2017-02-08 14:56:16 +00:00
Alexander Kornienko 258d9a528e [clang-tidy] misc-argument-comment - extended gmock support
It looks like direct calls to mocked methods happen in the wild. This patch
add support for these as well.

llvm-svn: 294293
2017-02-07 11:39:56 +00:00
Alexander Kornienko d9fa4e95ec [clang-tidy] misc-argument-comment support for gmock
Now for real. The use case supported previously is used by approximately nobody.
What's needed is support for matching argument comments in EXPECT_xxx calls to
the names of parameters of the mocked methods.

llvm-svn: 294193
2017-02-06 15:47:17 +00:00
Alexander Kornienko 2d73022122 [clang-tidy] getPreviousNonCommentToken -> getPreviousToken
llvm-svn: 294192
2017-02-06 15:46:33 +00:00
Alexander Kornienko 73c69a3714 [clang-tidy] misc-argument-comment support for gmock
llvm-svn: 293845
2017-02-02 00:37:08 +00:00
Alexander Kornienko 165fe63b4e [clang-tidy] misc-argument-comment: ignore comments after arguments
llvm-svn: 293771
2017-02-01 15:28:25 +00:00
Mads Ravn 72bcc049f2 [clang-tidy] Add check 'misc-string-compare'.
I have a created a new check for clang tidy: misc-string-compare. This will check for incorrect usage of std::string::compare when used to check equality or inequality of string instead of the string equality or inequality operators.

Example:
```
  std::string str1, str2;
  if (str1.compare(str2)) {
  }
```

Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons

Subscribers: xazax.hun, Eugene.Zelenko, cfe-commits, malcolm.parsons, Prazek, mgorny, JDevlieghere

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

llvm-svn: 290747
2016-12-30 10:09:46 +00:00
Gabor Horvath 2953b42a2e [clang-tidy] Add enum misuse check.
The checker detects various cases when an enum is probably misused
(as a bitmask).

Patch by: Peter Szecsi!

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

llvm-svn: 290600
2016-12-27 10:07:39 +00:00
Marek Sokolowski 23dd4c37be [clang-tidy] refactor ExprSequence out of use-after-move check
Differential Revision: https://reviews.llvm.org/D27700

llvm-svn: 290489
2016-12-24 12:45:07 +00:00
Malcolm Parsons 79578cc936 [clang-tidy] Remove duplicated check from move-constructor-init
Summary:
An addition to the move-constructor-init check was duplicating the
modernize-pass-by-value check.
Remove the additional check and UseCERTSemantics option.
Run the move-constructor-init test with both checks enabled.
Fix modernize-pass-by-value false-positive when initializing a base
class.
Add option to modernize-pass-by-value to only warn about parameters
that are already values.

Reviewers: alexfh, flx, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 290051
2016-12-17 20:23:14 +00:00