Index: LICENSE.TXT =================================================================== --- LICENSE.TXT +++ LICENSE.TXT @@ -60,3 +60,4 @@ Program Directory ------- --------- clang-tidy clang-tidy/cert +clang-tidy clang-tidy/hicpp Index: clang-tidy/CMakeLists.txt =================================================================== --- clang-tidy/CMakeLists.txt +++ clang-tidy/CMakeLists.txt @@ -26,17 +26,17 @@ clangToolingCore ) -add_subdirectory(tool) -add_subdirectory(plugin) add_subdirectory(boost) add_subdirectory(cert) -add_subdirectory(llvm) add_subdirectory(cppcoreguidelines) add_subdirectory(google) +add_subdirectory(hicpp) +add_subdirectory(llvm) add_subdirectory(misc) add_subdirectory(modernize) add_subdirectory(mpi) add_subdirectory(performance) +add_subdirectory(plugin) add_subdirectory(readability) -add_subdirectory(safety) +add_subdirectory(tool) add_subdirectory(utils) Index: clang-tidy/hicpp/CMakeLists.txt =================================================================== --- clang-tidy/hicpp/CMakeLists.txt +++ clang-tidy/hicpp/CMakeLists.txt @@ -0,0 +1,14 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyHICPPModule + NoAssemblerCheck.cpp + HICPPTidyModule.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + ) Index: clang-tidy/hicpp/HICPPTidyModule.cpp =================================================================== --- clang-tidy/hicpp/HICPPTidyModule.cpp +++ clang-tidy/hicpp/HICPPTidyModule.cpp @@ -0,0 +1,38 @@ +//===------- HICPPTidyModule.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 "NoAssemblerCheck.h" + +namespace clang { +namespace tidy { +namespace hicpp { + +class HICPPModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "hicpp-no-assembler"); + } +}; + +// Register the HICPPModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add + X("hicpp-module", "Adds High-Integrity C++ checks."); + +} // namespace hicpp + +// This anchor is used to force the linker to link in the generated object file +// and thus register the HICPPModule. +volatile int HICPPModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang Index: clang-tidy/hicpp/LICENSE.TXT =================================================================== --- clang-tidy/hicpp/LICENSE.TXT +++ clang-tidy/hicpp/LICENSE.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------------ +clang-tidy High-Integrity C++ Files +------------------------------------------------------------------------------ +All clang-tidy files are licensed under the LLVM license with the following +additions: + +Any file referencing a High-Integrity C++ Coding guideline: + +HIC++ Coding Standard as created by PRQA. + +Please see http://www.codingstandard.com/section/conditions-of-use/ for more +information. Index: clang-tidy/hicpp/NoAssemblerCheck.h =================================================================== --- clang-tidy/hicpp/NoAssemblerCheck.h +++ clang-tidy/hicpp/NoAssemblerCheck.h @@ -0,0 +1,35 @@ +//===--- NoAssemblerCheck.h - clang-tidy-------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H + +#include "../ClangTidy.h" + +namespace clang { +namespace tidy { +namespace hicpp { + +/// Find assembler statements. No fix is offered. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-no-assembler.html +class NoAssemblerCheck : public ClangTidyCheck { +public: + NoAssemblerCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace hicpp +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H Index: clang-tidy/hicpp/NoAssemblerCheck.cpp =================================================================== --- clang-tidy/hicpp/NoAssemblerCheck.cpp +++ clang-tidy/hicpp/NoAssemblerCheck.cpp @@ -0,0 +1,51 @@ +//===--- NoAssemblerCheck.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 "NoAssemblerCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace ast_matchers { +AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr(); } +const internal::VariadicDynCastAllOfMatcher + fileScopeAsmDecl; +} +} + +namespace clang { +namespace tidy { +namespace hicpp { + +void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(asmStmt().bind("asm-stmt"), this); + Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this); + Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this); +} + +void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) { + SourceLocation ASMLocation; + if (const auto *ASM = Result.Nodes.getNodeAs("asm-stmt")) + ASMLocation = ASM->getAsmLoc(); + else if (const auto *ASM = + Result.Nodes.getNodeAs("asm-file-scope")) + ASMLocation = ASM->getAsmLoc(); + else if (const auto *ASM = Result.Nodes.getNodeAs("asm-var")) + ASMLocation = ASM->getLocation(); + else + llvm_unreachable("Unhandled case in matcher."); + + diag(ASMLocation, "do not use inline assembler in safety-critical code"); +} + +} // namespace hicpp +} // namespace tidy +} // namespace clang Index: clang-tidy/safety/CMakeLists.txt =================================================================== --- clang-tidy/safety/CMakeLists.txt +++ clang-tidy/safety/CMakeLists.txt @@ -1,14 +0,0 @@ -set(LLVM_LINK_COMPONENTS support) - -add_clang_library(clangTidySafetyModule - NoAssemblerCheck.cpp - SafetyTidyModule.cpp - - LINK_LIBS - clangAST - clangASTMatchers - clangBasic - clangLex - clangTidy - clangTidyUtils - ) Index: clang-tidy/safety/NoAssemblerCheck.h =================================================================== --- clang-tidy/safety/NoAssemblerCheck.h +++ clang-tidy/safety/NoAssemblerCheck.h @@ -1,35 +0,0 @@ -//===--- NoAssemblerCheck.h - clang-tidy-------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SAFETY_NO_ASSEMBLER_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SAFETY_NO_ASSEMBLER_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace safety { - -/// Find assembler statements. No fix is offered. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/safety-no-assembler.html -class NoAssemblerCheck : public ClangTidyCheck { -public: - NoAssemblerCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace safety -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SAFETY_NO_ASSEMBLER_H Index: clang-tidy/safety/NoAssemblerCheck.cpp =================================================================== --- clang-tidy/safety/NoAssemblerCheck.cpp +++ clang-tidy/safety/NoAssemblerCheck.cpp @@ -1,51 +0,0 @@ -//===--- NoAssemblerCheck.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 "NoAssemblerCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace ast_matchers { -AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr(); } -const internal::VariadicDynCastAllOfMatcher - fileScopeAsmDecl; -} -} - -namespace clang { -namespace tidy { -namespace safety { - -void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(asmStmt().bind("asm-stmt"), this); - Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this); - Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this); -} - -void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) { - SourceLocation ASMLocation; - if (const auto *ASM = Result.Nodes.getNodeAs("asm-stmt")) - ASMLocation = ASM->getAsmLoc(); - else if (const auto *ASM = - Result.Nodes.getNodeAs("asm-file-scope")) - ASMLocation = ASM->getAsmLoc(); - else if (const auto *ASM = Result.Nodes.getNodeAs("asm-var")) - ASMLocation = ASM->getLocation(); - else - llvm_unreachable("Unhandled case in matcher."); - - diag(ASMLocation, "do not use inline assembler in safety-critical code"); -} - -} // namespace safety -} // namespace tidy -} // namespace clang Index: clang-tidy/safety/SafetyTidyModule.cpp =================================================================== --- clang-tidy/safety/SafetyTidyModule.cpp +++ clang-tidy/safety/SafetyTidyModule.cpp @@ -1,38 +0,0 @@ -//===------- SafetyTidyModule.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 "NoAssemblerCheck.h" - -namespace clang { -namespace tidy { -namespace safety { - -class SafetyModule : public ClangTidyModule { -public: - void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck( - "safety-no-assembler"); - } -}; - -// Register the SafetyModule using this statically initialized variable. -static ClangTidyModuleRegistry::Add - X("safety-module", "Adds safety-critical checks."); - -} // namespace safety - -// This anchor is used to force the linker to link in the generated object file -// and thus register the SafetyModule. -volatile int SafetyModuleAnchorSource = 0; - -} // namespace tidy -} // namespace clang Index: clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tidy/tool/CMakeLists.txt +++ clang-tidy/tool/CMakeLists.txt @@ -17,6 +17,7 @@ clangTidyCERTModule clangTidyCppCoreGuidelinesModule clangTidyGoogleModule + clangTidyHICPPModule clangTidyLLVMModule clangTidyMiscModule clangTidyModernizeModule @@ -23,7 +24,6 @@ clangTidyMPIModule clangTidyPerformanceModule clangTidyReadabilityModule - clangTidySafetyModule clangTooling ) Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -496,10 +496,10 @@ static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource; -// This anchor is used to force the linker to link the SafetyModule. -extern volatile int SafetyModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED SafetyModuleAnchorDestination = - SafetyModuleAnchorSource; +// This anchor is used to force the linker to link the HICPPModule. +extern volatile int HICPPModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination = + HICPPModuleAnchorSource; } // namespace tidy } // namespace clang Index: docs/clang-tidy/checks/hicpp-no-assembler.rst =================================================================== --- docs/clang-tidy/checks/hicpp-no-assembler.rst +++ docs/clang-tidy/checks/hicpp-no-assembler.rst @@ -0,0 +1,10 @@ +.. title:: clang-tidy - hicpp-no-assembler + +hicpp-no-assembler +=================== + +Check for assembler statements. No fix is offered. + +Inline assembler is forbidden by the `High Intergrity C++ Coding Standard +`_ +as it restricts the portability of code. Index: docs/clang-tidy/checks/list.rst =================================================================== --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -53,6 +53,7 @@ google-runtime-memset google-runtime-operator google-runtime-references + hicpp-no-assembler llvm-header-guard llvm-include-order llvm-namespace-comment @@ -155,4 +156,3 @@ readability-simplify-boolean-expr readability-static-definition-in-anonymous-namespace readability-uniqueptr-delete-release - safety-no-assembler Index: docs/clang-tidy/checks/safety-no-assembler.rst =================================================================== --- docs/clang-tidy/checks/safety-no-assembler.rst +++ docs/clang-tidy/checks/safety-no-assembler.rst @@ -1,10 +0,0 @@ -.. title:: clang-tidy - safety-no-assembler - -safety-no-assembler -=================== - -Check for assembler statements. No fix is offered. - -Inline assembler is forbidden by safety-critical C++ standards like `High -Intergrity C++ `_ as it restricts the -portability of code. Index: test/clang-tidy/hicpp-no-assembler.cpp =================================================================== --- test/clang-tidy/hicpp-no-assembler.cpp +++ test/clang-tidy/hicpp-no-assembler.cpp @@ -0,0 +1,12 @@ +// RUN: %check_clang_tidy %s hicpp-no-assembler %t + +__asm__(".symver foo, bar@v"); +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler] + +static int s asm("spam"); +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler] + +void f() { + __asm("mov al, 2"); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler] +} Index: test/clang-tidy/safety-no-assembler.cpp =================================================================== --- test/clang-tidy/safety-no-assembler.cpp +++ test/clang-tidy/safety-no-assembler.cpp @@ -1,13 +0,0 @@ -// RUN: %check_clang_tidy %s safety-no-assembler %t - -__asm__(".symver foo, bar@v"); -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not use inline assembler in safety-critical code [safety-no-assembler] - -static int s asm("spam"); -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use inline assembler in safety-critical code [safety-no-assembler] - -void f() { - __asm("mov al, 2"); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use inline assembler in safety-critical code [safety-no-assembler] -} -