[llvm] Mark STATISTIC variables as maybe_unused when stats are disabled. (PR #159103)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 16 07:05:48 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: James Y Knight (jyknight)

<details>
<summary>Changes</summary>

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
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.

``````````

</details>


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


More information about the llvm-commits mailing list