Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 1 | //===--- 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 Ballman | a742b84 | 2015-10-13 20:42:41 +0000 | [diff] [blame] | 18 | #include "../misc/ThrowByValueCatchByReferenceCheck.h" |
Aaron Ballman | 527a420 | 2016-02-22 16:01:06 +0000 | [diff] [blame] | 19 | #include "CommandProcessorCheck.h" |
Aaron Ballman | 611d2e4 | 2016-02-19 14:03:20 +0000 | [diff] [blame] | 20 | #include "FloatLoopCounter.h" |
Aaron Ballman | e4b1765 | 2015-10-08 19:54:43 +0000 | [diff] [blame] | 21 | #include "SetLongJmpCheck.h" |
Aaron Ballman | 43aef4c | 2015-12-01 14:05:39 +0000 | [diff] [blame] | 22 | #include "StaticObjectExceptionCheck.h" |
Aaron Ballman | d744e63 | 2016-04-29 20:56:48 +0000 | [diff] [blame] | 23 | #include "StrToNumCheck.h" |
Aaron Ballman | 5a786dd | 2015-11-16 19:17:43 +0000 | [diff] [blame] | 24 | #include "ThrownExceptionTypeCheck.h" |
Aaron Ballman | 46bc304 | 2015-10-05 20:08:59 +0000 | [diff] [blame] | 25 | #include "VariadicFunctionDefCheck.h" |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 26 | |
| 27 | namespace clang { |
| 28 | namespace tidy { |
Aaron Ballman | 1284f04 | 2016-01-04 14:31:14 +0000 | [diff] [blame] | 29 | namespace cert { |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 30 | |
| 31 | class CERTModule : public ClangTidyModule { |
| 32 | public: |
| 33 | void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { |
| 34 | // C++ checkers |
| 35 | // DCL |
Aaron Ballman | 46bc304 | 2015-10-05 20:08:59 +0000 | [diff] [blame] | 36 | CheckFactories.registerCheck<VariadicFunctionDefCheck>( |
| 37 | "cert-dcl50-cpp"); |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 38 | CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>( |
| 39 | "cert-dcl54-cpp"); |
| 40 | CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( |
| 41 | "cert-dcl59-cpp"); |
| 42 | // OOP |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 43 | CheckFactories.registerCheck<misc::MoveConstructorInitCheck>( |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 44 | "cert-oop11-cpp"); |
Aaron Ballman | e4b1765 | 2015-10-08 19:54:43 +0000 | [diff] [blame] | 45 | // ERR |
| 46 | CheckFactories.registerCheck<SetLongJmpCheck>( |
| 47 | "cert-err52-cpp"); |
Aaron Ballman | 43aef4c | 2015-12-01 14:05:39 +0000 | [diff] [blame] | 48 | CheckFactories.registerCheck<StaticObjectExceptionCheck>( |
| 49 | "cert-err58-cpp"); |
Aaron Ballman | 5a786dd | 2015-11-16 19:17:43 +0000 | [diff] [blame] | 50 | CheckFactories.registerCheck<ThrownExceptionTypeCheck>( |
| 51 | "cert-err60-cpp"); |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 52 | CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( |
Aaron Ballman | a742b84 | 2015-10-13 20:42:41 +0000 | [diff] [blame] | 53 | "cert-err61-cpp"); |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 54 | |
| 55 | // C checkers |
| 56 | // DCL |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 57 | CheckFactories.registerCheck<misc::StaticAssertCheck>( |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 58 | "cert-dcl03-c"); |
Aaron Ballman | 527a420 | 2016-02-22 16:01:06 +0000 | [diff] [blame] | 59 | // ENV |
| 60 | CheckFactories.registerCheck<CommandProcessorCheck>( |
| 61 | "cert-env33-c"); |
Aaron Ballman | 611d2e4 | 2016-02-19 14:03:20 +0000 | [diff] [blame] | 62 | // FLP |
| 63 | CheckFactories.registerCheck<FloatLoopCounter>( |
| 64 | "cert-flp30-c"); |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 65 | // FIO |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 66 | CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>( |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 67 | "cert-fio38-c"); |
Aaron Ballman | d744e63 | 2016-04-29 20:56:48 +0000 | [diff] [blame] | 68 | // ERR |
| 69 | CheckFactories.registerCheck<StrToNumCheck>( |
| 70 | "cert-err34-c"); |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 71 | } |
Alexander Kornienko | 5d08bb7 | 2016-05-20 13:42:40 +0000 | [diff] [blame^] | 72 | ClangTidyOptions getModuleOptions() override { |
| 73 | ClangTidyOptions Options; |
| 74 | Options.CheckOptions["cert-oop11-cpp.UseCERTSemantics"] = "1"; |
| 75 | return Options; |
| 76 | } |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Aaron Ballman | 1284f04 | 2016-01-04 14:31:14 +0000 | [diff] [blame] | 79 | } // namespace cert |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 80 | |
| 81 | // Register the MiscTidyModule using this statically initialized variable. |
Aaron Ballman | 1284f04 | 2016-01-04 14:31:14 +0000 | [diff] [blame] | 82 | static ClangTidyModuleRegistry::Add<cert::CERTModule> |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 83 | X("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. |
| 88 | volatile int CERTModuleAnchorSource = 0; |
| 89 | |
| 90 | } // namespace tidy |
| 91 | } // namespace clang |