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