Commit Graph

970 Commits

Author SHA1 Message Date
Douglas Yung 50c7db17f7 Fix test from r330245 on Windows.
llvm-svn: 330305
2018-04-18 23:58:05 +00:00
Yan Zhang 0313614f4d add extra acronyms for objc property names
Summary: This is to support general acronyms in Objective-C like 2G/3G/4G/... and coordinates X, Y, Z and W.

Reviewers: benhamilton

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 330286
2018-04-18 20:09:10 +00:00
Haojian Wu 10e50c8797 [clang-tidy] Fix clang-tidy doesn't read .clangtidy configuration file.
Summary: Fix https://bugs.llvm.org/show_bug.cgi?id=34900.

Reviewers: alexfh

Reviewed By: alexfh

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

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

llvm-svn: 330245
2018-04-18 08:54:28 +00:00
Roman Lebedev 4d37af003f [clang-tidy] readability-function-size: add VariableThreshold param.
Summary:
Pretty straight-forward, just count all the variable declarations in the function's body, and if more than the configured threshold - do complain.

Note that this continues perverse practice of disabling the new option by default.
I'm not certain where is the balance point between not being too noisy, and actually enforcing the good practice.
If we really want to not disable this by default, but also to not cause too many new warnings, we could default to 50 or so.
But that is a lot of variables too...

I was able to find one coding style referencing variable count:
  - https://www.kernel.org/doc/html/v4.15/process/coding-style.html#functions

    > Another measure of the function is the number of local variables. They shouldn’t exceed 5-10, or you’re doing something wrong.

Reviewers: hokein, xazax.hun, JonasToth, aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: kimgr, Eugene.Zelenko, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 329902
2018-04-12 12:06:42 +00:00
Zinovy Nis 60874d4faf [clang-tidy] [modernize-use-auto] Fix test modernize-use-auto-new-remove-stars.cpp after improvement
'tooling::fixit::getText' considers a length of "int *" to be 5 instead of 3 
in a new algorithm in https://reviews.llvm.org/rCTE329873. It was the root of 
the test failure.

llvm-svn: 329881
2018-04-12 06:45:47 +00:00
Jonas Toth 057f5a1259 [clang-tidy] fix buildbots from hicpp-signed-bitwise
The applied patch to diagnose assignment operators introduced
breakage on some architectures. This patch tries to rectify that.

llvm-svn: 329790
2018-04-11 10:22:25 +00:00
Jonas Toth 0f5f41df93 [clang-tidy] add missing assignment operations in hicpp-signed-bitwise
This patch resolves the bug https://bugs.llvm.org/show_bug.cgi?id=36963.

- implement missing assignment operators for hicpp-signed-bitwise
- mention fix in release notes

Reviewers:
aaron.ballman, hokein, alexfh

Differential: https://reviews.llvm.org/D45414
llvm-svn: 329789
2018-04-11 09:53:08 +00:00
George Burgess IV 3b151b2189 [clang-tidy] Add a `android-comparison-in-temp-failure-retry` check
This check attempts to catch buggy uses of the `TEMP_FAILURE_RETRY`
macro, which is provided by both Bionic and glibc.

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

llvm-svn: 329759
2018-04-10 21:22:22 +00:00
Roman Lebedev 9f742bc2e9 [clang-tidy] Unbreak run-clang-tidy.cpp test (modernize-use-auto.MinTypeNameLength)
Again, refs. D45405, rL329730.

llvm-svn: 329756
2018-04-10 20:59:27 +00:00
Zinovy Nis e68c7fa1e5 [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'
The threshold option is 'MinTypeNameLength' with default value '5'. 
With MinTypeNameLength == 5 'int'/'bool' and 'const int'/'const bool' 
will not be converted to 'auto', while 'unsigned' will be. 

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

llvm-svn: 329730
2018-04-10 18:05:24 +00:00
Alexander Kornienko c3ad02e840 [clang-tidy] Return non-zero exit code for clang errors.
Summary:
Updated tests broken by this change.
Fixes https://bugs.llvm.org/show_bug.cgi?id=27628

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 329579
2018-04-09 15:12:10 +00:00
Zinovy Nis 95ea1b05fd [clang-tidy] Check if grand-..parent's virtual method was called instead of overridden parent's.
class A {...int virtual foo() {...}...}; 
class B: public A {...int foo() override {...}...}; 
class C: public B {...int foo() override {... A::foo()...}};
                                              ^^^^^^^^ warning: qualified name A::foo refers to a member overridden in subclass; did you mean 'B'? [bugprone-parent-virtual-call] 

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

llvm-svn: 329448
2018-04-06 20:02:50 +00:00
Benjamin Kramer be92ce14e1 [clang-tidy] Remove google-runtime-member-string-references
This is triggering on a pattern that's both too broad (const
std::string& members can be used safely) and too narrow (std::string is
not the only class with this problem). It has a very low true positive
rate, just remove it until we find a better solution for dangling string
references.

llvm-svn: 329292
2018-04-05 14:51:01 +00:00
Alexander Kornienko b1c746ef04 [clang-tidy] Rename -warnings-as-errors tests. NFC.
The tests will be more discoverable with proper names.

llvm-svn: 329182
2018-04-04 12:40:00 +00:00
Haojian Wu dc62da4e0b [clang-tidy] Check for sizeof that call functions
Summary:
A common mistake that I have found in our codebase is calling a function to get an integer or enum that represents the type such as:

```
int numBytes = numElements * sizeof(x.GetType());
```

So this extends the `sizeof` check to check for these cases. There is also a `WarnOnSizeOfCall` option so it can be disabled.

Patch by Paul Fultz II!

Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov

Reviewed By: alexfh

Subscribers: lebedev.ri, xazax.hun, jkorous-apple, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 329073
2018-04-03 15:10:24 +00:00
Mike Edwards ac6a6577d9 Revert r328932 as it caused Windows and MacOS bot failures.
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/43991/

llvm-svn: 328997
2018-04-02 18:02:36 +00:00
Zinovy Nis c16815ca8a [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer
This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered as [[no-return]], and a lot of false-positive warnings about nullptr dereferenced are emitted.
This patch fixes the issue by explicitly added macro definition.

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

llvm-svn: 328932
2018-04-01 11:51:57 +00:00
Alexander Kornienko 301faac18b clang-tidy, modularize: return non-zero exit code on errors
When no inputs given, the tools should not only produce the help message, but
also return a non-zero exit code. Fixed tests accordingly.

llvm-svn: 328199
2018-03-22 14:18:20 +00:00
Julie Hockett 6e79ac5339 [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows
After changes to lit.site.cfg.in, the test is now running (and failing)
on windows, so temporarily marking it unsupported. See PR36855 for more
details.

llvm-svn: 328127
2018-03-21 18:03:41 +00:00
Jonas Toth bf50a7f880 [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test
The original check did break the green buildbot in the sanitizer build.
It took a while to redroduce and understand the issue.

There occured a stackoverflow while parsing the AST. The testcase with
256 case labels was the problem because each case label added another
stackframe. It seemed that the issue occured only in 'RelWithDebInfo' builds
and not in normal sanitizer builds.

To simplify the matchers the recognition for the different kinds of switch
statements has been moved into a seperate function and will not be done with
ASTMatchers. This is an attempt to reduce recursion and stacksize as well.

The new check removed this big testcase. Covering all possible values is still
implemented for bitfields and works there. The same logic on integer types
will lead to the issue.

Running it over LLVM gives the following results:


Differential: https://reviews.llvm.org/D40737
llvm-svn: 328107
2018-03-21 15:34:15 +00:00
Alexander Kornienko 670c6315ac [clang-tidy][modernize-make-unique] Checks c++14 flag before using std::make_unique
Summary: For a c++11 code, the clang-tidy rule "modernize-make-unique" should return immediately, as std::make_unique is not supported.

Reviewers: hokein, aaron.ballman, ilya-biryukov, alexfh

Reviewed By: hokein, aaron.ballman, alexfh

Subscribers: Quuxplusone, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Frederic Tingaud!

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

llvm-svn: 328101
2018-03-21 14:39:24 +00:00
Douglas Yung 2ecc0d3954 Fixup test to explicitly use -fexceptions since exceptions are disabled by default on the PS4 target.
llvm-svn: 327911
2018-03-19 21:22:58 +00:00
Miklos Vajna 10fe9bc79e run-clang-tidy: forward clang-tidy exit status
Exit with a non-zero value in case any of the underlying clang-tidy
invocations exit with a non-zero value.

This is useful in case WarningsAsErrors is enabled for some of the
checks: if any of those checks find something, the exit status now
reflects that.

Also add the ability to use run-clang-tidy.py via lit, and assert that
the exit code is not 0 when modernize-use-auto is triggered
intentionally.

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

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

llvm-svn: 327854
2018-03-19 14:43:59 +00:00
Alexander Kornienko fcefdb877c [clang-tidy] New check bugprone-unused-return-value
Summary:
Detects function calls where the return value is unused.

Checked functions can be configured.

Reviewers: alexfh, aaron.ballman, ilya-biryukov, hokein

Reviewed By: alexfh, aaron.ballman

Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Kalle Huttunen!

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

llvm-svn: 327833
2018-03-19 13:02:32 +00:00
Alexander Kornienko 67112853c2 [clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii --check_class_name=UnusedRAIICheck
llvm-svn: 327610
2018-03-15 08:27:42 +00:00
Alexander Kornienko 68fb65f413 [clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-container
llvm-svn: 327608
2018-03-15 08:26:47 +00:00
Alexander Kornienko 3273888536 [clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expression
llvm-svn: 327607
2018-03-15 08:26:19 +00:00
Alexander Kornienko 7ff6076129 [clang-tidy] rename_check.py {misc,bugprone}-macro-parentheses
llvm-svn: 327606
2018-03-15 08:25:39 +00:00
Julie Hockett b6f7c934ac [clang-tidy] Add Zircon module to clang-tidy
Adding a Zircon module to clang-tidy for checks specific to the Zircon
kernel, and adding a checker to fuchsia-zx (for zircon) to flag instances
where specific objects are temporarily created.

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

llvm-svn: 327590
2018-03-14 23:47:50 +00:00
Haojian Wu 40571b7c1c [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith
Patch by Niko Weh!

Reviewers: hokein

Subscribers: klimek, cfe-commits, ioeric, ilya-biryukov, ahedberg

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

llvm-svn: 327111
2018-03-09 10:47:14 +00:00
Fangrui Song c0e768df90 [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics
Reviewers: alexfh

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

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

llvm-svn: 326909
2018-03-07 16:57:42 +00:00
Haojian Wu 0dc8fd7460 [clang-tidy] Fix one corner case in make-unique check.
Summary:
Previously, we tried to cover all "std::initializer_list" implicit conversion
cases in the code, but there are some corner cases that not covered (see
newly-added test in the patch).

Sipping all implicit AST nodes is a better way to filter out all these cases.

Reviewers: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 326799
2018-03-06 14:34:35 +00:00
Aaron Ballman ada5234b6e Adds a clang-tidy test for a failing assertion in the misc-misplaced-const check.
The test case previously triggered an assertion in the AST matchers because the QualType being matched is invalid. That is no longer the case after r326604.

llvm-svn: 326605
2018-03-02 19:14:34 +00:00
Alexander Kornienko eb9d944419 [clang-tidy] Another batch of checks to rename from misc- to bugprone-.
Summary:
clang-tidy/rename_check.py {misc,bugprone}-suspicious-semicolon
clang-tidy/rename_check.py {misc,bugprone}-suspicious-string-compare
clang-tidy/rename_check.py {misc,bugprone}-swapped-arguments
clang-tidy/rename_check.py {misc,bugprone}-undelegated-constructor --check_class_name UndelegatedConstructor

Reviewers: hokein, sammccall, aaron.ballman

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

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

llvm-svn: 326386
2018-02-28 23:47:15 +00:00
Alexander Kornienko cb6d320345 Rename more checks from misc- to bugprone-.
Summary:
clang-tidy/rename_check.py {misc,bugprone}-string-integer-assignment
clang-tidy/rename_check.py {misc,bugprone}-string-literal-with-embedded-nul
clang-tidy/rename_check.py {misc,bugprone}-suspicious-enum-usage
clang-tidy/rename_check.py {misc,bugprone}-suspicious-missing-comma

Reviewers: hokein, sammccall, aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

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

llvm-svn: 326384
2018-02-28 23:30:29 +00:00
Alexander Kornienko a1a2933634 Rename a few checks from misc- to bugprone-.
Summary:
rename_check.py {misc,bugprone}-forwarding-reference-overload
rename_check.py {misc,bugprone}-macro-repeated-side-effects
rename_check.py {misc,bugprone}-lambda-function-name
rename_check.py {misc,bugprone}-misplaced-widening-cast

Reviewers: hokein, sammccall, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

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

llvm-svn: 326327
2018-02-28 14:47:20 +00:00
Alexander Kornienko a94a4308e1 [clang-tidy] Add a test for readability-implicit-bool-conversion with bitfields.
llvm-svn: 326314
2018-02-28 10:30:25 +00:00
Yan Zhang 2d83647007 [clang-tidy/google] Improve the Objective-C global variable declaration check 🔧
Summary:
The current Objective-C global variable declaration check restricts naming that is permitted by the Google Objective-C style guide.

The Objective-C style guide states the following:
"Global and file scope constants should have an appropriate prefix. [...] Constants may use a lowercase k prefix when appropriate"
http://google.github.io/styleguide/objcguide#constants

This change fixes the check to allow two or more capital letters as an appropriate prefix. This change intentionally avoids making a decision regarding whether to flag constants that use a two letter prefix (two letter prefixes are reserved by Apple¹ but many projects seem to violate this guideline).

This change eliminates an important category of false positives (constants prefixed with '[A-Z]{2,}') at the cost of introducing a less important category of false negatives (constants prefixed with only '[A-Z]'). The false positives are observed in standard recommended code while the false negatives occur in non-standard unrecommended code. The number of eliminated false positives is expected to be significantly larger than the number of exposed false negatives.

❧

(1)
"Two-letter prefixes like these are reserved by Apple for use in framework classes."
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html

Reviewers: aaron.ballman, Wizard, hokein, benhamilton

Reviewed By: aaron.ballman, Wizard

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 326046
2018-02-25 04:11:26 +00:00
Gabor Horvath 76e5023dd3 [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions
Patch by: Daniel Kolozsvari!

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

llvm-svn: 325572
2018-02-20 10:48:38 +00:00
Fangrui Song 258a959084 [clang-tidy] Add `readability-simd-intrinsics` check.
Summary:
Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
ARM NEON). It is common that SIMD code implementing the same algorithm, is
written in multiple target-dispatching pieces to optimize for different
architectures or micro-architectures.

The C++ standard proposal P0214 and its extensions cover many common SIMD
operations. By migrating from target-dependent intrinsics to P0214 operations,
the SIMD code can be simplified and pieces for different targets can be unified.

Refer to http://wg21.link/p0214 for introduction and motivation for the
data-parallel standard library.

Subscribers: klimek, aemerson, mgorny, xazax.hun, kristof.beyls, hintonda, cfe-commits

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

llvm-svn: 325272
2018-02-15 17:56:43 +00:00
Gabor Horvath 387d0005e0 [clang-tidy] Make a test pass on platforms where exceptions disabled by default.
llvm-svn: 325225
2018-02-15 09:24:55 +00:00
Gabor Horvath c23f924b75 [clang-tidy] New checker for exceptions that are created but not thrown
Patch by: Kristof Umann

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

llvm-svn: 325222
2018-02-15 09:08:51 +00:00
Julie Hockett 9a26bf935c [clang-tidy] Update fuchsia-multiple-inheritance to not fail
Updating the fuchsia-multiple-inheritance to gracefully handle unknown
record types (e.g. templatized classes) by simply continuing, rather
than asserting and failing.

Fixes PR36052.

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

llvm-svn: 325015
2018-02-13 15:40:40 +00:00
Julie Hockett 7a76ada901 [clang-tidy] Update fuchsia-multiple-inheritance to check for templates
Updating fuchsia-multiple-inheritance to not crash when a record
inherits a template.

Fixes PR36052.

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

llvm-svn: 324432
2018-02-07 00:33:50 +00:00
Yan Zhang ae5bc5aeea Support special acronyms inside property names and allow plural forms
Reviewers: benhamilton, hokein

Reviewed By: benhamilton, hokein

Subscribers: klimek, cfe-commits

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

llvm-svn: 324407
2018-02-06 21:40:38 +00:00
Ben Hamilton b4ab4b6317 [clang-tidy] ObjC ARC objects should not trigger performance-unnecessary-value-param
Summary:
The following Objective-C code currently incorrectly triggers
clang-tidy's performance-unnecessary-value-param check:

```
% cat /tmp/performance-unnecessary-value-param-arc.m
void foo(id object) { }

clang-tidy /tmp/performance-unnecessary-value-param-arc.m
-checks=-\*,performance-unnecessary-value-param -- -xobjective-c
-fobjc-abi-version=2 -fobjc-arc
1 warning generated.
/src/llvm/tools/clang/tools/extra/test/clang-tidy/performance-unnecessary-value-param-arc.m:10:13:
warning: the parameter 'object' is copied for each invocation but only
used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
void foo(id object) { }
         ~~ ^
         const &
```

This is wrong for a few reasons:

1) Objective-C doesn't have references, so `const &` is not going to help
2) ARC heavily optimizes the "expensive" copy which triggers the warning

This fixes the issue by disabling the warning for non-C++, as well as
disabling it for objects under ARC memory management for
Objective-C++.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32075

Test Plan: New tests added. Ran tests with `make -j12 check-clang-tools`.

Reviewers: alexfh, hokein

Reviewed By: hokein

Subscribers: stephanemoore, klimek, xazax.hun, cfe-commits, Wizard

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

llvm-svn: 324097
2018-02-02 15:34:33 +00:00
Alexander Kornienko 396fc87694 [clang-tidy] misc-redundant-expression: fix a crash under ubsan
llvm-svn: 323980
2018-02-01 16:39:12 +00:00
Alexander Kornienko 4256fd0b4b clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings
More specifically,
clang-tidy/rename_check.py misc-incorrect-roundings \
  bugprone-incorrect-roundings --check_class_name IncorrectRoundings

llvm-svn: 323768
2018-01-30 15:12:24 +00:00
Alexander Kornienko 5c9c0427bb clang-tidy/rename_check.py misc-string-compare readability-string-compare
llvm-svn: 323766
2018-01-30 14:55:50 +00:00
Yan Zhang 75b3b541d5 add prefix with '_' support for property name. Corresponding apple dev doc: https://developer.apple.com/library/content/qa/qa1908/_index.html
Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 323722
2018-01-30 01:44:00 +00:00