summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test
Commit message (Collapse)AuthorAgeFilesLines
...
* Reapply "Fix crash on switch conditions of non-integer types in templates"Melanie Blower2019-11-082-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch reapplies commit 76945821b9cad3. The first version broke buildbots due to clang-tidy test fails. The fails are because some errors in templates are now diagnosed earlier (does not wait till instantiation). I have modified the tests to add checks for these diagnostics/prevent these diagnostics. There are no additional code changes. Summary of code changes: Clang currently crashes for switch statements inside a template when the condition is a non-integer field member because contextual implicit conversion is skipped when parsing the condition. This conversion is however later checked in an assert when the case statement is handled. The conversion is skipped when parsing the condition because the field member is set as type-dependent based on its containing class. This patch sets the type dependency based on the field's type instead. This patch fixes Bug 40982. Reviewers: rnk, gribozavr2 Patch by: Elizabeth Andrews (eandrews) Differential revision: https://reviews.llvm.org/D69950
* [clang-tidy] Add readability-make-member-function-constMatthias Gehre2019-11-061-0/+332
| | | | | | | | | | | | | | | | | | Summary: Finds non-static member functions that can be made ``const`` because the functions don't use ``this`` in a non-const way. The check conservatively tries to preserve logical costness in favor of physical costness. See readability-make-member-function-const.rst for more details. Reviewers: aaron.ballman, gribozavr, hokein, alexfh Subscribers: mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68074
* [clang-tidy] New checker performance-trivially-destructible-checkAnton Bikineev2019-11-011-0/+84
| | | | | | | | | | | | | Checks for types which can be made trivially-destructible by removing out-of-line defaulted destructor declarations. The check is motivated by the work on C++ garbage collector in Blink (rendering engine for Chrome), which strives to minimize destructors and improve runtime of sweeping phase. In the entire chromium codebase the check hits over 2000 times. Differential Revision: https://reviews.llvm.org/D69435
* Add a test file that was missed in 4de6b1586807285e20a5db6596519c2336a64568Vladimir Plyashkun2019-10-301-0/+33
|
* Add a test file that was missed in e477988309dbde214a6d16ec690a416882714aacDaniel2019-10-301-0/+27
|
* Fix modernize-use-nodiscard for classes marked [[nodiscard]]Aaron Ballman2019-10-301-0/+5
| | | | | | | Current implementation suggests to add [[nodiscard]] to methods even if the return type is marked already as [[nodiscard]]. Patch by Eugene Sedykh.
* Fix a false positive in misc-redundant-expression checkAaron Ballman2019-10-301-1/+18
| | | | | | | | Do not warn for redundant conditional expressions when the true and false branches are expanded from different macros even when they are defined by one another. Patch by Daniel Krupp.
* Add the readability-redundant-access-specifiers check.Aaron Ballman2019-10-302-0/+159
| | | | | | This finds redundant access specifier declarations inside classes, structs, and unions. Patch by Mateusz Mackowski.
* [lit] Fix another test case that r374652 missedJoel E. Denny2019-10-161-1/+1
| | | | llvm-svn: 375058
* [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 4Csaba Dabis2019-10-131-1/+1
| | | | llvm-svn: 374715
* [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 3Csaba Dabis2019-10-132-0/+10
| | | | | | | On Windows the signed/unsigned int conversions of APInt seems broken, so that two of the test files marked as unsupported on Windows, as a hotfix. llvm-svn: 374713
* [clang-tidy] New checker for not null-terminated result caused by strlen(), ↵Csaba Dabis2019-10-1310-0/+954
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | size() or equal length Summary: New checker called bugprone-not-null-terminated-result. This checker finds function calls where it is possible to cause a not null-terminated result. Usually the proper length of a string is `strlen(src) + 1` or equal length of this expression, because the null terminator needs an extra space. Without the null terminator it can result in undefined behaviour when the string is read. The following and their respective `wchar_t` based functions are checked: `memcpy`, `memcpy_s`, `memchr`, `memmove`, `memmove_s`, `strerror_s`, `strncmp`, `strxfrm` The following is a real-world example where the programmer forgot to increase the passed third argument, which is `size_t length`. That is why the length of the allocated memory is not enough to hold the null terminator. ``` static char *stringCpy(const std::string &str) { char *result = reinterpret_cast<char *>(malloc(str.size())); memcpy(result, str.data(), str.size()); return result; } ``` In addition to issuing warnings, fix-it rewrites all the necessary code. It also tries to adjust the capacity of the destination array: ``` static char *stringCpy(const std::string &str) { char *result = reinterpret_cast<char *>(malloc(str.size() + 1)); strcpy(result, str.data()); return result; } ``` Note: It cannot guarantee to rewrite every of the path-sensitive memory allocations. Reviewed By: JonasToth, aaron.ballman, whisperity, alexfh Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D45050 llvm-svn: 374707
* [ClangTidy] Separate tests for infrastructure and checkers, fixupDmitri Gribenko2019-10-111-0/+0
| | | | | | Renamed a file that I missed in r374540. llvm-svn: 374549
* [ClangTidy] Separate tests for infrastructure and checkersDmitri Gribenko2019-10-11564-0/+0
| | | | | | | | | | | | | | | | | | | | Summary: This change moves tests for checkers and infrastructure into separate directories, making it easier to find infrastructure tests. Tests for checkers are already easy to find because they are named after the checker. Tests for infrastructure were difficult to find because they were outnumbered by tests for checkers. Now they are in a separate directory. Reviewers: jfb, jdoerfert, lebedev.ri Subscribers: srhines, nemanjai, aheejin, kbarton, christof, mgrang, arphaman, jfb, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68807 llvm-svn: 374540
* Try to get readability-deleted-default.cpp to pass on Windows.Nico Weber2019-10-081-2/+19
| | | | | | | | | | | | | | | In MS compatibility mode, "extern inline void g()" is not a redundant declaration for "inline void g()", because of redeclForcesDefMSVC() (see PR19264, r205485). To fix, run the test with -fms-compatiblity forced on and off and explicit check for the differing behavior for extern inline. Final bit of PR43593. Differential Revision: https://reviews.llvm.org/D68640 llvm-svn: 374103
* Attempt to fix a few clang-tidy tests on Windows, see PR43593.Nico Weber2019-10-074-4/+4
| | | | llvm-svn: 373951
* Add the misc-init-local-variables check.Aaron Ballman2019-10-021-0/+80
| | | | | | | | This checks finds all primitive type local variables (integers, doubles, pointers) that are declared without an initial value. Includes fixit functionality to initialize said variables with a default value. This is zero for most types and NaN for floating point types. The use of NaNs is copied from the D programming language. Patch by Jussi Pakkanen. llvm-svn: 373489
* [clang-tidy] Fix typo in r373428Sam McCall2019-10-021-1/+0
| | | | llvm-svn: 373436
* [clang-tidy] Fix for commits rL372706 and rL372711Adam Balogh2019-10-021-0/+23
| | | | | | | | | The patch committed was not the accepted version but the previous one. This commit fixes this issue. Differential Revision: https://reviews.llvm.org/D64736 llvm-svn: 373428
* [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlockStephane Moore2019-10-011-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Summary: OSSpinLock* are Apple/Darwin functions, but were previously located with ObjC checks as those were most closely tied to Apple platforms before. Now that there's a specific Darwin module, relocating the check there. This change was prepared by running rename_check.py. Contributed By: mwyman Reviewers: stephanemoore, dmaclach Reviewed By: stephanemoore Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang, #llvm Differential Revision: https://reviews.llvm.org/D68148 llvm-svn: 373392
* Fixed indentation in a ClangTidy testDmitri Gribenko2019-09-271-1/+1
| | | | llvm-svn: 373068
* Moved -fblocks from an individual test to check_clang_tidy.pyDmitri Gribenko2019-09-272-2/+3
| | | | | | | This way, all tests will benefit from it and will not have to worry about setting up language options properly. llvm-svn: 373066
* [clang-tidy] New check to warn when storing dispatch_once_t in non-static, ↵Dmitri Gribenko2019-09-271-0/+48
| | | | | | | | | | | | | | | | | | | | | non-global storage. Summary: Creates a new darwin ClangTidy module and adds the darwin-dispatch-once-nonstatic check that warns about dispatch_once_t variables not in static or global storage. This catches a missing static for local variables in e.g. singleton initialization behavior, and also warns on storing dispatch_once_t values in Objective-C instance variables. C/C++ struct/class instances may potentially live in static/global storage, and are ignored for this check. The osx.API static analysis checker can find the non-static storage use of dispatch_once_t; I thought it useful to also catch this issue in clang-tidy when possible. This is a re-land of https://reviews.llvm.org/D67567 Reviewers: thakis, gribozavr, stephanemoore Subscribers: Eugene.Zelenko, mgorny, xazax.hun, jkorous, arphaman, kadircet, usaxena95 Tags: #clang-tools-extra, #clang, #llvm Differential Revision: https://reviews.llvm.org/D68109 llvm-svn: 373065
* Revert "[clang-tidy] New check to warn when storing dispatch_once_t in ↵Dmitri Gribenko2019-09-261-48/+0
| | | | | | | | non-static, non-global storage" This reverts commit r373028, because the new test fails on Linux. llvm-svn: 373032
* [clang-tidy] New check to warn when storing dispatch_once_t in non-static, ↵Stephane Moore2019-09-261-0/+48
| | | | | | | | | | | | | | | | | | | | | | | non-global storage Summary: Creates a new darwin ClangTidy module and adds the darwin-dispatch-once-nonstatic check that warns about dispatch_once_t variables not in static or global storage. This catches a missing static for local variables in e.g. singleton initialization behavior, and also warns on storing dispatch_once_t values in Objective-C instance variables. C/C++ struct/class instances may potentially live in static/global storage, and are ignored for this check. The osx.API static analysis checker can find the non-static storage use of dispatch_once_t; I thought it useful to also catch this issue in clang-tidy when possible. Contributed By: mwyman Reviewers: benhamilton, hokein, stephanemoore, aaron.ballman, gribozavr Reviewed By: stephanemoore, gribozavr Subscribers: jkorous, arphaman, kadircet, usaxena95, NoQ, xazax.hun, lebedev.ri, mgorny, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D67567 llvm-svn: 373028
* [clang-tidy][test] Add -fexceptions to bugprone-infinite-loop.testFangrui Song2019-09-241-1/+1
| | | | | | | | This fixes llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast. -fexceptions is disabled by default on XCore and PS4. llvm-svn: 372715
* [clang-tidy] Add missing InfiniteLoopCheck.h, InfiniteLoopCheck.cpp and test ↵Fangrui Song2019-09-241-0/+298
| | | | | | from D64736 llvm-svn: 372706
* Added a test for agreement between paths used in ClangTidy's diagnostics and ↵Dmitri Gribenko2019-09-231-0/+19
| | | | | | | | header filter This test would have been broken by r372388. llvm-svn: 372607
* Revert "[clang-tidy] Fix relative path in header-filter."Dmitri Gribenko2019-09-234-84/+2
| | | | | | | This reverts commit r372388. It made '-header-filter' inconsistent with paths printed in diagnostics. llvm-svn: 372601
* [clang-tidy] Add check for classes missing -hash ⚠️Stephane Moore2019-09-211-0/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Apple documentation states that: "If two objects are equal, they must have the same hash value. This last point is particularly important if you define isEqual: in a subclass and intend to put instances of that subclass into a collection. Make sure you also define hash in your subclass." https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418795-isequal?language=objc In many or all versions of libobjc, -[NSObject isEqual:] is a pointer equality check and -[NSObject hash] returns the messaged object's pointer. A relatively common form of developer error is for a developer to override -isEqual: in a subclass without overriding -hash to ensure that hashes are equal for objects that are equal. It is assumed that an override of -isEqual: is a strong signal for changing the object's equality operator to something other than pointer equality which implies that a missing override of -hash could result in distinct objects being equal but having distinct hashes because they are independent instances. This added check flags classes that override -isEqual: but inherit NSObject's implementation of -hash to warn of the potential for unexpected behavior. The proper implementation of -hash is the responsibility of the developer and the check will only verify that the developer made an effort to properly implement -hash. Developers can set up unit tests to verify that their implementation of -hash is appropriate. Test Notes: Ran check-clang-tools. Reviewers: aaron.ballman, benhamilton Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67737 llvm-svn: 372445
* [clang-tidy] Fix relative path in header-filter.Dmitri Gribenko2019-09-204-2/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Clang-tidy supports output diagnostics from header files if user specifies --header-filter. But it can't handle relative path well. For example, the folder structure of a project is: ``` // a.h is in /src/a/a.h // b.h is in /src/b/b.h ... // c.cpp is in /src/c.cpp ``` Now, we set --header-filter as --header-filter=/a/. That means we only want to check header files under /src/a/ path, and ignore header files uder /src/b/ path, but in current implementation, clang-tidy will check /src/b/b.h also, because the name of b.h used in clang-tidy is /src/a/../b/b.h. This change tries to fix this issue. Reviewers: alexfh, hokein, aaron.ballman, gribozavr Reviewed By: gribozavr Subscribers: MyDeveloperDay, xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D67501 Patch by Yubo Xie. llvm-svn: 372388
* [clang-tidy] Fix bugprone-argument-comment-check to correctly ignore ↵Yitzhak Mandelbaum2019-09-191-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | implicit constructors. Summary: After revision 370919, this check incorrectly flags certain cases of implicit constructors. Specifically, if an argument is annotated with an argument-comment and the argument expression triggers an implicit constructor, then the argument comment is associated with argument of the implicit constructor. However, this only happens when the constructor has more than one argument. This revision fixes the check for implicit constructors and adds a regression test for this case. Note: r370919 didn't cause this bug, it simply uncovered it by fixing another bug that was masking the behavior. Reviewers: gribozavr Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67744 llvm-svn: 372317
* [clang-tidy] Fix a potential infinite loop in ↵Haojian Wu2019-09-181-0/+7
| | | | | | | | | | | | | | readability-isolate-declaration check. Reviewers: ilya-biryukov Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67654 llvm-svn: 372206
* [clang-tidy] add checks to bugprone-posix-returnJian Cai2019-09-161-0/+80
| | | | | | This check now also checks if any calls to pthread_* functions expect negative return values. These functions return either 0 on success or an errno on failure, which is positive only. llvm-svn: 372037
* [clang-tidy] performance-inefficient-vector-operation: Support proto ↵Haojian Wu2019-09-161-2/+86
| | | | | | | | | | | | | | | | | | | | | | | | | repeated field Summary: Finds calls that add element to protobuf repeated field in a loop without calling Reserve() before the loop. Calling Reserve() first can avoid unnecessary memory reallocations. A new option EnableProto is added to guard this feature. Patch by Cong Liu! Reviewers: gribozavr, alexfh, hokein, aaron.ballman Reviewed By: hokein Subscribers: lebedev.ri, xazax.hun, Eugene.Zelenko, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D67135 llvm-svn: 371963
* [clang-tidy] Fix bug in bugprone-use-after-move checkYitzhak Mandelbaum2019-09-091-1/+33
| | | | | | | | | | | | | | | | | | | | Summary: The bugprone-use-after-move check exhibits false positives for certain uses of the C++17 if/switch init statements. These false positives are caused by a bug in the ExprSequence calculations. This revision adds tests for the false positives and fixes the corresponding sequence calculation. Reviewers: gribozavr Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67292 llvm-svn: 371396
* [clang-tidy] Make most ArgumentCommentCheck options local, as they should beAlexander Kornienko2019-09-052-2/+17
| | | | llvm-svn: 371076
* Add a bugprone-argument-comment option: IgnoreSingleArgument.Alexander Kornienko2019-09-051-0/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add bugprone-argument-comment option: IgnoreSingleArgument. When true, the check will ignore the single argument. Sometimes, it's not necessary to add comment to single argument. For example: > std::string name("Yubo Xie"); > pScreen->SetWidth(1920); > pScreen->SetHeight(1080); This option can ignore such single argument in bugprone-argument-comment check. Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits Tags: #clang Patch by Yubo Xie. Differential Revision: https://reviews.llvm.org/D67056 llvm-svn: 371075
* [clang-tidy] Fix bugprone-argument-comment bug: negative literal number is ↵Alexander Kornienko2019-09-051-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | not checked. Summary: For example: ``` void foo(int a); foo(-2); ``` should be fixed as: ``` foo(/*a=*/-2); ``` This change tries to fix this issue. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: alexfh, aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Patch by Yubo Xie. Differential Revision: https://reviews.llvm.org/D67084 llvm-svn: 371072
* [clang-tidy] Fix definitions in headers check to respect qualifiersKadir Cetinkaya2019-09-051-0/+12
| | | | | | | | | | | | | | | | Summary: The check was generating a fix without taking qualifiers in return type into account. This patch changes the insertion location to be before qualifers. Reviewers: gribozavr Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67213 llvm-svn: 371022
* [clang-tidy] Fix bugprone-argument-comment bug if there are marcos.Alexander Kornienko2019-09-041-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Fix bugprone-argument-comment bug if there are marcos. For example: ``` void j(int a, int b, int c); j(X(1), /*b=*/1, X(1)); ``` clang-tidy can't recognize comment "/*b=*/". It suggests fix like this: ``` j(X(1), /*b=*//*b=*/1, X(1)); ``` This change tries to fix this issue. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Patch by Yubo Xie. Differential Revision: https://reviews.llvm.org/D67080 llvm-svn: 370919
* [clang-tidy] Fix a false positive in unused-using-decl checkHaojian Wu2019-09-031-0/+9
| | | | | | | | | | The previous matcher "hasAnyTemplateArgument(templateArgument())" only matches the first template argument, but the check wants to iterate all template arguments. This patch fixes this. Also some refactorings in this patch (to make the code reusable). llvm-svn: 370760
* [clang-tidy] Add llvm-prefer-register-over-unsigned to clang-tidyDaniel Sanders2019-08-303-0/+201
| | | | | | | | | | | | | | | | | Summary: This clang-tidy check is looking for unsigned integer variables whose initializer starts with an implicit cast from llvm::Register and changes the type of the variable to llvm::Register (dropping the llvm:: where possible). Reviewers: arsenm, bogner Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, mgorny, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D65919 llvm-svn: 370512
* [clang-tidy] Fix the potential infinite loop in ↵Haojian Wu2019-08-281-0/+7
| | | | | | | | | | | | | | | | | | recordIsTriviallyDefaultConstructible. Summary: The recordIsTriviallyDefaultConstructible may cause an infinite loop when running on an ill-formed decl. Reviewers: gribozavr Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66874 llvm-svn: 370200
* [clang-tidy] readability-identifier-naming shouldn't complain about CRTP ↵Sam McCall2019-08-281-0/+26
| | | | | | | | | | | | | | pseudo-overrides Reviewers: ilya-biryukov Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66864 llvm-svn: 370193
* [clang-tidy] Manually enable exceptions in tesst that uses themBenjamin Kramer2019-08-241-1/+1
| | | | llvm-svn: 369853
* [clang-tidy] Possibility of displaying duplicate warningsKristof Umann2019-08-231-0/+15
| | | | | | | | | | | | | | | | | | Summary: In case a checker is registered multiple times as an alias, the emitted warnings are uniqued by the report message. However, it is random which checker name is included in the warning. When processing the output of clang-tidy this behavior caused some problems. In this commit the uniquing key contains the checker name too. Reviewers: alexfh, xazax.hun, Szelethus, aaron.ballman, lebedev.ri, JonasToth, gribozavr Reviewed By: alexfh Subscribers: dkrupp, whisperity, rnkovacs, mgrang, cfe-commits Patch by Tibor Brunner! Tags: #clang Differential Revision: https://reviews.llvm.org/D65065 llvm-svn: 369763
* [clang-tidy] Don't emit google-runtime-references warning for functions ↵Haojian Wu2019-08-231-0/+4
| | | | | | | | | | | | | | | | | | defined in macros. Summary: The macro are usually defined in the common/base headers which are hard for normal users to modify it. Reviewers: gribozavr, alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66631 llvm-svn: 369739
* [clang-tidy] Check for dynamically initialized statics in headers.Yuanfang Chen2019-08-211-0/+44
| | | | | | | | | | | | Finds instances where variables with static storage are initialized dynamically in header files. Reviewed By: aaron.ballman, alexfh Patch by Charles Zhang! Differential Revision: https://reviews.llvm.org/D62829 llvm-svn: 369568
* Fix typo. "piont" => "point"Richard Trieu2019-08-201-9/+9
| | | | | | Found by Chris Morris (cwmorris). llvm-svn: 369316
OpenPOWER on IntegriCloud