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

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 16 07:09:51 PDT 2025


Author: James Y Knight
Date: 2025-09-16T10:09:47-04:00
New Revision: 334013b090eef5b97cef8bc1817ed9ff67680488

URL: https://github.com/llvm/llvm-project/commit/334013b090eef5b97cef8bc1817ed9ff67680488
DIFF: https://github.com/llvm/llvm-project/commit/334013b090eef5b97cef8bc1817ed9ff67680488.diff

LOG: Mark STATISTIC variables as maybe_unused when stats are disabled. (#159103)

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.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Statistic.h

Removed: 
    


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


        


More information about the llvm-commits mailing list