[llvm] [llvm] Use static_assert on getEmptyKey and getTombstoneKey (NFC) (PR #167167)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 8 10:59:10 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/167167
Note that DenseMapInfo<unsigned>::getEmptyKey() and getTombstoneKey()
are constexpr.
This patch removes assertion messages as they don't state any more
than what's expressed in the assertion condition.
Identified with misc-static-assert.
>From 68f75673ac52426337c90d176892957261426d0a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 6 Nov 2025 22:59:08 -0800
Subject: [PATCH] [llvm] Use static_assert on getEmptyKey and getTombstoneKey
(NFC)
Note that DenseMapInfo<unsigned>::getEmptyKey() and getTombstoneKey()
are constexpr.
This patch removes assertion messages as they don't state any more
than what's expressed in the assertion condition.
Identified with misc-static-assert.
---
llvm/include/llvm/Analysis/IRSimilarityIdentifier.h | 9 ++++-----
llvm/include/llvm/Transforms/IPO/IROutliner.h | 8 ++++----
llvm/lib/CodeGen/MachineOutliner.cpp | 8 ++++----
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
index 09a8875e1e28c..693777483ade2 100644
--- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
+++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
@@ -509,11 +509,10 @@ struct IRInstructionMapper {
: InstDataAllocator(IDA), IDLAllocator(IDLA) {
// Make sure that the implementation of DenseMapInfo<unsigned> hasn't
// changed.
- assert(DenseMapInfo<unsigned>::getEmptyKey() == static_cast<unsigned>(-1) &&
- "DenseMapInfo<unsigned>'s empty key isn't -1!");
- assert(DenseMapInfo<unsigned>::getTombstoneKey() ==
- static_cast<unsigned>(-2) &&
- "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
+ static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
+ static_cast<unsigned>(-1));
+ static_assert(DenseMapInfo<unsigned>::getTombstoneKey() ==
+ static_cast<unsigned>(-2));
IDL = new (IDLAllocator->Allocate())
IRInstructionDataList();
diff --git a/llvm/include/llvm/Transforms/IPO/IROutliner.h b/llvm/include/llvm/Transforms/IPO/IROutliner.h
index 28970f7dcdf10..e8275b2d20ade 100644
--- a/llvm/include/llvm/Transforms/IPO/IROutliner.h
+++ b/llvm/include/llvm/Transforms/IPO/IROutliner.h
@@ -204,10 +204,10 @@ class IROutliner {
: getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {
// Check that the DenseMap implementation has not changed.
- assert(DenseMapInfo<unsigned>::getEmptyKey() == (unsigned)-1 &&
- "DenseMapInfo<unsigned>'s empty key isn't -1!");
- assert(DenseMapInfo<unsigned>::getTombstoneKey() == (unsigned)-2 &&
- "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
+ static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
+ static_cast<unsigned>(-1));
+ static_assert(DenseMapInfo<unsigned>::getTombstoneKey() ==
+ static_cast<unsigned>(-2));
}
bool run(Module &M);
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 9feb9740de126..9f95c5ee9cbc6 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -420,10 +420,10 @@ struct InstructionMapper {
InstructionMapper(const MachineModuleInfo &MMI_) : MMI(MMI_) {
// Make sure that the implementation of DenseMapInfo<unsigned> hasn't
// changed.
- assert(DenseMapInfo<unsigned>::getEmptyKey() == (unsigned)-1 &&
- "DenseMapInfo<unsigned>'s empty key isn't -1!");
- assert(DenseMapInfo<unsigned>::getTombstoneKey() == (unsigned)-2 &&
- "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
+ static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
+ static_cast<unsigned>(-1));
+ static_assert(DenseMapInfo<unsigned>::getTombstoneKey() ==
+ static_cast<unsigned>(-2));
}
};
More information about the llvm-commits
mailing list