forked from OSchip/llvm-project
Adding a new clang-tidy module to house CERT-specific checkers, and map existing checkers to CERT 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).
llvm-svn: 249130
This commit is contained in:
parent
b1a73fa94d
commit
ea2f90c96b
|
@ -26,6 +26,7 @@ add_clang_library(clangTidy
|
|||
)
|
||||
|
||||
add_subdirectory(tool)
|
||||
add_subdirectory(cert)
|
||||
add_subdirectory(llvm)
|
||||
add_subdirectory(google)
|
||||
add_subdirectory(misc)
|
||||
|
|
|
@ -11,6 +11,6 @@ CLANG_LEVEL := ../../..
|
|||
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
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,12 @@
|
|||
set(LLVM_LINK_COMPONENTS support)
|
||||
|
||||
add_clang_library(clangTidyCERTModule
|
||||
CERTTidyModule.cpp
|
||||
|
||||
LINK_LIBS
|
||||
clangAST
|
||||
clangASTMatchers
|
||||
clangBasic
|
||||
clangLex
|
||||
clangTidy
|
||||
)
|
|
@ -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
|
|
@ -10,6 +10,7 @@ target_link_libraries(clang-tidy
|
|||
clangASTMatchers
|
||||
clangBasic
|
||||
clangTidy
|
||||
clangTidyCERTModule
|
||||
clangTidyGoogleModule
|
||||
clangTidyLLVMModule
|
||||
clangTidyMiscModule
|
||||
|
|
|
@ -347,6 +347,11 @@ static int clangTidyMain(int argc, const char **argv) {
|
|||
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 =
|
||||
|
|
|
@ -16,8 +16,9 @@ TOOL_NO_EXPORTS = 1
|
|||
|
||||
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 \
|
||||
|
|
Loading…
Reference in New Issue