summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/bugprone
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-tidy] misc-string-integer-assignment: fix false positiveClement Courbet2019-02-281-2/+7
| | | | | | | | | | | | | | | | | | | | Summary: using CodePoint = uint32_t; CodePoint cp; basic_string<CodePoint> s; s += cp; See PR27723. Reviewers: xazax.hun, alexfh Subscribers: rnkovacs, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58606 llvm-svn: 355076
* [clang-tidy] misc-string-integer-assignment: ignore toupper/tolowerClement Courbet2019-02-251-4/+9
| | | | | | | | | | | | | | Summary: Tis represents ~20% of false positives. See PR27723. Reviewers: xazax.hun, alexfh Subscribers: rnkovacs, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58604 llvm-svn: 354780
* [clang-tidy] refactor ExceptionAnalyzer further to give ternary answerJonas Toth2019-02-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: The analsis on the throwing behvaiour on functions and statements gave only a binary answer whether an exception could occur and if yes which types are thrown. This refactoring allows keeping track if there is a unknown factor, because the code calls to some functions with unavailable source code with no `noexcept` information. This 'potential Unknown' information is propagated properly and can be queried separately. Reviewers: lebedev.ri, aaron.ballman, baloghadamsoftware, alexfh Reviewed By: lebedev.ri, baloghadamsoftware Subscribers: xazax.hun, rnkovacs, a.sidorin, Szelethus, donat.nagy, dkrupp, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57883 llvm-svn: 354517
* [clang-tidy][NFCI] DanglingHandleCheck: Remove a superflous IgnoreParenImpCastsBruno Ricci2019-02-171-3/+2
| | | | | | | | | | | | ExprWithCleanups is currently not skipped by IgnoreParenImpCasts, but is skipped by IgnoreImpCasts. In view of fixing this inconsistency in D57267, remove the IgnoreParenImpCasts between the ReturnStmt and the ExprWithCleanups which is not needed since ExprWithCleanups is always created as a direct child of ReturnStmt (by inspection of each ReturnStmt::Create in Sema/SemaStmt.cpp). NFC intended. llvm-svn: 354228
* [clang-tidy] Add options to bugprone-argument-comment to add missing ↵Paul Hoad2019-02-082-12/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | argument comments to literals bugprone-argument-comment only supports identifying those comments which do not match the function parameter name This revision add 3 options to adding missing argument comments to literals (granularity on type is added to control verbosity of fixit) ``` CheckOptions: - key: bugprone-argument-comment.CommentBoolLiterals value: '1' - key: bugprone-argument-comment.CommentFloatLiterals value: '1' - key: bugprone-argument-comment.CommentIntegerLiterals value: '1' - key: bugprone-argument-comment.CommentStringLiterals value: '1' - key: bugprone-argument-comment.CommentCharacterLiterals value: '1' - key: bugprone-argument-comment.CommentUserDefinedLiterals value: '1' - key: bugprone-argument-comment.CommentNullPtrs value: '1' ``` After applying these options, literal arguments will be preceded with /*ParameterName=*/ Reviewers: JonasToth, Eugene.Zelenko, alexfh, hokein, aaron.ballman Reviewed By: aaron.ballman, Eugene.Zelenko Differential Revision: https://reviews.llvm.org/D57674 llvm-svn: 353535
* [clang-tidy] refactor bugprone-exception-escape analysis into classJonas Toth2019-01-312-151/+20
| | | | | | | | | | | | | | | | | | | | | | Summary: The check `bugprone-exception-escape` does an AST-based analysis to determine if a function might throw an exception and warns based on that information. The analysis part is refactored into a standalone class similiar to `ExprMutAnalyzer` that is generally useful. I intent to use that class in a new check to automatically introduce `noexcept` if possible. Reviewers: aaron.ballman, alexfh, hokein, baloghadamsoftware, lebedev.ri Reviewed By: baloghadamsoftware, lebedev.ri Subscribers: lebedev.ri, mgorny, xazax.hun, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D57100 llvm-svn: 352741
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-1981-324/+243
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-tidy] bugprone-string-constructor: Catch string from nullptr.Clement Courbet2019-01-161-0/+16
| | | | | | | | | | Summary: Context: https://twitter.com/willkirkby/status/1084219580799741953 Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D56657 llvm-svn: 351308
* [clang-tidy] Treat references to smart pointers correctly in use-after-move.Martin Bohme2019-01-161-1/+1
| | | | | | | | | | | | | | | | | | | Summary: Previously, we weren't recognizing these as smart pointers and thus weren't allowing non-dereference accesses as we should -- see new test cases which fail without the fix. Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: JonasToth Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D56585 llvm-svn: 351303
* Adapt to CXXMethodDecl::getThisType change (NFC)Brian Gesiak2019-01-111-3/+1
| | | | | | | | | Summary: https://reviews.llvm.org/D56509 changed the API of the CXXMethodDecl::getThisType method. Adapt to the change (and re-apply clang-format) to fix the clang-tidy build. llvm-svn: 350916
* Revert "[clang-tidy] new check: bugprone-branch-clone"Jonas Toth2018-12-054-258/+0
| | | | | | | The patch broke on buildbot with assertion-failure. Revert until this is figured out. llvm-svn: 348344
* [clang-tidy] new check: bugprone-branch-cloneJonas Toth2018-12-054-0/+258
| | | | | | | | | | | | | | | | | | | | | | Summary: 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 donat.nagy. Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: JonasToth Subscribers: MTC, lebedev.ri, whisperity, xazax.hun, Eugene.Zelenko, mgorny, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D54757 llvm-svn: 348343
* Fix a false positive in misplaced-widening-castJonas Toth2018-12-051-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: bugprone-misplaced-widening-cast check used to give a false warning to the following example. enum DaysEnum{ MON = 0, TUE = 1 }; day = (DaysEnum)(day + 1); //warning: either cast from 'int' to 'DaysEnum' is ineffective... But i think int to enum cast is not widening neither ineffective. Patch by dkrupp. Reviewers: JonasToth, alexfh Reviewed By: alexfh Subscribers: rnkovacs, Szelethus, gamesh411, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D55255 llvm-svn: 348341
* Re-commit r347419 "Update call to EvaluateAsInt() to the new syntax."Hans Wennborg2018-11-282-14/+21
| | | | llvm-svn: 347757
* Revert r347419 "Update call to EvaluateAsInt() to the new syntax."Hans Wennborg2018-11-272-21/+14
| | | | | | It's pre-requisite was reverted in r347656. llvm-svn: 347657
* A bit of AST matcher cleanup, NFC.Alexander Kornienko2018-11-255-28/+28
| | | | | | | | | Removed the uses of the allOf() matcher inside node matchers that are implicit allOf(). Replaced uses of allOf() with the explicit node matcher where it makes matchers more readable. Replace anyOf(hasName(), hasName(), ...) with the more efficient and readable hasAnyName(). llvm-svn: 347520
* Update call to EvaluateAsInt() to the new syntax.Bill Wendling2018-11-212-14/+21
| | | | llvm-svn: 347419
* Revert 347366, its prerequisite 347364 got reverted.Nico Weber2018-11-212-21/+14
| | | | llvm-svn: 347390
* Update EvaluateAsInt to the new syntax.Bill Wendling2018-11-202-14/+21
| | | | llvm-svn: 347366
* [clang-tidy] new check: bugprone-too-small-loop-variableJonas Toth2018-11-124-0/+215
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The new checker searches for those for loops which has a loop variable with a "too small" type which means this type can't represent all values which are part of the iteration range. For example: ``` int main() { long size = 300000; for( short int i = 0; i < size; ++i) {} } ``` The short type leads to infinite loop here because it can't store all values in the `[0..size]` interval. In a real use case, size means a container's size which depends on the user input. Which means for small amount of objects the algorithm works, but with a larger user input the software will freeze. The idea of the checker comes from the LibreOffice project, where the same check was implemented as a clang compiler plugin, called `LoopVarTooSmall` (LLVM licensed). The idea is the same behind this check, but the code is different because of the different framework. Patch by ztamas. Reviewers: alexfh, hokein, aaron.ballman, JonasToth, xazax.hun, whisperity Reviewed By: JonasToth, whisperity Differential Revision: https://reviews.llvm.org/D53974 llvm-svn: 346665
* [AST] Refactor PredefinedExprBruno Ricci2018-10-271-3/+3
| | | | | | | | | | | | | | | | | | Make the following changes to PredefinedExpr: 1. Move PredefinedExpr below StringLiteral so that it can use its definition. 2. Rename IdentType to IdentKind to be more in line with clang's conventions, and propagate the change to its users. 3. Move the location and the IdentKind into the newly available space of the bit-fields of Stmt. 4. Only store the function name when needed. When parsing all of Boost, of the 1357 PredefinedExpr 919 have no function name. Differential Revision: https://reviews.llvm.org/D53605 Reviewed By: rjmccall llvm-svn: 345460
* [clang-tidy] Optimize query in bugprone-exception-escapeAdam Balogh2018-10-131-3/+3
| | | | | | | | | | | | Checking whether a functions throws indirectly may be very expensive because it needs to visit its whole call graph. Therefore we should first check whether the function is forbidden to throw and only check whether it throws afterward. This also seems to solve bug https://bugs.llvm.org/show_bug.cgi?id=39167 where the execution time is so long that it seems to hang. Differential Revision: https://reviews.llvm.org/D53187 llvm-svn: 344444
* Revert "[clang-tidy] New checker for not null-terminated result caused by ↵Jonas Toth2018-10-134-1095/+0
| | | | | | | | strlen(), size() or equal length" This reverts commit r344374. llvm-svn: 344442
* [clang-tidy] New checker for not null-terminated result caused by strlen(), ↵Jonas Toth2018-10-124-0/+1095
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | size() or equal length New checker called bugprone-not-null-terminated-result. This check 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 function calls are checked: memcpy, wmemcpy, memcpy_s, wmemcpy_s, memchr, wmemchr, memmove, wmemmove, memmove_s, wmemmove_s, memset, wmemset, strerror_s, strncmp, wcsncmp, strxfrm, wcsxfrm 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 problematic too. static char *StringCpy(const std::string &str) { char *result = reinterpret_cast<char *>(malloc(str.size())); memcpy(result, str.data(), str.size()); return result; } After running the tool fix-it rewrites all the necessary code according to the given options. If it is necessary, the buffer size will be increased to hold the null terminator. static char *StringCpy(const std::string &str) { char *result = reinterpret_cast<char *>(malloc(str.size() + 1)); strcpy(result, str.data()); return result; } Patch by Charusso. Differential ID: https://reviews.llvm.org/D45050 llvm-svn: 344374
* [clang-tidy] NFC refactor lexer-utils to be usable without ASTContextJonas Toth2018-10-052-3/+5
| | | | | | | | | | | | | | | | | | | Summary: This patch is a small refactoring necessary for 'readability-isolate-declaration' and does not introduce functional changes. It allows to use the utility functions without a full `ASTContext` and requires only the `SourceManager` and the `LangOpts`. Reviewers: alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52684 llvm-svn: 343850
* [clang-tidy] fix PR39167, bugprone-exception-escape hangs-upJonas Toth2018-10-041-0/+3
| | | | | | | | | | | | | | | | | Summary: The check bugprone-exception-escape should not register if -fno-exceptions is set for the compile options. Bailing out on non-cplusplus and non-exceptions language options resolves the issue. Reviewers: alexfh, aaron.ballman, baloghadamsoftware Reviewed By: alexfh Subscribers: lebedev.ri, xazax.hun, rnkovacs, cfe-commits Differential Revision: https://reviews.llvm.org/D52880 llvm-svn: 343789
* [clang-tidy] Sequence statements with multiple parents correctly (PR39149)Martin Bohme2018-10-041-2/+3
| | | | | | | | | | | | | | | | | | | | | Summary: Before this fix, the bugprone-use-after-move check could incorrectly conclude that a use and move in a function template were not sequenced. For details, see https://bugs.llvm.org/show_bug.cgi?id=39149 Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52782 llvm-svn: 343768
* [clang-tidy] Recognize [[clang::reinitializes]] attribute in ↵Martin Bohme2018-08-131-0/+4
| | | | | | | | | | | | | | | | | | | | | | | bugprone-use-after-move Summary: This allows member functions to be marked as reinitializing the object. After a moved-from object has been reinitialized, the check will no longer consider it to be in an indeterminate state. The patch that adds the attribute itself is at https://reviews.llvm.org/D49911 Reviewers: ilya-biryukov, aaron.ballman, alexfh, hokein, rsmith Reviewed By: aaron.ballman Subscribers: dblaikie, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D49910 llvm-svn: 339571
* Port getLocEnd -> getEndLocStephen Kelly2018-08-097-9/+9
| | | | | | | | Subscribers: nemanjai, ioeric, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D50355 llvm-svn: 339401
* Port getLocStart -> getBeginLocStephen Kelly2018-08-0929-65/+67
| | | | | | | | | | 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] Exception Escape CheckerAdam Balogh2018-07-134-0/+265
| | | | | | | | | | | Finds functions which may throw an exception directly or indirectly, but they should not: Destructors, move constructors, move assignment operators, the main() function, swap() functions, functions marked with throw() or noexcept and functions given as option to the checker. Differential Revision: https://reviews.llvm.org/D33537 llvm-svn: 336997
* [clang-tidy] new cppcoreguidelines-narrowing-conversions check.Clement Courbet2018-05-232-0/+4
| | | | | | | | | | | | | | | | | | | Summary: Checks for narrowing conversions, e.g. int i = 0; i += 0.1; This has what some might consider false positives for: i += ceil(d); Reviewers: alexfh, hokein Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38455 llvm-svn: 333066
* [clang-tidy] Add terminating continue checkGabor Horvath2018-05-144-0/+89
| | | | | | | | Patch by: Daniel Kolozsvari! Differential Revision: https://reviews.llvm.org/D33844 llvm-svn: 332223
* Fix up after clang r331155.Richard Smith2018-04-302-7/+8
| | | | llvm-svn: 331156
* [clang-tidy] Improve bugprone-unused-return-value checkJonathan Coe2018-04-241-10/+28
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add support for checking class template member functions. Also add the following functions to be checked by default: - std::unique_ptr::release - std::basic_string::empty - std::vector::empty Reviewers: alexfh, hokein, aaron.ballman, ilya-biryukov Reviewed By: aaron.ballman Subscribers: jbcoe, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D45891 Patch by khuttun (Kalle Huttunen) llvm-svn: 330772
* [clang-tidy] Fix ParentVirtualCallCheck for old MSVS compilersZinovy Nis2018-04-131-1/+2
| | | | llvm-svn: 329999
* [clang-tidy] [bugprone-parent-virtual-call] Minor cosmetic changes. NFCZinovy Nis2018-04-131-16/+11
| | | | llvm-svn: 329994
* Fix unused variable warning.Chandler Carruth2018-04-091-0/+1
| | | | llvm-svn: 329550
* [clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cppZinovy Nis2018-04-071-8/+7
| | | | | | | | There's an error for PSP4 platform only: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\algorithm(95): error C2719: '_Pred': formal parameter with requested alignment of 8 won't be aligned llvm-svn: 329495
* [clang-tidy] One more fix compilation for ParentVirtualCallCheck.cpp: ↵Zinovy Nis2018-04-061-2/+5
| | | | | | find_if predicate llvm-svn: 329454
* [clang-tidy] Fix compilation for ParentVirtualCallCheck.cppZinovy Nis2018-04-061-7/+10
| | | | llvm-svn: 329452
* [clang-tidy] Check if grand-..parent's virtual method was called instead of ↵Zinovy Nis2018-04-064-0/+193
| | | | | | | | | | | | | overridden parent's. class A {...int virtual foo() {...}...}; class B: public A {...int foo() override {...}...}; class C: public B {...int foo() override {... A::foo()...}}; ^^^^^^^^ warning: qualified name A::foo refers to a member overridden in subclass; did you mean 'B'? [bugprone-parent-virtual-call] Differential Revision: https://reviews.llvm.org/D44295 llvm-svn: 329448
* [clang-tidy] Check for sizeof that call functionsHaojian Wu2018-04-032-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: A common mistake that I have found in our codebase is calling a function to get an integer or enum that represents the type such as: ``` int numBytes = numElements * sizeof(x.GetType()); ``` So this extends the `sizeof` check to check for these cases. There is also a `WarnOnSizeOfCall` option so it can be disabled. Patch by Paul Fultz II! Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov Reviewed By: alexfh Subscribers: lebedev.ri, xazax.hun, jkorous-apple, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D44231 llvm-svn: 329073
* [clang-tidy] New check bugprone-unused-return-valueAlexander Kornienko2018-03-194-0/+125
| | | | | | | | | | | | | | | | | | | | | Summary: Detects function calls where the return value is unused. Checked functions can be configured. Reviewers: alexfh, aaron.ballman, ilya-biryukov, hokein Reviewed By: alexfh, aaron.ballman Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra Patch by Kalle Huttunen! Differential Revision: https://reviews.llvm.org/D41655 llvm-svn: 327833
* [clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii ↵Alexander Kornienko2018-03-154-0/+133
| | | | | | --check_class_name=UnusedRAIICheck llvm-svn: 327610
* Fixed filename in a comment. NFCAlexander Kornienko2018-03-151-1/+1
| | | | llvm-svn: 327609
* [clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-containerAlexander Kornienko2018-03-154-0/+89
| | | | llvm-svn: 327608
* [clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expressionAlexander Kornienko2018-03-154-0/+309
| | | | llvm-svn: 327607
* [clang-tidy] rename_check.py {misc,bugprone}-macro-parenthesesAlexander Kornienko2018-03-154-0/+307
| | | | llvm-svn: 327606
* [clang-tidy] Another batch of checks to rename from misc- to bugprone-.Alexander Kornienko2018-02-2810-0/+641
| | | | | | | | | | | | | | | | Summary: clang-tidy/rename_check.py {misc,bugprone}-suspicious-semicolon clang-tidy/rename_check.py {misc,bugprone}-suspicious-string-compare clang-tidy/rename_check.py {misc,bugprone}-swapped-arguments clang-tidy/rename_check.py {misc,bugprone}-undelegated-constructor --check_class_name UndelegatedConstructor Reviewers: hokein, sammccall, aaron.ballman Subscribers: klimek, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D43870 llvm-svn: 326386
OpenPOWER on IntegriCloud