Skip to content

Conversation

@jyknight
Copy link
Member

PR #159045 made the constructor constexpr, which allows -Wunused-variable to trigger. However, we don't really care if a statistic is unused if LLVM_ENABLE_STATS is 0.

PR llvm#159045 made the constructor constexpr, which allows `-Wunused-variable` to trigger. However, we don't really care if a statistic is unused if `LLVM_ENABLE_STATS` is 0.
@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2025

@llvm/pr-subscribers-llvm-adt

Author: James Y Knight (jyknight)

Changes

PR #159045 made the constructor constexpr, which allows -Wunused-variable to trigger. However, we don't really care if a statistic is unused if LLVM_ENABLE_STATS is 0.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/Statistic.h (+5)
diff --git a/llvm/include/llvm/ADT/Statistic.h b/llvm/include/llvm/ADT/Statistic.h
index 795b0c2082c77..75d608beb0134 100644
--- a/llvm/include/llvm/ADT/Statistic.h
+++ b/llvm/include/llvm/ADT/Statistic.h
@@ -164,8 +164,13 @@ using Statistic = NoopStatistic;
 
 // STATISTIC - A macro to make definition of statistics really simple.  This
 // automatically passes the DEBUG_TYPE of the file into the statistic.
+#if LLVM_ENABLE_STATS
 #define STATISTIC(VARNAME, DESC)                                               \
   static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC}
+#else
+#define STATISTIC(VARNAME, DESC)                                               \
+  static llvm::Statistic VARNAME [[maybe_unused]] = {DEBUG_TYPE, #VARNAME, DESC}
+#endif
 
 // ALWAYS_ENABLED_STATISTIC - A macro to define a statistic like STATISTIC but
 // it is enabled even if LLVM_ENABLE_STATS is off.

@jyknight jyknight requested review from d0k and joker-eph September 16, 2025 14:08
@jyknight jyknight merged commit 334013b into llvm:main Sep 16, 2025
9 of 11 checks passed
@jyknight jyknight deleted the statistic-maybe-unused branch September 16, 2025 14:09
@joker-eph
Copy link
Collaborator

Thanks @jyknight !
Looks like no bot is covering this :(
(there are no reports on the original PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants