1 //===--- BugproneTidyModule.cpp - clang-tidy ------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "../ClangTidy.h"
10 #include "../ClangTidyModule.h"
11 #include "../ClangTidyModuleRegistry.h"
12 #include "../cppcoreguidelines/NarrowingConversionsCheck.h"
13 #include "ArgumentCommentCheck.h"
14 #include "AssertSideEffectCheck.h"
15 #include "BadSignalToKillThreadCheck.h"
16 #include "BoolPointerImplicitConversionCheck.h"
17 #include "BranchCloneCheck.h"
18 #include "CopyConstructorInitCheck.h"
19 #include "DanglingHandleCheck.h"
20 #include "DynamicStaticInitializersCheck.h"
21 #include "ExceptionEscapeCheck.h"
22 #include "FoldInitTypeCheck.h"
23 #include "ForwardDeclarationNamespaceCheck.h"
24 #include "ForwardingReferenceOverloadCheck.h"
25 #include "InaccurateEraseCheck.h"
26 #include "IncorrectRoundingsCheck.h"
27 #include "InfiniteLoopCheck.h"
28 #include "IntegerDivisionCheck.h"
29 #include "LambdaFunctionNameCheck.h"
30 #include "MacroParenthesesCheck.h"
31 #include "MacroRepeatedSideEffectsCheck.h"
32 #include "MisplacedOperatorInStrlenInAllocCheck.h"
33 #include "MisplacedWideningCastCheck.h"
34 #include "MoveForwardingReferenceCheck.h"
35 #include "MultipleStatementMacroCheck.h"
36 #include "NotNullTerminatedResultCheck.h"
37 #include "ParentVirtualCallCheck.h"
38 #include "PosixReturnCheck.h"
39 #include "SizeofContainerCheck.h"
40 #include "SizeofExpressionCheck.h"
41 #include "StringConstructorCheck.h"
42 #include "StringIntegerAssignmentCheck.h"
43 #include "StringLiteralWithEmbeddedNulCheck.h"
44 #include "SuspiciousEnumUsageCheck.h"
45 #include "SuspiciousMemsetUsageCheck.h"
46 #include "SuspiciousMissingCommaCheck.h"
47 #include "SuspiciousSemicolonCheck.h"
48 #include "SuspiciousStringCompareCheck.h"
49 #include "SwappedArgumentsCheck.h"
50 #include "TerminatingContinueCheck.h"
51 #include "ThrowKeywordMissingCheck.h"
52 #include "TooSmallLoopVariableCheck.h"
53 #include "UndefinedMemoryManipulationCheck.h"
54 #include "UndelegatedConstructorCheck.h"
55 #include "UnhandledSelfAssignmentCheck.h"
56 #include "UnusedRaiiCheck.h"
57 #include "UnusedReturnValueCheck.h"
58 #include "UseAfterMoveCheck.h"
59 #include "VirtualNearMissCheck.h"
60 
61 namespace clang {
62 namespace tidy {
63 namespace bugprone {
64 
65 class BugproneModule : public ClangTidyModule {
66 public:
67   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
68     CheckFactories.registerCheck<ArgumentCommentCheck>(
69         "bugprone-argument-comment");
70     CheckFactories.registerCheck<AssertSideEffectCheck>(
71         "bugprone-assert-side-effect");
72     CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
73         "bugprone-bad-signal-to-kill-thread");
74     CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
75         "bugprone-bool-pointer-implicit-conversion");
76     CheckFactories.registerCheck<BranchCloneCheck>(
77         "bugprone-branch-clone");
78     CheckFactories.registerCheck<CopyConstructorInitCheck>(
79         "bugprone-copy-constructor-init");
80     CheckFactories.registerCheck<DanglingHandleCheck>(
81         "bugprone-dangling-handle");
82     CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
83         "bugprone-dynamic-static-initializers");
84     CheckFactories.registerCheck<ExceptionEscapeCheck>(
85         "bugprone-exception-escape");
86     CheckFactories.registerCheck<FoldInitTypeCheck>(
87         "bugprone-fold-init-type");
88     CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
89         "bugprone-forward-declaration-namespace");
90     CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
91         "bugprone-forwarding-reference-overload");
92     CheckFactories.registerCheck<InaccurateEraseCheck>(
93         "bugprone-inaccurate-erase");
94     CheckFactories.registerCheck<IncorrectRoundingsCheck>(
95         "bugprone-incorrect-roundings");
96     CheckFactories.registerCheck<InfiniteLoopCheck>(
97         "bugprone-infinite-loop");
98     CheckFactories.registerCheck<IntegerDivisionCheck>(
99         "bugprone-integer-division");
100     CheckFactories.registerCheck<LambdaFunctionNameCheck>(
101         "bugprone-lambda-function-name");
102     CheckFactories.registerCheck<MacroParenthesesCheck>(
103         "bugprone-macro-parentheses");
104     CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
105         "bugprone-macro-repeated-side-effects");
106     CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
107         "bugprone-misplaced-operator-in-strlen-in-alloc");
108     CheckFactories.registerCheck<MisplacedWideningCastCheck>(
109         "bugprone-misplaced-widening-cast");
110     CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
111         "bugprone-move-forwarding-reference");
112     CheckFactories.registerCheck<MultipleStatementMacroCheck>(
113         "bugprone-multiple-statement-macro");
114     CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
115         "bugprone-narrowing-conversions");
116     CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
117         "bugprone-not-null-terminated-result");
118     CheckFactories.registerCheck<ParentVirtualCallCheck>(
119         "bugprone-parent-virtual-call");
120     CheckFactories.registerCheck<PosixReturnCheck>(
121         "bugprone-posix-return");
122     CheckFactories.registerCheck<SizeofContainerCheck>(
123         "bugprone-sizeof-container");
124     CheckFactories.registerCheck<SizeofExpressionCheck>(
125         "bugprone-sizeof-expression");
126     CheckFactories.registerCheck<StringConstructorCheck>(
127         "bugprone-string-constructor");
128     CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
129         "bugprone-string-integer-assignment");
130     CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
131         "bugprone-string-literal-with-embedded-nul");
132     CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
133         "bugprone-suspicious-enum-usage");
134     CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
135         "bugprone-suspicious-memset-usage");
136     CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
137         "bugprone-suspicious-missing-comma");
138     CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
139         "bugprone-suspicious-semicolon");
140     CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
141         "bugprone-suspicious-string-compare");
142     CheckFactories.registerCheck<SwappedArgumentsCheck>(
143         "bugprone-swapped-arguments");
144     CheckFactories.registerCheck<TerminatingContinueCheck>(
145         "bugprone-terminating-continue");
146     CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
147         "bugprone-throw-keyword-missing");
148     CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
149         "bugprone-too-small-loop-variable");
150     CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
151         "bugprone-undefined-memory-manipulation");
152     CheckFactories.registerCheck<UndelegatedConstructorCheck>(
153         "bugprone-undelegated-constructor");
154     CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(
155         "bugprone-unhandled-self-assignment");
156     CheckFactories.registerCheck<UnusedRaiiCheck>(
157         "bugprone-unused-raii");
158     CheckFactories.registerCheck<UnusedReturnValueCheck>(
159         "bugprone-unused-return-value");
160     CheckFactories.registerCheck<UseAfterMoveCheck>(
161         "bugprone-use-after-move");
162     CheckFactories.registerCheck<VirtualNearMissCheck>(
163         "bugprone-virtual-near-miss");
164   }
165 };
166 
167 } // namespace bugprone
168 
169 // Register the BugproneTidyModule using this statically initialized variable.
170 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
171     X("bugprone-module", "Adds checks for bugprone code constructs.");
172 
173 // This anchor is used to force the linker to link in the generated object file
174 // and thus register the BugproneModule.
175 volatile int BugproneModuleAnchorSource = 0;
176 
177 } // namespace tidy
178 } // namespace clang
179