Index: clang-tools-extra/clang-tidy/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/CMakeLists.txt +++ clang-tools-extra/clang-tidy/CMakeLists.txt @@ -49,9 +49,10 @@ # Checks. # If you add a check, also add it to ClangTidyForceLinker.h in this directory. -add_subdirectory(android) add_subdirectory(abseil) add_subdirectory(altera) +add_subdirectory(android) +add_subdirectory(autosar) add_subdirectory(boost) add_subdirectory(bugprone) add_subdirectory(cert) @@ -76,9 +77,10 @@ add_subdirectory(readability) add_subdirectory(zircon) set(ALL_CLANG_TIDY_CHECKS - clangTidyAndroidModule clangTidyAbseilModule clangTidyAlteraModule + clangTidyAndroidModule + clangTidyAutosarModule clangTidyBoostModule clangTidyBugproneModule clangTidyCERTModule Index: clang-tools-extra/clang-tidy/ClangTidyForceLinker.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -30,6 +30,11 @@ static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination = AndroidModuleAnchorSource; +// This anchor is used to force the linker to link the AutosarModule. +extern volatile int AutosarModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED AutosarModuleAnchorDestination = + AutosarModuleAnchorSource; + // This anchor is used to force the linker to link the BoostModule. extern volatile int BoostModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination = Index: clang-tools-extra/clang-tidy/autosar/AutosarTidyModule.cpp =================================================================== --- /dev/null +++ clang-tools-extra/clang-tidy/autosar/AutosarTidyModule.cpp @@ -0,0 +1,38 @@ +//===--- AutosarTidyModule.cpp - clang-tidy -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "../cppcoreguidelines/ProTypeReinterpretCastCheck.h" + +namespace clang { +namespace tidy { +namespace autosar { + +class AutosarModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories + .registerCheck( + "autosar-a5-2-4-reinterpret-cast"); + } +}; + +} // namespace autosar + +// Register the AutosarTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add + X("autosar-module", "Adds AUTOSAR C++14 clang-tidy checks."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the AutosarModule. +volatile int AutosarModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang Index: clang-tools-extra/clang-tidy/autosar/CMakeLists.txt =================================================================== --- /dev/null +++ clang-tools-extra/clang-tidy/autosar/CMakeLists.txt @@ -0,0 +1,26 @@ +set(LLVM_LINK_COMPONENTS + FrontendOpenMP + Support + ) + +add_clang_library(clangTidyAutosarModule + AutosarTidyModule.cpp + + LINK_LIBS + clangTidy + clangTidyUtils + clangTidyCppCoreGuidelinesModule + + DEPENDS + omp_gen + ) + +clang_target_link_libraries(clangTidyAutosarModule + PRIVATE + clangAnalysis + clangAST + clangASTMatchers + clangBasic + clangLex + clangTooling + ) Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -67,6 +67,8 @@ Improvements to clang-tidy -------------------------- +- New module: `autosar`, covering the AUTOSAR C++14 Coding Guidelines. + - Added support for globbing in `NOLINT*` expressions, to simplify suppressing multiple warnings in the same line. @@ -103,6 +105,11 @@ New check aliases ^^^^^^^^^^^^^^^^^ +- New alias :doc:`autosar-a5-4-2-reinterpret-cast + ` to + :doc:`cppcoreguidelines-pro-type-reinterpret-cast + ` was added. + - New alias :doc:`cert-exp42-c ` to :doc:`bugprone-suspicious-memory-comparison Index: clang-tools-extra/docs/clang-tidy/checks/autosar-a5-4-2-reinterpret-cast.rst =================================================================== --- /dev/null +++ clang-tools-extra/docs/clang-tidy/checks/autosar-a5-4-2-reinterpret-cast.rst @@ -0,0 +1,10 @@ +.. title:: clang-tidy - autosar-a5-4-2-reinterpret-cast +.. meta:: + :http-equiv=refresh: 5;URL=cppcoreguidelines-pro-type-reinterpret-cast.html + +autosar-a5-4-2-reinterpret-cast +=============================== + +The autosar-a5-4-2-reinterpret-cast check is an alias, please see +`cppcoreguidelines-pro-type-reinterpret-cast `_ +for more information. Index: clang-tools-extra/docs/clang-tidy/checks/list.rst =================================================================== --- clang-tools-extra/docs/clang-tidy/checks/list.rst +++ clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -50,6 +50,7 @@ `android-cloexec-pipe2 `_, `android-cloexec-socket `_, `android-comparison-in-temp-failure-retry `_, + `autosar-a5-4-2-reinterpret-cast `_, `boost-use-to-string `_, "Yes" `bugprone-argument-comment `_, "Yes" `bugprone-assert-side-effect `_, @@ -328,6 +329,7 @@ .. csv-table:: Aliases.. :header: "Name", "Redirect", "Offers fixes" + `autosar-a5-4-2-reinterpret-cast `_, `cppcoreguidelines-pro-type-reinterpret-cast `_, `cert-con36-c `_, `bugprone-spuriously-wake-up-functions `_, `cert-con54-cpp `_, `bugprone-spuriously-wake-up-functions `_, `cert-dcl03-c `_, `misc-static-assert `_, "Yes" Index: clang-tools-extra/docs/clang-tidy/index.rst =================================================================== --- clang-tools-extra/docs/clang-tidy/index.rst +++ clang-tools-extra/docs/clang-tidy/index.rst @@ -60,6 +60,7 @@ ``abseil-`` Checks related to Abseil library. ``altera-`` Checks related to OpenCL programming for FPGAs. ``android-`` Checks related to Android. +``autosar-`` Checks related to AUTOSAR C++14 Coding Guidelines. ``boost-`` Checks related to Boost library. ``bugprone-`` Checks that target bugprone code constructs. ``cert-`` Checks related to CERT Secure Coding Guidelines. Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-reinterpret-cast.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-reinterpret-cast.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-reinterpret-cast.cpp @@ -1,6 +1,6 @@ -// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-reinterpret-cast %t +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-reinterpret-cast,autosar-a5-2-4-reinterpret-cast %t int i = 0; void *j; void f() { j = reinterpret_cast(i); } -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use reinterpret_cast [autosar-a5-2-4-reinterpret-cast,cppcoreguidelines-pro-type-reinterpret-cast]