aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-10[clang-tidy][NFC] fix 'misc-use-internal-linkage' check warnings (#143482)Baranov Victor1-1/+1
Run misc-use-internal-linkage check over clang-tidy code. Also fixed a couple of other clang-tidy warnings. Apart from issues in header files, all '.cpp' in `clang-tools-extra/clang-tidy` must be clang-tidy clear now.
2024-06-08[clang-tidy] new check misc-use-internal-linkage (#90830)Congcong Cai1-0/+3
Add new check misc-use-internal-linkage to detect variable and function can be marked as static. --------- Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2023-10-17[clang-tidy] Add check to diagnose coroutine-hostile RAII objects (#68738)Utkarsh Saxena1-0/+3
This check detects **hostile-RAII** objects which should not **persist across a suspension point in a coroutine**. Some objects require that they be destroyed on the same thread that created them. Traditionally this requirement was often phrased as "must be a local variable", under the assumption that local variables always work this way. However this is incorrect with **C++20 coroutines**, since an intervening `co_await` may cause the coroutine to suspend and later be resumed on another thread. The lifetime of an object that requires being destroyed on the same thread must not encompass a `co_await` or `co_yield` point. If you create/destroy an object, you must do so without allowing the coroutine to suspend in the meantime. The check considers the following type as hostile: - **Scoped-lockable types**: A scoped-lockable object persisting across a suspension point is problematic as the lock held by this object could be unlocked by a different thread. This would be undefined behaviour. - Types belonging to a configurable **denylist**. ```cpp // Call some async API while holding a lock. const my::MutexLock l(&mu_); // Oops! The async Bar function may finish on a different // thread from the one that created the MutexLock object and therefore called // Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread. co_await Bar(); ```
2023-06-24[clang-tidy] Add misc-header-include-cycle checkPiotr Zegar1-0/+3
Check detects cyclic #include dependencies between user-defined headers. Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D144828
2023-06-24Revert "[clang-tidy] Add misc-header-include-cycle check"Piotr Zegar1-3/+0
This reverts commit f3aa6cc0f5d56752242203c2a9231c1bc230c15e.
2023-06-24[clang-tidy] Add misc-header-include-cycle checkPiotr Zegar1-0/+3
Check detects cyclic #include dependencies between user-defined headers. Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D144828
2023-06-02[clang-tidy] Implement an include-cleaner check.Viktoriia Bakalova1-0/+2
Differential Revision: https://reviews.llvm.org/D148793
2023-04-15Revert "[clang-tidy] Add misc-header-include-cycle check"Piotr Zegar1-3/+0
This reverts commit 9ece8753d5e6f49c31c2d988ef69225c036b25e0.
2023-04-15[clang-tidy] Add misc-header-include-cycle checkPiotr Zegar1-0/+3
Check detects cyclic #include dependencies between user-defined headers. Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D144828
2023-01-14[clang-tidy][NFC] Use C++17 nested namespaces in the clang-tidy folderCarlos Galvez1-4/+2
Fix applied by running: run-clang-tidy.py -checks=-*,modernize-concat-nested-namespaces Differential Revision: https://reviews.llvm.org/D141770
2022-12-01[clang-tidy] Add misc-use-anonymous-namespace checkCarlos Galvez1-0/+3
Differential Revision: https://reviews.llvm.org/D137340
2022-07-24[clang-tidy] implement new check 'misc-const-correctness' to add 'const' to ↵Jonas Toth1-0/+3
unmodified variables This patch connects the check for const-correctness with the new general utility to add `const` to variables. The code-transformation is only done, if the detected variable for const-ness is not part of a group-declaration. The check allows to control multiple facets of adding `const`, e.g. if pointers themself should be marked as `const` if they are not changed. Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D54943
2022-06-22[clang-tidy] Confusable identifiers detectionserge-sans-paille1-0/+3
Detect identifiers that are confusable using a variant of Unicode definition http://www.unicode.org/reports/tr39/#Confusable_Detection and have conflicting scopes. This a recommit (with portability and feature fixes) of b94db7ed7eaf4a3b21f600653a09c55cab77b79f Differential Revision: https://reviews.llvm.org/D112916
2022-06-03Revert "[clang-tidy] Confusable identifiers detection"Nico Weber1-2/+0
This reverts commit b94db7ed7eaf4a3b21f600653a09c55cab77b79f. See comments on https://reviews.llvm.org/D112916: - breaks `check-clangd`, and makes clang-tidy crash on simple inputs - likely does the wrong thing in cross builds Also revert follow-up "[gn build] (manually) port b94db7ed7eaf (Confusables.inc)" This reverts commit 180bae08a04d4dc724cb5e6f2ea9df8641a3f657.
2022-06-03[clang-tidy] Confusable identifiers detectionserge-sans-paille1-0/+2
Detect identifiers that are confusable according to Unicode definition http://www.unicode.org/reports/tr39/#Confusable_Detection and have conflicting scopes. Differential Revision: https://reviews.llvm.org/D112916
2022-01-12Misleading bidirectional detectionserge-sans-paille1-0/+3
This patch implements detection of incomplete bidirectional sequence withing comments and string literals within clang-tidy. It detects the bidi part of https://www.trojansource.codes/trojan-source.pdf Differential Revision: https://reviews.llvm.org/D112913
2021-11-10Misleading unicode identifier detection passserge-sans-paille1-0/+3
Detect when an identifier contains some Right-To-Left characters. This pass relates to https://trojansource.codes/ Example of misleading source: short int א = (short int)0; short int ג = (short int)12345; int main() { int א = ג; // a local variable, set to zero? printf("ג is %d\n", ג); printf("א is %d\n", א); } This is a recommit of 299aa4dfa1d8c120648b1404b481d858b76c8173 with missing option registration fixed. Differential Revision: https://reviews.llvm.org/D112914
2021-11-09Revert "Misleading unicode identifier detection pass"serge-sans-paille1-3/+0
This reverts commit 7f92a1a84b96ff0b7568a35704c9483e9f24f057. It triggers an assert, see http://45.33.8.238/linux/60293/step_9.txt "AST/Decl.h:277: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed."
2021-11-09Misleading unicode identifier detection passserge-sans-paille1-0/+3
Detect when an identifier contains some Right-To-Left characters. This pass relates to https://trojansource.codes/ This is a recommit of 299aa4dfa1d8c120648b1404b481d858b76c8173 with missing option registration fixed. Differential Revision: https://reviews.llvm.org/D112914
2020-02-13[clang-tidy] misc-no-recursion: a new checkRoman Lebedev1-0/+2
Summary: Recursion is a powerful tool, but like any tool without care it can be dangerous. For example, if the recursion is unbounded, you will eventually run out of stack and crash. You can of course track the recursion depth but if it is hardcoded, there can always be some other environment when that depth is too large, so said magic number would need to be env-dependent. But then your program's behavior is suddenly more env-dependent. Also, recursion, while it does not outright stop optimization, recursive calls are less great than normal calls, for example they hinder inlining. Recursion is banned in some coding guidelines: * SEI CERT DCL56-CPP. Avoid cycles during initialization of static objects * JPL 2.4 Do not use direct or indirect recursion. * I'd say it is frowned upon in LLVM, although not banned And is plain unsupported in some cases: * OpenCL 1.2, 6.9 Restrictions: i. Recursion is not supported. So there's clearly a lot of reasons why one might want to avoid recursion, and replace it with worklist handling. It would be great to have a enforcement for it though. This implements such a check. Here we detect both direct and indirect recursive calls, although since clang-tidy (unlike clang static analyzer) is CTU-unaware, if the recursion transcends a single standalone TU, we will naturally not find it :/ The algorithm is pretty straight-forward: 1. Build call-graph for the entire TU. For that, the existing `clang::CallGraph` is re-used, although it had to be modified to also track the location of the call. 2. Then, the hard problem: how do we detect recursion? Since we have a graph, let's just do the sane thing, and look for Strongly Connected Function Declarations - widely known as `SCC`. For that LLVM provides `llvm::scc_iterator`, which is internally an Tarjan's DFS algorithm, and is used throught LLVM, so this should be as performant as possible. 3. Now that we've got SCC's, we discard those that don't contain loops. Note that there may be more than one loop in SCC! 4. For each loopy SCC, we call out each function, and print a single example call graph that shows recursion -- it didn't seem worthwhile enumerating every possible loop in SCC, although i suppose it could be implemented. * To come up with that call graph cycle example, we start at first SCC node, see which callee of the node is within SCC (and is thus known to be in cycle), and recurse into it until we hit the callee that is already in call stack. Reviewers: JonasToth, aaron.ballman, ffrankies, Eugene.Zelenko, erichkeane, NoQ Reviewed By: aaron.ballman Subscribers: Charusso, Naghasan, bader, riccibruno, mgorny, Anastasia, xazax.hun, cfe-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D72362
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
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
2018-10-18[clang-tidy] Non-private member variables in classes (MISRA, ↵Roman Lebedev1-0/+3
CppCoreGuidelines, HICPP) Summary: Finds classes that not only contain the data (non-static member variables), but also have logic (non-static member functions), and diagnoses all member variables that have any other scope other than `private`. They should be made `private`, and manipulated exclusively via the member functions. Optionally, classes with all member variables being `public` could be ignored, and optionally all `public` member variables could be ignored. Options ------- * IgnoreClassesWithAllMemberVariablesBeingPublic Allows to completely ignore classes if **all** the member variables in that class have `public` visibility. * IgnorePublicMemberVariables Allows to ignore (not diagnose) **all** the member variables with `public` visibility scope. References: * MISRA 11-0-1 Member data in non-POD class types shall be private. * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-private * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-protected Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, zinovy.nis, cfe-commits, rnkovacs, nemanjai, mgorny, xazax.hun, kbarton Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52771 llvm-svn: 344757
2018-09-20[Clang-tidy] Alphabetical sort of files/checks. Add space after clang-tidy ↵Eugene Zelenko1-3/+3
in source code headers. llvm-svn: 342601
2018-03-15[clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii ↵Alexander Kornienko1-2/+0
--check_class_name=UnusedRAIICheck llvm-svn: 327610
2018-03-15[clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-containerAlexander Kornienko1-2/+0
llvm-svn: 327608
2018-03-15[clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expressionAlexander Kornienko1-3/+0
llvm-svn: 327607
2018-03-15[clang-tidy] rename_check.py {misc,bugprone}-macro-parenthesesAlexander Kornienko1-3/+0
llvm-svn: 327606
2018-02-28[clang-tidy] Another batch of checks to rename from misc- to bugprone-.Alexander Kornienko1-12/+0
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
2018-02-28Rename more checks from misc- to bugprone-.Alexander Kornienko1-12/+0
Summary: clang-tidy/rename_check.py {misc,bugprone}-string-integer-assignment clang-tidy/rename_check.py {misc,bugprone}-string-literal-with-embedded-nul clang-tidy/rename_check.py {misc,bugprone}-suspicious-enum-usage clang-tidy/rename_check.py {misc,bugprone}-suspicious-missing-comma Reviewers: hokein, sammccall, aaron.ballman Subscribers: klimek, cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D43868 llvm-svn: 326384
2018-02-28Rename a few checks from misc- to bugprone-.Alexander Kornienko1-12/+0
Summary: rename_check.py {misc,bugprone}-forwarding-reference-overload rename_check.py {misc,bugprone}-macro-repeated-side-effects rename_check.py {misc,bugprone}-lambda-function-name rename_check.py {misc,bugprone}-misplaced-widening-cast Reviewers: hokein, sammccall, aaron.ballman Reviewed By: aaron.ballman Subscribers: klimek, cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D43867 llvm-svn: 326327
2018-01-30clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundingsAlexander Kornienko1-3/+0
More specifically, clang-tidy/rename_check.py misc-incorrect-roundings \ bugprone-incorrect-roundings --check_class_name IncorrectRoundings llvm-svn: 323768
2018-01-30clang-tidy/rename_check.py misc-string-compare readability-string-compareAlexander Kornienko1-2/+0
llvm-svn: 323766
2017-11-28[clang-tidy] Move more checks from misc- to performance-Alexander Kornienko1-6/+0
Summary: rename_check.py misc-move-const-arg performance-move-const-arg rename_check.py misc-noexcept-move-constructor performance-noexcept-move-constructor Reviewers: hokein, xazax.hun Reviewed By: xazax.hun Subscribers: rnkovacs, klimek, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40507 llvm-svn: 319183
2017-11-27[clang-tidy] Move checks from misc- to performance-Alexander Kornienko1-6/+0
Summary: rename_check.py misc-move-constructor-init performance-move-constructor-init rename_check.py misc-inefficient-algorithm performance-inefficient-algorithm Reviewers: hokein, aaron.ballman Reviewed By: hokein, aaron.ballman Subscribers: aaron.ballman, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40487 llvm-svn: 319023
2017-11-24[clang-tidy] Move a few more checks from misc to bugprone.Alexander Kornienko1-24/+0
Summary: clang_tidy/rename_check.py misc-assert-side-effect bugprone-assert-side-effect clang_tidy/rename_check.py misc-bool-pointer-implicit-conversion bugprone-bool-pointer-implicit-conversion clang_tidy/rename_check.py misc-fold-init-type bugprone-fold-init-type clang_tidy/rename_check.py misc-forward-declaration-namespace bugprone-forward-declaration-namespace clang_tidy/rename_check.py misc-inaccurate-erase bugprone-inaccurate-erase clang_tidy/rename_check.py misc-move-forwarding-reference bugprone-move-forwarding-reference clang_tidy/rename_check.py misc-multiple-statement-macro bugprone-multiple-statement-macro clang_tidy/rename_check.py misc-use-after-move bugprone-use-after-move clang_tidy/rename_check.py misc-virtual-near-miss bugprone-virtual-near-miss Manually fixed a reference to UseAfterMoveCheck in the hicpp module. Manually fixed header guards. Reviewers: hokein Reviewed By: hokein Subscribers: nemanjai, mgorny, javed.absar, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D40426 llvm-svn: 318950
2017-11-24[clang-tidy] rename_check.py misc-dangling-handle bugprone-dangling-handleAlexander Kornienko1-2/+0
Reviewers: hokein Reviewed By: hokein Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40389 llvm-svn: 318941
2017-11-23[clang-tidy] rename_check.py misc-argument-comment bugprone-argument-commentAlexander Kornienko1-2/+0
Summary: + manually convert the unit test to lit test. Reviewers: hokein Reviewed By: hokein Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40392 llvm-svn: 318926
2017-11-23[clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructorAlexander Kornienko1-3/+0
Summary: Rename misc-string-constructor to bugprone-string-constructor + manually update the lenght of '==='s in the doc file. Reviewers: hokein, xazax.hun Reviewed By: hokein, xazax.hun Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40388 llvm-svn: 318916
2017-06-02[clang-tidy] check for __func__/__FUNCTION__ in lambdasAlexander Kornienko1-0/+3
Add a clang-tidy check for using func__/FUNCTION__ inside lambdas. This evaluates to the string operator(), which is almost never useful and almost certainly not what the author intended. Patch by Bryce Liu! Differential Revision: https://reviews.llvm.org/D33497 llvm-svn: 304570
2017-04-06[clang-tidy] Check for forwarding reference overload in constructors.Gabor Horvath1-0/+3
Patch by András Leitereg! Differential Revision: https://reviews.llvm.org/D30547 llvm-svn: 299638
2016-12-30[clang-tidy] Add check 'misc-string-compare'.Mads Ravn1-0/+2
I have a created a new check for clang tidy: misc-string-compare. This will check for incorrect usage of std::string::compare when used to check equality or inequality of string instead of the string equality or inequality operators. Example: ``` std::string str1, str2; if (str1.compare(str2)) { } ``` Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons Subscribers: xazax.hun, Eugene.Zelenko, cfe-commits, malcolm.parsons, Prazek, mgorny, JDevlieghere Differential Revision: https://reviews.llvm.org/D27210 llvm-svn: 290747
2016-12-27[clang-tidy] Add enum misuse check.Gabor Horvath1-0/+3
The checker detects various cases when an enum is probably misused (as a bitmask). Patch by: Peter Szecsi! Differential Revision: https://reviews.llvm.org/D22507 llvm-svn: 290600
2016-11-08[clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang1-13/+8
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
2016-10-21Remove 'misc-pointer-and-integral-operation' clang-tidy check. The only casesRichard Smith1-3/+0
it detects are ill-formed (some per C++ core issue 1512, others always have been). llvm-svn: 284888
2016-09-14[clang-tidy] Add check 'misc-use-after-move'Martin Bohme1-0/+2
Summary: The check warns if an object is used after it has been moved, without an intervening reinitialization. See user-facing documentation for details. Reviewers: sbenza, Prazek, alexfh Subscribers: beanz, mgorny, shadeware, omtcyfz, Eugene.Zelenko, Prazek, fowles, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D23353 llvm-svn: 281453
2016-08-30[clang-tidy] Add check 'misc-move-forwarding-reference'Martin Bohme1-0/+3
Summary: The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type. If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference. This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite. As a fix, the check will suggest replacing the std::move() with a std::forward(). This patch requires D23004 to be submitted before it. Reviewers: sbenza, aaron.ballman Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits Projects: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D22220 llvm-svn: 280077
2016-08-01[clang-tidy] remove trailing whitespaces and retabKirill Bobyrev1-1/+1
llvm-svn: 277340
2016-06-07Add the misc-misplaced-const check to clang-tidy, which diagnoses when a ↵Aaron Ballman1-0/+3
const-qualifier is applied to a typedef of pointer type rather than to the pointee type. llvm-svn: 272025
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