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 "MisplacedPointerArithmeticInAllocCheck.h"
34 #include "MisplacedWideningCastCheck.h"
35 #include "MoveForwardingReferenceCheck.h"
36 #include "MultipleStatementMacroCheck.h"
37 #include "NoEscapeCheck.h"
38 #include "NotNullTerminatedResultCheck.h"
39 #include "ParentVirtualCallCheck.h"
40 #include "PosixReturnCheck.h"
41 #include "RedundantBranchConditionCheck.h"
42 #include "ReservedIdentifierCheck.h"
43 #include "SignalHandlerCheck.h"
44 #include "SignedCharMisuseCheck.h"
45 #include "SizeofContainerCheck.h"
46 #include "SizeofExpressionCheck.h"
47 #include "SpuriouslyWakeUpFunctionsCheck.h"
48 #include "StringConstructorCheck.h"
49 #include "StringIntegerAssignmentCheck.h"
50 #include "StringLiteralWithEmbeddedNulCheck.h"
51 #include "SuspiciousEnumUsageCheck.h"
52 #include "SuspiciousIncludeCheck.h"
53 #include "SuspiciousMemsetUsageCheck.h"
54 #include "SuspiciousMissingCommaCheck.h"
55 #include "SuspiciousSemicolonCheck.h"
56 #include "SuspiciousStringCompareCheck.h"
57 #include "SwappedArgumentsCheck.h"
58 #include "TerminatingContinueCheck.h"
59 #include "ThrowKeywordMissingCheck.h"
60 #include "TooSmallLoopVariableCheck.h"
61 #include "UndefinedMemoryManipulationCheck.h"
62 #include "UndelegatedConstructorCheck.h"
63 #include "UnhandledSelfAssignmentCheck.h"
64 #include "UnusedRaiiCheck.h"
65 #include "UnusedReturnValueCheck.h"
66 #include "UseAfterMoveCheck.h"
67 #include "VirtualNearMissCheck.h"
68 
69 namespace clang {
70 namespace tidy {
71 namespace bugprone {
72 
73 class BugproneModule : public ClangTidyModule {
74 public:
addCheckFactories(ClangTidyCheckFactories & CheckFactories)75   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
76     CheckFactories.registerCheck<ArgumentCommentCheck>(
77         "bugprone-argument-comment");
78     CheckFactories.registerCheck<AssertSideEffectCheck>(
79         "bugprone-assert-side-effect");
80     CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
81         "bugprone-bad-signal-to-kill-thread");
82     CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
83         "bugprone-bool-pointer-implicit-conversion");
84     CheckFactories.registerCheck<BranchCloneCheck>(
85         "bugprone-branch-clone");
86     CheckFactories.registerCheck<CopyConstructorInitCheck>(
87         "bugprone-copy-constructor-init");
88     CheckFactories.registerCheck<DanglingHandleCheck>(
89         "bugprone-dangling-handle");
90     CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
91         "bugprone-dynamic-static-initializers");
92     CheckFactories.registerCheck<ExceptionEscapeCheck>(
93         "bugprone-exception-escape");
94     CheckFactories.registerCheck<FoldInitTypeCheck>(
95         "bugprone-fold-init-type");
96     CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
97         "bugprone-forward-declaration-namespace");
98     CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
99         "bugprone-forwarding-reference-overload");
100     CheckFactories.registerCheck<InaccurateEraseCheck>(
101         "bugprone-inaccurate-erase");
102     CheckFactories.registerCheck<IncorrectRoundingsCheck>(
103         "bugprone-incorrect-roundings");
104     CheckFactories.registerCheck<InfiniteLoopCheck>(
105         "bugprone-infinite-loop");
106     CheckFactories.registerCheck<IntegerDivisionCheck>(
107         "bugprone-integer-division");
108     CheckFactories.registerCheck<LambdaFunctionNameCheck>(
109         "bugprone-lambda-function-name");
110     CheckFactories.registerCheck<MacroParenthesesCheck>(
111         "bugprone-macro-parentheses");
112     CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
113         "bugprone-macro-repeated-side-effects");
114     CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
115         "bugprone-misplaced-operator-in-strlen-in-alloc");
116     CheckFactories.registerCheck<MisplacedPointerArithmeticInAllocCheck>(
117         "bugprone-misplaced-pointer-arithmetic-in-alloc");
118     CheckFactories.registerCheck<MisplacedWideningCastCheck>(
119         "bugprone-misplaced-widening-cast");
120     CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
121         "bugprone-move-forwarding-reference");
122     CheckFactories.registerCheck<MultipleStatementMacroCheck>(
123         "bugprone-multiple-statement-macro");
124     CheckFactories.registerCheck<RedundantBranchConditionCheck>(
125         "bugprone-redundant-branch-condition");
126     CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
127         "bugprone-narrowing-conversions");
128     CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
129     CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
130         "bugprone-not-null-terminated-result");
131     CheckFactories.registerCheck<ParentVirtualCallCheck>(
132         "bugprone-parent-virtual-call");
133     CheckFactories.registerCheck<PosixReturnCheck>(
134         "bugprone-posix-return");
135     CheckFactories.registerCheck<ReservedIdentifierCheck>(
136         "bugprone-reserved-identifier");
137     CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
138     CheckFactories.registerCheck<SignedCharMisuseCheck>(
139         "bugprone-signed-char-misuse");
140     CheckFactories.registerCheck<SizeofContainerCheck>(
141         "bugprone-sizeof-container");
142     CheckFactories.registerCheck<SizeofExpressionCheck>(
143         "bugprone-sizeof-expression");
144     CheckFactories.registerCheck<SpuriouslyWakeUpFunctionsCheck>(
145         "bugprone-spuriously-wake-up-functions");
146     CheckFactories.registerCheck<StringConstructorCheck>(
147         "bugprone-string-constructor");
148     CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
149         "bugprone-string-integer-assignment");
150     CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
151         "bugprone-string-literal-with-embedded-nul");
152     CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
153         "bugprone-suspicious-enum-usage");
154     CheckFactories.registerCheck<SuspiciousIncludeCheck>(
155         "bugprone-suspicious-include");
156     CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
157         "bugprone-suspicious-memset-usage");
158     CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
159         "bugprone-suspicious-missing-comma");
160     CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
161         "bugprone-suspicious-semicolon");
162     CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
163         "bugprone-suspicious-string-compare");
164     CheckFactories.registerCheck<SwappedArgumentsCheck>(
165         "bugprone-swapped-arguments");
166     CheckFactories.registerCheck<TerminatingContinueCheck>(
167         "bugprone-terminating-continue");
168     CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
169         "bugprone-throw-keyword-missing");
170     CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
171         "bugprone-too-small-loop-variable");
172     CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
173         "bugprone-undefined-memory-manipulation");
174     CheckFactories.registerCheck<UndelegatedConstructorCheck>(
175         "bugprone-undelegated-constructor");
176     CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(
177         "bugprone-unhandled-self-assignment");
178     CheckFactories.registerCheck<UnusedRaiiCheck>(
179         "bugprone-unused-raii");
180     CheckFactories.registerCheck<UnusedReturnValueCheck>(
181         "bugprone-unused-return-value");
182     CheckFactories.registerCheck<UseAfterMoveCheck>(
183         "bugprone-use-after-move");
184     CheckFactories.registerCheck<VirtualNearMissCheck>(
185         "bugprone-virtual-near-miss");
186   }
187 };
188 
189 } // namespace bugprone
190 
191 // Register the BugproneTidyModule using this statically initialized variable.
192 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
193     X("bugprone-module", "Adds checks for bugprone code constructs.");
194 
195 // This anchor is used to force the linker to link in the generated object file
196 // and thus register the BugproneModule.
197 volatile int BugproneModuleAnchorSource = 0;
198 
199 } // namespace tidy
200 } // namespace clang
201