summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/utils
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzerShuai Wang2018-09-101-6/+20
| | | | | | | | | | | | | | Summary: - If a function is unresolved, assume it mutates its arguments - Follow unresolved member expressions for nested mutations Reviewers: aaron.ballman, JonasToth, george.karpenkov Subscribers: xazax.hun, a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D50619 llvm-svn: 341848
* Port getLocStart -> getBeginLocStephen Kelly2018-08-093-4/+4
| | | | | | | | | | Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
* [clang-tidy] Sequence init statements, declarations, and conditions ↵Martin Bohme2018-08-031-3/+18
| | | | | | | | | | | | | | | | | | correctly in if, switch, and while Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36516. Reviewers: ilya-biryukov, alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D49918 llvm-svn: 338932
* [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression ↵Alexander Kornienko2018-06-273-0/+317
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | is mutated within a statement. Summary: (Originally started as a clang-tidy check but there's already D45444 so shifted to just adding ExprMutationAnalyzer) `ExprMutationAnalyzer` is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.) This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization. It should also be possible to construct checks like D45444 (suggest adding const to variable declaration) or https://bugs.llvm.org/show_bug.cgi?id=21981 (suggest adding const to member function) using this helper function. This function is tested by itself and is intended to stay generally useful instead of tied to any particular check. Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov, george.karpenkov Reviewed By: aaron.ballman Subscribers: lebedev.ri, shuaiwang, rnkovacs, hokein, alexfh, aaron.ballman, a.sidorin, Eugene.Zelenko, xazax.hun, JonasToth, klimek, mgorny, cfe-commits Tags: #clang-tools-extra Patch by Shuai Wang. Differential Revision: https://reviews.llvm.org/D45679 llvm-svn: 335736
* Reverting r334604 due to failing tests.Aaron Ballman2018-06-133-318/+0
| | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/31500 llvm-svn: 334606
* Add a new class to analyze whether an expression is mutated within a statement.Aaron Ballman2018-06-133-0/+318
| | | | | | | | ExprMutationAnalyzer is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.) This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization. Patch by Shuai Wang llvm-svn: 334604
* Reland "[tools] Updating PPCallbacks::InclusionDirective calls"Julie Hockett2018-05-101-1/+2
| | | | | | | | | This commit relands r331905. r331904 added SrcMgr::CharacteristicKind to the InclusionDirective callback, this revision updates instances of it in clang-tools-extra. llvm-svn: 332023
* Revert "[tools] Updating PPCallbacks::InclusionDirective calls"Julie Hockett2018-05-091-2/+1
| | | | | | This reverts commit r331905, since it's dependent on reverted r331905. llvm-svn: 331931
* [tools] Updating PPCallbacks::InclusionDirective callsJulie Hockett2018-05-091-1/+2
| | | | | | | | | [revision] added SrcMgr::CharacteristicKind to the InclusionDirective callback, this revision updates instances of it in clang-tools-extra. Differential Revision: https://reviews.llvm.org/D46615 llvm-svn: 331905
* [clang-tidy] ObjC ARC objects should not trigger ↵Ben Hamilton2018-02-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Kill marco. No functionality change.Benjamin Kramer2018-02-021-1/+1
| | | | llvm-svn: 324084
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Revert Implement type-based check for gsl::ownerJonas Toth2017-09-121-4/+0
| | | | | | This should unbreak the buildbot for visual studio 2015 for now. llvm-svn: 313059
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are usedAlexander Kornienko2017-07-202-2/+6
| | | | llvm-svn: 308605
* [clang-tidy] Add a new Android check "android-cloexec-socket"Yan Wang2017-07-122-0/+35
| | | | | | | | | | | | | | | | Summary: socket() is better to include SOCK_CLOEXEC in its type argument to avoid the file descriptor leakage. Reviewers: chh, Eugene.Zelenko, alexfh, hokein, aaron.ballman Reviewed By: chh, alexfh Subscribers: srhines, mgorny, JDevlieghere, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34913 llvm-svn: 307818
* Extend readability-container-size-empty to add comparisons to empty-state ↵Aaron Ballman2017-04-242-0/+18
| | | | | | | | objects. Patch by Josh Zimmerman. llvm-svn: 301185
* Spelling mistakes in comments. NFCI.Simon Pilgrim2017-03-301-1/+1
| | | | | | Based on corrections mentioned in patch for clang for PR27635 llvm-svn: 299074
* [clang-tidy] Reword the "code outside header guard" warning.Benjamin Kramer2017-02-211-6/+6
| | | | | | | | | | | | The check doesn't really know if the code it is warning about came before or after the header guard, so phrase it more neutral instead of complaining about code before the header guard. The location for the warning is still not optimal, but I don't think fixing that is worth the effort, the preprocessor doesn't give us a better location. Differential Revision: https://reviews.llvm.org/D30191 llvm-svn: 295715
* [clang-tidy] getPreviousNonCommentToken -> getPreviousTokenAlexander Kornienko2017-02-063-8/+7
| | | | llvm-svn: 294192
* [clang-tidy] Do not trigger move fix for non-copy assignment operators in ↵Felix Berger2017-01-191-1/+2
| | | | | | | | | | | | performance-unnecessary-value-param check Reviewers: alexfh, sbenza, malcolm.parsons Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D28899 llvm-svn: 292491
* Correctly classify main file includes if there is a prefix addedAlexander Kornienko2017-01-121-1/+2
| | | | | | | | | | | | | | | | | Summary: Prevents misclassifying includes based on the command-line filename (e.g. if a project is in a subdirectory). This is slightly more robust than the additional duplicate detection, however the current classification scheme is still kind of brittle for a lot of code. Reviewers: hokein, alexfh Subscribers: cfe-commits, #clang-tools-extra Patch by Julian Bangert! Differential Revision: https://reviews.llvm.org/D26015 llvm-svn: 291767
* [clang-tidy] Handle constructors in performance-unnecessary-value-paramMalcolm Parsons2017-01-032-14/+70
| | | | | | | | | | | | | | Summary: modernize-pass-by-value doesn't warn about value parameters that cannot be moved, so performance-unnecessary-value-param should. Reviewers: aaron.ballman, flx, alexfh Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D28022 llvm-svn: 290883
* [clang-tidy] refactor ExprSequence out of use-after-move checkMarek Sokolowski2016-12-243-0/+307
| | | | | | Differential Revision: https://reviews.llvm.org/D27700 llvm-svn: 290489
* [clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang2016-11-085-13/+9
| | | | | | | | | | | | | | | | Summary: Ran clang-format on all .c/.cpp/.h files in clang-tools-extra. Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories. Reviewers: klimek, alexfh Subscribers: nemanjai Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26329 llvm-svn: 286221
* [clang-tidy] Ignore incomplete types when determining whether they are ↵Felix Berger2016-11-041-1/+1
| | | | | | | | | | | | | | | | expensive to copy Summary: IsExpensiveToCopy can return false positives for incomplete types, so ignore them. All existing ClangTidy tests that depend on this function still pass as the types are complete. Reviewers: alexfh, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26195 llvm-svn: 286008
* Recommit "[ClangTidy] Add UsingInserter and NamespaceAliaser"Haojian Wu2016-10-177-0/+345
| | | | | | | | | | | | | | Summary: This adds helper classes to add using declaractions and namespace aliases to function bodies. These help making function calls to deeply nested functions concise (e.g. when calling helpers in a refactoring) Patch by Julian Bangert! Reviewers: alexfh, hokein Subscribers: beanz, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D24997 llvm-svn: 284368
* Revert "[ClangTidy] Add UsingInserter and NamespaceAliaser"Haojian Wu2016-10-126-342/+0
| | | | | | This reverts commit r283981. This patch breaks the buildbot. llvm-svn: 283985
* [ClangTidy] Add UsingInserter and NamespaceAliaserHaojian Wu2016-10-126-0/+342
| | | | | | | | | | | | | | | | Summary: This adds helper classes to add using declaractions and namespace aliases to function bodies. These help making function calls to deeply nested functions concise (e.g. when calling helpers in a refactoring) Patch by Julian Bangert! Reviewers: alexfh, hokein Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D24997 llvm-svn: 283981
* Fix some false-positives with cppcoreguidelines-pro-type-member-init. Handle ↵Aaron Ballman2016-10-041-0/+5
| | | | | | | | | | classes with default constructors that are defaulted or are not present in the AST. Classes with virtual methods or virtual bases are not trivially default constructible, so their members and bases need to be initialized. Patch by Malcolm Parsons. llvm-svn: 283224
* [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init ↵Matthias Gehre2016-09-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with in-class initializers Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=30487 where ``` warning: uninitialized record type: 's' [cppcoreguidelines-pro-type-member-init] ``` is emitted on ``` struct MyStruct { int a = 5; int b = 7; }; int main() { MyStruct s; } ``` Reviewers: alexfh, aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D24848 llvm-svn: 282625
* [clang-tidy] Some tweaks on header guard checks.Haojian Wu2016-08-262-18/+14
| | | | | | | | * Implement missing storeOption interfaces. * Remove unnecessary parameter copy in isHeaderFileExtension. * Fix doc style. llvm-svn: 279814
* [clang-tidy] Added hh, hxx and hpp to header guard checks.Mads Ravn2016-08-264-5/+34
| | | | | | | | Changed the extension check to include the option of ",h,hh,hpp,hxx" instead of just returning whether the file ended with ".h". Differential revision: https://reviews.llvm.org/D20512 llvm-svn: 279803
* [clang-tidy] Fixes to modernize-use-emplacePiotr Padlewski2016-07-291-2/+0
| | | | | | | | Not everything is valid, but it should works for 99.8% cases https://reviews.llvm.org/D22208 llvm-svn: 277097
* [clang-tidy] UnnecessaryValueParamCheck - suggest std::move() if non-const ↵Felix Berger2016-07-015-14/+84
| | | | | | | | | | | | | | | | | | | | value parameter can be moved. Summary: Make check more useful in the following two cases: The parameter is passed by non-const value, has a non-deleted move constructor and is only referenced once in the function as argument to the type's copy constructor. The parameter is passed by non-const value, has a non-deleted move assignment operator and is only referenced once in the function as argument of the the type's copy assignment operator. In this case suggest a fix to move the parameter which avoids the unnecessary copy and is closest to what the user might have intended. Reviewers: alexfh, sbenza Subscribers: cfe-commits, Prazek Differential Revision: http://reviews.llvm.org/D20277 llvm-svn: 274380
* Remove ignoringImplicit from clang-tidy.Cong Liu2016-06-241-5/+0
| | | | llvm-svn: 273660
* [clang-tidy] Add modernize-use-emplacePiotr Padlewski2016-06-211-0/+2
| | | | | | | | | | Summary: Add check that replaces call of push_back to emplace_back Reviewers: hokein Differential Revision: http://reviews.llvm.org/D20964 llvm-svn: 273275
* [clang-tidy] More doc fixes. NFC.Alexander Kornienko2016-06-173-30/+30
| | | | llvm-svn: 272995
* [clang-tidy] Fix doxygen errors. NFC.Alexander Kornienko2016-06-176-47/+55
| | | | llvm-svn: 272994
* [clang-tidy] Fix a functional change from r269656.Benjamin Kramer2016-05-181-3/+4
| | | | | | | | Instead of forming char ranges that patch made us form token ranges, which behave subtly different. Sadly I'm only seeing this as part of a larger test case that I haven't fully reduced yet. llvm-svn: 269896
* [clang-tidy] Lift common matchers to utils namespaceEtienne Bergeron2016-05-171-0/+5
| | | | | | | | | | | | | | Summary: This patch is lifting matchers used by more than one checkers to the common namespace. Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D19841 llvm-svn: 269804
* [clang-tidy] Cleanups utils filesEtienne Bergeron2016-05-169-46/+19
| | | | | | | | | | | | | | | | | | | Summary: Cleanup some code by using appropriate APIs. Some coding style cleanups. There is no behavior changes. - Function `IncludeSorter::CreateFixIt` can be replaced by `FixItHint::CreateReplacement`. - Function `cleanPath` is a wrapper for `llvm::sys::path::remove_dots`. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20279 llvm-svn: 269656
* [clang-tidy] TypeTraits - Type is not expensive to copy when it has a ↵Felix Berger2016-05-142-3/+20
| | | | | | | | | | | | deleted copy constructor. Reviewers: alexfh, sbenza Subscribers: etienneb, aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D20170 llvm-svn: 269581
* [clang-tidy] Lift parsing of sequence of names functions to utils.Etienne Bergeron2016-05-103-1/+72
| | | | | | | | | | | | | | | | Summary: Lift some common code used by multiple checkers. This function is also used by checkers that are coming. It is quite common for a checker to parse a list of names. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19846 llvm-svn: 269065
* [clang-tidy] Cleanup namespace in utils folder.Etienne Bergeron2016-05-0315-17/+41
| | | | | | | | | | | | | | Summary: This is a step forward cleaning up the namespaces in clang-tidy/utils. There is no behavior change. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19819 llvm-svn: 268356
* [clang-tidy] Cleanup some ast-matchers and lift some to utils.Etienne Bergeron2016-04-211-0/+12
| | | | | | | | | | | | | | | | Summary: Little cleanup to lift-out and to remove some frequently used ast-matchers. Some of theses matchers are candidates to be lifted to ASTMatchers.h. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19200 llvm-svn: 267003
* Complete support for C++ Core Guidelines Type.6: Always initialize a member ↵Alexander Kornienko2016-04-133-0/+87
| | | | | | | | | | | | | | | | variable. Summary: Added the remaining features needed to satisfy C++ Core Guideline Type.6: Always initialize a member variable to cppcoreguidelines-pro-type-member-init. The check now flags all default-constructed uses of record types without user-provided default constructors that would leave their memory in an undefined state. The check suggests value initializing them instead. Reviewers: flx, alexfh, aaron.ballman Subscribers: klimek, aaron.ballman, LegalizeAdulthood, cfe-commits Patch by Michael Miller! Differential Revision: http://reviews.llvm.org/D18584 llvm-svn: 266191
* [clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on ↵Felix Berger2016-03-055-0/+200
| | | | | | | | | | | | | | | | non-const copies that can be safely converted to const references. Summary: Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck into utilities files. Add more test cases for UnnecessaryCopyInitialization and disable fixes inside of macros. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17488 llvm-svn: 262781
* [clang-tidy] Fix an assertion failure of "SLocEntry::getExpansion()" when ↵Haojian Wu2016-03-021-2/+3
| | | | | | | | | | | | | | IncludeInserter handles macro header file. Summary: Also Fixes PR24749. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17805 llvm-svn: 262484
* [clang-tdiy] Add header file extension configuration support.Haojian Wu2016-02-053-0/+117
| | | | | | | | | | | | Summary: * Add a `HeaderFileExtensions` check option in misc-definitions-in-headers, google-build-namespaces and google-global-names-in-headers. Reviewers: aaron.ballman, alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16113 llvm-svn: 259879
OpenPOWER on IntegriCloud