Skip to content

[NFC][sanitizer] Use UNLIKELY in VReport/VPrintf #104403

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

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: 2 additions & 2 deletions compiler-rt/lib/asan/asan_poisoning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p,
const void *new_mid_p) {
if (!flags()->detect_container_overflow)
return;
VPrintf(2, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p,
VPrintf(3, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p,
new_mid_p);
uptr storage_beg = reinterpret_cast<uptr>(beg_p);
uptr storage_end = reinterpret_cast<uptr>(end_p);
Expand Down Expand Up @@ -479,7 +479,7 @@ void __sanitizer_annotate_double_ended_contiguous_container(
if (!flags()->detect_container_overflow)
return;

VPrintf(2, "contiguous_container: %p %p %p %p %p %p\n", storage_beg_p,
VPrintf(3, "contiguous_container: %p %p %p %p %p %p\n", storage_beg_p,
storage_end_p, old_container_beg_p, old_container_end_p,
new_container_beg_p, new_container_end_p);

Expand Down
14 changes: 8 additions & 6 deletions compiler-rt/lib/sanitizer_common/sanitizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ void RemoveANSIEscapeSequencesFromString(char *buffer);
void Printf(const char *format, ...) FORMAT(1, 2);
void Report(const char *format, ...) FORMAT(1, 2);
void SetPrintfAndReportCallback(void (*callback)(const char *));
#define VReport(level, ...) \
do { \
if ((uptr)Verbosity() >= (level)) Report(__VA_ARGS__); \
#define VReport(level, ...) \
do { \
if (UNLIKELY((uptr)Verbosity() >= (level))) \
Report(__VA_ARGS__); \
} while (0)
#define VPrintf(level, ...) \
do { \
if ((uptr)Verbosity() >= (level)) Printf(__VA_ARGS__); \
#define VPrintf(level, ...) \
do { \
if (UNLIKELY((uptr)Verbosity() >= (level))) \
Printf(__VA_ARGS__); \
} while (0)

// Lock sanitizer error reporting and protects against nested errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static DTLS::DTVBlock *DTLS_NextBlock(atomic_uintptr_t *cur) {
}

static DTLS::DTV *DTLS_Find(uptr id) {
VReport(2, "__tls_get_addr: DTLS_Find %p %zd\n", (void *)&dtls, id);
VReport(3, "__tls_get_addr: DTLS_Find %p %zd\n", (void *)&dtls, id);
static constexpr uptr kPerBlock = ARRAY_SIZE(DTLS::DTVBlock::dtvs);
DTLS::DTVBlock *cur = DTLS_NextBlock(&dtls.dtv_block);
if (!cur)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t.so
// RUN: %clangxx --std=c++11 %s -o %t
// RUN: %env_tool_opts=verbosity=2 %run %t 2>&1 | FileCheck %s
// RUN: %env_tool_opts=verbosity=3 %run %t 2>&1 | FileCheck %s

// Does not call __tls_get_addr
// UNSUPPORTED: i386-linux
Expand Down
Loading