1 //===--- CERTTidyModule.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 "../bugprone/BadSignalToKillThreadCheck.h" 13 #include "../bugprone/ReservedIdentifierCheck.h" 14 #include "../bugprone/SignalHandlerCheck.h" 15 #include "../bugprone/SignedCharMisuseCheck.h" 16 #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h" 17 #include "../bugprone/UnhandledSelfAssignmentCheck.h" 18 #include "../google/UnnamedNamespaceInHeaderCheck.h" 19 #include "../misc/NewDeleteOverloadsCheck.h" 20 #include "../misc/NonCopyableObjects.h" 21 #include "../misc/StaticAssertCheck.h" 22 #include "../misc/ThrowByValueCatchByReferenceCheck.h" 23 #include "../performance/MoveConstructorInitCheck.h" 24 #include "../readability/UppercaseLiteralSuffixCheck.h" 25 #include "CommandProcessorCheck.h" 26 #include "DefaultOperatorNewAlignmentCheck.h" 27 #include "DontModifyStdNamespaceCheck.h" 28 #include "FloatLoopCounter.h" 29 #include "LimitedRandomnessCheck.h" 30 #include "MutatingCopyCheck.h" 31 #include "NonTrivialTypesLibcMemoryCallsCheck.h" 32 #include "PostfixOperatorCheck.h" 33 #include "ProperlySeededRandomGeneratorCheck.h" 34 #include "SetLongJmpCheck.h" 35 #include "StaticObjectExceptionCheck.h" 36 #include "StrToNumCheck.h" 37 #include "ThrownExceptionTypeCheck.h" 38 #include "VariadicFunctionDefCheck.h" 39 40 namespace clang { 41 namespace tidy { 42 namespace cert { 43 44 class CERTModule : public ClangTidyModule { 45 public: addCheckFactories(ClangTidyCheckFactories & CheckFactories)46 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { 47 // C++ checkers 48 // CON 49 CheckFactories.registerCheck<bugprone::SpuriouslyWakeUpFunctionsCheck>( 50 "cert-con54-cpp"); 51 // DCL 52 CheckFactories.registerCheck<PostfixOperatorCheck>( 53 "cert-dcl21-cpp"); 54 CheckFactories.registerCheck<VariadicFunctionDefCheck>("cert-dcl50-cpp"); 55 CheckFactories.registerCheck<bugprone::ReservedIdentifierCheck>( 56 "cert-dcl51-cpp"); 57 CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>( 58 "cert-dcl54-cpp"); 59 CheckFactories.registerCheck<DontModifyStdNamespaceCheck>( 60 "cert-dcl58-cpp"); 61 CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( 62 "cert-dcl59-cpp"); 63 // ERR 64 CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( 65 "cert-err09-cpp"); 66 CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp"); 67 CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp"); 68 CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp"); 69 CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( 70 "cert-err61-cpp"); 71 // MEM 72 CheckFactories.registerCheck<DefaultOperatorNewAlignmentCheck>( 73 "cert-mem57-cpp"); 74 // MSC 75 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp"); 76 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>( 77 "cert-msc51-cpp"); 78 // OOP 79 CheckFactories.registerCheck<performance::MoveConstructorInitCheck>( 80 "cert-oop11-cpp"); 81 CheckFactories.registerCheck<bugprone::UnhandledSelfAssignmentCheck>( 82 "cert-oop54-cpp"); 83 CheckFactories.registerCheck<NonTrivialTypesLibcMemoryCallsCheck>( 84 "cert-oop57-cpp"); 85 CheckFactories.registerCheck<MutatingCopyCheck>( 86 "cert-oop58-cpp"); 87 88 // C checkers 89 // CON 90 CheckFactories.registerCheck<bugprone::SpuriouslyWakeUpFunctionsCheck>( 91 "cert-con36-c"); 92 // DCL 93 CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c"); 94 CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>( 95 "cert-dcl16-c"); 96 CheckFactories.registerCheck<bugprone::ReservedIdentifierCheck>( 97 "cert-dcl37-c"); 98 // ENV 99 CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c"); 100 // FLP 101 CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c"); 102 // FIO 103 CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c"); 104 // ERR 105 CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c"); 106 // MSC 107 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c"); 108 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>( 109 "cert-msc32-c"); 110 // POS 111 CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>( 112 "cert-pos44-c"); 113 // SIG 114 CheckFactories.registerCheck<bugprone::SignalHandlerCheck>("cert-sig30-c"); 115 // STR 116 CheckFactories.registerCheck<bugprone::SignedCharMisuseCheck>( 117 "cert-str34-c"); 118 } 119 getModuleOptions()120 ClangTidyOptions getModuleOptions() override { 121 ClangTidyOptions Options; 122 ClangTidyOptions::OptionMap &Opts = Options.CheckOptions; 123 Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU"; 124 Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0"; 125 Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "0"; 126 return Options; 127 } 128 }; 129 130 } // namespace cert 131 132 // Register the MiscTidyModule using this statically initialized variable. 133 static ClangTidyModuleRegistry::Add<cert::CERTModule> 134 X("cert-module", 135 "Adds lint checks corresponding to CERT secure coding guidelines."); 136 137 // This anchor is used to force the linker to link in the generated object file 138 // and thus register the CERTModule. 139 volatile int CERTModuleAnchorSource = 0; 140 141 } // namespace tidy 142 } // namespace clang 143