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
GitOrigin-RevId: ea2f90c96b4c3f8a87f7254785a0496f37ed2453
diff --git a/clang-tidy/CMakeLists.txt b/clang-tidy/CMakeLists.txt
index 89a0318..d698fd2 100644
--- a/clang-tidy/CMakeLists.txt
+++ b/clang-tidy/CMakeLists.txt
@@ -26,6 +26,7 @@
)
add_subdirectory(tool)
+add_subdirectory(cert)
add_subdirectory(llvm)
add_subdirectory(google)
add_subdirectory(misc)
diff --git a/clang-tidy/Makefile b/clang-tidy/Makefile
index 7eb5899..74da15c 100644
--- a/clang-tidy/Makefile
+++ b/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
diff --git a/clang-tidy/cert/CERTTidyModule.cpp b/clang-tidy/cert/CERTTidyModule.cpp
new file mode 100644
index 0000000..0c6b5dc
--- /dev/null
+++ b/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
diff --git a/clang-tidy/cert/CMakeLists.txt b/clang-tidy/cert/CMakeLists.txt
new file mode 100644
index 0000000..c61424e
--- /dev/null
+++ b/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
+ )
diff --git a/clang-tidy/cert/Makefile b/clang-tidy/cert/Makefile
new file mode 100644
index 0000000..0dda83a
--- /dev/null
+++ b/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
diff --git a/clang-tidy/tool/CMakeLists.txt b/clang-tidy/tool/CMakeLists.txt
index c26894b..1764a42 100644
--- a/clang-tidy/tool/CMakeLists.txt
+++ b/clang-tidy/tool/CMakeLists.txt
@@ -10,6 +10,7 @@
clangASTMatchers
clangBasic
clangTidy
+ clangTidyCERTModule
clangTidyGoogleModule
clangTidyLLVMModule
clangTidyMiscModule
diff --git a/clang-tidy/tool/ClangTidyMain.cpp b/clang-tidy/tool/ClangTidyMain.cpp
index b6e6445..03667fb 100644
--- a/clang-tidy/tool/ClangTidyMain.cpp
+++ b/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 =
diff --git a/clang-tidy/tool/Makefile b/clang-tidy/tool/Makefile
index 91d45c5..21a07a7 100644
--- a/clang-tidy/tool/Makefile
+++ b/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 \