[llvm] Mark STATISTIC variables as maybe_unused when stats are disabled. (PR #159103)
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 07:05:13 PDT 2025
https://github.com/jyknight created https://github.com/llvm/llvm-project/pull/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.
>From 2869bcd42e8045939598b91c62152a356be933ee Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight at google.com>
Date: Tue, 16 Sep 2025 10:02:18 -0400
Subject: [PATCH] Mark STATISTIC variables as maybe_unused when stats are
disabled.
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.
---
llvm/include/llvm/ADT/Statistic.h | 5 +++++
1 file changed, 5 insertions(+)
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