Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify clang-format config #11

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: LLVM
Language: Cpp
CommentPragmas: "(NOLINT|^ IWYU pragma:)"
5 changes: 4 additions & 1 deletion development/cli/style_check/clang_format.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}
50 changes: 24 additions & 26 deletions libc_replacer/cc/internal/definition_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@
#include "libc_replacer/cc/internal/macro_impl.h"
#include <stdatomic.h>

/// @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.
/// @param ret_t Return value type of the libc API.
/// @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_