Skip to content

[NFC] [DebugCounter] warn if --debug-counter is unused in NDEBUG #143057

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

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Jun 6, 2025

No description provided.

Created using spr 1.3.4
@fmayer fmayer requested a review from nikic June 6, 2025 01:30
@fmayer fmayer marked this pull request as ready for review June 6, 2025 01:30
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-llvm-support

Author: Florian Mayer (fmayer)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Support/DebugCounter.cpp (+5)
diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index 9c4a4429ca0ee..1fbd700afa1d7 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -172,6 +172,11 @@ DebugCounter &DebugCounter::instance() {
 void DebugCounter::push_back(const std::string &Val) {
   if (Val.empty())
     return;
+#ifdef NDEBUG
+  // isCountingEnabled is hardcoded to false in NDEBUG.
+  errs() << "Requested --debug-counter in non-debug LLVM build. This is a "
+            "no-op.\n";
+#endif
 
   // The strings should come in as counter=chunk_list
   auto CounterPair = StringRef(Val).split('=');

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I was wondering whether we could just unconditionally enable debug counters, but doing that does have some meaningful overhead: https://llvm-compile-time-tracker.com/compare.php?from=100a1d0c4caad0d0f2ec26b07d3cc73f59b9a9a8&to=341c03268229f2982df1fd7ddb5e3db7a2e7731a&stat=instructions:u

Copy link

github-actions bot commented Jun 6, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

fmayer added 2 commits June 6, 2025 10:04
Created using spr 1.3.4
Created using spr 1.3.4
@fmayer fmayer merged commit 44a6a44 into main Jun 6, 2025
5 of 7 checks passed
@fmayer fmayer deleted the users/fmayer/spr/nfc-debugcounter-warn-if-debug-counter-is-unused-in-ndebug branch June 6, 2025 17:54
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