Commit Graph

1564 Commits

Author SHA1 Message Date
Alexander Kornienko 07ef786652 [clang-tidy] make getLangOpts return a const ref
llvm-svn: 357468
2019-04-02 11:31:56 +00:00
Alexander Kornienko 397ee70180 [clang-tidy] Fix PR28406
Fix the crash resulting from a careless use of getLocWithOffset. At the
beginning of a macro expansion it produces an invalid SourceLocation that causes
an assertion failure later on.

llvm-svn: 357312
2019-03-29 20:55:29 +00:00
Zinovy Nis f8b7269f98 [clang-tidy] Handle missing yaml module in run-clang-tidy.py
The Yaml module is missing on some systems and on many of clang buildbots. 
But the test for run-clang-tidy.py doesn't fail due to 'NOT' statement masking a python runtime error.

This patch conditionally imports and enables the yaml module only if it's present in the system. 
If not, then '-export-fixes' is disabled.

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

llvm-svn: 357114
2019-03-27 19:21:32 +00:00
Duncan P. N. Exon Smith db8a742206 Basic: Return a reference from FileManager::getVirtualFileSystem, NFC
FileManager constructs a VFS in its constructor if it isn't passed one,
and there's no way to reset it.  Make that contract clear by returning a
reference from its accessor.

https://reviews.llvm.org/D59388

llvm-svn: 357038
2019-03-26 22:32:06 +00:00
Alexander Kornienko 6291868864 [clang-tidy] ClangTidy.h -> ClangTidyCheck.h
llvm-svn: 356902
2019-03-25 14:46:51 +00:00
Nico Weber 43356f56bd Rename directory housing clang-include-fixer to be eponymous
Makes the name of this directory consistent with the names of the other
directories in clang-tools-extra.

Similar to r356254. No intended behavior change.

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

llvm-svn: 356897
2019-03-25 14:09:10 +00:00
Alexander Kornienko 478fc5c83e [clang-tidy] Switch checks to #include "ClangTidyCheck.h"
llvm-svn: 356892
2019-03-25 12:38:26 +00:00
Alexander Kornienko e9087fe75c [clang-tidy] Separate the check-facing interface
Summary:
Move ClangTidyCheck to a separate header/.cpp
Switch checks to #include "ClangTidyCheck.h"
Mention ClangTidyCheck.h in the docs

Reviewers: hokein, gribozavr, aaron.ballman

Reviewed By: hokein

Subscribers: mgorny, javed.absar, xazax.hun, arphaman, jdoerfert, llvm-commits, cfe-commits

Tags: #clang, #llvm

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

llvm-svn: 356890
2019-03-25 12:36:30 +00:00
Clement Courbet d8e78022c6 [clang-tidy] Fix more false positives for bugprone-string-integer-assignment
Summary:
And add various tests gleaned for our codebase.

See PR27723.

Reviewers: JonasToth, alexfh, xazax.hun

Subscribers: rnkovacs, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 356871
2019-03-25 08:18:00 +00:00
Roman Lebedev 462446fd9a [clang-tidy] openmp-exception-escape - a new check
Summary:
Finally, we are here!

Analyzes OpenMP Structured Blocks and checks that no exception escapes
out of the Structured Block it was thrown in.

As per the OpenMP specification, structured block is an executable statement,
possibly compound, with a single entry at the top and a single exit at the
bottom. Which means, ``throw`` may not be used to to 'exit' out of the
structured block. If an exception is not caught in the same structured block
it was thrown in, the behaviour is undefined / implementation defined,
the program will likely terminate.

Reviewers: JonasToth, aaron.ballman, baloghadamsoftware, gribozavr

Reviewed By: aaron.ballman, gribozavr

Subscribers: mgorny, xazax.hun, rnkovacs, guansong, jdoerfert, cfe-commits, ABataev

Tags: #clang-tools-extra, #openmp, #clang

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

llvm-svn: 356802
2019-03-22 19:46:25 +00:00
Roman Lebedev cbbf92825f [clang-tidy] openmp-use-default-none - a new check
Summary:
Finds OpenMP directives that are allowed to contain `default` clause,
but either don't specify it, or the clause is specified but with the kind
other than `none`, and suggests to use `default(none)` clause.

Using `default(none)` clause changes the default variable visibility from
being implicitly determined, and thus forces developer to be explicit about the
desired data scoping for each variable.

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

Reviewed By: JonasToth, aaron.ballman

Subscribers: jdoerfert, openmp-commits, klimek, sbenza, arphaman, Eugene.Zelenko, ABataev, mgorny, rnkovacs, guansong, cfe-commits

Tags: #clang-tools-extra, #openmp, #clang

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

llvm-svn: 356801
2019-03-22 19:46:12 +00:00
Roman Lebedev 819bedf3a1 [clang-tidy] A new OpenMP module
Summary:
Just the empty skeleton.
Previously reviewed as part of D57113.

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

Reviewed By: JonasToth, gribozavr

Subscribers: jdoerfert, mgorny, rnkovacs, guansong, arphaman, cfe-commits

Tags: #clang-tools-extra, #openmp, #clang

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

llvm-svn: 356800
2019-03-22 19:46:01 +00:00
Roman Lebedev d5ce57184a [NFC] ExceptionEscapeCheck: small refactoring
Summary:
D59466 wants to analyse the `Stmt`, and `ExceptionEscapeCheck` does not
have that as a possible entry point.
This simplifies addition of `Stmt` analysis entry point.

Reviewers: baloghadamsoftware, JonasToth, gribozavr

Reviewed By: gribozavr

Subscribers: rnkovacs, cfe-commits

Tags: #clang-tools-extra, #clang

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

llvm-svn: 356799
2019-03-22 19:45:51 +00:00
Alexander Kornienko b6c4db9981 [clang-tidy] Move all checks to the new registerPPCallbacks API
llvm-svn: 356796
2019-03-22 18:58:12 +00:00
Alexander Kornienko a0006211e2 [clang-tidy] anyOf(hasName(..), hasName(..)) -> hasAnyName
+ a minor style fix

llvm-svn: 356792
2019-03-22 18:37:45 +00:00
Alexander Kornienko 1ae5c63f35 [clang-tidy] Fix a compiler warning.
Rename the Preprocessor field to fix the

  declaration of ‘std::unique_ptr<clang::Preprocessor> clang::tooling::ExpandModularHeadersPPCallbacks::Preprocessor’ changes the meaning of ‘Preprocessor’ from ‘class clang::Preprocessor’ [-fpermissive]

warning.

llvm-svn: 356756
2019-03-22 15:07:18 +00:00
Alexander Kornienko bbc89dcb29 [clang-tidy] Expand modular headers for PPCallbacks
Summary:
Add a way to expand modular headers for PPCallbacks. Checks can opt-in for this
expansion by overriding the new registerPPCallbacks virtual method and
registering their PPCallbacks in the preprocessor created for this specific
purpose.

Use module expansion in the readability-identifier-naming check

Reviewers: gribozavr, usaxena95, sammccall

Reviewed By: gribozavr

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

Tags: #clang, #clang-tools-extra

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

llvm-svn: 356750
2019-03-22 13:42:48 +00:00
Zinovy Nis 72bb9a65d6 Reland r356547 after fixing the YAML module missing issue.
[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

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

llvm-svn: 356649
2019-03-21 08:32:07 +00:00
Douglas Yung 6452ba4786 Revert "Reland r356547 after fixing the tests for Linux."
This reverts commit 538fb72226 (r356565).

This is still breaking a build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/45557

llvm-svn: 356630
2019-03-20 23:21:43 +00:00
Stephane Moore 5f70c473c9 [clang-tidy] Disable google-runtime-int in Objective-C++ 🔓
Summary:
In contrast to Google C++, Objective-C often uses built-in integer types
other than `int`. In fact, the Objective-C runtime itself defines the
types NSInteger¹ and NSUInteger² which are variant types depending on
the target architecture. The Objective-C style guide indicates that
usage of system types with variant sizes is appropriate when handling
values provided by system interfaces³. Objective-C++ is commonly the
result of conversion from Objective-C to Objective-C++ for the purpose
of integrating C++ functionality. The opposite of Objective-C++ being
used to expose Objective-C functionality to C++ is less common,
potentially because Objective-C has a signficantly more uneven presence
on different platforms compared to C++. This generally predisposes
Objective-C++ to commonly being more Objective-C than C++. Forcing
Objective-C++ developers to perform conversions between variant system types
and fixed size integer types depending on target architecture when
Objective-C++ commonly uses variant system types from Objective-C is
likely to lead to more bugs and overhead than benefit. For that reason,
this change proposes to disable google-runtime-int in Objective-C++.

[1] https://developer.apple.com/documentation/objectivec/nsinteger?language=objc
[2] https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
[3] "Types long, NSInteger, NSUInteger, and CGFloat vary in size between
32- and 64-bit builds. Use of these types is appropriate when handling
values exposed by system interfaces, but they should be avoided for most
other computations."
https://github.com/google/styleguide/blob/gh-pages/objcguide.md#types-with-inconsistent-sizes

Subscribers: xazax.hun, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 356627
2019-03-20 23:05:00 +00:00
Zinovy Nis 538fb72226 Reland r356547 after fixing the tests for Linux.
[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

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

llvm-svn: 356565
2019-03-20 15:50:26 +00:00
Simon Pilgrim 2b70dcd2ef Revert rL356547 : [clang-tidy] Cosmetic fix
Differential Revision: https://reviews.llvm.org/D57662
........
[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D57662
........
Reverted to fix buildbot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/45547/steps/test/logs/stdio

llvm-svn: 356553
2019-03-20 13:24:33 +00:00
Zinovy Nis 4bfe83679d [clang-tidy] Cosmetic fix
Differential Revision: https://reviews.llvm.org/D57662

llvm-svn: 356548
2019-03-20 11:34:29 +00:00
Zinovy Nis d3939d2013 [clang-tidy] Parallelize clang-tidy-diff.py
This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

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

llvm-svn: 356547
2019-03-20 11:30:05 +00:00
Yan Zhang 787a773498 Fixed global constant/variable naming check on C++ class for ObjC++ files.
Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 356220
2019-03-15 00:17:41 +00:00
Hyrum Wright 4199a73cee [clang-tidy] Add additional patterns to the abseil-duration-unnecessary-conversion check.
Differential Revision: https://reviews.llvm.org/D59183

llvm-svn: 356141
2019-03-14 13:38:16 +00:00
Haojian Wu 42810363de [clang-tidy] NOLINT support for "clang-diagnostic-*".
Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

llvm-svn: 355934
2019-03-12 16:11:46 +00:00
Hyrum Wright 1603447b03 [clang-tidy] Add the abseil-time-compare check
This is an analog of the abseil-duration-comparison check, but for the
absl::Time domain. It has a similar implementation and tests.

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

llvm-svn: 355835
2019-03-11 16:47:45 +00:00
Hyrum Wright 8172a0a5f4 [clang-tidy] NFC: Negate the name and semantics of the isNotInMacro function.
This function is always used in a context where its result was also
negated, which made for confusing naming and code.

llvm-svn: 355702
2019-03-08 15:37:15 +00:00
Alexander Kornienko 401997db92 [clang-tidy] Fix bugprone-string-constructor crash
llvm-svn: 355401
2019-03-05 14:09:57 +00:00
Shoaib Meenai 5be71faf4b [build] Rename clang-headers to clang-resource-headers
Summary:
The current install-clang-headers target installs clang's resource
directory headers. This is different from the install-llvm-headers
target, which installs LLVM's API headers. We want to introduce the
corresponding target to clang, and the natural name for that new target
would be install-clang-headers. Rename the existing target to
install-clang-resource-headers to free up the install-clang-headers name
for the new target, following the discussion on cfe-dev [1].

I didn't find any bots on zorg referencing install-clang-headers. I'll
send out another PSA to cfe-dev to accompany this rename.

[1] http://lists.llvm.org/pipermail/cfe-dev/2019-February/061365.html

Reviewers: beanz, phosek, tstellar, rnk, dim, serge-sans-paille

Subscribers: mgorny, javed.absar, jdoerfert, #sanitizers, openmp-commits, lldb-commits, cfe-commits, llvm-commits

Tags: #clang, #sanitizers, #lldb, #openmp, #llvm

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

llvm-svn: 355340
2019-03-04 21:19:53 +00:00
Fangrui Song ffe9f00cfe Fix file headers. NFC
llvm-svn: 355188
2019-03-01 09:52:53 +00:00
Paul Hoad 68f5e5456f [clang-tidy] add OverrideMacro to modernize-use-override check
Summary:
The usefulness of **modernize-use-override** can be reduced if you have to live in an environment where you support multiple compilers, some of which sadly are not yet fully C++11 compliant

some codebases have to use override as a macro OVERRIDE e.g.

```
// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled.
```

This allows code to be compiled with C++11 compliant compilers and get warnings and errors that clang, MSVC,gcc can give, while still allowing other legacy pre C++11 compilers to compile the code. This can be an important step towards modernizing C++ code whilst living in a legacy codebase.

When it comes to clang tidy, the use of the **modernize-use-override** is one of the most useful checks, but the messages reported are inaccurate for that codebase if the standard approach is to use the macros OVERRIDE and/or FINAL.

When combined with fix-its that introduce the C++11 override keyword, they become fatal, resulting in the modernize-use-override check being turned off to prevent the introduction of such errors.

This revision, allows the possibility for the replacement **override **to be a macro instead, Allowing the clang-tidy check to be run on  both pre and post C++11 code, and allowing fix-its to be applied.

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

Reviewed By: alexfh, JonasToth

Subscribers: lewmpk, malcolm.parsons, jdoerfert, xazax.hun, cfe-commits, llvm-commits

Tags: #clang-tools-extra

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

llvm-svn: 355132
2019-02-28 20:00:48 +00:00
Jonas Toth da666233fe [clang-tidy] added cppcoreguidelines-explicit-virtual-functions
Addresses the bugzilla bug #30397. (https://bugs.llvm.org/show_bug.cgi?id=30397)
modernize-use-override suggests that destructors require the override specifier
and the CPP core guidelines do not recommend this.

Patch by lewmpk.

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

llvm-svn: 355093
2019-02-28 14:55:12 +00:00
Clement Courbet 58724a61ac [clang-tidy] bugprone-string-integer-assignment: Reduce false positives.
Summary: Detect a few expressions as likely character expressions, see PR27723.

Reviewers: xazax.hun, alexfh

Subscribers: rnkovacs, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 355089
2019-02-28 13:39:01 +00:00
Clement Courbet ff5e4bcad0 [clang-tidy] misc-string-integer-assignment: fix false positive
Summary:
using CodePoint = uint32_t;
CodePoint cp;
basic_string<CodePoint> s;
s += cp;

See PR27723.

Reviewers: xazax.hun, alexfh

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

llvm-svn: 355076
2019-02-28 10:33:32 +00:00
Hyrum Wright c526e02668 [clang-tidy] Add the abseil-time-subtraction check
Differential Revision: https://reviews.llvm.org/D58137

llvm-svn: 355024
2019-02-27 20:08:50 +00:00
Jonas Toth c1e8cbd5c3 [clang-tidy] undo bitfields in ExceptionAnalyzer
Scoped enums do induce some problems with some MSVC and GCC versions
if used as bitfields. Therefor this is deactivated for now.

llvm-svn: 354903
2019-02-26 18:15:17 +00:00
Clement Courbet 4bfa716f7c [clang-tidy] misc-string-integer-assignment: ignore toupper/tolower
Summary: Tis represents ~20% of false positives. See PR27723.

Reviewers: xazax.hun, alexfh

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

llvm-svn: 354780
2019-02-25 13:09:02 +00:00
Douglas Yung 38dd1b3726 Attempt to fix VS2015 build breakage from r354517. NFCI.
llvm-svn: 354545
2019-02-21 04:55:31 +00:00
Stephane Moore 3eea706e3e [clang-tidy] Make google-objc-function-naming ignore implicit functions 🙈
Summary:
Implicit functions are outside the control of source authors and should
be exempt from style restrictions.

Tested via running clang tools tests.

This is an amended followup to https://reviews.llvm.org/D57207

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: jdoerfert, xazax.hun, cfe-commits

Tags: #clang

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

llvm-svn: 354534
2019-02-21 00:34:01 +00:00
Jonas Toth 32d5b252b9 [clang-tidy] refactor ExceptionAnalyzer further to give ternary answer
Summary:
The analsis on the throwing behvaiour on functions and statements gave only
a binary answer whether an exception could occur and if yes which types are
thrown.
This refactoring allows keeping track if there is a unknown factor, because the
code calls to some functions with unavailable source code with no `noexcept`
information.
This 'potential Unknown' information is propagated properly and can be queried
separately.

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

Reviewed By: lebedev.ri, baloghadamsoftware

Subscribers: xazax.hun, rnkovacs, a.sidorin, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 354517
2019-02-20 21:04:36 +00:00
Yan Zhang 19bceda879 Update property prefix regex to allow numbers.
Subscribers: jfb, cfe-commits

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

llvm-svn: 354485
2019-02-20 17:32:41 +00:00
Bruno Ricci b73b5cda62 [clang-tidy][NFCI] DanglingHandleCheck: Remove a superflous IgnoreParenImpCasts
ExprWithCleanups is currently not skipped by IgnoreParenImpCasts, but is skipped
by IgnoreImpCasts. In view of fixing this inconsistency in D57267, remove the
IgnoreParenImpCasts between the ReturnStmt and the ExprWithCleanups which
is not needed since ExprWithCleanups is always created as a direct child of
ReturnStmt (by inspection of each ReturnStmt::Create in Sema/SemaStmt.cpp).

NFC intended.

llvm-svn: 354228
2019-02-17 18:21:54 +00:00
Stephane Moore 358f99c7fe [clang-tidy] Delete obsolete objc-property-declaration options ✂️
Summary:
The Acronyms and IncludeDefaultAcronyms options were deprecated in
https://reviews.llvm.org/D51832. These options can be removed.

Tested by running the clang-tidy tests.

This is an amended resubmission of https://reviews.llvm.org/D56945.

Reviewers: Eugene.Zelenko, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

llvm-svn: 354195
2019-02-16 04:27:12 +00:00
Malcolm Parsons 297b6a2b6e [clang-tidy] Don't use assignment for value-initialized enums
Summary:
The modernize-use-default-member-init check crashes when trying to
create an assignment value for a value-initialized enum because it isn't a
BuiltinType.
An enum cannot be initialized by assigning 0 to it unless a cast is added.
It could be initialized with an enumerator with the value 0, but there might not
be one.
Avoid these issues by ignoring the UseAssignment setting for value-initialized
enums.

Fixes PR35050.

Reviewers: aaron.ballman, alexfh, JonasToth

Reviewed By: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

llvm-svn: 353554
2019-02-08 19:44:42 +00:00
Paul Hoad 6bfd721571 [clang-tidy] Add options to bugprone-argument-comment to add missing argument comments to literals
bugprone-argument-comment only supports identifying those comments which do not match the function parameter name

This revision add 3 options to adding missing argument comments to literals (granularity on type is added to control verbosity of fixit)

```
CheckOptions:
  - key:             bugprone-argument-comment.CommentBoolLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentFloatLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentIntegerLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentStringLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentCharacterLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentUserDefinedLiterals
    value:           '1'
  - key:             bugprone-argument-comment.CommentNullPtrs
    value:           '1'
```

After applying these options, literal arguments will be preceded with /*ParameterName=*/

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

Reviewed By: aaron.ballman, Eugene.Zelenko

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

llvm-svn: 353535
2019-02-08 17:00:01 +00:00
Yitzhak Mandelbaum f6be5573dc [clang-tidy][NFC] Fix typo.
Fix placement of comma from previous (test) commit.

llvm-svn: 353525
2019-02-08 15:05:57 +00:00
Yitzhak Mandelbaum 01d6bfc94d [clang-tidy][NFC] Test commit. Add missing comma.
llvm-svn: 353523
2019-02-08 14:57:22 +00:00
Jonas Toth a822b1155e [clang-tidy] Fixed a std::bind() transformation
There was an extra semicolon that was somehow working in some contexts.

Patch by oleg.smolsky.

llvm-svn: 353389
2019-02-07 11:00:59 +00:00