aaron.ballman created this revision. aaron.ballman added reviewers: alexfh, sbenza. aaron.ballman added a subscriber: cfe-commits.
CERT produces a set of secure coding rules and recommendations for both C (https://www.securecoding.cert.org/confluence/display/c/SEI+CERT+C+Coding+Standard) and C++ (https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=637). One of the tasks we've been doing lately is mapping existing checks to our rules, as well as coming up with new checks where there is insufficient existing coverage for a rule. This patch adds a new module so that users can enable CERT-specific checkers by using -checks=-*,cert-*. Currently, this is remapping existing checkers under a new name that matches the CERT guideline the checker matches. However, this also is a convenient place for us to hang CERT-specific rules that do not apply elsewhere. This patch does not come with any tests because the only thing we could test is the name change for reported diagnostics, and I wasn't certain whether that was worth testing. One thing this patch does not do is enable tests for static analyzer checkers under new names. For instance, I would like to have a way to map clang-analyzer-unix.Malloc to cert-mem34-c, but that seems slightly more involved, and so I intend to do this in a follow-up patch. ~Aaron http://reviews.llvm.org/D13352 Files: clang-tidy/CMakeLists.txt clang-tidy/Makefile clang-tidy/cert/CERTTidyModule.cpp clang-tidy/cert/CMakeLists.txt clang-tidy/cert/Makefile clang-tidy/tool/CMakeLists.txt clang-tidy/tool/ClangTidyMain.cpp clang-tidy/tool/Makefile
Index: clang-tidy/tool/Makefile =================================================================== --- clang-tidy/tool/Makefile +++ clang-tidy/tool/Makefile @@ -16,8 +16,9 @@ include $(CLANG_LEVEL)/../../Makefile.config LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc option -USEDLIBS = clangTidy.a clangTidyLLVMModule.a clangTidyGoogleModule.a \ - clangTidyMiscModule.a clangTidyModernizeModule.a clangTidyReadability.a \ +USEDLIBS = clangTidy.a clangTidyCERTModule.a clangTidyLLVMModule.a \ + clangTidyGoogleModule.a \ clangTidyMiscModule.a \ + clangTidyModernizeModule.a clangTidyReadability.a \ clangTidyUtils.a clangStaticAnalyzerFrontend.a \ clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a \ clangFormat.a clangASTMatchers.a clangTooling.a clangToolingCore.a \ Index: clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tidy/tool/CMakeLists.txt +++ clang-tidy/tool/CMakeLists.txt @@ -10,6 +10,7 @@ clangASTMatchers clangBasic clangTidy + clangTidyCERTModule clangTidyGoogleModule clangTidyLLVMModule clangTidyMiscModule Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -347,6 +347,11 @@ return 0; } +// This anchor is used to force the linker to link the CERTModule. +extern volatile int CERTModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination = + CERTModuleAnchorSource; + // This anchor is used to force the linker to link the LLVMModule. extern volatile int LLVMModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = Index: clang-tidy/Makefile =================================================================== --- clang-tidy/Makefile +++ clang-tidy/Makefile @@ -11,6 +11,6 @@ LIBRARYNAME := clangTidy include $(CLANG_LEVEL)/../../Makefile.config -DIRS = utils readability llvm google misc modernize tool +DIRS = utils cert readability llvm google misc modernize tool include $(CLANG_LEVEL)/Makefile Index: clang-tidy/CMakeLists.txt =================================================================== --- clang-tidy/CMakeLists.txt +++ clang-tidy/CMakeLists.txt @@ -26,6 +26,7 @@ ) add_subdirectory(tool) +add_subdirectory(cert) add_subdirectory(llvm) add_subdirectory(google) add_subdirectory(misc) Index: clang-tidy/cert/Makefile =================================================================== --- clang-tidy/cert/Makefile +++ clang-tidy/cert/Makefile @@ -0,0 +1,12 @@ +##===- clang-tidy/misc/Makefile ----------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +CLANG_LEVEL := ../../../.. +LIBRARYNAME := clangTidyCERTModule + +include $(CLANG_LEVEL)/Makefile Index: clang-tidy/cert/CMakeLists.txt =================================================================== --- clang-tidy/cert/CMakeLists.txt +++ clang-tidy/cert/CMakeLists.txt @@ -0,0 +1,12 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyCERTModule + CERTTidyModule.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + ) Index: clang-tidy/cert/CERTTidyModule.cpp =================================================================== --- clang-tidy/cert/CERTTidyModule.cpp +++ clang-tidy/cert/CERTTidyModule.cpp @@ -0,0 +1,59 @@ +//===--- CERTTidyModule.cpp - clang-tidy ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "../google/UnnamedNamespaceInHeaderCheck.h" +#include "../misc/MoveConstructorInitCheck.h" +#include "../misc/NewDeleteOverloadsCheck.h" +#include "../misc/NonCopyableObjects.h" +#include "../misc/StaticAssertCheck.h" + +namespace clang { +namespace tidy { +namespace CERT { + +class CERTModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + // C++ checkers + // DCL + CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>( + "cert-dcl54-cpp"); + CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( + "cert-dcl59-cpp"); + // OOP + CheckFactories.registerCheck<MoveConstructorInitCheck>( + "cert-oop11-cpp"); + + // C checkers + // DCL + CheckFactories.registerCheck<StaticAssertCheck>( + "cert-dcl03-c"); + + // FIO + CheckFactories.registerCheck<NonCopyableObjectsCheck>( + "cert-fio38-c"); + } +}; + +} // namespace misc + +// Register the MiscTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<CERT::CERTModule> +X("cert-module", + "Adds lint checks corresponding to CERT secure coding guidelines."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the CERTModule. +volatile int CERTModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits