[compiler-rt] a9a1499 - [NFC][lsan] Change LeakSuppressionContext interface
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 9 11:38:17 PST 2021
Author: Vitaly Buka
Date: 2021-12-09T11:38:02-08:00
New Revision: a9a14990809dbc4fb081ae0ae61f15c4a422b86c
URL: https://github.com/llvm/llvm-project/commit/a9a14990809dbc4fb081ae0ae61f15c4a422b86c
DIFF: https://github.com/llvm/llvm-project/commit/a9a14990809dbc4fb081ae0ae61f15c4a422b86c.diff
LOG: [NFC][lsan] Change LeakSuppressionContext interface
Reviewed By: morehouse
Differential Revision: https://reviews.llvm.org/D115318
Added:
Modified:
compiler-rt/lib/lsan/lsan_common.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 510b4a35be475..ee20ed2a67809 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -74,14 +74,14 @@ class LeakSuppressionContext {
Suppression *GetSuppressionForAddr(uptr addr);
void LazyInit();
+ bool SuppressByRule(const StackTrace &stack, uptr hit_count, uptr total_size);
public:
LeakSuppressionContext(const char *supprression_types[],
int suppression_types_num)
: context(supprression_types, suppression_types_num) {}
- Suppression *GetSuppressionForStack(u32 stack_trace_id,
- const StackTrace &stack);
+ bool Suppress(u32 stack_trace_id, uptr hit_count, uptr total_size);
const InternalMmapVector<u32> &GetSortedSuppressedStacks() {
if (!suppressed_stacks_sorted) {
@@ -148,19 +148,29 @@ Suppression *LeakSuppressionContext::GetSuppressionForAddr(uptr addr) {
return s;
}
-Suppression *LeakSuppressionContext::GetSuppressionForStack(
- u32 stack_trace_id, const StackTrace &stack) {
- LazyInit();
+bool LeakSuppressionContext::SuppressByRule(const StackTrace &stack,
+ uptr hit_count, uptr total_size) {
for (uptr i = 0; i < stack.size; i++) {
Suppression *s = GetSuppressionForAddr(
StackTrace::GetPreviousInstructionPc(stack.trace[i]));
if (s) {
- suppressed_stacks_sorted = false;
- suppressed_stacks.push_back(stack_trace_id);
- return s;
+ s->weight += total_size;
+ atomic_fetch_add(&s->hit_count, hit_count, memory_order_relaxed);
+ return true;
}
}
- return nullptr;
+ return false;
+}
+
+bool LeakSuppressionContext::Suppress(u32 stack_trace_id, uptr hit_count,
+ uptr total_size) {
+ LazyInit();
+ StackTrace stack = StackDepotGet(stack_trace_id);
+ if (!SuppressByRule(stack, hit_count, total_size))
+ return false;
+ suppressed_stacks_sorted = false;
+ suppressed_stacks.push_back(stack_trace_id);
+ return true;
}
static LeakSuppressionContext *GetSuppressionContext() {
@@ -909,12 +919,8 @@ uptr LeakReport::ApplySuppressions() {
LeakSuppressionContext *suppressions = GetSuppressionContext();
uptr new_suppressions = false;
for (uptr i = 0; i < leaks_.size(); i++) {
- Suppression *s = suppressions->GetSuppressionForStack(
- leaks_[i].stack_trace_id, StackDepotGet(leaks_[i].stack_trace_id));
- if (s) {
- s->weight += leaks_[i].total_size;
- atomic_fetch_add(&s->hit_count, leaks_[i].hit_count,
- memory_order_relaxed);
+ if (suppressions->Suppress(leaks_[i].stack_trace_id, leaks_[i].hit_count,
+ leaks_[i].total_size)) {
leaks_[i].is_suppressed = true;
++new_suppressions;
}
More information about the llvm-commits
mailing list