Commit Graph

1146 Commits

Author SHA1 Message Date
Gabor Horvath ec87e17c84 [clang-tidy] Misc redundant expressions checker updated for macros
Redundant Expression Checker is updated to be able to detect expressions that
contain macros. Also, other small details are modified to improve the current
implementation.

The improvements in detail are as follows:
* Binary and ternary operator expressions containing two constants, with at
least one of them from a macro, are detected and tested for redundancy.

Macro expressions are treated somewhat differently from other expressions,
because the particular values of macros can vary across builds.
They can be considered correct and intentional, even if macro values equal,
produce ranges that exclude each other or fully overlap, etc. 

* The code structure is slightly modified: typos are corrected,
comments are added and some functions are renamed to improve comprehensibility,
both in the checker and the test file. A few test cases are moved to another
function.

* The checker is now able to detect redundant CXXFunctionalCastExprs as well.
A corresponding test case is added.

Patch by: Lilla Barancsuk!

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

llvm-svn: 317570
2017-11-07 13:17:58 +00:00
Haojian Wu 5529a244e1 Add new check in google module for Objective-C code to ensure global variables follow the naming convention of Google Objective-C Style Guide
Summary:
This is a new checker for objc files in clang-tidy.

The new check finds global variable declarations in Objective-C files that are not follow the pattern of variable names in Google's Objective-C Style Guide.

All the global variables should follow the pattern of "g[A-Z].*" (variables) or "k[A-Z].*" (constants). The check will suggest a variable name that follows the pattern
if it can be inferred from the original name.

Patch by Yan Zhang!

Reviewers: benhamilton, hokein, alexfh

Reviewed By: hokein

Subscribers: Eugene.Zelenko, mgorny

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

llvm-svn: 317552
2017-11-07 08:53:37 +00:00
Gabor Horvath 8de900ae1f [clang-tidy] Support relative paths in run-clang-tidy.py
Unfortunately, these python scripts are not tested currently. I did the testing
manually on LLVM by editing the CMake generated compilation database to
contain relative paths for some of the files. 

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

llvm-svn: 317468
2017-11-06 10:36:02 +00:00
Shoaib Meenai 09d4efee52 [clang-tidy] Clean up installation rules
An installation rule for the executable with the correct component is
already created by `add_clang_tool`, so the rule in this file is
redundant. Correct the installation component for the Python scripts so
that they also get installed by `install-clang-tidy`.

llvm-svn: 317155
2017-11-02 01:48:20 +00:00
Jonas Toth 8ba28c7200 [clang-tidy] Fix bug 34845, offending standard bitmask types
Summary:
The C++ standard allows implementations to choose the underlying type for
bitmask types (e.g. std::ios_base::openmode). MSVC implemented some of them
as signed integers resulting in warnings for usual code like
`auto dd = std::ios_base::badbit | std::ios_base::failbit;`

These false positives were reported in https://bugs.llvm.org/show_bug.cgi?id=34845

The fix allows bitwise |,&,^ for known standard bitmask types under the condition
that both operands are such bitmask types.
Shifting and bitwise complement are still forbidden.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun

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

llvm-svn: 316767
2017-10-27 14:44:08 +00:00
Haojian Wu e010406e28 [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing
Summary:
This is part 3 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This adds a new clang-tidy check `objc-forbidden-subclassing` which
ensures clients do not create subclasses of Objective-C classes which
are not designed to be subclassed.

(Note that for code under your control, you should use
__attribute__((objc_subclassing_restricted)) instead -- this
is intended for third-party APIs which cannot be modified.)

By default, the following classes (which are publicly documented
as not supporting subclassing) are forbidden from subclassing:

ABNewPersonViewController
ABPeoplePickerNavigationController
ABPersonViewController
ABUnknownPersonViewController
NSHashTable
NSMapTable
NSPointerArray
NSPointerFunctions
NSTimer
UIActionSheet
UIAlertView
UIImagePickerController
UITextInputMode
UIWebView

Clients can set a CheckOption
`objc-forbidden-subclassing.ClassNames` to a semicolon-separated
list of class names, which overrides this list.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun

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

llvm-svn: 316744
2017-10-27 07:41:36 +00:00
Haojian Wu abcd64ccbf [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks
Summary:
This is part 1 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This introduces a new clang-tidy module, `objc`, specifically for
Objective-C / Objective-C++ checks.

The module is currently empty; D39142 adds the first check.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard, mgorny

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

llvm-svn: 316643
2017-10-26 08:23:20 +00:00
NAKAMURA Takumi f793fa3335 clang-tidy: Fix deps.
llvm-svn: 316260
2017-10-21 11:02:30 +00:00
Zachary Turner fbdca1daec [clang-tidy] Don't error on MS-style inline assembly.
To get MS-style inline assembly, we need to link in the various
backends.  Some other clang tools already do this, and this issue
has been raised with clang-tidy several times, indicating there
is sufficient desire to make this work.

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

llvm-svn: 316246
2017-10-20 23:00:51 +00:00
Jonas Toth c9aea86e6a [clang-tidy] introduce legacy resource functions to 'cppcoreguidelines-owning-memory'
Summary:
This patch introduces support for legacy C-style resource functions that must obey
the 'owner<>' semantics.

- added legacy creators like malloc,fopen,...
- added legacy consumers like free,fclose,...

This helps codes that mostly benefit from owner:
Legacy, C-Style code that isn't feasable to port directly to RAII but needs a step in between
to identify actual resource management and just using the resources.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton

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

llvm-svn: 316092
2017-10-18 16:14:15 +00:00
Alexander Kornienko 5d62569b04 Revert "Fix nested namespaces in google-readability-nested-namespace-comments."
This reverts r315057. The revision introduces assertion failures:
assertion failed at llvm/tools/clang/include/clang/Basic/SourceManager.h:428 in
const clang::SrcMgr::ExpansionInfo &clang::SrcMgr::SLocEntry::getExpansion()
const: isExpansion() && "Not a macro expansion SLocEntry!"
Stack trace:
    __assert_fail
    clang::SrcMgr::SLocEntry::getExpansion()
    clang::SourceManager::getExpansionLocSlowCase()
    clang::SourceManager::getExpansionLoc()
    clang::Lexer::getRawToken()
    clang::tidy::readability::NamespaceCommentCheck::check()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch()
    clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchDispatch()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::ast_matchers::MatchFinder::matchAST()
    clang::MultiplexConsumer::HandleTranslationUnit()
    clang::ParseAST()
    clang::FrontendAction::Execute()
    clang::CompilerInstance::ExecuteAction()
    clang::tooling::FrontendActionFactory::runInvocation()
    clang::tooling::ToolInvocation::runInvocation()
    clang::tooling::ToolInvocation::run()

Still working on an isolated test case.

llvm-svn: 315580
2017-10-12 14:25:16 +00:00
Benjamin Kramer 252dd8b745 [clang-tidy] Use a more efficient map for the virtual near miss check.
DenseMap performs better here. No functionality change intended.

llvm-svn: 315277
2017-10-10 07:21:51 +00:00
Aaron Ballman 9549c1180f Fix nested namespaces in google-readability-nested-namespace-comments.
Fixes PR34701.

Patch by Alexandru Octavian Buțiu.

llvm-svn: 315057
2017-10-06 12:57:28 +00:00
Jonas Toth 5a09996ff7 [clang-tidy] Emit note for variable declaration that are later deleted
This patch introduces a note for variable declaration that are later deleted.
Adds FIXME notes for possible automatic type-rewriting positions as well.

Reviewed by aaron.ballman
Differential: https://reviews.llvm.org/D38411

llvm-svn: 314913
2017-10-04 16:49:20 +00:00
Jonas Toth c1f906c134 [clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise
The bug happened with stream operations, that were not recognized in all cases.
Even there were already existing test for streaming classes, they did not catch this bug.
Adding the isolated example to the existing tests did not trigger the bug.
Therefore i created a new isolated file that did expose the bug indeed.

Differential: https://reviews.llvm.org/D38399
reviewed by aaron.ballman

llvm-svn: 314808
2017-10-03 16:25:01 +00:00
Richard Smith 2ccecb9d88 Fix up clang-tidy after clang r314037.
llvm-svn: 314047
2017-09-22 23:47:20 +00:00
Alexander Kornienko 7b9f3e28cc [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34449

**Problem:**

Clang-tidy check misc-unused-parameters comments out parameter name omitting following characters (e.g. square brackets) what results in its complete removal. Compilation errors might occur after clang-tidy fix as well.

**Patch description:**

Changed removal range. The range should end after parameter name, not after whole parameter declarator (which might be followed by e.g. square brackets).

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Pawel Maciocha!

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

llvm-svn: 313355
2017-09-15 11:28:28 +00:00
Alexander Kornienko e5590927d6 [clang-tidy] fixed misc-unused-parameters omitting parameters default value
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34450

**Problem:**

Clang-tidy check misc-unused-parameters omits parameter default value what results in its complete removal. Compilation errors might occur after clang-tidy fix.

**Patch description:**

Changed removal range. The range should end after parameter declarator, not after whole parameter declaration (which might contain a default value).

Reviewers: alexfh, xazax.hun

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

Tags: #clang-tools-extra

Patch by Pawel Maciocha!

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

llvm-svn: 313150
2017-09-13 14:55:13 +00:00
Jonas Toth 6ccc1c342a [clang-tidy] Implement type-based check for `gsl::owner`
This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template <typename T> 
void f(T t) { delete t; }
// ...
f(gsl::owner<int*>(new int(42)));
```
Will created false positive (the deletion is problematic), since the type deduction
removes the wrapping `typeAlias`.

Codereview in D36354

llvm-svn: 313067
2017-09-12 20:00:42 +00:00
Jonas Toth 8bfdc0b1cc [clang-tidy] Revert Implement type-based check for gsl::owner
This should unbreak the buildbot for visual studio 2015 for now.

llvm-svn: 313059
2017-09-12 18:35:54 +00:00
Jonas Toth a5d53274f3 [clang-tidy] Implement type-based check for `gsl::owner`
This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template <typename T> 
void f(T t) { delete t; }
// ...
f(gsl::owner<int*>(new int(42)));
```
Will created false positive (the deletion is problematic), since the type deduction
removes the wrapping `typeAlias`.

Please give your comments :)

llvm-svn: 313043
2017-09-12 16:20:51 +00:00
Peter Szecsi 2087113f6c [clang-tidy] SuspiciousEnumUsageCheck bugfix
iThere is a reported bug on the checker not handling the some APSInt values
correctly: https://bugs.llvm.org/show_bug.cgi?id=34400

This patch aims to fix it.

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

llvm-svn: 313016
2017-09-12 09:40:13 +00:00
Roman Lebedev 728284dc39 [clang-tidy] FunctionSizeCheck: wrap FunctionASTVisitor into anon namespace, NFC
This check is relatively simple, and is often being used
as an example. I'm aware of at least two cases, when
simply copying the FunctionASTVisitor class to a new
check resulted in a rather unobvious segfault. Having it
in anonymous namespace prevents such a problem.

No functionality change, so i opted to avoid phabricator,
especially since clang-tidy reviews are seriously jammed.

llvm-svn: 312912
2017-09-11 13:12:31 +00:00
Jonas Toth a735803801 [clang-tidy] add more aliases for the hicpp module
This patch will introduce even more aliases for the hicpp-module to already existing
checks and is a follow up for D30383 finishing the other sections.
It fixes a forgotten highlight in hicpp-braces-around-statements.rst, too.

llvm-svn: 312901
2017-09-11 09:20:07 +00:00
Rafael Espindola d63b2f3996 Update for PrintHelpMessage not calling exit.
llvm-svn: 312769
2017-09-08 00:33:39 +00:00
Kevin Funk d331cb66f9 Make run-clang-tidy compatible with Python 3.x
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, JDevlieghere

Tags: #clang-tools-extra

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

Change-Id: I89a95d1e082e566e7e64c2a5ca4123c543e6b1be
llvm-svn: 312532
2017-09-05 12:36:33 +00:00
Benjamin Kramer 6be49244b1 [cppcoreguidelines] Don't rely on SmallPtrSet iteration order.
The fixit emission breaks if the iteration order changes and also missed
to emit fixits for some edge cases.

llvm-svn: 312166
2017-08-30 20:18:40 +00:00
Jonas Toth 673dbd1aff [clang-tidy] Improve hicpp-exception-baseclass to handle generic code better
Summary:
This patch is a followup to the first revision D36583, that had problems with 
generic code and its diagnostic messages, which were found by @lebedev.ri

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

Reviewed By: aaron.ballman, lebedev.ri

Subscribers: klimek, sbenza, cfe-commits, JDevlieghere, lebedev.ri, xazax.hun

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

llvm-svn: 312134
2017-08-30 15:59:01 +00:00
Jonas Toth a8c34530df [clang-tidy] hicpp bitwise operations on signed integers
Summary:
This check implements the rule [[ http://www.codingstandard.com/section/5-6-shift-operators/ | 5.6. HIC++ ]]
that forbidds bitwise operations on signed integer types.

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

Reviewed By: aaron.ballman

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

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

llvm-svn: 312122
2017-08-30 13:32:05 +00:00
Jonas Toth a88abd58b4 [clang-tidy] test commit for granted access
llvm-svn: 312102
2017-08-30 07:50:28 +00:00
Daniel Marjamaki cad8443724 [clang-tidy] Fix 'misc-misplaced-widening-cast' assertion error.
Reviewers: alexfh, xazax.hun, danielmarjamaki

Differential Revision: http://reviews.llvm.org/D36670

llvm-svn: 311984
2017-08-29 06:25:24 +00:00
Haojian Wu 3f495944de [clang-tidy] A follow-up fix of braced-init-list constructors in make-unique check.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311652
2017-08-24 13:35:55 +00:00
Alexander Kornienko 15ea4ebbb2 [clang-tidy] bugprone-undefined-memory-manipulation: include type into the message
Having the actual type in the message helps a lot understanding warnings in templates ;)

+ fix a false negative for type aliases.

llvm-svn: 311651
2017-08-24 12:11:05 +00:00
Alexander Kornienko dea43983ae [clang-tidy] Add modernize-use-equals-default.IgnoreMacros option
llvm-svn: 311136
2017-08-17 23:07:59 +00:00
Haojian Wu 80330ffc6b [clang-tidy] Ignore statements inside a template instantiation.
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311086
2017-08-17 14:12:38 +00:00
Haojian Wu 4b956cb70d [clang-tidy] Don't generate fixes for initializer_list constructor in make_unique check.
Summary:
The current fix will break the compilation -- because braced list is not
deducible in std::make_unique (with the use of forwarding) without
specifying the type explicitly.

We could support it in the future.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 311078
2017-08-17 10:14:52 +00:00
Chih-Hung Hsieh 2414429962 [clang-tidy] Remove unused static variable.
Differential Revision: https://reviews.llvm.org/D36761

llvm-svn: 311040
2017-08-16 21:00:06 +00:00
Chih-Hung Hsieh a54d379812 [clang-tidy] Use const char* to compile with VC cl.exe.
Summary:
cl.exe does not accept constexpr char FuncBindingStr[] = ...

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

llvm-svn: 311035
2017-08-16 19:13:35 +00:00
Chih-Hung Hsieh 41d29b15e8 [clang-tidy] Add a close-on-exec check on epoll_create() in Android module.
Summary:
epoll_create() is better to be replaced by epoll_create1() with EPOLL_CLOEXEC
flag to avoid file descriptor leakage.

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

llvm-svn: 311029
2017-08-16 18:02:49 +00:00
Chih-Hung Hsieh 3be4ecb15b [clang-tidy] Add a close-on-exec check on epoll_create1() in Android module.
Summary:
epoll_create1() is better to set EPOLL_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 311028
2017-08-16 17:53:12 +00:00
Chih-Hung Hsieh 5ac20c9c25 [clang-tidy] Add a close-on-exec check on accept4() in Android module.
Summary:
accept4() is better to set SOCK_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 311027
2017-08-16 17:46:18 +00:00
Chih-Hung Hsieh ae3527e6bb [clang-tidy] Add a close-on-exec check on accept() in Android module.
Summary:
accept() is better to be replaced by accept4() with SOCK_CLOEXEC
flag to avoid file descriptor leakage.

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

llvm-svn: 311024
2017-08-16 17:18:16 +00:00
Chih-Hung Hsieh fec506daaa [clang-tidy] Use CloexecCheck as base class.
Summary:
Simplify registerMatchers and check functions in CloexecCreatCheck,
CloexecSocketCheck, CloexecFopenCheck, and CloexecOpenCheck.

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

llvm-svn: 311020
2017-08-16 16:59:26 +00:00
Chih-Hung Hsieh 7651e66cdf [clang-tidy] Add a close-on-exec check on inotify_init1() in Android module.
Summary:
inotify_init1() is better to set IN_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 310863
2017-08-14 17:45:48 +00:00
Chih-Hung Hsieh 2e6f9a16f9 [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.
Summary:
inotify_init() is better to be replaced by inotify_init1() with IN_CLOEXEC flag to avoid file descriptor leakage.

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

llvm-svn: 310861
2017-08-14 17:25:41 +00:00
Chih-Hung Hsieh 56650e7fc5 [clang-tidy] Add a close-on-exec check on dup() in Android module.
Summary:
dup() is better to be replaced by fcntl() to avoid file descriptor leakage.

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

llvm-svn: 310858
2017-08-14 17:04:16 +00:00
Simon Pilgrim 7c87ebf3cd Fix Wdocumentation warning - typo in argument list. NFCI.
llvm-svn: 310783
2017-08-12 18:50:53 +00:00
Aaron Ballman a3274e5443 Add hicpp-exception-baseclass to the HIC++ module.
This enforces that throwing an exception in C++ requires that exception to inherit from std::exception.

Patch by Jonas Toth.

llvm-svn: 310727
2017-08-11 16:31:51 +00:00
Aaron Ballman 6c2920a30a Implement hicpp-braces-around-statements as an alias to readability-braces-around-statements.
Patch by Jonas Toth.

llvm-svn: 310707
2017-08-11 12:12:36 +00:00
Yan Wang b21739f988 [clang-tidy] Fix for buildbot.
Summary:
Fix an issue for windows.

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

llvm-svn: 310669
2017-08-10 22:09:22 +00:00