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