diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7796597 --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +--- +BasedOnStyle: LLVM +Language: Cpp +CommentPragmas: "(NOLINT|^ IWYU pragma:)" diff --git a/development/cli/style_check/clang_format.bash b/development/cli/style_check/clang_format.bash index 2858e9c..4e5a4f2 100755 --- a/development/cli/style_check/clang_format.bash +++ b/development/cli/style_check/clang_format.bash @@ -15,4 +15,7 @@ clang_format_targets="$( xargs -I{} echo "$(pwd)/{}" )" -"${BAZEL_EXECUTABLE[@]}" run -- @clang_tools//:clang_format -i ${clang_format_targets} +"${BAZEL_EXECUTABLE[@]}" run -- @clang_tools//:clang_format \ + -style=file \ + --assume-filename="${REPO_ROOT_DIR}/.clang-format" \ + -i ${clang_format_targets} diff --git a/libc_replacer/cc/internal/definition_helper.h b/libc_replacer/cc/internal/definition_helper.h index f60d47b..492cdb6 100644 --- a/libc_replacer/cc/internal/definition_helper.h +++ b/libc_replacer/cc/internal/definition_helper.h @@ -4,10 +4,8 @@ #include "libc_replacer/cc/internal/macro_impl.h" #include -/// @note Suppress clang-tidy warnings occuring inside macros. -#define LIBC_REPLACER_INTERNAL_NOLINTBEGIN -/// @note Suppress clang-tidy warnings occuring inside macros. -#define LIBC_REPLACER_INTERNAL_NOLINTEND +/// @brief Macro for annotation. +#define LIBC_REPLACER_INTERNAL_ANNOTATE() /// @brief Define replacer functions of a libc API. /// @param library Name of the libc API to replace. @@ -15,27 +13,27 @@ /// @param ... Argument value types of the libc API. /// @note Disable `cppcoreguidelines-avoid-non-const-global-variables` for /// defining a global atomic function pointer. -#define LIBC_REPLACER_INTERNAL_DEFINE(library, ret_t, ...) \ - LIBC_REPLACER_INTERNAL_NOLINTBEGIN \ - ret_t __real_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ - ret_t __wrap_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ - static _Atomic(libc_replacer_##library##_func_ptr_t) \ - libc_replacer_func_global = __real_##library; \ - void libc_replacer_overwrite_##library( \ - libc_replacer_##library##_func_ptr_t func_new) { \ - atomic_store(&libc_replacer_func_global, func_new); \ - } \ - void libc_replacer_reset_##library(void) { \ - atomic_store(&libc_replacer_func_global, __real_##library); \ - } \ - ret_t __wrap_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)) { \ - libc_replacer_##library##_func_ptr_t func_got = \ - atomic_load(&libc_replacer_func_global); \ - return func_got(LIBC_REPLACER_INTERNAL_GET_ARG_NAMES(__VA_ARGS__)); \ - } \ - LIBC_REPLACER_INTERNAL_NOLINTEND +#define LIBC_REPLACER_INTERNAL_DEFINE(library, ret_t, ...) \ + ret_t __real_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ + ret_t __wrap_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ + static _Atomic(libc_replacer_##library##_func_ptr_t) \ + LIBC_REPLACER_INTERNAL_ANNOTATE( \ + /* NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) */) \ + libc_replacer_func_global = __real_##library; \ + void libc_replacer_overwrite_##library( \ + libc_replacer_##library##_func_ptr_t func_new) { \ + atomic_store(&libc_replacer_func_global, func_new); \ + } \ + void libc_replacer_reset_##library(void) { \ + atomic_store(&libc_replacer_func_global, __real_##library); \ + } \ + ret_t __wrap_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)) { \ + libc_replacer_##library##_func_ptr_t func_got = \ + atomic_load(&libc_replacer_func_global); \ + return func_got(LIBC_REPLACER_INTERNAL_GET_ARG_NAMES(__VA_ARGS__)); \ + } #endif // INCLUDE_GUARD_LIBC_REPLACER_CC_INTERNAL_DEFINITION_HELPER_H_