[llvm] [llvm] Use static_assert on getEmptyKey and getTombstoneKey (NFC) (PR #167167)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 8 10:59:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/167167.diff
3 Files Affected:
- (modified) llvm/include/llvm/Analysis/IRSimilarityIdentifier.h (+4-5)
- (modified) llvm/include/llvm/Transforms/IPO/IROutliner.h (+4-4)
- (modified) llvm/lib/CodeGen/MachineOutliner.cpp (+4-4)
``````````diff
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));
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/167167
More information about the llvm-commits
mailing list