Commit Graph

2449 Commits

Author SHA1 Message Date
Roman Lebedev a1cee29608 [clang-tidy] readability-function-size: add NestingThreshold param.
Summary:
Finds compound statements which create next nesting level after `NestingThreshold` and emits a warning.
Do note that it warns about each compound statement that breaches the threshold, but not any of it's sub-statements, to have readable warnings.

I was able to find only one coding style referencing nesting:
  - https://www.kernel.org/doc/html/v4.10/process/coding-style.html#indentation
     > In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep.

This seems too basic, i'm not sure what else to test. Are more tests needed?

Reviewers: alexfh, aaron.ballman, sbenza

Reviewed By: alexfh, aaron.ballman

Subscribers: xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 305082
2017-06-09 14:22:10 +00:00
Roman Lebedev 739b48399d [clang-tools-extra] ReleaseNotes.rst: test commit: whitespace fix
llvm-svn: 305067
2017-06-09 12:00:04 +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
Argyrios Kyrtzidis 783e4c2e32 [clangd] Update for ASTUnit API change.
llvm-svn: 305046
2017-06-09 02:04:19 +00:00
Alexander Kornienko 934b516a0a [clang-tidy] Use -fexceptions explicitly in the tests that need exceptions.
This should fix relevant buildbot breakages.

llvm-svn: 305024
2017-06-08 22:25:23 +00:00
Simon Pilgrim 1496468259 Wdocumentation fix.
llvm-svn: 304988
2017-06-08 17:01:01 +00:00
Krasimir Georgiev e1cac9171c [clangd] extend completion test
llvm-svn: 304983
2017-06-08 16:02:27 +00:00
Krasimir Georgiev 5579eb0a7a [clangd] Separate authority less uris from completion tests
llvm-svn: 304981
2017-06-08 15:21:55 +00:00
Krasimir Georgiev e6035a51f7 [clangd] Add parameter and return type information to completion results
Summary:
This patch adds information about the parameters and return types of completion
candidates.
Previously, for the following code:
```
struct S {
  int func(int a, double b) const;
};
```
the completer would only return the label of the candidate `func`.
Now it will also return the return type `int` and will format the label for the
candidate as `func(int a, double b) const`.

Reviewers: bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 304980
2017-06-08 15:11:51 +00:00
Alexander Kornienko 08936e4740 [clang-tidy] New checker to replace dynamic exception specifications
Summary:
New checker to replace dynamic exception
specifications

This is an alternative to D18575 which relied on reparsing the decl to
find the location of dynamic exception specifications, but couldn't
deal with preprocessor conditionals correctly without reparsing the
entire file.

This approach uses D20428 to find dynamic exception specification
locations and handles all cases correctly.

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman, alexfh

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

Patch by Don Hinton!

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

llvm-svn: 304977
2017-06-08 14:04:16 +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
Yan Wang bebc9b707c [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.
Summary: clang-tidy is better not to issues this warning, which checks where the initializer for the object may throw an exception, when "-fno-exceptions" is used.

Reviewers: chh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 304931
2017-06-07 17:41:59 +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
Dimitry Andric dbe776e86d Adjust SetVersionPrinter call for D33899
Summary:
In D33899, I'm adding a `raw_ostream &` parameter to the function
objects passed to `cl::SetVersionPrinter`.  Adjust the call in
clang-apply-replacements for this.

Reviewers: klimek, alexfh

Subscribers: cfe-commits

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

llvm-svn: 304837
2017-06-06 21:54:45 +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 038aefdec5 Fix formatting in docs.
llvm-svn: 304581
2017-06-02 18:44:32 +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
Miklos Vajna a0ce632079 clang-rename: add new -force option
Summary:
    The use-case is when renaming a widely used name, like a lower-level
    class in a codebase and clang-rename is simply invoked for each
    translation unit based on the compile database. In this case it's not
    interesting to show errors: not finding the symbol means there is
    simply nothing to do.

Reviewers: klimek

Reviewed By: klimek

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

llvm-svn: 304534
2017-06-02 09:32:28 +00:00
Ilya Biryukov 2260299830 [clangd] Mark results of clangd requests with a tag provided by the FileSystemProvider.
Summary:
This allows an implementation of FileSystemProvider that can track which vfs::FileSystem
were used for each of the requests.

Reviewers: bkramer, krasimir

Reviewed By: bkramer

Subscribers: klimek, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 304214
2017-05-30 15:11:02 +00:00
Alexander Kornienko 0055d97d4b [clang-tidy] Use getLocalOrGlobal for the StrictMode option
llvm-svn: 304154
2017-05-29 13:59:27 +00:00
NAKAMURA Takumi 2efabeb933 ClangdTests.cpp: Use "clang/Config/config.h" instead of "llvm/Config/config.h".
llvm-svn: 304082
2017-05-27 23:19:28 +00:00
NAKAMURA Takumi 4455641ae0 ClangdTests.cpp: Fix a possible typo, it was "if (TmpDir2 != TmpDir2)"
It caused failures in unittests if TmpDir2 is not "/tmp" .

llvm-svn: 304067
2017-05-27 08:06:52 +00:00
Ilya Biryukov 90fecdb47c [clangd] Attempt to fix tests failing on Windows
llvm-svn: 303993
2017-05-26 14:34:34 +00:00
Ilya Biryukov 0f62ed2bbe [clangd] Allow to use vfs::FileSystem for file accesses.
Summary:
Custom vfs::FileSystem is currently used for unit tests.
This revision depends on https://reviews.llvm.org/D33397.

Reviewers: bkramer, krasimir

Reviewed By: bkramer, krasimir

Subscribers: klimek, cfe-commits, mgorny

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

llvm-svn: 303977
2017-05-26 12:26:51 +00:00
Erich Keane a37711b1e2 Earlier revert introduced an extra space, remove it.
llvm-svn: 303909
2017-05-25 20:29:17 +00:00
Eugene Zelenko eed5f028ee [Documentation] Mention hicpp check group in Clang-tidy main document.
llvm-svn: 303884
2017-05-25 17:22:29 +00:00
Erich Keane ea0f630055 Revert 303872/303877 since the patch that caused these issues
is also being reverted.

llvm-svn: 303881
2017-05-25 16:23:00 +00:00
Erich Keane 594d0d592d Clang-tidy doesn't understand -fno-ms-compatibility, so just removing 'not'
llvm-svn: 303877
2017-05-25 16:07:19 +00:00
Erich Keane e6617e47d2 Disable MSVC-Compat mode for two tests that use C++Operator Names
MSVC doesn't support C++ operator names (using 'or' instead of ||, 
'not' instead of '!', etc), so this was disabled in MSVC mode in r303798.
This fixes the regression noticed on the buildbots.

llvm-svn: 303872
2017-05-25 15:39:24 +00:00
Florian Gross 7ce3a83c50 (no commit message)
llvm-svn: 303849
2017-05-25 11:43:06 +00:00
Serge Pavlov 0d4cc9bfbf Modify test so that it looks for patterns in stderr as well
With the change https://reviews.llvm.org/D33013 driver will not build
compilation object if command line is invalid, in particular, if
unrecognized option is provided. In such cases it will prints diagnostics
on stderr. The test 'clang-tidy/diagnostic.cpp' checks reaction on
unrecognized option and will fail when D33013 is applied because it checks
only stdout for test patterns and expects the name of diagnostic category
prepared by clang-tidy. With this change the test makes more general check
and must work in either case.

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

llvm-svn: 303735
2017-05-24 10:50:56 +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
Ilya Biryukov 9bab8eab49 [clangd] Added a missing dependency on clangdAST to fix the build
llvm-svn: 303636
2017-05-23 13:59:37 +00:00
Ilya Biryukov f01af686a2 [clangd] Replaced WorkerRequest with std::function...
Summary:
And implemented a helper function to dump an AST of a file for
testing/debugging purposes.

Reviewers: bkramer, krasimir

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 303634
2017-05-23 13:42:59 +00:00
Benjamin Kramer 85c7827a0a [clangd] Explicitly link against pthread.
llvm-svn: 303625
2017-05-23 10:29:54 +00:00
Benjamin Kramer b2dfa0b840 [clangd] Pick up deps via LLVM components, which will hopefully include pthread.
llvm-svn: 303623
2017-05-23 10:17:48 +00:00
Ilya Biryukov af4ed4528a [clangd] Split clangd into library+executable (mainly for unit tests).
Summary:
This commit itself doesn't add any unit tests, but one that does will
follow shortly.

Reviewers: krasimir, bkramer

Reviewed By: bkramer

Subscribers: mgorny, klimek, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 303616
2017-05-23 08:12:45 +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 1e034c3f22 [clang-tidy] readability-redundant-declaration false positive for defaulted function
Summary:
```
template <class T>
struct C {
  C();
};

template <class T>
C<T>::C() = default;
```

Causes a readability-redundant-declaration diagnostic. This is caused by `isDefinition` not matching defaulted functions.

Reviewers: alexfh, danielmarjamaki

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Patch by Florian Gross!
Differential Revision: https://reviews.llvm.org/D33358

llvm-svn: 303552
2017-05-22 13:58:57 +00:00
Alexander Kornienko a0ddf5fc1c [clang-tidy] readability-braces-around-statements false positive with char literals
Summary:
Single-line if statements cause a false positive when the last token in the conditional statement is a char constant:

```
if (condition)
  return 'a';
```

For some reason `findEndLocation` seems to skips too many (vertical) whitespaces in this case. The same problem already occured with string literals (https://reviews.llvm.org/D25558), and was fixed by adding a special check for this very case. I just extended the condition to also include char constants. No idea what really causes the issue though.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Patch by Florian Gross!
Differential Revision: https://reviews.llvm.org/D33354

llvm-svn: 303551
2017-05-22 13:58:16 +00:00
Krasimir Georgiev d814533851 [clangd] Switch to incomplete translation units
Summary: This speeds up code completion. All the cool kids (ycmd) are doing it.

Reviewers: bkramer, ilya-biryukov

Reviewed By: bkramer

Subscribers: cfe-commits

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

llvm-svn: 303547
2017-05-22 12:49:08 +00:00
Benjamin Kramer 0daf2be704 [clangd] Make formatting.test asynchronous again.
This test doesn't rely on the order of asynchronous messages, enable
threads so we have at least some coverage for those code paths.

llvm-svn: 303376
2017-05-18 20:10:04 +00:00
Simon Pilgrim 8d81c22164 Fix 'not all control paths return a value' warning on windows buildbots.
llvm-svn: 303344
2017-05-18 10:48:23 +00:00
Alexander Kornienko 6180337fe1 [clang-tidy] Optimize GlobList::contains
With large lists of checks and large number of warnings GlobList::contains
starts being ridiculously CPU hungry, since it runs regexp match per glob.
Caching results of glob matching in a StringMap significantly speeds up check
filtering even for small GlobLists.

/tmp/q.cc:

void f() {
  int I;
  {int I;}
  {int I;}
  {int I;}
  ... // 200k times
}

Before the patch:

GlobList with 2 entries:
  $ time clang-tidy-old -checks=-*,modernize-use-override /tmp/q.cc -- -Wshadow
  200000 warnings generated.
  Suppressed 200000 warnings (200000 with check filters).

  real    0m3.826s
  user    0m3.176s
  sys     0m0.504s

GlobList with 28 entries:
  $ time clang-tidy-old -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow
  200000 warnings generated.
  Suppressed 200000 warnings (200000 with check filters).

  real    0m5.000s
  user    0m4.744s
  sys     0m0.060s

GlobList with 158 entries:
  $ time clang-tidy-old -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow
  200000 warnings generated.
  Suppressed 200000 warnings (200000 with check filters).

  real    0m13.920s
  user    0m13.636s
  sys     0m0.104s

With the patch runtime is practically independent from the length of the GlobList:
  $ time clang-tidy-new -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow
  200000 warnings generated.
  Suppressed 200000 warnings (200000 with check filters).

  real    0m2.300s
  user    0m2.104s
  sys     0m0.044s

llvm-svn: 303321
2017-05-18 01:13:51 +00:00
Alexander Kornienko 21375185e7 Change getChecksFilter() interface to hide implementation details.
llvm-svn: 303264
2017-05-17 14:39:47 +00:00
Alexander Kornienko c321a4f2b9 [clang-tidy] Replace matchesName with hasName where no regex is needed
llvm-svn: 303263
2017-05-17 14:39:39 +00:00
Haojian Wu dbc3911ce2 Recommit "[include-fixer] Don't throw exception when parsing unknown ar… …guments in vim script."
Summary: To make it work in neovim.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits

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

llvm-svn: 303260
2017-05-17 14:13:59 +00:00
Alexander Kornienko 63144359c5 [clang-tidy] A bit of refactoring of modernize-replace-auto-ptr. NFC
llvm-svn: 303256
2017-05-17 12:57:06 +00:00