From a4e578d0d587aa2bb8a3f3a82e7ae15c972521ef Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:33:46 +0200 Subject: [PATCH] Update to the Clang v20.1.7 version of the main Also make sure we build only the plugin, since the upstream clang now supports loading clang-tidy plugins via the -load option. --- CMakeLists.txt | 56 +-- FileExtensionsSet.h | 19 - GlobList.h | 66 --- NoLintDirectiveHandler.h | 47 --- aliceO2/CMakeLists.txt | 31 +- clang-tidy-config.h | 10 - omp.h | 521 ----------------------- plugin/CMakeLists.txt | 17 - plugin/FooCheck.cpp | 34 -- plugin/FooCheck.h | 36 -- plugin/PluginTidyModule.cpp | 48 --- reporting/CMakeLists.txt | 16 - reporting/InterfaceLister.cpp | 46 -- reporting/InterfaceLister.h | 43 -- reporting/ReportingTidyModule.cpp | 40 -- reporting/VirtFuncLister.cpp | 85 ---- reporting/VirtFuncLister.h | 36 -- tool/CMakeLists.txt | 70 ---- tool/ClangTidyMain.cpp | 671 ------------------------------ tool/ClangTidyMain.h | 23 - tool/clang-tidy-diff.py | 121 ------ 21 files changed, 29 insertions(+), 2007 deletions(-) delete mode 100644 FileExtensionsSet.h delete mode 100644 GlobList.h delete mode 100644 NoLintDirectiveHandler.h delete mode 100644 clang-tidy-config.h delete mode 100644 omp.h delete mode 100644 plugin/CMakeLists.txt delete mode 100644 plugin/FooCheck.cpp delete mode 100644 plugin/FooCheck.h delete mode 100644 plugin/PluginTidyModule.cpp delete mode 100644 reporting/CMakeLists.txt delete mode 100644 reporting/InterfaceLister.cpp delete mode 100644 reporting/InterfaceLister.h delete mode 100644 reporting/ReportingTidyModule.cpp delete mode 100644 reporting/VirtFuncLister.cpp delete mode 100644 reporting/VirtFuncLister.h delete mode 100644 tool/ClangTidyMain.cpp delete mode 100644 tool/ClangTidyMain.h delete mode 100755 tool/clang-tidy-diff.py diff --git a/CMakeLists.txt b/CMakeLists.txt index ff3e144..7ebacb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,62 +1,34 @@ cmake_minimum_required(VERSION 3.4.3) enable_testing() -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - # require at least gcc 12.0 !! - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0) - message(FATAL_ERROR "GCC version must be at least 12.0!") - endif() -endif() - - -if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) - project(O2CodeChecker) - - - # find clang + llvm - find_package(Clang REQUIRED CONFIG) - - if( LLVM_FOUND ) - list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") - include(AddLLVM) +project(O2CodeChecker) - # set the compiler flags to match llvm - include(HandleLLVMOptions) - endif() +# find clang + llvm +find_package(Clang REQUIRED CONFIG) - # Make sure that our source directory is on the current cmake module path so that - # we can include cmake files from this directory. - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +if( LLVM_FOUND ) + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + include(AddLLVM) - # include Clang macros (unfortunately they are not part of the cmake installation) - include(AddClang) + # set the compiler flags to match llvm + include(HandleLLVMOptions) +endif() - # add include directories - include_directories(${LLVM_INCLUDE_DIRS}) +# Make sure that our source directory is on the current cmake module path so that +# we can include cmake files from this directory. +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") -set(LLVM_LINK_COMPONENTS - Support - ) +# include Clang macros (unfortunately they are not part of the cmake installation) +include(AddClang) # the main executable add_subdirectory(tool) # the specific aliceO2 checker code add_subdirectory(aliceO2) -# the specific reporting tools code -add_subdirectory(reporting) - -# plugin -add_subdirectory(plugin) # for testing add_subdirectory(test) # some extra utilities add_subdirectory(utility) - -string(REPLACE "." ";" LLVM_PACKAGE_VERSION_LIST ${LLVM_PACKAGE_VERSION}) -list(GET LLVM_PACKAGE_VERSION_LIST 0 LLVM_PACKAGE_VERSION_MAJOR) -install(FILES omp.h DESTINATION lib/clang/${LLVM_PACKAGE_VERSION_MAJOR}/include) - -endif() diff --git a/FileExtensionsSet.h b/FileExtensionsSet.h deleted file mode 100644 index 7ca4e6e..0000000 --- a/FileExtensionsSet.h +++ /dev/null @@ -1,19 +0,0 @@ -//===--- FileExtensionsSet.h - clang-tidy -----------------------*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H - -#include "llvm/ADT/SmallSet.h" -#include "llvm/ADT/StringRef.h" - -namespace clang::tidy { -using FileExtensionsSet = llvm::SmallSet; -} // namespace clang::tidy - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H diff --git a/GlobList.h b/GlobList.h deleted file mode 100644 index 44af182..0000000 --- a/GlobList.h +++ /dev/null @@ -1,66 +0,0 @@ -//===--- GlobList.h ---------------------------------------------*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H - -#include "clang/Basic/LLVM.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Regex.h" - -namespace clang::tidy { - -/// Read-only set of strings represented as a list of positive and negative -/// globs. -/// -/// Positive globs add all matched strings to the set, negative globs remove -/// them in the order of appearance in the list. -class GlobList { -public: - virtual ~GlobList() = default; - - /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is - /// supported) with an optional '-' prefix to denote exclusion. - /// - /// An empty \p Globs string is interpreted as one glob that matches an empty - /// string. - /// - /// \p KeepNegativeGlobs a bool flag indicating whether to keep negative - /// globs from \p Globs or not. When false, negative globs are simply ignored. - GlobList(StringRef Globs, bool KeepNegativeGlobs = true); - - /// Returns \c true if the pattern matches \p S. The result is the last - /// matching glob's Positive flag. - virtual bool contains(StringRef S) const; - -private: - struct GlobListItem { - bool IsPositive; - llvm::Regex Regex; - }; - SmallVector Items; -}; - -/// A \p GlobList that caches search results, so that search is performed only -/// once for the same query. -class CachedGlobList final : public GlobList { -public: - using GlobList::GlobList; - - /// \see GlobList::contains - bool contains(StringRef S) const override; - -private: - mutable llvm::StringMap Cache; -}; - -} // namespace clang::tidy - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H diff --git a/NoLintDirectiveHandler.h b/NoLintDirectiveHandler.h deleted file mode 100644 index e862195..0000000 --- a/NoLintDirectiveHandler.h +++ /dev/null @@ -1,47 +0,0 @@ -//===-- clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h ----*- C++ *-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H - -#include "clang/Basic/Diagnostic.h" -#include "llvm/ADT/StringRef.h" -#include - -namespace clang::tooling { -struct Diagnostic; -} // namespace clang::tooling - -namespace llvm { -template class SmallVectorImpl; -} // namespace llvm - -namespace clang::tidy { - -/// This class is used to locate NOLINT comments in the file being analyzed, to -/// decide whether a diagnostic should be suppressed. -/// This class keeps a cache of every NOLINT comment found so that files do not -/// have to be repeatedly parsed each time a new diagnostic is raised. -class NoLintDirectiveHandler { -public: - NoLintDirectiveHandler(); - ~NoLintDirectiveHandler(); - - bool shouldSuppress(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Diag, llvm::StringRef DiagName, - llvm::SmallVectorImpl &NoLintErrors, - bool AllowIO, bool EnableNoLintBlocks); - -private: - class Impl; - std::unique_ptr PImpl; -}; - -} // namespace clang::tidy - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H diff --git a/aliceO2/CMakeLists.txt b/aliceO2/CMakeLists.txt index 0c487da..e00c918 100644 --- a/aliceO2/CMakeLists.txt +++ b/aliceO2/CMakeLists.txt @@ -1,17 +1,16 @@ -set(LLVM_LINK_COMPONENTS support) +add_library(clangTidyAliceO2Module MODULE "") +target_compile_options(clangTidyAliceO2Module PRIVATE -fno-rtti) +target_include_directories(clangTidyAliceO2Module + PRIVATE + ${CLANG_INCLUDE_DIRS} + ${LLVM_INCLUDE_DIRS} +) -add_clang_library(clangTidyAliceO2Module - AliceO2TidyModule.cpp - MemberNamesCheck.cpp - NamespaceNamingCheck.cpp - SizeofCheck.cpp - - LINK_LIBS - clangAST - clangASTMatchers - clangBasic - clangLex - clangTidy - clangTidyUtils - clangTooling - ) +target_sources(clangTidyAliceO2Module + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/AliceO2TidyModule.cpp + ${CMAKE_CURRENT_LIST_DIR}/MemberNamesCheck.cpp + ${CMAKE_CURRENT_LIST_DIR}/NamespaceNamingCheck.cpp + ${CMAKE_CURRENT_LIST_DIR}/SizeofCheck.cpp +) +install(TARGETS clangTidyAliceO2Module LIBRARY DESTINATION lib) diff --git a/clang-tidy-config.h b/clang-tidy-config.h deleted file mode 100644 index c3847d4..0000000 --- a/clang-tidy-config.h +++ /dev/null @@ -1,10 +0,0 @@ -/* This generated file is for internal use. Do not include it from headers. */ - -#ifdef CLANG_TIDY_CONFIG_H -#error clang-tidy-config.h can only be included once -#else -#define CLANG_TIDY_CONFIG_H - -#define CLANG_TIDY_ENABLE_STATIC_ANALYZER 1 - -#endif diff --git a/omp.h b/omp.h deleted file mode 100644 index 94be362..0000000 --- a/omp.h +++ /dev/null @@ -1,521 +0,0 @@ -/* - * include/omp.h.var - */ - - -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - - -#ifndef __OMP_H -# define __OMP_H - -# include -# include -# include - -# define KMP_VERSION_MAJOR 5 -# define KMP_VERSION_MINOR 0 -# define KMP_VERSION_BUILD 20140926 -# define KMP_BUILD_DATE "No_Timestamp" - -# ifdef __cplusplus - extern "C" { -# endif - -# define omp_set_affinity_format ompc_set_affinity_format -# define omp_get_affinity_format ompc_get_affinity_format -# define omp_display_affinity ompc_display_affinity -# define omp_capture_affinity ompc_capture_affinity - -# if defined(_WIN32) -# define __KAI_KMPC_CONVENTION __cdecl -# ifndef __KMP_IMP -# define __KMP_IMP __declspec(dllimport) -# endif -# else -# define __KAI_KMPC_CONVENTION -# ifndef __KMP_IMP -# define __KMP_IMP -# endif -# endif - - /* schedule kind constants */ - typedef enum omp_sched_t { - omp_sched_static = 1, - omp_sched_dynamic = 2, - omp_sched_guided = 3, - omp_sched_auto = 4, - omp_sched_monotonic = 0x80000000 - } omp_sched_t; - - /* set API functions */ - extern void __KAI_KMPC_CONVENTION omp_set_num_threads (int); - extern void __KAI_KMPC_CONVENTION omp_set_dynamic (int); - extern void __KAI_KMPC_CONVENTION omp_set_nested (int); - extern void __KAI_KMPC_CONVENTION omp_set_max_active_levels (int); - extern void __KAI_KMPC_CONVENTION omp_set_schedule (omp_sched_t, int); - - /* query API functions */ - extern int __KAI_KMPC_CONVENTION omp_get_num_threads (void); - extern int __KAI_KMPC_CONVENTION omp_get_dynamic (void); - extern int __KAI_KMPC_CONVENTION omp_get_nested (void); - extern int __KAI_KMPC_CONVENTION omp_get_max_threads (void); - extern int __KAI_KMPC_CONVENTION omp_get_thread_num (void); - extern int __KAI_KMPC_CONVENTION omp_get_num_procs (void); - extern int __KAI_KMPC_CONVENTION omp_in_parallel (void); - extern int __KAI_KMPC_CONVENTION omp_in_final (void); - extern int __KAI_KMPC_CONVENTION omp_get_active_level (void); - extern int __KAI_KMPC_CONVENTION omp_get_level (void); - extern int __KAI_KMPC_CONVENTION omp_get_ancestor_thread_num (int); - extern int __KAI_KMPC_CONVENTION omp_get_team_size (int); - extern int __KAI_KMPC_CONVENTION omp_get_thread_limit (void); - extern int __KAI_KMPC_CONVENTION omp_get_max_active_levels (void); - extern void __KAI_KMPC_CONVENTION omp_get_schedule (omp_sched_t *, int *); - extern int __KAI_KMPC_CONVENTION omp_get_max_task_priority (void); - - /* lock API functions */ - typedef struct omp_lock_t { - void * _lk; - } omp_lock_t; - - extern void __KAI_KMPC_CONVENTION omp_init_lock (omp_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_set_lock (omp_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_unset_lock (omp_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_destroy_lock (omp_lock_t *); - extern int __KAI_KMPC_CONVENTION omp_test_lock (omp_lock_t *); - - /* nested lock API functions */ - typedef struct omp_nest_lock_t { - void * _lk; - } omp_nest_lock_t; - - extern void __KAI_KMPC_CONVENTION omp_init_nest_lock (omp_nest_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_set_nest_lock (omp_nest_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_unset_nest_lock (omp_nest_lock_t *); - extern void __KAI_KMPC_CONVENTION omp_destroy_nest_lock (omp_nest_lock_t *); - extern int __KAI_KMPC_CONVENTION omp_test_nest_lock (omp_nest_lock_t *); - - /* OpenMP 5.0 Synchronization hints*/ - typedef enum omp_sync_hint_t { - omp_sync_hint_none = 0, - omp_lock_hint_none = omp_sync_hint_none, - omp_sync_hint_uncontended = 1, - omp_lock_hint_uncontended = omp_sync_hint_uncontended, - omp_sync_hint_contended = (1<<1), - omp_lock_hint_contended = omp_sync_hint_contended, - omp_sync_hint_nonspeculative = (1<<2), - omp_lock_hint_nonspeculative = omp_sync_hint_nonspeculative, - omp_sync_hint_speculative = (1<<3), - omp_lock_hint_speculative = omp_sync_hint_speculative, - kmp_lock_hint_hle = (1<<16), - kmp_lock_hint_rtm = (1<<17), - kmp_lock_hint_adaptive = (1<<18) - } omp_sync_hint_t; - - /* lock hint type for dynamic user lock */ - typedef omp_sync_hint_t omp_lock_hint_t; - - /* hinted lock initializers */ - extern void __KAI_KMPC_CONVENTION omp_init_lock_with_hint(omp_lock_t *, omp_lock_hint_t); - extern void __KAI_KMPC_CONVENTION omp_init_nest_lock_with_hint(omp_nest_lock_t *, omp_lock_hint_t); - - /* time API functions */ - extern double __KAI_KMPC_CONVENTION omp_get_wtime (void); - extern double __KAI_KMPC_CONVENTION omp_get_wtick (void); - - /* OpenMP 4.0 */ - extern int __KAI_KMPC_CONVENTION omp_get_default_device (void); - extern void __KAI_KMPC_CONVENTION omp_set_default_device (int); - extern int __KAI_KMPC_CONVENTION omp_is_initial_device (void); - extern int __KAI_KMPC_CONVENTION omp_get_num_devices (void); - extern int __KAI_KMPC_CONVENTION omp_get_num_teams (void); - extern int __KAI_KMPC_CONVENTION omp_get_team_num (void); - extern int __KAI_KMPC_CONVENTION omp_get_cancellation (void); - - /* OpenMP 4.5 */ - extern int __KAI_KMPC_CONVENTION omp_get_initial_device (void); - extern void* __KAI_KMPC_CONVENTION omp_target_alloc(size_t, int); - extern void __KAI_KMPC_CONVENTION omp_target_free(void *, int); - extern int __KAI_KMPC_CONVENTION omp_target_is_present(const void *, int); - extern int __KAI_KMPC_CONVENTION omp_target_memcpy(void *, const void *, size_t, size_t, size_t, int, int); - extern int __KAI_KMPC_CONVENTION omp_target_memcpy_rect(void *, const void *, size_t, int, const size_t *, - const size_t *, const size_t *, const size_t *, const size_t *, int, int); - extern int __KAI_KMPC_CONVENTION omp_target_associate_ptr(const void *, const void *, size_t, size_t, int); - extern int __KAI_KMPC_CONVENTION omp_target_disassociate_ptr(const void *, int); - - /* OpenMP 5.0 */ - extern int __KAI_KMPC_CONVENTION omp_get_device_num (void); - typedef void * omp_depend_t; - - /* OpenMP 5.1 interop */ - typedef intptr_t omp_intptr_t; - - /* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined properties */ - typedef enum omp_interop_property { - omp_ipr_fr_id = -1, - omp_ipr_fr_name = -2, - omp_ipr_vendor = -3, - omp_ipr_vendor_name = -4, - omp_ipr_device_num = -5, - omp_ipr_platform = -6, - omp_ipr_device = -7, - omp_ipr_device_context = -8, - omp_ipr_targetsync = -9, - omp_ipr_first = -9 - } omp_interop_property_t; - - #define omp_interop_none 0 - - typedef enum omp_interop_rc { - omp_irc_no_value = 1, - omp_irc_success = 0, - omp_irc_empty = -1, - omp_irc_out_of_range = -2, - omp_irc_type_int = -3, - omp_irc_type_ptr = -4, - omp_irc_type_str = -5, - omp_irc_other = -6 - } omp_interop_rc_t; - - typedef enum omp_interop_fr { - omp_ifr_cuda = 1, - omp_ifr_cuda_driver = 2, - omp_ifr_opencl = 3, - omp_ifr_sycl = 4, - omp_ifr_hip = 5, - omp_ifr_level_zero = 6, - omp_ifr_last = 7 - } omp_interop_fr_t; - - typedef void * omp_interop_t; - - /*! - * The `omp_get_num_interop_properties` routine retrieves the number of implementation-defined properties available for an `omp_interop_t` object. - */ - extern int __KAI_KMPC_CONVENTION omp_get_num_interop_properties(const omp_interop_t); - /*! - * The `omp_get_interop_int` routine retrieves an integer property from an `omp_interop_t` object. - */ - extern omp_intptr_t __KAI_KMPC_CONVENTION omp_get_interop_int(const omp_interop_t, omp_interop_property_t, int *); - /*! - * The `omp_get_interop_ptr` routine retrieves a pointer property from an `omp_interop_t` object. - */ - extern void * __KAI_KMPC_CONVENTION omp_get_interop_ptr(const omp_interop_t, omp_interop_property_t, int *); - /*! - * The `omp_get_interop_str` routine retrieves a string property from an `omp_interop_t` object. - */ - extern const char * __KAI_KMPC_CONVENTION omp_get_interop_str(const omp_interop_t, omp_interop_property_t, int *); - /*! - * The `omp_get_interop_name` routine retrieves a property name from an `omp_interop_t` object. - */ - extern const char * __KAI_KMPC_CONVENTION omp_get_interop_name(const omp_interop_t, omp_interop_property_t); - /*! - * The `omp_get_interop_type_desc` routine retrieves a description of the type of a property associated with an `omp_interop_t` object. - */ - extern const char * __KAI_KMPC_CONVENTION omp_get_interop_type_desc(const omp_interop_t, omp_interop_property_t); - /*! - * The `omp_get_interop_rc_desc` routine retrieves a description of the return code associated with an `omp_interop_t` object. - */ - extern const char * __KAI_KMPC_CONVENTION omp_get_interop_rc_desc(const omp_interop_t, omp_interop_rc_t); - - /* OpenMP 5.1 device memory routines */ - - /*! - * The `omp_target_memcpy_async` routine asynchronously performs a copy between any combination of host and device pointers. - */ - extern int __KAI_KMPC_CONVENTION omp_target_memcpy_async(void *, const void *, size_t, size_t, size_t, int, - int, int, omp_depend_t *); - /*! - * The `omp_target_memcpy_rect_async` routine asynchronously performs a copy between any combination of host and device pointers. - */ - extern int __KAI_KMPC_CONVENTION omp_target_memcpy_rect_async(void *, const void *, size_t, int, const size_t *, - const size_t *, const size_t *, const size_t *, const size_t *, int, int, - int, omp_depend_t *); - - /* OpenMP 6.0 device memory routines */ - extern void * __KAI_KMPC_CONVENTION omp_target_memset(void *, int, size_t, int); - extern void * __KAI_KMPC_CONVENTION omp_target_memset_async(void *, int, size_t, int, int, omp_depend_t *); - - /*! - * The `omp_get_mapped_ptr` routine returns the device pointer that is associated with a host pointer for a given device. - */ - extern void * __KAI_KMPC_CONVENTION omp_get_mapped_ptr(const void *, int); - extern int __KAI_KMPC_CONVENTION omp_target_is_accessible(const void *, size_t, int); - - /* kmp API functions */ - extern int __KAI_KMPC_CONVENTION kmp_get_stacksize (void); - extern void __KAI_KMPC_CONVENTION kmp_set_stacksize (int); - extern size_t __KAI_KMPC_CONVENTION kmp_get_stacksize_s (void); - extern void __KAI_KMPC_CONVENTION kmp_set_stacksize_s (size_t); - extern int __KAI_KMPC_CONVENTION kmp_get_blocktime (void); - extern int __KAI_KMPC_CONVENTION kmp_get_library (void); - extern void __KAI_KMPC_CONVENTION kmp_set_blocktime (int); - extern void __KAI_KMPC_CONVENTION kmp_set_library (int); - extern void __KAI_KMPC_CONVENTION kmp_set_library_serial (void); - extern void __KAI_KMPC_CONVENTION kmp_set_library_turnaround (void); - extern void __KAI_KMPC_CONVENTION kmp_set_library_throughput (void); - extern void __KAI_KMPC_CONVENTION kmp_set_defaults (char const *); - extern void __KAI_KMPC_CONVENTION kmp_set_disp_num_buffers (int); - - /* Intel affinity API */ - typedef void * kmp_affinity_mask_t; - - extern int __KAI_KMPC_CONVENTION kmp_set_affinity (kmp_affinity_mask_t *); - extern int __KAI_KMPC_CONVENTION kmp_get_affinity (kmp_affinity_mask_t *); - extern int __KAI_KMPC_CONVENTION kmp_get_affinity_max_proc (void); - extern void __KAI_KMPC_CONVENTION kmp_create_affinity_mask (kmp_affinity_mask_t *); - extern void __KAI_KMPC_CONVENTION kmp_destroy_affinity_mask (kmp_affinity_mask_t *); - extern int __KAI_KMPC_CONVENTION kmp_set_affinity_mask_proc (int, kmp_affinity_mask_t *); - extern int __KAI_KMPC_CONVENTION kmp_unset_affinity_mask_proc (int, kmp_affinity_mask_t *); - extern int __KAI_KMPC_CONVENTION kmp_get_affinity_mask_proc (int, kmp_affinity_mask_t *); - - /* OpenMP 4.0 affinity API */ - typedef enum omp_proc_bind_t { - omp_proc_bind_false = 0, - omp_proc_bind_true = 1, - omp_proc_bind_master = 2, - omp_proc_bind_close = 3, - omp_proc_bind_spread = 4 - } omp_proc_bind_t; - - extern omp_proc_bind_t __KAI_KMPC_CONVENTION omp_get_proc_bind (void); - - /* OpenMP 4.5 affinity API */ - extern int __KAI_KMPC_CONVENTION omp_get_num_places (void); - extern int __KAI_KMPC_CONVENTION omp_get_place_num_procs (int); - extern void __KAI_KMPC_CONVENTION omp_get_place_proc_ids (int, int *); - extern int __KAI_KMPC_CONVENTION omp_get_place_num (void); - extern int __KAI_KMPC_CONVENTION omp_get_partition_num_places (void); - extern void __KAI_KMPC_CONVENTION omp_get_partition_place_nums (int *); - - extern void * __KAI_KMPC_CONVENTION kmp_malloc (size_t); - extern void * __KAI_KMPC_CONVENTION kmp_aligned_malloc (size_t, size_t); - extern void * __KAI_KMPC_CONVENTION kmp_calloc (size_t, size_t); - extern void * __KAI_KMPC_CONVENTION kmp_realloc (void *, size_t); - extern void __KAI_KMPC_CONVENTION kmp_free (void *); - - extern void __KAI_KMPC_CONVENTION kmp_set_warnings_on(void); - extern void __KAI_KMPC_CONVENTION kmp_set_warnings_off(void); - - /* OpenMP 5.0 Tool Control */ - typedef enum omp_control_tool_result_t { - omp_control_tool_notool = -2, - omp_control_tool_nocallback = -1, - omp_control_tool_success = 0, - omp_control_tool_ignored = 1 - } omp_control_tool_result_t; - - typedef enum omp_control_tool_t { - omp_control_tool_start = 1, - omp_control_tool_pause = 2, - omp_control_tool_flush = 3, - omp_control_tool_end = 4 - } omp_control_tool_t; - - extern int __KAI_KMPC_CONVENTION omp_control_tool(int, int, void*); - - /* OpenMP 5.0 Memory Management */ - typedef uintptr_t omp_uintptr_t; - - typedef enum { - omp_atk_sync_hint = 1, - omp_atk_alignment = 2, - omp_atk_access = 3, - omp_atk_pool_size = 4, - omp_atk_fallback = 5, - omp_atk_fb_data = 6, - omp_atk_pinned = 7, - omp_atk_partition = 8 - } omp_alloctrait_key_t; - - typedef enum { - omp_atv_false = 0, - omp_atv_true = 1, - omp_atv_contended = 3, - omp_atv_uncontended = 4, - omp_atv_serialized = 5, - omp_atv_sequential = omp_atv_serialized, // (deprecated) - omp_atv_private = 6, - omp_atv_all = 7, - omp_atv_thread = 8, - omp_atv_pteam = 9, - omp_atv_cgroup = 10, - omp_atv_default_mem_fb = 11, - omp_atv_null_fb = 12, - omp_atv_abort_fb = 13, - omp_atv_allocator_fb = 14, - omp_atv_environment = 15, - omp_atv_nearest = 16, - omp_atv_blocked = 17, - omp_atv_interleaved = 18 - } omp_alloctrait_value_t; - #define omp_atv_default ((omp_uintptr_t)-1) - - typedef struct { - omp_alloctrait_key_t key; - omp_uintptr_t value; - } omp_alloctrait_t; - -# if defined(_WIN32) - // On Windows cl and icl do not support 64-bit enum, let's use integer then. - typedef omp_uintptr_t omp_allocator_handle_t; - extern __KMP_IMP omp_allocator_handle_t const omp_null_allocator; - extern __KMP_IMP omp_allocator_handle_t const omp_default_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_large_cap_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_const_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_high_bw_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_low_lat_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_cgroup_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_pteam_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const omp_thread_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const llvm_omp_target_host_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const llvm_omp_target_shared_mem_alloc; - extern __KMP_IMP omp_allocator_handle_t const llvm_omp_target_device_mem_alloc; - - typedef omp_uintptr_t omp_memspace_handle_t; - extern __KMP_IMP omp_memspace_handle_t const omp_default_mem_space; - extern __KMP_IMP omp_memspace_handle_t const omp_large_cap_mem_space; - extern __KMP_IMP omp_memspace_handle_t const omp_const_mem_space; - extern __KMP_IMP omp_memspace_handle_t const omp_high_bw_mem_space; - extern __KMP_IMP omp_memspace_handle_t const omp_low_lat_mem_space; - extern __KMP_IMP omp_memspace_handle_t const llvm_omp_target_host_mem_space; - extern __KMP_IMP omp_memspace_handle_t const llvm_omp_target_shared_mem_space; - extern __KMP_IMP omp_memspace_handle_t const llvm_omp_target_device_mem_space; -# else -# if __cplusplus >= 201103 - typedef enum omp_allocator_handle_t : omp_uintptr_t -# else - typedef enum omp_allocator_handle_t -# endif - { - omp_null_allocator = 0, - omp_default_mem_alloc = 1, - omp_large_cap_mem_alloc = 2, - omp_const_mem_alloc = 3, - omp_high_bw_mem_alloc = 4, - omp_low_lat_mem_alloc = 5, - omp_cgroup_mem_alloc = 6, - omp_pteam_mem_alloc = 7, - omp_thread_mem_alloc = 8, - llvm_omp_target_host_mem_alloc = 100, - llvm_omp_target_shared_mem_alloc = 101, - llvm_omp_target_device_mem_alloc = 102, - KMP_ALLOCATOR_MAX_HANDLE = UINTPTR_MAX - } omp_allocator_handle_t; -# if __cplusplus >= 201103 - typedef enum omp_memspace_handle_t : omp_uintptr_t -# else - typedef enum omp_memspace_handle_t -# endif - { - omp_default_mem_space = 0, - omp_large_cap_mem_space = 1, - omp_const_mem_space = 2, - omp_high_bw_mem_space = 3, - omp_low_lat_mem_space = 4, - llvm_omp_target_host_mem_space = 100, - llvm_omp_target_shared_mem_space = 101, - llvm_omp_target_device_mem_space = 102, - KMP_MEMSPACE_MAX_HANDLE = UINTPTR_MAX - } omp_memspace_handle_t; -# endif - extern omp_allocator_handle_t __KAI_KMPC_CONVENTION omp_init_allocator(omp_memspace_handle_t m, - int ntraits, omp_alloctrait_t traits[]); - extern void __KAI_KMPC_CONVENTION omp_destroy_allocator(omp_allocator_handle_t allocator); - - extern void __KAI_KMPC_CONVENTION omp_set_default_allocator(omp_allocator_handle_t a); - extern omp_allocator_handle_t __KAI_KMPC_CONVENTION omp_get_default_allocator(void); -# ifdef __cplusplus - extern void *__KAI_KMPC_CONVENTION omp_alloc(size_t size, omp_allocator_handle_t a = omp_null_allocator); - extern void *__KAI_KMPC_CONVENTION omp_aligned_alloc(size_t align, size_t size, - omp_allocator_handle_t a = omp_null_allocator); - extern void *__KAI_KMPC_CONVENTION omp_calloc(size_t nmemb, size_t size, - omp_allocator_handle_t a = omp_null_allocator); - extern void *__KAI_KMPC_CONVENTION omp_aligned_calloc(size_t align, size_t nmemb, size_t size, - omp_allocator_handle_t a = omp_null_allocator); - extern void *__KAI_KMPC_CONVENTION omp_realloc(void *ptr, size_t size, - omp_allocator_handle_t allocator = omp_null_allocator, - omp_allocator_handle_t free_allocator = omp_null_allocator); - extern void __KAI_KMPC_CONVENTION omp_free(void * ptr, omp_allocator_handle_t a = omp_null_allocator); -# else - extern void *__KAI_KMPC_CONVENTION omp_alloc(size_t size, omp_allocator_handle_t a); - extern void *__KAI_KMPC_CONVENTION omp_aligned_alloc(size_t align, size_t size, - omp_allocator_handle_t a); - extern void *__KAI_KMPC_CONVENTION omp_calloc(size_t nmemb, size_t size, omp_allocator_handle_t a); - extern void *__KAI_KMPC_CONVENTION omp_aligned_calloc(size_t align, size_t nmemb, size_t size, - omp_allocator_handle_t a); - extern void *__KAI_KMPC_CONVENTION omp_realloc(void *ptr, size_t size, omp_allocator_handle_t allocator, - omp_allocator_handle_t free_allocator); - extern void __KAI_KMPC_CONVENTION omp_free(void *ptr, omp_allocator_handle_t a); -# endif - - /* OpenMP 5.0 Affinity Format */ - extern void __KAI_KMPC_CONVENTION omp_set_affinity_format(char const *); - extern size_t __KAI_KMPC_CONVENTION omp_get_affinity_format(char *, size_t); - extern void __KAI_KMPC_CONVENTION omp_display_affinity(char const *); - extern size_t __KAI_KMPC_CONVENTION omp_capture_affinity(char *, size_t, char const *); - - /* OpenMP 5.0 events */ -# if defined(_WIN32) - // On Windows cl and icl do not support 64-bit enum, let's use integer then. - typedef omp_uintptr_t omp_event_handle_t; -# else - typedef enum omp_event_handle_t { KMP_EVENT_MAX_HANDLE = UINTPTR_MAX } omp_event_handle_t; -# endif - extern void __KAI_KMPC_CONVENTION omp_fulfill_event ( omp_event_handle_t event ); - - /* OpenMP 5.0 Pause Resources */ - typedef enum omp_pause_resource_t { - omp_pause_resume = 0, - omp_pause_soft = 1, - omp_pause_hard = 2 - } omp_pause_resource_t; - extern int __KAI_KMPC_CONVENTION omp_pause_resource(omp_pause_resource_t, int); - extern int __KAI_KMPC_CONVENTION omp_pause_resource_all(omp_pause_resource_t); - - extern int __KAI_KMPC_CONVENTION omp_get_supported_active_levels(void); - - /* OpenMP 5.1 */ - extern void __KAI_KMPC_CONVENTION omp_set_num_teams(int num_teams); - extern int __KAI_KMPC_CONVENTION omp_get_max_teams(void); - extern void __KAI_KMPC_CONVENTION omp_set_teams_thread_limit(int limit); - extern int __KAI_KMPC_CONVENTION omp_get_teams_thread_limit(void); - - /* OpenMP 5.1 Display Environment */ - extern void omp_display_env(int verbose); - -# if defined(_OPENMP) && _OPENMP >= 201811 - #pragma omp begin declare variant match(device={kind(host)}) - static inline int omp_is_initial_device(void) { return 1; } - #pragma omp end declare variant - #pragma omp begin declare variant match(device={kind(nohost)}) - static inline int omp_is_initial_device(void) { return 0; } - #pragma omp end declare variant -# endif - - /* OpenMP 5.2 */ - extern int __KAI_KMPC_CONVENTION omp_in_explicit_task(void); - - /* LLVM Extensions */ - extern void *llvm_omp_target_dynamic_shared_alloc(void); - -# undef __KAI_KMPC_CONVENTION -# undef __KMP_IMP - - /* Warning: - The following typedefs are not standard, deprecated and will be removed in a future release. - */ - typedef int omp_int_t; - typedef double omp_wtime_t; - -# ifdef __cplusplus - } -# endif - -#endif /* __OMP_H */ diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt deleted file mode 100644 index 942142d..0000000 --- a/plugin/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set(LLVM_LINK_COMPONENTS support) - -add_clang_library(clangTidyPluginModule - SHARED - - FooCheck.cpp - PluginTidyModule.cpp - - LINK_LIBS - clangAST - clangASTMatchers - clangBasic - clangLex - clangTidy - clangTidyUtils - clangTooling - ) diff --git a/plugin/FooCheck.cpp b/plugin/FooCheck.cpp deleted file mode 100644 index cd8cc9d..0000000 --- a/plugin/FooCheck.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===--- FooCheck.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 "FooCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace plugin { - -void FooCheck::registerMatchers(MatchFinder *Finder) { - // FIXME: Add matchers. - Finder->addMatcher(functionDecl().bind("x"), this); -} - -void FooCheck::check(const MatchFinder::MatchResult &Result) { - // FIXME: Add callback implementation. - const auto *MatchedDecl = Result.Nodes.getNodeAs("x"); - diag(MatchedDecl->getLocation(), "you should not use functions") - << MatchedDecl; -} - -} // namespace plugin -} // namespace tidy -} // namespace clang diff --git a/plugin/FooCheck.h b/plugin/FooCheck.h deleted file mode 100644 index 5d843bb..0000000 --- a/plugin/FooCheck.h +++ /dev/null @@ -1,36 +0,0 @@ -//===--- FooCheck.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_PLUGIN_FOO_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PLUGIN_FOO_H - -#include "clang-tidy/ClangTidy.h" -#include "clang-tidy/ClangTidyCheck.h" - -namespace clang { -namespace tidy { -namespace plugin { - -/// FIXME: Write a short description. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/plugin-Foo.html -class FooCheck : public ClangTidyCheck { -public: - FooCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace plugin -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PLUGIN_FOO_H diff --git a/plugin/PluginTidyModule.cpp b/plugin/PluginTidyModule.cpp deleted file mode 100644 index c8f4b10..0000000 --- a/plugin/PluginTidyModule.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===--- PluginTidyModule.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 "clang-tidy/ClangTidy.h" -#include "clang-tidy/ClangTidyModule.h" -#include "clang-tidy/ClangTidyModuleRegistry.h" -#include "FooCheck.h" -#include - -namespace clang { -namespace tidy { -namespace plugin { - -class PluginModule : public ClangTidyModule { -public: - void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - std::cerr << "side effect \n"; - CheckFactories.registerCheck( - "plugin-Foo"); - } -}; - -} // namespace plugin - -// Register the PluginTidyModule using this statically initialized variable. -static ClangTidyModuleRegistry::Add -X("pluginO2-module", "Adds Plugin specific checks"); - -// This anchor is used to force the linker to link in the generated object file -// and thus register the PluginModule. -volatile int PluginModuleAnchorSource = 0; - -} // namespace tidy -} // namespace clang - - -// A function to execute upon load of shared library -//__attribute__((constructor)) -static int huhuhuhuhu() { - static clang::tidy::plugin::PluginModule module; - return clang::tidy::PluginModuleAnchorSource; -} diff --git a/reporting/CMakeLists.txt b/reporting/CMakeLists.txt deleted file mode 100644 index e41a910..0000000 --- a/reporting/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -set(LLVM_LINK_COMPONENTS support) - -add_clang_library(clangTidyReportingModule - ReportingTidyModule.cpp - InterfaceLister.cpp - VirtFuncLister.cpp - - LINK_LIBS - clangAST - clangASTMatchers - clangBasic - clangLex - clangTidy - clangTidyUtils - clangTooling - ) diff --git a/reporting/InterfaceLister.cpp b/reporting/InterfaceLister.cpp deleted file mode 100644 index cfe0638..0000000 --- a/reporting/InterfaceLister.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===--- InterfaceLister.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 "InterfaceLister.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace reporting { - -void InterfaceLister::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(cxxMemberCallExpr().bind("member"), this); -} - -void InterfaceLister::check(const MatchFinder::MatchResult &Result) { - const auto *MatchedCallExpr = - Result.Nodes.getNodeAs("member"); - if (MatchedCallExpr) { - if (std::strcmp(MatchedCallExpr->getRecordDecl() - ->getDeclName() - .getAsString() - .c_str(), - ClassName.c_str()) != 0) - return; - - std::string sourceInfo(MatchedCallExpr->getExprLoc().printToString( - *Result.SourceManager)); - std::cerr << sourceInfo << " ; " << ClassName << " : " - << MatchedCallExpr->getMethodDecl()->getQualifiedNameAsString() - << "\n"; - } -} - -} // namespace reporting -} // namespace tidy -} // namespace clang diff --git a/reporting/InterfaceLister.h b/reporting/InterfaceLister.h deleted file mode 100644 index 5a4c91a..0000000 --- a/reporting/InterfaceLister.h +++ /dev/null @@ -1,43 +0,0 @@ -//===--- MemberNamesCheck.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_INTERFACELISTER_NAMES_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INTERFACELISTER_NAMES_H - -#include "clang-tidy/ClangTidy.h" -#include "clang-tidy/ClangTidyCheck.h" - -namespace clang { -namespace tidy { -namespace reporting { - -/// A simple tool/check that given a ClassName reports the interfaces -/// used in the code base -/// -class InterfaceLister : public ClangTidyCheck { -private: - const std::string ClassName; // the class name for which we want to find - // used interfaces -public: - InterfaceLister(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), ClassName(Options.get("ClassName", "")) {} - - void storeOptions(ClangTidyOptions::OptionMap &Opts) override { - Options.store(Opts, "ClassName", ClassName); - } - - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace reporting -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INTERFACELISTER_NAMES_H diff --git a/reporting/ReportingTidyModule.cpp b/reporting/ReportingTidyModule.cpp deleted file mode 100644 index 3674a70..0000000 --- a/reporting/ReportingTidyModule.cpp +++ /dev/null @@ -1,40 +0,0 @@ -//===--- AliceO2TidyModule.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 "clang-tidy/ClangTidy.h" -#include "clang-tidy/ClangTidyModule.h" -#include "clang-tidy/ClangTidyModuleRegistry.h" -#include "InterfaceLister.h" -#include "VirtFuncLister.h" - -namespace clang { -namespace tidy { -namespace reporting { - -class ReportingModule : public ClangTidyModule { -public: - void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck("Reporting-interfaces-used"); - - CheckFactories.registerCheck("Reporting-unusedvirtfunc"); - } -}; - -} // namespace Reporting - -// Register the ReportingTidyModule using this statically initialized variable. -static ClangTidyModuleRegistry::Add -X("Reporting-module", "Adds Reporting tools (for simple analytics)"); - -// This anchor is used to force the linker to link in the generated object file -// and thus register the ReportingModule. -volatile int ReportingModuleAnchorSource = 0; - -} // namespace tidy -} // namespace clang diff --git a/reporting/VirtFuncLister.cpp b/reporting/VirtFuncLister.cpp deleted file mode 100644 index 9fdb102..0000000 --- a/reporting/VirtFuncLister.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//===--- VirtFuncLister.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 "VirtFuncLister.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace reporting { - -void VirtFuncLister::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(cxxMethodDecl().bind("method"), this); -} - -void VirtFuncLister::check(const MatchFinder::MatchResult &Result) { - const auto &SM = *Result.SourceManager; - const auto *MatchedDecl = - Result.Nodes.getNodeAs("method"); - if (MatchedDecl) { - DeclarationNameInfo name_info = MatchedDecl->getNameInfo(); - std::string func_name = name_info.getAsString(); - - bool isvirtual = MatchedDecl->isVirtual(); - - llvm::errs() << "MEMBER FUNCTION DECL " << func_name << "("<isVirtualAsWritten() << " is virtual " - << isvirtual << "\n"; - - // get class declaration of this member function - // auto record = MatchedDecl->getCanonicalDecl()->getParent(); - - // we need to get source location the base node - // as well as overriding node - if (isvirtual) { - auto iter = MatchedDecl->begin_overridden_methods(); - auto enditer = MatchedDecl->end_overridden_methods(); - - if (iter == enditer) { - SourceLocation loc = MatchedDecl->getBeginLoc();//getLocation(); - loc.dump(SM); - llvm::errs() << "VIRTUAL-START-DECLARATION \n"; - } else { - // otherwise find the base this is referring to - decltype(iter) lastiter = iter; - while (iter != enditer) { - lastiter = iter; - // counter number of paths up; if there is more than one - // we have to give up for the moment - int counter = 0; - decltype(iter) countiter = iter; - for (; countiter != enditer; ++countiter) { - counter++; - } - if (counter > 1) { - llvm::errs() << " OVERRIDING MULTIPLE FUNCTIONS NOT TREATED YET\n"; - return; - } - enditer = (*iter)->end_overridden_methods(); - iter = (*iter)->begin_overridden_methods(); - } - SourceLocation loc = (*lastiter)->getBeginLoc();//getLocation(); - loc.dump(SM); - llvm::errs() << " OVERRIDEN-AT "; - loc = MatchedDecl->getBeginLoc();//getLocation(); - loc.dump(SM); - llvm::errs() << "\n"; - } - } - } -} - -} // namespace reporting -} // namespace tidy -} // namespace clang diff --git a/reporting/VirtFuncLister.h b/reporting/VirtFuncLister.h deleted file mode 100644 index d8ccf21..0000000 --- a/reporting/VirtFuncLister.h +++ /dev/null @@ -1,36 +0,0 @@ -//===--- MemberNamesCheck.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_VIRTFUNCLISTER_NAMES_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_VIRTFUNCLISTER_NAMES_H - -#include "clang-tidy/ClangTidy.h" -#include "clang-tidy/ClangTidyCheck.h" - -namespace clang { -namespace tidy { -namespace reporting { - -/// A simple tool/check that given a ClassName reports the interfaces -/// used in the code base -/// -class VirtFuncLister : public ClangTidyCheck { -public: - VirtFuncLister(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace reporting -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_VIRTFUNCLISTER_NAMES_H diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index 5d9de7e..ae6622f 100644 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -1,71 +1 @@ -set(LLVM_LINK_COMPONENTS - AllTargetsAsmParsers - AllTargetsDescs - AllTargetsInfos - support - ) - -add_clang_executable(O2codecheck - ClangTidyMain.cpp - ) - -target_link_libraries(O2codecheck - PRIVATE - clangAST - clangASTMatchers - clangBasic - clangTidy - - # link our own checks - clangTidyAliceO2Module - clangTidyReportingModule - - # include checkers available from main clang-tidy - clangTidyAlteraModule - clangTidyAndroidModule - clangTidyAbseilModule - clangTidyBoostModule - clangTidyBugproneModule - clangTidyCERTModule - clangTidyConcurrencyModule - clangTidyCppCoreGuidelinesModule - clangTidyDarwinModule - clangTidyFuchsiaModule - clangTidyGoogleModule - clangTidyHICPPModule - clangTidyLinuxKernelModule - clangTidyLLVMModule - clangTidyLLVMLibcModule - clangTidyMiscModule - clangTidyModernizeModule - clangTidyMPIModule - clangTidyObjCModule - clangTidyOpenMPModule - clangTidyPerformanceModule - clangTidyPortabilityModule - clangTidyReadabilityModule - clangTidyZirconModule - clangTooling - clangToolingCore - ) - -install(TARGETS O2codecheck - RUNTIME DESTINATION bin) - -#install(PROGRAMS clang-tidy-diff.py DESTINATION share/clang) install(PROGRAMS run_O2CodeChecker.py DESTINATION bin) - -# we need to install the builtin headers in a path which is searched by the tool -# FIXME: a soft link would be better -string(REPLACE "." ";" LLVM_PACKAGE_VERSION_LIST ${LLVM_PACKAGE_VERSION}) -list(GET LLVM_PACKAGE_VERSION_LIST 0 LLVM_PACKAGE_VERSION_MAJOR) -install(DIRECTORY ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION_MAJOR}/include DESTINATION lib/clang/${LLVM_PACKAGE_VERSION_MAJOR}) - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # On MacOS we need to do the same with C++ headers since they are in a non-standard location - # (alternative would be to set the CPATH environment variable) - INSTALL(CODE "execute_process(COMMAND mkdir ${CMAKE_INSTALL_PREFIX}/include)") - INSTALL(CODE "execute_process(COMMAND ln -sf \ - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++ \ - ${CMAKE_INSTALL_PREFIX}/include/c++)") -ENDIF() diff --git a/tool/ClangTidyMain.cpp b/tool/ClangTidyMain.cpp deleted file mode 100644 index 48066ef..0000000 --- a/tool/ClangTidyMain.cpp +++ /dev/null @@ -1,671 +0,0 @@ -//===--- tools/extra/clang-tidy/ClangTidyMain.cpp - Clang tidy tool -------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file implements a clang-tidy tool. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -#include "ClangTidyMain.h" -#include "clang-tidy/ClangTidy.h" -//#include "clang-tidy/ClangTidyForceLinker.h" -#include "../GlobList.h" -#include "clang/Tooling/CommonOptionsParser.h" -#include "llvm/ADT/StringSet.h" -#include "llvm/Support/InitLLVM.h" -#include "llvm/Support/PluginLoader.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/Signals.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/WithColor.h" - -using namespace clang::tooling; -using namespace llvm; - -static cl::OptionCategory ClangTidyCategory("clang-tidy options"); - -static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); -static cl::extrahelp ClangTidyHelp(R"( -Configuration files: - clang-tidy attempts to read configuration for each source file from a - .clang-tidy file located in the closest parent directory of the source - file. If InheritParentConfig is true in a config file, the configuration file - in the parent directory (if any exists) will be taken and current config file - will be applied on top of the parent one. If any configuration options have - a corresponding command-line option, command-line option takes precedence. - The effective configuration can be inspected using -dump-config: - - $ clang-tidy -dump-config - --- - Checks: '-*,some-check' - WarningsAsErrors: '' - HeaderFilterRegex: '' - FormatStyle: none - InheritParentConfig: true - User: user - CheckOptions: - some-check.SomeOption: 'some value' - ... - -)"); - -const char DefaultChecks[] = // Enable these checks by default: - "clang-diagnostic-*," // * compiler diagnostics - "clang-analyzer-*"; // * Static Analyzer checks - -static cl::opt Checks("checks", cl::desc(R"( -Comma-separated list of globs with optional '-' -prefix. Globs are processed in order of -appearance in the list. Globs without '-' -prefix add checks with matching names to the -set, globs with the '-' prefix remove checks -with matching names from the set of enabled -checks. This option's value is appended to the -value of the 'Checks' option in .clang-tidy -file, if any. -)"), - cl::init(""), cl::cat(ClangTidyCategory)); - -static cl::opt WarningsAsErrors("warnings-as-errors", cl::desc(R"( -Upgrades warnings to errors. Same format as -'-checks'. -This option's value is appended to the value of -the 'WarningsAsErrors' option in .clang-tidy -file, if any. -)"), - cl::init(""), - cl::cat(ClangTidyCategory)); - -static cl::opt HeaderFilter("header-filter", cl::desc(R"( -Regular expression matching the names of the -headers to output diagnostics from. Diagnostics -from the main file of each translation unit are -always displayed. -Can be used together with -line-filter. -This option overrides the 'HeaderFilterRegex' -option in .clang-tidy file, if any. -)"), - cl::init(""), - cl::cat(ClangTidyCategory)); - -static cl::opt - SystemHeaders("system-headers", - cl::desc("Display the errors from system headers."), - cl::init(false), cl::cat(ClangTidyCategory)); -static cl::opt LineFilter("line-filter", cl::desc(R"( -List of files with line ranges to filter the -warnings. Can be used together with --header-filter. The format of the list is a -JSON array of objects: - [ - {"name":"file1.cpp","lines":[[1,3],[5,7]]}, - {"name":"file2.h"} - ] -)"), - cl::init(""), - cl::cat(ClangTidyCategory)); - -static cl::opt Fix("fix", cl::desc(R"( -Apply suggested fixes. Without -fix-errors -clang-tidy will bail out if any compilation -errors were found. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt FixErrors("fix-errors", cl::desc(R"( -Apply suggested fixes even if compilation -errors were found. If compiler errors have -attached fix-its, clang-tidy will apply them as -well. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt FixNotes("fix-notes", cl::desc(R"( -If a warning has no fix, but a single fix can -be found through an associated diagnostic note, -apply the fix. -Specifying this flag will implicitly enable the -'--fix' flag. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt FormatStyle("format-style", cl::desc(R"( -Style for formatting code around applied fixes: - - 'none' (default) turns off formatting - - 'file' (literally 'file', not a placeholder) - uses .clang-format file in the closest parent - directory - - '{ }' specifies options inline, e.g. - -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' - - 'llvm', 'google', 'webkit', 'mozilla' -See clang-format documentation for the up-to-date -information about formatting styles and options. -This option overrides the 'FormatStyle` option in -.clang-tidy file, if any. -)"), - cl::init("none"), - cl::cat(ClangTidyCategory)); - -static cl::opt ListChecks("list-checks", cl::desc(R"( -List all enabled checks and exit. Use with --checks=* to list all available checks. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt ExplainConfig("explain-config", cl::desc(R"( -For each enabled check explains, where it is -enabled, i.e. in clang-tidy binary, command -line or a specific configuration file. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt Config("config", cl::desc(R"( -Specifies a configuration in YAML/JSON format: - -config="{Checks: '*', - CheckOptions: {x: y}}" -When the value is empty, clang-tidy will -attempt to find a file named .clang-tidy for -each source file in its parent directories. -)"), - cl::init(""), cl::cat(ClangTidyCategory)); - -static cl::opt ConfigFile("config-file", cl::desc(R"( -Specify the path of .clang-tidy or custom config file: - e.g. --config-file=/some/path/myTidyConfigFile -This option internally works exactly the same way as - --config option after reading specified config file. -Use either --config-file or --config, not both. -)"), - cl::init(""), - cl::cat(ClangTidyCategory)); - -static cl::opt DumpConfig("dump-config", cl::desc(R"( -Dumps configuration in the YAML format to -stdout. This option can be used along with a -file name (and '--' if the file is outside of a -project with configured compilation database). -The configuration used for this file will be -printed. -Use along with -checks=* to include -configuration of all checks. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt EnableCheckProfile("enable-check-profile", cl::desc(R"( -Enable per-check timing profiles, and print a -report to stderr. -)"), - cl::init(false), - cl::cat(ClangTidyCategory)); - -static cl::opt StoreCheckProfile("store-check-profile", - cl::desc(R"( -By default reports are printed in tabulated -format to stderr. When this option is passed, -these per-TU profiles are instead stored as JSON. -)"), - cl::value_desc("prefix"), - cl::cat(ClangTidyCategory)); - -/// This option allows enabling the experimental alpha checkers from the static -/// analyzer. This option is set to false and not visible in help, because it is -/// highly not recommended for users. -static cl::opt - AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", - cl::init(false), cl::Hidden, - cl::cat(ClangTidyCategory)); - -static cl::opt ExportFixes("export-fixes", cl::desc(R"( -YAML file to store suggested fixes in. The -stored fixes can be applied to the input source -code with clang-apply-replacements. -)"), - cl::value_desc("filename"), - cl::cat(ClangTidyCategory)); - -static cl::opt Quiet("quiet", cl::desc(R"( -Run clang-tidy in quiet mode. This suppresses -printing statistics about ignored warnings and -warnings treated as errors if the respective -options are specified. -)"), - cl::init(false), - cl::cat(ClangTidyCategory)); - -static cl::opt VfsOverlay("vfsoverlay", cl::desc(R"( -Overlay the virtual filesystem described by file -over the real file system. -)"), - cl::value_desc("filename"), - cl::cat(ClangTidyCategory)); - -static cl::opt UseColor("use-color", cl::desc(R"( -Use colors in diagnostics. If not set, colors -will be used if the terminal connected to -standard output supports colors. -This option overrides the 'UseColor' option in -.clang-tidy file, if any. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -static cl::opt VerifyConfig("verify-config", cl::desc(R"( -Check the config files to ensure each check and -option is recognized. -)"), - cl::init(false), cl::cat(ClangTidyCategory)); - -namespace clang { -namespace tidy { - -static void printStats(const ClangTidyStats &Stats) { - if (Stats.errorsIgnored()) { - llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings ("; - StringRef Separator = ""; - if (Stats.ErrorsIgnoredNonUserCode) { - llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code"; - Separator = ", "; - } - if (Stats.ErrorsIgnoredLineFilter) { - llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter - << " due to line filter"; - Separator = ", "; - } - if (Stats.ErrorsIgnoredNOLINT) { - llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT"; - Separator = ", "; - } - if (Stats.ErrorsIgnoredCheckFilter) - llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter - << " with check filters"; - llvm::errs() << ").\n"; - if (Stats.ErrorsIgnoredNonUserCode) - llvm::errs() << "Use -header-filter=.* to display errors from all " - "non-system headers. Use -system-headers to display " - "errors from system headers as well.\n"; - } -} - -static std::unique_ptr createOptionsProvider( - llvm::IntrusiveRefCntPtr FS) { - ClangTidyGlobalOptions GlobalOptions; - if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) { - llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return nullptr; - } - - ClangTidyOptions DefaultOptions; - DefaultOptions.Checks = DefaultChecks; - DefaultOptions.WarningsAsErrors = ""; - DefaultOptions.HeaderFilterRegex = HeaderFilter; - DefaultOptions.SystemHeaders = SystemHeaders; - DefaultOptions.FormatStyle = FormatStyle; - DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); - // USERNAME is used on Windows. - if (!DefaultOptions.User) - DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME"); - - ClangTidyOptions OverrideOptions; - if (Checks.getNumOccurrences() > 0) - OverrideOptions.Checks = Checks; - if (WarningsAsErrors.getNumOccurrences() > 0) - OverrideOptions.WarningsAsErrors = WarningsAsErrors; - if (HeaderFilter.getNumOccurrences() > 0) - OverrideOptions.HeaderFilterRegex = HeaderFilter; - if (SystemHeaders.getNumOccurrences() > 0) - OverrideOptions.SystemHeaders = SystemHeaders; - if (FormatStyle.getNumOccurrences() > 0) - OverrideOptions.FormatStyle = FormatStyle; - if (UseColor.getNumOccurrences() > 0) - OverrideOptions.UseColor = UseColor; - - auto LoadConfig = - [&](StringRef Configuration, - StringRef Source) -> std::unique_ptr { - llvm::ErrorOr ParsedConfig = - parseConfiguration(MemoryBufferRef(Configuration, Source)); - if (ParsedConfig) - return std::make_unique( - std::move(GlobalOptions), - ClangTidyOptions::getDefaults().merge(DefaultOptions, 0), - std::move(*ParsedConfig), std::move(OverrideOptions), std::move(FS)); - llvm::errs() << "Error: invalid configuration specified.\n" - << ParsedConfig.getError().message() << "\n"; - return nullptr; - }; - - if (ConfigFile.getNumOccurrences() > 0) { - if (Config.getNumOccurrences() > 0) { - llvm::errs() << "Error: --config-file and --config are " - "mutually exclusive. Specify only one.\n"; - return nullptr; - } - - llvm::ErrorOr> Text = - llvm::MemoryBuffer::getFile(ConfigFile); - if (std::error_code EC = Text.getError()) { - llvm::errs() << "Error: can't read config-file '" << ConfigFile - << "': " << EC.message() << "\n"; - return nullptr; - } - - return LoadConfig((*Text)->getBuffer(), ConfigFile); - } - - if (Config.getNumOccurrences() > 0) - return LoadConfig(Config, ""); - - return std::make_unique( - std::move(GlobalOptions), std::move(DefaultOptions), - std::move(OverrideOptions), std::move(FS)); -} - -llvm::IntrusiveRefCntPtr -getVfsFromFile(const std::string &OverlayFile, - llvm::IntrusiveRefCntPtr BaseFS) { - llvm::ErrorOr> Buffer = - BaseFS->getBufferForFile(OverlayFile); - if (!Buffer) { - llvm::errs() << "Can't load virtual filesystem overlay file '" - << OverlayFile << "': " << Buffer.getError().message() - << ".\n"; - return nullptr; - } - - IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( - std::move(Buffer.get()), /*DiagHandler*/ nullptr, OverlayFile); - if (!FS) { - llvm::errs() << "Error: invalid virtual filesystem overlay file '" - << OverlayFile << "'.\n"; - return nullptr; - } - return FS; -} - -static StringRef closest(StringRef Value, const StringSet<> &Allowed) { - unsigned MaxEdit = 5U; - StringRef Closest; - for (auto Item : Allowed.keys()) { - unsigned Cur = Value.edit_distance_insensitive(Item, true, MaxEdit); - if (Cur < MaxEdit) { - Closest = Item; - MaxEdit = Cur; - } - } - return Closest; -} - -static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n"; - -static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob, - StringRef Source) { - llvm::StringRef Cur, Rest; - bool AnyInvalid = false; - for (std::tie(Cur, Rest) = CheckGlob.split(','); - !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) { - Cur = Cur.trim(); - if (Cur.empty()) - continue; - Cur.consume_front("-"); - if (Cur.starts_with("clang-diagnostic")) - continue; - if (Cur.contains('*')) { - SmallString<128> RegexText("^"); - StringRef MetaChars("()^$|*+?.[]\\{}"); - for (char C : Cur) { - if (C == '*') - RegexText.push_back('.'); - else if (MetaChars.contains(C)) - RegexText.push_back('\\'); - RegexText.push_back(C); - } - RegexText.push_back('$'); - llvm::Regex Glob(RegexText); - std::string Error; - if (!Glob.isValid(Error)) { - AnyInvalid = true; - llvm::WithColor::error(llvm::errs(), Source) - << "building check glob '" << Cur << "' " << Error << "'\n"; - continue; - } - if (llvm::none_of(AllChecks.keys(), - [&Glob](StringRef S) { return Glob.match(S); })) { - AnyInvalid = true; - llvm::WithColor::warning(llvm::errs(), Source) - << "check glob '" << Cur << "' doesn't match any known check" - << VerifyConfigWarningEnd; - } - } else { - if (AllChecks.contains(Cur)) - continue; - AnyInvalid = true; - llvm::raw_ostream &Output = llvm::WithColor::warning(llvm::errs(), Source) - << "unknown check '" << Cur << '\''; - llvm::StringRef Closest = closest(Cur, AllChecks); - if (!Closest.empty()) - Output << "; did you mean '" << Closest << '\''; - Output << VerifyConfigWarningEnd; - } - } - return AnyInvalid; -} - -int clangTidyMain(int argc, const char **argv) { - llvm::InitLLVM X(argc, argv); - - // Enable help for -load option, if plugins are enabled. - if (cl::Option *LoadOpt = cl::getRegisteredOptions().lookup("load")) - LoadOpt->addCategory(ClangTidyCategory); - - llvm::Expected OptionsParser = - CommonOptionsParser::create(argc, argv, ClangTidyCategory, - cl::ZeroOrMore); - if (!OptionsParser) { - llvm::WithColor::error() << llvm::toString(OptionsParser.takeError()); - return 1; - } - - llvm::IntrusiveRefCntPtr BaseFS( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - - if (!VfsOverlay.empty()) { - IntrusiveRefCntPtr VfsFromFile = - getVfsFromFile(VfsOverlay, BaseFS); - if (!VfsFromFile) - return 1; - BaseFS->pushOverlay(std::move(VfsFromFile)); - } - - auto OwningOptionsProvider = createOptionsProvider(BaseFS); - auto *OptionsProvider = OwningOptionsProvider.get(); - if (!OptionsProvider) - return 1; - - auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> { - if (Input.empty()) - return {}; - SmallString<256> AbsolutePath(Input); - if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) { - llvm::errs() << "Can't make absolute path from " << Input << ": " - << EC.message() << "\n"; - } - return AbsolutePath; - }; - - SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile); - - StringRef FileName("dummy"); - auto PathList = OptionsParser->getSourcePathList(); - if (!PathList.empty()) { - FileName = PathList.front(); - } - - SmallString<256> FilePath = MakeAbsolute(std::string(FileName)); - - ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath); - std::vector EnabledChecks = - getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers); - - if (ExplainConfig) { - // FIXME: Show other ClangTidyOptions' fields, like ExtraArg. - std::vector - RawOptions = OptionsProvider->getRawOptions(FilePath); - for (const std::string &Check : EnabledChecks) { - for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) { - if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) { - llvm::outs() << "'" << Check << "' is enabled in the " << It->second - << ".\n"; - break; - } - } - } - return 0; - } - - if (ListChecks) { - if (EnabledChecks.empty()) { - llvm::errs() << "No checks enabled.\n"; - return 1; - } - llvm::outs() << "Enabled checks:"; - for (const auto &CheckName : EnabledChecks) - llvm::outs() << "\n " << CheckName; - llvm::outs() << "\n\n"; - return 0; - } - - if (DumpConfig) { - EffectiveOptions.CheckOptions = - getCheckOptions(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers); - llvm::outs() << configurationAsText(ClangTidyOptions::getDefaults().merge( - EffectiveOptions, 0)) - << "\n"; - return 0; - } - - if (VerifyConfig) { - std::vector RawOptions = - OptionsProvider->getRawOptions(FileName); - NamesAndOptions Valid = - getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers); - bool AnyInvalid = false; - for (const std::pair &OptionWithSource : - RawOptions) { - const ClangTidyOptions &Opts = OptionWithSource.first; - if (Opts.Checks) - AnyInvalid |= - verifyChecks(Valid.Names, *Opts.Checks, OptionWithSource.second); - - for (auto Key : Opts.CheckOptions.keys()) { - if (Valid.Options.contains(Key)) - continue; - AnyInvalid = true; - auto &Output = - llvm::WithColor::warning(llvm::errs(), OptionWithSource.second) - << "unknown check option '" << Key << '\''; - llvm::StringRef Closest = closest(Key, Valid.Options); - if (!Closest.empty()) - Output << "; did you mean '" << Closest << '\''; - Output << VerifyConfigWarningEnd; - } - } - if (AnyInvalid) - return 1; - llvm::outs() << "No config errors detected.\n"; - return 0; - } - - if (EnabledChecks.empty()) { - llvm::errs() << "Error: no checks enabled.\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return 1; - } - - if (PathList.empty()) { - llvm::errs() << "Error: no input files specified.\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return 1; - } - - llvm::InitializeAllTargetInfos(); - llvm::InitializeAllTargetMCs(); - llvm::InitializeAllAsmParsers(); - - ClangTidyContext Context(std::move(OwningOptionsProvider), - AllowEnablingAnalyzerAlphaCheckers); - std::vector Errors = - runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS, - FixNotes, EnableCheckProfile, ProfilePrefix); - bool FoundErrors = llvm::any_of(Errors, [](const ClangTidyError &E) { - return E.DiagLevel == ClangTidyError::Error; - }); - - // --fix-errors and --fix-notes imply --fix. - FixBehaviour Behaviour = FixNotes ? FB_FixNotes - : (Fix || FixErrors) ? FB_Fix - : FB_NoFix; - - const bool DisableFixes = FoundErrors && !FixErrors; - - unsigned WErrorCount = 0; - - handleErrors(Errors, Context, DisableFixes ? FB_NoFix : Behaviour, - WErrorCount, BaseFS); - - if (!ExportFixes.empty() && !Errors.empty()) { - std::error_code EC; - llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::OF_None); - if (EC) { - llvm::errs() << "Error opening output file: " << EC.message() << '\n'; - return 1; - } - exportReplacements(FilePath.str(), Errors, OS); - } - - if (!Quiet) { - printStats(Context.getStats()); - if (DisableFixes && Behaviour != FB_NoFix) - llvm::errs() - << "Found compiler errors, but -fix-errors was not specified.\n" - "Fixes have NOT been applied.\n\n"; - } - - if (WErrorCount) { - if (!Quiet) { - StringRef Plural = WErrorCount == 1 ? "" : "s"; - llvm::errs() << WErrorCount << " warning" << Plural << " treated as error" - << Plural << "\n"; - } - return 1; - } - - if (FoundErrors) { - // TODO: Figure out when zero exit code should be used with -fix-errors: - // a. when a fix has been applied for an error - // b. when a fix has been applied for all errors - // c. some other condition. - // For now always returning zero when -fix-errors is used. - if (FixErrors) - return 0; - if (!Quiet) - llvm::errs() << "Found compiler error(s).\n"; - return 1; - } - - return 0; -} - -} // namespace tidy -} // namespace clang - -int main(int argc, const char **argv) { - return clang::tidy::clangTidyMain(argc, argv); -} diff --git a/tool/ClangTidyMain.h b/tool/ClangTidyMain.h deleted file mode 100644 index f87f84b..0000000 --- a/tool/ClangTidyMain.h +++ /dev/null @@ -1,23 +0,0 @@ -//===--- tools/extra/clang-tidy/ClangTidyMain.h - Clang tidy tool -------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file declares the main function for the clang-tidy tool. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -namespace clang { -namespace tidy { - -int clangTidyMain(int argc, const char **argv); - -} // namespace tidy -} // namespace clang diff --git a/tool/clang-tidy-diff.py b/tool/clang-tidy-diff.py deleted file mode 100755 index e3dcbe7..0000000 --- a/tool/clang-tidy-diff.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python -# -#===- clang-tidy-diff.py - ClangTidy Diff Checker ------------*- python -*--===# -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -#===------------------------------------------------------------------------===# - -r""" -ClangTidy Diff Checker -====================== - -This script reads input from a unified diff, runs clang-tidy on all changed -files and outputs clang-tidy warnings in changed lines only. This is useful to -detect clang-tidy regressions in the lines touched by a specific patch. -Example usage for git/svn users: - - git diff -U0 HEAD^ | clang-tidy-diff.py -p1 - svn diff --diff-cmd=diff -x-U0 | \ - clang-tidy-diff.py -fix -checks=-*,modernize-use-override - -""" - -import argparse -import json -import re -import subprocess -import sys - - -def main(): - parser = argparse.ArgumentParser(description= - 'Run clang-tidy against changed files, and ' - 'output diagnostics only for modified ' - 'lines.') - parser.add_argument('-clang-tidy-binary', metavar='PATH', - default='clang-tidy', - help='path to clang-tidy binary') - parser.add_argument('-p', metavar='NUM', default=0, - help='strip the smallest prefix containing P slashes') - parser.add_argument('-regex', metavar='PATTERN', default=None, - help='custom pattern selecting file paths to check ' - '(case sensitive, overrides -iregex)') - parser.add_argument('-iregex', metavar='PATTERN', default= - r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc)', - help='custom pattern selecting file paths to check ' - '(case insensitive, overridden by -regex)') - - parser.add_argument('-fix', action='store_true', default=False, - help='apply suggested fixes') - parser.add_argument('-checks', - help='checks filter, when not specified, use clang-tidy ' - 'default', - default='') - clang_tidy_args = [] - argv = sys.argv[1:] - if '--' in argv: - clang_tidy_args.extend(argv[argv.index('--'):]) - argv = argv[:argv.index('--')] - - args = parser.parse_args(argv) - - # Extract changed lines for each file. - filename = None - lines_by_file = {} - for line in sys.stdin: - match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line) - if match: - filename = match.group(2) - if filename == None: - continue - - if args.regex is not None: - if not re.match('^%s$' % args.regex, filename): - continue - else: - if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): - continue - - match = re.search('^@@.*\+(\d+)(,(\d+))?', line) - if match: - start_line = int(match.group(1)) - line_count = 1 - if match.group(3): - line_count = int(match.group(3)) - if line_count == 0: - continue - end_line = start_line + line_count - 1; - lines_by_file.setdefault(filename, []).append([start_line, end_line]) - - if len(lines_by_file) == 0: - print("No relevant changes found.") - sys.exit(0) - - line_filter_json = json.dumps( - [{"name" : name, "lines" : lines_by_file[name]} for name in lines_by_file], - separators = (',', ':')) - - quote = ""; - if sys.platform == 'win32': - line_filter_json=re.sub(r'"', r'"""', line_filter_json) - else: - quote = "'"; - - # Run clang-tidy on files containing changes. - command = [args.clang_tidy_binary] - command.append('-line-filter=' + quote + line_filter_json + quote) - if args.fix: - command.append('-fix') - if args.checks != '': - command.append('-checks=' + quote + args.checks + quote) - command.extend(lines_by_file.keys()) - command.extend(clang_tidy_args) - - sys.exit(subprocess.call(' '.join(command), shell=True)) - -if __name__ == '__main__': - main()