aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-05-04[clang-tidy] New: checker misc-unconventional-assign-operator replacing ↵Gabor Horvath1-3/+3
misc-assign-operator-signature Summary: Finds return statements in assign operator bodies where the return value is different from '*this'. Only assignment operators with correct return value Class& are checked. Reviewers: aaron.ballman, alexfh, sbenza Subscribers: o.gyorgy, baloghadamsoftware, LegalizeAdulthood, aaron.ballman, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18265 llvm-svn: 268492
2016-04-26[clang-tidy] New checker for redundant expressions.Etienne Bergeron1-0/+3
Summary: This checker finds redundant expression on both side of a binary operator. The current implementation provide a function to check whether expressions are equivalent. This implementation is able to recognize the common subset encounter in C++ program. Side-effects like "x++" are not considered to be equivalent. There are many False Positives related to macros and to floating point computations (detecting NaN). The checker is ignoring these cases. Example: ``` if( !dst || dst->depth != desired_depth || dst->nChannels != desired_num_channels || dst_size.width != src_size.width || dst_size.height != dst_size.height ) <<--- bug { ``` Reviewers: alexfh Subscribers: danielmarjamaki, fahlgren, jordan_rose, zaks.anna, Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D19451 llvm-svn: 267574
2016-04-26A clang-tidy check for std:accumulate.Alexander Kornienko1-0/+3
Summary: For folds (e.g. std::accumulate), check matches between the provided init value and the range's value_type. A typical error is "std::accumulate(begin, end, 0);", where begin and end have float value_type. See the documentation for more examples. For now we check std::accumulate, std::reduce and std::inner_product. Reviewers: hokein, alexfh Subscribers: Prazek, aaron.ballman, cfe-commits, courbet Patch by Clément Courbet! Differential Revision: http://reviews.llvm.org/D18442 llvm-svn: 267542
2016-04-21[clang-tidy] New checker to detect suspicious string constructor.Etienne Bergeron1-0/+3
Summary: Checker to validate string constructor parameters. A common mistake is to swap parameter for the fill-constructor. ``` std::string str('x', 4); std::string str('4', x); ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19146 llvm-svn: 267011
2016-04-21[clang-tidy] Add new checker for comparison with runtime string functions.Etienne Bergeron1-0/+3
Summary: This checker is validating suspicious usage of string compare functions. Example: ``` if (strcmp(...)) // Implicitly compare to zero if (!strcmp(...)) // Won't warn if (strcmp(...) != 0) // Won't warn ``` This patch was checked over large amount of code. There is three checks: [*] Implicit comparator to zero (coding-style, many warnings found), [*] Suspicious implicit cast to non-integral (bugs!?, almost none found), [*] Comparison to suspicious constant (bugs!?, found two cases), Example: [[https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c | https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c]] ``` else if(strcmp(id, "select") == 0) { array->array[i].key1 = 25; } else if(strcmp(id, "sk") == 28) // BUG!? { array->array[i].key1 = 20; } ``` Reviewers: alexfh Subscribers: Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D18703 llvm-svn: 267009
2016-04-19Initial version of misc-unused-using-decl check.Daniel Jasper1-0/+3
llvm-svn: 266735
2016-04-15[clang-tidy] Add new checker for suspicious sizeof expressionsEtienne Bergeron1-0/+3
Summary: This check is finding suspicious cases of sizeof expression. Sizeof expression is returning the size (in bytes) of a type or an expression. Programmers often abuse or misuse this expression. This checker is adding common set of patterns to detect some of these bad constructs. Some examples found by this checker: R/packages/ifultools/ifultools/src/fra_neig.c ``` /* free buffer memory */ (void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) ); (void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) ); ``` graphviz/v2_20_2/lib/common/utils.c ``` static Dtdisc_t mapDisc = { offsetof(item, p), sizeof(2 * sizeof(void *)), offsetof(item, link), (Dtmake_f) newItem, (Dtfree_f) freeItem, (Dtcompar_f) cmpItem, NIL(Dthash_f), NIL(Dtmemory_f), NIL(Dtevent_f) }; ``` mDNSResponder/mDNSShared/dnsextd.c ``` context = ( TCPContext* ) malloc( sizeof( TCPContext ) ); require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) ); mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) ); context->d = self; ``` Reviewers: alexfh Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D19014 llvm-svn: 266451
2016-04-15[clang-tidy] Add checker for operations between integrals and pointersEtienne Bergeron1-0/+3
Summary: This check is finding suspicious operations involving pointers and integral types; which are most likely bugs. Examples: subversion/v1_6/subversion/libsvn_subr/utf.c ``` static const char * fuzzy_escape(const char *src, apr_size_t len, apr_pool_t *pool) { [...] while (src_orig < src_end) { if (! svn_ctype_isascii(*src_orig) || src_orig == '\0') // Should be *src_orig { ``` apache2/v2_2_23/modules/metadata/mod_headers.c ``` static char *parse_format_tag(apr_pool_t *p, format_tag *tag, const char **sa) { [...] tag->arg = '\0'; // ERROR: tag->arg has type char* /* grab the argument if there is one */ if (*s == '{') { ++s; tag->arg = ap_getword(p,&s,'}'); } ``` Reviewers: alexfh Subscribers: Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D19118 llvm-svn: 266450
2016-04-14[clang-tidy] Add check misc-multiple-statement-macroSamuel Benzaquen1-0/+3
Summary: The check detects multi-statement macros that are used in unbraced conditionals. Only the first statement will be part of the conditionals and the rest will fall outside of it and executed unconditionally. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18766 llvm-svn: 266369
2016-04-07[clang-tidy] add new checker for string literal with NUL character.Etienne Bergeron1-0/+3
Summary: This patch adds the support for detecting suspicious string literals and their //incorrect// usage. The following example shows a incorrect character escaping leading to an embedded NUL character. ``` std::string str = "\0x42"; // Should be "\x42". ``` The patch also add detection of truncated literal when a literal is passed to a string constructor. Reviewers: hokein, alexfh Subscribers: LegalizeAdulthood, bcraig, Eugene.Zelenko, bkramer, cfe-commits Differential Revision: http://reviews.llvm.org/D18783 llvm-svn: 265691
2016-03-31[clang-tidy] Add a new checker to detect missing comma in initializer list.Etienne Bergeron1-0/+3
Summary: This checker is able to detect missing comma in an array of string literals. ``` const char* A[] = { "abc", "def" // missing comma (no compiler warnings) "ghi", }; ``` The ratio of false-positive is reduced by restricting the size of the array considered and the ratio of missing comma. To validate the quantity of false positive, the checker was tried over LLVM and chromium code and detected these cases: [[ http://reviews.llvm.org/D18454 | http://reviews.llvm.org/D18454 ]] [[https://codereview.chromium.org/1807753002/ | https://codereview.chromium.org/1807753002/]] [[https://codereview.chromium.org/1826193002/ | https://codereview.chromium.org/1826193002/]] [[https://codereview.chromium.org/1805713002/ | https://codereview.chromium.org/1805713002/]] Reviewers: alexfh Subscribers: LegalizeAdulthood, szdominik, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18457 llvm-svn: 265033
2016-03-29[clang-tidy] Add check to detect dangling references in value handlers.Samuel Benzaquen1-0/+3
Summary: Add check misc-dangling-handle to detect dangling references in value handlers like std::experimental::string_view. It provides a configuration option to specify other handle types that should also be checked. Right now it detects: - Construction from temporaries. - Assignment from temporaries. - Return statements from temporaries or locals. - Insertion into containers from temporaries. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17811 llvm-svn: 264759
2016-02-24[clang-tidy] Added a check for forward declaration in the potentially wrong ↵Alexander Kornienko1-0/+3
namespace Adds a new check "misc-forward-declaration-namespace". In check, A forward declaration is considerred in a potentially wrong namespace if there is any definition/declaration with the same name exists in a different namespace. Reviewers: akuegel, hokein, alexfh Patch by Eric Liu! Differential Revision: http://reviews.llvm.org/D17195 llvm-svn: 261737
2016-02-11[clang-tidy] Add a check to find unintended semicolons that changes the ↵Gabor Horvath1-0/+3
semantics. Reviewers: hokein, alexfh Differential Revision: http://reviews.llvm.org/D16535 llvm-svn: 260503
2016-02-09[clang-tidy] Add 'misc-misplaced-widening-cast' check.Daniel Marjamaki1-0/+3
Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16310 llvm-svn: 260223
2016-02-08[clang-tidy] Move incorrect-roundings to upstream.Haojian Wu1-0/+3
Summary: This is originally implemented by Jacques Pienaar. Reviewers: alexfh Subscribers: cfe-commits, jpienaar Differential Revision: http://reviews.llvm.org/D16764 llvm-svn: 260084
2016-01-13Support virtual-near-miss check.Alexander Kornienko1-0/+3
Summary: Virtual function override near miss detection. Function complete. Test complete. Do not conduct Fix for now. Reviewers: alexfh Subscribers: cfe-commits Patch by Cong Liu! Differential Revision: http://reviews.llvm.org/D15823 llvm-svn: 257599
2016-01-08[clang-tidy] Add non-inline function definition and variable definition ↵Alexander Kornienko1-0/+3
check in header files. Summary: The new check will find all functionand variable definitions which may violate cpp one definition rule in header file. Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, cfe-commits Patch by Haojian Wu! Differential Revision: http://reviews.llvm.org/D15710 llvm-svn: 257178
2015-12-15[clang-tidy] Check for suspicious string assignments.Gabor Horvath1-0/+3
It is possible to assign arbitrary integer types to strings. Sometimes it is the result of missing to_string call or apostrophes. Reviewers: alexfh Differential Revision: http://reviews.llvm.org/D15411 llvm-svn: 255630
2015-11-25[clang-tidy] Const std::move() argument ClangTidy checkAlexander Kornienko1-0/+3
ClangTidy check for finding cases when std::move() is called with const or trivially copyable arguments, that doesn't lead to any move or argument but it makes copy. FixIt generates patch for removing call of std::move(). Patch by Vadym Doroshenko! (+ a couple of minor fixes) Differential Revision: http://reviews.llvm.org/D12031 llvm-svn: 254070
2015-10-09Add a new checker that tests whether a throw expression throws by value, and ↵Aaron Ballman1-0/+3
whether a catch statement catches by reference. Patch by Tobias Langner! llvm-svn: 249899
2015-09-30Adding a checker (misc-non-copyable-objects) that detects situations where a ↵Aaron Ballman1-2/+4
non-copyable C type is being dereferenced, such as FILE or pthread_mutex_t. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object llvm-svn: 248907
2015-09-29Adding a checker (misc-new-delete-overloads) that detects mismatched ↵Aaron Ballman1-0/+3
overloads of operator new and operator delete. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/DCL54-CPP.+Overload+allocation+and+deallocation+functions+as+a+pair+in+the+same+scope llvm-svn: 248791
2015-09-10[clang-tidy] Add misc-sizeof-container check to find sizeof() uses on stlAlexander Kornienko1-0/+3
containers. Summary: sizeof(some_std_string) is likely to be an error. This check finds this pattern and suggests using .size() instead. Reviewers: djasper, klimek, aaron.ballman Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D12759 llvm-svn: 247297
2015-08-31[clang-tidy] Move misc-use-override and readability-shrink-to-fit to ↵Alexander Kornienko1-2/+0
"modernize/" These checks are focusing on migrating the code from C++98/03 to C++11, so they belong to the modernize module. llvm-svn: 246437
2015-08-20Add a new clang-tidy check (misc-move-constructor-init) that diagnoses move ↵Aaron Ballman1-0/+3
constructor initializations that call copy constructors instead of move constructors. llvm-svn: 245571
2015-07-31Add misc-unused-alias-decls check that currently finds unused namespaceDaniel Jasper1-0/+3
alias declarations. In the future, we might want to reuse it to also fine unsed using declarations and such. llvm-svn: 243754
2015-07-20Initial version of clang-tidy check to find and fix unused parameters.Daniel Jasper1-0/+3
Also see: llvm.org/PR24180. llvm-svn: 242654
2015-06-17clang-tidy: Add checker that warn when macro argument with side effects is ↵Daniel Marjamaki1-0/+3
repeated in the macro llvm-svn: 239909
2015-06-16clang-tidy: Add checker that warns about missing parentheses in macrosDaniel Marjamaki1-0/+3
* calculations in the replacement list should be inside parentheses * macro arguments should be inside parentheses llvm-svn: 239820
2015-05-27[clang-tidy] Renamed misc-noexcept-move-ctors to misc-noexcept-move-constructorAlexander Kornienko1-3/+3
llvm-svn: 238326
2015-05-22Add a clang-tidy check for move constructors/assignment ops without noexcept.Alexander Kornienko1-0/+3
Summary: Add a clang-tidy check (misc-noexcept-move-ctors) for move constructors and assignment operators not using noexcept. http://llvm.org/PR23519 Reviewers: klimek Reviewed By: klimek Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D9933 llvm-svn: 238013
2015-03-09[clang-tidy] Refactor: Rename clang-tidy misc check files and classes to ↵Alexander Kornienko1-7/+7
follow naming conventions Classes are named WhateverCheck, files are named WhateverCheck.cpp and WhateverCheck.h. http://reviews.llvm.org/D8145 Patch by Richard Thomson! llvm-svn: 231648
2015-03-02[clang-tidy] Refactor: Move misc clang-tidy checks to namespace ↵Alexander Kornienko1-1/+4
clang::tidy::misc clang-tidy checks are organized into modules. This refactoring moves the misc module checks into the namespace clang::tidy::misc http://reviews.llvm.org/D7996 Patch by Richard Thomson! llvm-svn: 230950
2015-03-02[clang-tidy] Assert related checkersAlexander Kornienko1-0/+6
This patch contains two assert related checkers. These checkers are the part of those that is being open sourced by Ericsson (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040520.html). The checkers: AssertSideEffect: /// \brief Finds \c assert() with side effect. /// /// The conition of \c assert() is evaluated only in debug builds so a condition /// with side effect can cause different behaviour in debug / relesase builds. StaticAssert: /// \brief Replaces \c assert() with \c static_assert() if the condition is /// evaluatable at compile time. /// /// The condition of \c static_assert() is evaluated at compile time which is /// safer and more efficient. http://reviews.llvm.org/D7375 Patch by Szabolcs Sipos! llvm-svn: 230943
2015-02-10[clang-tidy] Checker for inaccurate use of erase() method.Gabor Horvath1-0/+3
Algorithms like remove() does not actually remove any element from the container but returns an iterator to the first redundant element at the end of the container. These redundant elements must be removed using the erase() method. This check warns when not all of the elements will be removed due to using an inappropriate overload. Reviewer: alexfh Differential Revision: http://reviews.llvm.org/D7496 llvm-svn: 228679
2015-02-09Verify assign operator signatures.Samuel Benzaquen1-0/+3
Summary: Warn when the return type of assign operators is not Class&. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6667 llvm-svn: 228583
2015-02-07[clang-tidy] Checker for inefficient use of algorithms on associative containersGabor Horvath1-0/+3
Summary: Associative containers implements some of the algorithms as methods which should be preferred to the algorithms in the algorithm header. The methods can take advantage of the order of the elements. Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D7246 llvm-svn: 228505
2015-01-14[cleanup] Re-sort the #include lines with llvm/utils/sort_includes.pyChandler Carruth1-1/+1
No functionality changed, this is just a mechanical cleanup to keep the order of #include lines consistent across the project. llvm-svn: 225976
2014-12-05[clang-tidy] Add clang-tidy check for unique_ptr's reset+release -> moveAlexander Kornienko1-0/+3
Replace x.reset(y.release()); with x = std::move(y); If y is rvalue, replace with x = y; instead. http://reviews.llvm.org/D6485 Patch by Alexey Sokolov! llvm-svn: 223460
2014-10-26[clang-tidy] Bring order to check registration.Alexander Kornienko1-11/+0
Summary: Register readability checks in a separate module. Renamed the checks and test file names accordingly. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5936 llvm-svn: 220631
2014-10-15[clang-tidy] Move some of the misc checks to readability/Alexander Kornienko1-6/+9
Summary: Some of the misc checks belong to readability/. I'm moving them there without changing check names for now. As the next step, I want to register some of these checks in the google and llvm modules with suitable settings (e.g. BracesAroundStatementsCheck). I'm not sure if we want to create a "readability" module, probably not. Reviewers: djasper Reviewed By: djasper Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5792 llvm-svn: 219786
2014-10-02[clang-tidy] Add check misc-braces-around-statements.Alexander Kornienko1-0/+3
This check looks for if statements and loops: for, range-for, while and do-while, and verifies that the inside statements are inside braces '{}'. If not, proposes to add braces around them. Example: if (condition) action(); becomes if (condition) { action(); } This check ought to be used with the -format option, so that the braces be well-formatted. Patch by Marek Kurdej! http://reviews.llvm.org/D5395 llvm-svn: 218898
2014-09-15[clang-tidy] Add a checker for long functions.Benjamin Kramer1-0/+2
As this is very dependent on the code base it has some ways of configuration. It's possible to pick between 3 modes of operation: - Line counting: number of lines including whitespace and comments - Statement counting: number of statements within compoundStmts. - Branch counter In addition a threshold can be picked, warnings are only emitted when it is met. The thresholds can be configured via a .clang-tidy file. Differential Revision: http://reviews.llvm.org/D4986 llvm-svn: 217768
2014-09-10Unique-ptrify ClangTidyCheckFactories. Add a more convenient alternative toAlexander Kornienko1-21/+11
addCheckFactory: registerCheck. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5288 llvm-svn: 217489
2014-07-31[clang-tidy] Add a checker for code that looks like a delegate constructors ↵Benjamin Kramer1-0/+4
but doesn't delegate. Summary: class Foo { Foo() { Foo(42); // oops } Foo(int); }; This is valid code but it does nothing and we can't emit a warning in clang because there might be side effects. The checker emits a warning for this pattern and also for base class initializers written in this style. There is some overlap with the unused-rtti checker but they follow different goals and fire in different places most of the time. Reviewers: alexfh, djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4667 llvm-svn: 214397
2014-07-23Reapply r213647 with a fix.Benjamin Kramer1-0/+4
ASTMatchers currently have problems mixing bound TypeLoc nodes with Decl/Stmt nodes. That should be fixed soon but for this checker there we only need the TypeLoc to generate a fixit so postpone the potentially heavyweight AST walking until after we know that we're going to emit a warning. This is covered by existing test cases. Original message: [clang-tidy] Add a check for RAII temporaries. This tries to find code similar that immediately destroys an object that looks like it's trying to follow RAII. { scoped_lock(&global_mutex); critical_section(); } This checker will have false positives if someone uses this pattern to legitimately invoke a destructor immediately (or the statement is at the end of a scope anyway). To reduce the number we ignore this pattern in macros (this is heavily used by gtest) and ignore objects with no user-defined destructor. llvm-svn: 213738
2014-07-23Revert r213647; the added test triggers an assertion.Richard Smith1-4/+0
llvm-svn: 213722
2014-07-22[clang-tidy] Add a check for RAII temporaries.Benjamin Kramer1-0/+4
Summary: This tries to find code similar that immediately destroys an object that looks like it's trying to follow RAII. { scoped_lock(&global_mutex); critical_section(); } This checker will have false positives if someone uses this pattern to legitimately invoke a destructor immediately (or the statement is at the end of a scope anyway). To reduce the number we ignore this pattern in macros (this is heavily used by gtest) and ignore objects with no user-defined destructor. Reviewers: alexfh, djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4615 llvm-svn: 213647
2014-07-14[clang-tidy] Add a checker for swapped arguments.Benjamin Kramer1-0/+4
This looks for swapped arguments by looking at implicit conversions of arguments void Foo(int, double); Foo(1.0, 3); // Most likely a bug llvm-svn: 212942