Skip to content

[rtsan] Add stats summary even when halt_on_error=true #110165

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
merged 1 commit into from
Oct 7, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Sep 26, 2024

I discovered this on another branch. We only output the summary when halt_on_exit=false.

Questions:

  1. Should this configuration be valid? It will always definitionally output "total = 1, unique =1". We could just abort early as an invalid combo

Edit: on second thought, if we add more stats in the future we will want to output them here too, so I think this is a valid fix for this issue.

@cjappl
Copy link
Contributor Author

cjappl commented Sep 26, 2024

CC for review @davidtrevelyan

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

Changes

I discovered this on another branch. We only output the summary when halt_on_exit=false.

Questions:

  1. Should this configuration be valid? It will always definitionally output "total = 1, unique =1". We could just abort early as an invalid combo

Full diff: https://github.com/llvm/llvm-project/pull/110165.diff

2 Files Affected:

  • (modified) compiler-rt/lib/rtsan/rtsan.cpp (+4-1)
  • (modified) compiler-rt/test/rtsan/exit_stats.cpp (+6-1)
diff --git a/compiler-rt/lib/rtsan/rtsan.cpp b/compiler-rt/lib/rtsan/rtsan.cpp
index 6fcff5e326a52f..f4f242c0f34638 100644
--- a/compiler-rt/lib/rtsan/rtsan.cpp
+++ b/compiler-rt/lib/rtsan/rtsan.cpp
@@ -75,8 +75,11 @@ static auto OnViolationAction(DiagnosticsInfo info) {
       handle.inc_use_count_unsafe();
     }
 
-    if (flags().halt_on_error)
+    if (flags().halt_on_error) {
+      if (flags().print_stats_on_exit)
+        PrintStatisticsSummary();
       Die();
+    }
   };
 }
 
diff --git a/compiler-rt/test/rtsan/exit_stats.cpp b/compiler-rt/test/rtsan/exit_stats.cpp
index 4341fbb0f9cf21..d4d19ace778ba5 100644
--- a/compiler-rt/test/rtsan/exit_stats.cpp
+++ b/compiler-rt/test/rtsan/exit_stats.cpp
@@ -1,5 +1,6 @@
 // RUN: %clangxx -fsanitize=realtime %s -o %t
-// RUN: env RTSAN_OPTIONS="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
+// RUN: %env_rtsan_opts="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
+// RUN: %env_rtsan_opts="halt_on_error=true,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HALT
 
 // UNSUPPORTED: ios
 
@@ -22,3 +23,7 @@ int main() {
 // CHECK: RealtimeSanitizer exit stats:
 // CHECK-NEXT: Total error count: 10
 // CHECK-NEXT: Unique error count: 1
+
+// CHECK-HALT: RealtimeSanitizer exit stats:
+// CHECK-HALT-NEXT: Total error count: 1
+// CHECK-HALT-NEXT: Unique error count: 1

@fmayer
Copy link
Contributor

fmayer commented Sep 26, 2024

Considering it's not the default, I think this is reasonable.

@cjappl cjappl merged commit 9e06e77 into llvm:main Oct 7, 2024
10 checks passed
@cjappl cjappl deleted the print_stats_even_on_single branch October 7, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants