Commit Graph

1508 Commits

Author SHA1 Message Date
Jonas Toth 9b127421b6 [clang-tidy] refactor bugprone-exception-escape analysis into class
Summary:
The check `bugprone-exception-escape` does an AST-based analysis to determine
if a function might throw an exception and warns based on that information.
The analysis part is refactored into a standalone class similiar to
`ExprMutAnalyzer` that is generally useful.
I intent to use that class in a new check to automatically introduce `noexcept`
if possible.

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

Reviewed By: baloghadamsoftware, lebedev.ri

Subscribers: lebedev.ri, mgorny, xazax.hun, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 352741
2019-01-31 10:46:37 +00:00
Haojian Wu f02e9f3783 [clang-tidy] Fix a build error.
llvm-svn: 352364
2019-01-28 14:07:45 +00:00
Hyrum Wright 722191be25 [clang-tidy] Add the abseil-duration-addition check
Differential Revision: https://reviews.llvm.org/D57185

llvm-svn: 352362
2019-01-28 14:03:09 +00:00
Haojian Wu c67dab5bd0 [clang-tidy] Add check for underscores in googletest names.
Summary: Adds a clang-tidy warning for underscores in googletest names.

Patch by Kar Epker!

Reviewers: hokein, alexfh, aaron.ballman

Reviewed By: hokein

Subscribers: Eugene.Zelenko, JonasToth, MyDeveloperDay, lebedev.ri, xazax.hun, mgorny, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 352183
2019-01-25 10:03:49 +00:00
Hyrum Wright 1ec465dbfd [clang-tidy] Rename the absl duration helper functions; NFC
llvm-svn: 352088
2019-01-24 19:23:50 +00:00
Stephane Moore 05a449b481 Revert rCTE351921 to fix documentation geneeration.
Original review: https://reviews.llvm.org/D56945

llvm-svn: 351922
2019-01-23 02:58:59 +00:00
Stephane Moore be9eca442e [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.

Reviewers: benhamilton, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 351921
2019-01-23 02:34:21 +00:00
Alexander Kornienko efde822cd1 [clang-tidy] Work around http://llvm.org/PR40392
The readability-else-after-return check should be smarter about cases where the
variable defined in the condition is used in the `else` branch. This patch makes
it just ignore such cases, but alternative solutions may be better (added a
FIXME).

llvm-svn: 351751
2019-01-21 16:26:54 +00:00
Kadir Cetinkaya fd29980f09 [clang-tidy] Use getStripPluginsAdjuster
Summary: See rC351531 for the introduction of getStripPluginsAdjuster.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 351738
2019-01-21 10:10:18 +00:00
Miklos Vajna 61c818f253 [clang-tidy] misc-non-private-member-variables-in-classes: ignore implicit methods
Otherwise we don't warn on a struct containing a single public int, but
we warn on a struct containing a single public std::string, which is
inconsistent.

llvm-svn: 351686
2019-01-20 14:28:27 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Chandler Carruth 4a50956c07 Convert two more files that were using Windows line endings and remove
a stray single '\r' from one file. These are the last line ending issues
I can find in the files containing parts of LLVM's file headers.

llvm-svn: 351634
2019-01-19 06:36:08 +00:00
Chandler Carruth 469bdefd44 Install new LLVM license structure and new developer policy.
This installs the new developer policy and moves all of the license
files across all LLVM projects in the monorepo to the new license
structure. The remaining projects will be moved independently.

Note that I've left odd formatting and other idiosyncracies of the
legacy license structure text alone to make the diff easier to read.
Critically, note that we do not in any case *remove* the old license
notice or terms, as that remains necessary until we finish the
relicensing process.

I've updated a few license files that refer to the LLVM license to
instead simply refer generically to whatever license the LLVM project is
under, basically trying to minimize confusion.

This is really the culmination of so many people. Chris led the
community discussions, drafted the policy update and organized the
multi-year string of meeting between lawyers across the community to
figure out the strategy. Numerous lawyers at companies in the community
spent their time figuring out initial answers, and then the Foundation's
lawyer Heather Meeker has done *so* much to help refine and get us ready
here. I could keep going on, but I just want to make sure everyone
realizes what a huge community effort this has been from the begining.

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

llvm-svn: 351631
2019-01-19 06:14:24 +00:00
Hyrum Wright b60de17b51 [clang-tidy] Add abseil-duration-conversion-cast check
Differential Revision: https://reviews.llvm.org/D56532

llvm-svn: 351473
2019-01-17 20:37:35 +00:00
Hyrum Wright 56de30fd4b [clang-tidy] Move the macro helper function to a common location; NFC
This is useful for multiple checks.

llvm-svn: 351348
2019-01-16 14:49:32 +00:00
Clement Courbet ae814fcb4c [clang-tidy] bugprone-string-constructor: Catch string from nullptr.
Summary: Context: https://twitter.com/willkirkby/status/1084219580799741953

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 351308
2019-01-16 08:36:23 +00:00
Sam McCall 5a8e6afff2 [clang-tidy] Avoid fuchsia-overloaded-operator false positive with lambdas after r351047
llvm-svn: 351307
2019-01-16 08:29:54 +00:00
Martin Bohme c4db59c63c [clang-tidy] Treat references to smart pointers correctly in use-after-move.
Summary:
Previously, we weren't recognizing these as smart pointers and thus
weren't allowing non-dereference accesses as we should -- see new test
cases which fail without the fix.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 351303
2019-01-16 07:53:25 +00:00
Sam McCall d37be4b779 [clang-tidy] update FunctionSizeCheck for D56444
Reviewers: JonasToth, aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 351048
2019-01-14 10:40:41 +00:00
Miklos Vajna 98ef5337c9 [clang-tidy] new check 'readability-redundant-preprocessor'
Finds potentially redundant preprocessor directives.

Reviewed By: aaron.ballman

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

llvm-svn: 350922
2019-01-11 07:59:47 +00:00
Brian Gesiak eb139def3d Adapt to CXXMethodDecl::getThisType change (NFC)
Summary:
https://reviews.llvm.org/D56509 changed the API of the
CXXMethodDecl::getThisType method. Adapt to the change (and re-apply
clang-format) to fix the clang-tidy build.

llvm-svn: 350916
2019-01-11 02:12:31 +00:00
Jonas Toth 6a9f831ffd [clang-tidy] Fix case of local variables in modernize-use-nodiscard checker
Summary:
Correct the case of the local variables..

Rational:
I want to be able to run clang-tidy on new clang-tidy checker code prior to creating a review (to demonstrate we should dog food our own tools during development, not my suggestion but @Eugene.Zelenko)

To this end I am running the following in a script, prior to make a change.

```
tidy:
    @for source in $$(git status -suno | grep ".cpp$$" | cut -c4-) ;\
    do \
        clang-tidy -quiet  $$source -- $(TIDY_FLAGS);\
    done

```

I then want to go through the checkers and see which checkers most closely match the review style of the reviewers

```
---
Checks:          '
-clang-diagnostic-*,
readability-identifier-naming,
llvm-header-guard
'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle:     LLVM
CheckOptions:
  - key:             readability-identifier-naming.IgnoreFailedSplit
    value:           '0'
  - key:             readability-identifier-naming.VariableCase
    value:           'CamelCase'
  - key:             readability-identifier-naming.LocalVariableCase
    value:           'CamelCase'
...

```

Unfortunately in doing so, I have identified that my previous review {D55433} it violates what looks like to be the convention of local variables being in CamelCase.

Sending this small review in the hope it can be corrected.

Patch by MyDeveloperDay.

Reviewers: JonasToth, Eugene.Zelenko

Reviewed By: JonasToth

Subscribers: xazax.hun, Eugene.Zelenko

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

llvm-svn: 350814
2019-01-10 11:56:44 +00:00
Jonas Toth ca8e20cdf7 [clang-tidy] Adding a new modernize use nodiscard checker
Summary: Adds a checker to clang-tidy to warn when a non void const member function, taking only parameters passed by value or const reference could be marked as '[[nodiscard]]'

Patch by MyDeveloperDay.

Reviewers: alexfh, stephenkelly, curdeius, aaron.ballman, hokein, JonasToth

Reviewed By: curdeius, JonasToth

Subscribers: Eugene.Zelenko, lefticus, lebedev.ri, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 350760
2019-01-09 20:50:50 +00:00
Hyrum Wright 1bec67f605 [clang-tidy] Use the public hasInit matcher, rather than defining our own, NFC
llvm-svn: 350526
2019-01-07 14:36:47 +00:00
Hyrum Wright 4ce05801c7 [clang-tidy] Export the abseil duration inverse lookup function, NFC
This allows other tools to use this function.

llvm-svn: 350133
2018-12-28 19:04:21 +00:00
Miklos Vajna 7fb1c2a6ca [clang-tidy] add IgnoreMacros option to readability-uppercase-literal-suffix
And also enable it by default to be consistent with e.g.
modernize-use-using.

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

Reviewed By: JonasToth, lebedev.ri

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

llvm-svn: 350056
2018-12-24 17:47:32 +00:00
Hyrum Wright 9fc3a5f438 [clang-tidy] Be more liberal about literal zeroes in abseil checks
Summary:
Previously, we'd only match on literal floating or integral zeroes, but I've now also learned that some users spell that value as int{0} or float{0}, which also need to be matched.

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

llvm-svn: 349953
2018-12-21 21:07:11 +00:00
Julie Hockett e2e73b221b [clang-tidy] Add export-fixes flag to clang-tidy-diff
Differential Revision: https://reviews.llvm.org/D55848

llvm-svn: 349930
2018-12-21 17:25:27 +00:00
Bjorn Pettersson f069f1c288 Fix warning about unused variable [NFC]
llvm-svn: 349891
2018-12-21 08:51:04 +00:00
Alexander Kornienko 14706b9687 [clang-tidy] Use translationUnitDecl() instead of a custom matcher.
llvm-svn: 349758
2018-12-20 13:50:04 +00:00
Hyrum Wright 06a8febe76 [clang-tidy] Diagnose abseil-duration-comparison on macro arguments
Summary:
This change relaxes the requirements on the utility
`rewriteExprFromNumberToDuration` function, and introduces new checking
inside of the `abseil-duration-comparison` check to allow macro argument
expression transformation.

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

llvm-svn: 349636
2018-12-19 16:03:34 +00:00
Haojian Wu 530108cb5c [clang-tidy] use "const SourceManager&" parameter, NFC.
llvm-svn: 349623
2018-12-19 13:25:08 +00:00
Ivan Donchevskii 13c9c05441 [clang-tidy] Remove extra config.h includes
It's included in a new header ClangTidyForceLinker.h and should not
be included the second time.

Follow up for the https://reviews.llvm.org/D55595

llvm-svn: 349132
2018-12-14 07:44:52 +00:00
Ivan Donchevskii 37512e58ba [clang-tidy] Share the forced linking code between clang-tidy tool and plugin
Extract code that forces linking to the separate header and include it in both plugin and standalone tool.
Try 2: missing header guard and "clang/Config/config.h" are added to the new header.

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

llvm-svn: 349131
2018-12-14 07:29:06 +00:00
Stephane Moore b69ece899d [clang-tidy] Improve google-objc-function-naming diagnostics 📙
Summary:
The diagnostics from google-objc-function-naming check will be more
actionable if they provide a brief description of the requirements from
the Google Objective-C style guide. The more descriptive diagnostics may
help clarify that functions in the global namespace must have an
appropriate prefix followed by Pascal case (engineers working previously
with static functions might not immediately understand the different
requirements of static and non-static functions).

Test Notes:
Verified against the clang-tidy tests.

Reviewers: benhamilton, aaron.ballman

Reviewed By: benhamilton

Subscribers: MyDeveloperDay, xazax.hun, cfe-commits

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

llvm-svn: 349123
2018-12-14 03:13:31 +00:00
Douglas Yung 29bfeb97d4 Revert "[clang-tidy] Share the forced linking code between clang-tidy tool and plugin"
This reverts commit r349038 as it was causing test failures:

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/22185
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/40886

llvm-svn: 349121
2018-12-14 02:04:04 +00:00
Hyrum Wright 35cb7e9fe8 [clang-tidy] Add the abseil-duration-subtraction check
Summary:
This check uses the context of a subtraction expression as well as knowledge
about the Abseil Time types, to infer the type of the second operand of some
subtraction expressions in Duration conversions. For example:

   absl::ToDoubleSeconds(duration) - foo

can become
   absl::ToDoubleSeconds(duration - absl::Seconds(foo))

This ensures that time calculations are done in the proper domain, and also
makes it easier to further deduce the types of the second operands to these
expressions.

Reviewed By: JonasToth

Tags: #clang-tools-extra

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

llvm-svn: 349073
2018-12-13 19:23:52 +00:00
Ivan Donchevskii e74d487be8 [clang-tidy] Share the forced linking code between clang-tidy tool and plugin
Extract code that forces linking to the separate header and include it in both plugin and standalone tool

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

llvm-svn: 349038
2018-12-13 14:37:17 +00:00
Fangrui Song 41c249adc4 Add explicit dependency on clangSerialization after rC348911
llvm-svn: 348916
2018-12-12 08:25:16 +00:00
Jonas Toth 4b59a1fe29 Use the standard Duration factory matcher
Summary: A new check came in over the weekend; it should use our existing infrastructure for matching `absl::Duration` factories.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Subscribers: astrelni

Tags: #clang-tools-extra

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

llvm-svn: 348842
2018-12-11 12:45:51 +00:00
Jonas Toth e740145e19 [clang-tidy] insert release notes for new checkers alphabetically
Summary:
Almost all code review comments on new checkers {D55433} {D48866} {D54349} seem to ask for the release notes to be added alphabetically, plus I've seen commits by @Eugene.Zelenko reordering the lists

Make add_new_check.py add those release notes alphabetically based on checker name

If include-fixer section is seen add it at the end

Minor change in the message format to prevent double newlines added before the checker.

Do the tools themselves have unit tests? (sorry new to this game)

- Tested adding new checker at the beginning
- Tested on adding new checker in the middle
- Tested on empty ReleasesNotes.rst (as we would see after RC)

Patch by MyDeveloperDay.

Reviewers: alexfh, JonasToth, curdeius, aaron.ballman, benhamilton, hokein

Reviewed By: JonasToth

Subscribers: cfe-commits, xazax.hun, Eugene.Zelenko

Tags: #clang-tools-extra

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

llvm-svn: 348793
2018-12-10 19:41:53 +00:00
Eric Fiselier 2bbbd8be24 [clang-tidy]: Abseil: new check 'abseil-upgrade-duration-conversions'
Patch by Alex Strelnikov.
Reviewed as D53830

Introduce a new check to upgrade user code based on upcoming API breaking changes to absl::Duration.

The check finds calls to arithmetic operators and factory functions for absl::Duration that rely on
an implicit user defined conversion to int64_t. These cases will no longer compile after proposed
changes are released. Suggested fixes explicitly cast the argument int64_t.

llvm-svn: 348633
2018-12-07 20:03:03 +00:00
Haojian Wu 75f6caddab [clang-tidy] Remove duplicated getText implementation, NFC
llvm-svn: 348583
2018-12-07 11:25:37 +00:00
Jonas Toth 71a29aa947 Revert "[clang-tidy] new check: bugprone-branch-clone"
The patch broke on buildbot with assertion-failure. Revert until this
is figured out.

llvm-svn: 348344
2018-12-05 09:34:18 +00:00
Jonas Toth cd207f1552 [clang-tidy] new check: bugprone-branch-clone
Summary:
Implement a check for detecting if/else if/else chains where two or more
branches are Type I clones of each other (that is, they contain identical code)
and for detecting switch statements where two or more consecutive branches are
Type I clones of each other.

Patch by donat.nagy.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: JonasToth

Subscribers: MTC, lebedev.ri, whisperity, xazax.hun, Eugene.Zelenko, mgorny, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 348343
2018-12-05 09:16:25 +00:00
Jonas Toth c361e0d627 Fix a false positive in misplaced-widening-cast
Summary:
bugprone-misplaced-widening-cast check
used to give a false warning to the
following example.

 enum DaysEnum{
    MON = 0,
    TUE = 1
    };

 day = (DaysEnum)(day + 1);
 //warning: either cast from 'int' to 'DaysEnum' is ineffective...

But i think int to enum cast is not widening neither ineffective.

Patch by dkrupp.

Reviewers: JonasToth, alexfh

Reviewed By: alexfh

Subscribers: rnkovacs, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 348341
2018-12-05 08:29:56 +00:00
Stephane Moore af4755aca8 [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms 🔧
Summary:
§1 Description

This changes the objc-property-declaration check to allow arbitrary acronyms and initialisms instead of using whitelisted acronyms. In Objective-C it is relatively common to use project prefixes in property names for the purposes of disambiguation. For example, the CIColor¹ and CGColor² properties on UIColor both represent symbol prefixes being used in proeprty names outside of Apple's accepted acronyms³. The union of Apple's accepted acronyms and all symbol prefixes that might be used for disambiguation in property declarations effectively allows for any arbitrary sequence of capital alphanumeric characters to be acceptable in property declarations. This change updates the check accordingly.

The test variants with custom configurations are deleted as part of this change because their configurations no longer impact behavior. The acronym configurations are currently preserved for backwards compatibility of check configuration.

[1] https://developer.apple.com/documentation/uikit/uicolor/1621951-cicolor?language=objc
[2] https://developer.apple.com/documentation/uikit/uicolor/1621954-cgcolor?language=objc
[3] https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE

§2 Test Notes

Changes verified by:
• Running clang-tidy unit tests.
• Used check_clang_tidy.py to verify expected output of processing objc-property-declaration.m

Reviewers: benhamilton, Wizard

Reviewed By: benhamilton

Subscribers: jfb, cfe-commits

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

llvm-svn: 348331
2018-12-05 03:44:03 +00:00
Stephane Moore f6d96e0f98 [clang-tidy] Ignore namespaced and C++ member functions in google-objc-function-naming check 🙈
Summary: The google-objc-function-naming check applies to functions that are not namespaced and should not be applied to C++ member functions. Such function declarations should be ignored by the check to avoid false positives in Objective-C++ sources.

Reviewers: benhamilton, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 348317
2018-12-04 23:40:42 +00:00
Jonas Toth 3f51ee19ae [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so
llvm-svn: 348172
2018-12-03 19:41:04 +00:00
Jonas Toth 00f1d76738 [clang-tidy] Recommit: Add the abseil-duration-comparison check
Summary:
This check finds instances where Duration values are being converted to a numeric value in a comparison expression, and suggests that the conversion happen on the other side of the expression to a Duration.  See documentation for examples.

This also shuffles some code around so that the new check may perform in sone step simplifications also caught by other checks.
Compilation is unbroken, because the hash-function is now directly
specified for std::unordered_map, as 'enum class' does not compile as
key (seamingly only on some compilers).

Patch by hwright.

Reviewers: aaron.ballman, JonasToth, alexfh, hokein

Reviewed By: JonasToth

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

Tags: #clang-tools-extra

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

llvm-svn: 348169
2018-12-03 19:22:08 +00:00