Skip to content

Commit 8f8d5f0

Browse files
authored
[rtsan] Add statistics for suppression count (#112718)
1 parent 6d7712a commit 8f8d5f0

File tree

8 files changed

+40
-4
lines changed

8 files changed

+40
-4
lines changed

compiler-rt/lib/rtsan/rtsan_assertions.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "rtsan/rtsan.h"
1616
#include "rtsan/rtsan_context.h"
1717
#include "rtsan/rtsan_diagnostics.h"
18+
#include "rtsan/rtsan_stats.h"
1819
#include "rtsan/rtsan_suppressions.h"
1920

2021
#include "sanitizer_common/sanitizer_stacktrace.h"
@@ -28,8 +29,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
2829
if (context.InRealtimeContext() && !context.IsBypassed()) {
2930
ScopedBypass sb{context};
3031

31-
if (IsFunctionSuppressed(info.func_name))
32+
if (IsFunctionSuppressed(info.func_name)) {
33+
IncrementSuppressedCount();
3234
return;
35+
}
3336

3437
__sanitizer::BufferedStackTrace stack;
3538

@@ -38,8 +41,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
3841
stack.Unwind(info.pc, info.bp, nullptr,
3942
__sanitizer::common_flags()->fast_unwind_on_fatal);
4043

41-
if (IsStackTraceSuppressed(stack))
44+
if (IsStackTraceSuppressed(stack)) {
45+
IncrementSuppressedCount();
4246
return;
47+
}
4348

4449
OnViolation(stack, info);
4550
}

compiler-rt/lib/rtsan/rtsan_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct Flags {
1818
Type Name{DefaultValue};
1919
#include "rtsan_flags.inc"
2020
#undef RTSAN_FLAG
21+
22+
bool ContainsSuppresionFile() { return suppressions[0] != '\0'; }
2123
};
2224

2325
extern Flags flags_data;

compiler-rt/lib/rtsan/rtsan_stats.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "rtsan/rtsan_stats.h"
14+
#include "rtsan/rtsan_flags.h"
1415

1516
#include "sanitizer_common/sanitizer_atomic.h"
1617
#include "sanitizer_common/sanitizer_common.h"
@@ -20,6 +21,7 @@ using namespace __rtsan;
2021

2122
static atomic_uint32_t rtsan_total_error_count{0};
2223
static atomic_uint32_t rtsan_unique_error_count{0};
24+
static atomic_uint32_t rtsan_suppressed_count{0};
2325

2426
void __rtsan::IncrementTotalErrorCount() {
2527
atomic_fetch_add(&rtsan_total_error_count, 1, memory_order_relaxed);
@@ -37,9 +39,20 @@ static u32 GetUniqueErrorCount() {
3739
return atomic_load(&rtsan_unique_error_count, memory_order_relaxed);
3840
}
3941

42+
void __rtsan::IncrementSuppressedCount() {
43+
atomic_fetch_add(&rtsan_suppressed_count, 1, memory_order_relaxed);
44+
}
45+
46+
static u32 GetSuppressedCount() {
47+
return atomic_load(&rtsan_suppressed_count, memory_order_relaxed);
48+
}
49+
4050
void __rtsan::PrintStatisticsSummary() {
4151
ScopedErrorReportLock l;
4252
Printf("RealtimeSanitizer exit stats:\n");
4353
Printf(" Total error count: %u\n", GetTotalErrorCount());
4454
Printf(" Unique error count: %u\n", GetUniqueErrorCount());
55+
56+
if (flags().ContainsSuppresionFile())
57+
Printf(" Suppression count: %u\n", GetSuppressedCount());
4558
}

compiler-rt/lib/rtsan/rtsan_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace __rtsan {
1616

1717
void IncrementTotalErrorCount();
1818
void IncrementUniqueErrorCount();
19+
void IncrementSuppressedCount();
1920

2021
void PrintStatisticsSummary();
2122

compiler-rt/lib/rtsan/rtsan_suppressions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void __rtsan::InitializeSuppressions() {
5656
CHECK_EQ(nullptr, suppression_ctx);
5757

5858
// We will use suppression_ctx == nullptr as an early out
59-
if (flags().suppressions[0] == '\0')
59+
if (!flags().ContainsSuppresionFile())
6060
return;
6161

6262
suppression_ctx = new (suppression_placeholder)

compiler-rt/test/rtsan/exit_stats.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clangxx -fsanitize=realtime %s -o %t
22
// RUN: %env_rtsan_opts="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
33
// RUN: %env_rtsan_opts="halt_on_error=true,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HALT
4+
// RUN: %env_rtsan_opts="suppressions=%s.supp,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPPRESSIONS
45

56
// UNSUPPORTED: ios
67

@@ -23,7 +24,17 @@ int main() {
2324
// CHECK: RealtimeSanitizer exit stats:
2425
// CHECK-NEXT: Total error count: 10
2526
// CHECK-NEXT: Unique error count: 1
27+
// CHECK-NOT: Suppression count
2628

2729
// CHECK-HALT: RealtimeSanitizer exit stats:
2830
// CHECK-HALT-NEXT: Total error count: 1
2931
// CHECK-HALT-NEXT: Unique error count: 1
32+
// CHECK-HALT-NOT: Suppression count
33+
34+
// We pass in intentionally_non_existant_function in the suppressions file
35+
// This is just to ensure we only get the "Suppression count" metric if this
36+
// file is passed at runtime, otherwise that statistic is omitted
37+
// CHECK-SUPPRESSIONS: RealtimeSanitizer exit stats:
38+
// CHECK-SUPPRESSIONS-NEXT: Total error count: 1
39+
// CHECK-SUPPRESSIONS-NEXT: Unique error count: 1
40+
// CHECK-SUPPRESSIONS-NEXT: Suppression count: 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function-name-matches:intentionally_non_existant_function

compiler-rt/test/rtsan/stack_suppressions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsanitize=realtime %s -o %t
22
// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS
3-
// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s
3+
// RUN: %env_rtsan_opts=suppressions='%s.supp':print_stats_on_exit=true not %run %t 2>&1 | FileCheck %s
44
// UNSUPPORTED: ios
55

66
// Intent: Ensure that suppressions work as intended
@@ -61,6 +61,9 @@ int main() {
6161
// CHECK-NOT: free
6262
// CHECK-NOT: BlockFunc
6363

64+
// CHECK: RealtimeSanitizer exit stats:
65+
// CHECK: Suppression count: 7
66+
6467
// CHECK-NOSUPPRESSIONS: malloc
6568
// CHECK-NOSUPPRESSIONS: vector
6669
// CHECK-NOSUPPRESSIONS: free

0 commit comments

Comments
 (0)