Skip to content

Commit

Permalink
sanity: Get rid of sanitize_ignore()
Browse files Browse the repository at this point in the history
It's probably nicer to avoid evaluating expensive arguments when not
sanitizing, rather than relying on the optimizer to clean them up.
  • Loading branch information
tavianator committed Dec 16, 2024
1 parent 2c85beb commit ce37830
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ void *varena_realloc(struct varena *varena, void *ptr, size_t old_count, size_t
return NULL;
}

size_t new_exact_size = varena_exact_size(varena, new_count);
size_t old_exact_size = varena_exact_size(varena, old_count);
_maybe_unused size_t new_exact_size = varena_exact_size(varena, new_count);
_maybe_unused size_t old_exact_size = varena_exact_size(varena, old_count);

if (new_arena == old_arena) {
if (new_count < old_count) {
Expand Down
13 changes: 4 additions & 9 deletions src/sanity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
#define SANITIZE_CALL__(macro, ptr, size, ...) \
macro(ptr, size)

/**
* Squelch unused variable warnings when not sanitizing.
*/
#define sanitize_ignore(ptr, size) ((void)(ptr), (void)(size))

#if __SANITIZE_ADDRESS__
# include <sanitizer/asan_interface.h>

Expand All @@ -43,8 +38,8 @@
#define sanitize_free(...) SANITIZE_CALL(__asan_poison_memory_region, __VA_ARGS__)

#else
# define sanitize_alloc(...) SANITIZE_CALL(sanitize_ignore, __VA_ARGS__)
# define sanitize_free(...) SANITIZE_CALL(sanitize_ignore, __VA_ARGS__)
# define sanitize_alloc(...) ((void)0)
# define sanitize_free(...) ((void)0)
#endif

#if __SANITIZE_MEMORY__
Expand All @@ -65,8 +60,8 @@
#define sanitize_uninit(...) SANITIZE_CALL(__msan_allocated_memory, __VA_ARGS__)

#else
# define sanitize_init(...) SANITIZE_CALL(sanitize_ignore, __VA_ARGS__)
# define sanitize_uninit(...) SANITIZE_CALL(sanitize_ignore, __VA_ARGS__)
# define sanitize_init(...) ((void)0)
# define sanitize_uninit(...) ((void)0)
#endif

/**
Expand Down

0 comments on commit ce37830

Please sign in to comment.