summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/bugprone
Commit message (Collapse)AuthorAgeFilesLines
* Fix crash in InfinteLoopCheckNathan James2020-02-171-0/+2
| | | | (cherry picked from commit 8c4cf23dee1ac3f259c4795b275cc9bb1234aa29)
* [clang-tidy] Added check to disable bugprone-infinite-loop on known false ↵Nathan James2020-02-121-0/+10
| | | | | | | | | | | | | | | | | | condition Summary: Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=44816 | bugprone-infinite-loop false positive with CATCH2 ]] by disabling the check on loops where the condition is known to always eval as false, in other words not a loop. Reviewers: aaron.ballman, alexfh, hokein, gribozavr2, JonasToth Reviewed By: gribozavr2 Subscribers: xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D74374 (cherry picked from commit c69ec6476806147e46bf09b693acb24177982dc2)
* [clan-tidy] Fix false positive in bugprone-infinite-loopAdam Balogh2020-01-291-4/+20
| | | | | | | | | | | | | | The checker bugprone-infinite-loop does not track changes of variables in the initialization expression of a variable declared inside the condition of the while statement. This leads to false positives, similarly to the one in the bug report https://bugs.llvm.org/show_bug.cgi?id=44618. This patch fixes this issue by enabling tracking of the variables of this expression as well. Differential Revision: https://reviews.llvm.org/D73270 (cherry picked from commit 70f4c6e7b14f225f9628fbdab3620ce037613351)
* [clang-tidy] Fix check for generic lambda invented template parametersSaar Raz2020-01-241-1/+1
| | | | | | | | | clang-tidy previously relied on there being no identifier for a TemplateTypeParmDecl for checking whether 'decltype(x)' should be inserted, instead of checking whether or not it is implicit. D65042 added new names for invented generic lambda template parameters, rendering that check incorrect. (cherry picked from commit 5fdad8e3f803adce501ca25118f325184e54018d)
* [clang-tidy] Disable Checks on If constexpr statements in template ↵Nathan2020-01-231-1/+2
| | | | | | | | | | | | | | | | | | Instantiations for BugproneBranchClone and ReadabilityBracesAroundStatements Summary: fixes [[ https://bugs.llvm.org/show_bug.cgi?id=32203 | readability-braces-around-statements broken for if constexpr]] and [[ https://bugs.llvm.org/show_bug.cgi?id=44229 | bugprone-branch-clone false positive with template functions and constexpr ]] by disabling the relevant checks on if constexpr statements while inside an instantiated template. This is due to how the else branch of an if constexpr statement is folded away to a null statement if the condition evaluates to false Reviewers: alexfh, hokein, aaron.ballman, xazax.hun Reviewed By: aaron.ballman, xazax.hun Subscribers: rnkovacs, JonasToth, Jim, lebedev.ri, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D71980 (cherry picked from commit f9c46229e4ac29053747c96e08c574c6c48d544b)
* [clang-tidy] new check: bugprone-signed-char-misuseTamás Zolnai2020-01-064-0/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check searches for signed char -> integer conversions which might indicate programming error, because of the misinterpretation of char values. A signed char might store the non-ASCII characters as negative values. The human programmer probably expects that after an integer conversion the converted value matches with the character code (a value from [0..255]), however, the actual value is in [-128..127] interval. See also: STR34-C. Cast characters to unsigned char before converting to larger integer sizes <https://wiki.sei.cmu.edu/confluence/display/c/STR34-C.+Cast+characters+to+unsigned+char+before+converting+to+larger+integer+sizes> By now this check is limited to assignment / variable declarations. If we would catch all signed char -> integer conversion, then it would produce a lot of findings and also false positives. So I added only this use case now, but this check can be extended with additional use cases later. The CERT documentation mentions another use case when the char is used for array subscript. Next to that a third use case can be the signed char - unsigned char comparison, which also a use case where things happen unexpectedly because of conversion to integer. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: aaron.ballman Subscribers: sylvestre.ledru, whisperity, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D71174
* NFC: Fix trivial typos in commentsKazuaki Ishizaki2020-01-042-2/+2
|
* Fix trivial typos in comments; NFCKazuaki Ishizaki2020-01-021-1/+1
|
* [Clang-Tidy] Quick fix for bug in bugprone-macro-parentheses 43804Adam Balogh2019-12-021-1/+1
| | | | | | | | | Applying parentheses for statement leads to compilation error. Bug [[ 43804 | https://bugs.llvm.org/show_bug.cgi?id=43804 ]] is a compilation error suggested by a wrong fix of this checker. This patch is a quick fix for this issue. Differential Revision: https://reviews.llvm.org/D70850
* [clang-tidy] Fix PR35824Gabor Horvath2019-11-271-1/+2
| | | | Differential Revision: https://reviews.llvm.org/D46027
* Remove +x permission on some filesSylvestre Ledru2019-11-162-0/+0
|
* Avoid including Builtins.h in Preprocessor.hReid Kleckner2019-11-151-0/+1
| | | | | | Builtins are rarely if ever accessed via the Preprocessor. They are typically found on the ASTContext, so there should be no performance penalty to using a pointer indirection to store the builtin context.
* [clang-tidy] Add bugprone-bad-signal-to-kill-thread check and its alias ↵Abel Kocsis2019-11-114-0/+111
| | | | cert-pos44-c
* Revert "[clang-tidy] Add bugprone-bad-signal-to-kill-thread checker and ↵Abel Kocsis2019-11-114-111/+0
| | | | | | alias cert-pos44-c" This reverts commit 4edf0cb0e03e31d468979d0d7dec08bd9f4f8204.
* [clang-tidy] Add bugprone-bad-signal-to-kill-thread checker and alias ↵Abel Kocsis2019-11-114-0/+111
| | | | cert-pos44-c
* [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 2Csaba Dabis2019-10-131-7/+8
| | | | llvm-svn: 374712
* [clang-tidy] bugprone-not-null-terminated-result: checker adjustmentsCsaba Dabis2019-10-131-6/+6
| | | | llvm-svn: 374711
* [clang-tidy] New checker for not null-terminated result caused by strlen(), ↵Csaba Dabis2019-10-134-0/+1077
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Fix for commits rL372706 and rL372711Adam Balogh2019-10-021-9/+8
| | | | | | | | | 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] Add missing InfiniteLoopCheck.h, InfiniteLoopCheck.cpp and test ↵Fangrui Song2019-09-244-0/+228
| | | | | | from D64736 llvm-svn: 372706
* Revert rL372693 : [clang-tidy] New bugprone-infinite-loop check for ↵Simon Pilgrim2019-09-242-4/+0
| | | | | | | | | | | | | | | | | | detecting obvious infinite loops Finding infinite loops is well-known to be impossible (halting problem). However, it is possible to detect some obvious infinite loops, for example, if the loop condition is not changed. Detecting such loops is beneficial since the tests will hang on programs containing infinite loops so testing-time detection may be costly in large systems. Obvious cases are where the programmer forgets to increment/decrement the counter or increments/decrements the wrong variable. Differential Revision: https://reviews.llvm.org/D64736 ------- Broke some buildbots "No SOURCES given to target: obj.clangTidyBugproneModule" llvm-svn: 372704
* [clang-tidy] New bugprone-infinite-loop check for detecting obvious infinite ↵Adam Balogh2019-09-242-0/+4
| | | | | | | | | | | | | | | | loops Finding infinite loops is well-known to be impossible (halting problem). However, it is possible to detect some obvious infinite loops, for example, if the loop condition is not changed. Detecting such loops is beneficial since the tests will hang on programs containing infinite loops so testing-time detection may be costly in large systems. Obvious cases are where the programmer forgets to increment/decrement the counter or increments/decrements the wrong variable. Differential Revision: https://reviews.llvm.org/D64736 llvm-svn: 372693
* Removed an incorred namespace-end commentDmitri Gribenko2019-09-231-1/+1
| | | | llvm-svn: 372593
* [clang-tidy] Fix bugprone-argument-comment-check to correctly ignore ↵Yitzhak Mandelbaum2019-09-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] add checks to bugprone-posix-returnJian Cai2019-09-162-16/+21
| | | | | | 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] Make most ArgumentCommentCheck options local, as they should beAlexander Kornienko2019-09-051-13/+8
| | | | llvm-svn: 371076
* Add a bugprone-argument-comment option: IgnoreSingleArgument.Alexander Kornienko2019-09-052-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 bugprone-argument-comment bug if there are marcos.Alexander Kornienko2019-09-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove \brief commands from doxygen comments.Dmitri Gribenko2019-08-225-7/+7
| | | | | | | | | | | | | | | | | | | | | | | Summary: We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done [This is analogous to LLVM r331272 and CFE r331834] Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66578 llvm-svn: 369643
* [clang-tidy] Check for dynamically initialized statics in headers.Yuanfang Chen2019-08-214-0/+115
| | | | | | | | | | | | 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
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-144-5/+5
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clang-tidy] Fix crash on end location inside macroNathan Huckleberry2019-07-171-6/+11
| | | | | | | | | | | | | | | | | | | | Summary: Lexer::getLocForEndOfToken is defined to return an invalid location if the given location is inside a macro. Other checks conditionally warn based off location validity. Updating this check to do the same. Reviewers: JonasToth, aaron.ballman, nickdesaulniers Reviewed By: nickdesaulniers Subscribers: lebedev.ri, nickdesaulniers, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64607 llvm-svn: 366353
* Simplify with llvm::is_contained. NFCFangrui Song2019-07-132-3/+2
| | | | llvm-svn: 365993
* [clang-tidy] new check: bugprone-posix-returnDmitri Gribenko2019-07-034-0/+116
| | | | | | | | | | | | | | | | | | | | Summary: Checks if any calls to posix functions (except posix_openpt) expect negative return values. These functions return either 0 on success or an errno on failure, which is positive only. Reviewers: JonasToth, gribozavr, alexfh, hokein Reviewed By: gribozavr Subscribers: Eugene.Zelenko, lebedev.ri, llozano, george.burgess.iv, xazax.hun, srhines, mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63623 Patch by Jian Cai. llvm-svn: 365007
* [clang-tidy] Fix typo in bugprone-string-constructor.Clement Courbet2019-06-111-1/+1
| | | | | | s/bigger then/bigger than/ llvm-svn: 363053
* [clang-tidy]: Add cert-oop54-cpp alias for bugprone-unhandled-self-assignmentTamas Zolnai2019-05-232-25/+44
| | | | | | | | | | | | | | | | | | | | Summary: Added WarnOnlyIfThisHasSuspiciousField option to allow to catch any copy assignment operator independently from the container class's fields. Added the cert alias using this option. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: mgorny, Eugene.Zelenko, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62192 llvm-svn: 361550
* [clang-tidy] Sort this list alphabeticallyTamas Zolnai2019-05-201-2/+2
| | | | llvm-svn: 361138
* [clang-tidy] new check: bugprone-branch-cloneKristof Umann2019-05-154-0/+269
| | | | | | | | | | | | | 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 Donát Nagy! Differential Revision: https://reviews.llvm.org/D54757 llvm-svn: 360779
* [clang-tidy] new check: bugprone-unhandled-self-assignmentTamas Zolnai2019-05-124-0/+139
| | | | | | | | | | | | | | | | | | | | | Summary: This check searches for copy assignment operators which might not handle self-assignment properly. There are three patterns of handling a self assignment situation: self check, copy-and-swap or the less common copy-and-move. The new check warns if none of these patterns is found in a user defined implementation. See also: OOP54-CPP. Gracefully handle self-copy assignment https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP54-CPP.+Gracefully+handle+self-copy+assignment Reviewers: JonasToth, alexfh, hokein, aaron.ballman Subscribers: riccibruno, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D60507 llvm-svn: 360540
* [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to ↵Adam Balogh2019-05-071-2/+9
| | | | | | | | | | | | structures) Accidentally taking the size of a struct-pointer type or a value of this type is more common than explicitly using the & operator for the value. This patch extends the check to include these cases. Differential Revision: https://reviews.llvm.org/D61260 llvm-svn: 360114
* [clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse ↵Adam Balogh2019-05-061-2/+55
| | | | | | | | | | | | | | | in pointer arithmetic Some programmers tend to forget that subtracting two pointers results in the difference between them in number of elements of the pointee type instead of bytes. This leads to codes such as `size_t size = (p - q) / sizeof(int)` where `p` and `q` are of type `int*`. Or similarily, `if (p - q < buffer_size * sizeof(int)) { ... }`. This patch extends `bugprone-sizeof-expression` to detect such cases. Differential Revision: https://reviews.llvm.org/D61422 llvm-svn: 360032
* Added an AST matcher for declarations that are in the `std` namespaceDmitri Gribenko2019-05-031-4/+0
| | | | | | | | | | | | Reviewers: alexfh Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61480 llvm-svn: 359876
* [clang-tidy] Add MagnitudeBitsUpperLimit option to ↵Tamas Zolnai2019-04-142-20/+38
| | | | | | | | | | | | | | | | | | | | | bugprone-too-small-loop-variable Summary: The bugprone-too-small-loop-variable check often catches loop variables which can represent "big enough" values, so we don't actually need to worry about that this variable will overflow in a loop when the code iterates through a container. For example a 32 bit signed integer type's maximum value is 2 147 483 647 and a container's size won't reach this maximum value in most of the cases. So the idea of this option to allow the user to specify an upper limit (using magnitude bit of the integer type) to filter out those catches which are not interesting for the user, so he/she can focus on the more risky integer incompatibilities. Next to the option I replaced the term "positive bits" to "magnitude bits" which seems a better naming both in the code and in the name of the new option. Reviewers: JonasToth, alexfh, aaron.ballman, hokein Reviewed By: JonasToth Subscribers: Eugene.Zelenko, xazax.hun, jdoerfert, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D59870 llvm-svn: 358356
* Make SourceManager::createFileID(UnownedTag, ...) take a const ↵Nico Weber2019-04-041-1/+1
| | | | | | | | | | | | | | | | | | | | | llvm::MemoryBuffer* Requires making the llvm::MemoryBuffer* stored by SourceManager const, which in turn requires making the accessors for that return const llvm::MemoryBuffer*s and updating all call sites. The original motivation for this was to use it and fix the TODO in CodeGenAction.cpp's ConvertBackendLocation() by using the UnownedTag version of createFileID, and since llvm::SourceMgr* hands out a const llvm::MemoryBuffer* this is required. I'm not sure if fixing the TODO this way actually works, but this seems like a good change on its own anyways. No intended behavior change. Differential Revision: https://reviews.llvm.org/D60247 llvm-svn: 357724
* [clang-tidy] Switch checks to #include "ClangTidyCheck.h"Alexander Kornienko2019-03-2540-40/+40
| | | | llvm-svn: 356892
* [clang-tidy] Fix more false positives for bugprone-string-integer-assignmentClement Courbet2019-03-251-23/+84
| | | | | | | | | | | | | | | | | Summary: And add various tests gleaned for our codebase. See PR27723. Reviewers: JonasToth, alexfh, xazax.hun Subscribers: rnkovacs, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59360 llvm-svn: 356871
* [clang-tidy] Move all checks to the new registerPPCallbacks APIAlexander Kornienko2019-03-226-15/+15
| | | | llvm-svn: 356796
* [clang-tidy] Fix bugprone-string-constructor crashAlexander Kornienko2019-03-051-1/+2
| | | | llvm-svn: 355401
* [clang-tidy] bugprone-string-integer-assignment: Reduce false positives.Clement Courbet2019-02-281-0/+29
| | | | | | | | | | | | | | Summary: Detect a few expressions as likely character expressions, see PR27723. Reviewers: xazax.hun, alexfh Subscribers: rnkovacs, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58609 llvm-svn: 355089
OpenPOWER on IntegriCloud