blob: 1a0d9c5485733b36488a325034ed7fe8c6b05df0 [file] [log] [blame]
Aaron Ballmanea2f90c2015-10-02 13:27:19 +00001//===--- CERTTidyModule.cpp - clang-tidy ----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "../ClangTidy.h"
11#include "../ClangTidyModule.h"
12#include "../ClangTidyModuleRegistry.h"
13#include "../google/UnnamedNamespaceInHeaderCheck.h"
14#include "../misc/MoveConstructorInitCheck.h"
15#include "../misc/NewDeleteOverloadsCheck.h"
16#include "../misc/NonCopyableObjects.h"
17#include "../misc/StaticAssertCheck.h"
Aaron Ballmana742b842015-10-13 20:42:41 +000018#include "../misc/ThrowByValueCatchByReferenceCheck.h"
Aaron Ballman527a4202016-02-22 16:01:06 +000019#include "CommandProcessorCheck.h"
Aaron Ballman611d2e42016-02-19 14:03:20 +000020#include "FloatLoopCounter.h"
Aaron Ballmane4b17652015-10-08 19:54:43 +000021#include "SetLongJmpCheck.h"
Aaron Ballman43aef4c2015-12-01 14:05:39 +000022#include "StaticObjectExceptionCheck.h"
Aaron Ballmand744e632016-04-29 20:56:48 +000023#include "StrToNumCheck.h"
Aaron Ballman5a786dd2015-11-16 19:17:43 +000024#include "ThrownExceptionTypeCheck.h"
Aaron Ballman46bc3042015-10-05 20:08:59 +000025#include "VariadicFunctionDefCheck.h"
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000026
27namespace clang {
28namespace tidy {
Aaron Ballman1284f042016-01-04 14:31:14 +000029namespace cert {
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000030
31class CERTModule : public ClangTidyModule {
32public:
33 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
34 // C++ checkers
35 // DCL
Aaron Ballman46bc3042015-10-05 20:08:59 +000036 CheckFactories.registerCheck<VariadicFunctionDefCheck>(
37 "cert-dcl50-cpp");
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000038 CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
39 "cert-dcl54-cpp");
40 CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
41 "cert-dcl59-cpp");
42 // OOP
Etienne Bergeron456177b2016-05-02 18:00:29 +000043 CheckFactories.registerCheck<misc::MoveConstructorInitCheck>(
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000044 "cert-oop11-cpp");
Aaron Ballmane4b17652015-10-08 19:54:43 +000045 // ERR
46 CheckFactories.registerCheck<SetLongJmpCheck>(
47 "cert-err52-cpp");
Aaron Ballman43aef4c2015-12-01 14:05:39 +000048 CheckFactories.registerCheck<StaticObjectExceptionCheck>(
49 "cert-err58-cpp");
Aaron Ballman5a786dd2015-11-16 19:17:43 +000050 CheckFactories.registerCheck<ThrownExceptionTypeCheck>(
51 "cert-err60-cpp");
Etienne Bergeron456177b2016-05-02 18:00:29 +000052 CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
Aaron Ballmana742b842015-10-13 20:42:41 +000053 "cert-err61-cpp");
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000054
55 // C checkers
56 // DCL
Etienne Bergeron456177b2016-05-02 18:00:29 +000057 CheckFactories.registerCheck<misc::StaticAssertCheck>(
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000058 "cert-dcl03-c");
Aaron Ballman527a4202016-02-22 16:01:06 +000059 // ENV
60 CheckFactories.registerCheck<CommandProcessorCheck>(
61 "cert-env33-c");
Aaron Ballman611d2e42016-02-19 14:03:20 +000062 // FLP
63 CheckFactories.registerCheck<FloatLoopCounter>(
64 "cert-flp30-c");
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000065 // FIO
Etienne Bergeron456177b2016-05-02 18:00:29 +000066 CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>(
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000067 "cert-fio38-c");
Aaron Ballmand744e632016-04-29 20:56:48 +000068 // ERR
69 CheckFactories.registerCheck<StrToNumCheck>(
70 "cert-err34-c");
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000071 }
Alexander Kornienko5d08bb72016-05-20 13:42:40 +000072 ClangTidyOptions getModuleOptions() override {
73 ClangTidyOptions Options;
74 Options.CheckOptions["cert-oop11-cpp.UseCERTSemantics"] = "1";
75 return Options;
76 }
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000077};
78
Aaron Ballman1284f042016-01-04 14:31:14 +000079} // namespace cert
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000080
81// Register the MiscTidyModule using this statically initialized variable.
Aaron Ballman1284f042016-01-04 14:31:14 +000082static ClangTidyModuleRegistry::Add<cert::CERTModule>
Aaron Ballmanea2f90c2015-10-02 13:27:19 +000083X("cert-module",
84 "Adds lint checks corresponding to CERT secure coding guidelines.");
85
86// This anchor is used to force the linker to link in the generated object file
87// and thus register the CERTModule.
88volatile int CERTModuleAnchorSource = 0;
89
90} // namespace tidy
91} // namespace clang