Commit Graph

1125 Commits

Author SHA1 Message Date
Yan Wang 36206206cd [clang-tidy][Part1] Add a new module Android and three new checks.
Summary:
A common source of security bugs is code that opens a file descriptors without using the O_CLOEXEC flag.  (Without that flag, an opened sensitive file would remain open across a fork+exec to a lower-privileged SELinux domain, leaking that sensitive data.).

Add a new Android module and one checks in clang-tidy.
-- open(), openat(), and open64() should include O_CLOEXEC in their flags argument. [android-file-open-flag]

Links to part2 and part3:
https://reviews.llvm.org/D33745
https://reviews.llvm.org/D33747


Reviewers: chh, alexfh, aaron.ballman, hokein

Reviewed By: alexfh, hokein

Subscribers: jbcoe, joerg, malcolm.parsons, Eugene.Zelenko, srhines, mgorny, xazax.hun, cfe-commits, krytarowski

Tags: #clang-tools-extra

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

llvm-svn: 306165
2017-06-23 21:37:29 +00:00
Haojian Wu 25e54c93bb [clang-tidy] Fix a false positive in modernize-use-nullptr.
Summary:
The FP happens when a casting nullptr expression is used within a NULL-default-arguemnt cxx constructor.

Before the fix, the check will give a warning on nullptr when running
with the test case, which should not happen:

```
G(g(static_cast<char*>(nullptr)));
    ^~~~~~~~~~~
    nullptr
```

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, xazax.hun

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

llvm-svn: 306091
2017-06-23 09:36:49 +00:00
Roman Lebedev eb6d821cda [clang-tidy] readability-function-size: fix nesting level calculation
Summary:
A followup for D32942.

Malcolm Parsons has provided a valid testcase that the initial version of the check complained about nested `if`'s.
As it turns out, the culprit is the **partially** un-intentional `switch` fallthrough.
So rewrite the NestingThreshold logic without ab-using+mis-using that switch with fallthrough, and add testcases with nested `if`' where there should be a warning and shouldn't be a warning. This results in a cleaner, simpler code, too.

I guess, now it would be actually possible to pick some reasonable default for `NestingThreshold` setting.

Fixes PR33454.

Reviewers: malcolm.parsons, alexfh

Reviewed By: malcolm.parsons

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

Tags: #clang-tools-extra

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

llvm-svn: 305554
2017-06-16 13:07:47 +00:00
Krasimir Georgiev a1de3c91e5 [clangd] Add priority to completion item sort text
Summary:
This patch adds the priority of a completion item to the sort text of the
returned LSP result.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 305454
2017-06-15 09:11:57 +00:00
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
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
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
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
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 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
Erich Keane a37711b1e2 Earlier revert introduced an extra space, remove it.
llvm-svn: 303909
2017-05-25 20:29:17 +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
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
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
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
Haojian Wu be6ef0eff9 [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.
Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

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

Tags: #clang-tools-extra

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

llvm-svn: 303157
2017-05-16 10:39:55 +00:00
Ilya Biryukov 38d79774d0 Restored r303067 and fixed failing test.
Summary:
This commit restores r303067(reverted by r303094) and fixes the 'formatting.test'
failure.
The failure is due to destructors of `ClangdLSPServer`'s fields(`FixItsMap` and
`FixItsMutex`) being called before destructor of `Server`. It led to the worker
thread calling `consumeDiagnostics` after `FixItsMutex` and `FixItsMap`
destructors were called.
Also, clangd is now run with '-run-synchronously' flag in 'formatting.test'.

Reviewers: bkramer, krasimir

Reviewed By: krasimir

Subscribers: mgorny, cfe-commits, klimek

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

llvm-svn: 303151
2017-05-16 09:38:59 +00:00
Jakub Kuderski 4cdeb41072 [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls
Summary:
This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`.

Eq.

```
std::vector<std::tuple<int, char, bool>> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);
```

Reviewers: alexfh, aaron.ballman, Prazek, hokein

Reviewed By: Prazek

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

Tags: #clang-tools-extra

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

llvm-svn: 303145
2017-05-16 06:32:38 +00:00
Jakub Kuderski 9ac6c03989 Revert "[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls"
This reverts commit r303139. The commit made docs build emit a warning.

llvm-svn: 303140
2017-05-16 05:07:40 +00:00
Jakub Kuderski 7ff204ffdc [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls
Summary:
This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`.

Eq.

```
std::vector<std::tuple<int, char, bool>> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);
```

Reviewers: alexfh, aaron.ballman, Prazek, hokein

Reviewed By: Prazek

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

Tags: #clang-tools-extra

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

llvm-svn: 303139
2017-05-16 04:25:42 +00:00
Alexander Kornienko 1ca0e322a2 Make google-build-using-namespace skip std::.*literals
Summary:
C++14 added a couple of user-defined literals in the standard library. E.g.
std::chrono_literals and std::literals::chrono_literals . Using them
requires a using directive so do not warn in google-build-using-namespace
if namespace name starts with "std::" and ends with "literals".

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Martin Ejdestig!

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

llvm-svn: 303085
2017-05-15 17:37:48 +00:00
Yan Wang 7696b71d64 [clang-tidy] TwineLocalCheck: add param # checking
Summary:
The statement **getArg** tries to get the first one without checking, which may cause segmentation fault.

 

Reviewers: chh, bkramer

Reviewed By: bkramer

Subscribers: cfe-commits, xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 303001
2017-05-14 04:14:59 +00:00
Alexander Kornienko d09472e721 [clang-tidy] Add a test for PR33020
Fix committed in clang as r302889.

llvm-svn: 302890
2017-05-12 11:24:58 +00:00
Gabor Horvath a7fcc00d51 [clang-tidy] Add new cert-dcl21-cpp check
This check flags postfix operator++/-- declarations,
where the return type is not a const object.

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

llvm-svn: 302637
2017-05-10 11:16:55 +00:00
Alexander Kornienko d0488d427c Change EOL style to LF. NFC
llvm-svn: 302534
2017-05-09 14:56:28 +00:00
Alexander Kornienko 7aedf33a24 [clang-tidy] Minor cleanup + a disabled test case for PR26228. NFC
llvm-svn: 302522
2017-05-09 12:41:11 +00:00
Alexander Kornienko f89e0bb2c4 [clang-tidy] Fix readability-implicit-bool-cast false positives
The patch makes the check treat binary conditional operator (`x ?: y`), `while`
and regular `for` loops as conditional statements for the purpose of
AllowConditional*Cast options.

llvm-svn: 302431
2017-05-08 15:22:09 +00:00
Miklos Vajna 0854f2dd8f clang-tidy: add IgnoreMacros option to modernize-use-default-member-init
Summary:
And also enable it by default to be consistent with e.g.
modernize-use-using.

This helps e.g. when running this check on cppunit client code where the
macro is provided by the system, so there is no easy way to modify it.

Reviewers: alexfh, malcolm.parsons

Reviewed By: malcolm.parsons

Subscribers: cfe-commits

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

llvm-svn: 302429
2017-05-08 15:13:31 +00:00
Alexander Kornienko 096977abbf [clang-tidy] Ignore private =deleted methods in macros.
modernize-use-equals-delete is extremely noisy in code using
DISALLOW_COPY_AND_ASSIGN-style macros and there's no easy way to automatically
fix the warning when macros are in play.

llvm-svn: 302425
2017-05-08 14:17:27 +00:00
Jakub Kuderski f8d872c66e [clang-tidy] Fix PR32896: detect initializer lists in modernize-use-empalce
Summary:
This patch fixes [[ https://bugs.llvm.org/show_bug.cgi?id=32896 | PR32896 ]].

The problem was that modernize-use-emplace incorrectly removed changed push_back into emplace_back, removing explicit constructor call with initializer list parameter, resulting in compiler error after applying fixits.
modernize-use-emplace used to check if matched constructor had InitListExpr, but didn't check against CXXStdInitializerListExpr.

Eg.

```
std::vector<std::vector<int>> v;
  v.push_back(std::vector<int>({1})); // --> v.emplace_back({1});
```

Reviewers: Prazek, alexfh, aaron.ballman

Reviewed By: Prazek, alexfh, aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 302281
2017-05-05 20:35:30 +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
Alexander Kornienko c6ba6fc3c8 [clang-tidy] fix readability-implicit-bool-cast false positive with xor
llvm-svn: 302164
2017-05-04 16:06:08 +00:00
Alexander Kornienko b92cb07bad [clang-tidy] fix readability-implicit-bool-cast false alarm on |=, &=
llvm-svn: 302161
2017-05-04 15:34:31 +00:00
Alexander Kornienko cbe8d16da4 [clang-tidy] Code cleanup, (almost) NFC (*).
(*) Printed types of member pointers don't use elaborated type specifiers
(`int struct S::*` -> `int S::*`).

llvm-svn: 302160
2017-05-04 15:34:23 +00:00
NAKAMURA Takumi 68ce7c3b0d clang-tools-extra/test/CMakeLists.txt: Rework r297806 (D29851) to make sure test utils should be built.
FIXME: This may be moved to llvm's add_lit_target().
llvm-svn: 301762
2017-04-30 03:19:04 +00:00
Alexander Kornienko 4e001b5bd7 [clang-tidy] Expand AllowConditional*Casts to binary logical operators
llvm-svn: 301743
2017-04-29 12:06:45 +00:00
Jakub Kuderski 2a43d71765 [clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls
Summary:
When there is a push_back with a call to make_pair, turn it into emplace_back and remove the unnecessary make_pair call.

Eg.

```
std::vector<std::pair<int, int>> v;
v.push_back(std::make_pair(1, 2)); // --> v.emplace_back(1, 2);
```

make_pair doesn't get removed when explicit template parameters are provided, because of potential problems with type conversions.

Reviewers: Prazek, aaron.ballman, hokein, alexfh

Reviewed By: Prazek, alexfh

Subscribers: JDevlieghere, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 301651
2017-04-28 16:25:45 +00:00
Haojian Wu 489f363380 [clang-tidy] Support detecting for-range loop in inefficient-vector-operation check.
Summary:
Also add an option "VectorLikeClasses" allowing user specify customized
vectors.

Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

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

llvm-svn: 301440
2017-04-26 18:13:05 +00:00